mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 13:45:30 +00:00
refactor(providers): share firmware and Flutter cleanup aggregation (#12618)
* refactor(providers): share firmware and Flutter cleanup aggregation * test(firmware): check both cleanup failure records through retry
This commit is contained in:
5 files changed
+59
-27
No files matched your search
@@ -11,8 +11,6 @@
|
||||
"src/desktop/ScreenJudgeProcess.ts": 1,
|
||||
"src/domain/explicitSensitiveFailure.ts": 1,
|
||||
"src/evm/EvmoleInterfaceProvider.ts": 3,
|
||||
"src/firmware/FirmwareProvider.ts": 1,
|
||||
"src/flutter/FlutterBuildProvider.ts": 1,
|
||||
"src/gdb/GdbSessionManager.ts": 2,
|
||||
"src/hopper/BridgeLauncher.ts": 3,
|
||||
"src/hopper/HopperAnalysisProfile.ts": 1,
|
||||
|
||||
@@ -16,7 +16,10 @@ import {
|
||||
type FirmwarePartialObservation,
|
||||
} from "../domain/firmware/firmwareAnalysis.js";
|
||||
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import { analysisErrorWithCleanupDependencies } from "../domain/analysisErrorCleanup.js";
|
||||
import {
|
||||
analysisErrorWithCleanupDependencies,
|
||||
providerCleanupErrorFromFailures,
|
||||
} from "../domain/analysisErrorCleanup.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisOutputError,
|
||||
@@ -101,9 +104,9 @@ const combineCleanupFailures = (
|
||||
failures: readonly AnalysisError[],
|
||||
): AnalysisError | undefined => {
|
||||
if (failures.length < 2) return failures[0];
|
||||
return new ProviderCleanupError(
|
||||
return providerCleanupErrorFromFailures(
|
||||
"firmware",
|
||||
failures.flatMap((failure) => [...failure.cleanupResources]),
|
||||
failures,
|
||||
{
|
||||
reason: "Multiple owned firmware resources could not be cleaned",
|
||||
failures: failures.map((failure) => ({
|
||||
@@ -119,8 +122,8 @@ const combineCleanupFailures = (
|
||||
reason: failure.diagnostics?.reason ?? failure.message,
|
||||
})),
|
||||
},
|
||||
{ operation: "close_firmware", cause: new AggregateError(failures) },
|
||||
).bindCleanupDependencies(failures);
|
||||
{ operation: "close_firmware" },
|
||||
);
|
||||
};
|
||||
const waitForPredecessor = (
|
||||
predecessor: Promise<void>,
|
||||
|
||||
@@ -9,7 +9,10 @@ import {
|
||||
type ArtifactEntry,
|
||||
ZipArtifactReader,
|
||||
} from "../resources/index.js";
|
||||
import { analysisErrorWithCleanupDependencies } from "../domain/analysisErrorCleanup.js";
|
||||
import {
|
||||
analysisErrorWithCleanupDependencies,
|
||||
providerCleanupErrorFromFailures,
|
||||
} from "../domain/analysisErrorCleanup.js";
|
||||
import { analysisErrorWithCancellation } from "../domain/analysisErrorCancellation.js";
|
||||
import { regularFileCancellation } from "../filesystem/OwnedRegularFile.js";
|
||||
import { createHash } from "node:crypto";
|
||||
@@ -575,7 +578,7 @@ export class FlutterBuildProvider {
|
||||
const primary = mapOwnedIoFailure(operation, cause, root);
|
||||
const released = await this.discardRoot(root);
|
||||
if (!released)
|
||||
throw this.withCleanup(
|
||||
throw analysisErrorWithCleanupDependencies(
|
||||
primary,
|
||||
this.cleanupError(root, operation),
|
||||
operation,
|
||||
@@ -691,14 +694,6 @@ export class FlutterBuildProvider {
|
||||
return error;
|
||||
}
|
||||
|
||||
private withCleanup(
|
||||
primary: AnalysisError,
|
||||
cleanup: AnalysisError,
|
||||
operation: string,
|
||||
): AnalysisError {
|
||||
return analysisErrorWithCleanupDependencies(primary, cleanup, operation);
|
||||
}
|
||||
|
||||
/** Stop admission and drain active snapshots before attempting retained cleanup. */
|
||||
async close(): Promise<void> {
|
||||
await this.operations.close();
|
||||
@@ -715,9 +710,9 @@ export class FlutterBuildProvider {
|
||||
}
|
||||
if (failures.length === 1) throw failures[0];
|
||||
if (failures.length > 1)
|
||||
throw new ProviderCleanupError(
|
||||
throw providerCleanupErrorFromFailures(
|
||||
FLUTTER_PROVIDER_IDENTITY.id,
|
||||
failures.flatMap((failure) => failure.cleanupResources),
|
||||
failures,
|
||||
{
|
||||
reason: failures
|
||||
.map((failure) => failure.diagnostics?.reason ?? failure.message)
|
||||
@@ -727,11 +722,8 @@ export class FlutterBuildProvider {
|
||||
return Array.isArray(roots) ? roots : [];
|
||||
}),
|
||||
},
|
||||
{
|
||||
cause: new AggregateError(failures),
|
||||
operation,
|
||||
},
|
||||
).bindCleanupDependencies(failures);
|
||||
{ operation },
|
||||
);
|
||||
}
|
||||
|
||||
async execute(
|
||||
@@ -849,7 +841,13 @@ export class FlutterBuildProvider {
|
||||
);
|
||||
if (cleanup !== undefined) {
|
||||
if (!result.ok)
|
||||
return err(this.withCleanup(result.error, cleanup, request.operation));
|
||||
return err(
|
||||
analysisErrorWithCleanupDependencies(
|
||||
result.error,
|
||||
cleanup,
|
||||
request.operation,
|
||||
),
|
||||
);
|
||||
cleanup.retainPartialObservation(
|
||||
createAnalysisExecutionEvidence(
|
||||
request.operation,
|
||||
|
||||
@@ -2137,6 +2137,14 @@ it("retains mixed-root cleanup diagnostics and releases aggregate errors only af
|
||||
aggregate = cause;
|
||||
}
|
||||
expect(aggregate).toMatchObject({
|
||||
operation: "close_flutter_build",
|
||||
cause: expect.objectContaining({
|
||||
errors: expect.arrayContaining(
|
||||
roots.map((root) =>
|
||||
expect.objectContaining({ cleanupResources: [root] }),
|
||||
),
|
||||
),
|
||||
}),
|
||||
cleanupIncomplete: true,
|
||||
cleanupResources: expect.arrayContaining(roots),
|
||||
diagnostics: {
|
||||
|
||||
@@ -472,7 +472,8 @@ it.each(["descriptor-first", "workspace-first"])(
|
||||
const root = await createTestTempDirectory("rea-firmware-mixed-owner-");
|
||||
const path = join(root, "input.bin");
|
||||
await writeFile(path, "firmware bytes");
|
||||
fault.selected = "report.json";
|
||||
// Keep the retained descriptor outside the workspace so either owner can release first.
|
||||
fault.selected = path;
|
||||
let workspaceBlocked = true;
|
||||
let workspacePath = "";
|
||||
const close = PrivateRuntimeRoot.prototype.close;
|
||||
@@ -500,7 +501,27 @@ it.each(["descriptor-first", "workspace-first"])(
|
||||
});
|
||||
expect(blocked).toMatchObject({
|
||||
ok: false,
|
||||
error: { cleanupIncomplete: true },
|
||||
error: {
|
||||
operation: "close_firmware",
|
||||
cleanupIncomplete: true,
|
||||
cause: expect.any(AggregateError),
|
||||
diagnostics: {
|
||||
failures: expect.arrayContaining([
|
||||
{
|
||||
engine: "firmware",
|
||||
operation: "close_firmware",
|
||||
resources: [path],
|
||||
reason: "controlled firmware descriptor close failure",
|
||||
},
|
||||
{
|
||||
engine: "binwalk",
|
||||
operation: "inspect_firmware_regions",
|
||||
resources: [workspacePath],
|
||||
reason: "controlled workspace cleanup failure",
|
||||
},
|
||||
]),
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(fault.handles).toHaveLength(1);
|
||||
if (order === "descriptor-first") fault.blocked.clear();
|
||||
@@ -508,6 +529,10 @@ it.each(["descriptor-first", "workspace-first"])(
|
||||
const retry = await provider.close().catch((cause: unknown) => cause);
|
||||
expect(retry).toBeInstanceOf(AnalysisError);
|
||||
expect(result.error.cleanupIncomplete).toBe(true);
|
||||
if (!blocked.ok)
|
||||
expect(blocked.error.cleanupResources).toEqual([
|
||||
order === "descriptor-first" ? workspacePath : path,
|
||||
]);
|
||||
if (order === "workspace-first")
|
||||
await expect(access(workspacePath)).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
|
||||
Reference in new issue
Block a user