Reverse engineer anything with agents, from app behavior down to native binaries.
TypeScript agent-skillsai-agentsbinary-analysisclaude-codeclicodexcordisdecompilerdeveloper-toolsdshdsh-pluginghidrahopperllmmcpmodel-context-protocolreareverse-engineeringstatic-analysistouhou
fix(ci): isolate packed Python syntax checks from ambient imports (#6293)
gensokyo-dev21f9af9d93da
diff --git a/docs/testing.md b/docs/testing.mdindex ef6e98da5..a148f37fc 100644--- a/docs/testing.md+++ b/docs/testing.md@@ -258,6 +258,13 @@ cases. Share setup without hiding inputs or expected evidence. For successful`.ok` assertion adds no coverage. Protocol fixtures must reject unmodeledcommands and preserve actual producer reply shapes.+Packed bridge validation uses Python's standard-library AST and tar readers+with `-I -S`: caller-local modules, `PYTHONPATH`, and site startup hooks must+not replace those readers or execute during validation. Controlled `ast.py`+and `sitecustomize.py` fixtures must leave their markers absent and still+reject malformed packed Python with `SyntaxError`. This checks static package+verification, not real Hopper or Ghidra behavior.+Stateless source-analysis matrices may share a file-owned stdio MCP connectionand retain representative compiled CLI parity checks. Every distinct sourcescenario still runs through the public workflow; session-lifecycle scenariosdiff --git a/scripts/verify-packed-bridge.mjs b/scripts/verify-packed-bridge.mjsindex 5f4116874..70d2aa65c 100644--- a/scripts/verify-packed-bridge.mjs+++ b/scripts/verify-packed-bridge.mjs@@ -18,7 +18,11 @@ export async function verifyPackedBridge({ tarball, packedFiles }) {if (!packedFiles.includes(path)) throw new Error(`package omitted ${path}`);}// Read the packed source without extracting into the caller's leased root.+ // Only the interpreter's standard library is needed; caller-local modules+ // and site startup hooks must not replace the parser or execute here.await exec("python3", [+ "-I",+ "-S","-c",["import ast, sys, tarfile",diff --git a/tests/boundary/process/packedBridgeVerification.test.ts b/tests/boundary/process/packedBridgeVerification.test.tsindex df9d5ba3b..344d17671 100644--- a/tests/boundary/process/packedBridgeVerification.test.ts+++ b/tests/boundary/process/packedBridgeVerification.test.ts@@ -10,6 +10,7 @@ import {import { dirname, join } from "node:path";import { promisify } from "node:util";import { expect, it } from "vitest";+import { z } from "zod";import { verifyPackedBridge } from "../../../scripts/verify-packed-bridge.mjs";import {@@ -56,6 +57,69 @@ it("parses packed Python without executing it or extracting archive members", asexpect(await readFile(sentinel, "utf8")).toBe("preserved\n");});+it.each(["cwd", "pythonpath", "sitecustomize"] as const)(+ "rejects invalid packed Python without importing ambient %s code",+ async (kind) => {+ const input = await fixture("def broken(:\n");+ const modules = join(input.workspace, "local modules");+ await mkdir(modules);+ const marker = join(input.workspace, "ambient-import-executed.txt");+ const moduleSource = [+ "import os",+ "from pathlib import Path",+ "Path(os.environ['REA_PACKED_IMPORT_MARKER']).write_text('executed')",+ ...(kind === "sitecustomize"+ ? ["import ast", "ast.parse = lambda *args, **kwargs: None"]+ : ["def parse(*args, **kwargs): return None"]),+ ].join("\n");+ await writeFile(+ join(modules, kind === "sitecustomize" ? "sitecustomize.py" : "ast.py"),+ moduleSource,+ );+ const verifier = new URL(+ "../../../scripts/verify-packed-bridge.mjs",+ import.meta.url,+ ).href;+ // A separate Node process owns cwd/environment changes; the Vitest worker+ // and its other subprocess fixtures retain their original environment.+ const result = await exec(+ process.execPath,+ [+ "--input-type=module",+ "--eval",+ `import { verifyPackedBridge } from ${JSON.stringify(verifier)};+try {+ await verifyPackedBridge(JSON.parse(process.env.REA_PACKED_VERIFY_INPUT));+ console.log(JSON.stringify({ accepted: true }));+} catch (error) {+ console.log(JSON.stringify({ accepted: false, stderr: String(error.stderr) }));+}`,+ ],+ {+ cwd: kind === "cwd" ? modules : input.workspace,+ env: {+ ...Object.fromEntries(+ Object.entries(process.env).filter(+ ([name]) => name.toLowerCase() !== "pythonpath",+ ),+ ),+ PYTHONPATH: kind === "cwd" ? "" : modules,+ REA_PACKED_IMPORT_MARKER: marker,+ REA_PACKED_VERIFY_INPUT: JSON.stringify(input),+ },+ },+ );+ const observation = z+ .object({ accepted: z.boolean(), stderr: z.string().optional() })+ .parse(JSON.parse(result.stdout));+ expect(observation).toMatchObject({+ accepted: false,+ stderr: expect.stringContaining("SyntaxError"),+ });+ await expect(access(marker)).rejects.toMatchObject({ code: "ENOENT" });+ },+);+it.each(packedFiles)("rejects an unadvertised required member: %s",async (member) => {@@ -121,6 +185,8 @@ it.each(["symlink", "hardlink", "directory"])(async (kind) => {const input = await fixture();await exec("python3", [+ "-I",+ "-S","-c",["import io, sys, tarfile",