Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 70 additions & 30 deletions .agents/decisions/0124-lint-the-patterns-agent-rebuilds-repeat.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
Nine agents rebuilt a reference feature from its PRD: six to-do rebuilds and
three greeting rebuilds. Every rebuild passed every gate, and each still
carried patterns a reviewer would reject. Six of them recurred, can be found in
one file with no type information, and had no false positive in the
reference. Several are what agents reach for in place of a banned form: with
one file with no type information, and leave the fixed reference with no
finding. Two later to-do rebuilds, r7 and r8, repeated them and added one
variant, a status read through a lookup object. Several are what agents reach for in place of a banned form: with
`noUncheckedIndexedAccess` on and the non-null assertion banned, a test that
needs a value writes `?? ''`, because the repository offered no sanctioned way
to unwrap one.
Expand All @@ -23,43 +24,82 @@ result-root override, `{apps,packages}/*/src/**/*.{ts,tsx}` and
`showcase/*/*/src/**/*.{ts,tsx}`:

- `policy/one-status-from-hooks`: a `use*` hook returns one `status` union,
and one object it returns reads at most one of a query's `data`, `error`,
`status`, `isPending`, `isLoading`, `isFetching`, `isError` and
`isSuccess`, following one `const` binding.
- `policy/test-unwraps-values`: a test unwraps a value with `present()`.
`?? ''` and an `x.ok ? … : <literal>` stand-in fail. The rule also runs on
each result's `web/e2e/**/*.ts`, in an override of its own.
and one object it returns reads at most one of a query's `data`, `status`,
`isPending`, `isLoading`, `isError` and `isSuccess`. A query is a `const`
bound to the result of `useQuery`, `useSuspenseQuery` or `useInfiniteQuery`.
A lookup keyed by the status, such as `STATES[list.status]`, reads
`status`. The rule follows one `const` binding, and resolves each name in
its own scope. `error` and `isFetching` describe a state rather than choose
one, so `{ status: list.status, problem: list.error }` and
`{ list: list.data, refreshing: list.isFetching }` pass, as does a mutation
hook's `{ submitting, problem }`.
- `policy/test-unwraps-values`: a test takes a value with `present()` and an
outcome's value with `unwrap()`. `?? ''` fails, and so does a ternary on
`x.ok` whose other branch reads `x.value…` and whose fallback is a literal;
`response.ok ? 'passed' : 'failed'` passes. The rule also runs on each
result's `web/e2e/**/*.ts`, in an override of its own.
- `policy/test-imports-the-type`: a test declares no interface or type alias
that a non-test module in its folder exports.
- `policy/message-uses-its-limit`: a string or JSX text holds no number that a
module-scope `const` of 10 or more in the same file names. Smaller numbers
appear in ordinary prose too often to tie to one constant.
- `policy/import-types-from-their-owner`: a module under `src/routes/<slice>/`
or `src/features/<slice>/`, other than `index.ts`, re-exports nothing, from
a source or from an import.
that a non-test module in its folder exports with a declaration at the
start of a line, so `export type` inside a string or comment does not
count. One scan of a folder serves all its tests until a module in it
changes.
- `policy/message-uses-its-limit`: a string, template or JSX text writes no
limit as a count. A limit is a module-scope `const` of 10 or more in the
same file whose name holds `MAX`, `MIN`, `MAXIMUM`, `MINIMUM`, `LIMIT`,
`LENGTH` or `LEN` (`TITLE_MAX_LENGTH`, `maxTitleLength`). A count is the
number, or its grouped form such as `1,000`, followed by a word
(`100 characters`), so `100%`, `gap-10` and a port in a URL pass. JSX
attribute values and import sources hold no message and are skipped.
Smaller numbers appear in ordinary prose too often to tie to one
constant.
- `policy/reexport-only-from-index`: a module under `src/routes/<slice>/` or
`src/features/<slice>/`, other than the slice's own `index.ts`, re-exports
nothing, from a source or from an import, so its siblings import each name
from the module that declares it. A nested barrel such as
`src/routes/todos/components/index.ts` is not the slice's public surface
and fails too: `no-restricted-imports` already admits only
`routes/*/index.ts` and `features/*/index.ts` as entry points.
- `policy/keep-rejections`: a `.catch` or second `.then` handler that ignores
its error and returns a literal, `undefined` or nothing fails, following one
`const` binding.
`const` binding resolved in the handler's own scope. When a caller means to
ignore a failure, settle the promise and read the result:
`void Promise.allSettled([prefetch()])` for a fire-and-forget call, or
`Promise.allSettled([save()]).then(([result]) => result?.status === 'fulfilled')`
for a yes or no. Both keep the rejection in the settled result and pass
`pnpm lint:policy`, `pnpm lint:anti-slop` and Biome. A handler that uses its
error, such as `.catch(report)`, also passes.

