chore: preserve current main archive typing and runtime fixes
This commit is contained in:
@@ -100,18 +100,24 @@ export class AnalysisOutputError extends AnalysisError {
|
||||
export class AnalysisCapabilityUnavailableError extends AnalysisError {
|
||||
readonly _tag = "AnalysisCapabilityUnavailableError";
|
||||
override readonly userMessage: string | undefined;
|
||||
/** Incomplete cleanup must settle before the operation can be retried. */
|
||||
readonly retryable: boolean;
|
||||
|
||||
constructor(
|
||||
readonly providerId: string,
|
||||
readonly operation: string,
|
||||
readonly reason: string,
|
||||
options?: AnalysisErrorOptions & { readonly userMessage?: string },
|
||||
options?: AnalysisErrorOptions & {
|
||||
readonly userMessage?: string;
|
||||
readonly retryable?: boolean;
|
||||
},
|
||||
) {
|
||||
super(
|
||||
`Provider ${providerId} cannot execute ${operation}: ${reason}`,
|
||||
options,
|
||||
);
|
||||
this.userMessage = options?.userMessage;
|
||||
this.retryable = options?.retryable === true && !this.cleanupIncomplete;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
AnalysisAccessDeniedError,
|
||||
AnalysisArtifactChangedError,
|
||||
AnalysisCapabilityUnavailableError,
|
||||
AnalysisInputError,
|
||||
AnalysisUnsupportedTargetError,
|
||||
AnalysisResourceConstraintError,
|
||||
@@ -33,6 +34,8 @@ import type { AnalysisErrorProjection } from "./analysisErrorProjection.js";
|
||||
export const analysisErrorRemediationAction = (
|
||||
error: AnalysisError,
|
||||
): string => {
|
||||
if (error instanceof AnalysisCapabilityUnavailableError && error.retryable)
|
||||
return "Review details.reason, then retry the same analysis after the condition clears.";
|
||||
if (error instanceof EvidenceFileError && error.published !== undefined)
|
||||
return "Use the published file at details.published_path and resolve the reported staging cleanup failure.";
|
||||
if (error instanceof AnalysisSnapshotMismatchError)
|
||||
@@ -112,6 +115,8 @@ export const analysisErrorRemediationAction = (
|
||||
export const analysisErrorCategory = (
|
||||
error: AnalysisError,
|
||||
): AnalysisErrorProjection["category"] => {
|
||||
if (error instanceof AnalysisCapabilityUnavailableError && error.retryable)
|
||||
return "unavailable";
|
||||
if (
|
||||
error instanceof BinaryTargetError &&
|
||||
error.constraint === "load_selection_rejected"
|
||||
@@ -220,6 +225,8 @@ export const analysisErrorUserMessage = (error: AnalysisError): string => {
|
||||
const hopperMessage = hopperErrorUserMessage(error);
|
||||
if (hopperMessage !== undefined) return hopperMessage;
|
||||
if (error.userMessage !== undefined) return error.userMessage;
|
||||
if (error instanceof AnalysisCapabilityUnavailableError && error.retryable)
|
||||
return "Required runtime controls are unavailable for this attempt.";
|
||||
const standardMessage = standardErrorMessage(error._tag);
|
||||
if (standardMessage !== undefined) return standardMessage;
|
||||
if (error instanceof ArtifactOperationError) return artifactMessage(error);
|
||||
|
||||
@@ -25,6 +25,91 @@ import { ProviderSelectionError } from "./providerSelectionError.js";
|
||||
import { analysisErrorProjectionSchema } from "../contracts/errorSchemas.js";
|
||||
import { nativeCallPartialObservationSchema } from "./native/nativeCallPartialObservation.js";
|
||||
|
||||
describe("capability failure retry disposition", () => {
|
||||
it.each([
|
||||
{ options: {}, retryable: false, category: "unsupported_provider" },
|
||||
{
|
||||
options: { retryable: false },
|
||||
retryable: false,
|
||||
category: "unsupported_provider",
|
||||
},
|
||||
{ options: { retryable: true }, retryable: true, category: "unavailable" },
|
||||
] as const)(
|
||||
"preserves the producer's $retryable disposition",
|
||||
({ options, retryable, category }) => {
|
||||
const reason = "Native self-test failed with a sharing violation";
|
||||
const projected = projectAnalysisError(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
"fixture-provider",
|
||||
"inspect",
|
||||
reason,
|
||||
options,
|
||||
),
|
||||
);
|
||||
expect(projected).toMatchObject({
|
||||
code: "capability_unavailable",
|
||||
category,
|
||||
retryable,
|
||||
details: { reason },
|
||||
});
|
||||
if (retryable) {
|
||||
expect(projected.message).toBe(
|
||||
"Required runtime controls are unavailable for this attempt.",
|
||||
);
|
||||
expect(projected.remediation.action).toContain(
|
||||
"retry the same analysis",
|
||||
);
|
||||
}
|
||||
expect(analysisErrorProjectionSchema.safeParse(projected).success).toBe(
|
||||
true,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("preserves a caller-selected message for a retryable failure", () => {
|
||||
expect(
|
||||
projectAnalysisError(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
"fixture-provider",
|
||||
"inspect",
|
||||
"temporary failure",
|
||||
{
|
||||
retryable: true,
|
||||
userMessage: "Selected runtime diagnostic",
|
||||
},
|
||||
),
|
||||
).message,
|
||||
).toBe("Selected runtime diagnostic");
|
||||
});
|
||||
|
||||
it("retains cleanup ownership before allowing a transient operation to retry", () => {
|
||||
expect(
|
||||
projectAnalysisError(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
"fixture-provider",
|
||||
"inspect",
|
||||
"temporary failure",
|
||||
{
|
||||
retryable: true,
|
||||
cleanup: {
|
||||
reason: "owned handle is still live",
|
||||
resources: ["native-owner"],
|
||||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
).toMatchObject({
|
||||
code: "cleanup_incomplete",
|
||||
retryable: false,
|
||||
details: {
|
||||
cleanup: "incomplete",
|
||||
resources: ["native-owner"],
|
||||
execution_failure: "capability_unavailable",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("projects a published file receipt alongside retained cleanup failure", () => {
|
||||
const projected = projectAnalysisError(
|
||||
new EvidenceFileError("write", "io", {
|
||||
|
||||
@@ -83,6 +83,8 @@ export const projectAnalysisError = (
|
||||
message: analysisErrorUserMessage(error),
|
||||
retryable:
|
||||
RETRYABLE_CODES.has(code) ||
|
||||
(error instanceof AnalysisCapabilityUnavailableError &&
|
||||
error.retryable) ||
|
||||
(code === "resource_constraint" &&
|
||||
error instanceof AnalysisResourceConstraintError &&
|
||||
error.resource === "capacity"),
|
||||
|
||||
@@ -73,6 +73,12 @@ import {
|
||||
androidViewRequestSchema,
|
||||
androidManifestViewItemSchema,
|
||||
} from "./androidPackageView.js";
|
||||
import {
|
||||
projectDartAotView,
|
||||
dartAotSummarySchema,
|
||||
dartAotViewRequestSchema,
|
||||
dartAotViewContextSchema,
|
||||
} from "./dartAotView.js";
|
||||
|
||||
/** Public name of the selected-view workflow. */
|
||||
export const INSPECT_ANALYSIS_VIEW_OPERATION = "inspect_analysis_view" as const;
|
||||
@@ -190,6 +196,7 @@ export const analysisViewRequestSchema = z.discriminatedUnion("kind", [
|
||||
apiSurfaceViewSchema,
|
||||
captureViewRequestSchema,
|
||||
qlogViewRequestSchema,
|
||||
dartAotViewRequestSchema,
|
||||
]);
|
||||
|
||||
// The application owns admission and authenticated Evidence parsing. SDK and
|
||||
@@ -305,6 +312,7 @@ const viewResultBase = {
|
||||
"inspect_managed_artifact",
|
||||
"inspect_web_network_capture",
|
||||
"inspect_android_package",
|
||||
"inspect_dart_aot",
|
||||
]),
|
||||
parent_digest: digestSchema,
|
||||
view_digest: digestSchema,
|
||||
@@ -376,6 +384,13 @@ export const androidPackageSummaryViewResultSchema = z.strictObject({
|
||||
summary: androidPackageSummarySchema,
|
||||
});
|
||||
|
||||
/** Exact snapshot and pool-coverage carrier for selected AOT delivery. */
|
||||
export const dartAotSummaryViewResultSchema = z.strictObject({
|
||||
...summaryViewResultBase,
|
||||
parent_operation: z.literal("inspect_dart_aot"),
|
||||
summary: dartAotSummarySchema,
|
||||
});
|
||||
|
||||
/** Projected facts for one selected view of retained analysis Evidence. */
|
||||
export const analysisViewResultSchema = z.discriminatedUnion("kind", [
|
||||
z.strictObject({
|
||||
@@ -400,6 +415,7 @@ export const analysisViewResultSchema = z.discriminatedUnion("kind", [
|
||||
managedSummarySchema,
|
||||
captureSummarySchema,
|
||||
androidPackageSummarySchema,
|
||||
dartAotSummarySchema,
|
||||
]),
|
||||
}),
|
||||
z.strictObject({
|
||||
@@ -470,6 +486,14 @@ export const analysisViewResultSchema = z.discriminatedUnion("kind", [
|
||||
...viewResultBase,
|
||||
parent_operation: z.literal("inspect_android_package"),
|
||||
}),
|
||||
z.strictObject({
|
||||
kind: z.literal("dart-aot"),
|
||||
view: dartAotViewRequestSchema,
|
||||
items: z.array(z.string()),
|
||||
...viewResultBase,
|
||||
...dartAotViewContextSchema.shape,
|
||||
parent_operation: z.literal("inspect_dart_aot"),
|
||||
}),
|
||||
z.strictObject({
|
||||
kind: z.literal("inventory"),
|
||||
view: inventoryViewSchema,
|
||||
@@ -549,6 +573,10 @@ export type UnsignedAnalysisView =
|
||||
| Omit<
|
||||
Extract<AnalysisViewResult, { readonly kind: "android" }>,
|
||||
"view_digest"
|
||||
>
|
||||
| Omit<
|
||||
Extract<AnalysisViewResult, { readonly kind: "dart-aot" }>,
|
||||
"view_digest"
|
||||
>;
|
||||
|
||||
/** Attach the content digest that must change when projected bytes change. */
|
||||
@@ -594,7 +622,7 @@ const unsupportedParent = (
|
||||
new AnalysisUnsupportedTargetError(
|
||||
INSPECT_ANALYSIS_VIEW_OPERATION,
|
||||
parentArtifactPath(parent),
|
||||
`Parent Evidence operation ${JSON.stringify(parent.operation)} does not support analysis views. Use completed binary layout, JavaScript application, native function, artifact inventory/inspection, WASM, EVM, managed artifact, Android package, or web network capture Evidence.`,
|
||||
`Parent Evidence operation ${JSON.stringify(parent.operation)} does not support analysis views. Use completed binary layout, JavaScript application, native function, artifact inventory/inspection, WASM, EVM, managed artifact, Android package, Dart AOT, or web network capture Evidence.`,
|
||||
);
|
||||
|
||||
const parentArtifactPath = (parent: AnalysisViewParent): string => {
|
||||
@@ -624,6 +652,7 @@ const retainedViewProjectors = new Map<string, typeof projectWasmArtifactView>([
|
||||
["inspect_evm_interface", projectEvmInterfaceView],
|
||||
["inspect_managed_artifact", projectManagedArtifactView],
|
||||
["inspect_android_package", projectAndroidPackageView],
|
||||
["inspect_dart_aot", projectDartAotView],
|
||||
["inspect_artifact", projectArtifactInventoryView],
|
||||
["inventory_artifact", projectArtifactInventoryView],
|
||||
]);
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
import { z } from "zod";
|
||||
import type { AnalysisError } from "../analysisErrorBase.js";
|
||||
import { flutterResultSchemas } from "../flutter/flutterBuildAnalysis.js";
|
||||
import { analysisInputErrorFromIssues } from "../inputIssueProjection.js";
|
||||
import { err, ok, type Result } from "../result.js";
|
||||
import {
|
||||
analysisViewInputError,
|
||||
type AnalysisViewParent,
|
||||
type AnalysisViewRequest,
|
||||
type UnsignedAnalysisView,
|
||||
} from "./analysisView.js";
|
||||
import {
|
||||
completeWithinViewCoverage,
|
||||
pageViewCoverage,
|
||||
} from "./analysisViewCoverage.js";
|
||||
|
||||
const aotSchema = flutterResultSchemas.inspect_dart_aot;
|
||||
|
||||
/** Snapshot identity and original coverage, without unrelated string inventories. */
|
||||
export const dartAotSummarySchema = aotSchema.extend({
|
||||
string_pool: aotSchema.shape.string_pool
|
||||
.omit({ package_uris: true, dart_uris: true, class_like_tokens: true })
|
||||
.extend({
|
||||
returned_counts: z.strictObject({
|
||||
package_uris: z.number().int().nonnegative(),
|
||||
dart_uris: z.number().int().nonnegative(),
|
||||
class_like_tokens: z.number().int().nonnegative(),
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
/** Pages of the producer-returned strings, preserving original order and scope. */
|
||||
export const dartAotViewRequestSchema = z.strictObject({
|
||||
kind: z.literal("dart-aot"),
|
||||
collection: z.enum(["package_uris", "dart_uris", "class_like_tokens"]),
|
||||
offset: z.number().int().nonnegative().default(0),
|
||||
limit: z.number().int().positive().default(64),
|
||||
});
|
||||
|
||||
export const dartAotViewContextSchema = z.strictObject({
|
||||
abi: aotSchema.shape.abi,
|
||||
libapp: aotSchema.shape.libapp,
|
||||
source_coverage: aotSchema.shape.coverage,
|
||||
string_pool: dartAotSummarySchema.shape.string_pool,
|
||||
});
|
||||
|
||||
/** Reuse authenticated AOT Evidence without opening the APK or rescanning its ELF. */
|
||||
export const projectDartAotView = (
|
||||
parent: AnalysisViewParent,
|
||||
view: AnalysisViewRequest,
|
||||
): Result<UnsignedAnalysisView, AnalysisError> => {
|
||||
if (view.kind !== "summary" && view.kind !== "dart-aot")
|
||||
return err(
|
||||
analysisViewInputError([
|
||||
{
|
||||
path: ["view"],
|
||||
reason: "invalid_value",
|
||||
message: "Dart AOT Evidence supports summary and string-pool pages.",
|
||||
},
|
||||
]),
|
||||
);
|
||||
const parsed = aotSchema.safeParse(parent.normalizedResult);
|
||||
if (!parsed.success)
|
||||
return err(
|
||||
analysisInputErrorFromIssues(
|
||||
"inspect_analysis_view",
|
||||
parsed.error.issues.map((issue) => ({
|
||||
...issue,
|
||||
path: ["source", "normalized_result", ...issue.path],
|
||||
})),
|
||||
{ source: { normalized_result: parent.normalizedResult } },
|
||||
{ cause: parsed.error },
|
||||
),
|
||||
);
|
||||
const report = parsed.data;
|
||||
const { package_uris, dart_uris, class_like_tokens, ...pool } =
|
||||
report.string_pool;
|
||||
const string_pool = {
|
||||
...pool,
|
||||
returned_counts: {
|
||||
package_uris: package_uris.length,
|
||||
dart_uris: dart_uris.length,
|
||||
class_like_tokens: class_like_tokens.length,
|
||||
},
|
||||
};
|
||||
const shared = {
|
||||
parent_evidence_id: parent.evidenceId,
|
||||
parent_operation: "inspect_dart_aot" as const,
|
||||
parent_digest: parent.evidenceId.slice(3),
|
||||
artifact: { path: report.target.path, sha256: report.target.sha256 },
|
||||
limitations: [...parent.limitations],
|
||||
unknowns: [
|
||||
"String-pool entries are byte-pattern observations, not recovered typed classes or functions.",
|
||||
"Counts ending in _at_least remain lower bounds; exhausting returned strings does not establish a complete snapshot inventory.",
|
||||
...(parent.subject == null
|
||||
? [
|
||||
"The parent has no recorded subject; its normalized target identity cannot be cross-checked against a subject digest.",
|
||||
]
|
||||
: []),
|
||||
],
|
||||
};
|
||||
if (view.kind === "summary")
|
||||
return ok({
|
||||
kind: "summary",
|
||||
view,
|
||||
...shared,
|
||||
summary: { ...report, string_pool },
|
||||
coverage: completeWithinViewCoverage(1, 1),
|
||||
});
|
||||
const collection = report.string_pool[view.collection];
|
||||
const items = collection.slice(view.offset, view.offset + view.limit);
|
||||
return ok({
|
||||
kind: "dart-aot",
|
||||
view,
|
||||
...shared,
|
||||
items,
|
||||
abi: report.abi,
|
||||
libapp: report.libapp,
|
||||
source_coverage: report.coverage,
|
||||
string_pool,
|
||||
coverage: pageViewCoverage(view.offset, items.length, collection.length),
|
||||
});
|
||||
};
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { ZipPackageFormat } from "./zipPackageFormat.js";
|
||||
|
||||
/** Provider-neutral CPU families detected from supported executable headers. */
|
||||
export const BINARY_ARCHITECTURES = [
|
||||
"x86",
|
||||
@@ -167,19 +169,7 @@ export type BinaryTarget =
|
||||
| (BinaryTargetIdentity &
|
||||
NonExecutableMetadata & {
|
||||
readonly kind: "archive";
|
||||
readonly format:
|
||||
| "zip"
|
||||
| "ipa"
|
||||
| "apk"
|
||||
| "msix"
|
||||
| "appx"
|
||||
| "hap"
|
||||
| "hsp"
|
||||
| "app-pack"
|
||||
| "asar"
|
||||
| "ines"
|
||||
| "dmg"
|
||||
| "pkg";
|
||||
readonly format: ZipPackageFormat | "asar" | "ines" | "dmg" | "pkg";
|
||||
})
|
||||
| (BinaryTargetIdentity &
|
||||
NonExecutableMetadata & {
|
||||
|
||||
@@ -30,6 +30,12 @@ export const flutterInputSchemas = {
|
||||
}),
|
||||
} as const;
|
||||
|
||||
/** Retained delivery is selected independently of the provider's ABI request. */
|
||||
export const dartAotInspectionInputSchema =
|
||||
flutterInputSchemas.inspect_dart_aot.extend({
|
||||
detail: z.enum(["complete", "summary"]).optional(),
|
||||
});
|
||||
|
||||
/** Supported Flutter-backed operations. */
|
||||
export type FlutterOperation = keyof typeof flutterInputSchemas;
|
||||
/** Validated Flutter requests carry their selected operation. */
|
||||
|
||||
Reference in New Issue
Block a user