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:
@@ -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 {
|
||||
spawn as nodeSpawn,
|
||||
type ChildProcess,
|
||||
type ChildProcessWithoutNullStreams,
|
||||
type SpawnOptionsWithoutStdio,
|
||||
} from "node:child_process";
|
||||
@@ -37,8 +38,9 @@ export interface TestProcesses {
|
||||
shutdown(): Promise<void>;
|
||||
}
|
||||
|
||||
const waitForExit = (
|
||||
child: ChildProcessWithoutNullStreams,
|
||||
/** Wait for a child process to exit within a timeout, reporting completion. */
|
||||
export const waitForExit = (
|
||||
child: ChildProcess,
|
||||
timeoutMs: number,
|
||||
): Promise<boolean> =>
|
||||
new Promise((resolve) => {
|
||||
|
||||
Reference in New Issue
Block a user