Dudung1018's CC Switch had third-party providers named as magpie's
subscriptions are: a Pi proxy "workbuddy", an OpenCode relay "Claude".
Reproduced in a sandbox GUI with a CC Switch db in cc-switch's real
schema:
- the default import answered 400 "workbuddy is the id of the workbuddy
subscription; pick another name", after some picks had already been
written. That is why the reporter later saw "already added" and couldn't
find where the key went.
- the "Replace it" choice on a row named "claude" wrote the relay's models
as the Claude subscription's picks, and dropped its key and address.
What changed:
- importapps: a row whose id is a subscription's (signed in or not), or
magpie's own, is marked reserved. It is picked like a new one and added
under a free id beside the subscription. Replace is refused for it, and
key mode never joins an account or a provider at another address.
- the picker has a name field on every row whose name collides. A renamed
row is added under its new name, and Replace is no longer offered for it.
"Add as another key" names the provider the key went to.
- import links (magpie://import, magpie import) named or id'd as a
subscription get a free id.
- the new sub-line is in en, zh, zh-TW, ja and de.
What was run:
- sandbox GUI on the old build (the 400, the partial write, the Replace
case), then on the new one. The same picks gave 200 ["Relay 1487",
"Claude (findcg)", "workbuddy"]: findcg got one more key, and relay-1487
and workbuddy-2 were added at their own addresses.
- importapps_reserved_test.go: 4 tests on the real cc-switch schema, all
red on the old code.
- import-collision.test.cjs: chromium and webkit, in en/zh/zh-TW/ja/de, at
900 and 390px, 20/20 passing and red on the old assets.
provider-discovery.test.cjs still passes.
- go test -tags nogui ./... green, gofmt -l, and GOOS=linux and windows go
vet for internal/provider and internal/gui.
The same relay with the same key is often both a CC Switch entry and
what Claude Code's settings.json points at (CC Switch writes it there).
The import picker lists it under both apps as new and turns both on, so
one import added it twice ("Some Relay" and "relay.example.com"). Once
the user removed one, the other copy made the CC Switch entry "Already
added" and it could not be imported again, which is what the reporter
saw.
ImportFromApps now skips an add whose account (key at the address,
sameProvider, as the list's "same" says) a provider already holds,
including one added earlier in the same import. The picker's "Already
added" row also says which provider holds it ("magpie has {name}
already", an existing string), so a leftover copy can be found.
Run: TestImportSameAccountFromTwoAppsOnce (CC Switch db + settings.json
fixtures, default picks) fails without the change ("the relay added 2
times: [some-relay relay-example-com]") and passes with it; go test
-run TestImport ./internal/provider passes. provider-discovery.test.cjs
in Chromium and WebKit (en, zh) passes 13/13, and fails 2 with the row's
new line taken out.