@roomi-fields/grillhouse 0.50.3 → 0.52.0

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 (150) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +68 -0
  3. package/agents/developpeur.md +1 -1
  4. package/agents/direct.md +1 -1
  5. package/agents/explorateur.md +1 -1
  6. package/agents/questionneur.md +1 -1
  7. package/agents/relecteur.md +1 -1
  8. package/agents/testwriter.md +1 -1
  9. package/cadre/templates/c/package.json +1 -0
  10. package/cadre/templates/cargo/package.json +1 -0
  11. package/cadre/templates/python/package.json +1 -0
  12. package/charte/plan.md +47 -0
  13. package/charte/preuve.md +39 -0
  14. package/charte/superviseur.md +61 -0
  15. package/charte/tests.md +38 -0
  16. package/charte.md +39 -189
  17. package/dist/machine/part-par-sorte.d.ts +16 -0
  18. package/dist/machine/part-par-sorte.js +36 -0
  19. package/dist/machine/part-par-sorte.js.map +1 -0
  20. package/dist/temporal/circuit/appel.js +1 -1
  21. package/dist/temporal/circuit/appel.js.map +1 -1
  22. package/dist/temporal/circuit/client.d.ts +4 -4
  23. package/dist/temporal/circuit/client.js +38 -16
  24. package/dist/temporal/circuit/client.js.map +1 -1
  25. package/dist/temporal/circuit/contrat.d.ts +11 -7
  26. package/dist/temporal/circuit/contrat.js +5 -9
  27. package/dist/temporal/circuit/contrat.js.map +1 -1
  28. package/dist/temporal/circuit/deroule.js +18 -6
  29. package/dist/temporal/circuit/deroule.js.map +1 -1
  30. package/dist/temporal/commande.js +12 -3
  31. package/dist/temporal/commande.js.map +1 -1
  32. package/dist/temporal/installation.d.ts +54 -3
  33. package/dist/temporal/installation.js +187 -17
  34. package/dist/temporal/installation.js.map +1 -1
  35. package/dist/temporal/places/client.d.ts +5 -1
  36. package/dist/temporal/places/client.js +23 -11
  37. package/dist/temporal/places/client.js.map +1 -1
  38. package/docs/ARCHITECTURE.md +23 -2700
  39. package/docs/INTERFACE.md +26 -10
  40. package/docs/architecture/circuit.md +61 -14
  41. package/docs/architecture/entree.md +21 -8
  42. package/docs/architecture/greffon.md +49 -20
  43. package/docs/architecture/installation.md +46 -17
  44. package/docs/architecture/machine.md +79 -39
  45. package/docs/architecture/tests.md +59 -16
  46. package/docs/lexique.md +163 -0
  47. package/hooks/hooks.json +0 -10
  48. package/hooks/register.tsx +92 -4
  49. package/package.json +2 -1
  50. package/scripts/activites.mjs +105 -65
  51. package/scripts/aiguillage.mjs +15 -8
  52. package/scripts/attente-au-tour.mjs +2 -3
  53. package/scripts/attente-de-la-machine.mjs +4 -8
  54. package/scripts/avancement.mjs +12 -8
  55. package/scripts/bilan.mjs +126 -63
  56. package/scripts/bilans-gardes.mjs +37 -0
  57. package/scripts/branche-de-nuit.mjs +2 -2
  58. package/scripts/ci-de-main.mjs +18 -21
  59. package/scripts/circuit.mjs +89 -44
  60. package/scripts/circuits-du-serveur.mjs +5 -5
  61. package/scripts/composants-affectes.mjs +30 -12
  62. package/scripts/composition-des-langages.mjs +5 -3
  63. package/scripts/conformite.mjs +1 -1
  64. package/scripts/consommation-des-passes.mjs +8 -6
  65. package/scripts/copies-finies.mjs +3 -14
  66. package/scripts/depart-du-ticket.d.mts +8 -2
  67. package/scripts/depart-du-ticket.mjs +26 -8
  68. package/scripts/direct.mjs +158 -72
  69. package/scripts/droits.mjs +165 -208
  70. package/scripts/engendres.mjs +3 -14
  71. package/scripts/entree-de-seance.mjs +35 -0
  72. package/scripts/enveloppe/enveloppe.mjs +98 -46
  73. package/scripts/enveloppe/lancer.sh +90 -66
  74. package/scripts/enveloppe/paquets-du-plan.mjs +38 -11
  75. package/scripts/enveloppe/travail-de-la-copie.mjs +192 -3
  76. package/scripts/etapes.mjs +84 -22
  77. package/scripts/faits-du-circuit.mjs +8 -2
  78. package/scripts/grillhouse-maj.mjs +43 -18
  79. package/scripts/groupe-cles.d.mts +15 -0
  80. package/scripts/groupe-cles.mjs +77 -2
  81. package/scripts/init.mjs +9 -2
  82. package/scripts/integration/rejeu.mjs +8 -1
  83. package/scripts/jointure.d.ts +24 -4
  84. package/scripts/langages/c/index.mjs +5 -2
  85. package/scripts/langages/cargo/commandes.mjs +35 -15
  86. package/scripts/langages/cargo/composants.mjs +45 -3
  87. package/scripts/langages/cargo/index.mjs +6 -3
  88. package/scripts/langages/python/commandes.mjs +50 -7
  89. package/scripts/langages/python/index.mjs +5 -2
  90. package/scripts/langages/python/squelette.mjs +2 -1
  91. package/scripts/langages/typescript/chemins-des-tests.mjs +1 -1
  92. package/scripts/langages/typescript/index.mjs +16 -14
  93. package/scripts/langages/typescript/mise-a-jour.mjs +1 -1
  94. package/scripts/langages/typescript/rapports-aux-lignes.mjs +74 -0
  95. package/scripts/langages/typescript/turbo-des-paquets.mjs +151 -38
  96. package/scripts/langages/typescript/verdict.mjs +29 -3
  97. package/scripts/langages/typescript/verifier.mjs +28 -3
  98. package/scripts/langages/typescript/vitest-config/changements.mjs +8 -6
  99. package/scripts/langages/typescript/vitest-config/lances.mjs +15 -32
  100. package/scripts/langages.mjs +54 -4
  101. package/scripts/matieres-lues.mjs +1 -1
  102. package/scripts/mesure/base-de-passe.mjs +32 -90
  103. package/scripts/migrations/serveurs-de-l-index.mjs +79 -0
  104. package/scripts/migrations/suivi-du-superviseur-retire.mjs +56 -0
  105. package/scripts/migrations.mjs +23 -7
  106. package/scripts/nuit.sh +3 -2
  107. package/scripts/paquet.mjs +1 -1
  108. package/scripts/paquets.d.ts +3 -0
  109. package/scripts/paquets.mjs +88 -1
  110. package/scripts/passe-de-la-machine.mjs +109 -36
  111. package/scripts/places-de-la-machine.mjs +81 -29
  112. package/scripts/plafond-de-la-machine.d.mts +2 -5
  113. package/scripts/plafond-de-la-machine.mjs +9 -9
  114. package/scripts/reprise.mjs +42 -13
  115. package/scripts/resultats.mjs +78 -56
  116. package/scripts/retirer-les-copies-finies.mjs +1 -1
  117. package/scripts/seances.mjs +471 -133
  118. package/scripts/services-du-noyau.mjs +9 -1
  119. package/scripts/session-start.sh +22 -7
  120. package/scripts/sortie-de-seance.mjs +70 -0
  121. package/scripts/sortie.mjs +37 -6
  122. package/scripts/sous-commandes.mjs +0 -3
  123. package/scripts/superviseur.mjs +400 -162
  124. package/scripts/tableau.mjs +188 -65
  125. package/scripts/transitions.d.mts +25 -2
  126. package/scripts/transitions.mjs +137 -29
  127. package/scripts/verrous/ecriture-hors-enveloppe.mjs +31 -9
  128. package/skills/codebase-design/DESIGN-IT-TWICE.md +1 -1
  129. package/skills/developpeur/SKILL.md +38 -15
  130. package/skills/direct/SKILL.md +29 -9
  131. package/skills/domain-modeling/GLOSSARY-FORMAT.md +9 -9
  132. package/skills/domain-modeling/SKILL.md +14 -12
  133. package/skills/explorateur/SKILL.md +32 -8
  134. package/skills/grill/SKILL.md +3 -2
  135. package/skills/pitmaster/SKILL.md +80 -50
  136. package/skills/pitmaster/references/cadre.md +1 -1
  137. package/skills/pitmaster/references/consigne-agent.md +12 -11
  138. package/skills/pitmaster/references/tour.md +6 -5
  139. package/skills/relecteur/SKILL.md +13 -6
  140. package/skills/systematic-debugging/SKILL.md +281 -0
  141. package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
  142. package/skills/systematic-debugging/condition-based-waiting.md +115 -0
  143. package/skills/systematic-debugging/defense-in-depth.md +122 -0
  144. package/skills/systematic-debugging/find-polluter.sh +72 -0
  145. package/skills/systematic-debugging/root-cause-tracing.md +169 -0
  146. package/skills/testwriter/SKILL.md +37 -31
  147. package/cadre/templates/projet/pitmaster/SUIVI.md +0 -22
  148. package/scripts/attente-a-l-arret.mjs +0 -114
  149. package/scripts/verrous/commande.mjs +0 -214
  150. package/scripts/verrous/verrou.mjs +0 -311
