test: prune redundant and obsolete coverage

This commit is contained in:
morluto committed 2026-11-17 14:16:24 -05:00
1 parent 05be423acb
commit 015f726a9e
39 files changed
+317 -979

No files matched your search

-32
View File
@@ -332,38 +332,6 @@ describe("parseDumpsysPackageOutput", () => {
).requestedPermissions,
).toBe(2);
});
it("counts Unicode permission names without ending the section", () => {
expect(
parseDumpsysPackageOutput(
[
"Package [com.example] (abcdef):",
" pkg=Package{abcdef com.example}",
" requested permissions:",
" com.example.permission-First",
" com.example.permission.ÉCRIRE WITH SPACE",
" android.permission.CAMERA",
" install permissions:",
" android.permission.CAMERA: granted=true",
].join("\n"),
).requestedPermissions,
).toBe(3);
});
it("ends requested permissions at a same-indent field", () => {
expect(
parseDumpsysPackageOutput(
[
"Package [com.example] (abcdef):",
" pkg=Package{abcdef com.example}",
" requested permissions:",
" android.permission.INTERNET",
" gids=[1000]",
" android.permission.CAMERA",
].join("\n"),
).requestedPermissions,
).toBe(1);
});
});
describe("parseWmDensityOutput", () => {
+5 -12
View File
@@ -4,10 +4,7 @@ import { AnalysisOutputError } from "../domain/analysisErrorCore.js";
import type { JsonValue } from "../domain/jsonValue.js";
import {
listNamesFact,
listProceduresFact,
listStringsFact,
searchProceduresFact,
searchStringsFact,
} from "../domain/native/nativeOperationFacts.js";
import { ok } from "../domain/result.js";
import { executeFact } from "./AnalysisOperationFacts.js";
@@ -32,21 +29,18 @@ const nameRow = { address: "0x1000", value: "main", provider_extra: 7 };
const stringRow = { address: "0x2000", value: "hello", provider_extra: 7 };
it.each([
[listNamesFact, nameRow],
[listProceduresFact, nameRow],
[searchProceduresFact, nameRow],
[listStringsFact, stringRow],
[searchStringsFact, stringRow],
["list_names", listNamesFact, nameRow],
["list_strings", listStringsFact, stringRow],
] as const)(
"parses %s once, dropping unknown row fields from the fact but not the execution",
async (contract, row) => {
"retains the raw %s execution and projects its typed fact",
async (operation, contract, row) => {
const calls: string[] = [];
const executed = await executeFact(
portReturning([row], calls),
contract,
{},
);
expect(calls).toEqual([contract.operation]);
expect(calls).toEqual([operation]);
if (!executed.ok) throw executed.error;
expect(executed.value.fact).toEqual([
{ address: row.address, value: row.value },
@@ -67,7 +61,6 @@ it("refuses a malformed result with field diagnostics and the observed execution
expect(executed.error).toBeInstanceOf(AnalysisOutputError);
expect(executed.error).toMatchObject({
operation: "list_names",
reason: "Provider returned an invalid name inventory",
diagnostics: {
contract_issues: [
{
@@ -6,18 +6,14 @@ import { expect, it } from "vitest";
import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js";
import { resolveAppleBundleExecutable } from "./AppBundleExecutable.js";
it.each([
["no comment", ""],
["block comment", "/* App metadata */\n"],
["line comment", "// App metadata\n"],
["mixed comments", " \t/* header */\n// executable selection\n"],
])("resolves an OpenStep Info.plist with %s", async (_label, prefix) => {
it("resolves the declared executable from a commented OpenStep Info.plist", async () => {
const root = await createTestTempDirectory("rea-openstep-bundle-");
const bundle = join(root, "Fixture.app");
const programs = join(bundle, "Contents", "MacOS");
const executable = join(programs, "Fixture");
const infoPlist = join(bundle, "Contents", "Info.plist");
const source = `${prefix}{ CFBundleExecutable = Fixture; }`;
const source =
" \t/* header */\n// executable selection\n{ CFBundleExecutable = Fixture; }";
await mkdir(programs, { recursive: true });
await writeFile(infoPlist, source);
await writeFile(executable, "fixture - never executed");
-21
View File
@@ -1,6 +1,3 @@
import { readdir, readFile } from "node:fs/promises";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { expect, it } from "vitest";
import {
@@ -38,21 +35,3 @@ it.each([
expected,
);
});
// Client root semantics differ per reader, so they are derived only here.
it("keeps client configuration-root variables in one owner", async () => {
const directory = fileURLToPath(new URL(".", import.meta.url));
const offenders: string[] = [];
for (const name of await readdir(directory)) {
if (
!name.endsWith(".ts") ||
name.endsWith(".test.ts") ||
name === "ClientConfigRoots.ts"
)
continue;
const text = await readFile(join(directory, name), "utf8");
if (/\.(?:XDG_CONFIG_HOME|VSCODE_APPDATA|VSCODE_PORTABLE)\b/u.test(text))
offenders.push(name);
}
expect(offenders).toEqual([]);
});
@@ -1,50 +0,0 @@
import { describe, expect, it } from "vitest";
import { JAVASCRIPT_FEATURE_TRACE_EXAMPLE } from "../contracts/javascript/javascriptApplicationWorkflowExamples.js";
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
import { resolveEvidenceInput } from "./EvidenceInputResolver.js";
const evidence = JAVASCRIPT_FEATURE_TRACE_EXAMPLE.application;
const reference = {
kind: "retained-evidence" as const,
evidence_id: evidence.evidence_id,
};
describe("exact Evidence input resolution", () => {
it("reports a missing reference and an available recovery", () => {
for (const lookup of [undefined, () => undefined]) {
const result = resolveEvidenceInput(reference, lookup);
if (result.ok) throw new Error("unknown reference was resolved");
const projected = projectAnalysisError(result.error);
expect(projected).toMatchObject({
details: {
evidence_id: reference.evidence_id,
reason: "missing",
actual: null,
},
});
expect(projected.message).toContain(
"not available from the selected source",
);
expect(projected.remediation.action).toContain(
"complete inline Evidence",
);
expect(projected.details).not.toHaveProperty("reference_scope");
}
});
it("rejects a lookup returning another record rather than guessing identity", () => {
const otherId = `ev_${"f".repeat(64)}`;
const result = resolveEvidenceInput(
{ ...reference, evidence_id: otherId },
() => evidence,
);
if (result.ok) throw new Error("mismatched reference was resolved");
expect(projectAnalysisError(result.error)).toMatchObject({
details: {
reason: "identity_mismatch",
expected: otherId,
actual: evidence.evidence_id,
},
});
});
});
@@ -283,20 +283,24 @@ describe("Evidence request branches and source diagnostics", () => {
it("retains the exact missing/incorrect identity and its source path", () => {
const schema = z.strictObject({ source: evidenceInputSchema });
const missing = resolveEvidenceRequest(
"test",
{ source: reference },
schema,
undefined,
{ referenceScope: "retained-closure" },
);
if (missing.ok) throw new Error("missing reference was accepted");
expect(missing.error).toBeInstanceOf(EvidenceReferenceError);
expect(missing.error).toMatchObject({
reason: "missing",
referenceScope: "retained-closure",
diagnostics: { input_path: ["source"] },
});
for (const referenceScope of [undefined, "retained-closure"] as const) {
const missing = resolveEvidenceRequest(
"test",
{ source: reference },
schema,
undefined,
referenceScope === undefined ? {} : { referenceScope },
);
if (missing.ok) throw new Error("missing reference was accepted");
expect(missing.error).toBeInstanceOf(EvidenceReferenceError);
expect(missing.error).toMatchObject({
evidenceId: reference.evidence_id,
reason: "missing",
actual: null,
referenceScope,
diagnostics: { input_path: ["source"] },
});
}
const different = { ...reference, evidence_id: `ev_${"f".repeat(64)}` };
const mismatched = resolveEvidenceRequest(
"test",
@@ -305,7 +309,12 @@ describe("Evidence request branches and source diagnostics", () => {
() => evidence,
);
if (mismatched.ok) throw new Error("mismatched record was accepted");
expect(mismatched.error).toMatchObject({ reason: "identity_mismatch" });
expect(mismatched.error).toMatchObject({
reason: "identity_mismatch",
expected: different.evidence_id,
actual: evidence.evidence_id,
diagnostics: { input_path: ["source"] },
});
});
});
-22
View File
@@ -252,15 +252,6 @@ describe("browserScenarioSchema", () => {
expect(actions[1]).toMatchObject({ duration_ms: 120_001 });
});
it("does not accept the removed provider timeout configuration", () => {
expect(
browserScenarioSchema.safeParse({
...baseScenario(),
limits: { max_duration_ms: 1 },
}).success,
).toBe(false);
});
it("redacts overlapping secrets longest-first", () => {
const scenario = browserScenarioSchema.parse(baseScenario());
const secrets = resolveScenarioSecrets(scenario, {
@@ -367,19 +358,6 @@ describe("browserScenarioSchema secret declarations", () => {
expect(browserScenarioSchema.safeParse(unused).success).toBe(false);
});
it("rejects removed replay and origin policy options", () => {
for (const legacyField of [
{ request_replay: { mode: "disabled" } },
{ allowed_origins: ["https://app.example.test"] },
])
expect(
browserScenarioSchema.safeParse({
...baseScenario(),
...legacyField,
}).success,
).toBe(false);
});
it("rejects raw secret-shaped action values", () => {
const scenario = baseScenario();
scenario.actions[0] = {
-41
View File
@@ -1,41 +0,0 @@
import { expect, it } from "vitest";
import { runWithAnalysisOperationSnapshot } from "../domain/analysisOperationSnapshot.js";
import {
kunaProjectDeadline,
readKunaConfiguration,
} from "../kuna/KunaConfiguration.js";
it("keeps the deadline a failed export accepted after the override is reset", () => {
const environment = {
REA_KUNA_COMMAND: "/usr/bin/kuna",
REA_KUNA_PROJECT_TIMEOUT_MS: "not-a-timeout",
};
const configuration = runWithAnalysisOperationSnapshot(
{
revision: 1,
overrides: { "kuna.project_timeout_ms": 5000 },
},
() => {
const parsed = readKunaConfiguration(environment, "linux");
if (!parsed.ok) throw new Error(parsed.error.reason);
return parsed.value;
},
);
expect(configuration.projectTimeoutLaunchValid).toBe(false);
const accepted = runWithAnalysisOperationSnapshot(
{
revision: 1,
overrides: { "kuna.project_timeout_ms": 5000 },
},
() => kunaProjectDeadline(configuration),
);
expect(accepted).toEqual({
setting: "REA_KUNA_PROJECT_TIMEOUT_MS",
ms: 5000,
source: "runtime",
});
expect(() => kunaProjectDeadline(configuration)).toThrow(
/no runtime override is active/,
);
expect(accepted).toMatchObject({ ms: 5000, source: "runtime" });
});
+1 -1
View File
@@ -127,7 +127,7 @@ export const annotationsFromEffects = (
* failure reasons and availability diagnostics) and the adb and apktool
* client probes (version output and stderr excerpts) can.
*/
export const TARGET_CONTENT_FREE_TOOLS: ReadonlySet<string> = new Set([
const TARGET_CONTENT_FREE_TOOLS: ReadonlySet<string> = new Set([
"inspect_analysis_settings",
"update_analysis_settings",
"export_evidence_bundle",
@@ -1,4 +1,4 @@
import { expect, it, vi } from "vitest";
import { expect, it } from "vitest";
import { z } from "zod";
import {
freezeOwnedJsonTreeSnapshot,
@@ -52,23 +52,31 @@ it("keeps schema-specific normalized facts separate without mutating sealed sour
}
});
it("borrows omitted optional fields from a sealed JSON source and reuses their parsed facts", () => {
it("borrows a sealed JSON source with an omitted optional field", () => {
const source = freezeOwnedJsonTreeSnapshot({});
const schema = z.strictObject({ optional: z.string().optional() });
const parse = vi.spyOn(schema, "safeParse");
const read = createAnalysisViewResultReader(schema);
try {
for (let attempt = 0; attempt < 2; attempt++) {
const result = read(parent(source));
if (!result.ok) throw result.error;
expect(result.value).toBe(source);
expect(result.value.optional).toBeUndefined();
expect(Object.hasOwn(result.value, "optional")).toBe(false);
}
expect(parse).toHaveBeenCalledTimes(1);
} finally {
parse.mockRestore();
}
const result = read(parent(source));
if (!result.ok) throw result.error;
expect(result.value).toBe(source);
expect(Object.hasOwn(result.value, "optional")).toBe(false);
});
it("reuses normalized facts only when the parent carries the owning seal", () => {
const source = freezeOwnedJsonTreeSnapshot({});
const sealed = parent(source);
const unsealed = { ...sealed, sealedResult: false };
let revision = "initial";
const read = createAnalysisViewResultReader(
z.strictObject({}).transform(() => ({ revision })),
);
expect(read(unsealed)).toEqual({ ok: true, value: { revision: "initial" } });
revision = "sealed";
expect(read(sealed)).toEqual({ ok: true, value: { revision: "sealed" } });
revision = "latest";
expect(read(sealed)).toEqual({ ok: true, value: { revision: "sealed" } });
expect(read(unsealed)).toEqual({ ok: true, value: { revision: "latest" } });
});
it("preserves explicit undefined normalization without freezing or caching non-JSON facts", () => {
@@ -1,5 +1,5 @@
import { UNKNOWN_EVIDENCE_SUBJECT } from "../../../tests/fixtures/evidenceSubject.js";
import { expect, it, vi } from "vitest";
import { expect, it } from "vitest";
import { z } from "zod";
import { androidComponentsViewRequestSchema } from "../android/androidPackageQuery.js";
import { createEvidence } from "../evidence.js";
@@ -11,10 +11,7 @@ import {
androidMethodSummaryViewResultSchema,
} from "./analysisViewResult.js";
import type { AdmittedView } from "./analysisViewShape.js";
import {
androidClassSummarySchema,
projectAndroidSymbolSummary as projectAdmittedAndroidSymbolSummary,
} from "./androidSymbolView.js";
import { projectAndroidSymbolSummary as projectAdmittedAndroidSymbolSummary } from "./androidSymbolView.js";
const projectAndroidSymbolSummary = (
parent: Parameters<typeof projectAdmittedAndroidSymbolSummary>[0],
@@ -313,15 +310,3 @@ it("refuses an admitted one-MiB source plus summary context without truncation a
});
expect(parent.normalizedResult).toEqual(facts);
});
it("reuses validation of an authenticated sealed class result across retained summaries", () => {
const { parent } = fixture("inspect_android_class", classReport());
const parse = vi.spyOn(androidClassSummarySchema, "safeParse");
try {
for (let attempt = 0; attempt < 2; attempt++)
expect(projectAnalysisView(parent, { kind: "summary" }).ok).toBe(true);
expect(parse).toHaveBeenCalledTimes(1);
} finally {
parse.mockRestore();
}
});
@@ -1,5 +1,5 @@
import { createEmptyIl2cppMetadataFixture } from "../il2cpp/il2cppMetadata.fixture.js";
import { afterEach, expect, it, vi } from "vitest";
import { expect, it } from "vitest";
import { z } from "zod";
import {
il2cppMetadataParentSchema,
@@ -25,10 +25,6 @@ const projectIl2cppMetadataView = (
): ReturnType<typeof projectAdmittedIl2cppMetadataView> =>
projectAdmittedIl2cppMetadataView(parent, view satisfies AdmittedView);
afterEach(() => {
vi.restoreAllMocks();
});
const report: Il2cppMetadata = {
...createEmptyIl2cppMetadataFixture(),
images: [{ name: "A.dll", type_start: 0, type_count: 2 }],
@@ -88,8 +84,7 @@ const page = {
limit: 1,
} as const;
it("validates a sealed parent once across pages and keeps counts exact", () => {
const parse = vi.spyOn(il2cppMetadataParentSchema, "safeParse");
it("keeps collection counts exact across sealed metadata pages", () => {
const sealed = parent(freezeJsonSnapshot(structuredClone(report)), true);
for (const offset of [0, 1]) {
const view = projectIl2cppMetadataView(sealed, { ...page, offset });
@@ -114,15 +109,6 @@ it("validates a sealed parent once across pages and keeps counts exact", () => {
},
});
}
expect(parse).toHaveBeenCalledTimes(1);
});
it("revalidates unsealed inline input on every page", () => {
const parse = vi.spyOn(il2cppMetadataParentSchema, "safeParse");
const inline = parent(structuredClone(report), false);
projectIl2cppMetadataView(inline, page);
projectIl2cppMetadataView(inline, page);
expect(parse).toHaveBeenCalledTimes(2);
});
it("preserves historical omission as unknown while keeping existing metadata queries usable", () => {
@@ -1,9 +1,8 @@
import { describe, expect, it, vi } from "vitest";
import { describe, expect, it } from "vitest";
import {
changedEvidenceSubject,
UNKNOWN_EVIDENCE_SUBJECT,
} from "../../../tests/fixtures/evidenceSubject.js";
import { interfaceBuilderAnalysisSchema } from "../apple/interfaceBuilderGraph.js";
import { freezeJsonSnapshot } from "../immutableJson.js";
import { projectAnalysisView } from "./analysisView.js";
@@ -109,40 +108,23 @@ const parent = (
});
describe("Interface Builder immutable interpretation", () => {
it("validates a sealed graph once while checking the current parent binding every time", () => {
it("checks the current subject even after admitting the sealed graph", () => {
const source = {
...parent(freezeJsonSnapshot(report())),
sealedResult: true,
};
const parse = vi.spyOn(interfaceBuilderAnalysisSchema, "safeParse");
try {
expect(projectAnalysisView(source, { kind: "summary" }).ok).toBe(true);
expect(
projectAnalysisView(source, {
kind: "interface-builder",
collection: "nodes",
document: main,
offset: 0,
limit: 1,
}).ok,
).toBe(true);
expect(parse).toHaveBeenCalledTimes(1);
const changed = {
...source,
subject: changedEvidenceSubject(source.subject!, {
sha256: "d".repeat(64),
}),
};
const rejected = projectAnalysisView(changed, { kind: "summary" });
if (rejected.ok)
throw new Error("expected a subject refusal after reuse");
expect(rejected.error).toMatchObject({
issues: [{ path: ["source", "subject"] }],
});
expect(parse).toHaveBeenCalledTimes(1);
} finally {
parse.mockRestore();
}
expect(projectAnalysisView(source, { kind: "summary" }).ok).toBe(true);
const changed = {
...source,
subject: changedEvidenceSubject(source.subject!, {
sha256: "d".repeat(64),
}),
};
const rejected = projectAnalysisView(changed, { kind: "summary" });
if (rejected.ok) throw new Error("expected a subject refusal");
expect(rejected.error).toMatchObject({
issues: [{ path: ["source", "subject"] }],
});
});
it("revalidates mutable and shallow-frozen imports despite a claimed seal", () => {
@@ -163,18 +145,6 @@ describe("Interface Builder immutable interpretation", () => {
expect(corrected.value).toMatchObject({ items: [{ name: "corrected" }] });
});
it("does not reuse a claimed immutable graph without the owning seal", () => {
const source = parent(freezeJsonSnapshot(report()));
const parse = vi.spyOn(interfaceBuilderAnalysisSchema, "safeParse");
try {
expect(projectAnalysisView(source, { kind: "summary" }).ok).toBe(true);
expect(projectAnalysisView(source, { kind: "summary" }).ok).toBe(true);
expect(parse).toHaveBeenCalledTimes(2);
} finally {
parse.mockRestore();
}
});
it("counts matching rows once, preserves their order, and exhausts empty or late pages", () => {
const decoded = report(true);
decoded.graph.nodes.splice(1, 0, node("other:middle", "control", second));
@@ -1,13 +1,10 @@
import { UNKNOWN_EVIDENCE_SUBJECT } from "../../../tests/fixtures/evidenceSubject.js";
import { afterEach, expect, it, vi } from "vitest";
import { expect, it } from "vitest";
import { freezeJsonSnapshot } from "../immutableJson.js";
import { nativeInventoryRowsSchemas } from "../native/nativeInventory.js";
import { projectAnalysisView } from "./analysisView.js";
import type { AnalysisViewParent } from "./analysisViewParent.js";
import { analysisViewRequestSchema } from "./analysisViewRequest.js";
afterEach(() => vi.restoreAllMocks());
const rows = () => [
{
address: "0x10",
@@ -74,9 +71,8 @@ it("pages exact source order and same-address alternatives, with selectable fiel
expect(source.normalizedResult).toEqual(original);
});
it("reuses only authenticated immutable validation while rebinding provenance to the current parent", () => {
it("binds provenance to the current parent when its inventory facts were already viewed", () => {
const source = parent(freezeJsonSnapshot(rows()));
const parse = vi.spyOn(nativeInventoryRowsSchemas.names, "safeParse");
project(source, { kind: "summary" });
const next = project(
{
@@ -86,7 +82,6 @@ it("reuses only authenticated immutable validation while rebinding provenance to
},
{ kind: "native-inventory", limit: 1 },
);
expect(parse).toHaveBeenCalledOnce();
expect(next).toMatchObject({
parent_evidence_id: `ev_${"b".repeat(64)}`,
source_provider: { id: "other", name: "Other", version: null },
@@ -96,19 +91,17 @@ it("reuses only authenticated immutable validation while rebinding provenance to
});
});
it("retains caller metadata in Evidence while reusing owner-normalized inventory rows", () => {
it("projects normalized inventory rows while retaining caller metadata in Evidence", () => {
const original = [{ ...rows()[0]!, caller_metadata: { label: "keep me" } }];
const source = parent(freezeJsonSnapshot(original));
const parse = vi.spyOn(nativeInventoryRowsSchemas.names, "safeParse");
for (let attempt = 0; attempt < 2; attempt++) {
const page = project(source, { kind: "native-inventory", limit: 1 });
expect(page).toMatchObject({
rows: [{ source_index: 0, record: rows()[0] }],
});
}
expect(parse).toHaveBeenCalledOnce();
const page = project(source, { kind: "native-inventory", limit: 1 });
expect(page).toMatchObject({
rows: [{ source_index: 0, record: rows()[0] }],
});
expect(source.normalizedResult).toEqual(original);
expect(original[0]?.caller_metadata).toEqual({ label: "keep me" });
expect(source.normalizedResult).toMatchObject([
{ caller_metadata: { label: "keep me" } },
]);
});
it("revalidates mutable and shallow-frozen arrays despite a forged sealing flag", () => {
+1 -7
View File
@@ -71,7 +71,7 @@ describe("artifact graph path and provenance fields", () => {
expect(parsed.provenance[0]?.arguments[0]).toBe(arguments_[0]);
});
it("requires current coverage and integrity facts and rejects the obsolete status alias", () => {
it("requires coverage and integrity facts", () => {
const inventory = {
manifest: {
manifest_id: `agm_${"b".repeat(64)}`,
@@ -110,11 +110,5 @@ describe("artifact graph path and provenance fields", () => {
integrity_contradictions: [],
}).success,
).toBe(true);
expect(
artifactInventoryResultSchema.safeParse({
...inventory,
coverage_status: "complete",
}).success,
).toBe(false);
});
});
+2 -21
View File
@@ -9,10 +9,7 @@ import { artifactInventoryResultSchema } from "./artifactGraph.js";
import { artifactGraphDigest, artifactManifestId } from "./artifactIdentity.js";
import { createEvidenceBundle } from "./evidenceBundle.js";
import { EvidenceIntegrityError } from "./evidenceErrors.js";
import {
reconstructionVerificationResultSchema,
reconstructionSpecificationSchema,
} from "./reconstructionVerificationSchemas.js";
import { reconstructionVerificationResultSchema } from "./reconstructionVerificationSchemas.js";
import {
jsonObjectSchema,
jsonValueSchema,
@@ -259,7 +256,7 @@ const verifyArtifactComparison = (
};
describe("reconstruction verification", () => {
it("accepts real process dimensions and rejects removed protocol dimensions", () => {
it("verifies interaction and process dimensions independently", () => {
const left = source("1", "controlled-replay");
const right = source("2", "controlled-replay");
const result = {
@@ -308,22 +305,6 @@ describe("reconstruction verification", () => {
).toMatchObject({
summary: { total: 2, passed: 1, failed: 1, unknown: 0 },
});
for (const dimension of ["protocol", "shim"] as const) {
expect(
reconstructionSpecificationSchema.safeParse({
name: "Removed process dimension",
claims: [
{
kind: "behavioral",
claim_id: dimension,
title: "Unsupported dimension",
comparison_evidence_id: comparison.evidence_id,
dimension,
},
],
}).success,
).toBe(false);
}
});
it("passes a complete authoritative claim with two-sided citations", () => {
-19
View File
@@ -1,19 +0,0 @@
import { expect, it } from "vitest";
import { hasValidSourceMapContents } from "./sourceMapContents.js";
it("accepts absent map-level source contents and nullable string slots", () => {
expect(hasValidSourceMapContents(undefined)).toBe(true);
expect(hasValidSourceMapContents(null)).toBe(true);
expect(hasValidSourceMapContents([null, "retained source"])).toBe(true);
expect(hasValidSourceMapContents([null, 42])).toBe(false);
expect(hasValidSourceMapContents("retained source")).toBe(false);
});
it("leaves sourcesContent length to source decoding (ECMA-426 DecodeSourceMapSources)", () => {
expect(hasValidSourceMapContents([])).toBe(true);
expect(hasValidSourceMapContents(["retained source"])).toBe(true);
expect(
hasValidSourceMapContents(["a", null, "unused trailing content"]),
).toBe(true);
});
+8 -10
View File
@@ -21,7 +21,6 @@ import { compareFunctions } from "./functionComparison.js";
import { functionSnapshotFixture } from "./functionDossierEvidence.fixture.js";
import {
correlateStaticAndRuntime,
staticRuntimeCorrelationInputSchema,
staticRuntimeCorrelationResultSchema,
} from "./staticRuntimeCorrelation.js";
@@ -222,17 +221,16 @@ it("keeps text, assembly and unavailable CFG caveats on their selected correlati
});
describe("static/runtime correlation", () => {
it("accepts real runtime dimensions and rejects removed protocol dimensions", () => {
const runtime = processComparison("unchanged");
it("uses the selected interaction status even when the terminal changed", () => {
const runtime = processComparison("changed");
expect(
correlateStaticAndRuntime(mapping(runtime, "static_only", "interaction")),
).toMatchObject({ status: "correlated" });
for (const dimension of ["protocol", "shim"] as const)
expect(
staticRuntimeCorrelationInputSchema.safeParse(
mapping(runtime, "static_only", dimension),
).success,
).toBe(false);
).toMatchObject({
status: "correlated",
correlations: {
items: [{ runtime: { dimension: "interaction", status: "unchanged" } }],
},
});
});
it("rejects duplicate static comparison selection", () => {
@@ -1,39 +0,0 @@
import { expect, it } from "vitest";
import {
ghidraDecompileTimeoutRecovery,
ghidraStartupTimeoutGuidance,
} from "./GhidraProviderClient.js";
it("names the saved Program when a finished invocation must restart after a decompile deadline", () => {
const recovery = ghidraDecompileTimeoutRecovery(10, "owned-checkpoint");
expect(recovery.remediationAction).toContain(
"restores the last saved Program from REA_GHIDRA_CHECKPOINT_DIR",
);
expect(recovery.remediationAction).toContain(
"if initial analysis never completed",
);
expect(recovery.remediationAction).not.toContain(
"repeats import and analysis",
);
expect(recovery.continuingRemediationAction).toContain(
"update_analysis_settings",
);
});
it("keeps initial analysis and later restore explicit in checkpoint startup recovery", () => {
const guidance = ghidraStartupTimeoutGuidance(250, "owned-checkpoint");
expect(guidance.userMessage).toContain(
"checkpoint restore or initial analysis and saving",
);
for (const action of [
guidance.remediationAction,
guidance.continuingCallerGuidance.remediationAction,
]) {
expect(action).toContain("Keep REA_GHIDRA_CHECKPOINT_DIR");
expect(action).toContain(
"initial analysis and its first checkpoint must complete once",
);
expect(action).not.toContain("repeats import from scratch");
expect(action).not.toContain("REA_GHIDRA_PROJECT_PATH");
}
});
+58 -16
View File
@@ -20,6 +20,7 @@ import {
ghidraFunctionSeedRecovery,
ghidraNotInProcedureLimitation,
limitationsFor,
type GhidraSessionSource,
} from "./GhidraProviderCapabilities.js";
import { AnalysisProviderRegistry } from "../application/binary/AnalysisProviderRegistry.js";
import { composeBinarySession } from "../application/binary/BinarySessionComposition.js";
@@ -2236,13 +2237,20 @@ it("preserves a bridge request limit when reattributing a Ghidra session failure
describe("Ghidra decompile deadline for a finished invocation", () => {
const decompileDeadline = async (
seconds: number,
existingProject: boolean,
source: GhidraSessionSource,
cancelled = false,
) => {
const environment: Record<string, string> = {
REA_GHIDRA_DECOMPILE_TIMEOUT_SECONDS: String(seconds),
};
if (existingProject) {
if (source === "owned-checkpoint") {
const root = await mkdtemp(join(tmpdir(), "rea-deadline-checkpoint-"));
onTestFinished(async () => {
await rm(root, { recursive: true, force: true });
});
environment.REA_GHIDRA_CHECKPOINT_DIR = root;
}
if (source === "existing-project") {
const root = await mkdtemp(join(tmpdir(), "rea-deadline-project-"));
onTestFinished(async () => {
await rm(root, { recursive: true, force: true });
@@ -2288,20 +2296,18 @@ describe("Ghidra decompile deadline for a finished invocation", () => {
};
it.each([
{ seconds: 5, existingProject: false },
{ seconds: 2_147_483, existingProject: false },
{ seconds: 5, existingProject: true },
])(
"delivers each lifetime's recovery for a $seconds-second deadline (existing project: $existingProject)",
async ({ seconds, existingProject }) => {
{ seconds: 5, source: "fresh-import" },
{ seconds: 2_147_483, source: "fresh-import" },
{ seconds: 5, source: "existing-project" },
{ seconds: 5, source: "owned-checkpoint" },
] as const)(
"delivers each lifetime's recovery for a $seconds-second deadline ($source)",
async ({ seconds, source }) => {
const { message, continuing, invocation } = await decompileDeadline(
seconds,
existingProject,
);
const recovery = ghidraDecompileTimeoutRecovery(
seconds,
existingProject ? "existing-project" : "fresh-import",
source,
);
const recovery = ghidraDecompileTimeoutRecovery(seconds, source);
for (const projected of [continuing, invocation])
expect(projected).toMatchObject({
code: "provider_timeout",
@@ -2316,10 +2322,20 @@ describe("Ghidra decompile deadline for a finished invocation", () => {
expect(continuing.remediation.action).toBe(
recovery.continuingRemediationAction,
);
// Only a saved project's rerun reopens it instead of importing again.
expect(
invocation.remediation.action.includes("REA_GHIDRA_PROJECT_PATH"),
).toBe(existingProject);
).toBe(source === "existing-project");
if (source === "owned-checkpoint") {
expect(invocation.remediation.action).toMatch(
/restores.*REA_GHIDRA_CHECKPOINT_DIR/u,
);
expect(invocation.remediation.action).toMatch(
/if initial analysis never completed/u,
);
expect(continuing.remediation.action).toContain(
"update_analysis_settings",
);
}
expect(invocation.message.startsWith(message)).toBe(true);
expect(continuing.message).toBe(
`${invocation.message} ${GHIDRA_SESSION_RETAINED}`,
@@ -2353,7 +2369,7 @@ describe("Ghidra decompile deadline for a finished invocation", () => {
async (existingProject) => {
const { continuing, invocation } = await decompileDeadline(
5,
existingProject,
existingProject ? "existing-project" : "fresh-import",
true,
);
// Cancellation closed the session, so no caller is told it remains.
@@ -4921,6 +4937,32 @@ describe("Ghidra startup deadline for a finished invocation", () => {
});
});
it("identifies checkpoint recovery for a timed-out startup", async () => {
const root = await mkdtemp(join(tmpdir(), "rea-startup-checkpoint-"));
onTestFinished(async () => {
await rm(root, { recursive: true, force: true });
});
for (const lifetime of ["invocation", "continuing"] as const) {
const projected = await ghidraTimedOut(
"start",
"Ghidra startup deadline elapsed",
{ REA_GHIDRA_CHECKPOINT_DIR: root },
lifetime,
);
expect(projected).toMatchObject({
code: "provider_timeout",
details: { timeout_ms: 250 },
});
expect(projected.message).toMatch(/checkpoint restore.*initial analysis/u);
expect(projected.remediation.action).toContain(
"Keep REA_GHIDRA_CHECKPOINT_DIR",
);
expect(projected.remediation.action).toMatch(
/first checkpoint must complete once/u,
);
}
});
const startFailure = async (
stdout: string,
environment: Readonly<Record<string, string>> = {},
@@ -1,11 +0,0 @@
import { describe, expect, it } from "vitest";
import { windowsP0Limitations } from "./GhidraProviderCapabilities.js";
describe("Windows Ghidra P0 filesystem boundary", () => {
it("admits NTFS and ReFS targets and runtimes", () => {
expect(windowsP0Limitations.join(" ")).toContain(
"local NTFS/ReFS targets and runtimes",
);
});
});
-31
View File
@@ -15,37 +15,6 @@ const failure = bindGhidraSessionFailure(() => ({
}));
describe("Ghidra request queue failure settlement", () => {
it("forwards the request deadline to the executor", async () => {
const optionsSeen: { timeoutMs?: number }[] = [];
const queue = new GhidraRequestQueue(
(_method, _parameters, options) => {
optionsSeen.push(options);
return Promise.resolve(
options.timeoutMs === 0
? err(
failure(
"timeout",
"Ghidra request deadline elapsed",
undefined,
{ timeoutMs: 0 },
),
)
: ok(null),
);
},
failure,
() => Promise.resolve(ok(null)),
);
await expect(
queue.run("ping", {}, { timeoutMs: 0 }),
).resolves.toMatchObject({
ok: false,
error: { kind: "timeout", timeoutMs: 0 },
});
expect(optionsSeen).toEqual([{ timeoutMs: 0 }]);
});
it.each([new TypeError("Decoder rejected"), "decoder rejected", null])(
"preserves a rejected executor cause (%j) and drains the next request",
async (cause) => {
-7
View File
@@ -27,13 +27,6 @@ it("retains an explicitly undefined cause separately from omission", () => {
expect(error.diagnostics).toEqual({ stage: "queue" });
});
it("retains an opaque caller reason by identity", () => {
const reason = { source: "caller", opaque: 7 };
const error = new HopperCancelledError(reason);
expect(error.cause).toBe(reason);
});
it("reports a stopped or unstartable bridge as a provider-wide failure", () => {
expect(new HopperProcessError(1).providerWide).toBe(true);
expect(new HopperStartError().providerWide).toBe(true);
-36
View File
@@ -1,36 +0,0 @@
import { describe, expect, it } from "vitest";
import { IDA_COMPATIBILITY_PROFILES } from "./IdaConfiguration.js";
import {
idaCapabilities,
idaOperationUnavailableReason,
} from "./IdaProviderCapabilities.js";
import { IDA_OPERATIONS } from "./IdaProviderMetadata.js";
describe("IDA profile operation admission", () => {
for (const [name, profile] of Object.entries(IDA_COMPATIBILITY_PROFILES)) {
it(`keeps ${name} advertisement and execution admission aligned`, () => {
const capabilities = idaCapabilities(profile, false);
for (const operation of IDA_OPERATIONS) {
const capability = capabilities.find(
(candidate) => candidate.operation === operation,
);
const reason = idaOperationUnavailableReason(operation, profile);
if (capability === undefined) {
expect(operation).toBe("resolve_containing_procedure");
expect(profile.mode).toBe("attached");
expect(reason).toBeDefined();
} else {
expect(capability.available).toBe(reason === undefined);
expect(capability.reason).toBe(reason ?? null);
}
}
// No supported profile proves direct call edges.
expect(
idaOperationUnavailableReason("procedure_callers", profile),
).toBeDefined();
expect(
idaOperationUnavailableReason("procedure_callees", profile),
).toBeUndefined();
});
}
});
+11 -32
View File
@@ -1,35 +1,14 @@
import { expect, it } from "vitest";
import {
externalJvmExhaustionRecovery,
RUNTIME_EXHAUSTION_AREAS,
type ExternalJvm,
} from "./RuntimeExhaustion.js";
import { externalJvmExhaustionRecovery } from "./RuntimeExhaustion.js";
const jvm: ExternalJvm = {
program: "Fixture's",
role: "engine",
raise: (option) => `Raise the ${option}`,
settings: "the fixture's JVM memory settings",
threads: "Reduce concurrent fixture work",
smaller: "select a smaller input",
};
it.each([
["heap", /Raise the maximum heap \(-Xmx\)/u],
["gc-overhead", /raise the maximum heap \(-Xmx\)/u],
["metaspace", /-XX:MaxMetaspaceSize; a larger heap \(-Xmx\) does not raise/u],
["array-size", /a larger heap \(-Xmx\) does not lift this limit/u],
["native-thread", /a larger heap \(-Xmx\) does not help/u],
[undefined, /Review the reported out-of-memory line/u],
] as const)("names the JVM option that governs a %s report", (area, advice) => {
expect(externalJvmExhaustionRecovery(area, jvm)).toMatch(advice);
});
it("advises only the heap for the areas the heap governs", () => {
for (const area of RUNTIME_EXHAUSTION_AREAS) {
const recovery = externalJvmExhaustionRecovery(area, jvm);
expect(/raise the maximum heap/iu.test(recovery)).toBe(
area === "heap" || area === "gc-overhead",
);
}
it("recommends increasing the heap for a JVM GC overhead report", () => {
const recovery = externalJvmExhaustionRecovery("gc-overhead", {
program: "Fixture's",
role: "engine",
raise: (option) => `Raise the ${option}`,
settings: "the fixture's JVM memory settings",
threads: "Reduce concurrent fixture work",
smaller: "select a smaller input",
});
expect(recovery).toMatch(/raise[^.]*-Xmx/iu);
});
+9 -39
View File
@@ -15,19 +15,7 @@ const options = () => ({
cwd: "C:\\project",
});
it("looks up an explicitly named extension without appending PATHEXT again", async () => {
lookup.stat.mockResolvedValue({ isFile: () => true });
expect(
await findWindowsExecutable(
"npm.cmd",
{ PATH: "C:\\tools", PATHEXT: ".EXE;.CMD" },
{ ...options(), allowBatch: true },
),
).toEqual({ ok: true, value: "C:\\tools\\npm.cmd" });
expect(lookup.stat).toHaveBeenCalledExactlyOnceWith("C:\\tools\\npm.cmd");
});
it("uses native PATH extensions for ADB, preserving directory and extension precedence", async () => {
it("selects an executable in the earlier PATH entry even when another extension ranks first", async () => {
lookup.stat.mockImplementation(async (path: string) => ({
isFile: () => ["C:\\tools\\adb.EXE", "D:\\tools\\adb.COM"].includes(path),
}));
@@ -38,24 +26,6 @@ it("uses native PATH extensions for ADB, preserving directory and extension prec
options(),
),
).toEqual({ ok: true, value: "C:\\tools\\adb.EXE" });
expect(lookup.stat.mock.calls.map(([path]) => path)).toEqual([
"C:\\tools\\adb.COM",
"C:\\tools\\adb.EXE",
]);
});
it("preserves explicitly selected relative directories and quoted semicolons", async () => {
lookup.stat.mockImplementation(async (path: string) => ({
isFile: () => path === "C:\\project\\tools;selected\\npm.CMD",
}));
expect(
await findWindowsExecutable(
"npm",
{ PATH: ';"";".\\tools;selected";.', PATHEXT: ".CMD" },
{ ...options(), allowBatch: true },
),
).toEqual({ ok: true, value: "C:\\project\\tools;selected\\npm.CMD" });
expect(lookup.stat).toHaveBeenCalledTimes(1);
});
it.each([
@@ -76,7 +46,9 @@ it.each([
it("retains the failed candidate and cause rather than selecting a later executable", async () => {
const cause = Object.assign(new Error("denied"), { code: "EACCES" });
lookup.stat.mockRejectedValue(cause);
lookup.stat
.mockRejectedValueOnce(cause)
.mockResolvedValue({ isFile: () => true });
expect(
await findWindowsExecutable(
"adb",
@@ -92,7 +64,6 @@ it("retains the failed candidate and cause rather than selecting a later executa
cause,
},
});
expect(lookup.stat).toHaveBeenCalledTimes(1);
});
it("stops a pending filesystem lookup when its owner aborts", async () => {
@@ -112,12 +83,15 @@ it("stops a pending filesystem lookup when its owner aborts", async () => {
controller.abort();
expect(await pending).toEqual({ ok: false, error: { kind: "interrupted" } });
complete({ isFile: () => true });
expect(lookup.stat).toHaveBeenCalledTimes(1);
});
it("resolves a path-qualified command at its own location with PATHEXT, never on PATH", async () => {
lookup.stat.mockImplementation(async (path: string) => ({
isFile: () => path === "C:\\project\\.venv\\Scripts\\python.EXE",
isFile: () =>
[
"C:\\project\\.venv\\Scripts\\python.EXE",
"C:\\tools\\python.COM",
].includes(path),
}));
expect(
await findWindowsExecutable(
@@ -126,8 +100,4 @@ it("resolves a path-qualified command at its own location with PATHEXT, never on
options(),
),
).toEqual({ ok: true, value: "C:\\project\\.venv\\Scripts\\python.EXE" });
expect(lookup.stat.mock.calls.map(([path]) => path)).toEqual([
"C:\\project\\.venv\\Scripts\\python.COM",
"C:\\project\\.venv\\Scripts\\python.EXE",
]);
});
+7 -22
View File
@@ -5,8 +5,8 @@ import {
snapshotEnvironment,
} from "./snapshotEnvironment.js";
it.each(["win32", "linux", "darwin"] as const)(
"merges explicit environment layers using %s key identity before sorting",
it.each(["win32", "linux"] as const)(
"merges explicit environment layers using %s key identity",
(platform) => {
const existing = {
rea_analysis_provider: "hopper",
@@ -29,26 +29,11 @@ it.each(["win32", "linux", "darwin"] as const)(
},
);
it.each(["linux", "darwin"] as const)(
"preserves case-sensitive %s variables in an immutable snapshot",
(platform) => {
const selected = { PATH: "/chosen/bin", Path: "/other/bin" };
const snapshot = snapshotEnvironment(selected, platform);
selected.PATH = "/later/bin";
expect(snapshot).toEqual({ PATH: "/chosen/bin", Path: "/other/bin" });
expect(Object.isFrozen(snapshot)).toBe(true);
},
);
it("canonicalizes selected Windows variables without inheriting ambient values", () => {
const snapshot = snapshotEnvironment(
{ Path: "C:\\selected", ComSpec: "C:\\selected\\cmd.exe" },
"win32",
);
expect(snapshot).toEqual({
PATH: "C:\\selected",
COMSPEC: "C:\\selected\\cmd.exe",
});
it("preserves case-sensitive POSIX variables in an immutable snapshot", () => {
const selected = { PATH: "/chosen/bin", Path: "/other/bin" };
const snapshot = snapshotEnvironment(selected, "linux");
selected.PATH = "/later/bin";
expect(snapshot).toEqual({ PATH: "/chosen/bin", Path: "/other/bin" });
expect(Object.isFrozen(snapshot)).toBe(true);
});
@@ -18,14 +18,6 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
import { createMcpSchemaValidation } from "../../fixtures/mcpSchemaValidation.js";
cliTest("rejects the removed compare-bundles command", async ({ cli }) => {
const result = await cli.run({
arguments: ["compare-bundles", "left.json", "right.json", "--json"],
});
expect(result.exitCode).toBe(1);
expect(result.stdout).toContain("COMMAND_NOT_FOUND");
});
cliTest(
"compares Evidence bundles without unexplained display-only changes",
async ({ cli }) => {
@@ -15,8 +15,6 @@ import { reconstructionObligationLedgerSchema } from "../../../src/domain/recons
import { createEvidence, parseEvidence } from "../../../src/domain/evidence.js";
import { createEvidenceBundle } from "../../../src/domain/evidenceBundle.js";
import {
MIXED_AUTHORITY_SUMMARY,
mixedAuthorityRequest,
readyProcessLedgerRequest,
readyReviewedLedgerRequest,
} from "../../../src/application/ReconstructionObligationLedger.fixture.js";
@@ -110,7 +108,13 @@ describe("reconstruction obligation ledger CLI bundle validation", () => {
{ cwd: process.cwd(), env: process.env, maxBuffer: 16 * 1_024 * 1_024 },
);
expect(JSON.parse(accepted.stdout)).toMatchObject({
normalized_result: { status: "unknown", summary: { total: 0 } },
operation: "build_reconstruction_obligation_ledger",
predicate_type: "rea.reconstruction-obligation-ledger",
normalized_result: {
schema: "ReconstructionObligationLedger",
status: "unknown",
summary: { total: 0 },
},
});
input.evidence_bundle = {
...canonical,
@@ -149,80 +153,6 @@ describe("reconstruction obligation ledger CLI bundle validation", () => {
},
});
});
it("builds the same Evidence-backed empty ledger through the CLI", async () => {
const input = {
evidence_bundle: createEvidenceBundle([]),
reviewed_obligations: [],
manifest: {
bindings: [],
contradictions: [],
},
};
const { stdout } = await execute(
process.execPath,
[
"scripts/rea.mjs",
"build-reconstruction-obligation-ledger",
JSON.stringify(input),
"--json",
],
{
cwd: process.cwd(),
env: process.env,
maxBuffer: 16 * 1_024 * 1_024,
},
);
expect(JSON.parse(stdout)).toMatchObject({
operation: "build_reconstruction_obligation_ledger",
predicate_type: "rea.reconstruction-obligation-ledger",
normalized_result: {
schema: "ReconstructionObligationLedger",
status: "unknown",
summary: { total: 0 },
},
});
});
it("summarizes obligations by their cited Evidence authorities", async () => {
const { stdout } = await execute(
process.execPath,
[
"scripts/rea.mjs",
"build-reconstruction-obligation-ledger",
JSON.stringify(mixedAuthorityRequest()),
"--json",
],
{ cwd: process.cwd(), env: process.env, maxBuffer: 16 * 1_024 * 1_024 },
);
const ledger = JSON.parse(stdout).normalized_result;
expect(ledger.summary).toMatchObject(MIXED_AUTHORITY_SUMMARY);
expect(
ledger.obligations.map(
(obligation: {
readonly obligation_id: string;
readonly authority_references: readonly {
readonly authority: string;
readonly state: string;
}[];
}) => [
obligation.obligation_id,
obligation.authority_references.map(
({ authority, state }) => `${authority}/${state}`,
),
],
),
).toEqual([
[
"review.mixed",
expect.arrayContaining([
"shipped-artifact/candidate",
"controlled-replay/reviewed",
]),
],
["review.shipped", ["shipped-artifact/candidate"]],
]);
});
});
describe("reconstruction obligation ledger CLI contradictions", () => {
-27
View File
@@ -1,27 +0,0 @@
import { readdir } from "node:fs/promises";
import { describe, expect } from "vitest";
import { workspaceCliTest } from "../../support/cli/workspaceCliFixture.js";
describe("CLI skill lifecycle boundary", () => {
workspaceCliTest(
"does not expose the unmanaged Incur skill generator",
async ({ cli, workspace }) => {
const help = await cli.run({
arguments: ["--help"],
environment: workspace.environment,
});
expect(help).toMatchObject({ exitCode: 0 });
expect(help.stdout).not.toMatch(/^\s+skills\b/mu);
const result = await cli.run({
arguments: ["skills", "add"],
environment: workspace.environment,
});
expect(result.exitCode).toBe(1);
expect(result.stdout).toContain("COMMAND_NOT_FOUND");
await expect(readdir(workspace.home)).resolves.toEqual([]);
},
);
});
@@ -296,29 +296,7 @@ describe("reconstruction obligation ledger MCP parity", () => {
),
);
const canonical = createEvidenceBundle(records);
const session = createTestBinarySession(() => ({
execute: () => Promise.resolve(observed(null)),
close: () => Promise.resolve(resultOk(null)),
}));
const server = createServer({ kind: "session", session });
const client = new Client(
{ name: "obligation-ledger-test", version: "1" },
{ jsonSchemaValidator: createMcpSchemaValidation() },
);
const [clientTransport, serverTransport] =
InMemoryTransport.createLinkedPair();
try {
await server.connect(serverTransport);
await client.connect(clientTransport);
const request = (evidenceBundle: unknown) =>
client.callTool({
name: "build_reconstruction_obligation_ledger",
arguments: {
evidence_bundle: evidenceBundle,
reviewed_obligations: [],
manifest: { bindings: [], contradictions: [] },
},
});
await withLedgerClient(async (request) => {
const valid = await request(canonical);
expect(valid.isError).not.toBe(true);
expect(valid.structuredContent).toMatchObject({
@@ -332,11 +310,7 @@ describe("reconstruction obligation ledger MCP parity", () => {
expect(parseMcpToolError(result)).toMatchObject(
integrityError("Evidence bundle sections are not canonical: records"),
);
} finally {
await client.close();
await server.close();
await session.close();
}
});
});
it("distinguishes corrupt source bundles from missing caller-selected review references", async () => {
@@ -384,38 +358,31 @@ describe("reconstruction obligation ledger MCP parity", () => {
input.reviewed_obligations,
);
expect(result.isError).not.toBe(true);
expect(result.structuredContent).toMatchObject({
normalized_result: { summary: MIXED_AUTHORITY_SUMMARY },
const ledger = reconstructionObligationLedgerSchema.parse(
evidenceSchema.parse(result.structuredContent).normalized_result,
);
expect(ledger.summary).toMatchObject(MIXED_AUTHORITY_SUMMARY);
const authorities = Object.fromEntries(
ledger.obligations.map(({ obligation_id, authority_references }) => [
obligation_id,
authority_references.map(
({ authority, state }) => `${authority}/${state}`,
),
]),
);
expect(authorities).toEqual({
"review.mixed": expect.arrayContaining([
"shipped-artifact/candidate",
"controlled-replay/reviewed",
]),
"review.shipped": ["shipped-artifact/candidate"],
});
});
});
it("returns the complete Evidence-backed ledger inline", async () => {
const session = createTestBinarySession(() => ({
execute: () => Promise.resolve(observed(null)),
close: () => Promise.resolve(resultOk(null)),
}));
const server = createServer({ kind: "session", session });
const client = new Client(
{ name: "obligation-ledger-test", version: "1" },
{ jsonSchemaValidator: createMcpSchemaValidation() },
);
const [clientTransport, serverTransport] =
InMemoryTransport.createLinkedPair();
try {
await server.connect(serverTransport);
await client.connect(clientTransport);
const result = await client.callTool({
name: "build_reconstruction_obligation_ledger",
arguments: {
evidence_bundle: createEvidenceBundle([]),
reviewed_obligations: [],
manifest: {
bindings: [],
contradictions: [],
},
},
});
await withLedgerClient(async (request) => {
const result = await request(createEvidenceBundle([]));
expect(result.isError).not.toBe(true);
expect(result.structuredContent).toMatchObject({
evidence_id: expect.stringMatching(/^ev_[a-f0-9]{64}$/u),
@@ -425,11 +392,7 @@ describe("reconstruction obligation ledger MCP parity", () => {
summary: { total: 0 },
},
});
} finally {
await client.close();
await server.close();
await session.close();
}
});
});
});
@@ -11,9 +11,15 @@ processTest(
async ({ processes }) => {
const root = await createTestTempDirectory("rea-npm-invocation-");
const npmEntry = join(root, "selected npm entry.mjs");
const arguments_ = [
"pack",
"value with spaces",
"--literal=$HOME",
"quote'and\"double",
];
await writeFile(
npmEntry,
`process.stdout.write(JSON.stringify({ arguments: process.argv.slice(2), cwd: process.cwd(), marker: process.env.REA_NPM_TEST_MARKER }));\n`,
`process.stdout.write(JSON.stringify({ arguments: process.argv.slice(2), cwd: process.cwd(), marker: process.env.REA_NPM_TEST_MARKER, ambient: process.env.REA_NPM_TEST_AMBIENT ?? null }));\n`,
);
const helper = pathToFileURL(
resolve("scripts/lib/verify-package-commands.mjs"),
@@ -27,10 +33,15 @@ processTest(
const commands = await createPackageVerifierCommands({
workspace: { path: ${JSON.stringify(root)}, close: async () => {} },
});
process.env.REA_NPM_TEST_AMBIENT = "ambient-only";
const result = await withVerifierCleanup(
() => commands.execNpm(["pack", "value with spaces"], {
() => commands.execNpm(${JSON.stringify(arguments_)}, {
cwd: ${JSON.stringify(root)},
env: { ...process.env, npm_execpath: ${JSON.stringify(npmEntry)}, REA_NPM_TEST_MARKER: "caller-selected" },
env: {
...(process.platform === "win32" ? { SystemRoot: process.env.SystemRoot } : {}),
npm_execpath: ${JSON.stringify(npmEntry)},
REA_NPM_TEST_MARKER: "caller-selected",
},
}),
[() => commands.close()],
);
@@ -44,9 +55,10 @@ processTest(
expect(result.exitCode, result.stderr).toBe(0);
expect(result.signal, result.stderr).toBeNull();
expect(JSON.parse(result.stdout)).toEqual({
arguments: ["pack", "value with spaces"],
arguments: arguments_,
cwd: root,
marker: "caller-selected",
ambient: null,
});
},
);
@@ -170,60 +170,6 @@ it.skipIf(process.platform === "win32")(
},
);
it("uses the exact selected environment and npm entry without rewriting arguments", async () => {
const fixture = await commandFixture();
const entry = join(fixture.parent, "selected npm entry.mjs");
const sentinel = "REA_PACKAGE_COMMAND_AMBIENT_SENTINEL";
const previous = process.env[sentinel];
const source = `process.stdout.write(JSON.stringify({ args: process.argv.slice(2), cwd: process.cwd(), selected: process.env.REA_PACKAGE_COMMAND_SELECTED, ambient: process.env.${sentinel} ?? null }));`;
await writeFile(entry, source);
const arguments_ = [
"pack",
"value with spaces",
"--literal=$HOME",
"quote'and\"double",
];
const environment = {
...(process.platform === "win32"
? { SystemRoot: process.env.SystemRoot }
: {}),
REA_PACKAGE_COMMAND_SELECTED: "caller-selected",
npm_execpath: entry,
};
let direct;
let npm;
process.env[sentinel] = "ambient-only";
try {
direct = await fixture.commands.exec(process.execPath, ["-e", source], {
cwd: fixture.workspace.path,
env: environment,
});
npm = await fixture.commands.execNpm(arguments_, {
cwd: fixture.workspace.path,
env: environment,
});
} finally {
if (previous === undefined) delete process.env[sentinel];
else process.env[sentinel] = previous;
await fixture.commands.close();
}
expect(JSON.parse(direct!.stdout)).toEqual({
args: [],
cwd: fixture.workspace.path,
selected: "caller-selected",
ambient: null,
});
expect(JSON.parse(npm!.stdout)).toEqual({
args: arguments_,
cwd: fixture.workspace.path,
selected: "caller-selected",
ambient: null,
});
expect(direct?.stderr).toBe("");
expect(npm?.stderr).toBe("");
});
it("allows delayed commands with omitted and explicit zero timeouts", async () => {
const fixture = await commandFixture();
const outputs = [];
@@ -278,7 +224,7 @@ setTimeout(() => process.exit(0), 10000);
const running = observed(
fixture.commands.exec(process.execPath, ["-e", source]),
);
let sameClose = false;
let workspaceExistsAtCompletion;
let outcome;
try {
await waitForMarker(ready);
@@ -287,14 +233,18 @@ setTimeout(() => process.exit(0), 10000);
.parse(JSON.parse(await readFile(ready, "utf8"))));
const first = fixture.commands.close();
const second = fixture.commands.close();
sameClose = first === second;
await Promise.all([first, second]);
workspaceExistsAtCompletion = await Promise.all(
[first, second].map(async (closing) => {
await closing;
return existsSync(fixture.workspace.path);
}),
);
outcome = await running;
} finally {
await fixture.commands.close();
await running;
}
expect(sameClose).toBe(true);
expect(workspaceExistsAtCompletion).toEqual([false, false]);
expect(outcome).toEqual({
ok: false,
cause: expect.objectContaining({ reason: "cancelled" }),
@@ -556,9 +556,8 @@ it.skipIf(process.platform === "win32")(
),
);
let outcome;
let sameClose = false;
let closeSettled = false;
let settledBeforeLaunchRelease = false;
let settledCloses = 0;
let settledBeforeLaunchRelease;
try {
await Promise.race([
entered.promise,
@@ -568,17 +567,13 @@ it.skipIf(process.platform === "win32")(
]);
const first = commands.close();
const second = commands.close();
sameClose = first === second;
void first.then(
() => {
closeSettled = true;
},
() => {
closeSettled = true;
},
);
const settled = () => {
settledCloses += 1;
};
for (const closing of [first, second])
void closing.then(settled, settled);
await cancelled.promise;
settledBeforeLaunchRelease = closeSettled;
settledBeforeLaunchRelease = settledCloses;
release.resolve();
await Promise.all([first, second]);
outcome = await running;
@@ -588,8 +583,7 @@ it.skipIf(process.platform === "win32")(
await running;
}
expect(sameClose).toBe(true);
expect(settledBeforeLaunchRelease).toBe(false);
expect(settledBeforeLaunchRelease).toBe(0);
expect(outcome).toEqual({
ok: false,
cause: expect.objectContaining({ reason: "cancelled", snapshot: null }),
@@ -2,6 +2,8 @@ import { afterEach, expect, it } from "vitest";
import { z } from "zod";
import { EnhancedTools } from "../../../../src/application/EnhancedTools.js";
import { UNCLASSIFIED_CALL_SITE_LIMITATION } from "../../../../src/ida/IdaCallGraph.js";
import { IDA_COMPATIBILITY_PROFILES } from "../../../../src/ida/IdaConfiguration.js";
import { idaCapabilities } from "../../../../src/ida/IdaProviderCapabilities.js";
import {
callGraphSession,
edge,
@@ -29,9 +31,30 @@ const armSession = () =>
leafRoots: ["0x2000", "0x3000"],
});
it("keeps unknown caller coverage and callee diagnostics in an ARM64 dossier", async () => {
it("refuses direct callers and keeps caller coverage unknown in an ARM64 dossier", async () => {
const { client } = await armSession();
try {
const declared = idaCapabilities(IDA_COMPATIBILITY_PROFILES.modern, false);
const callers = declared.find(
({ operation }) => operation === "procedure_callers",
);
expect(callers).toMatchObject({
available: false,
reason: expect.any(String),
});
expect(
declared.find(({ operation }) => operation === "procedure_callees"),
).toMatchObject({ available: true });
expect(
await client.execute("procedure_callers", { procedure: "main" }),
).toMatchObject({
ok: false,
error: {
_tag: "AnalysisCapabilityUnavailableError",
operation: "procedure_callers",
reason: callers?.reason,
},
});
const result = await client.execute("analyze_function", {
procedure: "main",
});
@@ -1,76 +1,20 @@
import { readFile } from "node:fs/promises";
import { resolve } from "node:path";
import { describe, expect, it } from "vitest";
import { expect, it } from "vitest";
import { TOOL_CONTRACTS } from "../../../src/contracts/toolContracts.js";
import { TARGET_CONTENT_FREE_TOOLS } from "../../../src/contracts/toolEffects.js";
describe("target-content provenance audit", () => {
it("marks every tool except the audited content-free exceptions", () => {
const names = new Set<string>(TOOL_CONTRACTS.map(({ name }) => name));
expect(
[...TARGET_CONTENT_FREE_TOOLS].filter((name) => !names.has(name)),
).toEqual([]);
for (const contract of TOOL_CONTRACTS)
expect({
name: contract.name,
returnsTargetContent: contract.returnsTargetContent,
}).toEqual({
name: contract.name,
returnsTargetContent: !TARGET_CONTENT_FREE_TOOLS.has(contract.name),
});
expect([...TARGET_CONTENT_FREE_TOOLS].sort()).toEqual([
"export_evidence_bundle",
"guided_workflows",
"inspect_analysis_settings",
"read_guidance_section",
"record_unknown",
"search_guidance",
"update_analysis_settings",
]);
});
it("documents exactly the audited content-free exceptions", async () => {
const guide = await readFile(
resolve("docs/reference/mcp-contracts.md"),
"utf8",
);
const exceptions = /on by default: ([^.]*?) omit it\./su.exec(guide)?.[1];
expect(exceptions).toBeDefined();
expect(
[...(exceptions ?? "").matchAll(/`([a-z_]+)`/gu)]
.map(([, name]) => name)
.sort(),
).toEqual([...TARGET_CONTENT_FREE_TOOLS].sort());
});
it.each([
"procedure_pseudo_code",
"list_strings",
"search_strings",
"batch_decompile",
"inspect_web_page",
"analyze_web_bundle",
"export_web_scripts",
"inspect_web_network_capture",
"read_adb_logcat",
"list_adb_directory",
"decompile_jeb_item",
"inspect_artifact",
"analyze_javascript_application",
"capture_process_scenario",
"get_evidence_bundle",
"inspect_analysis_view",
"binary_session",
"close_binary",
"inspect_adb_client",
"inspect_apktool_client",
"update_unknown",
])("marks %s as returning target content", (name) => {
expect(
TOOL_CONTRACTS.find((contract) => contract.name === name)
?.returnsTargetContent,
).toBe(true);
});
it("marks every tool except the audited content-free exceptions", () => {
const contentFree = TOOL_CONTRACTS.filter(
({ returnsTargetContent }) => returnsTargetContent !== true,
)
.map(({ name }) => name)
.sort();
expect(contentFree).toEqual([
"export_evidence_bundle",
"guided_workflows",
"inspect_analysis_settings",
"read_guidance_section",
"record_unknown",
"search_guidance",
"update_analysis_settings",
]);
});
+28 -24
View File
@@ -1,10 +1,11 @@
import { parse } from "@babel/parser";
import * as t from "@babel/types";
import { readFile, readdir } from "node:fs/promises";
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
import { dirname, join, relative, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { expect, it } from "vitest";
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
import {
importSpecifier,
readImportSpecifiers,
@@ -40,7 +41,7 @@ const exportedValues = (tree: ReturnType<typeof syntax>) => {
return names;
};
/** Derive migrated metadata symbols from their current source owners. */
/** Derive metadata symbols from their source owners. */
const metadataSymbols = async () => {
const pending = [resolve(root, "src/composition/capabilityDeclarations.ts")];
const seen = new Set<string>();
@@ -165,6 +166,7 @@ const scriptsBelow = async (directory: string): Promise<string[]> => {
};
const linkFailures = async (
repository: string,
file: string,
source: string,
symbols: ReadonlySet<string>,
@@ -174,25 +176,25 @@ const linkFailures = async (
for (const { name, reference, line } of links) {
if (reference === undefined) {
failures.push(
`${relative(root, file)}:${line}: unresolved ${name} import`,
`${relative(repository, file)}:${line}: unresolved ${name} import`,
);
continue;
}
const target = reference.startsWith("file:")
? fileURLToPath(reference)
: reference.startsWith("dist/")
? resolve(root, reference)
? resolve(repository, reference)
: resolve(dirname(file), reference);
const compiled = relative(root, target).replaceAll("\\", "/");
const compiled = relative(repository, target).replaceAll("\\", "/");
if (!compiled.startsWith("dist/")) continue;
const sourcePath = resolve(
root,
repository,
compiled.replace(/^dist\//u, "src/"),
).replace(/\.js$/u, ".ts");
const exports = exportedValues(syntax(await readFile(sourcePath, "utf8")));
if (!exports.has(name))
failures.push(
`${relative(root, file)}:${line}: ${compiled} has no ${name} export`,
`${relative(repository, file)}:${line}: ${compiled} has no ${name} export`,
);
}
return { failures, checked: links.length };
@@ -208,6 +210,7 @@ it("links verifier metadata exports through static, namespace and packaged dynam
let checked = 0;
for (const file of files) {
const result = await linkFailures(
root,
file,
await readFile(file, "utf8"),
symbols,
@@ -220,20 +223,21 @@ it("links verifier metadata exports through static, namespace and packaged dynam
});
it.each([
'import { HOPPER_PROVIDER_IDENTITY } from "../dist/hopper/HopperProviderCapabilities.js";',
'const { GHIDRA_OPERATIONS } = await import(pathToFileURL(join(packageRoot, "dist/ghidra/GhidraProviderCapabilities.js")));',
'const metadata = await import("../dist/ghidra/GhidraProviderCapabilities.js"); metadata.GHIDRA_OPERATIONS;',
])(
"detects a metadata consumer whose old owner no longer exports its requirement: %s",
async (source) => {
const result = await linkFailures(
resolve(root, "scripts/authored-negative-control.mjs"),
source,
await metadataSymbols(),
);
expect(result.failures).toHaveLength(1);
expect(result.failures[0]).toMatch(
/ has no (?:HOPPER_PROVIDER_IDENTITY|GHIDRA_OPERATIONS) export$/u,
);
},
);
'import { REQUIRED_METADATA } from "../dist/metadata.js";',
'const { REQUIRED_METADATA } = await import(pathToFileURL(join(packageRoot, "dist/metadata.js")));',
'const metadata = await import("../dist/metadata.js"); metadata.REQUIRED_METADATA;',
])("detects a missing metadata export referenced by %s", async (source) => {
const repository = await createTestTempDirectory("rea-verifier-metadata-");
await mkdir(join(repository, "src"));
const target = join(repository, "src", "metadata.ts");
const verifier = join(repository, "scripts", "fixture.mjs");
const symbols = new Set(["REQUIRED_METADATA"]);
await writeFile(target, "export const OTHER_METADATA = 1;\n");
const broken = await linkFailures(repository, verifier, source, symbols);
expect(broken.failures).toEqual([
expect.stringContaining("dist/metadata.js has no REQUIRED_METADATA export"),
]);
await writeFile(target, "export const REQUIRED_METADATA = 1;\n");
const linked = await linkFailures(repository, verifier, source, symbols);
expect(linked.failures).toEqual([]);
});
@@ -1,8 +1,6 @@
import { expect, it } from "vitest";
import { Ajv2020 } from "ajv/dist/2020.js";
import { geminiUnsupportedLiteral } from "../../../scripts/lib/gemini-schema-literals.mjs";
import { clientSchemaPositions } from "../../../scripts/lib/client-schema-positions.mjs";
import { unsupportedInputLiteralSchemaError } from "../../fixtures/mcpClientSchemaConstraints.js";
it("checks an explicitly referenced example as a schema while leaving unreferenced examples opaque", () => {
const literal = { examples: [{ const: false }] };
@@ -18,9 +16,6 @@ it("checks an explicitly referenced example as a schema while leaving unreferenc
keyword: "const",
reason: "boolean",
});
expect(unsupportedInputLiteralSchemaError(schema, "tool")).toBe(
"tool.examples[0].const is boolean",
);
});
it("preserves the inline schema keyword encounter order used by the native Gemini verifier", () => {
@@ -30,9 +25,6 @@ it("preserves the inline schema keyword encounter order used by the native Gemin
keyword: "enum",
reason: "empty-string",
});
expect(unsupportedInputLiteralSchemaError(schema, "tool")).toBe(
"tool.properties.early.enum contains an empty string",
);
});
it("resolves nested local references against their own resource while retaining root-relative diagnostic locations", () => {
@@ -52,9 +44,6 @@ it("resolves nested local references against their own resource while retaining
keyword: "enum",
reason: "empty-string",
});
expect(unsupportedInputLiteralSchemaError(schema, "tool")).toBe(
"tool.$defs.child.default.enum contains an empty string",
);
});
it("terminates reference cycles and reports the first newly reached constraint at its source path", () => {
@@ -70,11 +59,6 @@ it("terminates reference cycles and reports the first newly reached constraint a
keyword: "const",
reason: "empty-string",
});
expect(
[...clientSchemaPositions(schema)].filter(
(position) => position.kind === "schema",
),
).toHaveLength(4);
});
it("uses decoded reference tokens and preserves the existing spelling of property names in diagnostic paths", () => {
@@ -111,12 +95,10 @@ it("leaves external, dynamic, anchor and ambiguous resource references unknown",
).toBeUndefined();
});
it("keeps literal-policy diagnostic prose for const and enum failures", () => {
for (const [schema, message] of [
[{ const: false }, "tool.const is boolean"],
[{ const: "" }, "tool.const is an empty string"],
[{ enum: [false, ""] }, "tool.enum contains a boolean"],
[{ enum: [""] }, "tool.enum contains an empty string"],
] as const)
expect(unsupportedInputLiteralSchemaError(schema, "tool")).toBe(message);
it("reports a boolean enum value when the enum also contains an empty string", () => {
expect(geminiUnsupportedLiteral({ enum: [false, ""] })).toEqual({
path: "$.enum",
keyword: "enum",
reason: "boolean",
});
});
@@ -665,17 +665,8 @@ describe("update subprocess boundaries", () => {
});
expect(help.exitCode, help.stderr).toBe(0);
expect(help.stdout).toMatch(/^\s{2}update\s/mu);
expect(help.stdout).not.toMatch(/^\s{2}upgrade\s/mu);
});
cliTest("rejects the removed upgrade CLI command", async ({ cli }) => {
const removed = await cli.run({
arguments: ["upgrade", "--json"],
environment: process.env,
});
expect(removed.exitCode, removed.stderr).toBe(1);
expect(removed.json).toMatchObject({ code: "COMMAND_NOT_FOUND" });
});
it("captures output through stream closure and keeps arguments literal", async () => {
const literal = 'space and $(echo bad); & | "quotes"';
const result = await updateCommands.runProbe(