codex-genesis-harness 0.1.1 → 0.1.4
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/.codebase/ARCHITECTURE_REVIEW_COMPLETE.md +216 -0
- package/.codebase/CURRENT_STATE.md +2 -0
- package/.codebase/DOMAIN_MODELS.md +5 -3
- package/.codebase/FILE_NAMING_CLARIFICATION.md +161 -0
- package/.codebase/HARNESS_COMPLETENESS_AUDIT.md +613 -0
- package/.codebase/IMPLEMENTATION_COMPLETE.md +429 -0
- package/.codebase/IMPLEMENTATION_HANDOFF.md +351 -0
- package/.codebase/IMPROVEMENTS_SUMMARY.md +419 -0
- package/.codebase/PHASE3_SKILLS_NAMING_COMPLETE.md +292 -0
- package/.codebase/PHASE_DEPENDENCY_MAP.md +486 -0
- package/.codebase/QUICK_START_SPEC_IMPACT.md +456 -0
- package/.codebase/README.md +139 -0
- package/.codebase/RECOVERY_POINTS.md +438 -0
- package/.codex/skills/genesis-api-sync/SKILL.md +354 -0
- package/.codex/skills/genesis-api-sync/agents/openai.yaml +7 -0
- package/.codex/skills/genesis-api-sync/checklists/api-sync-checklist.md +101 -0
- package/.codex/skills/genesis-api-sync/examples/example.md +68 -0
- package/.codex/skills/genesis-api-sync/templates/api-change-template.md +257 -0
- package/.codex/skills/genesis-debug-guide/SKILL.md +479 -0
- package/.codex/skills/genesis-debug-guide/agents/openai.yaml +7 -0
- package/.codex/skills/genesis-debug-guide/checklists/flaky-test-investigation.md +339 -0
- package/.codex/skills/genesis-debug-guide/checklists/production-bug-debug.md +210 -0
- package/.codex/skills/genesis-debug-guide/checklists/test-failure-debug.md +158 -0
- package/.codex/skills/genesis-debug-guide/examples/example.md +48 -0
- package/.codex/skills/genesis-debug-guide/observability/debug-commands.md +365 -0
- package/.codex/skills/genesis-debug-guide/playbooks/unit-test-failures.md +289 -0
- package/.codex/skills/genesis-debug-guide/templates/debug-investigation-log.md +288 -0
- package/.codex/skills/genesis-docs-automation/SKILL.md +1003 -0
- package/.codex/skills/genesis-docs-automation/agents/openai.yaml +7 -0
- package/.codex/skills/genesis-docs-automation/checklists/docs-validation.md +359 -0
- package/.codex/skills/genesis-docs-automation/checklists/spec-alignment.md +312 -0
- package/.codex/skills/genesis-docs-automation/examples/example.md +59 -0
- package/.codex/skills/genesis-docs-automation/observability/docs-tracking.md +382 -0
- package/.codex/skills/genesis-docs-automation/playbooks/auto-update-flow.md +851 -0
- package/.codex/skills/genesis-docs-automation/playbooks/changelog-generation.md +491 -0
- package/.codex/skills/genesis-docs-automation/templates/changelog-entry-template.md +187 -0
- package/.codex/skills/genesis-docs-automation/templates/handoff-template.md +297 -0
- package/.codex/skills/genesis-harness/SKILL.md +734 -82
- package/.codex/skills/genesis-harness/checklists/bug-fix-qa.md +169 -0
- package/.codex/skills/genesis-harness/checklists/new-feature-qa.md +157 -0
- package/.codex/skills/genesis-harness/checklists/refactor-qa.md +216 -0
- package/.codex/skills/genesis-harness/checklists/requirements-validation.md +211 -0
- package/.codex/skills/genesis-harness/resources/change-impact-matrix-template.md +204 -0
- package/.codex/skills/genesis-harness/resources/foundation-phase-template.md +131 -0
- package/.codex/skills/genesis-harness/resources/phase-00-foundation-template.md +76 -0
- package/.codex/skills/genesis-harness/resources/post-implementation-guide.md +347 -0
- package/.codex/skills/genesis-harness/scripts/check-architecture-boundaries.sh +23 -23
- package/.codex/skills/genesis-harness/scripts/check-docs-sync.sh +24 -24
- package/.codex/skills/genesis-harness/scripts/check-no-debug-logs.sh +21 -21
- package/.codex/skills/genesis-harness/scripts/check-required-planning-files.sh +46 -46
- package/.codex/skills/genesis-harness/scripts/check-spec-changelog.sh +24 -24
- package/.codex/skills/genesis-harness/scripts/check-task-tracking.sh +25 -25
- package/.codex/skills/genesis-harness/scripts/compact-context.sh +54 -0
- package/.codex/skills/genesis-harness/scripts/create-adr.sh +74 -74
- package/.codex/skills/genesis-harness/scripts/create-bug.sh +160 -160
- package/.codex/skills/genesis-harness/scripts/create-feature.sh +217 -217
- package/.codex/skills/genesis-harness/scripts/detect-stack.sh +26 -26
- package/.codex/skills/genesis-harness/scripts/init-planning.sh +750 -719
- package/.codex/skills/genesis-harness/scripts/list-changed-files.sh +12 -12
- package/.codex/skills/genesis-harness/scripts/offload-log.sh +72 -0
- package/.codex/skills/genesis-harness/scripts/run-verification.sh +47 -47
- package/.codex/skills/genesis-harness/scripts/run-verify-loop.sh +75 -0
- package/.codex/skills/genesis-harness/scripts/update-state.sh +33 -33
- package/.codex/skills/genesis-harness-engineering/SKILL.md +159 -0
- package/.codex/skills/genesis-harness-engineering/checklists/checklist.md +48 -0
- package/.codex/skills/genesis-harness-engineering/examples/example.md +57 -0
- package/.codex/skills/genesis-harness-engineering/playbooks/harness-evolution.md +99 -0
- package/.codex/skills/genesis-harness-engineering/templates/harness-change-template.md +37 -0
- package/.codex/skills/genesis-observability-automation/SKILL.md +382 -0
- package/.codex/skills/genesis-observability-automation/agents/openai.yaml +7 -0
- package/.codex/skills/genesis-observability-automation/examples/example.md +86 -0
- package/.codex/skills/genesis-performance-profiling/SKILL.md +510 -0
- package/.codex/skills/genesis-performance-profiling/agents/openai.yaml +6 -0
- package/.codex/skills/genesis-performance-profiling/checklists/optimization-verification.md +199 -0
- package/.codex/skills/genesis-performance-profiling/checklists/performance-baseline.md +183 -0
- package/.codex/skills/genesis-performance-profiling/examples/example.md +234 -0
- package/.codex/skills/genesis-performance-profiling/observability/performance-tracking.md +202 -0
- package/.codex/skills/genesis-performance-profiling/playbooks/load-testing-orchestration.md +593 -0
- package/.codex/skills/genesis-performance-profiling/playbooks/profiling-playbook.md +601 -0
- package/.codex/skills/genesis-performance-profiling/templates/load-test-config-template.md +428 -0
- package/.codex/skills/genesis-performance-profiling/templates/performance-report-template.md +238 -0
- package/.codex/skills/genesis-release-orchestration/SKILL.md +653 -0
- package/.codex/skills/genesis-release-orchestration/agents/openai.yaml +7 -0
- package/.codex/skills/genesis-release-orchestration/checklists/post-deployment-verification.md +274 -0
- package/.codex/skills/genesis-release-orchestration/checklists/pre-release-validation.md +220 -0
- package/.codex/skills/genesis-release-orchestration/examples/example.md +78 -0
- package/.codex/skills/genesis-release-orchestration/observability/release-tracking.md +253 -0
- package/.codex/skills/genesis-release-orchestration/playbooks/canary-deployment-orchestration.md +472 -0
- package/.codex/skills/genesis-release-orchestration/playbooks/semantic-versioning-automation.md +494 -0
- package/.codex/skills/genesis-release-orchestration/templates/deployment-strategy-template.md +303 -0
- package/.codex/skills/genesis-release-orchestration/templates/release-runbook-template.md +420 -0
- package/.codex/skills/genesis-research-first/SKILL.md +237 -0
- package/.codex/skills/genesis-research-first/agents/openai.yaml +7 -0
- package/.codex/skills/genesis-research-first/examples/example.md +85 -0
- package/.codex/skills/genesis-spec-propagation/SKILL.md +534 -0
- package/.codex/skills/genesis-spec-propagation/agents/openai.yaml +7 -0
- package/.codex/skills/genesis-spec-propagation/checklists/phase-update-verification.md +384 -0
- package/.codex/skills/genesis-spec-propagation/checklists/spec-change-detection.md +257 -0
- package/.codex/skills/genesis-spec-propagation/examples/example.md +63 -0
- package/.codex/skills/genesis-spec-propagation/observability/propagation-tracking.md +373 -0
- package/.codex/skills/genesis-spec-propagation/playbooks/breaking-change-propagation.md +692 -0
- package/.codex/skills/genesis-spec-propagation/playbooks/feature-change-propagation.md +434 -0
- package/.codex/skills/genesis-spec-propagation/templates/migration-guide-template.md +407 -0
- package/.codex/skills/spec-impact-engine/SKILL.md +504 -0
- package/.codex/skills/spec-impact-engine/agents/openai.yaml +7 -0
- package/.codex/skills/spec-impact-engine/detect-spec-changes.sh +262 -0
- package/.codex/skills/spec-impact-engine/examples/example.md +98 -0
- package/.codex/skills/spec-impact-engine/templates/impact-report.md +248 -0
- package/.codex/skills/spec-impact-engine/templates/migration-guide.md +223 -0
- package/.codex-plugin/plugin.json +1 -1
- package/README.EN.md +719 -0
- package/README.VI.md +712 -0
- package/README.md +261 -107
- package/VERSION +1 -1
- package/bin/genesis-harness.js +20 -11
- package/package.json +1 -1
- package/scripts/README.md +342 -0
- package/scripts/compact-context.sh +54 -0
- package/scripts/detect-changes.sh +152 -0
- package/scripts/install.sh +50 -41
- package/scripts/offload-log.sh +72 -0
- package/scripts/run-evals.sh +70 -43
- package/scripts/run-verify-loop.sh +75 -0
- package/scripts/uninstall.sh +52 -43
- package/scripts/verify.sh +165 -73
- package/.codex/skills/harness-engineering-skill/SKILL.md +0 -45
- package/.codex/skills/harness-engineering-skill/checklists/checklist.md +0 -8
- package/.codex/skills/harness-engineering-skill/examples/example.md +0 -4
- package/.codex/skills/harness-engineering-skill/templates/harness-change-template.md +0 -8
- /package/.codex/skills/{ai-provider-skill → genesis-ai-provider}/SKILL.md +0 -0
- /package/.codex/skills/{ai-provider-skill → genesis-ai-provider}/agents/openai.yaml +0 -0
- /package/.codex/skills/{ai-provider-skill → genesis-ai-provider}/checklists/checklist.md +0 -0
- /package/.codex/skills/{ai-provider-skill → genesis-ai-provider}/examples/example.md +0 -0
- /package/.codex/skills/{ai-provider-skill → genesis-ai-provider}/templates/provider-contract-template.md +0 -0
- /package/.codex/skills/{api-contract-skill → genesis-api-contract}/SKILL.md +0 -0
- /package/.codex/skills/{api-contract-skill → genesis-api-contract}/agents/openai.yaml +0 -0
- /package/.codex/skills/{api-contract-skill → genesis-api-contract}/checklists/checklist.md +0 -0
- /package/.codex/skills/{api-contract-skill → genesis-api-contract}/examples/example.md +0 -0
- /package/.codex/skills/{api-contract-skill → genesis-api-contract}/templates/api-contract-template.md +0 -0
- /package/.codex/skills/{architecture-skill → genesis-architecture}/SKILL.md +0 -0
- /package/.codex/skills/{architecture-skill → genesis-architecture}/agents/openai.yaml +0 -0
- /package/.codex/skills/{architecture-skill → genesis-architecture}/checklists/checklist.md +0 -0
- /package/.codex/skills/{architecture-skill → genesis-architecture}/examples/example.md +0 -0
- /package/.codex/skills/{architecture-skill → genesis-architecture}/templates/architecture-decision-template.md +0 -0
- /package/.codex/skills/{codebase-map-skill → genesis-codebase-map}/SKILL.md +0 -0
- /package/.codex/skills/{codebase-map-skill → genesis-codebase-map}/agents/openai.yaml +0 -0
- /package/.codex/skills/{codebase-map-skill → genesis-codebase-map}/checklists/checklist.md +0 -0
- /package/.codex/skills/{codebase-map-skill → genesis-codebase-map}/examples/example.md +0 -0
- /package/.codex/skills/{codebase-map-skill → genesis-codebase-map}/templates/map-update-template.md +0 -0
- /package/.codex/skills/{design-spec-skill → genesis-design-spec}/SKILL.md +0 -0
- /package/.codex/skills/{design-spec-skill → genesis-design-spec}/agents/openai.yaml +0 -0
- /package/.codex/skills/{design-spec-skill → genesis-design-spec}/checklists/checklist.md +0 -0
- /package/.codex/skills/{design-spec-skill → genesis-design-spec}/examples/example.md +0 -0
- /package/.codex/skills/{design-spec-skill → genesis-design-spec}/templates/design-spec-template.md +0 -0
- /package/.codex/skills/{docs-skill → genesis-docs}/SKILL.md +0 -0
- /package/.codex/skills/{docs-skill → genesis-docs}/agents/openai.yaml +0 -0
- /package/.codex/skills/{docs-skill → genesis-docs}/checklists/checklist.md +0 -0
- /package/.codex/skills/{docs-skill → genesis-docs}/examples/example.md +0 -0
- /package/.codex/skills/{docs-skill → genesis-docs}/templates/docs-update-template.md +0 -0
- /package/.codex/skills/{harness-engineering-skill → genesis-harness-engineering}/agents/openai.yaml +0 -0
- /package/.codex/skills/{pipeline-orchestration-skill → genesis-pipeline-orchestration}/SKILL.md +0 -0
- /package/.codex/skills/{pipeline-orchestration-skill → genesis-pipeline-orchestration}/agents/openai.yaml +0 -0
- /package/.codex/skills/{pipeline-orchestration-skill → genesis-pipeline-orchestration}/checklists/checklist.md +0 -0
- /package/.codex/skills/{pipeline-orchestration-skill → genesis-pipeline-orchestration}/examples/example.md +0 -0
- /package/.codex/skills/{pipeline-orchestration-skill → genesis-pipeline-orchestration}/templates/orchestration-template.md +0 -0
- /package/.codex/skills/{planning-skill → genesis-planning}/SKILL.md +0 -0
- /package/.codex/skills/{planning-skill → genesis-planning}/agents/openai.yaml +0 -0
- /package/.codex/skills/{planning-skill → genesis-planning}/checklists/checklist.md +0 -0
- /package/.codex/skills/{planning-skill → genesis-planning}/examples/example.md +0 -0
- /package/.codex/skills/{planning-skill → genesis-planning}/templates/plan-template.md +0 -0
- /package/.codex/skills/{release-skill → genesis-release}/SKILL.md +0 -0
- /package/.codex/skills/{release-skill → genesis-release}/agents/openai.yaml +0 -0
- /package/.codex/skills/{release-skill → genesis-release}/checklists/checklist.md +0 -0
- /package/.codex/skills/{release-skill → genesis-release}/examples/example.md +0 -0
- /package/.codex/skills/{release-skill → genesis-release}/templates/release-checklist-template.md +0 -0
- /package/.codex/skills/{research-skill → genesis-research}/SKILL.md +0 -0
- /package/.codex/skills/{research-skill → genesis-research}/agents/openai.yaml +0 -0
- /package/.codex/skills/{research-skill → genesis-research}/checklists/checklist.md +0 -0
- /package/.codex/skills/{research-skill → genesis-research}/examples/example.md +0 -0
- /package/.codex/skills/{research-skill → genesis-research}/templates/research-note-template.md +0 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Example: Debugging a Failing Unit Test
|
|
2
|
+
|
|
3
|
+
## Scenario
|
|
4
|
+
|
|
5
|
+
A unit test for the `UserService.createUser()` method suddenly fails with:
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
AssertionError: expected undefined but got "john@example.com"
|
|
9
|
+
Expected: undefined
|
|
10
|
+
Received: "john@example.com"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Using genesis-debug-guide
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
/debug "UserService createUser test failing - expects undefined, gets email string"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Workflow Executed
|
|
20
|
+
|
|
21
|
+
1. **Isolation** — Run only the failing test:
|
|
22
|
+
```bash
|
|
23
|
+
npx jest UserService.test.ts --testNamePattern="createUser"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
2. **Mock inspection** — Found that mock setup for `EmailValidator` returns full user object instead of `null` for invalid input.
|
|
27
|
+
|
|
28
|
+
3. **Root cause** — `EmailValidator` mock was updated to return `{ email }` but test still expected `undefined`.
|
|
29
|
+
|
|
30
|
+
4. **Fix** — Updated mock to align with new `EmailValidator` interface:
|
|
31
|
+
```ts
|
|
32
|
+
jest.mock('./EmailValidator', () => ({ validate: () => undefined }));
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
5. **Regression test** — Added assertion for both valid and invalid email inputs.
|
|
36
|
+
|
|
37
|
+
6. **Verification** — Full test suite passes; debug log cleaned up.
|
|
38
|
+
|
|
39
|
+
## Debug Investigation Log
|
|
40
|
+
|
|
41
|
+
Saved to: `observability/agent-runs/debug-2026-05-31.md`
|
|
42
|
+
|
|
43
|
+
## Outcome
|
|
44
|
+
|
|
45
|
+
- ✅ Root cause documented
|
|
46
|
+
- ✅ Fix minimal (1 line in test mock)
|
|
47
|
+
- ✅ Regression test added
|
|
48
|
+
- ✅ No debug code left in implementation
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
# Debug Commands by Language
|
|
2
|
+
|
|
3
|
+
Quick reference for debugging commands in different languages used in Genesis projects.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Node.js / JavaScript
|
|
8
|
+
|
|
9
|
+
### Console Methods
|
|
10
|
+
```javascript
|
|
11
|
+
// Information
|
|
12
|
+
console.log('Message:', value);
|
|
13
|
+
console.info('Info message');
|
|
14
|
+
console.warn('Warning message');
|
|
15
|
+
console.error('Error message');
|
|
16
|
+
|
|
17
|
+
// Structured
|
|
18
|
+
console.table([{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }]);
|
|
19
|
+
console.dir(object);
|
|
20
|
+
|
|
21
|
+
// Timing
|
|
22
|
+
console.time('label');
|
|
23
|
+
// ... code ...
|
|
24
|
+
console.timeEnd('label'); // Outputs: label: 1234.56ms
|
|
25
|
+
|
|
26
|
+
// Assertions
|
|
27
|
+
console.assert(condition, 'Message if assertion fails');
|
|
28
|
+
|
|
29
|
+
// Trace
|
|
30
|
+
console.trace('Stack trace at this point');
|
|
31
|
+
|
|
32
|
+
// Groups
|
|
33
|
+
console.group('Group label');
|
|
34
|
+
console.log('...logs in group...');
|
|
35
|
+
console.groupEnd();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Debugging CLI
|
|
39
|
+
```bash
|
|
40
|
+
# Run with Node inspector
|
|
41
|
+
node --inspect script.js
|
|
42
|
+
node --inspect-brk script.js # Breaks on first line
|
|
43
|
+
|
|
44
|
+
# Run Jest with debugging
|
|
45
|
+
node --inspect-brk node_modules/.bin/jest --runInBand test.js
|
|
46
|
+
|
|
47
|
+
# Open Chrome DevTools: chrome://inspect
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Jest/Test Debugging
|
|
51
|
+
```javascript
|
|
52
|
+
test('example', () => {
|
|
53
|
+
debugger; // Browser debugger breakpoint (if using inspect)
|
|
54
|
+
expect(value).toBe(expected);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Skip a test
|
|
58
|
+
test.skip('should do something', () => {});
|
|
59
|
+
|
|
60
|
+
// Only run this test
|
|
61
|
+
test.only('should do something', () => {});
|
|
62
|
+
|
|
63
|
+
// Print all mocks
|
|
64
|
+
console.log(jest.fn.mock.calls);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Python
|
|
70
|
+
|
|
71
|
+
### Print Debugging
|
|
72
|
+
```python
|
|
73
|
+
print(f"Value: {value}")
|
|
74
|
+
print(f"Type: {type(value)}")
|
|
75
|
+
print(f"Dict keys: {obj.__dict__}")
|
|
76
|
+
|
|
77
|
+
# Pretty print
|
|
78
|
+
import pprint
|
|
79
|
+
pprint.pprint(large_dict)
|
|
80
|
+
|
|
81
|
+
# JSON
|
|
82
|
+
import json
|
|
83
|
+
print(json.dumps(obj, indent=2))
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Logging
|
|
87
|
+
```python
|
|
88
|
+
import logging
|
|
89
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
90
|
+
logger = logging.getLogger(__name__)
|
|
91
|
+
|
|
92
|
+
logger.debug('Debug message')
|
|
93
|
+
logger.info('Info message')
|
|
94
|
+
logger.warning('Warning message')
|
|
95
|
+
logger.error('Error message')
|
|
96
|
+
|
|
97
|
+
# With context
|
|
98
|
+
logger.info(f'Processing user {user_id}: {user.name}')
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Interactive Debugging
|
|
102
|
+
```python
|
|
103
|
+
# PDB - Python Debugger
|
|
104
|
+
import pdb
|
|
105
|
+
pdb.set_trace() # Breakpoint - enters debugger here
|
|
106
|
+
|
|
107
|
+
# Or:
|
|
108
|
+
breakpoint() # Python 3.7+
|
|
109
|
+
|
|
110
|
+
# IPython for interactive shell
|
|
111
|
+
from IPython import embed
|
|
112
|
+
embed() # Opens interactive IPython shell
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Testing
|
|
116
|
+
```python
|
|
117
|
+
import unittest
|
|
118
|
+
|
|
119
|
+
# Skip test
|
|
120
|
+
@unittest.skip("Not implemented")
|
|
121
|
+
def test_something(self):
|
|
122
|
+
pass
|
|
123
|
+
|
|
124
|
+
# Print test details
|
|
125
|
+
python -m pytest -v -s test.py # -v verbose, -s show print statements
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## PHP
|
|
131
|
+
|
|
132
|
+
### Echo/Print
|
|
133
|
+
```php
|
|
134
|
+
echo "Simple output";
|
|
135
|
+
print_r($array); // For arrays/objects
|
|
136
|
+
var_dump($variable); // Detailed dump with types
|
|
137
|
+
var_export($variable); // Machine-readable format
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Error Reporting
|
|
141
|
+
```php
|
|
142
|
+
// Set error level
|
|
143
|
+
ini_set('display_errors', 1);
|
|
144
|
+
error_reporting(E_ALL);
|
|
145
|
+
|
|
146
|
+
// Log to file
|
|
147
|
+
error_log("Debug message", 3, "/tmp/debug.log");
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Debugging Tools
|
|
151
|
+
```php
|
|
152
|
+
// Xdebug extension (if installed)
|
|
153
|
+
var_dump($variable); // With Xdebug: shows enhanced output
|
|
154
|
+
|
|
155
|
+
// Fire up debugger breakpoint
|
|
156
|
+
xdebug_break();
|
|
157
|
+
|
|
158
|
+
// Stack trace
|
|
159
|
+
debug_backtrace();
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Laravel Specific
|
|
163
|
+
```php
|
|
164
|
+
// Log helper
|
|
165
|
+
\Log::debug('Message', ['key' => $value]);
|
|
166
|
+
\Log::channel('single')->debug('Message');
|
|
167
|
+
|
|
168
|
+
// Dump and die
|
|
169
|
+
dd($variable);
|
|
170
|
+
|
|
171
|
+
// Dump without dying
|
|
172
|
+
dump($variable);
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## Ruby
|
|
178
|
+
|
|
179
|
+
### Print Debugging
|
|
180
|
+
```ruby
|
|
181
|
+
puts "Message: #{value}"
|
|
182
|
+
p variable # Inspect format (like Ruby console)
|
|
183
|
+
pp object # Pretty print (requires 'pp')
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Debugging
|
|
187
|
+
```ruby
|
|
188
|
+
# Byebug debugger
|
|
189
|
+
require 'byebug'
|
|
190
|
+
byebug # Breakpoint - enters debugger
|
|
191
|
+
|
|
192
|
+
# Pry (better interactive console)
|
|
193
|
+
require 'pry'
|
|
194
|
+
binding.pry # Open Pry console here
|
|
195
|
+
|
|
196
|
+
# Interactive shell
|
|
197
|
+
irb # Interactive Ruby shell
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Logging
|
|
201
|
+
```ruby
|
|
202
|
+
require 'logger'
|
|
203
|
+
logger = Logger.new(STDOUT)
|
|
204
|
+
logger.debug("Debug message")
|
|
205
|
+
logger.info("Info message")
|
|
206
|
+
|
|
207
|
+
# Rails logging
|
|
208
|
+
Rails.logger.debug("Message")
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Testing
|
|
212
|
+
```bash
|
|
213
|
+
# Run single test
|
|
214
|
+
ruby -I lib test/test_name.rb
|
|
215
|
+
|
|
216
|
+
# Run with debugging
|
|
217
|
+
ruby -r pry -I lib test/test_name.rb
|
|
218
|
+
|
|
219
|
+
# Rspec with debugging
|
|
220
|
+
rspec test_file.rb --format documentation
|
|
221
|
+
rspec test_file.rb -e "test name" # Run specific test
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## Go
|
|
227
|
+
|
|
228
|
+
### Logging
|
|
229
|
+
```go
|
|
230
|
+
import "log"
|
|
231
|
+
|
|
232
|
+
log.Println("Standard output")
|
|
233
|
+
log.Printf("Formatted: %v, %s", value, text)
|
|
234
|
+
log.Fatalf("Fatal error: %v", err) // Prints and exits
|
|
235
|
+
|
|
236
|
+
// Structured logging (with external package)
|
|
237
|
+
import "github.com/sirupsen/logrus"
|
|
238
|
+
log.WithField("user_id", id).Debug("User action")
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Debugging
|
|
242
|
+
```go
|
|
243
|
+
// Delve debugger
|
|
244
|
+
import _ "net/http/pprof"
|
|
245
|
+
|
|
246
|
+
// Profiling
|
|
247
|
+
import "runtime/pprof"
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Testing
|
|
251
|
+
```bash
|
|
252
|
+
# Run tests with verbose output
|
|
253
|
+
go test -v ./...
|
|
254
|
+
|
|
255
|
+
# Run single test
|
|
256
|
+
go test -run TestName ./...
|
|
257
|
+
|
|
258
|
+
# Show coverage
|
|
259
|
+
go test -cover ./...
|
|
260
|
+
|
|
261
|
+
# Debug test with dlv
|
|
262
|
+
dlv test ./package -- -test.v -test.run TestName
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## System / Performance Debugging
|
|
268
|
+
|
|
269
|
+
### Check System Load
|
|
270
|
+
```bash
|
|
271
|
+
# Unix/Linux/macOS
|
|
272
|
+
top # Real-time CPU/Memory usage
|
|
273
|
+
htop # Better interface for top
|
|
274
|
+
ps aux # List all processes
|
|
275
|
+
uptime # System load average
|
|
276
|
+
|
|
277
|
+
# Network
|
|
278
|
+
netstat -tuln # Listen ports
|
|
279
|
+
lsof -i :8000 # Processes using port 8000
|
|
280
|
+
|
|
281
|
+
# File I/O
|
|
282
|
+
iotop # I/O by process
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Check Application Ports
|
|
286
|
+
```bash
|
|
287
|
+
# See if port is in use
|
|
288
|
+
lsof -i :3000
|
|
289
|
+
netstat -tulpn | grep 3000
|
|
290
|
+
|
|
291
|
+
# Kill process on port
|
|
292
|
+
kill -9 $(lsof -t -i :3000)
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Trace System Calls
|
|
296
|
+
```bash
|
|
297
|
+
# Linux
|
|
298
|
+
strace command # Show system calls
|
|
299
|
+
strace -e trace=network command # Network calls only
|
|
300
|
+
|
|
301
|
+
# macOS
|
|
302
|
+
dtruss command # Similar to strace
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## Browser DevTools
|
|
308
|
+
|
|
309
|
+
### Chrome/Edge DevTools
|
|
310
|
+
```javascript
|
|
311
|
+
// Keyboard shortcuts
|
|
312
|
+
F12 or Ctrl+Shift+I // Open DevTools
|
|
313
|
+
Ctrl+Shift+J // Console
|
|
314
|
+
Ctrl+Shift+C // Element picker
|
|
315
|
+
Ctrl+Shift+M // Device mode
|
|
316
|
+
|
|
317
|
+
// Console commands
|
|
318
|
+
console.log(...)
|
|
319
|
+
console.time('label')
|
|
320
|
+
console.assert(condition, 'message')
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### Break on Error
|
|
324
|
+
```javascript
|
|
325
|
+
// Pause on all exceptions
|
|
326
|
+
DevTools → Sources → Pause on exceptions (icon with triangle)
|
|
327
|
+
|
|
328
|
+
// Break on specific line
|
|
329
|
+
DevTools → Sources → Click line number to set breakpoint
|
|
330
|
+
|
|
331
|
+
// Conditional breakpoint
|
|
332
|
+
Right-click line → Add conditional breakpoint → Condition
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
## Environment Inspection
|
|
338
|
+
|
|
339
|
+
### Check Environment
|
|
340
|
+
```bash
|
|
341
|
+
# Node.js
|
|
342
|
+
node -e "console.log(process.versions)"
|
|
343
|
+
|
|
344
|
+
# Python
|
|
345
|
+
python -c "import sys; print(sys.version)"
|
|
346
|
+
|
|
347
|
+
# Check installed packages
|
|
348
|
+
npm list # Node
|
|
349
|
+
pip list # Python
|
|
350
|
+
gem list # Ruby
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### Debug Environment Variables
|
|
354
|
+
```bash
|
|
355
|
+
# Show all env vars
|
|
356
|
+
env | sort
|
|
357
|
+
echo $PATH
|
|
358
|
+
|
|
359
|
+
# Node.js
|
|
360
|
+
console.log(process.env.NODE_ENV)
|
|
361
|
+
|
|
362
|
+
# Python
|
|
363
|
+
import os
|
|
364
|
+
print(os.environ.get('DATABASE_URL'))
|
|
365
|
+
```
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
# Unit Test Failures - Debugging Playbook
|
|
2
|
+
|
|
3
|
+
**Purpose**: Systematic approach to debugging unit test failures. Unit tests are isolated and deterministic, so failures are usually in test setup, mocks, or implementation logic.
|
|
4
|
+
|
|
5
|
+
**Trigger**: When a unit test fails consistently
|
|
6
|
+
|
|
7
|
+
**Duration**: 5-15 minutes typically
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Step 1: Isolate the Failure (2-3 min)
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Run ONLY the failing test
|
|
15
|
+
npm test -- path/to/test.test.js
|
|
16
|
+
|
|
17
|
+
# Verify it fails every time
|
|
18
|
+
npm test -- path/to/test.test.js
|
|
19
|
+
npm test -- path/to/test.test.js
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Check**:
|
|
23
|
+
- ✅ Fails same way every run? → Deterministic, proceed
|
|
24
|
+
- ❌ Fails sometimes? → See flaky-test-investigation.md
|
|
25
|
+
- ❌ Passes on retry? → Environment issue, check dependencies
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Step 2: Understand the Failure (2-3 min)
|
|
30
|
+
|
|
31
|
+
Read the error message **completely**:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
FAIL src/utils/__tests__/parseDate.test.js
|
|
35
|
+
parseDate()
|
|
36
|
+
✓ should parse valid ISO date
|
|
37
|
+
✗ should return null for invalid date
|
|
38
|
+
Expected: null
|
|
39
|
+
Received: "Invalid Date"
|
|
40
|
+
at Object.<anonymous> (src/utils/__tests__/parseDate.test.js:15:5)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Extract**:
|
|
44
|
+
- Test name: "should return null for invalid date"
|
|
45
|
+
- Expected: `null`
|
|
46
|
+
- Received: `"Invalid Date"` (string, not null!)
|
|
47
|
+
- File & line: `parseDate.test.js:15`
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Step 3: Review Test Code (3-4 min)
|
|
52
|
+
|
|
53
|
+
Open the test file and find the failing test:
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
// parseDate.test.js line 15
|
|
57
|
+
test('should return null for invalid date', () => {
|
|
58
|
+
const result = parseDate('not-a-date');
|
|
59
|
+
expect(result).toBe(null); // ← Expectation at line 15
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**Questions**:
|
|
64
|
+
- [ ] Is test setup correct? (line 1-5)
|
|
65
|
+
- [ ] Are mocks configured properly? (if any)
|
|
66
|
+
- [ ] Is the assertion testing the right thing?
|
|
67
|
+
- [ ] Could test data be wrong?
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Step 4: Review Implementation (3-4 min)
|
|
72
|
+
|
|
73
|
+
Find the function being tested:
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
// parseDate.js
|
|
77
|
+
export function parseDate(dateString) {
|
|
78
|
+
const date = new Date(dateString);
|
|
79
|
+
if (isNaN(date.getTime())) {
|
|
80
|
+
return 'Invalid Date'; // ← BUG! Should return null
|
|
81
|
+
}
|
|
82
|
+
return date;
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Questions**:
|
|
87
|
+
- [ ] Does function return correct type? (null vs "Invalid Date")
|
|
88
|
+
- [ ] Does logic match test expectations?
|
|
89
|
+
- [ ] Are there other callers expecting different behavior?
|
|
90
|
+
- [ ] Any recent changes to this function? (git blame)
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Step 5: Fix the Bug (1-2 min)
|
|
95
|
+
|
|
96
|
+
**Option A: Fix is in implementation**
|
|
97
|
+
```javascript
|
|
98
|
+
// WRONG: returns string
|
|
99
|
+
return 'Invalid Date';
|
|
100
|
+
|
|
101
|
+
// CORRECT: returns null
|
|
102
|
+
return null;
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Option B: Fix is in test**
|
|
106
|
+
```javascript
|
|
107
|
+
// If implementation is correct, test is wrong
|
|
108
|
+
expect(result).toBe('Invalid Date'); // Update test
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Option C: Fix is in mock setup**
|
|
112
|
+
```javascript
|
|
113
|
+
// Mock not configured correctly
|
|
114
|
+
const mockFetch = jest.fn().mockResolvedValue({ ok: true });
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Rule**: Fix only ONE thing per fix. Don't refactor while fixing.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Step 6: Verify Fix (1-2 min)
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
# Run failing test - should now PASS
|
|
125
|
+
npm test -- path/to/test.test.js
|
|
126
|
+
|
|
127
|
+
# Run full test suite - all should PASS
|
|
128
|
+
npm test
|
|
129
|
+
|
|
130
|
+
# Check: no new failures
|
|
131
|
+
# Check: no debug code left (console.log, debugger)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Step 7: Add Prevention (2-3 min)
|
|
137
|
+
|
|
138
|
+
**Similar bugs to prevent**:
|
|
139
|
+
- [ ] Add test for related edge cases
|
|
140
|
+
- [ ] Add test for null/undefined inputs
|
|
141
|
+
- [ ] Add test for wrong type inputs
|
|
142
|
+
- [ ] Add test for boundary values
|
|
143
|
+
|
|
144
|
+
```javascript
|
|
145
|
+
test('should handle null input', () => {
|
|
146
|
+
expect(parseDate(null)).toBe(null);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('should handle undefined input', () => {
|
|
150
|
+
expect(parseDate(undefined)).toBe(null);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('should handle empty string', () => {
|
|
154
|
+
expect(parseDate('')).toBe(null);
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Common Unit Test Issues
|
|
161
|
+
|
|
162
|
+
### 1. Mock Not Configured
|
|
163
|
+
```javascript
|
|
164
|
+
// ❌ WRONG: mock returns undefined
|
|
165
|
+
const mock = jest.fn();
|
|
166
|
+
|
|
167
|
+
// ✅ CORRECT: mock returns expected value
|
|
168
|
+
const mock = jest.fn().mockReturnValue({ id: 1, name: 'Test' });
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### 2. Wrong Import
|
|
172
|
+
```javascript
|
|
173
|
+
// ❌ WRONG: importing test mock
|
|
174
|
+
import parseDate from './parseDate.mock.js';
|
|
175
|
+
|
|
176
|
+
// ✅ CORRECT: importing actual implementation
|
|
177
|
+
import { parseDate } from './parseDate.js';
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### 3. Test Data Type Mismatch
|
|
181
|
+
```javascript
|
|
182
|
+
// ❌ WRONG: passing wrong type
|
|
183
|
+
parseDate(123456); // Passing number, expects string
|
|
184
|
+
|
|
185
|
+
// ✅ CORRECT: passing correct type
|
|
186
|
+
parseDate('2024-01-01'); // Passing string
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### 4. Shared State Between Tests
|
|
190
|
+
```javascript
|
|
191
|
+
// ❌ WRONG: variable shared across tests
|
|
192
|
+
let counter = 0;
|
|
193
|
+
test('test 1', () => { counter++; });
|
|
194
|
+
test('test 2', () => { expect(counter).toBe(1); }); // Fails if test 1 ran first!
|
|
195
|
+
|
|
196
|
+
// ✅ CORRECT: each test has isolated state
|
|
197
|
+
test('test 1', () => { const counter = 0; counter++; });
|
|
198
|
+
test('test 2', () => { const counter = 0; expect(counter).toBe(0); });
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### 5. Async/Promise Not Awaited
|
|
202
|
+
```javascript
|
|
203
|
+
// ❌ WRONG: not waiting for promise
|
|
204
|
+
test('should fetch user', () => {
|
|
205
|
+
fetchUser(1); // Returns promise, but not awaited
|
|
206
|
+
expect(result).toBe(...); // Runs before promise resolves!
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// ✅ CORRECT: await promise or return from test
|
|
210
|
+
test('should fetch user', async () => {
|
|
211
|
+
const result = await fetchUser(1);
|
|
212
|
+
expect(result).toBe(...);
|
|
213
|
+
});
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Debugging Strategy by Test Type
|
|
219
|
+
|
|
220
|
+
### Simple Unit (pure function)
|
|
221
|
+
1. Check inputs match implementation
|
|
222
|
+
2. Check return type
|
|
223
|
+
3. Check logic handles edge cases
|
|
224
|
+
4. Add edge case tests
|
|
225
|
+
|
|
226
|
+
### Function with Dependencies
|
|
227
|
+
1. Check mocks are configured
|
|
228
|
+
2. Check mock is called correctly
|
|
229
|
+
3. Check mock return value used
|
|
230
|
+
4. Verify mock reset between tests
|
|
231
|
+
|
|
232
|
+
### Class/Object Method
|
|
233
|
+
1. Check class instantiation
|
|
234
|
+
2. Check method parameters
|
|
235
|
+
3. Check state after method call
|
|
236
|
+
4. Check side effects (if any)
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## Recovery: Still Can't Find Bug?
|
|
241
|
+
|
|
242
|
+
If stuck for >10 minutes:
|
|
243
|
+
|
|
244
|
+
1. **Add debug logging**:
|
|
245
|
+
```javascript
|
|
246
|
+
test('test name', () => {
|
|
247
|
+
console.log('Input:', input);
|
|
248
|
+
const result = parseDate(input);
|
|
249
|
+
console.log('Result:', result);
|
|
250
|
+
console.log('Expected:', expectedValue);
|
|
251
|
+
expect(result).toBe(expectedValue);
|
|
252
|
+
});
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
2. **Simplify test**:
|
|
256
|
+
```javascript
|
|
257
|
+
// Remove test setup, use hardcoded values
|
|
258
|
+
test('test name', () => {
|
|
259
|
+
const result = parseDate('2024-01-01');
|
|
260
|
+
expect(result).toEqual({ year: 2024, month: 1, day: 1 });
|
|
261
|
+
});
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
3. **Check git history**:
|
|
265
|
+
```bash
|
|
266
|
+
git log -p -- path/to/test.js
|
|
267
|
+
git log -p -- path/to/implementation.js
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
4. **Run with debugging**:
|
|
271
|
+
```bash
|
|
272
|
+
node --inspect-brk node_modules/.bin/jest --runInBand path/to/test.js
|
|
273
|
+
# Opens Chrome DevTools for debugging
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## Checklist: Ready to Complete
|
|
279
|
+
|
|
280
|
+
- [ ] Test fails in isolation
|
|
281
|
+
- [ ] Error message understood
|
|
282
|
+
- [ ] Test code reviewed
|
|
283
|
+
- [ ] Implementation reviewed
|
|
284
|
+
- [ ] Bug fixed (one thing only)
|
|
285
|
+
- [ ] Test passes
|
|
286
|
+
- [ ] Full suite passes
|
|
287
|
+
- [ ] No debug code left
|
|
288
|
+
- [ ] Edge case tests added
|
|
289
|
+
- [ ] Ready to commit
|