test: prune redundant and implementation-coupled coverage

This commit is contained in:
morluto committed 2026-11-17 18:48:24 -05:00
1 parent 14b15ba8a5
commit 48e27e19b7
191 files changed
+2757 -5418

No files matched your search

@@ -1,3 +1,4 @@
import { createHash } from "node:crypto";
import { describe, expect, it } from "vitest";
import {
computeJavaScriptApplicationGraphSha256,
@@ -178,10 +179,9 @@ describe("JavaScript Application Graph: vocabulary", () => {
const decoded: unknown = JSON.parse(serialized);
expect(parseJavaScriptApplicationGraph(decoded)).toEqual(graph);
expect(javascriptApplicationGraphSchema.parse(decoded)).toEqual(graph);
expect(serializeJavaScriptApplicationGraph(decoded)).toBe(serialized);
expect(computeJavaScriptApplicationGraphSha256(decoded)).toMatch(
/^[a-f0-9]{64}$/u,
expect(computeJavaScriptApplicationGraphSha256(decoded)).toBe(
createHash("sha256").update(serialized).digest("hex"),
);
const { graph_id: _graphId, ...semantic } = graph;
@@ -207,39 +207,6 @@ describe("JavaScript Application Graph: vocabulary", () => {
Object.keys(largeExport?.observations[0]?.properties ?? {}),
).toHaveLength(1_001);
});
it("represents the synthetic ASAR to preload to IPC to native chain", () => {
const graph = buildSyntheticJavaScriptApplicationGraph();
const labels = [
"resources/app.asar",
"desktop preload",
"desktopApi",
"project:open",
"project open handler",
"synthetic.node",
"openProject",
];
const chain = labels.map((label) => nodeByLabel(graph, label));
const expectedRelations = [
"contains",
"exposes",
"invokes",
"handles",
"loads",
"contains",
];
for (let index = 0; index < expectedRelations.length; index += 1)
expect(graph.edges).toContainEqual(
expect.objectContaining({
source_node_id: chain[index]?.node_id,
target_node_id: chain[index + 1]?.node_id,
relation: expectedRelations[index],
}),
);
expect(chain.at(-2)?.kind).toBe("native-addon");
expect(chain.at(-1)?.kind).toBe("native-export");
});
});
describe("JavaScript Application Graph: evidence authority", () => {
@@ -1,51 +1,15 @@
import * as t from "@babel/types";
import { describe, expect, it } from "vitest";
import { expect, it } from "vitest";
import { parseJavaScriptSource } from "./javascriptSourceParser.js";
import {
javaScriptClassifiedNodeTypes,
javaScriptExecutions,
javaScriptTypeOnlyAliases,
} from "./javascriptSemanticExecutionPoints.js";
import { javaScriptExecutions } from "./javascriptSemanticExecutionPoints.js";
import { childNodes } from "./javascriptSemanticTraversal.js";
import { semanticPropertyReadSources } from "./javascriptSemanticIterationSources.js";
const installedNodeTypes = [
...new Set([...Object.keys(t.VISITOR_KEYS), ...Object.keys(t.NODE_FIELDS)]),
].sort();
const typeOnly = new Set<string>(
javaScriptTypeOnlyAliases.flatMap(
(alias) => t.FLIPPED_ALIAS_KEYS[alias] ?? [],
),
);
describe("JavaScript execution classification", () => {
it("classifies every installed Babel node type", () => {
const classified = new Set(javaScriptClassifiedNodeTypes());
const unclassified = installedNodeTypes.filter(
(type) =>
!classified.has(type) &&
(!typeOnly.has(type) || type === "EnumDeclaration"),
);
expect(unclassified).toEqual([]);
});
it("names no node type the installed Babel version lacks", () => {
const known = new Set([
...installedNodeTypes,
...Object.keys(t.DEPRECATED_KEYS),
]);
expect(
javaScriptClassifiedNodeTypes().filter((type) => !known.has(type)),
).toEqual([]);
});
it("treats a node type it does not know as code that may run", () => {
const future = { type: "FutureExpression" } as unknown as t.Node;
expect(javaScriptExecutions(future, null)).toMatchObject([
{ kind: "unsupported-syntax", node: future },
]);
});
it("treats a node type it does not know as code that may run", () => {
const future = { type: "FutureExpression" } as unknown as t.Node;
expect(javaScriptExecutions(future, null)).toMatchObject([
{ kind: "unsupported-syntax", node: future },
]);
});
const parsed = (source: string): t.Program => {
@@ -89,7 +53,6 @@ it.each([
["const copy = [...value];", { SpreadElement: ["iteration"] }],
["const copy = { ...value };", { SpreadElement: ["property-copy"] }],
["for (const item of value);", { ForOfStatement: ["iteration"] }],
["for (const key in value);", { ForInStatement: ["enumeration"] }],
[
"try { throw source; } catch ({ value }) {}",
{ CatchClause: ["destructuring"] },
@@ -117,9 +80,9 @@ it.each([
it("exposes the enumerated object", () => {
const node = parsed("for (const key in value);").body[0];
if (!t.isForInStatement(node)) throw new Error("Expected for-in statement");
expect(javaScriptExecutions(node, null)).toContainEqual(
expect.objectContaining({ kind: "enumeration", operands: [node.right] }),
);
expect(javaScriptExecutions(node, null)).toMatchObject([
{ kind: "enumeration", operands: [node.right] },
]);
});
it.each(["!trigger", "typeof trigger", "void trigger", "trigger === 1"])(
@@ -349,8 +349,7 @@ const moduleEvaluation: Classifier<t.Node> = (node) => [
/**
* One classifier per runtime Babel node type. The mapped type makes a new
* Babel node type a compile error; the guard test checks the installed
* runtime definitions as well.
* Babel node type a compile error.
*/
const classifiers: {
readonly [Type in ClassifiedType]: Classifier<
@@ -600,10 +599,3 @@ export const javaScriptExecutions = (
? unsupported(node, parent, options)
: classify(node, parent, options);
};
/** Node types with an explicit classifier, for the coverage guard. */
export const javaScriptClassifiedNodeTypes = (): readonly string[] =>
Object.keys(classifiers);
/** Babel aliases whose members have no runtime representation. */
export const javaScriptTypeOnlyAliases = typeOnlyAliases;