Skip to content

refactor(todos): share the title rules between the api and the web (ADR 0127) - #344

Merged
BenSheridanEdwards merged 3 commits into
mainfrom
refactor/share-feature-rules
Nov 16, 2026
Merged

BenSheridanEdwards merged 3 commits into
mainfrom
refactor/share-feature-rules

Conversation

@BenSheridanEdwards

@BenSheridanEdwards BenSheridanEdwards commented Nov 8, 2026 •

Copy link
Copy Markdown
Owner

Why does this feature exist?

  • In six of nine agent rebuilds the to-do title rules (normalise whitespace, 1 to 100 characters, Enter a title, Use 100 characters or fewer) were written twice, in apps/api/src/features/todos/domain.ts and apps/web/src/routes/todos/todoFormSchema.ts, as the reference does (SLOP finding R1). In six rebuilds the web copy hard-codes 100 while the api interpolates its constant (P4), and two split normalising across the schema and the hook (B4). The architecture forces the duplication: the web may import the api by type only.
  • Issue adr: share a feature's validation rules between api and web #338 asks for an ADR on sharing a feature's validation rules, and a prototype on the to-do feature. Chief decides before this merges, so it stays a draft.

Base: rebased onto main (e7653ac); #335 was closed unmerged. This PR retains ADR 0127 and its prototype.

Closes #338

