* fix(rename-prefix): do not double IDs already on the target prefix
When config.issue_prefix is stale (e.g. still "global") but issue IDs
were already rewritten to "atlas-*", rename-prefix atlas did:
TrimPrefix("atlas-1", "global-") → "atlas-1"
newID = "atlas-" + "atlas-1" → "atlas-atlas-1"
Detect IDs that already use the destination prefix and leave them
alone, then still update the config cell (GH#4827).
Fixes #4827
* fix(rename-prefix): use the detected row prefix, not the config cell, to drive ID rewrites
PR #5135 review (maphew, 2026-07-29): rewriteIssueID's "already on
target prefix" guard ran before the old-prefix match, so it also
matched the first hyphen-boundary segment of a multi-part prefix.
Shortening beads-vscode- -> beads- silently skipped every row (they
all start with "beads-"), leaving the config cell and IDs out of
sync — the exact GH#4827 state, now produced by the fix for it.
Restructure so the caller threads the prefix actually detected on
the rows (detectPrefixes), not the possibly-stale issue_prefix
config cell, into rewriteIssueID/renamePrefixInDB:
- detected == newPrefix: config-only repair (GH#4827 half-migrated
DB) — SetConfig, no ID rewrites, distinct success/dry-run message.
- otherwise: rewrite detected-* -> newPrefix-* as before.
rewriteIssueID collapses to a single oldPrefix check; the newPrefix
guard is gone, since the caller now guarantees oldPrefix reflects
reality instead of a cell that may have drifted.
Also from the same review, three cheap correctness fixes:
- dry-run no longer claims "(all N issue IDs already use prefix X)"
on a zero-rewrite run when the rows are on an unrelated prefix —
that message only fires now for the genuine config-only-repair case.
- the success/JSON path reports issues_count: 0 (not len(issues)) and
a distinct message when only the config was repaired.
- dry-run's "... and more" restores the exact "... and N more issues"
count.
Left out of scope (per review): the #4175 SetConfig no-op textual-
conflict note, and the PR title's leading "# " (already fixed).
Added: a failing-first unit test for the shortening regression
(TestRewriteIssueID_PrefixShortening), an end-to-end embedded-CLI
subtest for the same case, and a DB-level test pinning the GH#4827
config-only-repair path (TestRenamePrefixInDB_HalfMigratedConfigNotDoubled).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test(rename-prefix): assert the rewritten prefix, not a sequential ID
bd create mints hash IDs (beads-cyc), never sequential ones, so
Contains("beads-1") only passed when a hash happened to start with 1 --
a flaky assertion that fails deterministically for most runs. Assert the
"beads-" prefix instead; the existing !Contains("beads-vscode-") check
is what actually pins the shortening fix. Mirrors rename_basic, which
asserts "new-" for the same reason.
Reported by maphew on PR #5135.
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestRewriteIssueID_NoDoublePrefix(t *testing.T) {
|
|
t.Parallel()
|
|
// GH#4827: config still "global" but rows already "atlas-*"
|
|
got := rewriteIssueID("global", "atlas", "atlas-1")
|
|
if got != "atlas-1" {
|
|
t.Fatalf("got %q, want atlas-1 (must not double)", got)
|
|
}
|
|
got = rewriteIssueID("global-", "atlas-", "atlas-99")
|
|
if got != "atlas-99" {
|
|
t.Fatalf("got %q, want atlas-99", got)
|
|
}
|
|
}
|
|
|
|
func TestRewriteIssueID_NormalRename(t *testing.T) {
|
|
t.Parallel()
|
|
got := rewriteIssueID("global", "atlas", "global-1")
|
|
if got != "atlas-1" {
|
|
t.Fatalf("got %q, want atlas-1", got)
|
|
}
|
|
got = rewriteIssueID("old-", "new-", "old-abc")
|
|
if got != "new-abc" {
|
|
t.Fatalf("got %q, want new-abc", got)
|
|
}
|
|
}
|
|
|
|
func TestRewriteIssueID_UnrelatedPrefixUnchanged(t *testing.T) {
|
|
t.Parallel()
|
|
got := rewriteIssueID("global", "atlas", "other-1")
|
|
if got != "other-1" {
|
|
t.Fatalf("got %q, want other-1", got)
|
|
}
|
|
}
|
|
|
|
// TestRewriteIssueID_PrefixShortening pins PR #5135 review blocker B1
|
|
// (maphew, 2026-07-29): the "already on target prefix" guard was checked
|
|
// before the old-prefix match, so shortening a multi-part prefix to one of
|
|
// its own leading segments (e.g. "beads-vscode-" -> "beads-") silently
|
|
// skipped every ID, because "beads-vscode-1" also starts with "beads-".
|
|
func TestRewriteIssueID_PrefixShortening(t *testing.T) {
|
|
t.Parallel()
|
|
got := rewriteIssueID("beads-vscode", "beads", "beads-vscode-1")
|
|
if got != "beads-1" {
|
|
t.Fatalf("got %q, want beads-1 (shortening regression)", got)
|
|
}
|
|
got = rewriteIssueID("kw-team", "kw", "kw-team-42")
|
|
if got != "kw-42" {
|
|
t.Fatalf("got %q, want kw-42 (shortening regression)", got)
|
|
}
|
|
}
|