@srobroek/pi-code-quality 0.0.0-stage → 0.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +191 -0
  2. package/LICENSE +202 -0
  3. package/README.md +150 -2
  4. package/agents/adversarial-challenger.md +29 -0
  5. package/extensions/quality.js +4583 -0
  6. package/package.json +40 -4
  7. package/skills/prototype-logic/LICENSE +21 -0
  8. package/skills/prototype-logic/NOTICE +26 -0
  9. package/skills/prototype-logic/SKILL.md +76 -0
  10. package/skills/quality-code-design/LICENSE-mattpocock-skills +21 -0
  11. package/skills/quality-code-design/NOTICE +63 -0
  12. package/skills/quality-code-design/SKILL.md +63 -0
  13. package/skills/quality-code-design/references/contracts.md +37 -0
  14. package/skills/quality-code-design/references/debugging.md +85 -0
  15. package/skills/quality-code-design/references/deep-modules.md +67 -0
  16. package/skills/quality-code-design/references/dependencies.md +81 -0
  17. package/skills/quality-code-design/references/encapsulation.md +148 -0
  18. package/skills/quality-code-design/references/feature-flags.md +189 -0
  19. package/skills/quality-code-design/references/go.md +110 -0
  20. package/skills/quality-code-design/references/lifecycle.md +66 -0
  21. package/skills/quality-code-design/references/middleware.md +55 -0
  22. package/skills/quality-code-design/references/other-paradigms.md +44 -0
  23. package/skills/quality-code-design/references/persistence.md +52 -0
  24. package/skills/quality-code-design/references/python.md +100 -0
  25. package/skills/quality-code-design/references/release.md +59 -0
  26. package/skills/quality-code-design/references/review.md +121 -0
  27. package/skills/quality-code-design/references/rust.md +140 -0
  28. package/skills/quality-code-design/references/safe-mutation.md +33 -0
  29. package/skills/quality-code-design/references/security.md +65 -0
  30. package/skills/quality-code-design/references/simplicity.md +165 -0
  31. package/skills/quality-code-design/references/solid.md +165 -0
  32. package/skills/quality-code-design/references/supporting-principles.md +78 -0
  33. package/skills/quality-code-design/references/telemetry.md +54 -0
  34. package/skills/quality-code-design/references/test-first.md +78 -0
  35. package/skills/quality-code-design/references/typescript.md +93 -0
  36. package/skills/quality-code-design/references/verification.md +53 -0
  37. package/skills/quality-code-policy/SKILL.md +34 -0
  38. package/skills/quality-profiling/SKILL.md +48 -0
  39. package/skills/quality-profiling/references/hygiene.md +27 -0
  40. package/skills/quality-profiling/references/reading-profiles.md +21 -0
  41. package/skills/quality-profiling/references/system.md +51 -0
  42. package/skills/quality-test-audit/SKILL.md +122 -0
  43. package/skills/quality-test-audit/references/catalog.md +108 -0
  44. package/skills/quality-test-audit/references/evidence.md +123 -0
  45. package/skills/quality-test-audit/references/report.md +75 -0
  46. package/skills/quality-testing/SKILL.md +62 -0
  47. package/skills/quality-testing/references/bad-tests.md +258 -0
  48. package/skills/quality-testing/references/doubles.md +49 -0
  49. package/skills/quality-testing/references/good-tests.md +90 -0
  50. package/skills/quality-testing/references/maintenance.md +96 -0
  51. package/skills/quality-testing/references/review-tests.md +72 -0
  52. package/skills/quality-testing/references/shared-contracts.md +30 -0
  53. package/skills/quality-testing/references/signals.md +50 -0
  54. package/skills/quality-testing/references/test-budget.md +81 -0
  55. package/skills/quality-testing/references/what-to-test.md +58 -0
