@cleocode/adapters 2026.10.27 → 2026.11.1-canary.10
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/README.md +2 -0
- package/dist/.source-stamp.json +4 -0
- package/dist/index.js +2676 -1895
- package/dist/index.js.map +3 -3
- package/dist/manifests.d.ts +25 -0
- package/dist/manifests.d.ts.map +1 -0
- package/dist/manifests.js +28 -0
- package/dist/manifests.js.map +6 -0
- package/dist/orca-execution.d.ts +89 -0
- package/dist/orca-execution.d.ts.map +1 -0
- package/dist/orca-execution.js +794 -0
- package/dist/orca-execution.js.map +6 -0
- package/dist/providers/claude-code/index.js +46710 -0
- package/dist/providers/claude-code/index.js.map +6 -0
- package/dist/providers/claude-code/lead-mcp.d.ts +99 -0
- package/dist/providers/claude-code/lead-mcp.d.ts.map +1 -0
- package/dist/providers/claude-code/lead-session.d.ts +133 -0
- package/dist/providers/claude-code/lead-session.d.ts.map +1 -0
- package/dist/providers/claude-code/spawn.d.ts +39 -0
- package/dist/providers/claude-code/spawn.d.ts.map +1 -1
- package/dist/providers/claude-sdk/index.js +44549 -0
- package/dist/providers/claude-sdk/index.js.map +6 -0
- package/dist/providers/claude-sdk/spawn.d.ts +6 -0
- package/dist/providers/claude-sdk/spawn.d.ts.map +1 -1
- package/dist/providers/codex/index.js +19315 -0
- package/dist/providers/codex/index.js.map +6 -0
- package/dist/providers/codex/spawn.d.ts +2 -0
- package/dist/providers/codex/spawn.d.ts.map +1 -1
- package/dist/providers/cursor/index.js +637 -0
- package/dist/providers/cursor/index.js.map +6 -0
- package/dist/providers/cursor/spawn.d.ts +2 -0
- package/dist/providers/cursor/spawn.d.ts.map +1 -1
- package/dist/providers/gemini-cli/index.js +18877 -0
- package/dist/providers/gemini-cli/index.js.map +6 -0
- package/dist/providers/gemini-cli/spawn.d.ts +2 -0
- package/dist/providers/gemini-cli/spawn.d.ts.map +1 -1
- package/dist/providers/kimi/index.js +18806 -0
- package/dist/providers/kimi/index.js.map +6 -0
- package/dist/providers/kimi/spawn.d.ts +2 -0
- package/dist/providers/kimi/spawn.d.ts.map +1 -1
- package/dist/providers/openai-sdk/adapter.d.ts +1 -1
- package/dist/providers/openai-sdk/index.d.ts +0 -1
- package/dist/providers/openai-sdk/index.d.ts.map +1 -1
- package/dist/providers/openai-sdk/index.js +44190 -0
- package/dist/providers/openai-sdk/index.js.map +6 -0
- package/dist/providers/openai-sdk/spawn.d.ts +4 -2
- package/dist/providers/openai-sdk/spawn.d.ts.map +1 -1
- package/dist/providers/openai-sdk/tracing.d.ts +8 -82
- package/dist/providers/openai-sdk/tracing.d.ts.map +1 -1
- package/dist/providers/opencode/index.js +19317 -0
- package/dist/providers/opencode/index.js.map +6 -0
- package/dist/providers/opencode/spawn.d.ts +2 -0
- package/dist/providers/opencode/spawn.d.ts.map +1 -1
- package/dist/providers/pi/index.js +18453 -0
- package/dist/providers/pi/index.js.map +6 -0
- package/dist/providers/pi/spawn.d.ts +2 -0
- package/dist/providers/pi/spawn.d.ts.map +1 -1
- package/dist/providers/shared/lead-tool-strip.d.ts +52 -0
- package/dist/providers/shared/lead-tool-strip.d.ts.map +1 -0
- package/dist/registry.d.ts +2 -55
- package/dist/registry.d.ts.map +1 -1
- package/package.json +14 -6
- package/src/__tests__/harness-interop.test.ts +0 -7
- package/src/__tests__/orca-execution-fixture.ts +380 -0
- package/src/__tests__/orca-execution.test.ts +1357 -0
- package/src/__tests__/orca-plugin-panel.test.ts +661 -0
- package/src/__tests__/orca-plugin.test.ts +660 -0
- package/src/manifests.ts +55 -0
- package/src/orca-execution.ts +1136 -0
- package/src/providers/claude-code/__tests__/lead-mcp.test.ts +348 -0
- package/src/providers/claude-code/__tests__/worker-exit-settings.test.ts +32 -0
- package/src/providers/claude-code/lead-mcp.ts +244 -0
- package/src/providers/claude-code/lead-session.ts +241 -0
- package/src/providers/claude-code/spawn.ts +180 -11
- package/src/providers/claude-sdk/__tests__/spawn.test.ts +63 -3
- package/src/providers/claude-sdk/spawn.ts +28 -1
- package/src/providers/codex/spawn.ts +5 -0
- package/src/providers/cursor/spawn.ts +3 -0
- package/src/providers/gemini-cli/spawn.ts +5 -0
- package/src/providers/kimi/spawn.ts +5 -0
- package/src/providers/openai-sdk/__tests__/openai-sdk-spawn.test.ts +0 -80
- package/src/providers/openai-sdk/adapter.ts +1 -1
- package/src/providers/openai-sdk/index.ts +0 -1
- package/src/providers/openai-sdk/manifest.json +1 -1
- package/src/providers/openai-sdk/spawn.ts +10 -16
- package/src/providers/openai-sdk/tracing.ts +8 -169
- package/src/providers/opencode/spawn.ts +5 -0
- package/src/providers/pi/spawn.ts +5 -0
- package/src/providers/shared/__tests__/lead-tool-strip.test.ts +126 -0
- package/src/providers/shared/lead-tool-strip.ts +76 -0
- package/src/registry.ts +2 -78
- package/dist/providers/shared/conduit-trace-writer.d.ts +0 -72
- package/dist/providers/shared/conduit-trace-writer.d.ts.map +0 -1
- package/src/providers/shared/conduit-trace-writer.ts +0 -101
|
@@ -0,0 +1,1357 @@
|
|
|
1
|
+
import type { OrcaAttempt, OrcaReply } from '@cleocode/contracts/orca-execution.js';
|
|
2
|
+
import { ORCA_AGENT_HARNESSES, orcaReplySchema } from '@cleocode/contracts/orca-execution.js';
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { OrcaExecutionBackend } from '../orca-execution.js';
|
|
5
|
+
import {
|
|
6
|
+
fixtureAttempt,
|
|
7
|
+
fixtureContext,
|
|
8
|
+
fixtureHelperExited,
|
|
9
|
+
fixtureLaunch,
|
|
10
|
+
fixturePendingStart,
|
|
11
|
+
fixtureReleasedShow,
|
|
12
|
+
fixtureReply,
|
|
13
|
+
fixtureRunner,
|
|
14
|
+
fixtureShow,
|
|
15
|
+
fixtureStart,
|
|
16
|
+
orcaFixture,
|
|
17
|
+
runOrcaFixture,
|
|
18
|
+
} from './orca-execution-fixture.js';
|
|
19
|
+
|
|
20
|
+
describe('Orca execution process boundary', () => {
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
fixtureRunner.mockReset().mockImplementation(runOrcaFixture);
|
|
23
|
+
orcaFixture.launch = { ...fixtureLaunch };
|
|
24
|
+
orcaFixture.start = fixtureStart();
|
|
25
|
+
orcaFixture.show = fixtureShow();
|
|
26
|
+
orcaFixture.helperShows = {};
|
|
27
|
+
orcaFixture.capabilities = [
|
|
28
|
+
'orchestration.contract.v1',
|
|
29
|
+
'orchestration.worker-stop-helpers.v1',
|
|
30
|
+
];
|
|
31
|
+
orcaFixture.stop = fixtureReply(
|
|
32
|
+
{
|
|
33
|
+
dispatchId: 'ctx_fixture',
|
|
34
|
+
state: 'stop_unknown',
|
|
35
|
+
processAction: 'closed_agent_terminal',
|
|
36
|
+
helpers: [],
|
|
37
|
+
},
|
|
38
|
+
1,
|
|
39
|
+
);
|
|
40
|
+
orcaFixture.request = fixtureReply({ state: 'completed', requestId: 'request-fixture' });
|
|
41
|
+
orcaFixture.currentRun = fixtureReply({ run: { id: 'run_fixture' } });
|
|
42
|
+
orcaFixture.accounts = fixtureReply({
|
|
43
|
+
codex: {
|
|
44
|
+
accounts: [{ email: 'private@example.invalid', home: '/private/account' }],
|
|
45
|
+
activeAccountId: 'managed-private-id',
|
|
46
|
+
},
|
|
47
|
+
opencode: { accounts: [], activeAccountId: null },
|
|
48
|
+
claude: { accounts: [], activeAccountId: 'system' },
|
|
49
|
+
});
|
|
50
|
+
orcaFixture.caller = fixtureReply({
|
|
51
|
+
terminal: {
|
|
52
|
+
handle: fixtureContext.coordinatorHandle,
|
|
53
|
+
executionHostId: 'local',
|
|
54
|
+
connected: true,
|
|
55
|
+
writable: true,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
afterEach(() => vi.unstubAllEnvs());
|
|
61
|
+
|
|
62
|
+
it('ignores TERM_PROGRAM alone and proves the exact local caller before exposing account availability', async () => {
|
|
63
|
+
for (const key of [
|
|
64
|
+
'ORCA_TERMINAL_HANDLE',
|
|
65
|
+
'ORCA_WORKTREE_ID',
|
|
66
|
+
'ORCA_WORKSPACE_ID',
|
|
67
|
+
'ORCA_RUNTIME_SOURCE_ID',
|
|
68
|
+
'ORCA_APP_VERSION',
|
|
69
|
+
])
|
|
70
|
+
vi.stubEnv(key, undefined);
|
|
71
|
+
vi.stubEnv('TERM_PROGRAM', 'Orca');
|
|
72
|
+
const backend = new OrcaExecutionBackend(fixtureRunner, '/fixture/orca');
|
|
73
|
+
expect(backend.hasContextHints()).toBe(false);
|
|
74
|
+
expect(await backend.discover(fixtureLaunch.projectRoot)).toBeNull();
|
|
75
|
+
expect(fixtureRunner).not.toHaveBeenCalled();
|
|
76
|
+
vi.stubEnv('ORCA_TERMINAL_HANDLE', fixtureContext.coordinatorHandle);
|
|
77
|
+
expect(backend.hasContextHints()).toBe(true);
|
|
78
|
+
const discovery = await backend.discover(fixtureLaunch.projectRoot);
|
|
79
|
+
expect(discovery).toEqual({
|
|
80
|
+
context: fixtureContext,
|
|
81
|
+
accounts: [
|
|
82
|
+
{ provider: 'codex', accountCount: 1, activeAccountPresent: true },
|
|
83
|
+
{ provider: 'opencode', accountCount: 0, activeAccountPresent: false },
|
|
84
|
+
{ provider: 'claude', accountCount: 0, activeAccountPresent: true },
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
expect(JSON.stringify(discovery)).not.toMatch(/private|@|managed-/);
|
|
88
|
+
expect(fixtureRunner.mock.calls.map(([, args]) => args)).toContainEqual([
|
|
89
|
+
'terminal',
|
|
90
|
+
'show',
|
|
91
|
+
'--terminal',
|
|
92
|
+
fixtureContext.coordinatorHandle,
|
|
93
|
+
'--environment',
|
|
94
|
+
'local',
|
|
95
|
+
'--json',
|
|
96
|
+
]);
|
|
97
|
+
expect(fixtureRunner.mock.calls.map(([, args]) => args)).toContainEqual([
|
|
98
|
+
'account',
|
|
99
|
+
'list',
|
|
100
|
+
'--json',
|
|
101
|
+
]);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it.each([
|
|
105
|
+
'run_fixture',
|
|
106
|
+
null,
|
|
107
|
+
])('proves the coordinator Run binding %s without mutation', async (runId) => {
|
|
108
|
+
orcaFixture.currentRun = fixtureReply({ run: runId === null ? null : { id: runId } });
|
|
109
|
+
const backend = new OrcaExecutionBackend(fixtureRunner);
|
|
110
|
+
expect(await backend.currentRun(fixtureLaunch.projectRoot, fixtureContext)).toBe(runId);
|
|
111
|
+
expect(fixtureRunner.mock.calls.map(([, args]) => args)).toContainEqual([
|
|
112
|
+
'orchestration',
|
|
113
|
+
'run-current',
|
|
114
|
+
'--from',
|
|
115
|
+
fixtureContext.coordinatorHandle,
|
|
116
|
+
'--environment',
|
|
117
|
+
'local',
|
|
118
|
+
'--json',
|
|
119
|
+
'--full',
|
|
120
|
+
]);
|
|
121
|
+
expect(fixtureRunner.mock.calls.some(([, args]) => args[1] === 'worker-start')).toBe(false);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it.each(['missing', 'wrong-runtime'])('refuses an unproven %s Run binding', async (condition) => {
|
|
125
|
+
orcaFixture.currentRun =
|
|
126
|
+
condition === 'missing'
|
|
127
|
+
? fixtureReply({})
|
|
128
|
+
: {
|
|
129
|
+
stdout: JSON.stringify({
|
|
130
|
+
ok: true,
|
|
131
|
+
result: { run: null },
|
|
132
|
+
_meta: { runtimeId: 'other' },
|
|
133
|
+
}),
|
|
134
|
+
stderr: '',
|
|
135
|
+
exitCode: 0,
|
|
136
|
+
};
|
|
137
|
+
await expect(
|
|
138
|
+
new OrcaExecutionBackend(fixtureRunner).currentRun(fixtureLaunch.projectRoot, fixtureContext),
|
|
139
|
+
).rejects.toMatchObject({
|
|
140
|
+
code: 'E_ORCA_CONTEXT',
|
|
141
|
+
fix: expect.any(String),
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it.each([
|
|
146
|
+
'missing-handle',
|
|
147
|
+
'different-caller',
|
|
148
|
+
'remote-caller',
|
|
149
|
+
'unavailable',
|
|
150
|
+
'bad-accounts',
|
|
151
|
+
] as const)('refuses %s without launching, exposing private account data or selecting another runtime', async (condition) => {
|
|
152
|
+
vi.stubEnv('ORCA_TERMINAL_HANDLE', fixtureContext.coordinatorHandle);
|
|
153
|
+
vi.stubEnv('ORCA_WORKTREE_ID', 'workspace-fixture');
|
|
154
|
+
if (condition === 'missing-handle') vi.stubEnv('ORCA_TERMINAL_HANDLE', undefined);
|
|
155
|
+
if (condition === 'different-caller' || condition === 'remote-caller')
|
|
156
|
+
orcaFixture.caller = fixtureReply({
|
|
157
|
+
terminal: {
|
|
158
|
+
handle:
|
|
159
|
+
condition === 'different-caller' ? 'term_other' : fixtureContext.coordinatorHandle,
|
|
160
|
+
executionHostId: condition === 'remote-caller' ? 'remote' : 'local',
|
|
161
|
+
connected: true,
|
|
162
|
+
writable: true,
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
if (condition === 'unavailable')
|
|
166
|
+
fixtureRunner.mockResolvedValue({ stdout: '', stderr: 'unreachable', exitCode: null });
|
|
167
|
+
if (condition === 'bad-accounts')
|
|
168
|
+
orcaFixture.accounts = {
|
|
169
|
+
stdout: 'private@example.invalid /private/home',
|
|
170
|
+
stderr: '',
|
|
171
|
+
exitCode: 1,
|
|
172
|
+
};
|
|
173
|
+
const failure = await new OrcaExecutionBackend(fixtureRunner)
|
|
174
|
+
.discover(fixtureLaunch.projectRoot)
|
|
175
|
+
.catch((error: Error) => error);
|
|
176
|
+
expect(failure).toMatchObject({
|
|
177
|
+
code: expect.stringMatching(/^E_ORCA_/),
|
|
178
|
+
fix: expect.any(String),
|
|
179
|
+
});
|
|
180
|
+
expect(String(failure)).not.toMatch(/private@example|\/private\/home/);
|
|
181
|
+
expect(fixtureRunner.mock.calls.some(([, args]) => args[1] === 'worker-start')).toBe(false);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('recognizes only a runtime-bound resource-free agent_unconfigured pre-dispatch refusal', async () => {
|
|
185
|
+
const refused = {
|
|
186
|
+
ok: false,
|
|
187
|
+
error: { code: 'agent_unconfigured', message: 'Agent is disabled' },
|
|
188
|
+
_meta: { runtimeId: fixtureContext.runtimeId },
|
|
189
|
+
};
|
|
190
|
+
orcaFixture.start = { stdout: JSON.stringify(refused), stderr: '', exitCode: 1 };
|
|
191
|
+
const backend = new OrcaExecutionBackend(fixtureRunner);
|
|
192
|
+
expect(await backend.start(fixtureAttempt())).toMatchObject({
|
|
193
|
+
state: 'failed',
|
|
194
|
+
resourceState: 'stopped',
|
|
195
|
+
startRefusal: 'agent_unconfigured',
|
|
196
|
+
dispatchId: null,
|
|
197
|
+
});
|
|
198
|
+
orcaFixture.start = {
|
|
199
|
+
...orcaFixture.start,
|
|
200
|
+
stdout: JSON.stringify({ ...refused, result: { dispatchId: 'ctx_unknown' } }),
|
|
201
|
+
};
|
|
202
|
+
expect(await backend.start(fixtureAttempt())).toMatchObject({
|
|
203
|
+
state: 'outcome_unknown',
|
|
204
|
+
resourceState: 'unknown',
|
|
205
|
+
});
|
|
206
|
+
orcaFixture.start = {
|
|
207
|
+
...orcaFixture.start,
|
|
208
|
+
stdout: JSON.stringify({ ...refused, _meta: { runtimeId: 'other-runtime' } }),
|
|
209
|
+
};
|
|
210
|
+
expect(await backend.start(fixtureAttempt())).toMatchObject({
|
|
211
|
+
state: 'outcome_unknown',
|
|
212
|
+
resourceState: 'unknown',
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('refuses ambiguous workspace resolution with an exact-selector fix before launch', async () => {
|
|
217
|
+
fixtureRunner.mockImplementation(async (...args) =>
|
|
218
|
+
args[1][0] === 'worktree'
|
|
219
|
+
? {
|
|
220
|
+
stdout: JSON.stringify({
|
|
221
|
+
ok: false,
|
|
222
|
+
error: { code: 'ambiguous_selector', message: 'Several workspaces match' },
|
|
223
|
+
_meta: { runtimeId: fixtureContext.runtimeId },
|
|
224
|
+
}),
|
|
225
|
+
stderr: '',
|
|
226
|
+
exitCode: 1,
|
|
227
|
+
}
|
|
228
|
+
: runOrcaFixture(...args),
|
|
229
|
+
);
|
|
230
|
+
await expect(
|
|
231
|
+
new OrcaExecutionBackend(fixtureRunner).preflight(fixtureLaunch, fixtureContext),
|
|
232
|
+
).rejects.toMatchObject({
|
|
233
|
+
code: 'E_ORCA_WORKSPACE',
|
|
234
|
+
message: 'Several workspaces match',
|
|
235
|
+
fix: expect.stringContaining('<exact-selector>'),
|
|
236
|
+
});
|
|
237
|
+
expect(fixtureRunner.mock.calls.some(([, args]) => args[1] === 'worker-start')).toBe(false);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('preflights the command registry and exact runtime/workspace, then starts once with inert stdin', async () => {
|
|
241
|
+
const backend = new OrcaExecutionBackend(fixtureRunner, '/fixture/orca');
|
|
242
|
+
const workspace = await backend.preflight(fixtureLaunch, fixtureContext);
|
|
243
|
+
expect(workspace).toEqual({
|
|
244
|
+
workspaceId: 'workspace-fixture',
|
|
245
|
+
workspaceSelector: 'identity:workspace-fixture',
|
|
246
|
+
});
|
|
247
|
+
const result = await backend.start(fixtureAttempt(workspace));
|
|
248
|
+
expect(result).toMatchObject({
|
|
249
|
+
state: 'ready',
|
|
250
|
+
runId: 'run_fixture',
|
|
251
|
+
orcaTaskId: 'task_fixture',
|
|
252
|
+
dispatchId: 'ctx_fixture',
|
|
253
|
+
resourceState: 'owned',
|
|
254
|
+
});
|
|
255
|
+
const starts = fixtureRunner.mock.calls.filter(([, args]) => args[1] === 'worker-start');
|
|
256
|
+
expect(starts).toEqual([
|
|
257
|
+
[
|
|
258
|
+
'/fixture/orca',
|
|
259
|
+
[
|
|
260
|
+
'orchestration',
|
|
261
|
+
'worker-start',
|
|
262
|
+
'--from',
|
|
263
|
+
'term_fixture',
|
|
264
|
+
'--worktree',
|
|
265
|
+
'identity:workspace-fixture',
|
|
266
|
+
'--agent',
|
|
267
|
+
'codex',
|
|
268
|
+
'--spec-file',
|
|
269
|
+
'-',
|
|
270
|
+
'--task-title',
|
|
271
|
+
'project-fixture:T001:worker-fixture',
|
|
272
|
+
'--environment',
|
|
273
|
+
'local',
|
|
274
|
+
'--json',
|
|
275
|
+
'--full',
|
|
276
|
+
],
|
|
277
|
+
'/fixture/project',
|
|
278
|
+
fixtureLaunch.prompt,
|
|
279
|
+
],
|
|
280
|
+
]);
|
|
281
|
+
expect(result.lastReceipt).toBe(orcaFixture.start.stdout);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it.each([
|
|
285
|
+
'lead',
|
|
286
|
+
'account',
|
|
287
|
+
'kimi',
|
|
288
|
+
'effort',
|
|
289
|
+
] as const)('refuses unsupported %s before any process call', async (constraint) => {
|
|
290
|
+
const launch = { ...fixtureLaunch };
|
|
291
|
+
if (constraint === 'lead') launch.role = 'lead';
|
|
292
|
+
if (constraint === 'account') launch.accountId = 'requested-account';
|
|
293
|
+
if (constraint === 'kimi') launch.harness = 'kimi';
|
|
294
|
+
if (constraint === 'effort') {
|
|
295
|
+
launch.harness = 'opencode';
|
|
296
|
+
launch.model = 'explicit-model';
|
|
297
|
+
launch.effort = 'high';
|
|
298
|
+
}
|
|
299
|
+
const backend = new OrcaExecutionBackend(fixtureRunner);
|
|
300
|
+
await expect(backend.preflight(launch, fixtureContext)).rejects.toThrow();
|
|
301
|
+
expect(fixtureRunner).not.toHaveBeenCalled();
|
|
302
|
+
await expect(backend.start(fixtureAttempt({ launch }))).rejects.toThrow();
|
|
303
|
+
expect(fixtureRunner).not.toHaveBeenCalled();
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it('uses opencode2 without changing the selected harness identity', async () => {
|
|
307
|
+
orcaFixture.start = fixtureReply({
|
|
308
|
+
state: 'ready',
|
|
309
|
+
dispatchId: 'ctx_fixture',
|
|
310
|
+
taskId: 'task_fixture',
|
|
311
|
+
runId: 'run_fixture',
|
|
312
|
+
effects: [{ kind: 'worktree', id: 'workspace-fixture' }],
|
|
313
|
+
launch: { effective: { agent: 'opencode2' } },
|
|
314
|
+
});
|
|
315
|
+
const result = await new OrcaExecutionBackend(fixtureRunner).start(
|
|
316
|
+
fixtureAttempt({ launch: { ...fixtureLaunch, harness: 'opencode' } }),
|
|
317
|
+
);
|
|
318
|
+
expect(result.launch.harness).toBe('opencode');
|
|
319
|
+
expect(result.state).toBe('ready');
|
|
320
|
+
expect(fixtureRunner.mock.calls.find(([, args]) => args[1] === 'worker-start')?.[1]).toContain(
|
|
321
|
+
'opencode2',
|
|
322
|
+
);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it.each(
|
|
326
|
+
Object.values(ORCA_AGENT_HARNESSES),
|
|
327
|
+
)('refuses an explicit Orca %s lead before a failed account inventory can mask its guard', async (harness) => {
|
|
328
|
+
orcaFixture.accounts = { stdout: '', stderr: 'inventory unavailable', exitCode: 1 };
|
|
329
|
+
const launch = { ...fixtureLaunch, role: 'lead' as const, harness };
|
|
330
|
+
const backend = new OrcaExecutionBackend(fixtureRunner);
|
|
331
|
+
expect(backend.leadToolStrip).toBe('unsupported');
|
|
332
|
+
for (const invoke of [
|
|
333
|
+
() => backend.preflight(launch, fixtureContext),
|
|
334
|
+
() => backend.start(fixtureAttempt({ launch })),
|
|
335
|
+
]) {
|
|
336
|
+
await expect(invoke()).rejects.toMatchObject({
|
|
337
|
+
code: 'E_LEAD_TOOLS_UNSTRIPPED',
|
|
338
|
+
exitCode: 63,
|
|
339
|
+
message: expect.stringMatching(
|
|
340
|
+
/--tools.*--permission-mode.*strict MCP.*owner channel.*--session-id/,
|
|
341
|
+
),
|
|
342
|
+
fix: expect.stringContaining('keep orchestrate.leadWorker.v1 enabled'),
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
expect(fixtureRunner).not.toHaveBeenCalled();
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('refuses a changed runtime and an incomplete command registry before launch', async () => {
|
|
349
|
+
fixtureRunner.mockImplementation(async (...args) =>
|
|
350
|
+
args[1][0] === 'status'
|
|
351
|
+
? {
|
|
352
|
+
stdout: JSON.stringify({
|
|
353
|
+
ok: true,
|
|
354
|
+
_meta: { runtimeId: 'different-runtime' },
|
|
355
|
+
result: {},
|
|
356
|
+
}),
|
|
357
|
+
stderr: '',
|
|
358
|
+
exitCode: 0,
|
|
359
|
+
}
|
|
360
|
+
: runOrcaFixture(...args),
|
|
361
|
+
);
|
|
362
|
+
await expect(
|
|
363
|
+
new OrcaExecutionBackend(fixtureRunner).preflight(fixtureLaunch, fixtureContext),
|
|
364
|
+
).rejects.toThrow('runtime identity');
|
|
365
|
+
expect(fixtureRunner.mock.calls.some(([, args]) => args[1] === 'worker-start')).toBe(false);
|
|
366
|
+
fixtureRunner.mockReset().mockResolvedValue({
|
|
367
|
+
stdout: JSON.stringify({ schemaVersion: 1, commands: [] }),
|
|
368
|
+
stderr: '',
|
|
369
|
+
exitCode: 0,
|
|
370
|
+
});
|
|
371
|
+
await expect(
|
|
372
|
+
new OrcaExecutionBackend(fixtureRunner).preflight(fixtureLaunch, fixtureContext),
|
|
373
|
+
).rejects.toThrow('does not declare');
|
|
374
|
+
expect(fixtureRunner).toHaveBeenCalledTimes(1);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('requires the runtime model-override capability before accepting an explicit route', async () => {
|
|
378
|
+
await expect(
|
|
379
|
+
new OrcaExecutionBackend(fixtureRunner).preflight(
|
|
380
|
+
{ ...fixtureLaunch, model: 'requested-model' },
|
|
381
|
+
fixtureContext,
|
|
382
|
+
),
|
|
383
|
+
).rejects.toThrow('runtime is unavailable or changed');
|
|
384
|
+
expect(fixtureRunner.mock.calls.some(([, args]) => args[1] === 'worker-start')).toBe(false);
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it.each([
|
|
388
|
+
null,
|
|
389
|
+
0,
|
|
390
|
+
])('refuses an unavailable or malformed CLI registry (exit %s) actionably', async (exitCode) => {
|
|
391
|
+
fixtureRunner.mockResolvedValue({ stdout: '', stderr: 'unavailable fixture CLI', exitCode });
|
|
392
|
+
await expect(
|
|
393
|
+
new OrcaExecutionBackend(fixtureRunner).preflight(fixtureLaunch, fixtureContext),
|
|
394
|
+
).rejects.toMatchObject({
|
|
395
|
+
code: exitCode === null ? 'E_ORCA_CONTEXT' : 'E_ORCA_COMMAND_UNSUPPORTED',
|
|
396
|
+
fix: expect.stringContaining('selected Orca'),
|
|
397
|
+
});
|
|
398
|
+
expect(fixtureRunner).toHaveBeenCalledTimes(1);
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it('keeps unobserved-turn starts in flight despite a nonzero full-view exit', async () => {
|
|
402
|
+
orcaFixture.start = fixtureStart('outcome_unknown');
|
|
403
|
+
const backend = new OrcaExecutionBackend(fixtureRunner);
|
|
404
|
+
const result = await backend.start(fixtureAttempt());
|
|
405
|
+
expect(result).toMatchObject({ state: 'turn_unobserved', dispatchId: 'ctx_fixture' });
|
|
406
|
+
await expect(backend.replayStart(result)).rejects.toThrow('No replayable');
|
|
407
|
+
expect(fixtureRunner.mock.calls.filter(([, args]) => args[1] === 'worker-start')).toHaveLength(
|
|
408
|
+
1,
|
|
409
|
+
);
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it('fences lost receipts across new backend instances', async () => {
|
|
413
|
+
orcaFixture.start = { stdout: '', stderr: 'timeout', exitCode: null };
|
|
414
|
+
const result = await new OrcaExecutionBackend(fixtureRunner).start(fixtureAttempt());
|
|
415
|
+
expect(result).toMatchObject({ state: 'outcome_unknown', dispatchId: null, lastReceipt: '' });
|
|
416
|
+
await expect(new OrcaExecutionBackend(fixtureRunner).start(result)).rejects.toThrow(
|
|
417
|
+
'cannot start another',
|
|
418
|
+
);
|
|
419
|
+
await expect(new OrcaExecutionBackend(fixtureRunner).replayStart(result)).rejects.toThrow(
|
|
420
|
+
'No replayable',
|
|
421
|
+
);
|
|
422
|
+
expect(fixtureRunner.mock.calls.filter(([, args]) => args[1] === 'worker-start')).toHaveLength(
|
|
423
|
+
1,
|
|
424
|
+
);
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
it('recovers an issued request only with identical placement, prompt and retry-request', async () => {
|
|
428
|
+
orcaFixture.start = {
|
|
429
|
+
stdout: JSON.stringify({
|
|
430
|
+
ok: false,
|
|
431
|
+
error: {
|
|
432
|
+
code: 'runtime_timeout',
|
|
433
|
+
message: 'lost reply',
|
|
434
|
+
data: { orchestrationRequestId: 'request-fixture' },
|
|
435
|
+
},
|
|
436
|
+
_meta: { runtimeId: fixtureContext.runtimeId },
|
|
437
|
+
}),
|
|
438
|
+
stderr: '',
|
|
439
|
+
exitCode: 1,
|
|
440
|
+
};
|
|
441
|
+
const unknown = await new OrcaExecutionBackend(fixtureRunner).start(fixtureAttempt());
|
|
442
|
+
expect(unknown).toMatchObject({ state: 'outcome_unknown', startRequestId: 'request-fixture' });
|
|
443
|
+
orcaFixture.start = fixtureStart();
|
|
444
|
+
const recovered = await new OrcaExecutionBackend(fixtureRunner).replayStart(unknown);
|
|
445
|
+
expect(recovered.state).toBe('ready');
|
|
446
|
+
const starts = fixtureRunner.mock.calls.filter(([, args]) => args[1] === 'worker-start');
|
|
447
|
+
expect(starts[1]?.[1]).toEqual([
|
|
448
|
+
...starts[0]![1].slice(0, -4),
|
|
449
|
+
'--retry-request',
|
|
450
|
+
'request-fixture',
|
|
451
|
+
'--environment',
|
|
452
|
+
'local',
|
|
453
|
+
'--json',
|
|
454
|
+
'--full',
|
|
455
|
+
]);
|
|
456
|
+
expect(starts[1]?.[3]).toBe(fixtureLaunch.prompt);
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
it('does not replay an absent request or route around a circuit breaker', async () => {
|
|
460
|
+
const backend = new OrcaExecutionBackend(fixtureRunner);
|
|
461
|
+
orcaFixture.request = fixtureReply({ state: 'absent' });
|
|
462
|
+
await expect(
|
|
463
|
+
backend.replayStart(
|
|
464
|
+
fixtureAttempt({ state: 'outcome_unknown', startRequestId: 'request-fixture' }),
|
|
465
|
+
),
|
|
466
|
+
).rejects.toThrow('absence');
|
|
467
|
+
orcaFixture.start = fixtureStart('failed', 3);
|
|
468
|
+
const broken = await backend.start(fixtureAttempt());
|
|
469
|
+
expect(broken).toMatchObject({ state: 'circuit_broken', failureCount: 3 });
|
|
470
|
+
await expect(backend.start(broken)).rejects.toThrow('cannot start');
|
|
471
|
+
await expect(
|
|
472
|
+
backend.replayStart({
|
|
473
|
+
...broken,
|
|
474
|
+
state: 'outcome_unknown',
|
|
475
|
+
startRequestId: 'request-fixture',
|
|
476
|
+
}),
|
|
477
|
+
).rejects.toThrow('No replayable');
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
it('fences a reserved key without an exact retry binding even when its request is absent', async () => {
|
|
481
|
+
const key = '00000000-0000-4000-8000-000000000000';
|
|
482
|
+
orcaFixture.request = fixtureReply({ state: 'absent', requestId: key });
|
|
483
|
+
const backend = new OrcaExecutionBackend(fixtureRunner);
|
|
484
|
+
await expect(backend.start(fixtureAttempt({ startRequestKey: key }))).rejects.toThrow(
|
|
485
|
+
'exact retry binding',
|
|
486
|
+
);
|
|
487
|
+
await expect(
|
|
488
|
+
backend.replayStart(fixtureAttempt({ state: 'outcome_unknown', startRequestKey: key })),
|
|
489
|
+
).rejects.toThrow('exact retry binding');
|
|
490
|
+
expect(fixtureRunner.mock.calls.some(([, args]) => args[1] === 'worker-start')).toBe(false);
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
it('replays original spec argv even when a partial receipt supplied Run, Task and Dispatch ids', async () => {
|
|
494
|
+
const partial = orcaReplySchema.parse(JSON.parse(fixtureStart('outcome_unknown').stdout));
|
|
495
|
+
orcaFixture.start = {
|
|
496
|
+
...orcaFixture.start,
|
|
497
|
+
stdout: JSON.stringify({
|
|
498
|
+
...partial,
|
|
499
|
+
ok: false,
|
|
500
|
+
error: {
|
|
501
|
+
code: 'runtime_timeout',
|
|
502
|
+
message: 'receipt lost after dispatch',
|
|
503
|
+
data: { orchestrationRequestId: 'request-fixture' },
|
|
504
|
+
},
|
|
505
|
+
}),
|
|
506
|
+
exitCode: 1,
|
|
507
|
+
};
|
|
508
|
+
const unknown = await new OrcaExecutionBackend(fixtureRunner).start(fixtureAttempt());
|
|
509
|
+
expect(unknown).toMatchObject({
|
|
510
|
+
state: 'outcome_unknown',
|
|
511
|
+
dispatchId: 'ctx_fixture',
|
|
512
|
+
startRequestId: 'request-fixture',
|
|
513
|
+
startBinding: { runId: null, orcaTaskId: null, retryOf: null },
|
|
514
|
+
});
|
|
515
|
+
orcaFixture.start = fixtureStart();
|
|
516
|
+
const recovered = await new OrcaExecutionBackend(fixtureRunner).replayStart(unknown);
|
|
517
|
+
expect(recovered.state).toBe('ready');
|
|
518
|
+
const starts = fixtureRunner.mock.calls.filter(([, args]) => args[1] === 'worker-start');
|
|
519
|
+
expect(starts[1]?.[1]).toEqual([
|
|
520
|
+
...starts[0]![1].slice(0, -4),
|
|
521
|
+
'--retry-request',
|
|
522
|
+
'request-fixture',
|
|
523
|
+
'--environment',
|
|
524
|
+
'local',
|
|
525
|
+
'--json',
|
|
526
|
+
'--full',
|
|
527
|
+
]);
|
|
528
|
+
expect(starts[1]?.[3]).toBe(fixtureLaunch.prompt);
|
|
529
|
+
await expect(
|
|
530
|
+
new OrcaExecutionBackend(fixtureRunner).start({ ...unknown, state: 'launching' }),
|
|
531
|
+
).rejects.toThrow('cannot start');
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
it('starts a retry on the same Run and Task with explicit placement and its predecessor', async () => {
|
|
535
|
+
const result = await new OrcaExecutionBackend(fixtureRunner).start(
|
|
536
|
+
fixtureAttempt({
|
|
537
|
+
runId: 'run_fixture',
|
|
538
|
+
orcaTaskId: 'task_fixture',
|
|
539
|
+
retryOf: 'ctx_predecessor',
|
|
540
|
+
failureCount: 2,
|
|
541
|
+
startBinding: {
|
|
542
|
+
runId: 'run_fixture',
|
|
543
|
+
orcaTaskId: 'task_fixture',
|
|
544
|
+
retryOf: 'ctx_predecessor',
|
|
545
|
+
},
|
|
546
|
+
}),
|
|
547
|
+
);
|
|
548
|
+
expect(result).toMatchObject({ state: 'ready', failureCount: 2, retryOf: 'ctx_predecessor' });
|
|
549
|
+
expect(fixtureRunner.mock.calls.at(-1)).toEqual([
|
|
550
|
+
expect.any(String),
|
|
551
|
+
[
|
|
552
|
+
'orchestration',
|
|
553
|
+
'worker-start',
|
|
554
|
+
'--from',
|
|
555
|
+
'term_fixture',
|
|
556
|
+
'--worktree',
|
|
557
|
+
'identity:workspace-fixture',
|
|
558
|
+
'--agent',
|
|
559
|
+
'codex',
|
|
560
|
+
'--task',
|
|
561
|
+
'task_fixture',
|
|
562
|
+
'--run',
|
|
563
|
+
'run_fixture',
|
|
564
|
+
'--retry-of',
|
|
565
|
+
'ctx_predecessor',
|
|
566
|
+
'--environment',
|
|
567
|
+
'local',
|
|
568
|
+
'--json',
|
|
569
|
+
'--full',
|
|
570
|
+
],
|
|
571
|
+
fixtureLaunch.projectRoot,
|
|
572
|
+
undefined,
|
|
573
|
+
]);
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
it('refuses legacy launch replay when the original argv binding was not persisted', async () => {
|
|
577
|
+
await expect(
|
|
578
|
+
new OrcaExecutionBackend(fixtureRunner).replayStart(
|
|
579
|
+
fixtureAttempt({
|
|
580
|
+
state: 'outcome_unknown',
|
|
581
|
+
startRequestId: 'request-fixture',
|
|
582
|
+
startBinding: undefined,
|
|
583
|
+
}),
|
|
584
|
+
),
|
|
585
|
+
).rejects.toThrow('No replayable');
|
|
586
|
+
expect(fixtureRunner).not.toHaveBeenCalled();
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
it('does not adopt a different Dispatch from a replayed launch receipt', async () => {
|
|
590
|
+
orcaFixture.start = fixtureStart('ready', 0, 'ctx_other');
|
|
591
|
+
const result = await new OrcaExecutionBackend(fixtureRunner).replayStart(
|
|
592
|
+
fixtureAttempt({
|
|
593
|
+
state: 'outcome_unknown',
|
|
594
|
+
runId: 'run_fixture',
|
|
595
|
+
orcaTaskId: 'task_fixture',
|
|
596
|
+
dispatchId: 'ctx_fixture',
|
|
597
|
+
startRequestId: 'request-fixture',
|
|
598
|
+
}),
|
|
599
|
+
);
|
|
600
|
+
expect(result).toMatchObject({ state: 'outcome_unknown', dispatchId: 'ctx_fixture' });
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
it.each([
|
|
604
|
+
'issued',
|
|
605
|
+
'reserved',
|
|
606
|
+
])('adopts a pending successor for the %s request key without admitting ready', async (keyState) => {
|
|
607
|
+
const key = '00000000-0000-4000-8000-000000000001';
|
|
608
|
+
orcaFixture.request = fixtureReply({ state: 'pending', requestId: key });
|
|
609
|
+
orcaFixture.start = fixturePendingStart('ctx_retry', key);
|
|
610
|
+
const recovered = await new OrcaExecutionBackend(fixtureRunner).replayStart(
|
|
611
|
+
fixtureAttempt({
|
|
612
|
+
state: 'outcome_unknown',
|
|
613
|
+
runId: 'run_fixture',
|
|
614
|
+
orcaTaskId: 'task_fixture',
|
|
615
|
+
retryOf: 'ctx_fixture',
|
|
616
|
+
startRequestId: keyState === 'issued' ? key : null,
|
|
617
|
+
startRequestKey: keyState === 'reserved' ? key : undefined,
|
|
618
|
+
startBinding: {
|
|
619
|
+
runId: 'run_fixture',
|
|
620
|
+
orcaTaskId: 'task_fixture',
|
|
621
|
+
retryOf: 'ctx_fixture',
|
|
622
|
+
},
|
|
623
|
+
}),
|
|
624
|
+
);
|
|
625
|
+
expect(recovered).toMatchObject({
|
|
626
|
+
state: 'outcome_unknown',
|
|
627
|
+
resourceState: 'unknown',
|
|
628
|
+
dispatchId: 'ctx_retry',
|
|
629
|
+
runId: 'run_fixture',
|
|
630
|
+
orcaTaskId: 'task_fixture',
|
|
631
|
+
startRequestId: key,
|
|
632
|
+
lastReceipt: orcaFixture.start.stdout,
|
|
633
|
+
});
|
|
634
|
+
orcaFixture.show = fixtureShow('ctx_retry');
|
|
635
|
+
expect(await new OrcaExecutionBackend(fixtureRunner).show(recovered)).toMatchObject({
|
|
636
|
+
state: 'outcome_unknown',
|
|
637
|
+
resourceState: 'owned',
|
|
638
|
+
dispatchId: 'ctx_retry',
|
|
639
|
+
});
|
|
640
|
+
expect(fixtureRunner.mock.calls.filter(([, args]) => args[1] === 'worker-start')).toHaveLength(
|
|
641
|
+
1,
|
|
642
|
+
);
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
it.each([
|
|
646
|
+
'request',
|
|
647
|
+
'recovery_request',
|
|
648
|
+
'missing_request',
|
|
649
|
+
'missing_recovery_request',
|
|
650
|
+
'runtime',
|
|
651
|
+
'predecessor',
|
|
652
|
+
'dispatch',
|
|
653
|
+
'refusal',
|
|
654
|
+
])('does not adopt a pending refusal with a mismatched %s binding', async (mismatch) => {
|
|
655
|
+
const key = '00000000-0000-4000-8000-000000000001';
|
|
656
|
+
const reply = orcaReplySchema.parse(JSON.parse(fixturePendingStart('ctx_retry', key).stdout));
|
|
657
|
+
if (!reply.error?.data || !reply._meta) throw new Error('Missing pending refusal fixture');
|
|
658
|
+
if (mismatch === 'request') reply.error.data.requestId = 'other-request';
|
|
659
|
+
if (mismatch === 'recovery_request') reply.error.data.orchestrationRequestId = 'other-request';
|
|
660
|
+
if (mismatch === 'missing_request') delete reply.error.data.requestId;
|
|
661
|
+
if (mismatch === 'missing_recovery_request') delete reply.error.data.orchestrationRequestId;
|
|
662
|
+
if (mismatch === 'runtime') reply._meta.runtimeId = 'other-runtime';
|
|
663
|
+
if (mismatch === 'predecessor') reply.error.data.dispatchId = 'ctx_predecessor';
|
|
664
|
+
if (mismatch === 'refusal') reply.error.code = 'request_mismatch';
|
|
665
|
+
orcaFixture.start = { stdout: JSON.stringify(reply), stderr: '', exitCode: 1 };
|
|
666
|
+
orcaFixture.request = fixtureReply({ state: 'pending', requestId: key });
|
|
667
|
+
const dispatchId = mismatch === 'dispatch' ? 'ctx_original' : null;
|
|
668
|
+
const result = await new OrcaExecutionBackend(fixtureRunner).replayStart(
|
|
669
|
+
fixtureAttempt({
|
|
670
|
+
state: 'outcome_unknown',
|
|
671
|
+
runId: 'run_fixture',
|
|
672
|
+
orcaTaskId: 'task_fixture',
|
|
673
|
+
dispatchId,
|
|
674
|
+
retryOf: 'ctx_predecessor',
|
|
675
|
+
startRequestId: null,
|
|
676
|
+
startRequestKey: key,
|
|
677
|
+
startBinding: {
|
|
678
|
+
runId: 'run_fixture',
|
|
679
|
+
orcaTaskId: 'task_fixture',
|
|
680
|
+
retryOf: 'ctx_predecessor',
|
|
681
|
+
},
|
|
682
|
+
}),
|
|
683
|
+
);
|
|
684
|
+
expect(result).toMatchObject({
|
|
685
|
+
state: 'outcome_unknown',
|
|
686
|
+
resourceState: 'unknown',
|
|
687
|
+
dispatchId,
|
|
688
|
+
startRequestId: key,
|
|
689
|
+
});
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
it.each([
|
|
693
|
+
'owner',
|
|
694
|
+
'observation',
|
|
695
|
+
'terminal',
|
|
696
|
+
'release',
|
|
697
|
+
'state',
|
|
698
|
+
'none',
|
|
699
|
+
])('requires exact exited and released resource proof before retry eligibility (%s)', async (missing) => {
|
|
700
|
+
const reply = orcaReplySchema.parse(JSON.parse(fixtureReleasedShow().stdout));
|
|
701
|
+
const resource = reply.result?.projection?.resource;
|
|
702
|
+
const observation = reply.result?.observation;
|
|
703
|
+
if (!resource || !observation) throw new Error('Missing resource fixture');
|
|
704
|
+
if (missing === 'owner') resource.ownerDispatchId = 'ctx_other';
|
|
705
|
+
if (missing === 'observation') observation.exactWorker = false;
|
|
706
|
+
if (missing === 'terminal') resource.terminalState = 'release_unknown';
|
|
707
|
+
if (missing === 'release') resource.releaseState = 'release_unknown';
|
|
708
|
+
if (missing === 'state') resource.state = 'stopped';
|
|
709
|
+
orcaFixture.show = { stdout: JSON.stringify(reply), stderr: '', exitCode: 0 };
|
|
710
|
+
const result = await new OrcaExecutionBackend(fixtureRunner).show(
|
|
711
|
+
fixtureAttempt({
|
|
712
|
+
state: 'failed',
|
|
713
|
+
runId: 'run_fixture',
|
|
714
|
+
orcaTaskId: 'task_fixture',
|
|
715
|
+
dispatchId: 'ctx_fixture',
|
|
716
|
+
}),
|
|
717
|
+
);
|
|
718
|
+
expect(result.resourceState).toBe(missing === 'none' ? 'stopped' : 'unknown');
|
|
719
|
+
});
|
|
720
|
+
|
|
721
|
+
it.each([
|
|
722
|
+
'absent',
|
|
723
|
+
'wrong_request',
|
|
724
|
+
'wrong_runtime',
|
|
725
|
+
])('fences stop replay on %s without sending another cancellation', async (reason) => {
|
|
726
|
+
orcaFixture.request =
|
|
727
|
+
reason === 'wrong_runtime'
|
|
728
|
+
? {
|
|
729
|
+
stdout: JSON.stringify({
|
|
730
|
+
ok: true,
|
|
731
|
+
_meta: { runtimeId: 'other-runtime' },
|
|
732
|
+
result: { state: 'completed', requestId: 'request-fixture' },
|
|
733
|
+
}),
|
|
734
|
+
stderr: '',
|
|
735
|
+
exitCode: 0,
|
|
736
|
+
}
|
|
737
|
+
: fixtureReply({
|
|
738
|
+
state: reason === 'absent' ? 'absent' : 'completed',
|
|
739
|
+
requestId: reason === 'wrong_request' ? 'request-other' : 'request-fixture',
|
|
740
|
+
});
|
|
741
|
+
await expect(
|
|
742
|
+
new OrcaExecutionBackend(fixtureRunner).replayStop(
|
|
743
|
+
fixtureAttempt({
|
|
744
|
+
state: 'stop_unknown',
|
|
745
|
+
runId: 'run_fixture',
|
|
746
|
+
orcaTaskId: 'task_fixture',
|
|
747
|
+
dispatchId: 'ctx_fixture',
|
|
748
|
+
stopRequestId: 'request-fixture',
|
|
749
|
+
}),
|
|
750
|
+
),
|
|
751
|
+
).rejects.toThrow();
|
|
752
|
+
expect(fixtureRunner.mock.calls.some(([, args]) => args[1] === 'worker-stop')).toBe(false);
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
it('replays only the original cancellation request after a lost stop receipt', async () => {
|
|
756
|
+
orcaFixture.stop = {
|
|
757
|
+
stdout: JSON.stringify({
|
|
758
|
+
ok: false,
|
|
759
|
+
_meta: { runtimeId: fixtureContext.runtimeId },
|
|
760
|
+
error: {
|
|
761
|
+
code: 'runtime_timeout',
|
|
762
|
+
message: 'lost stop reply',
|
|
763
|
+
data: { orchestrationRequestId: 'request-fixture' },
|
|
764
|
+
},
|
|
765
|
+
}),
|
|
766
|
+
stderr: '',
|
|
767
|
+
exitCode: 1,
|
|
768
|
+
};
|
|
769
|
+
const unknown = await new OrcaExecutionBackend(fixtureRunner).stop(
|
|
770
|
+
fixtureAttempt({
|
|
771
|
+
state: 'stop_pending',
|
|
772
|
+
runId: 'run_fixture',
|
|
773
|
+
orcaTaskId: 'task_fixture',
|
|
774
|
+
dispatchId: 'ctx_fixture',
|
|
775
|
+
}),
|
|
776
|
+
);
|
|
777
|
+
expect(unknown).toMatchObject({ state: 'stop_unknown', stopRequestId: 'request-fixture' });
|
|
778
|
+
orcaFixture.stop = fixtureReply({
|
|
779
|
+
dispatchId: 'ctx_fixture',
|
|
780
|
+
state: 'stopped',
|
|
781
|
+
processAction: 'closed_agent_terminal',
|
|
782
|
+
helpers: [],
|
|
783
|
+
});
|
|
784
|
+
const recovered = await new OrcaExecutionBackend(fixtureRunner).replayStop(unknown);
|
|
785
|
+
expect(recovered).toMatchObject({ state: 'stopped', resourceState: 'stopped' });
|
|
786
|
+
const stops = fixtureRunner.mock.calls.filter(([, args]) => args[1] === 'worker-stop');
|
|
787
|
+
expect(stops[1]?.[1]).toEqual([
|
|
788
|
+
'orchestration',
|
|
789
|
+
'worker-stop',
|
|
790
|
+
'--dispatch',
|
|
791
|
+
'ctx_fixture',
|
|
792
|
+
'--retry-request',
|
|
793
|
+
'request-fixture',
|
|
794
|
+
'--environment',
|
|
795
|
+
'local',
|
|
796
|
+
'--json',
|
|
797
|
+
'--full',
|
|
798
|
+
]);
|
|
799
|
+
});
|
|
800
|
+
|
|
801
|
+
it('settles a durable stop_pending only from release proof plus affirmative helper evidence', async () => {
|
|
802
|
+
const pending = (lastReceipt: string | null): OrcaAttempt =>
|
|
803
|
+
fixtureAttempt({
|
|
804
|
+
state: 'stop_pending',
|
|
805
|
+
dispatchId: 'ctx_fixture',
|
|
806
|
+
orcaTaskId: 'task_fixture',
|
|
807
|
+
runId: 'run_fixture',
|
|
808
|
+
stopRequestKey: '4f7d2f8e-0000-4000-8000-000000000001',
|
|
809
|
+
lastReceipt,
|
|
810
|
+
});
|
|
811
|
+
const stopReceipt = fixtureReply({
|
|
812
|
+
dispatchId: 'ctx_fixture',
|
|
813
|
+
state: 'stopped',
|
|
814
|
+
processAction: 'closed_agent_terminal',
|
|
815
|
+
helpers: [],
|
|
816
|
+
mutation: { requestId: '4f7d2f8e-0000-4000-8000-000000000001', replayed: false },
|
|
817
|
+
}).stdout;
|
|
818
|
+
const backend = new OrcaExecutionBackend(fixtureRunner);
|
|
819
|
+
orcaFixture.show = fixtureReleasedShow();
|
|
820
|
+
expect(await backend.show(pending(stopReceipt))).toMatchObject({
|
|
821
|
+
state: 'stopped',
|
|
822
|
+
resourceState: 'stopped',
|
|
823
|
+
lastReceipt: orcaFixture.show.stdout,
|
|
824
|
+
});
|
|
825
|
+
// A lost receipt is not helper evidence: exact parent release alone never settles,
|
|
826
|
+
// and the record keeps whatever receipt it had for later recovery.
|
|
827
|
+
expect(await backend.show(pending(null))).toMatchObject({
|
|
828
|
+
state: 'stop_unknown',
|
|
829
|
+
resourceState: 'unknown',
|
|
830
|
+
lastReceipt: null,
|
|
831
|
+
});
|
|
832
|
+
// A non-stop receipt proves nothing about helpers either.
|
|
833
|
+
const startReceipt = fixtureStart().stdout;
|
|
834
|
+
expect(await backend.show(pending(startReceipt))).toMatchObject({
|
|
835
|
+
state: 'stop_unknown',
|
|
836
|
+
resourceState: 'unknown',
|
|
837
|
+
lastReceipt: startReceipt,
|
|
838
|
+
});
|
|
839
|
+
orcaFixture.show = fixtureShow();
|
|
840
|
+
expect(await backend.show(pending(stopReceipt))).toMatchObject({
|
|
841
|
+
state: 'stop_unknown',
|
|
842
|
+
resourceState: 'owned',
|
|
843
|
+
});
|
|
844
|
+
expect(
|
|
845
|
+
await backend.show(fixtureAttempt({ ...pending(stopReceipt), state: 'stop_unknown' })),
|
|
846
|
+
).toMatchObject({ state: 'stop_unknown' });
|
|
847
|
+
expect(fixtureRunner.mock.calls.some(([, args]) => args[1] === 'worker-stop')).toBe(false);
|
|
848
|
+
});
|
|
849
|
+
|
|
850
|
+
it('treats an omitted helper list as affirmative only when the stop recorded helper enumeration', async () => {
|
|
851
|
+
const pending = (stopHelperEvidence?: 'enumerated'): OrcaAttempt =>
|
|
852
|
+
fixtureAttempt({
|
|
853
|
+
state: 'stop_pending',
|
|
854
|
+
dispatchId: 'ctx_fixture',
|
|
855
|
+
orcaTaskId: 'task_fixture',
|
|
856
|
+
runId: 'run_fixture',
|
|
857
|
+
stopRequestKey: '4f7d2f8e-0000-4000-8000-000000000011',
|
|
858
|
+
// Installed Orca omits the list when the worker started no helper.
|
|
859
|
+
lastReceipt: fixtureReply({
|
|
860
|
+
dispatchId: 'ctx_fixture',
|
|
861
|
+
state: 'stopped',
|
|
862
|
+
processAction: 'closed_agent_terminal',
|
|
863
|
+
mutation: { requestId: '4f7d2f8e-0000-4000-8000-000000000011', replayed: false },
|
|
864
|
+
}).stdout,
|
|
865
|
+
stopHelperEvidence,
|
|
866
|
+
});
|
|
867
|
+
orcaFixture.show = fixtureReleasedShow();
|
|
868
|
+
const backend = new OrcaExecutionBackend(fixtureRunner);
|
|
869
|
+
expect(await backend.show(pending('enumerated'))).toMatchObject({
|
|
870
|
+
state: 'stopped',
|
|
871
|
+
resourceState: 'stopped',
|
|
872
|
+
});
|
|
873
|
+
// Without the stop-time proof an omitted list stays an unknown helper tree.
|
|
874
|
+
expect(await backend.show(pending())).toMatchObject({
|
|
875
|
+
state: 'stop_unknown',
|
|
876
|
+
resourceState: 'unknown',
|
|
877
|
+
});
|
|
878
|
+
});
|
|
879
|
+
|
|
880
|
+
it('records helper enumeration only when a capable stop reply omits the helper list', async () => {
|
|
881
|
+
const stop = (): OrcaAttempt =>
|
|
882
|
+
fixtureAttempt({
|
|
883
|
+
state: 'stop_pending',
|
|
884
|
+
dispatchId: 'ctx_fixture',
|
|
885
|
+
orcaTaskId: 'task_fixture',
|
|
886
|
+
runId: 'run_fixture',
|
|
887
|
+
stopRequestKey: '4f7d2f8e-0000-4000-8000-000000000012',
|
|
888
|
+
});
|
|
889
|
+
orcaFixture.stop = fixtureReply({
|
|
890
|
+
dispatchId: 'ctx_fixture',
|
|
891
|
+
state: 'stopped',
|
|
892
|
+
processAction: 'closed_agent_terminal',
|
|
893
|
+
});
|
|
894
|
+
const backend = new OrcaExecutionBackend(fixtureRunner);
|
|
895
|
+
expect(await backend.stop(stop())).toMatchObject({
|
|
896
|
+
state: 'stopped',
|
|
897
|
+
resourceState: 'stopped',
|
|
898
|
+
stopHelperEvidence: 'enumerated',
|
|
899
|
+
});
|
|
900
|
+
// A failed parent stop may still start helpers, so it never records enumeration.
|
|
901
|
+
orcaFixture.stop = fixtureReply({
|
|
902
|
+
dispatchId: 'ctx_fixture',
|
|
903
|
+
state: 'stop_unknown',
|
|
904
|
+
processAction: 'closed_agent_terminal',
|
|
905
|
+
});
|
|
906
|
+
expect((await backend.stop(stop())).stopHelperEvidence).toBeUndefined();
|
|
907
|
+
orcaFixture.stop = fixtureReply({
|
|
908
|
+
dispatchId: 'ctx_fixture',
|
|
909
|
+
state: 'stopped',
|
|
910
|
+
processAction: 'closed_agent_terminal',
|
|
911
|
+
});
|
|
912
|
+
orcaFixture.capabilities = ['orchestration.contract.v1'];
|
|
913
|
+
const unproven = await backend.stop(stop());
|
|
914
|
+
expect(unproven).toMatchObject({ state: 'stop_unknown', resourceState: 'unknown' });
|
|
915
|
+
expect(unproven.stopHelperEvidence).toBeUndefined();
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
it('replays a lost stop by its reserved key and fences a stop with neither key nor id', async () => {
|
|
919
|
+
const key = '4f7d2f8e-0000-4000-8000-000000000002';
|
|
920
|
+
const backend = new OrcaExecutionBackend(fixtureRunner);
|
|
921
|
+
orcaFixture.stop = {
|
|
922
|
+
stdout: JSON.stringify({
|
|
923
|
+
ok: false,
|
|
924
|
+
_meta: { runtimeId: fixtureContext.runtimeId },
|
|
925
|
+
error: { code: 'runtime_timeout', message: 'lost stop reply' },
|
|
926
|
+
}),
|
|
927
|
+
stderr: '',
|
|
928
|
+
exitCode: 1,
|
|
929
|
+
};
|
|
930
|
+
const unknown = await backend.stop(
|
|
931
|
+
fixtureAttempt({
|
|
932
|
+
state: 'stop_pending',
|
|
933
|
+
dispatchId: 'ctx_fixture',
|
|
934
|
+
orcaTaskId: 'task_fixture',
|
|
935
|
+
runId: 'run_fixture',
|
|
936
|
+
stopRequestKey: key,
|
|
937
|
+
}),
|
|
938
|
+
);
|
|
939
|
+
expect(unknown).toMatchObject({
|
|
940
|
+
state: 'stop_unknown',
|
|
941
|
+
stopRequestId: null,
|
|
942
|
+
stopRequestKey: key,
|
|
943
|
+
});
|
|
944
|
+
const [first] = fixtureRunner.mock.calls.filter(([, args]) => args[1] === 'worker-stop');
|
|
945
|
+
expect(first?.[1]).toEqual(expect.arrayContaining(['--retry-request', key]));
|
|
946
|
+
orcaFixture.request = fixtureReply({ state: 'absent', requestId: key });
|
|
947
|
+
orcaFixture.stop = fixtureReply({
|
|
948
|
+
dispatchId: 'ctx_fixture',
|
|
949
|
+
state: 'stopped',
|
|
950
|
+
processAction: 'closed_agent_terminal',
|
|
951
|
+
helpers: [],
|
|
952
|
+
});
|
|
953
|
+
const recovered = await backend.replayStop({ ...unknown, state: 'stop_pending' });
|
|
954
|
+
expect(recovered).toMatchObject({ state: 'stopped', resourceState: 'stopped' });
|
|
955
|
+
const stops = fixtureRunner.mock.calls.filter(([, args]) => args[1] === 'worker-stop');
|
|
956
|
+
expect(stops[1]?.[1]).toEqual(expect.arrayContaining(['--retry-request', key]));
|
|
957
|
+
await expect(
|
|
958
|
+
backend.replayStop(
|
|
959
|
+
fixtureAttempt({
|
|
960
|
+
state: 'stop_pending',
|
|
961
|
+
dispatchId: 'ctx_fixture',
|
|
962
|
+
orcaTaskId: 'task_fixture',
|
|
963
|
+
runId: 'run_fixture',
|
|
964
|
+
}),
|
|
965
|
+
),
|
|
966
|
+
).rejects.toThrow('No replayable');
|
|
967
|
+
});
|
|
968
|
+
|
|
969
|
+
it('retains an unknown receipt when workspace or effective harness is unproven', async () => {
|
|
970
|
+
orcaFixture.start = fixtureReply({
|
|
971
|
+
state: 'ready',
|
|
972
|
+
dispatchId: 'ctx_other',
|
|
973
|
+
taskId: 'task_other',
|
|
974
|
+
runId: 'run_other',
|
|
975
|
+
effects: [{ kind: 'worktree', id: 'other-workspace' }],
|
|
976
|
+
});
|
|
977
|
+
const result = await new OrcaExecutionBackend(fixtureRunner).start(fixtureAttempt());
|
|
978
|
+
expect(result).toMatchObject({
|
|
979
|
+
state: 'outcome_unknown',
|
|
980
|
+
dispatchId: 'ctx_other',
|
|
981
|
+
lastReceipt: orcaFixture.start.stdout,
|
|
982
|
+
});
|
|
983
|
+
});
|
|
984
|
+
|
|
985
|
+
it('pins observations to Dispatch, Run, Task, runtime and workspace after restart', async () => {
|
|
986
|
+
const attempt = fixtureAttempt({
|
|
987
|
+
state: 'ready',
|
|
988
|
+
dispatchId: 'ctx_fixture',
|
|
989
|
+
orcaTaskId: 'task_fixture',
|
|
990
|
+
runId: 'run_fixture',
|
|
991
|
+
});
|
|
992
|
+
orcaFixture.show = fixtureShow('ctx_other');
|
|
993
|
+
await expect(new OrcaExecutionBackend(fixtureRunner).show(attempt)).rejects.toThrow(
|
|
994
|
+
'does not match',
|
|
995
|
+
);
|
|
996
|
+
orcaFixture.show = fixtureShow('ctx_fixture', 3);
|
|
997
|
+
expect(await new OrcaExecutionBackend(fixtureRunner).show(attempt)).toMatchObject({
|
|
998
|
+
state: 'circuit_broken',
|
|
999
|
+
failureCount: 3,
|
|
1000
|
+
});
|
|
1001
|
+
});
|
|
1002
|
+
|
|
1003
|
+
it('preserves stop_unknown even when Orca issued a terminal close', async () => {
|
|
1004
|
+
const backend = new OrcaExecutionBackend(fixtureRunner);
|
|
1005
|
+
const stopped = await backend.stop(
|
|
1006
|
+
fixtureAttempt({
|
|
1007
|
+
state: 'stop_pending',
|
|
1008
|
+
dispatchId: 'ctx_fixture',
|
|
1009
|
+
orcaTaskId: 'task_fixture',
|
|
1010
|
+
runId: 'run_fixture',
|
|
1011
|
+
}),
|
|
1012
|
+
);
|
|
1013
|
+
expect(stopped).toMatchObject({ state: 'stop_unknown', resourceState: 'unknown' });
|
|
1014
|
+
orcaFixture.show = fixtureShow('ctx_fixture', 3);
|
|
1015
|
+
expect((await backend.show(stopped)).state).toBe('stop_unknown');
|
|
1016
|
+
await expect(backend.stop(stopped)).rejects.toThrow('reserved');
|
|
1017
|
+
const stop = fixtureRunner.mock.calls.find(([, args]) => args[1] === 'worker-stop')?.[1];
|
|
1018
|
+
expect(stop).toEqual([
|
|
1019
|
+
'orchestration',
|
|
1020
|
+
'worker-stop',
|
|
1021
|
+
'--dispatch',
|
|
1022
|
+
'ctx_fixture',
|
|
1023
|
+
'--environment',
|
|
1024
|
+
'local',
|
|
1025
|
+
'--json',
|
|
1026
|
+
'--full',
|
|
1027
|
+
]);
|
|
1028
|
+
});
|
|
1029
|
+
|
|
1030
|
+
it('reads a bounded source-pinned page without consuming coordinator mail', async () => {
|
|
1031
|
+
const raw = await new OrcaExecutionBackend(fixtureRunner).read(
|
|
1032
|
+
fixtureAttempt({
|
|
1033
|
+
state: 'ready',
|
|
1034
|
+
dispatchId: 'ctx_fixture',
|
|
1035
|
+
orcaTaskId: 'task_fixture',
|
|
1036
|
+
runId: 'run_fixture',
|
|
1037
|
+
}),
|
|
1038
|
+
'exact-cursor',
|
|
1039
|
+
);
|
|
1040
|
+
expect(raw).toBe(orcaFixture.read.stdout);
|
|
1041
|
+
const args = fixtureRunner.mock.calls.at(-1)?.[1];
|
|
1042
|
+
expect(args).toEqual([
|
|
1043
|
+
'orchestration',
|
|
1044
|
+
'worker-read',
|
|
1045
|
+
'--dispatch',
|
|
1046
|
+
'ctx_fixture',
|
|
1047
|
+
'--source',
|
|
1048
|
+
'auto',
|
|
1049
|
+
'--limit',
|
|
1050
|
+
'200',
|
|
1051
|
+
'--cursor',
|
|
1052
|
+
'exact-cursor',
|
|
1053
|
+
'--environment',
|
|
1054
|
+
'local',
|
|
1055
|
+
'--json',
|
|
1056
|
+
'--full',
|
|
1057
|
+
]);
|
|
1058
|
+
});
|
|
1059
|
+
|
|
1060
|
+
it('treats kept-open or unconfirmed helpers as unresolved cancellation', async () => {
|
|
1061
|
+
orcaFixture.stop = fixtureReply({
|
|
1062
|
+
dispatchId: 'ctx_fixture',
|
|
1063
|
+
state: 'stopped',
|
|
1064
|
+
processAction: 'closed_agent_terminal',
|
|
1065
|
+
helpers: [{ outcome: 'kept_open' }],
|
|
1066
|
+
});
|
|
1067
|
+
const attempt = fixtureAttempt({
|
|
1068
|
+
state: 'stop_pending',
|
|
1069
|
+
dispatchId: 'ctx_fixture',
|
|
1070
|
+
orcaTaskId: 'task_fixture',
|
|
1071
|
+
runId: 'run_fixture',
|
|
1072
|
+
});
|
|
1073
|
+
expect((await new OrcaExecutionBackend(fixtureRunner).stop(attempt)).state).toBe(
|
|
1074
|
+
'stop_unknown',
|
|
1075
|
+
);
|
|
1076
|
+
orcaFixture.stop = fixtureReply({
|
|
1077
|
+
dispatchId: 'ctx_fixture',
|
|
1078
|
+
state: 'stopped',
|
|
1079
|
+
processAction: 'closed_agent_terminal',
|
|
1080
|
+
helpers: [],
|
|
1081
|
+
});
|
|
1082
|
+
expect((await new OrcaExecutionBackend(fixtureRunner).stop(attempt)).state).toBe('stopped');
|
|
1083
|
+
});
|
|
1084
|
+
|
|
1085
|
+
it('does not settle a released parent while its stop receipt leaves a helper unresolved', async () => {
|
|
1086
|
+
const backend = new OrcaExecutionBackend(fixtureRunner);
|
|
1087
|
+
const stopReceipt = (helpers: string[], helperStopError?: string): string =>
|
|
1088
|
+
fixtureReply({
|
|
1089
|
+
dispatchId: 'ctx_fixture',
|
|
1090
|
+
state: 'stopped',
|
|
1091
|
+
processAction: 'closed_agent_terminal',
|
|
1092
|
+
helpers: helpers.map((outcome) => ({ outcome })),
|
|
1093
|
+
mutation: { requestId: '4f7d2f8e-0000-4000-8000-000000000003', replayed: false },
|
|
1094
|
+
...(helperStopError ? { helperStopError } : {}),
|
|
1095
|
+
}).stdout;
|
|
1096
|
+
orcaFixture.show = fixtureReleasedShow();
|
|
1097
|
+
const pending = (lastReceipt: string): OrcaAttempt =>
|
|
1098
|
+
fixtureAttempt({
|
|
1099
|
+
state: 'stop_pending',
|
|
1100
|
+
dispatchId: 'ctx_fixture',
|
|
1101
|
+
orcaTaskId: 'task_fixture',
|
|
1102
|
+
runId: 'run_fixture',
|
|
1103
|
+
stopRequestKey: '4f7d2f8e-0000-4000-8000-000000000003',
|
|
1104
|
+
lastReceipt,
|
|
1105
|
+
});
|
|
1106
|
+
for (const unresolved of [
|
|
1107
|
+
stopReceipt(['kept_open']),
|
|
1108
|
+
stopReceipt(['unconfirmed']),
|
|
1109
|
+
stopReceipt([], 'helper stop error'),
|
|
1110
|
+
]) {
|
|
1111
|
+
expect(await backend.show(pending(unresolved))).toMatchObject({
|
|
1112
|
+
state: 'stop_unknown',
|
|
1113
|
+
resourceState: 'unknown',
|
|
1114
|
+
lastReceipt: unresolved,
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
expect(fixtureRunner.mock.calls.some(([, args]) => args[1] === 'worker-stop')).toBe(false);
|
|
1118
|
+
});
|
|
1119
|
+
|
|
1120
|
+
it('settles a stop once its kept-open helper finishes later, without replaying the stop', async () => {
|
|
1121
|
+
const helper = 'ctx_helper';
|
|
1122
|
+
const backend = new OrcaExecutionBackend(fixtureRunner);
|
|
1123
|
+
const stopReceipt = fixtureReply({
|
|
1124
|
+
dispatchId: 'ctx_fixture',
|
|
1125
|
+
state: 'stopped',
|
|
1126
|
+
processAction: 'closed_agent_terminal',
|
|
1127
|
+
helpers: [
|
|
1128
|
+
{
|
|
1129
|
+
dispatchId: helper,
|
|
1130
|
+
creatorDispatchId: 'ctx_fixture',
|
|
1131
|
+
outcome: 'kept_open',
|
|
1132
|
+
state: 'ready',
|
|
1133
|
+
},
|
|
1134
|
+
],
|
|
1135
|
+
mutation: { requestId: '4f7d2f8e-0000-4000-8000-000000000003', replayed: false },
|
|
1136
|
+
}).stdout;
|
|
1137
|
+
const pending = (lastReceipt: string): OrcaAttempt =>
|
|
1138
|
+
fixtureAttempt({
|
|
1139
|
+
state: 'stop_pending',
|
|
1140
|
+
dispatchId: 'ctx_fixture',
|
|
1141
|
+
orcaTaskId: 'task_fixture',
|
|
1142
|
+
runId: 'run_fixture',
|
|
1143
|
+
stopRequestKey: '4f7d2f8e-0000-4000-8000-000000000003',
|
|
1144
|
+
lastReceipt,
|
|
1145
|
+
});
|
|
1146
|
+
orcaFixture.show = fixtureReleasedShow();
|
|
1147
|
+
orcaFixture.helperShows = { [helper]: fixtureShow(helper) };
|
|
1148
|
+
expect(await backend.show(pending(stopReceipt))).toMatchObject({
|
|
1149
|
+
state: 'stop_unknown',
|
|
1150
|
+
resourceState: 'unknown',
|
|
1151
|
+
lastReceipt: stopReceipt,
|
|
1152
|
+
});
|
|
1153
|
+
// The completed stop key would replay the same kept-open outcome forever, so the
|
|
1154
|
+
// helper's own current state settles the stop instead.
|
|
1155
|
+
orcaFixture.helperShows = { [helper]: fixtureHelperExited(helper) };
|
|
1156
|
+
expect(await backend.show(pending(stopReceipt))).toMatchObject({
|
|
1157
|
+
state: 'stopped',
|
|
1158
|
+
resourceState: 'stopped',
|
|
1159
|
+
lastReceipt: orcaFixture.show.stdout,
|
|
1160
|
+
});
|
|
1161
|
+
expect(
|
|
1162
|
+
fixtureRunner.mock.calls.some(
|
|
1163
|
+
([, args]) => args[1] === 'worker-show' && args.includes(helper),
|
|
1164
|
+
),
|
|
1165
|
+
).toBe(true);
|
|
1166
|
+
expect(fixtureRunner.mock.calls.some(([, args]) => args[1] === 'worker-stop')).toBe(false);
|
|
1167
|
+
});
|
|
1168
|
+
|
|
1169
|
+
it('ignores a stop receipt that belongs to another dispatch, run or request key', async () => {
|
|
1170
|
+
const backend = new OrcaExecutionBackend(fixtureRunner);
|
|
1171
|
+
orcaFixture.show = fixtureReleasedShow();
|
|
1172
|
+
const pending = (lastReceipt: string): OrcaAttempt =>
|
|
1173
|
+
fixtureAttempt({
|
|
1174
|
+
state: 'stop_pending',
|
|
1175
|
+
dispatchId: 'ctx_fixture',
|
|
1176
|
+
orcaTaskId: 'task_fixture',
|
|
1177
|
+
runId: 'run_fixture',
|
|
1178
|
+
stopRequestKey: '4f7d2f8e-0000-4000-8000-000000000031',
|
|
1179
|
+
lastReceipt,
|
|
1180
|
+
});
|
|
1181
|
+
const stopReply = (overrides: Partial<NonNullable<OrcaReply['result']>> = {}): string =>
|
|
1182
|
+
fixtureReply({
|
|
1183
|
+
dispatchId: 'ctx_fixture',
|
|
1184
|
+
state: 'stopped',
|
|
1185
|
+
processAction: 'closed_agent_terminal',
|
|
1186
|
+
helpers: [],
|
|
1187
|
+
mutation: { requestId: '4f7d2f8e-0000-4000-8000-000000000031', replayed: false },
|
|
1188
|
+
...overrides,
|
|
1189
|
+
}).stdout;
|
|
1190
|
+
const foreign = [
|
|
1191
|
+
// Another Dispatch in the same Run.
|
|
1192
|
+
stopReply({ dispatchId: 'ctx_other' }),
|
|
1193
|
+
// The same Dispatch id, but another Run.
|
|
1194
|
+
stopReply({ runId: 'run_other' }),
|
|
1195
|
+
// This Dispatch refused under a stop key this attempt never issued.
|
|
1196
|
+
JSON.stringify({
|
|
1197
|
+
ok: false,
|
|
1198
|
+
_meta: { runtimeId: fixtureContext.runtimeId },
|
|
1199
|
+
error: {
|
|
1200
|
+
code: 'operation_unknown',
|
|
1201
|
+
message: 'another attempt cancelled this Dispatch',
|
|
1202
|
+
data: {
|
|
1203
|
+
dispatchId: 'ctx_fixture',
|
|
1204
|
+
orchestrationRequestId: '4f7d2f8e-0000-4000-8000-000000000032',
|
|
1205
|
+
},
|
|
1206
|
+
},
|
|
1207
|
+
}),
|
|
1208
|
+
// This Dispatch stopped successfully under a stop key this attempt never issued.
|
|
1209
|
+
stopReply({
|
|
1210
|
+
mutation: { requestId: '4f7d2f8e-0000-4000-8000-000000000032', replayed: false },
|
|
1211
|
+
}),
|
|
1212
|
+
// This Dispatch stopped on another runtime epoch.
|
|
1213
|
+
JSON.stringify({
|
|
1214
|
+
ok: true,
|
|
1215
|
+
_meta: { runtimeId: 'runtime-other' },
|
|
1216
|
+
result: {
|
|
1217
|
+
dispatchId: 'ctx_fixture',
|
|
1218
|
+
state: 'stopped',
|
|
1219
|
+
processAction: 'closed_agent_terminal',
|
|
1220
|
+
helpers: [],
|
|
1221
|
+
mutation: { requestId: '4f7d2f8e-0000-4000-8000-000000000031', replayed: false },
|
|
1222
|
+
},
|
|
1223
|
+
}),
|
|
1224
|
+
];
|
|
1225
|
+
for (const receipt of foreign) {
|
|
1226
|
+
expect(await backend.show(pending(receipt))).toMatchObject({
|
|
1227
|
+
state: 'stop_unknown',
|
|
1228
|
+
resourceState: 'unknown',
|
|
1229
|
+
lastReceipt: receipt,
|
|
1230
|
+
});
|
|
1231
|
+
// Repeated reads never promote a mismatched receipt by a later release.
|
|
1232
|
+
expect(await backend.show(pending(receipt))).toMatchObject({ state: 'stop_unknown' });
|
|
1233
|
+
}
|
|
1234
|
+
expect(fixtureRunner.mock.calls.some(([, args]) => args[1] === 'worker-stop')).toBe(false);
|
|
1235
|
+
});
|
|
1236
|
+
|
|
1237
|
+
it('does not settle a stop from an exited helper that another Dispatch created', async () => {
|
|
1238
|
+
const helper = 'ctx_unrelated';
|
|
1239
|
+
const backend = new OrcaExecutionBackend(fixtureRunner);
|
|
1240
|
+
const stopReceipt = fixtureReply({
|
|
1241
|
+
dispatchId: 'ctx_fixture',
|
|
1242
|
+
state: 'stopped',
|
|
1243
|
+
processAction: 'closed_agent_terminal',
|
|
1244
|
+
helpers: [
|
|
1245
|
+
{
|
|
1246
|
+
dispatchId: helper,
|
|
1247
|
+
creatorDispatchId: 'ctx_other',
|
|
1248
|
+
outcome: 'kept_open',
|
|
1249
|
+
state: 'ready',
|
|
1250
|
+
},
|
|
1251
|
+
],
|
|
1252
|
+
mutation: { requestId: '4f7d2f8e-0000-4000-8000-000000000033', replayed: false },
|
|
1253
|
+
}).stdout;
|
|
1254
|
+
const pending = (lastReceipt: string): OrcaAttempt =>
|
|
1255
|
+
fixtureAttempt({
|
|
1256
|
+
state: 'stop_pending',
|
|
1257
|
+
dispatchId: 'ctx_fixture',
|
|
1258
|
+
orcaTaskId: 'task_fixture',
|
|
1259
|
+
runId: 'run_fixture',
|
|
1260
|
+
stopRequestKey: '4f7d2f8e-0000-4000-8000-000000000033',
|
|
1261
|
+
lastReceipt,
|
|
1262
|
+
});
|
|
1263
|
+
orcaFixture.show = fixtureReleasedShow();
|
|
1264
|
+
// The helper exited, but its creator chain never reaches this worker.
|
|
1265
|
+
orcaFixture.helperShows = {
|
|
1266
|
+
[helper]: fixtureHelperExited(helper, 'ctx_other'),
|
|
1267
|
+
ctx_other: fixtureShow('ctx_other'),
|
|
1268
|
+
};
|
|
1269
|
+
expect(await backend.show(pending(stopReceipt))).toMatchObject({
|
|
1270
|
+
state: 'stop_unknown',
|
|
1271
|
+
resourceState: 'unknown',
|
|
1272
|
+
lastReceipt: stopReceipt,
|
|
1273
|
+
});
|
|
1274
|
+
// A nested helper whose chain does reach this worker still settles the stop.
|
|
1275
|
+
const nested = 'ctx_nested';
|
|
1276
|
+
orcaFixture.helperShows = {
|
|
1277
|
+
[nested]: fixtureHelperExited(nested, helper),
|
|
1278
|
+
[helper]: fixtureShow(helper, 0, 'ctx_fixture'),
|
|
1279
|
+
};
|
|
1280
|
+
expect(
|
|
1281
|
+
await backend.show(
|
|
1282
|
+
pending(
|
|
1283
|
+
fixtureReply({
|
|
1284
|
+
dispatchId: 'ctx_fixture',
|
|
1285
|
+
state: 'stopped',
|
|
1286
|
+
processAction: 'closed_agent_terminal',
|
|
1287
|
+
helpers: [
|
|
1288
|
+
{
|
|
1289
|
+
dispatchId: nested,
|
|
1290
|
+
creatorDispatchId: helper,
|
|
1291
|
+
outcome: 'kept_open',
|
|
1292
|
+
state: 'ready',
|
|
1293
|
+
},
|
|
1294
|
+
],
|
|
1295
|
+
mutation: { requestId: '4f7d2f8e-0000-4000-8000-000000000033', replayed: false },
|
|
1296
|
+
}).stdout,
|
|
1297
|
+
),
|
|
1298
|
+
),
|
|
1299
|
+
).toMatchObject({ state: 'stopped', resourceState: 'stopped' });
|
|
1300
|
+
});
|
|
1301
|
+
|
|
1302
|
+
it('records helper enumeration only from a proven stop reply from this exact runtime', async () => {
|
|
1303
|
+
const stop = (): OrcaAttempt =>
|
|
1304
|
+
fixtureAttempt({
|
|
1305
|
+
state: 'stop_pending',
|
|
1306
|
+
dispatchId: 'ctx_fixture',
|
|
1307
|
+
orcaTaskId: 'task_fixture',
|
|
1308
|
+
runId: 'run_fixture',
|
|
1309
|
+
stopRequestKey: '4f7d2f8e-0000-4000-8000-000000000034',
|
|
1310
|
+
});
|
|
1311
|
+
const backend = new OrcaExecutionBackend(fixtureRunner);
|
|
1312
|
+
const stoppedReply = {
|
|
1313
|
+
dispatchId: 'ctx_fixture',
|
|
1314
|
+
state: 'stopped',
|
|
1315
|
+
processAction: 'closed_agent_terminal',
|
|
1316
|
+
};
|
|
1317
|
+
// A refused reply that still carried a stopped result never proves enumeration.
|
|
1318
|
+
orcaFixture.stop = {
|
|
1319
|
+
stdout: JSON.stringify({
|
|
1320
|
+
ok: false,
|
|
1321
|
+
_meta: { runtimeId: fixtureContext.runtimeId },
|
|
1322
|
+
this: 'not-a-reply-field',
|
|
1323
|
+
result: stoppedReply,
|
|
1324
|
+
}),
|
|
1325
|
+
stderr: '',
|
|
1326
|
+
exitCode: 1,
|
|
1327
|
+
};
|
|
1328
|
+
// Unparseable extras are ignored by the wire schema, so the refusal alone must not mint.
|
|
1329
|
+
expect((await backend.stop(stop())).stopHelperEvidence).toBeUndefined();
|
|
1330
|
+
// Another runtime epoch is not this attempt's proof.
|
|
1331
|
+
orcaFixture.stop = {
|
|
1332
|
+
stdout: JSON.stringify({
|
|
1333
|
+
ok: true,
|
|
1334
|
+
_meta: { runtimeId: 'runtime-other' },
|
|
1335
|
+
result: stoppedReply,
|
|
1336
|
+
}),
|
|
1337
|
+
stderr: '',
|
|
1338
|
+
exitCode: 0,
|
|
1339
|
+
};
|
|
1340
|
+
expect(await backend.stop(stop())).toMatchObject({
|
|
1341
|
+
state: 'stop_unknown',
|
|
1342
|
+
stopHelperEvidence: undefined,
|
|
1343
|
+
});
|
|
1344
|
+
// A reply for another Dispatch is not this attempt's proof either.
|
|
1345
|
+
orcaFixture.stop = fixtureReply({ ...stoppedReply, dispatchId: 'ctx_other' });
|
|
1346
|
+
expect(await backend.stop(stop())).toMatchObject({
|
|
1347
|
+
state: 'stop_unknown',
|
|
1348
|
+
stopHelperEvidence: undefined,
|
|
1349
|
+
});
|
|
1350
|
+
// Only the exact runtime, Dispatch and stopped parent records enumeration.
|
|
1351
|
+
orcaFixture.stop = fixtureReply(stoppedReply);
|
|
1352
|
+
expect(await backend.stop(stop())).toMatchObject({
|
|
1353
|
+
state: 'stopped',
|
|
1354
|
+
stopHelperEvidence: 'enumerated',
|
|
1355
|
+
});
|
|
1356
|
+
});
|
|
1357
|
+
});
|