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:
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"_comment": "Test files are intentionally NOT excluded: the gate used to report zero clones because it skipped **/*.test.ts, hiding all test-tree duplication. Current actual is ~2.6% lines across src+ and tests/, down from 3.4% when tests were included. Lower this as duplication is removed.",
|
"_comment": "Test files are intentionally NOT excluded: the gate used to report zero clones because it skipped **/*.test.ts, hiding all test-tree duplication. Current actual is ~2.4% lines across src+ and tests/, down from 3.4% when tests were included. Lower this as duplication is removed.",
|
||||||
"threshold": 2.7,
|
"threshold": 2.5,
|
||||||
"reporters": ["consoleFull"],
|
"reporters": ["consoleFull"],
|
||||||
"ignore": [
|
"ignore": [
|
||||||
"node_modules/**",
|
"node_modules/**",
|
||||||
|
|||||||
@@ -1,21 +1,10 @@
|
|||||||
{
|
{
|
||||||
"$schema": "./node_modules/knip/schema.json",
|
"$schema": "./node_modules/knip/schema.json",
|
||||||
"entry": [
|
"entry": ["src/main.ts", "src/cli.ts", "src/contracts/errorSchemas.ts"],
|
||||||
"src/main.ts",
|
|
||||||
"src/cli.ts",
|
|
||||||
"src/contracts/errorSchemas.ts",
|
|
||||||
"scripts/run-development-tests.mjs"
|
|
||||||
],
|
|
||||||
"project": ["src/**/*.ts", "tests/**/*.ts", "scripts/**/*.mjs"],
|
"project": ["src/**/*.ts", "tests/**/*.ts", "scripts/**/*.mjs"],
|
||||||
"ignoreDependencies": ["electron"],
|
"ignoreDependencies": ["electron"],
|
||||||
"ignoreBinaries": ["ps"],
|
"ignoreBinaries": ["ps"],
|
||||||
"ignoreExportsUsedInFile": true,
|
"ignoreExportsUsedInFile": true,
|
||||||
"ignoreIssues": {
|
|
||||||
"src/domain/mobileApplicationInvestigation.ts": ["types"],
|
|
||||||
"src/domain/objcSwiftMetadata.ts": ["types"],
|
|
||||||
"src/domain/interfaceBuilderGraph.ts": ["types"],
|
|
||||||
"src/domain/nativeInvestigationGraph.ts": ["types"]
|
|
||||||
},
|
|
||||||
"rules": {
|
"rules": {
|
||||||
"files": "error",
|
"files": "error",
|
||||||
"dependencies": "error",
|
"dependencies": "error",
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ export const iosManifestSchema = z.strictObject({
|
|||||||
ui_required_device_capabilities: z.array(z.string()).default([]),
|
ui_required_device_capabilities: z.array(z.string()).default([]),
|
||||||
app_permissions: z.array(z.string()).default([]),
|
app_permissions: z.array(z.string()).default([]),
|
||||||
});
|
});
|
||||||
export type IosManifest = z.infer<typeof iosManifestSchema>;
|
|
||||||
/** Signing information. */
|
/** Signing information. */
|
||||||
export const signingInfoSchema = z.strictObject({
|
export const signingInfoSchema = z.strictObject({
|
||||||
is_signed: z.boolean().default(false),
|
is_signed: z.boolean().default(false),
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ export const objcPropertyAttributeSchema = z.strictObject({
|
|||||||
is_copy: z.boolean().default(false),
|
is_copy: z.boolean().default(false),
|
||||||
is_strong: z.boolean().default(false),
|
is_strong: z.boolean().default(false),
|
||||||
});
|
});
|
||||||
export type ObjcPropertyAttribute = z.infer<typeof objcPropertyAttributeSchema>;
|
|
||||||
|
|
||||||
/** Objective-C method metadata. */
|
/** Objective-C method metadata. */
|
||||||
export const objcMethodSchema = z.strictObject({
|
export const objcMethodSchema = z.strictObject({
|
||||||
@@ -39,7 +38,6 @@ export const objcPropertySchema = z.strictObject({
|
|||||||
getter: z.string().nullable(),
|
getter: z.string().nullable(),
|
||||||
setter: z.string().nullable(),
|
setter: z.string().nullable(),
|
||||||
});
|
});
|
||||||
export type ObjcProperty = z.infer<typeof objcPropertySchema>;
|
|
||||||
|
|
||||||
/** Objective-C protocol metadata. */
|
/** Objective-C protocol metadata. */
|
||||||
export const objcProtocolSchema = z.strictObject({
|
export const objcProtocolSchema = z.strictObject({
|
||||||
@@ -48,7 +46,6 @@ export const objcProtocolSchema = z.strictObject({
|
|||||||
optional_methods: z.array(objcMethodSchema).default([]),
|
optional_methods: z.array(objcMethodSchema).default([]),
|
||||||
properties: z.array(objcPropertySchema).default([]),
|
properties: z.array(objcPropertySchema).default([]),
|
||||||
});
|
});
|
||||||
export type ObjcProtocol = z.infer<typeof objcProtocolSchema>;
|
|
||||||
|
|
||||||
/** Objective-C class metadata. */
|
/** Objective-C class metadata. */
|
||||||
export const objcClassSchema = z.strictObject({
|
export const objcClassSchema = z.strictObject({
|
||||||
@@ -106,7 +103,6 @@ export const nativeMetadataDecodeSchema = z.strictObject({
|
|||||||
status: z.enum(["decoded", "partial", "unsupported", "invalid"]),
|
status: z.enum(["decoded", "partial", "unsupported", "invalid"]),
|
||||||
reason: z.string().nullable(),
|
reason: z.string().nullable(),
|
||||||
});
|
});
|
||||||
export type NativeMetadataDecode = z.infer<typeof nativeMetadataDecodeSchema>;
|
|
||||||
|
|
||||||
/** Evidence attached to one dispatch edge or metadata record. */
|
/** Evidence attached to one dispatch edge or metadata record. */
|
||||||
export const nativeMetadataEvidenceSchema = z.strictObject({
|
export const nativeMetadataEvidenceSchema = z.strictObject({
|
||||||
@@ -142,7 +138,6 @@ export const objcIvarSchema = z.strictObject({
|
|||||||
decode: nativeMetadataDecodeSchema,
|
decode: nativeMetadataDecodeSchema,
|
||||||
evidence: z.array(nativeMetadataEvidenceSchema).min(1),
|
evidence: z.array(nativeMetadataEvidenceSchema).min(1),
|
||||||
});
|
});
|
||||||
export type ObjcIvar = z.infer<typeof objcIvarSchema>;
|
|
||||||
|
|
||||||
/** Encoded Objective-C protocol declaration with required and optional method facts. */
|
/** Encoded Objective-C protocol declaration with required and optional method facts. */
|
||||||
export const objcProtocolRecordSchema = z.strictObject({
|
export const objcProtocolRecordSchema = z.strictObject({
|
||||||
@@ -179,7 +174,6 @@ export const swiftConformanceSchema = z.strictObject({
|
|||||||
decode: nativeMetadataDecodeSchema,
|
decode: nativeMetadataDecodeSchema,
|
||||||
evidence: z.array(nativeMetadataEvidenceSchema).min(1),
|
evidence: z.array(nativeMetadataEvidenceSchema).min(1),
|
||||||
});
|
});
|
||||||
export type SwiftConformance = z.infer<typeof swiftConformanceSchema>;
|
|
||||||
|
|
||||||
/** A typed slot in a Swift protocol witness table or class vtable. */
|
/** A typed slot in a Swift protocol witness table or class vtable. */
|
||||||
export const swiftDispatchSlotSchema = z.strictObject({
|
export const swiftDispatchSlotSchema = z.strictObject({
|
||||||
@@ -194,7 +188,6 @@ export const swiftDispatchSlotSchema = z.strictObject({
|
|||||||
decode: nativeMetadataDecodeSchema,
|
decode: nativeMetadataDecodeSchema,
|
||||||
evidence: z.array(nativeMetadataEvidenceSchema).min(1),
|
evidence: z.array(nativeMetadataEvidenceSchema).min(1),
|
||||||
});
|
});
|
||||||
export type SwiftDispatchSlot = z.infer<typeof swiftDispatchSlotSchema>;
|
|
||||||
|
|
||||||
/** Signed-relative pointer as stored in an Apple binary metadata structure. */
|
/** Signed-relative pointer as stored in an Apple binary metadata structure. */
|
||||||
export const relativePointerSchema = z.strictObject({
|
export const relativePointerSchema = z.strictObject({
|
||||||
@@ -206,7 +199,6 @@ export const relativePointerSchema = z.strictObject({
|
|||||||
decode: nativeMetadataDecodeSchema,
|
decode: nativeMetadataDecodeSchema,
|
||||||
evidence: z.array(nativeMetadataEvidenceSchema).min(1),
|
evidence: z.array(nativeMetadataEvidenceSchema).min(1),
|
||||||
});
|
});
|
||||||
export type RelativePointer = z.infer<typeof relativePointerSchema>;
|
|
||||||
|
|
||||||
/** A raw Swift-mangled symbol when a provider has not decoded its metadata. */
|
/** A raw Swift-mangled symbol when a provider has not decoded its metadata. */
|
||||||
export const swiftSymbolSchema = z.strictObject({
|
export const swiftSymbolSchema = z.strictObject({
|
||||||
@@ -225,9 +217,6 @@ export const nativeMetadataCoverageSchema = z.strictObject({
|
|||||||
examined: z.number().int().nonnegative(),
|
examined: z.number().int().nonnegative(),
|
||||||
decoded: z.number().int().nonnegative(),
|
decoded: z.number().int().nonnegative(),
|
||||||
});
|
});
|
||||||
export type NativeMetadataCoverage = z.infer<
|
|
||||||
typeof nativeMetadataCoverageSchema
|
|
||||||
>;
|
|
||||||
|
|
||||||
/** Swift declaration kind. */
|
/** Swift declaration kind. */
|
||||||
export const swiftDeclKindSchema = z.enum([
|
export const swiftDeclKindSchema = z.enum([
|
||||||
@@ -250,7 +239,6 @@ export const swiftAccessLevelSchema = z.enum([
|
|||||||
"public",
|
"public",
|
||||||
"open",
|
"open",
|
||||||
]);
|
]);
|
||||||
export type SwiftAccessLevel = z.infer<typeof swiftAccessLevelSchema>;
|
|
||||||
/** Swift declaration metadata. */
|
/** Swift declaration metadata. */
|
||||||
export const swiftDeclSchema = z.strictObject({
|
export const swiftDeclSchema = z.strictObject({
|
||||||
kind: swiftDeclKindSchema,
|
kind: swiftDeclKindSchema,
|
||||||
@@ -275,8 +263,6 @@ export const dbOperationSchema = z.enum([
|
|||||||
"export",
|
"export",
|
||||||
"import",
|
"import",
|
||||||
]);
|
]);
|
||||||
export type DbOperation = z.infer<typeof dbOperationSchema>;
|
|
||||||
|
|
||||||
/** Database save operation result. */
|
/** Database save operation result. */
|
||||||
export const dbSaveResultSchema = z.strictObject({
|
export const dbSaveResultSchema = z.strictObject({
|
||||||
operation: dbOperationSchema,
|
operation: dbOperationSchema,
|
||||||
@@ -322,9 +308,6 @@ export const nativeDispatchMetadataResultSchema = z.strictObject({
|
|||||||
analysis_profile_digest: z.string().min(1).nullable(),
|
analysis_profile_digest: z.string().min(1).nullable(),
|
||||||
result: objcSwiftMetadataSchema,
|
result: objcSwiftMetadataSchema,
|
||||||
});
|
});
|
||||||
export type NativeDispatchMetadataResult = z.infer<
|
|
||||||
typeof nativeDispatchMetadataResultSchema
|
|
||||||
>;
|
|
||||||
|
|
||||||
/** Decode only facts visible in a provider's existing name inventory. */
|
/** Decode only facts visible in a provider's existing name inventory. */
|
||||||
export const inspectNativeDispatchMetadata = (
|
export const inspectNativeDispatchMetadata = (
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ import {
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||||
|
import {
|
||||||
|
createNonApplicationZipInventory,
|
||||||
|
requireSuccessfulProjection,
|
||||||
|
} from "../../support/applicationSessionFixture.js";
|
||||||
|
|
||||||
import { projectAndroidApplicationEvidence } from "../../../src/application/AndroidApplicationService.js";
|
import { projectAndroidApplicationEvidence } from "../../../src/application/AndroidApplicationService.js";
|
||||||
import { runProviderAnalysis } from "../../../src/application/DirectAnalysis.js";
|
import { runProviderAnalysis } from "../../../src/application/DirectAnalysis.js";
|
||||||
@@ -50,14 +54,11 @@ describe("Android application projection", () => {
|
|||||||
const second = projectAndroidApplicationEvidence({
|
const second = projectAndroidApplicationEvidence({
|
||||||
inventory_evidence: [inventory],
|
inventory_evidence: [inventory],
|
||||||
});
|
});
|
||||||
expect(first.ok).toBe(true);
|
|
||||||
expect(second.ok).toBe(true);
|
|
||||||
if (!first.ok || !second.ok) return;
|
|
||||||
const left = androidApplicationProjectionResultSchema.parse(
|
const left = androidApplicationProjectionResultSchema.parse(
|
||||||
first.value.normalized_result,
|
requireSuccessfulProjection(first).normalized_result,
|
||||||
);
|
);
|
||||||
const right = androidApplicationProjectionResultSchema.parse(
|
const right = androidApplicationProjectionResultSchema.parse(
|
||||||
second.value.normalized_result,
|
requireSuccessfulProjection(second).normalized_result,
|
||||||
);
|
);
|
||||||
expect(left).toEqual(right);
|
expect(left).toEqual(right);
|
||||||
expect(left).toMatchObject({
|
expect(left).toMatchObject({
|
||||||
@@ -87,13 +88,8 @@ describe("Android application projection", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("rejects non-APK inventory Evidence", async () => {
|
it("rejects non-APK inventory Evidence", async () => {
|
||||||
const root = await createTestTempDirectory("rea-android-invalid-");
|
const inventory = await createNonApplicationZipInventory(
|
||||||
const path = join(root, "fixture.zip");
|
"rea-android-invalid-",
|
||||||
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", {}),
|
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
projectAndroidApplicationEvidence({ inventory_evidence: [inventory] }),
|
projectAndroidApplicationEvidence({ inventory_evidence: [inventory] }),
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ import { describe, expect, it } from "vitest";
|
|||||||
|
|
||||||
import { fragmentInventoryEvidence } from "../../fixtures/artifactEvidence.js";
|
import { fragmentInventoryEvidence } from "../../fixtures/artifactEvidence.js";
|
||||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||||
|
import {
|
||||||
|
createNonApplicationZipInventory,
|
||||||
|
requireSuccessfulProjection,
|
||||||
|
} from "../../support/applicationSessionFixture.js";
|
||||||
|
|
||||||
import { projectAppleApplicationEvidence } from "../../../src/application/AppleApplicationService.js";
|
import { projectAppleApplicationEvidence } from "../../../src/application/AppleApplicationService.js";
|
||||||
import { runProviderAnalysis } from "../../../src/application/DirectAnalysis.js";
|
import { runProviderAnalysis } from "../../../src/application/DirectAnalysis.js";
|
||||||
@@ -109,14 +113,11 @@ describe("Apple application projection", () => {
|
|||||||
const second = projectAppleApplicationEvidence({
|
const second = projectAppleApplicationEvidence({
|
||||||
inventory_evidence: [inventory],
|
inventory_evidence: [inventory],
|
||||||
});
|
});
|
||||||
expect(first.ok).toBe(true);
|
|
||||||
expect(second.ok).toBe(true);
|
|
||||||
if (!first.ok || !second.ok) return;
|
|
||||||
const left = appleApplicationProjectionResultSchema.parse(
|
const left = appleApplicationProjectionResultSchema.parse(
|
||||||
first.value.normalized_result,
|
requireSuccessfulProjection(first).normalized_result,
|
||||||
);
|
);
|
||||||
const right = appleApplicationProjectionResultSchema.parse(
|
const right = appleApplicationProjectionResultSchema.parse(
|
||||||
second.value.normalized_result,
|
requireSuccessfulProjection(second).normalized_result,
|
||||||
);
|
);
|
||||||
expect(left).toEqual(right);
|
expect(left).toEqual(right);
|
||||||
expect(left).toMatchObject({
|
expect(left).toMatchObject({
|
||||||
@@ -149,14 +150,8 @@ describe("Apple application projection", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("rejects non-IPA Evidence", async () => {
|
it("rejects non-IPA Evidence", async () => {
|
||||||
const root = await createTestTempDirectory("rea-apple-invalid-");
|
const inventory =
|
||||||
const path = join(root, "fixture.zip");
|
await createNonApplicationZipInventory("rea-apple-invalid-");
|
||||||
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", {}),
|
|
||||||
);
|
|
||||||
expect(
|
expect(
|
||||||
projectAppleApplicationEvidence({ inventory_evidence: [inventory] }),
|
projectAppleApplicationEvidence({ inventory_evidence: [inventory] }),
|
||||||
).toMatchObject({
|
).toMatchObject({
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ import type {
|
|||||||
AnalysisClient,
|
AnalysisClient,
|
||||||
AnalysisProvider,
|
AnalysisProvider,
|
||||||
} from "../../../src/application/AnalysisProvider.js";
|
} 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 { createAnalysisProfile } from "../../../src/domain/analysisProfile.js";
|
||||||
import {
|
import {
|
||||||
HopperStartError,
|
HopperStartError,
|
||||||
@@ -93,6 +96,44 @@ const client = (fail = false): AnalysisClient => ({
|
|||||||
close: () => Promise.resolve(),
|
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", () => {
|
describe("detached provider and target metadata", () => {
|
||||||
it("returns detached provider and target metadata", async () => {
|
it("returns detached provider and target metadata", async () => {
|
||||||
const [first] = await createBinarySessionTargets();
|
const [first] = await createBinarySessionTargets();
|
||||||
@@ -349,31 +390,11 @@ describe("snapshot switch rollback", () => {
|
|||||||
await copyFile(first, second);
|
await copyFile(first, second);
|
||||||
const calls: string[] = [];
|
const calls: string[] = [];
|
||||||
const session = createTestBinarySession(createCacheProvider(calls));
|
const session = createTestBinarySession(createCacheProvider(calls));
|
||||||
expect((await session.open(first)).ok).toBe(true);
|
await openAndExecuteAddressName(session, first, {
|
||||||
expect(
|
address: "0x1000",
|
||||||
(
|
document: "first",
|
||||||
await session.execute("address_name", {
|
});
|
||||||
address: "0x1000",
|
recordNetworkReachabilityUnknown(session, "medium");
|
||||||
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);
|
|
||||||
const originalCache = session.exportAnalysisSnapshot();
|
const originalCache = session.exportAnalysisSnapshot();
|
||||||
expect(originalCache).toMatchObject({
|
expect(originalCache).toMatchObject({
|
||||||
ok: true,
|
ok: true,
|
||||||
@@ -382,22 +403,7 @@ describe("snapshot switch rollback", () => {
|
|||||||
|
|
||||||
const conflicting = createTestBinarySession(createCacheProvider([]));
|
const conflicting = createTestBinarySession(createCacheProvider([]));
|
||||||
expect((await conflicting.open(second)).ok).toBe(true);
|
expect((await conflicting.open(second)).ok).toBe(true);
|
||||||
expect(
|
recordNetworkReachabilityUnknown(conflicting, "high");
|
||||||
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);
|
|
||||||
const conflictingSnapshot = conflicting.exportAnalysisSnapshot();
|
const conflictingSnapshot = conflicting.exportAnalysisSnapshot();
|
||||||
expect(conflictingSnapshot.ok).toBe(true);
|
expect(conflictingSnapshot.ok).toBe(true);
|
||||||
if (!conflictingSnapshot.ok || !originalCache.ok) return;
|
if (!conflictingSnapshot.ok || !originalCache.ok) return;
|
||||||
@@ -425,8 +431,7 @@ describe("snapshot cache eligibility", () => {
|
|||||||
const [first] = await createBinarySessionTargets();
|
const [first] = await createBinarySessionTargets();
|
||||||
const calls: string[] = [];
|
const calls: string[] = [];
|
||||||
const session = createTestBinarySession(createCacheProvider(calls));
|
const session = createTestBinarySession(createCacheProvider(calls));
|
||||||
expect((await session.open(first)).ok).toBe(true);
|
await openAndExecuteAddressName(session, first, {});
|
||||||
expect((await session.execute("address_name", {})).ok).toBe(true);
|
|
||||||
expect((await session.execute("address_name", {})).ok).toBe(true);
|
expect((await session.execute("address_name", {})).ok).toBe(true);
|
||||||
expect(calls).toEqual(["health", "address_name", "address_name"]);
|
expect(calls).toEqual(["health", "address_name", "address_name"]);
|
||||||
expect(session.exportAnalysisSnapshot()).toMatchObject({
|
expect(session.exportAnalysisSnapshot()).toMatchObject({
|
||||||
|
|||||||
+29
-30
@@ -184,26 +184,18 @@ it("keeps suffix-named ASAR directories in the graph and analyzes their files",
|
|||||||
),
|
),
|
||||||
).toBe(true);
|
).toBe(true);
|
||||||
|
|
||||||
const result = await reconstructJavaScriptArtifact({
|
await reconstructAsarArchive(archive, [
|
||||||
input_path: archive,
|
expect.objectContaining({
|
||||||
format: "asar",
|
kind: "javascript-asset",
|
||||||
});
|
observations: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
expect(result.statistics.parsed_javascript_files).toBeGreaterThan(0);
|
properties: expect.objectContaining({
|
||||||
expect(result.graph.nodes).toEqual(
|
path: "node_modules/@zip.js/entry.js",
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
kind: "javascript-asset",
|
|
||||||
observations: expect.arrayContaining([
|
|
||||||
expect.objectContaining({
|
|
||||||
properties: expect.objectContaining({
|
|
||||||
path: "node_modules/@zip.js/entry.js",
|
|
||||||
}),
|
|
||||||
}),
|
}),
|
||||||
]),
|
}),
|
||||||
}),
|
]),
|
||||||
]),
|
}),
|
||||||
);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps ASAR analysis usable when unpacked native companion bytes are absent", async () => {
|
it("keeps ASAR analysis usable when unpacked native companion bytes are absent", async () => {
|
||||||
@@ -228,17 +220,9 @@ it("keeps ASAR analysis usable when unpacked native companion bytes are absent",
|
|||||||
]),
|
]),
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await reconstructJavaScriptArtifact({
|
await reconstructAsarArchive(archive, [
|
||||||
input_path: archive,
|
expect.objectContaining({ kind: "javascript-asset" }),
|
||||||
format: "asar",
|
]);
|
||||||
});
|
|
||||||
|
|
||||||
expect(result.statistics.parsed_javascript_files).toBeGreaterThan(0);
|
|
||||||
expect(result.graph.nodes).toEqual(
|
|
||||||
expect.arrayContaining([
|
|
||||||
expect.objectContaining({ kind: "javascript-asset" }),
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("recurses into filesystem-backed ASAR containers without losing container-relative paths", async () => {
|
it("recurses into filesystem-backed ASAR containers without losing container-relative paths", async () => {
|
||||||
@@ -360,6 +344,21 @@ const assertSemanticLinks = (
|
|||||||
expect(endpointJson).toContain("token=fixture-secret");
|
expect(endpointJson).toContain("token=fixture-secret");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const reconstructAsarArchive = async (
|
||||||
|
archive: string,
|
||||||
|
expectedNodes: readonly unknown[],
|
||||||
|
): Promise<Awaited<ReturnType<typeof reconstructJavaScriptArtifact>>> => {
|
||||||
|
const result = await reconstructJavaScriptArtifact({
|
||||||
|
input_path: archive,
|
||||||
|
format: "asar",
|
||||||
|
});
|
||||||
|
expect(result.statistics.parsed_javascript_files).toBeGreaterThan(0);
|
||||||
|
expect(result.graph.nodes).toEqual(
|
||||||
|
expect.arrayContaining([...expectedNodes]),
|
||||||
|
);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
const fixtureDirectory = async (): Promise<string> => {
|
const fixtureDirectory = async (): Promise<string> => {
|
||||||
const root = await createTestTempDirectory("rea-javascript-artifact-");
|
const root = await createTestTempDirectory("rea-javascript-artifact-");
|
||||||
await writeJavaScriptArtifactFixture(root);
|
await writeJavaScriptArtifactFixture(root);
|
||||||
|
|||||||
@@ -1,29 +1,43 @@
|
|||||||
import { mkdir, writeFile } from "node:fs/promises";
|
|
||||||
import { join } from "node:path";
|
|
||||||
|
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||||
|
|
||||||
import { reconstructJavaScriptArtifact } from "../../../src/application/JavaScriptArtifactReconstruction.js";
|
import {
|
||||||
import type {
|
findChunkNode,
|
||||||
ApplicationEdge,
|
findGraphEdge,
|
||||||
ApplicationNode,
|
findModuleNodeByKey,
|
||||||
JavaScriptApplicationGraph,
|
reconstructJavaScriptFixture,
|
||||||
} from "../../../src/domain/javascriptApplicationGraph.js";
|
writeFixtureFiles,
|
||||||
|
} from "../../support/javascriptApplicationFixture.js";
|
||||||
|
|
||||||
describe("Webpack and Rspack runtime adapters", () => {
|
describe("Webpack and Rspack runtime adapters", () => {
|
||||||
it("recovers runtime entry modules, async chunks, and factory require aliases", async () => {
|
it("recovers runtime entry modules, async chunks, and factory require aliases", async () => {
|
||||||
const root = await bundlerFixture();
|
const root = await bundlerFixture();
|
||||||
const result = await reconstructJavaScriptArtifact({ input_path: root });
|
const result = await reconstructJavaScriptFixture(root);
|
||||||
const graph = result.graph;
|
const graph = result.graph;
|
||||||
|
|
||||||
const webpackEntry = chunk(graph, "webpackChunkcustomPortal", "main");
|
const webpackEntry = findChunkNode(
|
||||||
const webpackLazy = chunk(graph, "webpackChunkcustomPortal", "lazy");
|
graph,
|
||||||
const webpackModule = moduleNode(graph, "10");
|
"webpackChunkcustomPortal",
|
||||||
const rspackEntry = chunk(graph, "rspackChunkcustomPortal", "editor");
|
"main",
|
||||||
const rspackModel = chunk(graph, "rspackChunkcustomPortal", "model");
|
);
|
||||||
const rspackModule = moduleNode(graph, "src/entry.ts");
|
const webpackLazy = findChunkNode(
|
||||||
|
graph,
|
||||||
|
"webpackChunkcustomPortal",
|
||||||
|
"lazy",
|
||||||
|
);
|
||||||
|
const webpackModule = findModuleNodeByKey(graph, "10");
|
||||||
|
const rspackEntry = findChunkNode(
|
||||||
|
graph,
|
||||||
|
"rspackChunkcustomPortal",
|
||||||
|
"editor",
|
||||||
|
);
|
||||||
|
const rspackModel = findChunkNode(
|
||||||
|
graph,
|
||||||
|
"rspackChunkcustomPortal",
|
||||||
|
"model",
|
||||||
|
);
|
||||||
|
const rspackModule = findModuleNodeByKey(graph, "src/entry.ts");
|
||||||
|
|
||||||
expect(webpackEntry?.observations[0]?.properties).toMatchObject({
|
expect(webpackEntry?.observations[0]?.properties).toMatchObject({
|
||||||
bundler: "webpack",
|
bundler: "webpack",
|
||||||
@@ -49,32 +63,42 @@ describe("Webpack and Rspack runtime adapters", () => {
|
|||||||
runtime_entry: true,
|
runtime_entry: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(edge(graph, webpackEntry, webpackModule, "loads")).toMatchObject({
|
expect(
|
||||||
|
findGraphEdge(graph, webpackEntry, webpackModule, "loads"),
|
||||||
|
).toMatchObject({
|
||||||
properties: expect.objectContaining({
|
properties: expect.objectContaining({
|
||||||
kind: "bundler-entry-module",
|
kind: "bundler-entry-module",
|
||||||
resolution_status: "resolved",
|
resolution_status: "resolved",
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
expect(edge(graph, webpackEntry, webpackLazy, "imports")).toMatchObject({
|
expect(
|
||||||
|
findGraphEdge(graph, webpackEntry, webpackLazy, "imports"),
|
||||||
|
).toMatchObject({
|
||||||
properties: expect.objectContaining({
|
properties: expect.objectContaining({
|
||||||
kind: "bundler-async-chunk",
|
kind: "bundler-async-chunk",
|
||||||
resolution_status: "resolved",
|
resolution_status: "resolved",
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
expect(edge(graph, webpackModule, webpackLazy, "imports")).toMatchObject({
|
expect(
|
||||||
|
findGraphEdge(graph, webpackModule, webpackLazy, "imports"),
|
||||||
|
).toMatchObject({
|
||||||
properties: expect.objectContaining({
|
properties: expect.objectContaining({
|
||||||
kind: "dynamic-import",
|
kind: "dynamic-import",
|
||||||
specifier: "chunk:lazy",
|
specifier: "chunk:lazy",
|
||||||
resolved_path: "renderer/chunks/runtime.js#chunk:lazy",
|
resolved_path: "renderer/chunks/runtime.js#chunk:lazy",
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
expect(edge(graph, rspackEntry, rspackModel, "imports")).toMatchObject({
|
expect(
|
||||||
|
findGraphEdge(graph, rspackEntry, rspackModel, "imports"),
|
||||||
|
).toMatchObject({
|
||||||
properties: expect.objectContaining({
|
properties: expect.objectContaining({
|
||||||
kind: "bundler-async-chunk",
|
kind: "bundler-async-chunk",
|
||||||
resolution_status: "resolved",
|
resolution_status: "resolved",
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
expect(edge(graph, rspackModule, rspackModel, "imports")).toMatchObject({
|
expect(
|
||||||
|
findGraphEdge(graph, rspackModule, rspackModel, "imports"),
|
||||||
|
).toMatchObject({
|
||||||
properties: expect.objectContaining({
|
properties: expect.objectContaining({
|
||||||
kind: "dynamic-import",
|
kind: "dynamic-import",
|
||||||
specifier: "chunk:model",
|
specifier: "chunk:model",
|
||||||
@@ -103,11 +127,9 @@ describe("Webpack and Rspack runtime adapters", () => {
|
|||||||
|
|
||||||
it("recovers esbuild wrapper modules and Vite preload dependencies", async () => {
|
it("recovers esbuild wrapper modules and Vite preload dependencies", async () => {
|
||||||
const root = await esmRuntimeFixture();
|
const root = await esmRuntimeFixture();
|
||||||
const { graph } = await reconstructJavaScriptArtifact({
|
const { graph } = await reconstructJavaScriptFixture(root);
|
||||||
input_path: root,
|
const commonJsModule = findModuleNodeByKey(graph, "src/dep.js");
|
||||||
});
|
const esmModule = findModuleNodeByKey(graph, "src/core.js");
|
||||||
const commonJsModule = moduleNode(graph, "src/dep.js");
|
|
||||||
const esmModule = moduleNode(graph, "src/core.js");
|
|
||||||
|
|
||||||
expect(commonJsModule?.observations[0]?.properties).toMatchObject({
|
expect(commonJsModule?.observations[0]?.properties).toMatchObject({
|
||||||
bundler: "esbuild",
|
bundler: "esbuild",
|
||||||
@@ -132,10 +154,8 @@ describe("Webpack and Rspack runtime adapters", () => {
|
|||||||
|
|
||||||
const bundlerFixture = async (): Promise<string> => {
|
const bundlerFixture = async (): Promise<string> => {
|
||||||
const root = await createTestTempDirectory("rea-bundler-adapters-");
|
const root = await createTestTempDirectory("rea-bundler-adapters-");
|
||||||
await mkdir(join(root, "renderer", "chunks"), { recursive: true });
|
await writeFixtureFiles(root, {
|
||||||
await writeFile(
|
"renderer/chunks/runtime.js": `
|
||||||
join(root, "renderer", "chunks", "runtime.js"),
|
|
||||||
`
|
|
||||||
var __webpack_module_cache__ = {};
|
var __webpack_module_cache__ = {};
|
||||||
(globalThis["webpackChunkcustomPortal"] = globalThis["webpackChunkcustomPortal"] || []).push([
|
(globalThis["webpackChunkcustomPortal"] = globalThis["webpackChunkcustomPortal"] || []).push([
|
||||||
["main"],
|
["main"],
|
||||||
@@ -179,15 +199,14 @@ const bundlerFixture = async (): Promise<string> => {
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
`,
|
`,
|
||||||
);
|
});
|
||||||
return root;
|
return root;
|
||||||
};
|
};
|
||||||
|
|
||||||
const esmRuntimeFixture = async (): Promise<string> => {
|
const esmRuntimeFixture = async (): Promise<string> => {
|
||||||
const root = await createTestTempDirectory("rea-esm-runtime-adapters-");
|
const root = await createTestTempDirectory("rea-esm-runtime-adapters-");
|
||||||
await writeFile(
|
await writeFixtureFiles(root, {
|
||||||
join(root, "main.js"),
|
"main.js": `
|
||||||
`
|
|
||||||
const __vite__mapDeps = (indexes, map = __vite__mapDeps, dependencies =
|
const __vite__mapDeps = (indexes, map = __vite__mapDeps, dependencies =
|
||||||
(map.f || (map.f = ["./feature.js", "./main.css"]))) =>
|
(map.f || (map.f = ["./feature.js", "./main.css"]))) =>
|
||||||
indexes.map((index) => dependencies[index]);
|
indexes.map((index) => dependencies[index]);
|
||||||
@@ -204,51 +223,8 @@ const esmRuntimeFixture = async (): Promise<string> => {
|
|||||||
__vite__mapDeps([0, 1]);
|
__vite__mapDeps([0, 1]);
|
||||||
init_core();
|
init_core();
|
||||||
`,
|
`,
|
||||||
);
|
"feature.js": "export const feature = true;",
|
||||||
await writeFile(join(root, "feature.js"), "export const feature = true;");
|
"main.css": ".app { color: green; }",
|
||||||
await writeFile(join(root, "main.css"), ".app { color: green; }");
|
});
|
||||||
return root;
|
return root;
|
||||||
};
|
};
|
||||||
|
|
||||||
const chunk = (
|
|
||||||
graph: JavaScriptApplicationGraph,
|
|
||||||
runtime: string,
|
|
||||||
chunkKey: string,
|
|
||||||
): ApplicationNode | undefined =>
|
|
||||||
graph.nodes.find(
|
|
||||||
({ kind, observations }) =>
|
|
||||||
kind === "javascript-chunk" &&
|
|
||||||
observations.some(
|
|
||||||
({ properties }) =>
|
|
||||||
properties.runtime === runtime &&
|
|
||||||
Array.isArray(properties.chunk_keys) &&
|
|
||||||
properties.chunk_keys.includes(chunkKey),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
const moduleNode = (
|
|
||||||
graph: JavaScriptApplicationGraph,
|
|
||||||
moduleKey: string,
|
|
||||||
): ApplicationNode | undefined =>
|
|
||||||
graph.nodes.find(
|
|
||||||
({ kind, observations }) =>
|
|
||||||
kind === "javascript-module" &&
|
|
||||||
observations.some(
|
|
||||||
({ properties }) => properties.module_key === moduleKey,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
const edge = (
|
|
||||||
graph: JavaScriptApplicationGraph,
|
|
||||||
source: ApplicationNode | undefined,
|
|
||||||
target: ApplicationNode | undefined,
|
|
||||||
relation: string,
|
|
||||||
): ApplicationEdge | undefined =>
|
|
||||||
graph.edges.find(
|
|
||||||
({ source_node_id, target_node_id, relation: edgeRelation }) =>
|
|
||||||
source !== undefined &&
|
|
||||||
target !== undefined &&
|
|
||||||
source_node_id === source.node_id &&
|
|
||||||
target_node_id === target.node_id &&
|
|
||||||
edgeRelation === relation,
|
|
||||||
);
|
|
||||||
|
|||||||
@@ -1,31 +1,32 @@
|
|||||||
import { mkdir, writeFile } from "node:fs/promises";
|
import { writeFile } from "node:fs/promises";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
|
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||||
|
|
||||||
import { reconstructJavaScriptArtifact } from "../../../src/application/JavaScriptArtifactReconstruction.js";
|
import {
|
||||||
import type {
|
findExportNode,
|
||||||
ApplicationEdge,
|
findRelationshipEdge,
|
||||||
ApplicationNode,
|
findSourceModule,
|
||||||
JavaScriptApplicationGraph,
|
reconstructJavaScriptFixture,
|
||||||
} from "../../../src/domain/javascriptApplicationGraph.js";
|
writeFixtureFiles,
|
||||||
|
} from "../../support/javascriptApplicationFixture.js";
|
||||||
|
|
||||||
describe("CommonJS and ESM module relationships", () => {
|
describe("CommonJS and ESM module relationships", () => {
|
||||||
it("composes bindings, re-exports, dynamic imports, and JSON modules", async () => {
|
it("composes bindings, re-exports, dynamic imports, and JSON modules", async () => {
|
||||||
const root = await moduleFixture();
|
const root = await moduleFixture();
|
||||||
const first = await reconstructJavaScriptArtifact({ input_path: root });
|
const first = await reconstructJavaScriptFixture(root);
|
||||||
const second = await reconstructJavaScriptArtifact({ input_path: root });
|
const second = await reconstructJavaScriptFixture(root);
|
||||||
const graph = first.graph;
|
const graph = first.graph;
|
||||||
|
|
||||||
expect(second.graph).toEqual(graph);
|
expect(second.graph).toEqual(graph);
|
||||||
expect(sourceModule(graph, "main.cjs")).toBeDefined();
|
expect(findSourceModule(graph, "main.cjs")).toBeDefined();
|
||||||
expect(sourceModule(graph, "consumer.mjs")).toBeDefined();
|
expect(findSourceModule(graph, "consumer.mjs")).toBeDefined();
|
||||||
expect(sourceModule(graph, "dependency.mjs")).toBeDefined();
|
expect(findSourceModule(graph, "dependency.mjs")).toBeDefined();
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
relationship(graph, {
|
findRelationshipEdge(graph, {
|
||||||
kind: "require",
|
kind: "require",
|
||||||
specifier: "./dependency.mjs",
|
specifier: "./dependency.mjs",
|
||||||
resolvedPath: "dependency.mjs",
|
resolvedPath: "dependency.mjs",
|
||||||
@@ -46,7 +47,7 @@ describe("CommonJS and ESM module relationships", () => {
|
|||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
relationship(graph, {
|
findRelationshipEdge(graph, {
|
||||||
kind: "require",
|
kind: "require",
|
||||||
specifier: "fixture-package",
|
specifier: "fixture-package",
|
||||||
resolvedPath: "node_modules/fixture-package/cjs.cjs",
|
resolvedPath: "node_modules/fixture-package/cjs.cjs",
|
||||||
@@ -54,7 +55,7 @@ describe("CommonJS and ESM module relationships", () => {
|
|||||||
}),
|
}),
|
||||||
).toBeDefined();
|
).toBeDefined();
|
||||||
expect(
|
expect(
|
||||||
relationship(graph, {
|
findRelationshipEdge(graph, {
|
||||||
kind: "import",
|
kind: "import",
|
||||||
specifier: "fixture-package",
|
specifier: "fixture-package",
|
||||||
resolvedPath: "node_modules/fixture-package/esm.mjs",
|
resolvedPath: "node_modules/fixture-package/esm.mjs",
|
||||||
@@ -63,7 +64,7 @@ describe("CommonJS and ESM module relationships", () => {
|
|||||||
}),
|
}),
|
||||||
).toBeDefined();
|
).toBeDefined();
|
||||||
expect(
|
expect(
|
||||||
relationship(graph, {
|
findRelationshipEdge(graph, {
|
||||||
kind: "import",
|
kind: "import",
|
||||||
specifier: "./values.js",
|
specifier: "./values.js",
|
||||||
resolvedPath: "values.js",
|
resolvedPath: "values.js",
|
||||||
@@ -72,7 +73,7 @@ describe("CommonJS and ESM module relationships", () => {
|
|||||||
}),
|
}),
|
||||||
).toBeDefined();
|
).toBeDefined();
|
||||||
expect(
|
expect(
|
||||||
relationship(graph, {
|
findRelationshipEdge(graph, {
|
||||||
kind: "re-export",
|
kind: "re-export",
|
||||||
specifier: "./star.js",
|
specifier: "./star.js",
|
||||||
resolvedPath: "star.js",
|
resolvedPath: "star.js",
|
||||||
@@ -81,7 +82,7 @@ describe("CommonJS and ESM module relationships", () => {
|
|||||||
}),
|
}),
|
||||||
).toBeDefined();
|
).toBeDefined();
|
||||||
|
|
||||||
const forwarded = exportNode(graph, "main.cjs", "forwarded");
|
const forwarded = findExportNode(graph, "main.cjs", "forwarded");
|
||||||
expect(forwarded).toBeDefined();
|
expect(forwarded).toBeDefined();
|
||||||
expect(
|
expect(
|
||||||
graph.edges.some(
|
graph.edges.some(
|
||||||
@@ -101,11 +102,11 @@ describe("CommonJS and ESM module relationships", () => {
|
|||||||
properties.resolved_path === "lazy.js",
|
properties.resolved_path === "lazy.js",
|
||||||
),
|
),
|
||||||
).toMatchObject({
|
).toMatchObject({
|
||||||
source_node_id: sourceModule(graph, "consumer.mjs")?.node_id,
|
source_node_id: findSourceModule(graph, "consumer.mjs")?.node_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
relationship(graph, {
|
findRelationshipEdge(graph, {
|
||||||
kind: "require",
|
kind: "require",
|
||||||
specifier: "./data.json",
|
specifier: "./data.json",
|
||||||
resolvedPath: "data.json",
|
resolvedPath: "data.json",
|
||||||
@@ -115,7 +116,7 @@ describe("CommonJS and ESM module relationships", () => {
|
|||||||
target_json_status: "included",
|
target_json_status: "included",
|
||||||
});
|
});
|
||||||
expect(
|
expect(
|
||||||
relationship(graph, {
|
findRelationshipEdge(graph, {
|
||||||
kind: "require",
|
kind: "require",
|
||||||
specifier: "./broken.json",
|
specifier: "./broken.json",
|
||||||
resolvedPath: "broken.json",
|
resolvedPath: "broken.json",
|
||||||
@@ -125,7 +126,7 @@ describe("CommonJS and ESM module relationships", () => {
|
|||||||
target_json_status: "invalid",
|
target_json_status: "invalid",
|
||||||
});
|
});
|
||||||
expect(
|
expect(
|
||||||
relationship(graph, {
|
findRelationshipEdge(graph, {
|
||||||
kind: "require",
|
kind: "require",
|
||||||
specifier: "electron",
|
specifier: "electron",
|
||||||
})?.properties,
|
})?.properties,
|
||||||
@@ -164,8 +165,8 @@ describe("complete static application projections", () => {
|
|||||||
writeFile(join(root, "many.json"), JSON.stringify(jsonKeys)),
|
writeFile(join(root, "many.json"), JSON.stringify(jsonKeys)),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const { graph } = await reconstructJavaScriptArtifact({ input_path: root });
|
const { graph } = await reconstructJavaScriptFixture(root);
|
||||||
const module = sourceModule(graph, "many-exports.mjs");
|
const module = findSourceModule(graph, "many-exports.mjs");
|
||||||
const exportObservation = module?.observations.find(
|
const exportObservation = module?.observations.find(
|
||||||
({ properties }) => properties.semantic_role === "source-module",
|
({ properties }) => properties.semantic_role === "source-module",
|
||||||
);
|
);
|
||||||
@@ -187,14 +188,9 @@ describe("complete static application projections", () => {
|
|||||||
|
|
||||||
const moduleFixture = async (): Promise<string> => {
|
const moduleFixture = async (): Promise<string> => {
|
||||||
const root = await createTestTempDirectory("rea-module-relationships-");
|
const root = await createTestTempDirectory("rea-module-relationships-");
|
||||||
await mkdir(join(root, "node_modules", "fixture-package"), {
|
await writeFixtureFiles(root, {
|
||||||
recursive: true,
|
"package.json": '{"main":"main.cjs"}',
|
||||||
});
|
"main.cjs": `
|
||||||
await Promise.all([
|
|
||||||
writeFile(join(root, "package.json"), '{"main":"main.cjs"}'),
|
|
||||||
writeFile(
|
|
||||||
join(root, "main.cjs"),
|
|
||||||
`
|
|
||||||
const { value: importedValue } = require("./dependency.mjs");
|
const { value: importedValue } = require("./dependency.mjs");
|
||||||
const data = require("./data.json");
|
const data = require("./data.json");
|
||||||
const broken = require("./broken.json");
|
const broken = require("./broken.json");
|
||||||
@@ -207,104 +203,32 @@ const moduleFixture = async (): Promise<string> => {
|
|||||||
exports.packageValue = packageValue;
|
exports.packageValue = packageValue;
|
||||||
require(dynamicName);
|
require(dynamicName);
|
||||||
`,
|
`,
|
||||||
),
|
"dependency.mjs": `
|
||||||
writeFile(
|
|
||||||
join(root, "dependency.mjs"),
|
|
||||||
`
|
|
||||||
export { value } from "./values.js";
|
export { value } from "./values.js";
|
||||||
export * from "./star.js";
|
export * from "./star.js";
|
||||||
`,
|
`,
|
||||||
),
|
"consumer.mjs": `
|
||||||
writeFile(
|
|
||||||
join(root, "consumer.mjs"),
|
|
||||||
`
|
|
||||||
import { value as alias } from "./values.js";
|
import { value as alias } from "./values.js";
|
||||||
import packageDefault from "fixture-package";
|
import packageDefault from "fixture-package";
|
||||||
export { alias as relayed };
|
export { alias as relayed };
|
||||||
void import("./lazy.js");
|
void import("./lazy.js");
|
||||||
void packageDefault;
|
void packageDefault;
|
||||||
`,
|
`,
|
||||||
),
|
"values.js": "export const value = 42;",
|
||||||
writeFile(join(root, "values.js"), "export const value = 42;"),
|
"star.js": "export const extra = true;",
|
||||||
writeFile(join(root, "star.js"), "export const extra = true;"),
|
"lazy.js": "export default 'lazy';",
|
||||||
writeFile(join(root, "lazy.js"), "export default 'lazy';"),
|
"data.json": '{"name":"fixture","value":42}',
|
||||||
writeFile(join(root, "data.json"), '{"name":"fixture","value":42}'),
|
"broken.json": '{"name":',
|
||||||
writeFile(join(root, "broken.json"), '{"name":'),
|
"node_modules/fixture-package/package.json": JSON.stringify({
|
||||||
writeFile(
|
exports: {
|
||||||
join(root, "node_modules", "fixture-package", "package.json"),
|
".": {
|
||||||
JSON.stringify({
|
import: "./esm.mjs",
|
||||||
exports: {
|
require: "./cjs.cjs",
|
||||||
".": {
|
|
||||||
import: "./esm.mjs",
|
|
||||||
require: "./cjs.cjs",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
),
|
}),
|
||||||
writeFile(
|
"node_modules/fixture-package/esm.mjs": "export default 'esm';",
|
||||||
join(root, "node_modules", "fixture-package", "esm.mjs"),
|
"node_modules/fixture-package/cjs.cjs": "module.exports = 'cjs';",
|
||||||
"export default 'esm';",
|
});
|
||||||
),
|
|
||||||
writeFile(
|
|
||||||
join(root, "node_modules", "fixture-package", "cjs.cjs"),
|
|
||||||
"module.exports = 'cjs';",
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
return root;
|
return root;
|
||||||
};
|
};
|
||||||
|
|
||||||
interface RelationshipQuery {
|
|
||||||
readonly kind: string;
|
|
||||||
readonly specifier: string;
|
|
||||||
readonly resolvedPath?: string;
|
|
||||||
readonly importedName?: string;
|
|
||||||
readonly localName?: string;
|
|
||||||
readonly exportedName?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const relationship = (
|
|
||||||
graph: JavaScriptApplicationGraph,
|
|
||||||
query: RelationshipQuery,
|
|
||||||
): ApplicationEdge | undefined =>
|
|
||||||
graph.edges.find(
|
|
||||||
({ relation, properties }) =>
|
|
||||||
relation === "imports" &&
|
|
||||||
properties.module_link_kind === query.kind &&
|
|
||||||
properties.specifier === query.specifier &&
|
|
||||||
(query.resolvedPath === undefined ||
|
|
||||||
properties.resolved_path === query.resolvedPath) &&
|
|
||||||
(query.importedName === undefined ||
|
|
||||||
properties.imported_name === query.importedName) &&
|
|
||||||
(query.localName === undefined ||
|
|
||||||
properties.local_name === query.localName) &&
|
|
||||||
(query.exportedName === undefined ||
|
|
||||||
properties.exported_name === query.exportedName),
|
|
||||||
);
|
|
||||||
|
|
||||||
const sourceModule = (
|
|
||||||
graph: JavaScriptApplicationGraph,
|
|
||||||
path: string,
|
|
||||||
): ApplicationNode | undefined =>
|
|
||||||
graph.nodes.find(
|
|
||||||
(node) =>
|
|
||||||
node.kind === "javascript-module" &&
|
|
||||||
node.observations.some(
|
|
||||||
({ properties }) => properties.logical_module_key === path,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
const exportNode = (
|
|
||||||
graph: JavaScriptApplicationGraph,
|
|
||||||
path: string,
|
|
||||||
name: string,
|
|
||||||
): ApplicationNode | undefined =>
|
|
||||||
graph.nodes.find(
|
|
||||||
(node) =>
|
|
||||||
node.kind === "javascript-module" &&
|
|
||||||
node.observations.some(
|
|
||||||
({ properties }) =>
|
|
||||||
properties.semantic_role === "export-binding" &&
|
|
||||||
properties.module_path === path &&
|
|
||||||
properties.exported_name === name,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
completeVerifierRun,
|
completeVerifierRun,
|
||||||
createVerifierRun,
|
createVerifierRun,
|
||||||
} from "../../scripts/lib/verifier-run.mjs";
|
} from "../../scripts/lib/verifier-run.mjs";
|
||||||
|
import { waitForExit } from "../support/process/processFixture.js";
|
||||||
|
|
||||||
const execFileAsync = promisify(execFile);
|
const execFileAsync = promisify(execFile);
|
||||||
const CHILD_SHUTDOWN_GRACE_MS = 1_000;
|
const CHILD_SHUTDOWN_GRACE_MS = 1_000;
|
||||||
@@ -154,27 +155,6 @@ const stopChild = async (child: ChildProcess): Promise<void> => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const waitForExit = (
|
|
||||||
child: ChildProcess,
|
|
||||||
timeoutMs: number,
|
|
||||||
): Promise<boolean> =>
|
|
||||||
new Promise((resolve) => {
|
|
||||||
if (child.exitCode !== null || child.signalCode !== null) {
|
|
||||||
resolve(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const timer = setTimeout(() => {
|
|
||||||
child.removeListener("exit", onExit);
|
|
||||||
resolve(false);
|
|
||||||
}, timeoutMs);
|
|
||||||
timer.unref();
|
|
||||||
const onExit = (): void => {
|
|
||||||
clearTimeout(timer);
|
|
||||||
resolve(true);
|
|
||||||
};
|
|
||||||
child.once("exit", onExit);
|
|
||||||
});
|
|
||||||
|
|
||||||
const restoreRunId = (runId: string | undefined): void => {
|
const restoreRunId = (runId: string | undefined): void => {
|
||||||
if (runId === undefined) delete process.env.REA_PROCESS_RUN_ID;
|
if (runId === undefined) delete process.env.REA_PROCESS_RUN_ID;
|
||||||
else process.env.REA_PROCESS_RUN_ID = runId;
|
else process.env.REA_PROCESS_RUN_ID = runId;
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { writeFile } from "node:fs/promises";
|
||||||
|
import { join } from "node:path";
|
||||||
|
|
||||||
|
import { TextReader, Uint8ArrayWriter, ZipWriter } from "@zip.js/zip.js";
|
||||||
|
import { expect } from "vitest";
|
||||||
|
|
||||||
|
import { runProviderAnalysis } from "../../src/application/DirectAnalysis.js";
|
||||||
|
import type { AnalysisError } from "../../src/domain/errors.js";
|
||||||
|
import { type Evidence, parseEvidence } from "../../src/domain/evidence.js";
|
||||||
|
import type { Result } from "../../src/domain/result.js";
|
||||||
|
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
||||||
|
|
||||||
|
/** Assert a projection succeeded and return its Evidence for schema parsing. */
|
||||||
|
export const requireSuccessfulProjection = (
|
||||||
|
result: Result<Evidence, AnalysisError>,
|
||||||
|
): Evidence => {
|
||||||
|
expect(result.ok).toBe(true);
|
||||||
|
if (!result.ok)
|
||||||
|
throw new TypeError("Expected application projection to succeed");
|
||||||
|
return result.value;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build inventory Evidence from a ZIP that is neither an APK nor an IPA.
|
||||||
|
* Both mobile projections must reject it with an AnalysisInputError.
|
||||||
|
*/
|
||||||
|
export const createNonApplicationZipInventory = async (
|
||||||
|
prefix: string,
|
||||||
|
): Promise<Evidence> => {
|
||||||
|
const root = await createTestTempDirectory(prefix);
|
||||||
|
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());
|
||||||
|
return parseEvidence(
|
||||||
|
await runProviderAnalysis(path, "inventory_artifact", {}),
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
import { mkdir, writeFile } from "node:fs/promises";
|
||||||
|
import { dirname, join } from "node:path";
|
||||||
|
|
||||||
|
import { reconstructJavaScriptArtifact } from "../../src/application/JavaScriptArtifactReconstruction.js";
|
||||||
|
import type {
|
||||||
|
ApplicationEdge,
|
||||||
|
ApplicationNode,
|
||||||
|
JavaScriptApplicationGraph,
|
||||||
|
} from "../../src/domain/javascriptApplicationGraph.js";
|
||||||
|
|
||||||
|
/** Write text fixture files, creating parent directories as needed. */
|
||||||
|
export const writeFixtureFiles = async (
|
||||||
|
root: string,
|
||||||
|
files: Readonly<Record<string, string>>,
|
||||||
|
): Promise<void> => {
|
||||||
|
await Promise.all(
|
||||||
|
Object.entries(files).map(async ([relative, contents]) => {
|
||||||
|
const path = join(root, relative);
|
||||||
|
await mkdir(dirname(path), { recursive: true });
|
||||||
|
await writeFile(path, contents);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Reconstruct one JavaScript artifact fixture directory. */
|
||||||
|
export const reconstructJavaScriptFixture = (
|
||||||
|
inputPath: string,
|
||||||
|
): Promise<Awaited<ReturnType<typeof reconstructJavaScriptArtifact>>> =>
|
||||||
|
reconstructJavaScriptArtifact({ input_path: inputPath });
|
||||||
|
|
||||||
|
/** Find a bundler chunk node by runtime and chunk key. */
|
||||||
|
export const findChunkNode = (
|
||||||
|
graph: JavaScriptApplicationGraph,
|
||||||
|
runtime: string,
|
||||||
|
chunkKey: string,
|
||||||
|
): ApplicationNode | undefined =>
|
||||||
|
graph.nodes.find(
|
||||||
|
({ kind, observations }) =>
|
||||||
|
kind === "javascript-chunk" &&
|
||||||
|
observations.some(
|
||||||
|
({ properties }) =>
|
||||||
|
properties.runtime === runtime &&
|
||||||
|
Array.isArray(properties.chunk_keys) &&
|
||||||
|
properties.chunk_keys.includes(chunkKey),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
/** Find a bundler module node by module key. */
|
||||||
|
export const findModuleNodeByKey = (
|
||||||
|
graph: JavaScriptApplicationGraph,
|
||||||
|
moduleKey: string,
|
||||||
|
): ApplicationNode | undefined =>
|
||||||
|
graph.nodes.find(
|
||||||
|
({ kind, observations }) =>
|
||||||
|
kind === "javascript-module" &&
|
||||||
|
observations.some(
|
||||||
|
({ properties }) => properties.module_key === moduleKey,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
/** Find one directed edge between two application nodes. */
|
||||||
|
export const findGraphEdge = (
|
||||||
|
graph: JavaScriptApplicationGraph,
|
||||||
|
source: ApplicationNode | undefined,
|
||||||
|
target: ApplicationNode | undefined,
|
||||||
|
relation: string,
|
||||||
|
): ApplicationEdge | undefined =>
|
||||||
|
graph.edges.find(
|
||||||
|
({ source_node_id, target_node_id, relation: edgeRelation }) =>
|
||||||
|
source !== undefined &&
|
||||||
|
target !== undefined &&
|
||||||
|
source_node_id === source.node_id &&
|
||||||
|
target_node_id === target.node_id &&
|
||||||
|
edgeRelation === relation,
|
||||||
|
);
|
||||||
|
|
||||||
|
/** Module-link facts used to query one import edge. */
|
||||||
|
export interface RelationshipQuery {
|
||||||
|
readonly kind: string;
|
||||||
|
readonly specifier: string;
|
||||||
|
readonly resolvedPath?: string;
|
||||||
|
readonly importedName?: string;
|
||||||
|
readonly localName?: string;
|
||||||
|
readonly exportedName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Find one module-link import edge matching the query. */
|
||||||
|
export const findRelationshipEdge = (
|
||||||
|
graph: JavaScriptApplicationGraph,
|
||||||
|
query: RelationshipQuery,
|
||||||
|
): ApplicationEdge | undefined =>
|
||||||
|
graph.edges.find(
|
||||||
|
({ relation, properties }) =>
|
||||||
|
relation === "imports" &&
|
||||||
|
properties.module_link_kind === query.kind &&
|
||||||
|
properties.specifier === query.specifier &&
|
||||||
|
(query.resolvedPath === undefined ||
|
||||||
|
properties.resolved_path === query.resolvedPath) &&
|
||||||
|
(query.importedName === undefined ||
|
||||||
|
properties.imported_name === query.importedName) &&
|
||||||
|
(query.localName === undefined ||
|
||||||
|
properties.local_name === query.localName) &&
|
||||||
|
(query.exportedName === undefined ||
|
||||||
|
properties.exported_name === query.exportedName),
|
||||||
|
);
|
||||||
|
|
||||||
|
/** Find a source module node by logical path. */
|
||||||
|
export const findSourceModule = (
|
||||||
|
graph: JavaScriptApplicationGraph,
|
||||||
|
path: string,
|
||||||
|
): ApplicationNode | undefined =>
|
||||||
|
graph.nodes.find(
|
||||||
|
(node) =>
|
||||||
|
node.kind === "javascript-module" &&
|
||||||
|
node.observations.some(
|
||||||
|
({ properties }) => properties.logical_module_key === path,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
/** Find one export-binding node by module path and export name. */
|
||||||
|
export const findExportNode = (
|
||||||
|
graph: JavaScriptApplicationGraph,
|
||||||
|
path: string,
|
||||||
|
name: string,
|
||||||
|
): ApplicationNode | undefined =>
|
||||||
|
graph.nodes.find(
|
||||||
|
(node) =>
|
||||||
|
node.kind === "javascript-module" &&
|
||||||
|
node.observations.some(
|
||||||
|
({ properties }) =>
|
||||||
|
properties.semantic_role === "export-binding" &&
|
||||||
|
properties.module_path === path &&
|
||||||
|
properties.exported_name === name,
|
||||||
|
),
|
||||||
|
);
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
spawn as nodeSpawn,
|
spawn as nodeSpawn,
|
||||||
|
type ChildProcess,
|
||||||
type ChildProcessWithoutNullStreams,
|
type ChildProcessWithoutNullStreams,
|
||||||
type SpawnOptionsWithoutStdio,
|
type SpawnOptionsWithoutStdio,
|
||||||
} from "node:child_process";
|
} from "node:child_process";
|
||||||
@@ -37,8 +38,9 @@ export interface TestProcesses {
|
|||||||
shutdown(): Promise<void>;
|
shutdown(): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const waitForExit = (
|
/** Wait for a child process to exit within a timeout, reporting completion. */
|
||||||
child: ChildProcessWithoutNullStreams,
|
export const waitForExit = (
|
||||||
|
child: ChildProcess,
|
||||||
timeoutMs: number,
|
timeoutMs: number,
|
||||||
): Promise<boolean> =>
|
): Promise<boolean> =>
|
||||||
new Promise((resolve) => {
|
new Promise((resolve) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user