refactor!: simplify runtime tools and remove replay engines (#572)

* fix(hopper): report unavailable procedure body coverage

* refactor!: simplify runtime tools and remove replay engines

Keep direct inspection, capture, and comparison tools. Bind handlers to named contracts and let agents compose experiments with commands and local fixture servers.

BREAKING CHANGE: Remove controlled replay, Node characterization, finite replay-machine, managed runtime planning, and redundant string-tracing tools. Retire process replay, shims, reactive scenarios, custom checkpoints, and active browser replay and origin-scope inputs.
This commit is contained in:
morluto
2026-10-05 21:15:04 +08:00
committed by GitHub
parent c6d3bdf597
commit e07b81649e
258 changed files with 1193 additions and 22444 deletions
@@ -64,11 +64,9 @@ describe("JavaScript export return-shape comparison", () => {
unpaired_left_variants: 0,
unpaired_right_variants: 0,
});
expect(first.runtime_validation).toEqual({
recommended_tool: "run_controlled_replay",
automatically_started: false,
required_for: "runtime-semantics",
});
expect(first.limitations).toContain(
"This static comparison cannot establish runtime semantics; run behavioral probes directly against the relevant application versions when that evidence is required.",
);
});
it("keeps additions unknown when spread coverage is incomplete", async () => {
@@ -1,178 +0,0 @@
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { planManagedRuntimeCorrelationEvidence } from "../../../src/application/ManagedRuntimeCorrelationService.js";
import { MANAGED_STATIC_PROVIDER } from "../../../src/application/InvestigationProviders.js";
import { createEvidence } from "../../../src/domain/evidence.js";
import {
managedRuntimeCorrelationInputSchema,
managedRuntimeCorrelationResultSchema,
} from "../../../src/domain/managedRuntimeCorrelation.js";
import { inspectManagedMembersBytes } from "../../../src/dotnet/ManagedMemberInspector.js";
import {
buildManagedPeFixture,
managedPeFixtureTarget,
} from "../../../src/dotnet/ManagedPe.fixture.js";
describe("managed runtime correlation planning", () => {
it("records an exact-build non-executing plan without REA permission grants", async () => {
const directory = await createTestTempDirectory("rea-managed-runtime-");
const artifactPath = join(directory, "fixture.dll");
const executablePath = process.execPath;
const fixture = inspect(buildManagedPeFixture(), artifactPath);
let configurationReads = 0;
const result = await planManagedRuntimeCorrelationEvidence(
{
configuration: () => {
configurationReads += 1;
return { executablePath };
},
},
{
...inputFor(fixture.evidence, fixture.method),
bounds: {
timeout_ms: 5_000,
max_threads: 32,
max_output_bytes: 65_536,
allow_network: true,
allow_ui: true,
},
},
);
expect(configurationReads).toBe(1);
expect(result.ok).toBe(true);
if (!result.ok) return;
expect(result.value.operation).toBe("plan_managed_runtime_correlation");
expect(result.value.confidence).toBe("derived");
expect(result.value.authority).toBe("analyst-inference");
const plan = managedRuntimeCorrelationResultSchema.parse(
result.value.normalized_result,
);
expect(
managedRuntimeCorrelationInputSchema.safeParse({
...inputFor(fixture.evidence, fixture.method),
bounds: {
timeout_ms: 60_001,
max_threads: 257,
max_output_bytes: 1_048_577,
allow_network: true,
allow_ui: true,
},
}).success,
).toBe(true);
expect(
managedRuntimeCorrelationResultSchema.safeParse({
...plan,
limitations: Array.from({ length: 1_001 }, () => "x".repeat(4_097)),
}).success,
).toBe(true);
expect(plan).toMatchObject({
executed: false,
method_lock: {
token: "0x06000001",
exact_build_required: true,
},
requested_runtime: {
effect: "instrumentation",
executable_path: executablePath,
network: "host",
confinement: "not-established",
},
effect_taxonomy: {
instruments_code: true,
invokes_target_code: false,
},
unsupported_until_executor_exists: true,
});
});
it("rejects a method lock that no longer matches static Evidence", async () => {
const directory = await createTestTempDirectory("rea-managed-runtime-");
const artifactPath = join(directory, "fixture.dll");
const executablePath = process.execPath;
const fixture = inspect(buildManagedPeFixture(), artifactPath);
const result = await planManagedRuntimeCorrelationEvidence(
{ configuration: () => ({ executablePath }) },
{
...inputFor(fixture.evidence, fixture.method),
method: {
...inputFor(fixture.evidence, fixture.method).method,
normalized_il_sha256: "0".repeat(64),
},
},
);
expect(result.ok).toBe(false);
if (result.ok) return;
expect(result.error._tag).toBe("AnalysisInputError");
});
it("plans without probing or requiring an installed runtime executable", async () => {
const fixture = inspect(
buildManagedPeFixture(),
"/tmp/managed-runtime.dll",
);
const result = await planManagedRuntimeCorrelationEvidence(
{ configuration: () => ({ executablePath: undefined }) },
inputFor(fixture.evidence, fixture.method),
);
expect(result.ok).toBe(true);
if (!result.ok) return;
const plan = managedRuntimeCorrelationResultSchema.parse(
result.value.normalized_result,
);
expect(plan.executed).toBe(false);
expect(plan.requested_runtime.executable_path).toBe("dotnet");
expect(plan.limitations.join(" ")).toContain(
"prerequisites are unverified",
);
});
});
const inputFor = (
staticMembers: ReturnType<typeof createEvidence>,
method: ReturnType<typeof inspect>["method"],
) => ({
static_members: staticMembers,
method: {
token: method.token,
signature_sha256: method.signature.raw_sha256,
normalized_il_sha256: method.body.normalized_il_sha256,
},
requested_effect: "instrumentation" as const,
host: {
os: "linux" as const,
clr_family: "dotnet" as const,
architecture: "x86_64" as const,
},
bounds: {
timeout_ms: 5_000,
max_threads: 32,
max_output_bytes: 65_536,
allow_network: false as const,
allow_ui: false as const,
},
});
const inspect = (bytes: Buffer, path: string) => {
const target = managedPeFixtureTarget(bytes, path);
const result = inspectManagedMembersBytes(bytes, target);
const method = result.methods[0];
if (method === undefined) throw new Error("fixture has no method");
return {
result,
method,
evidence: createEvidence(target, MANAGED_STATIC_PROVIDER, {
operation: "inspect_managed_members",
parameters: {},
result,
rawResult: null,
limitations: result.limitations,
}),
};
};
@@ -1,282 +0,0 @@
import { createHash } from "node:crypto";
import { readFile, realpath, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import {
executeNodeCharacterization,
prepareNodeCharacterization,
} from "../../../src/application/NodeRuntimeCharacterizationService.js";
import type {
JavaScriptReplayConfiguration,
JavaScriptReplayHost,
JavaScriptReplayRunner,
} from "../../../src/application/JavaScriptReplayPlanning.js";
import {
nodeCharacterizationPreparationInputSchema,
nodeCharacterizationPreparationOutputSchema,
} from "../../../src/domain/nodeRuntimeCharacterization.js";
import { createRuntimeCharacterizationPlan } from "../../../src/domain/runtimeCharacterization.js";
const sha256 = (value: Uint8Array): string =>
createHash("sha256").update(value).digest("hex");
describe("Node runtime characterization", () => {
it("prepares without execution, then requires the exact prepared plan hash", async () => {
const fixture = await createFixture();
let executions = 0;
const dependencies = dependenciesFor(fixture.root, () => {
executions += 1;
});
const input = preparationInput(fixture);
const prepared = await prepareNodeCharacterization(dependencies, input);
expect(prepared.ok).toBe(true);
expect(executions).toBe(0);
if (!prepared.ok) throw prepared.error;
const output = nodeCharacterizationPreparationOutputSchema.parse(
prepared.value,
);
expect(output).toMatchObject({
phase: "preparation",
plan: {
preparation_sha256: expect.stringMatching(/^[a-f0-9]{64}$/u),
runtime: { family: "ecmascript", provider_id: "node-javascript" },
},
transformation: {
original_sha256: fixture.sha256,
output_format: "commonjs-factory",
},
transformation_evidence: {
predicate_type: "rea.javascript-export-transformation",
authority: "shipped-artifact",
},
replay: { phase: "plan" },
});
expect(() =>
nodeCharacterizationPreparationOutputSchema.parse({
...output,
plan: { ...output.plan, expected_effect: "bounded-effects" },
}),
).toThrow();
const stale = await executeNodeCharacterization(dependencies, {
plan_sha256: "0".repeat(64),
preparation: input,
});
expect(stale.ok).toBe(false);
expect(!stale.ok && stale.error._tag).toBe("ReplayPlanStaleError");
expect(executions).toBe(0);
const executed = await executeNodeCharacterization(dependencies, {
plan_sha256: output.plan.plan_sha256,
preparation: input,
});
expect(executed.ok && executed.value).toMatchObject({
phase: "execution",
replay: {
phase: "execute",
evidence: { authority: "controlled-replay" },
},
evidence: {
predicate_type: "rea.runtime-characterization",
authority: "controlled-replay",
},
});
expect(executions).toBe(1);
expect(await readFile(fixture.path)).toEqual(Buffer.from(fixture.bytes));
});
it("maps replay-only alias syntax to a provider-neutral module identity", async () => {
const fixture = await createFixture();
const input = preparationInput(fixture);
const alias = "@scope/pkg";
const prepared = await prepareNodeCharacterization(
dependenciesFor(fixture.root, () => undefined),
{
...input,
selected_alias: alias,
replay: {
...input.replay,
left: {
...input.replay.left,
entry_alias: alias,
modules: input.replay.left.modules.map((module) => ({
...module,
alias,
})),
},
},
},
);
expect(prepared.ok && prepared.value).toMatchObject({
plan: {
callable: {
module_id: expect.stringMatching(/^module\/[a-f0-9]{64}$/u),
},
},
});
});
// Neither the declared call budget nor the alias length has a ceiling. The
// absence of a cap cannot be asserted through the preparation path, because
// the budget is derived from the case count, so reaching a large value end to
// end would mean submitting tens of thousands of cases. Assert it where a
// bound would actually be added, at a value far above any ceiling a change
// would plausibly introduce.
it("admits call budgets and aliases beyond any plausible ceiling", async () => {
const fixture = await createFixture();
const input = preparationInput(fixture);
const alias = "a".repeat(4_096);
const parsed = nodeCharacterizationPreparationInputSchema.parse({
...input,
selected_alias: alias,
replay: {
...input.replay,
left: {
...input.replay.left,
entry_alias: alias,
modules: input.replay.left.modules.map((module) => ({
...module,
alias,
})),
},
},
});
expect(parsed.selected_alias).toBe(alias);
const prepared = await prepareNodeCharacterization(
dependenciesFor(fixture.root, () => undefined),
input,
);
expect(prepared.ok).toBe(true);
if (!prepared.ok) return;
const { plan_sha256: _digest, ...plan } =
nodeCharacterizationPreparationOutputSchema.parse(prepared.value).plan;
expect(
createRuntimeCharacterizationPlan({
...plan,
limits: { ...plan.limits, max_calls: 10_000_001 },
}).limits.max_calls,
).toBe(10_000_001);
});
});
const createFixture = async () => {
const root = await createTestTempDirectory("rea-characterization-");
const path = join(root, "bundle.js");
const source = "const hidden = (value) => value.trim();";
const selected = "(value) => value.trim()";
const bytes = new TextEncoder().encode(source);
await writeFile(path, bytes);
const byteStart = source.indexOf(selected);
return {
root,
path,
bytes,
sha256: sha256(bytes),
byteStart,
selectedBytes: new TextEncoder().encode(selected),
};
};
const preparationInput = (
fixture: Awaited<ReturnType<typeof createFixture>>,
) => ({
selected_alias: "bundle",
expected_effect: "pure" as const,
instrumentation: {
artifact_path: fixture.path,
artifact_sha256: fixture.sha256,
selection: {
byte_start: fixture.byteStart,
byte_end: fixture.byteStart + fixture.selectedBytes.byteLength,
selected_sha256: sha256(fixture.selectedBytes),
export_name: "selected",
},
},
replay: {
mode: "plan" as const,
left: {
modules: [
{
alias: "bundle",
path: fixture.path,
format: "commonjs-factory" as const,
role: "module" as const,
dependencies: {},
},
],
entry_alias: "bundle",
entry_export: "selected",
},
cases: [{ case_id: "trim", arguments: [" value "] }],
},
});
const dependenciesFor = (root: string, onExecute: () => void) => {
const configuration: JavaScriptReplayConfiguration = {
nodePath: process.execPath,
bubblewrapPath: process.execPath,
systemdRunPath: process.execPath,
systemctlPath: process.execPath,
shellPath: process.execPath,
};
const host: JavaScriptReplayHost = {
readSource: async (path, maximumBytes) => {
const canonicalPath = await realpath(path);
const bytes = await readFile(canonicalPath);
if (bytes.byteLength > maximumBytes)
throw new RangeError("fixture limit");
return { canonicalPath, bytes };
},
identifyExecutable: async (path) => ({
path,
version: "fixture-node-24",
sha256: "1".repeat(64),
}),
identifyWorker: async () => ({
path: "/fixture/worker.js",
version: "fixture-worker",
sha256: "2".repeat(64),
}),
identifyRuntimeClosure: async (path) => [
{
sourcePath: path,
destinationPath: "/runtime/node",
sha256: "1".repeat(64),
},
],
seccompDigest: () => "3".repeat(64),
probe: async () => undefined,
};
const runner: JavaScriptReplayRunner = {
execute: async (prepared) => {
onExecute();
return {
plan_digest: prepared.publicPlan.plan_digest,
outcomes: [
{
case_id: "trim",
outcome: "return",
value: "value",
input_sha256:
prepared.publicPlan.cases[0]?.sha256 ?? "0".repeat(64),
output_sha256: "4".repeat(64),
truncated: false,
},
],
stderr: "",
termination: "completed",
cleanup: { state: "complete", residual_resources: [] },
limitations: ["fixture runner"],
reproducer: null,
};
},
};
return { configuration: () => configuration, host, runner };
};
@@ -1,44 +0,0 @@
import { access, readFile } from "node:fs/promises";
import { dirname } from "node:path";
import { describe, expect, it } from "vitest";
import { buildLinuxX64ReplaySeccomp } from "../../../src/replay/LinuxSeccompPolicy.js";
import { temporaryFilterHandle } from "../../../src/replay/ReplaySeccompFile.js";
describe("replay seccomp file ownership", () => {
it("writes the policy bytes and removes its private directory on close", async () => {
const filter = await temporaryFilterHandle();
try {
expect(await readFile(filter.path)).toEqual(
Buffer.from(buildLinuxX64ReplaySeccomp()),
);
expect(await filter.handle.readFile()).toEqual(
Buffer.from(buildLinuxX64ReplaySeccomp()),
);
} finally {
await filter.close();
}
await expect(access(dirname(filter.path))).rejects.toThrow();
await filter.close();
});
it.skipIf(process.platform !== "linux")(
"removes the directory even when descriptor cleanup rejects",
async () => {
const filter = await temporaryFilterHandle();
const close = filter.handle.close.bind(filter.handle);
const failure = new Error("injected descriptor cleanup failure");
filter.handle.close = async () => {
throw failure;
};
try {
await expect(filter.close()).rejects.toBe(failure);
await expect(access(dirname(filter.path))).rejects.toThrow();
} finally {
filter.handle.close = close;
await filter.close();
}
},
);
});
@@ -1,79 +0,0 @@
import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import { prepareReplayPlan } from "../../../src/application/JavaScriptReplayPlanning.js";
import { controlledReplayInputSchema } from "../../../src/domain/javascriptReplay.js";
import { SystemJavaScriptReplayHost } from "../../../src/replay/SystemJavaScriptReplayHost.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
describe("replay source byte admission", () => {
it.each([0, 16, 65_537])("reads exactly %i admitted bytes", async (limit) => {
const root = await createTestTempDirectory("rea-replay-source-");
const path = join(root, "module.mjs");
const bytes = Buffer.alloc(limit, 0x61);
await writeFile(path, bytes);
expect(
await new SystemJavaScriptReplayHost().readSource(path, limit),
).toEqual({
canonicalPath: path,
bytes,
});
});
it("rejects an oversized source and a directory", async () => {
const root = await createTestTempDirectory("rea-replay-source-");
const path = join(root, "module.mjs");
await writeFile(path, "oversized");
const host = new SystemJavaScriptReplayHost();
await expect(host.readSource(path, 1)).rejects.toThrow("declared limit");
await expect(host.readSource(root, 1)).rejects.toThrow();
});
});
it("rejects a host result larger than the remaining module budget", async () => {
const path = process.execPath;
const identity = { path, version: "fixture", sha256: "1".repeat(64) };
const input = controlledReplayInputSchema.parse({
mode: "plan",
left: {
modules: [
{
alias: "entry",
path,
format: "esm",
role: "module",
dependencies: {},
},
],
entry_alias: "entry",
entry_export: "default",
},
cases: [{ case_id: "one", arguments: [] }],
limits: { module_bytes: 16 },
});
await expect(
prepareReplayPlan(
input,
{
nodePath: path,
bubblewrapPath: path,
systemdRunPath: path,
systemctlPath: path,
shellPath: path,
},
{
readSource: async (canonicalPath, maximumBytes) => ({
canonicalPath,
bytes: Buffer.alloc(maximumBytes + 1),
}),
identifyExecutable: async () => identity,
identifyWorker: async () => identity,
identifyRuntimeClosure: async () => [],
seccompDigest: () => "2".repeat(64),
probe: async () => undefined,
},
),
).rejects.toThrow("Replay module bytes exceed the aggregate limit");
});