1313from pathlib import Path
1414
1515from canonical_authority_fixture import isolate_sqlite_runtime
16+ from tests .control_plane .codex_checkpoint_fixture import read_cli_policy_payload
1617import test_quota_settlement_cli as settlement
1718from test_todo_list_record_references import expand_references
1819from test_quota_authority_settlement_journey import _source
2324
2425def test_file_sqlite_file_retains_new_todos_results_and_settled_turn (tmp_path , monkeypatch ):
2526 isolate_sqlite_runtime (tmp_path , monkeypatch )
26- project , runtime , registry , state , _ = _source (
27+ project , runtime , registry , state , goal_intent = _source (
2728 tmp_path , provider = "file" , handoff_mode = "hard_lease" ,
2829 extra = f"claimed_by={ settlement .AGENT_ID } " ,
2930 )
@@ -39,7 +40,7 @@ def run(*args, expected=0):
3940 capture_output = True , text = True , timeout = 90 , check = False ,
4041 )
4142 assert process .returncode == expected , process .stdout + process .stderr
42- return json . loads (process .stdout )
43+ return read_cli_policy_payload (process .stdout , returncode = process . returncode )
4344
4445 def listed ():
4546 payload = run ("todo" , "list" , "--goal-id" , goal )
@@ -78,6 +79,9 @@ def history(name):
7879 assert listed ()["authority_read" ]["source_authority" ] == "file_v0"
7980 assert run (* migration , "--execute" )["selected_provider" ] == "sqlite"
8081 state .unlink () # Neither restart nor rollback may restore old display truth.
82+ # Keep registered Goal intent available without restoring any Todo rows.
83+ # Canonical work continuity is distinct from permission to lose intent.
84+ state .write_text (goal_intent )
8185
8286 add_args = ("todo" , "add" , "--goal-id" , goal , "--role" , "agent" ,
8387 "--text" , "Validate work added after the upgrade" , "--priority" , "P0" ,
@@ -90,11 +94,17 @@ def history(name):
9094 assert added_again ["status" ] == "replayed"
9195
9296 guard = run (* guard_args )
93- assert guard ["interaction_contract" ]["agent_channel" ]["delivery_allowed" ] is True
97+ assert guard ["should_run" ] is True
98+ assert guard ["execution_preparation" ]["state" ] == "claim_required"
99+ assert guard ["interaction_contract" ]["agent_channel" ]["delivery_allowed" ] is False
94100 identity = guard ["heartbeat_receipt" ]["settlement_identity" ]
95101 acquired = run ("task-lease" , "acquire" , * lease_args , "--expected-version" , "0" ,
96102 "--ttl-seconds" , "3600" , "--write-scope" , "tests/**" )
97103 version = str (acquired ["lease" ]["version" ])
104+ prepared = run (* guard_args )
105+ assert prepared ["execution_preparation" ]["state" ] == "ready"
106+ assert prepared ["interaction_contract" ]["agent_channel" ]["delivery_allowed" ] is True
107+ assert prepared ["heartbeat_receipt" ]["settlement_identity" ] == identity
98108 proof = ("--task-lease-idempotency-key" , "retained-work" ,
99109 "--task-lease-expected-version" , version )
100110 note = "New result after SQLite upgrade; 中文说明与原操作回执必须保留。"
0 commit comments