@rryando/arcs 4.0.0 → 4.2.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.
- package/README.md +18 -20
- package/dist/cli/arcs-flash.d.ts +1 -1
- package/dist/cli/arcs-flash.d.ts.map +1 -1
- package/dist/cli/arcs-flash.js +9 -50
- package/dist/cli/arcs-flash.js.map +1 -1
- package/dist/cli/arcs-orchestrate-caveman.d.ts +2 -2
- package/dist/cli/arcs-orchestrate-caveman.d.ts.map +1 -1
- package/dist/cli/arcs-orchestrate-caveman.js +2 -8
- package/dist/cli/arcs-orchestrate-caveman.js.map +1 -1
- package/dist/cli/arcs-orchestrate.d.ts +1 -1
- package/dist/cli/arcs-orchestrate.d.ts.map +1 -1
- package/dist/cli/arcs-orchestrate.js +4 -54
- package/dist/cli/arcs-orchestrate.js.map +1 -1
- package/dist/cli/orchestrator-shared-blocks.d.ts +10 -30
- package/dist/cli/orchestrator-shared-blocks.d.ts.map +1 -1
- package/dist/cli/orchestrator-shared-blocks.js +46 -128
- package/dist/cli/orchestrator-shared-blocks.js.map +1 -1
- package/dist/utils/claude-code-hook-install.d.ts.map +1 -1
- package/dist/utils/claude-code-hook-install.js +3 -2
- package/dist/utils/claude-code-hook-install.js.map +1 -1
- package/dist/utils/diagram-generator.d.ts.map +1 -1
- package/dist/utils/diagram-generator.js +11 -6
- package/dist/utils/diagram-generator.js.map +1 -1
- package/dist/utils/hook-token-store.d.ts +5 -3
- package/dist/utils/hook-token-store.d.ts.map +1 -1
- package/dist/utils/hook-token-store.js +5 -3
- package/dist/utils/hook-token-store.js.map +1 -1
- package/dist/utils/session-store.d.ts +9 -57
- package/dist/utils/session-store.d.ts.map +1 -1
- package/dist/utils/session-store.js +19 -92
- package/dist/utils/session-store.js.map +1 -1
- package/dist/utils/storage-utils.d.ts +1 -1
- package/dist/utils/storage-utils.d.ts.map +1 -1
- package/dist/utils/storage-utils.js +1 -1
- package/dist/utils/storage-utils.js.map +1 -1
- package/dist/web-client/assets/{GraphCanvas-CTyf_XXQ.js → GraphCanvas-BPDgvsyT.js} +1 -1
- package/dist/web-client/assets/{MarkdownEditor-af2vwQOX.js → MarkdownEditor-D7TLp78z.js} +1 -1
- package/dist/web-client/assets/{abnfDiagram-VRR7QNED-CdxcKX9t.js → abnfDiagram-VRR7QNED-CyuP2N9t.js} +1 -1
- package/dist/web-client/assets/architecture-TIHT7OUA-Bdo2Yvm9.js +1 -0
- package/dist/web-client/assets/{architectureDiagram-ZJ3FMSHR-DOISDv6o.js → architectureDiagram-ZJ3FMSHR-DZ0ul9QX.js} +1 -1
- package/dist/web-client/assets/{blockDiagram-677ZJIJ3-DKwtbttM.js → blockDiagram-677ZJIJ3-LLGzlc9l.js} +1 -1
- package/dist/web-client/assets/{c4Diagram-LMCZKHZV-CilqK-Mm.js → c4Diagram-LMCZKHZV-CViu3CTc.js} +1 -1
- package/dist/web-client/assets/channel-DBNmizpo.js +1 -0
- package/dist/web-client/assets/{chunk-32BRIVSS-C79m1mkG.js → chunk-32BRIVSS-Bw_IuJCM.js} +1 -1
- package/dist/web-client/assets/{chunk-52WLFC77-C6WelGWJ.js → chunk-52WLFC77-C29h440W.js} +1 -1
- package/dist/web-client/assets/{chunk-C7G6YPKG-DLg7ryWI.js → chunk-C7G6YPKG-hhOrvw5w.js} +1 -1
- package/dist/web-client/assets/{chunk-EX3LRPZG-DjWgo4gL.js → chunk-EX3LRPZG-COMzol-M.js} +1 -1
- package/dist/web-client/assets/{chunk-FWX5IMBZ-BgS9p_zy.js → chunk-FWX5IMBZ-6vdX9EUn.js} +2 -2
- package/dist/web-client/assets/{chunk-HOUHSVGY-DuVR7dZO.js → chunk-HOUHSVGY-DWDW6sxp.js} +1 -1
- package/dist/web-client/assets/{chunk-ICXQ74PX-Y8DlnIJM.js → chunk-ICXQ74PX-BdMYglo2.js} +1 -1
- package/dist/web-client/assets/{chunk-MOJQB5TN-BEM3QgeD.js → chunk-MOJQB5TN-C0LAX_dC.js} +1 -1
- package/dist/web-client/assets/{chunk-OGEWGWER-DlM8LxGr.js → chunk-OGEWGWER-CBx8MB7f.js} +1 -1
- package/dist/web-client/assets/{chunk-PUDLZKDR-c6cqNVTx.js → chunk-PUDLZKDR-DKssR1nf.js} +1 -1
- package/dist/web-client/assets/{chunk-Q4XR5HBZ-C5lNmcka.js → chunk-Q4XR5HBZ-B3kcxFE-.js} +1 -1
- package/dist/web-client/assets/{chunk-V7JOEXUC-nSswxvSG.js → chunk-V7JOEXUC-CAlymndy.js} +1 -1
- package/dist/web-client/assets/{chunk-VAUOI2AC-CqJkCkT0.js → chunk-VAUOI2AC-BowfsmTW.js} +1 -1
- package/dist/web-client/assets/{chunk-VR4S4FIN-D3pFchin.js → chunk-VR4S4FIN-BBOydgvt.js} +1 -1
- package/dist/web-client/assets/{chunk-WYO6CB5R-BI9c-NzI.js → chunk-WYO6CB5R-DcymFbES.js} +1 -1
- package/dist/web-client/assets/{chunk-ZGVPDNZ5-CKTF2kLR.js → chunk-ZGVPDNZ5--uKFP-Lr.js} +1 -1
- package/dist/web-client/assets/classDiagram-OUVF2IWQ-CB3HiA1_.js +1 -0
- package/dist/web-client/assets/classDiagram-v2-EOCWNBFH-CB3HiA1_.js +1 -0
- package/dist/web-client/assets/{cynefin-VYW2F7L2-BrJrnfh1.js → cynefin-VYW2F7L2-CjboUOMA.js} +1 -1
- package/dist/web-client/assets/{cynefinDiagram-TSTJHNR4-9jYzPWJZ.js → cynefinDiagram-TSTJHNR4-BcxygBP7.js} +1 -1
- package/dist/web-client/assets/{dagre-VKFMJZFB-B705Djpu.js → dagre-VKFMJZFB-D-tiERQE.js} +1 -1
- package/dist/web-client/assets/{diagram-FQU43EPY-BfQAlUlJ.js → diagram-FQU43EPY-ChPXczaS.js} +1 -1
- package/dist/web-client/assets/{diagram-G47NLZAW-s1YDe06A.js → diagram-G47NLZAW-CVL3Y91h.js} +1 -1
- package/dist/web-client/assets/{diagram-NH7WQ7WH-Dy3z11Hc.js → diagram-NH7WQ7WH-DsaNA9Lh.js} +1 -1
- package/dist/web-client/assets/{diagram-OA4YK3LP-Bius2xUN.js → diagram-OA4YK3LP-CXhrhdhU.js} +1 -1
- package/dist/web-client/assets/{diagram-WEI45ONY-D7x4VcHM.js → diagram-WEI45ONY-BTVPnk4E.js} +1 -1
- package/dist/web-client/assets/{ebnfDiagram-CCIWWBDH-CBg1xrmD.js → ebnfDiagram-CCIWWBDH-BAyrRBtM.js} +1 -1
- package/dist/web-client/assets/{erDiagram-Q63AITRT-CJRvTFvd.js → erDiagram-Q63AITRT-Qm24Wepm.js} +1 -1
- package/dist/web-client/assets/eventmodeling-45OFAUF4-DoTBIvl5.js +1 -0
- package/dist/web-client/assets/flowDiagram-23GEKE2U-BEH23L1A.js +1 -0
- package/dist/web-client/assets/{ganttDiagram-NO4QXBWP-C_LsypZ4.js → ganttDiagram-NO4QXBWP-D8h7l3XJ.js} +1 -1
- package/dist/web-client/assets/{gitGraph-TEB2WS4Q-Dx2XxdGk.js → gitGraph-TEB2WS4Q-DIBml1SB.js} +1 -1
- package/dist/web-client/assets/{gitGraphDiagram-IHSO6WYX-DiKWkGWQ.js → gitGraphDiagram-IHSO6WYX-CtkYoXjn.js} +1 -1
- package/dist/web-client/assets/{index-CYwhkPtc.js → index-DOSH4Q9H.js} +38 -38
- package/dist/web-client/assets/{info-DKCQHKI2-DORwHenK.js → info-DKCQHKI2-DLEUtV5Q.js} +1 -1
- package/dist/web-client/assets/{infoDiagram-FWYZ7A6U-CQecXS1E.js → infoDiagram-FWYZ7A6U-BJQ7aQux.js} +1 -1
- package/dist/web-client/assets/{ishikawaDiagram-FXEZZL3T-CWhj60Zp.js → ishikawaDiagram-FXEZZL3T-BPM11FvG.js} +1 -1
- package/dist/web-client/assets/{journeyDiagram-5HDEW3XC-Cj3z2U8u.js → journeyDiagram-5HDEW3XC-C0aX2z3c.js} +1 -1
- package/dist/web-client/assets/{kanban-definition-HUTT4EX6-DFmBRenP.js → kanban-definition-HUTT4EX6-C56F29Ib.js} +1 -1
- package/dist/web-client/assets/{line-C_Hxz9xb.js → line-BLFHLF2N.js} +1 -1
- package/dist/web-client/assets/{mermaid-parser.core-E3xRdzPn.js → mermaid-parser.core-BLC8FhgU.js} +3 -3
- package/dist/web-client/assets/{mermaid.core-C2_CcotH.js → mermaid.core-BBqkKuXt.js} +3 -3
- package/dist/web-client/assets/{mindmap-definition-LN4V7U3C-Bs7VxPid.js → mindmap-definition-LN4V7U3C-aVZbsoPc.js} +1 -1
- package/dist/web-client/assets/{packet-7NZHBO7P-D2nqso7i.js → packet-7NZHBO7P-D4aqSQfB.js} +1 -1
- package/dist/web-client/assets/{pegDiagram-2B236MQR-Cepo1sIu.js → pegDiagram-2B236MQR-DjfyNI0U.js} +1 -1
- package/dist/web-client/assets/{pie-RZYD4A2V-Sx0IGbXt.js → pie-RZYD4A2V-ChCwYsYj.js} +1 -1
- package/dist/web-client/assets/{pieDiagram-ENE6RG2P-D-PMDNhk.js → pieDiagram-ENE6RG2P-BeHLKkXC.js} +1 -1
- package/dist/web-client/assets/{quadrantDiagram-ABIIQ3AL-BNGC7Fms.js → quadrantDiagram-ABIIQ3AL-stga3gvq.js} +1 -1
- package/dist/web-client/assets/{radar-I7S5WNFK-CFf_-2OC.js → radar-I7S5WNFK-DOGheiwT.js} +1 -1
- package/dist/web-client/assets/{railroad-3IZDKUUU-BvZeVRGh.js → railroad-3IZDKUUU-_JnU7M6L.js} +1 -1
- package/dist/web-client/assets/railroad-abnf-AHOZXSZD-nhNub7LE.js +1 -0
- package/dist/web-client/assets/railroad-ebnf-EBAXGLYW-BlQYe7Yf.js +1 -0
- package/dist/web-client/assets/railroad-peg-LSFZ7HO6-B3E8pRVN.js +1 -0
- package/dist/web-client/assets/{railroadDiagram-RFXS5EU6-D0iK_k84.js → railroadDiagram-RFXS5EU6-C0CkMsOd.js} +1 -1
- package/dist/web-client/assets/{requirementDiagram-TGXJPOKE-BPdsw9tz.js → requirementDiagram-TGXJPOKE-DuImwoRD.js} +1 -1
- package/dist/web-client/assets/{sankeyDiagram-HTMAVEWB-maA6ukOJ.js → sankeyDiagram-HTMAVEWB-kprq0XF9.js} +1 -1
- package/dist/web-client/assets/{sequenceDiagram-DBY2YBRQ-DKmAjmgr.js → sequenceDiagram-DBY2YBRQ-DiXKJMF6.js} +1 -1
- package/dist/web-client/assets/{stateDiagram-2N3HPSRC-esxmzk3w.js → stateDiagram-2N3HPSRC-D5qbVStE.js} +1 -1
- package/dist/web-client/assets/stateDiagram-v2-6OUMAXLB-DWwTAG1r.js +1 -0
- package/dist/web-client/assets/{swimlanes-5IMT3BWC-DFd-wGBv.js → swimlanes-5IMT3BWC-DCbw389c.js} +1 -1
- package/dist/web-client/assets/swimlanesDiagram-G3AALYLV-DabrCsjZ.js +8 -0
- package/dist/web-client/assets/{timeline-definition-FHXFAJF6-C7SG8MQH.js → timeline-definition-FHXFAJF6-CQeaYN_9.js} +1 -1
- package/dist/web-client/assets/{treeView-QDETBFTQ-M0rhxbs2.js → treeView-QDETBFTQ-Cf7Sq3qo.js} +1 -1
- package/dist/web-client/assets/{treemap-6X3UGDF4-BQfkQxSh.js → treemap-6X3UGDF4-BovzvoTU.js} +1 -1
- package/dist/web-client/assets/{vennDiagram-L72KCM5P-CyIlb8ju.js → vennDiagram-L72KCM5P-CZsJy139.js} +1 -1
- package/dist/web-client/assets/{wardley-OPB4EBWU-EE-7q8M1.js → wardley-OPB4EBWU-DJ7MS6XZ.js} +1 -1
- package/dist/web-client/assets/{wardleyDiagram-EHGQE667-bY8XdYYS.js → wardleyDiagram-EHGQE667-rqhcmsbM.js} +1 -1
- package/dist/web-client/assets/{xychartDiagram-FW5EYKEG-AhuXJ3de.js → xychartDiagram-FW5EYKEG-HuK4Seps.js} +1 -1
- package/dist/web-client/index.html +1 -1
- package/dist/web-server/app.d.ts +2 -2
- package/dist/web-server/app.d.ts.map +1 -1
- package/dist/web-server/app.js +0 -3
- package/dist/web-server/app.js.map +1 -1
- package/dist/web-server/routes/hook-events.d.ts +6 -7
- package/dist/web-server/routes/hook-events.d.ts.map +1 -1
- package/dist/web-server/routes/hook-events.js +18 -22
- package/dist/web-server/routes/hook-events.js.map +1 -1
- package/dist/web-server/routes/sessions.d.ts +6 -8
- package/dist/web-server/routes/sessions.d.ts.map +1 -1
- package/dist/web-server/routes/sessions.js +27 -137
- package/dist/web-server/routes/sessions.js.map +1 -1
- package/opencode/arcs/bundle-runtime.json +0 -3
- package/opencode/arcs/manifest.json +8 -25
- package/opencode/arcs/prompts/arcs-docs.txt +19 -157
- package/opencode/arcs/prompts/arcs-flash.txt +49 -152
- package/opencode/arcs/prompts/arcs-orchestrate-caveman.txt +47 -165
- package/opencode/arcs/prompts/arcs-orchestrate.txt +46 -158
- package/opencode/arcs/prompts/code-reviewer.txt +20 -60
- package/opencode/arcs/prompts/graph-explorer.txt +19 -49
- package/opencode/arcs/prompts/software-engineer.txt +21 -67
- package/opencode/arcs/prompts/tech-architect.txt +20 -130
- package/opencode/arcs/skills/brainstorming/SKILL.md +20 -100
- package/opencode/arcs/skills/brainstorming/visual-companion.md +6 -264
- package/opencode/arcs/skills/caveman-commit/SKILL.md +6 -43
- package/opencode/arcs/skills/deep-pr-review/SKILL.md +18 -200
- package/opencode/arcs/skills/deep-pr-review/codegraph-diff.md +7 -93
- package/opencode/arcs/skills/deep-pr-review/review-template.md +13 -60
- package/opencode/arcs/skills/enriching-codegraph-proposals/SKILL.md +16 -156
- package/opencode/arcs/skills/implementation/SKILL.md +20 -46
- package/opencode/arcs/skills/init-project/SKILL.md +12 -150
- package/opencode/arcs/skills/install-claude-code-hook/SKILL.md +13 -133
- package/opencode/arcs/skills/systematic-debugging/SKILL.md +13 -152
- package/opencode/arcs/skills/systematic-debugging/condition-based-waiting.md +7 -110
- package/opencode/arcs/skills/systematic-debugging/defense-in-depth.md +7 -119
- package/opencode/arcs/skills/systematic-debugging/phases-reference.md +9 -166
- package/opencode/arcs/skills/systematic-debugging/root-cause-tracing.md +8 -165
- package/opencode/arcs/skills/test-driven-development/SKILL.md +10 -61
- package/opencode/arcs/skills/test-driven-development/tdd-rationalizations-and-examples.md +7 -154
- package/opencode/arcs/skills/test-driven-development/testing-anti-patterns.md +8 -295
- package/opencode/arcs/skills/to-diagram/SKILL.md +18 -206
- package/opencode/arcs/skills/writing-knowledge/SKILL.md +11 -63
- package/opencode/arcs/skills/writing-plans/SKILL.md +25 -118
- package/opencode/arcs/skills/writing-plans/plan-document-reviewer-prompt.md +10 -61
- package/package.json +1 -1
- package/scripts/claude-code-session-hook.mjs +16 -41
- package/skills/explore-dag.md +9 -52
- package/skills/init-project.md +9 -98
- package/skills/orchestrate.md +15 -109
- package/skills/update-docs.md +9 -60
- package/dist/web-client/assets/architecture-TIHT7OUA-Bt2-DmfV.js +0 -1
- package/dist/web-client/assets/channel-C2mb9np_.js +0 -1
- package/dist/web-client/assets/classDiagram-OUVF2IWQ-CPd_w3Zr.js +0 -1
- package/dist/web-client/assets/classDiagram-v2-EOCWNBFH-CPd_w3Zr.js +0 -1
- package/dist/web-client/assets/eventmodeling-45OFAUF4-CTKRC2Yj.js +0 -1
- package/dist/web-client/assets/flowDiagram-23GEKE2U-CaZjFyU1.js +0 -1
- package/dist/web-client/assets/railroad-abnf-AHOZXSZD-DnGh6x2O.js +0 -1
- package/dist/web-client/assets/railroad-ebnf-EBAXGLYW-CGfgCoaE.js +0 -1
- package/dist/web-client/assets/railroad-peg-LSFZ7HO6-BzQxYdqp.js +0 -1
- package/dist/web-client/assets/stateDiagram-v2-6OUMAXLB-hcBqlOLc.js +0 -1
- package/dist/web-client/assets/swimlanesDiagram-G3AALYLV-DbSrPBYr.js +0 -8
- package/dist/web-server/opencode-client.d.ts +0 -123
- package/dist/web-server/opencode-client.d.ts.map +0 -1
- package/dist/web-server/opencode-client.js +0 -514
- package/dist/web-server/opencode-client.js.map +0 -1
- package/opencode/arcs/prompts/devil-advocate.txt +0 -79
- package/opencode/arcs/skills/executing-plans/SKILL.md +0 -49
|
@@ -1,168 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Debugging Phases
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
1. Observe the complete failure.
|
|
4
|
+
2. Reproduce it reliably.
|
|
5
|
+
3. Form one specific hypothesis.
|
|
6
|
+
4. Isolate one variable.
|
|
7
|
+
5. Add a regression test when practical.
|
|
8
|
+
6. Fix the root cause.
|
|
9
|
+
7. Verify the reproduction and relevant checks.
|
|
4
10
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
**BEFORE attempting ANY fix:**
|
|
8
|
-
|
|
9
|
-
1. **Read Error Messages Carefully**
|
|
10
|
-
- Don't skip past errors or warnings
|
|
11
|
-
- They often contain the exact solution
|
|
12
|
-
- Read stack traces completely
|
|
13
|
-
- Note line numbers, file paths, error codes
|
|
14
|
-
|
|
15
|
-
2. **Reproduce Consistently**
|
|
16
|
-
- Can you trigger it reliably?
|
|
17
|
-
- What are the exact steps?
|
|
18
|
-
- Does it happen every time?
|
|
19
|
-
- If not reproducible → gather more data, don't guess
|
|
20
|
-
|
|
21
|
-
3. **Check Recent Changes**
|
|
22
|
-
- What changed that could cause this?
|
|
23
|
-
- Git diff, recent commits
|
|
24
|
-
- New dependencies, config changes
|
|
25
|
-
- Environmental differences
|
|
26
|
-
|
|
27
|
-
4. **Gather Evidence in Multi-Component Systems**
|
|
28
|
-
|
|
29
|
-
**WHEN system has multiple components (CI → build → signing, API → service → database):**
|
|
30
|
-
|
|
31
|
-
**BEFORE proposing fixes, add diagnostic instrumentation:**
|
|
32
|
-
```
|
|
33
|
-
For EACH component boundary:
|
|
34
|
-
- Log what data enters component
|
|
35
|
-
- Log what data exits component
|
|
36
|
-
- Verify environment/config propagation
|
|
37
|
-
- Check state at each layer
|
|
38
|
-
|
|
39
|
-
Run once to gather evidence showing WHERE it breaks
|
|
40
|
-
THEN analyze evidence to identify failing component
|
|
41
|
-
THEN investigate that specific component
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
**Example (multi-layer system):**
|
|
45
|
-
```bash
|
|
46
|
-
# Layer 1: Workflow
|
|
47
|
-
echo "=== Secrets available in workflow: ==="
|
|
48
|
-
echo "IDENTITY: ${IDENTITY:+SET}${IDENTITY:-UNSET}"
|
|
49
|
-
|
|
50
|
-
# Layer 2: Build script
|
|
51
|
-
echo "=== Env vars in build script: ==="
|
|
52
|
-
env | grep IDENTITY || echo "IDENTITY not in environment"
|
|
53
|
-
|
|
54
|
-
# Layer 3: Signing script
|
|
55
|
-
echo "=== Keychain state: ==="
|
|
56
|
-
security list-keychains
|
|
57
|
-
security find-identity -v
|
|
58
|
-
|
|
59
|
-
# Layer 4: Actual signing
|
|
60
|
-
codesign --sign "$IDENTITY" --verbose=4 "$APP"
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
**This reveals:** Which layer fails (secrets → workflow ✓, workflow → build ✗)
|
|
64
|
-
|
|
65
|
-
5. **Trace Data Flow**
|
|
66
|
-
|
|
67
|
-
**WHEN error is deep in call stack:**
|
|
68
|
-
|
|
69
|
-
See `root-cause-tracing.md` in this directory for the complete backward tracing technique.
|
|
70
|
-
|
|
71
|
-
**Quick version:**
|
|
72
|
-
- Where does bad value originate?
|
|
73
|
-
- What called this with bad value?
|
|
74
|
-
- Keep tracing up until you find the source
|
|
75
|
-
- Fix at source, not at symptom
|
|
76
|
-
|
|
77
|
-
## Phase 2: Pattern Analysis
|
|
78
|
-
|
|
79
|
-
**Find the pattern before fixing:**
|
|
80
|
-
|
|
81
|
-
1. **Find Working Examples**
|
|
82
|
-
- Locate similar working code in same codebase
|
|
83
|
-
- What works that's similar to what's broken?
|
|
84
|
-
|
|
85
|
-
2. **Compare Against References**
|
|
86
|
-
- If implementing pattern, read reference implementation COMPLETELY
|
|
87
|
-
- Don't skim — read every line
|
|
88
|
-
- Understand the pattern fully before applying
|
|
89
|
-
|
|
90
|
-
3. **Identify Differences**
|
|
91
|
-
- What's different between working and broken?
|
|
92
|
-
- List every difference, however small
|
|
93
|
-
- Don't assume "that can't matter"
|
|
94
|
-
|
|
95
|
-
4. **Understand Dependencies**
|
|
96
|
-
- What other components does this need?
|
|
97
|
-
- What settings, config, environment?
|
|
98
|
-
- What assumptions does it make?
|
|
99
|
-
|
|
100
|
-
## Phase 3: Hypothesis and Testing
|
|
101
|
-
|
|
102
|
-
**Scientific method:**
|
|
103
|
-
|
|
104
|
-
1. **Form Single Hypothesis**
|
|
105
|
-
- State clearly: "I think X is the root cause because Y"
|
|
106
|
-
- Write it down
|
|
107
|
-
- Be specific, not vague
|
|
108
|
-
|
|
109
|
-
2. **Test Minimally**
|
|
110
|
-
- Make the SMALLEST possible change to test hypothesis
|
|
111
|
-
- One variable at a time
|
|
112
|
-
- Don't fix multiple things at once
|
|
113
|
-
|
|
114
|
-
3. **Verify Before Continuing**
|
|
115
|
-
- Did it work? Yes → Phase 4
|
|
116
|
-
- Didn't work? Form NEW hypothesis
|
|
117
|
-
- DON'T add more fixes on top
|
|
118
|
-
|
|
119
|
-
4. **When You Don't Know**
|
|
120
|
-
- Say "I don't understand X"
|
|
121
|
-
- Don't pretend to know
|
|
122
|
-
- Ask for help
|
|
123
|
-
- Research more
|
|
124
|
-
|
|
125
|
-
## Phase 4: Implementation
|
|
126
|
-
|
|
127
|
-
**Fix the root cause, not the symptom:**
|
|
128
|
-
|
|
129
|
-
1. **Create Failing Test Case**
|
|
130
|
-
- Simplest possible reproduction
|
|
131
|
-
- Automated test if possible
|
|
132
|
-
- One-off test script if no framework
|
|
133
|
-
- MUST have before fixing
|
|
134
|
-
- Use the `arcs:test-driven-development` skill for writing proper failing tests
|
|
135
|
-
|
|
136
|
-
2. **Implement Single Fix**
|
|
137
|
-
- Address the root cause identified
|
|
138
|
-
- ONE change at a time
|
|
139
|
-
- No "while I'm here" improvements
|
|
140
|
-
- No bundled refactoring
|
|
141
|
-
|
|
142
|
-
3. **Verify Fix**
|
|
143
|
-
- Test passes now?
|
|
144
|
-
- No other tests broken?
|
|
145
|
-
- Issue actually resolved?
|
|
146
|
-
|
|
147
|
-
4. **If Fix Doesn't Work**
|
|
148
|
-
- STOP
|
|
149
|
-
- Count: How many fixes have you tried?
|
|
150
|
-
- If < 3: Return to Phase 1, re-analyze with new information
|
|
151
|
-
- **If ≥ 3: STOP and question the architecture (step 5 below)**
|
|
152
|
-
- DON'T attempt Fix #4 without architectural discussion
|
|
153
|
-
|
|
154
|
-
5. **If 3+ Fixes Failed: Question Architecture**
|
|
155
|
-
|
|
156
|
-
**Pattern indicating architectural problem:**
|
|
157
|
-
- Each fix reveals new shared state/coupling/problem in different place
|
|
158
|
-
- Fixes require "massive refactoring" to implement
|
|
159
|
-
- Each fix creates new symptoms elsewhere
|
|
160
|
-
|
|
161
|
-
**STOP and question fundamentals:**
|
|
162
|
-
- Is this pattern fundamentally sound?
|
|
163
|
-
- Are we "sticking with it through sheer inertia"?
|
|
164
|
-
- Should we refactor architecture vs. continue fixing symptoms?
|
|
165
|
-
|
|
166
|
-
**Discuss with your human partner before attempting more fixes**
|
|
167
|
-
|
|
168
|
-
This is NOT a failed hypothesis — this is a wrong architecture.
|
|
11
|
+
After three failed fixes, stop and revisit assumptions or architecture.
|
|
@@ -1,169 +1,12 @@
|
|
|
1
|
-
# Root
|
|
1
|
+
# Root-Cause Tracing
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Start at the observed failure and trace inputs backward through boundaries until the first incorrect state appears.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
At each boundary record:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- expected value;
|
|
8
|
+
- actual value;
|
|
9
|
+
- producer;
|
|
10
|
+
- evidence.
|
|
8
11
|
|
|
9
|
-
|
|
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 /Users/jesse/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 (scoped to the suspect test file — never the full suite):**
|
|
88
|
-
```bash
|
|
89
|
-
npm test -- path/to/suspect.test.ts 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
|
-
./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
|
|
12
|
+
Fix the earliest incorrect assumption you own, not the last place that notices it. Compare with a working path when available.
|
|
@@ -1,72 +1,21 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: test-driven-development
|
|
3
|
-
description: Use
|
|
3
|
+
description: Use a focused red-green-refactor loop for observable behavior changes
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# Test-Driven Development
|
|
7
7
|
|
|
8
8
|
## When
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Use when a feature, bug fix, or behavior change benefits from executable proof. Pure prose, metadata, generated output, or mechanical refactors may rely on existing contracts instead of adding a new test.
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
## Loop
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
For a behavior change, write one failing test that demonstrates the requirement, run it to confirm the expected failure, add the minimal implementation, rerun until green, then refactor while preserving behavior.
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
B -->|Wrong failure| A
|
|
21
|
-
B -->|Passes immediately| D[Test is wrong — fix or delete]
|
|
22
|
-
D --> A
|
|
23
|
-
C --> E{Run test}
|
|
24
|
-
E -->|Your tests pass| F[Refactor — keep green]
|
|
25
|
-
E -->|Fails| C
|
|
26
|
-
F --> G{More behavior needed?}
|
|
27
|
-
G -->|Yes| A
|
|
28
|
-
G -->|No| H[Done — your test files green, scoped VERIFY passes]
|
|
29
|
-
```
|
|
16
|
+
1. **Failing test:** one behavior, clear name, real boundary.
|
|
17
|
+
2. **Minimal code:** only what makes the test pass.
|
|
18
|
+
3. **Refactor:** remove duplication and improve names without adding behavior.
|
|
19
|
+
4. **Verify:** run the relevant test and any proportionate integration check.
|
|
30
20
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
Code written before a test? **Delete it.** No "reference", no "adapting". Start fresh from tests.
|
|
34
|
-
|
|
35
|
-
## RED — Write Failing Test
|
|
36
|
-
|
|
37
|
-
- One behavior per test, clear name, real code (no mocks unless unavoidable)
|
|
38
|
-
- Run: `npm test -- path/to/test.test.ts` — confirm fails for the right reason
|
|
39
|
-
|
|
40
|
-
## GREEN — Minimal Code
|
|
41
|
-
|
|
42
|
-
- Simplest code to pass. Nothing beyond what the test requires.
|
|
43
|
-
- Run: re-run YOUR test file(s) (`npm test -- path/to/test.test.ts`) — confirm they pass, output pristine. Never the unscoped suite; the devil-advocate completion gate owns full-project verification.
|
|
44
|
-
|
|
45
|
-
## REFACTOR — Clean Up
|
|
46
|
-
|
|
47
|
-
- Remove duplication, improve names, extract helpers
|
|
48
|
-
- Keep tests green. Don't add behavior.
|
|
49
|
-
|
|
50
|
-
## Common Rationalizations
|
|
51
|
-
|
|
52
|
-
| Excuse | Reality |
|
|
53
|
-
|--------|---------|
|
|
54
|
-
| "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
|
|
55
|
-
| "I'll test after" | Tests passing immediately prove nothing. |
|
|
56
|
-
| "Need to explore first" | Fine. Throw away exploration, then TDD. |
|
|
57
|
-
| "Test hard = design unclear" | Hard to test = hard to use. Listen to the test. |
|
|
58
|
-
| "TDD will slow me down" | TDD faster than debugging. |
|
|
59
|
-
|
|
60
|
-
## When Stuck
|
|
61
|
-
|
|
62
|
-
| Problem | Solution |
|
|
63
|
-
|---------|----------|
|
|
64
|
-
| Don't know how to test | Write wished-for API. Assertion first. |
|
|
65
|
-
| Test too complicated | Design too complicated. Simplify interface. |
|
|
66
|
-
| Must mock everything | Code too coupled. Use dependency injection. |
|
|
67
|
-
|
|
68
|
-
## Red Flags — Delete and Start Over
|
|
69
|
-
|
|
70
|
-
Code before test, test passes immediately, can't explain why test failed, rationalizing "just this once".
|
|
71
|
-
|
|
72
|
-
See `tdd-rationalizations-and-examples.md` for expanded examples and rebuttals.
|
|
21
|
+
If a test passes immediately, verify that it actually covers the new behavior. Avoid mocks that merely confirm implementation details. Use `testing-anti-patterns.md` or `tdd-rationalizations-and-examples.md` only when those details help.
|
|
@@ -1,157 +1,10 @@
|
|
|
1
|
-
# TDD
|
|
1
|
+
# TDD Quick Examples
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Use this optional reference when the right test boundary is unclear.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
- Bug: reproduce the reported failure, then fix it.
|
|
6
|
+
- Feature: assert the smallest user-visible behavior before implementation.
|
|
7
|
+
- Refactor: existing behavior tests may be sufficient; add a test only for an uncovered contract.
|
|
8
|
+
- Mechanical/prose/generated changes: verify the relevant contract instead of inventing a unit test.
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Tests written after code pass immediately. Passing immediately proves nothing:
|
|
10
|
-
- Might test wrong thing
|
|
11
|
-
- Might test implementation, not behavior
|
|
12
|
-
- Might miss edge cases you forgot
|
|
13
|
-
- You never saw it catch the bug
|
|
14
|
-
|
|
15
|
-
Test-first forces you to see the test fail, proving it actually tests something.
|
|
16
|
-
|
|
17
|
-
### "I already manually tested all the edge cases"
|
|
18
|
-
|
|
19
|
-
Manual testing is ad-hoc. You think you tested everything but:
|
|
20
|
-
- No record of what you tested
|
|
21
|
-
- Can't re-run when code changes
|
|
22
|
-
- Easy to forget cases under pressure
|
|
23
|
-
- "It worked when I tried it" ≠ comprehensive
|
|
24
|
-
|
|
25
|
-
Automated tests are systematic. They run the same way every time.
|
|
26
|
-
|
|
27
|
-
### "Deleting X hours of work is wasteful"
|
|
28
|
-
|
|
29
|
-
Sunk cost fallacy. The time is already gone. Your choice now:
|
|
30
|
-
- Delete and rewrite with TDD (X more hours, high confidence)
|
|
31
|
-
- Keep it and add tests after (30 min, low confidence, likely bugs)
|
|
32
|
-
|
|
33
|
-
The "waste" is keeping code you can't trust. Working code without real tests is technical debt.
|
|
34
|
-
|
|
35
|
-
### "TDD is dogmatic, being pragmatic means adapting"
|
|
36
|
-
|
|
37
|
-
TDD IS pragmatic:
|
|
38
|
-
- Finds bugs before commit (faster than debugging after)
|
|
39
|
-
- Prevents regressions (tests catch breaks immediately)
|
|
40
|
-
- Documents behavior (tests show how to use code)
|
|
41
|
-
- Enables refactoring (change freely, tests catch breaks)
|
|
42
|
-
|
|
43
|
-
"Pragmatic" shortcuts = debugging in production = slower.
|
|
44
|
-
|
|
45
|
-
### "Tests after achieve the same goals — it's spirit not ritual"
|
|
46
|
-
|
|
47
|
-
No. Tests-after answer "What does this do?" Tests-first answer "What should this do?"
|
|
48
|
-
|
|
49
|
-
Tests-after are biased by your implementation. You test what you built, not what's required. You verify remembered edge cases, not discovered ones.
|
|
50
|
-
|
|
51
|
-
Tests-first force edge case discovery before implementing. Tests-after verify you remembered everything (you didn't).
|
|
52
|
-
|
|
53
|
-
30 minutes of tests after ≠ TDD. You get coverage, lose proof tests work.
|
|
54
|
-
|
|
55
|
-
## Worked Example: Bug Fix via TDD
|
|
56
|
-
|
|
57
|
-
**Bug:** Empty email accepted
|
|
58
|
-
|
|
59
|
-
### RED
|
|
60
|
-
```typescript
|
|
61
|
-
test('rejects empty email', async () => {
|
|
62
|
-
const result = await submitForm({ email: '' });
|
|
63
|
-
expect(result.error).toBe('Email required');
|
|
64
|
-
});
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### Verify RED
|
|
68
|
-
```bash
|
|
69
|
-
$ npm test -- submitForm.test.ts
|
|
70
|
-
FAIL: expected 'Email required', got undefined
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### GREEN
|
|
74
|
-
```typescript
|
|
75
|
-
function submitForm(data: FormData) {
|
|
76
|
-
if (!data.email?.trim()) {
|
|
77
|
-
return { error: 'Email required' };
|
|
78
|
-
}
|
|
79
|
-
// ...
|
|
80
|
-
}
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
### Verify GREEN
|
|
84
|
-
```bash
|
|
85
|
-
$ npm test -- submitForm.test.ts
|
|
86
|
-
PASS
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### REFACTOR
|
|
90
|
-
Extract validation for multiple fields if needed.
|
|
91
|
-
|
|
92
|
-
## Good vs Bad Tests and Implementations
|
|
93
|
-
|
|
94
|
-
### RED — Good failing test
|
|
95
|
-
|
|
96
|
-
```typescript
|
|
97
|
-
test('retries failed operations 3 times', async () => {
|
|
98
|
-
let attempts = 0;
|
|
99
|
-
const operation = () => {
|
|
100
|
-
attempts++;
|
|
101
|
-
if (attempts < 3) throw new Error('fail');
|
|
102
|
-
return 'success';
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const result = await retryOperation(operation);
|
|
106
|
-
|
|
107
|
-
expect(result).toBe('success');
|
|
108
|
-
expect(attempts).toBe(3);
|
|
109
|
-
});
|
|
110
|
-
```
|
|
111
|
-
Clear name, tests real behavior, one thing.
|
|
112
|
-
|
|
113
|
-
### RED — Bad failing test
|
|
114
|
-
|
|
115
|
-
```typescript
|
|
116
|
-
test('retry works', async () => {
|
|
117
|
-
const mock = jest.fn()
|
|
118
|
-
.mockRejectedValueOnce(new Error())
|
|
119
|
-
.mockRejectedValueOnce(new Error())
|
|
120
|
-
.mockResolvedValueOnce('success');
|
|
121
|
-
await retryOperation(mock);
|
|
122
|
-
expect(mock).toHaveBeenCalledTimes(3);
|
|
123
|
-
});
|
|
124
|
-
```
|
|
125
|
-
Vague name, tests mock not code.
|
|
126
|
-
|
|
127
|
-
### GREEN — Good minimal implementation
|
|
128
|
-
|
|
129
|
-
```typescript
|
|
130
|
-
async function retryOperation<T>(fn: () => Promise<T>): Promise<T> {
|
|
131
|
-
for (let i = 0; i < 3; i++) {
|
|
132
|
-
try {
|
|
133
|
-
return await fn();
|
|
134
|
-
} catch (e) {
|
|
135
|
-
if (i === 2) throw e;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
throw new Error('unreachable');
|
|
139
|
-
}
|
|
140
|
-
```
|
|
141
|
-
Just enough to pass.
|
|
142
|
-
|
|
143
|
-
### GREEN — Bad over-engineered implementation
|
|
144
|
-
|
|
145
|
-
```typescript
|
|
146
|
-
async function retryOperation<T>(
|
|
147
|
-
fn: () => Promise<T>,
|
|
148
|
-
options?: {
|
|
149
|
-
maxRetries?: number;
|
|
150
|
-
backoff?: 'linear' | 'exponential';
|
|
151
|
-
onRetry?: (attempt: number) => void;
|
|
152
|
-
}
|
|
153
|
-
): Promise<T> {
|
|
154
|
-
// YAGNI
|
|
155
|
-
}
|
|
156
|
-
```
|
|
157
|
-
Over-engineered. Don't add features, refactor other code, or "improve" beyond the test.
|
|
10
|
+
If the test passes before implementation, confirm it exercises the new behavior. If testing requires extensive mocking, look for a simpler public boundary.
|