Files
magpie/.github/workflows/test.yml
T
yetone 75d40ba48b ci: race gateway tests run in chunks taken in turn; 64 MB bodies are 20 MB under -race
The macOS -race gateway step split 3772 tests by sorted name into one
fixed share per core (3 on macos-latest), and the shares ran out of their
20 minutes with no test hung: run 42354008450 at 191f3c0af ended at 12m,
16m and over 20m (shard 2 in TestMediaJSONPastOldBodyLimit/images), and
42350695944 ran all three at ~19m20s. Two causes: the shares were uneven,
and a few tests scan tens of MB byte by byte, which the race detector
makes 14 to 30 times as slow.

Measured on mote (M5 Pro), -race, -test.v, old script, per test (plain
run in brackets): TestLoopGuardLeavesOrdinaryRepliesAlone 104s (7.6s),
TestLargeRequestEndpoints 104s (3.6s), TestRequestTailAfterOldLimit 33s
(4s), TestCodexBodyReadsPastOldLimit 14.6s (0.55s),
TestMediaJSONPastOldBodyLimit 10.7s (0.7s), TestCodexCompressedTailError
10.2s. Sums of test time per share: 487s, 641s, 761s.

- build/race-shards.sh: the tests go in ~118 chunks of about 32 (test N
  in chunk N mod m, so TestCodex..., TestCompaction... spread out), and
  each of the N workers takes the next chunk when it is done (xargs -P).
  Workers end within a chunk of each other. Each chunk logs in its own
  ::group:: with its time; the five slowest are printed at the end. A
  chunk whose process didn't finish counts as failed.
