chore: merge main into feat/pkg-inventory
main now carries #1037 at skill version 30, so this branch moves to 31. Regenerate the product catalog, conformance manifest, skill digest and package metadata on top of it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,691 @@
|
||||
import {
|
||||
createTestWorkspace,
|
||||
removeTestWorkspace,
|
||||
} from "../../support/workspace/workspaceFixture.js";
|
||||
import { access, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { z } from "zod";
|
||||
import { expect, it, onTestFinished } from "vitest";
|
||||
import { PwntoolsLayoutProvider } from "../../../src/native/pwntools/PwntoolsLayoutProvider.js";
|
||||
import { PWNTOOLS_PROVIDER_IDENTITY } from "../../../src/native/pwntools/PwntoolsRelease.js";
|
||||
import { spawnOwnedProviderProcess } from "../../../src/process/ProviderProcess.js";
|
||||
import { waitForProviderProcessReady } from "../../fixtures/providerProcess.js";
|
||||
import { PrivateRuntimeRoot } from "../../../src/process/PrivateRuntimeRoot.js";
|
||||
import { binaryLayoutFixture } from "../../fixtures/binaryDiagnostics/layout.js";
|
||||
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
|
||||
|
||||
const unsupportedHost = process.platform !== "linux" || process.arch !== "x64";
|
||||
const requestSchema = z.strictObject({
|
||||
snapshot_path: z.string(),
|
||||
reply_path: z.string(),
|
||||
});
|
||||
|
||||
it.runIf(!unsupportedHost).each([
|
||||
["SIGXCPU", "reported", "cpu"],
|
||||
["SIGXCPU", "missing", "cpu"],
|
||||
["SIGXCPU", "malformed", "cpu"],
|
||||
["SIGXFSZ", "reported", "file-size"],
|
||||
["EFBIG", "reported", "file-size"],
|
||||
["EFBIG", "malformed", "file-size"],
|
||||
] as const)(
|
||||
"preserves observed %s with %s limit evidence",
|
||||
async (failure, scenario, resource) => {
|
||||
const { path } = await fixture();
|
||||
let ownedPath = "";
|
||||
const limits = {
|
||||
address_space_bytes: 3221225472,
|
||||
cpu_seconds: 1,
|
||||
file_size_bytes: 1024,
|
||||
};
|
||||
const provider = new PwntoolsLayoutProvider(
|
||||
{ REA_PWNTOOLS_PYTHON: process.execPath },
|
||||
async (spawn) => {
|
||||
ownedPath = spawn.cwd ?? "";
|
||||
if (failure === "EFBIG")
|
||||
await writeFile(join(ownedPath, "resource.failure"), "F");
|
||||
if (scenario !== "missing")
|
||||
await writeFile(
|
||||
join(ownedPath, "limits.json"),
|
||||
scenario === "reported"
|
||||
? JSON.stringify(limits)
|
||||
: '{"cpu_seconds":999}',
|
||||
);
|
||||
return spawnOwnedProviderProcess({
|
||||
...spawn,
|
||||
command: process.execPath,
|
||||
arguments: [
|
||||
"-e",
|
||||
failure === "EFBIG"
|
||||
? 'process.stdout.write("resource diagnostic", () => { process.exitCode = 76; })'
|
||||
: failure === "SIGXFSZ"
|
||||
? 'process.on("SIGXFSZ", () => { process.removeAllListeners("SIGXFSZ"); process.kill(process.pid, "SIGXFSZ"); }); process.stdout.write("resource diagnostic", () => process.kill(process.pid, "SIGXFSZ")); setTimeout(() => {}, 1000);'
|
||||
: `process.stdout.write("resource diagnostic", () => process.kill(process.pid, "${failure}"))`,
|
||||
],
|
||||
});
|
||||
},
|
||||
);
|
||||
const result = await provider.inspect({ path });
|
||||
if (result.ok) throw new Error("Expected observed resource failure");
|
||||
const projected = projectAnalysisError(result.error);
|
||||
expect(projected).toMatchObject({
|
||||
code: "resource_constraint",
|
||||
details: {
|
||||
resource,
|
||||
reported_limits: scenario === "reported" ? limits : null,
|
||||
captured_output: { stdout: "resource diagnostic", truncated: false },
|
||||
},
|
||||
});
|
||||
expect(result.error.message).toContain(
|
||||
failure === "EFBIG"
|
||||
? "exact write failure cause is unknown"
|
||||
: "exact signal cause is unknown",
|
||||
);
|
||||
if (scenario !== "reported")
|
||||
expect(result.error.message).toContain("limit report unavailable");
|
||||
expect(projected.remediation.action).toContain(
|
||||
resource === "cpu" ? "CPU" : "file-size",
|
||||
);
|
||||
await expect(access(ownedPath)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
},
|
||||
);
|
||||
|
||||
it.runIf(!unsupportedHost)(
|
||||
"retains actual diagnostic truncation when output overflow and process cleanup both fail",
|
||||
async () => {
|
||||
const { path } = await fixture();
|
||||
let ownedPath = "";
|
||||
const provider = new PwntoolsLayoutProvider(
|
||||
{ REA_PWNTOOLS_PYTHON: process.execPath },
|
||||
async (spawn) => {
|
||||
ownedPath = spawn.cwd ?? "";
|
||||
const launched = await spawnOwnedProviderProcess({
|
||||
...spawn,
|
||||
command: process.execPath,
|
||||
arguments: ["-e", 'process.stdout.write("x".repeat(1048577))'],
|
||||
});
|
||||
return {
|
||||
...launched,
|
||||
cleanup: async () => {
|
||||
await launched.cleanup?.();
|
||||
throw new Error("injected post-cleanup reporting failure");
|
||||
},
|
||||
};
|
||||
},
|
||||
);
|
||||
const result = await provider.inspect({ path });
|
||||
if (result.ok) throw new Error("Expected compounded lifecycle failure");
|
||||
expect(result.error).toMatchObject({
|
||||
cleanupIncomplete: true,
|
||||
diagnostics: {
|
||||
reason: "injected post-cleanup reporting failure",
|
||||
previous_error: { failure_kind: "output-limit" },
|
||||
captured_output: { truncated: true, stderr: "" },
|
||||
},
|
||||
});
|
||||
await expect(access(ownedPath)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
},
|
||||
);
|
||||
|
||||
it
|
||||
.runIf(!unsupportedHost)
|
||||
.each([
|
||||
"reserved-memory-status",
|
||||
"unmarked-memory-status",
|
||||
"unmarked-file-status",
|
||||
"wrong-marker",
|
||||
"ordinary-exit",
|
||||
"signal",
|
||||
])(
|
||||
"requires matching private bridge failure evidence, without guessing from stderr: %s",
|
||||
async (scenario) => {
|
||||
const { path } = await fixture();
|
||||
let ownedPath = "";
|
||||
const provider = new PwntoolsLayoutProvider(
|
||||
{ REA_PWNTOOLS_PYTHON: process.execPath },
|
||||
async (spawn) => {
|
||||
ownedPath = spawn.cwd ?? "";
|
||||
if (
|
||||
scenario === "reserved-memory-status" ||
|
||||
scenario === "wrong-marker"
|
||||
)
|
||||
await writeFile(
|
||||
join(ownedPath, "resource.failure"),
|
||||
scenario === "wrong-marker" ? Buffer.from([0xcd]) : "M",
|
||||
);
|
||||
return spawnOwnedProviderProcess({
|
||||
...spawn,
|
||||
command: process.execPath,
|
||||
arguments: [
|
||||
"-e",
|
||||
'process.stderr.write("MemoryError-like diagnostic\\n");' +
|
||||
(scenario === "signal"
|
||||
? 'process.kill(process.pid,"SIGKILL")'
|
||||
: `process.exit(${scenario === "unmarked-file-status" ? "76" : ["reserved-memory-status", "unmarked-memory-status", "wrong-marker"].includes(scenario) ? "75" : "7"})`),
|
||||
],
|
||||
});
|
||||
},
|
||||
);
|
||||
const result = await provider.inspect({ path });
|
||||
if (result.ok) throw new Error("Expected explicit process failure");
|
||||
const projected = projectAnalysisError(result.error);
|
||||
expect(projected.code).toBe(
|
||||
scenario === "reserved-memory-status"
|
||||
? "resource_constraint"
|
||||
: "execution_failure",
|
||||
);
|
||||
expect(JSON.stringify(projected)).toContain("MemoryError-like diagnostic");
|
||||
if (scenario === "reserved-memory-status")
|
||||
expect(projected.details).toMatchObject({
|
||||
resource: "memory",
|
||||
reported_limits: null,
|
||||
captured_output: { truncated: false },
|
||||
});
|
||||
await expect(access(ownedPath)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
},
|
||||
);
|
||||
|
||||
it.runIf(!unsupportedHost).each([1048576, 1048577])(
|
||||
"keeps complete diagnostics or fails explicitly when a valid reply emits %s bytes",
|
||||
async (bytes) => {
|
||||
const { path } = await fixture();
|
||||
let ownedPath = "";
|
||||
const provider = new PwntoolsLayoutProvider(
|
||||
{ REA_PWNTOOLS_PYTHON: process.execPath },
|
||||
async (spawn) => {
|
||||
ownedPath = spawn.cwd ?? "";
|
||||
const requestPath = spawn.arguments.at(-1);
|
||||
if (requestPath === undefined) throw new Error("Request path missing");
|
||||
const request = requestSchema.parse(
|
||||
JSON.parse(await readFile(requestPath, "utf8")),
|
||||
);
|
||||
const {
|
||||
artifact: _artifact,
|
||||
diagnostics: _diagnostics,
|
||||
...value
|
||||
} = binaryLayoutFixture(path);
|
||||
await writeFile(
|
||||
request.reply_path,
|
||||
JSON.stringify({
|
||||
ok: true,
|
||||
profile: PWNTOOLS_PROVIDER_IDENTITY.version,
|
||||
value,
|
||||
}),
|
||||
);
|
||||
return spawnOwnedProviderProcess({
|
||||
...spawn,
|
||||
command: process.execPath,
|
||||
arguments: [
|
||||
"-e",
|
||||
`process.stdout.write("x".repeat(${String(bytes)}))`,
|
||||
],
|
||||
});
|
||||
},
|
||||
);
|
||||
const result = await provider.inspect({ path });
|
||||
if (bytes === 1048576) {
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.diagnostics.stdout).toHaveLength(bytes);
|
||||
expect(result.value.diagnostics.truncated).toBe(false);
|
||||
} else {
|
||||
if (result.ok)
|
||||
throw new Error("Excess diagnostics must not return partial success");
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "unreadable_output",
|
||||
details: { captured_output: { truncated: true } },
|
||||
});
|
||||
}
|
||||
await expect(access(ownedPath)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
},
|
||||
);
|
||||
|
||||
it.runIf(!unsupportedHost).each([
|
||||
null,
|
||||
{
|
||||
address_space_bytes: 67108864,
|
||||
cpu_seconds: 20,
|
||||
file_size_bytes: 33554432,
|
||||
},
|
||||
])(
|
||||
"preserves reported memory failure, budgets, diagnostics and cleanup: %j",
|
||||
async (limits) => {
|
||||
const { path } = await fixture();
|
||||
let ownedPath = "";
|
||||
const provider = new PwntoolsLayoutProvider(
|
||||
{ REA_PWNTOOLS_PYTHON: process.execPath },
|
||||
async (spawn) => {
|
||||
ownedPath = spawn.cwd ?? "";
|
||||
const requestPath = spawn.arguments.at(-1);
|
||||
if (requestPath === undefined) throw new Error("Request path missing");
|
||||
const request = requestSchema.parse(
|
||||
JSON.parse(await readFile(requestPath, "utf8")),
|
||||
);
|
||||
await writeFile(
|
||||
request.reply_path,
|
||||
JSON.stringify({
|
||||
ok: false,
|
||||
reason: "resource-limit",
|
||||
message: "Memory allocation failed; exact cause unknown.",
|
||||
reported_limits: limits,
|
||||
}),
|
||||
);
|
||||
return spawnOwnedProviderProcess({
|
||||
...spawn,
|
||||
command: process.execPath,
|
||||
arguments: [
|
||||
"-e",
|
||||
"process.stderr.write('upstream allocation diagnostic')",
|
||||
],
|
||||
});
|
||||
},
|
||||
);
|
||||
const result = await provider.inspect({ path });
|
||||
if (result.ok) throw new Error("Expected resource failure");
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "resource_constraint",
|
||||
category: "resource_constraint",
|
||||
details: {
|
||||
resource: "memory",
|
||||
reported_limits: limits,
|
||||
captured_output: {
|
||||
stderr: "upstream allocation diagnostic",
|
||||
truncated: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
await expect(access(ownedPath)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
expect(await readFile(path, "utf8")).toBe("source-owned-seam-bytes");
|
||||
},
|
||||
);
|
||||
|
||||
it.runIf(!unsupportedHost).each(["cancelled", "output-limit", "process"])(
|
||||
"releases an acquired decoder and its snapshot after %s",
|
||||
async (scenario) => {
|
||||
const { path } = await fixture();
|
||||
const controller = new AbortController();
|
||||
let ownedPath = "";
|
||||
let pid: number | undefined;
|
||||
const provider = new PwntoolsLayoutProvider(
|
||||
{ REA_PWNTOOLS_PYTHON: process.execPath },
|
||||
async (spawn) => {
|
||||
ownedPath = spawn.cwd ?? "";
|
||||
const launched = await spawnOwnedProviderProcess({
|
||||
...spawn,
|
||||
command: process.execPath,
|
||||
arguments: [
|
||||
"-e",
|
||||
scenario === "cancelled"
|
||||
? 'process.stdout.write("ready\\n"); setInterval(() => undefined, 1000)'
|
||||
: scenario === "output-limit"
|
||||
? 'process.stdout.write("x".repeat(1048577))'
|
||||
: 'process.stderr.write("decoder exited unexpectedly"); process.exit(7)',
|
||||
],
|
||||
});
|
||||
pid = launched.process.pid;
|
||||
if (scenario === "cancelled") {
|
||||
await waitForProviderProcessReady(launched.process);
|
||||
setImmediate(() => controller.abort());
|
||||
}
|
||||
return launched;
|
||||
},
|
||||
);
|
||||
const result = await provider.inspect(
|
||||
{ path },
|
||||
{ signal: controller.signal },
|
||||
);
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
_tag:
|
||||
scenario === "cancelled"
|
||||
? "AnalysisCancelledError"
|
||||
: scenario === "output-limit"
|
||||
? "AnalysisOutputError"
|
||||
: "ProviderAdapterError",
|
||||
...(scenario === "process"
|
||||
? {
|
||||
diagnostics: {
|
||||
exit_code: 7,
|
||||
stderr: "decoder exited unexpectedly",
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
});
|
||||
if (pid === undefined) throw new Error("Decoder was not acquired");
|
||||
const acquiredPid = pid;
|
||||
expect(() => process.kill(acquiredPid, 0)).toThrow();
|
||||
await expect(access(ownedPath)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
expect(await readFile(path, "utf8")).toBe("source-owned-seam-bytes");
|
||||
},
|
||||
);
|
||||
|
||||
it.runIf(!unsupportedHost)(
|
||||
"reports private storage denial as an adapter failure rather than selected-input read denial",
|
||||
async () => {
|
||||
const { path } = await fixture();
|
||||
const provider = new PwntoolsLayoutProvider(
|
||||
{ REA_PWNTOOLS_PYTHON: process.execPath },
|
||||
undefined,
|
||||
() =>
|
||||
Promise.reject(
|
||||
Object.assign(new Error("private root denied"), { code: "EACCES" }),
|
||||
),
|
||||
);
|
||||
expect(await provider.inspect({ path })).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
_tag: "ProviderAdapterError",
|
||||
diagnostics: { phase: "decoder", reason: "private root denied" },
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.runIf(!unsupportedHost)(
|
||||
"preserves a decoder failure when private-root cleanup also fails",
|
||||
async () => {
|
||||
const { path, root } = await fixture();
|
||||
const provider = new PwntoolsLayoutProvider(
|
||||
{ REA_PWNTOOLS_PYTHON: process.execPath },
|
||||
async (spawn) => {
|
||||
const requestPath = spawn.arguments.at(-1);
|
||||
if (requestPath === undefined) throw new Error("Request path missing");
|
||||
const request = requestSchema.parse(
|
||||
JSON.parse(await readFile(requestPath, "utf8")),
|
||||
);
|
||||
await writeFile(
|
||||
request.reply_path,
|
||||
JSON.stringify({
|
||||
ok: false,
|
||||
reason: "format",
|
||||
message: "Malformed original ELF table.",
|
||||
}),
|
||||
);
|
||||
return spawnOwnedProviderProcess({
|
||||
...spawn,
|
||||
arguments: ["-e", "process.exit(0)"],
|
||||
});
|
||||
},
|
||||
() =>
|
||||
Promise.resolve({
|
||||
path: root,
|
||||
close: () => Promise.reject(new Error("root cleanup failed")),
|
||||
}),
|
||||
);
|
||||
expect(await provider.inspect({ path })).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
cleanupIncomplete: true,
|
||||
cleanupResources: [root],
|
||||
diagnostics: {
|
||||
reason: "root cleanup failed",
|
||||
previous_error: { category: "invalid_input" },
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
const fixture = async () => {
|
||||
const workspace = await createTestWorkspace("rea-layout-boundary-");
|
||||
const root = workspace.root;
|
||||
onTestFinished(() => removeTestWorkspace(root));
|
||||
const path = join(root, "selected.elf");
|
||||
await writeFile(path, "source-owned-seam-bytes");
|
||||
return { root, path };
|
||||
};
|
||||
|
||||
it.runIf(!unsupportedHost)(
|
||||
"preserves cancellation during the actual signal-aware snapshot write and closes its acquired root",
|
||||
async () => {
|
||||
const { path } = await fixture();
|
||||
const controller = new AbortController();
|
||||
let ownedPath = "";
|
||||
const provider = new PwntoolsLayoutProvider(
|
||||
{ REA_PWNTOOLS_PYTHON: process.execPath },
|
||||
() => {
|
||||
throw new Error("Decoder must not launch");
|
||||
},
|
||||
async () => {
|
||||
const root = await PrivateRuntimeRoot.create({
|
||||
prefix: "rea-layout-cancel-",
|
||||
});
|
||||
ownedPath = root.path;
|
||||
controller.abort();
|
||||
return root;
|
||||
},
|
||||
);
|
||||
expect(
|
||||
await provider.inspect({ path }, { signal: controller.signal }),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisCancelledError" } });
|
||||
await expect(access(ownedPath)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
},
|
||||
);
|
||||
|
||||
it
|
||||
.runIf(!unsupportedHost)
|
||||
.each([
|
||||
"success",
|
||||
"format",
|
||||
"unavailable",
|
||||
"unsupported",
|
||||
"output-limit",
|
||||
"wrong-profile",
|
||||
"malformed-reply",
|
||||
])(
|
||||
"preserves process/reply boundaries and cleans private snapshots: %s",
|
||||
async (scenario) => {
|
||||
const { root, path } = await fixture();
|
||||
let ownedPath = "";
|
||||
const provider = new PwntoolsLayoutProvider(
|
||||
{ REA_PWNTOOLS_PYTHON: process.execPath },
|
||||
async (spawn) => {
|
||||
const requestPath = spawn.arguments.at(-1);
|
||||
if (requestPath === undefined) throw new Error("request path missing");
|
||||
ownedPath = spawn.cwd ?? "";
|
||||
expect(spawn.arguments[0]).toBe("-I");
|
||||
const request = requestSchema.parse(
|
||||
JSON.parse(await readFile(requestPath, "utf8")),
|
||||
);
|
||||
expect(await readFile(request.snapshot_path, "utf8")).toBe(
|
||||
"source-owned-seam-bytes",
|
||||
);
|
||||
const {
|
||||
artifact: _artifact,
|
||||
diagnostics: _diagnostics,
|
||||
...value
|
||||
} = binaryLayoutFixture(path);
|
||||
await writeFile(
|
||||
request.reply_path,
|
||||
scenario === "malformed-reply"
|
||||
? "broken-json"
|
||||
: JSON.stringify(
|
||||
[
|
||||
"format",
|
||||
"unavailable",
|
||||
"unsupported",
|
||||
"output-limit",
|
||||
].includes(scenario)
|
||||
? {
|
||||
ok: false,
|
||||
reason: scenario,
|
||||
message: "ELF table is truncated.",
|
||||
}
|
||||
: {
|
||||
ok: true,
|
||||
profile:
|
||||
scenario === "wrong-profile"
|
||||
? "pwntools@other"
|
||||
: PWNTOOLS_PROVIDER_IDENTITY.version,
|
||||
value,
|
||||
},
|
||||
),
|
||||
);
|
||||
return spawnOwnedProviderProcess({
|
||||
...spawn,
|
||||
command: process.execPath,
|
||||
arguments: ["-e", "process.stderr.write('upstream warning')"],
|
||||
});
|
||||
},
|
||||
);
|
||||
const result = await provider.inspect({ path });
|
||||
if (scenario === "success") {
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.artifact).toMatchObject({
|
||||
path,
|
||||
bytes: Buffer.byteLength("source-owned-seam-bytes"),
|
||||
});
|
||||
expect(result.value.artifact.sha256).toMatch(/^[a-f0-9]{64}$/);
|
||||
expect(result.value.diagnostics.stderr).toBe("upstream warning");
|
||||
} else
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
_tag:
|
||||
scenario === "format"
|
||||
? "AnalysisInputError"
|
||||
: scenario === "unavailable"
|
||||
? "ProviderSelectionError"
|
||||
: scenario === "unsupported"
|
||||
? "AnalysisCapabilityUnavailableError"
|
||||
: "AnalysisOutputError",
|
||||
},
|
||||
});
|
||||
if (!result.ok)
|
||||
expect(projectAnalysisError(result.error).details).toMatchObject({
|
||||
captured_output: {
|
||||
stdout: "",
|
||||
stderr: "upstream warning",
|
||||
truncated: false,
|
||||
},
|
||||
});
|
||||
expect(await readFile(path, "utf8")).toBe("source-owned-seam-bytes");
|
||||
expect(ownedPath.startsWith(root)).toBe(false);
|
||||
await expect(access(ownedPath)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
},
|
||||
);
|
||||
|
||||
it.runIf(!unsupportedHost)(
|
||||
"rejects missing configuration, absent input and prelaunch cancellation distinctly",
|
||||
async () => {
|
||||
const { path } = await fixture();
|
||||
expect(
|
||||
await new PwntoolsLayoutProvider({}).inspect({ path }),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "ProviderSelectionError", reason: "provider_unavailable" },
|
||||
});
|
||||
const provider = new PwntoolsLayoutProvider({
|
||||
REA_PWNTOOLS_PYTHON: process.execPath,
|
||||
});
|
||||
expect(await provider.inspect({ path: path + ".absent" })).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisInputError" },
|
||||
});
|
||||
const controller = new AbortController();
|
||||
controller.abort();
|
||||
expect(
|
||||
await provider.inspect({ path }, { signal: controller.signal }),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisCancelledError" } });
|
||||
},
|
||||
);
|
||||
it.runIf(unsupportedHost)(
|
||||
"reports unverified host coverage before acquiring a provider",
|
||||
async () => {
|
||||
expect(
|
||||
await new PwntoolsLayoutProvider({}).inspect({ path: "/selected.elf" }),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisCapabilityUnavailableError" },
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.runIf(!unsupportedHost)(
|
||||
"retains decoder warnings when cancellation arrives during successful root cleanup",
|
||||
async () => {
|
||||
const { path } = await fixture();
|
||||
const controller = new AbortController();
|
||||
let ownedPath = "";
|
||||
const provider = new PwntoolsLayoutProvider(
|
||||
{ REA_PWNTOOLS_PYTHON: process.execPath },
|
||||
async (spawn) => {
|
||||
const requestPath = spawn.arguments.at(-1);
|
||||
if (requestPath === undefined) throw new Error("Request path missing");
|
||||
const request = requestSchema.parse(
|
||||
JSON.parse(await readFile(requestPath, "utf8")),
|
||||
);
|
||||
const {
|
||||
artifact: _artifact,
|
||||
diagnostics: _diagnostics,
|
||||
...value
|
||||
} = binaryLayoutFixture(path);
|
||||
await writeFile(
|
||||
request.reply_path,
|
||||
JSON.stringify({
|
||||
ok: true,
|
||||
profile: PWNTOOLS_PROVIDER_IDENTITY.version,
|
||||
value,
|
||||
}),
|
||||
);
|
||||
return spawnOwnedProviderProcess({
|
||||
...spawn,
|
||||
command: process.execPath,
|
||||
arguments: ["-e", 'process.stderr.write("retained late warning")'],
|
||||
});
|
||||
},
|
||||
async () => {
|
||||
const root = await PrivateRuntimeRoot.create({
|
||||
prefix: "rea-layout-late-cancel-",
|
||||
});
|
||||
ownedPath = root.path;
|
||||
return {
|
||||
path: root.path,
|
||||
close: async () => {
|
||||
await root.close();
|
||||
controller.abort();
|
||||
},
|
||||
};
|
||||
},
|
||||
);
|
||||
const result = await provider.inspect(
|
||||
{ path },
|
||||
{ signal: controller.signal },
|
||||
);
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisCancelledError" },
|
||||
});
|
||||
if (result.ok) throw new Error("Late cancellation must be preserved");
|
||||
expect(projectAnalysisError(result.error).details?.captured_output).toEqual(
|
||||
{ stdout: "", stderr: "retained late warning", truncated: false },
|
||||
);
|
||||
await expect(access(ownedPath)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
},
|
||||
);
|
||||
|
||||
it.runIf(!unsupportedHost).each(["directory", "missing-interpreter"])(
|
||||
"identifies the configured executable on actual launch/preflight failure: %s",
|
||||
async (scenario) => {
|
||||
const { path, root } = await fixture();
|
||||
const executable =
|
||||
scenario === "directory" ? root : join(root, "broken-python");
|
||||
if (scenario === "missing-interpreter")
|
||||
await writeFile(
|
||||
executable,
|
||||
"#!/rea-missing-interpreter-for-boundary-test\n",
|
||||
{ mode: 0o700 },
|
||||
);
|
||||
const result = await new PwntoolsLayoutProvider({
|
||||
REA_PWNTOOLS_PYTHON: executable,
|
||||
}).inspect({ path });
|
||||
if (result.ok) throw new Error("Expected unavailable executable");
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "provider_unavailable",
|
||||
details: {
|
||||
rejections: [{ diagnostics: { executable_path: executable } }],
|
||||
},
|
||||
});
|
||||
expect(result.error._tag).toBe("ProviderSelectionError");
|
||||
expect(await readFile(path, "utf8")).toBe("source-owned-seam-bytes");
|
||||
},
|
||||
);
|
||||
@@ -1,3 +1,4 @@
|
||||
import { PWNTOOLS_PROVIDER_IDENTITY } from "../../../src/native/pwntools/PwntoolsRelease.js";
|
||||
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
@@ -115,6 +116,7 @@ describe("canonical product catalog", () => {
|
||||
GHIDRA_PROVIDER_IDENTITY,
|
||||
IDA_PROVIDER_IDENTITY,
|
||||
NATIVE_MACOS_PROVIDER_IDENTITY,
|
||||
PWNTOOLS_PROVIDER_IDENTITY,
|
||||
ARTIFACT_GRAPH_PROVIDER,
|
||||
ANDROID_APPLICATION_PROVIDER,
|
||||
APPLE_APPLICATION_PROVIDER,
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { expect, it, onTestFinished } from "vitest";
|
||||
import { BinaryLayoutService } from "../../../src/application/binaryDiagnostics/BinaryLayoutService.js";
|
||||
import { toolContract } from "../../../src/contracts/toolContracts.js";
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { ok } from "../../../src/domain/result.js";
|
||||
import { createServer } from "../../../src/server/createServer.js";
|
||||
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
||||
import {
|
||||
binaryLayoutFixture,
|
||||
BINARY_LAYOUT_TEST_PROVIDER,
|
||||
} from "../../fixtures/binaryDiagnostics/layout.js";
|
||||
|
||||
it("advertises exact valid schemas and records inline layout without a binary target", async () => {
|
||||
const value = binaryLayoutFixture();
|
||||
const service = new BinaryLayoutService({
|
||||
identity: BINARY_LAYOUT_TEST_PROVIDER,
|
||||
inspect: () => Promise.resolve(ok(value)),
|
||||
});
|
||||
const session = createTestBinarySession(() => {
|
||||
throw new Error("deep provider must not start");
|
||||
});
|
||||
const server = createServer(session, session, { binaryLayout: service });
|
||||
const client = new Client({ name: "binary-layout-contract", version: "1" });
|
||||
onTestFinished(async () => {
|
||||
await client.close();
|
||||
await server.close();
|
||||
await session.close();
|
||||
});
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const advertised = (await client.listTools()).tools.find(
|
||||
(tool) => tool.name === "inspect_binary_layout",
|
||||
);
|
||||
if (advertised?.outputSchema === undefined)
|
||||
throw new Error("layout must publish both schemas");
|
||||
const ajv = new Ajv2020({ strict: false, validateFormats: false });
|
||||
const inputSchema: Record<string, unknown> = advertised.inputSchema;
|
||||
const outputSchema: Record<string, unknown> = advertised.outputSchema;
|
||||
expect(ajv.validateSchema(inputSchema)).toBe(true);
|
||||
expect(ajv.validateSchema(outputSchema)).toBe(true);
|
||||
expect(ajv.validate(inputSchema, { path: value.artifact.path })).toBe(true);
|
||||
expect(
|
||||
ajv.validate(inputSchema, {
|
||||
path: value.artifact.path,
|
||||
approval: true,
|
||||
}),
|
||||
).toBe(false);
|
||||
const response = await client.callTool({
|
||||
name: "inspect_binary_layout",
|
||||
arguments: { path: value.artifact.path },
|
||||
});
|
||||
expect(response.isError).not.toBe(true);
|
||||
expect(
|
||||
ajv.validate(outputSchema, response.structuredContent),
|
||||
JSON.stringify(ajv.errors),
|
||||
).toBe(true);
|
||||
const parsed = toolContract("inspect_binary_layout").outputSchema.parse(
|
||||
response.structuredContent,
|
||||
);
|
||||
const evidence = parseEvidence(parsed.evidence);
|
||||
expect(parsed.result).toEqual(value);
|
||||
expect(parsed.result).toEqual(evidence.normalized_result);
|
||||
expect(session.evidenceById(evidence.evidence_id)).toEqual(evidence);
|
||||
expect(
|
||||
(
|
||||
await client.callTool({
|
||||
name: "inspect_binary_layout",
|
||||
arguments: { path: "relative.elf" },
|
||||
})
|
||||
).isError,
|
||||
).toBe(true);
|
||||
});
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
import type { BinaryLayout } from "../../../src/domain/native/binaryLayout.js";
|
||||
|
||||
/** Small source-owned provider observation for validation and transport tests. */
|
||||
export const binaryLayoutFixture = (
|
||||
path = "/artifacts/source-owned.elf",
|
||||
): BinaryLayout => ({
|
||||
artifact: { path, sha256: "a".repeat(64), bytes: 128 },
|
||||
format: "elf",
|
||||
architecture: { machine: "EM_X86_64", bits: 64, byte_order: "little" },
|
||||
image_type: "ET_REL",
|
||||
entry_point: {
|
||||
reported_value: "0x0",
|
||||
meaning: "not-applicable",
|
||||
execution_status: "unknown",
|
||||
},
|
||||
runtime_load_base: null,
|
||||
sections: [],
|
||||
segments: [],
|
||||
symbols: [],
|
||||
relocations: [],
|
||||
packed_relative_relocations: [],
|
||||
relocation_inventory_completeness: "unknown",
|
||||
linkage: {
|
||||
needed_libraries: [],
|
||||
interpreters: [],
|
||||
got: [],
|
||||
plt: [],
|
||||
convenience_maps_completeness: "unknown",
|
||||
runtime_library_paths: null,
|
||||
},
|
||||
mitigations: {
|
||||
evidence_kind: "inferred",
|
||||
position_independent: false,
|
||||
nx_indicator: null,
|
||||
executable_stack_indicator: false,
|
||||
stack_canary_indicator: false,
|
||||
relro: null,
|
||||
},
|
||||
diagnostics: { stdout: "producer warning", stderr: "", truncated: false },
|
||||
limitations: ["Runtime addresses remain unknown."],
|
||||
});
|
||||
|
||||
/** Producer identity belongs to the test seam, not a simulated installed engine claim. */
|
||||
export const BINARY_LAYOUT_TEST_PROVIDER = {
|
||||
id: "fixture-layout",
|
||||
name: "Source-owned layout seam",
|
||||
version: "1",
|
||||
} as const;
|
||||
Reference in New Issue
Block a user