@@ -0,0 +1,115 @@
1
+ # Condition-Based Waiting
2
+
3
+ ## Overview
4
+
5
+ Flaky tests often guess at timing with arbitrary delays. This creates race conditions where tests pass on fast machines but fail under load or in CI.
6
+
7
+ **Core principle:** Wait for the actual condition you care about, not a guess about how long it takes.
8
+
9
+ ## When to Use
10
+
11
+ ```dot
12
+ digraph when_to_use {
13
+ "Test uses setTimeout/sleep?" [shape=diamond];
14
+ "Testing timing behavior?" [shape=diamond];
15
+ "Document WHY timeout needed" [shape=box];
16
+ "Use condition-based waiting" [shape=box];
17
+
18
+ "Test uses setTimeout/sleep?" -> "Testing timing behavior?" [label="yes"];
19
+ "Testing timing behavior?" -> "Document WHY timeout needed" [label="yes"];
20
+ "Testing timing behavior?" -> "Use condition-based waiting" [label="no"];
21
+ }
22
+ ```
23
+
24
+ **Use when:**
25
+ - Tests have arbitrary delays (`setTimeout`, `sleep`, `time.sleep()`)
26
+ - Tests are flaky (pass sometimes, fail under load)
27
+ - Tests timeout when run in parallel
28
+ - Waiting for async operations to complete
29
+
30
+ **Don't use when:**
31
+ - Testing actual timing behavior (debounce, throttle intervals)
32
+ - Always document WHY if using arbitrary timeout
33
+
34
+ ## Core Pattern
35
+
36
+ ```typescript
37
+ // ❌ BEFORE: Guessing at timing
38
+ await new Promise(r => setTimeout(r, 50));
39
+ const result = getResult();
40
+ expect(result).toBeDefined();
41
+
42
+ // ✅ AFTER: Waiting for condition
43
+ await waitFor(() => getResult() !== undefined);
44
+ const result = getResult();
45
+ expect(result).toBeDefined();
46
+ ```
47
+
48
+ ## Quick Patterns
49
+
50
+ | Scenario | Pattern |
51
+ |----------|---------|
52
+ | Wait for event | `waitFor(() => events.find(e => e.type === 'DONE'))` |
53
+ | Wait for state | `waitFor(() => machine.state === 'ready')` |
54
+ | Wait for count | `waitFor(() => items.length >= 5)` |
55
+ | Wait for file | `waitFor(() => fs.existsSync(path))` |
56
+ | Complex condition | `waitFor(() => obj.ready && obj.value > 10)` |
57
+
58
+ ## Implementation
59
+
60
+ Generic polling function:
61
+ ```typescript
62
+ async function waitFor<T>(
63
+ condition: () => T | undefined | null | false,
64
+ description: string,
65
+ timeoutMs = 5000
66
+ ): Promise<T> {
67
+ const startTime = Date.now();
68
+
69
+ while (true) {
70
+ const result = condition();
71
+ if (result) return result;
72
+
73
+ if (Date.now() - startTime > timeoutMs) {
74
+ throw new Error(`Timeout waiting for ${description} after ${timeoutMs}ms`);
75
+ }
76
+
77
+ await new Promise(r => setTimeout(r, 10)); // Poll every 10ms
78
+ }
79
+ }
80
+ ```
81
+
82
+ See `condition-based-waiting-example.ts` in this directory for complete implementation with domain-specific helpers (`waitForEvent`, `waitForEventCount`, `waitForEventMatch`) from actual debugging session.
83
+
84
+ ## Common Mistakes
85
+
86
+ **❌ Polling too fast:** `setTimeout(check, 1)` - wastes CPU
87
+ **✅ Fix:** Poll every 10ms
88
+
89
+ **❌ No timeout:** Loop forever if condition never met
90
+ **✅ Fix:** Always include timeout with clear error
91
+
92
+ **❌ Stale data:** Cache state before loop
93
+ **✅ Fix:** Call getter inside loop for fresh data
94
+
95
+ ## When Arbitrary Timeout IS Correct
96
+
97
+ ```typescript
98
+ // Tool ticks every 100ms - need 2 ticks to verify partial output
99
+ await waitForEvent(manager, 'TOOL_STARTED'); // First: wait for condition
100
+ await new Promise(r => setTimeout(r, 200)); // Then: wait for timed behavior
101
+ // 200ms = 2 ticks at 100ms intervals - documented and justified
102
+ ```
103
+
104
+ **Requirements:**
105
+ 1. First wait for triggering condition
106
+ 2. Based on known timing (not guessing)
107
+ 3. Comment explaining WHY
108
+
109
+ ## Real-World Impact
110
+
111
+ From debugging session (2025-10-03):
112
+ - Fixed 15 flaky tests across 3 files
113
+ - Pass rate: 60% → 100%
114
+ - Execution time: 40% faster
115
+ - No more race conditions
@@ -0,0 +1,122 @@
1
+ # Defense-in-Depth Validation
2
+
3
+ ## Overview
4
+
5
+ When you fix a bug caused by invalid data, adding validation at one place feels sufficient. But that single check can be bypassed by different code paths, refactoring, or mocks.
6
+
7
+ **Core principle:** Validate at EVERY layer data passes through. Make the bug structurally impossible.
8
+
9
+ ## Why Multiple Layers
10
+
11
+ Single validation: "We fixed the bug"
12
+ Multiple layers: "We made the bug impossible"
13
+
14
+ Different layers catch different cases:
15
+ - Entry validation catches most bugs
16
+ - Business logic catches edge cases
17
+ - Environment guards prevent context-specific dangers
18
+ - Debug logging helps when other layers fail
19
+
20
+ ## The Four Layers
21
+
22
+ ### Layer 1: Entry Point Validation
23
+ **Purpose:** Reject obviously invalid input at API boundary
24
+
25
+ ```typescript
26
+ function createProject(name: string, workingDirectory: string) {
27
+ if (!workingDirectory || workingDirectory.trim() === '') {
28
+ throw new Error('workingDirectory cannot be empty');
29
+ }
30
+ if (!existsSync(workingDirectory)) {
31
+ throw new Error(`workingDirectory does not exist: ${workingDirectory}`);
32
+ }
33
+ if (!statSync(workingDirectory).isDirectory()) {
34
+ throw new Error(`workingDirectory is not a directory: ${workingDirectory}`);
35
+ }
36
+ // ... proceed
37
+ }
38
+ ```
39
+
40
+ ### Layer 2: Business Logic Validation
41
+ **Purpose:** Ensure data makes sense for this operation
42
+
43
+ ```typescript
44
+ function initializeWorkspace(projectDir: string, sessionId: string) {
45
+ if (!projectDir) {
46
+ throw new Error('projectDir required for workspace initialization');
47
+ }
48
+ // ... proceed
49
+ }
50
+ ```
51
+
52
+ ### Layer 3: Environment Guards
53
+ **Purpose:** Prevent dangerous operations in specific contexts
54
+
55
+ ```typescript
56
+ async function gitInit(directory: string) {
57
+ // In tests, refuse git init outside temp directories
58
+ if (process.env.NODE_ENV === 'test') {
59
+ const normalized = normalize(resolve(directory));
60
+ const tmpDir = normalize(resolve(tmpdir()));
61
+
62
+ if (!normalized.startsWith(tmpDir)) {
63
+ throw new Error(
64
+ `Refusing git init outside temp dir during tests: ${directory}`
65
+ );
66
+ }
67
+ }
68
+ // ... proceed
69
+ }
70
+ ```
71
+
72
+ ### Layer 4: Debug Instrumentation
73
+ **Purpose:** Capture context for forensics
74
+
75
+ ```typescript
76
+ async function gitInit(directory: string) {
77
+ const stack = new Error().stack;
78
+ logger.debug('About to git init', {
79
+ directory,
80
+ cwd: process.cwd(),
81
+ stack,
82
+ });
83
+ // ... proceed
84
+ }
85
+ ```
86
+
87
+ ## Applying the Pattern
88
+
89
+ When you find a bug:
90
+
91
+ 1. **Trace the data flow** - Where does bad value originate? Where used?
92
+ 2. **Map all checkpoints** - List every point data passes through
93
+ 3. **Add validation at each layer** - Entry, business, environment, debug
94
+ 4. **Test each layer** - Try to bypass layer 1, verify layer 2 catches it
95
+
96
+ ## Example from Session
97
+
98
+ Bug: Empty `projectDir` caused `git init` in source code
99
+
100
+ **Data flow:**
101
+ 1. Test setup → empty string
102
+ 2. `Project.create(name, '')`
103
+ 3. `WorkspaceManager.createWorkspace('')`
104
+ 4. `git init` runs in `process.cwd()`
105
+
106
+ **Four layers added:**
107
+ - Layer 1: `Project.create()` validates not empty/exists/writable
108
+ - Layer 2: `WorkspaceManager` validates projectDir not empty
109
+ - Layer 3: `WorktreeManager` refuses git init outside tmpdir in tests
110
+ - Layer 4: Stack trace logging before git init
111
+
112
+ **Result:** All 1847 tests passed, bug impossible to reproduce
113
+
114
+ ## Key Insight
115
+
116
+ All four layers were necessary. During testing, each layer caught bugs the others missed:
117
+ - Different code paths bypassed entry validation
118
+ - Mocks bypassed business logic checks
119
+ - Edge cases on different platforms needed environment guards
120
+ - Debug logging identified structural misuse
121
+
122
+ **Don't stop at one validation point.** Add checks at every layer.
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env bash
2
+ # Bisection script to find which test creates unwanted files/state
3
+ # Usage: ./find-polluter.sh <file_or_dir_to_check> <test_pattern>
4
+ # Example: ./find-polluter.sh '.git' 'src/**/*.test.ts'
5
+
6
+ set -e
7
+
8
+ if [ $# -ne 2 ]; then
9
+ echo "Usage: $0 <file_to_check> <test_pattern>"
10
+ echo "Example: $0 '.git' 'src/**/*.test.ts'"
11
+ exit 1
12
+ fi
13
+
14
+ POLLUTION_CHECK="$1"
15
+ TEST_PATTERN="$2"
16
+
17
+ echo "🔍 Searching for test that creates: $POLLUTION_CHECK"
18
+ echo "Test pattern: $TEST_PATTERN"
19
+ echo ""
20
+
21
+ # Get list of test files (find . emits ./-prefixed paths, so accept the
22
+ # pattern written with or without a leading ./)
23
+ TEST_PATTERN="${TEST_PATTERN#./}"
24
+ # find -path can't match '**/' against zero directory levels, so a pattern
25
+ # like src/**/*.test.ts would skip src/top.test.ts; also try the pattern
26
+ # with '**/' collapsed to cover files directly under the base directory.
27
+ TEST_FILES=$(find . \( -path "./$TEST_PATTERN" -o -path "./${TEST_PATTERN//\*\*\//}" \) | sort -u)
28
+ if [ -z "$TEST_FILES" ]; then
29
+ TOTAL=0
30
+ else
31
+ TOTAL=$(printf '%s\n' "$TEST_FILES" | wc -l | tr -d ' ')
32
+ fi
33
+
34
+ echo "Found $TOTAL test files"
35
+ echo ""
36
+
37
+ COUNT=0
38
+ for TEST_FILE in $TEST_FILES; do
39
+ COUNT=$((COUNT + 1))
40
+
41
+ # Skip if pollution already exists
42
+ if [ -e "$POLLUTION_CHECK" ]; then
43
+ echo "⚠️ Pollution already exists before test $COUNT/$TOTAL"
44
+ echo " Skipping: $TEST_FILE"
45
+ continue
46
+ fi
47
+
48
+ echo "[$COUNT/$TOTAL] Testing: $TEST_FILE"
49
+
50
+ # Run the test
51
+ npm test "$TEST_FILE" > /dev/null 2>&1 || true
52
+
53
+ # Check if pollution appeared
54
+ if [ -e "$POLLUTION_CHECK" ]; then
55
+ echo ""
56
+ echo "🎯 FOUND POLLUTER!"
57
+ echo " Test: $TEST_FILE"
58
+ echo " Created: $POLLUTION_CHECK"
59
+ echo ""
60
+ echo "Pollution details:"
61
+ ls -la "$POLLUTION_CHECK"
62
+ echo ""
63
+ echo "To investigate:"
64
+ echo " npm test $TEST_FILE # Run just this test"
65
+ echo " cat $TEST_FILE # Review test code"
66
+ exit 1
67
+ fi
68
+ done
69
+
70
+ echo ""
71
+ echo "✅ No polluter found - all tests clean!"
72
+ exit 0
@@ -0,0 +1,169 @@
1
+ # Root Cause Tracing
2
+
3
+ ## Overview
4
+
5
+ Bugs often manifest deep in the call stack (git init in wrong directory, file created in wrong location, database opened with wrong path). Your instinct is to fix where the error appears, but that's treating a symptom.
6
+
7
+ **Core principle:** Trace backward through the call chain until you find the original trigger, then fix at the source.
8
+
9
+ ## When to Use
10
+
11
+ ```dot
12
+ digraph when_to_use {
13
+ "Bug appears deep in stack?" [shape=diamond];
14
+ "Can trace backwards?" [shape=diamond];
15
+ "Fix at symptom point" [shape=box];
16
+ "Trace to original trigger" [shape=box];
17
+ "BETTER: Also add defense-in-depth" [shape=box];
18
+
19
+ "Bug appears deep in stack?" -> "Can trace backwards?" [label="yes"];
20
+ "Can trace backwards?" -> "Trace to original trigger" [label="yes"];
21
+ "Can trace backwards?" -> "Fix at symptom point" [label="no - dead end"];
22
+ "Trace to original trigger" -> "BETTER: Also add defense-in-depth";
23
+ }
24
+ ```
25
+
26
+ **Use when:**
27
+ - Error happens deep in execution (not at entry point)
28
+ - Stack trace shows long call chain
29
+ - Unclear where invalid data originated
30
+ - Need to find which test/code triggers the problem
31
+
32
+ ## The Tracing Process
33
+
34
+ ### 1. Observe the Symptom
35
+ ```
36
+ Error: git init failed in ~/project/packages/core
37
+ ```
38
+
39
+ ### 2. Find Immediate Cause
40
+ **What code directly causes this?**
41
+ ```typescript
42
+ await execFileAsync('git', ['init'], { cwd: projectDir });
43
+ ```
44
+
45
+ ### 3. Ask: What Called This?
46
+ ```typescript
47
+ WorktreeManager.createSessionWorktree(projectDir, sessionId)
48
+ → called by Session.initializeWorkspace()
49
+ → called by Session.create()
50
+ → called by test at Project.create()
51
+ ```
52
+
53
+ ### 4. Keep Tracing Up
54
+ **What value was passed?**
55
+ - `projectDir = ''` (empty string!)
56
+ - Empty string as `cwd` resolves to `process.cwd()`
57
+ - That's the source code directory!
58
+
59
+ ### 5. Find Original Trigger
60
+ **Where did empty string come from?**
61
+ ```typescript
62
+ const context = setupCoreTest(); // Returns { tempDir: '' }
63
+ Project.create('name', context.tempDir); // Accessed before beforeEach!
64
+ ```
65
+
66
+ ## Adding Stack Traces
67
+
68
+ When you can't trace manually, add instrumentation:
69
+
70
+ ```typescript
71
+ // Before the problematic operation
72
+ async function gitInit(directory: string) {
73
+ const stack = new Error().stack;
74
+ console.error('DEBUG git init:', {
75
+ directory,
76
+ cwd: process.cwd(),
77
+ nodeEnv: process.env.NODE_ENV,
78
+ stack,
79
+ });
80
+
81
+ await execFileAsync('git', ['init'], { cwd: directory });
82
+ }
83
+ ```
84
+
85
+ **Critical:** Use `console.error()` in tests (not logger - may not show)
86
+
87
+ **Run and capture:**
88
+ ```bash
89
+ npm test 2>&1 | grep 'DEBUG git init'
90
+ ```
91
+
92
+ **Analyze stack traces:**
93
+ - Look for test file names
94
+ - Find the line number triggering the call
95
+ - Identify the pattern (same test? same parameter?)
96
+
97
+ ## Finding Which Test Causes Pollution
98
+
99
+ If something appears during tests but you don't know which test:
100
+
101
+ Use the bisection script `find-polluter.sh` in this directory:
102
+
103
+ ```bash
104
+ bash ./find-polluter.sh '.git' 'src/**/*.test.ts'
105
+ ```
106
+
107
+ Runs tests one-by-one, stops at first polluter. See script for usage.
108
+
109
+ ## Real Example: Empty projectDir
110
+
111
+ **Symptom:** `.git` created in `packages/core/` (source code)
112
+
113
+ **Trace chain:**
114
+ 1. `git init` runs in `process.cwd()` ← empty cwd parameter
115
+ 2. WorktreeManager called with empty projectDir
116
+ 3. Session.create() passed empty string
117
+ 4. Test accessed `context.tempDir` before beforeEach
118
+ 5. setupCoreTest() returns `{ tempDir: '' }` initially
119
+
120
+ **Root cause:** Top-level variable initialization accessing empty value
121
+
122
+ **Fix:** Made tempDir a getter that throws if accessed before beforeEach
123
+
124
+ **Also added defense-in-depth:**
125
+ - Layer 1: Project.create() validates directory
126
+ - Layer 2: WorkspaceManager validates not empty
127
+ - Layer 3: NODE_ENV guard refuses git init outside tmpdir
128
+ - Layer 4: Stack trace logging before git init
129
+
130
+ ## Key Principle
131
+
132
+ ```dot
133
+ digraph principle {
134
+ "Found immediate cause" [shape=ellipse];
135
+ "Can trace one level up?" [shape=diamond];
136
+ "Trace backwards" [shape=box];
137
+ "Is this the source?" [shape=diamond];
138
+ "Fix at source" [shape=box];
139
+ "Add validation at each layer" [shape=box];
140
+ "Bug impossible" [shape=doublecircle];
141
+ "NEVER fix just the symptom" [shape=octagon, style=filled, fillcolor=red, fontcolor=white];
142
+
143
+ "Found immediate cause" -> "Can trace one level up?";
144
+ "Can trace one level up?" -> "Trace backwards" [label="yes"];
145
+ "Can trace one level up?" -> "NEVER fix just the symptom" [label="no"];
146
+ "Trace backwards" -> "Is this the source?";
147
+ "Is this the source?" -> "Trace backwards" [label="no - keeps going"];
148
+ "Is this the source?" -> "Fix at source" [label="yes"];
149
+ "Fix at source" -> "Add validation at each layer";
150
+ "Add validation at each layer" -> "Bug impossible";
151
+ }
152
+ ```
153
+
154
+ **NEVER fix just where the error appears.** Trace back to find the original trigger.
155
+
156
+ ## Stack Trace Tips
157
+
158
+ **In tests:** Use `console.error()` not logger - logger may be suppressed
159
+ **Before operation:** Log before the dangerous operation, not after it fails
160
+ **Include context:** Directory, cwd, environment variables, timestamps
161
+ **Capture stack:** `new Error().stack` shows complete call chain
162
+
163
+ ## Real-World Impact
164
+
165
+ From debugging session (2025-10-03):
166
+ - Found root cause through 5-level trace
167
+ - Fixed at source (getter validation)
168
+ - Added 4 layers of defense
169
+ - 1847 tests passed, zero pollution
@@ -11,8 +11,8 @@ des fichiers de test et le paquet de la matière de test partagée (celui qui ex
11
11
  `./test-fixtures`), en entier, son `package.json` et ses `docs/` compris, et ce dont tes tests
12
12
  dépendent : les `devDependencies` du `package.json` d'un paquet du plan et `package-lock.json`, ou
13
13
  les tables `[dev-dependencies]` (et `[target.<cible>.dev-dependencies]`) du `Cargo.toml` d'un
14
- crate du plan et `Cargo.lock` ; un verrou refuse le reste, et tout autre changement d'un
15
- manifeste, chaque partie nommée. Tu écris le manifeste par Write ou Edit, que le verrou juge ;
14
+ crate du plan et `Cargo.lock`. Ton lot se juge à la fin de ta séance : tout autre fichier, et tout
15
+ autre changement d'un manifeste, te rendent l'étape, chaque fichier et chaque partie nommés ;
16
16
  `npm test` met `Cargo.lock` d'accord. Dans un projet cargo, chaque crate a un seul exécutable de
17
17
  tests par l'interface, `tests/it/main.rs` : un fichier de tests neuf est un module de `tests/it/`,
18
18
  que tu déclares dans `tests/it/main.rs` (`mod <fichier>;`), et ta fiche nomme ce fichier du
@@ -22,14 +22,14 @@ sous `tests/` (sa dette inscrite) reçoit tes fichiers neufs sous `tests/it/` ;
22
22
  leur module, sous `src/`, dans un fichier `tests.rs` ou un dossier `tests/`. Tu les déclares
23
23
  toi-même dans le fichier de code du module, par la ligne `#[cfg(test)] mod tests;`, sans quoi
24
24
  le test n'est jamais compilé ; un `#[cfg(test)] mod tests { … }` en ligne, tu le retires du
25
- fichier de code et le déplaces dans `tests.rs`. Le verrou te refuse tout autre changement d'un
26
- fichier de code, la partie nommée. Un test de nuit Rust est un module de `tests/it_nuit/`, un
25
+ fichier de code et le déplaces dans `tests.rs`. Tout autre changement d'un fichier de code te
26
+ rend l'étape, la partie nommée. Un test de nuit Rust est un module de `tests/it_nuit/`, un
27
27
  banc de temps un module de `tests/it_budget/`, chacun déclaré dans le `main.rs` de son dossier.
28
28
  La matière partagée est le crate dont le manifeste dit `[package.metadata.grillhouse] matiere = true`.
29
29
  Dans un paquet Python, tes tests sont les fichiers que pytest trouve, `test_*.py` ou `*_test.py`,
30
30
  un test de nuit `*_nuit_test.py` ; leurs aides vont dans `conftest.py` et sous `tests/`. Ce dont
31
31
  ils dépendent va dans le groupe `test` de `[dependency-groups]` du `pyproject.toml`, et
32
- `uv.lock` suit ; le verrou te refuse toute autre partie du `pyproject.toml`. Un dossier ou un
32
+ `uv.lock` suit ; toute autre partie du `pyproject.toml` que ton lot change te rend l'étape. Un dossier ou un
33
33
  fichier temporaire se crée par `tempfile` (`TemporaryDirectory`, `NamedTemporaryFile`), jamais
34
34
  par `mkdtemp` à la main : la passe échoue sur ce qu'un test laisse dans son dossier temporaire.
35
35
 
@@ -44,6 +44,12 @@ par `mkdtemp` à la main : la passe échoue sur ce qu'un test laisse dans son do
44
44
  3. Lis ce que publient les fournisseurs des paquets du plan : leur ligne et leurs éléments dans
45
45
  `docs/agents/index-des-interfaces.md`, puis la section d'un élément dans l'interface du
46
46
  fournisseur, et la ligne « Déclaré pour » de sa section « Consommateurs ».
47
+ 4. Lis le code que tes tests visent, **l'index d'abord** : avant toute recherche par le shell, tu
48
+ appelles `mcp__rtfm__rtfm_search` (`rtfm_search`, mode `hybrid`) pour le quoi, et
49
+ `mcp__rtfm__rtfm_expand` (`rtfm_expand`) lit en entier un résultat qu'elle rend ; l'appel se
50
+ cherche par `mcp__codegraph__codegraph_explore` (`codegraph_explore`), ou par
51
+ `codegraph explore <symboles>` ; le shell lit un fichier déjà nommé. Ainsi un test vise le code
52
+ tel qu'il est.
47
53
 
48
54
  ## Tes références, à lire au moment où elles servent
49
55
 
@@ -54,17 +60,13 @@ par `mkdtemp` à la main : la passe échoue sur ce qu'un test laisse dans son do
54
60
 
55
61
  ## Tes outils
56
62
 
57
- **Un fichier s'écrit par l'outil Write ou Edit**, que ton verrou juge : jamais par un script
58
- (python3, sed -i, perl -i) ni par une redirection du shell, que ta séance refuse ; un fichier
59
- temporaire va dans `$TMPDIR`. Un fichier de tes tests se supprime par un script node que tu écris
63
+ **Tu prends l'outil que ton travail demande** : Write ou Edit, un script (python3, sed -i), une
64
+ redirection du shell, le client d'une base. Une substitution par script vérifie qu'elle a trouvé
65
+ son texte : `sed` qui ne trouve rien réussit sans rien changer. Un fichier temporaire va dans
66
+ `$TMPDIR`. Un fichier de tes tests se supprime par un script node que tu écris
60
67
  dans `$TMPDIR` : il appelle `rmSync` de `node:fs` sur le chemin nommé et lu, et tu le lances par
61
68
  `node $TMPDIR/<script>.mjs`. Les tests se lancent par `npm test -- <chemins>`, jamais par l'outil
62
- de test directement. Ainsi chaque écriture passe par le verrou de ton rôle.
63
-
64
- **L'index d'abord** : toute recherche commence par `rtfm_search` (mode `hybrid`) pour le quoi, et
65
- `rtfm_expand` lit en entier un résultat qu'elle rend ; l'appel se cherche par
66
- `codegraph explore <symboles>`, ou l'outil `codegraph_explore` ; le shell lit un fichier déjà
67
- nommé. Ainsi un test vise le code tel qu'il est.
69
+ de test directement. Ainsi ton lot ne porte que ce que ton rôle écrit.
68
70
 
69
71
  **Tu attends au premier plan ce que tu lances** : ta séance n'a aucune tâche de fond, et elle finit
70
72
  avec ta fiche. Ainsi le circuit reprend dès ta fiche rendue.
@@ -108,7 +110,7 @@ qu'il rend, sans simuler ce que le composant fait lui-même. Ainsi ils restent v
108
110
  change de forme.
109
111
 
110
112
  **La plus petite taille qui prouve** : la taille d'un test — petit, moyen, grand — est une décision
111
- d'architecture, que le plan du ticket fixe (charte, « La taille d'un test suit la pyramide »). Par
113
+ d'architecture, que le plan du ticket fixe (charte, module `preuve`, « La taille d'un test suit la pyramide »). Par
112
114
  défaut, chaque critère se prouve **petit** : un test qui appelle son module par son interface, dans
