Skip to content

test(evals): migrate the sanitizer and report schemas to scenarios - #199

Merged
pgermishuys merged 2 commits into
mainfrom
test/evals-sanitizer-migration
Sep 20, 2026
Merged

pgermishuys merged 2 commits into
mainfrom
test/evals-sanitizer-migration

Conversation

@pgermishuys

Copy link
Copy Markdown
Contributor

Finishes what #197 started. sanitizer.test.ts and report-schema.test.ts enumerated a denylist and a regex table — "contains composedPrompt", "includes a pattern for html_script_tag" — and said nothing about what a reader of a published bundle is promised. 113 scenarios in tests/evals/publish-safety.scenario.test.ts now feed the equivalent hostile inputs through the real ArtifactBundleWriter and assert what comes out on disk.

Before After
sanitizer.test.ts 140 91
report-schema.test.ts 188 112
Scenario cases 12 125
Total 340 328

The count barely moves, and that is the honest result: the enumeration's user-visible form is an equally long table of hostile inputs. What changes is that the tests now fail when a reader is put at risk, rather than when a constant is renamed.

What the scenarios cover

  • All 24 sensitive field names fed in at once, absent from every written file — value and key.
  • Eight shapes the allowlist has never seen: nested objects, arrays of objects, arrays of bare strings, prototype-shaped keys, extra keys inside an explanation, inside a dimension score, and inside the closed trajectorySummary allowlist.
  • 30 injection payloads in an explanation — chain-of-thought tags, transcript role markers, prompt delimiters, scorer markers, secrets, and every HTML vector in docs/eval-xss-policy.md — each kept out of every uploadable artifact while the case itself still publishes.
  • The four allowed explanation sources and seven rejected ones; missing text, missing source, empty text.
  • The 300-character bound, at the limit and one over.
  • The score buckets a reader skims, including dry-run → skip.
  • A case id carrying markup: dropped from the Markdown, carried verbatim in the JSON where the XSS policy puts escaping in the dashboard. Recorded, not endorsed.
  • The schema versions the website pins, on the report, its suite summaries and all six index files.

Proved by mutation before anything was deleted

Against tests/evals alone:

Mutation Result
sanitizeCaseResultSummary() returns its input 38 of 113 red
Explanation validation removed from assembleCaseEntry() 42 red
sanitizeMdValue() returns its input verbatim 2 red
sanitizeProvenanceRecord() spreads its input 1 red

The second is #197's lesson repeating. On the first pass it turned exactly one scenario red: without validation the whole report fails schema parsing, so public-report.json is never written and "the payload appears in no public artifact" stays true for the wrong reason. Each payload case now also asserts the case is still published — the graceful degradation the pipeline actually promises — and the same mutation turns 42 red.

packages/ was restored and verified clean after every mutation.

Kept, and why

Each file's docblock says this too.

Kept Why
assertPublishSafe() / assertJsonPublishSafe() While the allowlist projection works they never fire, so no written file reveals their behaviour
The manifest schemas' rejection branches Unreachable from a writer that always stamps the version constant; they guard a future producer, and the website's rejection of a bad version depends on them
Strict-mode rejection of sensitive field names A layer above the sanitizer, not a duplicate: the scenarios prove nothing sensitive reaches a file, these prove the schema would refuse one that did
sanitizeScoreRecord, dropUnknownFields, truncateExplanation, buildExplanation, assertExplanationSafe, REDACTED, FORBIDDEN_EXPLANATION_SOURCE_DESCRIPTORS No production caller — see below

Three things observing turned up

All recorded in docs/testing-strategy.md.

  • A case with an empty caseId costs a run its entire dashboard presence, silently. Public-report assembly fails validation, writeBundle() treats that as non-fatal, and no public-report.json, no Markdown and no index files are written — with an ok result and nothing saying so. Two scenarios pin the behaviour as observed.
  • Seven exported sanitizer surfaces have no production caller. The runners build explanations through buildPublicExplanation() in langchain-agent-evals.ts and redact with their own patterns. About 60 unit cases cover code nothing calls. Kept and flagged rather than deleted — removing the API is a product decision.
  • A summary missing dimensionScores makes writeBundle() throw a TypeError instead of returning a typed BundleError, against the neverthrow rule in AGENTS.md. Reachable only by defeating the type system, so no scenario asserts it.

