mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 05:51:06 +00:00
fix(process): report denied inspection as typed cleanup failures (#9261)
* fix(process): report denied inspection as typed cleanup failures Preserve the native ps diagnostic through owned-worker cleanup and finalize one-shot JavaScript analysis before Evidence delivery. Retain mandatory inspection and existing cleanup authority. Preserve the inspector diagnostic when the initial process-table read succeeds but pre-signal revalidation fails, and remove the unreachable typed-error branch so retained artifact retry failures project through the existing cleanup contract. * fix(resources): preserve independent close failure ownership * fix(cli): retain cleanup recovery and nested close evidence * refactor(providers): classify rejected closes at the shared boundary * test(cli): preserve bundle metadata and physical inspection failures * fix(cli): preserve the JavaScript failure envelope after finalization * test(cli): validate the JavaScript error envelope at its boundary * fix(providers): preserve unnamed close failure resources * fix(cli): retain invocation owners through outer cleanup * test(cli): distinguish reported cleanup failures from uncaught errors * fix(cli): compose each runtime’s declared cleanup owners * test(cli): preserve the original cleanup rejection * test(cli): allow cleanup retry recovery after a reported failure * fix(cli): report final cleanup after returned results * fix(cli): preserve launcher executable mode * test(cli): retain invocation cleanup in file sessions --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
1 parent
891a999a12
commit
f5055cd2ed
33 files changed
+1501
-111
No files matched your search
@@ -4,22 +4,24 @@ import type { AnalysisViewRequest } from "../domain/analysisView/analysisViewReq
|
||||
import { publishCliAnalysisEvidence } from "./analysisEvidenceDelivery.js";
|
||||
import { JAVASCRIPT_APPLICATION_PROVIDER } from "../domain/investigationProviders.js";
|
||||
import { createProgressReporter } from "../ports/ProgressReporter.js";
|
||||
import {
|
||||
ArtifactReaderFailure,
|
||||
ArtifactResourceScope,
|
||||
} from "../resources/index.js";
|
||||
import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js";
|
||||
import { ArtifactResourceScope } from "../resources/index.js";
|
||||
import { analysisErrorWithCleanupDependencies } from "../domain/analysisErrorCleanup.js";
|
||||
import { completeProviderEvidence } from "../application/ProviderOperationExecution.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
||||
import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js";
|
||||
import { javaScriptSourcePathsSchema } from "../domain/javascript/javascriptSourceSelection.js";
|
||||
import { parseCliJsonInput } from "./cliJsonInput.js";
|
||||
import { writeCliProgressLine } from "./cliProgress.js";
|
||||
import { ownCliProcessResource } from "./cliResources.js";
|
||||
import type { AnalysisCallerLifetime } from "../domain/analysisErrorBase.js";
|
||||
import { finishAnalysisCommand } from "./finishAnalysisCommand.js";
|
||||
import { projectCliAnalysisResult } from "./projectCliAnalysisResult.js";
|
||||
import { classifyProviderFailure } from "../providers/classifyProviderFailure.js";
|
||||
import { artifactCloseFailureDialect } from "../providers/artifactCloseFailure.js";
|
||||
|
||||
const OPERATION = "analyze_javascript_application";
|
||||
const CLI_ERROR = "JavaScript application analysis failed";
|
||||
|
||||
/**
|
||||
* Combine repeated `--source-path` values with `--source-paths-json`, an inline
|
||||
@@ -57,14 +59,16 @@ export const cliJavaScriptSourcePaths = async (
|
||||
};
|
||||
|
||||
/**
|
||||
* One parked JavaScript worker for one CLI host. A healthy worker stays
|
||||
* parked between that host's commands. Independent hosts do not share it.
|
||||
* JavaScript resources for one CLI host. Reusable hosts park healthy workers;
|
||||
* invocation hosts finalize them before returning analysis. Hosts do not share scopes.
|
||||
*/
|
||||
export class CliJavaScriptAnalysisHost {
|
||||
#retainedScope: ArtifactResourceScope | undefined;
|
||||
/** One shutdown shared by the exit callback and the dispatch `finally`. */
|
||||
/** Concurrent callers share one shutdown attempt; failed close stays retryable. */
|
||||
#closing: Promise<void> | undefined;
|
||||
|
||||
constructor(readonly callerLifetime: AnalysisCallerLifetime = "continuing") {}
|
||||
|
||||
scope(): ArtifactResourceScope {
|
||||
this.#retainedScope ??= new ArtifactResourceScope();
|
||||
return this.#retainedScope;
|
||||
@@ -123,39 +127,68 @@ export const runCliJavaScriptApplicationAnalysis = async (
|
||||
{ minimumIntervalMs: 0 },
|
||||
);
|
||||
const resources = host.scope();
|
||||
const result = await analyzeJavaScriptApplication(input, resources, {
|
||||
let result = await analyzeJavaScriptApplication(input, resources, {
|
||||
sourceAnalysis: javascriptSourceAnalysis,
|
||||
environment,
|
||||
progress,
|
||||
...(signal === undefined ? {} : { signal }),
|
||||
});
|
||||
let completedBeforeCleanup:
|
||||
| ReturnType<typeof completeProviderEvidence>
|
||||
| undefined;
|
||||
try {
|
||||
// Retry failed owners without stopping a healthy parked worker.
|
||||
await resources.retryCleanup();
|
||||
} catch (cause: unknown) {
|
||||
const cleanup = ArtifactReaderFailure.cleanupObservation(
|
||||
const failure = classifyProviderFailure(
|
||||
cause,
|
||||
"JavaScript application resources",
|
||||
);
|
||||
const failure = new ProviderCleanupError(
|
||||
JAVASCRIPT_APPLICATION_PROVIDER.id,
|
||||
cleanup.resources,
|
||||
{ reason: cleanup.reason },
|
||||
{ cause, operation: "analyze_javascript_application" },
|
||||
artifactCloseFailureDialect(
|
||||
JAVASCRIPT_APPLICATION_PROVIDER.id,
|
||||
OPERATION,
|
||||
"JavaScript application resources",
|
||||
),
|
||||
);
|
||||
const completed = result.ok
|
||||
? completeProviderEvidence(result.value, signal)
|
||||
: result;
|
||||
if (completed.ok) failure.retainPartialObservation(completed.value);
|
||||
return cliError(
|
||||
completed.ok
|
||||
if (completed.ok) {
|
||||
completedBeforeCleanup = completed;
|
||||
failure.retainPartialObservation(completed.value);
|
||||
}
|
||||
result = {
|
||||
ok: false,
|
||||
error: completed.ok
|
||||
? failure
|
||||
: analysisErrorWithCleanupFailure(
|
||||
: analysisErrorWithCleanupDependencies(
|
||||
completed.error,
|
||||
failure,
|
||||
"analyze_javascript_application",
|
||||
),
|
||||
};
|
||||
}
|
||||
if (host.callerLifetime === "invocation") {
|
||||
const finalized = await finishAnalysisCommand(
|
||||
async () => result,
|
||||
host,
|
||||
JAVASCRIPT_APPLICATION_PROVIDER.id,
|
||||
OPERATION,
|
||||
signal ?? new AbortController().signal,
|
||||
undefined,
|
||||
{
|
||||
recoverResolvedCleanup: () =>
|
||||
completedBeforeCleanup?.ok ? completedBeforeCleanup.value : undefined,
|
||||
},
|
||||
);
|
||||
const output = finalized.ok
|
||||
? finalized
|
||||
: { ok: false as const, error: { error: CLI_ERROR, ...finalized.error } };
|
||||
return delivery === undefined
|
||||
? projectCliAnalysisResult(output)
|
||||
: publishCliAnalysisEvidence(output, {
|
||||
...delivery,
|
||||
operation: OPERATION,
|
||||
signal: signal ?? new AbortController().signal,
|
||||
});
|
||||
}
|
||||
const completed = result.ok
|
||||
? completeProviderEvidence(result.value, signal)
|
||||
@@ -177,7 +210,7 @@ export const runCliJavaScriptApplicationAnalysis = async (
|
||||
const cliError = (
|
||||
error: Parameters<typeof projectAnalysisError>[0],
|
||||
): JsonValue => ({
|
||||
error: "JavaScript application analysis failed",
|
||||
error: CLI_ERROR,
|
||||
...projectAnalysisError(error),
|
||||
});
|
||||
|
||||
@@ -231,7 +264,10 @@ export const javaScriptApplicationCliProjection = (target: string) =>
|
||||
* delivering Evidence as the caller selected.
|
||||
*/
|
||||
export const runJavaScriptApplicationCommand =
|
||||
(environment: Readonly<Record<string, string | undefined>>) =>
|
||||
(
|
||||
environment: Readonly<Record<string, string | undefined>>,
|
||||
host: CliJavaScriptAnalysisHost = processJavaScriptAnalysis,
|
||||
) =>
|
||||
async (
|
||||
input: object & { readonly source_paths?: readonly string[] | undefined },
|
||||
{
|
||||
@@ -258,5 +294,6 @@ export const runJavaScriptApplicationCommand =
|
||||
environment,
|
||||
signal,
|
||||
delivery,
|
||||
host,
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user