chore: sync current main into the CI baseline repair
Validate the formatting and reconstruction fixture repairs against the latest merged feature and correctness changes. Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { expect } from "vitest";
|
||||
import { createEvidence, parseEvidence } from "../../src/domain/evidence.js";
|
||||
import { wasmInterfaceComparisonSchema } from "../../src/contracts/wasm/wasmComparisonContracts.js";
|
||||
import { composeBinarySession } from "../../src/application/binary/BinarySessionComposition.js";
|
||||
import { AnalysisProviderRegistry } from "../../src/application/binary/AnalysisProviderRegistry.js";
|
||||
import { createServer } from "../../src/server/createServer.js";
|
||||
import { wasmArtifactFixture } from "../fixtures/wasm/artifact.js";
|
||||
import { cliTest } from "../support/cli/cliFixture.js";
|
||||
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
||||
|
||||
cliTest(
|
||||
"compares portable Evidence identically through CLI and retained MCP with schema/provenance",
|
||||
async ({ cli }) => {
|
||||
const sources = (["i32", "i64"] as const).map((parameter) => {
|
||||
const report = wasmArtifactFixture();
|
||||
report.interface = {
|
||||
state: "complete",
|
||||
issues: [],
|
||||
entries: [
|
||||
{
|
||||
direction: "export",
|
||||
module: null,
|
||||
name: 'quoted"\ufeffname',
|
||||
kind: "func",
|
||||
index: 0,
|
||||
signature: { kind: "func", params: [parameter], results: [] },
|
||||
wat_form: '(export "quoted\\22\\ef\\bb\\bfname" (func 0))',
|
||||
issue: null,
|
||||
},
|
||||
],
|
||||
};
|
||||
return createEvidence(
|
||||
{
|
||||
path: report.artifact.path,
|
||||
sha256: report.artifact.sha256,
|
||||
format: "file",
|
||||
},
|
||||
{ id: "typed-fixture", name: "Typed fixture", version: "1" },
|
||||
{
|
||||
operation: "inspect_wasm_artifact",
|
||||
parameters: { path: report.artifact.path },
|
||||
result: report,
|
||||
confidence: "observed",
|
||||
},
|
||||
);
|
||||
});
|
||||
const [left, right] = sources;
|
||||
if (left === undefined || right === undefined)
|
||||
throw new Error("Missing paired fixture");
|
||||
const root = await createTestTempDirectory("rea-wasm-comparison-");
|
||||
const path = join(root, "input.json");
|
||||
const input = { left, right, scope: "both" };
|
||||
await writeFile(path, JSON.stringify(input));
|
||||
const cliResult = await cli.run({
|
||||
arguments: ["compare-wasm-interfaces", path, "--json"],
|
||||
});
|
||||
expect(cliResult.exitCode).toBe(0);
|
||||
const cliEvidence = parseEvidence(cliResult.json);
|
||||
const cliReport = wasmInterfaceComparisonSchema.parse(
|
||||
cliEvidence.normalized_result,
|
||||
);
|
||||
expect(cliReport).toMatchObject({
|
||||
coverage: "complete-within-inputs",
|
||||
changes: [{ name: 'quoted"\ufeffname', state: "changed" }],
|
||||
left: {
|
||||
evidence_id: left.evidence_id,
|
||||
artifact: {
|
||||
path: "/artifacts/module.wasm",
|
||||
sha256: "a".repeat(64),
|
||||
bytes: 8,
|
||||
},
|
||||
},
|
||||
});
|
||||
const session = composeBinarySession(new AnalysisProviderRegistry([]));
|
||||
const server = createServer({ kind: "session", session });
|
||||
const client = new Client({ name: "wasm-interface-parity", version: "1" });
|
||||
const [ct, st] = InMemoryTransport.createLinkedPair();
|
||||
try {
|
||||
await server.connect(st);
|
||||
await client.connect(ct);
|
||||
const tool = (await client.listTools()).tools.find(
|
||||
(t) => t.name === "compare_wasm_interfaces",
|
||||
);
|
||||
if (tool?.outputSchema === undefined)
|
||||
throw new Error("Missing comparison schema");
|
||||
const outputSchema: Record<string, unknown> = tool.outputSchema;
|
||||
const ajv = new Ajv2020({ strict: false, validateFormats: false });
|
||||
expect(ajv.validate(tool.inputSchema, input)).toBe(true);
|
||||
expect(ajv.validate(tool.inputSchema, { left, right })).toBe(false);
|
||||
const mcp = await client.callTool({ name: tool.name, arguments: input });
|
||||
expect(mcp.isError, JSON.stringify(mcp)).not.toBe(true);
|
||||
expect(
|
||||
ajv.validate(outputSchema, mcp.structuredContent),
|
||||
JSON.stringify(ajv.errors),
|
||||
).toBe(true);
|
||||
const mcpEvidence = parseEvidence(mcp.structuredContent);
|
||||
expect(mcpEvidence.normalized_result).toEqual(cliReport);
|
||||
expect(mcpEvidence.evidence_id).toBe(cliEvidence.evidence_id);
|
||||
expect(mcpEvidence.evidence_links).toEqual([
|
||||
left.evidence_id,
|
||||
right.evidence_id,
|
||||
]);
|
||||
const retained = await client.callTool({
|
||||
name: tool.name,
|
||||
arguments: {
|
||||
scope: "both",
|
||||
left: { kind: "retained-evidence", evidence_id: left.evidence_id },
|
||||
right: { kind: "retained-evidence", evidence_id: right.evidence_id },
|
||||
},
|
||||
});
|
||||
expect(retained.isError).not.toBe(true);
|
||||
expect(parseEvidence(retained.structuredContent).evidence_id).toBe(
|
||||
mcpEvidence.evidence_id,
|
||||
);
|
||||
const invalid = await client.callTool({
|
||||
name: tool.name,
|
||||
arguments: { ...input, scope: "all" },
|
||||
});
|
||||
expect(invalid.isError).toBe(true);
|
||||
} finally {
|
||||
await client.close();
|
||||
await server.close();
|
||||
await session.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -4,6 +4,40 @@ import {
|
||||
recordedCrashFixtureBytes,
|
||||
} from "../../fixtures/binaryDiagnostics/recordedCrash.js";
|
||||
import { validateRecordedCrashStructure } from "../../../src/native/pwntools/RecordedCrashStructureBindings.js";
|
||||
import { RECORDED_LINUX_CORE_PROFILES } from "../../../src/domain/native/recordedCrash.js";
|
||||
|
||||
it.each(["x86_64-little-endian", "aarch64-little-endian"] as const)(
|
||||
"admits a %s core whose header carries that profile's e_machine",
|
||||
(architecture) => {
|
||||
const report = recordedCrashFixture(undefined, architecture);
|
||||
expect(() =>
|
||||
validateRecordedCrashStructure(
|
||||
report,
|
||||
recordedCrashFixtureBytes(report),
|
||||
report.decoder_diagnostics,
|
||||
),
|
||||
).not.toThrow();
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
["x86_64-little-endian", "aarch64-little-endian"],
|
||||
["aarch64-little-endian", "x86_64-little-endian"],
|
||||
] as const)(
|
||||
"rejects a %s report whose header carries the other profile's e_machine",
|
||||
(reported, embedded) => {
|
||||
const report = recordedCrashFixture(undefined, reported);
|
||||
const snapshot = recordedCrashFixtureBytes(report);
|
||||
snapshot.writeUInt16LE(RECORDED_LINUX_CORE_PROFILES[embedded].machine, 18);
|
||||
expect(() =>
|
||||
validateRecordedCrashStructure(
|
||||
report,
|
||||
snapshot,
|
||||
report.decoder_diagnostics,
|
||||
),
|
||||
).toThrow(/Reported core structure differs/);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
[6, 0],
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import type { AnalysisError } from "../../../src/domain/analysisErrorBase.js";
|
||||
import type { RecordedCrash } from "../../../src/domain/native/recordedCrash.js";
|
||||
import type {
|
||||
RecordedCrash,
|
||||
RecordedCrashArchitecture,
|
||||
} from "../../../src/domain/native/recordedCrash.js";
|
||||
import { access, mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { expect, it, onTestFinished } from "vitest";
|
||||
@@ -48,6 +51,7 @@ it
|
||||
.runIf(host)
|
||||
.each([
|
||||
"success",
|
||||
"success-aarch64",
|
||||
"wrong-register",
|
||||
"wrong-register-source",
|
||||
"missing-thread",
|
||||
@@ -77,9 +81,13 @@ it
|
||||
] as const)(
|
||||
"validates recorded source bytes and cleanup: %s",
|
||||
async (scenario) => {
|
||||
const architecture = scenario.endsWith("aarch64")
|
||||
? "aarch64-little-endian"
|
||||
: "x86_64-little-endian";
|
||||
const { path, value, bytes } = await fixture(
|
||||
true,
|
||||
scenario === "wrong-owner-display",
|
||||
architecture,
|
||||
);
|
||||
if (scenario.startsWith("wrong-ei-version-"))
|
||||
bytes[6] = Number(scenario.at(-1));
|
||||
@@ -123,8 +131,9 @@ it
|
||||
path,
|
||||
include_debugger_context: false,
|
||||
});
|
||||
if (scenario === "success") {
|
||||
if (scenario === "success" || scenario === "success-aarch64") {
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.architecture).toBe(architecture);
|
||||
expect(result.value.threads).toEqual(value.threads);
|
||||
expect(result.value.diagnostics.stdout).toBe("recorded warning");
|
||||
} else
|
||||
@@ -340,13 +349,17 @@ const expectOptionalContextFailure = (
|
||||
});
|
||||
};
|
||||
|
||||
const fixture = async (includeSignal = false, opaqueOwner = false) => {
|
||||
const fixture = async (
|
||||
includeSignal = false,
|
||||
opaqueOwner = false,
|
||||
architecture: RecordedCrashArchitecture = "x86_64-little-endian",
|
||||
) => {
|
||||
const workspace = await createTestWorkspace("rea-recorded-core-seam-");
|
||||
onTestFinished(() => removeTestWorkspace(workspace.root));
|
||||
const path = join(workspace.root, "recorded.core");
|
||||
const value = includeSignal
|
||||
? recordedCrashSignalFixture(path)
|
||||
: recordedCrashFixture(path);
|
||||
? recordedCrashSignalFixture(path, architecture)
|
||||
: recordedCrashFixture(path, architecture);
|
||||
if (opaqueOwner) {
|
||||
value.notes = value.notes.map((note) =>
|
||||
note.index === 0
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { chmod, realpath, writeFile } from "node:fs/promises";
|
||||
import { chmod, readFile, realpath, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { systemDoctorHost } from "../../../src/application/Doctor.js";
|
||||
@@ -78,7 +78,7 @@ describe("executable format refusal diagnostics", () => {
|
||||
});
|
||||
|
||||
describe("target route diagnostics", () => {
|
||||
it.each(["module.wasm", "module.bin", "misleading.js"])(
|
||||
it.each(["module.wasm", "module.bin", "misleading.js", "misleading.hop"])(
|
||||
"identifies a WASM v1 header in %s without suggesting native provider installation",
|
||||
async (name) => {
|
||||
const directory = await createTestTempDirectory("rea-wasm-target-");
|
||||
@@ -346,3 +346,68 @@ describe("raw-binary load rejection diagnostics", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("caller-selected and inferred target interpretation", () => {
|
||||
it.each(["archive.hop", "archive.HOP"])(
|
||||
"preserves inferred database routing for ZIP content named %s",
|
||||
async (name) => {
|
||||
const directory = await createTestTempDirectory("rea-zip-database-");
|
||||
const bytes = Buffer.alloc(22);
|
||||
bytes.writeUInt32LE(0x06054b50, 0);
|
||||
const zipPath = join(directory, "archive.zip");
|
||||
const databasePath = join(directory, name);
|
||||
await writeFile(zipPath, bytes);
|
||||
await writeFile(databasePath, bytes);
|
||||
expect(await parseBinaryTarget(zipPath)).toMatchObject({
|
||||
ok: true,
|
||||
value: { kind: "archive", format: "zip" },
|
||||
});
|
||||
expect(await parseBinaryTarget(databasePath)).toMatchObject({
|
||||
ok: true,
|
||||
value: { kind: "database", format: "analysis-database" },
|
||||
});
|
||||
expect(await readFile(databasePath)).toEqual(bytes);
|
||||
},
|
||||
);
|
||||
|
||||
it("preserves explicit DOS COM interpretation for bytes with a WASM header", async () => {
|
||||
const directory = await createTestTempDirectory("rea-wasm-explicit-com-");
|
||||
const path = join(directory, "module.hop");
|
||||
await writeFile(path, Buffer.from([0, 0x61, 0x73, 0x6d, 1, 0, 0, 0]));
|
||||
expect(
|
||||
await parseBinaryTarget(path, { formatHint: "dos-com" }),
|
||||
).toMatchObject({
|
||||
ok: true,
|
||||
value: { kind: "executable", format: "dos-com", architecture: "x86" },
|
||||
});
|
||||
});
|
||||
it.each(["module.wasm", "misleading.hop"])(
|
||||
"preserves explicitly selected database routing for %s",
|
||||
async (name) => {
|
||||
const directory = await createTestTempDirectory(
|
||||
"rea-wasm-explicit-database-",
|
||||
);
|
||||
const path = join(directory, name);
|
||||
await writeFile(path, Buffer.from([0, 0x61, 0x73, 0x6d, 1, 0, 0, 0]));
|
||||
expect(
|
||||
await parseBinaryTarget(path, { targetKind: "database" }),
|
||||
).toMatchObject({
|
||||
ok: true,
|
||||
value: { kind: "database", format: "analysis-database" },
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["ordinary.hop", "ordinary.HOP"])(
|
||||
"retains automatic database routing for non-WASM %s",
|
||||
async (name) => {
|
||||
const directory = await createTestTempDirectory("rea-ordinary-database-");
|
||||
const path = join(directory, name);
|
||||
await writeFile(path, "existing database content");
|
||||
expect(await parseBinaryTarget(path)).toMatchObject({
|
||||
ok: true,
|
||||
value: { kind: "database", format: "analysis-database" },
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { advertisedMcpToolSchemas } from "../../fixtures/advertisedMcpTool.js";
|
||||
import { API_SURFACE_EXAMPLE } from "../../../src/contracts/analysisViewApiSurfaceExample.js";
|
||||
import { createHash } from "node:crypto";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
@@ -212,16 +213,10 @@ it("advertises exact schemas and projects one layout section from retained Evide
|
||||
inspect: () => Promise.resolve(ok(layout)),
|
||||
});
|
||||
const { client, session } = await connect(service);
|
||||
const advertised = (await client.listTools()).tools.find(
|
||||
(tool) => tool.name === "inspect_analysis_view",
|
||||
const { ajv, inputSchema, outputSchema } = await advertisedMcpToolSchemas(
|
||||
client,
|
||||
"inspect_analysis_view",
|
||||
);
|
||||
if (advertised?.outputSchema === undefined)
|
||||
throw new Error("inspect_analysis_view 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, {
|
||||
source: { kind: "inline", evidence: analysisViewLayoutEvidence() },
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import {
|
||||
advertisedMcpToolSchemas,
|
||||
assertRecordedMcpEvidence,
|
||||
} from "../../fixtures/advertisedMcpTool.js";
|
||||
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";
|
||||
@@ -43,16 +45,11 @@ it("advertises exact valid schemas and records inline layout without a binary ta
|
||||
InMemoryTransport.createLinkedPair();
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const advertised = (await client.listTools()).tools.find(
|
||||
(tool) => tool.name === "inspect_binary_layout",
|
||||
const schemas = await advertisedMcpToolSchemas(
|
||||
client,
|
||||
"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);
|
||||
const { ajv, inputSchema } = schemas;
|
||||
expect(ajv.validate(inputSchema, { path: value.artifact.path })).toBe(true);
|
||||
expect(
|
||||
ajv.validate(inputSchema, {
|
||||
@@ -64,19 +61,14 @@ it("advertises exact valid schemas and records inline layout without a binary ta
|
||||
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 = assertRecordedMcpEvidence(
|
||||
response,
|
||||
"inspect_binary_layout",
|
||||
schemas,
|
||||
session,
|
||||
value,
|
||||
"observed",
|
||||
);
|
||||
const evidence = parseEvidence(parsed);
|
||||
expect(evidence.confidence).toBe("observed");
|
||||
expect(evidence.subject?.digest.sha256).toBe(value.artifact.sha256);
|
||||
expect(parsed.normalized_result).toEqual(value);
|
||||
expect(session.evidenceById(evidence.evidence_id)).toEqual(evidence);
|
||||
const viewed = await client.callTool({
|
||||
name: "inspect_analysis_view",
|
||||
arguments: {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import {
|
||||
advertisedMcpToolSchemas,
|
||||
assertRecordedMcpEvidence,
|
||||
} from "../../fixtures/advertisedMcpTool.js";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { createHash } from "node:crypto";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
@@ -66,16 +70,11 @@ it("advertises exact valid schemas and records inline EVM interface evidence wit
|
||||
InMemoryTransport.createLinkedPair();
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const advertised = (await client.listTools()).tools.find(
|
||||
(tool) => tool.name === "inspect_evm_interface",
|
||||
const schemas = await advertisedMcpToolSchemas(
|
||||
client,
|
||||
"inspect_evm_interface",
|
||||
);
|
||||
if (advertised?.outputSchema === undefined)
|
||||
throw new Error("EVM interface inspection 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);
|
||||
const { ajv, inputSchema } = schemas;
|
||||
expect(
|
||||
ajv.validate(inputSchema, { path: value.artifact.path, encoding: "hex" }),
|
||||
).toBe(true);
|
||||
@@ -99,19 +98,14 @@ it("advertises exact valid schemas and records inline EVM interface evidence wit
|
||||
name: "inspect_evm_interface",
|
||||
arguments: { path: value.artifact.path, encoding: "hex" },
|
||||
});
|
||||
expect(response.isError).not.toBe(true);
|
||||
expect(
|
||||
ajv.validate(outputSchema, response.structuredContent),
|
||||
JSON.stringify(ajv.errors),
|
||||
).toBe(true);
|
||||
const parsed = toolContract("inspect_evm_interface").outputSchema.parse(
|
||||
response.structuredContent,
|
||||
assertRecordedMcpEvidence(
|
||||
response,
|
||||
"inspect_evm_interface",
|
||||
schemas,
|
||||
session,
|
||||
value,
|
||||
"inferred",
|
||||
);
|
||||
const evidence = parseEvidence(parsed);
|
||||
expect(evidence.confidence).toBe("inferred");
|
||||
expect(evidence.subject?.digest.sha256).toBe(value.artifact.sha256);
|
||||
expect(parsed.normalized_result).toEqual(value);
|
||||
expect(session.evidenceById(evidence.evidence_id)).toEqual(evidence);
|
||||
expect(
|
||||
(
|
||||
await client.callTool({
|
||||
|
||||
@@ -217,6 +217,46 @@ function resolveReference(schema: unknown, reference: string): unknown {
|
||||
return value;
|
||||
}
|
||||
|
||||
function localReferenceExpansions(schema: Record<string, unknown>): number {
|
||||
// Clients that render SDK declarations from the advertised input expand
|
||||
// schema-local references against a shared per-input budget; Pi 1.1.0
|
||||
// code-mode allows 32 and renders every later reference as `unknown`.
|
||||
// Count conservatively: every resolvable, non-cyclic reference occurrence
|
||||
// reached while walking the input, never the definitions themselves.
|
||||
let count = 0;
|
||||
const visit = (node: unknown, active: ReadonlySet<string>): void => {
|
||||
if (Array.isArray(node)) {
|
||||
node.forEach((child) => visit(child, active));
|
||||
return;
|
||||
}
|
||||
if (!isRecord(node)) return;
|
||||
if (typeof node.$ref === "string" && !active.has(node.$ref)) {
|
||||
const target = resolveReference(schema, node.$ref);
|
||||
if (target !== undefined) {
|
||||
count += 1;
|
||||
visit(target, new Set([...active, node.$ref]));
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (const [key, value] of Object.entries(node)) {
|
||||
if (
|
||||
[
|
||||
"$defs",
|
||||
"definitions",
|
||||
"examples",
|
||||
"default",
|
||||
"const",
|
||||
"enum",
|
||||
].includes(key)
|
||||
)
|
||||
continue;
|
||||
visit(value, active);
|
||||
}
|
||||
};
|
||||
visit(schema, new Set());
|
||||
return count;
|
||||
}
|
||||
|
||||
function recursiveReferences(tools: readonly ToolSchemas[]): string[] {
|
||||
return tools.flatMap((tool) =>
|
||||
(["inputSchema", "outputSchema"] as const).flatMap((kind) => {
|
||||
@@ -674,6 +714,14 @@ it("ships nonrecursive input and output schemas in the generated catalog", () =>
|
||||
expect(recursiveReferences(GENERATED_MCP_TOOL_CATALOG)).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps advertised input references within the client expansion budget", () => {
|
||||
for (const tool of GENERATED_MCP_TOOL_CATALOG)
|
||||
expect(
|
||||
localReferenceExpansions(tool.inputSchema),
|
||||
`${tool.name} exhausts the shared reference-expansion budget`,
|
||||
).toBeLessThanOrEqual(32);
|
||||
});
|
||||
|
||||
it("rejects unresolved output-schema references even for uncalled tools", () => {
|
||||
const errors = schemaErrors([
|
||||
{
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import {
|
||||
advertisedMcpToolSchemas,
|
||||
assertRecordedMcpEvidence,
|
||||
} from "../../fixtures/advertisedMcpTool.js";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { expect, it, onTestFinished, vi } from "vitest";
|
||||
import { readFile, realpath, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
@@ -20,20 +24,6 @@ import {
|
||||
wasmArtifactExecution,
|
||||
} from "../../fixtures/wasm/artifact.js";
|
||||
|
||||
const wasmToolSchemas = async (client: Client) => {
|
||||
const advertised = (await client.listTools()).tools.find(
|
||||
(tool) => tool.name === "inspect_wasm_artifact",
|
||||
);
|
||||
if (advertised?.outputSchema === undefined)
|
||||
throw new Error("WASM recovery must name an advertised static tool");
|
||||
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);
|
||||
return { name: advertised.name, ajv, inputSchema, outputSchema };
|
||||
};
|
||||
|
||||
const assertFirstSummaryDelivery = async (
|
||||
harness: Awaited<ReturnType<typeof createApplicationMcpHarness>>,
|
||||
value: ReturnType<typeof wasmArtifactFixture>,
|
||||
@@ -43,7 +33,7 @@ const assertFirstSummaryDelivery = async (
|
||||
ajv: wasmAjv,
|
||||
inputSchema,
|
||||
outputSchema,
|
||||
} = await wasmToolSchemas(harness.client);
|
||||
} = await advertisedMcpToolSchemas(harness.client, "inspect_wasm_artifact");
|
||||
const summaryInput = { path: value.artifact.path, detail: "summary" };
|
||||
expect(wasmAjv.validate(inputSchema, summaryInput)).toBe(true);
|
||||
expect(
|
||||
@@ -91,73 +81,86 @@ const assertFirstSummaryDelivery = async (
|
||||
return { summary, retained };
|
||||
};
|
||||
|
||||
it("directs rejected native WASM opening to the advertised static tool while preserving missing-WABT diagnostics", async () => {
|
||||
const directory = await createTestTempDirectory("rea-wasm-recovery-");
|
||||
const path = join(
|
||||
await realpath(directory),
|
||||
process.platform === "win32" ? "module space.bin" : 'module "quoted".bin',
|
||||
);
|
||||
await writeFile(path, Buffer.from([0, 0x61, 0x73, 0x6d, 1, 0, 0, 0]));
|
||||
const createClient = vi.fn(() => {
|
||||
throw new Error("native provider must not start for WASM");
|
||||
});
|
||||
const session = createTestBinarySession(createClient);
|
||||
const harness = await createApplicationMcpHarness({
|
||||
session,
|
||||
serverOptions: { environment: {} },
|
||||
});
|
||||
onTestFinished(harness.close);
|
||||
const { client } = harness;
|
||||
const { name, ajv, inputSchema } = await wasmToolSchemas(client);
|
||||
const input = { path };
|
||||
expect(
|
||||
toolContract("inspect_wasm_artifact").inputSchema.safeParse(input).success,
|
||||
).toBe(true);
|
||||
const opening = await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: input,
|
||||
});
|
||||
expect(opening.isError).toBe(true);
|
||||
const failure = parseMcpToolError(opening);
|
||||
expect(failure).toMatchObject({
|
||||
error: {
|
||||
code: "target_unavailable",
|
||||
category: "unsupported_target",
|
||||
details: { constraint: "wasm_requires_static_inspection" },
|
||||
},
|
||||
});
|
||||
expect(failure.error.remediation.action).toContain(JSON.stringify({ path }));
|
||||
expect(ajv.validate(inputSchema, input)).toBe(true);
|
||||
const inspection = await client.callTool({
|
||||
name,
|
||||
arguments: input,
|
||||
});
|
||||
expect(inspection.isError).toBe(true);
|
||||
expect(parseMcpToolError(inspection)).toMatchObject({
|
||||
error: {
|
||||
code: "capability_unavailable",
|
||||
details: {
|
||||
operation: "inspect_wasm_artifact",
|
||||
reason: expect.stringContaining("REA_WABT_BIN_DIRECTORY"),
|
||||
it.each(["bin", "hop"])(
|
||||
"directs rejected native WASM opening (%s suffix) to the advertised static tool while preserving missing-WABT diagnostics",
|
||||
async (extension) => {
|
||||
const directory = await createTestTempDirectory("rea-wasm-recovery-");
|
||||
const path = join(
|
||||
await realpath(directory),
|
||||
process.platform === "win32"
|
||||
? `module space.${extension}`
|
||||
: `module "quoted".${extension}`,
|
||||
);
|
||||
await writeFile(path, Buffer.from([0, 0x61, 0x73, 0x6d, 1, 0, 0, 0]));
|
||||
const createClient = vi.fn(() => {
|
||||
throw new Error("native provider must not start for WASM");
|
||||
});
|
||||
const session = createTestBinarySession(createClient);
|
||||
const harness = await createApplicationMcpHarness({
|
||||
session,
|
||||
serverOptions: { environment: {} },
|
||||
});
|
||||
onTestFinished(harness.close);
|
||||
const { client } = harness;
|
||||
const { name, ajv, inputSchema } = await advertisedMcpToolSchemas(
|
||||
client,
|
||||
"inspect_wasm_artifact",
|
||||
);
|
||||
const input = { path };
|
||||
const opening = await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: input,
|
||||
});
|
||||
expect(opening.isError).toBe(true);
|
||||
const failure = parseMcpToolError(opening);
|
||||
expect(failure).toMatchObject({
|
||||
error: {
|
||||
code: "target_unavailable",
|
||||
category: "unsupported_target",
|
||||
details: { constraint: "wasm_requires_static_inspection" },
|
||||
},
|
||||
},
|
||||
});
|
||||
const summary = await client.callTool({
|
||||
name,
|
||||
arguments: { ...input, detail: "summary" },
|
||||
});
|
||||
expect(parseMcpToolError(summary)).toMatchObject({
|
||||
error: {
|
||||
code: "capability_unavailable",
|
||||
details: { reason: expect.stringContaining("REA_WABT_BIN_DIRECTORY") },
|
||||
},
|
||||
});
|
||||
await client.ping();
|
||||
expect(createClient).not.toHaveBeenCalled();
|
||||
expect(await readFile(path)).toEqual(
|
||||
Buffer.from([0, 0x61, 0x73, 0x6d, 1, 0, 0, 0]),
|
||||
);
|
||||
});
|
||||
});
|
||||
const [, recoveryName, serializedInput] =
|
||||
failure.error.remediation.action.match(
|
||||
/call (\w+) with (\{.*\}) or run/,
|
||||
) ?? [];
|
||||
expect(recoveryName).toBe(name);
|
||||
const recoveryInput = z
|
||||
.object({ path: z.literal(path) })
|
||||
.strict()
|
||||
.parse(JSON.parse(serializedInput ?? "null"));
|
||||
expect(ajv.validate(inputSchema, recoveryInput)).toBe(true);
|
||||
const inspection = await client.callTool({
|
||||
name: recoveryName ?? "",
|
||||
arguments: recoveryInput,
|
||||
});
|
||||
expect(inspection.isError).toBe(true);
|
||||
expect(parseMcpToolError(inspection)).toMatchObject({
|
||||
error: {
|
||||
code: "capability_unavailable",
|
||||
details: {
|
||||
operation: "inspect_wasm_artifact",
|
||||
reason: expect.stringContaining("REA_WABT_BIN_DIRECTORY"),
|
||||
},
|
||||
},
|
||||
});
|
||||
const summary = await client.callTool({
|
||||
name,
|
||||
arguments: { ...input, detail: "summary" },
|
||||
});
|
||||
expect(parseMcpToolError(summary)).toMatchObject({
|
||||
error: {
|
||||
code: "capability_unavailable",
|
||||
details: { reason: expect.stringContaining("REA_WABT_BIN_DIRECTORY") },
|
||||
},
|
||||
});
|
||||
await client.ping();
|
||||
expect(createClient).not.toHaveBeenCalled();
|
||||
expect(await readFile(path)).toEqual(
|
||||
Buffer.from([0, 0x61, 0x73, 0x6d, 1, 0, 0, 0]),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("advertises exact valid schemas and records inline WASM interface evidence without a binary target", async () => {
|
||||
const value = wasmArtifactFixture();
|
||||
@@ -175,7 +178,11 @@ it("advertises exact valid schemas and records inline WASM interface evidence wi
|
||||
});
|
||||
onTestFinished(harness.close);
|
||||
const { client } = harness;
|
||||
const { ajv, inputSchema, outputSchema } = await wasmToolSchemas(client);
|
||||
const schemas = await advertisedMcpToolSchemas(
|
||||
client,
|
||||
"inspect_wasm_artifact",
|
||||
);
|
||||
const { ajv, inputSchema } = schemas;
|
||||
expect(ajv.validate(inputSchema, { path: value.artifact.path })).toBe(true);
|
||||
expect(
|
||||
ajv.validate(inputSchema, {
|
||||
@@ -188,19 +195,14 @@ it("advertises exact valid schemas and records inline WASM interface evidence wi
|
||||
name: "inspect_wasm_artifact",
|
||||
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_wasm_artifact").outputSchema.parse(
|
||||
response.structuredContent,
|
||||
assertRecordedMcpEvidence(
|
||||
response,
|
||||
"inspect_wasm_artifact",
|
||||
schemas,
|
||||
session,
|
||||
value,
|
||||
"observed",
|
||||
);
|
||||
const evidence = parseEvidence(parsed);
|
||||
expect(evidence.confidence).toBe("observed");
|
||||
expect(evidence.subject?.digest.sha256).toBe(value.artifact.sha256);
|
||||
expect(parsed.normalized_result).toEqual(value);
|
||||
expect(session.evidenceById(evidence.evidence_id)).toEqual(evidence);
|
||||
expect(
|
||||
(
|
||||
await client.callTool({
|
||||
|
||||
@@ -229,6 +229,62 @@ it("normalizes legacy version-minimum commands into build metadata", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("names numeric build-version platforms and tools", () => {
|
||||
const load = parseOtoolLoadCommands(
|
||||
withOtoolMachHeader(
|
||||
[
|
||||
"Load command 0",
|
||||
" cmd LC_BUILD_VERSION",
|
||||
" cmdsize 48",
|
||||
" platform 1",
|
||||
" minos 11.0",
|
||||
" sdk 26.5",
|
||||
" ntools 2",
|
||||
" tool 3",
|
||||
" version 1267.0",
|
||||
" tool 1029",
|
||||
" version 1.0",
|
||||
"Load command 1",
|
||||
" cmd LC_BUILD_VERSION",
|
||||
" cmdsize 24",
|
||||
" platform 99",
|
||||
" minos 1.0",
|
||||
" sdk 1.0",
|
||||
" ntools 0",
|
||||
"Load command 2",
|
||||
" cmd LC_BUILD_VERSION",
|
||||
" cmdsize 32",
|
||||
" platform MACCATALYST",
|
||||
" minos 14.0",
|
||||
" sdk 14.2",
|
||||
" ntools 1",
|
||||
" tool SWIFT",
|
||||
" version 5.9",
|
||||
"",
|
||||
].join("\n"),
|
||||
),
|
||||
);
|
||||
expect(load.builds).toEqual([
|
||||
{
|
||||
platform: "MACOS",
|
||||
minimum_os: "11.0",
|
||||
sdk: "26.5",
|
||||
tools: [
|
||||
{ name: "LD", version: "1267.0" },
|
||||
{ name: "1029", version: "1.0" },
|
||||
],
|
||||
},
|
||||
{ platform: "99", minimum_os: "1.0", sdk: "1.0", tools: [] },
|
||||
{
|
||||
platform: "MACCATALYST",
|
||||
minimum_os: "14.0",
|
||||
sdk: "14.2",
|
||||
tools: [{ name: "SWIFT", version: "5.9" }],
|
||||
},
|
||||
]);
|
||||
expect(load.commands[0]?.fields.platform).toBe(1);
|
||||
});
|
||||
|
||||
it("does not classify LC_LOAD_DYLINKER as a dylib dependency", async () => {
|
||||
const load = parseOtoolLoadCommands(
|
||||
await nativeFixture("native-macho-header/otool-header-load.txt"),
|
||||
@@ -273,3 +329,78 @@ it("limits thread-state entrypoints instead of reporting none silently", async (
|
||||
"Thread-state entrypoints (LC_UNIXTHREAD/LC_THREAD) are retained as raw load commands; file offsets are not derived.",
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["1", "MACOS"],
|
||||
["2", "IOS"],
|
||||
["3", "TVOS"],
|
||||
["4", "WATCHOS"],
|
||||
["5", "BRIDGEOS"],
|
||||
["6", "MACCATALYST"],
|
||||
["7", "IOSSIMULATOR"],
|
||||
["8", "TVOSSIMULATOR"],
|
||||
["9", "WATCHOSSIMULATOR"],
|
||||
["10", "DRIVERKIT"],
|
||||
["11", "VISIONOS"],
|
||||
["12", "VISIONOSSIMULATOR"],
|
||||
["13", "FIRMWARE"],
|
||||
["14", "SEPOS"],
|
||||
["15", "MACOS_EXCLAVECORE"],
|
||||
["16", "MACOS_EXCLAVEKIT"],
|
||||
["17", "IOS_EXCLAVECORE"],
|
||||
["18", "IOS_EXCLAVEKIT"],
|
||||
["19", "TVOS_EXCLAVECORE"],
|
||||
["20", "TVOS_EXCLAVEKIT"],
|
||||
["21", "WATCHOS_EXCLAVECORE"],
|
||||
["22", "WATCHOS_EXCLAVEKIT"],
|
||||
["23", "VISIONOS_EXCLAVECORE"],
|
||||
["24", "VISIONOS_EXCLAVEKIT"],
|
||||
] as const)("names build platform %s as %s", (code, name) => {
|
||||
const load = parseOtoolLoadCommands(
|
||||
withOtoolMachHeader(
|
||||
[
|
||||
"Load command 0",
|
||||
"cmd LC_BUILD_VERSION",
|
||||
"cmdsize 24",
|
||||
`platform ${code}`,
|
||||
"minos 1.0",
|
||||
"sdk 1.0",
|
||||
"ntools 0",
|
||||
"",
|
||||
].join("\n"),
|
||||
),
|
||||
);
|
||||
expect(load.builds[0]?.platform).toBe(name);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["1", "CLANG"],
|
||||
["2", "SWIFT"],
|
||||
["3", "LD"],
|
||||
["4", "LLD"],
|
||||
["1024", "METAL"],
|
||||
["1025", "AIRLLD"],
|
||||
["1026", "AIRNT"],
|
||||
["1027", "AIRNT_PLUGIN"],
|
||||
["1028", "AIRPACK"],
|
||||
["1031", "GPUARCHIVER"],
|
||||
["1032", "METAL_FRAMEWORK"],
|
||||
] as const)("names build tool %s as %s", (code, name) => {
|
||||
const load = parseOtoolLoadCommands(
|
||||
withOtoolMachHeader(
|
||||
[
|
||||
"Load command 0",
|
||||
"cmd LC_BUILD_VERSION",
|
||||
"cmdsize 32",
|
||||
"platform 1",
|
||||
"minos 1.0",
|
||||
"sdk 1.0",
|
||||
"ntools 1",
|
||||
`tool ${code}`,
|
||||
"version 1.0",
|
||||
"",
|
||||
].join("\n"),
|
||||
),
|
||||
);
|
||||
expect(load.builds[0]?.tools).toEqual([{ name, version: "1.0" }]);
|
||||
});
|
||||
|
||||
Vendored
+52
@@ -0,0 +1,52 @@
|
||||
import type { Client } from "@modelcontextprotocol/client";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { expect } from "vitest";
|
||||
import { toolContract } from "../../src/contracts/toolContracts.js";
|
||||
import { parseEvidence } from "../../src/domain/evidence.js";
|
||||
import type { BinarySession } from "../../src/application/binary/BinarySession.js";
|
||||
|
||||
/** Verify the actual advertised schemas, retaining a private Ajv registry. */
|
||||
export const advertisedMcpToolSchemas = async (
|
||||
client: Client,
|
||||
name: string,
|
||||
) => {
|
||||
const advertised = (await client.listTools()).tools.find(
|
||||
(tool) => tool.name === name,
|
||||
);
|
||||
if (advertised?.outputSchema === undefined)
|
||||
throw new Error(`${name} 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);
|
||||
return { name: advertised.name, ajv, inputSchema, outputSchema };
|
||||
};
|
||||
|
||||
/** Keep public output, provenance and session retention checks together. */
|
||||
export const assertRecordedMcpEvidence = (
|
||||
response: Awaited<ReturnType<Client["callTool"]>>,
|
||||
name:
|
||||
| "inspect_wasm_artifact"
|
||||
| "inspect_binary_layout"
|
||||
| "inspect_evm_interface",
|
||||
schemas: Awaited<ReturnType<typeof advertisedMcpToolSchemas>>,
|
||||
session: BinarySession,
|
||||
expected: { readonly artifact: { readonly sha256: string } },
|
||||
confidence: ReturnType<typeof parseEvidence>["confidence"],
|
||||
) => {
|
||||
expect(response.isError).not.toBe(true);
|
||||
expect(
|
||||
schemas.ajv.validate(schemas.outputSchema, response.structuredContent),
|
||||
JSON.stringify(schemas.ajv.errors),
|
||||
).toBe(true);
|
||||
const parsed = toolContract(name).outputSchema.parse(
|
||||
response.structuredContent,
|
||||
);
|
||||
const evidence = parseEvidence(parsed);
|
||||
expect(evidence.confidence).toBe(confidence);
|
||||
expect(evidence.subject?.digest.sha256).toBe(expected.artifact.sha256);
|
||||
expect(parsed.normalized_result).toEqual(expected);
|
||||
expect(session.evidenceById(evidence.evidence_id)).toEqual(evidence);
|
||||
return evidence;
|
||||
};
|
||||
+66
-49
@@ -1,17 +1,41 @@
|
||||
import type { RecordedCrash } from "../../../src/domain/native/recordedCrash.js";
|
||||
import {
|
||||
RECORDED_LINUX_CORE_PROFILES,
|
||||
type RecordedCrash,
|
||||
type RecordedCrashArchitecture,
|
||||
} from "../../../src/domain/native/recordedCrash.js";
|
||||
|
||||
// One note is a 12-byte header, the "CORE\0" owner padded to 8 bytes, then the
|
||||
// descriptor. The first note starts at the end of the owned header and phdr.
|
||||
const NOTE_START = 0x80;
|
||||
const OWNER_START = NOTE_START + 12;
|
||||
const DESCRIPTOR_START = OWNER_START + 8;
|
||||
const NOTE_HEADER_BYTES = 20;
|
||||
|
||||
const hex = (value: number): string => `0x${value.toString(16)}`;
|
||||
|
||||
/** Source-owned observation seam; these bytes do not simulate a verified ELF engine. */
|
||||
export const recordedCrashFixture = (
|
||||
path = "/artifacts/source-owned.core",
|
||||
architecture: RecordedCrashArchitecture = "x86_64-little-endian",
|
||||
): RecordedCrash => {
|
||||
const descriptor = Buffer.alloc(336);
|
||||
const profile = RECORDED_LINUX_CORE_PROFILES[architecture];
|
||||
const noteBytes = NOTE_HEADER_BYTES + profile.prstatusBytes;
|
||||
const descriptor = Buffer.alloc(profile.prstatusBytes);
|
||||
descriptor.writeInt32LE(123, 32);
|
||||
descriptor.writeInt16LE(11, 12);
|
||||
descriptor.writeBigUInt64LE(0x1122334455667788n, 224);
|
||||
// One distinguishable register carries a full uint64 so retention is asserted.
|
||||
descriptor.writeBigUInt64LE(
|
||||
0x1122334455667788n,
|
||||
profile.registerOffset + 14 * profile.registerBytes,
|
||||
);
|
||||
return {
|
||||
artifact: { path, sha256: "a".repeat(64), bytes: 512 },
|
||||
artifact: {
|
||||
path,
|
||||
sha256: "a".repeat(64),
|
||||
bytes: Math.max(512, DESCRIPTOR_START + profile.prstatusBytes),
|
||||
},
|
||||
format: "elf-core",
|
||||
architecture: "x86_64-little-endian",
|
||||
architecture,
|
||||
target_execution: "not-performed",
|
||||
live_process_identity: "unknown",
|
||||
segments: [
|
||||
@@ -20,7 +44,7 @@ export const recordedCrashFixture = (
|
||||
type: "PT_NOTE",
|
||||
header_location: { offset: "0x40", bytes: "0x38" },
|
||||
offset: "0x80",
|
||||
file_size: "0x164",
|
||||
file_size: hex(noteBytes),
|
||||
memory_size: "0x0",
|
||||
virtual_address: "0x0",
|
||||
physical_address: "0x0",
|
||||
@@ -34,11 +58,14 @@ export const recordedCrashFixture = (
|
||||
index: 0,
|
||||
segment_index: 0,
|
||||
type: "NT_PRSTATUS",
|
||||
location: { offset: "0x80", bytes: "0x164" },
|
||||
owner_location: { offset: "0x8c", bytes: "0x5" },
|
||||
location: { offset: hex(NOTE_START), bytes: hex(noteBytes) },
|
||||
owner_location: { offset: hex(OWNER_START), bytes: "0x5" },
|
||||
owner_bytes_base64: Buffer.from("CORE\0").toString("base64"),
|
||||
owner_display: "CORE",
|
||||
descriptor_location: { offset: "0x94", bytes: "0x150" },
|
||||
descriptor_location: {
|
||||
offset: hex(DESCRIPTOR_START),
|
||||
bytes: hex(profile.prstatusBytes),
|
||||
},
|
||||
descriptor_bytes_base64: descriptor.toString("base64"),
|
||||
},
|
||||
],
|
||||
@@ -48,40 +75,16 @@ export const recordedCrashFixture = (
|
||||
note_index: 0,
|
||||
historical_pid: 123,
|
||||
recorded_current_signal: 11,
|
||||
registers: [
|
||||
"r15",
|
||||
"r14",
|
||||
"r13",
|
||||
"r12",
|
||||
"rbp",
|
||||
"rbx",
|
||||
"r11",
|
||||
"r10",
|
||||
"r9",
|
||||
"r8",
|
||||
"rax",
|
||||
"rcx",
|
||||
"rdx",
|
||||
"rsi",
|
||||
"rdi",
|
||||
"orig_rax",
|
||||
"rip",
|
||||
"cs",
|
||||
"eflags",
|
||||
"rsp",
|
||||
"ss",
|
||||
"fs_base",
|
||||
"gs_base",
|
||||
"ds",
|
||||
"es",
|
||||
"fs",
|
||||
"gs",
|
||||
].map((name, index) => ({
|
||||
registers: profile.registers.map((name, index) => ({
|
||||
name,
|
||||
value: name === "rdi" ? "0x1122334455667788" : "0x0",
|
||||
value: index === 14 ? "0x1122334455667788" : "0x0",
|
||||
location: {
|
||||
offset: `0x${(148 + 112 + index * 8).toString(16)}`,
|
||||
bytes: "0x8",
|
||||
offset: hex(
|
||||
DESCRIPTOR_START +
|
||||
profile.registerOffset +
|
||||
index * profile.registerBytes,
|
||||
),
|
||||
bytes: hex(profile.registerBytes),
|
||||
},
|
||||
})),
|
||||
},
|
||||
@@ -100,27 +103,38 @@ export const recordedCrashFixture = (
|
||||
};
|
||||
|
||||
/** Source-owned SIGSEGV descriptor for scalar/source binding regressions. */
|
||||
export const recordedCrashSignalFixture = (path?: string): RecordedCrash => {
|
||||
const value = recordedCrashFixture(path);
|
||||
export const recordedCrashSignalFixture = (
|
||||
path?: string,
|
||||
architecture: RecordedCrashArchitecture = "x86_64-little-endian",
|
||||
): RecordedCrash => {
|
||||
const value = recordedCrashFixture(path, architecture);
|
||||
const profile = RECORDED_LINUX_CORE_PROFILES[architecture];
|
||||
const descriptor = Buffer.alloc(32);
|
||||
descriptor.writeInt32LE(11, 0);
|
||||
descriptor.writeInt32LE(-2, 4);
|
||||
descriptor.writeInt32LE(1, 8);
|
||||
descriptor.writeBigUInt64LE(0x1122334455667788n, 16);
|
||||
value.artifact.bytes = 640;
|
||||
const prstatusNoteBytes = NOTE_HEADER_BYTES + profile.prstatusBytes;
|
||||
const signalNoteStart = NOTE_START + prstatusNoteBytes;
|
||||
const signalDescriptorStart = signalNoteStart + NOTE_HEADER_BYTES;
|
||||
const signalNoteBytes = NOTE_HEADER_BYTES + 32;
|
||||
value.artifact.bytes = Math.max(640, signalDescriptorStart + 32);
|
||||
value.segments = value.segments.map((segment) => ({
|
||||
...segment,
|
||||
file_size: "0x198",
|
||||
file_size: hex(prstatusNoteBytes + signalNoteBytes),
|
||||
}));
|
||||
value.notes.push({
|
||||
index: 1,
|
||||
segment_index: 0,
|
||||
type: "NT_SIGINFO",
|
||||
location: { offset: "0x1e4", bytes: "0x34" },
|
||||
owner_location: { offset: "0x1f0", bytes: "0x5" },
|
||||
location: { offset: hex(signalNoteStart), bytes: hex(signalNoteBytes) },
|
||||
owner_location: { offset: hex(signalNoteStart + 12), bytes: "0x5" },
|
||||
owner_bytes_base64: Buffer.from("CORE\0").toString("base64"),
|
||||
owner_display: "CORE",
|
||||
descriptor_location: { offset: "0x1f8", bytes: "0x20" },
|
||||
descriptor_location: {
|
||||
offset: hex(signalDescriptorStart),
|
||||
bytes: "0x20",
|
||||
},
|
||||
descriptor_bytes_base64: descriptor.toString("base64"),
|
||||
});
|
||||
value.signals.push({
|
||||
@@ -141,7 +155,10 @@ export const recordedCrashFixtureBytes = (value: RecordedCrash): Buffer => {
|
||||
bytes.set([0x7f, 0x45, 0x4c, 0x46, 2, 1, 1]);
|
||||
bytes.writeUInt32LE(1, 20);
|
||||
bytes.writeUInt16LE(4, 16);
|
||||
bytes.writeUInt16LE(62, 18);
|
||||
bytes.writeUInt16LE(
|
||||
RECORDED_LINUX_CORE_PROFILES[value.architecture].machine,
|
||||
18,
|
||||
);
|
||||
bytes.writeBigUInt64LE(64n, 32);
|
||||
bytes.writeUInt16LE(56, 54);
|
||||
bytes.writeUInt16LE(value.segments.length, 56);
|
||||
|
||||
Reference in New Issue
Block a user