Skip to content

Commit 2373750

Browse files
test(operator): cover image rollout preflight
1 parent 49a0f77 commit 2373750

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import assert from "node:assert/strict"
2+
import fs from "node:fs"
3+
import os from "node:os"
4+
import path from "node:path"
5+
import { spawnSync } from "node:child_process"
6+
7+
const script = path.resolve(process.argv[2] || new URL("./codex-image-rollout-preflight.mjs", import.meta.url).pathname)
8+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "codex-image-rollout-preflight-"))
9+
10+
function run(sessionsRoot, extraEnv = {}) {
11+
const result = spawnSync(process.execPath, [script, "--sessions-root", sessionsRoot, "--json"], {
12+
encoding: "utf8",
13+
env: {
14+
...process.env,
15+
OPERATOR_CODEX_IMAGE_ROLLOUT_WARNING_MIB: "1",
16+
OPERATOR_CODEX_IMAGE_ROLLOUT_CRITICAL_MIB: "4",
17+
OPERATOR_CODEX_IMAGE_ROLLOUT_MAX_SCAN_MIB: "32",
18+
...extraEnv,
19+
},
20+
})
21+
let parsed = null
22+
if (result.stdout.trim()) parsed = JSON.parse(result.stdout)
23+
return { ...result, parsed }
24+
}
25+
26+
try {
27+
const clean = path.join(root, "clean")
28+
fs.mkdirSync(clean, { recursive: true })
29+
fs.writeFileSync(path.join(clean, "small.jsonl"), '{"type":"message","text":"ok"}\n')
30+
const cleanResult = run(clean)
31+
assert.equal(cleanResult.status, 0)
32+
assert.equal(cleanResult.parsed.desktop_safe_to_launch, true)
33+
assert.equal(cleanResult.parsed.status, "clean")
34+
35+
const inline = path.join(root, "inline")
36+
fs.mkdirSync(inline, { recursive: true })
37+
fs.writeFileSync(
38+
path.join(inline, "image.jsonl"),
39+
`${"x".repeat(1024 * 1024)}data:image/png;base64,AAAA`,
40+
)
41+
const inlineResult = run(inline)
42+
assert.equal(inlineResult.status, 75)
43+
assert.equal(inlineResult.parsed.desktop_safe_to_launch, false)
44+
assert(inlineResult.parsed.findings.some((item) => item.code === "inline_image_rollout"))
45+
46+
const oversized = path.join(root, "oversized")
47+
fs.mkdirSync(oversized, { recursive: true })
48+
fs.writeFileSync(path.join(oversized, "large.jsonl"), Buffer.alloc(5 * 1024 * 1024, 0x61))
49+
const oversizedResult = run(oversized)
50+
assert.equal(oversizedResult.status, 75)
51+
assert(oversizedResult.parsed.findings.some((item) => item.code === "oversized_rollout"))
52+
53+
if (process.platform !== "win32") {
54+
const symlinked = path.join(root, "symlinked")
55+
fs.mkdirSync(symlinked, { recursive: true })
56+
fs.symlinkSync(path.join(clean, "small.jsonl"), path.join(symlinked, "linked.jsonl"))
57+
const symlinkResult = run(symlinked)
58+
assert.equal(symlinkResult.status, 75)
59+
assert(symlinkResult.parsed.findings.some((item) => item.code === "symlink_in_sessions"))
60+
}
61+
62+
console.log("codex image-rollout preflight self-test passed")
63+
} finally {
64+
fs.rmSync(root, { recursive: true, force: true })
65+
}

0 commit comments

Comments
 (0)