Skip to content
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

IDWhereWhat goes wrongFixStatus
B1issue/adapters/gh.ts:39 listProjects, shared/adapters/cache.ts:31 cachedLikely. 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 neededIn cached, skip the write when the fetched value is an empty array, the same guard it already applies on readfixed
B2drift/main.ts:52-64 mainLikely. 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 storedRecord the fingerprint only once the warning was answered, or when shouldWarn is false. Never record it on the non-interactive branchfixed
B3shared/adapters/gh.ts:17-20 createIssueLikely. 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 lostPass --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
B4shared/adapters/exec.ts:5 runConfirmed. 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 itFingerprint git diff --raw --no-abbrev, whose blob ids stay stable as the repo grows, instead of the full text. Raise maxBuffer in runfixed
B5map/domain/capabilities.ts:64 mentionsConfirmed. 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 commandAdd a (?<![\w:-]) lookbehind, re-render, and treat any new — rows as real doc gapsfixed
B6shared/domain/cli.ts:56-66 reportConfirmed. 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 twiceSkip detailOf when the stack already contains that textfixed
B7ship/adapters/git.ts:12-14 pushEvery 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 reasonAppend the caught error's stderr to the ExpectedErrorfixed
B8coverage-report/adapters/nx.ts:34-45 nxThe 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 exceptionClean up in one finally path, and reject on a failed readwont-fix — spawning process.execPath and reading a file the same function just created do not fail in practice
B9drift/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

IDCopiesConsolidate intoStatus
D1The lines-changed reducer, in drift/domain/detect.ts:13 parseLinesChanged (only its spec calls it) and drift/domain/size.ts:7-10 changeSizechangeSize calls parseLinesChangedfixed
D2split("-").map(titleCase).join(" ") in drift/domain/detect.ts:63 displayName and dev/domain/projects.ts:18 labelForA titleCaseSlug beside titleCase in shared/domain/layout.tswont-fix — two call sites of a one-line expression; a shared helper costs more than it saves
D3Three 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 notwont-fix — each walker's ignore list fits its caller, and Q5 is wont-fix
D4dirsIn and filesIn in map/adapters/files.ts:15-35, and the frontmatter name: regex at lines 60 and 77 of the same fileOne entriesIn(path, predicate) and one nameField(text)fixed
D5The cache write in shared/adapters/cache.ts: once inside cached and once as writeCachecached calls writeCache, which is also where B1's guard goesfixed
D6writeText/writeBytes and matchesText/matchesBytes in agents-sync/adapters/files.ts:53-73Buffers only: Buffer.from(string) makes Output.contents a single type in agents-sync/main.tswont-fix — text and bytes differ in chmod handling; merging only moves Buffer.from into main.ts
D7The "@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 differentExport SCOPE and rename the localfixed

Quality

IDWhereIssueFixStatus
Q1.husky/pre-push, README.md:178, drift/README.md:12, 0011, 0013Confirmed. 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 rangeEither wire it into the hook, with </dev/tty for the prompt and ZERO_SHA handled for new branches, or correct the four docsfixed — the docs now say drift runs manually
Q2issue/pick.ts:70 pickIssue, issue/domain/pick.ts:24-31 projectLoadissueSource({ 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 decisionReduce both to the booleans the callers actually usefixed
Q3issue/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 pickerFilter server-side with --search "project:…", or page until exhaustedwont-fix — the repo has under 20 open issues
Q4issue/adapters/gh.ts:25 repoOwnerOne extra gh round trip per listProjects and per moveToInProgressMemoise it the way repoRoot iswont-fix — one extra gh call inside an interactive prompt
Q5package-contracts/adapters/files.ts:6 filesUnderWalks dist/, .nuxt/ and coverage/ inside each package, so a generated file can make a missing export target passFixed by D3's shared ignore setwont-fix — export targets point into src/, generated dirs never hold a file at those paths, and packages have no dist/
Q6package-contracts/domain/validate.ts:136 validateExportNodenull targets (Node's way to block a subpath) and fallback arrays are both valid exports values, and both are reported as errorsAccept null. Validate each element of an arraywont-fix — no manifest here uses null or array targets, and adding one fails the check loudly
Q7package-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 iconsDrop the emojifixed
Q8review-version/main.ts:21,28 main"four artifacts unchanged" is hardcoded and drifts as soon as METHOD_ARTIFACTS changes length${METHOD_ARTIFACTS.length}fixed
Q9shared/adapters/cache.ts:5,12CACHE_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 Argsat(CACHE_DIR), with refresh passed in by the callerwont-fix — every entry point runs with cwd at infrastructure/scripts
Q10issue/add.ts:49-53, dev/main.ts:15-23A throw from listLabels or projectsWithDev leaves the spinner running under the errorStop it in a finallywont-fix — the error still prints; a leftover spinner frame on a crash is cosmetic
Q11coverage-report/domain/discover.ts:18-20 resolveOutputThe 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 isNeutral wording, replaceAll, and handle {workspaceRoot}wont-fix — the only test:coverage output is {projectRoot}/coverage in nx.json
Q12ship/main.ts:28 mainAuto-merge is enabled before checks run and stays on after one fails, so a later re-run that passes merges with nobody watchingDisable auto-merge on failure, or say in the failure message that it stays queuedwont-fix — staying queued for a passing re-run is what auto-merge is for
Q13shared/adapters/exec.ts:15 assertNotFlagLikeThe message says "gh would read it as a flag", but drift/adapters/git.ts also uses it for git refsName the command in the message, or drop the tool namefixed
Q14map/main.ts:42, coverage-report/main.ts:19-20, issue/adapters/prompts.tsThe 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

  1. 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).
  2. D5 before B1, so the empty-list guard lives in the one cache write.
  3. D3 before B5. Both change FEATURES.md. Land the walker merge, confirm pnpm docs:map --check is unchanged, then apply B5 and review its re-render on its own. The merge fixes Q5 for free.
  4. 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.
  5. 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.