113
115
  son processus, sans rien lancer. Le plan ne nomme que l'exception, avec sa raison : **moyen** (une
114
116
  couture entre quelques modules que le petit n'atteint pas, avec des processus locaux) ou **grand**
@@ -166,17 +168,19 @@ tous les paquets du plan, et écrit au ticket les rouges, les verts non nommés
166
168
  relecteur lit) et les tests nommés encore verts, qui sont un défaut : il te relance. Un test nommé
167
169
  que HEAD tient déjà vert sous le même nom n'a rien à prouver. Les fichiers de ton lot que joue la
168
170
  seule nuit (un test de nuit, un banc, un témoin de temps) sont mis de côté : ils ne sont ni exigés
169
- rouges ni cause de refus. Sous un plan « comportement changé », la preuve passe avec au moins un
170
- rouge ; sans rouge, la question monte au superviseur. Ainsi la
171
+ rouges ni cause de refus. Sous un plan « comportement changé », quand la preuve joue des
172
+ fichiers de ton lot, elle passe avec au moins un rouge du lot (dans un fichier que le lot change, ou
173
+ un test que ta fiche nomme) ou une construction rouge : des rouges existants seuls la refusent. Une
174
+ preuve refusée te relance deux fois, puis la question monte au superviseur. Ainsi la
171
175
  preuve mesure le travail du ticket, et aucun test ne rougit pour la forme.
