fix(server): normalize project names before migrate to prevent case-only duplicates#451
Merged
Merged
Conversation
…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
There was a problem hiding this comment.
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/migratebefore 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.
| // See: https://github.com/Gentleman-Programming/engram/issues/438 | ||
| normalizedOld, _ := store.NormalizeProject(body.OldProject) | ||
| normalizedNew, _ := store.NormalizeProject(body.NewProject) | ||
| if normalizedOld == normalizedNew { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_Namevsrepo_name), the session-start hook POSTed/projects/migrateand the server migrated because it did an exact string compare.Change
handleMigrateProject(internal/server/server.go) now normalizes bothOldProjectandNewProjectviastore.NormalizeProjectbefore the equality check; case-only differences returnstatus: "skipped"._helpers.sh/session-start.sh: lowercasedetect_projectoutput andOLD_PROJECT(defense-in-depth).Test plan
TDD red→green.
TestMigrateProjectCaseOnlySkippedseeds a session underrepo_name, then POSTs migraterepo_name→Repo_Nameand assertsskipped(wasmigratedbefore the fix).go test ./internal/server/...andgo build ./...clean.Notes
Passed adversarial review:
store.NormalizeProjectis the same normalizer used on all write paths, so the guard can only skip genuine no-ops — no legitimate rename is lost.