Tests and specs are outside the three source rules, and inside the two test
rules. Ship `present` in `tooling/jest/present.ts`, beside the Jest setup that
holds the other shared test helpers. It returns a defined value or the value of
an ok outcome, and throws otherwise. The Jest setup makes it a global, typed by
`tooling/types/present.d.ts`, because a unit test in a package may import
nothing from outside that package (`policy/slice-isolation`). A result is
self-contained and a showcase copies the reference's `e2e/` folder, so each
result's `e2e/fixtures.ts` holds its own five-line `present` for defined
values, and each E2E spec imports it from there.
rules. Ship `present` and `unwrap` in `tooling/jest/test-globals.ts`, beside
the Jest setup that holds the other shared test helpers. `present(value)`
returns a value that is neither `null` nor `undefined` and throws otherwise.
`unwrap(outcome)` takes only an `{ ok: true, value } | { ok: false }` outcome,
returns its value, and throws with the failure otherwise. The Jest setup makes
both globals, because a unit test in a package may import nothing from outside
that package (`policy/slice-isolation`). `tooling/types/test-globals.d.ts`
types them, and only the test type programs, `tsconfig.test.json` and
`tsconfig.api.test.json`, include it: the web and api programs exclude test
files, so a production module that calls either fails `pnpm typecheck`. A
result is self-contained and a showcase copies the reference's `e2e/` folder,
so each result's `e2e/fixtures.ts` holds its own five-line `present`, which a
unit test holds to the same behaviour as the Jest global, and each E2E spec
imports it from there.

## Consequences

The reference fixes its own hits in the same change: four in
`application.test.ts`, five in `e2e/todos.spec.ts` and the restated `Todo` in
`TodosPage.test.tsx`. Each rule fires on the rebuild samples it was mined
from. Until the pre-commit hook runs `pnpm lint:policy`, these rules fail at
pre-push and in CI rather than at commit.
from, and r7 and r8 confirm them.

