From 854d7e1bef0b2713b6b07dc122d3652aa2f7bcb6 Mon Sep 17 00:00:00 2001 From: Dotta Date: Thu, 8 Oct 2026 10:23:31 -0500 Subject: [PATCH] test: handle empty npm optional Codex slots in consumer verification Co-Authored-By: Paperclip --- .../grok-public-install-sandbox.test.mjs | 11 +++++++++++ scripts/grok-public-install-sandbox.mjs | 16 ++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/scripts/__tests__/grok-public-install-sandbox.test.mjs b/scripts/__tests__/grok-public-install-sandbox.test.mjs index 7942052cab8..ef296af1e50 100644 --- a/scripts/__tests__/grok-public-install-sandbox.test.mjs +++ b/scripts/__tests__/grok-public-install-sandbox.test.mjs @@ -93,6 +93,17 @@ test('the installed Codex probe exercises the public export and rejects incomple assert.equal(JSON.parse(result.stdout).codexCommandLeaseVerified, true); assert.equal(readFileSync(join(server, 'lease-closed'), 'utf8'), 'ok'); assert.equal(JSON.parse(result.stdout).providerCalls, 0); + const emptySlot = join(server, 'node_modules/@openai/codex-' + target); + mkdirSync(emptySlot, { recursive: true }); + result = run(); assert.equal(result.status, 0, result.stderr); + assert.equal(JSON.parse(result.stdout).codexPlatformPackages.length, 1, + 'An empty nested npm optional slot must not obscure the qualified hoisted host package'); + writeFileSync(join(emptySlot, 'undeclared-native-payload'), 'native fixture; never executed'); + result = run(); assert.notEqual(result.status, 0); assert.match(result.stderr, /empty regular directory; found.*undeclared-native-payload/); + rmSync(join(emptySlot, 'undeclared-native-payload')); + writeFileSync(join(emptySlot, 'package.json'), '{ malformed'); + result = run(); assert.notEqual(result.status, 0); assert.match(result.stderr, /SyntaxError/); + rmSync(join(emptySlot, 'package.json')); writeFileSync(integrity, moduleSource.replace('assert.deepEqual(profile,', "throw new Error('qualified executable digest mismatch'); assert.deepEqual(profile,")); result = run(); assert.notEqual(result.status, 0); assert.match(result.stderr, /qualified executable digest mismatch/); writeFileSync(integrity, moduleSource.replace("writeFileSync(", "throw new Error('command lease close failed'); writeFileSync(")); diff --git a/scripts/grok-public-install-sandbox.mjs b/scripts/grok-public-install-sandbox.mjs index 35595b58425..4fbc8ab0ebc 100644 --- a/scripts/grok-public-install-sandbox.mjs +++ b/scripts/grok-public-install-sandbox.mjs @@ -63,7 +63,7 @@ export function installedCodexProbeSource(indexPath, consumerRoot, expectedVersi import assert from 'node:assert/strict'; import { execFileSync } from 'node:child_process'; import { createRequire } from 'node:module'; - import { accessSync, constants, existsSync, readFileSync, readdirSync, realpathSync, statSync } from 'node:fs'; + import { accessSync, constants, existsSync, lstatSync, readFileSync, readdirSync, realpathSync, statSync } from 'node:fs'; import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'; import { pathToFileURL } from 'node:url'; const root = realpathSync(${JSON.stringify(consumerRoot)}); @@ -83,7 +83,19 @@ export function installedCodexProbeSource(indexPath, consumerRoot, expectedVersi assert.ok(++visited <= 10000 && contained(packageRoot), 'Installed dependency graph must be bounded and contained'); const path = relative(root, packageRoot).split(sep).join('/'); if (${/(?:^|\/)node_modules\/@openai\/codex-(?:linux|darwin|win32)-(?:x64|arm64)$/.toString()}.test(path)) { - installed.push({ path, manifest: JSON.parse(readFileSync(join(packageRoot, 'package.json'), 'utf8')) }); + let manifest; + try { manifest = JSON.parse(readFileSync(join(packageRoot, 'package.json'), 'utf8')); } + catch (error) { + if (error.code !== 'ENOENT') throw error; + const contents = readdirSync(packageRoot), slot = lstatSync(packageRoot); + assert.ok(slot.isDirectory() && !slot.isSymbolicLink() && contents.length === 0, + 'Codex optional slot without a manifest must be an empty regular directory; found ' + + JSON.stringify(contents.sort().slice(0, 16).map(name => name.slice(0, 256)))); + // npm can leave an empty nested optional slot while hoisting the + // actual host payload. Its real lock and manifest still qualify below. + continue; + } + installed.push({ path, manifest }); } const nested = join(packageRoot, 'node_modules'); if (existsSync(nested)) pending.push(nested);