Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

test: classify filesystem and process workflows by boundary

morlutoc2b56e3e1c96
diff --git a/tests/composition/android/application.test.ts b/tests/boundary/filesystem/android/application.test.ts
similarity index 96%
rename from tests/composition/android/application.test.ts
rename to tests/boundary/filesystem/android/application.test.ts
index b4260a170..c976b591c 100644
--- a/tests/composition/android/application.test.ts
+++ b/tests/boundary/filesystem/android/application.test.ts
@@ -9,16 +9,16 @@ import {
} from "@zip.js/zip.js";
import { describe, expect, it } from "vitest";
-import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
+import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
import {
createNonApplicationZipInventory,
requireSuccessfulProjection,
-} from "../../support/applicationSessionFixture.js";
+} from "../../../support/applicationSessionFixture.js";
-import { projectAndroidApplicationEvidence } from "../../../src/application/android/AndroidApplicationService.js";
-import { createDirectAnalysis } from "../../../src/composition/directAnalysis.js";
-import { androidApplicationProjectionResultSchema } from "../../../src/domain/android/androidApplication.js";
-import { parseEvidence } from "../../../src/domain/evidence.js";
+import { projectAndroidApplicationEvidence } from "../../../../src/application/android/AndroidApplicationService.js";
+import { createDirectAnalysis } from "../../../../src/composition/directAnalysis.js";
+import { androidApplicationProjectionResultSchema } from "../../../../src/domain/android/androidApplication.js";
+import { parseEvidence } from "../../../../src/domain/evidence.js";
const { runProviderAnalysis } = createDirectAnalysis({});
diff --git a/tests/composition/analysis-sessions/appleApplication.test.ts b/tests/boundary/filesystem/appleApplication.test.ts
similarity index 100%
rename from tests/composition/analysis-sessions/appleApplication.test.ts
rename to tests/boundary/filesystem/appleApplication.test.ts
diff --git a/tests/composition/analysis-sessions/artifactComparison.test.ts b/tests/boundary/filesystem/artifactComparison.test.ts
similarity index 100%
rename from tests/composition/analysis-sessions/artifactComparison.test.ts
rename to tests/boundary/filesystem/artifactComparison.test.ts
diff --git a/tests/composition/harmony/application.test.ts b/tests/boundary/filesystem/harmony/application.test.ts
similarity index 94%
rename from tests/composition/harmony/application.test.ts
rename to tests/boundary/filesystem/harmony/application.test.ts
index 9665eb66c..5f758c003 100644
--- a/tests/composition/harmony/application.test.ts
+++ b/tests/boundary/filesystem/harmony/application.test.ts
@@ -4,24 +4,24 @@ import { TextReader, Uint8ArrayWriter, ZipWriter } from "@zip.js/zip.js";
import { describe, expect, it } from "vitest";
-import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
+import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
import {
createNonApplicationZipInventory,
inventoryApplicationPackage,
requireDeterministicProjection,
requireSuccessfulProjection,
writeApplicationZip,
-} from "../../support/applicationSessionFixture.js";
+} from "../../../support/applicationSessionFixture.js";
-import { projectHarmonyApplicationEvidence } from "../../../src/application/harmony/HarmonyApplicationService.js";
-import { createDirectAnalysis } from "../../../src/composition/directAnalysis.js";
-import { harmonyApplicationProjectionResultSchema } from "../../../src/domain/harmony/harmonyApplication.js";
-import { artifactInventoryResultSchema } from "../../../src/domain/artifactGraph.js";
-import { parseBinaryTarget } from "../../../src/application/BinaryTargetResolver.js";
+import { projectHarmonyApplicationEvidence } from "../../../../src/application/harmony/HarmonyApplicationService.js";
+import { createDirectAnalysis } from "../../../../src/composition/directAnalysis.js";
+import { harmonyApplicationProjectionResultSchema } from "../../../../src/domain/harmony/harmonyApplication.js";
+import { artifactInventoryResultSchema } from "../../../../src/domain/artifactGraph.js";
+import { parseBinaryTarget } from "../../../../src/application/BinaryTargetResolver.js";
import {
ZIP_PACKAGE_FORMATS,
ZIP_NON_ENTRY_TAIL_LIMITATION,
-} from "../../../src/domain/zipPackageFormat.js";
+} from "../../../../src/domain/zipPackageFormat.js";
const { runProviderAnalysis } = createDirectAnalysis({});
const elf = Uint8Array.from([0x7f, 0x45, 0x4c, 0x46, 2, 1, 1, 0]);
diff --git a/tests/composition/runtime-observation/javascriptRuntimeReconciliation.test.ts b/tests/boundary/filesystem/javascript-applications/javascriptRuntimeReconciliation.test.ts
similarity index 93%
rename from tests/composition/runtime-observation/javascriptRuntimeReconciliation.test.ts
rename to tests/boundary/filesystem/javascript-applications/javascriptRuntimeReconciliation.test.ts
index 5d9eab69b..a3b2231a2 100644
--- a/tests/composition/runtime-observation/javascriptRuntimeReconciliation.test.ts
+++ b/tests/boundary/filesystem/javascript-applications/javascriptRuntimeReconciliation.test.ts
@@ -3,26 +3,26 @@ import { join } from "node:path";
import { expect, it } from "vitest";
-import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
+import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
-import { createElectronActiveEvidence } from "../../../src/application/javascript/ElectronActiveEvidence.js";
-import { reconcileJavaScriptRuntimeEvidence } from "../../../src/application/javascript/JavaScriptRuntimeReconciliationService.js";
-import { createEvidence } from "../../../src/domain/evidence.js";
+import { createElectronActiveEvidence } from "../../../../src/application/javascript/ElectronActiveEvidence.js";
+import { reconcileJavaScriptRuntimeEvidence } from "../../../../src/application/javascript/JavaScriptRuntimeReconciliationService.js";
+import { createEvidence } from "../../../../src/domain/evidence.js";
import {
parseRuntimeReconciliationInput,
reconcileJavaScriptRuntime,
-} from "../../../src/domain/javascript/javascriptRuntimeReconciliation.js";
-import { reconcileJavaScriptRuntimeInputSchema } from "../../../src/domain/javascript/javascriptRuntimeReconciliationSchemas.js";
-import { javascriptRuntimeReconciliationResultSchema } from "../../../src/domain/javascript/javascriptRuntimeReconciliationSchemas.js";
-import { electronActiveObservationInputSchema } from "../../../src/domain/javascript/electronActiveObservation.js";
-import { createElectronActiveObservationFixtureResult } from "../../../src/domain/javascript/electronActiveObservation.fixture.js";
+} from "../../../../src/domain/javascript/javascriptRuntimeReconciliation.js";
+import { reconcileJavaScriptRuntimeInputSchema } from "../../../../src/domain/javascript/javascriptRuntimeReconciliationSchemas.js";
+import { javascriptRuntimeReconciliationResultSchema } from "../../../../src/domain/javascript/javascriptRuntimeReconciliationSchemas.js";
+import { electronActiveObservationInputSchema } from "../../../../src/domain/javascript/electronActiveObservation.js";
+import { createElectronActiveObservationFixtureResult } from "../../../../src/domain/javascript/electronActiveObservation.fixture.js";
import {
SOURCE,
applicationFixture,
analyzeFixture,
electronRuntimeEvidence,
-} from "../../fixtures/javascriptRuntimeReconciliation.js";
+} from "../../../fixtures/javascriptRuntimeReconciliation.js";
const reconcileInput = (input: unknown) =>
reconcileJavaScriptRuntime(
diff --git a/tests/boundary/process/binarySessionCleanupRetry.test.ts b/tests/boundary/process/binarySessionCleanupRetry.test.ts
new file mode 100644
index 000000000..ff00563fc
--- /dev/null
+++ b/tests/boundary/process/binarySessionCleanupRetry.test.ts
@@ -0,0 +1,166 @@
+import { access, mkdtemp, rm } from "node:fs/promises";
+import { expect, it, onTestFinished } from "vitest";
+
+import { createAnalysisExecution } from "../../../src/application/AnalysisProvider.js";
+import { HopperStartError } from "../../../src/domain/hopperErrors.js";
+import { err, ok as resultOk } from "../../../src/domain/result.js";
+import type {
+ BridgeLauncher,
+ BridgeSession,
+} from "../../../src/hopper/BridgeLauncher.js";
+import { HopperClient } from "../../../src/hopper/HopperClient.js";
+import {
+ acquireHopperTargetLease,
+ type HopperTargetLease,
+} from "../../../src/hopper/HopperTargetLease.js";
+import { cleanupOwnedProcessGroup } from "../../../src/process/ProcessOwnership.js";
+import { spawnOwnedProviderProcess } from "../../../src/process/ProviderProcess.js";
+import { hopperFixturePath } from "../providers/hopper/hopperClient.fixture.js";
+import {
+ createBinarySessionTargets,
+ createTestBinarySession,
+} from "../../fixtures/binarySession.js";
+
+class RetryingHopperLauncher implements BridgeLauncher {
+ cleanupAllowed = false;
+ cleanupAttempts = 0;
+ directory: string | undefined;
+ lease: HopperTargetLease | undefined;
+
+ constructor(
+ readonly leaseDirectory: string,
+ readonly targetPath: string,
+ readonly cleanupRequired = false,
+ ) {}
+
+ acquire(runId: string) {
+ return acquireHopperTargetLease({
+ targetPath: this.targetPath,
+ targetKind: "database",
+ loaderArgs: [],
+ runId,
+ directory: this.leaseDirectory,
+ });
+ }
+
+ async launch(session: BridgeSession) {
+ const lease = await this.acquire(session.runId);
+ if (!lease.acquired)
+ return err(
+ new HopperStartError({ userMessage: "fixture lease is held" }),
+ );
+ this.lease = lease.lease;
+ this.directory = session.directory;
+ const started = await spawnOwnedProviderProcess({
+ command: process.execPath,
+ arguments: [
+ hopperFixturePath,
+ session.socketPath,
+ session.token,
+ session.runId,
+ this.cleanupRequired ? "cleanup-required" : "acknowledge",
+ ],
+ runId: session.runId,
+ expectedCommand: null,
+ });
+ return resultOk({
+ ...started,
+ ownsProcessLifetime: true as const,
+ providerLifetime: "launcher-process" as const,
+ shutdownMode: "process-cleanup" as const,
+ cleanup: () => {
+ this.cleanupAttempts += 1;
+ return this.cleanupAllowed
+ ? cleanupOwnedProcessGroup(started.ownership)
+ : Promise.resolve({
+ cleaned: false as const,
+ reason: "fixture process cleanup not confirmed",
+ });
+ },
+ releaseLease: () => lease.lease.release(),
+ });
+ }
+}
+
+it("retains Hopper process handles, private files, and lease until an actual session cleanup retry succeeds", async () => {
+ const leaseDirectory = await mkdtemp("/tmp/rea-hl-");
+ onTestFinished(() => rm(leaseDirectory, { recursive: true, force: true }));
+ const [first, second] = await createBinarySessionTargets();
+ const launcher = new RetryingHopperLauncher(leaseDirectory, first);
+ const hopper = new HopperClient({ launcher, startupTimeoutMs: 10_000 });
+ let clientsCreated = 0;
+ const session = createTestBinarySession(() => {
+ clientsCreated += 1;
+ return {
+ execute: async () => {
+ const started = await hopper.start();
+ return started.ok
+ ? resultOk(
+ createAnalysisExecution(null, {
+ id: "hopper",
+ name: "fixture Hopper",
+ version: null,
+ }),
+ )
+ : started;
+ },
+ close: (options) => hopper.close(options),
+ };
+ });
+ onTestFinished(async () => {
+ launcher.cleanupAllowed = true;
+ await session.close();
+ await hopper.close();
+ await launcher.lease?.release();
+ });
+ expect(await session.open(first)).toMatchObject({ ok: true });
+ expect(await session.close()).toMatchObject({
+ ok: false,
+ error: { cleanupIncomplete: true },
+ });
+ const runtime = launcher.directory;
+ if (runtime === undefined)
+ throw new Error("Fixture did not capture its runtime");
+ await access(runtime);
+ expect(launcher.cleanupAttempts).toBe(1);
+ expect(await launcher.acquire("other-owner")).toMatchObject({
+ acquired: false,
+ });
+ expect(await session.open(second)).toMatchObject({
+ ok: false,
+ error: { cleanupIncomplete: true },
+ });
+ expect(clientsCreated).toBe(1);
+ expect(launcher.cleanupAttempts).toBe(2);
+ launcher.cleanupAllowed = true;
+ expect(await session.close()).toEqual(resultOk(null));
+ expect(launcher.cleanupAttempts).toBe(3);
+ await expect(access(runtime)).rejects.toMatchObject({ code: "ENOENT" });
+ const replacement = await launcher.acquire("replacement-owner");
+ expect(replacement.acquired).toBe(true);
+ if (replacement.acquired) await replacement.lease.release();
+ expect((await session.open(second)).ok).toBe(true);
+ expect(clientsCreated).toBe(2);
+});
+
+it("reports a direct Hopper close failure and retries the retained owned process", async () => {
+ const leaseDirectory = await mkdtemp("/tmp/rea-hl-");
+ onTestFinished(() => rm(leaseDirectory, { recursive: true, force: true }));
+ const [target] = await createBinarySessionTargets();
+ const launcher = new RetryingHopperLauncher(leaseDirectory, target, true);
+ const hopper = new HopperClient({ launcher, startupTimeoutMs: 10_000 });
+ onTestFinished(async () => {
+ launcher.cleanupAllowed = true;
+ await hopper.close();
+ await launcher.lease?.release();
+ });
+ expect(await hopper.start()).toMatchObject({ ok: true });
+ expect(await hopper.close()).toMatchObject({
+ ok: false,
+ error: { cleanupIncomplete: true },
+ });
+ expect(launcher.cleanupAttempts).toBe(1);
+ launcher.cleanupAllowed = true;
+ expect(await hopper.close()).toEqual(resultOk(null));
+ expect(launcher.cleanupAttempts).toBe(2);
+});
diff --git a/tests/conformance/scanTodos.test.ts b/tests/boundary/process/scanTodos.test.ts
similarity index 93%
rename from tests/conformance/scanTodos.test.ts
rename to tests/boundary/process/scanTodos.test.ts
index 2085dd3ba..b48dd2dd3 100644
--- a/tests/conformance/scanTodos.test.ts
+++ b/tests/boundary/process/scanTodos.test.ts
@@ -5,7 +5,7 @@ import { promisify } from "node:util";
import { describe, expect, it } from "vitest";
-import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
+import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const execute = promisify(execFile);
diff --git a/tests/composition/analysis-sessions/binarySessionCleanupRetry.test.ts b/tests/composition/analysis-sessions/binarySessionCleanupRetry.test.ts
index 29dd1c0b3..76f13c5ac 100644
--- a/tests/composition/analysis-sessions/binarySessionCleanupRetry.test.ts
+++ b/tests/composition/analysis-sessions/binarySessionCleanupRetry.test.ts
@@ -1,34 +1,12 @@
-import {
- access,
- mkdir,
- mkdtemp,
- readFile,
- rm,
- writeFile,
-} from "node:fs/promises";
+import { access, mkdir, readFile, rm, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect, it, onTestFinished } from "vitest";
-import {
- createAnalysisExecution,
- type AnalysisClient,
-} from "../../../src/application/AnalysisProvider.js";
+import type { AnalysisClient } from "../../../src/application/AnalysisProvider.js";
import { HopperStartError } from "../../../src/domain/hopperErrors.js";
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
import { ProviderCleanupError } from "../../../src/domain/providerCleanupError.js";
import { err, ok as resultOk } from "../../../src/domain/result.js";
-import type {
- BridgeLauncher,
- BridgeSession,
-} from "../../../src/hopper/BridgeLauncher.js";
-import { HopperClient } from "../../../src/hopper/HopperClient.js";
-import {
- acquireHopperTargetLease,
- type HopperTargetLease,
-} from "../../../src/hopper/HopperTargetLease.js";
-import { cleanupOwnedProcessGroup } from "../../../src/process/ProcessOwnership.js";
-import { spawnOwnedProviderProcess } from "../../../src/process/ProviderProcess.js";
-import { hopperFixturePath } from "../../boundary/providers/hopper/hopperClient.fixture.js";
import { observed as ok } from "../../fixtures/analysisExecution.js";
import {
createBinarySessionTargets,
@@ -289,147 +267,3 @@ it("does not start a replacement cancelled while pending cleanup completes", asy
expect(created).toBe(1);
await expect(access(runtime)).rejects.toMatchObject({ code: "ENOENT" });
});
-
-class RetryingHopperLauncher implements BridgeLauncher {
- cleanupAllowed = false;
- cleanupAttempts = 0;
- directory: string | undefined;
- lease: HopperTargetLease | undefined;
-
- constructor(
- readonly leaseDirectory: string,
- readonly targetPath: string,
- readonly cleanupRequired = false,
- ) {}
-
- acquire(runId: string) {
- return acquireHopperTargetLease({
- targetPath: this.targetPath,
- targetKind: "database",
- loaderArgs: [],
- runId,
- directory: this.leaseDirectory,
- });
- }
-
- async launch(session: BridgeSession) {
- const lease = await this.acquire(session.runId);
- if (!lease.acquired)
- return err(
- new HopperStartError({ userMessage: "fixture lease is held" }),
- );
- this.lease = lease.lease;
- this.directory = session.directory;
- const started = await spawnOwnedProviderProcess({
- command: process.execPath,
- arguments: [
- hopperFixturePath,
- session.socketPath,
- session.token,
- session.runId,
- this.cleanupRequired ? "cleanup-required" : "acknowledge",
- ],
- runId: session.runId,
- expectedCommand: null,
- });
- return resultOk({
- ...started,
- ownsProcessLifetime: true as const,
- providerLifetime: "launcher-process" as const,
- shutdownMode: "process-cleanup" as const,
- cleanup: () => {
- this.cleanupAttempts += 1;
- return this.cleanupAllowed
- ? cleanupOwnedProcessGroup(started.ownership)
- : Promise.resolve({
- cleaned: false as const,
- reason: "fixture process cleanup not confirmed",
- });
- },
- releaseLease: () => lease.lease.release(),
- });
- }
-}
-
-it("retains Hopper process handles, private files, and lease until an actual session cleanup retry succeeds", async () => {
- const leaseDirectory = await mkdtemp("/tmp/rea-hl-");
- onTestFinished(() => rm(leaseDirectory, { recursive: true, force: true }));
- const [first, second] = await createBinarySessionTargets();
- const launcher = new RetryingHopperLauncher(leaseDirectory, first);
- const hopper = new HopperClient({ launcher, startupTimeoutMs: 10_000 });
- let clientsCreated = 0;
- const session = createTestBinarySession(() => {
- clientsCreated += 1;
- return {
- execute: async () => {
- const started = await hopper.start();
- return started.ok
- ? resultOk(
- createAnalysisExecution(null, {
- id: "hopper",
- name: "fixture Hopper",
- version: null,
- }),
- )
- : started;
- },
- close: (options) => hopper.close(options),
- };
- });
- onTestFinished(async () => {
- launcher.cleanupAllowed = true;
- await session.close();
- await hopper.close();
- await launcher.lease?.release();
- });
- expect(await session.open(first)).toMatchObject({ ok: true });
- expect(await session.close()).toMatchObject({
- ok: false,
- error: { cleanupIncomplete: true },
- });
- const runtime = launcher.directory;
- if (runtime === undefined)
- throw new Error("Fixture did not capture its runtime");
- await access(runtime);
- expect(launcher.cleanupAttempts).toBe(1);
- expect(await launcher.acquire("other-owner")).toMatchObject({
- acquired: false,
- });
- expect(await session.open(second)).toMatchObject({
- ok: false,
- error: { cleanupIncomplete: true },
- });
- expect(clientsCreated).toBe(1);
- expect(launcher.cleanupAttempts).toBe(2);
- launcher.cleanupAllowed = true;
- expect(await session.close()).toEqual(resultOk(null));
- expect(launcher.cleanupAttempts).toBe(3);
- await expect(access(runtime)).rejects.toMatchObject({ code: "ENOENT" });
- const replacement = await launcher.acquire("replacement-owner");
- expect(replacement.acquired).toBe(true);
- if (replacement.acquired) await replacement.lease.release();
- expect((await session.open(second)).ok).toBe(true);
- expect(clientsCreated).toBe(2);
-});
-
-it("reports a direct Hopper close failure and retries the retained owned process", async () => {
- const leaseDirectory = await mkdtemp("/tmp/rea-hl-");
- onTestFinished(() => rm(leaseDirectory, { recursive: true, force: true }));
- const [target] = await createBinarySessionTargets();
- const launcher = new RetryingHopperLauncher(leaseDirectory, target, true);
- const hopper = new HopperClient({ launcher, startupTimeoutMs: 10_000 });
- onTestFinished(async () => {
- launcher.cleanupAllowed = true;
- await hopper.close();
- await launcher.lease?.release();
- });
- expect(await hopper.start()).toMatchObject({ ok: true });
- expect(await hopper.close()).toMatchObject({
- ok: false,
- error: { cleanupIncomplete: true },
- });
- expect(launcher.cleanupAttempts).toBe(1);
- launcher.cleanupAllowed = true;
- expect(await hopper.close()).toEqual(resultOk(null));
- expect(launcher.cleanupAttempts).toBe(2);
-});