Repository navigation
Show request/response traces when clicking a result - #215
Conversation
Clicking a result symbol on the results page opens a modal (reusing modalOpen) with, for each request in the test, what the client sent, what it received and what the origin saw. The line the failure message is about is highlighted in the result's colour; an expected header that's absent is shown as a "(not present)" line. The client now records a trace for every test, including the origin's view (which is also fetched when a test fails early, as that's when it's most useful). `npm run cli --traces=FILE` writes them as compact JSON, and `npm run embed-traces` merges a file into a single <script type="application/json" id="traces"> block in index.html, one implementation per line, so it can be extracted later. test-docker.sh does both. Traces are about 10 KB gzipped per implementation. Locating the failing line parses the failure message text (display.mjs:locateFailure); a reworded assertion loses its highlight but still shows the message. Existing results have no traces until they're re-run. test-browser.html gets click-to-view and a manual traces download. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Traces now sit under a "_traces" key in results/<implementation>.json, beside the test results, which keep their existing flat shape. The CLI prints both, and the browser page's single download includes them, so there's no separate embed step, --traces flag or traces download. Test results are pretty-printed as before; traces get one compact line per test (serializeResults in lib/results.mjs), and the loader splits them out again (parseResults). The results page now fetches the traces with the results on load, rather than parsing them from index.html. Results files without "_traces" still load; they just have nothing to click. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
mnot
left a comment
There was a problem hiding this comment.
Review of f04e3f9. Moving the traces into the results file removes the stale-trace problem and the embed step. I checked it by running the CLI against the local test server: 365 tests and 365 traces, the file round-trips through parseResults / serializeResults, and standard passes. Two things need attention before merging.
1. Normalise volatile header values (needed)
Two consecutive CLI runs against the same server differed on 364 of 365 trace lines, so every re-run of an implementation rewrites its whole _traces block in git. The fields that moved between the two runs:
dateon responses: 733 differenceslast-modified: 98;expires: 47if-modified-since: 6 on the client request and 6 on the origin's copylocation/content-location: 8 and 9 (they carry the test UUID and base URL)- one response body (I didn't look at which)
I'd normalise these in traceHeaders, reusing dateHeaders and locationHeaders from defines.mjs:
Datebecomes[now].- The other date headers become an offset from the response's
Date, e.g.[now - 60]or[now + 3600]. That keeps the relationship the test is about and drops the absolute time. For request headers, use the previous response'sDate, asfixupHeaderdoes withserver-now. LocationandContent-Locationget the base URL and UUID replaced with[test URL], which is what the modal already shows on the request line.
A value that doesn't parse as a date should be kept as-is.
2. Identifying details from real proxies
This doesn't show up against the local server, but with a real proxy or CDN the traces will carry whatever it adds, and the results files are public. Nothing under tests/ asserts on Host, Via, X-Forwarded-For or Forwarded (I grepped), so eliding them costs nothing. Suggested:
Hostbecomes[host].Viakeeps the protocol version and the list structure, with received-by replaced:1.1 [proxy], 1.0 [proxy].X-Forwarded-For,Forwarded,X-Real-IPand similar have each IP address replaced with[ip], so the hop count survives.- Any IPv4 or IPv6 literal in any other header value becomes
[ip], as a catch-all. - Per-request identifiers (
X-Request-Id,X-Amzn-Trace-Id,X-Amz-Cf-Id,CF-Rayand the like) become[id], which also removes more run-to-run noise.
This is a denylist, so it won't catch everything a CDN invents. The README should say to skim the _traces diff before committing a proxy's results.
3. Nit
serializeResults({}, traces) returns {} and silently drops the traces, because the splice looks for \n} and an empty object has none. A real run never has empty results, so this is cosmetic.
AI-generated: reviewed and drafted by Claude Code. Mark Nottingham chose the points to raise and the normalisation approach in #1; the suggestions in #2 and #3 are Claude's and haven't had a separate human review. The numbers above come from two runs of the CLI against the local test server only; test-docker.sh and real proxies weren't run.
Two consecutive CLI runs against the same server differed on 364 of 365 traces, which would rewrite a whole implementation's traces in git on every re-run; they now differ on none. Traces also go into public results files, where a proxy or CDN's own headers would identify the machines and networks the tests ran on. Volatile values: Date becomes [now]; the other date headers become offsets from the server's clock for that response (its Server-Now header, which is how the tests specify them), e.g. [now - 60], keeping rfc850 format. Values that aren't dates, or are further out than a year, are literals and are kept. The origin's copy of a request is relative to the previous response, as fixupHeader does. URLs to the test (Location, Content-Location) become [test URL], and bodies that are a copy of the UUID are summarised. Identifying values: Host and X-Forwarded-Host become [host]; Via keeps its protocol versions and hop count; X-Forwarded-For, Forwarded and similar have each address replaced with [ip], as do IP literals in any other header; per-request identifiers and timings become [id] and [time]; and User-Agent, Accept-Language, Cookie and Sec-CH-UA* become [redacted]. Headers the test itself sent are its own data and aren't elided (some tests send Cookie and Accept-Language). Nothing in tests/ asserts on the elided headers. Also fixes serializeResults dropping traces when the results are empty, and the README now says to skim a proxy's _traces diff before committing. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
mnot
left a comment
There was a problem hiding this comment.
AI-generated review (Claude Code). Mark asked for it and decided to post it; he hasn't independently verified the findings. I read the diff against the surrounding code and ran two small probes against the PR head. I didn't run the CLI end-to-end, standard, or anything against a real proxy.
Two bugs to fix before merge; the rest is minor.
Bugs
1. serializeResults can write invalid JSON (test-engine/lib/results.mjs, the body.replace(/\n}$/, ...) call)
The replacement is a string containing the trace JSON, so $&, $', $` and $$ in any header value or body are interpreted as replacement patterns. Probe: a header value of cost $& and $$ and $' produced a results file that JSON.parse rejects ("Bad control character in string literal"). A proxy or CDN header containing $ could corrupt results/<impl>.json. Using a function replacement avoids it: .replace(/\n}$/, () => ...).
2. The "Client sent" block redacts the test's own headers (test-engine/client/trace.mjs, traceHeaders as called for req in test-engine/client/test.mjs)
The sent exemption is only passed for the origin view, not for the client request itself. Tests deliberately send Accept-Language (the Vary tests in tests/vary.mjs) and Cookie (tests/other.mjs:233). Probe: traceHeaders([['Accept-Language', 'en, de'], ['Cookie', 'a=b']], { uuid }) returns [redacted] for both, while the origin block shows the real en, de. So the two blocks disagree, and the header the test is about is hidden in exactly the tests where its value is the point.
init.headers only holds the test's own headers plus the harness's, so nothing identifying is lost by skipping elide for the client request. Date and test-URL normalisation should still apply.
Minor
locateFailurematches every message format I checked incheckResponseandcheckServerRequests. For an interim-response failure it highlights every interim status line rather than the one that failed.- The IPv4 regex in
elideruns over every header value, so something likeServer: Apache/2.4.58.1becomesApache/[ip]. Rare, and it errs on the safe side. - Without
Server-Now(some browser CORS setups, AFAIK), non-Datedate headers fall back to the literal value, so those traces won't be stable between runs. locateFailuredepends on the wording of assertion messages and nothing tests it. The PR already says so; a small unit test over the message formats would catch a reworded assertion.
Checked, no issue found
serverNows[item.request_num - 2]is right: the server'srequest_numis the client'sReq-Num(handle-test.mjs:107).- The extra
getServerStateon early failure is read-only and its errors are swallowed. summary.mjsis the only consumer of the results files in the repo, andparseResultsstrips_tracesbefore anything else sees it.- Modal HTML is escaped via
escapeHtml; the test name and colour come from the repo. - Size looks fine for the 12 current results files.
serializeResults spliced the traces in with a string replacement, so "$&", "$'" and similar sequences in a header value or body were interpreted as replacement patterns and could produce a results file that isn't valid JSON. It now uses a function replacement. The client request's own headers were being elided, so the Accept-Language and Cookie the tests send deliberately showed as [redacted] in "Client sent" while "Origin received" showed the real values. Everything in the client request is the test's own data, so only dates and test URLs are normalised there. locateFailure moves to its own module (display.mjs pulls in browser-only imports) and gets a node:test suite, run with `npm test`. It checks a sample message per format, and that every request/response assertion message in client/test.mjs can still be located, so rewording an assertion fails the test rather than silently losing its highlight. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…t got The trace modal now reads in the order a request travels: client sent, origin received, origin sent, client received. Comparing the last two shows what a cache changed on the way back. The test server records the response it generated (status, headers, interim responses, and the body when it isn't the test's UUID) in its per-request state, alongside the existing response_headers. The client copies that into each origin entry in the trace. Those values are the test's own data, so only dates and test URLs are normalised; nothing is elided. An older server doesn't report the response; the client then records origin entries without it and the modal leaves the block out. Against the same test server, traces grow by about 21% (12.1 KB to 14.7 KB gzipped per implementation) and are identical across consecutive runs. Node adds Content-Length, Connection, Keep-Alive and the real Date when it writes the response, after the server records it, so they appear in "Client received" but not in "Origin sent". Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… pauses
"Client sent" often read as just "GET [test URL]". The harness's own
Req-Num header was being dropped, along with the request body and fetch
options (redirect, cache, mode, credentials) a test sets. All three are
now shown. Test-ID, Test-Name and the Pragma and Cache-Control values the
client adds to defeat browser caching stay hidden; the last two can arrive
joined to a test's own Cache-Control ("nothing-to-see-here, max-age=0"),
so only our part is removed.
User-Agent, Accept-Language and Sec-CH-UA are no longer redacted. The
threat model for a results file is disclosing the test environment, not
the device under test. Cookie stays redacted, since one sent to the test
host could carry identifiers from the environment.
The trace notes programmed pauses: "Client waited 3 seconds before the
next request" for pause_after, recorded only when the client did pause,
and "Origin waited N seconds before responding" for response_pause, which
comes from the test definition and so works against an older server.
The modal's close button now stays in view when its content scrolls; it
was absolutely positioned inside the scrolling element.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Clicking a result symbol on the results page now opens a modal showing what the test saw: for each request, what the client sent, what it received, and what the origin received. The line the failure is about is highlighted in the result's colour (red, yellow or blue), and an expected header that's absent appears as a "(not present)" line. The modal reuses
modalOpen; the native hover tooltip is unchanged.How it works:
results/<implementation>.jsonunder a_traceskey, beside the test results, which keep their existing flat shape. The CLI prints both, and the browser test page's download includes them. Test results stay pretty-printed; traces get one compact line per test, so diffs stay readable.test-engine/client/trace.mjs): dates become offsets such as[now - 60], test URLs become[test URL], and hosts, IP addresses, per-request identifiers and browser identity are elided. Two consecutive CLI runs against the same server give identical traces. This is a denylist, so the README says to skim a proxy's_tracesdiff before committing it._tracesout when it loads each file. Results files without it still load; they just have nothing to click.Things to know:
results/*.jsonand iterates its keys will see_tracesas an extra entry.locateFailureindisplay.mjs). A reworded assertion loses its highlight but still shows the message.Tested by running the CLI twice against the local test server and comparing the traces, loading the resulting file in the results page, and clicking through every failure type in the browser pane, plus a page with no traces and the browser test page.
standardpasses.test-docker.shand real proxies were not run.AI-generated: written with Claude Code. Mark Nottingham directed the design in conversation (traces in the results file, compact JSON, click to open a modal, all tests, colour for failures); the code itself hasn't had a separate human review yet.
🤖 Generated with Claude Code