homeenv

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package homeenv isolates a test binary from the real developer machine's persistent boid state — $HOME, the XDG base directories, and the docker engine — and lets a test assert that the isolation is actually in place.

Why this exists as a package rather than a copy-pasted TestMain body: boid resolves several persistent roots — the workspace homes root (dispatcher.WorkspaceHomesDir), the workspace home init bookkeeping root (dispatcher's workspaceHomeMetaDir, docs/plans/workspace-home-volume-persistence.md 論点b), the daemon's own ~/.config/boid — from $XDG_DATA_HOME / $XDG_CONFIG_HOME / $HOME whenever the corresponding *Runner field is left empty, and a bare `dispatcher.Runner{}` is the standard minimal test wiring across several packages. Any package whose tests reach Runner.Dispatch (directly, or through a service that does) therefore has to install the same isolation, and every additional hand-rolled copy is another place for the set of variables to drift out of sync — the same single-source reasoning internal/dockerres was created for in PR1 of that same plan doc.

The engine went on the same list in PR7 of that plan doc (論点 a-2), because the volume-only pivot moved a persistent root the tests can destroy OFF the filesystem entirely: a workspace's $HOME is a docker named volume now, so isolating $XDG_DATA_HOME no longer isolates it. See dockerSocketName's own comment for the measured incident.

Everything here is test-only. It is imported from _test.go files and from testutil (itself test-only — it takes *testing.T), so it never links into the shipped binary despite importing "testing".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertIsolated

func AssertIsolated(t *testing.T)

AssertIsolated fails t when Unisolated reports anything — i.e. when the package under test has no TestMain calling Run/Isolate, or gained a new variable the lists above cover but that TestMain does not.

Call it from a test in every package whose suite can reach a code path that resolves a boid data/config root, or a docker engine, from the environment. Without it, losing the TestMain is silent: the suite keeps passing, it just starts writing into (and, via init.sh, executing code from) the real user's boid installation — and, since PR7 of docs/plans/workspace-home-volume-persistence.md, deleting named volumes off their real engine. That is not hypothetical — it is exactly what internal/server's suite did until PR2 of that same plan doc added its TestMain, and what internal/api's did until PR7's round-2 review.

func Isolate

func Isolate() (cleanup func(), err error)

Isolate points HOME, the XDG base directories and DOCKER_HOST at a fresh temp directory (clearing the remaining docker transport variables) and returns a function that removes it. Callers that use Isolate directly (rather than Run) are responsible for calling the returned cleanup — and for not calling os.Exit before it runs.

func Run

func Run(m *testing.M) int

Run is the whole body of a TestMain that needs nothing else:

func TestMain(m *testing.M) { os.Exit(homeenv.Run(m)) }

It points every isolatedKeys variable at a throwaway temp directory for the lifetime of the test binary, runs the suite, removes the temp directory and returns m.Run's exit code. Individual tests that want their own per-case isolation still call t.Setenv with a fresh t.TempDir(); that overrides this process-wide default for one test and is restored afterwards, so the two layers compose rather than conflict.

A package whose TestMain has other work to do (spawning itself as a helper process, say) should call Isolate directly instead.

func Unisolated

func Unisolated() []string

Unisolated reports every variable this package manages that is still the developer's own: an isolatedKeys entry unchanged since the test binary started, or a clearedKeys entry that is still set. An empty result means Isolate (or Run) has taken effect.

Exported as a plain predicate, rather than living inside AssertIsolated, so the same judgment can be made where there is no *testing.T-shaped assertion to hang off — specifically testutil.NewTestServer, which refuses to boot a daemon into an un-isolated environment. Two copies of this rule would be two places for the key list to drift.

Types

This section is empty.

Jump to

Keyboard shortcuts

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