Skip to content

Enforce test coverage on every code change (framework + scaffolded apps) #162

Description

@vivek7405

Problem

A code change can ship with unit tests only and miss the browser / e2e / smoke layers it actually needs. This happened with the link-prefetch feature (#152): it is fundamentally browser behaviour (hover issues a speculative fetch, the click consumes a warm cache) yet initially shipped with unit tests alone. Skill descriptions and AGENTS.md prose are advisory; only a deterministic gate keeps every change honest about its test layers.

Design / approach

Two parts.

(A) Framework repo.

  • .claude/hooks/require-tests-with-src.sh, a PreToolUse(Bash) hook that BLOCKS a git commit staging packages/*/src/** with no accompanying test file, and BLOCKS a commit that net-removes test lines (the tests-trimmed-to-pass guard). Escape hatches: WEBJS_NO_TEST_GATE=1 and WEBJS_ALLOW_TEST_REMOVAL=1. For client-facing source it also injects a layer reminder (unit is necessary but not sufficient; confirm browser/e2e).
  • AGENTS.md "Definition of done" rewrite: the test bullet becomes an explicit per-layer checklist (unit / browser / e2e / smoke) stating that a unit test alone is insufficient for client-router / component / browser-facing changes.

(B) Scaffolded apps (end users). Most webjs users develop with an AI agent, so the gate must reach their apps too. Ship the same enforcement via packages/cli/templates/: wire it into the scaffold .claude/settings.json, the universal .hooks/pre-commit, and the scaffold AGENTS.md / CONVENTIONS.md. Add a test/scaffolds/ assertion that a freshly scaffolded app contains the gate.

Acceptance criteria

  • Framework hook blocks a commit staging packages/*/src/** with no test, and a commit that net-removes test lines; both overrides work
  • AGENTS.md "Definition of done" spells out the unit / browser / e2e / smoke layers
  • Scaffold templates carry the same gate (settings, pre-commit, AGENTS/CONVENTIONS)
  • A test/scaffolds/ test asserts a freshly scaffolded app contains the gate
  • Tests cover the hook decisions (block, allow, overrides, test-shrink)

Activity

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions