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: {
+30
View File
@@ -111,4 +111,34 @@ describe("Apple application projection", () => {
error: { _tag: "AnalysisInputError" },
});
});
it("infers an application root when the IPA omits directory entries", async () => {
const root = await mkdtemp(join(tmpdir(), "rea-apple-root-"));
const path = join(root, "Fixture.ipa");
const writer = new ZipWriter(new Uint8ArrayWriter());
await writer.add(
"Payload/Fixture.app/Fixture",
new Uint8ArrayReader(
Uint8Array.from([0xcf, 0xfa, 0xed, 0xfe, 0x0c, 0, 0, 1]),
),
);
await writeFile(path, await writer.close());
const inventory = parseEvidence(
await runProviderAnalysis(path, "inventory_artifact", {}),
);
const result = projectAppleApplicationEvidence({
inventory_evidence: [inventory],
});
expect(result.ok).toBe(true);
if (!result.ok) return;
expect(
appleApplicationProjectionResultSchema.parse(
result.value.normalized_result,
),
).toMatchObject({
application_roots: ["Payload/Fixture.app"],
components: { executables: [expect.any(Object)] },
});
});
});
+25
View File
@@ -0,0 +1,25 @@
import { describe, expect, it } from "vitest";
import { projectBoundedCartesian } from "../src/domain/boundedCartesianProjection.js";
describe("bounded Cartesian projection", () => {
it("stops projection work at the output limit", () => {
const values = Array.from({ length: 10_000 }, (_, index) => index);
let projections = 0;
const result = projectBoundedCartesian(values, values, 3, (left, right) => {
projections += 1;
return [left, right] as const;
});
expect(result).toEqual({
values: [
[0, 0],
[0, 1],
[0, 2],
],
omitted: 100_000_000 - 3,
});
expect(projections).toBe(3);
});
});
+5
View File
@@ -78,6 +78,11 @@ describe("runtime identification", () => {
]);
expect(first.runtimes).toEqual(
expect.arrayContaining([
expect.objectContaining({
family: "android",
inspection: "available",
provider_id: "rea-android-application",
}),
expect.objectContaining({
family: "jvm",
inspection: "provider-missing",