Files
magpie/internal/library/instructions_only_test.go
T
yetone f57dc9610b library, gui: an instruction set made, saved or removed writes only the instructions, and the page holds its buttons while it does (#1624, Hipple)
On Windows 11 the Library's Instructions tab took 30s+ to show, and each
instruction made, saved or removed took about a minute with nothing on
the page to say so; a second click made a second set or removed twice.

What an instruction change cost:
- SaveInstructions and ImportInstructions went through change(), which
  gives every agent its MCP servers and skills again too (takeEdits and
  syncSkills look through every skill folder, and the projects), and
  the API then answered with a whole library.Read, which reads every
  agent's skill folders through again (foundSkills, behind: minutes on
  a machine with many skills, #541).
- Every read of the library found the agents (Targets: every agent's
  folders, WSL too) three times: ReadInstructions, readView, and
  foundServers.

Now:
- library: changeInstructions writes only the instructions into the
  agents (with backups as before); readView finds the agents once and
  passes them to instructionsView and foundServersOf. ReadInstructions
  stays for the TUI.
- gui: an instructions/* action answers {part: "instructions",
  instructions, result, problems}; the problems the last change had with
  servers and skills stay, those with the instructions are the new
  change's.
- library.js change(): one change at a time; while one is out the
  page's (and the Library dialog's) buttons are disabled, the page is
  aria-busy, the button pressed says "Saving…" and so does the status.
  An answer with part "instructions" is merged into the page's library.

Timed on the Windows test box (sandbox profile, 1 agent, 80 skills, copy
mode): an instruction create was ~170ms + a ~460ms Read, now ~80ms + a
~70ms instructions read; Glance 350 -> 200ms, Read 480 -> 320ms. The
30s/1min the reporter sees wasn't reproduced there.

Tests (each fails on the old code):
- TestInstructionChangeWritesOnlyInstructions: a server taken out of
  codex's config by hand stays out through instruction create, switch,
  save and remove, and comes back with a server change.
- TestInstructionChangeAnswersInstructions: the instructions answer and
  the problems kept.
- library-instr-busy.test.cjs: a double click on Add sends one create,
  every page button is disabled and the pressed one says Saving… while
  the answer is held, the page keeps the rest of the library after an
  instructions-only answer; the sure Remove double-clicked sends one.
  Chromium and WebKit, en/zh/zh-TW/ja/de.

Also run: go test ./internal/library ./internal/gui ./internal/tui;
gofmt; GOOS=linux and windows go vet; every library*.test.cjs plus the
30 other GUI tests that reach the Library, Chromium and WebKit: all pass
but library-mcp-tool-switch in WebKit, which fails the same alone on
origin/main (#1609), and mobile-web's desktop-vs-main check, which needs
a git checkout the scratch copy it ran in hadn't.
2026-10-12 00:10:59 +08:00

42 lines
1.6 KiB
Go

package library
import (
"path/filepath"
"strings"
"testing"
)
// A change to the instructions writes the instructions and nothing else:
// it gave every agent its MCP servers and skills again too, looking through
// every skill folder, which took up to a minute a click on Windows (#1624,
// Hipple). A server taken out of an agent's file by hand stays out of it
// through an instruction made, saved, switched or removed, and comes back
// with the next change to the servers.
func TestInstructionChangeWritesOnlyInstructions(t *testing.T) {
h := sandbox(t)
ok(t)(SaveServer("", Server{Name: "fs", Transport: "stdio", Command: "npx", Agents: []string{"codex"}}))
cfg := filepath.Join(h, ".codex/config.toml")
if !strings.Contains(read(t, cfg), "fs") {
t.Fatalf("codex wasn't given the server:\n%s", read(t, cfg))
}
write(t, cfg, "")
shared := "Be brief."
ok(t)(SaveInstructions(InstructionsChange{Shared: &shared, Agents: []string{"codex"}}))
work := "Work rules."
ok(t)(SaveInstructions(InstructionsChange{Create: &InstrSet{ID: "work", Name: "Work"}, Texts: map[string]*string{"work": &work}, Activate: "work"}))
ok(t)(SaveInstructions(InstructionsChange{Activate: "default"}))
ok(t)(SaveInstructions(InstructionsChange{Remove: "work"}))
if s := read(t, filepath.Join(h, ".codex/AGENTS.md")); !strings.Contains(s, "Be brief.") {
t.Errorf("codex's instructions:\n%s", s)
}
if s := read(t, cfg); strings.Contains(s, "fs") {
t.Errorf("an instruction change wrote the servers again:\n%s", s)
}
ok(t)(ServerAgents("fs", []string{"codex"}))
if s := read(t, cfg); !strings.Contains(s, "fs") {
t.Errorf("a server change didn't write the servers:\n%s", s)
}
}