testenv

package
v0.119.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package testenv isolates a test process from the ambient machine state documented in internal/envguard: WB_AGENT_* variables inherited from whichever agent is operating the shell that launched `go test`, and an ambient GOWORK the test process would otherwise carry into every `go` invocation it makes.

WB's own test suite runs as a subprocess of that operating agent. A test that asserts "no active owner" or "no live registered session" observes the outer agent's identity instead of a clean slate unless it calls Isolate first: WB_AGENT_PID/WB_AGENT_RUNTIME/WB_AGENT_MODEL/WB_AGENT_ID are inherited by the `go test` binary itself, not only by subprocesses wb spawns, so internal/envguard's subprocess-environment sanitizing cannot reach them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Isolate

func Isolate(t testing.TB)

Isolate truly unsets every WB_AGENT_* variable -- the key itself is removed from the environment, not merely emptied -- and sets GOWORK=off for the current test's environment. It restores every value it changed, via t.Cleanup, when t (or the subtest it was called from) completes.

t.Setenv("WB_AGENT_X", "") is not enough: it leaves the key present with an empty value, and envguard.Inspect (like most agent-var detection) keys off presence in os.Environ(), not value, so an emptied variable still reads as set. Isolate calls os.Unsetenv directly instead.

A test that intentionally exercises agent-mode behavior calls Isolate first and then sets its own WB_AGENT_* value with t.Setenv, so the intentional value applies last and is the one the code under test observes.

Like t.Setenv, Isolate makes the calling test (and its subtests) unsafe to run in parallel with sibling tests that also touch the process environment: it mutates shared process state and only restores it on this test's own Cleanup.

func IsolateProcess

func IsolateProcess()

IsolateProcess performs the same isolation as Isolate for a caller with no *testing.T -- typically a package's TestMain, which isolates its whole test binary process before any test runs. Unlike Isolate this is not restored: TestMain's process exits once m.Run() returns, so there is nothing to restore it for.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL