Repository navigation
mcpx: name the resolved key in the degraded-scope log line (#280) #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package daemon | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/dezren39/mcpx/internal/config" | ||
| ) | ||
|
|
||
| // TestWarnDegradedNamesResolvedKey is the regression test for #280: the | ||
| // degraded-scope log line used to claim every scope "degraded to per-call", | ||
| // even when Scope.Key fell back to a directory (shared by every caller in | ||
| // it) or to the session key. The line must name the resolved key. | ||
| func TestWarnDegradedNamesResolvedKey(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| scope config.Scope | ||
| key string | ||
| reason string | ||
| }{ | ||
| {"worktree to cwd", config.ScopeWorktree, "cwd:/work/bare.git", "no worktree: core.bare is true"}, | ||
| {"repo to cwd", config.ScopeRepo, "cwd:/work/plain", "not a git repository"}, | ||
| {"parent-session to session", config.ScopeParentSession, "session:s1", "no parent session id; using the session id"}, | ||
| {"session to per-call", config.ScopeSession, "call:c1", "no session id; set MCPX_SESSION_ID or pass --session"}, | ||
| } | ||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| var lines []string | ||
| r := &Registry{logf: func(format string, args ...any) { | ||
| lines = append(lines, fmt.Sprintf(format, args...)) | ||
| }} | ||
| r.warnDegraded("bytree", tc.scope, tc.key, tc.reason) | ||
| if len(lines) != 1 { | ||
| t.Fatalf("logged %d lines, want 1: %v", len(lines), lines) | ||
| } | ||
| want := fmt.Sprintf("server %q: scope %q degraded to %s: %s", "bytree", tc.scope, tc.key, tc.reason) | ||
| if lines[0] != want { | ||
| t.Fatalf("log line = %q, want %q", lines[0], want) | ||
| } | ||
| if strings.Contains(lines[0], "per-call") && !strings.HasPrefix(tc.key, "call:") { | ||
| t.Fatalf("log line claims per-call for a shared key: %q", lines[0]) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // TestWarnDegradedDedupesPerResolvedKey: the same degradation warns once, | ||
| // but the same reason resolving to a different key is a different | ||
| // degradation and must warn again — the two directories are not shared. | ||
| func TestWarnDegradedDedupesPerResolvedKey(t *testing.T) { | ||
| var lines []string | ||
| r := &Registry{logf: func(format string, args ...any) { | ||
| lines = append(lines, fmt.Sprintf(format, args...)) | ||
| }} | ||
| r.warnDegraded("bytree", config.ScopeWorktree, "cwd:/work/a", "no worktree") | ||
| r.warnDegraded("bytree", config.ScopeWorktree, "cwd:/work/a", "no worktree") | ||
| r.warnDegraded("bytree", config.ScopeWorktree, "cwd:/work/b", "no worktree") | ||
| if len(lines) != 2 { | ||
| t.Fatalf("logged %d lines, want 2 (one per distinct key): %v", len(lines), lines) | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Bound warning state for per-call fallbacks.
If a session-scoped call has no session ID, each distinct call ID produces a distinct
call:<id>key.LoadOrStorethen retains an entry and emits a warning for every call. On a long-running daemon, repeated calls can grow the map and warning log without limit. Keep per-key warnings for shared keys, but coalesce or bound warning state for per-call keys.🤖 Prompt for AI Agents