๐ ์ฒด๊ณ์ ๋๋ฒ๊น (Dev Coding Debug)
์ด ์ํฌํ๋ก์ฐ๋ obra/superpowers์ **"The Iron Law"**๋ฅผ ์ค์ํฉ๋๋ค. ๊ทผ๋ณธ ์์ธ ๊ท๋ช
์์ด๋ ์ ๋ ์ฝ๋๋ฅผ ์์ ํ์ง ์์ต๋๋ค.
1. ์ด๊ธฐํ (Initialization)
- ์์น ํ์ธ:
this document๋ฅผ ์ฝ๊ณ Iron Law๋ฅผ ์๊ธฐํฉ๋๋ค. - ์ฆ์ ์ ์: ์ฌ์ฉ์๋ก๋ถํฐ ์ ํํ ์๋ฌ ๋ฉ์์ง์ ํ์์ ์ ๋ ฅ๋ฐ์ต๋๋ค.
2. ์กฐ์ฌ (Phase 1: Root Cause Investigation)
"์ถ์ธกํ์ง ๋ง๊ณ ์ฆ๊ฑฐ๋ฅผ ์์งํ์ธ์."
- ์๋ฌ ๋ถ์: ์คํ ํธ๋ ์ด์ค์ ์๋ฌ ์ฝ๋๋ฅผ ์ ๋ฐ ๋ถ์ํฉ๋๋ค.
- ์ฌํ (Reproduction): ๋ฒ๊ทธ๋ฅผ ํ์คํ๊ฒ ๋ฐ์์ํค๋ ์ต์ ๋จ์์ ์คํฌ๋ฆฝํธ๋ฅผ ์์ฑํฉ๋๋ค. (ํ์)
- ๊ธฐ๊ธฐ/๋ก๊ทธ ์ถ๊ฐ (Instrumentation): ๋ฐ์ดํฐ๊ฐ ์ค์ผ๋๋ ์ง์ ์ ์ฐพ๊ธฐ ์ํด ๋ก๊ทธ๋ฅผ ์ถ๊ฐํ๊ณ , ๋ฐ์ดํฐ ํ๋ฆ์ ์ญ์ถ์ (Trace)ํฉ๋๋ค.
3. ๋ถ์ (Phase 2: Pattern Analysis)
"์ ์์ ์ธ ํจํด๊ณผ ๋ฌด์์ด ๋ค๋ฅธ๊ฐ์?"
- ์ ์ ์ฌ๋ก ์ฐพ๊ธฐ: ํ๋ก์ ํธ ๋ด์์ ์ ๋์ํ๋ ์ ์ฌํ ์ฝ๋๋ฅผ ์ฐพ์ต๋๋ค.
- ๋น๊ต ๋ถ์: ์ ์ ์ฝ๋์ ๋ฌธ์ ๊ฐ ์๋ ์ฝ๋์ ์ฐจ์ด์ ์ ํ ์ค ํ ์ค ๋น๊ตํฉ๋๋ค.
- ์ฐจ์ด์ ๋ชฉ๋ก: ์ฌ์ํด ๋ณด์ด๋ ์ฐจ์ด์ ์ด๋ผ๋ ๋ชจ๋ ๋์ดํฉ๋๋ค.
4. ๊ฐ์ค (Phase 3: Hypothesis & Testing)
"๊ณผํ์ ๋ฐฉ๋ฒ๋ก ์ ์ ์ฉํ์ธ์."
- ๊ฐ์ค ์๋ฆฝ: "X ๋๋ฌธ์ Y๊ฐ ๋ฐ์ํ๋ค"๋ ๊ฐ์ค์ ํ๋ ์ธ์๋๋ค.
- ์ต์ ๊ฒ์ฆ: ๊ฐ์ค์ ํ์ธํ๊ธฐ ์ํด ๋ณ์ ํ๋๋ง ๋ณ๊ฒฝํ์ฌ ํ ์คํธํฉ๋๋ค. (์์ ์ด ์๋)
- ๋ฐ๋ณต: ๊ฐ์ค์ด ํ๋ ธ๋ค๋ฉด ๋ณ๊ฒฝ ์ฌํญ์ ๋๋๋ฆฌ๊ณ (Revert), ์๋ก์ด ๊ฐ์ค์ ์ธ์๋๋ค. ๊ธฐ์กด ๋ณ๊ฒฝ ์์ ๋ง์น ๊ธ์ง.
5. ํด๊ฒฐ (Phase 4: Implementation)
"์ฆ์์ด ์๋ ์์ธ์ ๊ณ ์น์ธ์."
- ์คํจ ํ ์คํธ (Red): ์๋ณ๋ ์์ธ์ ํ๊ฒ์ผ๋ก ํ๋ ์คํจ ํ ์คํธ ์ผ์ด์ค๋ฅผ ํ์ ํฉ๋๋ค.
- ๋จ์ผ ์์ (Green): ๊ทผ๋ณธ ์์ธ์ ์ ๊ฑฐํ๋ ์ต์ํ์ ์ฝ๋๋ฅผ ์์ฑํฉ๋๋ค.
- ๊ฒ์ฆ (Verification): ํ ์คํธ ํต๊ณผ ๋ฐ ํ๊ท ํ ์คํธ(Regression Test) ์ํ.
- ์ ๋ฆฌ (Cleanup): ๋๋ฒ๊น ์ฉ ๋ก๊ทธ์ ์์ ์ฝ๋๋ฅผ ๊นจ๋์ด ์ญ์ ํฉ๋๋ค.
6. ์ข ๋ฃ (Completion)
- ํ๊ณ : ์ด๋ค ๋ถ๋ถ์ด ๊ทผ๋ณธ ์์ธ์ด์๋์ง ์ฌ์ฉ์์๊ฒ ์ค๋ช ํ๊ณ ์ข ๋ฃํฉ๋๋ค.
Standards & Rules
Systematic Debugging (Dev Coding Debug)
Core Principles (The Iron Law)
NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST.
If you haven't completed Phase 1 (Root Cause) and Phase 2 (Pattern Analysis), you cannot propose fixes. Symptom fixes are failure.
๐๏ธ The Four Phases
Phase 1: Root Cause Investigation
Goal: Understand WHAT and WHY.
- Read Errors: sticky to the error message. Don't skip stack traces.
- Reproduce: Can you trigger it reliably? If not, gather more data.
- Instrumentation: For multi-component systems, log data flow at boundaries.
- Trace: Follow the bad value backwards to its source (
root-cause-tracing).
Phase 2: Pattern Analysis
Goal: Find the standard before fixing.
- Find Working Examples: Locate similar code that works.
- Compare: Read reference implementations completely.
- Identify Differences: List every difference, however small.
Phase 3: Hypothesis and Testing
Goal: Scientific Method.
- Single Hypothesis: "I think X is the root cause because Y".
- Test Minimally: Change ONE variable at a time to test the hypothesis.
- Verify: If it didn't work, revert and form a NEW hypothesis. NO layering fixes.
Phase 4: Implementation
Goal: Fix the root cause, not the symptom.
- Failing Test: Create a minimal reproduction test case (Red).
- Single Fix: Address the identified root cause (Green).
- Verify: Ensure no regressions.
๏ฟฝ๏ธ Supporting Techniques
1. Root Cause Tracing ("Why did this happen?")
Don't just fix the bad value. Find where it came from.
- Technique: Ask "What called this with a bad value?" repeatedly until you find the source.
- Rule: Fix at the source, not at the symptom.
2. Defense-in-Depth ("Make it impossible")
Don't just validate at one place.
- Layer 1 (Entry): Reject invalid input at IDL/API boundary.
- Layer 2 (Logic): Ensure data makes sense for the operation.
- Layer 3 (Guard): Environment checks (e.g., test vs prod).
- Layer 4 (Debug): Logging for forensics.
3. Condition-Based Waiting (No sleep)
Never guess how long something takes.
- Bad:
sleep(50) - Good:
waitFor(() => condition) - Why: Flaky tests often come from arbitrary timeouts.
๏ฟฝ๐ฉ Red Flags (STOP immediately)
- "Quick fix for now"
- "Just try changing X"
- "One more fix attempt" (Limit: 3 attempts. Then question Architecture.)
- Proposing solutions before tracing.
โ Quality Standards
- Reproduction Script: Must exist before fixing.
- Log Cleanup: All temporary instrumentation removed.
- Safe YAML: Frontmatter descriptions quoted.
Checklist
- [ ] Phase 1: Did you identify the exact line/reason for failure?
- [ ] Phase 2: Did you compare with a working example?
- [ ] Phase 4: Is there a test case that failed before and passes now?
- [ ] Cleanup: Are all
print/console.logremoved?