mirror of
https://github.com/morluto/rea.git
synced 2026-12-02 19:57:58 +00:00
test(fixtures): let each test clean up its own temporary directories (#14805)
This commit is contained in:
1 parent
352f6085e5
commit
a3a4771918
8 files changed
+14
-106
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
@@ -14,15 +14,9 @@ import {
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const browsers: FakeCdpBrowser[] = [];
|
||||
const temporary: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(browsers.splice(0).map(async (browser) => browser.close()));
|
||||
await Promise.all(
|
||||
temporary
|
||||
.splice(0)
|
||||
.map(async (root) => rm(root, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
const normalizedResult = (value: unknown): unknown => {
|
||||
@@ -133,7 +127,6 @@ cliTest(
|
||||
"uses the same ownership facts for passive Electron worker inspection",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-worker-ownership-");
|
||||
temporary.push(root);
|
||||
await writeFile(join(root, "index.html"), "<html></html>");
|
||||
await writeFile(join(root, "worker.js"), "void 0;");
|
||||
const browser = await startFakeCdpBrowser({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { spawn } from "node:child_process";
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
@@ -28,7 +28,6 @@ import { waitFor } from "../../support/testWait.js";
|
||||
const cliProcesses = createTestProcessRegistry();
|
||||
const cli = createTestCli(cliProcesses);
|
||||
const browsers: FakeCdpBrowser[] = [];
|
||||
const temporary: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await closeVerifierResources([
|
||||
@@ -37,16 +36,11 @@ afterEach(async () => {
|
||||
await browser.close();
|
||||
browsers.splice(browsers.indexOf(browser), 1);
|
||||
}),
|
||||
...temporary.map((path) => async () => {
|
||||
await rm(path, { recursive: true, force: true });
|
||||
temporary.splice(temporary.indexOf(path), 1);
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("returns the same endpoint-scoped Electron Evidence contracts", async () => {
|
||||
const root = await createTestTempDirectory("rea-electron-cli-");
|
||||
temporary.push(root);
|
||||
await writeFile(join(root, "index.html"), "<script src='app.js'></script>");
|
||||
await writeFile(join(root, "app.js"), "export const app = true;");
|
||||
const browser = await startFakeCdpBrowser({
|
||||
@@ -158,7 +152,6 @@ it.skipIf(process.platform === "win32")(
|
||||
"forwards SIGINT through Electron page inspection and completes target cleanup",
|
||||
async () => {
|
||||
const root = await createTestTempDirectory("rea-electron-cli-cancel-");
|
||||
temporary.push(root);
|
||||
const page = join(root, "index.html");
|
||||
await writeFile(page, "<main>fixture</main>");
|
||||
const browser = await startFakeCdpBrowser({
|
||||
@@ -232,7 +225,6 @@ it.skipIf(process.platform === "win32")(
|
||||
|
||||
it("returns the static JavaScript application Evidence contract", async () => {
|
||||
const root = await createTestTempDirectory("rea-electron-static-cli-");
|
||||
temporary.push(root);
|
||||
await writeElectronBoundaryFixture(root);
|
||||
const environment = {
|
||||
...process.env,
|
||||
@@ -263,7 +255,6 @@ it("returns the static JavaScript application Evidence contract", async () => {
|
||||
describe("Electron CLI artifact behavior", () => {
|
||||
it("keeps artifact format separate from structured output format", async () => {
|
||||
const root = await createTestTempDirectory("rea-electron-format-cli-");
|
||||
temporary.push(root);
|
||||
await writeElectronBoundaryFixture(root);
|
||||
const environment = {
|
||||
...process.env,
|
||||
@@ -289,7 +280,6 @@ describe("Electron CLI artifact behavior", () => {
|
||||
|
||||
it("routes generic directory analysis to static JavaScript", async () => {
|
||||
const root = await createTestTempDirectory("rea-electron-routed-cli-");
|
||||
temporary.push(root);
|
||||
await writeElectronBoundaryFixture(root);
|
||||
const environment = {
|
||||
...process.env,
|
||||
@@ -335,7 +325,6 @@ describe("Electron CLI runtime reconciliation", () => {
|
||||
it("reads a file and returns the derived static/runtime reconciliation contract", async () => {
|
||||
const root = await createTestTempDirectory("rea-runtime-cli-");
|
||||
const inputPath = join(root, "reconciliation.json");
|
||||
temporary.push(root);
|
||||
await writeFile(
|
||||
inputPath,
|
||||
JSON.stringify(JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE),
|
||||
@@ -370,7 +359,6 @@ describe("Electron CLI runtime reconciliation", () => {
|
||||
const assets = await createTestTempDirectory("rea-runtime-cli-assets-");
|
||||
const runtime = await createTestTempDirectory("rea-runtime-cli-live-");
|
||||
const inputPath = join(assets, "reconciliation.json");
|
||||
temporary.push(application, assets, runtime);
|
||||
await Promise.all([
|
||||
writeFile(join(assets, "app.js"), SOURCE),
|
||||
writeFile(join(assets, "absent.js"), "export const absent = true;\n"),
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { jsonValueSchema } from "../../../src/domain/jsonValue.js";
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdir, rm, writeFile } from "node:fs/promises";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { afterEach, expect, it } from "vitest";
|
||||
import { expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createBrowserEvidence } from "../../../src/application/BrowserEvidence.js";
|
||||
@@ -14,15 +14,6 @@ import { passiveNetworkCapture } from "../../fixtures/passiveNetworkCapture.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
const temporary: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
temporary
|
||||
.splice(0)
|
||||
.map(async (path) => rm(path, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
const reconciledSchema = z.object({
|
||||
normalized_result: z.object({
|
||||
@@ -198,7 +189,6 @@ const mappedLocation = (path: string) => ({
|
||||
|
||||
it("matches a source-free webpack script to its containing asset", async () => {
|
||||
const root = await createTestTempDirectory("rea-url-bundler-asset-");
|
||||
temporary.push(root);
|
||||
await mkdir(join(root, "chunks"));
|
||||
await writeFile(
|
||||
join(root, "chunks", "runtime.js"),
|
||||
@@ -219,7 +209,6 @@ it("matches a source-free webpack script to its containing asset", async () => {
|
||||
|
||||
it("keeps an encoded slash inside one URL segment rather than naming a nested artifact", async () => {
|
||||
const root = await createTestTempDirectory("rea-url-prefix-segments-");
|
||||
temporary.push(root);
|
||||
await mkdir(join(root, "child"));
|
||||
await Promise.all([
|
||||
writeFile(join(root, "child", "part.js"), "export const nested = 1;\n"),
|
||||
@@ -254,7 +243,6 @@ it("keeps an encoded slash inside one URL segment rather than naming a nested ar
|
||||
|
||||
it("keeps static load state unknown beneath a prefix whose runtime script had no artifact path", async () => {
|
||||
const root = await createTestTempDirectory("rea-url-prefix-load-state-");
|
||||
temporary.push(root);
|
||||
await mkdir(join(root, "child"));
|
||||
await Promise.all([
|
||||
writeFile(join(root, "child", "part.js"), "export const nested = 1;\n"),
|
||||
|
||||
@@ -3,10 +3,10 @@ import {
|
||||
fileSubjectDisplay,
|
||||
} from "../../fixtures/evidenceSubject.js";
|
||||
import { unknownTarget } from "../../../src/domain/targetIdentity.js";
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join, relative, resolve } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
@@ -53,16 +53,6 @@ import { MANAGED_APPLICATION_GRAPH_EXAMPLE } from "../../../src/contracts/manage
|
||||
import { JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE } from "../../../src/contracts/javascript/javascriptRuntimeReconciliationExample.js";
|
||||
import { managedApplicationGraphResultSchema } from "../../../src/domain/managed/managedApplicationGraph.js";
|
||||
|
||||
const temporary: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
temporary
|
||||
.splice(0)
|
||||
.map(async (path) => rm(path, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
describe("JavaScript application workflows", () => {
|
||||
it("preserves source-owned requested native members across trace directions", () => {
|
||||
const graph = buildSyntheticJavaScriptApplicationGraph();
|
||||
@@ -271,7 +261,6 @@ describe("historical native comparison projections", () => {
|
||||
const root = await createTestTempDirectory(
|
||||
"rea-historical-native-members-",
|
||||
);
|
||||
temporary.push(root);
|
||||
await writeFile(join(root, "package.json"), '{"type":"commonjs"}');
|
||||
await writeFile(
|
||||
join(root, "main.js"),
|
||||
@@ -362,7 +351,6 @@ describe("historical native comparison projections", () => {
|
||||
describe("complete comparison projections", () => {
|
||||
it("matches rechunked modules by exact source and minified modules by structural fingerprint", async () => {
|
||||
const root = await createTestTempDirectory("rea-application-versions-");
|
||||
temporary.push(root);
|
||||
const fixtures = await writeVersionedJavaScriptApplicationFixtures(root);
|
||||
const [left, right] = await Promise.all([
|
||||
analyzeFixture(fixtures.left),
|
||||
@@ -425,7 +413,6 @@ describe("complete comparison projections", () => {
|
||||
|
||||
it("pairs source-map originals without promoting the match to exact", async () => {
|
||||
const root = await createTestTempDirectory("rea-source-map-versions-");
|
||||
temporary.push(root);
|
||||
const fixtures = await writeVersionedJavaScriptApplicationFixtures(root);
|
||||
const [left, right] = await Promise.all([
|
||||
analyzeFixture(fixtures.left),
|
||||
@@ -570,7 +557,6 @@ describe("JavaScript application workflow error diagnostics", () => {
|
||||
const root = await createTestTempDirectory(
|
||||
"rea-application-workflow-diagnostics-",
|
||||
);
|
||||
temporary.push(root);
|
||||
const evidence = await analyzeFixture(root);
|
||||
const subject = evidence.subject;
|
||||
if (subject.identity.kind !== "file")
|
||||
@@ -603,7 +589,6 @@ describe("JavaScript application workflow error diagnostics", () => {
|
||||
const root = await createTestTempDirectory(
|
||||
"rea-application-workflow-schema-diagnostics-",
|
||||
);
|
||||
temporary.push(root);
|
||||
const evidence = await analyzeFixture(root);
|
||||
const subject = evidence.subject;
|
||||
const result = javascriptApplicationAnalysisResultSchema.parse(
|
||||
@@ -663,7 +648,6 @@ describe("JavaScript application workflow error diagnostics", () => {
|
||||
const root = await createTestTempDirectory(
|
||||
"rea-runtime-workflow-diagnostics-",
|
||||
);
|
||||
temporary.push(root);
|
||||
const evidence = await analyzeFixture(root);
|
||||
|
||||
const result = reconcileJavaScriptRuntimeEvidence({
|
||||
|
||||
@@ -9,7 +9,7 @@ import { pathToFileURL } from "node:url";
|
||||
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { afterEach, expect, it, onTestFinished, vi } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
@@ -46,7 +46,6 @@ const testClient = (name: string) =>
|
||||
|
||||
const browsers: FakeCdpBrowser[] = [];
|
||||
const resources: Array<{ close(): Promise<unknown> }> = [];
|
||||
const temporary: string[] = [];
|
||||
|
||||
it("retains failed JavaScript inventory cleanup through server shutdown retries", async () => {
|
||||
const { archive } = await createStrippedAsarAddon();
|
||||
@@ -103,11 +102,6 @@ it("retains failed JavaScript inventory cleanup through server shutdown retries"
|
||||
afterEach(async () => {
|
||||
await Promise.all(resources.splice(0).map(async (item) => item.close()));
|
||||
await Promise.all(browsers.splice(0).map(async (browser) => browser.close()));
|
||||
await Promise.all(
|
||||
temporary
|
||||
.splice(0)
|
||||
.map(async (path) => rm(path, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
it("records completed Electron facts after final detach as server Evidence", async () => {
|
||||
@@ -288,7 +282,6 @@ it("advertises owned JavaScript analysis effects without foreign target executio
|
||||
|
||||
it("exposes endpoint-scoped Electron discovery and inspection as Evidence", async () => {
|
||||
const root = await createTestTempDirectory("rea-electron-mcp-");
|
||||
temporary.push(root);
|
||||
await writeFile(join(root, "index.html"), "<script src='app.js'></script>");
|
||||
await writeFile(
|
||||
join(root, "app.js"),
|
||||
@@ -437,7 +430,6 @@ it("exposes endpoint-scoped Electron discovery and inspection as Evidence", asyn
|
||||
/** Create the selected-path aliases and retained IPC-gap capture for the public workflow. */
|
||||
const activeElectronScenarioFixture = async () => {
|
||||
const root = await createTestTempDirectory("rea-electron-active-mcp-");
|
||||
temporary.push(root);
|
||||
const applicationPath = join(root, "main.js");
|
||||
await writeFile(applicationPath, "module.exports = {};\n");
|
||||
const aliasedRoot = join(root, "..", `${basename(root)}-alias`);
|
||||
@@ -447,11 +439,10 @@ const activeElectronScenarioFixture = async () => {
|
||||
aliasedRoot,
|
||||
process.platform === "win32" ? "junction" : "dir",
|
||||
);
|
||||
temporary.push(aliasedRoot);
|
||||
onTestFinished(() => rm(aliasedRoot, { recursive: true, force: true }));
|
||||
const workingDirectory = await createTestTempDirectory(
|
||||
"rea-electron-working-directory-",
|
||||
);
|
||||
temporary.push(workingDirectory);
|
||||
const activeResult =
|
||||
createElectronActiveObservationFixtureResult(applicationPath);
|
||||
const capturedEvent = activeResult.timeline.events[0];
|
||||
@@ -629,7 +620,6 @@ it("runs active Electron scenarios with selected paths and inferred working dire
|
||||
|
||||
it("exposes the target-free static JavaScript application workflow", async () => {
|
||||
const root = await createTestTempDirectory("rea-electron-static-mcp-");
|
||||
temporary.push(root);
|
||||
await writeElectronBoundaryFixture(root);
|
||||
const session = createTestBinarySession(() => ({
|
||||
execute: () => Promise.resolve(observed(null)),
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { copyFile, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { copyFile, mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
@@ -12,19 +12,8 @@ import { writeVersionedJavaScriptApplicationFixtures } from "../../fixtures/java
|
||||
const execute = promisify(execFile);
|
||||
|
||||
describe("local application workflow verifier", () => {
|
||||
const temporary: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
temporary
|
||||
.splice(0)
|
||||
.map(async (path) => rm(path, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
it("reports two-version and trace results", async () => {
|
||||
const root = await createTestTempDirectory("rea-application-verifier-");
|
||||
temporary.push(root);
|
||||
const fixtures = await writeVersionedJavaScriptApplicationFixtures(root);
|
||||
const { stdout } = await execute(
|
||||
process.execPath,
|
||||
@@ -61,7 +50,6 @@ describe("local application workflow verifier", () => {
|
||||
|
||||
it("reports an added parser return field", async () => {
|
||||
const root = await createTestTempDirectory("rea-shape-verifier-");
|
||||
temporary.push(root);
|
||||
const left = join(root, "left");
|
||||
const right = join(root, "right");
|
||||
await Promise.all([mkdir(left), mkdir(right)]);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { rm, writeFile } from "node:fs/promises";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { afterEach, expect, it } from "vitest";
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
@@ -30,19 +30,8 @@ const reconcileInput = (input: unknown) => {
|
||||
|
||||
const execute = promisify(execFile);
|
||||
|
||||
const temporary: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
temporary
|
||||
.splice(0)
|
||||
.map(async (path) => rm(path, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
it("retains each capture and both runtime instances of a loaded asset", async () => {
|
||||
const fixture = await applicationFixture();
|
||||
temporary.push(fixture);
|
||||
const staticEvidence = await analyzeFixture(fixture);
|
||||
const runtimeObservations = [
|
||||
electronRuntimeEvidence(fixture, SOURCE, {
|
||||
@@ -110,7 +99,6 @@ it("retains each capture and both runtime instances of a loaded asset", async ()
|
||||
|
||||
it("keeps graph omission counts unknown when a runtime section is unavailable", async () => {
|
||||
const fixture = await applicationFixture();
|
||||
temporary.push(fixture);
|
||||
const result = reconcileInput({
|
||||
static_layers: [
|
||||
{ role: "application", analysis: await analyzeFixture(fixture) },
|
||||
@@ -138,7 +126,6 @@ it("runs the local verifier from operator-provided paths without emitting source
|
||||
const fixture = await applicationFixture();
|
||||
const evidenceRoot = await createTestTempDirectory("rea-runtime-evidence-");
|
||||
const evidencePath = join(evidenceRoot, "runtime-evidence.json");
|
||||
temporary.push(fixture, evidenceRoot);
|
||||
await writeFile(
|
||||
evidencePath,
|
||||
JSON.stringify(electronRuntimeEvidence(fixture, SOURCE)),
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { rm, symlink, writeFile } from "node:fs/promises";
|
||||
import { symlink, writeFile } from "node:fs/promises";
|
||||
import { join, relative } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { afterEach, expect, it } from "vitest";
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import {
|
||||
@@ -13,20 +13,10 @@ import {
|
||||
} from "../../fixtures/javascriptRuntimeReconciliation.js";
|
||||
|
||||
const execute = promisify(execFile);
|
||||
const temporary: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
temporary
|
||||
.splice(0)
|
||||
.map((path) => rm(path, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
const selectedFixture = async () => {
|
||||
const physical = await applicationFixture();
|
||||
const root = await createTestTempDirectory("rea-verifier-selection-");
|
||||
temporary.push(physical, root);
|
||||
const alias = join(root, "selected-app");
|
||||
await symlink(
|
||||
physical,
|
||||
|
||||
Reference in new issue
Block a user