beads/internal/utils
Cherub Kumar ab88b20517
fix(utils): refuse a bare jq/JS sentinel (null, undefined, empty) as an issue ID (#6215)
* fix(utils): refuse a bare jq/JS sentinel as an issue ID

`jq -r` prints the literal string "null" when a selector misses, and JS
tooling prints "undefined". Both are a valid partial-ID shape, so
ResolvePartialID accepted them and resolved them through its leading-prefix
abbreviation branch: any issue whose hash began with the token became the
target, and the write reported success naming an issue the caller never
mentioned.

Reproduced on stock beads at a07794015, embedded Dolt, scratch workspace,
no orchestrator:

    bd init --prefix bd
    bd create --id bd-null3t0 "decoy: must not be touched"
    bd update null --status closed
    ✓ Updated issue: bd-null3t0 — decoy: must not be touched   (exit 0)

HasPrefix), so this needs a hash that begins with the token — the same case

The guard sits in ResolvePartialID rather than in a command because
internal/utils/id_parser.go is the only ID-resolution entry point in the
repository: 52 non-test call sites across 29 files, plus 2 through the
ResolvePartialIDs wrapper, and the four cmd/bd/*_proxied_server.go twins
resolve through the same function. One guard covers the direct, embedded and
proxied-server paths uniformly.

The riskiest thing this does is add a refusal to the resolver every command
shares. An ID that merely contains a token (bd-null, null3t0,
undefined-behavior) is unaffected, abbreviation matching is otherwise
unchanged, and the empty string already failed — it now says why.

Case folding is deliberate: NULL is what SQL-shaped tooling prints.
Whitespace is trimmed for the comparison only, never for resolution.

The tests use a nil store so the ordering is observable: reaching the
"storage is nil" error proves the guard did not fire. Mutation-tested — with
the guard reverted all eight refused inputs fail and the seven accepted
inputs still pass.

Fixes #6214
Refs #5393

Agent-Signature: claude-code-opus-5-unknown-reasoning on behalf of Cherub Kumar
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SDrKFyrfKTKM5J9yFbW7uA

* fix(utils): refuse none/nil too, and list the new test in the Bazel srcs

Maintainer review fixes for #6215, review iteration 1. Both lanes and the
scorecard returned approve with no required changes; this commit takes the two
actionable minors, both of which land inside the PR's own change.

Taken:

- Behavioral Correctness (minor). `bd update None --status closed` still reached
  the leading-prefix abbreviation branch: strings.ToLower("None") is "none" and
  every character passes looksLikePartialIDHash, so it could silently write to
  whichever issue's hash begins "none" and exit 0. `nil` is the same class. That
  is the identical silent-wrong-write harm this PR exists to prevent, and the
  remedy lands in the switch the PR just added, so "none" and "nil" join the
  same case arm and the refused-inputs table.

  The error text is generalized with them: "none" is Python and "nil" is
  Go/Ruby, so the previous jq/JS-only wording would have mis-described the two
  new tokens.

- Change Impact / Blast Radius (minor). The PR adds two TestX functions that
  `go list` selects for internal/utils but that Bazel's utils_test target could
  not compile or run -- exactly what tools/bazel/equivalence.py reports as
  `missing`. Gazelle's verdict, not a hand-guess: `make bazel-sync` produced
  exactly `+ "id_parser_sentinel_test.go",` for internal/utils/BUILD.bazel. It
  also rewrote 13 other BUILD.bazel files (pre-existing base drift), which is out
  of scope here, so that output was reverted and only this PR's row re-applied at
  gazelle's chosen slot. utils_test is 10 entries, sorted, no duplicates, all on
  disk.

  Note the review predicted the regen would also add `+ "//internal/debug",` to
  this file's go_library deps "once rebased on main". It did not at this base,
  because the import that needs it is not present here -- that dep is
  base-owned drift and is already tracked separately.

Over-refusal is guarded, not assumed: the pre-existing accepted-inputs test
(nullos, null3t0) and the whole ResolvePartialID suite -- cross-prefix,
allowed-prefixes, wisp, title-false-positive -- all still pass.

Validation: gofmt clean, go build ./... and CGO_ENABLED=1 go vet ./internal/utils/
clean; 42 PASS / 0 FAIL / 0 SKIP over -run "Sentinel|ResolvePartialID". The new
rows are mutation-proved: dropping "none" from the case arm reds
TestResolvePartialIDRefusesSentinelTokens, and restoring returns rc=0.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Cherub Kumar <5449665+ckumar1@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-29 17:15:45 -07:00
..
BUILD.bazel fix(utils): refuse a bare jq/JS sentinel (null, undefined, empty) as an issue ID (#6215) 2026-09-29 17:15:45 -07:00
id_parser.go fix(utils): refuse a bare jq/JS sentinel (null, undefined, empty) as an issue ID (#6215) 2026-09-29 17:15:45 -07:00
id_parser_prefix_test.go feat(issueops): add the Reader role and wire both front doors through it 2026-07-31 18:37:25 +00:00
id_parser_sentinel_test.go fix(utils): refuse a bare jq/JS sentinel (null, undefined, empty) as an issue ID (#6215) 2026-09-29 17:15:45 -07:00
id_parser_test.go feat(issueops): add the Reader role and wire both front doors through it 2026-07-31 18:37:25 +00:00
id_parser_unit_test.go feat(ids): say when a partial ID resolved to something else (#6302) 2026-09-28 13:12:39 -07:00
issue_446_test.go style: run gofmt across entire codebase (bd-nmk12) 2026-02-07 19:35:20 -08:00
issue_id.go fix(sort): natural numeric sort for issue IDs with dotted suffixes (GH#3477) (#3486) 2026-04-27 07:04:37 -07:00
issue_id_test.go fix(sort): natural numeric sort for issue IDs with dotted suffixes (GH#3477) (#3486) 2026-04-27 07:04:37 -07:00
path.go fix(utils): resolve macOS true-case via F_GETPATH instead of scanning every ancestor (wy-9ai3u) 2026-07-25 22:24:39 -07:00
path_case_darwin.go fix(lint): suppress two darwin-only gosec findings and cross-lint the darwin build in CI (#6243) 2026-09-28 15:44:52 -07:00
path_case_other.go fix(utils): resolve macOS true-case via F_GETPATH instead of scanning every ancestor (wy-9ai3u) 2026-07-25 22:24:39 -07:00
path_case_test.go test(utils): rate the true-case fast path against the walk, not the wall clock (wy-9ai3u) 2026-07-25 22:28:22 -07:00
path_test.go fix packaging and windows install regressions 2026-04-24 11:48:39 -07:00
strings.go fix: complete decision type aliases and help strings 2026-02-11 17:23:21 -08:00
strings_test.go fix: complete decision type aliases and help strings 2026-02-11 17:23:21 -08:00
testmain_test.go test(testutil): opt-in local dolt sql-server backend for Dolt-backed tests (#6891) 2026-09-28 04:06:49 -07:00