Files
magpie/internal/testenv
JoeyWu-tech 8cf9dbe6bd testenv: the test home holds XDG_CONFIG_DIRS too (#3372)
Isolate pointed HOME, USERPROFILE, the XDG_*_HOME folders, APPDATA and
LOCALAPPDATA into the temporary home, and left XDG_CONFIG_DIRS as the
machine has it. The next commit has Open at login on Linux read a
package's autostart entry in $XDG_CONFIG_DIRS/autostart, /etc/xdg when
it is unset or empty (#3372), and the gui's settingsState reads Open at
login (api.go's loginState) in many tests. On a machine with a package's
magpie.desktop (NixOS, or a distro's package some day) their s.Login
would follow that entry, and a test switching it would write a hiding
entry where it expects none. LESSONS has the rule: give the sandbox
every variable the code reads (ee7a9b24a).

Now Isolate points XDG_CONFIG_DIRS at <home>/etc/xdg, which nothing
makes, so a test reads no system entry unless it writes one there. Every
test package that reaches internal/autostart (autostart, cli, daemon,
gui and tui) isolates through testenv. It isn't one of folderVars:
checkChild checks each of those as one path in the temporary folder, and
XDG_CONFIG_DIRS is a list.

Rebased onto origin/main 58fb3a77 with the next commit; this one is
as it was.

What was run (tree 2da4f92a, on origin/main 58fb3a77, go1.26.8,
linux/amd64, Linux 5.15), outside graftcp, umask 077:
- This commit's tree alone: not run. At the next commit's tree
  (59fb33a8), go test ./internal/testenv -v: TestIsolate ok, and all
  but TestProgram (umask 077, #3640); the full suite there is in the
  next commit.

The rest is what was run for 2d17d5e8, at tree efb86cbc on origin/main
6e6aba51, the same code (not this tree):
- TestIsolate sets XDG_CONFIG_DIRS to /etc/xdg before Isolate, and now
  checks that it lies in the test home after. With the new line taken
  out of Isolate by hand it went red, testenv_test.go:65:
  XDG_CONFIG_DIRS is "/etc/xdg", outside
  "/tmp/magpie-test-home-1706789611"; put back, it passed.
- The testenv package through pkgtest.sh, outside graftcp: all pass but
  TestProgram, red under this box's umask 077 (#3640), as it is when run
  alone at origin/main 6e6aba51. No -race: the change sets one more
  variable before any test starts.
- Full suite, -tags nogui (CI's Linux job tags gtk3), outside graftcp
  (systemd-run, umask 077, Bun 1.4.2 first on PATH as on CI, -timeout
  45m, log kept): 64 packages ok and 8 packages red, each filed: #3640
  (umask 077: testenv's TestProgram, as above, and edit's
  TestWriteAtomicReadOnlyHardLink), #3141 (TestInstalledVersion,
  TestCursorFolderFromTheEditorIsNotTheCLI,
  TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
  TestQoderSettingsFromAnIDEPluginIsNotTheCLI,
  TestOmpDetectedWithPiDir), #3398 (TestCodexDriftReached), #3641 (the
  two Reasonix tests, this box's /tmp/.git), #3420 (davsync's TestSync),
  #3675 (TestPluginToldWhereTheAgentWorks, this box's /tmp/.git), #3649
  (TestGatewayHeldByAContainer and TestGatewayFixQuitsOnlyAMagpie, this
  box's open fds), #3741, and provider's synctest fatal (#3632) in
  TestUnreadLoginsWriteErrorsKeepCredentials, after which that package's
  tests didn't run.
- gofmt -l: clean. go vet -tags nogui for linux, windows and darwin,
  GOOS=windows go vet ./..., GOOS=freebsd go vet ./internal/testenv/, go
  build -tags nogui for linux and darwin and GOOS=windows go build
  ./...: all clean. Untagged linux vet and build stop at pkg-config here
  (no GTK headers on this box).

Not changed: internal/gateway isolates itself in its own TestMain, not
through testenv, and doesn't set XDG_CONFIG_DIRS; none of its tests
reach internal/autostart.

Not tried: a machine with a package's magpie.desktop in
/etc/xdg/autostart (this box has none), where without this the gui's
tests would read it once the next commit is in.

Batch run, at tree 104d75f0a (the twelve coffemon ports together, on
origin/main 7d022bdb6), mote, macOS, go1.26.8:
- go test -tags nogui -count=1 -timeout 45m on the packages the batch
  changes (agent, autostart, daemon, gateway, library, proc, provider,
  sessions, testenv, tui, gui): ok each.
- GUI, node --test with Playwright 1.62.0, Chromium and WebKit:
  library-*.test.cjs and i18n-keys.test.cjs, 1044 of 1044 pass.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... and go build ./...: ok at cdd7c8e46, the same
  batch on origin/main 00098f12b one rebase before.
- The whole go test ./... at cdd7c8e46: 86 packages ok, one red,
  internal/cli TestEveryRouteHasACommandOrIsNamed (GET
  /api/context/reply has no command), red on main too (#5026).
- Linux (wsl-run, Ubuntu 24.04, at 339055896, the batch on f4c664a09):
  proc, autostart, testenv, tui ok; agent: only TestGrokInstalled red
  (#3548); #4033's proc.Look reds (Zed, Copilot, Qoder, Cursor, Omp)
  pass.
- Windows (win-run, Windows 11, at 339055896): proc, autostart, testenv,
  tui ok; library and agent red in the same tests as on origin/main
  f4c664a09 (#4115, #1827, #4786; #5068, #5069, #5070 filed now).
- Rebased onto origin/main fb1f4856a (three commits, no file in
  common with the batch) and run again at the pushed tree: gofmt -l
  nothing, go build ./... and go vet ./... ok; go test -tags nogui
  sessions, agent, autostart, tui, proc, testenv ok; i18n-keys and
  library-* 1044 of 1044 pass.
- Not run before the push: the whole GUI suite (a run at cdd7c8e46 was
  cut off at 1170 of ~1174 tests when mote rebooted; it runs again after
  the tag and any red is filed).
2026-11-03 20:38:11 +08:00
..
gateway, provider tests: the tests stay off the network (testenv.Offline in their TestMains) — after 555f5706 (#1016) routing reads a plan key's quota windows, and a test whose provider has a vendor's real base URL and a made-up key would ask the vendor in the background. Routing's own read (keyAllowance, allowances) was already stubbed in routing_test.go's init, and a survey with a dial guard found no plan-key dial, but it found others: every plugin host's first start fetched models.dev's catalog (65 dials in the gateway's plugin tests), and provider tests asked api.github.com (TestSubscriptionUsageEachAccount, TestSubscriptionUsageServesStale), chatgpt.com (TestCopilotQuotaWithoutEditorsSignIn), server.codeium.com (TestDevinSignedInOnlyInMagpie) and decide.test (TestModelTest) with made-up accounts; each passed whether the vendor answered or not. internal/testenv's Offline wraps http.DefaultTransport's DialContext (so http.DefaultClient and every transport cloned from it later): localhost, *.localhost, loopback and unspecified addresses are dialled, anything else is refused before it is looked up, said once per address on stderr ("testenv: a test asked models.dev:443, refused: tests stay off the network"). internal/gateway's TestMain and internal/provider's (kiro_main_test.go, in RunIn's setup) call it before the tests run. TestLocal (the address table) and TestOffline (a loopback httptest server answers through DefaultClient; models.dev is refused through it and through a Clone made after the call) pass -race -count=3. go test -race -tags nogui -timeout 30m ./internal/testenv ./internal/provider ./internal/gateway passes under a temp HOME (gateway 516 s). The gateway and provider test binaries were then run under sandbox-exec with every non-loopback network-outbound denied, with the kernel's Sandbox reports streamed: both PASS, Offline refused only the six addresses above, and the kernel reported no denial, so no transport outside DefaultTransport reaches the network either. go vet, gofmt -l, linux and windows (nogui) builds pass. Tests only.
2026-10-06 21:08:57 +08:00
gateway, provider tests: the tests stay off the network (testenv.Offline in their TestMains) — after 555f5706 (#1016) routing reads a plan key's quota windows, and a test whose provider has a vendor's real base URL and a made-up key would ask the vendor in the background. Routing's own read (keyAllowance, allowances) was already stubbed in routing_test.go's init, and a survey with a dial guard found no plan-key dial, but it found others: every plugin host's first start fetched models.dev's catalog (65 dials in the gateway's plugin tests), and provider tests asked api.github.com (TestSubscriptionUsageEachAccount, TestSubscriptionUsageServesStale), chatgpt.com (TestCopilotQuotaWithoutEditorsSignIn), server.codeium.com (TestDevinSignedInOnlyInMagpie) and decide.test (TestModelTest) with made-up accounts; each passed whether the vendor answered or not. internal/testenv's Offline wraps http.DefaultTransport's DialContext (so http.DefaultClient and every transport cloned from it later): localhost, *.localhost, loopback and unspecified addresses are dialled, anything else is refused before it is looked up, said once per address on stderr ("testenv: a test asked models.dev:443, refused: tests stay off the network"). internal/gateway's TestMain and internal/provider's (kiro_main_test.go, in RunIn's setup) call it before the tests run. TestLocal (the address table) and TestOffline (a loopback httptest server answers through DefaultClient; models.dev is refused through it and through a Clone made after the call) pass -race -count=3. go test -race -tags nogui -timeout 30m ./internal/testenv ./internal/provider ./internal/gateway passes under a temp HOME (gateway 516 s). The gateway and provider test binaries were then run under sandbox-exec with every non-loopback network-outbound denied, with the kernel's Sandbox reports streamed: both PASS, Offline refused only the six addresses above, and the kernel reported no denial, so no transport outside DefaultTransport reaches the network either. go vet, gofmt -l, linux and windows (nogui) builds pass. Tests only.
2026-10-06 21:08:57 +08:00