fix(artifacts): reuse current classification and region reads

This commit is contained in:
64579525
2026-10-13 15:38:40 +08:00
175 changed files with 6746 additions and 1348 deletions
@@ -0,0 +1,39 @@
import { expect } from "vitest";
import { parseJavaScriptSource } from "../../../src/domain/javascript/javascriptSourceParser.js";
import { processTest } from "../../support/process/processFixture.js";
for (const source of [
"return;",
"void new.target;",
"var await = 1; return;",
"with ({ value: 1 }) { void value; } void new.target;",
]) {
processTest(
`accepts Node CommonJS syntax while retaining module errors: ${source}`,
async ({ processes }) => {
const commonjs = await processes.run(
process.execPath,
["--check", "--input-type=commonjs"],
{ input: source, timeoutMs: 5_000 },
);
expect(commonjs.exitCode).toBe(0);
const module = await processes.run(
process.execPath,
["--check", "--input-type=module"],
{ input: source, timeoutMs: 5_000 },
);
expect(module.exitCode).not.toBe(0);
const parsed = parseJavaScriptSource(source, "main.cjs");
expect(parsed).not.toBeNull();
expect(parsed?.errors).toEqual([]);
expect(
parseJavaScriptSource(source, "main.mjs")?.errors.length,
).toBeGreaterThan(0);
expect(
parseJavaScriptSource(source, "main.mts")?.errors.length,
).toBeGreaterThan(0);
},
);
}
@@ -4,7 +4,7 @@ import { access, readFile, rm, symlink, writeFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
import { expect } from "vitest";
import { expect, vi } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { itWithCaptureCapability } from "./processCaptureCapability.js";
@@ -123,6 +123,93 @@ const terminateFixtureProcess = async (pid: number): Promise<void> => {
await waitForProcessExit(pid);
};
itWithCaptureCapability(
"keeps the process deadline bounded when the wall clock moves backward",
async () => {
const wallStart = Date.now();
let wallReads = 0;
const now = vi.spyOn(Date, "now").mockImplementation(() => {
wallReads += 1;
return wallReads === 1 ? wallStart : wallStart - 60_000 + wallReads;
});
const controller = new AbortController();
const fallback = setTimeout(() => controller.abort(), 1_500);
try {
const result = await captureProcessScenario(
parseProcessScenario({
executable: process.execPath,
arguments: [processFixture, "hang"],
working_directory: dirname(processFixture),
timeout_ms: 100,
idle_timeout_ms: 5_000,
}),
controller.signal,
);
expect(result.ok).toBe(true);
if (!result.ok) throw result.error;
expect(result.value.exit.reason).toBe("timeout");
} finally {
clearTimeout(fallback);
now.mockRestore();
}
},
10_000,
);
itWithCaptureCapability(
"preserves reversed wall-clock observations and monotonic frames across capture",
async () => {
vi.useFakeTimers({ toFake: ["Date"] });
vi.setSystemTime(new Date("2026-01-02T00:00:00.000Z"));
try {
const result = await captureProcessScenario(
parseProcessScenario({
executable: process.execPath,
arguments: [processFixture, "partial"],
working_directory: dirname(processFixture),
settle_ms: 0,
timeout_ms: 5_000,
idle_timeout_ms: 5_000,
}),
undefined,
process.platform,
process.env,
undefined,
undefined,
{
async report(update) {
if (update.phase === "running")
vi.setSystemTime(new Date("2026-01-01T00:00:00.000Z"));
},
},
);
expect(result.ok).toBe(true);
if (!result.ok) throw result.error;
expect(result.value.frames.length).toBeGreaterThan(0);
expect(Date.parse(result.value.manifest.completed_at)).toBeLessThan(
Date.parse(result.value.manifest.started_at),
);
expect(result.value.limitations).toContain(
"Wall-clock completion time precedes start time; elapsed capture timing is recorded separately and remains monotonic.",
);
expect(
result.value.frames.map(({ at_ms }) => at_ms),
"capture-relative frame times stay ordered and nonnegative",
).toEqual(
result.value.frames.map(({ at_ms }) => at_ms).sort(
(left, right) => left - right,
),
);
expect(result.value.frames.every(({ at_ms }) => at_ms >= 0)).toBe(true);
expect(result.value.exit.reason).toBe("exited");
expect(result.value.settlement.elapsed_ms).toBeGreaterThan(0);
} finally {
vi.useRealTimers();
}
},
10_000,
);
itWithCaptureCapability(
"cleans detached run-token children omitted by sampling and preserves an unowned neighbor",
async () => {
@@ -1,4 +1,4 @@
import { readFile } from "node:fs/promises";
import { mkdir, readFile, symlink } from "node:fs/promises";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import { expect, it } from "vitest";
@@ -202,3 +202,61 @@ itWithLinuxCaptureCapability.each([false, true])(
},
20_000,
);
itWithCaptureCapability(
"preserves selected nested path identities in actual PTY Evidence",
async () => {
const root = await createTestTempDirectory("rea-process-nested-paths-");
const executable = join(root, "selected-node");
const observed = join(root, "data");
await symlink(process.execPath, executable);
await mkdir(observed);
const original = `${executable}\n${observed}/result\n${root}/log`;
const scenario = parseProcessScenario({
executable,
working_directory: root,
filesystem_observation_paths: [observed],
arguments: ["-e", `process.stdout.write(${JSON.stringify(original)})`],
normalization: { paths: true, pids: false, ports: false, patterns: [] },
settle_ms: 100,
});
const result = await captureProcessScenario(scenario);
if (!result.ok) throw result.error;
const capture = parseProcessCapture(
createProcessCaptureEvidence(scenario, result.value).normalized_result,
);
expect(capture.frames.map(({ data }) => data).join("")).toBe(
"<executable>\r\n<filesystem-root-0>/result\r\n<working-directory>/log",
);
expect(
capture.frames.map(({ raw_data, data }) => raw_data ?? data).join(""),
).toBe(original.replaceAll("\n", "\r\n"));
expect(capture.manifest.comparison_contract).toHaveProperty(
"path_normalization_version",
"longest-original-paths-v1",
);
const legacyContract = { ...capture.manifest.comparison_contract };
delete legacyContract.path_normalization_version;
const legacy = parseProcessCapture({
...capture,
manifest: {
...capture.manifest,
comparison_contract: legacyContract,
comparison_contract_sha256: digestProcessCommitment(legacyContract),
},
});
expect(() => compareProcessCaptures(legacy, capture)).toThrow(
expect.objectContaining({
issues: [
expect.objectContaining({ expected: ["path_normalization_version"] }),
],
}),
);
expect(capture.exit).toMatchObject({ code: 0, reason: "exited" });
expect(capture.cleanup).toMatchObject({
owned_process_group: "verified",
temporary_root: "removed",
});
},
20_000,
);