Doc correction

docs/eval-sanitization-and-publish-pipeline.md claimed every index file carries updatedAt. model-comparison-<runId>.json does not — it is regenerated per run and carries runId. Corrected, with a scenario pinning it. Neither normative document is weakened by this change.

Refs #183 (task group 14)

🤖 Generated with Claude Code

https://claude.ai/code/session_01DisVZW27sd6Pe7uhbjXNve

Finishes what #197 started. sanitizer.test.ts and report-schema.test.ts
enumerated a denylist and a regex table — "contains composedPrompt",
"includes a pattern for html_script_tag" — and said nothing about what a
reader of a published bundle is promised. 113 scenarios now feed the
equivalent hostile inputs through the real ArtifactBundleWriter and
assert what comes out on disk.

  sanitizer.test.ts      140 -> 91
  report-schema.test.ts  188 -> 112
  scenarios               12 -> 125
  total                  340 -> 328

The count barely moves, and that is the honest result: the enumeration's
user-visible form is an equally long table. What changes is that the
tests now fail when a reader is put at risk rather than when a constant
is renamed.

What the scenarios cover: every one of the 24 sensitive field names fed
in at once and absent from every written file, value and key; eight
shapes the allowlist has never seen — nested objects, arrays of objects,
prototype-shaped keys, extra keys inside an explanation and inside the
closed trajectory allowlist; 30 injection payloads in an explanation,
each kept out of every uploadable artifact while the case itself still
publishes; the four allowed explanation sources and seven rejected ones;
the 300-character bound at and one over; the score buckets a reader
skims; a case id carrying markup, dropped from the Markdown and carried
verbatim in the JSON where docs/eval-xss-policy.md puts escaping in the
dashboard; and the schema versions the website pins on the report, its
suite summaries and all six indexes.

Proved by mutation before anything was deleted, against tests/evals
alone:

  sanitizeCaseResultSummary returns its input     38 of 113 red
  explanation validation removed from assembly    42 red
  sanitizeMdValue returns its input verbatim       2 red
  sanitizeProvenanceRecord spreads its input       1 red

The second one is the lesson again. On the first pass it turned exactly
one scenario red: without validation the whole report fails schema
parsing, so public-report.json is never written and "the payload appears
in no public artifact" stays true for the wrong reason. Each payload
case now also asserts the case is still published — the graceful
degradation the pipeline actually promises — and the same mutation turns
42 red.

Kept, with the reasoning in each file's docblock: assertPublishSafe and
assertJsonPublishSafe, which never fire while the projection works and
so are invisible from outside; the manifest schemas' rejection branches,
unreachable from a writer that always stamps the version constant; and
the strict-mode rejection of sensitive field names, a layer above the
sanitizer rather than a duplicate of it.

Three things turned up while observing rather than transcribing, all
recorded in docs/testing-strategy.md:

  - A case with an empty caseId costs a run its entire dashboard
    presence, silently. Public-report assembly fails validation,
    writeBundle treats that as non-fatal, and no public-report.json, no
    Markdown and no index files are written — with an ok result.
  - Seven exported sanitizer surfaces have no production caller:
    sanitizeScoreRecord, dropUnknownFields, truncateExplanation,
    buildExplanation, assertExplanationSafe, REDACTED and
    FORBIDDEN_EXPLANATION_SOURCE_DESCRIPTORS. The runners build
    explanations through buildPublicExplanation and redact with their
    own patterns. About 60 unit cases cover code nothing calls; kept and
    flagged, because removing the API is a product decision.
  - A summary missing dimensionScores makes writeBundle throw a
    TypeError instead of returning a typed BundleError.

