feat(javascript): report observed export property presence (#1160)
* feat(javascript): report observed export property presence Extend compare_javascript_export_shapes so each retained return variant lists observed property names and each change reports presence independently of value resolution. Complete parent coverage classifies one-sided names as added or removed even when static values stay unknown. Fixes #725 * test(javascript): match unknown export-shape values by availability Nested availability objects include a reason when values stay unresolved. Assert availability through objectContaining so presence-only added and removed rows still verify unknown values. * fix(javascript): preserve uncertain export property presence and locations * fix(javascript): normalize presence and preserve local property coverage * fix(javascript): require present discriminants for return pairing * fix(javascript): normalize retained shapes before comparison * refactor(javascript): share return projection with executable examples * fix(javascript): localize uncertainty for missing mutated slots * fix(javascript): bind advertised export examples to exact artifacts * fix(javascript): keep uncertain property flow as candidates --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
@@ -32,7 +32,7 @@ import {
|
||||
resolveArtifactPathByContext,
|
||||
type ArtifactPathResolution,
|
||||
} from "./JavaScriptArtifactPathResolution.js";
|
||||
import { projectJavaScriptExportReturnShapes } from "./JavaScriptReturnShapeProjection.js";
|
||||
import { projectJavaScriptExportReturnShapes } from "../../domain/javascript/javascriptExportReturnShapeProjection.js";
|
||||
|
||||
import type { JavaScriptModuleSemanticIr } from "./JavaScriptArtifactAnalysisTypes.js";
|
||||
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
import { jsonObjectSchema, jsonValueSchema } from "../../domain/jsonValue.js";
|
||||
import {
|
||||
partialApplicationCoverage,
|
||||
truncatedApplicationCoverage,
|
||||
} from "../../domain/javascript/javascriptApplicationEvidenceSchemas.js";
|
||||
import type {
|
||||
JavaScriptSemanticCallable,
|
||||
JavaScriptSemanticModuleLink,
|
||||
} from "../../domain/javascript/javascriptSemanticIr.js";
|
||||
import { flattenSemanticReturnValue } from "../../domain/javascript/javascriptSemanticReturns.js";
|
||||
import type { JavaScriptSourceRange } from "../../domain/javascript/javascriptStaticAnalysisTypes.js";
|
||||
import type { JavaScriptArtifactGraphCoverage } from "./JavaScriptArtifactGraphContext.js";
|
||||
import type { JavaScriptModuleSemanticIr } from "./JavaScriptArtifactAnalysisTypes.js";
|
||||
|
||||
export interface JavaScriptReturnShapeProjection {
|
||||
readonly properties: ReturnType<typeof jsonObjectSchema.parse>;
|
||||
readonly range: JavaScriptSourceRange;
|
||||
readonly coverage: JavaScriptArtifactGraphCoverage;
|
||||
readonly limitations: readonly string[];
|
||||
}
|
||||
|
||||
/** Project one exact export/callable link into shallow bounded graph values. */
|
||||
export const projectJavaScriptExportReturnShapes = (input: {
|
||||
readonly ir: JavaScriptModuleSemanticIr;
|
||||
readonly link: JavaScriptSemanticModuleLink;
|
||||
readonly modulePath: string;
|
||||
readonly baseCoverage: JavaScriptArtifactGraphCoverage;
|
||||
}): JavaScriptReturnShapeProjection | null => {
|
||||
if (input.link.callableId === null || input.link.exportedName === null)
|
||||
return null;
|
||||
const callable = input.ir.callables.find(
|
||||
({ callableId }) => callableId === input.link.callableId,
|
||||
);
|
||||
if (callable === undefined) return null;
|
||||
const projection = projectReturnSites(callable);
|
||||
const projectionOmitted =
|
||||
projection.omittedSites +
|
||||
projection.omittedFields +
|
||||
projection.omittedCoverage;
|
||||
const semanticOmitted = callable.returnCoverage.omittedCount;
|
||||
const complete =
|
||||
input.baseCoverage.status === "complete" &&
|
||||
callable.returnCoverage.status === "complete" &&
|
||||
projectionOmitted === 0;
|
||||
const limits = input.baseCoverage.limits;
|
||||
const omitted =
|
||||
semanticOmitted === null ? null : semanticOmitted + projectionOmitted;
|
||||
const coverage = complete
|
||||
? input.baseCoverage
|
||||
: projectionOmitted > 0
|
||||
? truncatedApplicationCoverage(limits, omitted)
|
||||
: partialApplicationCoverage(limits, omitted);
|
||||
const limitations = [
|
||||
...input.ir.limitations,
|
||||
"Return shapes are inferred from inert syntax and do not prove runtime behavior.",
|
||||
...(callable.returnSites.length === 0
|
||||
? [
|
||||
"No direct return value was retained; runtime return behavior remains unknown.",
|
||||
]
|
||||
: []),
|
||||
];
|
||||
return {
|
||||
properties: jsonObjectSchema.parse({
|
||||
semantic_role: "export-return-shapes",
|
||||
module_path: input.modulePath,
|
||||
exported_name: input.link.exportedName,
|
||||
callable_id: callable.callableId,
|
||||
callable_kind: callable.kind,
|
||||
static_return_shapes: projection.shapes,
|
||||
return_shape_coverage: {
|
||||
status: callable.returnCoverage.status,
|
||||
retained_return_sites: projection.shapes.length,
|
||||
omitted_return_sites:
|
||||
semanticOmitted === null
|
||||
? null
|
||||
: semanticOmitted + projection.omittedSites,
|
||||
omitted_fields: projection.omittedFields,
|
||||
omitted_property_coverage: projection.omittedCoverage,
|
||||
projection_complete: projectionOmitted === 0,
|
||||
},
|
||||
}),
|
||||
range: callable.location,
|
||||
coverage,
|
||||
limitations,
|
||||
};
|
||||
};
|
||||
|
||||
const projectReturnSites = (callable: JavaScriptSemanticCallable) => {
|
||||
const retainedSites = callable.returnSites;
|
||||
const shapes = retainedSites.map((site) => {
|
||||
const flattened = flattenSemanticReturnValue(site.value);
|
||||
const fields = flattened.fields.map((field) => ({
|
||||
...field,
|
||||
value: jsonValueSchema.parse(field.value),
|
||||
}));
|
||||
const propertyCoverage = flattened.propertyCoverage;
|
||||
return {
|
||||
source_range: site.location,
|
||||
value_status: site.value.status,
|
||||
fields,
|
||||
property_coverage: propertyCoverage,
|
||||
};
|
||||
});
|
||||
return {
|
||||
shapes,
|
||||
omittedSites: 0,
|
||||
omittedFields: 0,
|
||||
omittedCoverage: 0,
|
||||
};
|
||||
};
|
||||
@@ -69,7 +69,10 @@ const projectValue = (input: ValueProjectionInput): void => {
|
||||
source: target,
|
||||
target: slot,
|
||||
relation: "writes-property",
|
||||
resolution: value.unknownProperties ? "candidate" : "resolved",
|
||||
resolution:
|
||||
value.unknownProperties || property.presence === "unknown-coverage"
|
||||
? "candidate"
|
||||
: "resolved",
|
||||
});
|
||||
projectValue({
|
||||
context,
|
||||
|
||||
Reference in New Issue
Block a user