- oldBodyLimit (the pre-#118 64 MB) is 20 MB under -race
  (race_on_test.go), 64 MB in the plain run. 20 MB still passes every cut
  below 64 MB (bodyKept's 4 MB, the 8 MB and 16 MB reads); the plain Test
  step on ubuntu and macOS still sends the full 64 MB.
- TestLoopGuardLeavesOrdinaryRepliesAlone is skipped under -race: one
  goroutine feeds one loopGuard (loop_guard.go starts none), so there is
  no race to find; the plain run reads the whole corpus.

After, per test on mote under -race: TestLargeRequestEndpoints 40.7s,
TestRequestTailAfterOldLimit 13.05s, TestCodexBodyReadsPastOldLimit
5.1s, TestMediaJSONPastOldBodyLimit 4.46s, TestCodexCompressedTailError
3.1s, TestLoopGuard skipped: ~210s less race time.
A/B in one window on mote (same commit, binaries built from base and
change, 3 workers, load 15 to 30): old script with old tests 12m59s
wall (red: TestTranslatedStreamKeepsClientAlive, the load-timing test
of #2711/#2737); new script with new tests 10m57s, green, slowest
chunk 62s. On 3-core CI the wall should be about the total over three
plus a chunk, instead of the slowest share.

Broken by hand (wsl-run, Linux): defaultBodyLimit 16<<20 under -race
turns TestCodexBodyReadsPastOldLimit, TestLargeRequestEndpoints and
TestRequestTailAfterOldLimit red (body rejected / 413); defaultBodyLimit
48<<20 in the plain run turns the same three red. So the race run guards
the read-whole path past 16 MB and the plain run still guards 64 MB.
TestCodexCompressedTailError and TestMediaJSONPastOldBodyLimit stay green
with either cap: they never guarded the limit (true before this change).

Run: gofmt -l; on mote GOOS=linux go vet -tags nogui ./..., GOOS=windows
go vet ./..., go vet ./..., go vet -race ./internal/gateway; the seven
touched tests plain on mote (all pass, 21.9s); the whole gateway package
under -race through the new script on mote twice (one red,
TestBurstTellsNoSpeed/responses_from_chat_burst, the load timing of
#2719; the second run green).
Not tried: the race run with a 48 MB cap (it would pass: under -race
nothing now covers 20 to 64 MB, the plain step does); a CI run before
the push.

Fixes #5361
Fixes #5320
2026-11-07 19:45:30 +08:00

182 lines
7.1 KiB
YAML

name: Test
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
# On main a run finishes: a release waits for a green run, and one cancelled
# by every next push left none to wait for (LESSONS.md). A newer push still
# replaces a run that hasn't started. A PR's run is cancelled by its next push.
concurrency:
group: test-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
permissions:
contents: read
jobs:
test:
name: test (${{ matrix.os }})
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
# The GUI links GTK 3 and WebKitGTK 4.1 through cgo on Linux (see the
# Makefile), so vet and test need their headers and the gtk3 tag.
# A stuck apt mirror held main's run here for 2.5 hours (b0d456c3), and
# every later push queued behind it; it takes under a minute.
- name: Install GTK and WebKitGTK
if: runner.os == 'Linux'
timeout-minutes: 15
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.1-dev
- name: Tags
id: tags
shell: bash
run: |
if [ "$RUNNER_OS" = Linux ]; then echo "tags=gtk3" >> "$GITHUB_OUTPUT"; fi
# Unformatted files reached main 8 times from 10-01 to 10-06 and each
# took a gofmt commit of its own. Linux only: Windows checks out CRLF.
- name: Gofmt
if: runner.os == 'Linux'
shell: bash
run: |
bad=$(gofmt -l $(git ls-files '*.go'))
if [ -n "$bad" ]; then echo "not gofmt'd:"; echo "$bad"; exit 1; fi
- name: Vet
run: go vet -tags "${{ steps.tags.outputs.tags }}" ./...
- uses: oven-sh/setup-bun@v2
with:
bun-version: 1.4.2
# internal/gateway takes 450-600s on macOS runners, and go test's
# default 10m timed it out in 3 of 8 finished main runs (#2108).
- name: Test
if: runner.os != 'Windows'
run: go test -timeout 30m -tags "${{ steps.tags.outputs.tags }}" ./...
# Windows skips the Test step above, so the two plugin stderr tests run
# here. The end-to-end one needs bun on PATH; without it it skips.
- name: Plugin stderr tests (Windows)
if: runner.os == 'Windows'
shell: bash
run: |
bun --version
go test -v -count=1 ./internal/plugin/ -run '^(TestHostStartsPastAnOverlongStderrLine|TestDrainStderrKeepsTheChildGoing)$'
- name: Production plugin flow
if: runner.os == 'Linux'
timeout-minutes: 10
env:
MAGPIE_FLOW_BIG: '1'
run: |
bun --version
go test -timeout 10m -tags "${{ steps.tags.outputs.tags }}" ./internal/plugin/... -run '^TestFlowBigReplyProd$' -count=1
# The redaction tests reuse this binary in fresh processes to check
# first-use races, so it must include the race detector. The gateway's
# tests can't call t.Parallel (t.Setenv), so its suite runs in chunks,
# one process per core at a time, each taking the next chunk when done
# (#923, #5361); each process isolates its own home.
- name: Race
if: runner.os != 'Windows'
shell: bash
run: |
go test -race -c -o "$RUNNER_TEMP/gateway.race" -tags "${{ steps.tags.outputs.tags }}" ./internal/gateway/
build/race-shards.sh internal/gateway "$RUNNER_TEMP/gateway.race" "$(getconf _NPROCESSORS_ONLN)" -test.timeout=20m
go test -race -tags "${{ steps.tags.outputs.tags }}" ./internal/redact/
# Account usage mixes cached results with concurrent fetches.
- name: Race account usage
if: runner.os != 'Windows'
run: go test -race -tags "${{ steps.tags.outputs.tags }}" ./internal/provider/ -run '^Test(LoginUsage|SubscriptionUsageEachAccount)'
# Some tests fake a home through $HOME, which Windows doesn't read
# (USERPROFILE), or assume Unix file modes. Compile the full suite
# on Windows and run the isolated native checks below.
- name: Compile tests
if: runner.os == 'Windows'
run: go test -run '^$' ./...
# These checks use in-memory errors and loopback test servers. Run
# the native Winsock refusal case rather than only compiling it.
- name: Windows MCP health
if: runner.os == 'Windows'
run: go test -v -count=1 -timeout 2m ./internal/library -run '^(TestNetHealth|TestCheckHTTP)$'
# Usage isolates USERPROFILE and the agent homes; execute its native
# ChangeTime checks rather than only cross-compiling the Windows API.
- name: Windows usage cache
if: runner.os == 'Windows'
run: go test -v -count=1 ./internal/usage -run '^(TestWindows|TestLogChange|TestLogFileInfoPreservesIdentity$|TestUsageSameSizeAndMtimeRewrite$|TestLogGrowingRewriteThenAppend$|TestUsagePageCacheAfterUncachedQuery$)'
# Install tests keep their files in t.TempDir; exercise real Windows
# executable and held-handle rename/rollback behavior, and the trial
# start before the install (#2272).
- name: Windows update install
if: runner.os == 'Windows'
run: go test -v -count=1 -timeout 2m ./internal/update -run '^(TestInstallBinary|TestMoveAside|TestTrialStart)'
# These tests use temporary paths, without the Unix HOME assumptions
# of the full suite. Run the native link-kind and sharing-error checks,
# and the Codex copy checks that read NTFS ChangeTime (#1299).
- name: Windows session moves
if: runner.os == 'Windows'
run: go test -v -count=1 ./internal/sessions -run '^Test(WindowsSession|Move|CopyAll|CodexArchived|CodexSameTick|CodexPlainTwin)'
# dsh's layered config is read and edited in temporary homes. Run
# these checks on Windows too, including Desktop's home patch layer.
- name: Windows dsh configuration
if: runner.os == 'Windows'
run: go test -v -count=1 ./internal/agent -run '^Test(Dsh|KeepDsh)'
- name: Windows VS Code detection
if: runner.os == 'Windows'
run: go test -v -count=1 ./internal/agent -run '^TestVSCodeDetected$'
cli:
name: cli (${{ matrix.goos }}/${{ matrix.goarch }}, nogui)
strategy:
fail-fast: false
matrix:
include:
- goos: linux
goarch: amd64
- goos: android
goarch: arm64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Build the terminal-only release
env:
CGO_ENABLED: '0'
run: make release-cli TARGETS="${{ matrix.goos }}/${{ matrix.goarch }}"
- uses: actions/setup-node@v4
if: matrix.goos == 'linux'
with:
node-version: 22
- name: Test the site and installer
if: matrix.goos == 'linux'
run: |
sh -n site/public/install.sh
node --test site/*.test.mjs