DEV Community

Sandscale
Sandscale

Posted on Originally published at sandscale.dev

Go teams: setting up the coding agent's test loop on its own machine

A Go service compiles quickly once the module cache is filled, and slowly the first time an agent runs go test ./... on a cold machine. The first run downloads modules, builds a test binary for each package and runs go vet on the way. Later runs in the same module reuse that work. Two agents sharing one module cache and one laptop will step on each other; one agent with its own machine will not.

This post is about setting up that machine so the edit-test loop stays on it. The go test behaviour comes from the Go command documentation, read on 2 December 2026. Sandscale commands are from CLI 1.4.1. We do not show test output, because it depends on your packages.

Why a machine per agent suits Go

The Go documentation draws a distinction that matters for agents.

  • Local directory mode is go test with no package arguments. It compiles and runs the tests in the current directory. Caching is disabled in this mode.
  • Package list mode is go test with explicit package arguments, including go test ./... and even go test .. Successful package tests can be cached. When a result is reused, the documentation says go test prints (cached) in place of the elapsed time.

An agent that always runs go test ./... after a one-function change pays for every package, plus whatever the cache does not cover. An agent that runs go test ./internal/billing -run TestInvoiceTotal while it works, and go test ./... once before the pull request, is using the tool the way it is designed.

A Sandscale workspace is a persistent cloud machine with its own disk, CPU and memory, per agent. The disk survives stops and starts, so the Go toolchain, the module cache and compiled packages are still there next time.

What goes in the template

Ask whoever administers your workspace templates to put these in once:

  • A pinned Go toolchain, the same version your CI uses. A go directive in go.mod records the version the module expects; the machine should have at least that version installed.
  • git, and a C compiler if any package uses cgo.
  • Whatever the tests call outside the Go toolchain.

Then each engineer creates a machine for the task:

sandscale workspace create --name go-3301-billing --template-id TEMPLATE_ID --ttl-seconds 28800
sandscale workspace ssh go-3301-billing
Enter fullscreen mode Exit fullscreen mode

Whether the machine can reach the module proxy (by default proxy.golang.org) or your internal GOPROXY depends on your plan and your organization's network policy. If the first go test cannot download, that is the first place to look. GOPROXY and GOPRIVATE belong in the environment, not in a prompt.

Warm the cache once

Before handing the agent a task, download modules and compile the tests once:

go mod download
go test ./...
Enter fullscreen mode Exit fullscreen mode

go mod download fills the module cache. go test ./... compiles and runs every package once, which also fills the test cache in package list mode. Treat this as a warm-up. A new dependency still needs the network.

The loop: one package, one test

Teach the agent the narrow forms. These are all in the Go documentation:

go test ./internal/billing
go test ./internal/billing -run TestInvoiceTotal
go test ./internal/billing -count=1 -run TestInvoiceTotal
Enter fullscreen mode Exit fullscreen mode

-run takes a regular expression and runs only the tests that match. In package list mode, passing tests may be served from the cache; -count is not in the documentation's list of cacheable flags, so -count=1 is a reliable way to force a fresh run of the test you just changed. -failfast stops starting new tests after the first failure, which is useful in the loop and not a way to hide a failure.

As part of building a test binary, go test runs a high-confidence subset of go vet. If vet finds a problem, the documentation says go test reports it and does not run the test binary. An agent that then passes -vet=off to get past the error should be told not to, unless the task says to.

For a machine-readable summary the agent can act on, go test -json is the documented flag; our post on test results a coding agent can act on covers how to use it.

The AGENTS.md block

## Build and test (Go)
- Use the Go version the go.mod file expects. Do not install a different toolchain.
- While working, run only the package you changed:
  go test ./path/to/package -run TestName
- Before committing, run go test ./path/to/package for each package you touched.
- Do not delete the module cache to "fix" a build. If a download looks stuck, say so and stop.
- Do not use -vet=off to make a test command pass.
- Do not edit go.mod or go.sum unless the task says to change a dependency.
- Before opening a PR, run go test ./... once and put the result in the PR description.
Enter fullscreen mode Exit fullscreen mode

What the reviewer checks

A go.mod or go.sum change in a pull request is a signal. If the task did not ask for a dependency change, ask why. Our reviewer checklist covers the rest.

The full suite

go test ./... before the pull request, on the agent's machine if it fits, or on a larger leased machine if the module is heavy; see leasing a build host for a full test suite. CI on the pull request stays the merge gate, not the agent's loop. That split is the subject of why the edit-test loop should not wait on CI.

When the task is done, stop the machine. A running machine counts toward the plan's hours whether the agent is busy or waiting:

sandscale workspace stop --ws-id WORKSPACE_ID
Enter fullscreen mode Exit fullscreen mode

The disk is kept, so the next task starts with a warm module cache.

Originally published on the Sandscale blog.

Top comments (0)