graph-test
Skill1 starsChanged 4 months agoMITView on GitHub
Derive and audit tests from the project's domain graph (.graph/world.yaml): turn every business rule into guard tests (in-bound, out-of-bound, bypass), every event into state-transition tests, every temporal relationship into history-preservation tests — and measure coverage by rules covered, not lines. Use this skill whenever the user asks to write tests, add test coverage, check whether tests are sufficient, audit coverage before a release, or says "补测 试", "测试够不够", "写单元测试", "test coverage", "add tests", "帮我把测试补 上", "上线前检查测试". Completes the loop with graph-engineering (builds the graph) and graph-review (reviews diffs against it): review is the probabilistic defense of the rules, tests are the deterministic one. Works without a graph too (falls back to risk-based test writing).
In this repository2 other files it gives its agents.
- graph-engineeringSkill
- graph-reviewSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 3 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 30
Read .graph/world.yaml. No graph → write a one-line note, fall back to ordinary risk-based test writing (happy path, boundaries, error …
- Very specific: line 33
Read the existing test suite.
- Very specific: line 51
Read references/derivation-patterns.md for worked code examples of each pattern.
- Very specific: line 61
Temporal relationship → history-preservation test: After the ending/superseding operation: old fact still queryable with a closed valid_to, …
- Very specific: line 73
Write assertions against observable behavior (state, events, errors) — not implementation details — so refactors don't break rule tests.
- Distinctive: line 89
Run the full suite; everything green before reporting.
- Distinctive: line 101
After graph-review flags "rule has no test pointing at it" → this skill closes it.
- Distinctive: line 103
After graph-engineering adds a rule via the six questions → the same change set should add its guard tests.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Graph-Driven Testing
<!-- 中文注释:核心思想 —— 测试是规则的确定性防线。review 抓"这次改动
删了守卫"是概率性的;一条规则只有被一个"删掉守卫就会红"的测试盯着,
才算真正被保护。覆盖率按规则算,不按行算。 -->A rule in world.yaml is only protected when a test exists that FAILS if the
rule's enforcement is removed. Line coverage cannot tell you this; a suite can
touch every line of refund.py and still pass when the approval guard is
deleted. This skill measures and closes that gap.
Step 1 — Build the rule-coverage matrix
- Read
.graph/world.yaml. No graph → write a one-line note, fall back to ordinary risk-based test writing (happy path, boundaries, error paths for the code in question), skip the graph-specific steps. - Read the existing test suite. Map every rule, temporal relationship, and
event to the tests that exercise it (match by behavior, not by name — a test
asserting a 200-amount refund goes to pending-approval covers
refund-capwhatever it's called). - Produce the matrix before writing anything new:
rule/node | enforcing code | guarding tests | status
refund-cap | payments.py:process_refund | (none) | UNGUARDED
escrow-release-window | payments.py:release_payment | (none) | UNGUARDED
guardian-of (temporal) | guardian.py:end_guardianship| (none) | UNGUARDEDRules with no enforcing code at all are not a testing problem — report them as drift and stop there (that's graph-review/graph-engineering territory).
Step 2 — Derive tests by node type
Read references/derivation-patterns.md for worked code examples of each
pattern. The shapes:
Rule → three guard tests. (1) In-bound: just inside the limit, effect happens. (2) Out-of-bound: just outside, effect blocked/rerouted — test the exact boundary value, off-by-one lives there. (3) Bypass: every OTHER code path that reaches the guarded effect also hits the guard — new endpoints, batch paths, admin paths. Bypass tests are what catch tomorrow's shadow feature reusing today's weakened internals.
Temporal relationship → history-preservation test. After the
ending/superseding operation: old fact still queryable with a closed
valid_to, nothing hard-deleted, and "was X true at time T" still answerable.
Event → state-transition tests. Legal transition works; illegal ones (wrong pre-state, out-of-window, double-fire) are rejected. Test transitions, not internals.
Capability → happy path + permission. One end-to-end success per
capability; if guarded_by is non-empty, at least one test that an
unauthorized/unqualified caller is refused.
Write assertions against observable behavior (state, events, errors) — not
implementation details — so refactors don't break rule tests. Name tests so
the matrix stays auditable: test_rule_refund_cap_boundary, etc.
Step 3 — Prove the guards (the step everyone skips)
A new guard test is only trusted after it has been seen to fail. For each rule:
temporarily weaken the enforcement (comment out the guard branch, or flip the
boundary), run the suite, confirm the new test goes red, restore the code,
confirm green. Do this at least for every blocker-grade rule. A guard test
that stays green when the guard is gone is decoration — this mutation check is
cheap here and is exactly the scenario the test exists for (a future diff
deleting the guard).
Step 4 — Run and report
Run the full suite; everything green before reporting. Report:
- The updated matrix — every rule now GUARDED or explicitly listed as not coverable and why.
- Rule coverage: N/M rules guarded (this number, not line coverage, is the headline).
- Which guards were mutation-proven.
- Drift found (rules with no enforcing code), handed off rather than tested around.
Working with the companion skills
- After graph-review flags "rule has no test pointing at it" → this skill closes it.
- After graph-engineering adds a rule via the six questions → the same change set should add its guard tests; suggest that wiring when you see rules added without tests.
- CI order: structural graph validation → test suite. Both must pass.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

