mixdog 0.9.47 → 0.9.50
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 +6 -6
- package/package.json +19 -9
- package/scripts/agent-parallel-smoke.mjs +4 -1
- package/scripts/agent-route-batch-test.mjs +40 -0
- package/scripts/code-graph-aggregate-cwd-test.mjs +154 -0
- package/scripts/code-graph-description-contract.mjs +185 -0
- package/scripts/code-graph-disk-hit-test.mjs +55 -0
- package/scripts/code-graph-dispatch-test.mjs +96 -0
- package/scripts/compact-pressure-test.mjs +40 -0
- package/scripts/deferred-tool-loading-test.mjs +233 -0
- package/scripts/embedding-worker-exit-test.mjs +76 -0
- package/scripts/execution-completion-dedup-test.mjs +48 -0
- package/scripts/explore-prompt-policy-test.mjs +88 -3
- package/scripts/live-worker-smoke.mjs +68 -16
- package/scripts/memory-core-input-test.mjs +33 -13
- package/scripts/native-edit-wire-test.mjs +152 -0
- package/scripts/openai-oauth-ws-1006-retry-test.mjs +294 -16
- package/scripts/patch-binary-cache-test.mjs +181 -0
- package/scripts/prompt-immediate-render-test.mjs +89 -0
- package/scripts/provider-toolcall-test.mjs +280 -15
- package/scripts/shell-failure-diagnostics-test.mjs +211 -0
- package/scripts/smoke-loop.mjs +9 -3
- package/scripts/smoke.mjs +5 -106
- package/scripts/statusline-quota-hysteresis-test.mjs +26 -1
- package/scripts/streaming-tail-window-test.mjs +29 -0
- package/scripts/tool-failures.mjs +21 -3
- package/scripts/tool-smoke.mjs +263 -38
- package/scripts/tool-tui-presentation-test.mjs +17 -1
- package/scripts/tui-perf-run.ps1 +26 -0
- package/scripts/tui-transcript-perf-test.mjs +7 -1
- package/scripts/verify-release-assets-test.mjs +281 -0
- package/scripts/verify-release-assets.mjs +293 -0
- package/scripts/windows-hide-spawn-options-test.mjs +19 -0
- package/src/cli.mjs +1 -0
- package/src/runtime/agent/orchestrator/agent-trace-format.mjs +16 -5
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +35 -11
- package/src/runtime/agent/orchestrator/providers/anthropic.mjs +35 -11
- package/src/runtime/agent/orchestrator/providers/custom-tool-wire.mjs +28 -0
- package/src/runtime/agent/orchestrator/providers/openai-compat-wire.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +34 -34
- package/src/runtime/agent/orchestrator/providers/openai-oauth.mjs +45 -38
- package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +36 -11
- package/src/runtime/agent/orchestrator/providers/retry-classifier.mjs +4 -4
- package/src/runtime/agent/orchestrator/session/eager-dispatch.mjs +10 -6
- package/src/runtime/agent/orchestrator/session/loop/deferred-call-through.mjs +4 -3
- package/src/runtime/agent/orchestrator/session/loop/recall-fasttrack.mjs +4 -3
- package/src/runtime/agent/orchestrator/session/loop/tool-helpers.mjs +16 -1
- package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +0 -1
- package/src/runtime/agent/orchestrator/session/tool-batch.mjs +13 -8
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +30 -16
- package/src/runtime/agent/orchestrator/tools/code-graph/build.mjs +25 -8
- package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +69 -4
- package/src/runtime/agent/orchestrator/tools/code-graph-prewarm-worker.mjs +5 -4
- package/src/runtime/agent/orchestrator/tools/code-graph-tool-defs.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/graph-manifest.json +12 -12
- package/src/runtime/agent/orchestrator/tools/patch/native-server.mjs +12 -7
- package/src/runtime/agent/orchestrator/tools/patch-binary-fetcher.mjs +77 -18
- package/src/runtime/agent/orchestrator/tools/patch-manifest.json +11 -11
- package/src/runtime/agent/orchestrator/tools/shell-command.mjs +99 -24
- package/src/runtime/memory/lib/embedding-provider.mjs +3 -2
- package/src/runtime/memory/lib/memory-action-handlers.mjs +21 -11
- package/src/runtime/memory/tool-defs.mjs +1 -2
- package/src/session-runtime/context-status.mjs +25 -16
- package/src/session-runtime/model-route-api.mjs +2 -0
- package/src/session-runtime/runtime-core.mjs +2 -2
- package/src/session-runtime/session-turn-api.mjs +4 -1
- package/src/session-runtime/tool-catalog.mjs +113 -19
- package/src/session-runtime/tool-defs.mjs +1 -0
- package/src/standalone/agent-tool/helpers.mjs +25 -6
- package/src/standalone/agent-tool.mjs +75 -41
- package/src/tui/App.jsx +4 -0
- package/src/tui/app/input-parsers.mjs +8 -9
- package/src/tui/components/Markdown.jsx +6 -1
- package/src/tui/components/Message.jsx +11 -2
- package/src/tui/components/PromptInput.jsx +19 -21
- package/src/tui/components/Spinner.jsx +4 -4
- package/src/tui/components/StatusLine.jsx +6 -6
- package/src/tui/components/TranscriptItem.jsx +2 -2
- package/src/tui/components/prompt-input/immediate-render.mjs +47 -0
- package/src/tui/components/tool-execution/surface-detail.mjs +14 -9
- package/src/tui/dist/index.mjs +130 -45
- package/src/tui/engine/agent-job-feed.mjs +21 -2
- package/src/tui/engine/turn.mjs +12 -1
- package/src/tui/markdown/measure-rendered-rows.mjs +1 -1
- package/src/tui/markdown/streaming-markdown.mjs +20 -0
- package/src/ui/statusline.mjs +5 -5
- package/src/vendor/statusline/src/gateway/session-routes.mjs +22 -10
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import test from 'node:test';
|
|
3
3
|
import assert from 'node:assert/strict';
|
|
4
4
|
import { OpenAIOAuthProvider } from '../src/runtime/agent/orchestrator/providers/openai-oauth.mjs';
|
|
5
|
-
import { sendViaWebSocket } from '../src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs';
|
|
5
|
+
import { _acquireWithRetry, sendViaWebSocket } from '../src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs';
|
|
6
|
+
import { _sendFrame } from '../src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs';
|
|
6
7
|
|
|
7
8
|
function close1006() {
|
|
8
9
|
const err = new Error('WebSocket closed abnormally');
|
|
@@ -27,28 +28,153 @@ function wsArgs(overrides = {}) {
|
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
test('acquire timeout reconnects successfully with progress, not a terminal WS error', async () => {
|
|
32
|
+
const oldWrite = process.stderr.write;
|
|
33
|
+
const oldQuiet = process.env.MIXDOG_QUIET_PROVIDER_LOG;
|
|
34
|
+
let stderr = '';
|
|
35
|
+
let attempts = 0;
|
|
36
|
+
const stages = [];
|
|
37
|
+
try {
|
|
38
|
+
delete process.env.MIXDOG_QUIET_PROVIDER_LOG;
|
|
39
|
+
process.stderr.write = (chunk) => {
|
|
40
|
+
stderr += String(chunk);
|
|
41
|
+
return true;
|
|
42
|
+
};
|
|
43
|
+
const result = await sendViaWebSocket(wsArgs({
|
|
44
|
+
onStageChange: (stage, detail) => stages.push({ stage, detail }),
|
|
45
|
+
_acquireWithRetryFn: (opts) => _acquireWithRetry({
|
|
46
|
+
...opts,
|
|
47
|
+
maxAttempts: 2,
|
|
48
|
+
_sleepFn: async () => {},
|
|
49
|
+
_acquire: async () => {
|
|
50
|
+
attempts += 1;
|
|
51
|
+
if (attempts === 1) {
|
|
52
|
+
throw Object.assign(new Error('OpenAI OAuth WS acquire timed out before open'), {
|
|
53
|
+
code: 'EWSACQUIRETIMEOUT',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return { entry: entry(), reused: false };
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
_streamFn: async () => ({
|
|
60
|
+
content: 'recovered',
|
|
61
|
+
model: 'gpt-5.5',
|
|
62
|
+
toolCalls: [],
|
|
63
|
+
usage: {},
|
|
64
|
+
closeSocket: true,
|
|
65
|
+
}),
|
|
66
|
+
}));
|
|
67
|
+
assert.equal(result.content, 'recovered');
|
|
68
|
+
assert.equal(attempts, 2);
|
|
69
|
+
assert.deepEqual(
|
|
70
|
+
stages.filter(({ stage }) => stage === 'reconnecting'),
|
|
71
|
+
[{ stage: 'reconnecting', detail: {
|
|
72
|
+
attempt: 1,
|
|
73
|
+
max: 1,
|
|
74
|
+
classifier: 'acquire_timeout',
|
|
75
|
+
message: 'Reconnecting... 1/1',
|
|
76
|
+
} }],
|
|
77
|
+
);
|
|
78
|
+
assert.doesNotMatch(stderr, /Reconnecting/);
|
|
79
|
+
assert.doesNotMatch(stderr, /acquire timed out|handshake failed|terminal/i);
|
|
80
|
+
} finally {
|
|
81
|
+
process.stderr.write = oldWrite;
|
|
82
|
+
if (oldQuiet == null) delete process.env.MIXDOG_QUIET_PROVIDER_LOG;
|
|
83
|
+
else process.env.MIXDOG_QUIET_PROVIDER_LOG = oldQuiet;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
for (const failure of ['callback error', 'callback timeout']) {
|
|
88
|
+
test(`send ${failure} drops the socket and retries on a fresh one`, async () => {
|
|
89
|
+
const acquires = [];
|
|
90
|
+
const sockets = [];
|
|
91
|
+
let acquireIndex = 0;
|
|
92
|
+
const result = await sendViaWebSocket(wsArgs({
|
|
93
|
+
_acquireWithRetryFn: async (opts) => {
|
|
94
|
+
acquires.push(opts.forceFresh);
|
|
95
|
+
const isFirst = acquireIndex++ === 0;
|
|
96
|
+
const socket = {
|
|
97
|
+
readyState: 1,
|
|
98
|
+
terminated: false,
|
|
99
|
+
send(_payload, callback) {
|
|
100
|
+
if (!isFirst) queueMicrotask(() => callback());
|
|
101
|
+
else if (failure === 'callback error') {
|
|
102
|
+
queueMicrotask(() => callback(new Error('write failed')));
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
terminate() {
|
|
106
|
+
this.terminated = true;
|
|
107
|
+
this.readyState = 3;
|
|
108
|
+
},
|
|
109
|
+
close() {
|
|
110
|
+
this.readyState = 3;
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
sockets.push(socket);
|
|
114
|
+
return { entry: { socket }, reused: false };
|
|
115
|
+
},
|
|
116
|
+
_sendFrameFn: (wsEntry, frame, span) => _sendFrame(wsEntry, frame, span, 10),
|
|
117
|
+
_streamFn: async () => ({
|
|
118
|
+
content: 'recovered',
|
|
119
|
+
model: 'gpt-5.5',
|
|
120
|
+
toolCalls: [],
|
|
121
|
+
usage: {},
|
|
122
|
+
closeSocket: true,
|
|
123
|
+
}),
|
|
124
|
+
}));
|
|
125
|
+
|
|
126
|
+
assert.equal(result.content, 'recovered');
|
|
127
|
+
assert.deepEqual(acquires, [false, true]);
|
|
128
|
+
assert.equal(sockets[0].terminated, true);
|
|
129
|
+
assert.notEqual(sockets[1], sockets[0]);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
30
133
|
test('pre-response 1006 opens a fresh WS and replays the same request', async () => {
|
|
31
134
|
const acquires = [];
|
|
32
135
|
const frames = [];
|
|
136
|
+
const stages = [];
|
|
137
|
+
let stderr = '';
|
|
138
|
+
const oldWrite = process.stderr.write;
|
|
33
139
|
let streams = 0;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
140
|
+
let result;
|
|
141
|
+
try {
|
|
142
|
+
process.stderr.write = (chunk) => {
|
|
143
|
+
stderr += String(chunk);
|
|
144
|
+
return true;
|
|
145
|
+
};
|
|
146
|
+
result = await sendViaWebSocket(wsArgs({
|
|
147
|
+
onStageChange: (stage, detail) => stages.push({ stage, detail }),
|
|
148
|
+
_acquireWithRetryFn: async (opts) => {
|
|
149
|
+
acquires.push(opts.forceFresh);
|
|
150
|
+
return { entry: entry(), reused: false };
|
|
151
|
+
},
|
|
152
|
+
_sendFrameFn: async (_entry, frame) => { frames.push(frame); },
|
|
153
|
+
_streamFn: async () => {
|
|
154
|
+
streams += 1;
|
|
155
|
+
if (streams === 1) throw close1006();
|
|
156
|
+
return { content: 'recovered', model: 'gpt-5.5', toolCalls: [], usage: {}, closeSocket: true };
|
|
157
|
+
},
|
|
158
|
+
}));
|
|
159
|
+
} finally {
|
|
160
|
+
process.stderr.write = oldWrite;
|
|
161
|
+
}
|
|
46
162
|
|
|
47
163
|
assert.equal(result.content, 'recovered');
|
|
48
164
|
assert.deepEqual(acquires, [false, true], 'retry must acquire a fresh socket');
|
|
49
165
|
assert.equal(frames.length, 2);
|
|
50
166
|
assert.deepEqual(frames[1].input, frames[0].input, 'retry must replay the same input');
|
|
51
167
|
assert.equal(result.__midstreamRetries, 1);
|
|
168
|
+
assert.deepEqual(
|
|
169
|
+
stages.filter(({ stage }) => stage === 'reconnecting'),
|
|
170
|
+
[{ stage: 'reconnecting', detail: {
|
|
171
|
+
attempt: 1,
|
|
172
|
+
max: 4,
|
|
173
|
+
classifier: 'ws_1006',
|
|
174
|
+
message: 'Reconnecting... 1/4',
|
|
175
|
+
} }],
|
|
176
|
+
);
|
|
177
|
+
assert.doesNotMatch(stderr, /mid-stream recovered|Reconnecting/);
|
|
52
178
|
});
|
|
53
179
|
|
|
54
180
|
test('successful iteration emits one compact send-spans row', async () => {
|
|
@@ -97,7 +223,7 @@ test('exhausted pre-response 1006 retries reach the HTTP/SSE fallback', async ()
|
|
|
97
223
|
provider.ensureAuth = async () => ({ access_token: 'test-token' });
|
|
98
224
|
let streamAttempts = 0;
|
|
99
225
|
let httpCalls = 0;
|
|
100
|
-
const
|
|
226
|
+
const sendOpts = {
|
|
101
227
|
sessionId: 'openai-oauth-ws-1006-fallback-test',
|
|
102
228
|
_prebuiltBody: { model: 'gpt-5.5', input: [], prompt_cache_key: 'openai-oauth-ws-1006-fallback-test' },
|
|
103
229
|
_sendViaWebSocketFn: (args) => sendViaWebSocket({
|
|
@@ -114,11 +240,14 @@ test('exhausted pre-response 1006 retries reach the HTTP/SSE fallback', async ()
|
|
|
114
240
|
httpCalls += 1;
|
|
115
241
|
return { content: 'http-recovered', toolCalls: [], usage: {} };
|
|
116
242
|
},
|
|
117
|
-
}
|
|
243
|
+
};
|
|
244
|
+
const result = await provider.send([], 'gpt-5.5', [], sendOpts);
|
|
245
|
+
const stickyResult = await provider.send([], 'gpt-5.5', [], sendOpts);
|
|
118
246
|
|
|
119
247
|
assert.equal(streamAttempts, 5, 'all bounded ws_1006 attempts must run before fallback');
|
|
120
|
-
assert.equal(httpCalls,
|
|
248
|
+
assert.equal(httpCalls, 2);
|
|
121
249
|
assert.equal(result.content, 'http-recovered');
|
|
250
|
+
assert.equal(stickyResult.content, 'http-recovered');
|
|
122
251
|
} finally {
|
|
123
252
|
for (const [name, value] of Object.entries(savedEnv)) {
|
|
124
253
|
if (value == null) delete process.env[name];
|
|
@@ -127,6 +256,155 @@ test('exhausted pre-response 1006 retries reach the HTTP/SSE fallback', async ()
|
|
|
127
256
|
}
|
|
128
257
|
});
|
|
129
258
|
|
|
259
|
+
test('sticky HTTP fallback is isolated by session and expired entries are cleaned', async () => {
|
|
260
|
+
const savedEnv = Object.fromEntries([
|
|
261
|
+
'MIXDOG_OAI_TRANSPORT',
|
|
262
|
+
'MIXDOG_OPENAI_HTTP_FALLBACK',
|
|
263
|
+
'MIXDOG_OPENAI_OAUTH_WS_WARMUP',
|
|
264
|
+
'MIXDOG_AGENT_TRACE_DISABLE',
|
|
265
|
+
].map((name) => [name, process.env[name]]));
|
|
266
|
+
Object.assign(process.env, {
|
|
267
|
+
MIXDOG_OAI_TRANSPORT: 'auto',
|
|
268
|
+
MIXDOG_OPENAI_HTTP_FALLBACK: '1',
|
|
269
|
+
MIXDOG_OPENAI_OAUTH_WS_WARMUP: '0',
|
|
270
|
+
MIXDOG_AGENT_TRACE_DISABLE: '1',
|
|
271
|
+
});
|
|
272
|
+
try {
|
|
273
|
+
const provider = new OpenAIOAuthProvider({});
|
|
274
|
+
provider.ensureAuth = async () => ({ access_token: 'test-token' });
|
|
275
|
+
const wsCalls = [];
|
|
276
|
+
const httpCalls = [];
|
|
277
|
+
let sessionAFailed = false;
|
|
278
|
+
const sendFor = (sessionId) => provider.send([], 'gpt-5.5', [], {
|
|
279
|
+
sessionId,
|
|
280
|
+
_prebuiltBody: { model: 'gpt-5.5', input: [], prompt_cache_key: sessionId },
|
|
281
|
+
_sendViaWebSocketFn: async () => {
|
|
282
|
+
wsCalls.push(sessionId);
|
|
283
|
+
if (sessionId === 'sticky-session-a' && !sessionAFailed) {
|
|
284
|
+
sessionAFailed = true;
|
|
285
|
+
throw Object.assign(new Error('ws retries exhausted'), {
|
|
286
|
+
code: 'ECONNRESET',
|
|
287
|
+
retryClassifier: 'reset',
|
|
288
|
+
wsRetriesExhausted: true,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
return { content: `ws-${sessionId}`, toolCalls: [], usage: {} };
|
|
292
|
+
},
|
|
293
|
+
_sendViaHttpSseFn: async () => {
|
|
294
|
+
httpCalls.push(sessionId);
|
|
295
|
+
return { content: `http-${sessionId}`, toolCalls: [], usage: {} };
|
|
296
|
+
},
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
assert.equal((await sendFor('sticky-session-a')).content, 'http-sticky-session-a');
|
|
300
|
+
assert.equal((await sendFor('sticky-session-b')).content, 'ws-sticky-session-b');
|
|
301
|
+
assert.equal((await sendFor('sticky-session-a')).content, 'http-sticky-session-a');
|
|
302
|
+
assert.deepEqual(wsCalls, ['sticky-session-a', 'sticky-session-b']);
|
|
303
|
+
assert.deepEqual(httpCalls, ['sticky-session-a', 'sticky-session-a']);
|
|
304
|
+
|
|
305
|
+
provider._httpFallbackUntilByPoolKey.set('sticky-session-a', Date.now() - 1);
|
|
306
|
+
assert.equal((await sendFor('sticky-session-a')).content, 'ws-sticky-session-a');
|
|
307
|
+
assert.equal(provider._httpFallbackUntilByPoolKey.has('sticky-session-a'), false);
|
|
308
|
+
} finally {
|
|
309
|
+
for (const [name, value] of Object.entries(savedEnv)) {
|
|
310
|
+
if (value == null) delete process.env[name];
|
|
311
|
+
else process.env[name] = value;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
test('close 1000 after tool dispatch refuses WS replay and HTTP fallback', async () => {
|
|
317
|
+
const savedEnv = Object.fromEntries([
|
|
318
|
+
'MIXDOG_OAI_TRANSPORT',
|
|
319
|
+
'MIXDOG_OPENAI_HTTP_FALLBACK',
|
|
320
|
+
'MIXDOG_OPENAI_OAUTH_WS_WARMUP',
|
|
321
|
+
'MIXDOG_AGENT_TRACE_DISABLE',
|
|
322
|
+
].map((name) => [name, process.env[name]]));
|
|
323
|
+
Object.assign(process.env, {
|
|
324
|
+
MIXDOG_OAI_TRANSPORT: 'auto',
|
|
325
|
+
MIXDOG_OPENAI_HTTP_FALLBACK: '1',
|
|
326
|
+
MIXDOG_OPENAI_OAUTH_WS_WARMUP: '0',
|
|
327
|
+
MIXDOG_AGENT_TRACE_DISABLE: '1',
|
|
328
|
+
});
|
|
329
|
+
try {
|
|
330
|
+
const provider = new OpenAIOAuthProvider({});
|
|
331
|
+
provider.ensureAuth = async () => ({ access_token: 'test-token' });
|
|
332
|
+
let acquires = 0;
|
|
333
|
+
let httpCalls = 0;
|
|
334
|
+
await assert.rejects(
|
|
335
|
+
provider.send([], 'gpt-5.5', [], {
|
|
336
|
+
sessionId: 'openai-oauth-ws-1000-tool-test',
|
|
337
|
+
_prebuiltBody: { model: 'gpt-5.5', input: [], prompt_cache_key: 'openai-oauth-ws-1000-tool-test' },
|
|
338
|
+
_sendViaWebSocketFn: (args) => sendViaWebSocket({
|
|
339
|
+
...args,
|
|
340
|
+
_acquireWithRetryFn: async () => {
|
|
341
|
+
acquires += 1;
|
|
342
|
+
return { entry: entry(), reused: false };
|
|
343
|
+
},
|
|
344
|
+
_sendFrameFn: async () => {},
|
|
345
|
+
_streamFn: async ({ state }) => {
|
|
346
|
+
state.sawResponseCreated = true;
|
|
347
|
+
state.emittedToolCall = true;
|
|
348
|
+
throw Object.assign(new Error('WebSocket closed normally before completion'), {
|
|
349
|
+
wsCloseCode: 1000,
|
|
350
|
+
});
|
|
351
|
+
},
|
|
352
|
+
}),
|
|
353
|
+
_sendViaHttpSseFn: async () => {
|
|
354
|
+
httpCalls += 1;
|
|
355
|
+
return { content: 'unsafe fallback', toolCalls: [], usage: {} };
|
|
356
|
+
},
|
|
357
|
+
}),
|
|
358
|
+
(err) => err.wsCloseCode === 1000
|
|
359
|
+
&& err.emittedToolCall === true
|
|
360
|
+
&& err.unsafeToRetry === true,
|
|
361
|
+
);
|
|
362
|
+
assert.equal(acquires, 1);
|
|
363
|
+
assert.equal(httpCalls, 0);
|
|
364
|
+
} finally {
|
|
365
|
+
for (const [name, value] of Object.entries(savedEnv)) {
|
|
366
|
+
if (value == null) delete process.env[name];
|
|
367
|
+
else process.env[name] = value;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
test('post-tool unknown-model errors never refresh or recursively replay', async () => {
|
|
373
|
+
for (const shape of [
|
|
374
|
+
{ httpStatus: 404, message: 'not found' },
|
|
375
|
+
{ message: 'model_not_found: unavailable model' },
|
|
376
|
+
]) {
|
|
377
|
+
const provider = new OpenAIOAuthProvider({});
|
|
378
|
+
provider.ensureAuth = async () => ({ access_token: 'test-token' });
|
|
379
|
+
let wsCalls = 0;
|
|
380
|
+
let refreshCalls = 0;
|
|
381
|
+
provider._refreshModelCache = async () => {
|
|
382
|
+
refreshCalls += 1;
|
|
383
|
+
return [];
|
|
384
|
+
};
|
|
385
|
+
const unsafe = Object.assign(new Error(shape.message), shape, {
|
|
386
|
+
emittedToolCall: true,
|
|
387
|
+
unsafeToRetry: true,
|
|
388
|
+
});
|
|
389
|
+
await assert.rejects(
|
|
390
|
+
provider.send([], 'gpt-5.5', [], {
|
|
391
|
+
sessionId: `post-tool-model-${shape.httpStatus || 'message'}`,
|
|
392
|
+
_prebuiltBody: { model: 'gpt-5.5', input: [] },
|
|
393
|
+
_sendViaWebSocketFn: async () => {
|
|
394
|
+
wsCalls += 1;
|
|
395
|
+
throw unsafe;
|
|
396
|
+
},
|
|
397
|
+
_sendViaHttpSseFn: async () => {
|
|
398
|
+
throw new Error('unsafe HTTP fallback');
|
|
399
|
+
},
|
|
400
|
+
}),
|
|
401
|
+
(err) => err === unsafe,
|
|
402
|
+
);
|
|
403
|
+
assert.equal(wsCalls, 1);
|
|
404
|
+
assert.equal(refreshCalls, 0);
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
|
|
130
408
|
test('post-emission 1006 refuses replay after text or tool output', async () => {
|
|
131
409
|
for (const emitted of ['emittedText', 'emittedToolCall']) {
|
|
132
410
|
let acquires = 0;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import {
|
|
4
|
+
mkdirSync, mkdtempSync, rmSync, writeFileSync,
|
|
5
|
+
} from 'node:fs';
|
|
6
|
+
import { tmpdir } from 'node:os';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import test from 'node:test';
|
|
9
|
+
import {
|
|
10
|
+
ensurePatchBinary,
|
|
11
|
+
findCachedPatchBinary,
|
|
12
|
+
} from '../src/runtime/agent/orchestrator/tools/patch-binary-fetcher.mjs';
|
|
13
|
+
import {
|
|
14
|
+
ensureNativePatchBinaryAvailable,
|
|
15
|
+
nativePatchBinPath,
|
|
16
|
+
} from '../src/runtime/agent/orchestrator/tools/patch/native-server.mjs';
|
|
17
|
+
|
|
18
|
+
const pkey = `${process.platform === 'win32' ? 'win32' : process.platform}-${process.arch}`;
|
|
19
|
+
const suffix = process.platform === 'win32' ? '.exe' : '';
|
|
20
|
+
|
|
21
|
+
function sha256(body) {
|
|
22
|
+
return createHash('sha256').update(body).digest('hex');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function makeManifest(version, body, url = `https://github.com/tribgames/mixdog/releases/download/patch-v${version}/mixdog-patch-${pkey}${suffix}`) {
|
|
26
|
+
return {
|
|
27
|
+
version,
|
|
28
|
+
assets: { [pkey]: { url, sha256: sha256(body) } },
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function fixture(t) {
|
|
33
|
+
const dataDir = mkdtempSync(join(tmpdir(), 'mixdog-patch-cache-'));
|
|
34
|
+
const binDir = join(dataDir, 'patch-bin');
|
|
35
|
+
mkdirSync(binDir, { recursive: true });
|
|
36
|
+
t.after(() => rmSync(dataDir, { recursive: true, force: true }));
|
|
37
|
+
return {
|
|
38
|
+
dataDir,
|
|
39
|
+
binDir,
|
|
40
|
+
bin(version) {
|
|
41
|
+
return join(binDir, `mixdog-patch-${version}${suffix}`);
|
|
42
|
+
},
|
|
43
|
+
localBin: join(dataDir, 'local-build', `mixdog-patch${suffix}`),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function nativeOptions(f, bundledManifest, download) {
|
|
48
|
+
return {
|
|
49
|
+
dataDir: f.dataDir,
|
|
50
|
+
defaultBin: f.localBin,
|
|
51
|
+
fetcherOptions: { bundledManifest, download },
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
test('stale cached manifest and binary cannot bypass native resolution', async (t) => {
|
|
56
|
+
const f = fixture(t);
|
|
57
|
+
const oldBody = Buffer.from('old binary');
|
|
58
|
+
const bundledBody = Buffer.from('bundled binary');
|
|
59
|
+
const bundledManifest = makeManifest('2.0.0', bundledBody);
|
|
60
|
+
writeFileSync(join(f.binDir, 'manifest.json'), JSON.stringify(makeManifest('1.0.0', oldBody)));
|
|
61
|
+
writeFileSync(f.bin('1.0.0'), oldBody);
|
|
62
|
+
const options = nativeOptions(f, bundledManifest, async (_url, destination) => {
|
|
63
|
+
writeFileSync(destination, bundledBody);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
assert.equal(findCachedPatchBinary(f.dataDir, { bundledManifest }), null);
|
|
67
|
+
assert.equal(nativePatchBinPath(options), f.localBin);
|
|
68
|
+
assert.equal(await ensureNativePatchBinaryAvailable(options), f.bin('2.0.0'));
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('wrong-hash binary cannot bypass native resolution', async (t) => {
|
|
72
|
+
const f = fixture(t);
|
|
73
|
+
const expectedBody = Buffer.from('expected binary');
|
|
74
|
+
const manifest = makeManifest('2.0.0', expectedBody);
|
|
75
|
+
writeFileSync(f.bin('2.0.0'), 'wrong binary');
|
|
76
|
+
const options = nativeOptions(f, manifest, async (_url, destination) => {
|
|
77
|
+
writeFileSync(destination, expectedBody);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
assert.equal(findCachedPatchBinary(f.dataDir, { bundledManifest: manifest }), null);
|
|
81
|
+
assert.equal(nativePatchBinPath(options), f.localBin);
|
|
82
|
+
assert.equal(await ensureNativePatchBinaryAvailable(options), f.bin('2.0.0'));
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('exact bundled filename with the correct hash is selected', (t) => {
|
|
86
|
+
const f = fixture(t);
|
|
87
|
+
const body = Buffer.from('correct binary');
|
|
88
|
+
const manifest = makeManifest('2.0.0', body);
|
|
89
|
+
writeFileSync(f.bin('2.0.0'), body);
|
|
90
|
+
|
|
91
|
+
assert.equal(findCachedPatchBinary(f.dataDir, { bundledManifest: manifest }), f.bin('2.0.0'));
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('upgrade downloads the bundled version through the network-free seam', async (t) => {
|
|
95
|
+
const f = fixture(t);
|
|
96
|
+
const oldBody = Buffer.from('old binary');
|
|
97
|
+
const newBody = Buffer.from('new binary');
|
|
98
|
+
const oldManifest = makeManifest('1.0.0', oldBody);
|
|
99
|
+
const bundledManifest = makeManifest('2.0.0', newBody);
|
|
100
|
+
writeFileSync(join(f.binDir, 'manifest.json'), JSON.stringify(oldManifest));
|
|
101
|
+
writeFileSync(f.bin('1.0.0'), oldBody);
|
|
102
|
+
let downloads = 0;
|
|
103
|
+
|
|
104
|
+
const selected = await ensurePatchBinary(f.dataDir, {
|
|
105
|
+
bundledManifest,
|
|
106
|
+
download: async (url, destination) => {
|
|
107
|
+
downloads += 1;
|
|
108
|
+
assert.equal(url, bundledManifest.assets[pkey].url);
|
|
109
|
+
writeFileSync(destination, newBody);
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
assert.equal(downloads, 1);
|
|
114
|
+
assert.equal(selected, f.bin('2.0.0'));
|
|
115
|
+
assert.equal(findCachedPatchBinary(f.dataDir, { bundledManifest }), selected);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('only a trusted, strictly newer valid cached manifest may advance policy', (t) => {
|
|
119
|
+
const f = fixture(t);
|
|
120
|
+
const bundledBody = Buffer.from('bundled binary');
|
|
121
|
+
const newerBody = Buffer.from('newer binary');
|
|
122
|
+
const bundledManifest = makeManifest('2.0.0', bundledBody);
|
|
123
|
+
const newerManifest = makeManifest('2.1.0', newerBody);
|
|
124
|
+
writeFileSync(join(f.binDir, 'manifest.json'), JSON.stringify(newerManifest));
|
|
125
|
+
writeFileSync(f.bin('2.1.0'), newerBody);
|
|
126
|
+
assert.equal(findCachedPatchBinary(f.dataDir, { bundledManifest }), f.bin('2.1.0'));
|
|
127
|
+
|
|
128
|
+
newerManifest.assets[pkey].url = 'https://example.com/untrusted';
|
|
129
|
+
writeFileSync(join(f.binDir, 'manifest.json'), JSON.stringify(newerManifest));
|
|
130
|
+
writeFileSync(f.bin('2.0.0'), bundledBody);
|
|
131
|
+
assert.equal(findCachedPatchBinary(f.dataDir, { bundledManifest }), f.bin('2.0.0'));
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('equal-version cached manifest cannot replace bundled policy', (t) => {
|
|
135
|
+
const f = fixture(t);
|
|
136
|
+
const bundledBody = Buffer.from('bundled binary');
|
|
137
|
+
const bundledManifest = makeManifest('2.0.0', bundledBody);
|
|
138
|
+
const equalManifest = makeManifest('2.0.0', Buffer.from('different binary'));
|
|
139
|
+
writeFileSync(join(f.binDir, 'manifest.json'), JSON.stringify(equalManifest));
|
|
140
|
+
writeFileSync(f.bin('2.0.0'), bundledBody);
|
|
141
|
+
|
|
142
|
+
assert.equal(findCachedPatchBinary(f.dataDir, { bundledManifest }), f.bin('2.0.0'));
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
for (const [label, badUrl] of [
|
|
146
|
+
['wrong release tag', `https://github.com/tribgames/mixdog/releases/download/patch-v9.9.9/mixdog-patch-${pkey}${suffix}`],
|
|
147
|
+
['wrong platform filename', `https://github.com/tribgames/mixdog/releases/download/patch-v2.1.0/mixdog-patch-wrong-platform${suffix}`],
|
|
148
|
+
]) {
|
|
149
|
+
test(`newer cached manifest with ${label} cannot replace bundled policy`, (t) => {
|
|
150
|
+
const f = fixture(t);
|
|
151
|
+
const bundledBody = Buffer.from('bundled binary');
|
|
152
|
+
const newerBody = Buffer.from('newer binary');
|
|
153
|
+
const bundledManifest = makeManifest('2.0.0', bundledBody);
|
|
154
|
+
const newerManifest = makeManifest('2.1.0', newerBody, badUrl);
|
|
155
|
+
writeFileSync(join(f.binDir, 'manifest.json'), JSON.stringify(newerManifest));
|
|
156
|
+
writeFileSync(f.bin('2.0.0'), bundledBody);
|
|
157
|
+
writeFileSync(f.bin('2.1.0'), newerBody);
|
|
158
|
+
|
|
159
|
+
assert.equal(findCachedPatchBinary(f.dataDir, { bundledManifest }), f.bin('2.0.0'));
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
test('explicit native override and local cargo path retain precedence', (t) => {
|
|
164
|
+
const f = fixture(t);
|
|
165
|
+
const body = Buffer.from('cached binary');
|
|
166
|
+
const bundledManifest = makeManifest('2.0.0', body);
|
|
167
|
+
writeFileSync(f.bin('2.0.0'), body);
|
|
168
|
+
mkdirSync(join(f.dataDir, 'local-build'), { recursive: true });
|
|
169
|
+
writeFileSync(f.localBin, 'local binary');
|
|
170
|
+
const options = nativeOptions(f, bundledManifest);
|
|
171
|
+
|
|
172
|
+
assert.equal(nativePatchBinPath(options), f.localBin);
|
|
173
|
+
const previous = process.env.MIXDOG_PATCH_NATIVE_BIN;
|
|
174
|
+
process.env.MIXDOG_PATCH_NATIVE_BIN = join(f.dataDir, 'explicit-binary');
|
|
175
|
+
try {
|
|
176
|
+
assert.equal(nativePatchBinPath(options), process.env.MIXDOG_PATCH_NATIVE_BIN);
|
|
177
|
+
} finally {
|
|
178
|
+
if (previous === undefined) delete process.env.MIXDOG_PATCH_NATIVE_BIN;
|
|
179
|
+
else process.env.MIXDOG_PATCH_NATIVE_BIN = previous;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
cancelPromptImmediateFlush,
|
|
6
|
+
schedulePromptImmediateFlush,
|
|
7
|
+
} from '../src/tui/components/prompt-input/immediate-render.mjs';
|
|
8
|
+
|
|
9
|
+
test('busy prompt input cancels a pending immediate render and schedules nothing', () => {
|
|
10
|
+
const throttle = { lastAt: 90, timer: 7 };
|
|
11
|
+
const cleared = [];
|
|
12
|
+
let queued = 0;
|
|
13
|
+
let flushed = 0;
|
|
14
|
+
|
|
15
|
+
const scheduled = schedulePromptImmediateFlush({
|
|
16
|
+
throttle,
|
|
17
|
+
isSuppressed: true,
|
|
18
|
+
flush: () => { flushed += 1; },
|
|
19
|
+
now: () => 100,
|
|
20
|
+
enqueue: () => { queued += 1; },
|
|
21
|
+
clearTimer: (timer) => cleared.push(timer),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
assert.equal(scheduled, false);
|
|
25
|
+
assert.equal(throttle.timer, null);
|
|
26
|
+
assert.deepEqual(cleared, [7]);
|
|
27
|
+
assert.equal(queued, 0);
|
|
28
|
+
assert.equal(flushed, 0);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('idle prompt input keeps one leading and one coalesced trailing immediate render', () => {
|
|
32
|
+
const throttle = { lastAt: 0, timer: null };
|
|
33
|
+
let current = 100;
|
|
34
|
+
const queued = [];
|
|
35
|
+
const timers = [];
|
|
36
|
+
let flushed = 0;
|
|
37
|
+
const options = {
|
|
38
|
+
throttle,
|
|
39
|
+
isSuppressed: false,
|
|
40
|
+
flush: () => { flushed += 1; },
|
|
41
|
+
now: () => current,
|
|
42
|
+
enqueue: (callback) => queued.push(callback),
|
|
43
|
+
setTimer: (callback, delay) => {
|
|
44
|
+
timers.push({ callback, delay });
|
|
45
|
+
return timers.length;
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
assert.equal(schedulePromptImmediateFlush(options), true);
|
|
50
|
+
assert.equal(queued.length, 1);
|
|
51
|
+
queued.shift()();
|
|
52
|
+
assert.equal(flushed, 1);
|
|
53
|
+
|
|
54
|
+
current = 105;
|
|
55
|
+
assert.equal(schedulePromptImmediateFlush(options), true);
|
|
56
|
+
current = 106;
|
|
57
|
+
assert.equal(schedulePromptImmediateFlush(options), false);
|
|
58
|
+
assert.equal(timers.length, 1);
|
|
59
|
+
assert.equal(timers[0].delay, 11);
|
|
60
|
+
|
|
61
|
+
current = 116;
|
|
62
|
+
timers[0].callback();
|
|
63
|
+
assert.equal(flushed, 2);
|
|
64
|
+
assert.equal(throttle.timer, null);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('a trailing immediate render is dropped if the turn becomes busy', () => {
|
|
68
|
+
const throttle = { lastAt: 100, timer: null };
|
|
69
|
+
let busy = false;
|
|
70
|
+
let timerCallback;
|
|
71
|
+
let flushed = 0;
|
|
72
|
+
|
|
73
|
+
schedulePromptImmediateFlush({
|
|
74
|
+
throttle,
|
|
75
|
+
isSuppressed: () => busy,
|
|
76
|
+
flush: () => { flushed += 1; },
|
|
77
|
+
now: () => 105,
|
|
78
|
+
setTimer: (callback) => {
|
|
79
|
+
timerCallback = callback;
|
|
80
|
+
return 1;
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
busy = true;
|
|
84
|
+
timerCallback();
|
|
85
|
+
|
|
86
|
+
assert.equal(flushed, 0);
|
|
87
|
+
assert.equal(throttle.timer, null);
|
|
88
|
+
assert.equal(cancelPromptImmediateFlush(throttle), false);
|
|
89
|
+
});
|