feat: complete REA remediation program

This commit is contained in:
N0zoM1z0
2026-07-22 22:09:12 +09:00
committed by N0zoM1z0
parent 737940c90c
commit d25e98c3f9
460 changed files with 13985 additions and 1877 deletions
@@ -6,11 +6,13 @@ import { parseArgs } from "node:util";
import { analyzeJavaScriptApplication } from "../dist/application/JavaScriptApplicationService.js";
import {
compareApplicationVersionsEvidence,
compareJavaScriptExportShapesEvidence,
traceApplicationFeatureEvidence,
} from "../dist/application/JavaScriptApplicationWorkflowService.js";
import { PermissionAuthority } from "../dist/application/PermissionAuthority.js";
import { applicationVersionComparisonResultSchema } from "../dist/domain/javascriptApplicationVersionComparisonSchemas.js";
import { applicationFeatureTraceResultSchema } from "../dist/domain/javascriptFeatureTraceSchemas.js";
import { javaScriptExportShapeComparisonResultSchema } from "../dist/domain/javascriptExportShapeComparisonSchemas.js";
import { createPermissionPolicy } from "../dist/domain/permissionPolicy.js";
const options = parseArgs({
@@ -20,6 +22,10 @@ const options = parseArgs({
"seed-kind": { type: "string", default: "module" },
"seed-value": { type: "string" },
"source-map-read-approved": { type: "boolean", default: false },
"left-module-path": { type: "string" },
"left-export-name": { type: "string" },
"right-module-path": { type: "string" },
"right-export-name": { type: "string" },
},
strict: true,
allowPositionals: false,
@@ -68,6 +74,23 @@ const traceResult =
trace === null
? null
: applicationFeatureTraceResultSchema.parse(trace.value.normalized_result);
const exportShapeSelector = resolveExportShapeSelector(left, right, options);
const exportShapeComparison =
exportShapeSelector === null
? null
: compareJavaScriptExportShapesEvidence({
left,
right,
...exportShapeSelector,
});
if (exportShapeComparison !== null && !exportShapeComparison.ok)
throw exportShapeComparison.error;
const exportShapeResult =
exportShapeComparison === null
? null
: javaScriptExportShapeComparisonResultSchema.parse(
exportShapeComparison.value.normalized_result,
);
process.stdout.write(
`${JSON.stringify({
@@ -78,6 +101,19 @@ process.stdout.write(
summary: comparisonResult.summary,
matching: comparisonResult.matching,
coverage: comparisonResult.coverage,
export_shape_comparison:
exportShapeResult === null
? null
: {
comparison_id: exportShapeResult.comparison_id,
evidence_id: exportShapeComparison.value.evidence_id,
left: exportShapeResult.left,
right: exportShapeResult.right,
summary: exportShapeResult.summary,
changes: exportShapeResult.changes,
coverage: exportShapeResult.coverage,
runtime_validation: exportShapeResult.runtime_validation,
},
trace:
traceResult === null
? null
@@ -98,6 +134,67 @@ process.stdout.write(
})}\n`,
);
function resolveExportShapeSelector(left, right, values) {
const explicit = [
values["left-module-path"],
values["left-export-name"],
values["right-module-path"],
values["right-export-name"],
];
if (explicit.some((value) => value !== undefined)) {
if (explicit.some((value) => value === undefined))
throw new Error(
"Explicit export-shape verification requires all left/right module and export selectors",
);
return {
left_module_path: explicit[0],
left_export_name: explicit[1],
right_module_path: explicit[2],
right_export_name: explicit[3],
};
}
const leftSelectors = returnShapeSelectors(left.normalized_result.graph);
const rightSelectors = new Set(
returnShapeSelectors(right.normalized_result.graph).map(selectorKey),
);
const common = leftSelectors.find((selector) =>
rightSelectors.has(selectorKey(selector)),
);
return common === undefined
? null
: {
left_module_path: common.modulePath,
left_export_name: common.exportName,
right_module_path: common.modulePath,
right_export_name: common.exportName,
};
}
function returnShapeSelectors(graph) {
const selectors = [];
for (const node of graph.nodes) {
for (const observation of node.observations) {
const properties = observation.properties;
if (
properties.semantic_role === "export-return-shapes" &&
typeof properties.module_path === "string" &&
typeof properties.exported_name === "string"
)
selectors.push({
modulePath: properties.module_path,
exportName: properties.exported_name,
});
}
}
return selectors.sort((left, right) =>
selectorKey(left).localeCompare(selectorKey(right), "en"),
);
}
function selectorKey(selector) {
return `${selector.modulePath}\0${selector.exportName}`;
}
async function analyze(path, authority) {
const result = await analyzeJavaScriptApplication(authority, {
input_path: path,