mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 05:02:40 +00:00
perf(ci): optimize semantic graph construction, directory containment checks, gate checkouts, and boundary stragglers (#11851)
* perf(javascript): avoid redundant semantic graph validation and node hashing * perf(resources): deduplicate directory containment checks and root lstat calls * perf(ci): trace script fixture modules, sparse-checkout gate jobs, and parallelize built doc checks * perf(tests): memoize live MCP doctor expectations and reuse CLI and verifier compilation * fix(ci): enforce containment after skipped entries, validate interned contexts, and supervise doc and verifier teardowns * fix(docs): decode buffered check output once to preserve multi-byte UTF-8
This commit is contained in:
1 parent
015f726a9e
commit
84ee604c6d
25 files changed
+1650
-259
No files matched your search
@@ -270,10 +270,20 @@ export const applicationGraphEvidenceContextSchema =
|
||||
applicationGraphEvidenceBaseSchema.omit({ location: true });
|
||||
|
||||
type EvidenceValue = z.infer<typeof applicationGraphEvidenceBaseSchema>;
|
||||
type EvidenceContextValue = z.infer<
|
||||
typeof applicationGraphEvidenceContextSchema
|
||||
>;
|
||||
type EvidenceIssueSink = {
|
||||
addIssue(issue: {
|
||||
readonly code: "custom";
|
||||
readonly path?: PropertyKey[];
|
||||
readonly message: string;
|
||||
}): void;
|
||||
};
|
||||
|
||||
const checkAuthorityState = (
|
||||
evidence: EvidenceValue,
|
||||
context: z.RefinementCtx,
|
||||
evidence: EvidenceContextValue,
|
||||
context: EvidenceIssueSink,
|
||||
): void => {
|
||||
if (
|
||||
evidence.authority === "static-relationship-inference" &&
|
||||
@@ -314,8 +324,8 @@ const checkAuthorityState = (
|
||||
};
|
||||
|
||||
const checkStateConfidence = (
|
||||
evidence: EvidenceValue,
|
||||
context: z.RefinementCtx,
|
||||
evidence: EvidenceContextValue,
|
||||
context: EvidenceIssueSink,
|
||||
): void => {
|
||||
if (
|
||||
["unknown", "unavailable"].includes(evidence.state) &&
|
||||
@@ -349,16 +359,10 @@ const checkStateConfidence = (
|
||||
});
|
||||
};
|
||||
|
||||
const checkTraceability = (
|
||||
evidence: EvidenceValue,
|
||||
context: z.RefinementCtx,
|
||||
const checkContextTraceability = (
|
||||
evidence: EvidenceContextValue,
|
||||
context: EvidenceIssueSink,
|
||||
): void => {
|
||||
if (evidence.state === "observed" && !evidence.location.available)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["location"],
|
||||
message: "Observed facts require an actionable location",
|
||||
});
|
||||
if (evidence.state === "inferred" && evidence.limitations.length === 0)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
@@ -376,9 +380,30 @@ const checkTraceability = (
|
||||
});
|
||||
};
|
||||
|
||||
const checkArtifactBacking = (
|
||||
/** Whether a validated evidence context permits the fact's source location. */
|
||||
export const isCompatibleApplicationGraphEvidenceLocation = (
|
||||
evidence: Pick<EvidenceContextValue, "state">,
|
||||
location: z.infer<typeof applicationGraphEvidenceLocationSchema>,
|
||||
): boolean => evidence.state !== "observed" || location.available;
|
||||
|
||||
const checkTraceability = (
|
||||
evidence: EvidenceValue,
|
||||
context: z.RefinementCtx,
|
||||
context: EvidenceIssueSink,
|
||||
): void => {
|
||||
if (
|
||||
!isCompatibleApplicationGraphEvidenceLocation(evidence, evidence.location)
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["location"],
|
||||
message: "Observed facts require an actionable location",
|
||||
});
|
||||
checkContextTraceability(evidence, context);
|
||||
};
|
||||
|
||||
const checkArtifactBacking = (
|
||||
evidence: EvidenceContextValue,
|
||||
context: EvidenceIssueSink,
|
||||
): void => {
|
||||
const artifactBacked = [
|
||||
"artifact-bytes",
|
||||
@@ -399,6 +424,23 @@ const checkArtifactBacking = (
|
||||
});
|
||||
};
|
||||
|
||||
/** Whether shared non-location provenance satisfies all context-level invariants. */
|
||||
export const isValidApplicationGraphEvidenceContext = (
|
||||
evidence: EvidenceContextValue,
|
||||
): boolean => {
|
||||
let valid = true;
|
||||
const sink: EvidenceIssueSink = {
|
||||
addIssue: () => {
|
||||
valid = false;
|
||||
},
|
||||
};
|
||||
checkAuthorityState(evidence, sink);
|
||||
checkStateConfidence(evidence, sink);
|
||||
checkContextTraceability(evidence, sink);
|
||||
checkArtifactBacking(evidence, sink);
|
||||
return valid;
|
||||
};
|
||||
|
||||
/** Provenance, authority, uncertainty, and bounds for one graph fact. */
|
||||
export const applicationGraphEvidenceSchema =
|
||||
applicationGraphEvidenceBaseSchema.superRefine((evidence, context) => {
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -25,6 +25,9 @@ import {
|
||||
createJavaScriptSemanticGraphNode,
|
||||
createJavaScriptSemanticGraphRelation,
|
||||
createJavaScriptSemanticGraphUnknown,
|
||||
createOwnedJavaScriptSemanticFingerprint,
|
||||
createOwnedJavaScriptSemanticGraphNode,
|
||||
withJavaScriptSemanticNodeApplicationIds,
|
||||
sealTransferredJavaScriptSemanticGraphSteps,
|
||||
isValidatedImmutableJavaScriptSemanticGraph,
|
||||
JavaScriptSemanticEvidenceContextRegistry,
|
||||
@@ -915,3 +918,162 @@ it("interns each distinct evidence context once under its content digest", () =>
|
||||
);
|
||||
expect(registry.resolve(repeated)).toEqual(elsewhere);
|
||||
});
|
||||
|
||||
it("rejects invalid provenance in direct registry.intern calls before sealing", () => {
|
||||
const registry = new JavaScriptSemanticEvidenceContextRegistry();
|
||||
const baseEvidence = semanticGraphTestEvidence();
|
||||
expect(() =>
|
||||
registry.intern({
|
||||
...baseEvidence,
|
||||
extractor: { ...baseEvidence.extractor, name: "" },
|
||||
}),
|
||||
).toThrow(z.ZodError);
|
||||
expect(registry.ownedContexts).toEqual([]);
|
||||
});
|
||||
|
||||
it("seals owned builder records while still rejecting tampered spread copies", () => {
|
||||
const registry = new JavaScriptSemanticEvidenceContextRegistry();
|
||||
const ownedModule = createOwnedJavaScriptSemanticGraphNode(
|
||||
{
|
||||
kind: "module",
|
||||
identity: {
|
||||
artifact_sha256: SHA,
|
||||
module_path: "bundle.js",
|
||||
source_range: {
|
||||
start: { line: 1, column: 0 },
|
||||
end: { line: 1, column: 20 },
|
||||
},
|
||||
role_key: "module",
|
||||
},
|
||||
function_node_id: null,
|
||||
application_node_ids: [],
|
||||
label: "bundle.js",
|
||||
properties: {},
|
||||
evidence: semanticGraphTestEvidence(),
|
||||
},
|
||||
registry,
|
||||
);
|
||||
const ownedCallable = withJavaScriptSemanticNodeApplicationIds(
|
||||
createOwnedJavaScriptSemanticGraphNode(
|
||||
{
|
||||
kind: "function",
|
||||
identity: {
|
||||
artifact_sha256: SHA,
|
||||
module_path: "bundle.js",
|
||||
source_range: {
|
||||
start: { line: 1, column: 2 },
|
||||
end: { line: 1, column: 18 },
|
||||
},
|
||||
role_key: "fn",
|
||||
},
|
||||
function_node_id: null,
|
||||
application_node_ids: [],
|
||||
label: "fn",
|
||||
properties: {},
|
||||
evidence: semanticGraphTestEvidence(),
|
||||
},
|
||||
registry,
|
||||
),
|
||||
[`jag_node_${"c".repeat(64)}`],
|
||||
);
|
||||
const ownedFingerprint = createOwnedJavaScriptSemanticFingerprint(
|
||||
{
|
||||
function_node_id: ownedCallable.node_id,
|
||||
algorithm: "rea.javascript-semantic-function",
|
||||
status: "complete",
|
||||
components: {
|
||||
parameter_arity: 0,
|
||||
normalized_ast_sha256: "1".repeat(64),
|
||||
control_flow_sha256: "2".repeat(64),
|
||||
relation_shape_sha256: "3".repeat(64),
|
||||
literal_set_sha256: "4".repeat(64),
|
||||
effects: ["network"],
|
||||
},
|
||||
limitations: [],
|
||||
evidence: semanticGraphTestEvidence("inferred"),
|
||||
},
|
||||
registry,
|
||||
);
|
||||
expect(Object.isFrozen(ownedModule)).toBe(true);
|
||||
expect(Object.isFrozen(ownedCallable)).toBe(true);
|
||||
expect(Object.isFrozen(ownedCallable.application_node_ids)).toBe(true);
|
||||
expect(Object.isFrozen(ownedFingerprint)).toBe(true);
|
||||
expect(Object.isFrozen(registry.ownedContexts[0])).toBe(true);
|
||||
|
||||
const ownedInput: JavaScriptSemanticGraphInput = {
|
||||
schema: "JavaScriptSemanticRelationGraph",
|
||||
root_artifact_sha256: SHA,
|
||||
application_graph_id: `jag_${"b".repeat(64)}`,
|
||||
root_node_ids: [ownedModule.node_id],
|
||||
evidence_contexts: registry.ownedContexts,
|
||||
nodes: [ownedModule, ownedCallable],
|
||||
relations: [],
|
||||
unknowns: [],
|
||||
fingerprints: [ownedFingerprint],
|
||||
coverage: {
|
||||
status: "complete",
|
||||
truncated: false,
|
||||
omitted_nodes: 0,
|
||||
omitted_relations: 0,
|
||||
limits: [],
|
||||
families: JAVASCRIPT_SEMANTIC_RELATION_FAMILIES.map((family) => ({
|
||||
family,
|
||||
status: "complete",
|
||||
retained_relations: 0,
|
||||
omitted_relations: 0,
|
||||
unknown_ids: [],
|
||||
})),
|
||||
},
|
||||
limitations: [],
|
||||
};
|
||||
const direct = createJavaScriptSemanticGraph(ownedInput);
|
||||
const transferred = complete(
|
||||
sealTransferredJavaScriptSemanticGraphSteps(ownedInput),
|
||||
);
|
||||
const unsealed = createJavaScriptSemanticGraph(
|
||||
JSON.parse(JSON.stringify(ownedInput)) as JavaScriptSemanticGraphInput,
|
||||
);
|
||||
expect(direct.graph_id).toBe(unsealed.graph_id);
|
||||
expect(transferred).toEqual(direct);
|
||||
|
||||
for (const tampered of [
|
||||
{
|
||||
...ownedInput,
|
||||
nodes: [
|
||||
ownedModule,
|
||||
{ ...ownedCallable, node_id: `jsrg_node_${"f".repeat(64)}` },
|
||||
],
|
||||
},
|
||||
{
|
||||
...ownedInput,
|
||||
fingerprints: [
|
||||
{
|
||||
...ownedFingerprint,
|
||||
fingerprint_id: `jsrg_fp_${"f".repeat(64)}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
...ownedInput,
|
||||
nodes: [
|
||||
{
|
||||
...ownedModule,
|
||||
evidence: {
|
||||
context_id: ownedModule.evidence.context_id,
|
||||
location: {
|
||||
available: false as const,
|
||||
reason: "unresolved" as const,
|
||||
detail: "Contradicts observed context.",
|
||||
},
|
||||
},
|
||||
},
|
||||
ownedCallable,
|
||||
],
|
||||
},
|
||||
] satisfies JavaScriptSemanticGraphInput[]) {
|
||||
expect(() => createJavaScriptSemanticGraph(tampered)).toThrow(z.ZodError);
|
||||
expect(() =>
|
||||
complete(sealTransferredJavaScriptSemanticGraphSteps(tampered)),
|
||||
).toThrow(z.ZodError);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user