Skip to content

docs: verify build output in the build, not by parsing it - #98

Merged
thecodedrift merged 3 commits into
mainfrom
docs/build-output-conventions
Aug 12, 2026
Merged

docs: verify build output in the build, not by parsing it#98
thecodedrift merged 3 commits into
mainfrom
docs/build-output-conventions

Conversation

@thecodedrift

Copy link
Copy Markdown
Member

Two documentation changes, one commit each.

1. New convention: verify build output in the build (.conventions/STYLEGUIDE-CODE.md)

A new Testing section, stating the rule in three parts:

  • A failing build is still a valid test — of the build. When an invariant is about a build artifact, enforce it where the artifact is produced. If a bundle must not contain something, the build should refuse to emit it rather than emitting it and leaving a test to go looking. An invariant enforced at production time cannot be violated; one enforced afterwards can only be detected.
  • Tests that use a built artifact are fine. Importing the built entry and asserting on behavior, or spawning the built CLI and asserting on output, are ordinary tests. The rule is not "tests must not touch build output."
  • Tests that parse build output are brittle and should be avoided. Re-deriving a fact from generated text reconstructs something the generator already knew, with a worse tool.

Folded in is the rule that prompted this: do not add a dependency in order to test an assertion. A test that needs a parser to make sense of an artifact is a test in the wrong place.

Worked example (the real case)

packages/cli/test/prompts.test.ts asserted that the built dist/prompts.js chunk graph never reaches the CLI entry or a host capability, by regex-scanning the built JavaScript for from "…" to reconstruct the import graph. A built chunk embeds every help recipe as a string literal, and the engine-selection recipe contains the phrase a different axis from "which engine" — so the scan reported dist/prompts.js graph imports which engine. Prose read as an import.

The rejected fixes are in the section as a table:

  • Filtering by specifier shape passed only because that phrase contains a space. Measured against the real bundle, differs from "static-tier" is a bare hyphenated name with no whitespace and would still have been reported. The guard held by luck of punctuation.
  • Adding es-module-lexer parsed the graph correctly but bought a dependency — and a second major version, since vite already pulls 1.7.0 transitively — to serve a single test.
  • Anchoring the regex to line-start matched the lexer exactly on today's bundles, but required from on the same line as import. A future bundler wrapping a long import would silently stop detecting real imports — trading a loud false positive for a quiet false negative, in the guard whose entire job is catching a leak.

The resolution: rollup's OutputChunk already exposes imports and dynamicImports — the exact resolved graph. The check moves into a vite plugin that fails the build, and the test is deleted.

The section generalizes past the anecdote: the same reasoning forbids a YAML parser to assert on generated config, or an HTML parser to assert on rendered output. In each case the generator knows the answer and the test is guessing at it.

This PR documents the convention only — no code changes.

2. Please look at this separately: a dead instruction removed from CLAUDE.md

The top Code Standards section pointed at three files under .claude/. None of the three exist. The same document already links @.conventions/STYLEGUIDE-CODE.md correctly further down under Code Quality Checks, so CLAUDE.md contradicted itself about where the guide lives.

Line Before After
Code Style Guide @.claude/STYLEGUIDE-CODE.md (missing) @.conventions/STYLEGUIDE-CODE.md
UI Conventions @.claude/STYLEGUIDE-UI.md (missing) @.conventions/STYLEGUIDE-UI.md
File Naming Conventions @.claude/FILE-CONVENTIONS.md (missing) line removed

The removed line is the one worth a look. Searching the repo for any file serving a file-naming-conventions role turned up nothing — the only occurrence of the string FILE-CONVENTIONS anywhere is that dangling reference itself. Rather than invent the file, the line is deleted; authoring a new one is out of scope here. This was raised with the repo owner and the removal is a decision already taken, recorded here so it is visible in review rather than silent in a diff. If a file-naming convention should exist, it wants its own PR.

Checks

pnpm lint passes; prettier ran via lint-staged. Markdown only — nothing under packages/, openspec/, or .changeset/ is touched, hence skip-changeset.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Jwc9FFroR3mTZ4hLiSkkX3

thecodedrift and others added 2 commits August 11, 2026 19:27
Adds a Testing section to the code styleguide: an invariant about a build
artifact belongs in the build, where it cannot be violated, rather than in
a test that inspects the artifact afterwards, where it can only be detected.
Tests that use a built artifact stay fine; tests that parse one do not.

Folds in the related rule that a test needing a new parser dependency is a
test in the wrong place, and uses the dist/prompts.js import-graph scan as
the worked example.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jwc9FFroR3mTZ4hLiSkkX3
Both styleguide pointers in the Code Standards section referenced
.claude/, where neither file exists; the same document already links
.conventions/STYLEGUIDE-CODE.md correctly under Code Quality Checks.
Repoints both at .conventions/.

Also drops the File Naming Conventions line: .claude/FILE-CONVENTIONS.md
does not exist and nothing in the repo serves that role, so the
instruction resolved to nothing.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Jwc9FFroR3mTZ4hLiSkkX3
Copilot AI lite review requested due to automatic review settings August 12, 2026 02:35
@thecodedrift thecodedrift added the skip-changeset PR intentionally ships no release note (bypasses the changeset requirement) label Aug 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates repository documentation to establish and clarify conventions around testing build artifacts, and to remove stale/incorrect references in contributor guidance.

Changes:

  • Adds a new Testing section to .conventions/STYLEGUIDE-CODE.md recommending enforcing build-artifact invariants inside the build (and avoiding tests that parse generated output).
  • Updates CLAUDE.md to point “Code Standards” links at the existing .conventions/ style guides and removes a dead reference to a non-existent file-naming conventions doc.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
CLAUDE.md Fixes “Code Standards” links to reference the actual .conventions/ guides; removes a dead .claude/ reference.
.conventions/STYLEGUIDE-CODE.md Documents a new testing convention: enforce build-output invariants at build time rather than regex/parsing generated artifacts.

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

Comment thread .conventions/STYLEGUIDE-CODE.md
Comment thread .conventions/STYLEGUIDE-CODE.md
Comment thread .conventions/STYLEGUIDE-CODE.md Outdated
Gives a complete self-contained example for the conventions doc

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@thecodedrift
thecodedrift merged commit a245c62 into main Aug 12, 2026
4 checks passed
@thecodedrift
thecodedrift deleted the docs/build-output-conventions branch August 12, 2026 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changeset PR intentionally ships no release note (bypasses the changeset requirement)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants