@linzumi/cli 1.0.323 → 1.0.326
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 +1 -1
- package/dist/cloud-supervisor.mjs +99 -253
- package/dist/hosted-coding-account-worker.js +8 -30
- package/dist/index.js +444 -420
- package/dist/native/darwin/manifest.json +1 -1
- package/dist/remote-codex-harness-worker.js +127 -118
- package/dist/tcp-tunnel-cli.mjs +25 -25
- package/package.json +6 -7
- package/scripts/build.mjs +2 -1
- package/scripts/bump-cli-version.mjs +64 -39
- package/scripts/vendor-codex-app-server-protocol.ts +0 -383
- package/scripts/vm-provision-proof.mjs +0 -150
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
- Date: 2026-06-29
|
|
3
|
-
Spec: plans/2026-06-29-claude-code-raw-replay-harness-plan.md
|
|
4
|
-
Relationship: Vendors OpenAI Codex app-server generated TypeScript protocol
|
|
5
|
-
schemas as a single declaration bundle so Commander replay/coverage tests can
|
|
6
|
-
type-check against the real JSON-RPC protocol surface without committing the
|
|
7
|
-
upstream one-file-per-type layout.
|
|
8
|
-
*/
|
|
9
|
-
import { cp, mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
|
10
|
-
import { existsSync } from 'node:fs';
|
|
11
|
-
import { tmpdir } from 'node:os';
|
|
12
|
-
import { dirname, join, relative, resolve } from 'node:path';
|
|
13
|
-
import { fileURLToPath } from 'node:url';
|
|
14
|
-
import { spawn } from 'node:child_process';
|
|
15
|
-
|
|
16
|
-
type VendorOptions = {
|
|
17
|
-
readonly sourceRepo: string | undefined;
|
|
18
|
-
readonly sourceUrl: string;
|
|
19
|
-
readonly sourceRef: string;
|
|
20
|
-
readonly outFile: string;
|
|
21
|
-
readonly manifestFile: string;
|
|
22
|
-
readonly keepTemp: boolean;
|
|
23
|
-
readonly check: boolean;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
type PreparedSource = {
|
|
27
|
-
readonly repoPath: string;
|
|
28
|
-
readonly cleanup: (() => Promise<void>) | undefined;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const thisFile = fileURLToPath(import.meta.url);
|
|
32
|
-
const packageRoot = resolve(dirname(thisFile), '..');
|
|
33
|
-
const protocolSubtree = 'codex-rs/app-server-protocol/schema/typescript';
|
|
34
|
-
const defaultSourceUrl = 'https://github.com/openai/codex.git';
|
|
35
|
-
const vendorModuleName = '@linzumi/vendor/codex-app-server-protocol';
|
|
36
|
-
const defaultOutFile = join(
|
|
37
|
-
packageRoot,
|
|
38
|
-
'src/vendor/codex-app-server-protocol.d.ts'
|
|
39
|
-
);
|
|
40
|
-
const defaultManifestFile = join(
|
|
41
|
-
packageRoot,
|
|
42
|
-
'src/vendor/codex-app-server-protocol-manifest.json'
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
async function main(): Promise<void> {
|
|
46
|
-
const args = process.argv.slice(2);
|
|
47
|
-
|
|
48
|
-
if (args.includes('--help')) {
|
|
49
|
-
printHelp();
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const options = parseArgs(args);
|
|
54
|
-
const source = await prepareSource(options);
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
const sourceDir = join(source.repoPath, protocolSubtree);
|
|
58
|
-
|
|
59
|
-
if (!existsSync(sourceDir)) {
|
|
60
|
-
throw new Error(
|
|
61
|
-
`Codex protocol schema directory not found: ${sourceDir}`
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const sourceCommit = await git(source.repoPath, ['rev-parse', 'HEAD']);
|
|
66
|
-
if (options.check) {
|
|
67
|
-
await checkVendoredOutput(options, sourceDir, sourceCommit.trim());
|
|
68
|
-
process.stdout.write(
|
|
69
|
-
`verified Codex app-server protocol declaration bundle\n`
|
|
70
|
-
);
|
|
71
|
-
} else {
|
|
72
|
-
await writeDeclarationBundle(options, sourceDir, sourceCommit.trim());
|
|
73
|
-
await writeManifest(options, sourceCommit.trim());
|
|
74
|
-
process.stdout.write(
|
|
75
|
-
`vendored Codex app-server protocol declaration bundle\n`
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
process.stdout.write(` source: ${options.sourceUrl}\n`);
|
|
79
|
-
process.stdout.write(` ref: ${options.sourceRef}\n`);
|
|
80
|
-
process.stdout.write(` commit: ${sourceCommit.trim()}\n`);
|
|
81
|
-
process.stdout.write(` module: ${vendorModuleName}\n`);
|
|
82
|
-
process.stdout.write(` out: ${options.outFile}\n`);
|
|
83
|
-
process.stdout.write(` manifest: ${options.manifestFile}\n`);
|
|
84
|
-
} finally {
|
|
85
|
-
await source.cleanup?.();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function parseArgs(args: readonly string[]): VendorOptions {
|
|
90
|
-
return {
|
|
91
|
-
sourceRepo: optionalResolvedArg(args, '--codex-repo'),
|
|
92
|
-
sourceUrl: argValue(args, '--source-url') ?? defaultSourceUrl,
|
|
93
|
-
sourceRef: argValue(args, '--ref') ?? 'main',
|
|
94
|
-
outFile: optionalResolvedArg(args, '--out-file') ?? defaultOutFile,
|
|
95
|
-
manifestFile:
|
|
96
|
-
optionalResolvedArg(args, '--manifest-file') ?? defaultManifestFile,
|
|
97
|
-
keepTemp: args.includes('--keep-temp'),
|
|
98
|
-
check: args.includes('--check'),
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async function checkVendoredOutput(
|
|
103
|
-
options: VendorOptions,
|
|
104
|
-
sourceDir: string,
|
|
105
|
-
sourceCommit: string
|
|
106
|
-
): Promise<void> {
|
|
107
|
-
const checkRoot = await mkdtemp(
|
|
108
|
-
join(packageRoot, '.linzumi-codex-protocol-check-')
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
try {
|
|
112
|
-
const expectedOutFile = join(checkRoot, 'codex-app-server-protocol.d.ts');
|
|
113
|
-
const expectedManifestFile = join(
|
|
114
|
-
checkRoot,
|
|
115
|
-
'codex-app-server-protocol-manifest.json'
|
|
116
|
-
);
|
|
117
|
-
const expectedOptions = {
|
|
118
|
-
...options,
|
|
119
|
-
outFile: expectedOutFile,
|
|
120
|
-
manifestFile: expectedManifestFile,
|
|
121
|
-
check: false,
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
await writeDeclarationBundle(expectedOptions, sourceDir, sourceCommit);
|
|
125
|
-
await writeManifest(expectedOptions, sourceCommit);
|
|
126
|
-
await normalizeExpectedManifestForCommittedPaths(
|
|
127
|
-
expectedManifestFile,
|
|
128
|
-
options.outFile
|
|
129
|
-
);
|
|
130
|
-
await assertSameFile(expectedOutFile, options.outFile);
|
|
131
|
-
await assertSameFile(expectedManifestFile, options.manifestFile);
|
|
132
|
-
} finally {
|
|
133
|
-
await rm(checkRoot, { recursive: true, force: true });
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async function normalizeExpectedManifestForCommittedPaths(
|
|
138
|
-
manifestPath: string,
|
|
139
|
-
committedOutFile: string
|
|
140
|
-
): Promise<void> {
|
|
141
|
-
const manifest = JSON.parse(await readFile(manifestPath, 'utf8')) as Record<
|
|
142
|
-
string,
|
|
143
|
-
unknown
|
|
144
|
-
>;
|
|
145
|
-
const normalized = {
|
|
146
|
-
...manifest,
|
|
147
|
-
declarationFile: relative(packageRoot, committedOutFile),
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
await writeFile(
|
|
151
|
-
manifestPath,
|
|
152
|
-
`${JSON.stringify(normalized, null, 2)}\n`,
|
|
153
|
-
'utf8'
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
async function assertSameFile(
|
|
158
|
-
expectedPath: string,
|
|
159
|
-
actualPath: string
|
|
160
|
-
): Promise<void> {
|
|
161
|
-
const expected = await readFile(expectedPath, 'utf8');
|
|
162
|
-
const actual = await readFile(actualPath, 'utf8');
|
|
163
|
-
|
|
164
|
-
if (expected !== actual) {
|
|
165
|
-
throw new Error(
|
|
166
|
-
`vendored Codex protocol drift detected: ${actualPath} does not match regenerated output`
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
async function prepareSource(options: VendorOptions): Promise<PreparedSource> {
|
|
172
|
-
if (options.sourceRepo !== undefined) {
|
|
173
|
-
return { repoPath: options.sourceRepo, cleanup: undefined };
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const repoPath = await mkdtemp(join(tmpdir(), 'linzumi-openai-codex-'));
|
|
177
|
-
await git(undefined, [
|
|
178
|
-
'clone',
|
|
179
|
-
'--filter=blob:none',
|
|
180
|
-
'--sparse',
|
|
181
|
-
options.sourceUrl,
|
|
182
|
-
repoPath,
|
|
183
|
-
]);
|
|
184
|
-
await git(repoPath, ['sparse-checkout', 'set', protocolSubtree]);
|
|
185
|
-
await git(repoPath, ['fetch', '--depth', '1', 'origin', options.sourceRef]);
|
|
186
|
-
await git(repoPath, ['checkout', 'FETCH_HEAD']);
|
|
187
|
-
|
|
188
|
-
return {
|
|
189
|
-
repoPath,
|
|
190
|
-
cleanup: options.keepTemp
|
|
191
|
-
? undefined
|
|
192
|
-
: async () => {
|
|
193
|
-
await rm(repoPath, { recursive: true, force: true });
|
|
194
|
-
},
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
async function writeDeclarationBundle(
|
|
199
|
-
options: VendorOptions,
|
|
200
|
-
sourceDir: string,
|
|
201
|
-
sourceCommit: string
|
|
202
|
-
): Promise<void> {
|
|
203
|
-
const bundleRoot = await mkdtemp(
|
|
204
|
-
join(tmpdir(), 'linzumi-codex-protocol-dts-')
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
try {
|
|
208
|
-
const copiedProtocolDir = join(bundleRoot, 'protocol');
|
|
209
|
-
const entryFile = join(bundleRoot, 'entry.ts');
|
|
210
|
-
const rawBundleFile = join(bundleRoot, 'raw-bundle.d.ts');
|
|
211
|
-
|
|
212
|
-
await cp(sourceDir, copiedProtocolDir, { recursive: true });
|
|
213
|
-
await writeFile(
|
|
214
|
-
entryFile,
|
|
215
|
-
[
|
|
216
|
-
"export * from './protocol/index';",
|
|
217
|
-
"export * as v2 from './protocol/v2/index';",
|
|
218
|
-
'',
|
|
219
|
-
].join('\n'),
|
|
220
|
-
'utf8'
|
|
221
|
-
);
|
|
222
|
-
|
|
223
|
-
await command(packageRoot, [
|
|
224
|
-
'pnpm',
|
|
225
|
-
'exec',
|
|
226
|
-
'tsc',
|
|
227
|
-
'--declaration',
|
|
228
|
-
'--emitDeclarationOnly',
|
|
229
|
-
'--outFile',
|
|
230
|
-
rawBundleFile,
|
|
231
|
-
'--module',
|
|
232
|
-
'amd',
|
|
233
|
-
'--moduleResolution',
|
|
234
|
-
'node',
|
|
235
|
-
'--target',
|
|
236
|
-
'ES2022',
|
|
237
|
-
'--skipLibCheck',
|
|
238
|
-
entryFile,
|
|
239
|
-
]);
|
|
240
|
-
|
|
241
|
-
const rawBundle = await readFile(rawBundleFile, 'utf8');
|
|
242
|
-
const bundled = rawBundle
|
|
243
|
-
.replaceAll(
|
|
244
|
-
'declare module "protocol/',
|
|
245
|
-
`declare module "${vendorModuleName}/`
|
|
246
|
-
)
|
|
247
|
-
.replaceAll('from "protocol/', `from "${vendorModuleName}/`)
|
|
248
|
-
.replace(
|
|
249
|
-
'declare module "entry" {',
|
|
250
|
-
`declare module "${vendorModuleName}" {`
|
|
251
|
-
);
|
|
252
|
-
const header = [
|
|
253
|
-
'// GENERATED CODE! DO NOT MODIFY BY HAND!',
|
|
254
|
-
'// Bundled from OpenAI Codex app-server protocol TypeScript schemas.',
|
|
255
|
-
`// Source commit: ${sourceCommit}`,
|
|
256
|
-
`// Module: ${vendorModuleName}`,
|
|
257
|
-
'',
|
|
258
|
-
].join('\n');
|
|
259
|
-
|
|
260
|
-
await mkdir(dirname(options.outFile), { recursive: true });
|
|
261
|
-
await writeFile(options.outFile, `${header}${bundled}`, 'utf8');
|
|
262
|
-
await formatGeneratedFile(options.outFile);
|
|
263
|
-
} finally {
|
|
264
|
-
await rm(bundleRoot, { recursive: true, force: true });
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
async function formatGeneratedFile(path: string): Promise<void> {
|
|
269
|
-
await command(packageRoot, [
|
|
270
|
-
'pnpm',
|
|
271
|
-
'exec',
|
|
272
|
-
'biome',
|
|
273
|
-
'format',
|
|
274
|
-
'--write',
|
|
275
|
-
'--no-errors-on-unmatched',
|
|
276
|
-
path,
|
|
277
|
-
]);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
async function writeManifest(
|
|
281
|
-
options: VendorOptions,
|
|
282
|
-
sourceCommit: string
|
|
283
|
-
): Promise<void> {
|
|
284
|
-
const manifest = {
|
|
285
|
-
source: 'openai/codex codex-rs/app-server-protocol/schema/typescript',
|
|
286
|
-
sourceUrl: options.sourceUrl,
|
|
287
|
-
requestedRef: options.sourceRef,
|
|
288
|
-
sourceCommit,
|
|
289
|
-
protocolSubtree,
|
|
290
|
-
moduleName: vendorModuleName,
|
|
291
|
-
declarationFile: relative(packageRoot, options.outFile),
|
|
292
|
-
updateCommand:
|
|
293
|
-
'pnpm --filter @linzumi/cli run vendor:codex-app-server-protocol -- --ref <openai-codex-ref>',
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
await mkdir(dirname(options.manifestFile), { recursive: true });
|
|
297
|
-
await writeFile(
|
|
298
|
-
options.manifestFile,
|
|
299
|
-
`${JSON.stringify(manifest, null, 2)}\n`,
|
|
300
|
-
'utf8'
|
|
301
|
-
);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
function optionalResolvedArg(
|
|
305
|
-
args: readonly string[],
|
|
306
|
-
name: string
|
|
307
|
-
): string | undefined {
|
|
308
|
-
const value = argValue(args, name);
|
|
309
|
-
return value === undefined ? undefined : resolve(value);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
function argValue(args: readonly string[], name: string): string | undefined {
|
|
313
|
-
const index = args.indexOf(name);
|
|
314
|
-
|
|
315
|
-
if (index === -1) {
|
|
316
|
-
return undefined;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
const value = args[index + 1];
|
|
320
|
-
|
|
321
|
-
if (value === undefined) {
|
|
322
|
-
throw new Error(`${name} requires a value`);
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
return value;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
function git(
|
|
329
|
-
cwd: string | undefined,
|
|
330
|
-
args: readonly string[]
|
|
331
|
-
): Promise<string> {
|
|
332
|
-
return command(cwd, ['git', ...args]);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
function command(
|
|
336
|
-
cwd: string | undefined,
|
|
337
|
-
args: readonly string[]
|
|
338
|
-
): Promise<string> {
|
|
339
|
-
return new Promise((resolvePromise, reject) => {
|
|
340
|
-
const [commandName, ...commandArgs] = args;
|
|
341
|
-
|
|
342
|
-
if (commandName === undefined) {
|
|
343
|
-
reject(new Error('command requires at least one argument'));
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
const child = spawn(commandName, commandArgs, {
|
|
348
|
-
cwd,
|
|
349
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
350
|
-
});
|
|
351
|
-
const stdout: string[] = [];
|
|
352
|
-
const stderr: string[] = [];
|
|
353
|
-
|
|
354
|
-
child.stdout.on('data', (chunk) => stdout.push(String(chunk)));
|
|
355
|
-
child.stderr.on('data', (chunk) => stderr.push(String(chunk)));
|
|
356
|
-
child.on('error', reject);
|
|
357
|
-
child.on('close', (code) => {
|
|
358
|
-
if (code === 0) {
|
|
359
|
-
resolvePromise(stdout.join(''));
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
reject(
|
|
364
|
-
new Error(
|
|
365
|
-
`${args.join(' ')} failed with exit ${code}: ${stderr.join('')}`
|
|
366
|
-
)
|
|
367
|
-
);
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
function printHelp(): void {
|
|
373
|
-
process.stdout.write(
|
|
374
|
-
`Usage: pnpm run vendor:codex-app-server-protocol -- [options]\n\nOptions:\n --codex-repo <path> Bundle from an existing OpenAI Codex checkout\n --ref <ref> Git ref to vendor when cloning. Default: main\n --source-url <url> Codex git URL. Default: ${defaultSourceUrl}\n --out-file <path> Declaration bundle path. Default: src/vendor/codex-app-server-protocol.d.ts\n --manifest-file <path> Manifest path. Default: src/vendor/codex-app-server-protocol-manifest.json\n --keep-temp Keep temporary clone when cloning\n --check Regenerate into a temp directory and fail if committed files differ\n\nExamples:\n pnpm --filter @linzumi/cli run vendor:codex-app-server-protocol -- --ref main\n pnpm --filter @linzumi/cli run vendor:codex-app-server-protocol -- --codex-repo /tmp/openai-codex\n pnpm --filter @linzumi/cli run vendor:codex-app-server-protocol -- --codex-repo /tmp/openai-codex --check\n`
|
|
375
|
-
);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
main().catch((error) => {
|
|
379
|
-
process.stderr.write(
|
|
380
|
-
`${error instanceof Error ? (error.stack ?? error.message) : String(error)}\n`
|
|
381
|
-
);
|
|
382
|
-
process.exitCode = 1;
|
|
383
|
-
});
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
// PROOF that a smolvm guest can really install the coding toolchain.
|
|
2
|
-
//
|
|
3
|
-
// This boots a REAL microVM with network:true and runs the ACTUAL
|
|
4
|
-
// guestProvisionCommand from the #2111 branch - i.e. `apk add --no-cache
|
|
5
|
-
// ca-certificates nodejs npm git ripgrep bash curl` fetched over real egress
|
|
6
|
-
// from the Alpine package mirrors, then `npm install -g @openai/codex` - and
|
|
7
|
-
// then execs `--version` for each tool inside the guest and verifies the CA
|
|
8
|
-
// bundle the TLS fix installs. If any tool is missing or the CA bundle is
|
|
9
|
-
// empty, it exits non-zero.
|
|
10
|
-
//
|
|
11
|
-
// RUN (from packages/linzumi-cli, requires HVF + the smolvm runtime installed):
|
|
12
|
-
// node scripts/vm-provision-proof.mjs
|
|
13
|
-
import { homedir } from 'node:os';
|
|
14
|
-
import { join } from 'node:path';
|
|
15
|
-
|
|
16
|
-
const here = new URL('.', import.meta.url).pathname;
|
|
17
|
-
const pkgRoot = join(here, '..');
|
|
18
|
-
|
|
19
|
-
// vmGuestProvision.ts is self-contained (no relative imports), so Node's native
|
|
20
|
-
// type-stripping can import it directly - this is the REAL provision command
|
|
21
|
-
// from the #2111 branch, not a copy.
|
|
22
|
-
const { guestProvisionCommand, guestProvisionCheckCommand, guestCaBundlePath } =
|
|
23
|
-
await import(join(pkgRoot, 'src', 'vmSandbox', 'vmGuestProvision.ts'));
|
|
24
|
-
|
|
25
|
-
// Inline of vmCodexSupervisor.loadSmolmachines (avoids pulling in that module's
|
|
26
|
-
// extensionless relative imports, which Node's stripper won't resolve).
|
|
27
|
-
async function loadSmolmachines(runtimeDir) {
|
|
28
|
-
const { createRequire } = await import('node:module');
|
|
29
|
-
const requireFromRuntime = createRequire(join(runtimeDir, 'package.json'));
|
|
30
|
-
return requireFromRuntime('smolmachines');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const runtimeDir =
|
|
34
|
-
process.env.LINZUMI_VM_RUNTIME_DIR ||
|
|
35
|
-
join(homedir(), '.linzumi', 'vm-runtime');
|
|
36
|
-
const CODEX_VERSION = process.env.LINZUMI_VM_CODEX_VERSION || '0.139.0';
|
|
37
|
-
|
|
38
|
-
function log(...a) {
|
|
39
|
-
console.log('[provision-proof]', ...a);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async function run(machine, label, cmd, timeout = 240) {
|
|
43
|
-
const r = await machine.exec(cmd, { timeout });
|
|
44
|
-
const out = (r.stdout || '').trim();
|
|
45
|
-
const err = (r.stderr || '').trim();
|
|
46
|
-
log(
|
|
47
|
-
`${label}: exit=${r.exitCode}` +
|
|
48
|
-
(out ? ` stdout=${JSON.stringify(out.slice(0, 200))}` : '') +
|
|
49
|
-
(err && r.exitCode !== 0
|
|
50
|
-
? ` stderr=${JSON.stringify(err.slice(0, 200))}`
|
|
51
|
-
: '')
|
|
52
|
-
);
|
|
53
|
-
return r;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const t0 = Date.now();
|
|
57
|
-
log(`loading smolvm runtime from ${runtimeDir} ...`);
|
|
58
|
-
const sdk = await loadSmolmachines(runtimeDir);
|
|
59
|
-
|
|
60
|
-
const name = `linzumi-provision-proof-${process.pid}`;
|
|
61
|
-
log(`creating microVM "${name}" (network:true, full egress) ...`);
|
|
62
|
-
const machine = await sdk.Machine.create({
|
|
63
|
-
name,
|
|
64
|
-
mounts: [],
|
|
65
|
-
resources: { cpus: 2, memoryMb: 2048, network: true },
|
|
66
|
-
persistent: false,
|
|
67
|
-
});
|
|
68
|
-
log(`VM booted in ${Date.now() - t0}ms`);
|
|
69
|
-
|
|
70
|
-
let failures = [];
|
|
71
|
-
try {
|
|
72
|
-
// Sanity: the guest has outbound network at all.
|
|
73
|
-
await run(machine, 'guest uname', ['/bin/sh', '-c', 'uname -a']);
|
|
74
|
-
|
|
75
|
-
// THE REAL THING: run the exact provision command #2111 ships.
|
|
76
|
-
log('running REAL guestProvisionCommand (apk add + npm i -g codex) ...');
|
|
77
|
-
const prov = await run(
|
|
78
|
-
machine,
|
|
79
|
-
'provision',
|
|
80
|
-
guestProvisionCommand(CODEX_VERSION),
|
|
81
|
-
600
|
|
82
|
-
);
|
|
83
|
-
if (prov.exitCode !== 0) failures.push('provision command failed');
|
|
84
|
-
|
|
85
|
-
// Prove each tool is actually installed and runnable in the guest.
|
|
86
|
-
const tools = [
|
|
87
|
-
['node', ['/bin/sh', '-c', 'node --version']],
|
|
88
|
-
['npm', ['/bin/sh', '-c', 'npm --version']],
|
|
89
|
-
['git', ['/bin/sh', '-c', 'git --version']],
|
|
90
|
-
['ripgrep (rg)', ['/bin/sh', '-c', 'rg --version | head -1']],
|
|
91
|
-
['bash', ['/bin/sh', '-c', 'bash --version | head -1']],
|
|
92
|
-
['curl', ['/bin/sh', '-c', 'curl --version | head -1']],
|
|
93
|
-
[
|
|
94
|
-
'codex',
|
|
95
|
-
[
|
|
96
|
-
'/bin/sh',
|
|
97
|
-
'-c',
|
|
98
|
-
'command -v codex && codex --version 2>/dev/null | head -1',
|
|
99
|
-
],
|
|
100
|
-
],
|
|
101
|
-
];
|
|
102
|
-
for (const [label, cmd] of tools) {
|
|
103
|
-
const r = await run(machine, `verify ${label}`, cmd, 60);
|
|
104
|
-
if (r.exitCode !== 0) failures.push(`${label} not runnable`);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// Prove the CA bundle (the TLS "No response" fix) is materialized + non-empty.
|
|
108
|
-
const ca = await run(machine, 'verify CA bundle', [
|
|
109
|
-
'/bin/sh',
|
|
110
|
-
'-c',
|
|
111
|
-
`test -s ${guestCaBundlePath} && wc -c <${guestCaBundlePath}`,
|
|
112
|
-
]);
|
|
113
|
-
if (ca.exitCode !== 0) failures.push('CA bundle missing/empty');
|
|
114
|
-
|
|
115
|
-
// Prove the provision-check predicate the supervisor gates on passes.
|
|
116
|
-
const check = await run(
|
|
117
|
-
machine,
|
|
118
|
-
'provisionCheckCommand',
|
|
119
|
-
guestProvisionCheckCommand(CODEX_VERSION)
|
|
120
|
-
);
|
|
121
|
-
if (check.exitCode !== 0) failures.push('provisionCheckCommand failed');
|
|
122
|
-
|
|
123
|
-
// Bonus: real outbound TLS from inside the guest (DNS + CA chain end-to-end).
|
|
124
|
-
await run(machine, 'guest TLS egress (https HEAD)', [
|
|
125
|
-
'/bin/sh',
|
|
126
|
-
'-c',
|
|
127
|
-
'curl -sS -o /dev/null -w "%{http_code}" https://registry.npmjs.org/ || echo CURL_FAILED',
|
|
128
|
-
]);
|
|
129
|
-
} finally {
|
|
130
|
-
log('tearing down VM ...');
|
|
131
|
-
try {
|
|
132
|
-
await machine.stop();
|
|
133
|
-
} catch (e) {
|
|
134
|
-
log('stop error (non-fatal):', String(e).slice(0, 120));
|
|
135
|
-
}
|
|
136
|
-
if (typeof machine.delete === 'function') {
|
|
137
|
-
try {
|
|
138
|
-
await machine.delete();
|
|
139
|
-
} catch (e) {
|
|
140
|
-
log('delete error (non-fatal):', String(e).slice(0, 120));
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (failures.length > 0) {
|
|
146
|
-
console.error('[provision-proof] FAILED:', failures.join('; '));
|
|
147
|
-
process.exit(1);
|
|
148
|
-
}
|
|
149
|
-
log(`DONE-OK - full toolchain installed + verified in ${Date.now() - t0}ms`);
|
|
150
|
-
process.exit(0);
|