|
| 1 | +# Bug fixing skill — github-code-search |
| 2 | + |
| 3 | +Deep reference for diagnosing and fixing bugs in this codebase. |
| 4 | +This skill complements `.github/instructions/bug-fixing.instructions.md`. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## Symptom → module diagnostic table |
| 9 | + |
| 10 | +| Symptom | Primary suspect | Secondary suspect | |
| 11 | +| ----------------------------------------------------------- | ----------------------------------------------- | --------------------------------- | |
| 12 | +| Results missing or duplicated | `src/aggregate.ts` | `src/api.ts` (pagination) | |
| 13 | +| Wrong repository grouping | `src/group.ts` | `src/aggregate.ts` | |
| 14 | +| `--exclude-repositories` / `--exclude-extracts` not working | `src/aggregate.ts` | `github-code-search.ts` (parsing) | |
| 15 | +| Markdown output malformed | `src/output.ts` | — | |
| 16 | +| JSON output missing fields or wrong shape | `src/output.ts` | `src/types.ts` (interface) | |
| 17 | +| Syntax highlighting wrong colour / wrong language | `src/render/highlight.ts` | — | |
| 18 | +| Row navigation skips or wraps incorrectly | `src/render/rows.ts` | `src/tui.ts` (key handler) | |
| 19 | +| Select-all / select-none inconsistent | `src/render/selection.ts` | `src/tui.ts` | |
| 20 | +| Filter count / stats incorrect | `src/render/filter.ts`, `src/render/summary.ts` | — | |
| 21 | +| Path filter (`/regex/`) doesn't match expected | `src/render/filter-match.ts` | `src/tui.ts` (filter state) | |
| 22 | +| API returns 0 results or stops paginating | `src/api.ts` | `src/api-utils.ts` | |
| 23 | +| Rate limit hit / 429 not retried | `src/api-utils.ts` (`fetchWithRetry`) | — | |
| 24 | +| TUI shows blank screen or wrong row | `src/tui.ts` | `src/render/rows.ts` | |
| 25 | +| Help overlay doesn't appear / has wrong keys | `src/render.ts` (`renderHelpOverlay`) | `src/tui.ts` | |
| 26 | +| Upgrade fails or replaces wrong binary | `src/upgrade.ts` | — | |
| 27 | +| Completion script wrong content | `src/completions.ts` | — | |
| 28 | +| Completion file written to wrong path | `src/completions.ts` (`getCompletionFilePath`) | env vars (`XDG_*`, `ZDOTDIR`) | |
| 29 | +| Completion not refreshed after upgrade | `src/upgrade.ts` (`refreshCompletions`) | — | |
| 30 | +| `--version` shows wrong info | `build.ts` (SHA injection) | — | |
| 31 | +| CLI option ignored or parsed wrong | `github-code-search.ts` | `src/types.ts` (`OutputType`) | |
| 32 | + |
| 33 | +--- |
| 34 | + |
| 35 | +## Reproducing a bug |
| 36 | + |
| 37 | +A complete bug report must have: |
| 38 | + |
| 39 | +1. **Exact command** (redact `GITHUB_TOKEN` with `***`): |
| 40 | + ``` |
| 41 | + GITHUB_TOKEN=*** github-code-search query "pattern" --org acme |
| 42 | + ``` |
| 43 | +2. **Observed output** vs **expected output**. |
| 44 | +3. **Version string**: `github-code-search --version` → e.g. `1.8.0 (a1b2c3d · darwin/arm64)`. |
| 45 | +4. **Bun version** (when running from source): `bun --version`. |
| 46 | + |
| 47 | +If the report is missing items 1 or 3, read the relevant module(s) to hypothesise the root cause before asking for more info. |
| 48 | + |
| 49 | +--- |
| 50 | + |
| 51 | +## Test-first patterns for bugs |
| 52 | + |
| 53 | +### Pure function bug (aggregate, group, output, render/\*) |
| 54 | + |
| 55 | +```typescript |
| 56 | +// src/aggregate.test.ts |
| 57 | +describe("applyFiltersAndExclusions — bug #N", () => { |
| 58 | + it("excludes org-prefixed repo names correctly", () => { |
| 59 | + const result = applyFiltersAndExclusions(matches, { |
| 60 | + excludeRepositories: ["acme/my-repo"], // the previously broken form |
| 61 | + }); |
| 62 | + expect(result).not.toContainEqual(expect.objectContaining({ repo: "acme/my-repo" })); |
| 63 | + }); |
| 64 | +}); |
| 65 | +``` |
| 66 | + |
| 67 | +The test must **fail** with the current code before the fix. Commit the test, then fix. |
| 68 | + |
| 69 | +### api-utils bug (retry / pagination) |
| 70 | + |
| 71 | +```typescript |
| 72 | +// src/api-utils.test.ts |
| 73 | +it("retries on 429 with Retry-After header", async () => { |
| 74 | + let callCount = 0; |
| 75 | + globalThis.fetch = async () => { |
| 76 | + callCount++; |
| 77 | + if (callCount === 1) { |
| 78 | + return new Response(null, { |
| 79 | + status: 429, |
| 80 | + headers: { "Retry-After": "0" }, |
| 81 | + }); |
| 82 | + } |
| 83 | + return new Response(JSON.stringify({ ok: true }), { status: 200 }); |
| 84 | + }; |
| 85 | + await fetchWithRetry("https://api.github.com/test"); |
| 86 | + expect(callCount).toBe(2); |
| 87 | +}); |
| 88 | +``` |
| 89 | + |
| 90 | +### Side-effectful bug (tui, api) — no unit test possible |
| 91 | + |
| 92 | +Document manual repro steps in the PR description: |
| 93 | + |
| 94 | +```markdown |
| 95 | +## Steps to reproduce (before fix) |
| 96 | + |
| 97 | +1. `GITHUB_TOKEN=... github-code-search query "foo" --org acme` |
| 98 | +2. Press `↓` past the last result |
| 99 | +3. Expected: cursor stays on last row / Expected: wraps to first row |
| 100 | +4. Observed: cursor jumps to blank row |
| 101 | +``` |
| 102 | + |
| 103 | +--- |
| 104 | + |
| 105 | +## Minimal fix principles |
| 106 | + |
| 107 | +- **Touch only the root cause.** Do not opportunistically refactor neighbouring code in the same PR — it makes the fix harder to review and risks introducing new bugs. |
| 108 | +- **Respect pure/IO layering**: a fix in `aggregate.ts` must not add a `console.log` call. |
| 109 | +- **Type changes cascade**: if `src/types.ts` must change, run `bun run knip` to find all affected consumers and update them all in the same PR. |
| 110 | +- **Regression comment**: if the root cause is non-obvious, add one line above the fix: |
| 111 | + ```typescript |
| 112 | + // Fix: short names ("repo") and qualified names ("org/repo") must both match — see issue #N |
| 113 | + ``` |
| 114 | + |
| 115 | +--- |
| 116 | + |
| 117 | +## Validation after fix |
| 118 | + |
| 119 | +```bash |
| 120 | +bun test # the previously failing test now passes; full suite still green |
| 121 | +bun run lint # oxlint — zero errors |
| 122 | +bun run format:check # oxfmt — no formatting diff |
| 123 | +bun run knip # no unused exports or imports |
| 124 | +bun run build.ts # binary compiles without errors |
| 125 | +``` |
0 commit comments