matrix0487 on Discord (#feedback, 11-05) asked to change image-files from
the GUI: 8fbf8e0af made it CLI-only (`magpie provider set <id>
image-files=off`). The editor's Advanced now has an Images tick, "Upload
images once and send them by file id", on by default. It shows only where
the setting has effect: a provider on api.deepseek.com, the built-in
DeepSeek or a custom one with that base.
The rule has one source: provider.ImageFilesAt(to) (own key, no account or
plugin, Chat/Responses/Anthropic, host == provider.DeepSeekHost), and
TakesImageFiles for the editor. The gateway's dsFilesOn and forward's
dsSent setup ask ImageFilesAt instead of their own host checks.
/api/providers sends imageFilesOff and takesImageFiles; /api/provider/save
takes imageFilesOff as *bool, so a save that leaves it out keeps the old
value (CLI-set off stays off), false turns it on, true off. app.js sends it
only when the row is shown. Strings in zh, zh-TW, ja and de. app.js is 135
bytes under its base (four comments cut to one line); no budget raised.
Run on mote:
- provider-image-files.test.cjs: chromium + webkit, en/zh/zh-TW/ja/de,
1100 and 420 wide, 60/60. Shown for DeepSeek and a custom
api.deepseek.com base, hidden for another relay, toggling saves the
field, CLI-set off shows off.
- i18n-keys, i18n-en-no-cjk, editor-advanced-align, editor-fold-clickable,
provider-limit-rest, provider-image-files: 131/132; the red is i18n-keys
"a plugin's words are its own" from other tests' strings ("View
routing", "No session ID"), #5332 / #5327.
- go test -timeout 45m ./internal/provider ./internal/gateway
./internal/cli ok; ./internal/gui ok but TestMainWindowCorners, the
macOS 27 red (#3949). TestProviderSaveImageFiles and
TestCoreScriptBudget rerun after the comment cut.
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows.
Broken by hand, each red then restored:
- row condition `if (false)`: GUI red (chromium en 420).
- save field renamed: GUI red (webkit zh 420).
- imageFilesOff left out of draftOf: GUI red ("one set off from the CLI").
- the old keep-only save restored: TestProviderSaveImageFiles red
("ticked on in the editor, still saved off").
- host rule loosened to contains "deepseek": TestProviderSaveImageFiles
red (api.deepseek.com.example.com offered).
Not tried: a real DeepSeek key or the real app; a URL edit on an unsaved
provider doesn't show or hide the row live (it follows the saved row's
flag).
88 lines
3.2 KiB
Go
88 lines
3.2 KiB
Go
package gui
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// matrix0487 (Discord, 11-05): image-files, set only with `magpie provider
|
|
// set <id> image-files=off` (#5407), is offered in the editor of a provider
|
|
// on DeepSeek's own API, the built-in one or a custom one there, and only
|
|
// there. A value set from the CLI opens as set, a Save that leaves it out
|
|
// keeps it, and the editor's tick saves it either way.
|
|
func TestProviderSaveImageFiles(t *testing.T) {
|
|
t.Setenv("HOME", t.TempDir())
|
|
t.Setenv("USERPROFILE", os.Getenv("HOME"))
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
mux := http.NewServeMux()
|
|
providerRoutes(mux, nil)
|
|
post := func(body string) {
|
|
t.Helper()
|
|
w := httptest.NewRecorder()
|
|
mux.ServeHTTP(w, httptest.NewRequest("POST", "/api/provider/save", strings.NewReader(body)))
|
|
if w.Code != 200 {
|
|
t.Fatalf("%d %s", w.Code, w.Body.String())
|
|
}
|
|
}
|
|
info := func(id string) providerJSON {
|
|
t.Helper()
|
|
p, err := provider.Find(id)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
in := providerInfo(*p, nil)
|
|
if in.ImageFilesOff != p.ImageFilesOff {
|
|
t.Fatalf("%s: the editor is shown off=%v, saved off=%v", id, in.ImageFilesOff, p.ImageFilesOff)
|
|
}
|
|
return in
|
|
}
|
|
|
|
// the built-in DeepSeek, set off from the CLI (the field it writes)
|
|
ds, err := provider.FromPreset("deepseek")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ds.Key = "sk-ds"
|
|
ds.ImageFilesOff = true
|
|
if err := provider.Save(ds); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := info("deepseek"); !got.TakesImageFiles || !got.ImageFilesOff {
|
|
t.Fatalf("built-in DeepSeek set off from the CLI: offered %v, shown off %v", got.TakesImageFiles, got.ImageFilesOff)
|
|
}
|
|
edit := `{"id":"deepseek","from":"deepseek","name":"DeepSeek","preset":"deepseek","key":"","chat":"` + ds.Chat + `","responses":"` + ds.Responses + `","anthropic":"` + ds.Anthropic + `","catalog":"deepseek","models":[],"headers":{}`
|
|
post(edit + `}`)
|
|
if !info("deepseek").ImageFilesOff {
|
|
t.Fatal("a Save that left it out turned the CLI's off back on")
|
|
}
|
|
post(edit + `,"imageFilesOff":false}`)
|
|
if info("deepseek").ImageFilesOff {
|
|
t.Fatal("ticked on in the editor, still saved off")
|
|
}
|
|
post(edit + `,"imageFilesOff":true}`)
|
|
if !info("deepseek").ImageFilesOff {
|
|
t.Fatal("unticked in the editor, still saved on")
|
|
}
|
|
|
|
// a custom provider on DeepSeek's own API is offered it, added off
|
|
post(`{"id":"mine","name":"Mine","key":"sk-m","anthropic":"https://api.deepseek.com/anthropic","icon":"generic","new":true,"imageFilesOff":true}`)
|
|
if got := info("mine"); !got.TakesImageFiles || !got.ImageFilesOff {
|
|
t.Fatalf("custom on api.deepseek.com: offered %v, off %v", got.TakesImageFiles, got.ImageFilesOff)
|
|
}
|
|
|
|
// another base, a relay serving DeepSeek's models included, is not
|
|
post(`{"id":"relay","name":"Relay","key":"sk-r","chat":"https://relay.example.com/deepseek/v1","icon":"generic","new":true}`)
|
|
post(`{"id":"near","name":"Near","key":"sk-n","chat":"https://api.deepseek.com.example.com/v1","icon":"generic","new":true}`)
|
|
for _, id := range []string{"relay", "near"} {
|
|
if info(id).TakesImageFiles {
|
|
t.Errorf("%s isn't DeepSeek's own API, yet offered image-files", id)
|
|
}
|
|
}
|
|
}
|