Skip to content

test: 46 tests for the card display layer, plus one real crash found#28

Draft
ohad6k wants to merge 1 commit into
mainfrom
agents/tests-coverage
Draft

test: 46 tests for the card display layer, plus one real crash found#28
ohad6k wants to merge 1 commit into
mainfrom
agents/tests-coverage

Conversation

@ohad6k

@ohad6k ohad6k commented Jul 23, 2026

Copy link
Copy Markdown
Owner

46 tests for the card display layer in emulo.py (months_between, fmt_tokens, _law_bar, load_card, print_card, _print_card_plain, render_card_html, show_card), which had one happy-path subprocess test and one HTML assertion covering it.

How the target was chosen. No pytest or coverage tooling is installed and CI runs unittest discover, so the agent wrote a throwaway sys.settrace line-coverage collector, ran the suite under it, and cross-referenced executed lines against AST statement lines per function. emulo.py measured 55.8%. Functions that only look uncovered because test_emulo.py drives them through subprocess were excluded.

What the tests actually catch

  • Frame-closure invariant across 8 terminal widths (40 to 200), spanning the narrow/wide layout switch. A padding regression tears the right edge of the card.
  • HTML escaping of mined text in every slot, including <script> in an archetype.
  • _law_bar against malformed counts: "5", None, "x/y", "30/20", "18/0".
  • UnicodeEncodeError fallback to the ASCII renderer, asserting its rows also share a border width.
  • load_card merge precedence between card.json and stats.json.

Bug found, reported not fixed
months_between() catches (ValueError, IndexError) but not TypeError. A card.json with "first_date": null makes None[:4] raise, and it escapes both print_card and render_card_html, so emulo --card tracebacks instead of degrading. A reducer emitting null instead of "" is a plausible real input. Two tests are marked @unittest.expectedFailure with the explanation inline. The fix is adding TypeError to the except tuple.

python -m unittest discover -s tests → 442 tests, OK (skipped=3, expected failures=2). Coverage of emulo.py 55.8% → 64.0%.

Written by an agent working in an isolated worktree, reviewed before push.

The card is the artifact users screenshot and post, and it renders
model-written text into a fixed-width terminal frame and into HTML.
Before this it had one happy-path subprocess test and one HTML label
assertion; a stdlib line-coverage pass put emulo.py at 55.8% with
print_card, _print_card_plain, load_card, show_card, _law_bar,
fmt_tokens and months_between at 0% in-process.

Adds tests/test_card_render.py:
- fmt_tokens / months_between unit boundaries and unparseable dates
- _law_bar width invariance, proportional fill, clamping, zero
  denominator, and the non-ratio counts a drifting reducer emits
- HTML escaping of mined text in every slot, three-law cap, dropped
  stat cells, grade fallback, art path resolution
- load_card stats.json-over-card.json merge precedence and the
  missing-card exit code and hint
- the frame-closure invariant: every framed line is one width across
  eight terminal sizes, narrow and wide layouts, long wrapped laws
- the UnicodeEncodeError -> ASCII fallback card
- show_card writing card.html without opening a browser
- strip_frontmatter / cursor_rule / install_destination edge cases

Two tests are xfail, documenting a real bug left unfixed here:
months_between catches (ValueError, IndexError) but not TypeError, so a
card.json with `"first_date": null` tracebacks out of both print_card
and render_card_html.

emulo.py line coverage 55.8% -> 64.0%. Suite: 396 -> 442 tests, green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ditto Ready Ready Preview, Comment Jul 23, 2026 1:07pm

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.

1 participant