test: extract shared fixtures, drop knip carve-outs (#627)
* refactor(domain): consolidate canonical ordering and digest helpers (#624) * refactor(domain): consolidate canonical ordering and digest helpers Single owner for code-point ordering (domain/canonicalOrdering.ts) and canonical JSON digests (domain/comparisonSemantics.ts). Delete all local compareCodePoints/compareText/digestCanonical duplicates and migrate every importer. No re-export shims. * fix(ci): allow slower real browser startup * chore(config): remove dead eslint, dedupe scripts, cacheable turbo tasks Delete eslint.config.js (oxlint is the linter), drop lint:dead alias, pin smol-toml, fold jscpd/scan:todos into check:pr, make test:run cacheable, align oxlint ignores. * fix(config): hash all test inputs for cached runs * docs: fix architecture diagram and pretty-print tool catalog Drop dangling REPLAY edges, add dotnet/reference/error/evaluation nodes. Emit 2-space JSON from the catalog generator and regenerate. * test: extract shared fixtures, drop knip carve-outs Dedupe android/apple session tests, bundler adapter headers, and reconstruction helpers into tests/support fixtures. Delete unused type aliases and the knip ignoreIssues block. Lower jscpd threshold 2.7 to 2.5.
This commit is contained in:
@@ -10,6 +10,10 @@ import {
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import {
|
||||
createNonApplicationZipInventory,
|
||||
requireSuccessfulProjection,
|
||||
} from "../../support/applicationSessionFixture.js";
|
||||
|
||||
import { projectAndroidApplicationEvidence } from "../../../src/application/AndroidApplicationService.js";
|
||||
import { runProviderAnalysis } from "../../../src/application/DirectAnalysis.js";
|
||||
@@ -50,14 +54,11 @@ describe("Android application projection", () => {
|
||||
const second = projectAndroidApplicationEvidence({
|
||||
inventory_evidence: [inventory],
|
||||
});
|
||||
expect(first.ok).toBe(true);
|
||||
expect(second.ok).toBe(true);
|
||||
if (!first.ok || !second.ok) return;
|
||||
const left = androidApplicationProjectionResultSchema.parse(
|
||||
first.value.normalized_result,
|
||||
requireSuccessfulProjection(first).normalized_result,
|
||||
);
|
||||
const right = androidApplicationProjectionResultSchema.parse(
|
||||
second.value.normalized_result,
|
||||
requireSuccessfulProjection(second).normalized_result,
|
||||
);
|
||||
expect(left).toEqual(right);
|
||||
expect(left).toMatchObject({
|
||||
@@ -87,13 +88,8 @@ describe("Android application projection", () => {
|
||||
});
|
||||
|
||||
it("rejects non-APK inventory Evidence", async () => {
|
||||
const root = await createTestTempDirectory("rea-android-invalid-");
|
||||
const path = join(root, "fixture.zip");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add("one.js", new TextReader("one"));
|
||||
await writeFile(path, await writer.close());
|
||||
const inventory = parseEvidence(
|
||||
await runProviderAnalysis(path, "inventory_artifact", {}),
|
||||
const inventory = await createNonApplicationZipInventory(
|
||||
"rea-android-invalid-",
|
||||
);
|
||||
expect(
|
||||
projectAndroidApplicationEvidence({ inventory_evidence: [inventory] }),
|
||||
|
||||
@@ -11,6 +11,10 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { fragmentInventoryEvidence } from "../../fixtures/artifactEvidence.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import {
|
||||
createNonApplicationZipInventory,
|
||||
requireSuccessfulProjection,
|
||||
} from "../../support/applicationSessionFixture.js";
|
||||
|
||||
import { projectAppleApplicationEvidence } from "../../../src/application/AppleApplicationService.js";
|
||||
import { runProviderAnalysis } from "../../../src/application/DirectAnalysis.js";
|
||||
@@ -109,14 +113,11 @@ describe("Apple application projection", () => {
|
||||
const second = projectAppleApplicationEvidence({
|
||||
inventory_evidence: [inventory],
|
||||
});
|
||||
expect(first.ok).toBe(true);
|
||||
expect(second.ok).toBe(true);
|
||||
if (!first.ok || !second.ok) return;
|
||||
const left = appleApplicationProjectionResultSchema.parse(
|
||||
first.value.normalized_result,
|
||||
requireSuccessfulProjection(first).normalized_result,
|
||||
);
|
||||
const right = appleApplicationProjectionResultSchema.parse(
|
||||
second.value.normalized_result,
|
||||
requireSuccessfulProjection(second).normalized_result,
|
||||
);
|
||||
expect(left).toEqual(right);
|
||||
expect(left).toMatchObject({
|
||||
@@ -149,14 +150,8 @@ describe("Apple application projection", () => {
|
||||
});
|
||||
|
||||
it("rejects non-IPA Evidence", async () => {
|
||||
const root = await createTestTempDirectory("rea-apple-invalid-");
|
||||
const path = join(root, "fixture.zip");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add("one.js", new TextReader("one"));
|
||||
await writeFile(path, await writer.close());
|
||||
const inventory = parseEvidence(
|
||||
await runProviderAnalysis(path, "inventory_artifact", {}),
|
||||
);
|
||||
const inventory =
|
||||
await createNonApplicationZipInventory("rea-apple-invalid-");
|
||||
expect(
|
||||
projectAppleApplicationEvidence({ inventory_evidence: [inventory] }),
|
||||
).toMatchObject({
|
||||
|
||||
@@ -2,6 +2,9 @@ import type {
|
||||
AnalysisClient,
|
||||
AnalysisProvider,
|
||||
} from "../../../src/application/AnalysisProvider.js";
|
||||
import type { BinarySession } from "../../../src/application/BinarySession.js";
|
||||
import type { JsonValue } from "../../../src/domain/jsonValue.js";
|
||||
import type { RecordUnknownInput } from "../../../src/domain/residualUnknown.js";
|
||||
import { createAnalysisProfile } from "../../../src/domain/analysisProfile.js";
|
||||
import {
|
||||
HopperStartError,
|
||||
@@ -93,6 +96,44 @@ const client = (fail = false): AnalysisClient => ({
|
||||
close: () => Promise.resolve(),
|
||||
});
|
||||
|
||||
/** Open a target and run one address_name query, asserting both succeed. */
|
||||
const openAndExecuteAddressName = async (
|
||||
session: BinarySession,
|
||||
target: string,
|
||||
parameters: Readonly<Record<string, JsonValue>>,
|
||||
): Promise<void> => {
|
||||
expect((await session.open(target)).ok).toBe(true);
|
||||
expect((await session.execute("address_name", parameters)).ok).toBe(true);
|
||||
};
|
||||
|
||||
/** Shared network-reachability unknown input at one severity. */
|
||||
const networkReachabilityUnknown = (
|
||||
severity: "medium" | "high",
|
||||
): RecordUnknownInput => ({
|
||||
question: "Does this function reach the network?",
|
||||
severity,
|
||||
domain: "network",
|
||||
supporting_evidence_ids: [],
|
||||
contradicting_evidence_ids: [],
|
||||
required_authority: "shipped-artifact",
|
||||
required_confidence: "observed",
|
||||
required_environment: null,
|
||||
recommended_probes: [
|
||||
{ operation: "analyze_function", rationale: "Inspect its callers." },
|
||||
],
|
||||
relationships: [],
|
||||
});
|
||||
|
||||
/** Record the shared network-reachability unknown, asserting success. */
|
||||
const recordNetworkReachabilityUnknown = (
|
||||
session: BinarySession,
|
||||
severity: "medium" | "high",
|
||||
): void => {
|
||||
expect(session.recordUnknown(networkReachabilityUnknown(severity)).ok).toBe(
|
||||
true,
|
||||
);
|
||||
};
|
||||
|
||||
describe("detached provider and target metadata", () => {
|
||||
it("returns detached provider and target metadata", async () => {
|
||||
const [first] = await createBinarySessionTargets();
|
||||
@@ -349,31 +390,11 @@ describe("snapshot switch rollback", () => {
|
||||
await copyFile(first, second);
|
||||
const calls: string[] = [];
|
||||
const session = createTestBinarySession(createCacheProvider(calls));
|
||||
expect((await session.open(first)).ok).toBe(true);
|
||||
expect(
|
||||
(
|
||||
await session.execute("address_name", {
|
||||
address: "0x1000",
|
||||
document: "first",
|
||||
})
|
||||
).ok,
|
||||
).toBe(true);
|
||||
expect(
|
||||
session.recordUnknown({
|
||||
question: "Does this function reach the network?",
|
||||
severity: "medium",
|
||||
domain: "network",
|
||||
supporting_evidence_ids: [],
|
||||
contradicting_evidence_ids: [],
|
||||
required_authority: "shipped-artifact",
|
||||
required_confidence: "observed",
|
||||
required_environment: null,
|
||||
recommended_probes: [
|
||||
{ operation: "analyze_function", rationale: "Inspect its callers." },
|
||||
],
|
||||
relationships: [],
|
||||
}).ok,
|
||||
).toBe(true);
|
||||
await openAndExecuteAddressName(session, first, {
|
||||
address: "0x1000",
|
||||
document: "first",
|
||||
});
|
||||
recordNetworkReachabilityUnknown(session, "medium");
|
||||
const originalCache = session.exportAnalysisSnapshot();
|
||||
expect(originalCache).toMatchObject({
|
||||
ok: true,
|
||||
@@ -382,22 +403,7 @@ describe("snapshot switch rollback", () => {
|
||||
|
||||
const conflicting = createTestBinarySession(createCacheProvider([]));
|
||||
expect((await conflicting.open(second)).ok).toBe(true);
|
||||
expect(
|
||||
conflicting.recordUnknown({
|
||||
question: "Does this function reach the network?",
|
||||
severity: "high",
|
||||
domain: "network",
|
||||
supporting_evidence_ids: [],
|
||||
contradicting_evidence_ids: [],
|
||||
required_authority: "shipped-artifact",
|
||||
required_confidence: "observed",
|
||||
required_environment: null,
|
||||
recommended_probes: [
|
||||
{ operation: "analyze_function", rationale: "Inspect its callers." },
|
||||
],
|
||||
relationships: [],
|
||||
}).ok,
|
||||
).toBe(true);
|
||||
recordNetworkReachabilityUnknown(conflicting, "high");
|
||||
const conflictingSnapshot = conflicting.exportAnalysisSnapshot();
|
||||
expect(conflictingSnapshot.ok).toBe(true);
|
||||
if (!conflictingSnapshot.ok || !originalCache.ok) return;
|
||||
@@ -425,8 +431,7 @@ describe("snapshot cache eligibility", () => {
|
||||
const [first] = await createBinarySessionTargets();
|
||||
const calls: string[] = [];
|
||||
const session = createTestBinarySession(createCacheProvider(calls));
|
||||
expect((await session.open(first)).ok).toBe(true);
|
||||
expect((await session.execute("address_name", {})).ok).toBe(true);
|
||||
await openAndExecuteAddressName(session, first, {});
|
||||
expect((await session.execute("address_name", {})).ok).toBe(true);
|
||||
expect(calls).toEqual(["health", "address_name", "address_name"]);
|
||||
expect(session.exportAnalysisSnapshot()).toMatchObject({
|
||||
|
||||
Reference in New Issue
Block a user