aboutsummaryrefslogtreecommitdiff
path: root/.agents/skills/write-tests
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-11-13 17:04:55 +0100
committerFelix Morgner <felix.morgner@ost.ch>2026-11-13 17:04:55 +0100
commit01805b0a7b78e4eed2c30f5c34e0044a0b240634 (patch)
tree51c4b83b67157542e99e9992e14d1df8cf1de806 /.agents/skills/write-tests
parent5d434c0103942ab66d3554d590d48fd0ad445858 (diff)
downloadkernel-01805b0a7b78e4eed2c30f5c34e0044a0b240634.tar.xz
kernel-01805b0a7b78e4eed2c30f5c34e0044a0b240634.zip
agents: implement basic rules and skills
Diffstat (limited to '.agents/skills/write-tests')
-rw-r--r--.agents/skills/write-tests/SKILL.md82
1 files changed, 82 insertions, 0 deletions
diff --git a/.agents/skills/write-tests/SKILL.md b/.agents/skills/write-tests/SKILL.md
new file mode 100644
index 00000000..5dcd2b99
--- /dev/null
+++ b/.agents/skills/write-tests/SKILL.md
@@ -0,0 +1,82 @@
+---
+name: write-tests
+description: Write or extend Catch2 host tests (BHT) for TeachOS when the user explicitly asks for tests, including regression tests that reproduce a bug and stress tests. If the user only asks what to test, answer in prose and use this skill only once they ask for the code. Never changes production code.
+---
+
+# Write tests
+
+## Hard limits
+
+- Write only to `**/*.tests.cpp`, `**/*.stress.cpp` and `**/test_support/**`.
+- Never edit production code.
+ That includes temporary edits to check that a test can fail, and includes making a type printable (see below).
+- No git commands that change state.
+- If a test needs a seam in production code (an injection point, an extracted function), stop and report what is needed and why.
+ Don't add it.
+
+## 1. Confirm the contract
+
+The interface under test must already exist (a header the human wrote, or a signature given in the request).
+If it does not, stop and propose cases in prose instead.
+State the source of the expected behavior: the header's docs, `docs/`, or the user's description.
+Derive cases from the contract, not from reading the implementation.
+If the contract is ambiguous, ask.
+
+## 2. Learn local conventions
+
+Read the neighbouring `*.tests.cpp` files and the `test_support/` of the library.
+Reuse what exists: simulated memory, the bump frame allocator, the log buffer, the VFS and ext2 fixtures, and the `kapi` fakes that stand in for the architecture layer.
+Add a new fake only if nothing fits.
+Keep it minimal, put it under `test_support/`, and say so in the report.
+
+## 3. Plan the cases
+
+List the cases in a few lines before writing: happy path, boundaries, error paths (assert the specific `kstd::errc` when the contract names one), and state transitions.
+If the request was broad, wait for a go-ahead.
+
+## 4. Write
+
+Match the neighbours:
+- `SCENARIO("<behavior in plain words>", "[layer][subsystem]")` with `GIVEN` / `WHEN` / `THEN`.
+ One assertion idea per `THEN`.
+- Tags are layer plus subsystem, as in `[kapi][devices]` or `[filesystem][path]`.
+ They become ctest labels, so don't invent new ones casually.
+- Include order follows the neighbours: unit header, kstd, Catch2, standard library.
+ Tests may use the full standard library.
+- `REQUIRE` when later steps depend on it, `CHECK` for independent assertions.
+- Deterministic only: no sleeps, no timing assumptions.
+ Concurrency goes in `*.stress.cpp` (ThreadSanitizer), bounded in run time.
+- To print a type in failures, add a `Catch::StringMaker` to the library's `test_support/string_makers.hpp`.
+ Never touch kernel code for that.
+- Binary assets (`*.img`) are out of scope.
+ Ask the human.
+- ASan, LSan and UBSan are on.
+ Tests must be clean.
+ Don't suppress reports.
+- Test files need no license header.
+ `REUSE.toml` covers them.
+
+## 5. Run
+
+New files are picked up by the next build.
+- `cmake --preset bht`, then `cmake --build --preset bht-dbg`
+- `ctest --preset bht-dbg --output-on-failure -R <name>` (or `-L <tag>`)
+- Concurrency: the `bht-stress` presets.
+
+If a test fails, decide which side is wrong.
+Test wrong: fix the test.
+Production wrong: stop, report the diagnosis with evidence, and leave the fix to the human.
+
+## 6. Check the tests can fail
+
+For each test, say which kind of bug it would catch.
+Reason about it; don't break production code to find out.
+
+## 7. Report
+
+Files touched.
+For each test, what it checks, in one line.
+The contract source.
+Cases deliberately not covered, and why.
+Seams you would need in production code.
+Anything you couldn't run. \ No newline at end of file