Skip to content

Commit 95f0544

Browse files
committed
test(agent): validate unchanged policy placement evidence
1 parent c544737 commit 95f0544

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"countercheck": "synthetic mapping",
4+
"exitCode": 0,
5+
"scope": "Synthetic mapping check using copied earlier receipt; no candidate inference occurred."
6+
},
7+
{
8+
"countercheck": "changed original policy",
9+
"exitCode": 1,
10+
"scope": "Synthetic mapping check using copied earlier receipt; no candidate inference occurred."
11+
}
12+
]
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""Validate frozen original-policy placement evidence mechanics separately from semantic review."""
2+
import argparse
3+
import hashlib
4+
import json
5+
from pathlib import Path
6+
7+
root = Path(__file__).parent
8+
parser = argparse.ArgumentParser(description=__doc__)
9+
mode = parser.add_mutually_exclusive_group()
10+
mode.add_argument('--partial', action='store_true', help='Check only captured rows; cannot certify completion')
11+
parser.add_argument('--receipt', type=Path, help='Partial receipt override for diagnostic counterchecks')
12+
args = parser.parse_args()
13+
fixtures = json.loads((root / '2026-10-07-qwen3-instruct2507-seven-language-cases.json').read_text())
14+
fixtures = [x for x in fixtures if x['id'] in ['zh-CN-summarize', 'en-translate', 'ja-translate']]
15+
fixtures = [(x, variant) for x in fixtures for variant in ['product', 'policy-system']]
16+
assert len(fixtures) == 6
17+
if args.partial:
18+
workspace = root.resolve().parents[1]
19+
initial = json.loads((workspace / '.scratch/2026-10-07-qwen3-instruct2507-policy-placement-initial-bindings.json').read_text())
20+
for name, expected in initial['sha256'].items():
21+
assert hashlib.sha256((workspace / name).read_bytes()).hexdigest() == expected, name
22+
receipt = args.receipt or workspace / '.scratch/2026-10-07-qwen3-instruct2507-policy-placement-native.json'
23+
report = json.loads(receipt.read_text())
24+
assert 0 < len(report['cases']) <= 6
25+
else:
26+
assert args.receipt is None, 'Receipt override requires explicit partial mode'
27+
bindings = json.loads((root / '2026-10-07-qwen3-instruct2507-policy-placement-bindings.json').read_text())
28+
for name, expected in bindings['evidenceSHA256'].items():
29+
assert hashlib.sha256((root / name).read_bytes()).hexdigest() == expected, name
30+
report = json.loads((root / '2026-10-07-qwen3-instruct2507-policy-placement-native.json').read_text())
31+
assert len(report['cases']) == 6
32+
assert report['browserClosed']
33+
assert bindings['processExitCode'] == 0
34+
assert report['modelSHA256'] == '8cdb57cbb880d313736a9bc4e3d3d2485f145b5e19cf33783746e753e82641fc'
35+
verified = 0
36+
for (fixture, variant), row in zip(fixtures, report['cases']):
37+
assert row['prompt'] == fixture and row['variant'] == variant
38+
assert row['finished'] and row['contextClosed'] and not row.get('error')
39+
load = row['loads'][0]
40+
assert load['requested'] == {'n_threads': 4, 'n_ctx': 2048, 'n_gpu_layers': 0, 'reasoning': False}
41+
assert load['actualThreads'] == 4 and load['multithread']
42+
assert row['selected'] == row['documentBefore'] == fixture['source'] + '\r\n'
43+
verified += 1
44+
assert not row['crashed'] and not row['errors'] and row['previewCount'] == 0
45+
assert len(row['sdk']) == 1
46+
probe = row['sdk'][0]
47+
request = probe['request']
48+
assert row['counts'][-1] == request
49+
original = probe['originalMessages']
50+
assert len(original) == 2 and original[0]['role'] == 'system' and original[1]['role'] == 'user'
51+
preamble, task_json = original[1]['content'].rsplit('\n', 1)
52+
expected = original if variant == 'product' else [{'role': 'system', 'content': preamble}, {'role': 'user', 'content': task_json}]
53+
assert request['messages'] == expected, 'Policy placement must preserve original preamble and task JSON verbatim'
54+
assert request['response_format']['json_schema']['schema'] == {'type': 'object', 'additionalProperties': False, 'required': ['text'], 'properties': {'text': {'type': 'string'}}}
55+
assert request['temperature'] == .7 and request['top_p'] == .8 and request['top_k'] == 20
56+
assert request['seed'] == 42 and request['max_tokens'] == 512
57+
users = [message for message in request['messages'] if message['role'] == 'user']
58+
assert len(users) == 1
59+
task = json.loads(users[0]['content'].splitlines()[-1])
60+
assert task == {'task': fixture['task'], 'targetLanguage': fixture['targetLanguage'], 'text': row['selected'].replace('\r\n', '\n'), 'instruction': fixture['instruction']}
61+
if row['documentUnchanged']:
62+
assert row['documentAfter'] == row['documentBefore']
63+
else:
64+
assert row['afterUndo'] == row['documentBefore']
65+
assert row['afterRedo'] == row['documentAfter']
66+
raw = probe['completion']['choices'][0]['message']['content']
67+
assert json.loads(raw)['text'].replace('\r\n', '\n') + '\n' == row['documentAfter'].replace('\r\n', '\n')
68+
if args.partial:
69+
print(f"PARTIAL ONLY: {len(report['cases'])}/6 inference rows/mechanics checked. No completion or semantic acceptance.")
70+
else:
71+
print('Frozen six paired policy-placement requests and native application/history checked; refusals and semantics require separate review.')

0 commit comments

Comments
 (0)