test: overhaul deterministic suite architecture

This commit is contained in:
morluto
2026-07-29 22:00:38 +00:00
parent 7f2348619a
commit 513d9b1555
371 changed files with 30879 additions and 24389 deletions
@@ -0,0 +1,35 @@
import { describe, expect, it } from "vitest";
import type {
AnalysisClient,
AnalysisProvider,
ProviderIdentity,
} from "./AnalysisProvider.js";
import { AnalysisProviderRegistry } from "./AnalysisProviderRegistry.js";
import { composeBinarySession } from "./BinarySessionComposition.js";
const auxiliaryProvider = (identity: ProviderIdentity): AnalysisProvider => ({
identity: () => identity,
capabilities: () => [],
createClient: (): AnalysisClient => {
throw new Error("The composition check must not create provider clients");
},
});
describe("composeBinarySession", () => {
it("exposes the complete configured provider set without starting clients", () => {
const session = composeBinarySession(new AnalysisProviderRegistry([]), [
auxiliaryProvider({
id: "test-auxiliary",
name: "Test auxiliary provider",
version: "1.0.0",
}),
]);
expect(session.providerIdentity()).toEqual({
id: "composite:test-auxiliary",
name: "REA composite analysis provider",
version: null,
});
});
});
@@ -0,0 +1,25 @@
import { describe, expect, it } from "vitest";
import { projectBoundedCartesian } from "./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);
});
});
+66
View File
@@ -0,0 +1,66 @@
import { describe, expect, it } from "vitest";
import { inferJsonShape } from "./jsonShape.js";
describe("inferJsonShape", () => {
it("retains paths and types without retaining JSON values", () => {
const shape = inferJsonShape(
JSON.stringify({
token: "super-secret",
users: [
{ id: 1, active: true },
{ id: "second-secret", active: false },
],
optional: null,
}),
{ maximumBytes: 4_096, maximumNodes: 100, maximumDepth: 10 },
);
expect(shape).toMatchObject({
root_type: "object",
truncated: false,
properties: expect.arrayContaining([
{ path: "/token", types: ["string"], observations: 1 },
{
path: "/users/*/id",
types: ["number", "string"],
observations: 2,
},
{
path: "/users/*/active",
types: ["boolean"],
observations: 2,
},
]),
});
expect(JSON.stringify(shape)).not.toContain("super-secret");
expect(JSON.stringify(shape)).not.toContain("second-secret");
});
it("rejects malformed and oversized JSON without returning a prefix", () => {
const limits = {
maximumBytes: 8,
maximumNodes: 100,
maximumDepth: 10,
};
expect(inferJsonShape("not-json", limits)).toBeNull();
expect(inferJsonShape('{"secret":"value"}', limits)).toBeNull();
});
it("reports node and depth truncation deterministically", () => {
expect(
inferJsonShape('{"a":{"b":{"c":1}}}', {
maximumBytes: 1_024,
maximumNodes: 100,
maximumDepth: 1,
}),
).toMatchObject({ truncated: true, max_depth_observed: 1 });
expect(
inferJsonShape("[1,2,3,4]", {
maximumBytes: 1_024,
maximumNodes: 2,
maximumDepth: 10,
}),
).toMatchObject({ truncated: true, node_count: 2 });
});
});
+82
View File
@@ -0,0 +1,82 @@
import { describe, expect, it } from "vitest";
import {
categorizeSwiftTypes,
discoverObjcClasses,
discoverObjcProtocols,
discoverSwiftClasses,
} from "./symbolAnalysis.js";
describe("symbol analysis", () => {
it("filters Swift classes and reports the uncapped match count", () => {
const symbols = Array.from({ length: 120 }, (_, index) => ({
address: `0x${String(index)}`,
name: `_TtCFixture${String(index)}`,
}));
const result = discoverSwiftClasses(symbols, "Fixture");
if (
typeof result === "object" &&
result !== null &&
!Array.isArray(result)
) {
expect(result.count).toBe(120);
expect(result.classes).toHaveLength(100);
expect(Array.isArray(result.classes) ? result.classes[0] : null).toEqual({
address: "0x0",
name: "_TtCFixture0",
});
}
});
it("deduplicates Objective-C classes and protocols by symbol name", () => {
const names = [
{ address: "0x1", name: "_OBJC_CLASS_$_App" },
{ address: "0x2", name: "_OBJC_CLASS_$_App" },
{ address: "0x3", name: "_OBJC_PROTOCOL_$_Delegate" },
{ address: "0x4", name: "_OBJC_PROTOCOL_$_Delegate" },
];
expect(discoverObjcClasses(names, "App")).toMatchObject({ count: 1 });
expect(discoverObjcProtocols(names)).toMatchObject({ count: 1 });
});
it("excludes Objective-C ivars, metaclasses, properties, and protocols from classes", () => {
const result = discoverObjcClasses(
[
{ address: "0x1", name: "_OBJC_IVAR_$_Fixture.value" },
{ address: "0x2", name: "_OBJC_METACLASS_$_Fixture" },
{ address: "0x3", name: "_OBJC_PROP_$_Fixture.value" },
{ address: "0x4", name: "_OBJC_PROTOCOL_$_FixtureProtocol" },
{ address: "0x5", name: "_OBJC_CLASS_$_Fixture" },
],
"",
);
expect(result).toMatchObject({
count: 1,
classes: [{ address: "0x5", name: "_OBJC_CLASS_$_Fixture" }],
});
});
it("categorizes every Swift mangling family and deduplicates names", () => {
const result = categorizeSwiftTypes([
{ address: "1", name: "_TtCClass" },
{ address: "2", name: "_TtVStruct" },
{ address: "3", name: "_TtOEnum" },
{ address: "4", name: "_TtPProtocol" },
{ address: "5", name: "_TtEExtension" },
{ address: "6", name: "prefix_TtOther" },
{ address: "7", name: "_TtCClass" },
]);
expect(result).toMatchObject({
total: 6,
categories: {
classes: { count: 1 },
structs: { count: 1 },
enums: { count: 1 },
protocols: { count: 1 },
extensions: { count: 1 },
other: { count: 1 },
},
});
});
});