mirror of
https://github.com/morluto/rea.git
synced 2026-11-13 10:12:50 +00:00
test: reduce brittle assertions and test-only runtime paths (#9289)
* test: focus assertions on behavioral evidence Prune redundant and wording-coupled checks while retaining diagnostic, parser, recovery, and cleanup coverage. * refactor: remove test-only wrappers and duplicate checks Exercise production operations through test fixtures, remove unused adapters, and keep managed-member uncertainty guidance under its existing owner. * test: focus process validation on diagnostic facts * refactor: remove test-only runtime helpers Move semantic evidence fixture setup out of runtime and remove unused Windows settle recovery helpers while checking configured defaults independently. * test: focus artifact diagnostics on format facts * test: verify retained cleanup guidance delivery
This commit is contained in:
1 parent
5679ed66f4
commit
352a846127
268 files changed
+586
-1141
No files matched your search
@@ -15,7 +15,6 @@ import {
|
||||
} from "./javascriptApplicationGraph.js";
|
||||
import {
|
||||
createJavaScriptSemanticGraph,
|
||||
createImmutableJavaScriptSemanticGraphSteps,
|
||||
isValidatedImmutableJavaScriptSemanticGraph,
|
||||
sealTransferredJavaScriptSemanticGraphSteps,
|
||||
} from "./javascriptSemanticGraph.js";
|
||||
@@ -41,7 +40,7 @@ const ownedExample = () => {
|
||||
createImmutableJavaScriptApplicationGraphSteps(application),
|
||||
),
|
||||
semantic_graph: complete(
|
||||
createImmutableJavaScriptSemanticGraphSteps(semantic),
|
||||
sealTransferredJavaScriptSemanticGraphSteps(semantic),
|
||||
),
|
||||
};
|
||||
};
|
||||
@@ -179,7 +178,7 @@ describe("owned JavaScript graph validation", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps ordinary constructors mutable and clones inputs before sealing", () => {
|
||||
it("keeps ordinary constructors mutable and seals independently owned inputs", () => {
|
||||
const input = example();
|
||||
const { graph_id: _applicationId, ...application } = input.graph;
|
||||
const { graph_id: _semanticId, ...semantic } = input.semantic_graph;
|
||||
@@ -189,7 +188,9 @@ describe("owned JavaScript graph validation", () => {
|
||||
expect(Object.isFrozen(ordinarySemantic)).toBe(false);
|
||||
const applicationSteps =
|
||||
createImmutableJavaScriptApplicationGraphSteps(application);
|
||||
const semanticSteps = createImmutableJavaScriptSemanticGraphSteps(semantic);
|
||||
const semanticSteps = sealTransferredJavaScriptSemanticGraphSteps(
|
||||
structuredClone(semantic),
|
||||
);
|
||||
application.limitations.push("Changed after factory input was cloned.");
|
||||
semantic.limitations.push("Changed after factory input was cloned.");
|
||||
expect(complete(applicationSteps)).toEqual(ordinaryApplication);
|
||||
@@ -270,12 +271,16 @@ describe("owned JavaScript graph validation", () => {
|
||||
};
|
||||
const mutable = createJavaScriptSemanticGraph(semantic);
|
||||
const { graph_id: _mutableId, ...mutableInput } = mutable;
|
||||
const steps = createImmutableJavaScriptSemanticGraphSteps(mutableInput);
|
||||
const steps = sealTransferredJavaScriptSemanticGraphSteps(
|
||||
structuredClone(mutableInput),
|
||||
);
|
||||
expect(steps.next().done).toBe(false);
|
||||
steps.return(mutable);
|
||||
expect(isValidatedImmutableJavaScriptSemanticGraph(mutable)).toBe(false);
|
||||
const sealed = complete(
|
||||
createImmutableJavaScriptSemanticGraphSteps(mutableInput),
|
||||
sealTransferredJavaScriptSemanticGraphSteps(
|
||||
structuredClone(mutableInput),
|
||||
),
|
||||
);
|
||||
expect(sealed).toEqual(mutable);
|
||||
expect(isValidatedImmutableJavaScriptSemanticGraph(sealed)).toBe(true);
|
||||
@@ -301,7 +306,7 @@ describe("owned JavaScript result bindings", () => {
|
||||
];
|
||||
}
|
||||
input.semantic_graph = complete(
|
||||
createImmutableJavaScriptSemanticGraphSteps(semantic),
|
||||
sealTransferredJavaScriptSemanticGraphSteps(semantic),
|
||||
);
|
||||
}
|
||||
expect(
|
||||
@@ -332,7 +337,7 @@ describe("owned JavaScript result bindings", () => {
|
||||
...semantic.nodes.slice(1),
|
||||
];
|
||||
input.semantic_graph = complete(
|
||||
createImmutableJavaScriptSemanticGraphSteps(semantic),
|
||||
sealTransferredJavaScriptSemanticGraphSteps(semantic),
|
||||
);
|
||||
freezeJsonSnapshot(input);
|
||||
const steps = parseOwnedJavaScriptApplicationAnalysisSteps(input);
|
||||
|
||||
@@ -25,7 +25,6 @@ import {
|
||||
type JavaScriptRuntimeTargetLocation,
|
||||
} from "./javascriptRuntimeObservation.js";
|
||||
import { digestCanonicalValue } from "../canonicalDigest.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import type { Evidence } from "../evidence.js";
|
||||
import { parseActiveElectronCapture } from "./javascriptRuntimeReconciliationActive.js";
|
||||
import {
|
||||
@@ -124,22 +123,6 @@ export type ParsedRuntimeCapture =
|
||||
};
|
||||
});
|
||||
|
||||
/** Parse only supported passive web/Electron inspection Evidence. */
|
||||
export const parseRuntimeCaptures = (
|
||||
observations: readonly unknown[],
|
||||
path: readonly (string | number)[] = ["runtime_observations"],
|
||||
): ParsedRuntimeCapture[] =>
|
||||
observations
|
||||
.map((observation, index) =>
|
||||
parseRuntimeCapture(observation, [...path, index]),
|
||||
)
|
||||
.sort((left, right) =>
|
||||
compareUnicodeCodePoints(
|
||||
left.evidence.evidence_id,
|
||||
right.evidence.evidence_id,
|
||||
),
|
||||
);
|
||||
|
||||
/** Authenticate one source before interpreting its runtime capture. */
|
||||
export const parseRuntimeCapture = (
|
||||
input: unknown,
|
||||
|
||||
@@ -752,20 +752,6 @@ export type JavaScriptSemanticGraph = z.infer<
|
||||
typeof javaScriptSemanticGraphSchema
|
||||
>;
|
||||
|
||||
/** Resolve one fact's compact provenance without changing its stored shape. */
|
||||
export const resolveJavaScriptSemanticEvidence = (
|
||||
graph: Pick<JavaScriptSemanticGraph, "evidence_contexts">,
|
||||
reference: JavaScriptSemanticEvidenceReference,
|
||||
): ApplicationGraphEvidence => {
|
||||
const context = graph.evidence_contexts.find(
|
||||
({ context_id }) => context_id === reference.context_id,
|
||||
);
|
||||
if (context === undefined)
|
||||
throw new TypeError("Semantic evidence reference names an absent context");
|
||||
const { context_id: _contextId, ...evidenceContext } = context;
|
||||
return { ...evidenceContext, location: reference.location };
|
||||
};
|
||||
|
||||
const normalizeGraphInput = (
|
||||
parsed: JavaScriptSemanticGraphInput,
|
||||
): JavaScriptSemanticGraphInput => ({
|
||||
@@ -853,14 +839,6 @@ const semanticGraphContainerSchema = javaScriptSemanticGraphInputSchema.extend({
|
||||
unknowns: arrayContainerSchema(semanticGraphShape.unknowns),
|
||||
});
|
||||
|
||||
/** Clone input synchronously; commit, check and seal the owned graph in steps. */
|
||||
export const createImmutableJavaScriptSemanticGraphSteps = (
|
||||
input: unknown,
|
||||
): Generator<void, JavaScriptSemanticGraph> =>
|
||||
validateAndSealSemanticGraphSteps(
|
||||
normalizeGraphInput(javaScriptSemanticGraphInputSchema.parse(input)),
|
||||
);
|
||||
|
||||
/**
|
||||
* Seal a graph whose input the caller transfers: the caller neither retains nor
|
||||
* mutates any part of it afterwards. Only the graph's own fields are validated
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { javaScriptSemanticQueryInputSchema } from "./javascriptSemanticQuerySchemas.js";
|
||||
import {
|
||||
resolveJavaScriptSemanticEvidence,
|
||||
semanticFixtureGraph,
|
||||
semanticFixtureInput,
|
||||
semanticGraphTestEvidence,
|
||||
@@ -24,11 +25,10 @@ import {
|
||||
createJavaScriptSemanticGraphNode,
|
||||
createJavaScriptSemanticGraphRelation,
|
||||
createJavaScriptSemanticGraphUnknown,
|
||||
createImmutableJavaScriptSemanticGraphSteps,
|
||||
sealTransferredJavaScriptSemanticGraphSteps,
|
||||
isValidatedImmutableJavaScriptSemanticGraph,
|
||||
JavaScriptSemanticEvidenceContextRegistry,
|
||||
javaScriptSemanticGraphSchema,
|
||||
resolveJavaScriptSemanticEvidence,
|
||||
type JavaScriptSemanticGraph,
|
||||
} from "./javascriptSemanticGraph.js";
|
||||
import { queryJavaScriptSemanticGraph } from "./javascriptSemanticQuery.js";
|
||||
@@ -744,7 +744,7 @@ const complete = <Value>(steps: Iterator<void, Value>): Value => {
|
||||
}
|
||||
};
|
||||
|
||||
it("captures nested input before yielding and preserves the synchronous graph commitment", () => {
|
||||
it("preserves a transferred graph independent of the caller retained copy", () => {
|
||||
const input = semanticFixtureInput(true);
|
||||
const node = input.nodes[0];
|
||||
if (node === undefined) throw new Error("Expected fixture node");
|
||||
@@ -754,7 +754,9 @@ it("captures nested input before yielding and preserves the synchronous graph co
|
||||
input.relations.reverse();
|
||||
input.coverage.families.reverse();
|
||||
const expected = createJavaScriptSemanticGraph(input);
|
||||
const steps = createImmutableJavaScriptSemanticGraphSteps(input);
|
||||
const steps = sealTransferredJavaScriptSemanticGraphSteps(
|
||||
structuredClone(input),
|
||||
);
|
||||
expect(steps.next().done).toBe(false);
|
||||
nested.text = "Changed while the owned graph is being hashed.";
|
||||
nested.rows.push(4);
|
||||
@@ -854,7 +856,9 @@ it.each(invalidGraphCases)(
|
||||
};
|
||||
const expected = issues(() => createJavaScriptSemanticGraph(input));
|
||||
expect(expected.map(({ message }) => message)).toContain(message);
|
||||
const steps = createImmutableJavaScriptSemanticGraphSteps(input);
|
||||
const steps = sealTransferredJavaScriptSemanticGraphSteps(
|
||||
structuredClone(input),
|
||||
);
|
||||
expect(steps.next().done).toBe(false);
|
||||
expect(issues(() => complete(steps))).toEqual(expected);
|
||||
},
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
resolveJavaScriptSemanticEvidence,
|
||||
semanticFixtureGraph,
|
||||
semanticGraphTestEvidence,
|
||||
unknownSemanticGraphTestEvidence,
|
||||
@@ -20,7 +21,6 @@ import {
|
||||
createJavaScriptSemanticGraphRelation,
|
||||
createJavaScriptSemanticGraphUnknown,
|
||||
JavaScriptSemanticEvidenceContextRegistry,
|
||||
resolveJavaScriptSemanticEvidence,
|
||||
type JavaScriptSemanticGraph,
|
||||
} from "./javascriptSemanticGraph.js";
|
||||
import { queryJavaScriptSemanticGraph } from "./javascriptSemanticQuery.js";
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
parserPluginsForPath,
|
||||
javaScriptRuntimeContext,
|
||||
javaScriptProgramStrictness,
|
||||
javaScriptTopLevelThisMayBeGlobal,
|
||||
javaScriptThisOwner,
|
||||
} from "./javascriptSourceParser.js";
|
||||
import { traverseJavaScriptAst } from "./javascriptSemanticTraversal.js";
|
||||
import { analyzeParsedJavaScriptStaticSource } from "./javascriptStaticAnalysis.js";
|
||||
@@ -39,7 +39,7 @@ it.each([
|
||||
});
|
||||
if (selected === undefined) throw new Error("Missing this fixture");
|
||||
expect(
|
||||
javaScriptTopLevelThisMayBeGlobal(selected, parsed.program, parents),
|
||||
javaScriptThisOwner(selected, parsed.program, parents) === "global",
|
||||
).toBe(expected);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -351,9 +351,3 @@ export const javaScriptThisOwner = (
|
||||
? "global"
|
||||
: "isolated";
|
||||
};
|
||||
|
||||
export const javaScriptTopLevelThisMayBeGlobal = (
|
||||
node: t.ThisExpression,
|
||||
program: t.Program,
|
||||
parents: WeakMap<t.Node, t.Node>,
|
||||
): boolean => javaScriptThisOwner(node, program, parents) === "global";
|
||||
Reference in new issue
Block a user