mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 05:32:44 +00:00
fix(setup): preserve cleanup ownership and resource reports (#6920)
* fix(setup): report host-owned cleanup resources alongside the primary's
SetupHost.close documents that it reports the resources a setup host still
owns, but its contract returned only a string. runSetup therefore built the
ProviderCleanupError from the primary failure's cleanupResources alone, so a
resource the host failed to release reached the projection only inside a
free-text reason while the error asks the caller to review the reported local
resources.
Return a SetupCloseReport instead. closeSetupResources absorbs the structured
resources of any cause that reports them, through
ArtifactReaderFailure.cleanupObservation, and leaves opaque failures
message-only so no resource name is invented. runSetup then unions the host's
resources with the primary's before building the typed cleanup error.
Two boundary tests read the close result directly: the skill-cleanup case now
asserts the retained backup path in the report reason rather than in a bare
string, and the shared ownership helper takes an opaque close result because it
only ever awaits undefined from either host it is given.
Validation: RED then green in src/application/Setup.recovery.test.ts, where
the new case previously received only the primary resource; 116 tests across
the seven Setup and cleanup-ownership suites pass; tsc --noEmit over the
changed set, its setup callers, and both boundary tests exits 0; oxlint
reports 0 errors; oxfmt --check is clean; verify:module-boundaries passes.
The two failures in src/setupEnvironment.test.ts reproduce identically on
pristine bded9c628 with this change stashed.
* fix(setup): preserve cleanup ownership through host reports
* fix(setup): bind finalization reports to cleanup owners
* fix(setup): retain live resources in returned cleanup views
* fix(setup): preserve completed cleanup and exact installer resources
* fix(setup): retain delegated cleanup across authority changes
* fix(setup): compose callback and source cleanup authorities
* fix(setup): retain producer cleanup failure reasons
* fix(cli): render structured setup cleanup resources
* fix(setup): separate failure evidence from cleanup ownership
* fix(setup): normalize close failures and unify lease binding
* fix(setup): preserve direct lease resource attribution
---------
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
This commit is contained in:
1 parent
bdf15b9bd5
commit
98ec00f406
23 files changed
+1543
-188
No files matched your search
@@ -15,6 +15,7 @@ import { promisify } from "node:util";
|
||||
|
||||
import { z } from "zod";
|
||||
import { homeDirectoryFromEnvironment } from "../config/homeDirectory.js";
|
||||
import type { AnalysisCleanupObservation } from "../domain/analysisErrorBase.js";
|
||||
import { HOPPER_PUBLISHER } from "../domain/hopperPublisher.js";
|
||||
import { macDeveloperIdRequirement } from "../process/MacCodeSignature.js";
|
||||
import { macHopperUserApplicationPath } from "./MacHopperPaths.js";
|
||||
@@ -120,7 +121,10 @@ export interface MacHopperInstallHost {
|
||||
openApplication(path: string): Promise<void>;
|
||||
cleanup(path: string): Promise<void>;
|
||||
/** Retain the cleanup capability until the owning setup host retries it. */
|
||||
retainCleanup?(cleanup: () => Promise<void>): void;
|
||||
retainCleanup?(
|
||||
cleanup: () => Promise<void>,
|
||||
resources: readonly string[],
|
||||
): void;
|
||||
destination(): string;
|
||||
}
|
||||
|
||||
@@ -228,7 +232,7 @@ export const installMacHopper = async (
|
||||
await cleanup();
|
||||
} catch (cause: unknown) {
|
||||
cleanupFailure = `Hopper DMG cleanup failed: ${failureMessage(cause)}`;
|
||||
host.retainCleanup?.(cleanup);
|
||||
host.retainCleanup?.(cleanup, [temporaryPath]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +254,10 @@ export const installMacHopperBundle = async (
|
||||
destination: string,
|
||||
replaceExisting: boolean,
|
||||
operations: MacHopperBundleInstallOperations,
|
||||
retainCleanup: (cleanup: () => Promise<void>) => void,
|
||||
retainCleanup: (
|
||||
cleanup: () => Promise<void>,
|
||||
resources: readonly string[],
|
||||
) => void,
|
||||
): Promise<MacHopperBundleInstallResult> => {
|
||||
const stagingRoot = await operations.createStagingRoot(
|
||||
posix.dirname(destination),
|
||||
@@ -297,7 +304,7 @@ export const installMacHopperBundle = async (
|
||||
originalBackedUp = false;
|
||||
}
|
||||
await operations.removeStagingRoot(stagingRoot);
|
||||
});
|
||||
}, [stagingRoot]);
|
||||
return {
|
||||
status: "failed",
|
||||
reason: failureReason,
|
||||
@@ -310,7 +317,10 @@ export const installMacHopperBundle = async (
|
||||
await operations.removeStagingRoot(stagingRoot);
|
||||
} catch (cleanupCause: unknown) {
|
||||
const cleanupFailure = `Hopper staging root cleanup failed: ${failureMessage(cleanupCause)}`;
|
||||
retainCleanup(() => operations.removeStagingRoot(stagingRoot));
|
||||
retainCleanup(
|
||||
() => operations.removeStagingRoot(stagingRoot),
|
||||
[stagingRoot],
|
||||
);
|
||||
diagnostics.push(cleanupFailure);
|
||||
return {
|
||||
status: "failed",
|
||||
@@ -331,7 +341,10 @@ export const installMacHopperBundle = async (
|
||||
return { status: "installed" };
|
||||
} catch (cause: unknown) {
|
||||
const cleanupFailure = `Hopper staging root cleanup failed after installation committed: ${failureMessage(cause)}`;
|
||||
retainCleanup(() => operations.removeStagingRoot(stagingRoot));
|
||||
retainCleanup(
|
||||
() => operations.removeStagingRoot(stagingRoot),
|
||||
[stagingRoot],
|
||||
);
|
||||
return { status: "installed", cleanupFailure };
|
||||
}
|
||||
};
|
||||
@@ -340,8 +353,10 @@ export const installMacHopperBundle = async (
|
||||
export const systemMacHopperInstallHost = (
|
||||
homeDirectory: string,
|
||||
environment: Readonly<NodeJS.ProcessEnv>,
|
||||
): MacHopperInstallHost & { close(): Promise<string | undefined> } => {
|
||||
const pendingCleanup = new Set<() => Promise<void>>();
|
||||
): MacHopperInstallHost & {
|
||||
close(): Promise<AnalysisCleanupObservation | undefined>;
|
||||
} => {
|
||||
const pendingCleanup = new Map<() => Promise<void>, readonly string[]>();
|
||||
return {
|
||||
download: downloadHopperPackage,
|
||||
createTemporaryDirectory: () => mkdtemp(join(tmpdir(), "rea-hopper-mac-")),
|
||||
@@ -427,24 +442,30 @@ export const systemMacHopperInstallHost = (
|
||||
rename,
|
||||
removeStagingRoot: (path) => rm(path, { recursive: true }),
|
||||
},
|
||||
(cleanup) => pendingCleanup.add(cleanup),
|
||||
(cleanup, resources) => pendingCleanup.set(cleanup, resources),
|
||||
),
|
||||
async openApplication(path) {
|
||||
await execFileAsync("open", [path], { env: environment });
|
||||
},
|
||||
cleanup: (path) => rm(path, { recursive: true, force: true }),
|
||||
retainCleanup: (cleanup) => pendingCleanup.add(cleanup),
|
||||
retainCleanup: (cleanup, resources) =>
|
||||
pendingCleanup.set(cleanup, resources),
|
||||
async close() {
|
||||
let failure: string | undefined;
|
||||
for (const cleanup of pendingCleanup) {
|
||||
const failures: string[] = [];
|
||||
for (const cleanup of pendingCleanup.keys()) {
|
||||
try {
|
||||
await cleanup();
|
||||
pendingCleanup.delete(cleanup);
|
||||
} catch (cause: unknown) {
|
||||
failure ??= `Hopper installer cleanup remains incomplete: ${failureMessage(cause)}`;
|
||||
failures.push(failureMessage(cause));
|
||||
}
|
||||
}
|
||||
return failure;
|
||||
return failures.length === 0
|
||||
? undefined
|
||||
: {
|
||||
reason: `Hopper installer cleanup remains incomplete: ${failures.join("; ")}`,
|
||||
resources: [...new Set([...pendingCleanup.values()].flat())],
|
||||
};
|
||||
},
|
||||
destination: () => macHopperUserApplicationPath(homeDirectory),
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user