test(environment): check coverage diagnostics without repeating projection (#11900)

* test(environment): check coverage diagnostics without repeating projection

* style(test): format environment coverage assertions
This commit is contained in:
morluto authored and GitHub committed 2026-11-18 07:47:00 +08:00
1 parent 16fb48f9b7
commit 14b15ba8a5
1 file changed
+38 -47
@@ -58,25 +58,24 @@ const plan = (
tool: string,
reason: StateWritePlan["reason"],
extra: Partial<StateWritePlan> = {},
): StateWritePlan =>
({
tool,
effect: "create",
target: "/api/folders",
served: reason === null,
reason,
exemplar_ordinal: 4,
observation: null,
response: null,
body: null,
rules: [],
collection: null,
insert: null,
merge: null,
checked_record_ordinals: [],
contradicted_by: null,
...extra,
}) as StateWritePlan;
): StateWritePlan => ({
tool,
effect: "create",
target: "/api/folders",
served: reason === null,
reason,
exemplar_ordinal: 4,
observation: null,
response: null,
body: null,
rules: [],
collection: null,
insert: null,
merge: null,
checked_record_ordinals: [],
contradicted_by: null,
...extra,
});
it("has a hint for every reason the state view reports for a withheld write", () => {
const reasons = environmentStateFields.writes.element.shape.reason
@@ -119,7 +118,7 @@ it("counts read tools by how they answer and lists writes as served or withheld
tool: "put_folders_by_uid",
effect: "update",
reason: "contradicted",
hint: WITHHELD_WRITE_HINTS.contradicted,
hint: expect.stringMatching(/later read.*contradicted_by/iu),
exemplar_ordinal: 4,
contradicted_by: 9,
},
@@ -127,7 +126,7 @@ it("counts read tools by how they answer and lists writes as served or withheld
tool: "delete_folders_by_uid",
effect: "delete",
reason: "no-state-target",
hint: WITHHELD_WRITE_HINTS["no-state-target"],
hint: expect.stringContaining("path template"),
exemplar_ordinal: null,
contradicted_by: null,
},
@@ -144,9 +143,6 @@ it("summarizes the state the environment-state view derives with the same rules"
coverage.kind !== "environment-coverage"
)
throw new Error("Expected state and coverage views");
const summary = summarizeEnvironmentCoverage(state);
expect(coverage.reads).toEqual(summary.reads);
expect(coverage.writes).toEqual(summary.writes);
expect(coverage.reads.state + coverage.reads.recorded).toBe(
state.views.length,
);
@@ -214,25 +210,20 @@ it("says an untimed capture learns no clock, and only for an untimed capture", (
}),
),
);
for (const [parent, timeline] of [
[parentOf(), "recorded-start-time"],
[scenarioParent, "record-order"],
for (const [parent, needsClockAdvice] of [
[parentOf(), false],
[scenarioParent, true],
] as const) {
const state = project("environment-state", parent);
const coverage = project("environment-coverage", parent);
if (
state.kind !== "environment-state" ||
coverage.kind !== "environment-coverage"
)
throw new Error("Expected state and coverage views");
expect(state.timeline).toBe(timeline);
if (coverage.kind !== "environment-coverage")
throw new Error("Expected coverage view");
expect(coverage.limitations.some((line) => untimed.test(line))).toBe(
timeline === "record-order",
needsClockAdvice,
);
}
});
it("refuses a browser scenario without response bodies as the state view does", () => {
it("refuses a browser scenario without selected response bodies", () => {
const evidence = scenarioCaptureEvidence(
scenarioCaptureFixture(SCENARIO_EXCHANGES, {
request_body: true,
@@ -240,16 +231,16 @@ it("refuses a browser scenario without response bodies as the state view does",
header_values: true,
}),
);
const view = (kind: "environment-state" | "environment-coverage") =>
projectAnalysisView(
parentOf(evidence),
analysisViewRequestSchema.parse({ kind, template_rules: [] }),
);
const state = view("environment-state");
const coverage = view("environment-coverage");
if (state.ok || coverage.ok) throw new Error("Expected both refusals");
expect(coverage.error).toMatchObject({
_tag: "AnalysisUnsupportedTargetError",
message: state.error.message,
expect(
projectAnalysisView(parentOf(evidence), {
kind: "environment-coverage",
template_rules: [],
}),
).toMatchObject({
ok: false,
error: {
_tag: "AnalysisUnsupportedTargetError",
message: expect.stringContaining("response_body selected"),
},
});
});