`policy/one-status-from-hooks` reads only the returned object, so a hook that
splits the flags across helper functions passes. `policy/test-unwraps-values`
leaves other fallback strings such as `?? 'waiting'` to review, because a test
may render one on purpose. Both are trade-offs for a zero false-positive rate.
Each rule trades recall for precision, and its fixtures, valid and invalid,
mark the boundary. `policy/one-status-from-hooks` reads only the returned
object, so a hook that splits the flags across helper functions passes, and it
leaves `data` beside `error` to review. `policy/test-unwraps-values` leaves
other fallback strings such as `?? 'waiting'` to review, because a test may
render one on purpose. `policy/message-uses-its-limit` skips JSX attributes, so
a `placeholder` that restates a limit passes. The first version of these rules
reported five shapes that were not the pattern, found in review: a query's
`isFetching`, a mutation's state, a status beside its error, a flattened local
union and an `ok` check that never reads `value`. Each is now a passing
fixture.
4 changes: 2 additions & 2 deletions .agents/project/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ each check's message names the fix.
| Every file belongs to one role and one slice. | Fallow `coverage.requireAllFiles`; `policy/slice-isolation` for a loose file under `src/routes/` or `src/features/` | `pnpm arch:gate`, `pnpm lint:policy` |
| A package reaches another only by its package name. | `policy/slice-isolation` (relative import out of the package) | `pnpm lint:policy` |
| A module is imported through its `index.ts`. | Oxlint `no-restricted-imports`; API reports | `pnpm lint:policy`, `pnpm api:check` |
| A slice re-exports only from its `index.ts`; its other modules import each name from the module that declares it. | Oxlint `policy/import-types-from-their-owner` | `pnpm lint:policy` |
| A slice re-exports only from its own `index.ts`, the one barrel it keeps; its other modules import each name from the module that declares it. | Oxlint `policy/reexport-only-from-index` | `pnpm lint:policy` |
| Procedures validate their input with Effect Schema. | Oxlint `policy/procedure-input-schema` | `pnpm lint:policy` |
| Procedures delegate to application logic. | Fallow `api-procedures` value-imports only `api-trpc`, `api-application` | `pnpm arch:gate` |
| Integrations import domain types only. | Fallow `api-integrations` allows `api-domain` through `allowTypeOnly` | `pnpm arch:gate`, `pnpm fallow:audit` |
Expand All @@ -157,7 +157,7 @@ each check's message names the fix.
| One React component per file. | Oxlint `policy/one-component-per-file` | `pnpm lint:policy` |
| State, server state and form state live in `use*` hooks. | Oxlint `policy/state-and-effects-in-hooks` | `pnpm lint:policy` |
| Forms validate with Effect Schema. | Oxlint `policy/form-uses-effect-schema` | `pnpm lint:policy` |
| Web code has the DOM and no Node; api code has no DOM and only erasable syntax; domain code has neither. | `tsconfig.json` (web, ui), `tsconfig.api.json` and `tsconfig.domain.json` over `tsconfig.base.json` | `pnpm typecheck` |
| Web code has the DOM and no Node; api code has no DOM and only erasable syntax; domain code has neither. Only tests see the Jest test globals. | `tsconfig.json` (web, ui), `tsconfig.api.json` and `tsconfig.domain.json` over `tsconfig.base.json`; `tsconfig.test.json` and `tsconfig.api.test.json` for tests | `pnpm typecheck` |
| Behaviour is defined by each result's E2E specs. | Playwright, one project per result | `pnpm e2e` |

