harness-everything 0.58.0 → 1.0.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/AGENTS.md +8 -2
- package/CHANGELOG.md +24 -0
- package/README.md +4 -4
- package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/README.md +40 -0
- package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/edit-state-final.json +11 -0
- package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/events-2026-11-24.jsonl +103 -0
- package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/host-version.txt +3 -0
- package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/live-event-trace-probe.js +11 -0
- package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/plugin-load-lines.txt +2 -0
- package/benchmarks/results/live-host/opencode-2026-11-24-v2-lifecycle/reminder-excerpt.txt +1 -0
- package/ci/doc-capability-consistency.test.js +4 -2
- package/ci/lib/opencode-v2-driver.js +169 -0
- package/ci/mechanism-2n-opencode-plugin.test.js +387 -223
- package/ci/mechanism-2p-opencode-v2-entrypoint.test.js +24 -15
- package/ci/mechanism-2u-issue-42-regressions.test.js +41 -2
- package/ci/mechanism-2w-platform-compatibility.test.js +16 -3
- package/ci/mechanism-30-opencode-plugin-loadability.test.js +78 -45
- package/ci/mechanism-338-opencode-async.test.js +367 -194
- package/ci/mechanism-341-opencode-lane.test.js +143 -183
- package/ci/mechanism-39-opencode-verify-outcomes.test.js +118 -86
- package/ci/mechanism-394-ledger-match.test.js +105 -3
- package/ci/mechanism-394-opencode-ledger-lesson.test.js +46 -97
- package/ci/mechanism-397-opencode-observations.test.js +58 -47
- package/ci/mechanism-453-opencode-v2-driver.test.js +51 -0
- package/ci/mechanism-453-opencode-v2-only-events.test.js +241 -0
- package/ci/mechanism-516-agy-post-tool-exit.test.js +472 -0
- package/ci/mechanism-516-agy-stop-revision.test.js +215 -0
- package/ci/telemetry.test.js +31 -24
- package/docs/architecture.md +4 -2
- package/docs/platform-capabilities.md +60 -26
- package/docs/platform-compatibility.json +8 -6
- package/docs/system-one-observations.md +1 -1
- package/docs/telemetry.md +1 -1
- package/docs/troubleshooting.md +2 -2
- package/hooks/scripts/agy-post-tool.js +79 -16
- package/hooks/scripts/agy-stop.js +63 -10
- package/hooks/scripts/lib/ledger-match.js +132 -20
- package/hooks/scripts/state-persist.js +7 -1
- package/opencode-plugin/README.md +60 -66
- package/opencode-plugin/index.mjs +11 -13
- 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/agy-post-tool.js +79 -16
- package/plugins/harness-everything/hooks/scripts/agy-stop.js +63 -10
- package/plugins/harness-everything/hooks/scripts/lib/ledger-match.js +132 -20
- package/plugins/harness-everything/hooks/scripts/state-persist.js +7 -1
- package/plugins/harness-everything/plugin.json +1 -1
- package/plugins/harness-everything/rules/AGENTS.md +8 -2
- package/sbom.cdx.json +12 -12
|
@@ -246,12 +246,6 @@ async function sendEdit(f, sessionID, id) {
|
|
|
246
246
|
await f.toolHooks.get('execute.after')({ ...event, status: 'completed', result: {} });
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
function completionEvent(kind, sessionID) {
|
|
250
|
-
return kind === 'idle'
|
|
251
|
-
? { type: 'session.idle', sessionID }
|
|
252
|
-
: v2Event('session.execution.succeeded', sessionID);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
249
|
test('inject: the documented OpenCode hooks deliver the kernel router output and exact label line', { concurrency: false }, async () => {
|
|
256
250
|
const f = fixture();
|
|
257
251
|
let dispose;
|
|
@@ -383,7 +377,7 @@ test('record: OpenCode prompt, tool and idle events append one host-tagged recor
|
|
|
383
377
|
await f.toolHooks.get('execute.after')({
|
|
384
378
|
status: 'completed', tool: 'edit', sessionID: 'record-session', id: 'call-1', input: { filePath: 'changed.js' }, result: {},
|
|
385
379
|
});
|
|
386
|
-
f.push(
|
|
380
|
+
f.push(v2Event('session.execution.succeeded', 'record-session'));
|
|
387
381
|
await waitFor(() => recordList(f.store).length === 1);
|
|
388
382
|
const [record] = recordList(f.store);
|
|
389
383
|
assert.equal(record.host, 'opencode');
|
|
@@ -675,7 +669,7 @@ test('workspace: an unbound session lifecycle event resolves its own workspace b
|
|
|
675
669
|
let dispose;
|
|
676
670
|
try {
|
|
677
671
|
dispose = await install(f);
|
|
678
|
-
f.push(
|
|
672
|
+
f.push(v2Event('session.created', sessionID));
|
|
679
673
|
await waitFor(() => f.sessionLookupCount() === 1 && !fs.existsSync(stateDir));
|
|
680
674
|
assert.equal(fs.existsSync(routerArtifact(f.workspace, sessionID)), false);
|
|
681
675
|
assert.deepEqual(recordList(f.store), []);
|
|
@@ -692,7 +686,7 @@ test('malformed: invalid labels remain null with a reason and export counts are
|
|
|
692
686
|
dispose = await install(f);
|
|
693
687
|
f.setFinal('Done.\n<!-- harness-label {"validity":"valid","tier":3,"skills_used":[]} -->');
|
|
694
688
|
await f.sessionHooks.get('prompt')({ sessionID: 'malformed-opencode', messageID: 'bad-opencode', prompt: { text: 'record an invalid label' } });
|
|
695
|
-
f.push(
|
|
689
|
+
f.push(v2Event('session.execution.succeeded', 'malformed-opencode'));
|
|
696
690
|
await waitFor(() => recordList(f.store).length === 1);
|
|
697
691
|
assert.equal(recordList(f.store)[0].selfReport, null);
|
|
698
692
|
assert.equal(recordList(f.store)[0].selfReportReason, 'label-invalid');
|
|
@@ -728,8 +722,7 @@ test('opt-out: HARNESS_OBSERVATIONS=off disables capture while prompt routing st
|
|
|
728
722
|
const context = { sessionID: 'optout-session', kind: 'primary', system: [], messages: [] };
|
|
729
723
|
await f.sessionHooks.get('context')(context);
|
|
730
724
|
assert.match(context.system.map(part => part.text || '').join('\n'), /=> ROUTER WORKFLOW PLAN/);
|
|
731
|
-
f.push(
|
|
732
|
-
await new Promise(resolve => setTimeout(resolve, 50));
|
|
725
|
+
await f.push(v2Event('session.execution.succeeded', 'optout-session'));
|
|
733
726
|
assert.deepEqual(recordList(f.store), []);
|
|
734
727
|
} finally {
|
|
735
728
|
if (dispose) await dispose();
|
|
@@ -852,28 +845,37 @@ test('control: a V2 turn end without a prompt route records nothing', { concurre
|
|
|
852
845
|
}
|
|
853
846
|
});
|
|
854
847
|
|
|
855
|
-
test('control:
|
|
848
|
+
test('control: repeated V2 session.execution.succeeded events for one turn record it once', { concurrency: false }, async () => {
|
|
856
849
|
const f = fixture();
|
|
857
850
|
let dispose;
|
|
858
851
|
try {
|
|
859
852
|
dispose = await install(f);
|
|
860
853
|
await f.sessionHooks.get('prompt')({ sessionID: 'dedupe', messageID: 'dedupe-1', prompt: { text: 'dedupe the turn end' } });
|
|
861
|
-
f.push(v2Event('session.execution.succeeded', 'dedupe'));
|
|
862
|
-
f.push({
|
|
863
|
-
await
|
|
864
|
-
await
|
|
865
|
-
|
|
866
|
-
|
|
854
|
+
const firstDone = f.push({ ...v2Event('session.execution.succeeded', 'dedupe'), id: 'evt-dedupe-1' });
|
|
855
|
+
const secondDone = f.push({ ...v2Event('session.execution.succeeded', 'dedupe'), id: 'evt-dedupe-2' });
|
|
856
|
+
await Promise.all([firstDone, secondDone]);
|
|
857
|
+
await waitFor(() => recordList(f.store).some(record => record.writer.sessionId === 'dedupe'));
|
|
858
|
+
|
|
859
|
+
// Positive control in the same fixture: a second session completes and
|
|
860
|
+
// flushes the async observation path without duplicating the first turn.
|
|
861
|
+
await f.sessionHooks.get('prompt')({ sessionID: 'dedupe-control', messageID: 'dedupe-control-1', prompt: { text: 'flush the observation path' } });
|
|
862
|
+
await f.push(v2Event('session.execution.succeeded', 'dedupe-control'));
|
|
863
|
+
await waitFor(() => recordList(f.store).some(record => record.writer.sessionId === 'dedupe-control'));
|
|
864
|
+
|
|
865
|
+
const dedupeRecords = recordList(f.store).filter(record => record.writer.sessionId === 'dedupe');
|
|
866
|
+
assert.equal(dedupeRecords.length, 1, 'the same turn must not be recorded twice');
|
|
867
|
+
assert.equal(dedupeRecords[0].selfReportReason, null);
|
|
867
868
|
} finally {
|
|
868
869
|
if (dispose) await dispose();
|
|
869
870
|
f.restore();
|
|
870
871
|
}
|
|
871
872
|
});
|
|
872
873
|
|
|
873
|
-
test('control: the
|
|
874
|
+
test('control: the plugin exports only the V2 default definition with setup and no server', { concurrency: false }, async () => {
|
|
874
875
|
const mod = await import(pathToFileURL(PLUGIN).href);
|
|
875
|
-
assert.
|
|
876
|
+
assert.deepStrictEqual(Object.keys(mod).sort(), ['default']);
|
|
876
877
|
assert.equal(typeof mod.default.setup, 'function');
|
|
878
|
+
assert.equal(Object.hasOwn(mod.default, 'server'), false);
|
|
877
879
|
});
|
|
878
880
|
|
|
879
881
|
test('V2 consumers α1: flat execution.succeeded verifies the edit in its session once', { concurrency: false }, async () => {
|
|
@@ -947,7 +949,7 @@ async function flatLifecycleReset(startType, lifecycleType) {
|
|
|
947
949
|
}
|
|
948
950
|
}
|
|
949
951
|
|
|
950
|
-
for (const startType of ['session.
|
|
952
|
+
for (const startType of ['session.execution.succeeded']) {
|
|
951
953
|
for (const lifecycleType of ['session.created', 'session.deleted']) {
|
|
952
954
|
test(`V2 consumers α2: flat ${startType} check is cancelled by flat ${lifecycleType}`, { concurrency: false }, async () => {
|
|
953
955
|
await flatLifecycleReset(startType, lifecycleType);
|
|
@@ -1071,7 +1073,7 @@ test('V2 consumers α: flat lifecycle and completion events without an id leave
|
|
|
1071
1073
|
}
|
|
1072
1074
|
});
|
|
1073
1075
|
|
|
1074
|
-
test('V2 consumers α3:
|
|
1076
|
+
test('V2 consumers α3: repeated V2 completions and a post-completion duplicate verify one revision once', { concurrency: false }, async () => {
|
|
1075
1077
|
const f = fixture('off');
|
|
1076
1078
|
const sessionID = 'v2-double-completion';
|
|
1077
1079
|
const checkLog = path.join(f.dir, 'check-runs.txt');
|
|
@@ -1079,29 +1081,34 @@ test('V2 consumers α3: both completion orders and a post-completion counterpart
|
|
|
1079
1081
|
let dispose;
|
|
1080
1082
|
try {
|
|
1081
1083
|
dispose = await install(f);
|
|
1082
|
-
const
|
|
1083
|
-
{
|
|
1084
|
-
{
|
|
1085
|
-
{
|
|
1084
|
+
const deliveries = [
|
|
1085
|
+
{ label: 'back-to-back', sequential: false, duplicate: true },
|
|
1086
|
+
{ label: 'post-completion', sequential: true, duplicate: true },
|
|
1087
|
+
{ label: 'next-revision-control', sequential: false, duplicate: false },
|
|
1086
1088
|
];
|
|
1087
|
-
for (let i = 0; i <
|
|
1088
|
-
const
|
|
1089
|
+
for (let i = 0; i < deliveries.length; i++) {
|
|
1090
|
+
const delivery = deliveries[i];
|
|
1089
1091
|
await sendEdit(f, sessionID, `success-edit-${i + 1}`);
|
|
1090
|
-
f.push(
|
|
1091
|
-
if (
|
|
1092
|
+
const first = f.push({ ...v2Event('session.execution.succeeded', sessionID), id: `evt-a3-pass-${i + 1}-a` });
|
|
1093
|
+
if (delivery.sequential) {
|
|
1092
1094
|
const completed = await waitUntil(() => fs.existsSync(checkLog)
|
|
1093
1095
|
&& fs.readFileSync(checkLog, 'utf8').trim().split(/\r?\n/).length === i + 1
|
|
1094
1096
|
&& readJson(editStateArtifact(f.workspace, sessionID)).verificationPending === false);
|
|
1095
1097
|
assert.equal(completed, true, 'the first end notification completed the check');
|
|
1096
|
-
|
|
1098
|
+
await first;
|
|
1099
|
+
await f.push({ ...v2Event('session.execution.succeeded', sessionID), id: `evt-a3-pass-${i + 1}-b` });
|
|
1100
|
+
} else if (delivery.duplicate) {
|
|
1101
|
+
const second = f.push({ ...v2Event('session.execution.succeeded', sessionID), id: `evt-a3-pass-${i + 1}-b` });
|
|
1102
|
+
await Promise.all([first, second]);
|
|
1097
1103
|
} else {
|
|
1098
|
-
|
|
1104
|
+
await first;
|
|
1099
1105
|
}
|
|
1100
|
-
await waitUntil(() => fs.existsSync(checkLog)
|
|
1101
|
-
&& fs.readFileSync(checkLog, 'utf8').trim().split(/\r?\n/).length >= i + 1
|
|
1102
|
-
|
|
1106
|
+
assert.equal(await waitUntil(() => fs.existsSync(checkLog)
|
|
1107
|
+
&& fs.readFileSync(checkLog, 'utf8').trim().split(/\r?\n/).length >= i + 1
|
|
1108
|
+
&& readJson(editStateArtifact(f.workspace, sessionID)).verificationPending === false), true,
|
|
1109
|
+
`delivery ${delivery.label} completed verification`);
|
|
1103
1110
|
assert.equal(fs.readFileSync(checkLog, 'utf8').trim().split(/\r?\n/).length, i + 1,
|
|
1104
|
-
`
|
|
1111
|
+
`delivery ${delivery.label} ran one check`);
|
|
1105
1112
|
assert.equal(readJson(path.join(stateDir(f.workspace, sessionID), 'compliance.json')).verifiedEdits, i + 1,
|
|
1106
1113
|
'compliance advances once for each new edit revision');
|
|
1107
1114
|
assert.equal(readJson(editStateArtifact(f.workspace, sessionID)).editsSinceVerification, 0);
|
|
@@ -1120,21 +1127,25 @@ test('V2 consumers α3: duplicate completion notifications do not duplicate veri
|
|
|
1120
1127
|
let dispose;
|
|
1121
1128
|
try {
|
|
1122
1129
|
dispose = await install(f);
|
|
1123
|
-
const
|
|
1124
|
-
{
|
|
1125
|
-
{
|
|
1126
|
-
{
|
|
1130
|
+
const deliveries = [
|
|
1131
|
+
{ label: 'back-to-back', sequential: false, duplicate: true },
|
|
1132
|
+
{ label: 'post-completion', sequential: true, duplicate: true },
|
|
1133
|
+
{ label: 'next-revision-control', sequential: false, duplicate: false },
|
|
1127
1134
|
];
|
|
1128
|
-
for (let i = 0; i <
|
|
1129
|
-
const
|
|
1135
|
+
for (let i = 0; i < deliveries.length; i++) {
|
|
1136
|
+
const delivery = deliveries[i];
|
|
1130
1137
|
await sendEdit(f, sessionID, `failure-edit-${i + 1}`);
|
|
1131
|
-
f.push(
|
|
1132
|
-
if (
|
|
1138
|
+
const first = f.push({ ...v2Event('session.execution.succeeded', sessionID), id: `evt-a3-fail-${i + 1}-a` });
|
|
1139
|
+
if (delivery.sequential) {
|
|
1133
1140
|
assert.equal(await waitUntil(() => readJson(editStateArtifact(f.workspace, sessionID)).followUpPending === true), true,
|
|
1134
1141
|
'the first end notification delivered its follow-up');
|
|
1135
|
-
|
|
1142
|
+
await first;
|
|
1143
|
+
await f.push({ ...v2Event('session.execution.succeeded', sessionID), id: `evt-a3-fail-${i + 1}-b` });
|
|
1144
|
+
} else if (delivery.duplicate) {
|
|
1145
|
+
const second = f.push({ ...v2Event('session.execution.succeeded', sessionID), id: `evt-a3-fail-${i + 1}-b` });
|
|
1146
|
+
await Promise.all([first, second]);
|
|
1136
1147
|
} else {
|
|
1137
|
-
|
|
1148
|
+
await first;
|
|
1138
1149
|
}
|
|
1139
1150
|
assert.equal(await waitUntil(() => fs.existsSync(editStateArtifact(f.workspace, sessionID))
|
|
1140
1151
|
&& readJson(editStateArtifact(f.workspace, sessionID)).followUpPending === true), true,
|
|
@@ -1357,7 +1368,7 @@ test('V2 consumers β2: a late session lookup cannot resurrect a deleted session
|
|
|
1357
1368
|
pendingPrompt = f.sessionHooks.get('prompt')({ sessionID, messageID: 'user-turn-b', prompt: { text: 'lookup will finish after deletion' } });
|
|
1358
1369
|
assert.equal(await waitUntil(() => lookupStarted), true, 'P2 lookup is pending');
|
|
1359
1370
|
|
|
1360
|
-
f.push(
|
|
1371
|
+
f.push(v2Event('session.deleted', sessionID));
|
|
1361
1372
|
const deleted = await waitUntil(() => !fs.existsSync(routerFile));
|
|
1362
1373
|
assert.equal(deleted, true, 'the known owner binding resets the session without waiting for P2 lookup');
|
|
1363
1374
|
resolvePending({ id: sessionID, location: { directory: f.workspace } });
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { test } = require('node:test');
|
|
4
|
+
const assert = require('node:assert/strict');
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const { createV2Driver } = require('./lib/opencode-v2-driver');
|
|
7
|
+
|
|
8
|
+
const FAILING_TEST = { test: 'node -e "process.exit(1)"' };
|
|
9
|
+
// Optional override so the mutation check can point at a scratch plugin copy.
|
|
10
|
+
const PLUGIN = process.env.OPENCODE_V2_DRIVER_PLUGIN || undefined;
|
|
11
|
+
|
|
12
|
+
async function editCycle(d, sessionID, id) {
|
|
13
|
+
const file = path.join(d.workspace, 'a.js');
|
|
14
|
+
await d.toolHook('execute.before')({ tool: 'edit', sessionID, id: `b-${id}`, input: { filePath: file } });
|
|
15
|
+
await d.toolHook('execute.after')({ tool: 'edit', sessionID, id: `a-${id}`, status: 'completed', input: { filePath: file }, result: {} });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
test('453 row 1: setup captures V2 hooks; teardown disposes them and ends the stream', async () => {
|
|
19
|
+
const d = await createV2Driver({ plugin: PLUGIN, scripts: FAILING_TEST });
|
|
20
|
+
assert.ok(d.toolHook('execute.before') && d.toolHook('execute.after'));
|
|
21
|
+
assert.ok(d.sessionHook('prompt') && d.sessionHook('context'));
|
|
22
|
+
assert.equal(d.subscribeCount(), 1);
|
|
23
|
+
assert.equal(d.eventStreamEnded(), false);
|
|
24
|
+
await d.teardown();
|
|
25
|
+
assert.equal(d.eventStreamEnded(), true);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('453 row 2: edit then session.execution.succeeded delivers the verification reminder', async () => {
|
|
29
|
+
const d = await createV2Driver({ plugin: PLUGIN, scripts: FAILING_TEST });
|
|
30
|
+
try {
|
|
31
|
+
await editCycle(d, 's1', 1);
|
|
32
|
+
d.emit('session.execution.succeeded', 's1');
|
|
33
|
+
await d.waitFor(() => d.prompts.length >= 1, { label: 'verification reminder prompt' });
|
|
34
|
+
assert.equal(d.prompts.length, 1);
|
|
35
|
+
assert.equal(d.prompts[0].sessionID, 's1');
|
|
36
|
+
assert.match(d.prompts[0].text, /verification failed/i);
|
|
37
|
+
} finally {
|
|
38
|
+
await d.teardown();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('453 row 3: session.execution.succeeded without an edit sends no prompt', async () => {
|
|
43
|
+
const d = await createV2Driver({ plugin: PLUGIN, scripts: FAILING_TEST });
|
|
44
|
+
try {
|
|
45
|
+
d.emit('session.execution.succeeded', 's1');
|
|
46
|
+
await d.settled();
|
|
47
|
+
assert.equal(d.prompts.length, 0);
|
|
48
|
+
} finally {
|
|
49
|
+
await d.teardown();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// #453 P2: the OpenCode plugin accepts only V2 event shapes at the
|
|
4
|
+
// ctx.event.subscribe() boundary. Negative rows B-E start with a fresh,
|
|
5
|
+
// unbound session and assert zero ctx.session.get lookups at the pulled-next
|
|
6
|
+
// checkpoint before sending the matching V2 positive control for the same ID.
|
|
7
|
+
|
|
8
|
+
const { test } = require('node:test');
|
|
9
|
+
const assert = require('node:assert/strict');
|
|
10
|
+
const fs = require('node:fs');
|
|
11
|
+
const os = require('node:os');
|
|
12
|
+
const path = require('node:path');
|
|
13
|
+
const { spawnSync } = require('node:child_process');
|
|
14
|
+
const { pathToFileURL } = require('node:url');
|
|
15
|
+
const workspaceState = require('../scripts/lib/workspace');
|
|
16
|
+
const harnessState = require('../hooks/scripts/lib/harness-state');
|
|
17
|
+
|
|
18
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
19
|
+
const PLUGIN = process.env.P453_PLUGIN || path.join(ROOT, 'opencode-plugin', 'index.mjs');
|
|
20
|
+
const DEADLINE_MS = 8000;
|
|
21
|
+
|
|
22
|
+
async function waitUntil(predicate, timeoutMs = DEADLINE_MS) {
|
|
23
|
+
const deadline = Date.now() + timeoutMs;
|
|
24
|
+
for (;;) {
|
|
25
|
+
if (predicate()) return true;
|
|
26
|
+
if (Date.now() >= deadline) return false;
|
|
27
|
+
await new Promise(resolve => setTimeout(resolve, 20));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function v2Event(type, sessionID) {
|
|
32
|
+
return { id: `evt-${type}-${sessionID}`, created: Date.now(), type, durable: true, data: { sessionID } };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function fixture() {
|
|
36
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'opencode-453-'));
|
|
37
|
+
const workspace = path.join(dir, 'workspace');
|
|
38
|
+
fs.mkdirSync(workspace, { recursive: true });
|
|
39
|
+
const gitInit = spawnSync('git', ['init', '-q', workspace], { encoding: 'utf8' });
|
|
40
|
+
assert.equal(gitInit.status, 0, gitInit.stderr);
|
|
41
|
+
fs.writeFileSync(path.join(workspace, 'package.json'), JSON.stringify({
|
|
42
|
+
name: 'opencode-453-fixture', version: '1.0.0', scripts: { test: 'node verify.js' },
|
|
43
|
+
}));
|
|
44
|
+
fs.writeFileSync(path.join(workspace, 'verify.js'), 'process.exit(1)\n');
|
|
45
|
+
const envBefore = Object.fromEntries(['HOME', 'USERPROFILE', 'HARNESS_STATE_HOME', 'HARNESS_OBSERVATIONS']
|
|
46
|
+
.map(key => [key, process.env[key]]));
|
|
47
|
+
process.env.HOME = dir;
|
|
48
|
+
process.env.USERPROFILE = dir;
|
|
49
|
+
process.env.HARNESS_STATE_HOME = path.join(dir, 'harness-state');
|
|
50
|
+
process.env.HARNESS_OBSERVATIONS = 'off';
|
|
51
|
+
|
|
52
|
+
const toolHooks = new Map();
|
|
53
|
+
const prompts = [];
|
|
54
|
+
const sessionLookups = [];
|
|
55
|
+
const queue = [];
|
|
56
|
+
let wake = null;
|
|
57
|
+
let afterYieldWaiter = null;
|
|
58
|
+
|
|
59
|
+
const failAfterYieldWaiter = reason => {
|
|
60
|
+
if (!afterYieldWaiter) return;
|
|
61
|
+
const waiter = afterYieldWaiter;
|
|
62
|
+
afterYieldWaiter = null;
|
|
63
|
+
waiter.reject(reason);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const ctx = {
|
|
67
|
+
location: { directory: workspace },
|
|
68
|
+
session: {
|
|
69
|
+
get: async ({ sessionID }) => {
|
|
70
|
+
sessionLookups.push(sessionID);
|
|
71
|
+
return { id: sessionID, location: { directory: workspace } };
|
|
72
|
+
},
|
|
73
|
+
hook: async () => ({ dispose: async () => {} }),
|
|
74
|
+
prompt: async input => { prompts.push(input); return {}; },
|
|
75
|
+
context: async () => [],
|
|
76
|
+
},
|
|
77
|
+
tool: { hook: async (name, callback) => { toolHooks.set(name, callback); return { dispose: async () => {} }; } },
|
|
78
|
+
event: {
|
|
79
|
+
subscribe: ({ signal }) => ({
|
|
80
|
+
[Symbol.asyncIterator]: () => ({
|
|
81
|
+
next: () => {
|
|
82
|
+
if (afterYieldWaiter) {
|
|
83
|
+
const waiter = afterYieldWaiter;
|
|
84
|
+
afterYieldWaiter = null;
|
|
85
|
+
waiter.resolve();
|
|
86
|
+
}
|
|
87
|
+
if (queue.length) {
|
|
88
|
+
const item = queue.shift();
|
|
89
|
+
if (item.waiter) afterYieldWaiter = item.waiter;
|
|
90
|
+
return Promise.resolve({ value: item.event, done: false });
|
|
91
|
+
}
|
|
92
|
+
if (signal.aborted) return Promise.resolve({ done: true });
|
|
93
|
+
return new Promise(resolve => {
|
|
94
|
+
const onAbort = () => {
|
|
95
|
+
wake = null;
|
|
96
|
+
failAfterYieldWaiter(new Error('Subscriber aborted before pulling next event'));
|
|
97
|
+
resolve({ done: true });
|
|
98
|
+
};
|
|
99
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
100
|
+
wake = item => {
|
|
101
|
+
signal.removeEventListener('abort', onAbort);
|
|
102
|
+
wake = null;
|
|
103
|
+
if (item.waiter) afterYieldWaiter = item.waiter;
|
|
104
|
+
resolve({ value: item.event, done: false });
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
return: async () => {
|
|
109
|
+
failAfterYieldWaiter(new Error('Subscriber exited loop before pulling next event'));
|
|
110
|
+
return { done: true };
|
|
111
|
+
},
|
|
112
|
+
}),
|
|
113
|
+
}),
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
dir, workspace, ctx, toolHooks, prompts,
|
|
118
|
+
lookupsFor: sessionID => sessionLookups.filter(id => id === sessionID),
|
|
119
|
+
emit(event) {
|
|
120
|
+
const item = { event, waiter: null };
|
|
121
|
+
if (wake) wake(item);
|
|
122
|
+
else queue.push(item);
|
|
123
|
+
},
|
|
124
|
+
emitAndAwaitNext(event, timeoutMs = DEADLINE_MS) {
|
|
125
|
+
assert.equal(afterYieldWaiter, null, 'previous event checkpoint must settle before emitting another');
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
let settled = false;
|
|
128
|
+
let waiter;
|
|
129
|
+
const finish = fn => value => {
|
|
130
|
+
if (settled) return;
|
|
131
|
+
settled = true;
|
|
132
|
+
clearTimeout(timer);
|
|
133
|
+
if (afterYieldWaiter === waiter) afterYieldWaiter = null;
|
|
134
|
+
fn(value);
|
|
135
|
+
};
|
|
136
|
+
const timer = setTimeout(() => {
|
|
137
|
+
finish(reject)(new Error(`Subscriber did not pull next event within ${timeoutMs}ms`));
|
|
138
|
+
}, timeoutMs);
|
|
139
|
+
waiter = {
|
|
140
|
+
resolve: finish(resolve),
|
|
141
|
+
reject: finish(reject),
|
|
142
|
+
};
|
|
143
|
+
const item = { event, waiter };
|
|
144
|
+
if (wake) wake(item);
|
|
145
|
+
else queue.push(item);
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
restore() {
|
|
149
|
+
failAfterYieldWaiter(new Error('Fixture restored before subscriber pulled next event'));
|
|
150
|
+
for (const [key, value] of Object.entries(envBefore)) {
|
|
151
|
+
if (value === undefined) delete process.env[key];
|
|
152
|
+
else process.env[key] = value;
|
|
153
|
+
}
|
|
154
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function editStateFile(f, sessionID) {
|
|
160
|
+
return path.join(workspaceState.getWorkspaceStateDir(f.workspace), 'state', 'sessions',
|
|
161
|
+
harnessState.sessionDirectoryName(sessionID), 'edit-state.json');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function readEditState(f, sessionID) {
|
|
165
|
+
const file = editStateFile(f, sessionID);
|
|
166
|
+
return fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function sendEdit(f, sessionID) {
|
|
170
|
+
const event = { tool: 'edit', sessionID, id: `edit-${sessionID}`, messageID: `assistant-${sessionID}`, input: { filePath: 'changed.js' } };
|
|
171
|
+
await f.toolHooks.get('execute.before')(event);
|
|
172
|
+
await f.toolHooks.get('execute.after')({ ...event, status: 'completed', result: {} });
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async function withPlugin(body) {
|
|
176
|
+
const f = fixture();
|
|
177
|
+
let dispose;
|
|
178
|
+
try {
|
|
179
|
+
const mod = await import(pathToFileURL(PLUGIN).href);
|
|
180
|
+
dispose = await mod.default.setup(f.ctx);
|
|
181
|
+
await body(f);
|
|
182
|
+
} finally {
|
|
183
|
+
if (dispose) await dispose();
|
|
184
|
+
f.restore();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const turnCases = [
|
|
189
|
+
['B', 'external session.idle with a valid V2 id', sid => ({ type: 'session.idle', data: { sessionID: sid } })],
|
|
190
|
+
['C', 'execution.succeeded with only a top-level sessionID', sid => ({ type: 'session.execution.succeeded', sessionID: sid })],
|
|
191
|
+
['D', 'execution.succeeded with only properties.sessionID', sid => ({ type: 'session.execution.succeeded', properties: { sessionID: sid } })],
|
|
192
|
+
];
|
|
193
|
+
|
|
194
|
+
for (const [row, label, make] of turnCases) {
|
|
195
|
+
test(`row ${row}: ${label} performs no session lookup at pulled-next checkpoint, while V2 completion for the same unbound ID does`, { concurrency: false }, async () => {
|
|
196
|
+
await withPlugin(async f => {
|
|
197
|
+
const sid = `s453-${row}`;
|
|
198
|
+
await f.emitAndAwaitNext(make(sid));
|
|
199
|
+
assert.equal(f.lookupsFor(sid).length, 0, `row ${row}: unsupported shape must not look up session`);
|
|
200
|
+
assert.equal(f.prompts.length, 0, `row ${row}: unsupported shape must not prompt`);
|
|
201
|
+
|
|
202
|
+
await f.emitAndAwaitNext(v2Event('session.execution.succeeded', sid));
|
|
203
|
+
assert.equal(f.lookupsFor(sid).length, 1, `row ${row} positive control: V2 completion looks up unbound session`);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
test('row A: session.execution.succeeded with data.sessionID sends the verification reminder prompt', { concurrency: false }, async () => {
|
|
209
|
+
await withPlugin(async f => {
|
|
210
|
+
const sid = 's453-A';
|
|
211
|
+
await sendEdit(f, sid);
|
|
212
|
+
assert.equal(readEditState(f, sid)?.verificationPending, true, 'the V2 edit created pending state');
|
|
213
|
+
await f.emitAndAwaitNext(v2Event('session.execution.succeeded', sid));
|
|
214
|
+
assert.equal(await waitUntil(() => f.prompts.length > 0), true, 'the reminder prompt is sent');
|
|
215
|
+
assert.equal(f.prompts.length, 1, 'exactly one prompt is sent');
|
|
216
|
+
assert.equal(f.prompts[0].sessionID, sid);
|
|
217
|
+
assert.match(String(f.prompts[0].text), /\S/, 'the prompt carries reminder text');
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('row E: session.created with properties.info.id performs no session lookup at pulled-next checkpoint, while V2 created for the same unbound ID does', { concurrency: false }, async () => {
|
|
222
|
+
await withPlugin(async f => {
|
|
223
|
+
const sid = 's453-E';
|
|
224
|
+
await f.emitAndAwaitNext({ type: 'session.created', properties: { info: { id: sid } } });
|
|
225
|
+
assert.equal(f.lookupsFor(sid).length, 0, 'row E: legacy-shaped created event must not look up session');
|
|
226
|
+
|
|
227
|
+
await f.emitAndAwaitNext({ type: 'session.created', data: { sessionID: sid } });
|
|
228
|
+
assert.equal(f.lookupsFor(sid).length, 1, 'row E positive control: V2 created event looks up unbound session');
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test('row F: session.created with data.sessionID resets session state', { concurrency: false }, async () => {
|
|
233
|
+
await withPlugin(async f => {
|
|
234
|
+
const sid = 's453-F';
|
|
235
|
+
await sendEdit(f, sid);
|
|
236
|
+
assert.equal(readEditState(f, sid)?.verificationPending, true, 'the V2 edit created pending state');
|
|
237
|
+
await f.emitAndAwaitNext({ type: 'session.created', data: { sessionID: sid } });
|
|
238
|
+
const reset = await waitUntil(() => readEditState(f, sid)?.verificationPending !== true);
|
|
239
|
+
assert.equal(reset, true, 'row F positive control: V2 created event resets session state');
|
|
240
|
+
});
|
|
241
|
+
});
|