Files
magpie/internal/provider/unredacted_test.go
T
yetone 698da36f31 gateway, providers, gui: a model on this computer or the local network can be set to get requests unmasked by Settings' redaction (lc on Discord: 本地模型可以不脱敏)
The provider editor has a Redaction row, "Send requests unmasked", while
every address of the provider is on this computer or the local network
(localhost, *.local, a loopback or private IP): Ollama, LM Studio, a vLLM
box. Ticked (provider.Unredacted; CLI `magpie provider set <id>
unmasked=yes`), a request whose provider and fallbacks, or whose routing
group's models, all skip redaction (provider.SkipsRedaction) goes to them
as the agent wrote it; anything that may reach another provider stays
masked for all of them. An address edited to a vendor's masks it again; a
signed-in account, a plugin's provider and another magpie never skip. The
log and recent calls keep the masked body. count_tokens and embeddings
follow the same rule.

It is a per-provider choice, not automatic for local addresses, because
a local address isn't a local model: a relay run locally (new-api,
CLIProxyAPI) or Ollama's cloud models pass the request on to a vendor.

Verified: TestLocalUnredactedProviderGetsTheRequestWhole (set, unset,
fallback to a vendor, fallback to another local one, a group of it alone,
a group with a vendor; chat and count_tokens) and TestLocalUnredactedEmbeddings
fail without the gateway change ("sent whole false, want true: … my key is
{{API_KEY_…}}"; count_tokens alone: "counted whole false"); TestSkipsRedaction;
TestProviderSaveKeepsUnredacted fails without the preset save line.
provider-unmasked.test.cjs (Chromium+WebKit, en/zh, 900 and 440 wide) 32/32,
3 of 4 fail on the old app.js; gui-ja, gui-de, i18n-keys, provider-search
and the other provider editor suites pass. go test -race on gateway,
provider, redact, gui; -race -count=10 on the new tests; go vet,
GOOS=linux/windows builds. Real: a sandbox gateway in front of the local
Ollama (llama3 8B) through a logging proxy: unset, Ollama was sent
{{API_KEY_…}}; with unmasked=yes it was sent the key as written, and
answered both times.
2026-10-07 00:33:15 +08:00

33 lines
1.6 KiB
Go

package provider
import "testing"
// Only a provider the user set to go unmasked whose every address is on
// this machine or the local network skips redaction; one at a vendor's
// address, a signed-in account or another magpie never does.
func TestSkipsRedaction(t *testing.T) {
cases := []struct {
name string
p Provider
want bool
}{
{"ollama", Provider{Unredacted: true, Chat: "http://localhost:11434/v1", Anthropic: "http://localhost:11434"}, true},
{"loopback ip", Provider{Unredacted: true, Chat: "http://127.0.0.1:1234/v1"}, true},
{"ipv6 loopback", Provider{Unredacted: true, Chat: "http://[::1]:8000/v1"}, true},
{"lan", Provider{Unredacted: true, Chat: "http://192.168.1.20:8000/v1"}, true},
{"mdns", Provider{Unredacted: true, Responses: "http://gpu-box.local:8000/v1"}, true},
{"not set", Provider{Chat: "http://localhost:11434/v1"}, false},
{"a vendor", Provider{Unredacted: true, Chat: "https://api.deepseek.com/v1"}, false},
{"one address a vendor's", Provider{Unredacted: true, Chat: "http://localhost:11434/v1", Anthropic: "https://ollama.com"}, false},
{"a public ip", Provider{Unredacted: true, Chat: "http://8.8.8.8/v1"}, false},
{"no address", Provider{Unredacted: true}, false},
{"an account", Provider{Unredacted: true, Chat: "http://localhost:1/v1", Account: &Account{Agent: "codex"}}, false},
{"another magpie", Provider{Unredacted: true, Preset: RemoteMagpiePreset, Anthropic: "http://192.168.1.5:3425"}, false},
}
for _, tc := range cases {
if got := tc.p.SkipsRedaction(); got != tc.want {
t.Errorf("%s: %v, want %v", tc.name, got, tc.want)
}
}
}