diff --git a/src/domain/android/androidApplication.ts b/src/domain/android/androidApplication.ts index 2659316a23..e28c03b6bf 100644 --- a/src/domain/android/androidApplication.ts +++ b/src/domain/android/androidApplication.ts @@ -1,14 +1,8 @@ -import { - bridgeCandidateCoverageSchema, - projectCartesianCandidates, -} from "../bridgeCandidateProjection.js"; +import { bridgeCandidateCoverageSchema } from "../bridgeCandidateProjection.js"; import { z } from "zod"; import { AnalysisInputError } from "../analysisErrorCore.js"; -import { - hasCompleteInventoryCoverage, - type ParsedInventorySet, -} from "../artifactInventoryEvidence.js"; +import type { ParsedInventorySet } from "../artifactInventoryEvidence.js"; import { digestSchema, prefixedDigestSchema } from "../digests.js"; import { digestCanonicalValue } from "../canonicalDigest.js"; import { nativeRuntimeConvention } from "../nativeConvention.js"; @@ -17,7 +11,9 @@ import { projectedComponentSchema, projectedInventoryEntries, projectedFileComponents, + projectManagedNativeCandidates, projectionCoverage, + projectionCoverageSchema, projectionEvidenceIdSchema, unavailableComponentSchema, } from "../mobileApplicationGraphProjection.js"; @@ -62,11 +58,7 @@ export const androidApplicationProjectionResultSchema = z.strictObject({ ] as const), ), bridge_candidate_coverage: bridgeCandidateCoverageSchema, - coverage: z.strictObject({ - status: z.enum(["complete-within-inventory", "partial"]), - // Count completeness is separate from the declared coverage status. - inventory_complete: z.boolean(), - }), + coverage: projectionCoverageSchema, limitations: z.array(z.string()), }); @@ -102,18 +94,21 @@ export const projectAndroidInventory = ( const unavailable = entries.flatMap(({ unavailable }) => unavailable === undefined ? [] : [unavailable], ); - const classified = classify(all); - const bridgeProjection = bridgeCandidates( - [...classified.dex, ...classified.jvm_classes], - classified.native_libraries, + const components = classify(all); + const bridgeProjection = projectManagedNativeCandidates( + [...components.dex, ...components.jvm_classes], + components.native_libraries, + bridgeBasis, + ); + const { coverage, sourceLimitations, bridgeLimitations } = projectionCoverage( + inventory, + bridgeProjection.coverage, + unavailable.length, ); - const components = classified; const limitations = [ ...unresolved, ...inventory.limitations, - ...(!hasCompleteInventoryCoverage(inventory, "container-entries") - ? ["Source inventory coverage is partial; absence is unknown."] - : []), + ...sourceLimitations, "Manifest, resource, signing, and bytecode semantics require a dedicated Android provider; this projection reports exact inventory paths and hashes only.", "Runtime families are inferred from inventory formats and paths; filename suffixes do not establish valid DEX or JVM class bytes.", "Bridge candidates are path-based hypotheses, not decoded JNI declarations or observed runtime calls.", @@ -127,11 +122,7 @@ export const projectAndroidInventory = ( : [ "No root AndroidManifest.xml occurrence was observed. The APK family comes from the .apk suffix of a ZIP archive, so these bytes may not be an APK.", ]), - ...(bridgeProjection.coverage.status === "partial" - ? [ - `Bridge candidate pairs exceeded the projection safety budget; ${bridgeProjection.coverage.omitted_candidates} hypotheses are omitted. Component arrays still include every component from the supplied inventory pages.`, - ] - : []), + ...bridgeLimitations, ...(unavailable.length > 0 ? [ "Some inventoried occurrences have no authenticated content identity. Their paths and limitations are retained in unavailable_components; component absence is unknown.", @@ -146,14 +137,10 @@ export const projectAndroidInventory = ( .sort(compareUnicodeCodePoints), components, unavailable_components: unavailable, - runtime_families: runtimeFamilies(classified), + runtime_families: runtimeFamilies(components), bridge_candidates: bridgeProjection.candidates, bridge_candidate_coverage: bridgeProjection.coverage, - coverage: projectionCoverage( - inventory, - bridgeProjection.coverage.status === "complete" && - unavailable.length === 0, - ), + coverage, limitations, }; return ok( @@ -217,20 +204,6 @@ const runtimeFamilies = ( return [...families].sort(compareUnicodeCodePoints); }; -const bridgeCandidates = ( - managed: readonly Component[], - native: readonly Component[], -) => { - return projectCartesianCandidates({ - groups: [{ left: managed, right: native }], - createCandidate: (managed_path, target) => ({ - managed_path, - native_path: target.path, - basis: bridgeBasis(target.path), - }), - }); -}; - const bridgeBasis = ( path: string, ): AndroidApplicationProjectionResult["bridge_candidates"][number]["basis"] => { diff --git a/src/domain/apple/appleApplication.ts b/src/domain/apple/appleApplication.ts index 63964213cf..88516bba2e 100644 --- a/src/domain/apple/appleApplication.ts +++ b/src/domain/apple/appleApplication.ts @@ -17,10 +17,7 @@ import { isSwiftRuntimeLibrary, nativeRuntimeConvention, } from "../nativeConvention.js"; -import { - hasCompleteInventoryCoverage, - type ParsedInventorySet, -} from "../artifactInventoryEvidence.js"; +import type { ParsedInventorySet } from "../artifactInventoryEvidence.js"; import { digestSchema, prefixedDigestSchema } from "../digests.js"; import { digestCanonicalValue } from "../canonicalDigest.js"; import { @@ -29,6 +26,8 @@ import { } from "../bridgeCandidateProjection.js"; import { projectedComponentSchema, + projectionCoverage, + projectionCoverageSchema, projectionEvidenceIdSchema, projectionPathSchema, projectedInventoryEntries, @@ -89,11 +88,7 @@ export const appleApplicationProjectionResultSchema = z.strictObject({ }), ), bridge_candidate_coverage: bridgeCandidateCoverageSchema, - coverage: z.strictObject({ - status: z.enum(["complete-within-inventory", "partial"]), - // Count completeness is separate from the declared coverage status. - inventory_complete: z.boolean(), - }), + coverage: projectionCoverageSchema, limitations: z.array(z.string()), }); @@ -144,22 +139,23 @@ export const projectAppleInventory = ( ), roots, ); - const inventoryComplete = hasCompleteInventoryCoverage( + const { coverage, sourceLimitations, bridgeLimitations } = projectionCoverage( inventory, - "container-entries", + bridgeProjection.coverage, + unavailable.all.length, ); const limitations = [ ...unresolved, ...inventory.limitations, + ...sourceLimitations, ...projectionLimitations({ - complete: inventoryComplete, + bridgeLimitations, roots, bundles, sidecars: entries.some(({ path }) => isSidecar(path)), symlinks: entries.some(({ kind }) => kind === "symlink"), unattributed: unattributed + unavailable.unattributed, unavailable: unavailable.all.length > 0, - bridgeCandidateCoverage: bridgeProjection.coverage, }), ]; const withoutId = { @@ -180,15 +176,7 @@ export const projectAppleInventory = ( runtime_families: runtimeFamilies, bridge_candidates: bridgeProjection.candidates, bridge_candidate_coverage: bridgeProjection.coverage, - coverage: { - status: - inventoryComplete && - unavailable.all.length === 0 && - bridgeProjection.coverage.status === "complete" - ? ("complete-within-inventory" as const) - : ("partial" as const), - inventory_complete: inventory.complete, - }, + coverage, limitations, }; return ok( @@ -397,18 +385,14 @@ const bridgeBasis = ( }; const projectionLimitations = (facts: { - readonly complete: boolean; + readonly bridgeLimitations: readonly string[]; readonly roots: readonly string[]; readonly bundles: readonly z.infer[]; readonly sidecars: boolean; readonly symlinks: boolean; readonly unattributed: number; readonly unavailable: boolean; - readonly bridgeCandidateCoverage: AppleApplicationProjectionResult["bridge_candidate_coverage"]; }): string[] => [ - ...(!facts.complete - ? ["Source inventory coverage is partial; absence is unknown."] - : []), ...(facts.roots.length === 0 ? [ "No application bundle (Payload/*.app or *.app/Contents) was present in the supplied inventory pages.", @@ -437,11 +421,7 @@ const projectionLimitations = (facts: { "AppleDouble sidecar entries (._* files and __MACOSX/) describe neighbouring files and are excluded from bundle roles.", ] : []), - ...(facts.bridgeCandidateCoverage.status === "partial" - ? [ - `Bridge candidate pairs exceeded the projection safety budget; ${facts.bridgeCandidateCoverage.omitted_candidates} hypotheses are omitted. Component arrays still include every component from the supplied inventory pages.`, - ] - : []), + ...facts.bridgeLimitations, ...(facts.unavailable ? [ "Some inventoried files have no authenticated content identity. Their paths and limitations are retained in unavailable_components; component absence is unknown.", diff --git a/src/domain/harmony/harmonyApplication.ts b/src/domain/harmony/harmonyApplication.ts index 2e6a04cf8a..3776888f79 100644 --- a/src/domain/harmony/harmonyApplication.ts +++ b/src/domain/harmony/harmonyApplication.ts @@ -1,14 +1,8 @@ -import { - bridgeCandidateCoverageSchema, - projectCartesianCandidates, -} from "../bridgeCandidateProjection.js"; +import { bridgeCandidateCoverageSchema } from "../bridgeCandidateProjection.js"; import { z } from "zod"; import { AnalysisInputError } from "../analysisErrorCore.js"; -import { - hasCompleteInventoryCoverage, - type ParsedInventorySet, -} from "../artifactInventoryEvidence.js"; +import type { ParsedInventorySet } from "../artifactInventoryEvidence.js"; import { digestSchema, prefixedDigestSchema } from "../digests.js"; import { digestCanonicalValue } from "../canonicalDigest.js"; import { nativeRuntimeConvention } from "../nativeConvention.js"; @@ -17,7 +11,9 @@ import { projectedComponentSchema, projectedInventoryEntries, projectedFileComponents, + projectManagedNativeCandidates, projectionCoverage, + projectionCoverageSchema, projectionEvidenceIdSchema, unavailableComponentSchema, type ProjectedInventoryEntry, @@ -58,11 +54,7 @@ export const harmonyApplicationProjectionResultSchema = z.strictObject({ ] as const), ), bridge_candidate_coverage: bridgeCandidateCoverageSchema, - coverage: z.strictObject({ - status: z.enum(["complete-within-inventory", "partial"]), - // Count completeness is separate from the declared coverage status. - inventory_complete: z.boolean(), - }), + coverage: projectionCoverageSchema, limitations: z.array(z.string()), }); @@ -111,16 +103,20 @@ export const projectHarmonyInventory = ( ...Object.values(classified).flat(), ...children, ]); - const bridgeProjection = bridgeCandidates( + const bridgeProjection = projectManagedNativeCandidates( classified.bytecode, classified.native_libraries, + napiBasis, + ); + const { coverage, sourceLimitations, bridgeLimitations } = projectionCoverage( + inventory, + bridgeProjection.coverage, + unavailable.length, ); const limitations = [ ...unresolved, ...inventory.limitations, - ...(!hasCompleteInventoryCoverage(inventory, "container-entries") - ? ["Source inventory coverage is partial; absence is unknown."] - : []), + ...sourceLimitations, ...(unavailable.length > 0 ? [ "Some inventoried files or slices have no authenticated content identity. Their paths and limitations are retained in unavailable_components; component and runtime absence is unknown.", @@ -139,11 +135,7 @@ export const projectHarmonyInventory = ( ] : []), "HarmonyOS .har shared libraries are not identified by this projection; the .har suffix also names HTTP Archive JSON, so that classification requires verified ZIP bytes.", - ...(bridgeProjection.coverage.status === "partial" - ? [ - `Bridge candidate pairs exceeded the projection safety budget; ${bridgeProjection.coverage.omitted_candidates} hypotheses are omitted. Component arrays still include every component from the supplied inventory pages.`, - ] - : []), + ...bridgeLimitations, ]; const withoutId = { root_sha256: inventory.manifest.root_sha256, @@ -161,11 +153,7 @@ export const projectHarmonyInventory = ( runtime_families: runtimeFamilies(all, classified), bridge_candidates: bridgeProjection.candidates, bridge_candidate_coverage: bridgeProjection.coverage, - coverage: projectionCoverage( - inventory, - bridgeProjection.coverage.status === "complete" && - unavailable.length === 0, - ), + coverage, limitations, }; return ok( @@ -278,20 +266,6 @@ const runtimeFamilies = ( return [...families].sort(compareUnicodeCodePoints); }; -const bridgeCandidates = ( - managed: readonly Component[], - native: readonly Component[], -) => { - return projectCartesianCandidates({ - groups: [{ left: managed, right: native }], - createCandidate: (managed_path, target) => ({ - managed_path, - native_path: target.path, - basis: napiBasis(target.path), - }), - }); -}; - const napiBasis = ( path: string, ): HarmonyApplicationProjectionResult["bridge_candidates"][number]["basis"] => diff --git a/src/domain/mobileApplicationGraphProjection.ts b/src/domain/mobileApplicationGraphProjection.ts index 84a1bbc41d..a170869fb0 100644 --- a/src/domain/mobileApplicationGraphProjection.ts +++ b/src/domain/mobileApplicationGraphProjection.ts @@ -6,6 +6,10 @@ import { ArtifactInventoryCarrierError, type ParsedInventorySet, } from "./artifactInventoryEvidence.js"; +import { + projectCartesianCandidates, + type bridgeCandidateCoverageSchema, +} from "./bridgeCandidateProjection.js"; import { evidenceInputSchema } from "./evidenceReference.js"; import { getEvidenceInputContract } from "./evidenceInputContract.js"; import { AnalysisInputError } from "./analysisErrorCore.js"; @@ -91,22 +95,57 @@ export const projectedBridgeCandidateSchema = < basis: z.enum(basis), }); -/** Coverage status combining inventory completeness with a projection budget. */ +/** Pair managed components with native libraries in inventory order. */ +export const projectManagedNativeCandidates = ( + managed: readonly ProjectedComponent[], + native: readonly ProjectedComponent[], + basis: (path: string) => Basis, +) => + projectCartesianCandidates({ + groups: [{ left: managed, right: native }], + createCandidate: (managed_path, target) => ({ + managed_path, + native_path: target.path, + basis: basis(target.path), + }), + }); + +export const projectionCoverageSchema = z.strictObject({ + status: z.enum(["complete-within-inventory", "partial"]), + // Count completeness is separate from the declared coverage status. + inventory_complete: z.boolean(), +}); + +/** Derive coverage and its limitations from the same inventory and bridge facts. */ export const projectionCoverage = ( inventory: ParsedInventorySet["inventory"], - budgetComplete: boolean, -): { - status: "complete-within-inventory" | "partial"; - /** True when all manifest graph-member counts are present, independent of source coverage. */ - inventory_complete: boolean; -} => ({ - status: - hasCompleteInventoryCoverage(inventory, "container-entries") && - budgetComplete - ? ("complete-within-inventory" as const) - : ("partial" as const), - inventory_complete: inventory.complete, -}); + bridges: z.infer, + unavailableCount: number, +) => { + const sourceComplete = hasCompleteInventoryCoverage( + inventory, + "container-entries", + ); + const coverage: z.infer = { + status: + sourceComplete && bridges.status === "complete" && unavailableCount === 0 + ? "complete-within-inventory" + : "partial", + inventory_complete: inventory.complete, + }; + return { + coverage, + sourceLimitations: sourceComplete + ? [] + : ["Source inventory coverage is partial; absence is unknown."], + bridgeLimitations: + bridges.status === "partial" + ? [ + `Bridge candidate pairs exceeded the projection safety budget; ${bridges.omitted_candidates} hypotheses are omitted. Component arrays still include every component from the supplied inventory pages.`, + ] + : [], + }; +}; /** One occurrence with resolved content, unavailable identity, or an unresolved node reference. */ export type ProjectedInventoryEntry = {