mixdog 0.9.50 → 0.9.52
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/package.json +5 -3
- package/scripts/abort-recovery-test.mjs +17 -1
- package/scripts/agent-model-liveness-test.mjs +79 -2
- package/scripts/anthropic-admission-retry-integration-test.mjs +119 -0
- package/scripts/anthropic-transport-policy-test.mjs +466 -0
- package/scripts/atomic-lock-tryonce-test.mjs +60 -1
- package/scripts/build-tui.mjs +13 -1
- package/scripts/channel-daemon-smoke.mjs +630 -10
- package/scripts/code-graph-aggregate-cwd-test.mjs +41 -37
- package/scripts/code-graph-disk-hit-test.mjs +11 -0
- package/scripts/code-graph-root-federation-test.mjs +273 -0
- package/scripts/compact-pressure-test.mjs +55 -1
- package/scripts/compact-smoke.mjs +80 -0
- package/scripts/context-mcp-metering-test.mjs +1350 -19
- package/scripts/deferred-tool-loading-test.mjs +17 -0
- package/scripts/gemini-provider-test.mjs +1053 -0
- package/scripts/hook-bus-test.mjs +23 -0
- package/scripts/internal-tools-normalization-test.mjs +10 -0
- package/scripts/interrupted-turn-history-test.mjs +371 -0
- package/scripts/lifecycle-api-test.mjs +76 -0
- package/scripts/max-output-recovery-test.mjs +55 -0
- package/scripts/mcp-grace-deferred-test.mjs +89 -13
- package/scripts/memory-pg-recovery-test.mjs +59 -0
- package/scripts/openai-oauth-ws-1006-retry-test.mjs +391 -4
- package/scripts/process-lifecycle-test.mjs +389 -0
- package/scripts/provider-admission-scheduler-test.mjs +582 -0
- package/scripts/provider-contract-test.mjs +268 -0
- package/scripts/provider-toolcall-test.mjs +520 -3
- package/scripts/reactive-compact-persist-smoke.mjs +59 -0
- package/scripts/resource-admission-test.mjs +789 -0
- package/scripts/session-bench-cache-break-test.mjs +102 -0
- package/scripts/session-bench.mjs +101 -42
- package/scripts/shell-failure-diagnostics-test.mjs +73 -4
- package/scripts/shell-jobs-windows-hide-test.mjs +1 -1
- package/scripts/smoke-loop-failure-summary-test.mjs +38 -0
- package/scripts/smoke-loop-failure-summary.mjs +16 -0
- package/scripts/smoke-loop.mjs +2 -7
- package/scripts/steering-drain-buckets-test.mjs +18 -0
- package/scripts/tool-failures.mjs +15 -1
- package/scripts/toolcall-args-test.mjs +14 -6
- package/scripts/tui-transcript-perf-test.mjs +43 -7
- package/scripts/web-fetch-routing-test.mjs +158 -0
- package/src/cli.mjs +15 -2
- package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch.mjs +26 -0
- package/src/runtime/agent/orchestrator/agent-runtime/agent-progress-watchdog.mjs +4 -1
- package/src/runtime/agent/orchestrator/agent-trace-format.mjs +12 -0
- package/src/runtime/agent/orchestrator/internal-tools.mjs +2 -0
- package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +331 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth.mjs +118 -26
- package/src/runtime/agent/orchestrator/providers/anthropic-sse.mjs +29 -17
- package/src/runtime/agent/orchestrator/providers/anthropic.mjs +136 -38
- package/src/runtime/agent/orchestrator/providers/gemini-cache.mjs +24 -4
- package/src/runtime/agent/orchestrator/providers/gemini-schema.mjs +554 -42
- package/src/runtime/agent/orchestrator/providers/gemini-stream.mjs +67 -18
- package/src/runtime/agent/orchestrator/providers/gemini.mjs +95 -46
- package/src/runtime/agent/orchestrator/providers/grok-oauth.mjs +12 -4
- package/src/runtime/agent/orchestrator/providers/model-catalog.mjs +54 -14
- package/src/runtime/agent/orchestrator/providers/openai-compat-presets.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/openai-compat-stream.mjs +14 -3
- package/src/runtime/agent/orchestrator/providers/openai-compat-xai.mjs +10 -80
- package/src/runtime/agent/orchestrator/providers/openai-compat.mjs +89 -17
- package/src/runtime/agent/orchestrator/providers/openai-oauth-http-sse.mjs +93 -26
- package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +144 -51
- package/src/runtime/agent/orchestrator/providers/openai-oauth.mjs +22 -8
- package/src/runtime/agent/orchestrator/providers/openai-ws-delta.mjs +74 -1
- package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +111 -6
- package/src/runtime/agent/orchestrator/providers/openai-ws-stream.mjs +13 -17
- package/src/runtime/agent/orchestrator/providers/openai-ws.mjs +78 -12
- package/src/runtime/agent/orchestrator/providers/opencode-go.mjs +44 -5
- package/src/runtime/agent/orchestrator/providers/registry.mjs +49 -8
- package/src/runtime/agent/orchestrator/providers/retry-classifier.mjs +224 -104
- package/src/runtime/agent/orchestrator/session/agent-loop.mjs +127 -55
- package/src/runtime/agent/orchestrator/session/compact/engine.mjs +99 -32
- package/src/runtime/agent/orchestrator/session/context-utils.mjs +17 -1
- package/src/runtime/agent/orchestrator/session/loop/pre-dispatch-deny.mjs +38 -0
- package/src/runtime/agent/orchestrator/session/loop/tool-exec.mjs +15 -0
- package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +69 -37
- package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +10 -1
- package/src/runtime/agent/orchestrator/session/manager/message-sanitize.mjs +8 -28
- package/src/runtime/agent/orchestrator/session/manager/runtime-liveness.mjs +6 -7
- package/src/runtime/agent/orchestrator/session/manager/session-close.mjs +2 -0
- package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +10 -1
- package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +42 -1
- package/src/runtime/agent/orchestrator/session/manager/tool-resolution.mjs +5 -1
- package/src/runtime/agent/orchestrator/session/manager/turn-interruption.mjs +220 -0
- package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +24 -4
- package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +5 -0
- package/src/runtime/agent/orchestrator/session/store-summary-index.mjs +17 -0
- package/src/runtime/agent/orchestrator/session/store.mjs +89 -22
- package/src/runtime/agent/orchestrator/stall-policy.mjs +2 -12
- package/src/runtime/agent/orchestrator/tools/bash-session.mjs +42 -4
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool.mjs +74 -37
- package/src/runtime/agent/orchestrator/tools/builtin/shell-job-process.mjs +223 -2
- package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +380 -37
- package/src/runtime/agent/orchestrator/tools/code-graph/build.mjs +176 -21
- package/src/runtime/agent/orchestrator/tools/code-graph/disk-cache.mjs +14 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +108 -2
- package/src/runtime/agent/orchestrator/tools/code-graph/trusted-roots.mjs +93 -0
- package/src/runtime/agent/orchestrator/tools/code-graph-prewarm-worker.mjs +12 -3
- package/src/runtime/agent/orchestrator/tools/shell-command.mjs +124 -14
- package/src/runtime/memory/index.mjs +22 -4
- package/src/runtime/memory/lib/pg/adapter.mjs +84 -10
- package/src/runtime/memory/lib/pg/process.mjs +91 -47
- package/src/runtime/memory/lib/pg/supervisor.mjs +50 -13
- package/src/runtime/search/index.mjs +41 -0
- package/src/runtime/search/lib/http-fetch.mjs +154 -0
- package/src/runtime/search/tool-defs.mjs +23 -0
- package/src/runtime/shared/atomic-file.mjs +28 -150
- package/src/runtime/shared/process-lifecycle.mjs +363 -0
- package/src/runtime/shared/process-shutdown.mjs +27 -4
- package/src/runtime/shared/resource-admission.mjs +359 -0
- package/src/runtime/shared/staged-child-result.mjs +19 -0
- package/src/session-runtime/context-status.mjs +38 -27
- package/src/session-runtime/lifecycle-api.mjs +26 -6
- package/src/session-runtime/provider-request-tools.mjs +72 -0
- package/src/session-runtime/runtime-core.mjs +43 -18
- package/src/session-runtime/session-turn-api.mjs +5 -4
- package/src/session-runtime/tool-catalog.mjs +375 -15
- package/src/standalone/agent-tool.mjs +17 -38
- package/src/standalone/channel-daemon-client.mjs +200 -38
- package/src/standalone/channel-daemon-transport.mjs +136 -9
- package/src/standalone/channel-worker.mjs +79 -12
- package/src/standalone/hook-bus/handlers.mjs +4 -0
- package/src/standalone/hook-bus/rules.mjs +7 -1
- package/src/standalone/hook-bus.mjs +10 -2
- package/src/tui/App.jsx +17 -11
- package/src/tui/app/live-spinner-visibility.mjs +20 -0
- package/src/tui/dist/index.mjs +101 -281
- package/src/tui/engine/session-api-ext.mjs +13 -2
- package/src/tui/engine/session-api.mjs +1 -1
- package/src/tui/engine/turn.mjs +10 -6
- package/src/tui/engine.mjs +13 -4
- package/src/tui/index.jsx +4 -1
- package/src/tui/lib/voice-setup.mjs +16 -0
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import {
|
|
3
|
+
existsSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
mkdtempSync,
|
|
6
|
+
readFileSync,
|
|
7
|
+
rmSync,
|
|
8
|
+
unlinkSync,
|
|
9
|
+
utimesSync,
|
|
10
|
+
writeFileSync,
|
|
11
|
+
} from 'node:fs';
|
|
12
|
+
import { tmpdir } from 'node:os';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
15
|
+
import test from 'node:test';
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
beginProcessLifecycle,
|
|
19
|
+
finishProcessLifecycle,
|
|
20
|
+
lifecyclePathsForTest,
|
|
21
|
+
LIFECYCLE_LEDGER_MAX_BYTES,
|
|
22
|
+
recordCatchableFatal,
|
|
23
|
+
} from '../src/runtime/shared/process-lifecycle.mjs';
|
|
24
|
+
import { installProcessSignalCleanup } from '../src/runtime/shared/process-shutdown.mjs';
|
|
25
|
+
import { stagedChildExitCode } from '../src/runtime/shared/staged-child-result.mjs';
|
|
26
|
+
|
|
27
|
+
const REPO_ROOT = new URL('..', import.meta.url);
|
|
28
|
+
|
|
29
|
+
function tempRoot() {
|
|
30
|
+
return mkdtempSync(join(tmpdir(), 'mixdog-lifecycle-'));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function entries(path) {
|
|
34
|
+
return readFileSync(path, 'utf8').trim().split('\n').filter(Boolean).map((line) => JSON.parse(line));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function childExit(child) {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
child.once('error', reject);
|
|
40
|
+
child.once('exit', (code, signal) => resolve({ code, signal }));
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
test('lifecycle ledger records bounded metadata and removes only its own marker', async () => {
|
|
45
|
+
const root = tempRoot();
|
|
46
|
+
try {
|
|
47
|
+
const paths = lifecyclePathsForTest(root);
|
|
48
|
+
const api = beginProcessLifecycle({ directory: root, configureReports: false });
|
|
49
|
+
const foreignMarker = join(paths.markerDir, `${process.pid}-foreign.json`);
|
|
50
|
+
writeFileSync(foreignMarker, JSON.stringify({ pid: process.pid, ppid: process.ppid, token: 'foreign' }));
|
|
51
|
+
recordCatchableFatal(1);
|
|
52
|
+
const duplicate = await import(`../src/runtime/shared/process-lifecycle.mjs?duplicate=${Date.now()}`);
|
|
53
|
+
assert.equal(duplicate.beginProcessLifecycle({ directory: join(root, 'ignored') }).markerPath, api.markerPath);
|
|
54
|
+
assert.equal(duplicate.finishProcessLifecycle('catchable-fatal-error', 1), true);
|
|
55
|
+
const rows = entries(paths.ledger);
|
|
56
|
+
assert.deepEqual(rows.map((row) => row.reason), [
|
|
57
|
+
'process-start',
|
|
58
|
+
'catchable-fatal-error',
|
|
59
|
+
'catchable-fatal-error',
|
|
60
|
+
]);
|
|
61
|
+
assert.deepEqual(Object.keys(rows[0]).sort(), [
|
|
62
|
+
'cwd', 'exitCode', 'memory', 'pid', 'ppid', 'reason', 'timestamp', 'version',
|
|
63
|
+
]);
|
|
64
|
+
assert.equal(existsSync(api.markerPath), false);
|
|
65
|
+
assert.equal(existsSync(foreignMarker), true);
|
|
66
|
+
} finally {
|
|
67
|
+
rmSync(root, { recursive: true, force: true });
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('vanished evidence uses only old-process fields and both ledger files stay hard-bounded', () => {
|
|
72
|
+
const root = tempRoot();
|
|
73
|
+
const originalKill = process.kill;
|
|
74
|
+
try {
|
|
75
|
+
process.kill = () => { const error = new Error('gone'); error.code = 'ESRCH'; throw error; };
|
|
76
|
+
const paths = lifecyclePathsForTest(root);
|
|
77
|
+
mkdirSync(paths.markerDir, { recursive: true });
|
|
78
|
+
const staleMarker = join(paths.markerDir, '2147483647-stale.json');
|
|
79
|
+
writeFileSync(staleMarker, JSON.stringify({
|
|
80
|
+
version: 1,
|
|
81
|
+
timestamp: new Date(0).toISOString(),
|
|
82
|
+
pid: 2147483647,
|
|
83
|
+
ppid: 1,
|
|
84
|
+
token: 'stale',
|
|
85
|
+
}));
|
|
86
|
+
writeFileSync(paths.ledger, `${'x'.repeat(LIFECYCLE_LEDGER_MAX_BYTES * 3)}\n`);
|
|
87
|
+
writeFileSync(paths.previousLedger, 'y'.repeat(LIFECYCLE_LEDGER_MAX_BYTES * 3));
|
|
88
|
+
beginProcessLifecycle({ directory: root, configureReports: false });
|
|
89
|
+
assert.ok(readFileSync(paths.previousLedger).byteLength <= LIFECYCLE_LEDGER_MAX_BYTES);
|
|
90
|
+
finishProcessLifecycle('clean-shutdown', 0);
|
|
91
|
+
const rows = entries(paths.ledger);
|
|
92
|
+
const vanished = rows.find((row) => row.reason === 'prior-process-vanished');
|
|
93
|
+
assert.deepEqual(Object.keys(vanished).sort(), [
|
|
94
|
+
'exitCode', 'pid', 'ppid', 'reason', 'timestamp', 'version',
|
|
95
|
+
]);
|
|
96
|
+
assert.equal(vanished.pid, 2147483647);
|
|
97
|
+
assert.equal(existsSync(staleMarker), false);
|
|
98
|
+
assert.ok(readFileSync(paths.ledger).byteLength <= LIFECYCLE_LEDGER_MAX_BYTES);
|
|
99
|
+
assert.ok(readFileSync(paths.previousLedger).byteLength <= LIFECYCLE_LEDGER_MAX_BYTES);
|
|
100
|
+
} finally {
|
|
101
|
+
process.kill = originalKill;
|
|
102
|
+
rmSync(root, { recursive: true, force: true });
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('PID reuse is detected by process identity while uncertain live identity is preserved', () => {
|
|
107
|
+
const root = tempRoot();
|
|
108
|
+
try {
|
|
109
|
+
const paths = lifecyclePathsForTest(root);
|
|
110
|
+
mkdirSync(paths.markerDir, { recursive: true });
|
|
111
|
+
const seed = beginProcessLifecycle({ directory: root, configureReports: false });
|
|
112
|
+
const currentIdentity = JSON.parse(readFileSync(seed.markerPath, 'utf8')).processIdentity;
|
|
113
|
+
assert.ok(currentIdentity);
|
|
114
|
+
finishProcessLifecycle('clean-shutdown', 0);
|
|
115
|
+
const reused = join(paths.markerDir, `${process.pid}-reused.json`);
|
|
116
|
+
const matching = join(paths.markerDir, `${process.pid}-matching.json`);
|
|
117
|
+
const uncertain = join(paths.markerDir, `${process.pid}-uncertain.json`);
|
|
118
|
+
const malformed = join(paths.markerDir, `${process.pid}-malformed.json`);
|
|
119
|
+
const clockAmbiguous = join(paths.markerDir, `${process.pid}-clock.json`);
|
|
120
|
+
const differentKind = join(paths.markerDir, `${process.pid}-different-kind.json`);
|
|
121
|
+
const reusedIdentity = currentIdentity.kind === 'linux-start-ticks'
|
|
122
|
+
? { kind: currentIdentity.kind, value: String(BigInt(currentIdentity.value) + 1n) }
|
|
123
|
+
: { kind: currentIdentity.kind, value: currentIdentity.value + 1 };
|
|
124
|
+
writeFileSync(reused, JSON.stringify({
|
|
125
|
+
pid: process.pid,
|
|
126
|
+
ppid: process.ppid,
|
|
127
|
+
token: 'reused',
|
|
128
|
+
processIdentity: reusedIdentity,
|
|
129
|
+
}));
|
|
130
|
+
writeFileSync(matching, JSON.stringify({
|
|
131
|
+
pid: process.pid,
|
|
132
|
+
token: 'matching',
|
|
133
|
+
processIdentity: currentIdentity,
|
|
134
|
+
}));
|
|
135
|
+
writeFileSync(uncertain, JSON.stringify({
|
|
136
|
+
pid: process.pid,
|
|
137
|
+
ppid: process.ppid,
|
|
138
|
+
token: 'uncertain',
|
|
139
|
+
}));
|
|
140
|
+
writeFileSync(malformed, JSON.stringify({
|
|
141
|
+
pid: process.pid,
|
|
142
|
+
ppid: process.ppid,
|
|
143
|
+
token: 'malformed',
|
|
144
|
+
processIdentity: process.platform === 'linux'
|
|
145
|
+
? { kind: 'linux-start-ticks', value: 'not-a-number' }
|
|
146
|
+
: { kind: 'start-seconds', value: 'not-a-number' },
|
|
147
|
+
}));
|
|
148
|
+
writeFileSync(clockAmbiguous, JSON.stringify({
|
|
149
|
+
pid: process.pid,
|
|
150
|
+
ppid: process.ppid,
|
|
151
|
+
token: 'clock-adjusted',
|
|
152
|
+
processIdentity: { kind: 'legacy-wall-clock', value: Date.now() + 86400000 },
|
|
153
|
+
}));
|
|
154
|
+
writeFileSync(differentKind, JSON.stringify({
|
|
155
|
+
pid: process.pid,
|
|
156
|
+
token: 'different-kind',
|
|
157
|
+
processIdentity: currentIdentity.kind === 'linux-start-ticks'
|
|
158
|
+
? { kind: 'start-seconds', value: 1 }
|
|
159
|
+
: { kind: 'linux-start-ticks', value: '1' },
|
|
160
|
+
}));
|
|
161
|
+
beginProcessLifecycle({ directory: root, configureReports: false });
|
|
162
|
+
finishProcessLifecycle('clean-shutdown', 0);
|
|
163
|
+
assert.equal(entries(paths.ledger).filter((row) => row.reason === 'prior-process-vanished').length, 1);
|
|
164
|
+
assert.equal(existsSync(reused), false);
|
|
165
|
+
assert.equal(existsSync(matching), true);
|
|
166
|
+
assert.equal(existsSync(uncertain), true);
|
|
167
|
+
assert.equal(existsSync(malformed), true);
|
|
168
|
+
assert.equal(existsSync(clockAmbiguous), true);
|
|
169
|
+
assert.equal(existsSync(differentKind), true);
|
|
170
|
+
} finally {
|
|
171
|
+
rmSync(root, { recursive: true, force: true });
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('marker PID probing is tri-state and invalid PIDs preserve evidence', () => {
|
|
176
|
+
const originalKill = process.kill;
|
|
177
|
+
try {
|
|
178
|
+
for (const [name, pid, code, vanished] of [
|
|
179
|
+
['success', 101, null, false],
|
|
180
|
+
['eperm', 102, 'EPERM', false],
|
|
181
|
+
['esrch', 103, 'ESRCH', true],
|
|
182
|
+
['eacces', 104, 'EACCES', false],
|
|
183
|
+
['zero', 0, 'ESRCH', false],
|
|
184
|
+
['negative', -1, 'ESRCH', false],
|
|
185
|
+
['fractional', 1.5, 'ESRCH', false],
|
|
186
|
+
['too-large', 2147483648, 'ESRCH', false],
|
|
187
|
+
]) {
|
|
188
|
+
const root = tempRoot();
|
|
189
|
+
try {
|
|
190
|
+
const paths = lifecyclePathsForTest(root);
|
|
191
|
+
mkdirSync(paths.markerDir, { recursive: true });
|
|
192
|
+
const marker = join(paths.markerDir, `${name}.json`);
|
|
193
|
+
writeFileSync(marker, JSON.stringify({ pid, token: name }));
|
|
194
|
+
process.kill = () => {
|
|
195
|
+
if (code === null) return true;
|
|
196
|
+
const error = new Error(code);
|
|
197
|
+
error.code = code;
|
|
198
|
+
throw error;
|
|
199
|
+
};
|
|
200
|
+
beginProcessLifecycle({ directory: root, configureReports: false });
|
|
201
|
+
finishProcessLifecycle('clean-shutdown', 0);
|
|
202
|
+
assert.equal(existsSync(marker), !vanished, name);
|
|
203
|
+
assert.equal(
|
|
204
|
+
entries(paths.ledger).some((row) => row.reason === 'prior-process-vanished'),
|
|
205
|
+
vanished,
|
|
206
|
+
name,
|
|
207
|
+
);
|
|
208
|
+
} finally {
|
|
209
|
+
rmSync(root, { recursive: true, force: true });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
} finally {
|
|
213
|
+
process.kill = originalKill;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('old live same-PID foreign-token lock is never stolen', () => {
|
|
218
|
+
const root = tempRoot();
|
|
219
|
+
try {
|
|
220
|
+
const paths = lifecyclePathsForTest(root);
|
|
221
|
+
writeFileSync(paths.lock, `${process.pid} ${Date.now() - 60000} foreign-token\n`);
|
|
222
|
+
const old = new Date(Date.now() - 60000);
|
|
223
|
+
utimesSync(paths.lock, old, old);
|
|
224
|
+
const api = beginProcessLifecycle({ directory: root, configureReports: false });
|
|
225
|
+
assert.equal(existsSync(paths.lock), true);
|
|
226
|
+
assert.equal(existsSync(api.markerPath), true);
|
|
227
|
+
assert.equal(existsSync(paths.ledger), false);
|
|
228
|
+
unlinkSync(paths.lock);
|
|
229
|
+
assert.equal(finishProcessLifecycle('clean-shutdown', 0), true);
|
|
230
|
+
} finally {
|
|
231
|
+
rmSync(root, { recursive: true, force: true });
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test('concurrent writers serialize rotation', async () => {
|
|
236
|
+
const root = tempRoot();
|
|
237
|
+
try {
|
|
238
|
+
const paths = lifecyclePathsForTest(root);
|
|
239
|
+
mkdirSync(root, { recursive: true });
|
|
240
|
+
const childSource = `
|
|
241
|
+
import { beginProcessLifecycle, finishProcessLifecycle, recordCatchableFatal } from './src/runtime/shared/process-lifecycle.mjs';
|
|
242
|
+
beginProcessLifecycle({ directory: process.env.LEDGER_DIR, configureReports: false });
|
|
243
|
+
for (let i = 0; i < 120; i++) recordCatchableFatal(1);
|
|
244
|
+
if (!finishProcessLifecycle('catchable-fatal-error', 1)) process.exit(4);
|
|
245
|
+
`;
|
|
246
|
+
const children = Array.from({ length: 3 }, () => spawn(
|
|
247
|
+
process.execPath,
|
|
248
|
+
['--input-type=module', '--eval', childSource],
|
|
249
|
+
{
|
|
250
|
+
cwd: REPO_ROOT,
|
|
251
|
+
env: { ...process.env, LEDGER_DIR: root },
|
|
252
|
+
stdio: 'ignore',
|
|
253
|
+
},
|
|
254
|
+
));
|
|
255
|
+
const results = await Promise.all(children.map(childExit));
|
|
256
|
+
assert.deepEqual(results, [
|
|
257
|
+
{ code: 0, signal: null },
|
|
258
|
+
{ code: 0, signal: null },
|
|
259
|
+
{ code: 0, signal: null },
|
|
260
|
+
]);
|
|
261
|
+
for (const path of [paths.ledger, paths.previousLedger]) {
|
|
262
|
+
assert.ok(readFileSync(path).byteLength <= LIFECYCLE_LEDGER_MAX_BYTES);
|
|
263
|
+
entries(path);
|
|
264
|
+
}
|
|
265
|
+
assert.equal(existsSync(paths.lock), false);
|
|
266
|
+
} finally {
|
|
267
|
+
rmSync(root, { recursive: true, force: true });
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
test('failed final ledger write preserves marker evidence', () => {
|
|
272
|
+
const root = tempRoot();
|
|
273
|
+
try {
|
|
274
|
+
const paths = lifecyclePathsForTest(root);
|
|
275
|
+
const api = beginProcessLifecycle({ directory: root, configureReports: false });
|
|
276
|
+
unlinkSync(paths.ledger);
|
|
277
|
+
mkdirSync(paths.ledger);
|
|
278
|
+
assert.equal(finishProcessLifecycle('clean-shutdown', 0), false);
|
|
279
|
+
assert.equal(existsSync(api.markerPath), true);
|
|
280
|
+
rmSync(paths.ledger, { recursive: true, force: true });
|
|
281
|
+
assert.equal(finishProcessLifecycle('forced-cleanup', 1), true);
|
|
282
|
+
assert.equal(existsSync(api.markerPath), false);
|
|
283
|
+
} finally {
|
|
284
|
+
rmSync(root, { recursive: true, force: true });
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
test('cleanup rejection and timeout are forced cleanup, not clean shutdown', async () => {
|
|
289
|
+
const root = tempRoot();
|
|
290
|
+
const originalExit = process.exit;
|
|
291
|
+
try {
|
|
292
|
+
const exits = [];
|
|
293
|
+
process.exit = (code) => { exits.push(code); };
|
|
294
|
+
for (const [name, cleanupFn] of [
|
|
295
|
+
['rejection', async () => { throw new Error('fixture failure'); }],
|
|
296
|
+
['timeout', async () => new Promise(() => {})],
|
|
297
|
+
]) {
|
|
298
|
+
const directory = join(root, name);
|
|
299
|
+
const paths = lifecyclePathsForTest(directory);
|
|
300
|
+
beginProcessLifecycle({ directory, configureReports: false });
|
|
301
|
+
const cleanup = installProcessSignalCleanup({
|
|
302
|
+
signals: [],
|
|
303
|
+
fatal: false,
|
|
304
|
+
timeoutMs: 20,
|
|
305
|
+
cleanup: cleanupFn,
|
|
306
|
+
log: () => {},
|
|
307
|
+
});
|
|
308
|
+
await cleanup.run('SIGTERM', { code: 143, shouldExit: true });
|
|
309
|
+
assert.equal(entries(paths.ledger).at(-1).reason, 'forced-cleanup');
|
|
310
|
+
}
|
|
311
|
+
assert.deepEqual(exits, [143, 143]);
|
|
312
|
+
} finally {
|
|
313
|
+
process.exit = originalExit;
|
|
314
|
+
rmSync(root, { recursive: true, force: true });
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test('Node report is compact, excludes environment, and rotates to one previous report', () => {
|
|
319
|
+
const root = tempRoot();
|
|
320
|
+
try {
|
|
321
|
+
const paths = lifecyclePathsForTest(root);
|
|
322
|
+
writeFileSync(paths.report, 'previous-report');
|
|
323
|
+
const source = `
|
|
324
|
+
import { beginProcessLifecycle, finishProcessLifecycle } from './src/runtime/shared/process-lifecycle.mjs';
|
|
325
|
+
const api = beginProcessLifecycle({ directory: process.env.REPORT_DIR, safeCommandLine: true });
|
|
326
|
+
if (!api.reportPath || !process.report.compact || !process.report.excludeEnv || !process.report.excludeNetwork) process.exit(3);
|
|
327
|
+
process.report.writeReport();
|
|
328
|
+
finishProcessLifecycle('clean-shutdown', 0);
|
|
329
|
+
`;
|
|
330
|
+
const result = spawnSync(process.execPath, ['--input-type=module', '--eval', source], {
|
|
331
|
+
cwd: REPO_ROOT,
|
|
332
|
+
env: { ...process.env, REPORT_DIR: root, MIXDOG_TEST_SECRET: 'must-not-appear' },
|
|
333
|
+
encoding: 'utf8',
|
|
334
|
+
});
|
|
335
|
+
assert.equal(result.status, 0, result.stderr);
|
|
336
|
+
const raw = readFileSync(paths.report, 'utf8');
|
|
337
|
+
const report = JSON.parse(raw);
|
|
338
|
+
assert.equal(raw.includes('must-not-appear'), false);
|
|
339
|
+
assert.equal('environmentVariables' in report, false);
|
|
340
|
+
assert.equal('networkInterfaces' in report.header, false);
|
|
341
|
+
assert.equal(raw.trim().includes('\n'), false);
|
|
342
|
+
assert.equal(readFileSync(`${paths.report}.1`, 'utf8'), 'previous-report');
|
|
343
|
+
} finally {
|
|
344
|
+
rmSync(root, { recursive: true, force: true });
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
test('executed TUI bundle shares lifecycle boundary and CLI preserves a bounded clean record', () => {
|
|
349
|
+
const root = tempRoot();
|
|
350
|
+
try {
|
|
351
|
+
const dist = readFileSync(new URL('../src/tui/dist/index.mjs', import.meta.url), 'utf8');
|
|
352
|
+
assert.match(dist, /from ['"]\.\.\/\.\.\/runtime\/shared\/process-shutdown\.mjs['"]/);
|
|
353
|
+
assert.doesNotMatch(dist, /function installProcessSignalCleanup\(/);
|
|
354
|
+
const result = spawnSync(process.execPath, ['src/cli.mjs'], {
|
|
355
|
+
cwd: REPO_ROOT,
|
|
356
|
+
env: { ...process.env, MIXDOG_DATA_DIR: root, MIXDOG_DISABLE_STAGED_SWAP: '1' },
|
|
357
|
+
encoding: 'utf8',
|
|
358
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
359
|
+
});
|
|
360
|
+
assert.equal(result.status, 1, result.stderr);
|
|
361
|
+
const diagnosticPaths = lifecyclePathsForTest(join(root, 'diagnostics'));
|
|
362
|
+
const rows = entries(diagnosticPaths.ledger);
|
|
363
|
+
assert.deepEqual(rows.map((row) => row.reason), ['process-start', 'clean-shutdown']);
|
|
364
|
+
assert.ok(readFileSync(diagnosticPaths.ledger).byteLength <= LIFECYCLE_LEDGER_MAX_BYTES);
|
|
365
|
+
} finally {
|
|
366
|
+
rmSync(root, { recursive: true, force: true });
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test('executed staged-child signal handling is monotonic after failed forced finalization', () => {
|
|
371
|
+
const root = tempRoot();
|
|
372
|
+
try {
|
|
373
|
+
const paths = lifecyclePathsForTest(root);
|
|
374
|
+
const api = beginProcessLifecycle({ directory: root, configureReports: false });
|
|
375
|
+
const statusChild = spawnSync(process.execPath, ['--eval', 'process.exit(7)']);
|
|
376
|
+
assert.equal(stagedChildExitCode(statusChild), 7);
|
|
377
|
+
unlinkSync(paths.ledger);
|
|
378
|
+
mkdirSync(paths.ledger);
|
|
379
|
+
assert.equal(stagedChildExitCode({ status: null, signal: 'SIGTERM', error: undefined }), 143);
|
|
380
|
+
assert.equal(existsSync(api.markerPath), true);
|
|
381
|
+
rmSync(paths.ledger, { recursive: true, force: true });
|
|
382
|
+
assert.equal(finishProcessLifecycle('clean-shutdown', 0), true);
|
|
383
|
+
const rows = entries(paths.ledger);
|
|
384
|
+
assert.deepEqual(rows.map((row) => row.reason), ['forced-cleanup']);
|
|
385
|
+
assert.equal(rows[0].exitCode, 143);
|
|
386
|
+
} finally {
|
|
387
|
+
rmSync(root, { recursive: true, force: true });
|
|
388
|
+
}
|
|
389
|
+
});
|