File size: 4,488 Bytes
b6e19c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Workflow β€” Fixing a Bug

## Purpose
Read this file every time you need to fix a bug.
Follow steps in order. Do not open files not mentioned in the log.

---

## Core Principle
**The log tells you where to look. Trust the log. Check one file.**
Do not scan the codebase. Do not refactor while fixing.

---

## Step 1 β€” Read the Error First
Before touching any code:
- [ ] Read `logs/errors.log` β€” find the exact error entry
- [ ] Identify: file, function, reason, fix hint from the log
- [ ] Read `docs/learnings.md` β€” has this failed before?
- [ ] If yes β†’ apply the known fix, skip to Step 5

Error log format to look for:

[ERROR] [timestamp] [file:function] β€” reason β€” fix hint

---

## Step 2 β€” Isolate Before Fixing
State this out loud before touching code:
Error in: [file:function]
Reason: [from log]
Fix hint: [from log]
Only file I will open: [file]

- [ ] Open only the file named in the log
- [ ] Find only the function named in the log
- [ ] Do not open any other file unless the log explicitly points there

---

## Step 3 β€” Understand the Failure
Inside the identified function:
- [ ] Check what input is coming in
- [ ] Check where exactly it breaks (line from log)
- [ ] Check if it is a null/undefined issue
- [ ] Check if it is an auth/session issue
- [ ] Check if it is a Supabase RLS issue
- [ ] Reference `docs/debugging.md` β†’ Supabase Specific Errors table

---

## Step 4 β€” Write the Fix
- [ ] Fix only the broken logic
- [ ] Do not rename variables or restructure the function
- [ ] Do not fix adjacent code that looks messy
- [ ] Add or improve error handling inline if it was missing
- [ ] Confirm fix hint from log is addressed

---

## Step 5 β€” Write or Update the Test
- [ ] Find the existing test file for this feature
- [ ] If the failing case was not covered β†’ add a test for it now
- [ ] The test must reproduce the exact failure condition
- [ ] Run only the test for this file first:
```bash
npm test -- tests/unit/[feature-name].test.ts 2>&1 | tee logs/test.log
```
- [ ] Confirm it passes before running full suite

---

## Step 6 β€” Run Full Test Suite
```bash
bash scripts/test.sh
```
- [ ] All tests pass
- [ ] No previously passing test is now failing
- [ ] If a new failure appears β†’ treat it as a new bug, do not chain fixes

---

## Step 7 β€” Update Docs
- [ ] Add one-liner to `docs/progress.md` under the feature
- [ ] If this was a repeated failure or needed a workaround β†’ add to `docs/learnings.md`
- [ ] Append one line to `session/phase-log.md`
- [ ] Update `session/summary.md`

---

## Step 8 β€” Git Commit Message
Provide one-liner commit message in this format:

fix([scope]): [what was broken and what fixed it]
Examples:
fix(auth): handle null session before calling fetchUser
fix(dashboard): return empty array instead of null on no results
fix(db): add missing RLS policy for users table select

**Do NOT push to GitHub. Hand the message to the user.**

---

## Step 9 β€” Confirm with User
- [ ] Show exactly what was changed and in which file
- [ ] Show test results
- [ ] Show commit message
- [ ] Ask: "Confirmed fixed β€” ready to continue?"
- [ ] Do NOT proceed until user confirms

---

## Bugfix Decision Tree

Error occurs
β”‚
β–Ό
Read logs/errors.log
β”‚
β”œβ”€β”€ Entry found β†’ go to Step 2
β”‚
└── No entry β†’ add logging first, reproduce error, then fix
β”‚
β–Ό
Check docs/learnings.md
β”‚
β”œβ”€β”€ Known issue β†’ apply fix directly
β”‚
└── New issue β†’ isolate β†’ fix β†’ document

---

## Common Bug Patterns

| Symptom | Likely Cause | Where to Look |
|---------|-------------|---------------|
| Function returns null unexpectedly | Missing null check on input | The function's first few lines |
| Supabase returns empty data | RLS policy blocking query | Supabase Dashboard β†’ Policies |
| Auth token errors | Session not refreshed | auth handler file |
| Test passes locally, fails in CI | Env var missing in CI | .env setup + CI config |
| Infinite re-render in React | useEffect dependency missing | The specific component file |
| Type error at runtime | TypeScript type not enforced at boundary | Input validation of the function |

---

## What NOT to Do
- Do not open the entire codebase to find the bug
- Do not fix multiple bugs in one session without separate commits
- Do not refactor while fixing β€” fix first, refactor separately
- Do not skip updating the test file
- Do not push to GitHub
- Do not chain fixes β€” one bug, one fix, one commit