Files
aevolution/tools/ci/history-domain-check.sh
T
dingoandClaude Opus 5.5 b73ccbae9a
Foundation / checks (ecs) (push) Successful in 2m19s
Foundation / checks (deploy) (push) Successful in 4m47s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 16m48s
Foundation / checks (network) (push) Canceled after 16m46s
Foundation / checks (postgres) (push) Canceled after 16m47s
Foundation / checks (client) (push) Canceled after 16m53s
Foundation / checks (tsan) (push) Canceled after 14m33s
feat(ecology): make photosynthesis regions playable on DEV
ADR-0176 and schema 57 admit raw cellular bundle 13 (rules 11 on owner
format 9) through parser-local normalization to bundle 12, and a fenced
no-tick 12 -> 13 upgrade that declares the region's light; recovery reads
the light from the target and re-derives the whole target from the source.
The resumable cellular-v8 opening provisions a cellular-v7 genesis, one
empty tick and the durable upgrades to bundle 13.

Session v12 adds the owner's captured light and the producers it can see
to its perception, and lets offers name photosynthesis; older sessions keep
their layouts and never receive photosynthesis candidates. The client
draws chloroplasts by efficiency, shows sunlight in the HUD and offers
photosynthesis cards. DEV now provisions and serves region 9 with the
trial light; region 8 stays stored but unserved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 23:04:34 -04:00

124 lines
9.4 KiB
Bash