@@ -0,0 +1,72 @@
1
+ # Reviewing test changes
2
+
3
+ Read when you review a diff or a pull request that touches code or tests, or before you
4
+ hand off your own change. Review the test diff against the code diff, not each one
5
+ alone.
6
+
7
+ ## Map test changes to code changes
8
+
9
+ Classify each code hunk, then look for the matching test change.
10
+
11
+ | Code change | Expect in the test diff | Flag |
12
+ | --- | --- | --- |
13
+ | New behavior | A test for each behavior, at the lowest level that catches the fault | A behavior with no test that would fail without it |
14
+ | Bug fix | A regression test that reproduces the bug | No regression test, or one that passes without the fix |
15
+ | Changed requirement | Updated expected values, and a stated requirement in the commit, pull request or spec | Expected values changed with no stated reason |
16
+ | Refactor that keeps behavior | No assertion changes; mechanical edits only | Rewritten assertions: the behavior changed, or the tests were coupled to structure |
17
+ | Removed behavior | Its tests, fixtures, helpers and snapshots deleted | Tests or fixtures left behind; a new test that only checks that the code is gone |
18
+ | Docs, config or formatting only | Nothing | Test edits with no reason |
19
+ | Test-only change | A named reason: a missing case, a flake fix, pruning | Deleted or weakened tests without a reason, or without a remaining test that gives the same protection |
20
+
21
+ ## Check each added or changed test
22
+
23
+ 1. It maps to a named behavior, requirement or bug.
24
+ 2. It goes through the public interface. It does not test private helpers, call order or
25
+ internal state.
26
+ 3. It tests one behavior with one logical outcome. Its inputs, action and expected
27
+ values are readable in the test body.
28
+ 4. Its expected values do not repeat the implementation and are not pasted output.
29
+ 5. It does not repeat an existing test. Cases with the same shape are parametrized.
30
+ 6. Doubles sit at boundaries. Nothing doubles the code under test. Interaction checks
31
+ appear only where the call is the behavior.
32
+ 7. It is deterministic: no sleeps, real clock, unseeded randomness or shared state.
33
+ 8. Snapshots are small, and the diff of each updated snapshot was reviewed.
34
+ 9. It is not on the "do not test" list in [what-to-test.md](what-to-test.md).
35
+ 10. It ran. A regression test failed before the fix. When you cannot run tests, name the
36
+ command for the author to run.
37
+
38
+ With access to the diff only, judge duplicates within the diff, and say what you could
39
+ not check.
40
+
41
+ ## Tampering
42
+
43
+ Tampering hides a behavior change or loses protection. Flag each of these when no
44
+ requirement states that the behavior changed:
45
+
46
+ - an assertion loosened, such as an exact value replaced by a not-null or a contains
47
+ check;
48
+ - an expected value edited to match the new output;
49
+ - a test skipped, deleted, or marked as an expected failure, with no remaining test that
50
+ gives its protection;
51
+ - a tolerance widened, a timeout raised, or a retry added;
52
+ - an exception handler that swallows a failure inside a test;
53
+ - a coverage exclusion added;
54
+ - many snapshots updated in one step without a reviewed diff.
55
+
56
+ Maintenance is not tampering. Pruning a duplicate that another test covers, deleting
57
+ the tests of removed behavior, and a quarantine with a tracked issue and a lane that
58
+ still runs the test are correct changes ([maintenance.md](maintenance.md)).
59
+
60
+ ## Severity
61
+
62
+ | Finding | Disposition |
63
+ | --- | --- |
64
+ | Tampering that hides a behavior change or loses protection | Blocking |
65
+ | Changed behavior or a bug fix with no test that fails without it, in code that has tests | Blocking |
66
+ | A new test that only checks that removed code, an export or a file is gone | Blocking |
67
+ | Tests or fixtures left behind for removed behavior | Non-blocking |
68
+ | Tests coupled to the implementation: private helpers, call order, internal mocks, an expected value that repeats the code | Non-blocking, unless the test cannot fail for the bug it claims to catch |
69
+ | Near-duplicate tests, copied cases, large snapshots | Non-blocking |
70
+
71
+ Map these dispositions to the review's own scale. Cite each finding at `path:line` with
72
+ the code hunk it fails to match. Examples of each kind are in [bad-tests.md](bad-tests.md).
@@ -0,0 +1,30 @@
1
+ # Shared contracts across languages
2
+
3
+ Read when two languages (or two processes) share a message contract: a host and its SDK, a server and a client in another language. The gates and tools are in `toolchain-api` ("Shared contract across languages", "JSON-RPC over stdio").
4
+
5
+ ## Rules
6
+
7
+ - **One schema, many consumers:** each language consumes the same generated schema files. A hand-copied schema is a second contract.
8
+ - **Pinned generator, regenerate and diff:** CI regenerates with the pinned generator and fails on any diff. A vendored copy is compared byte for byte with the source.
9
+ - **Shared conformance corpus:** valid and invalid messages, with the expected outcome, live beside the schemas. Each language runs the whole corpus against its own validator or codec. A language does not fork or filter the corpus; a fixture that only one language passes is checked against the specification first (see `doubles.md`).
10
+ - **Cross-language test per message type:** drive the real SDK of one language through the real host of the other, over the real transport. List the message types, and keep a test for each one, including its error replies.
11
+ - **Additive-only schema gate:** the schema diff gate in `toolchain-api` runs on the generated files, so a break fails before a consumer does.
12
+
13
+ ## Why
14
+
15
+ Each side's own tests pass against its own copy of the contract. Only a shared corpus and a test across the real boundary fail when the two sides disagree, and they fail before a release does.
16
+
17
+ ## Test shape
18
+
19
+ - Put the corpus in one directory with a manifest (`name`, `direction`, `message`, `expected`). The per-language runner reads the manifest; it holds no cases of its own.
20
+ - Keep expected outcomes in the corpus, worked out from the specification, never copied from one implementation's output.
21
+ - For a message type with several error replies, add one corpus entry per reply, not one parametrised case per language.
22
+ - Keep cross-language tests few and at the boundary; field-level rules are the corpus's job.
23
+
24
+ ## Review check
25
+
26
+ any of these: a schema copied rather than generated, a vendored copy with no byte check, a language skipping corpus entries, a message type with no cross-language test, expected outcomes recorded from an implementation.
27
+
28
+ ## Sources
29
+
30
+ - [JSON Schema specification](https://json-schema.org/specification), [JSON-RPC 2.0](https://www.jsonrpc.org/specification), [MCP conformance runner](https://github.com/modelcontextprotocol/conformance) (per-scenario wire-schema validation), [Buf breaking rules](https://buf.build/docs/breaking/) (the same idea for protobuf).
@@ -0,0 +1,50 @@
1
+ # Quality signals
2
+
3
+ Read when you use coverage, mutation testing, property tests or fuzzing to judge or
4
+ extend a suite. Pick the tool for each signal from the language's concerns table
5
+ (`coverage`, `mutation`, `property`, `fuzz`, `fuzz-continuous` and `flaky-order` rows), found
6
+ through the `toolchain-languages` skill's `references/concerns.md`; shared tools and report
7
+ formats are in its `references/shared-tools.md`. Detect a tool before use, and recommend
8
+ the install command and ask permission before you install it. Idioms are in the
9
+ `lang-<language>-testing` skill's `references/practice.md`.
10
+
11
+ | Signal | Shows | Does not show | Use |
12
+ | --- | --- | --- | --- |
13
+ | Line and branch coverage | Code that no test runs | That the code that runs is checked | Read uncovered branches for missing behaviors. It is not a number to raise |
14
+ | Changed-lines coverage | Lines in this diff that no test runs | Assertion strength | A hint in review, beside full-suite coverage |
15
+ | Mutation score | Whether tests fail when the code is changed on purpose | Which surviving mutants matter | Run it on critical logic, or on the diff of a pull request. A surviving mutant that changes behavior gets a test; an equivalent or irrelevant one does not |
16
+ | Flaky rate | Whether the suite can be trusted | The cause | Record every retry; fix or quarantine ([maintenance.md](maintenance.md)) |
17
+ | Suite runtime | Feedback speed | Value | Keep unit tests at milliseconds each |
18
+
19
+ - Never add assertion-free tests, or exclude code, to reach a coverage target. Do not
20
+ require 100% of any signal.
21
+ - Mutation testing is the stronger signal that tests detect wrong behavior. Coverage
22
+ only finds gaps.
23
+
24
+ ## Run cadence
25
+
26
+ - Mutation: diff-scoped on every pull request, blocking the merge only on the paths the
27
+ project names as critical and reporting elsewhere, plus a scheduled full run.
28
+ - Fuzzing: bounded in time or inputs on every pull request, plus scheduled long campaigns
29
+ that keep and grow the corpus.
30
+ - Flaky order: shuffled and repeated runs on a schedule, not on every pull request.
31
+
32
+ ## Property-based tests
33
+
34
+ Use them for invariants that hold over many inputs: round-trips
35
+ (`parse(print(x)) == x`), idempotence, ordering, conservation (a transfer keeps the
36
+ total), and "never crashes on any input" for parsers of untrusted data.
37
+
38
+ - One property replaces many example tests only when its oracle does not repeat the
39
+ implementation.
40
+ - Keep named examples for edge cases that the contract names.
41
+ - Keep a failing seed or a shrunk example as a regular example test.
42
+
43
+ ## Fuzzing
44
+
45
+ Fuzz parsers and decoders that read untrusted formats. Bound the fuzz time on pull requests and run long campaigns on a schedule. Keep
46
+ each minimized crashing input as a regression input.
47
+
48
+ Sources: [Software Engineering at Google, ch. 11](https://abseil.io/resources/swe-book/html/ch11.html),
49
+ [Are mutants a valid substitute for real faults?](https://doi.org/10.1145/2635868.2635929),
50
+ [Long-term effects of mutation testing at Google](https://research.google/pubs/long-term-effects-of-mutation-testing/).
@@ -0,0 +1,81 @@
1
+ # Test budget
2
+
3
+ Read when a behavior collects many tests, when an agent or a generator wrote the tests,
4
+ or when the suite grows faster than the code.
5
+
6
+ ## A budget per behavior
7
+
8
+ - Each behavior gets one canonical test, plus one test per boundary or error class that
9
+ can fail in a different way. There is no numeric cap: each extra test names the risk
10
+ that it protects and the other tests do not.
11
+ - Before you add a test, search the existing tests for the behavior. Extend a
12
+ parametrized case list, update the test that is there, or add nothing.
13
+ - Parametrize cases that share setup, action and assertion shape. Keep tests separate
14
+ when the setup or the assertion differs. A case list with mode flags and conditional
15
+ assertions is several tests in one.
16
+ - Delete a test when another test already gives its protection. Two tests that run the
17
+ same code are not always redundant: a library's contract test and a consumer's test
18
+ can cover the same lines for different reasons.
19
+
20
+ ## Signs of sprawl
21
+
22
+ - Many tests make the same claim, copied with different literals.
23
+ - Tests break on refactors that keep behavior.
24
+ - Large snapshots of incidental output.
25
+ - Mock setup longer than the test, or mocks of the module's own collaborators.
26
+ - The same scenario at the unit, integration and end-to-end level.
27
+ - Tests that run code but would not fail if it returned a wrong value. A mutation run
28
+ finds them ([signals.md](signals.md)).
29
+ - Hooks, flags or exports in production code that only tests use.
30
+
31
+ ## Tests from agents and generators
32
+
33
+ What studies of generated tests found:
34
+
35
+ - Meta's TestGen-LLM (FSE 2024) kept a generated test only when it built, passed five
36
+ repeated runs and raised line coverage. In its Instagram evaluation, 75% of test
37
+ classes got a candidate that built, 57% one that passed reliably and 25% one that
38
+ raised coverage. Engineers still rejected tests without assertions, tests of trivial
39
+ getters and tests of unimportant files.
40
+ - 47.4% of 194 Copilot-generated Python tests had at least one test smell (SBES 2024).
41
+ Duplicated assertions, empty tests, magic numbers, assertion roulette and calls to
42
+ APIs that do not exist recur in other studies.
43
+ - Coverage-driven generators can discard a failing test that reveals a real bug, and
44
+ keep a passing test that pins the bug (Waterloo preprint, 2024).
45
+
46
+ Rules for every test author, human or agent:
47
+
48
+ 1. Write the behavior list first. Each test maps to one item.
49
+ 2. Watch every new test fail for the expected reason. For a test of code that already
50
+ works, introduce a controlled fault and confirm that the test fails. Then restore the
51
+ code and check the restore with a diff (the `quality-code-design` skill's
52
+ `test-first.md`).
53
+ 3. Keep a test only when it protects a named behavior, passes on repeated runs and
54
+ fails for a plausible wrong implementation. The best evidence is a mutant that the
55
+ test kills and no other test kills. Added coverage supports a test; it is not the
56
+ reason to keep it.
57
+ 4. A failing generated test is a question about the requirement. Check it against the
58
+ requirement before you discard it or weaken it.
59
+ 5. Remove duplicates before hand-off. Report what each test protects, not how many tests
60
+ you added.
61
+
62
+ ## Test generators
63
+
64
+ TestGen-LLM and Cover-Agent add tests until coverage rises; they do not prune the
65
+ existing suite. Do not make a coverage-driven generator the default source of tests.
66
+
67
+ - Meta described TestGen-LLM in a paper. No public distribution of the tool was found
68
+ on 2026-11-12.
69
+ - Qodo's Cover-Agent (`qodo-cover`) README has said that the project is no longer
70
+ maintained since 2025-06-15. Its latest release is `0.3.10` (2025-05-21), and its
71
+ licence is AGPL-3.0.
72
+ - Apply the rules above to every generated test, whatever tool or agent wrote it.
73
+
74
+ Sources: [TestGen-LLM, arXiv 2402.09171](https://arxiv.org/abs/2402.09171),
75
+ [Copilot test smells, SBES 2024](https://sol.sbc.org.br/index.php/sbes/article/view/30398),
76
+ [Siddiq et al., EASE 2024](https://s2e-lab.github.io/preprints/ease24-preprint.pdf),
77
+ [Ouedraogo et al., arXiv 2407.00225](https://arxiv.org/html/2407.00225v4),
78
+ [Coverage-guided generators and bugs, arXiv 2412.14137](https://arxiv.org/html/2412.14137),
79
+ [qodo-cover README](https://github.com/qodo-ai/qodo-cover/blob/main/README.md#news),
80
+ [Canon TDD](https://newsletter.kentbeck.com/p/canon-tdd),
81
+ [The Practical Test Pyramid: avoid test duplication](https://martinfowler.com/articles/practical-test-pyramid.html#AvoidTestDuplication).
@@ -0,0 +1,58 @@
1
+ # What to test, and at which level
2
+
3
+ Read when you choose a test level, or decide whether something needs a test at all.
4
+
5
+ ## Levels
6
+
7
+ | Level | Exercises | Pays off for | Cost |
8
+ | --- | --- | --- | --- |
9
+ | Unit | One function or module, in process, no I/O | Domain rules, parsers, calculations, state machines | Milliseconds; survives internal refactors |
10
+ | Integration | Your code with a real dependency: database, filesystem, HTTP server, queue | Queries, transactions, serialization, framework configuration, adapter error mapping | Seconds; needs setup and isolation |
11
+ | End-to-end | The deployed or fully assembled system through its real entry point | A few critical user journeys and wiring | Slow and less reliable; keep the set small |
12
+
13
+ - Choose the smallest scope that can detect the fault. Pure policy belongs in unit tests.
14
+ SQL semantics, serialization, framework wiring and transport contracts need an
15
+ integration test against the real thing.
16
+ - Push logic out of adapters so that unit tests reach it. Give each adapter a few
17
+ integration tests: a real in-memory or container database with real migrations, a temp
18
+ directory, a local HTTP server.
19
+ - Do not fix a ratio between levels. The pyramid, the trophy and the honeycomb describe
20
+ particular architectures. Weigh speed, maintainability, resource use, reliability and
21
+ fidelity for each risk.
22
+ - Test one scenario at one level. Add a test at a second level only for a separate risk,
23
+ such as the wiring of a unit-tested rule into a handler, and do not repeat the cases
24
+ there.
25
+
26
+ ## What to cover
27
+
28
+ - The contract at the public boundary: inputs, outputs, errors, and the side effects that
29
+ callers rely on, such as a sent message or a written record.
30
+ - Size boundaries: empty, one, many. Number boundaries: zero, negative, maximum.
31
+ - Input boundaries: missing, malformed, duplicate, the first and the last element.
32
+ - Time zones and daylight saving time, where dates matter.
33
+ - The error paths that callers handle.
34
+ - The bug being fixed ([maintenance.md](maintenance.md)).
35
+
36
+ ## What not to test
37
+
38
+ | Do not test | Reason | Test instead, when it matters |
39
+ | --- | --- | --- |
40
+ | Getters, setters and constructors that only assign | No logic to break | The behavior that uses them |
41
+ | Private helpers, directly | A refactor breaks the test while behavior stays the same | The public behavior. A private part that needs its own tests is a module to extract |
42
+ | Call order and internal data layout | The test fails on harmless refactors | The outcome |
43
+ | Framework, library and generated code | Its authors test it | Your configuration of it, in an integration test |
44
+ | A constant or configuration value restated in the test | The test repeats the source and fails only when someone edits both | The behavior that the value drives |
45
+ | What the compiler or type checker proves: types, required fields, interface conformance | The build already fails | Runtime validation of untrusted input |
46
+ | That a function, export, module or file exists, or that it is gone | This checks structure, not behavior | A packaging or compatibility check at a public API boundary. For a capability that must stay off, the forbidden outcome, such as a 404 from a removed endpoint |
47
+ | Diagnostic log lines | The wording changes freely | For audit or security logs that are requirements: the record, not its format |
48
+ | The implementation's own computation as the expected value | The test passes with the same bug | An expected value worked out independently |
49
+
50
+ Packaging and API compatibility, audit logging, security exclusions and protocol
51
+ constants can be requirements. Then test the contract at the boundary where callers
52
+ observe it.
53
+
54
+ Sources: [The Practical Test Pyramid](https://martinfowler.com/articles/practical-test-pyramid.html),
55
+ [SMURF: beyond the test pyramid](https://testing.googleblog.com/2024/10/smurf-beyond-test-pyramid.html),
56
+ [Software Engineering at Google, ch. 12 and 14](https://abseil.io/resources/swe-book/html/ch12.html),
57
+ [Change-detector tests considered harmful](https://testing.googleblog.com/2015/01/testing-on-toilet-change-detector-tests.html),
58
+ [Khorikov: structural inspection](https://enterprisecraftsmanship.com/posts/structural-inspection/).