Skip to content

test(mcp): pin dedupe merge semantics with focused tests - #380

Merged
mar-schmidt merged 2 commits into
Podiom:masterfrom
eddyflores100-lang:tests/dedupe-coverage
Nov 8, 2026
Merged

mar-schmidt merged 2 commits into
Podiom:masterfrom
eddyflores100-lang:tests/dedupe-coverage

Conversation

@eddyflores100-lang

Copy link
Copy Markdown
Contributor

Adds internal/mcp/dedupe_test.go with focused tests for dedupe and the helpers it calls, per #378.

Covered behaviours (each trace verified against master before writing the tests):

  • dedupe(nil) and dedupe([]Server{}) return a non-nil empty slice.
  • The empty-name guard is s.Name == "" with no trim: whitespace-only names survive, and "x " / "x" stay separate. Ordering is case-sensitive bytewise (A, X, a, b, x).
  • A merged server can carry a stdio transport and an HTTP URL: the first entry is normalised to stdio before it is stored, so the if existing.Transport == "" guard in the merge block never fires and the URL is backfilled without a transport fix.
  • First-wins is per field: {Command:"first", Sources:[codex]} + {Command:"second", URL:"https://u", Sources:[podiom]} yields Command:"first" with URL:"https://u" and sources [podiom codex].
  • The invented podiom source is added only when the first occurrence has none; output order is always podiom -> claude -> codex regardless of input order.
  • The result aliases the caller's Args on first insert (the duplicate path copies).
  • A server with no env keeps EnvVars == nil while EnvStatus is a non-nil empty slice.
  • envStatus calls os.LookupEnv, so the set case runs under t.Setenv and the unset case uses a sentinel name that skips the test if it is unexpectedly present.

Verification:

go test ./internal/mcp            # ok
go test ./internal/mcp -coverprofile=/tmp/mcp.cover
go tool cover -func=/tmp/mcp.cover | grep dedupe
# dedupe: 97.2% (was 44.4%); envStatus 100%; mergeSources 100%
go vet ./internal/mcp             # clean

Tests only — no production behavior change.

Closes #378.

Covers the eight behaviours from Podiom#378: non-nil empty results for nil/empty
input, the untrimmed empty-name guard, bytewise case-sensitive ordering,
URL-into-stdio merging, per-field first-wins, the invented podiom source,
Args aliasing on first insert only, and the nil-EnvVars / non-nil-EnvStatus
shape. The LookupEnv case is deterministic via t.Setenv plus a
skipped-if-present unset sentinel.

dedupe: 44.4% -> 97.2%; envStatus and mergeSources reach 100%.
Tests only; no production code touched.
@mar-schmidt

Copy link
Copy Markdown
Collaborator

Nice set — I ran these against mutated copies of dedupe and 9 of the 11 bite. Two gaps before I merge.

TestDedupeFirstWinsPerField doesn't pin first-wins for URL. The first entry has no URL, so flipping mcp.go:560 to last-wins still passes. Give the first entry a URL too and assert a different second one doesn't replace it.

TestDedupeAliasesCallerArgsOnFirstInsert's second half can't reach the merge-path copy: the first entry has Args: {"a"}, so len(existing.Args) == 0 is false and mcp.go:566 never runs. Drop that first entry's Args — {Name: "y"}, {Name: "y", Args: in2} — and it starts biting. I checked both: as written they pass with existing.Args = s.Args, with the change they fail.

Everything else is clean here — build, full go test ./..., gofmt.

@mar-schmidt

Copy link
Copy Markdown
Collaborator

Ran these against the real function: I broke dedupe nine ways and eight of them turned a test red — the empty-name guard, the bytewise sort, the URL backfill, first-wins on Command, the invented podiom source, the non-nil empty result, the stdio transport default, and the EnvStatus recompute. Good coverage.

One assertion doesn't bite. In TestDedupeAliasesCallerArgsOnFirstInsert, the second half:

got2 := dedupe([]Server{
	{Name: "y", Args: []string{"a"}},
	{Name: "y", Args: in2},
})

The first entry already has Args, so len(existing.Args) == 0 is false and the copy branch never runs. got2[0].Args is the first entry's slice, so in2 is untouched whatever dedupe does — I replaced append([]string(nil), s.Args...) with a plain alias and the test still passed.

Dropping Args from the first entry reaches the branch:

{Name: "y"},

With that, the same mutation fails the test. Push it and I'll merge.

@mar-schmidt

Copy link
Copy Markdown
Collaborator

My second comment only named the Args gap — there are two, and I should have repeated both. The other is TestDedupeFirstWinsPerField: give the first entry a URL as well, so a different second URL failing to replace it is what the assertion actually proves. As written the first entry has none, so last-wins passes too.

Both are one-liners. Push them together and it goes in.

TestDedupeFirstWinsPerField: the first entry had no URL, so last-wins
passed too. Give it one and pin that the second does not replace it.
URL backfill stays covered by TestDedupeMergesURLIntoStdio.

TestDedupeAliasesCallerArgsOnFirstInsert: the first entry had Args, so
len(existing.Args) == 0 was false and the merge-path copy never ran.
Drop them to reach the branch.

Co-Authored-By: Claude <[email protected]>
@mar-schmidt
mar-schmidt merged commit e1e6b09 into Podiom:master Nov 8, 2026
5 checks passed
@mar-schmidt

Copy link
Copy Markdown
Collaborator

Merged. I pushed the two one-liners myself rather than leave this sitting — the Args change drops Args from the first entry, the URL change gives it https://first against a second https://second. URL backfill is still covered by TestDedupeMergesURLIntoStdio.

Both bite now: last-wins on mcp.go:560 fails TestDedupeFirstWinsPerField, and aliasing instead of copying at mcp.go:566 fails TestDedupeAliasesCallerArgsOnFirstInsert. Deleting the backfill fails the stdio test. Full go test ./... green.

Your eleven tests are the substance here. If Podiom is useful to you, a star helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

internal/mcp: dedupe's merge semantics have no test coverage

2 participants