refactor: return complete analysis results inline

This commit is contained in:
morluto
2026-09-29 08:07:24 +08:00
parent 07ff8b30ee
commit a2a3243ea8
127 changed files with 402 additions and 1508 deletions
@@ -396,8 +396,6 @@ const capability = (provider: ProviderIdentity): CapabilityDescriptor => ({
operation: "address_name",
available: true,
reason: null,
pagination: "none",
exhaustive: true,
effects: {
mutatesArtifact: false,
launchesProcess: true,
@@ -407,7 +405,6 @@ const capability = (provider: ProviderIdentity): CapabilityDescriptor => ({
changesPermissions: false,
requiresRoot: false,
},
limits: { maxResults: null, maxPayloadBytes: 1_000, timeoutMs: 1_000 },
limitations: [],
});
@@ -161,7 +161,6 @@ export const resolveCompareApplicationVersionsRequestValidated = (
...input.right_native_observations,
...rightNative.value,
],
limits: input.limits,
...(input.unknown_registry_approved === undefined
? {}
: { unknown_registry_approved: input.unknown_registry_approved }),
@@ -241,7 +240,6 @@ export const resolveCompareJavaScriptExportShapesRequestValidated = (
left_export_name: input.left_export_name,
right_module_path: input.right_module_path,
right_export_name: input.right_export_name,
limits: input.limits,
...(input.unknown_registry_approved === undefined
? {}
: { unknown_registry_approved: input.unknown_registry_approved }),
+1 -7
View File
@@ -53,8 +53,6 @@ export const exportEvidenceBundleCommand = async (
export const compareEvidenceBundlesCommand = async (input: {
readonly leftPath: string;
readonly rightPath: string;
readonly offset: number;
readonly limit: number;
readonly policy: EvidenceFilePolicy;
}): Promise<Result<JsonValue, AnalysisError>> => {
const [left, right] = await Promise.all([
@@ -64,11 +62,7 @@ export const compareEvidenceBundlesCommand = async (input: {
if (!left.ok) return left;
if (!right.ok) return right;
try {
return ok(
jsonValueSchema.parse(
compareBundles(left.value, right.value, [], input.offset, input.limit),
),
);
return ok(jsonValueSchema.parse(compareBundles(left.value, right.value)));
} catch (cause: unknown) {
return err(
new EvidenceIntegrityError("Evidence bundle comparison failed", {
@@ -119,9 +119,9 @@ export const compareApplicationVersionsEvidenceValidated = (
rootArtifactSha256: right.rootArtifactSha256,
graph: right.graph,
},
limits: input.limits,
leftNativeEvidence: leftNative,
rightNativeEvidence: rightNative,
limits: input.limits,
});
return ok(
createApplicationVersionComparisonEvidence(
@@ -214,7 +214,6 @@ export const compareJavaScriptExportShapesEvidenceValidated = (
modulePath: input.right_module_path,
exportName: input.right_export_name,
},
limits: input.limits,
});
return ok(
createJavaScriptExportShapeComparisonEvidence(
@@ -225,7 +224,6 @@ export const compareJavaScriptExportShapesEvidenceValidated = (
left_export_name: input.left_export_name,
right_module_path: input.right_module_path,
right_export_name: input.right_export_name,
limits: input.limits,
},
result,
),
@@ -125,7 +125,6 @@ export const prepareReplayPlan = async (
: prepareSide(input.right, input.limits.module_bytes, host),
]);
const withoutDigest = {
schema_version: 1 as const,
policy_version: REPLAY_POLICY_VERSION,
policy_sha256: digestJson(REPLAY_POLICY_DOCUMENT),
network: "none" as const,
@@ -310,7 +310,6 @@ const applyReproducerExport = async (
return executed;
const manifest = {
schema_version: 1,
plan: prepared.publicPlan,
result: executed,
sources: exportContext.includeSources
@@ -54,7 +54,7 @@ it("projects closure and direct interprocedural flow without execution", () => {
);
});
it("keeps dynamic calls explicit and returns bounded deterministic pages", () => {
it("keeps dynamic calls explicit and returns complete deterministic results", () => {
const graph = graphFor(`
const handlers = { ready() { return 1; } };
const key = process.argv[2];
@@ -73,21 +73,11 @@ it("keeps dynamic calls explicit and returns bounded deterministic pages", () =>
seed: { kind: "semantic-node", node_id: seedNodeId },
direction: "forward-influence",
include_ambiguous_dynamic_edges: true,
limits: {
max_seed_matches: 25,
max_nodes: 2_000,
max_edges: 4_000,
max_depth: 12,
max_functions: 500,
max_modules: 500,
page_size: 1,
},
});
const repeated = queryJavaScriptSemanticGraph(graph, {
seed: { kind: "semantic-node", node_id: seedNodeId },
direction: "forward-influence",
include_ambiguous_dynamic_edges: true,
limits: first.applied_limits,
});
expect(repeated).toEqual(first);
});
@@ -8,7 +8,6 @@ import {
import type { Evidence } from "../domain/evidence.js";
import { jsonValueSchema } from "../domain/jsonValue.js";
import { queryJavaScriptSemanticGraph } from "../domain/javascriptSemanticQuery.js";
import { JavaScriptSemanticQueryCursorError } from "../domain/javascriptSemanticQueryIdentity.js";
import {
javaScriptSemanticTraceResultSchema,
traceJavaScriptSemanticsInputSchema,
@@ -55,16 +54,6 @@ export const traceJavaScriptSemanticsEvidenceValidated = (
),
);
} catch (cause: unknown) {
if (cause instanceof JavaScriptSemanticQueryCursorError)
return err(
new AnalysisInputError(OPERATION, undefined, [
{
path: ["query", "cursor"],
reason: "invalid_value",
expected: "a cursor returned by the same graph, query, and limits",
},
]),
);
return err(
new AnalysisProtocolError("JavaScript semantic trace failed", { cause }),
);
@@ -284,7 +284,6 @@ const createCharacterizationPlan = (
replayPlan: ReplayPlan,
): RuntimeCharacterizationPlan =>
createRuntimeCharacterizationPlan({
schema_version: 1,
preparation_sha256: digestPreparation(
instrumentation.manifest.instrumented_sha256,
replayPlan.plan_digest,
@@ -11,9 +11,9 @@ import { createEvidenceBundle } from "../domain/evidenceBundle.js";
import { jsonValueSchema } from "../domain/jsonValue.js";
import { processCaptureSchema } from "../domain/processCapture.js";
import {
reconstructionObligationLedgerPageSchema,
reconstructionObligationLedgerSchema,
type ReconstructionObligationLedgerInput,
type ReconstructionObligationLedgerPage,
type ReconstructionObligationLedger,
type ReviewedReconstructionObligation,
} from "../domain/reconstructionObligationLedgerSchemas.js";
@@ -81,26 +81,25 @@ const request = (
evidence_bundle: createEvidenceBundle(records),
reviewed_obligations: [],
manifest: { bindings: [], contradictions: [] },
page: { offset: 0, limit: 50 },
...overrides,
});
const build = (
input: ReconstructionObligationLedgerInput,
): ReconstructionObligationLedgerPage => {
): ReconstructionObligationLedger => {
const parsed = resolveReconstructionObligationLedgerRequest(input);
if (!parsed.ok) throw parsed.error;
const result = buildReconstructionObligationLedgerEvidenceValidated(
parsed.value,
);
if (!result.ok) throw result.error;
return reconstructionObligationLedgerPageSchema.parse(
return reconstructionObligationLedgerSchema.parse(
result.value.normalized_result,
);
};
const originalCases = (
obligation: ReconstructionObligationLedgerPage["obligations"][number],
obligation: ReconstructionObligationLedger["obligations"][number],
evidenceId: string,
) =>
obligation.required_case_kinds.map((caseKind) => ({
@@ -11,10 +11,10 @@ import { createEvidenceBundle } from "../domain/evidenceBundle.js";
import { jsonValueSchema } from "../domain/jsonValue.js";
import { processCaptureSchema } from "../domain/processCapture.js";
import {
reconstructionObligationLedgerPageSchema,
reconstructionObligationLedgerSchema,
serializeReconstructionObligationLedger,
type ReconstructionObligationLedgerInput,
type ReconstructionObligationLedgerPage,
type ReconstructionObligationLedger,
type ReviewedReconstructionObligation,
} from "../domain/reconstructionObligationLedgerSchemas.js";
@@ -82,36 +82,25 @@ const request = (
evidence_bundle: createEvidenceBundle(records),
reviewed_obligations: [],
manifest: { bindings: [], contradictions: [] },
page: { offset: 0, limit: 50 },
...overrides,
});
const build = (
input: ReconstructionObligationLedgerInput,
): ReconstructionObligationLedgerPage => {
): ReconstructionObligationLedger => {
const parsed = resolveReconstructionObligationLedgerRequest(input);
if (!parsed.ok) throw parsed.error;
const result = buildReconstructionObligationLedgerEvidenceValidated(
parsed.value,
);
if (!result.ok) throw result.error;
return reconstructionObligationLedgerPageSchema.parse(
return reconstructionObligationLedgerSchema.parse(
result.value.normalized_result,
);
};
const completeLedger = (
page: ReconstructionObligationLedgerPage,
obligations: ReconstructionObligationLedgerPage["obligations"],
) => {
const { page: pagination, ...ledger } = page;
if (pagination.total !== obligations.length)
throw new TypeError("Incomplete obligation page set");
return { ...ledger, obligations };
};
const originalCases = (
obligation: ReconstructionObligationLedgerPage["obligations"][number],
obligation: ReconstructionObligationLedger["obligations"][number],
evidenceId: string,
) =>
obligation.required_case_kinds.map((caseKind) => ({
@@ -150,45 +139,26 @@ const reviewedObligation = (
});
describe("reconstruction obligation ledger", () => {
it("emits deterministic closure identity and paging", () => {
it("emits the complete deterministic ledger and closure identity", () => {
const evidence = proofEvidence("review");
const reviewed = [
reviewedObligation("obl.review.one", evidence.evidence_id),
reviewedObligation("obl.review.two", evidence.evidence_id),
];
const first = build(
request([evidence], {
reviewed_obligations: reviewed,
page: { offset: 0, limit: 1 },
}),
request([evidence], { reviewed_obligations: reviewed }),
);
const second = build(
request([evidence], {
reviewed_obligations: reviewed,
page: { offset: 1, limit: 1 },
}),
request([evidence], { reviewed_obligations: reviewed }),
);
expect(first.page).toEqual({
offset: 0,
limit: 1,
total: 2,
returned: 1,
next_offset: 1,
});
expect(second.page.next_offset).toBeNull();
expect(first.obligations).toHaveLength(2);
expect(first).toEqual(second);
expect(second.ledger_id).toBe(first.ledger_id);
expect(second.closure_digest).toBe(first.closure_digest);
expect(first.obligations[0]?.source_state).toBe("reviewed");
expect(first.status).toBe("open");
expect(
serializeReconstructionObligationLedger(
completeLedger(first, [...first.obligations, ...second.obligations]),
),
).toBe(
serializeReconstructionObligationLedger(
completeLedger(second, [...first.obligations, ...second.obligations]),
),
expect(serializeReconstructionObligationLedger(first)).toBe(
serializeReconstructionObligationLedger(second),
);
});
@@ -9,9 +9,9 @@ import { createEvidence, type Evidence } from "../domain/evidence.js";
import { jsonObjectSchema, jsonValueSchema } from "../domain/jsonValue.js";
import {
reconstructionObligationLedgerInputSchema,
reconstructionObligationLedgerPageSchema,
reconstructionObligationLedgerSchema,
type ReconstructionObligationLedgerInput,
type ReconstructionObligationLedgerPage,
type ReconstructionObligationLedger,
} from "../domain/reconstructionObligationLedgerSchemas.js";
import { err, ok, type Result } from "../domain/result.js";
import { JAVASCRIPT_APPLICATION_WORKFLOW_PROVIDER } from "./InvestigationProviders.js";
@@ -30,7 +30,7 @@ export const resolveReconstructionObligationLedgerRequest = (
: err(new AnalysisInputError(OPERATION, { cause: parsed.error }));
};
/** Build one deterministic ledger page and wrap it in portable Evidence. */
/** Build the complete deterministic ledger and wrap it in portable Evidence. */
export const buildReconstructionObligationLedgerEvidenceValidated = (
input: ReconstructionObligationLedgerInput,
): Result<Evidence, AnalysisError> => {
@@ -45,8 +45,7 @@ export const buildReconstructionObligationLedgerEvidenceValidated = (
manifest: input.manifest,
generationLimitations: generated.limitations,
});
const page = pageLedger(ledger, input.page.offset, input.page.limit);
return ok(createLedgerEvidence(input, page));
return ok(createLedgerEvidence(input, ledger));
} catch (cause: unknown) {
if (cause instanceof z.ZodError)
return err(new AnalysisInputError(OPERATION, { cause }));
@@ -59,47 +58,24 @@ export const buildReconstructionObligationLedgerEvidenceValidated = (
}
};
const pageLedger = (
ledger: ReturnType<typeof evaluateReconstructionObligationLedger>,
offset: number,
limit: number,
): ReconstructionObligationLedgerPage => {
const obligations = ledger.obligations.slice(offset, offset + limit);
const nextOffset =
offset + obligations.length < ledger.obligations.length
? offset + obligations.length
: null;
const { obligations: _allObligations, ...summary } = ledger;
return reconstructionObligationLedgerPageSchema.parse({
...summary,
page: {
offset,
limit,
total: ledger.obligations.length,
returned: obligations.length,
next_offset: nextOffset,
},
obligations,
});
};
const createLedgerEvidence = (
input: ReconstructionObligationLedgerInput,
page: ReconstructionObligationLedgerPage,
): Evidence =>
createEvidence(undefined, JAVASCRIPT_APPLICATION_WORKFLOW_PROVIDER, {
ledger: ReconstructionObligationLedger,
): Evidence => {
const completeLedger = reconstructionObligationLedgerSchema.parse(ledger);
return createEvidence(undefined, JAVASCRIPT_APPLICATION_WORKFLOW_PROVIDER, {
predicateType: "rea.reconstruction-obligation-ledger/v1",
operation: OPERATION,
parameters: jsonObjectSchema.parse({
ledger_id: page.ledger_id,
closure_digest: page.closure_digest,
page: input.page,
ledger_id: completeLedger.ledger_id,
closure_digest: completeLedger.closure_digest,
}),
result: jsonValueSchema.parse(page),
result: jsonValueSchema.parse(completeLedger),
rawResult: null,
confidence: "inferred",
authority: "analyst-inference",
environment: null,
limitations: page.limitations,
evidenceLinks: page.evidence_links,
limitations: completeLedger.limitations,
evidenceLinks: completeLedger.evidence_links,
});
};