~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0

The tests run under a 100% line and function coverage gate

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/hud:test/coverage-gate

HUD's tests now run under the same gate as knotless's: just cov, in just check and the test workflow, fails under 100% of lines or functions. The tests that reach 100% come with it, and found two bugs, fixed here: apply_writes panicked on a template that makes no records, and footnotes matched only by Unicode case drew no note.

Claude Opus 5.5

What changes

The gate. just cov runs every crate's tests under cargo-llvm-cov and fails under 100% of lines or functions, naming each line no test runs. just check runs it in place of cargo test, and test.yml runs the same through chadtmiller.com/steps/cargo-llvm-cov@1 (0.9.1, pinned in uses.lock), keeping HUD_ANSWERS for harness/answers.mjs. It leaves out the tests themselves (tests/, tests.rs), the harness, examples and the standard library. AGENTS.md says how to close a missed line, and docs/internals.md names the gate. HUD needs nothing like knotless's cov.mjs: its tests run against fake PDSes, so one run covers everything.

The tests. Lines went from 87.97% to 100%, functions from 87.34% to 100%. Most are tests of refusals, error paths and edge inputs, each asserting what a caller sees. crates/hud/tests/cli.rs runs the hud binary itself: hud serve with sign-in off and on, stopped by SIGTERM and SIGINT, every configuration refusal, and hud resolve.

Two fixes. apply_writes refuses a template that makes no records ("Nothing to write: no write's when holds") before anything is sent; it sent an empty applyWrites and indexed results[0]. Markdown footnote labels are matched as pulldown-cmark matches them, by Unicode case folding (unicase, a direct dependency now), so x[^É] with [^é]: A draws note A.

Code written so no path is dead. Where no test could reach a line, the code was written so the path does not exist, keeping behaviour for every input that can occur. The larger ones:

  • catalog.rs's prop helpers (p, req, lit, bound) are macros: as const fns they ran only at compile time, so no test could count them.
  • The markdown reader's open blocks are one struct with an Opened kind; its ends share one arm, and main's <details> sits in it as Opened::Details.
  • handle_did asks DNS and the well-known DID with try_join!, a DNS DID ending it at once, in place of a select! whose arms depended on which answered first; the result is the same in every order.
  • With sign-in off, sign_in answers Expired in place of Failed (no route exists then to show it). Auth::resource_metadata (no caller) and Auth::save's ended check (every caller holds a live session's lock or saves a new one) are gone.
  • Net::new's resolver and client builds, and a few others whose error no input reaches, use expect.
  • Multi-line tracing calls bind their fields first, so each is one line: without a subscriber their field lines never run.

Tests pause time where they need to (tokio's test-util, a dev-dependency of hud-core and hud-server).

Why

So a change can't land code no test runs, as on knotless. A missed line is usually a case nobody checked; the two fixes above were found that way.

How it was checked

just check passes: rustfmt, clippy, the tests under just cov (100% of 34,890 lines and 4,204 functions, main merged in), svelte-check, just lint and just lex (287 answers as their lexicons say). The gate runs in about a minute here once built. just e2e and just e2e-spaces were not run: nothing they drive changed but the two fixes above. The runner's first run of the new test.yml step is left to CI.

Shortcomings

  • Tests that run hud serve need its profile written, so they stop it by signal; a test killing it would lose its lines.
  • llvm-cov scores a function by its best compiled copy (hud-core is built for its own tests and again for hud-server's), so a line hud-server's tests reach can still count as missed in hud-core; cargo llvm-cov report --json names it.
  • One blob test streams 101 MB through the proxy to pass its cap: a few seconds.
  • A log-capture dispatcher stays registered for the whole hud-core test process, so a log line first reached on another test's thread is still caught.

Review

The production changes, not the tests: start at catalog.rs, ui/document.rs, identity.rs's handle_did, oauth/ and canvas/space.rs's write.

Approved

This pull adds a 100% line-and-function coverage gate: just cov runs in just check, and the test.yml step runs cargo-llvm-cov, pinned in uses.lock. It also brings the tests that reach 100%, two real fixes, and production code rewritten so no path is dead. AGENTS.md, docs/internals.md and docs/tools.md are updated with it. The test, check, web and docs runs pass at this head. e2e and e2e-spaces were still running when I looked.

What I checked in the production rewrites, which is where a coverage-driven refactor could change behaviour:

  • ui/document.rs: the new .expect()s run on untrusted markdown, so they need to be unreachable.
    • The task marker always arrives with its item on top of the stack.
    • close_details() runs before every block end pops the stack.
    • close_detail only ever pops a Details.
    • The new push into a List's blocks only ever receives items.
    • Footnote matching through UniCase is what pulldown-cmark does, and finish still uses filter_map.
  • identity::handle_did: try_join! short-circuits on a DNS DID and otherwise waits for both answers, the same result as the old select!.
  • oauth/:
    • Every caller of Auth::save either holds a live session's lock after checking ended (snapshot → refresh_locked, refresh_grant) or saves a session that is new.
    • loopback via host_str() matches what the old Host comparisons matched.
    • SignIn::Failed now carries the page, and a request taken in the meantime still reads as Expired.
  • canvas/space.rs: removing move_out relies on an occupied kept entry implying the owner's choice is Space. That holds: both places that set Choice::File (decide, and failed after three failures) call to_files under the same lock.
  • writes.rs: the empty-template refusal comes before anything is sent, and results.first() replaces the results[0] panic.
  • Smaller ones:
    • need in hud-server's xrpc.rs is safe because input is checked against the lexicon first.
    • The view.rs action and tab checks are safe because Ty::check_literal already requires objects.
    • ui/embed.rs external and feeds::fallback_name keep their old results for every input that can occur.

Nothing I read needs to change.

Not read in full: the diffs of crates/hud-core/src/tools.rs (about 1,200 lines) and crates/hud-core/src/oauth/tests.rs (about 1,450 lines) were too large for my tool to return. tools.rs has no new .expect() outside its tests, and the passing test run covers both files. I read every other file in the diff.

Approved

Since I approved at 9cc069c, the only new commit is 94f319f, a merge of main. It brings main's scope work (scope::asked, scope_refused, the removal of HUD_OAUTH_SCOPE) under the coverage gate. It also adds tests for what main brought in untested, and one test-only helper, Auth::signed_in_offline_asking.

The merge. The changes from 9cc069c to the head were too long for my tool to return whole, so I read the pull's own diff of the files where main's scope work and this pull meet: oauth/mod.rs, oauth/store.rs, writes.rs, hud-server's xrpc.rs and hud/src/main.rs.

  • signed_in_offline_asking only exists under cfg(any(test, feature = "testing")), and signed_in_offline_at now calls it with the configured scope, so it behaves as before.
  • In apply_writes, the empty-template refusal still comes before asks_to_write and before anything is sent.
  • The new scope checks sit beside it and are untouched by the merge.
  • The production rewrites I checked last round read the same at this head.

Checks. Every check passes at this head: test (under the gate), check, web, docs, and now e2e and e2e-spaces too, which were still running last round. lexicons was skipped because nothing it watches changed.

My last review asked for nothing, and nothing here needs to change.

Merged as bc7b13f