fix(artifacts): bound mobile projection candidates

This commit is contained in:
morluto
2026-07-20 11:31:36 +00:00
parent d36b385378
commit 0cc9d468c4
7 changed files with 109 additions and 20 deletions
+9 -5
View File
@@ -4,6 +4,7 @@ import canonicalize from "canonicalize";
import { z } from "zod";
import { parseArtifactInventoryEvidence } from "./artifactInventoryEvidence.js";
import { projectBoundedCartesian } from "./boundedCartesianProjection.js";
import { evidenceSchema } from "./evidence.js";
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
@@ -248,16 +249,19 @@ const bridgeCandidates = (
native: readonly Component[],
maximum: number,
) => {
const candidates = managed.flatMap((source) =>
native.map((target) => ({
const projection = projectBoundedCartesian(
managed,
native,
maximum,
(source, target) => ({
managed_path: source.path,
native_path: target.path,
basis: bridgeBasis(target.path),
})),
}),
);
return {
candidates: candidates.slice(0, maximum),
omitted: Math.max(0, candidates.length - maximum),
candidates: projection.values,
omitted: projection.omitted,
};
};
+17 -12
View File
@@ -4,6 +4,7 @@ import canonicalize from "canonicalize";
import { z } from "zod";
import { parseArtifactInventoryEvidence } from "./artifactInventoryEvidence.js";
import { projectBoundedCartesian } from "./boundedCartesianProjection.js";
import { evidenceSchema } from "./evidence.js";
const digestSchema = z.string().regex(/^[a-f0-9]{64}$/u);
@@ -114,13 +115,14 @@ export const projectAppleApplication = (
format: node.format,
} satisfies Component;
});
const roots = inventory.occurrences
.filter(
({ logical_path: path, entry_kind: kind }) =>
kind === "directory" && /^Payload\/[^/]+\.app$/u.test(path),
)
.map(({ logical_path: path }) => path)
.sort(compare);
const roots = [
...new Set(
inventory.occurrences.flatMap(({ logical_path: path }) => {
const match = /^(Payload\/[^/]+\.app)(?:\/|$)/u.exec(path);
return match?.[1] === undefined ? [] : [match[1]];
}),
),
].sort(compare);
const classified = classifyComponents(all, roots);
const retained = retainComponents(classified, parsed.limits.max_components);
const omitted = componentCount(classified) - componentCount(retained);
@@ -249,16 +251,19 @@ const identifyBridgeCandidates = (
native: readonly Component[],
maximum: number,
) => {
const candidates = scripts.flatMap((script) =>
native.map((item) => ({
const projection = projectBoundedCartesian(
scripts,
native,
maximum,
(script, item) => ({
source_path: script.path,
native_path: item.path,
basis: bridgeBasis(item.path),
})),
}),
);
return {
candidates: candidates.slice(0, maximum),
omitted: Math.max(0, candidates.length - maximum),
candidates: projection.values,
omitted: projection.omitted,
};
};
+20
View File
@@ -0,0 +1,20 @@
/** Project a Cartesian product without materializing values beyond the output limit. */
export const projectBoundedCartesian = <Left, Right, Value>(
left: readonly Left[],
right: readonly Right[],
maximum: number,
project: (left: Left, right: Right) => Value,
): { readonly values: Value[]; readonly omitted: number } => {
const values: Value[] = [];
for (const leftValue of left) {
for (const rightValue of right) {
if (values.length === maximum)
return {
values,
omitted: left.length * right.length - values.length,
};
values.push(project(leftValue, rightValue));
}
}
return { values, omitted: 0 };
};
+3 -3
View File
@@ -81,9 +81,9 @@ type RuntimeProvider = {
const PROVIDERS: Readonly<Record<RuntimeFamily, RuntimeProvider>> = {
android: {
inspection: "provider-missing",
id: null,
reason: "Install or configure an Android semantic-analysis provider.",
inspection: "available",
id: "rea-android-application",
reason: null,
},
apple: { inspection: "available", id: "rea-apple-application", reason: null },
javascript: {