Fallow loads [`contract.rules.jsonc`](../../tooling/architecture/contract.rules.jsonc)
Expand Down
8 changes: 4 additions & 4 deletions .agents/project/CONVENTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ The Oxlint rules and Biome naming override run on `{apps,packages}/*/src/**` and
| Functions defined inside a component start with `handle` (`handleAdd`). | Oxlint `policy/handler-names` |
| Callback props start with `on` (`onAdd`). | Oxlint `policy/callback-prop-names` |
| A hook returns one `status` union for its server state (`{ status: 'loading' } \| { status: 'failed' } \| { status: 'loaded'; todos }`), so the page renders exactly one state; it keeps a query's `data`, `isPending`, `isError` and `status` inside that union. | Oxlint `policy/one-status-from-hooks` ([ADR 0124](../decisions/0124-lint-the-patterns-agent-rebuilds-repeat.md)) |
| A test unwraps a value it expects with `present(value)`, which also takes an `{ ok, value }` outcome, so a missing value fails the test where it is read; `?? ''` and `x.ok ? x.value : ''` fail the gate. `present` is a Jest global, and an E2E spec imports it from `./fixtures`. | Oxlint `policy/test-unwraps-values` in unit tests and E2E specs ([ADR 0124](../decisions/0124-lint-the-patterns-agent-rebuilds-repeat.md)) |
| A test takes a value it expects with `present(value)`, which fails the test on `null` or `undefined`, and the value of an `{ ok, value }` outcome with `unwrap(outcome)`, which fails the test with the failure; `?? ''` and `x.ok ? x.value : ''` fail the gate. Both are Jest globals that only test files can see, and an E2E spec imports `present` from `./fixtures`. | Oxlint `policy/test-unwraps-values` in unit tests and E2E specs ([ADR 0124](../decisions/0124-lint-the-patterns-agent-rebuilds-repeat.md)) |
| A test imports a type its folder already exports (`import type { Todo } from './useTodos'`), so it follows the real shape. | Oxlint `policy/test-imports-the-type` |
| A message interpolates the limit constant it describes (`` `Use ${TITLE_MAX_LENGTH} characters or fewer` ``), so the text changes with the limit. | Oxlint `policy/message-uses-its-limit` for module constants of 10 or more |
| A module under `src/routes/` or `src/features/` imports a name straight from the module that declares it; a slice re-exports only from its `index.ts`. | Oxlint `policy/import-types-from-their-owner` |
| A failure reaches the place that shows it (`onError`, a `failure` state) and the promise keeps its rejection; `.catch(() => undefined)` and `.then(ok, () => false)` fail the gate. | Oxlint `policy/keep-rejections` |
| A message interpolates the limit constant it describes (`` `Use ${TITLE_MAX_LENGTH} characters or fewer` ``), so the text changes with the limit. | Oxlint `policy/message-uses-its-limit` for module constants of 10 or more named as a limit (`MAX`, `MIN`, `LIMIT`, `LENGTH`), written as a count (`100 characters`) outside JSX attributes |
| A module under `src/routes/` or `src/features/` imports a name straight from the module that declares it; a slice re-exports only from its own `index.ts`, and a nested `components/index.ts` re-exports nothing. | Oxlint `policy/reexport-only-from-index` |
| A failure reaches the place that shows it (`onError`, a `failure` state) and the promise keeps its rejection; `.catch(() => undefined)` and `.then(ok, () => false)` fail the gate. To ignore a failure on purpose, settle the promise with `Promise.allSettled` and read its result (`void Promise.allSettled([prefetch()])`). | Oxlint `policy/keep-rejections` ([ADR 0124](../decisions/0124-lint-the-patterns-agent-rebuilds-repeat.md)) |
| Page components (`<Name>Page`) live in `src/routes/<route-name>/`. | Oxlint `policy/pages-in-routes`, Fallow `web-routes` zone |
| Each file under `src/routes/` or `src/features/` sits in a slice folder, and a slice imports no sibling slice. | Oxlint `policy/slice-isolation` for static relative module references; Fallow child zones for `apps/web` routes. Computed specifiers and non-relative aliases remain a gap in the Oxlint rule. |
| A relative import stays inside its package; other packages are imported by name (`@repo/ui`). | Oxlint `policy/slice-isolation` |
Expand Down
2 changes: 1 addition & 1 deletion .agents/project/PR_QUALITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A change is done when every checklist item holds and deterministic evidence veri
- [ ] Installs stay stable. `pnpm check:lockfile` passes fresh installation and addition of two showcase importers without unrelated lockfile drift.
- [ ] Behaviour is specified. New or changed behaviour is covered by a spec in the result's `web/e2e/` folder (the behaviour map), such as `apps/web/e2e/todos.spec.ts`. The product's contract is explicit.
- [ ] Logic is unit-tested. Domain, application and procedures have `api` Jest tests; hooks and pages have `web` Jest tests that render through `TestApiProvider`. Coverage stays at/above the threshold in `jest.config.ts` (80%).
- [ ] Types check. `pnpm typecheck` passes its four programs, `tsconfig.json` (web and ui), `tsconfig.node.json` (configs and e2e), `tsconfig.api.json` (api) and `tsconfig.domain.json` (api domain, no Node), with no `any` and no weakened config.
- [ ] Types check. `pnpm typecheck` passes its six programs, `tsconfig.json` (web and ui), `tsconfig.node.json` (configs and e2e), `tsconfig.api.json` (api), `tsconfig.domain.json` (api domain, no Node), and `tsconfig.test.json` and `tsconfig.api.test.json` (tests), with no `any` and no weakened config.
- [ ] Lint + format clean. `pnpm check` (Biome), `pnpm lint:policy` (Oxlint), `pnpm lint:anti-slop` (Oxlint anti-slop rules), and `pnpm react-doctor` pass; every disabled rule carries a written reason.
- [ ] Code intelligence clean. `pnpm fallow:audit` reports no dead code, circular dependency, complexity, architecture or `contract/<id>` finding in any file the change touches.
- [ ] Architecture checks pass. `pnpm arch:check` passes: every file sits in a role, no forbidden import, every result passes the structure check, `docs/architecture/roles.mmd` and each result's `architecture.mmd` match `pnpm arch:diagram`, and every package's `etc/*.api.md` matches the code (`pnpm api:report` after an intended export change).
Expand Down
8 changes: 5 additions & 3 deletions .agents/project/QUALITY_GATES.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ See [ADR 0028](../decisions/0028-pre-push-runs-the-full-local-gate-suite.md).
- React Doctor (`pnpm react-doctor`) owns the project-level checks the
per-file plugins leave out, such as duplicated JSX across files.
- TypeScript owns type semantics; `pnpm typecheck` checks them with the pinned
Bun's `bun check` ([ADR 0120](../decisions/0120-bun-checks-types.md)) over four programs:
Bun's `bun check` ([ADR 0120](../decisions/0120-bun-checks-types.md)) over six programs:
`tsconfig.json` (web packages and `packages/ui`, with the DOM and no Node
types), `tsconfig.node.json` (root configs, Vite configs and e2e specs, on
Node), `tsconfig.api.json` (api packages, `NodeNext`, `.ts` import
extensions, `erasableSyntaxOnly`, no DOM) and `tsconfig.domain.json` (api
domain modules without Node types). All extend `tsconfig.base.json`.
extensions, `erasableSyntaxOnly`, no DOM), `tsconfig.domain.json` (api
domain modules without Node types), and `tsconfig.test.json` and
`tsconfig.api.test.json` (the web and api tests, which alone see the Jest
test globals `present` and `unwrap`). All extend `tsconfig.base.json`.
See [ADR 0034](../decisions/0034-trial-harness-and-evidence.md) for the
program boundaries and their limits.
- Jest + React Testing Library own component, hook and api behaviour in
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/features/todos/application.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ it('marks, renames and deletes a to-do in place', async () => {
addTodo({ title: 'First' });
const added = addTodo({ title: 'Second' });
addTodo({ title: 'Third' });
const { id } = present(added);
const { id } = unwrap(added);

expect(setTodoDone({ id, done: true })).toEqual({
ok: true,
Expand Down Expand Up @@ -68,7 +68,7 @@ it('answers not found for an unknown id', async () => {

it('clears the done to-dos and returns their ids', async () => {
const { addTodo, clearDoneTodos, listTodos, setTodoDone } = await application();
const ids = ['First', 'Second', 'Third'].map((title) => present(addTodo({ title })).id);
const ids = ['First', 'Second', 'Third'].map((title) => unwrap(addTodo({ title })).id);
setTodoDone({ id: present(ids[0]), done: true });
setTodoDone({ id: present(ids[2]), done: true });

Expand Down
2 changes: 1 addition & 1 deletion oxlint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export default {
'policy/test-unwraps-values': 'error',
'policy/test-imports-the-type': 'error',
'policy/message-uses-its-limit': 'error',
'policy/import-types-from-their-owner': 'error',
'policy/reexport-only-from-index': 'error',
'policy/keep-rejections': 'error',
'max-depth': ['error', 4],
'no-restricted-imports': [
Expand Down
Loading
Loading