Skip to content

fix(server): normalize project names before migrate to prevent case-only duplicates#451

Merged
Alan-TheGentleman merged 1 commit into
mainfrom
fix/migrate-normalize-case-438
May 29, 2026
Merged

fix(server): normalize project names before migrate to prevent case-only duplicates#451
Alan-TheGentleman merged 1 commit into
mainfrom
fix/migrate-normalize-case-438

Conversation

@Alan-TheGentleman
Copy link
Copy Markdown
Collaborator

Summary

Closes #438 — startup migration bypassed lowercase normalization, reintroducing the duplicate-projects problem fixed in #136. When a git remote repo name differed from the cwd basename only by case (Repo_Name vs repo_name), the session-start hook POSTed /projects/migrate and the server migrated because it did an exact string compare.

Change

  • handleMigrateProject (internal/server/server.go) now normalizes both OldProject and NewProject via store.NormalizeProject before the equality check; case-only differences return status: "skipped".
  • _helpers.sh / session-start.sh: lowercase detect_project output and OLD_PROJECT (defense-in-depth).

Test plan

TDD red→green. TestMigrateProjectCaseOnlySkipped seeds a session under repo_name, then POSTs migrate repo_nameRepo_Name and asserts skipped (was migrated before the fix). go test ./internal/server/... and go build ./... clean.

Notes

Passed adversarial review: store.NormalizeProject is the same normalizer used on all write paths, so the guard can only skip genuine no-ops — no legitimate rename is lost.

…nly duplicates (#438)

Before this fix, POST /projects/migrate compared old_project and new_project
with an exact string equality check, so "repo_name" vs "Repo_Name" bypassed
the skip guard and triggered a real migration, reintroducing the duplicate
project problem fixed in #136.

- server.go: normalize both names via store.NormalizeProject before the
  equality check; case-only differences now return status="skipped"
- _helpers.sh: lowercase detect_project output via tr '[:upper:]' '[:lower:]'
- session-start.sh: lowercase OLD_PROJECT at assignment
Copilot AI review requested due to automatic review settings May 29, 2026 12:15
@Alan-TheGentleman Alan-TheGentleman added the type:bug Bug fix label May 29, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes project-name casing drift during startup migration by applying canonical normalization before deciding whether a project migration is needed.

Changes:

  • Normalizes project names in /projects/migrate before the equality guard.
  • Lowercases Claude Code hook project detection outputs.
  • Adds a server regression test for case-only migration skips.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
internal/server/server.go Adds normalized comparison before project migration.
internal/server/server_test.go Adds regression coverage for case-only migrate requests.
plugin/claude-code/scripts/_helpers.sh Lowercases detected project names from git/cwd fallbacks.
plugin/claude-code/scripts/session-start.sh Lowercases cwd-derived old project name before comparison.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/server/server.go
// See: https://github.com/Gentleman-Programming/engram/issues/438
normalizedOld, _ := store.NormalizeProject(body.OldProject)
normalizedNew, _ := store.NormalizeProject(body.NewProject)
if normalizedOld == normalizedNew {
@Alan-TheGentleman Alan-TheGentleman merged commit 7fb528a into main May 29, 2026
9 checks passed
@Alan-TheGentleman Alan-TheGentleman deleted the fix/migrate-normalize-case-438 branch May 29, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(mcp): startup migrate from ensureImplicitSessionWithCWD bypasses lowercase normalization, reintroduces the duplicate-projects problem fixed in #136

2 participants