harness-everything 1.2.2 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +29 -0
- package/ci/archive/325-prep/README.md +9 -2
- package/ci/archive/325-prep/doc-reconciliation-red.js +34 -8
- package/ci/fixtures/468-dispatch/agy-quota-PROVENANCE.md +19 -0
- package/ci/fixtures/468-dispatch/agy-quota-direct-individual.stderr +2 -0
- package/ci/fixtures/468-dispatch/agy-quota-direct-third-party.stderr +2 -0
- package/ci/fixtures/468-dispatch/agy-quota-exec-individual.log +3 -0
- package/ci/fixtures/553-t2a/body-edit/base/.agents/harness-everything/project-docs.json +11 -0
- package/ci/fixtures/553-t2a/body-edit/base/docs/a.md +6 -0
- package/ci/fixtures/553-t2a/body-edit/base/docs/b.md +1 -0
- package/ci/fixtures/553-t2a/body-edit/candidate/docs/a.md +6 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/adr/EVID-001-verify-all-evidence.md +11 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/base/docs/governed-index.md +19 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/adr/EVID-001-verify-all-evidence.md +11 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/candidate/docs/governed-index.md +19 -0
- package/ci/fixtures/553-t2c/derived-regenerate-must/config.json +17 -0
- package/ci/fixtures/doc-obligations/derive/regression-pins.json +153 -0
- package/ci/fixtures/state-persist-post-tool-use/harness.js +206 -0
- package/ci/fixtures/state-persist-post-tool-use/off-handoff-golden.json +16 -0
- package/ci/fixtures/state-persist-post-tool-use/payload-post-tool-use-success.json +13 -0
- package/ci/fixtures/stop/fail-session-writes.js +109 -0
- package/ci/fixtures/workflow-contract/cases.json +3355 -0
- package/ci/fixtures/workflow-contract/wiring-cases.json +560 -0
- package/ci/lib/doc-reconciliation-prep-fixtures.js +4 -9
- package/ci/mechanism-2an-workflow-replay.test.js +324 -0
- package/ci/mechanism-2ax-doc-lifecycle.test.js +132 -0
- package/ci/mechanism-325-3a-doc-evidence.test.js +73 -0
- package/ci/mechanism-325-3a-doc-obligations.test.js +61 -0
- package/ci/mechanism-325-3b-preparation.test.js +208 -49
- package/ci/mechanism-325-3b-s1-review.test.js +20 -828
- package/ci/mechanism-325-3b-s3-providers.test.js +59 -0
- package/ci/mechanism-325-f3-derived-views.test.js +140 -0
- package/ci/mechanism-341-opencode-lane.test.js +164 -284
- package/ci/mechanism-35-verification-contract.test.js +246 -0
- package/ci/mechanism-365-step-edit-accounting.test.js +5 -6
- package/ci/mechanism-383-doc-glob-line-terminators.test.js +0 -30
- package/ci/mechanism-397-opencode-observations.test.js +151 -18
- package/ci/mechanism-468-dispatch-cli.test.js +1496 -4
- package/ci/mechanism-548-bigint-identity.test.js +531 -0
- package/ci/mechanism-553-e1-unhook-credit.test.js +328 -0
- package/ci/mechanism-553-p2a-claude-hooks.test.js +98 -0
- package/ci/mechanism-553-p3-plan-start.test.js +212 -0
- package/ci/mechanism-553-state-persist-post-tool-use.test.js +307 -0
- package/ci/mechanism-553-stop.test.js +427 -0
- package/ci/mechanism-553-t2a-derive.test.js +110 -0
- package/ci/mechanism-553-t2c-derive.test.js +94 -0
- package/ci/mechanism-e1-derived-regenerate.test.js +45 -206
- package/ci/mechanism-error-ledger-oracle.test.js +786 -3
- package/ci/mechanism-error-ledger-scan.test.js +981 -0
- package/ci/mechanism-outline-sanitizer.test.js +0 -8
- package/ci/mechanism-pr-a-conflict-check.test.js +38 -305
- package/ci/mechanism-prb-outline-review.test.js +101 -3283
- package/ci/mechanism-report-writer.test.js +45 -0
- package/docs/adr/DOCS-006-reconciliation-pilot.md +4 -2
- package/docs/adr/DOCS-008-obligation-abstraction-bounded-consumer.md +3 -3
- package/docs/doc-workflow-reconciliation.md +17 -2
- package/docs/document-lifecycle.md +6 -2
- package/docs/error-handling/details/c8-dispatch-cli.md +109 -13
- package/docs/platform-capabilities.md +35 -5
- package/error-ledger-bootstrap/SKILL.md +1 -1
- package/error-ledger-bootstrap/references/workflow.md +42 -7
- package/error-ledger-bootstrap/scripts/promote.js +8 -6
- package/error-ledger-bootstrap/scripts/scan.js +525 -12
- package/hooks/hooks.json +0 -46
- package/hooks/scripts/lib/workflow-obligations.js +0 -55
- package/hooks/scripts/state-persist.js +7 -95
- package/hooks/scripts/workflow-disposition.js +0 -2
- package/hooks/scripts/workflow-stop-gate.js +17 -30
- package/opencode-plugin/index.mjs +6 -70
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/hooks/scripts/lib/workflow-obligations.js +0 -55
- package/plugins/harness-everything/hooks/scripts/state-persist.js +7 -95
- package/plugins/harness-everything/hooks/scripts/workflow-disposition.js +0 -2
- package/plugins/harness-everything/hooks/scripts/workflow-stop-gate.js +17 -30
- package/plugins/harness-everything/plugin.json +1 -1
- package/plugins/harness-everything/skills/error-ledger-bootstrap/SKILL.md +1 -1
- package/plugins/harness-everything/skills/error-ledger-bootstrap/references/workflow.md +42 -7
- package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/promote.js +8 -6
- package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/scan.js +525 -12
- package/sbom.cdx.json +7 -7
- package/scripts/dispatch.js +499 -87
- package/scripts/error-ledger-oracle.js +521 -27
- package/scripts/errors-sync.js +4 -3
- package/scripts/report-writer.js +4 -3
- package/ci/fixtures/doc-obligations/reconciliation-s1/cases.json +0 -6854
- package/ci/fixtures/doc-obligations/reconciliation-s1/fail-session-writes.js +0 -116
- package/ci/fixtures/doc-obligations/reconciliation-s2a/harness.js +0 -507
- package/ci/fixtures/doc-obligations/reconciliation-s2a/run13-workflow-requirements.json +0 -42
- package/ci/fixtures/doc-obligations/reconciliation-s2a/vectors.json +0 -617
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/harness.js +0 -415
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-post-tool-use-success-minimal.json +0 -9
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-start.json +0 -7
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-freetext-reject.json +0 -11
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop-reject.json +0 -11
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-subagent-stop.json +0 -11
- package/ci/fixtures/doc-obligations/reconciliation-s2b/capture/payload-task-result.json +0 -19
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-capture-only.json +0 -99
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/off-legacy.json +0 -67
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-concurrent-writers.json +0 -62
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-lookalikes-runtime-mutations.json +0 -67
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-malformed.json +0 -85
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-normal-session.json +0 -74
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-runtime-drift-later-npm-test.json +0 -58
- package/ci/fixtures/doc-obligations/reconciliation-s2b/corpus/on-valid-direct-quoted-review.json +0 -85
- package/ci/fixtures/doc-obligations/reconciliation-s2b/f4/cases.json +0 -2267
- package/ci/fixtures/doc-obligations/reconciliation-s2b/wiring/cases.json +0 -1110
- package/ci/lib/doc-reconciliation-file-spy.js +0 -23
- package/ci/lib/doc-reconciliation-qualification-preload.js +0 -37
- package/ci/lib/doc-reconciliation-replay.js +0 -104
- package/ci/lib/doc-reconciliation-staged-tree.js +0 -102
- package/ci/mechanism-325-3b-h1-qualification.test.js +0 -206
- package/ci/mechanism-325-3b-s1.test.js +0 -188
- package/ci/mechanism-325-3b-s2a-core.test.js +0 -840
- package/ci/mechanism-325-3b-s2a-producer.test.js +0 -564
- package/ci/mechanism-325-3b-s2b-capture.test.js +0 -566
- package/ci/mechanism-325-3b-s2b-wiring.test.js +0 -679
- package/ci/mechanism-325-f4-invariants.test.js +0 -606
- package/ci/mechanism-325-f4-projections.test.js +0 -392
- package/ci/mechanism-325-f4-qualification.test.js +0 -228
- package/ci/mechanism-325-f4-trust-boundary.test.js +0 -880
- package/ci/mechanism-e1-dependency-artifact-scope.test.js +0 -657
- package/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
- package/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
- package/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
- package/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
- package/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
- package/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
- package/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
- package/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
- package/hooks/scripts/w6-state-operations.js +0 -239
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-capture.sanitized.jsonl +0 -26
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-core.js +0 -336
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-events.js +0 -292
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-outline-capture.sanitized.jsonl +0 -24
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-pilot.js +0 -482
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-producer.js +0 -468
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-provider.js +0 -3304
- package/plugins/harness-everything/hooks/scripts/lib/doc-reconciliation-qualification.json +0 -54
- package/plugins/harness-everything/hooks/scripts/w6-state-operations.js +0 -239
- package/scripts/system-one-eval-laya.js +0 -112
- /package/ci/fixtures/{doc-obligations/reconciliation-s2b/capture → state-persist-post-tool-use}/payload-post-tool-use-failure.json +0 -0
- /package/ci/fixtures/{doc-obligations/reconciliation-s2b/wiring → workflow-contract}/legacy-off-golden.json +0 -0
|
@@ -594,6 +594,252 @@ try {
|
|
|
594
594
|
}
|
|
595
595
|
}
|
|
596
596
|
|
|
597
|
+
const crypto = require('crypto');
|
|
598
|
+
|
|
599
|
+
// Retained F4 controls exercise generic verification/handoff entries directly;
|
|
600
|
+
// they do not load the retired qualification tree or pilot corpus.
|
|
601
|
+
const RETAINED_REQUIREMENTS = [
|
|
602
|
+
{ id: 'req-change', stepType: 'behavior-change', summary: 'Make the code change', acceptance: 'The change is recorded.' },
|
|
603
|
+
{ id: 'req-verify', stepType: 'verification', summary: 'Verify the change', acceptance: 'A successful generic check is recorded.' },
|
|
604
|
+
];
|
|
605
|
+
const RETAINED_LEGS = [
|
|
606
|
+
{ id: 'source', hooks: path.join(ROOT, 'hooks', 'scripts'), kernel: path.join(ROOT, 'harness-everything', 'scripts', 'kernel-router.js') },
|
|
607
|
+
{ id: 'packaged', hooks: path.join(ROOT, 'plugins', 'harness-everything', 'hooks', 'scripts'), kernel: path.join(ROOT, 'plugins', 'harness-everything', 'skills', 'harness-everything', 'scripts', 'kernel-router.js') },
|
|
608
|
+
];
|
|
609
|
+
let retainedSequence = 0;
|
|
610
|
+
|
|
611
|
+
function retainedCase(leg, label) {
|
|
612
|
+
retainedSequence++;
|
|
613
|
+
const workspace = path.join(temp, `retained-${leg.id}-${label}-${retainedSequence}`);
|
|
614
|
+
const stateHome = path.join(temp, `retained-state-${leg.id}-${label}-${retainedSequence}`);
|
|
615
|
+
initRepo(workspace);
|
|
616
|
+
writeJson(path.join(workspace, 'package.json'), packageScript({ test: 'node -e "process.exit(0)"' }));
|
|
617
|
+
return { leg, workspace, stateHome, sessionId: `retained-${leg.id}-${label}-${retainedSequence}` };
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function retainedEnv(testCase) {
|
|
621
|
+
const env = { ...process.env };
|
|
622
|
+
for (const key of Object.keys(env)) if (key.startsWith('HARNESS_')) delete env[key];
|
|
623
|
+
delete env.CLAUDE_PLUGIN_ROOT;
|
|
624
|
+
delete env.PLUGIN_ROOT;
|
|
625
|
+
delete env.NODE_OPTIONS;
|
|
626
|
+
env.HARNESS_STATE_HOME = testCase.stateHome;
|
|
627
|
+
env.HARNESS_WORKSPACE_ROOT = testCase.workspace;
|
|
628
|
+
env.HARNESS_SKIP_PROJECT_CHECKS = '';
|
|
629
|
+
return env;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function retainedRun(testCase, script, args = [], payload) {
|
|
633
|
+
const result = spawnSync(process.execPath, [script, ...args], {
|
|
634
|
+
cwd: testCase.workspace,
|
|
635
|
+
encoding: 'utf8',
|
|
636
|
+
env: retainedEnv(testCase),
|
|
637
|
+
input: payload === undefined ? undefined : JSON.stringify(payload),
|
|
638
|
+
timeout: 60000,
|
|
639
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
640
|
+
});
|
|
641
|
+
if (result.error) throw result.error;
|
|
642
|
+
return result;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function retainedExpectZero(result, label) {
|
|
646
|
+
assert.strictEqual(result.status, 0, `${label}: exit=${result.status}\nstdout=${result.stdout}\nstderr=${result.stderr}`);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
function retainedSessionDir(testCase) {
|
|
650
|
+
return path.join(testCase.stateHome, 'workspaces', getWorkspaceKey(testCase.workspace), 'state', 'sessions', testCase.sessionId);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
function retainedWorkflowFile(testCase) { return path.join(retainedSessionDir(testCase), 'workflow-run.json'); }
|
|
654
|
+
function retainedHandoffFile(testCase) { return path.join(retainedSessionDir(testCase), 'handoff-state.json'); }
|
|
655
|
+
function retainedReadJson(file) { return JSON.parse(fs.readFileSync(file, 'utf8')); }
|
|
656
|
+
|
|
657
|
+
function retainedController(testCase, args) {
|
|
658
|
+
const result = retainedRun(testCase, path.join(testCase.leg.hooks, 'workflow-disposition.js'), args);
|
|
659
|
+
retainedExpectZero(result, `workflow-disposition ${args[0]}`);
|
|
660
|
+
return result;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
function retainedRouteAndPlan(testCase) {
|
|
664
|
+
retainedExpectZero(retainedRun(testCase, testCase.leg.kernel, [], {
|
|
665
|
+
session_id: testCase.sessionId,
|
|
666
|
+
cwd: testCase.workspace,
|
|
667
|
+
prompt: 'Fix this checkout bug and add a regression test.',
|
|
668
|
+
}), 'kernel route');
|
|
669
|
+
retainedController(testCase, [
|
|
670
|
+
'plan', '--session-id', testCase.sessionId,
|
|
671
|
+
'--requirements-json', JSON.stringify(RETAINED_REQUIREMENTS),
|
|
672
|
+
'--strategy', 'iterative-single', '--evidence', 'two dependent code and verification requirements',
|
|
673
|
+
]);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
function retainedPassStep(testCase, stepId, bindingId) {
|
|
677
|
+
retainedController(testCase, [
|
|
678
|
+
'binding', '--session-id', testCase.sessionId, '--step-id', stepId,
|
|
679
|
+
'--binding-id', bindingId, '--disposition', 'loaded', '--evidence', 'the required step binding is available',
|
|
680
|
+
]);
|
|
681
|
+
return retainedController(testCase, [
|
|
682
|
+
'step', '--session-id', testCase.sessionId, '--step-id', stepId,
|
|
683
|
+
'--disposition', 'pass', '--evidence', 'the requirement acceptance condition is met',
|
|
684
|
+
]);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
function retainedStart(testCase) {
|
|
688
|
+
retainedController(testCase, ['start', '--session-id', testCase.sessionId]);
|
|
689
|
+
retainedPassStep(testCase, 'req-change', 'tdd');
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
function retainedHook(testCase, name, payload) {
|
|
693
|
+
return retainedRun(testCase, path.join(testCase.leg.hooks, name), [], payload);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
function retainedVerifyPayload(testCase, failed = false) {
|
|
697
|
+
return {
|
|
698
|
+
session_id: testCase.sessionId,
|
|
699
|
+
cwd: testCase.workspace,
|
|
700
|
+
hook_event_name: failed ? 'PostToolUseFailure' : 'PostToolUse',
|
|
701
|
+
tool_name: 'Bash',
|
|
702
|
+
tool_input: { command: 'npm test' },
|
|
703
|
+
tool_response: failed ? { stdout: '', stderr: 'fixture failure' } : { stdout: 'ok', stderr: '' },
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
function retainedMarkWorkspaceEdit(testCase) {
|
|
708
|
+
const file = path.join(testCase.workspace, 'README.md');
|
|
709
|
+
fs.appendFileSync(file, 'edited after baseline\n', 'utf8');
|
|
710
|
+
retainedExpectZero(retainedHook(testCase, 'state-persist.js', {
|
|
711
|
+
session_id: testCase.sessionId, cwd: testCase.workspace,
|
|
712
|
+
hook_event_name: 'PostToolUse', tool_name: 'Edit',
|
|
713
|
+
tool_input: { file_path: file }, tool_response: { stdout: '' },
|
|
714
|
+
}), 'record in-workspace edit');
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
function retainedExternalRuntimeEdit(testCase) {
|
|
718
|
+
const runtimeFile = path.join(temp, `runtime-${testCase.sessionId}.js`);
|
|
719
|
+
fs.writeFileSync(runtimeFile, 'module.exports = 1;\n', 'utf8');
|
|
720
|
+
fs.writeFileSync(runtimeFile, 'module.exports = 2;\n', 'utf8');
|
|
721
|
+
retainedExpectZero(retainedHook(testCase, 'state-persist.js', {
|
|
722
|
+
session_id: testCase.sessionId, cwd: testCase.workspace,
|
|
723
|
+
hook_event_name: 'PostToolUse', tool_name: 'Edit',
|
|
724
|
+
tool_input: { file_path: runtimeFile }, tool_response: { stdout: '' },
|
|
725
|
+
}), 'record external runtime edit');
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
function retainedSnapshot(directory) {
|
|
729
|
+
const files = [];
|
|
730
|
+
function walk(current) {
|
|
731
|
+
for (const entry of fs.readdirSync(current, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
732
|
+
const file = path.join(current, entry.name);
|
|
733
|
+
if (entry.isDirectory()) walk(file);
|
|
734
|
+
else if (entry.isFile()) files.push({
|
|
735
|
+
path: path.relative(directory, file).replace(/\\/g, '/'),
|
|
736
|
+
digest: crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex'),
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
walk(directory);
|
|
741
|
+
return files;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
function retainedDigestControl() {
|
|
745
|
+
const directory = path.join(temp, 'retained-digest-control');
|
|
746
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
747
|
+
const file = path.join(directory, 'handoff-state.json');
|
|
748
|
+
fs.writeFileSync(file, '{"lastVerifyAt":1}\n', 'utf8');
|
|
749
|
+
const before = retainedSnapshot(directory);
|
|
750
|
+
fs.appendFileSync(file, '{"lastVerifyAt":2}\n', 'utf8');
|
|
751
|
+
const after = retainedSnapshot(directory);
|
|
752
|
+
return before.map(item => item.path).join() === after.map(item => item.path).join()
|
|
753
|
+
&& before[0].digest !== after[0].digest;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
function runRetainedCaptureOnlyControl(leg) {
|
|
757
|
+
const testCase = retainedCase(leg, 'capture-only');
|
|
758
|
+
retainedRouteAndPlan(testCase);
|
|
759
|
+
retainedExpectZero(retainedHook(testCase, 'state-persist.js', retainedVerifyPayload(testCase)), 'seed existing handoff state');
|
|
760
|
+
const before = retainedSnapshot(retainedSessionDir(testCase));
|
|
761
|
+
const events = [
|
|
762
|
+
{ hook_event_name: 'PreToolUse', tool_name: 'Bash', tool_input: { command: 'npm test' } },
|
|
763
|
+
{ hook_event_name: 'PreToolUse', tool_name: 'Task', tool_input: { command: 'task' } },
|
|
764
|
+
{ hook_event_name: 'PreToolUse', tool_name: 'Agent', tool_input: { command: 'agent' } },
|
|
765
|
+
{ hook_event_name: 'PostToolUse', tool_name: 'Task', tool_input: { command: 'task' } },
|
|
766
|
+
{ hook_event_name: 'PostToolUse', tool_name: 'Agent', tool_input: { command: 'agent' } },
|
|
767
|
+
{ hook_event_name: 'SubagentStart', tool_name: 'Agent' },
|
|
768
|
+
{ hook_event_name: 'SubagentStop', tool_name: 'Agent' },
|
|
769
|
+
];
|
|
770
|
+
for (const [index, event] of events.entries()) {
|
|
771
|
+
retainedExpectZero(retainedHook(testCase, 'state-persist.js', {
|
|
772
|
+
...event, session_id: testCase.sessionId, cwd: testCase.workspace, tool_use_id: `capture-${index + 1}`,
|
|
773
|
+
}), `capture-only event ${index + 1}`);
|
|
774
|
+
}
|
|
775
|
+
assert.deepStrictEqual(retainedSnapshot(retainedSessionDir(testCase)), before, 'capture-only callbacks must not add or change state files');
|
|
776
|
+
assert.ok(retainedDigestControl(), 'the positive control detects an in-place write with an unchanged path list');
|
|
777
|
+
console.log(`PASS S1-I2@${leg.id}: capture-only events leave state bytes unchanged; digest control catches in-place writes`);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
function runRetainedGenericVerificationControl(leg) {
|
|
781
|
+
const testCase = retainedCase(leg, 'generic-verification-runtime-drift');
|
|
782
|
+
retainedRouteAndPlan(testCase);
|
|
783
|
+
retainedStart(testCase);
|
|
784
|
+
retainedMarkWorkspaceEdit(testCase);
|
|
785
|
+
retainedExpectZero(retainedHook(testCase, 'state-persist.js', retainedVerifyPayload(testCase, true)), 'failed generic verification event');
|
|
786
|
+
assert.ok(!retainedReadJson(retainedHandoffFile(testCase)).lastVerifyAt, 'failed check must not set lastVerifyAt');
|
|
787
|
+
retainedExpectZero(retainedHook(testCase, 'state-persist.js', retainedVerifyPayload(testCase)), 'successful generic verification event');
|
|
788
|
+
const verified = retainedReadJson(retainedHandoffFile(testCase));
|
|
789
|
+
assert.ok(Number.isFinite(verified.lastVerifyAt), JSON.stringify(verified));
|
|
790
|
+
assert.strictEqual(verified.lastVerifyExitCode, null);
|
|
791
|
+
assert.strictEqual(retainedPassStep(testCase, 'req-verify', 'verification-loop').status, 0);
|
|
792
|
+
console.log(`PASS S8-I2@${leg.id}: verify step passes after failed then successful check`);
|
|
793
|
+
console.log(`PASS S10-I2@${leg.id}: successful generic verification records lastVerifyAt`);
|
|
794
|
+
|
|
795
|
+
retainedExternalRuntimeEdit(testCase);
|
|
796
|
+
const afterRuntimeChange = retainedReadJson(retainedHandoffFile(testCase));
|
|
797
|
+
assert.strictEqual(afterRuntimeChange.lastVerifyAt, verified.lastVerifyAt);
|
|
798
|
+
assert.strictEqual(afterRuntimeChange.lastVerifyExitCode, verified.lastVerifyExitCode);
|
|
799
|
+
console.log(`PASS S7-I1@${leg.id}: runtime-file edit preserves generic verification state`);
|
|
800
|
+
const genericStop = retainedHook(testCase, 'stop-gate.js', {
|
|
801
|
+
session_id: testCase.sessionId, cwd: testCase.workspace, hook_event_name: 'Stop',
|
|
802
|
+
});
|
|
803
|
+
assert.strictEqual(genericStop.status, 0);
|
|
804
|
+
assert.doesNotMatch(String(genericStop.stderr || ''), /Verification Reminder/i, String(genericStop.stderr));
|
|
805
|
+
assert.ok(Number.isFinite(afterRuntimeChange.lastVerifyAt), JSON.stringify(afterRuntimeChange));
|
|
806
|
+
console.log(`PASS S10-I3@${leg.id}: generic verify stays visible and generic Stop quiet after runtime drift`);
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
function runRetainedWorkflowPendingControl(leg) {
|
|
810
|
+
const testCase = retainedCase(leg, 'generic-verification-only');
|
|
811
|
+
retainedRouteAndPlan(testCase);
|
|
812
|
+
retainedStart(testCase);
|
|
813
|
+
retainedMarkWorkspaceEdit(testCase);
|
|
814
|
+
retainedExpectZero(retainedHook(testCase, 'state-persist.js', retainedVerifyPayload(testCase)), 'successful generic verification event');
|
|
815
|
+
retainedExternalRuntimeEdit(testCase);
|
|
816
|
+
const beforeHandoff = fs.readFileSync(retainedHandoffFile(testCase), 'utf8');
|
|
817
|
+
const workflowStop = retainedHook(testCase, 'workflow-stop-gate.js', {
|
|
818
|
+
session_id: testCase.sessionId, cwd: testCase.workspace, hook_event_name: 'Stop',
|
|
819
|
+
});
|
|
820
|
+
assert.strictEqual(workflowStop.status, 0);
|
|
821
|
+
const workflow = retainedReadJson(retainedWorkflowFile(testCase));
|
|
822
|
+
assert.ok(workflow.state === 'running' && (workflow.unresolved || []).includes('step:req-verify:pending'), JSON.stringify(workflow));
|
|
823
|
+
assert.match(String(workflowStop.stderr || ''), /step:req-verify:pending/i, String(workflowStop.stderr));
|
|
824
|
+
const genericStop = retainedHook(testCase, 'stop-gate.js', {
|
|
825
|
+
session_id: testCase.sessionId, cwd: testCase.workspace, hook_event_name: 'Stop',
|
|
826
|
+
});
|
|
827
|
+
assert.strictEqual(genericStop.status, 0);
|
|
828
|
+
assert.doesNotMatch(String(genericStop.stderr || ''), /Verification Reminder/i, String(genericStop.stderr));
|
|
829
|
+
assert.strictEqual(fs.readFileSync(retainedHandoffFile(testCase), 'utf8'), beforeHandoff);
|
|
830
|
+
console.log(`PASS S11-I1@${leg.id}: generic verify leaves req-verify pending while generic Stop stays quiet`);
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
function runRetainedF4Controls() {
|
|
834
|
+
for (const leg of RETAINED_LEGS) {
|
|
835
|
+
runRetainedCaptureOnlyControl(leg);
|
|
836
|
+
runRetainedGenericVerificationControl(leg);
|
|
837
|
+
runRetainedWorkflowPendingControl(leg);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
runRetainedF4Controls();
|
|
842
|
+
|
|
597
843
|
console.log('Issue #242 verification contract: taxonomy, discovery, execution safety, multi-root scope, hook recognition, and Stop evidence verified.');
|
|
598
844
|
console.log('Issue #306 host cwd wrapper: validated prelude recognition, negative chaining/injection/out-of-root cases, contract governance, canonical/packaged parity, and hook-to-Stop replay verified.');
|
|
599
845
|
} finally {
|
|
@@ -27,8 +27,8 @@ function mustRun(command, args, cwd, env, input) {
|
|
|
27
27
|
return result;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
function startContext(runtimeRoot, packaged
|
|
31
|
-
const label =
|
|
30
|
+
function startContext(runtimeRoot, packaged) {
|
|
31
|
+
const label = packaged ? 'packaged' : 'source';
|
|
32
32
|
const repo = path.join(tempRoot, label, 'repo');
|
|
33
33
|
const stateHome = path.join(tempRoot, label, 'state');
|
|
34
34
|
const fakeHome = path.join(tempRoot, label, 'home');
|
|
@@ -38,7 +38,6 @@ function startContext(runtimeRoot, packaged, pilot) {
|
|
|
38
38
|
const env = {
|
|
39
39
|
HARNESS_STATE_HOME: stateHome,
|
|
40
40
|
HARNESS_WORKSPACE_ROOT: repo,
|
|
41
|
-
HARNESS_DOC_RECONCILIATION_PILOT: pilot ? '1' : '0',
|
|
42
41
|
HARNESS_365_EVIDENCE: 'expanded',
|
|
43
42
|
HOME: fakeHome,
|
|
44
43
|
USERPROFILE: fakeHome,
|
|
@@ -258,8 +257,8 @@ function nonStepEscapeControl(context, runtimeRoot, packaged) {
|
|
|
258
257
|
context.label + ': non-step operation leaves unresolved Fable evidence visible');
|
|
259
258
|
}
|
|
260
259
|
|
|
261
|
-
function checkTrace(runtimeRoot, packaged
|
|
262
|
-
const context = startContext(runtimeRoot, packaged
|
|
260
|
+
function checkTrace(runtimeRoot, packaged) {
|
|
261
|
+
const context = startContext(runtimeRoot, packaged);
|
|
263
262
|
const first = verifyFresh(context, runtimeRoot, 'initial-edit');
|
|
264
263
|
|
|
265
264
|
const readOnly = shell(context, 'git status --short');
|
|
@@ -387,7 +386,7 @@ function checkTrace(runtimeRoot, packaged, pilot) {
|
|
|
387
386
|
try {
|
|
388
387
|
for (const packaged of [false, true]) {
|
|
389
388
|
const runtimeRoot = packaged ? path.join(ROOT, 'plugins/harness-everything') : ROOT;
|
|
390
|
-
|
|
389
|
+
checkTrace(runtimeRoot, packaged);
|
|
391
390
|
}
|
|
392
391
|
console.log('PASS #365 step edit-accounting mechanism test');
|
|
393
392
|
} finally {
|
|
@@ -97,35 +97,5 @@ for (const [legIndex, dir] of LEGS.entries()) {
|
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
|
|
101
|
-
// #383 F1: the doc-reconciliation core mirrors the ** branch; each copy must match line terminators too.
|
|
102
|
-
const CORE_LEGS = [
|
|
103
|
-
path.join(ROOT, 'hooks', 'scripts', 'lib', 'doc-reconciliation-core.js'),
|
|
104
|
-
path.join(ROOT, 'plugins', 'harness-everything', 'hooks', 'scripts', 'lib', 'doc-reconciliation-core.js')
|
|
105
|
-
];
|
|
106
|
-
const binaryRecord = relative => ({ presence: 'present', path: relative, type: 'file', mode: '100644', storedBytes: Buffer.from([0xff, 0xfe, 0x41]) });
|
|
107
|
-
for (const [legIndex, corePath] of CORE_LEGS.entries()) {
|
|
108
|
-
const leg = legIndex === 0 ? 'source' : 'packaged';
|
|
109
|
-
const { deriveFiles, semanticRelevance } = require(corePath)._internals;
|
|
110
|
-
const config = { governed: [{ path: 'docs/**/*.md', role: 'reference' }] };
|
|
111
|
-
for (const terminator of ['\n', '\r', '
', '
']) {
|
|
112
|
-
const relative = `docs/a${terminator}b/file.md`;
|
|
113
|
-
check(`${leg}/doc-reconciliation-core: ${JSON.stringify(terminator)} is governed by docs/**/*.md`, () => {
|
|
114
|
-
assert.strictEqual(semanticRelevance(relative, config), 'document', JSON.stringify(relative));
|
|
115
|
-
});
|
|
116
|
-
check(`${leg}/doc-reconciliation-core: ${JSON.stringify(terminator)} undecodable record fails closed`, () => {
|
|
117
|
-
assert.throws(() => deriveFiles([binaryRecord(relative)], config), error => error.code === 'inventory-unsupported');
|
|
118
|
-
});
|
|
119
|
-
check(`${leg}/doc-reconciliation-core: ${JSON.stringify(terminator)} negative control (ungoverned path) is not fail-closed`, () => {
|
|
120
|
-
const other = `other/a${terminator}b/file.md`;
|
|
121
|
-
assert.strictEqual(semanticRelevance(other, config), null, JSON.stringify(other));
|
|
122
|
-
assert.deepStrictEqual(deriveFiles([binaryRecord(other)], config), {});
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
check(`${leg}/doc-reconciliation-core: positive control docs/ab/file.md fails closed`, () => {
|
|
126
|
-
assert.strictEqual(semanticRelevance('docs/ab/file.md', config), 'document');
|
|
127
|
-
assert.throws(() => deriveFiles([binaryRecord('docs/ab/file.md')], config), error => error.code === 'inventory-unsupported');
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
100
|
console.log(`${checks} checks passed; ${failures} failed`);
|
|
131
101
|
process.exitCode = failures ? 1 : 0;
|
|
@@ -1183,17 +1183,26 @@ test('V2 consumers β1: failed next-prompt identity cannot reuse the previous wo
|
|
|
1183
1183
|
await f.sessionHooks.get('prompt')({ sessionID, messageID: 'user-turn-a', prompt: { text: 'first turn in A' } });
|
|
1184
1184
|
await sendEdit(f, sessionID, 'turn-a-edit');
|
|
1185
1185
|
const editFile = editStateArtifact(f.workspace, sessionID);
|
|
1186
|
-
const
|
|
1186
|
+
const complianceFile = path.join(stateDir(f.workspace, sessionID), 'compliance.json');
|
|
1187
|
+
const routerFile = routerArtifact(f.workspace, sessionID);
|
|
1187
1188
|
const observationFile = path.join(f.store, 'sessions', `${observations.sha(sessionID, 32)}.json`);
|
|
1188
1189
|
const serverEnforcementFiles = [
|
|
1189
1190
|
editStateArtifact(serverWorkspace, sessionID),
|
|
1190
1191
|
path.join(stateDir(serverWorkspace, sessionID), 'compliance.json'),
|
|
1191
|
-
path.join(stateDir(serverWorkspace, sessionID), 'opencode-captures.jsonl'),
|
|
1192
1192
|
];
|
|
1193
|
+
assert.deepEqual({
|
|
1194
|
+
editRevision: readJson(editFile).editRevision,
|
|
1195
|
+
totalEdits: readJson(complianceFile).totalEdits,
|
|
1196
|
+
observationCwd: readJson(observationFile).pending?.cwd,
|
|
1197
|
+
}, {
|
|
1198
|
+
editRevision: 1,
|
|
1199
|
+
totalEdits: 1,
|
|
1200
|
+
observationCwd: observations.sha(f.workspace, 16),
|
|
1201
|
+
}, 'valid first-turn binding writes surviving edit, compliance and observation state in workspace A');
|
|
1193
1202
|
const before = {
|
|
1194
1203
|
edit: fs.readFileSync(editFile, 'utf8'),
|
|
1195
|
-
compliance: fs.readFileSync(
|
|
1196
|
-
|
|
1204
|
+
compliance: fs.readFileSync(complianceFile, 'utf8'),
|
|
1205
|
+
router: fs.readFileSync(routerFile, 'utf8'),
|
|
1197
1206
|
observation: fs.readFileSync(observationFile, 'utf8'),
|
|
1198
1207
|
};
|
|
1199
1208
|
|
|
@@ -1201,21 +1210,28 @@ test('V2 consumers β1: failed next-prompt identity cannot reuse the previous wo
|
|
|
1201
1210
|
const context = { sessionID, kind: 'primary', system: [], messages: [] };
|
|
1202
1211
|
await f.sessionHooks.get('context')(context);
|
|
1203
1212
|
await sendEdit(f, sessionID, 'turn-b-edit');
|
|
1204
|
-
f.push(v2Event('session.execution.succeeded', sessionID));
|
|
1213
|
+
await f.push(v2Event('session.execution.succeeded', sessionID));
|
|
1205
1214
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
1206
1215
|
|
|
1207
1216
|
const actual = {
|
|
1208
1217
|
noStaleContext: context.system.length === 0,
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1218
|
+
workspaceAEditUnchanged: fs.readFileSync(editFile, 'utf8') === before.edit,
|
|
1219
|
+
workspaceAComplianceUnchanged: fs.readFileSync(complianceFile, 'utf8') === before.compliance,
|
|
1220
|
+
workspaceARouterUnchanged: fs.readFileSync(routerFile, 'utf8') === before.router,
|
|
1212
1221
|
noStaleObservation: fs.readFileSync(observationFile, 'utf8') === before.observation,
|
|
1222
|
+
noCompletedObservation: recordList(f.store).length === 0,
|
|
1213
1223
|
noServerEnforcementState: serverEnforcementFiles.every(file => !fs.existsSync(file)),
|
|
1214
1224
|
noServerWorkspaceState: !fs.existsSync(routerArtifact(serverWorkspace, sessionID)),
|
|
1215
1225
|
};
|
|
1216
1226
|
assert.deepEqual(actual, {
|
|
1217
|
-
noStaleContext: true,
|
|
1218
|
-
|
|
1227
|
+
noStaleContext: true,
|
|
1228
|
+
workspaceAEditUnchanged: true,
|
|
1229
|
+
workspaceAComplianceUnchanged: true,
|
|
1230
|
+
workspaceARouterUnchanged: true,
|
|
1231
|
+
noStaleObservation: true,
|
|
1232
|
+
noCompletedObservation: true,
|
|
1233
|
+
noServerEnforcementState: true,
|
|
1234
|
+
noServerWorkspaceState: true,
|
|
1219
1235
|
}, `failed P2 identity must skip workspace-dependent work; actual=${JSON.stringify(actual)}`);
|
|
1220
1236
|
} finally {
|
|
1221
1237
|
if (dispose) await dispose();
|
|
@@ -1244,23 +1260,35 @@ test('V2 consumers β1 control: a resolved next prompt binds tools only to works
|
|
|
1244
1260
|
await f.sessionHooks.get('prompt')({ sessionID, messageID: 'resolved-turn-a', prompt: { text: 'first turn in A' } });
|
|
1245
1261
|
await sendEdit(f, sessionID, 'resolved-turn-a-edit');
|
|
1246
1262
|
const editA = editStateArtifact(f.workspace, sessionID);
|
|
1263
|
+
const complianceA = path.join(stateDir(f.workspace, sessionID), 'compliance.json');
|
|
1247
1264
|
const beforeA = fs.readFileSync(editA, 'utf8');
|
|
1265
|
+
const beforeComplianceA = fs.readFileSync(complianceA, 'utf8');
|
|
1248
1266
|
|
|
1249
1267
|
await f.sessionHooks.get('prompt')({ sessionID, messageID: 'resolved-turn-b', prompt: { text: 'second turn in B' } });
|
|
1250
1268
|
await sendEdit(f, sessionID, 'resolved-turn-b-edit');
|
|
1251
1269
|
const pendingFile = path.join(f.store, 'sessions', `${observations.sha(sessionID, 32)}.json`);
|
|
1270
|
+
const serverEnforcementFiles = [
|
|
1271
|
+
editStateArtifact(serverWorkspace, sessionID),
|
|
1272
|
+
path.join(stateDir(serverWorkspace, sessionID), 'compliance.json'),
|
|
1273
|
+
];
|
|
1252
1274
|
const actual = {
|
|
1253
1275
|
workspaceAUnchanged: fs.readFileSync(editA, 'utf8') === beforeA,
|
|
1276
|
+
workspaceAComplianceUnchanged: fs.readFileSync(complianceA, 'utf8') === beforeComplianceA,
|
|
1254
1277
|
workspaceBRevision: readJson(editStateArtifact(workspaceB, sessionID)).editRevision,
|
|
1278
|
+
workspaceBTotalEdits: readJson(path.join(stateDir(workspaceB, sessionID), 'compliance.json')).totalEdits,
|
|
1255
1279
|
observationCwd: readJson(pendingFile).pending.cwd,
|
|
1256
1280
|
expectedObservationCwd: observations.sha(workspaceB, 16),
|
|
1281
|
+
noServerEnforcementState: serverEnforcementFiles.every(file => !fs.existsSync(file)),
|
|
1257
1282
|
noServerWorkspaceState: !fs.existsSync(routerArtifact(serverWorkspace, sessionID)),
|
|
1258
1283
|
};
|
|
1259
1284
|
assert.deepEqual(actual, {
|
|
1260
1285
|
workspaceAUnchanged: true,
|
|
1286
|
+
workspaceAComplianceUnchanged: true,
|
|
1261
1287
|
workspaceBRevision: 1,
|
|
1288
|
+
workspaceBTotalEdits: 1,
|
|
1262
1289
|
observationCwd: observations.sha(workspaceB, 16),
|
|
1263
1290
|
expectedObservationCwd: observations.sha(workspaceB, 16),
|
|
1291
|
+
noServerEnforcementState: true,
|
|
1264
1292
|
noServerWorkspaceState: true,
|
|
1265
1293
|
}, `resolved P2 identity binds only to B; actual=${JSON.stringify(actual)}`);
|
|
1266
1294
|
} finally {
|
|
@@ -1271,7 +1299,7 @@ test('V2 consumers β1 control: a resolved next prompt binds tools only to works
|
|
|
1271
1299
|
});
|
|
1272
1300
|
|
|
1273
1301
|
test('V2 consumers β2: a pending identity makes prior-turn tool events safely skip', { concurrency: false }, async () => {
|
|
1274
|
-
const f = fixture(
|
|
1302
|
+
const f = fixture();
|
|
1275
1303
|
const sessionID = 'pending-next-prompt';
|
|
1276
1304
|
const serverWorkspace = makeWorkspace(f, 'pending-server-c');
|
|
1277
1305
|
const originalCwd = process.cwd();
|
|
@@ -1293,20 +1321,125 @@ test('V2 consumers β2: a pending identity makes prior-turn tool events safely s
|
|
|
1293
1321
|
await f.sessionHooks.get('prompt')({ sessionID, messageID: 'user-turn-a', prompt: { text: 'first turn in A' } });
|
|
1294
1322
|
await sendEdit(f, sessionID, 'pending-turn-a-edit');
|
|
1295
1323
|
const editFile = editStateArtifact(f.workspace, sessionID);
|
|
1296
|
-
const
|
|
1297
|
-
const
|
|
1298
|
-
const
|
|
1324
|
+
const complianceFile = path.join(stateDir(f.workspace, sessionID), 'compliance.json');
|
|
1325
|
+
const routerFile = routerArtifact(f.workspace, sessionID);
|
|
1326
|
+
const observationFile = path.join(f.store, 'sessions', `${observations.sha(sessionID, 32)}.json`);
|
|
1327
|
+
const serverEnforcementFiles = [
|
|
1328
|
+
editStateArtifact(serverWorkspace, sessionID),
|
|
1329
|
+
path.join(stateDir(serverWorkspace, sessionID), 'compliance.json'),
|
|
1330
|
+
];
|
|
1331
|
+
assert.deepEqual({
|
|
1332
|
+
editRevision: readJson(editFile).editRevision,
|
|
1333
|
+
totalEdits: readJson(complianceFile).totalEdits,
|
|
1334
|
+
observationCwd: readJson(observationFile).pending?.cwd,
|
|
1335
|
+
}, {
|
|
1336
|
+
editRevision: 1,
|
|
1337
|
+
totalEdits: 1,
|
|
1338
|
+
observationCwd: observations.sha(f.workspace, 16),
|
|
1339
|
+
}, 'valid first-turn binding writes surviving edit, compliance and observation state in workspace A');
|
|
1340
|
+
const before = {
|
|
1341
|
+
edit: fs.readFileSync(editFile, 'utf8'),
|
|
1342
|
+
compliance: fs.readFileSync(complianceFile, 'utf8'),
|
|
1343
|
+
router: fs.readFileSync(routerFile, 'utf8'),
|
|
1344
|
+
observation: fs.readFileSync(observationFile, 'utf8'),
|
|
1345
|
+
};
|
|
1299
1346
|
|
|
1300
1347
|
pendingPrompt = f.sessionHooks.get('prompt')({ sessionID, messageID: 'user-turn-b', prompt: { text: 'identity remains pending' } });
|
|
1301
1348
|
assert.equal(await waitUntil(() => lookupStarted), true, 'P2 lookup is pending');
|
|
1302
1349
|
await sendEdit(f, sessionID, 'ambiguous-assistant-tool');
|
|
1350
|
+
await f.push(v2Event('session.execution.succeeded', sessionID));
|
|
1351
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
1352
|
+
const actual = {
|
|
1353
|
+
workspaceAEditUnchanged: fs.readFileSync(editFile, 'utf8') === before.edit,
|
|
1354
|
+
workspaceAComplianceUnchanged: fs.readFileSync(complianceFile, 'utf8') === before.compliance,
|
|
1355
|
+
workspaceARouterUnchanged: fs.readFileSync(routerFile, 'utf8') === before.router,
|
|
1356
|
+
noStaleObservation: fs.readFileSync(observationFile, 'utf8') === before.observation,
|
|
1357
|
+
noCompletedObservation: recordList(f.store).length === 0,
|
|
1358
|
+
noServerEnforcementState: serverEnforcementFiles.every(file => !fs.existsSync(file)),
|
|
1359
|
+
noServerWorkspaceState: !fs.existsSync(routerArtifact(serverWorkspace, sessionID)),
|
|
1360
|
+
};
|
|
1361
|
+
assert.deepEqual(actual, {
|
|
1362
|
+
workspaceAEditUnchanged: true,
|
|
1363
|
+
workspaceAComplianceUnchanged: true,
|
|
1364
|
+
workspaceARouterUnchanged: true,
|
|
1365
|
+
noStaleObservation: true,
|
|
1366
|
+
noCompletedObservation: true,
|
|
1367
|
+
noServerEnforcementState: true,
|
|
1368
|
+
noServerWorkspaceState: true,
|
|
1369
|
+
}, `an uncorrelated tool or completion event cannot select the old binding while identity is pending; actual=${JSON.stringify(actual)}`);
|
|
1370
|
+
} finally {
|
|
1371
|
+
if (resolvePending) resolvePending({});
|
|
1372
|
+
if (pendingPrompt) await pendingPrompt;
|
|
1373
|
+
if (dispose) await dispose();
|
|
1374
|
+
process.chdir(originalCwd);
|
|
1375
|
+
f.restore();
|
|
1376
|
+
}
|
|
1377
|
+
});
|
|
1378
|
+
|
|
1379
|
+
test('V2 consumers β2 control: once a pending identity resolves to workspace B, surviving state writes there only', { concurrency: false }, async () => {
|
|
1380
|
+
const f = fixture();
|
|
1381
|
+
const sessionID = 'pending-then-resolved';
|
|
1382
|
+
const workspaceB = makeWorkspace(f, 'pending-session-b');
|
|
1383
|
+
const serverWorkspace = makeWorkspace(f, 'pending-control-server-c');
|
|
1384
|
+
const originalCwd = process.cwd();
|
|
1385
|
+
let lookupCount = 0;
|
|
1386
|
+
let resolvePending;
|
|
1387
|
+
let lookupStarted = false;
|
|
1388
|
+
f.ctx.location = undefined;
|
|
1389
|
+
f.ctx.directory = undefined;
|
|
1390
|
+
f.setSessionLookup(async () => {
|
|
1391
|
+
lookupCount++;
|
|
1392
|
+
if (lookupCount === 1) return { id: sessionID, location: { directory: f.workspace } };
|
|
1393
|
+
return new Promise(resolve => { resolvePending = resolve; lookupStarted = true; });
|
|
1394
|
+
});
|
|
1395
|
+
process.chdir(serverWorkspace);
|
|
1396
|
+
let dispose;
|
|
1397
|
+
let pendingPrompt;
|
|
1398
|
+
try {
|
|
1399
|
+
dispose = await install(f);
|
|
1400
|
+
await f.sessionHooks.get('prompt')({ sessionID, messageID: 'pending-ctrl-turn-a', prompt: { text: 'first turn in A' } });
|
|
1401
|
+
await sendEdit(f, sessionID, 'pending-ctrl-turn-a-edit');
|
|
1402
|
+
const editA = editStateArtifact(f.workspace, sessionID);
|
|
1403
|
+
const complianceA = path.join(stateDir(f.workspace, sessionID), 'compliance.json');
|
|
1404
|
+
const observationFile = path.join(f.store, 'sessions', `${observations.sha(sessionID, 32)}.json`);
|
|
1405
|
+
const beforeEditA = fs.readFileSync(editA, 'utf8');
|
|
1406
|
+
const beforeComplianceA = fs.readFileSync(complianceA, 'utf8');
|
|
1407
|
+
|
|
1408
|
+
pendingPrompt = f.sessionHooks.get('prompt')({ sessionID, messageID: 'pending-ctrl-turn-b', prompt: { text: 'second turn resolves to B' } });
|
|
1409
|
+
assert.equal(await waitUntil(() => lookupStarted), true, 'P2 lookup is pending');
|
|
1410
|
+
await sendEdit(f, sessionID, 'pending-ctrl-skipped-edit');
|
|
1411
|
+
assert.equal(fs.readFileSync(editA, 'utf8'), beforeEditA, 'pending edit does not mutate workspace A');
|
|
1412
|
+
assert.equal(fs.existsSync(editStateArtifact(workspaceB, sessionID)), false, 'pending edit does not pre-create workspace B');
|
|
1413
|
+
|
|
1414
|
+
resolvePending({ id: sessionID, location: { directory: workspaceB } });
|
|
1415
|
+
await pendingPrompt;
|
|
1416
|
+
pendingPrompt = null;
|
|
1417
|
+
await sendEdit(f, sessionID, 'pending-ctrl-turn-b-edit');
|
|
1418
|
+
|
|
1419
|
+
const serverEnforcementFiles = [
|
|
1420
|
+
editStateArtifact(serverWorkspace, sessionID),
|
|
1421
|
+
path.join(stateDir(serverWorkspace, sessionID), 'compliance.json'),
|
|
1422
|
+
];
|
|
1303
1423
|
const actual = {
|
|
1304
|
-
|
|
1305
|
-
|
|
1424
|
+
workspaceAEditUnchanged: fs.readFileSync(editA, 'utf8') === beforeEditA,
|
|
1425
|
+
workspaceAComplianceUnchanged: fs.readFileSync(complianceA, 'utf8') === beforeComplianceA,
|
|
1426
|
+
workspaceBRevision: readJson(editStateArtifact(workspaceB, sessionID)).editRevision,
|
|
1427
|
+
workspaceBTotalEdits: readJson(path.join(stateDir(workspaceB, sessionID), 'compliance.json')).totalEdits,
|
|
1428
|
+
observationCwd: readJson(observationFile).pending.cwd,
|
|
1429
|
+
expectedObservationCwd: observations.sha(workspaceB, 16),
|
|
1430
|
+
noServerEnforcementState: serverEnforcementFiles.every(file => !fs.existsSync(file)),
|
|
1306
1431
|
noServerWorkspaceState: !fs.existsSync(routerArtifact(serverWorkspace, sessionID)),
|
|
1307
1432
|
};
|
|
1308
|
-
assert.deepEqual(actual, {
|
|
1309
|
-
|
|
1433
|
+
assert.deepEqual(actual, {
|
|
1434
|
+
workspaceAEditUnchanged: true,
|
|
1435
|
+
workspaceAComplianceUnchanged: true,
|
|
1436
|
+
workspaceBRevision: 1,
|
|
1437
|
+
workspaceBTotalEdits: 1,
|
|
1438
|
+
observationCwd: observations.sha(workspaceB, 16),
|
|
1439
|
+
expectedObservationCwd: observations.sha(workspaceB, 16),
|
|
1440
|
+
noServerEnforcementState: true,
|
|
1441
|
+
noServerWorkspaceState: true,
|
|
1442
|
+
}, `resolved pending identity binds surviving state only to B; actual=${JSON.stringify(actual)}`);
|
|
1310
1443
|
} finally {
|
|
1311
1444
|
if (resolvePending) resolvePending({});
|
|
1312
1445
|
if (pendingPrompt) await pendingPrompt;
|