@@ -1601,6 +1601,132 @@ def test_prior_host_closeout_survives_hidden_todo_lifecycle(
16011601 assert resumed ["quota" ]["spent_slots" ] == prior ["quota" ]["spent_slots" ]
16021602
16031603
1604+ @pytest .mark .parametrize ("provider" , ["legacy" , "file" , "sqlite" ])
1605+ def test_prior_host_closeout_reads_archived_exact_todo (
1606+ tmp_path : Path ,
1607+ provider : str ,
1608+ monkeypatch : pytest .MonkeyPatch ,
1609+ ) -> None :
1610+ from canonical_authority_fixture import (
1611+ initialize_canonical_authority ,
1612+ isolate_sqlite_runtime ,
1613+ )
1614+ from loopx .control_plane .coordination .runtime_shadow import (
1615+ build_todo_runtime_shadow_projection ,
1616+ )
1617+
1618+ if provider == "sqlite" :
1619+ isolate_sqlite_runtime (tmp_path , monkeypatch )
1620+ project , runtime , registry_path = _write_fixture (tmp_path )
1621+ guard = (
1622+ "quota" ,
1623+ "should-run" ,
1624+ "--codex-app" ,
1625+ "--goal-id" ,
1626+ GOAL_ID ,
1627+ "--agent-id" ,
1628+ AGENT_ID ,
1629+ "--scan-path" ,
1630+ str (project ),
1631+ )
1632+ prior_turn_id = "turn-archived-closeout-prior"
1633+ rc , prior = _run_cli (
1634+ registry_path ,
1635+ runtime ,
1636+ * guard ,
1637+ "--turn-instance-id" ,
1638+ prior_turn_id ,
1639+ "--todo-id" ,
1640+ TODO_ID ,
1641+ )
1642+ assert rc == 0 , prior
1643+ assert prior ["heartbeat_receipt" ]["closeout_required" ] is True
1644+
1645+ state = project / ".codex" / "goals" / GOAL_ID / "ACTIVE_GOAL_STATE.md"
1646+ if provider != "legacy" :
1647+ rc , listed = _run_cli (
1648+ registry_path , runtime , "todo" , "list" , "--goal-id" , GOAL_ID
1649+ )
1650+ assert rc == 0 , listed
1651+ projection = build_todo_runtime_shadow_projection (
1652+ goal_id = GOAL_ID ,
1653+ handoff_mode = "soft_claim" ,
1654+ todos = listed ["todos" ],
1655+ )
1656+ initialize_canonical_authority (
1657+ runtime , GOAL_ID , projection , state_path = state , provider = provider
1658+ )
1659+
1660+ rc , complete = _run_cli (
1661+ registry_path ,
1662+ runtime ,
1663+ "todo" ,
1664+ "complete" ,
1665+ "--goal-id" ,
1666+ GOAL_ID ,
1667+ "--agent-id" ,
1668+ AGENT_ID ,
1669+ "--todo-id" ,
1670+ TODO_ID ,
1671+ "--turn-instance-id" ,
1672+ prior_turn_id ,
1673+ "--claimed-by" ,
1674+ AGENT_ID ,
1675+ "--evidence" ,
1676+ "archived closeout lifecycle validated" ,
1677+ "--next-agent-todo" ,
1678+ "Continue after archived closeout validation." ,
1679+ "--next-claimed-by" ,
1680+ AGENT_ID ,
1681+ "--next-action-kind" ,
1682+ "implement" ,
1683+ )
1684+ assert rc == 0 , complete
1685+ rc , archived = _run_cli (
1686+ registry_path ,
1687+ runtime ,
1688+ "todo" ,
1689+ "archive-completed" ,
1690+ "--goal-id" ,
1691+ GOAL_ID ,
1692+ "--max-active-done" ,
1693+ "0" ,
1694+ "--execute" ,
1695+ )
1696+ assert rc == 0 , archived
1697+ assert archived ["moved_count" ] == 1
1698+
1699+ rc , active = _run_cli (
1700+ registry_path , runtime , "todo" , "list" , "--goal-id" , GOAL_ID
1701+ )
1702+ assert rc == 0 , active
1703+ assert TODO_ID not in {item ["todo_id" ] for item in active ["todos" ]}
1704+ rc , exact = _run_cli (
1705+ registry_path ,
1706+ runtime ,
1707+ "todo" ,
1708+ "list" ,
1709+ "--goal-id" ,
1710+ GOAL_ID ,
1711+ "--role" ,
1712+ "agent" ,
1713+ "--todo-id" ,
1714+ TODO_ID ,
1715+ )
1716+ assert rc == 0 , exact
1717+ assert exact ["todo" ]["todo_id" ] == TODO_ID
1718+ assert exact ["todo" ]["status" ] == "done"
1719+ assert exact ["todo" ]["archive_state" ] == "archive"
1720+ assert exact ["todo" ]["source_section" ] == "Completed Work Archive"
1721+
1722+ rc , observed = _run_cli (registry_path , runtime , * guard , "--begin-turn" )
1723+ assert rc == 0 , observed
1724+ assert observed ["effective_action" ] != "unsettled_host_turn_recovery" , observed .get (
1725+ "unsettled_host_turn_recovery"
1726+ )
1727+ assert observed ["quota" ]["spent_slots" ] == prior ["quota" ]["spent_slots" ]
1728+
1729+
16041730def test_standard_codex_app_settlement_is_receipted_and_idempotent (
16051731 tmp_path : Path ,
16061732) -> None :
0 commit comments