Files
rea/src/cli/staticObservedEndpointsCommand.ts
T
gensokyo-dev c536c67ee1 fix(cli): deliver an unretained non-idempotent result complete
When the retained-Evidence cache could not keep an over-budget result,
the CLI delivered its summary with rerun arguments. Rerunning a
non-idempotent operation does not reproduce it: an extraction that
created its output root refuses the same root. Each CLI delivery now
knows whether its contract is idempotent, and a non-idempotent result the
cache does not keep is delivered complete.

Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
2026-11-27 05:21:32 +08:00

61 lines
2.4 KiB
TypeScript

import type { Logger } from "pino";
import type { Evidence } from "../domain/evidence.js";
import type { CliInstance } from "./types.js";
import { COMPARE_STATIC_AND_OBSERVED_ENDPOINTS_TOOL_CONTRACT } from "../contracts/staticObservedEndpointsToolContract.js";
import { registerContractDocumentCommand } from "./contractDocumentCommand.js";
import {
evidenceBundleOption,
runEvidenceInputCommand,
} from "./evidenceInputCommand.js";
import { publishCliAnalysisEvidence } from "./analysisEvidenceDelivery.js";
/** Reuse standard CLI publication so summaries keep their complete source closure on disk. */
export const registerStaticObservedEndpointsCommand = (
cli: CliInstance,
logger: Logger,
): void =>
registerContractDocumentCommand(
cli,
logger,
COMPARE_STATIC_AND_OBSERVED_ENDPOINTS_TOOL_CONTRACT,
{
description:
"Compare static JavaScript endpoints and HAR Evidence JSON offline; --detail summary with --evidence_output saves full facts for selected inspect-analysis-view pages",
document:
"Inline JSON or file containing application, capture and optional origin",
evidenceDelivery: true,
viewDelivery: { invalidJson: "view must be valid JSON" },
cliOptions: { evidenceBundle: evidenceBundleOption },
},
async (document, { signal, operation, delivery, cliOptions, frame }) => {
if (delivery === undefined)
throw new Error(`${operation} declares evidenceDelivery`);
let sources: readonly Evidence[] = [];
const result = await runEvidenceInputCommand(
document,
{ operation, signal, frame, cliOptions },
async (lookup) => {
const { compareStaticAndObservedEndpointsEvidence } =
await import("../application/javascript/StaticObservedEndpointComparisonService.js");
const compared = await compareStaticAndObservedEndpointsEvidence(
document,
lookup,
{ signal },
);
if (!compared.ok) return compared;
sources = compared.value.sources;
return { ok: true, value: compared.value.evidence };
},
);
return publishCliAnalysisEvidence(result, {
operation,
signal,
detail: delivery.detail,
evidenceOutput: delivery.evidenceOutput,
rerunRecoversResult: delivery.rerunRecoversResult,
...(delivery.view === undefined ? {} : { view: delivery.view }),
sourceEvidence: sources,
});
},
);