172
176
 
173
- **Un rouge existant suffit** : sans fichier de ton lot, la preuve joue en entier les paquets du
174
- plan ; un test que HEAD tient et que le lot rougit (un lecteur dont le fournisseur a changé un
175
- type) est un rouge de la preuve, `rouge existant`, qui lance le développeur. Quand ces rouges
176
- couvrent les critères du ticket, tu n'écris aucun test neuf et ta passation le dit.
177
- Sans fichier de ton lot ni rouge, la preuve échoue, sauf quand les seuls fichiers de test de ton
178
- lot sont ceux que joue la nuit : elle passe. Ainsi le développeur du lecteur est lancé sur
179
- ce que le lot casse.
177
+ **Un rouge existant suffit** : sans fichier de ton lot que la preuve joue, elle joue en entier les
178
+ paquets du plan ; un test que HEAD tient et que le lot rougit (un lecteur dont le fournisseur a
179
+ changé un type) est un rouge de la preuve, `rouge existant`, qui lance le développeur. Quand ces
180
+ rouges couvrent les critères du ticket, tu n'écris aucun test neuf et ta passation le dit.
181
+ Sans fichier de ton lot que la preuve joue ni rouge, elle échoue, sauf quand les seuls fichiers de
182
+ test de ton lot sont ceux que joue la nuit : elle passe. Ainsi le développeur du lecteur est lancé
183
+ sur ce que le lot casse.
180
184
 
