mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 05:32:44 +00:00
fix(cleanup): report live resources independently of failed closes (#12589)
fix(cleanup): follow live resources across owner close failures
This commit is contained in:
1 parent
2ff20ce32e
commit
b2bb427553
6 files changed
+134
-41
No files matched your search
@@ -3,10 +3,8 @@
|
||||
"src/application/SetupCleanupOwner.ts": 2,
|
||||
"src/application/binary/AnalysisProviderRegistry.ts": 2,
|
||||
"src/application/binary/CompositeProvider.ts": 1,
|
||||
"src/application/closeOwnedWebResources.ts": 1,
|
||||
"src/application/desktop/DesktopApplicationExport.ts": 2,
|
||||
"src/application/frida/FridaInstrumentationService.ts": 2,
|
||||
"src/application/releaseExposure/ReleaseExposureService.ts": 1,
|
||||
"src/browser/PlaywrightBrowserScenarioProvider.ts": 1,
|
||||
"src/browser/WebSourceMapFetcher.ts": 2,
|
||||
"src/cli/desktopCaptureCommands.ts": 1,
|
||||
|
||||
@@ -18,9 +18,48 @@ import {
|
||||
} from "../domain/webSourceLocation.js";
|
||||
import { WebSourceLocationService } from "./WebSourceLocationService.js";
|
||||
import type { WebSourceMapPort } from "../ports/WebSourceLocationPorts.js";
|
||||
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
||||
import { releaseOwnedCleanup } from "../../tests/support/cleanupRelease.js";
|
||||
|
||||
const service = (data = webSourceLocationFixture(), port = decoder) =>
|
||||
new WebSourceLocationService({ load: () => Promise.resolve(ok(data)) }, port);
|
||||
|
||||
it.each(["opaque", "already released"] as const)(
|
||||
"tracks the remaining web cleanup owner beside an %s sibling",
|
||||
async (sibling) => {
|
||||
const live = new ProviderCleanupError("artifacts", ["artifact-root"], {});
|
||||
const released = new ProviderCleanupError("codec", ["codec-root"], {});
|
||||
released.bindCleanupResourceOwner({ cleanupResources: ["codec-root"] });
|
||||
releaseOwnedCleanup(released);
|
||||
const other =
|
||||
sibling === "opaque" ? new Error("codec close unconfirmed") : released;
|
||||
const workflow = new WebSourceLocationService(
|
||||
{
|
||||
load: async () => ok(webSourceLocationFixture()),
|
||||
close: async () => {
|
||||
throw live;
|
||||
},
|
||||
},
|
||||
{
|
||||
...decoder,
|
||||
close: async () => {
|
||||
throw other;
|
||||
},
|
||||
},
|
||||
);
|
||||
const failure: unknown = await workflow
|
||||
.close()
|
||||
.catch((cause: unknown) => cause);
|
||||
if (!(failure instanceof ProviderCleanupError))
|
||||
throw new Error("expected aggregate cleanup failure");
|
||||
expect(failure.cause).toMatchObject({ errors: [live, other] });
|
||||
expect(failure.cleanupIncomplete).toBe(true);
|
||||
expect(failure.cleanupResources).toEqual(["artifact-root"]);
|
||||
releaseOwnedCleanup(live);
|
||||
expect(failure.cleanupResources).toEqual([]);
|
||||
expect(failure.cleanupIncomplete).toBe(sibling === "opaque");
|
||||
},
|
||||
);
|
||||
const expectCodecDeadline = (
|
||||
evidence: {
|
||||
readonly limitations: readonly string[];
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import { providerCleanupErrorFromCloseRejections } from "../domain/analysisErrorCleanup.js";
|
||||
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
import { errorMessage } from "../kernel/errorMessage.js";
|
||||
@@ -29,11 +30,16 @@ export const closeOwnedWebResources = async (
|
||||
if (failures.length > 1) {
|
||||
const normalized = failures.map((cause) => ({
|
||||
cause,
|
||||
// A resolved error without an owner does not establish that this close settled.
|
||||
cleanupOwner:
|
||||
cause instanceof AnalysisError &&
|
||||
(cause.cleanupIncomplete || cause.hasCleanupOwner)
|
||||
? cause
|
||||
: undefined,
|
||||
projection:
|
||||
cause instanceof AnalysisError
|
||||
? projectAnalysisError(cause)
|
||||
: undefined,
|
||||
resources: cause instanceof AnalysisError ? cause.cleanupResources : [],
|
||||
}));
|
||||
const recoveryActions = [
|
||||
...new Set(
|
||||
@@ -42,9 +48,9 @@ export const closeOwnedWebResources = async (
|
||||
),
|
||||
),
|
||||
];
|
||||
const aggregate = new ProviderCleanupError(
|
||||
throw providerCleanupErrorFromCloseRejections(
|
||||
"web-workflow",
|
||||
[...new Set(normalized.flatMap(({ resources }) => resources))],
|
||||
normalized,
|
||||
{
|
||||
failures: normalized.map(
|
||||
({ cause, projection }) =>
|
||||
@@ -54,23 +60,12 @@ export const closeOwnedWebResources = async (
|
||||
),
|
||||
},
|
||||
{
|
||||
cause: new AggregateError(
|
||||
normalized.map(({ cause }) => cause),
|
||||
message,
|
||||
),
|
||||
operation: "close_web_workflow",
|
||||
message,
|
||||
...(recoveryActions.length === 0
|
||||
? {}
|
||||
: { remediationAction: recoveryActions.join("; ") }),
|
||||
},
|
||||
);
|
||||
const dependencies = failures.filter(
|
||||
(cause): cause is AnalysisError =>
|
||||
cause instanceof AnalysisError && cause.cleanupIncomplete,
|
||||
);
|
||||
// Opaque or already-resolved rejections supply no live release authority.
|
||||
if (dependencies.length === failures.length)
|
||||
aggregate.bindCleanupDependencies(dependencies);
|
||||
throw aggregate;
|
||||
}
|
||||
};
|
||||
@@ -3323,3 +3323,19 @@ it("follows the remaining release-exposure owner when a sibling has already rele
|
||||
releaseOwnedCleanup(second);
|
||||
expect(failure.cleanupIncomplete).toBe(false);
|
||||
});
|
||||
|
||||
it("drops a released typed resource even while another owner remains unconfirmed", async () => {
|
||||
const { service, desktop, goBinaries } = owners(scan());
|
||||
const typed = new ProviderCleanupError("desktop", ["desktop-root"], {});
|
||||
const opaque = new Error("cannot confirm Go owner closed");
|
||||
desktop.close.mockRejectedValue(typed);
|
||||
goBinaries.close.mockRejectedValue(opaque);
|
||||
const failure = await service.close().catch((cause: unknown) => cause);
|
||||
if (!(failure instanceof ProviderCleanupError))
|
||||
throw new Error("expected typed aggregate");
|
||||
expect(failure.cleanupResources).toEqual(["desktop-root"]);
|
||||
expect(failure.cleanupIncomplete).toBe(true);
|
||||
releaseOwnedCleanup(typed);
|
||||
expect(failure.cleanupIncomplete).toBe(true);
|
||||
expect(failure.cleanupResources).toEqual([]);
|
||||
});
|
||||
@@ -11,6 +11,7 @@ import type { RustBinaryService } from "../rust/RustBinaryService.js";
|
||||
import { parseAnalysisInput } from "../AnalysisInput.js";
|
||||
import { completeProviderEvidence } from "../ProviderOperationExecution.js";
|
||||
import { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import { providerCleanupErrorFromCloseRejections } from "../../domain/analysisErrorCleanup.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisOutputError,
|
||||
@@ -30,7 +31,6 @@ import { recognizeEvidence } from "../../domain/evidenceValidation.js";
|
||||
import { evidenceSubjectFormatSchema } from "../../domain/evidenceSubject.js";
|
||||
import { goBinarySchema } from "../../domain/go/goBinary.js";
|
||||
import { RELEASE_EXPOSURE_PROVIDER } from "../../domain/investigationProviders.js";
|
||||
import { ProviderCleanupError } from "../../domain/providerCleanupError.js";
|
||||
import {
|
||||
scanCredentialMarkers,
|
||||
type CredentialMarkerHit,
|
||||
@@ -557,18 +557,18 @@ const ownerCloseFailure = (
|
||||
): unknown => {
|
||||
const [first] = failures;
|
||||
if (failures.length === 1 && first !== undefined) return first.cause;
|
||||
const typed = failures.flatMap(({ cause }) =>
|
||||
cause instanceof AnalysisError ? [cause] : [],
|
||||
);
|
||||
const resources = failures.flatMap(({ cause }) => {
|
||||
if (cause instanceof AnalysisError) return cause.cleanupResources;
|
||||
return cause instanceof ArtifactReaderFailure
|
||||
? (cause.cleanup?.resources ?? [])
|
||||
: [];
|
||||
});
|
||||
const aggregate = new ProviderCleanupError(
|
||||
return providerCleanupErrorFromCloseRejections(
|
||||
RELEASE_EXPOSURE_PROVIDER.id,
|
||||
[...new Set(resources)],
|
||||
failures.map(({ cause }) => ({
|
||||
cause,
|
||||
cleanupOwner:
|
||||
cause instanceof AnalysisError && cause.carriesCleanup
|
||||
? cause
|
||||
: undefined,
|
||||
...(cause instanceof ArtifactReaderFailure && cause.cleanup !== undefined
|
||||
? { unconfirmedResources: cause.cleanup.resources }
|
||||
: {}),
|
||||
})),
|
||||
{
|
||||
failures: failures.map(({ owner, cause }) => ({
|
||||
owner,
|
||||
@@ -581,21 +581,10 @@ const ownerCloseFailure = (
|
||||
})),
|
||||
},
|
||||
{
|
||||
cause: new AggregateError(
|
||||
failures.map(({ cause }) => cause),
|
||||
`Release exposure cleanup failed: ${failures.map(({ owner }) => owner).join(", ")}.`,
|
||||
),
|
||||
message: `Release exposure cleanup failed: ${failures.map(({ owner }) => owner).join(", ")}.`,
|
||||
operation: RELEASE_EXPOSURE_OPERATION,
|
||||
},
|
||||
);
|
||||
// An owner that already released still accounts for its rejection. An opaque
|
||||
// rejection supplies no release authority and keeps the aggregate incomplete.
|
||||
if (
|
||||
typed.length === failures.length &&
|
||||
typed.every((cause) => cause.carriesCleanup)
|
||||
)
|
||||
aggregate.bindCleanupDependencies(typed);
|
||||
return aggregate;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -131,6 +131,62 @@ export const providerCleanupErrorFromFailures = (
|
||||
},
|
||||
).bindCleanupDependencies(failures);
|
||||
|
||||
/** Compose rejected closes and follow known resource ownership independently of completion. */
|
||||
export const providerCleanupErrorFromCloseRejections = (
|
||||
providerId: string,
|
||||
rejections: readonly {
|
||||
readonly cause: unknown;
|
||||
readonly cleanupOwner?: AnalysisError | undefined;
|
||||
readonly unconfirmedResources?: readonly string[];
|
||||
}[],
|
||||
diagnostics: Readonly<Record<string, JsonValue>>,
|
||||
options: {
|
||||
readonly operation: string;
|
||||
readonly message: string;
|
||||
readonly remediationAction?: string;
|
||||
},
|
||||
): ProviderCleanupError => {
|
||||
const owners = rejections.flatMap(({ cleanupOwner }) =>
|
||||
cleanupOwner === undefined ? [] : [cleanupOwner],
|
||||
);
|
||||
const resources = () => [
|
||||
...new Set(
|
||||
rejections.flatMap(({ cleanupOwner, unconfirmedResources }) => {
|
||||
if (cleanupOwner === undefined) return unconfirmedResources ?? [];
|
||||
return cleanupOwner.cleanupIncomplete
|
||||
? cleanupOwner.cleanupResources
|
||||
: [];
|
||||
}),
|
||||
),
|
||||
];
|
||||
const aggregate = new ProviderCleanupError(
|
||||
providerId,
|
||||
resources(),
|
||||
diagnostics,
|
||||
{
|
||||
operation: options.operation,
|
||||
cause: new AggregateError(
|
||||
rejections.map(({ cause }) => cause),
|
||||
options.message,
|
||||
),
|
||||
...(options.remediationAction === undefined
|
||||
? {}
|
||||
: { remediationAction: options.remediationAction }),
|
||||
},
|
||||
);
|
||||
if (owners.length === rejections.length)
|
||||
return aggregate.bindCleanupDependencies(owners);
|
||||
// Unconfirmed closes keep the aggregate pending. Known owners still account
|
||||
// for their own resources as those resources are released.
|
||||
if (owners.length > 0)
|
||||
aggregate.bindCleanupResourceOwner({
|
||||
get cleanupResources() {
|
||||
return resources();
|
||||
},
|
||||
});
|
||||
return aggregate;
|
||||
};
|
||||
|
||||
/**
|
||||
* Follow an existing live owner's cleanup completion from a wrapper error while
|
||||
* keeping its released resource history empty once that owner finishes. If the
|
||||
|
||||
Reference in new issue
Block a user