joinery / docs
Scripts: bugs, duplication and weak code
Closed
docs/audits/2026-09-25-scripts.md · read at 33d1140
- Open
- 0
- Fixed
- 17
- Won't fix
- 13
🔎 Scripts: bugs, duplication and weak code
Context
A static read of infrastructure/scripts, covering every non-spec file under src/. A finding
marked Confirmed was reproduced by calling the module itself from a scratch script (B4, B5, B6),
or by grepping the committed file it describes (Q1). Likely means reasoned from the code and not
reproduced. The rest were read only. Line numbers are as of commit.
0019 was the previous pass over this package, and
anything it settled is left out here. Two examples: the titleCase merge has landed, and the two
currentBranch adapters stay separate by that report's decision.
Bugs
| ID | Where | What goes wrong | Fix | Status |
|---|---|---|---|---|
| B1 | issue/adapters/gh.ts:39 listProjects, shared/adapters/cache.ts:31 cached | Likely. listProjects turns a gh failure into [], and cached writes whatever fetch returns. Scenario: offline, with the project cache more than 24h old. The fetch fails and [] overwrites the cached projects. isOnline() is false, so listProjects(true) reads [] and issue:pick says "No cached projects to fall back to". The offline fallback erases itself the first time it's needed | In cached, skip the write when the fetched value is an empty array, the same guard it already applies on read | fixed |
| B2 | drift/main.ts:52-64 main | Likely. The fingerprint is written to the cache before the warning is shown or answered. After Ctrl+C at "File a GitHub issue?", drift never asks again about that diff. A non-interactive run prints "Run pnpm docs:drift to review", but rerunning it is a no-op because the fingerprint is already stored | Record the fingerprint only once the warning was answered, or when shouldWarn is false. Never record it on the non-interactive branch | fixed |
| B3 | shared/adapters/gh.ts:17-20 createIssue | Likely. assertNotFlagLike is applied to the values of --title and --body. A description starting - [ ] … (a markdown checklist) throws at the very end of issue:add, after the user has typed every field, and their input is lost | Pass --title=${title} / --body=${body} so a leading - can't be read as a flag, and drop the assertion on those values. Keep it for positionals (pr view <branch>, git push origin <branch>) | fixed |
| B4 | shared/adapters/exec.ts:5 run | Confirmed. execFileSync defaults to a 1 MiB maxBuffer. A 2 MiB stdout throws ENOBUFS. drift fingerprints the full git diff of a project (drift/adapters/git.ts:19 diffText), so the large changes drift exists to catch are the ones that crash it | Fingerprint git diff --raw --no-abbrev, whose blob ids stay stable as the repo grows, instead of the full text. Raise maxBuffer in run | fixed |
| B5 | map/domain/capabilities.ts:64 mentions | Confirmed. Only the right edge of the token is guarded. mentions("pnpm test:coverage", "coverage") and mentions("the latest release", "test") both return true, so FEATURES.md can link a doc that never describes the command | Add a (?<![\w:-]) lookbehind, re-render, and treat any new — rows as real doc gaps | fixed |
| B6 | shared/domain/cli.ts:56-66 report | Confirmed. Node already appends stderr to an execFileSync error's message, and so to its stack. detailOf appends it again, so a failing git rev-parse prints its stderr twice | Skip detailOf when the stack already contains that text | fixed |
| B7 | ship/adapters/git.ts:12-14 push | Every push failure becomes "Push rejected — ensure the code passes the push requirements…", and git's stderr is dropped. A missing remote, expired auth and a non-fast-forward all get the wrong reason | Append the caught error's stderr to the ExpectedError | fixed |
| B8 | coverage-report/adapters/nx.ts:34-45 nx | The error handler rejects without closing the fd or removing the temp dir. A throw from readFileSync inside the close handler escapes the promise as an uncaught exception | Clean up in one finally path, and reject on a failed read | wont-fix — spawning process.execPath and reading a file the same function just created do not fail in practice |
| B9 | drift/main.ts:44-45 main | ?? lets an empty env var through. DOCS_DRIFT_BASE="" makes the range ..HEAD, an empty diff, and drift silently does nothing. Latent while nothing sets the variable (Q1) | || instead of ?? | wont-fix — nothing sets DOCS_DRIFT_BASE, let alone to an empty string |
Duplication
| ID | Copies | Consolidate into | Status |
|---|---|---|---|
| D1 | The lines-changed reducer, in drift/domain/detect.ts:13 parseLinesChanged (only its spec calls it) and drift/domain/size.ts:7-10 changeSize | changeSize calls parseLinesChanged | fixed |
| D2 | split("-").map(titleCase).join(" ") in drift/domain/detect.ts:63 displayName and dev/domain/projects.ts:18 labelFor | A titleCaseSlug beside titleCase in shared/domain/layout.ts | wont-fix — two call sites of a one-line expression; a shared helper costs more than it saves |
| D3 | Three recursive walkers, each with its own ignore list: agents-sync/adapters/files.ts:28 walk, map/adapters/files.ts:85 walkMarkdown, package-contracts/adapters/files.ts:6 filesUnder. Only map skips worktrees, only agents-sync skips coverage and storybook-static, and package-contracts skips nothing (Q5) | One walk(dir, accept, extraIgnores) in shared/adapters/, with a common base set plus per-caller extras. map must scan .claude/, and agents-sync must not | wont-fix — each walker's ignore list fits its caller, and Q5 is wont-fix |
| D4 | dirsIn and filesIn in map/adapters/files.ts:15-35, and the frontmatter name: regex at lines 60 and 77 of the same file | One entriesIn(path, predicate) and one nameField(text) | fixed |
| D5 | The cache write in shared/adapters/cache.ts: once inside cached and once as writeCache | cached calls writeCache, which is also where B1's guard goes | fixed |
| D6 | writeText/writeBytes and matchesText/matchesBytes in agents-sync/adapters/files.ts:53-73 | Buffers only: Buffer.from(string) makes Output.contents a single type in agents-sync/main.ts | wont-fix — text and bytes differ in chmod handling; merging only moves Buffer.from into main.ts |
| D7 | The "@joinery/" literal in dev/main.ts:27, beside SCOPE in dev/domain/projects.ts:3. The local spellings there also shares its name with the domain export but means something different | Export SCOPE and rename the local | fixed |
Quality
| ID | Where | Issue | Fix | Status |
|---|---|---|---|---|
| Q1 | .husky/pre-push, README.md:178, drift/README.md:12, 0011, 0013 | Confirmed. The committed hook never runs docs:drift (grep -E 'drift|DOCS' finds nothing), yet four docs say it does, with DOCS_DRIFT_BASE/HEAD set to the pushed range | Either wire it into the hook, with </dev/tty for the prompt and ZERO_SHA handled for new branches, or correct the four docs | fixed — the docs now say drift runs manually |
| Q2 | issue/pick.ts:70 pickIssue, issue/domain/pick.ts:24-31 projectLoad | issueSource({ knownOffline, requestFailed: false, online: false }) is just knownOffline. projectLoad returns a projects field on the cache branch that the caller never reads. Two layers of indirection hide a two-line decision | Reduce both to the booleans the callers actually use | fixed |
| Q3 | issue/adapters/gh.ts:65 listIssues | --limit 100 is applied before the client-side project filter, so a repo with more than 100 open issues silently drops some from the picker | Filter server-side with --search "project:…", or page until exhausted | wont-fix — the repo has under 20 open issues |
| Q4 | issue/adapters/gh.ts:25 repoOwner | One extra gh round trip per listProjects and per moveToInProgress | Memoise it the way repoRoot is | wont-fix — one extra gh call inside an interactive prompt |
| Q5 | package-contracts/adapters/files.ts:6 filesUnder | Walks dist/, .nuxt/ and coverage/ inside each package, so a generated file can make a missing export target pass | Fixed by D3's shared ignore set | wont-fix — export targets point into src/, generated dirs never hold a file at those paths, and packages have no dist/ |
| Q6 | package-contracts/domain/validate.ts:136 validateExportNode | null targets (Node's way to block a subpath) and fallback arrays are both valid exports values, and both are reported as errors | Accept null. Validate each element of an array | wont-fix — no manifest here uses null or array targets, and adding one fails the check loudly |
| Q7 | package-contracts/main.ts:12,15 main | "✅"/"❌" are prefixed to out.success/out.error, which clack already decorates with its own icon, so interactive runs show two icons | Drop the emoji | fixed |
| Q8 | review-version/main.ts:21,28 main | "four artifacts unchanged" is hardcoded and drifts as soon as METHOD_ARTIFACTS changes length | ${METHOD_ARTIFACTS.length} | fixed |
| Q9 | shared/adapters/cache.ts:5,12 | CACHE_DIR resolves against cwd rather than at(), so the cache location depends on how the script was launched. The adapter imports flag from ../cli.ts, which means an adapter depends on the CLI layer and reads process.argv behind the parsed Args | at(CACHE_DIR), with refresh passed in by the caller | wont-fix — every entry point runs with cwd at infrastructure/scripts |
| Q10 | issue/add.ts:49-53, dev/main.ts:15-23 | A throw from listLabels or projectsWithDev leaves the spinner running under the error | Stop it in a finally | wont-fix — the error still prints; a leftover spinner frame on a crash is cosmetic |
| Q11 | coverage-report/domain/discover.ts:18-20 resolveOutput | The error says "in nx.json" when outputs can come from project.json or inference. Only the first {projectRoot} is replaced, and {workspaceRoot} is left as is | Neutral wording, replaceAll, and handle {workspaceRoot} | wont-fix — the only test:coverage output is {projectRoot}/coverage in nx.json |
| Q12 | ship/main.ts:28 main | Auto-merge is enabled before checks run and stays on after one fails, so a later re-run that passes merges with nobody watching | Disable auto-merge on failure, or say in the failure message that it stays queued | wont-fix — staying queued for a passing re-run is what auto-merge is for |
| Q13 | shared/adapters/exec.ts:15 assertNotFlagLike | The message says "gh would read it as a flag", but drift/adapters/git.ts also uses it for git refs | Name the command in the message, or drop the tool name | fixed |
| Q14 | map/main.ts:42, coverage-report/main.ts:19-20, issue/adapters/prompts.ts | The two commands write to disk directly, where every other script goes through adapters/. issue/adapters/prompts.ts is pure data and belongs in domain/ | Move the writes into each script's adapters/files.ts, and move prompts.ts into issue/domain/ | fixed — the writes moved into adapters; issue/adapters/prompts.ts stays, since it imports types from gh.ts |
Order
- B3, B1 and B2 first. They're the user-visible ones. B3 throws away a typed issue, B1
silently breaks offline
issue:pick, and B2 makes drift stop asking. Each needs a spec that pins the failure (writing-tests). - D5 before B1, so the empty-list guard lives in the one cache write.
- D3 before B5. Both change
FEATURES.md. Land the walker merge, confirmpnpm docs:map --checkis unchanged, then apply B5 and review its re-render on its own. The merge fixes Q5 for free. - B4, B6, B7, B8 and B9 are independent small fixes. B4 and B9 only matter once Q1 puts drift back in a hook, so settle Q1 alongside them.
- The remaining D and Q rows in any order. D1, D2, D4, D6 and D7 are behaviour-neutral, and the existing specs should pass untouched.