You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/copilot-instructions.md
+34-24Lines changed: 34 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,28 @@ are relevant. Only then report completion and wait for feedback.
13
13
checkpoints") before presenting it. Do NOT proceed to implementation until
14
14
the plan has been seen and explicitly approved.
15
15
16
+
**Store plans in PLAN.md**: Always write plans to `PLAN.md` in the repository
17
+
root so that context survives session boundaries. Update (not append to) the
18
+
file when the plan evolves. This is the single source of truth for what is
19
+
planned and what has been completed.
20
+
21
+
**Baseline the checkout before starting work**: Before beginning implementation
22
+
of any plan, verify that the current checkout builds and passes tests. Run the
23
+
build and test suite (per `.github/skills/building_and_testing.md`) and record the
24
+
results. If the baseline is broken, report the failures and stop — do not start
25
+
implementation on a broken base. Pre-existing failures that are not caused by
26
+
your changes must be acknowledged upfront so they are not confused with
27
+
regressions introduced by the plan. This establishes the ground truth against
28
+
which your changes will be measured.
29
+
30
+
**Every plan step must have a test gate**: Each step in a plan must produce
31
+
a testable result — a test, a build check, or a verifiable property — that
32
+
acts as the gate to the next step. Do not move to step N+1 until step N's
33
+
gate passes. This catches integration issues incrementally rather than
34
+
deferring all testing to the end. When writing a plan, structure it so that
35
+
independently testable components are implemented and verified first, and
36
+
later steps build on proven foundations.
37
+
16
38
**Mandatory review checkpoints**: At each of these points, run the full
17
39
review loop — spawn a fresh-context reviewer subagent, address findings,
18
40
spawn another fresh reviewer, repeat until a reviewer finds no issues. When
@@ -101,31 +123,19 @@ as a collaborator.
101
123
102
124
-**Fix what your change makes stale** - When a change invalidates something elsewhere — a comment, a test description, documentation — fix it in the same PR. Stale artefacts left behind are bugs in the making, and "I didn't modify that line" isn't an excuse when your change is what made it wrong.
103
125
104
-
## Testing
105
-
106
-
- Run `func-malloc-fast` and `func-jemalloc-fast` to catch allocation edge cases
107
-
- The `-check` variants include assertions but may pass when `-fast` hangs due to timing differences
108
-
- Use `timeout` when running tests to avoid infinite hangs
109
-
- Before considering a change complete, run the full test suite: `ctest --output-on-failure -j 4 -C Release --timeout 60`
110
-
111
-
### Test library (`snmalloc_testlib`)
112
-
113
-
Tests that only use the public allocator API can link against a pre-compiled static library (`snmalloc-testlib-{fast,check}`) instead of compiling the full allocator in each TU.
114
-
115
-
-**Header**: `test/snmalloc_testlib.h` — forward-declares the API surface; does NOT include any snmalloc headers. Tests that also need snmalloc internals (sizeclasses, pointer math, etc.) include `<snmalloc/snmalloc_core.h>` or `<snmalloc/pal/pal.h>` alongside it.
116
-
-**CMake**: Add the test name to `LIBRARY_FUNC_TESTS` or `LIBRARY_PERF_TESTS` in `CMakeLists.txt`.
117
-
-**Apply broadly**: When adding new API to testlib (e.g., `ScopedAllocHandle`), immediately audit all remaining non-library tests to see which ones can now be migrated. Don't wait for CI to find them one by one.
118
-
-**Cannot migrate**: Tests that use custom `Config` types, `Pool<T>`, override machinery, internal data structures (freelists, MPSC queues), or the statically-sized `alloc<size>()` template with many size values genuinely need `snmalloc.h`.
126
+
-**Document the code, not the change** - Comments and documentation describe how the code IS, not how it was changed or why it differs from a previous version. Don't leave comments explaining "we removed X" or "this was changed from Y" — a reader shouldn't need the git history to understand the code. If code needs context about alternatives or design decisions, put that in design docs, not inline comments.
119
127
120
-
## Build
128
+
## Building, Testing, and Benchmarking
121
129
122
-
- Build directory: `build/`
123
-
- Build system: Ninja with CMake
124
-
- Rebuild all targets before running ctest: `ninja -C build` (required - ctest runs pre-built binaries)
125
-
- Rebuild specific targets: `ninja -C build <target>`
126
-
- Always run `clang-format` before committing changes: `ninja -C build clangformat`
130
+
All build, test, and benchmarking guidance lives in `.github/skills/building_and_testing.md`.
127
131
128
-
## Benchmarking
132
+
**Delegate testing to a subagent.** When it is time to build and run tests,
133
+
spawn a subagent whose prompt includes the contents of
134
+
`.github/skills/building_and_testing.md` and tells it which tests to run (or "run the
135
+
full suite"). Do NOT include implementation context — the subagent must not
136
+
know what code changed. This prevents the tester from rationalising failures
137
+
as related to the changes instead of reporting them objectively.
129
138
130
-
- Before benchmarking, verify Release build: `grep CMAKE_BUILD_TYPE build/CMakeCache.txt` should show `Release`
131
-
- Debug builds have assertions enabled and will give misleading performance numbers
139
+
The subagent will report back: which tests passed, which failed, exact
140
+
commands, and full output of any failures. If failures are reported, treat
141
+
them as actionable per the failure protocol in the skill file.
This file is the complete reference for building and testing snmalloc.
4
+
It is designed to be used by a subagent that has NO context about what
5
+
code changes were made — only that it needs to build and verify the
6
+
project. This isolation is intentional: test results must be interpreted
7
+
without bias from knowing what changed.
8
+
9
+
## Build
10
+
11
+
- Build directory: `build/`
12
+
- Build system: Ninja with CMake
13
+
-**Always test with a Debug build.** Debug enables assertions (`-check` variants) that catch invariant violations invisible in Release. A Release-only test run can report 100% pass while masking real bugs. Verify with `grep CMAKE_BUILD_TYPE build/CMakeCache.txt` — it must show `Debug`.
14
+
- Rebuild all targets before running ctest: `ninja -C build` (required — ctest runs pre-built binaries)
15
+
- Rebuild specific targets: `ninja -C build <target>`
16
+
- Always run `clang-format` before committing changes: `ninja -C build clangformat`
17
+
18
+
## Testing
19
+
20
+
- Run `func-malloc-fast` and `func-jemalloc-fast` to catch allocation edge cases
21
+
- The `-check` variants include assertions but may pass when `-fast` hangs due to timing differences
22
+
- Use `timeout` when running tests to avoid infinite hangs
23
+
- Never run a test on a stale build artifact. Rebuild in the same build directory/config before any run or rerun: `ninja -C <build_dir>` for `ctest` runs, or `ninja -C <build_dir> <target>` if you invoke a direct binary. If the rebuild fails, stop and report with the rebuild log.
24
+
- Testing skill: keep commands stable (right build dir/config, consistent flags), prefer `ctest -R <name> --output-on-failure`, and avoid ad-hoc command variants that change coverage or filters.
25
+
- Before considering a change complete, run the full test suite: `ctest --output-on-failure -j 4 --timeout 60`
26
+
27
+
### Test failures (never hand-wave)
28
+
29
+
- Never describe a failure as transient without evidence. Treat every failure as actionable until disproven.
30
+
- After a rebuild (per the testing rule above) succeeds, rerun the exact failing command twice: Rerun #1 must match the original command (including filters/flags such as `-R`, `-j`, `--timeout`); Rerun #2 may add only `--output-on-failure` if it was missing. No other changes to flags or filters between reruns.
31
+
- Required logging bundle for any failure or flake claim: rebuild command plus stdout/stderr; original failing command plus stdout/stderr; both rerun commands plus stdout/stderr; commit/branch; build directory and config (Release/Debug); compiler/toolchain; host OS; env vars/options affecting the run (allocator config, sanitizers, thread count); note if Rerun #2 added `--output-on-failure`.
32
+
- Workflow: record failing command/output → rebuild in the same build directory (stop/report if rebuild fails) → two reruns as above → capture all logs/context → check CI status and origin/main baseline → only label a flake with evidence. Report flakes or unresolved failures in a PR comment with logs and CI links.
33
+
34
+
### Test library (`snmalloc_testlib`)
35
+
36
+
Tests that only use the public allocator API can link against a pre-compiled static library (`snmalloc-testlib-{fast,check}`) instead of compiling the full allocator in each TU.
37
+
38
+
-**Header**: `test/snmalloc_testlib.h` — forward-declares the API surface; does NOT include any snmalloc headers. Tests that also need snmalloc internals (sizeclasses, pointer math, etc.) include `<snmalloc/snmalloc_core.h>` or `<snmalloc/pal/pal.h>` alongside it.
39
+
-**CMake**: Add the test name to `LIBRARY_FUNC_TESTS` or `LIBRARY_PERF_TESTS` in `CMakeLists.txt`.
40
+
-**Apply broadly**: When adding new API to testlib (e.g., `ScopedAllocHandle`), immediately audit all remaining non-library tests to see which ones can now be migrated. Don't wait for CI to find them one by one.
41
+
-**Cannot migrate**: Tests that use custom `Config` types, `Pool<T>`, override machinery, internal data structures (freelists, MPSC queues), or the statically-sized `alloc<size>()` template with many size values genuinely need `snmalloc.h`.
42
+
43
+
## Benchmarking
44
+
45
+
- Before benchmarking, verify Release build: `grep CMAKE_BUILD_TYPE build/CMakeCache.txt` should show `Release`
46
+
- Debug builds have assertions enabled and will give misleading performance numbers
47
+
48
+
## Subagent protocol
49
+
50
+
When you are invoked as a testing subagent:
51
+
52
+
1.**Read this file first.** It is your only reference for how to build and test.
53
+
2.**You have no knowledge of what changed.** Do not ask. Do not speculate. Report only what you observe.
54
+
3.**Rebuild before testing.** Always run `ninja -C build` before any test invocation. If the rebuild fails, report the failure and stop.
55
+
4.**Run the requested tests** (or the full suite if not specified). Use the exact commands from this file.
56
+
5.**Report results factually**: which tests passed, which failed, the exact commands you ran, and the full output of any failures. Do not interpret failures in terms of code changes — you don't know what they are.
57
+
6.**Never label a failure as transient.** If a test fails, follow the failure protocol above (rebuild + two reruns + logging bundle). Report all evidence.
0 commit comments