From 7d98c37b113f03e783e7d42403078413f098dbf5 Mon Sep 17 00:00:00 2001 From: "lusendong.6789" Date: Sat, 14 Nov 2026 21:25:42 +0800 Subject: [PATCH] test: read original signed policy sources behind required views Signed-off-by: lusendong.6789 Co-authored-by: TRAE CLI --- .../rfcs/monorepo-distribution-split-v0.md | 26 +++++++++ .../monorepo-distribution-split-v0.zh-CN.md | 19 +++++++ .../control_plane/codex_checkpoint_fixture.py | 20 ++++++- .../test_work_context_host_delivery.py | 55 ++++++++++++++++++- 4 files changed, 118 insertions(+), 2 deletions(-) diff --git a/docs/architecture/rfcs/monorepo-distribution-split-v0.md b/docs/architecture/rfcs/monorepo-distribution-split-v0.md index 76e233404d..07588c657f 100644 --- a/docs/architecture/rfcs/monorepo-distribution-split-v0.md +++ b/docs/architecture/rfcs/monorepo-distribution-split-v0.md @@ -4062,3 +4062,29 @@ coercion but produced an inactive policy, silently skipping research evidence. The existing configuration owner now refuses this malformed shape before IO; documented scalar modes, defaults and errors retain their semantics. Real File/SQLite negative cases guard this boundary without changing valid activation. + + +### 2026-11-14 — Policy observers recover the original signed source + +- **Baseline:** `main@8d7d234c6f55`; C1 #8266 at `c3cb8b2fe7bf`. +- **Gap:** three current C1 guided-start and visible-Goal selection cases + rejected a required presentation as if it were the original signed decision. + The original capture passes both its physical digest and complete-contract + validation. Same-view Todo references and their read guidance change the + presentation body while retaining the original binding. +- **Delta:** the existing test policy observer follows the presentation's + declared immutable capture and digest before comparing decision facts. It + reuses the physical capture reader; inline/off outputs without such a + reference retain their current behavior. No producer, decision, hash codec, + admission, settlement owner or default changes. +- **Evidence:** the existing real guided-start/visible-Goal CLI cases pass on + the pinned C1 combination. The durable File/SQLite regression exercises the + shared typed projection and verifies original-source equality, its complete + binding, zero spend and rejection of changed or missing captured bytes, including a valid + replacement whose original binding differs. A + private matched observer comparison distinguishes the old and corrected + readers. Earlier failed and incomplete runs remain failed or incomplete. +- **Remaining:** this repairs a consumer-qualification prerequisite. Complete + V1–V5/V10, R1/M3, current D2/D5 closure, actual Host/model context adoption, + progressive product control, comparable complete costs, C1 default cutover + and original-Goal regression remain open. diff --git a/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md b/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md index e11c0e2367..b06b17be9f 100644 --- a/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md +++ b/docs/architecture/rfcs/monorepo-distribution-split-v0.zh-CN.md @@ -3160,3 +3160,22 @@ R1/M3、C1 切换和原目标回归仍未完成资格验证。 通过字符串强制转换,却生成 inactive policy,静默跳过研究证据。既有配置 owner 现在在 IO 之前拒绝这种错误形状;已声明的标量 mode、默认值和错误语义保持不变。 真实 File/SQLite 负向用例保护这个边界,不改变合法激活规则。 + + +### 2026-11-14 — 策略观察者恢复原始签名来源 + +- **基线:**`main@8d7d234c6f55`;C1 #8266 为 `c3cb8b2fe7bf`。 +- **缺口:**当前 C1 的三条 guided-start 和可见 Goal 选择用例,把必要 + 展示页当成原始签名决策而拒绝。原始捕获的物理摘要和完整合同校验均 + 通过。同页 Todo 引用及其读取说明改变了展示正文,但保留原来源绑定。 +- **交付:**既有测试策略观察者在比较决策事实前,沿展示页声明的不可变 + 捕获及摘要读取原来源,复用物理捕获 reader。没有该引用的 inline/off + 输出保留现有行为。生产者、决策、哈希编码、准入、结算 owner 和默认值 + 均未改变。 +- **证据:**固定 C1 组合的既有真实 guided-start/可见 Goal CLI 用例通过。 + 稳定 File/SQLite 回归执行共享 typed 投影,验证原来源相等、完整绑定、 + 零扣额,并拒绝捕获字节被改动或缺失,以及完整校验通过但原绑定不同的替代捕获。私有匹配观察者比较区分旧 reader + 与修复 reader。历史失败及未完成运行继续保持失败或未完成。 +- **剩余:**本切片修复消费者资格的前置缺口。完整 V1–V5/V10、R1/M3、 + 当前 D2/D5 闭包、真实 Host/模型上下文采用、渐进产品控制、可比完整成本、 + C1 默认切换和原 Goal 回归仍开放。 diff --git a/tests/control_plane/codex_checkpoint_fixture.py b/tests/control_plane/codex_checkpoint_fixture.py index 59c7145624..6412bb74be 100644 --- a/tests/control_plane/codex_checkpoint_fixture.py +++ b/tests/control_plane/codex_checkpoint_fixture.py @@ -157,7 +157,25 @@ def read_cli_policy_payload(stdout, *, returncode): recovery = payload["recovery"] if "reference_file" in recovery: recovery = read_context_read_reference(recovery["reference_file"])[1] - return read_context_capture_file(recovery["path"], recovery["sha256"], private=True)[2] + payload = read_context_capture_file(recovery["path"], recovery["sha256"], private=True)[2] + if returncode == 0 and payload.get("schema_version") == "loopx_turn_envelope_v1": + details = payload.get("context_details", {}) + command = details.get("command_template") if isinstance(details, dict) else None + if isinstance(command, str): + # A required view can reuse Todo rows while retaining the original + # binding. Inspect its declared immutable source for policy tests; + # the display itself is not the signed decision or model retention. + argv = shlex.split(command) + for flag in ("--capture-file", "--capture-sha256"): + if argv.count(flag) != 1: + raise ValueError("policy view requires one original capture and digest") + original = read_context_capture_file( + argv[argv.index("--capture-file") + 1], + argv[argv.index("--capture-sha256") + 1], private=True, + )[2] + if original.get("contract_binding") != payload.get("contract_binding"): + raise ValueError("policy view original capture binding mismatch") + payload = original return payload diff --git a/tests/control_plane/test_work_context_host_delivery.py b/tests/control_plane/test_work_context_host_delivery.py index 2061396d4b..6c0b2ed5b4 100644 --- a/tests/control_plane/test_work_context_host_delivery.py +++ b/tests/control_plane/test_work_context_host_delivery.py @@ -14,11 +14,64 @@ initialize_canonical_authority, isolate_sqlite_runtime, read_fixture_todos, ) from tests.control_plane.test_quota_settlement_cli import ( - AGENT_ID, GOAL_ID, TODO_ID, TURN_ID, _configure_read_only_todo, + AGENT_ID, GOAL_ID, TODO_ID, TURN_ID, _configure_read_only_todo, _configure_selectable_alternative, _heartbeat_receipt_count, _run_cli, _spend_run_count, _write_fixture, ) +@pytest.mark.parametrize('provider', ['file', 'sqlite']) +def test_policy_observer_reads_original_signed_capture_after_todo_references(tmp_path, monkeypatch, provider): + from loopx.control_plane.quota.turn_envelope import assert_complete_turn_decision, compose_turn_decision + from loopx.control_plane.turn_driver.decision_capture import capture_progressive_context, write_decision_capture + from tests.control_plane.canonical_authority_fixture import initialize_canonical_source_fixture + from tests.control_plane.codex_checkpoint_fixture import read_cli_policy_payload + + isolate_sqlite_runtime(tmp_path, monkeypatch) + project, runtime, registry = _write_fixture(tmp_path) + _configure_selectable_alternative(project) + initialize_canonical_source_fixture(runtime, GOAL_ID, + state_path=project / f'.codex/goals/{GOAL_ID}/ACTIVE_GOAL_STATE.md', provider=provider) + capture = tmp_path / 'signed-capture' + code, view = _run_cli(registry, runtime, 'quota', 'should-run', '--goal-id', GOAL_ID, + '--agent-id', AGENT_ID, '--begin-turn', + '--codex-app', '--complete-turn', '--context-delivery', 'auto', '--delta-delivery', 'off', + '--decision-output-dir', str(capture)) + assert code == 0, view + saved = capture / 'decision.json' + original_bytes = saved.read_bytes() + original = json.loads(original_bytes) + # Exercise the same typed projection used by C1's inline CLI presentation. + (tmp_path / 'view').mkdir(mode=0o700) + view = capture_progressive_context(original, directory=tmp_path / 'view', surface='complete_turn')[0] + assert 'context_reference_instruction' in view and view != original + source = tmp_path / 'view' / 'projection.json' + observed = read_cli_policy_payload(json.dumps(view), returncode=code) + assert observed == original + assert_complete_turn_decision(observed) + assert _spend_run_count(runtime) == 0 and saved.read_bytes() == original_bytes + replacement = compose_turn_decision({ + **{key: value for key, value in original.items() if key not in {'schema_version', 'contract_binding'}}, + 'reason': 'a separate valid captured observation', + }) + assert_complete_turn_decision(replacement) + replacement_path = source.with_name('replacement.json') + replacement_digest = write_decision_capture(replacement_path, replacement) + replaced_view = copy.deepcopy(view) + argv = shlex.split(replaced_view['context_details']['command_template']) + argv[argv.index('--capture-file') + 1] = str(replacement_path) + argv[argv.index('--capture-sha256') + 1] = replacement_digest + replaced_view['context_details']['command_template'] = shlex.join(argv) + with pytest.raises(ValueError, match='original capture binding mismatch'): + read_cli_policy_payload(json.dumps(replaced_view), returncode=code) + # A copied presentation must not mask corruption of its declared source. + source.write_text(json.dumps({**original, 'reason': 'changed after capture'})) + with pytest.raises(ValueError, match='capture digest mismatch'): + read_cli_policy_payload(json.dumps(view), returncode=code) + source.unlink() + with pytest.raises(FileNotFoundError): + read_cli_policy_payload(json.dumps(view), returncode=code) + + @pytest.mark.parametrize('provider', ['file', 'sqlite']) @pytest.mark.parametrize('repetitions', [1, 40]) def test_authored_requirements_survive_capture_projection_and_host(tmp_path, monkeypatch, provider, repetitions):