OpenAI's Codex Security CLI and TypeScript SDK for finding, validating, and fixing security vulnerabilities. npm: https://www.npmjs.com/package/@openai/codex-security
TypeScript ai-securityapplication-securityclicode-scanningcodexcodex-securitycybersecuritydevsecopsnodejsnpmopenaisdksecuritytypescriptvulnerability-scanning
fix: restore the SDK package and add Docker CI (#11)
mldangelo-oai0493698cbeb2
diff --git a/.github/workflows/container-ci.yml b/.github/workflows/container-ci.ymlnew file mode 100644index 000000000..ccf8bf1a6--- /dev/null+++ b/.github/workflows/container-ci.yml@@ -0,0 +1,155 @@+name: container-ci++on:+ push:+ branches: [main]+ paths:+ - .dockerignore+ - .github/workflows/container-ci.yml+ - Dockerfile+ - Dockerfile.dockerignore+ - compose.yaml+ - docker/**+ - sdk/typescript/**+ pull_request:+ paths:+ - .dockerignore+ - .github/workflows/container-ci.yml+ - Dockerfile+ - Dockerfile.dockerignore+ - compose.yaml+ - docker/**+ - sdk/typescript/**+ workflow_dispatch:++permissions:+ contents: read++jobs:+ container:+ name: linux-amd64+ runs-on: ubuntu-latest+ timeout-minutes: 30++ steps:+ - name: Checkout repository+ uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2+ with:+ persist-credentials: false++ - name: Verify customer build excludes secrets and scan data+ shell: bash+ run: |+ set -euo pipefail+ ignore_file=.dockerignore+ if [[ -f Dockerfile.dockerignore ]]; then+ ignore_file=Dockerfile.dockerignore+ if ! cmp -s .dockerignore "$ignore_file"; then+ echo "Dockerfile-specific ignore rules must match the approved customer baseline." >&2+ exit 1+ fi+ fi++ if grep -Fq '!' "$ignore_file"; then+ echo "Customer Docker ignore rules must not re-include excluded files: $ignore_file" >&2+ exit 1+ fi++ for pattern in \+ '**/.env' \+ '**/.env.*' \+ '**/.npmrc' \+ '**/node_modules' \+ '**/*.csv' \+ '**/repositories.csv' \+ '**/results' \+ '**/security-scans' \+ '**/state'; do+ if ! grep -Fxq -- "$pattern" "$ignore_file"; then+ echo "Missing customer Docker build exclusion in $ignore_file: $pattern" >&2+ exit 1+ fi+ done++ - name: Set up Docker Buildx+ uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3++ - name: Build customer container+ uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6+ with:+ context: .+ load: true+ platforms: linux/amd64+ push: false+ tags: codex-security:ci++ - name: Verify bundled scanner+ run: |+ docker run --rm codex-security:ci --version+ docker run --rm codex-security:ci bulk-scan --help+ docker run --rm codex-security:ci info --json++ - name: Validate hardened customer Compose configuration+ env:+ CODEX_SECURITY_IMAGE: codex-security:ci+ run: |+ mkdir -p results state+ chmod 700 results state+ printf 'id,repository,revision\n' > repositories.csv+ export CODEX_SECURITY_USER="$(id -u):$(id -g)"+ docker compose config --quiet+ docker compose run --rm codex-security --version++ - name: Verify hardened Codex command sandbox+ shell: bash+ run: |+ set -euo pipefail+ command=(+ docker run --rm+ --cap-drop ALL+ --security-opt no-new-privileges+ --security-opt "seccomp=$GITHUB_WORKSPACE/docker/codex-security-seccomp.json"+ --entrypoint node+ codex-security:ci+ /usr/local/lib/node_modules/@openai/codex-security/node_modules/@openai/codex/bin/codex.js+ )++ if output="$("${command[@]}" sandbox /usr/bin/true 2>&1)"; then+ printf '%s\n' "$output"+ elif grep -Eq 'bwrap: (Failed to make / slave: Permission denied|loopback: Failed RTM_NEW(ADDR|LINK): Operation not permitted|setting up uid map: Permission denied|No permissions to create a new namespace)' <<< "$output"; then+ echo '::warning::This Docker host blocks nested Bubblewrap namespaces; verifying the supported Landlock fallback.'+ "${command[@]}" sandbox --enable use_legacy_landlock /usr/bin/true+ else+ printf 'The hardened Codex sandbox failed unexpectedly:\n%s\n' "$output" >&2+ exit 1+ fi++ - name: Reject interactive repository discovery+ shell: bash+ run: |+ set -euo pipefail+ if output="$(docker run --rm -t codex-security:ci bulk-scan 2>&1)"; then+ echo "The customer container must require a repository CSV." >&2+ exit 1+ else+ status=$?+ fi+ if [[ "$status" -ne 2 ]]; then+ printf 'The customer container returned unexpected exit status %s:\n%s\n' "$status" "$output" >&2+ exit 1+ fi+ expected='codex-security: bulk-scan requires a repository CSV; interactive discovery is not supported in this image.'+ if [[ "${output//$'\r'/}" != "$expected" ]]; then+ printf 'The customer container returned an unexpected repository discovery error:\n%s\n' "$output" >&2+ exit 1+ fi++ - name: Verify host-scoped noninteractive Git credentials+ shell: bash+ run: |+ set -euo pipefail+ docker run --rm \+ --entrypoint /bin/sh \+ --env GH_TOKEN=SYNTHETIC_GITHUB_TOKEN \+ codex-security:ci \+ -ec 'actual="$(printf "protocol=https\nhost=github.com\n\n" | /usr/local/bin/codex-security-git-credential get)"; test "$actual" = "$(printf "username=x-access-token\npassword=SYNTHETIC_GITHUB_TOKEN")"; test -z "$(printf "protocol=https\nhost=untrusted.example\n\n" | /usr/local/bin/codex-security-git-credential get)"'diff --git a/sdk/typescript/_bundled_plugin/scripts/normalize_candidates.py b/sdk/typescript/_bundled_plugin/scripts/normalize_candidates.pynew file mode 100644index 000000000..d4de4c128--- /dev/null+++ b/sdk/typescript/_bundled_plugin/scripts/normalize_candidates.py@@ -0,0 +1,276 @@+#!/usr/bin/env python3+"""Validate and combine security-scan candidates into deterministic JSONL."""++from __future__ import annotations++import argparse+import hashlib+import json+import re+import sys+import tempfile+from pathlib import Path, PurePosixPath+from typing import Any++CWE = re.compile(r"(?i)CWE-(\d+)")+ROLES = {+ "entrypoint": 0,+ "entrypoint/wrapper": 1,+ "source": 2,+ "root_control": 3,+ "sink": 4,+ "concrete_implementation": 5,+ "evidence": 6,+}+FIELDS = {+ "candidate_id",+ "cwe_ids",+ "locations",+ "summary",+ "evidence",+ "context",+ "instance",+}+++def text_field(row: dict[str, Any], field: str, *, required: bool = True) -> str | None:+ value = row.get(field)+ if value is None and not required:+ return None+ if not isinstance(value, str) or not value.strip():+ raise ValueError(f"{field}: expected a non-empty string")+ return value.strip()+++def cwe_ids(row: dict[str, Any]) -> list[str]:+ value = row.get("cwe_ids")+ if not isinstance(value, list):+ raise ValueError("cwe_ids: expected an array")+ found: set[int] = set()+ for item in value:+ if not isinstance(item, str):+ raise ValueError("cwe_ids: expected CWE strings")+ match = CWE.fullmatch(item.strip())+ if match is None or int(match[1]) < 1:+ raise ValueError(f"cwe_ids: unsupported value {item!r}")+ found.add(int(match[1]))+ return [f"CWE-{number}" for number in sorted(found)]+++def relative_file(value: Any, repo_root: Path) -> tuple[str, Path]:+ if not isinstance(value, str) or not value or "\0" in value:+ raise ValueError("path: expected a non-empty repository-relative path")+ raw = value+ if sys.platform == "win32":+ raw = raw.replace("\\", "/")+ path = PurePosixPath(raw)+ if (+ path.is_absolute()+ or ".." in path.parts+ or (sys.platform == "win32" and re.match(r"^[A-Za-z]:", raw))+ ):+ raise ValueError("path: expected a repository-relative path without traversal")+ resolved = (repo_root / raw).resolve(strict=True)+ try:+ relative = resolved.relative_to(repo_root).as_posix()+ except ValueError as error:+ raise ValueError("path: must resolve inside --repo-root") from error+ if not resolved.is_file():+ raise ValueError("path: expected a regular file")+ return relative, resolved+++def positive_line(value: Any, field: str) -> int:+ if not isinstance(value, int) or isinstance(value, bool) or value < 1:+ raise ValueError(f"{field}: expected a positive integer")+ return value+++def normalize_locations(+ row: dict[str, Any], repo_root: Path, line_counts: dict[Path, int]+) -> list[dict[str, Any]]:+ value = row.get("locations")+ if not isinstance(value, list) or not value:+ raise ValueError("locations: expected a non-empty array")+ normalized: dict[tuple[str, int, int, str], dict[str, Any]] = {}+ for item in value:+ if not isinstance(item, dict):+ raise ValueError("locations: expected location objects")+ unknown = set(item) - {"path", "start_line", "end_line", "role"}+ if unknown:+ raise ValueError(f"locations: unsupported fields {', '.join(sorted(unknown))}")+ relative, source = relative_file(item.get("path"), repo_root)+ start = positive_line(item.get("start_line"), "start_line")+ end = positive_line(item.get("end_line", start), "end_line")+ if end < start:+ raise ValueError("end_line: must be greater than or equal to start_line")+ if source not in line_counts:+ line_counts[source] = len(source.read_bytes().splitlines())+ if end > line_counts[source]:+ raise ValueError(f"line range {start}-{end} exceeds {relative}:{line_counts[source]}")+ role = item.get("role")+ if not isinstance(role, str) or role not in ROLES:+ raise ValueError(f"role: unsupported value {role!r}")+ key = (relative, start, end, role)+ normalized[key] = {+ "path": relative,+ "start_line": start,+ "end_line": end,+ "role": role,+ }+ return sorted(+ normalized.values(),+ key=lambda item: (+ ROLES[item["role"]],+ item["path"],+ item["start_line"],+ item["end_line"],+ ),+ )+++def read_scope(path: Path, repo_root: Path) -> set[str]:+ scope: set[str] = set()+ for number, line in enumerate(path.read_bytes().decode("utf-8").split("\n"), 1):+ if sys.platform == "win32":+ line = line.removesuffix("\r")+ if not line:+ continue+ try:+ relative, _ = relative_file(line, repo_root)+ except (OSError, ValueError) as error:+ raise ValueError(f"in-scope file row {number}: {error}") from error+ scope.add(relative)+ return scope+++def normalize_candidate(+ row: dict[str, Any], repo_root: Path, scope: set[str], line_counts: dict[Path, int]+) -> dict[str, Any]:+ unknown = set(row) - FIELDS+ if unknown:+ raise ValueError(f"unsupported fields {', '.join(sorted(unknown))}")+ if "candidate_id" in row:+ text_field(row, "candidate_id")+ candidate_locations = normalize_locations(row, repo_root, line_counts)+ if not any(item["path"] in scope for item in candidate_locations):+ raise ValueError("locations: expected at least one in-scope file")+ result: dict[str, Any] = {+ "cwe_ids": cwe_ids(row),+ "locations": candidate_locations,+ "summary": text_field(row, "summary"),+ "evidence": text_field(row, "evidence"),+ }+ context = text_field(row, "context", required=False)+ if context is not None:+ result["context"] = context+ instance = text_field(row, "instance", required=False)+ if instance is not None:+ result["instance"] = instance+ return result+++def identity(row: dict[str, Any]) -> str:+ return json.dumps(+ {+ "cwe_ids": row["cwe_ids"],+ "locations": row["locations"],+ "instance": row.get("instance"),+ },+ ensure_ascii=False,+ separators=(",", ":"),+ sort_keys=True,+ )+++def merged_text(group: list[dict[str, Any]], field: str) -> str:+ return "\n".join(sorted({item[field] for item in group if field in item}))+++def combine(rows: list[dict[str, Any]]) -> list[dict[str, Any]]:+ groups: dict[str, list[dict[str, Any]]] = {}+ for row in rows:+ groups.setdefault(identity(row), []).append(row)+ combined: list[dict[str, Any]] = []+ for key, group in sorted(groups.items()):+ candidate_id = hashlib.sha256(key.encode()).hexdigest()[:16]++ result = {+ "candidate_id": f"candidate-{candidate_id}",+ "cwe_ids": group[0]["cwe_ids"],+ "locations": group[0]["locations"],+ "summary": merged_text(group, "summary"),+ "evidence": merged_text(group, "evidence"),+ }+ context = merged_text(group, "context")+ if context:+ result["context"] = context+ if "instance" in group[0]:+ result["instance"] = group[0]["instance"]+ combined.append(result)+ return combined+++def main() -> None:+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("--input", nargs="+", required=True, help="Candidate JSONL inputs.")+ parser.add_argument("--out", required=True, help="Combined candidate JSONL output.")+ parser.add_argument("--repo-root", required=True, help="Repository root for candidate paths.")+ parser.add_argument("--in-scope-files", required=True, help="Repository-relative file list.")+ args = parser.parse_args()+ try:+ repo_root = Path(args.repo_root).expanduser().resolve(strict=True)+ if not repo_root.is_dir():+ raise ValueError("--repo-root: expected a directory")+ output = Path(args.out).expanduser().resolve(strict=False)+ scope_path = Path(args.in_scope_files).expanduser().resolve(strict=True)+ inputs = sorted({Path(value).expanduser().resolve(strict=True) for value in args.input})+ if output in inputs:+ raise ValueError("--out: must not also be an input")+ if output == scope_path:+ raise ValueError("--out: must not replace --in-scope-files")+ scope = read_scope(scope_path, repo_root)+ line_counts: dict[Path, int] = {}+ rows: list[dict[str, Any]] = []+ for source in inputs:+ with source.open(encoding="utf-8") as handle:+ for number, line in enumerate(handle, 1):+ if not line.strip():+ continue+ try:+ row = json.loads(line)+ if not isinstance(row, dict):+ raise ValueError("expected a JSON object")+ rows.append(normalize_candidate(row, repo_root, scope, line_counts))+ except (ValueError, TypeError, OSError) as error:+ raise ValueError(f"{source} row {number}: {error}") from error+ combined = combine(rows)+ output.parent.mkdir(parents=True, exist_ok=True)+ payload = "".join(+ json.dumps(row, ensure_ascii=False, separators=(",", ":"), sort_keys=True) + "\n"+ for row in combined+ )+ temporary: Path | None = None+ try:+ with tempfile.NamedTemporaryFile(+ mode="w",+ encoding="utf-8",+ dir=output.parent,+ prefix=f".{output.name}.",+ suffix=".tmp",+ delete=False,+ ) as handle:+ temporary = Path(handle.name)+ handle.write(payload)+ temporary.replace(output)+ finally:+ if temporary is not None:+ temporary.unlink(missing_ok=True)+ print(f"Combined {len(rows)} candidate rows into {len(combined)} rows in {output}")+ except (OSError, ValueError) as error:+ print(f"normalize_candidates: {error}", file=sys.stderr)+ raise SystemExit(2) from error+++if __name__ == "__main__":+ main()diff --git a/sdk/typescript/tests-ts/api.test.ts b/sdk/typescript/tests-ts/api.test.tsindex 9d2ae101d..7f0bc6831 100644--- a/sdk/typescript/tests-ts/api.test.ts+++ b/sdk/typescript/tests-ts/api.test.ts@@ -1295,18 +1295,24 @@ describe("CodexSecurity orchestration", () => {},);- await expect(- client.run(repository, {+ // The fake Codex stream has no process handle to keep its unref'ed poll alive.+ const keepEventLoopAlive = setTimeout(() => {}, 10_000);+ try {+ await expect(+ client.run(repository, {+ maxCostUsd: 0.005,+ onCost: (cost) => costs.push(cost.estimatedUsd),+ signal: AbortSignal.timeout(5_000),+ }),+ ).rejects.toMatchObject({+ name: ScanCostLimitExceededError.name,maxCostUsd: 0.005,- onCost: (cost) => costs.push(cost.estimatedUsd),- signal: AbortSignal.timeout(5_000),- }),- ).rejects.toMatchObject({- name: ScanCostLimitExceededError.name,- maxCostUsd: 0.005,- scanDir,- cost,- });+ scanDir,+ cost,+ });+ } finally {+ clearTimeout(keepEventLoopAlive);+ }expect(costs.at(-1)).toBe(0.00625);expect(commands[1]).toEqual(["fail-scan",diff --git a/sdk/typescript/tests-ts/auth.test.ts b/sdk/typescript/tests-ts/auth.test.tsindex 39281ec2f..214c50bcf 100644--- a/sdk/typescript/tests-ts/auth.test.ts+++ b/sdk/typescript/tests-ts/auth.test.ts@@ -1,7 +1,8 @@-import { mkdtemp, readFile, rm, watch, writeFile } from "node:fs/promises";+import { ChildProcess } from "node:child_process";+import { mkdtemp, rm, writeFile } from "node:fs/promises";import { tmpdir } from "node:os";import { join } from "node:path";-import { afterEach, describe, expect, test } from "bun:test";+import { afterEach, describe, expect, spyOn, test } from "bun:test";import {accountStatus,CodexLoginHandle,@@ -125,47 +126,18 @@ describe("Codex authentication process boundary", () => {expect(succeeded).toBe(true);});- test("drains inherited stderr before resolving interactive login", async () => {- const root = await mkdtemp(join(tmpdir(), "codex-security-auth-drain-"));+ test("drains native login stderr before resolving authentication", async () => {+ const root = await mkdtemp(join(tmpdir(), "codex-security-auth-stderr-"));temporaryDirectories.push(root);- const script = join(root, "inherited-stderr.mjs");+ const script = join(root, "login-stderr.mjs");const message = "network timeout while authenticating";- const grandchildScript = `-process.once("disconnect", () => {- process.stderr.write(${JSON.stringify(`${message}\n`)});-});-process.send("ready");-`;await writeFile(script,- `-import { spawn } from "node:child_process";--const grandchild = spawn(process.execPath, ["-e", ${JSON.stringify(grandchildScript)}], {- stdio: ["ignore", "ignore", "inherit", "ipc"],- windowsHide: true,-});-const readyTimeout = setTimeout(() => {- grandchild.kill();- console.error("Timed out waiting for the login grandchild.");- process.exit(1);-}, 10_000);-grandchild.once("message", (message) => {- if (message === "ready") {- clearTimeout(readyTimeout);- process.exit(1);- }-});-grandchild.once("error", (error) => {- clearTimeout(readyTimeout);- console.error(error.message);- process.exit(1);-});-`,+ `process.stderr.write(${JSON.stringify(`${message}\n`)}, (error) => process.exit(error ? 2 : 1));\n`,);const handle = new CodexLoginHandle(- { command: process.execPath, prefixArgs: [script] },+ { command: "node", prefixArgs: [script] },["login"],process.env,() => {},@@ -178,105 +150,162 @@ grandchild.once("error", (error) => {});});- test- .skipIf(process.platform !== "win32")- .each([- "releases inherited login pipes when the Windows fallback fires",- "releases inherited login pipes after a native Windows process exits",- ])("%s", async () => {- const root = await mkdtemp(join(tmpdir(), "codex-security-auth-pipes-"));- temporaryDirectories.push(root);- const ready = join(root, "grandchild-ready");- const release = join(root, "release-grandchild");- const done = join(root, "grandchild-done");- const script = join(root, "inherited-pipes.mjs");- const grandchildScript = `-import { existsSync, watch, writeFileSync } from "node:fs";-import { join } from "node:path";+ test.skipIf(process.platform === "win32")(+ "drains inherited stderr before resolving interactive login",+ async () => {+ const root = await mkdtemp(join(tmpdir(), "codex-security-auth-drain-"));+ temporaryDirectories.push(root);+ const script = join(root, "inherited-stderr.mjs");+ const ready = join(root, "grandchild-ready");+ const release = join(root, "release-grandchild");+ const message = "network timeout while authenticating";+ const grandchildScript = `+import { existsSync, writeFileSync, writeSync } from "node:fs";-const root = process.argv[1];-const release = join(root, "release-grandchild");-const watcher = watch(root, () => {- if (existsSync(release)) {- watcher.close();- writeFileSync(join(root, "grandchild-done"), "done");- process.exit(0);+const ready = process.argv[1];+const release = process.argv[2];+const parentPid = Number(process.argv[3]);+const timeout = setTimeout(() => process.exit(1), 10_000);+const watcher = setInterval(() => {+ if (!existsSync(release)) return;+ try {+ process.kill(parentPid, 0);+ return;+ } catch (error) {+ if (error?.code !== "ESRCH") {+ clearInterval(watcher);+ clearTimeout(timeout);+ process.exit(1);+ }}-});-writeFileSync(join(root, "grandchild-ready"), "ready");-process.send("ready");-if (existsSync(release)) {- watcher.close();- writeFileSync(join(root, "grandchild-done"), "done");+ clearInterval(watcher);+ clearTimeout(timeout);+ writeSync(2, ${JSON.stringify(`${message}\n`)});process.exit(0);-}+}, 25);+writeFileSync(ready, "ready");`;- await writeFile(- script,- `+ await writeFile(+ script,+ `import { spawn } from "node:child_process";+import { existsSync, writeFileSync } from "node:fs";+const ready = ${JSON.stringify(ready)};+const release = ${JSON.stringify(release)};const grandchild = spawn(process.execPath,- ["-e", ${JSON.stringify(grandchildScript)}, ${JSON.stringify(root)}],- { stdio: ["ignore", "ignore", "inherit", "ipc"], windowsHide: true },+ ["-e", ${JSON.stringify(grandchildScript)}, ready, release, String(process.pid)],+ { stdio: ["ignore", "ignore", "inherit"], windowsHide: true },);const readyTimeout = setTimeout(() => {+ clearInterval(readyWatcher);grandchild.kill();- console.error("Timed out waiting for the Windows login grandchild.");+ console.error("Timed out waiting for the login grandchild.");process.exit(1);}, 10_000);-grandchild.once("message", (message) => {- if (message === "ready") {- clearTimeout(readyTimeout);- process.exit(0);- }-});+const readyWatcher = setInterval(() => {+ if (!existsSync(ready)) return;+ clearInterval(readyWatcher);+ clearTimeout(readyTimeout);+ writeFileSync(release, "released");+ process.exit(1);+}, 25);grandchild.once("error", (error) => {+ clearInterval(readyWatcher);clearTimeout(readyTimeout);console.error(error.message);process.exit(1);});`,- );+ );- const completionSignal = AbortSignal.timeout(20_000);- const grandchildDone = (async () => {- try {- for await (const event of watch(root, {- signal: completionSignal,- })) {- if (event.filename === "grandchild-done") {- return await readFile(done, "utf8");- }- }- } catch (error) {- if (completionSignal.aborted) {- throw new Error("The Windows login grandchild did not exit.", {- cause: error,- });- }- throw error;- }- throw new Error("The Windows login grandchild did not exit.");- })();- const handle = new CodexLoginHandle(- { command: process.execPath, prefixArgs: [script] },- ["login"],- process.env,- () => {},- );- try {+ const handle = new CodexLoginHandle(+ { command: "node", prefixArgs: [script] },+ ["login"],+ process.env,+ () => {},+ );+ await expect(handle.waitForInstructions()).rejects.toThrow(message);await expect(handle.wait()).resolves.toMatchObject({- success: true,- exitCode: 0,+ success: false,+ exitCode: 1,+ stderr: expect.stringContaining(message),});- await expect(readFile(ready, "utf8")).resolves.toBe("ready");- } finally {- await writeFile(release, "released");- await expect(grandchildDone).resolves.toBe("done");- }- });+ },+ );++ test.skipIf(process.platform !== "win32")(+ "releases native login pipes when the Windows fallback fires",+ async () => {+ const root = await mkdtemp(join(tmpdir(), "codex-security-auth-pipes-"));+ temporaryDirectories.push(root);+ const script = join(root, "login-pipes.mjs");+ await writeFile(+ script,+ 'process.stdout.write("ready\\n", () => process.exit(0));\n',+ );++ const originalOnce = ChildProcess.prototype.once;+ let loginChild: ChildProcess | undefined;+ let releaseClose: (() => void) | undefined;+ const processObserver = spyOn(ChildProcess.prototype, "once");+ processObserver.mockImplementation(function (+ this: ChildProcess,+ event: string,+ listener: (...eventArguments: never[]) => void,+ ) {+ if (event === "exit") loginChild = this;+ if (event === "close") {+ return Reflect.apply(originalOnce, this, [+ event,+ (...eventArguments: unknown[]) => {+ releaseClose = () =>+ Reflect.apply(listener, this, eventArguments);+ },+ ]);+ }+ return Reflect.apply(originalOnce, this, [event, listener]);+ });++ let handle: CodexLoginHandle;+ try {+ handle = new CodexLoginHandle(+ { command: "node", prefixArgs: [script] },+ ["login"],+ process.env,+ () => {},+ );+ } finally {+ processObserver.mockRestore();+ }++ try {+ const startedAt = Date.now();+ const timeout = AbortSignal.timeout(5_000);+ const completion = Promise.race([+ handle.wait(),+ new Promise<never>((_, reject) => {+ timeout.addEventListener(+ "abort",+ () => reject(new Error("The Windows login fallback timed out.")),+ { once: true },+ );+ }),+ ]);+ await expect(completion).resolves.toMatchObject({+ success: true,+ exitCode: 0,+ });+ expect(Date.now() - startedAt).toBeGreaterThanOrEqual(900);+ expect(releaseClose).toBeFunction();+ expect(loginChild?.stdout?.destroyed).toBe(true);+ expect(loginChild?.stderr?.destroyed).toBe(true);+ } finally {+ releaseClose?.();+ }+ },+ );test("does not report a canceled interactive login as successful", async () => {const root = await mkdtemp(join(tmpdir(), "codex-security-auth-cancel-"));diff --git a/sdk/typescript/tests-ts/cli.test.ts b/sdk/typescript/tests-ts/cli.test.tsindex 763a9f6b3..2235d9bad 100644--- a/sdk/typescript/tests-ts/cli.test.ts+++ b/sdk/typescript/tests-ts/cli.test.ts@@ -11,7 +11,7 @@ import {writeFile,} from "node:fs/promises";import { tmpdir } from "node:os";-import { delimiter, join } from "node:path";+import { delimiter, join, normalize } from "node:path";import { Writable } from "node:stream";import { fileURLToPath, pathToFileURL } from "node:url";import { stripVTControlCharacters } from "node:util";@@ -182,10 +182,12 @@ describe("CLI", () => {deps,),).toBe(0);- expect(JSON.parse(stdout.text())).toEqual({- hook,- failOnSeverity: "medium",- });+ const result = JSON.parse(stdout.text()) as {+ hook: string;+ failOnSeverity: string;+ };+ expect(normalize(result.hook)).toBe(hook);+ expect(result.failOnSeverity).toBe("medium");}expect(await readFile(hook, "utf8")).toContain("--working-tree --fail-on-severity medium",@@ -206,10 +208,12 @@ describe("CLI", () => {deps,),).toBe(0);- expect(JSON.parse(migratedHook.text())).toEqual({- hook,- failOnSeverity: "medium",- });+ const migrated = JSON.parse(migratedHook.text()) as {+ hook: string;+ failOnSeverity: string;+ };+ expect(normalize(migrated.hook)).toBe(hook);+ expect(migrated.failOnSeverity).toBe("medium");expect(await readFile(hook, "utf8")).toBe(trustedHook);const existingHook = capture();@@ -302,7 +306,7 @@ describe("CLI", () => {await expect(stat(maliciousMarker)).rejects.toMatchObject({code: "ENOENT",});- expect(trustedHook).not.toContain("npx");+ expect(trustedHook).not.toMatch(/^exec\s+npx(?:\s|$)/m);expect(trustedHook).toContain(await realpath(process.execPath));expect(trustedHook).toContain(await realpath(