* plugin: a slow reader pauses its stream instead of racing a watchdog #664 gave a plugin reply a soft watermark (softQueuedBytes 4 MiB, softQueuedEvents 4096) and a 10-second idle watchdog: past the watermark, a reader that made no progress for stallIdle had its call failed with errStalledReader, and hardQueuedBytes/hardQueuedEvents (64 MiB / 65536) cut the reply outright. Both are guesses at how long a reader may take, and both end a reply that reader was still consuming. The host now hands each fetch a credit window instead. Go grants streamWindow (512 KiB) up front and returns credit as the reader takes bytes, so the child stops producing at the window instead of being timed out; the window is charged per delivered byte plus frameOverhead (2048), so a run of tiny frames cannot fill it with metadata. streamBudget (64 MiB) and maxFrame (64 KiB) bound a whole reply and a single frame, and a child that sends past its window is a protocol violation (errProtocolOverrun) rather than a slow reader. The plugin side grew the matching gate (makeGate, gate.take/spend/add, waitDrain): a fetch holds at the window until Go credits it, and its pending writes are cancellable. Cancellation and shutdown now have one owner per call - a five-state lifecycle (sending, active, draining, aborting, released) whose single transition helper disposes the queue, detaches the watcher, commits the terminal answer, creates the abort and returns capacity exactly once - so a host failure, a Close, a cancelled context and an already-delivered reply can no longer race each other over who cleans up. A reply the host already delivered keeps its bytes and its vendor outcome when the host dies. Tests: the JS cancellation cases run the production sections with controlled stdout backpressure (stopped gate, split chunk, terminal suppression, acquired-body cancel, 30,000 cancelled bootstrap waits with no retained waiter or ready reaction); the Go cases drive lifecycle orderings directly (terminal-before-failure, failure-before-terminal, abort acknowledged before capacity returns, blocked enqueue), and the shutdown, body-close and mid-setup-cancel cases block on explicit channels instead of sleeping. TestFlowBigReplyProd reads 100 MiB non-SSE and SSE through the real host and checks lengths and SHA-256, including a 12 s reader pause. CI installs Bun 1.4.2 on Linux and runs that case in its own step, since the plugin sandbox skips when bun is not on PATH. * plugin: the stream-head credit test waits for the credits before the reply ends (CI, macos-latest: TestHostStreamHeadChunksFinal failed on the macOS runner with "the credits were given back didn't happen", while the same package passed on ubuntu-latest and locally) — the test sent the child's final answer together with its 50 chunks, so the call could be marked stopped and its pending credits dropped before waitFor saw them; a completed fetch needs no credit, so waiting longer could not recover them and the expectation was a race, not a real accounting bug. The final answer is now withheld until io.ReadFull has taken the 140 payload bytes in order and exactly 140 + 49*frameOverhead credits have been observed with frameOverhead still owed, and only then does the child answer and the test assert a zero-byte EOF read. No production code changed. Tests: go test -run '^TestHostStreamHeadChunksFinal$' -count=500 ./internal/plugin/ and -count=200 -race pass; go test -count=1 and -race -count=1 ./internal/plugin/... pass; gofmt -l and git diff --check clean.
131 lines
4.4 KiB
YAML
131 lines
4.4 KiB
YAML
name: Test
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
workflow_dispatch:
|
|
|
|
concurrency:
|
|
group: test-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
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.
|
|
- name: Install GTK and WebKitGTK
|
|
if: runner.os == 'Linux'
|
|
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
|
|
|
|
- name: Vet
|
|
run: go vet -tags "${{ steps.tags.outputs.tags }}" ./...
|
|
|
|
- uses: oven-sh/setup-bun@v2
|
|
if: runner.os == 'Linux'
|
|
with:
|
|
bun-version: 1.4.2
|
|
|
|
- name: Test
|
|
if: runner.os != 'Windows'
|
|
run: go test -tags "${{ steps.tags.outputs.tags }}" ./...
|
|
|
|
- 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.
|
|
- name: Race
|
|
if: runner.os != 'Windows'
|
|
# The full gateway suite can exceed Go's default 10-minute package
|
|
# timeout under the race detector on hosted macOS runners.
|
|
run: go test -race -timeout 20m -tags "${{ steps.tags.outputs.tags }}" ./internal/gateway/ ./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 '^$' ./...
|
|
|
|
# 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.
|
|
- name: Windows update install
|
|
if: runner.os == 'Windows'
|
|
run: go test -v -count=1 -timeout 2m ./internal/update -run '^(TestInstallBinary|TestMoveAside)'
|
|
|
|
# These tests use temporary paths, without the Unix HOME assumptions
|
|
# of the full suite. Run the native link-kind and sharing-error checks.
|
|
- name: Windows session moves
|
|
if: runner.os == 'Windows'
|
|
run: go test -v -count=1 ./internal/sessions -run '^Test(WindowsSession|Move|CopyAll)'
|
|
|
|
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
|