181
185
  **Un fichier entier se nomme sans `test`** : `portent_le_travail` porte `fichier` (depuis la
182
186
  racine du dépôt) et, facultatif, `test` (son nom complet tel que le rapport de la preuve l'écrit,
@@ -208,7 +212,7 @@ de npm.
208
212
 
209
213
  **Ce que tes tests lisent se nomme ou se déclare** : un test qui lance un script de son paquet,
210
214
  ou en lit un fichier, écrit son chemin entier dans une chaîne
211
- (`const SCRIPT = path.resolve(__dirname, '../scripts/verrous/verrou.mjs')`), et le cadre le
215
+ (`const SCRIPT = path.resolve(__dirname, '../scripts/droits.mjs')`), et le cadre le
212
216
  rejoue quand ce script, ou ce qu'il importe, change ; un chemin construit à l'exécution
213
217
  (`path.join(SCRIPTS, nom)`) est refusé par la garde des chemins des tests. Un test qui lit un
214
218
  fichier hors de son paquet et de ses imports (des scènes, des paires de la matière, la trace d'un
@@ -240,7 +244,7 @@ gardes, un plafond). Un critère qui porte sur cette matière est prouvé par sa
240
244
  au circuit ; tu écris le test du comportement du ticket, jamais un double de ce qu'une référence
241
245
  tient. Ainsi une seule chose prouve chaque fait, et le relecteur n'a pas un doublon à retirer.
242
246
 
243
- **Une mesure de temps joue la nuit** (la charte commune) : un test dont le verdict dépend d'une
247
+ **Une mesure de temps joue la nuit** (charte, module `tests`) : un test dont le verdict dépend d'une
244
248
  durée (une attente bornée, un écart de temps comparé à un seuil) s'écrit dans un banc, un fichier
245
249
  `*.budget.test.ts` (en Rust, un module de `tests/it_budget/`), ou dans un témoin de temps, un fichier à
246
250
  lui, sans test ordinaire à côté, où sa mesure s'enveloppe dans `mesurerAuRepos(ctx, () => …)`,
@@ -274,11 +278,13 @@ tests arrivent au dépôt avec le code qui les rend verts.
274
278
  **Ta séance finit sur ta fiche**, que ton schéma décrit et que le circuit lit seule :
275
279
 
276
280
  - `statut` FAIT : tes tests sont écrits, et la preuve du rouge les juge ;
277
- - `statut` BLOQUÉ, avec sa `raison` : ce qui reste est hors de ta portée (un fichier hors du
278
- plan, une décision hors de ton rôle) ; hors des paquets du plan et de la matière de test
279
- partagée, la copie est en lecture seule, ton verrou arrête ta séance sur une écriture hors du
280
- plan, et ta `raison` nomme le paquet qui possède le fichier ;
281
- - `statut` BESOIN, avec sa `question` : une réponse te manque pour avancer ;
281
+ - `statut` BLOQUÉ, avec sa `raison` : ce qui reste est hors de ta portée (une décision hors de
282
+ ton rôle) ;
283
+ - `statut` BESOIN, avec sa `question` : une réponse te manque pour avancer ; hors des paquets du
284
+ plan et de la matière de test partagée, la copie est en lecture seule, une écriture y échoue
285
+ (« Read-only file system »), ta `question` nomme le paquet qui possède le fichier et ton champ
286
+ `manque` le fichier : un fichier que le ticket nomme, ou un fichier de test d'un paquet lecteur,
287
+ étend le plan et ta séance reprend ;
282
288
  - `motif` `aucun-comportement`, sur BESOIN ou BLOQUÉ : aucun comportement n'est à tester, aucun
283
289
  test honnête (qui échoue avant le lot et passe après) ne peut rougir ; ta question le dit et
284
290
  propose au superviseur `--mecanique [<commande>]` (avec une commande vers 1.1, sans elle vers le
@@ -1,22 +0,0 @@
1
- # Suivi de la supervision
2
-
3
- Tenu par la compétence `pitmaster`. Une question s'écrit ici dès qu'elle naît ; tranchée, elle en
4
- sort et sa réponse va dans son ticket.
5
-
6
- ## Dernier tour
7
-
8
- - Date : aucun tour encore
9
- - Agents lancés : aucun
10
- - À vérifier au prochain tour : rien
11
-
12
- ## R — à confirmer par le responsable
13
-
14
- Chaque point : contexte, exemple, règle, recommandation, question, ticket.
15
-
16
- ## S — à surveiller
17
-
18
- Chaque point : ce qui se surveille, ce qui le fermera.
19
-
20
- ## F — fermés
21
-
22
- Chaque point : ce qui l'a fermé, le ticket.