Skip to content

Commit e09ebd5

Browse files
fix(store): handle global scope in normalizeScope (#428)
normalizeScope had no case for "global", silently coercing it to "project". Add "global" alongside "personal" in the switch so mem_save/mem_update/HTTP API callers can create and upsert global observations correctly. Closes #122
1 parent 69a26c8 commit e09ebd5

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

internal/store/store.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5816,10 +5816,12 @@ func truncate(s string, max int) string {
58165816

58175817
func normalizeScope(scope string) string {
58185818
v := strings.TrimSpace(strings.ToLower(scope))
5819-
if v == "personal" {
5820-
return "personal"
5819+
switch v {
5820+
case "personal", "global":
5821+
return v
5822+
default:
5823+
return "project"
58215824
}
5822-
return "project"
58235825
}
58245826

58255827
// NormalizeProject applies canonical project name normalization:

internal/store/store_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7716,6 +7716,32 @@ func TestGetDeferred_NotFound(t *testing.T) {
77167716
}
77177717
}
77187718

7719+
func TestNormalizeScopeHandlesGlobal(t *testing.T) {
7720+
tests := []struct {
7721+
input string
7722+
want string
7723+
}{
7724+
{"global", "global"},
7725+
{"Global", "global"},
7726+
{"GLOBAL", "global"},
7727+
{" global ", "global"},
7728+
{"personal", "personal"},
7729+
{"Personal", "personal"},
7730+
{"project", "project"},
7731+
{"Project", "project"},
7732+
{"", "project"},
7733+
{"unknown", "project"},
7734+
}
7735+
for _, tc := range tests {
7736+
t.Run(tc.input, func(t *testing.T) {
7737+
got := normalizeScope(tc.input)
7738+
if got != tc.want {
7739+
t.Errorf("normalizeScope(%q) = %q, want %q", tc.input, got, tc.want)
7740+
}
7741+
})
7742+
}
7743+
}
7744+
77197745
// TestSearchLegacyMixedCaseProject reproduces issue #146:
77207746
// observations stored with a mixed-case project name (legacy data pre-normalization)
77217747
// must be found when searched with a normalized (lowercase) project name.

0 commit comments

Comments
 (0)