mirror of
https://github.com/morluto/rea.git
synced 2026-11-13 02:02:36 +00:00
* fix(cleanup): preserve owner recovery instructions Keep cleanup remediation through combined errors and direct or managed one-shot analysis while retaining primary diagnostics. Refs: #4227 * fix(hopper): recover late startup and retained cleanup Authenticate initial and cleanup handshakes through the same identity owner. Expose startup and cleanup activity, retain health after target retirement, and expire abandoned unauthenticated listeners without timing out authenticated work. Refs: #4227 * fix(providers): retain composite lifecycle facts across retries Preserve observed child health with incomplete peer coverage, retry only unresolved clients, and retain all child cleanup recovery actions. Refs: #4233 * fix(process): honor cancellation through capture cleanup Check the request signal after cleanup and before final publication, retaining completed observations under typed cancellation. Refs: #4005 * fix(native): preserve failed LLDB launch ownership and exit proof Publish failed-launch process identity and observed exit separately from object validity. Retire only the exact owned process and retain uncertainty when exit cannot be established. Refs: #4232 * fix(native): honor cancellation after trace finalization Check cancellation after runtime-root cleanup and retain collected trace observations as partial cancellation evidence. Refs: #4009 * fix(cli): preserve analysis results when provider cleanup fails Reuse the existing one-shot finalizer across thirteen command families to retain completed Evidence and primary diagnostics on close failure. Cover success, denied cleanup, and combined primary/cleanup failure through the public CLI. Refs: #3935 * docs(lifecycle): define completion invariants and regression scenarios Document distinct ownership/readiness/exit facts, late cancellation and atomic publication boundaries, partial child cleanup, and diagnostic retention. Link representative regressions and route contributor guidance through AGENTS.md. Refs: #4227 * fix(session): retain run identity through pending cleanup * fix(cli): preserve original cleanup resource diagnostics * fix(native): retain completed facts through finalization failure * fix(providers): report retained cleanup paths at their owners
160 lines
5.8 KiB
TypeScript
160 lines
5.8 KiB
TypeScript
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect, it, onTestFinished, vi } from "vitest";
|
|
|
|
const injected = vi.hoisted(() => ({
|
|
sourcePath: undefined as string | undefined,
|
|
abortController: undefined as AbortController | undefined,
|
|
failClose: false,
|
|
closeAttempts: 0,
|
|
}));
|
|
|
|
vi.mock("node:fs/promises", async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import("node:fs/promises")>();
|
|
return {
|
|
...actual,
|
|
open: async (...args: Parameters<typeof actual.open>) => {
|
|
const handle = await actual.open(...args);
|
|
if (args[0] !== injected.sourcePath) return handle;
|
|
const createReadStream = handle.createReadStream.bind(handle);
|
|
handle.createReadStream = (options) => {
|
|
injected.abortController?.abort();
|
|
return createReadStream(options);
|
|
};
|
|
const close = handle.close.bind(handle);
|
|
handle.close = async () => {
|
|
injected.closeAttempts += 1;
|
|
if (injected.failClose) throw new Error("fixture close refusal");
|
|
await close();
|
|
};
|
|
return handle;
|
|
},
|
|
};
|
|
});
|
|
|
|
import { WebModuleTraceService } from "../../../src/application/WebModuleTraceService.js";
|
|
import { finishAnalysisCommand } from "../../../src/cli/finishAnalysisCommand.js";
|
|
import { LocalWebModuleArtifacts } from "../../../src/browser/modules/WebModuleArtifacts.js";
|
|
import { ProviderCleanupError } from "../../../src/domain/providerCleanupError.js";
|
|
import { AnalysisCancelledError } from "../../../src/domain/analysisErrorCore.js";
|
|
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
|
|
import { webModuleArtifactsFixture } from "../../fixtures/webModuleTrace.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
|
|
it("retains cancelled source read ownership until service close retries it", async () => {
|
|
const root = await createTestTempDirectory("rea-web-artifact-read-owner-");
|
|
onTestFinished(async () => {
|
|
injected.sourcePath = undefined;
|
|
injected.abortController = undefined;
|
|
injected.failClose = false;
|
|
injected.closeAttempts = 0;
|
|
await rm(root, { recursive: true, force: true });
|
|
});
|
|
const source = 'import "./dep.js";';
|
|
const fixture = webModuleArtifactsFixture(source);
|
|
const manifestPath = join(root, "manifest.json");
|
|
const sourcePath = join(root, "files", "modules", "main.js");
|
|
await mkdir(join(root, "files", "modules"), { recursive: true });
|
|
await writeFile(sourcePath, source);
|
|
await writeFile(manifestPath, JSON.stringify(fixture.manifest));
|
|
|
|
injected.sourcePath = sourcePath;
|
|
injected.failClose = true;
|
|
const controller = new AbortController();
|
|
injected.abortController = controller;
|
|
const resolver = {
|
|
resolve: vi.fn(),
|
|
close: vi.fn(async () => undefined),
|
|
};
|
|
const service = new WebModuleTraceService(
|
|
new LocalWebModuleArtifacts(),
|
|
resolver,
|
|
);
|
|
const input = { manifest_path: manifestPath, script_index: 0 };
|
|
|
|
const cancelled = await service.trace(input, { signal: controller.signal });
|
|
expect(cancelled.ok).toBe(false);
|
|
if (cancelled.ok) throw new Error("Expected cancelled source read");
|
|
expect(cancelled.error.cleanupIncomplete).toBe(true);
|
|
expect(cancelled.error.cleanupResources).toContain(sourcePath);
|
|
expect(resolver.resolve).not.toHaveBeenCalled();
|
|
|
|
injected.abortController = undefined;
|
|
const blocked = await service.trace(input);
|
|
expect(blocked.ok).toBe(false);
|
|
if (blocked.ok) throw new Error("Expected retained cleanup to block load");
|
|
expect(blocked.error.cleanupIncomplete).toBe(true);
|
|
expect(injected.closeAttempts).toBe(2);
|
|
|
|
let cleanupFailure: unknown;
|
|
try {
|
|
await service.close();
|
|
} catch (cause) {
|
|
cleanupFailure = cause;
|
|
}
|
|
expect(cleanupFailure).toBeInstanceOf(ProviderCleanupError);
|
|
expect(cleanupFailure).toMatchObject({
|
|
operation: "trace_web_module_imports",
|
|
cleanupResources: [sourcePath],
|
|
diagnostics: { reason: expect.stringContaining("fixture close refusal") },
|
|
});
|
|
expect((cleanupFailure as ProviderCleanupError).cause).toBeInstanceOf(Error);
|
|
expect(resolver.close).toHaveBeenCalledTimes(1);
|
|
expect(injected.closeAttempts).toBe(3);
|
|
|
|
const finalized = await finishAnalysisCommand(
|
|
() => service.trace(input),
|
|
service,
|
|
"web-module-artifacts",
|
|
"trace_web_module_imports",
|
|
);
|
|
expect(finalized).toMatchObject({
|
|
code: "cleanup_incomplete",
|
|
details: { resources: [sourcePath] },
|
|
});
|
|
expect(resolver.close).toHaveBeenCalledTimes(2);
|
|
|
|
injected.failClose = false;
|
|
const attemptsBeforeRetry = injected.closeAttempts;
|
|
await service.close();
|
|
expect(injected.closeAttempts).toBeGreaterThan(attemptsBeforeRetry);
|
|
expect(resolver.close).toHaveBeenCalledTimes(3);
|
|
});
|
|
|
|
it("preserves both web cleanup owners' resources, diagnostics and recovery actions", async () => {
|
|
const artifacts = new ProviderCleanupError(
|
|
"web-artifacts",
|
|
["artifact-root", "shared-resource"],
|
|
{ reason: "artifact cleanup denied" },
|
|
{ remediationAction: "Release the retained artifact lease." },
|
|
);
|
|
const resolver = new AnalysisCancelledError("web-resolution", {
|
|
cleanup: {
|
|
reason: "resolver shutdown unconfirmed",
|
|
resources: ["resolver-root", "shared-resource"],
|
|
},
|
|
});
|
|
const service = new WebModuleTraceService(
|
|
{
|
|
load: vi.fn(),
|
|
close: async () => {
|
|
throw artifacts;
|
|
},
|
|
},
|
|
{
|
|
resolve: vi.fn(),
|
|
close: async () => {
|
|
throw resolver;
|
|
},
|
|
},
|
|
);
|
|
const projected = [artifacts, resolver].map(projectAnalysisError);
|
|
await expect(service.close()).rejects.toMatchObject({
|
|
cleanupResources: ["artifact-root", "shared-resource", "resolver-root"],
|
|
diagnostics: { failures: projected },
|
|
remediationAction: projected
|
|
.map(({ remediation }) => remediation.action)
|
|
.join("; "),
|
|
});
|
|
});
|