--- name: tenet-build description: "Test-first implementation inside a Tenet Copilot contract: write the red, make it green, keep the change small, declare every edit." --- # Build: test first, smallest change Use when `next` says `test` or `implement`. Edit natively; the kernel judges. ## The loop 1. **Red.** Write the acceptance test(s) for the new examples exactly as recorded, in the test file named. Expected values come from the example, never from running the code. Run `tenet check --h --stage baseline`. If a new interface needs a minimal stub in an existing file so the test compiles, add `--scaffold ` naming that file: it is allowed at baseline and the reviewer will see it. Stubs in new files need no declaration. It must fail on an assertion; a compile or import error, a skipped test or a passing test is not a red and the kernel says so. Fix the test, not the product code. 2. **Green.** Make the smallest in-scope change. Format with the project's formatter first. Iterate with `tenet check --h --targeted --touched `; finish an attempt with a full `tenet check --h --stage candidate --touched `. 3. **Refactor.** After green, if a change inside the scope removes complexity (a duplicate, a tangled branch, an unclear name), make it, then rerun the affected checks (`--targeted --touched `) and the full candidate check. If none removes complexity, skip it and say so. The kernel does not check that you looked for one. 4. **Then** follow `next`: review, or finish. A behavior-preserving refactor uses preservation tests that already pass; there is no artificial red. For nonbehavioral work, do not invent a test; state the alternative check in the basis and report its result. Keep README run instructions, decision records, the architecture doc and CHANGELOG current for the change before handover. Record only verified commands and outcomes; preserve decision history and disclose missing or unverified documentation. ## Practice - **Tests earn their place.** A test fails when the behavior breaks and keeps passing when only internals change. Where an absence check could pass vacuously, add a control that proves it detects presence. - **Debug the shared premise.** After a failed attempt, before the next edit, write down the premise your attempts shared and test it with one observation that would differ if it were false. Suspect the test, fixture or environment before the system. - **Fix where the fault starts.** A guard, retry, catch or clamp is a fix only when the state it handles is legitimate. Fix the same defect at its other sites in the change. - **Report surprises; never improvise.** When a fact invalidates the plan, the sketch or the authority, stop and say: Expected, Found, Why it matters. - **Flag, don't expand.** An improvement outside the scope is advisory: say "noticed, not changed"; never add it to scope or treat it as binding. Remove what your own change made unused; leave other dead code and mention it. - A shortcut (`@ts-ignore`, `as any`, a skipped or focused test, an empty catch, a mock) is avoided; if one is truly needed, say why and the kernel asks the user. - A locked acceptance test never changes to make a failure pass; a changed example is a change of direction. - Never edit `.tenet/`. Never run the project's tests outside `tenet check`. ## User-facing handover In Guided style, offer to start the local app through the host terminal under native consent, never through the kernel runner. Confirm the local URL responds before calling it running; report a failed launch or response without claiming success. Give the URL, where local-only development credentials are kept (never their values), how to stop the app, and one domain task showing a confirmed example. Keep verification databases separate from development data. A running demo is not test evidence. Send what you verified with `finish` as JSON stdin `{"demo": {"surface": "ui"|"use"|"internal", "basisHash": "", "commands": [{"kind": "package-script", "path": "package.json", "script": "dev"}], "steps": [{"exampleId": "", "instruction": "..."}], "screenshots": [{"exampleId": "", "path": ""}]}}`; report `data.demo` and its `unavailable` list as it is. For a library, CLI or back-end change with nothing to open, give a verified command or call as "Use it:" instead; omit this section of the result when nothing is user-facing. ## Dirty working trees Your edits and the user's coexist. Never overwrite, format or revert a file you did not declare. If the kernel asks about the user's edits, relay its question; do not decide for them. Commit only through the kernel.