mirror of
https://github.com/morluto/rea.git
synced 2026-11-18 20:53:00 +00:00
refactor: remove test-only planning and native UI runtime seams
This commit is contained in:
1 parent
3c4be703cd
commit
fd584d4495
8 files changed
+38
-34
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { expect, it } from "vitest";
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import * as filesystemSnapshot from "../../process/capture/FilesystemSnapshot.js";
|
||||
|
||||
import { awaitAcknowledgement } from "../../../tests/fixtures/lifecycleAcknowledgement.js";
|
||||
import { createTestTempDirectory } from "../../../tests/fixtures/temporaryDirectory.js";
|
||||
@@ -10,6 +11,8 @@ import { err, ok, type Result } from "../../domain/result.js";
|
||||
import { ProcessCaptureError } from "../../process/capture/ProcessCaptureError.js";
|
||||
import { prepareProcessScenarioPlan } from "./ProcessScenarioPreparation.js";
|
||||
|
||||
afterEach(() => vi.restoreAllMocks());
|
||||
|
||||
it("rejects observation roots that capture admission rejects", async () => {
|
||||
const root = await createTestTempDirectory("rea-process-plan-");
|
||||
const file = join(root, "selected");
|
||||
@@ -40,23 +43,24 @@ it("reports cancellation normalized inside admission as planning cancellation",
|
||||
working_directory: ".",
|
||||
});
|
||||
const controller = new AbortController();
|
||||
vi.spyOn(
|
||||
filesystemSnapshot,
|
||||
"admitFilesystemObservationRoots",
|
||||
).mockImplementationOnce(() => {
|
||||
controller.abort("caller stopped during admission");
|
||||
return Promise.resolve(
|
||||
err(
|
||||
new ProcessCaptureError("filesystem observation admission failed", {
|
||||
cause: controller.signal.reason,
|
||||
}),
|
||||
),
|
||||
);
|
||||
});
|
||||
const prepared = await prepareProcessScenarioPlan(
|
||||
scenario,
|
||||
{},
|
||||
process.platform,
|
||||
controller.signal,
|
||||
{
|
||||
admitRoots: () => {
|
||||
controller.abort("caller stopped during admission");
|
||||
return Promise.resolve(
|
||||
err(
|
||||
new ProcessCaptureError("filesystem observation admission failed", {
|
||||
cause: controller.signal.reason,
|
||||
}),
|
||||
),
|
||||
);
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
expect(prepared.ok).toBe(false);
|
||||
@@ -85,18 +89,19 @@ it("reports cancellation after the last awaited admission step", async () => {
|
||||
);
|
||||
let admissionCalls = 0;
|
||||
|
||||
vi.spyOn(
|
||||
filesystemSnapshot,
|
||||
"admitFilesystemObservationRoots",
|
||||
).mockImplementationOnce(() => {
|
||||
admissionCalls += 1;
|
||||
admissionEntered();
|
||||
return pendingAdmission;
|
||||
});
|
||||
const planning = prepareProcessScenarioPlan(
|
||||
scenario,
|
||||
{},
|
||||
process.platform,
|
||||
controller.signal,
|
||||
{
|
||||
admitRoots: () => {
|
||||
admissionCalls += 1;
|
||||
admissionEntered();
|
||||
return pendingAdmission;
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
// Abort only once admission is actually running. Aborting earlier would be
|
||||
|
||||
@@ -14,11 +14,6 @@ import { err, ok, type Result } from "../../domain/result.js";
|
||||
/** A scenario whose executable and observation paths are resolved for execution. */
|
||||
export type ResolvedProcessScenario = Omit<ProcessScenario, "dry_run">;
|
||||
|
||||
/** Test seam for holding the final admission step while cancellation arrives. */
|
||||
export interface ProcessScenarioPreparationHost {
|
||||
readonly admitRoots?: typeof admitFilesystemObservationRoots;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a scenario for a dry run. This applies the same executable, working
|
||||
* directory, path and platform admission checks as a capture, then stops
|
||||
@@ -29,7 +24,6 @@ export const prepareProcessScenarioPlan = async (
|
||||
environment: Readonly<Record<string, string | undefined>> = process.env,
|
||||
platform: NodeJS.Platform = process.platform,
|
||||
signal?: AbortSignal,
|
||||
host: ProcessScenarioPreparationHost = {},
|
||||
): Promise<Result<ResolvedProcessScenario, AnalysisError>> => {
|
||||
if (signal?.aborted === true)
|
||||
return err(
|
||||
@@ -60,10 +54,7 @@ export const prepareProcessScenarioPlan = async (
|
||||
if (aborted()) return cancelled();
|
||||
const privacy = createProcessSensitiveOutput(scenario);
|
||||
if (!privacy.ok) return err(privacy.error);
|
||||
const admitted = await (host.admitRoots ?? admitFilesystemObservationRoots)(
|
||||
resolved,
|
||||
signal,
|
||||
);
|
||||
const admitted = await admitFilesystemObservationRoots(resolved, signal);
|
||||
if (!admitted.ok) return aborted() ? cancelled() : admitted;
|
||||
if (aborted()) return cancelled();
|
||||
return ok(resolved);
|
||||
|
||||
Reference in new issue
Block a user