#!/usr/bin/env bash
# Private postgres-check cluster only. No deployed database or biological rules.
set -euo pipefail
root="$(cd "$(dirname "$0")/../.." && pwd)"
createdb evo_history_domain
export PGDATABASE=evo_history_domain
bash "$root/tools/migrate-postgres.sh" > /dev/null
sql() { psql -XAt --no-password -v ON_ERROR_STOP=1 "$@"; }
fail() { echo "history-domain qualification FAILED: $*" >&2; exit 1; }
original="$(sql -c 'SELECT evolution.load_history_domain_v1()')"
[ -n "$original" ] || fail 'missing adoption domain'
bash "$root/tools/migrate-postgres.sh" > /dev/null
[ "$(sql -c 'SELECT evolution.load_history_domain_v1()')" = "$original" ] || fail 'no-op changed domain'
work="$(mktemp -d /tmp/evo-history-domain.XXXXXXXX)"
objects="$work/objects"
mkdir -m 700 "$objects"
trap 'rm -rf -- "$work"' EXIT
"${EVO_WORLD_CLONE_BIN:?private fixture tool}" provision --world 70201 --region 1 \
--opening development-v1 --pg-host "$PGHOST" --pg-port "$PGPORT" \
--pg-database "$PGDATABASE" --pg-user "$PGUSER" --objects "$objects" \
--build "$(printf 'cd%.0s' {1..32})" --retain-build true > /dev/null
request=51515151-5151-5151-5151-515151515151
if sql -c "SELECT evolution.fork_restored_history_v1('$request')" > /dev/null 2>&1; then
fail 'fork accepted a current build'
fi
[ "$(sql -c 'SELECT evolution.load_history_domain_v1()')" = "$original" ] || fail 'refusal mutated domain'
sql -c 'UPDATE evolution.retained_builds SET retired_at=clock_timestamp()' > /dev/null
if PGUSER="$EVO_PG_RUNTIME_USER" sql -c "SELECT evolution.fork_restored_history_v1('$request')" > /dev/null 2>&1; then
fail 'runtime can fork history'
fi
if PGUSER="$EVO_PG_RUNTIME_USER" sql -c 'SELECT * FROM evolution.current_history_domain' > /dev/null 2>&1; then
fail 'runtime can access context tables'
fi
sql -c "UPDATE evolution.region_leases SET epoch=1, holder=pg_catalog.gen_random_uuid(), expires_at=clock_timestamp()+interval '1 hour'" > /dev/null
if sql -c "SELECT evolution.fork_restored_history_v1('$request')" > /dev/null 2>&1; then
fail 'fork accepted a held lease'
fi
sql -c 'UPDATE evolution.region_leases SET holder=NULL, expires_at=NULL' > /dev/null
# An aborted transaction leaves both the namespace and provenance unchanged.
sql -c "BEGIN; SELECT evolution.fork_restored_history_v1('$request'); ROLLBACK" > /dev/null
[ "$(sql -c 'SELECT count(*) FROM evolution.history_domains')" = 1 ] &&
[ "$(sql -c 'SELECT count(*) FROM evolution.history_domain_cuts')" = 0 ] || fail 'rollback retained fork evidence'
fork="$(sql -c "SELECT evolution.fork_restored_history_v1('$request')")"
[ "$fork" != "$original" ] && [ -n "$fork" ] || fail 'fork reused parent domain'
[ "$(sql -c "SELECT evolution.fork_restored_history_v1('$request')")" = "$fork" ] &&
[ "$(sql -c 'SELECT count(*) FROM evolution.history_domains')" = 2 ] || fail 'retry duplicated fork'
[ "$(PGUSER="$EVO_PG_RUNTIME_USER" sql -c 'SELECT evolution.load_history_domain_v1()')" = "$fork" ] || fail 'runtime context read'
[ "$(sql -c "SELECT parent::text||':'||kind FROM evolution.history_domains WHERE domain='$fork'")" = "$original:restore" ] || fail 'parent provenance'
[ "$(sql -c "SELECT count(*) FROM evolution.history_domain_cuts d JOIN evolution.region_heads h USING(world_id,region_id) JOIN evolution.region_leases l USING(world_id,region_id) WHERE d.domain='$fork' AND d.frame_id=l.frame_id AND d.commit_sequence=h.commit_sequence AND d.commit_id=h.commit_id AND d.digest=h.digest AND d.end_tick=h.end_tick")" = 1 ] || fail 'exact fork cuts'
sql -c "SELECT evolution.fork_restored_history_v1('52525252-5252-5252-5252-525252525252')" > /dev/null
if sql -c "SELECT evolution.fork_restored_history_v1('$request')" > /dev/null 2>&1; then
fail 'stale request switched context backwards'
fi
for invalid in NULL "'00000000-0000-0000-0000-000000000000'"; do
if sql -c "SELECT evolution.fork_restored_history_v1($invalid)" > /dev/null 2>&1; then
fail 'invalid request accepted'
fi
done
# Reconstruct the exact pre-context metadata schema in this disposable database.
# Restore the resulting real legacy backup through both supported workflows.
# Undo schema 57's bundle-13 wrappers, schema 56's joint profile, schema 55's plan validators, schema 54's three
# replacements and schema 53; the backup must contain the actual pre-context
# function contracts and privileges.
awk '/^CREATE FUNCTION evolution\.admit_population_interval\(/ {capture=1; sub(/^CREATE FUNCTION/,"CREATE OR REPLACE FUNCTION")} capture {print} capture && /^END \$\$;/ {capture=0}' \
"$root/migrations/0045_owned_population_intervals.sql" | sql > /dev/null
awk '/^CREATE FUNCTION evolution\.(check_cellular_migration_trace|prepare_cellular_migration_freeze|publish_cellular_migration)\(/ {capture=1; sub(/^CREATE FUNCTION/,"CREATE OR REPLACE FUNCTION")} capture {print} capture && /^END \$\$;/ {capture=0}' \
"$root/migrations/0047_cellular_migration_freeze.sql" \
"$root/migrations/0049_cellular_migration_publication.sql" | sql > /dev/null
awk '/^CREATE OR REPLACE FUNCTION evolution\.(cellular_mutation_selections|check_cellular_mutation_block)\(/ {capture=1} capture {print} capture && /^END \$\$;/ {capture=0}' \
"$root/migrations/0040_cellular_mutation_decline.sql" | sql > /dev/null
sql -v runtime_role="$EVO_PG_RUNTIME_ROLE" > /dev/null <<'SQL'
DROP FUNCTION evolution.publish_cellular_profile_migration(bytea);
ALTER FUNCTION evolution.publish_cellular_profile_migration_v56(bytea) RENAME TO publish_cellular_profile_migration;
DROP FUNCTION evolution.cellular_births(bytea,bytea);
ALTER FUNCTION evolution.cellular_births_v56(bytea,bytea) RENAME TO cellular_births;
DROP FUNCTION evolution.parse_checkpoint_manifest(bytea);
ALTER FUNCTION evolution.parse_checkpoint_manifest_v56(bytea) RENAME TO parse_checkpoint_manifest;
DROP TRIGGER region_environment_evidence ON evolution.region_commits;
DROP FUNCTION evolution.refuse_unpublished_environment();
DROP FUNCTION evolution.load_environment_evidence(evolution.u64,evolution.u64,uuid,evolution.u64,uuid);
DROP FUNCTION evolution.resolve_environment_commit(evolution.u64,evolution.u64,uuid,bytea,bytea);
DROP FUNCTION evolution.publish_environment_profile_transition(bytea);
DROP FUNCTION evolution.publish_environment_checkpoint(bytea,bytea);
DROP FUNCTION evolution.check_environment_trace(bytea,bytea);
DROP TABLE evolution.environment_publications, evolution.environment_profile_transitions;
DROP FUNCTION evolution.parse_checkpoint_manifest(bytea);
DROP FUNCTION evolution.parse_checkpoint_manifest_v55(bytea);
DROP FUNCTION evolution.parse_checkpoint_manifest_v54(bytea);
ALTER FUNCTION evolution.parse_checkpoint_manifest_v52(bytea) RENAME TO parse_checkpoint_manifest;
DROP FUNCTION evolution.cellular_births(bytea,bytea);
DROP FUNCTION evolution.cellular_births_v54(bytea,bytea);
ALTER FUNCTION evolution.cellular_births_v52(bytea,bytea) RENAME TO cellular_births;
DROP FUNCTION evolution.check_population_trace(bytea,bytea);
ALTER FUNCTION evolution.check_population_trace_v52(bytea,bytea) RENAME TO check_population_trace;
DROP FUNCTION evolution.publish_cellular_profile_migration(bytea);
DROP FUNCTION evolution.publish_cellular_profile_migration_v54(bytea);
ALTER FUNCTION evolution.publish_cellular_profile_migration_v52(bytea) RENAME TO publish_cellular_profile_migration;
GRANT EXECUTE ON FUNCTION evolution.publish_cellular_profile_migration(bytea) TO :"runtime_role";
DROP FUNCTION evolution.publish_population_profile_transition_v44(bytea);
ALTER FUNCTION evolution.publish_population_profile_transition_v52(bytea) RENAME TO publish_population_profile_transition_v44;
DROP FUNCTION evolution.fork_restored_history_v1(uuid);
DROP FUNCTION evolution.load_world_cellular_migrations_v1(evolution.u64);
DROP FUNCTION evolution.load_history_domain_v1();
DROP TABLE evolution.history_domain_cuts, evolution.current_history_domain, evolution.history_domains;
ALTER TABLE evolution.cellular_mutation_action_publications DROP CONSTRAINT cellular_mutation_action_publications_result_check;
ALTER TABLE evolution.cellular_mutation_action_publications ADD CONSTRAINT cellular_mutation_action_publications_result_check CHECK(result BETWEEN 0 AND 3);
DELETE FROM evolution.schema_migrations WHERE version>=51;
UPDATE evolution.retained_builds SET retired_at=NULL;
SQL
bash "$root/tools/backup/backup-world.sh" --objects "$objects" --out "$work/legacy" --label legacy-context > /dev/null
createdb evo_history_legacy_isolated
PGDATABASE=evo_history_legacy_isolated bash "$root/tools/backup/restore-world.sh" \
--bundle "$work/legacy" --objects "$work/isolated" > "$work/isolated.log" 2>&1 ||
{ cat "$work/isolated.log" >&2; fail 'legacy isolated restore'; }
[ "$(PGDATABASE=evo_history_legacy_isolated sql -c "SELECT to_regprocedure('evolution.load_history_domain_v1()') IS NULL")" = t ] || fail 'invented legacy source context'
createdb evo_history_legacy_inplace
PGDATABASE=evo_history_legacy_inplace bash "$root/tools/backup/restore-world.sh" \
--bundle "$work/legacy" --objects "$work/inplace" --in-place \
--runtime-role "$EVO_PG_RUNTIME_ROLE" --accept-rewind > "$work/inplace.log" 2>&1 ||
{ cat "$work/inplace.log" >&2; fail 'legacy in-place restore'; }
[ "$(PGDATABASE=evo_history_legacy_inplace sql -c "SELECT count(*) FROM evolution.history_domains WHERE kind='adoption' AND parent IS NULL AND request IS NULL")" = 1 ] &&
[ "$(PGDATABASE=evo_history_legacy_inplace sql -c 'SELECT count(*) FROM evolution.history_domain_cuts')" = 0 ] || fail 'invented legacy branch provenance'
echo 'history-domain adoption, quarantine, rollback, exact cuts, retries, privileges and legacy restores passed'