Files
magpie/internal/gui/pencil_state_test.go
T
yetone 31d904d938 agents: Pencil (pen.dev) is an agent magpie sets up, its custom models in ~/.pencil/models.json (徐小小 on Discord: Pencil keeps its custom model file at ~/.pencil/models.json, in Pi's format) — Pencil's settings take a custom provider on OpenAI Completions, OpenAI Responses or Anthropic Messages (docs.pen.dev, Authentication), Pi's openai-completions, openai-responses and anthropic-messages, set for the provider as a whole, and its models.json is Pi's: {"providers":{"<id>":{"name","baseUrl","api","models":[{"id","name","reasoning","input","cost":{input,output,cacheRead,cacheWrite},"contextWindow","maxTokens","compat"}]}}}. The new pencil agent (pencil.go) adds magpie there as the provider "magpie": baseUrl the gateway's /v1, api openai-completions, apiKey magpie-pencil (its User-Agent isn't known, so its requests are told by the key), and every model as Pi's entry — Pi's model loop is now piModelJSON, shared — without a model's own api and baseUrl, which Pi reads but Pencil's own editor never writes, so every model goes to the gateway's Chat endpoint whatever Pencil makes of them; each model carries every field Pencil writes for one, Pi's defaults (128K window, 16K out) where magpie knows none, no cost and an empty compat. The model is picked in Pencil's agent composer, not in a file known to magpie, so its field is "provider", as for WorkBuddy and ZCode: whether magpie's models are in Pencil's picker; the user's other providers, their keys and Pencil's other keys stay, off takes only magpie's out, and the catalog sync rewrites it only where it is. It is found by ~/.pencil (the app's and pen.dev's CLI's) or, on a Mac, Pencil.app / pen.dev.app in /Applications or ~/Applications; not by a command, pencil and pen being common names. After a change it asks for Pencil to be restarted when Pencil is running (and always on Windows, where that can't be told): whether it reloads models.json on its own isn't known. No official icon with a licence that allows it was found, so it has the generic one. Nothing of Pencil's was downloaded or run; whether Pencil reads a model's thinkingLevelMap, a settings file naming a default model, and its paths on Windows and Linux (taken as ~/.pencil, as Node's homedir gives) aren't verified. TestPencilModels (the reporter's file with a key and a key of Pencil's: kept through on, sync and off; magpie's provider decoded strictly as Pencil's format, every model's fields of their types, no per-model api or baseUrl; found only with ~/.pencil; among All()) and TestStateListsPencil (the page's state lists Pencil with its provider field once ~/.pencil is there, not before) fail without the change. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass (TestClaudeSignedOut failed once on its 5 s wait, passes alone; untouched).
2026-10-02 14:43:06 +08:00

36 lines
972 B
Go

package gui
import (
"os"
"path/filepath"
"testing"
)
// Pencil (pen.dev) is on the page once ~/.pencil is there, with magpie to
// put in its model picker, and not before (unless this Mac has the app).
func TestStateListsPencil(t *testing.T) {
home := sandboxHome(t)
find := func() *agentJSON {
for _, a := range state().Agents {
if a.ID == "pencil" {
return &a
}
}
return nil
}
_, app := os.Stat("/Applications/Pencil.app")
_, app2 := os.Stat("/Applications/pen.dev.app")
if a := find(); a != nil && app != nil && app2 != nil {
t.Fatalf("listed with no ~/.pencil: %+v", a)
}
os.MkdirAll(filepath.Join(home, ".pencil"), 0o755)
a := find()
if a == nil {
t.Fatal("Pencil not listed")
}
if a.Name != "Pencil" || a.Path != filepath.Join("~", ".pencil", "models.json") || len(a.Fields) != 1 || a.Fields[0].Key != "provider" ||
len(a.Fields[0].Options) != 1 || a.Fields[0].Options[0].Value != "magpie" {
t.Fatalf("Pencil: %+v", a)
}
}