mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
refactor(javascript): share artifact graph evidence construction (#16109)
This commit is contained in:
1 parent
37e47cd7bc
commit
40dda21d90
1 file changed
+72
-75
@@ -22,77 +22,87 @@ export interface EvidenceInput {
|
||||
readonly range?: JavaScriptSourceRange;
|
||||
}
|
||||
|
||||
const createGraphEvidence = (
|
||||
{
|
||||
sha256,
|
||||
path,
|
||||
operation,
|
||||
coverage,
|
||||
limitations: inputLimitations,
|
||||
}: EvidenceInput,
|
||||
{
|
||||
range,
|
||||
limitations = [...(inputLimitations ?? [])],
|
||||
...classification
|
||||
}: Pick<ApplicationGraphEvidence, "authority" | "state" | "confidence"> & {
|
||||
readonly range?: JavaScriptSourceRange | undefined;
|
||||
readonly limitations?: string[];
|
||||
},
|
||||
): ApplicationGraphEvidence => ({
|
||||
...classification,
|
||||
artifact: {
|
||||
available: true,
|
||||
artifact_id: `art_${sha256}`,
|
||||
sha256,
|
||||
},
|
||||
location: {
|
||||
available: true,
|
||||
value:
|
||||
range === undefined
|
||||
? { kind: "artifact-path", path }
|
||||
: { kind: "source-range", source: path, ...range },
|
||||
},
|
||||
extractor: { ...EXTRACTOR, operation },
|
||||
coverage,
|
||||
limitations,
|
||||
evidence_ids: [],
|
||||
});
|
||||
|
||||
/** Exact artifact-byte evidence for one safely inventoried local file. */
|
||||
export const artifactObservationEvidence = (
|
||||
input: EvidenceInput,
|
||||
): ApplicationGraphEvidence => ({
|
||||
authority: "artifact-bytes",
|
||||
state: "observed",
|
||||
confidence: "exact",
|
||||
artifact: artifactReference(input.sha256),
|
||||
location: {
|
||||
available: true,
|
||||
value: { kind: "artifact-path", path: input.path },
|
||||
},
|
||||
extractor: { ...EXTRACTOR, operation: input.operation },
|
||||
coverage: input.coverage,
|
||||
limitations: [...(input.limitations ?? [])],
|
||||
evidence_ids: [],
|
||||
});
|
||||
): ApplicationGraphEvidence =>
|
||||
createGraphEvidence(input, {
|
||||
authority: "artifact-bytes",
|
||||
state: "observed",
|
||||
confidence: "exact",
|
||||
});
|
||||
|
||||
/** Exact AST syntax evidence with an actionable source range. */
|
||||
export const astObservationEvidence = (
|
||||
input: EvidenceInput & { readonly range: JavaScriptSourceRange },
|
||||
): ApplicationGraphEvidence => {
|
||||
const limitations = [
|
||||
...(input.limitations ?? []),
|
||||
...(input.coverage.status === "complete"
|
||||
? []
|
||||
: [
|
||||
"AST coverage is incomplete; omitted or dynamic facts must not be interpreted as absence.",
|
||||
]),
|
||||
];
|
||||
return {
|
||||
): ApplicationGraphEvidence =>
|
||||
createGraphEvidence(input, {
|
||||
authority: "ast-static-analysis",
|
||||
state: "observed",
|
||||
confidence: "exact",
|
||||
artifact: artifactReference(input.sha256),
|
||||
location: {
|
||||
available: true,
|
||||
value: { kind: "source-range", source: input.path, ...input.range },
|
||||
},
|
||||
extractor: { ...EXTRACTOR, operation: input.operation },
|
||||
coverage: input.coverage,
|
||||
limitations,
|
||||
evidence_ids: [],
|
||||
};
|
||||
};
|
||||
range: input.range,
|
||||
limitations: [
|
||||
...(input.limitations ?? []),
|
||||
...(input.coverage.status === "complete"
|
||||
? []
|
||||
: [
|
||||
"AST coverage is incomplete; omitted or dynamic facts must not be interpreted as absence.",
|
||||
]),
|
||||
],
|
||||
});
|
||||
|
||||
/** Explicit static relationship inference; never promoted to observation. */
|
||||
export const staticInferenceEvidence = (
|
||||
input: EvidenceInput & {
|
||||
readonly confidence?: "high" | "medium" | "low";
|
||||
},
|
||||
): ApplicationGraphEvidence => ({
|
||||
authority: "static-relationship-inference",
|
||||
state: "inferred",
|
||||
confidence: input.confidence ?? "high",
|
||||
artifact: artifactReference(input.sha256),
|
||||
location:
|
||||
input.range === undefined
|
||||
? { available: true, value: { kind: "artifact-path", path: input.path } }
|
||||
: {
|
||||
available: true,
|
||||
value: { kind: "source-range", source: input.path, ...input.range },
|
||||
},
|
||||
extractor: { ...EXTRACTOR, operation: input.operation },
|
||||
coverage: input.coverage,
|
||||
limitations: [
|
||||
"Static syntax does not prove that this relationship executes at runtime.",
|
||||
...(input.limitations ?? []),
|
||||
],
|
||||
evidence_ids: [],
|
||||
});
|
||||
): ApplicationGraphEvidence =>
|
||||
createGraphEvidence(input, {
|
||||
authority: "static-relationship-inference",
|
||||
state: "inferred",
|
||||
confidence: input.confidence ?? "high",
|
||||
range: input.range,
|
||||
limitations: [
|
||||
"Static syntax does not prove that this relationship executes at runtime.",
|
||||
...(input.limitations ?? []),
|
||||
],
|
||||
});
|
||||
|
||||
/** Unavailable static fact with the authority of its applicable processing phase. */
|
||||
export const unavailableStaticEvidence = (
|
||||
@@ -100,23 +110,10 @@ export const unavailableStaticEvidence = (
|
||||
readonly authority: JavaScriptArtifactAnalysisScope["authority"];
|
||||
readonly limitation: string;
|
||||
},
|
||||
): ApplicationGraphEvidence => ({
|
||||
authority: input.authority,
|
||||
state: "unavailable",
|
||||
confidence: "unknown",
|
||||
artifact: artifactReference(input.sha256),
|
||||
location: {
|
||||
available: true,
|
||||
value: { kind: "artifact-path", path: input.path },
|
||||
},
|
||||
extractor: { ...EXTRACTOR, operation: input.operation },
|
||||
coverage: input.coverage,
|
||||
limitations: [input.limitation, ...(input.limitations ?? [])],
|
||||
evidence_ids: [],
|
||||
});
|
||||
|
||||
const artifactReference = (sha256: string) => ({
|
||||
available: true as const,
|
||||
artifact_id: `art_${sha256}`,
|
||||
sha256,
|
||||
});
|
||||
): ApplicationGraphEvidence =>
|
||||
createGraphEvidence(input, {
|
||||
authority: input.authority,
|
||||
state: "unavailable",
|
||||
confidence: "unknown",
|
||||
limitations: [input.limitation, ...(input.limitations ?? [])],
|
||||
});
|
||||
Reference in new issue
Block a user