What changed?

  • Rebase follow-up: the merge-remedy test ignores the script path when checking its text, so a worktree named rebase-344 cannot cause a false failure. All 20 targeted tests pass.

  • ADR 0127 (Proposed) (4de0820): context, three options (status quo; a small shared pure module that the api domain and the web form import; api-only validation with the web reading api errors), the decision, consequences, and a table of every zone and import-rule change. It proposes option 2 with the module in the api feature, so the api stays the owner the PRD names and each result stays self-contained.

  • Prototype (a090f11):

    • apps/api/src/features/todos/rules.ts holds TITLE_MAX_LENGTH, TITLE_MESSAGES and normaliseTitle and imports nothing. domain.ts builds checkTitle from it; todoFormSchema.ts decodes with normaliseTitle and checks the shared limit and messages. Both copies are gone.
    • The web imports it as @repo/api/todos/rules: apps/api/package.json adds the export ./*/rules with a default condition; . stays types-only. apps/web/package.json moves @repo/api from devDependencies to dependencies (lockfile updated, no new package).
    • Architecture config: .fallowrc.jsonc adds the zone api-rules; api-domain, web-routes and web-features may import it by value; it may import no other role, types included, like ui. contract.rules.jsonc adds contract/rules-pure (no tRPC, Effect, React or Node). tsconfig.domain.json compiles rules.ts with no Node or DOM. structure.mjs route-colocation accepts @<scope>/api/<feature>/rules from the same result only. Diagrams regenerated.
    • Tests first: seeded Fallow tests prove the domain and a route may import the rules, and that rules importing their domain, rules importing Effect, and the api client importing the rules each fail; structure tests accept the own-result subpath and reject @repo/api/todos/domain and another result's rules. rules.test.ts takes the normaliser cases from domain.test.ts; todoFormSchema.test.ts asserts the form uses the api's limit and messages. The contract and trial-inclusion pins gain api-rules.
    • ARCHITECTURE.md (role table, api file roles, rules table, route co-location) and CONVENTIONS.md (contract and file-role tables) name rules.ts.

Behavioural Proof (with video and screenshots)

  • Video: Not applicable: an internal refactor; the page shows the same messages at the same moments, which the E2E tests pin.
  • Screenshots: Not applicable: no visible change; every title rule and message is the same text from one source.
  • Behaviour tests: apps/api/src/features/todos/rules.test.ts, domain.test.ts, apps/web/src/routes/todos/todoFormSchema.test.ts (shared limit and messages), TodosPage.test.tsx; tooling/architecture/boundaries.test.ts and structure.test.ts for the new rules. The new tests failed first (5 failed before rules.ts and the config existed).
  • E2E mapping: unchanged; all 45 Playwright tests, including the title tests ("asks for a title and sends nothing when the title is blank", "rejects a title over 100 characters and sends nothing", "accepts a title of exactly 100 characters after normalising"), pass in the pre-push hook at a090f11.

Verification Summary

  • Head commit: 6a587fd
  • PRDs checked: docs/prd/todos.md
  • PRD impact: No behaviour change: the api still owns and applies the title rules, and the page applies the same rules before it sends, now from one module.
  • North Star commit: e3e180b9024c3d51c5ec4c38783ef9306aa79b87
  • Commands run (e.g. pnpm verify, pnpm e2e): pnpm lint:anti-slop, pnpm verify, pnpm e2e; targeted pnpm exec jest --selectProjects tooling --runTestsByPath scripts/require-up-to-date-main.test.ts.
  • Results: all commands passed on 6a587fd: 96 unit/tooling suites, 3232 tests; contract and integration passed; E2E 32/32. JS 109.66 kB / 110 kB; CSS 2.72 kB / 5 kB. Earlier runs exposed a script-path assertion fixed here and worktree snapshot interference while committing; the final clean-tree run passed. Hosted checks and deployed runtime remain unverified.
  • Definition of Done (.agents/project/PR_QUALITY.md) satisfied, or each gap named: satisfied locally, but this is a draft for Chief's architecture decision.
  • pnpm verify
  • pnpm e2e
  • Behaviour is covered by the E2E map when user-visible behaviour changed.
  • Logic is unit-tested where logic changed.
  • Accessibility considered and verified for interactive/UI changes.
  • The diff follows .agents/project/ARCHITECTURE.md and CONVENTIONS.md; new decisions recorded as ADRs.
  • No gates were bypassed or weakened.
  • Known risks or skipped checks (with reason, risk, and rollback):
    • This deliberately widens one boundary, which is the decision Chief is asked to make: the web may now import one api zone, api-rules, by value, and @repo/api gains one runtime export. It is bounded by Fallow (only the domain, routes and web features may import it, and it imports no role), by contract/rules-pure and by the domain tsconfig. No hook, workflow, budget, guarded file or severity changes, and no gate was bypassed; the box above stays unticked because the boundary does widen.
    • AGENTS.md is not changed (outside this builder's remit). If ADR 0127 is accepted, line 68 (the first row of "Rules and what enforces them") needs two edits: "Type-only imports may cross roles except into @repo/ui, which imports no role" becomes "...except into @repo/ui and a feature's rules.ts, which import no role", and "route value and type imports stay within their own folder, @repo/ui, the api-client public barrel and external npm packages" becomes "...the api-client public barrel, their own api's feature rules (@<scope>/api/<feature>/rules) and external npm packages".
    • ADR 0127 amends ADRs 0032, 0075 and 0123 but does not edit them; ADR 0123's sentence "the web reaches the api by type only" stays as history.
    • A rebuild can still keep two copies; the ADR names a follow-up, check:shared-literals, to fail on a long string present in both apps/api/src and apps/web/src.
    • The local runs used Node 26.12.1 while .nvmrc pins 22; CI runs the pinned version.
    • Rollback: revert the two commits; both copies of the rules return.

PRD Behaviours to Review

  • docs/prd/todos.md: Says so when the list fails to load. Evidence: unchanged behaviour; pnpm e2e passed all 32 tests on 6a587fd.
  • docs/prd/todos.md: Marks a to-do done and active again, in place. Evidence: unchanged behaviour; pnpm e2e passed all 32 tests on 6a587fd.
  • docs/prd/todos.md: Edits a title in place, normalised. Evidence: unchanged behaviour; pnpm e2e passed all 32 tests on 6a587fd.
  • docs/prd/todos.md: Deletes a to-do at once. Evidence: unchanged behaviour; pnpm e2e passed all 32 tests on 6a587fd.
  • docs/prd/todos.md: Clears every done to-do, whatever the filter, and only while one is done. Evidence: unchanged behaviour; pnpm e2e passed all 32 tests on 6a587fd.
  • docs/prd/todos.md: Keeps the done to-dos and says so when clearing fails. Evidence: unchanged behaviour; pnpm e2e passed all 32 tests on 6a587fd.
  • docs/prd/todos.md: Shows only the latest failure, until the next change starts. Evidence: unchanged behaviour; pnpm e2e passed all 32 tests on 6a587fd.
  • docs/prd/todos.md: Says so when the list fails to load after a change. Evidence: unchanged behaviour; pnpm e2e passed all 32 tests on 6a587fd.
  • docs/prd/todos.md: Reads the list when the page opens and after each successful change. Evidence: unchanged behaviour; pnpm e2e passed all 32 tests on 6a587fd.
  • docs/prd/todos.md: Shows loading until the list arrives. Evidence: unchanged behaviour; pnpm e2e passed all 32 tests on 6a587fd.
  • docs/prd/todos.md: Loads an empty list and adds a normalised title. Evidence: unchanged behaviour; pnpm e2e passed all 32 tests on 6a587fd.
  • docs/prd/todos.md: Rejects blank and too-long titles. Evidence: unchanged behaviour; pnpm e2e passed all 32 tests on 6a587fd.
  • docs/prd/todos.md: Filters to active or done to-dos and back to all. Evidence: unchanged behaviour; pnpm e2e passed all 32 tests on 6a587fd.
  • docs/prd/todos.md: Hides a newly done to-do from Active. Evidence: unchanged behaviour; pnpm e2e passed all 32 tests on 6a587fd.
  • docs/prd/todos.md: Shows an empty message for an unmatched filter. Evidence: unchanged behaviour; pnpm e2e passed all 32 tests on 6a587fd.
  • docs/prd/todos.md: Passes the automated accessibility scan. Evidence: unchanged behaviour; pnpm e2e passed all 32 tests on 6a587fd.

PR Proof Law

  • I followed .agents/project/PR_QUALITY.md and .agents/skills/pr-quality-contract/SKILL.md; the PR quality check verifies the proof format.

@github-actions github-actions Bot added confidence: red A required gate is failing or pending, or evidence is unavailable. confidence: amber Required gates passed, with an E2E, PRD, unit coverage or import blast-radius gap. and removed confidence: red A required gate is failing or pending, or evidence is unavailable. labels Nov 8, 2026
@BenSheridanEdwards
BenSheridanEdwards force-pushed the refactor/share-feature-rules branch from 26c5235 to 75e5efd Compare November 9, 2026 00:13
@github-actions github-actions Bot added confidence: red A required gate is failing or pending, or evidence is unavailable. confidence: amber Required gates passed, with an E2E, PRD, unit coverage or import blast-radius gap. and removed confidence: amber Required gates passed, with an E2E, PRD, unit coverage or import blast-radius gap. confidence: red A required gate is failing or pending, or evidence is unavailable. labels Nov 9, 2026
BenSheridanEdwards added a commit that referenced this pull request Nov 9, 2026
- ADR 0128 (renumbered from 0127, which draft #344 holds) amends ADR
  0059: duplicates.ignore keeps one showcase/** entry in place of
  named per-result entries, because every trial result copies the
  reference's template files and would fail its own audit on them.
  0059's status and ARCHITECTURE.md say so; health.ignore is unchanged.
- The docs state the duplication check as the script enforces it:
  a threshold of 0 or above 0.001 fails the gate.
- boundaries.test.ts runs the gate's Fallow steps one by one without
  a shell, so a checkout path with a space cannot break them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BenSheridanEdwards added a commit that referenced this pull request Nov 10, 2026
- ADR 0128 (renumbered from 0127, which draft #344 holds) amends ADR
  0059: duplicates.ignore keeps one showcase/** entry in place of
  named per-result entries, because every trial result copies the
  reference's template files and would fail its own audit on them.
  0059's status and ARCHITECTURE.md say so; health.ignore is unchanged.
- The docs state the duplication check as the script enforces it:
  a threshold of 0 or above 0.001 fails the gate.
- boundaries.test.ts runs the gate's Fallow steps one by one without
  a shell, so a checkout path with a space cannot break them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BenSheridanEdwards added a commit that referenced this pull request Nov 10, 2026
- ADR 0128 (renumbered from 0127, which draft #344 holds) amends ADR
  0059: duplicates.ignore keeps one showcase/** entry in place of
  named per-result entries, because every trial result copies the
  reference's template files and would fail its own audit on them.
  0059's status and ARCHITECTURE.md say so; health.ignore is unchanged.
- The docs state the duplication check as the script enforces it:
  a threshold of 0 or above 0.001 fails the gate.
- boundaries.test.ts runs the gate's Fallow steps one by one without
  a shell, so a checkout path with a space cannot break them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BenSheridanEdwards added a commit that referenced this pull request Nov 10, 2026
…rnings (#346)

* feat(gates): fail the gate on Fallow, Playwright worker and runner warnings

- pnpm arch:gate runs scripts/check-fallow-severity.mjs first, which
  fails when a Fallow rule, override or rule-pack rule is set to warn.
  Fallow reports a warn finding and exits 0, so the gate refuses the
  setting. boundaries.test.ts proves it on a seeded repository.
- The Playwright fixture listens on the browser context, so a popup,
  another page or a dedicated worker that warns or throws fails the
  test, and records console.warn, console.error and Node warnings in
  the test's own process.
- pnpm e2e:console-guard proves seven new failing cases and runs three
  fixture mutants in one child run, so its servers still start twice.
- ADR 0127 records the decision and what stays outside it; the North
  Star states warnings-as-failures as a guarantee.

Closes #231

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

* fix(gates): fail the audit on any Fallow clone group

fallow audit reports a clone group as a warning, returns the warn
verdict and exits 0 unless duplicates.threshold is set. The first
gate run of this branch showed it: a duplicated block in the guard
cases passed.

- .fallowrc.jsonc sets duplicates.threshold to 0.001, so any clone
  group fails the audit; showcase results stay out because they copy
  the reference's template files by design. Main has no clone group.
- check-fallow-severity.mjs also fails a config with duplication on
  and no threshold, and is split into small functions.
- boundaries.test.ts proves both: a committed clone gives warn and
  exit 0 without the threshold, fail and exit 1 with it.
- The popup guard cases share one helper instead of a copied block.
- ADR 0127 records that Fallow's zone log lines are diagnostics, not
  findings, and stay non-fatal.

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

* fix(gates): keep the duplicates ignore list first and multi-line for the benchmark

scripts/bench/generate.mjs appends its clones to duplicates.ignore and
needs that list first in the block; a comment inside the list keeps
Biome from folding it onto one line. The boundaries tests set the
threshold to 0 rather than strip the block.

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

* fix(gates): apply the first review's findings to the warning guards

- Node prints its own process warnings through console.error, so the
  fixture recorded one warning twice and the runner-warning mutant
  failed in CI. The console patch now skips text that starts with
  "(node:<pid>) "; the warning listener records each one once.
- The proof's children run without NO_COLOR, as CI does: beside
  FORCE_COLOR it makes Node warn at worker start, which hid the bug.
- A failing fixture attaches console-guard.json with its exact
  unexpected and missing lists, and the proof compares those instead
  of scraping single-line strings from the assertion diff.
- Two more mutants: popup pages and the console.warn patch.
- The console patch formats arguments with util.format, so a
  prototype-less object is recorded instead of throwing.
- check-fallow-severity.mjs requires a duplication threshold above 0
  and at most 0.001; a threshold of 5 now fails the gate too.
- The North Star names the four tools whose warn-severity findings
  fail, and ADR 0127 is retitled to match and lists commitlint's warn
  rules as outside the guarantee.

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

* fix(gates): apply the second review's findings to the warning guards

- ADR 0128 (renumbered from 0127, which draft #344 holds) amends ADR
  0059: duplicates.ignore keeps one showcase/** entry in place of
  named per-result entries, because every trial result copies the
  reference's template files and would fail its own audit on them.
  0059's status and ARCHITECTURE.md say so; health.ignore is unchanged.
- The docs state the duplication check as the script enforces it:
  a threshold of 0 or above 0.001 fails the gate.
- boundaries.test.ts runs the gate's Fallow steps one by one without
  a shell, so a checkout path with a space cannot break them.

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

* docs(adr): align ADR 0059's body with the showcase duplication exemption

ADR 0059's Decision and Consequences still described per-result
duplicates.ignore entries; they now point to ADR 0128 for code
duplication and keep the per-result rule for health.ignore only.
check-fallow-severity.mjs treats a config with no rule pack as having
none, so it names each warn rule instead of throwing.

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

* docs(gates): bring the warning-guard docs in line with ADR 0128

- ADR 0086's Consequences say what it covered as first merged and
  point to ADR 0128 for pages, workers, the test process and Fallow.
- ADR 0079's status names its amendment by ADR 0128.
- QUALITY_GATES states the Playwright and Fallow warning guards.
- ADR 0128 and check-fallow-severity.mjs say the threshold is a share
  of every line Fallow analyses, and when one clone group stays above it.

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

* docs(gates): scope the AGENTS warning row and amend ADR 0034

- AGENTS.md says Fallow fails on a warn-severity finding and that its
  log lines stay output, matching the North Star and ADR 0128.
- ADR 0034 said no showcase result gets an exception; its status now
  names ADR 0128's code-duplication exemption, and 0128 lists 0034
  among the records it amends.
- ADR 0128 describes the seeded thresholds as the test sets them.

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

* docs(gates): say service-worker console calls fail the test

A service worker's console.warn or console.error reaches the browser
context, so the fixture records it; only the browser's own lifecycle
logs stay outside. ADR 0128's Amends list is one item per record,
ADR 0079 names the full threshold bound, and ADR 0059's status says
its title now holds for styling, complexity and health only.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Six of nine agent rebuilds wrote the to-do title rules twice, in the
api domain and in the web form, because the web may import the api by
type only. ADR 0127 (Proposed) weighs the status quo, a shared pure
module and api-only validation, and proposes a pure rules.ts in each
api feature that the domain and the web form both import, with the
zone, contract, structure and manifest changes it needs. Issue 338.
Prototype for ADR 0127. apps/api/src/features/todos/rules.ts holds
TITLE_MAX_LENGTH, TITLE_MESSAGES and normaliseTitle and imports
nothing. The domain's checkTitle and the web's todoFormSchema both use
it; the web imports it as @repo/api/todos/rules, the api package's one
runtime export.

Fallow gains the api-rules zone: the domain, routes and web features may
import it by value, and it imports no other role. contract/rules-pure
bans tRPC, Effect, React and Node there, tsconfig.domain.json compiles
it without Node or DOM, and route-colocation accepts the subpath from
the same result only. The web lists @repo/api as a dependency now that
it ships code from it.

Seeded boundary and structure tests cover each new allowance and each
new failure; the contract and trial inclusion pins gain api-rules, and
ADR 0127 lists them. Behaviour is unchanged.
@BenSheridanEdwards
BenSheridanEdwards changed the base branch from feat/todo-example-app to main November 16, 2026 20:14
@github-actions github-actions Bot added confidence: red A required gate is failing or pending, or evidence is unavailable. and removed confidence: amber Required gates passed, with an E2E, PRD, unit coverage or import blast-radius gap. labels Nov 16, 2026
@BenSheridanEdwards
BenSheridanEdwards force-pushed the refactor/share-feature-rules branch from 75e5efd to 6a587fd Compare November 16, 2026 20:20
@github-actions

Copy link
Copy Markdown
Contributor

This PR needs no enforcement or product intent sign-off.

@github-actions github-actions Bot added confidence: amber Required gates passed, with an E2E, PRD, unit coverage or import blast-radius gap. and removed confidence: red A required gate is failing or pending, or evidence is unavailable. labels Nov 16, 2026
@BenSheridanEdwards
BenSheridanEdwards marked this pull request as ready for review November 16, 2026 20:30
@BenSheridanEdwards

Copy link
Copy Markdown
Owner Author

Opus review — APPROVE

Reviewed head 6a587fdf04cf67da227fdb86f731128e57b2ac57 against main e7653ac and #338.

Verdict: APPROVE. No blocking findings.

The shared title rules live in one import-free rules.ts. The api domain and the web form both use it, behaviour tests still assert the literal messages and limits on both sides, and the new Fallow / contract / architecture tests cover the boundary. The rebase onto main left the change sound.

Non-blocking only: ADR 0127 is still marked Proposed while ARCHITECTURE.md already cites it; AGENTS.md's co-location sentence is stale; one schema test is mostly circular (literals are covered elsewhere); the new ./*/rules export becomes a showcase manifest requirement; the require-up-to-date-main path-mask is out of scope but sound; an unescaped scope in a regex is harmless for npm-legal scopes.

All required hosted checks were green at this head, enforcement-approval passed with no sign-off required, and the PR body has no wait-for-Ben wording.

@BenSheridanEdwards
BenSheridanEdwards merged commit a0a8ff6 into main Nov 16, 2026
21 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

confidence: amber Required gates passed, with an E2E, PRD, unit coverage or import blast-radius gap.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

adr: share a feature's validation rules between api and web

1 participant