docs/eval-sanitization-and-publish-pipeline.md claimed every index file
carries updatedAt; model-comparison-<runId>.json does not, and carries
runId instead. Corrected, with a scenario pinning it.

Refs #183 (task group 14)

Claude-Session: https://claude.ai/code/session_01DisVZW27sd6Pe7uhbjXNve

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 20, 2026 20:24
@coderabbitai

coderabbitai Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: eed0dd08-5c96-48c1-8819-71c060d83c1a

📥 Commits

Reviewing files that changed from the base of the PR and between f6f85b9 and be6688e.

⛔ Files ignored due to path filters (3)
  • .codesight/CODESIGHT.md is excluded by !.codesight/**
  • .codesight/coverage.md is excluded by !.codesight/**
  • .codesight/graph.md is excluded by !.codesight/**
📒 Files selected for processing (6)
  • docs/artifacts/cli-evals-migration-handoff.md
  • docs/eval-sanitization-and-publish-pipeline.md
  • docs/testing-strategy.md
  • packages/cli/src/evals/__tests__/report-schema.test.ts
  • packages/cli/src/evals/__tests__/sanitizer.test.ts
  • tests/evals/publish-safety.scenario.test.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pgermishuys

Copy link
Copy Markdown
Contributor Author

Reviewed. Scope is clean — only the two in-scope test files, the scenario file, docs, and the hook's codesight regeneration. No source touched, no other session's files.

I verified the headline defect independently rather than taking it on trust, and it holds. artifact-bundle.ts:1050-1058:

// Assembly failures are non-fatal: public-report.json is omitted when
// the bundle has no score files (e.g. empty dry-run with no cases).
const reportResult = assemblePublicReportBundle(bundle, runId);
if (reportResult.isErr()) {
  // Non-fatal: log-level omission, not a hard error

The comment is what makes it a defect rather than a design: the intent is "no score files, e.g. an empty dry-run", but the branch swallows every assembly failure. A malformed case id therefore costs the run public-report.json, public-report.md and all six index files, and writeBundle() still returns ok with nothing saying so. Good find, and the two scenarios pinning it as observed behaviour are the right call — they document it without asserting it should stay.

One correction: the counts mix two measures

The table compares source it( lines for the unit files against runtime cases for the scenarios. A table-driven it.each is one case in the source and many at runtime, and the scenarios lean on tables much harder than the deleted unit tests did — so "340 → 328" is not like-for-like.

Measured consistently:

Before After
sanitizer.test.ts (source) 140 91
report-schema.test.ts (source) 188 112
Unit total (source) 328 203
Scenarios added (source) — 26
Scenarios added (runtime) — 113

So 125 unit cases went and 26 scenario cases arrived, running as 113. The conclusion is unchanged and if anything understated — the reduction is real, it just isn't the point. I'll correct the table in docs/testing-strategy.md before merging; the worktree is currently held by the other session.

Held, not blocked

Merging once the worktree frees up. The three remaining findings are worth their own decisions rather than being folded in here:

  • Seven exported sanitizer surfaces have no production caller — removing an exported API is a product call, not a test one. Right to flag and keep.
  • writeBundle() throws instead of returning err on a missing dimensionScores, against the neverthrow rule in AGENTS.md. Only reachable by defeating the types, so leaving it unasserted is defensible.
  • A case id containing <script> is published verbatim in public-report.json — consistent with eval-xss-policy.md putting case-id escaping in layer 3, and now pinned by a test. Worth deciding separately whether raw markup in the JSON is acceptable given the website consumes it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The new scenarios contain POSIX-only path handling, an unused schema import remains, and a historical artifact is modified against repository documentation policy.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 2 Medium severity · 1 Low severity

Open (4)
What changed in this PR

This PR completes #197 under #183 by moving eval publish-safety coverage from white-box enumerations to end-to-end ArtifactBundleWriter scenarios.

Changes:

  • Adds hostile-input scenarios covering sanitization, explanations, scores, indexes, Markdown, and provenance.
  • Removes duplicated unit-test enumeration while retaining internal guard/schema tests.
  • Updates testing and pipeline documentation, plus generated Codesight metadata.
File Description
tests/​evals/​publish-safety.scenario.test.ts Adds end-to-end publish-safety scenarios.
packages/​cli/​src/​evals/​__tests__/​sanitizer.test.ts Retains internal sanitizer guard coverage.
packages/​cli/​src/​evals/​__tests__/​report-schema.test.ts Retains non-observable schema coverage.
docs/​testing-strategy.md Records migration results and findings.
docs/​eval-sanitization-and-publish-pipeline.md Corrects index freshness documentation.
docs/​artifacts/​cli-evals-migration-handoff.md Updates migration handoff notes.
.codesight/​graph.md Regenerated import metadata.
.codesight/​coverage.md Regenerated test-file metadata.
.codesight/​CODESIGHT.md Regenerated Codesight report.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.


import { describe, expect, it } from "bun:test";
import {
BoundedExplanationSchema,
Comment on lines +89 to +90
const name = path.slice(path.lastIndexOf("/") + 1);
const isIndex = !path.includes(`${join(root, "runs")}/`);
Comment on lines +707 to +710
const freshness = name.startsWith("model-comparison-")
? parsed.runId
: parsed.updatedAt;
expect(`${name}:${typeof freshness}`).toBe(`${name}:string`);
Comment on lines +48 to +52
| 188 | `report-schema.test.ts` | **migrated** — 188 → 112 (task group 14) |
| 169 | `loom-routing-runner.test.ts` | runner behaviour; mixed |
| 161 | `artifact-bundle.test.ts` | bundle writing; largely observable |
| 153 | `langchain-agent-evals.test.ts` | judge adapter; mixed |
| 140 | `sanitizer.test.ts` | *"contains X"* against a denylist |
| 140 | `sanitizer.test.ts` | **migrated** — 140 → 91 (task group 14) |
The migration table compared source it() lines for the unit files against
runtime cases for the scenarios. A table-driven it.each is one case in
the source and many at runtime, and the scenarios lean on tables far
harder than the deleted unit tests did, so the totals were not
like-for-like.

Measured consistently: 328 unit source cases to 203, with 26 scenario
source cases added that run as 113. The conclusion is unchanged and was
if anything understated.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DisVZW27sd6Pe7uhbjXNve
Copilot AI review requested due to automatic review settings September 20, 2026 20:32
@pgermishuys
pgermishuys merged commit 1ed3e30 into main Sep 20, 2026
7 checks passed
@pgermishuys
pgermishuys deleted the test/evals-sanitizer-migration branch September 20, 2026 20:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Scenario coverage and documentation consistency issues remain unresolved.

Review effort: Lite
Findings: 1 High severity · 2 Medium severity · 1 Low severity

Open (4)
Previously missed (3)

In code that hasn't changed since last review

Medium severity Exercise actual constructor and toString prototype keys

tests/​evals/​publish-safety.scenario.test.ts:272

This fixture does not exercise the advertised prototype-slot edge case: constructorNote and toStringNote are ordinary unknown names. A projection that mishandles own constructor or toString keys would still pass this scenario. Use the actual keys and assert those key names are absent from the written output.

Medium severity Add coverage for omitted weightedTotal skip path

tests/​evals/​publish-safety.scenario.test.ts:624

The migration removed the only coverage for the second documented computeScoreBucket skip path. This test exercises dryRun: true, but computeScoreBucket(undefined, false) is a separate branch (report-schema.ts:290-299) and no scenario now drives an omitted score through the writer, so that behavior could regress unnoticed. Add an omitted-weightedTotal case here and assert the published bucket is skip.

Low severity Update agent evals guide for runId freshness exception

docs/​eval-sanitization-and-publish-pipeline.md:360

This correction leaves docs/agent-evals.md:1150 contradicting it by requiring updatedAt for model-comparison-*.json. Since this change explicitly establishes runId as the freshness exception, update that guide too so dashboard consumers are not given two different contracts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants