Documentation
¶
Overview ¶
Package testenv contains helpers used by tests to assert hermeticity preconditions. The headline helper is RequireContainer, which fast-fails any test that ought to run inside the agentsync hermetic container but is somehow being run on the host.
Index ¶
Constants ¶
const EnvVar = "AGENTSYNC_TEST_IN_CONTAINER"
EnvVar is the explicit signal the agentsync test container sets at runtime. The hermetic entrypoint exports it; production environments never do.
Variables ¶
This section is empty.
Functions ¶
func InContainer ¶
func InContainer() bool
InContainer reports whether this process is plausibly running inside a Linux container. It is intentionally permissive — any one of the following signals is enough:
- the agentsync entrypoint's AGENTSYNC_TEST_IN_CONTAINER=1 export
- /.dockerenv (docker convention)
- /run/.containerenv (podman convention)
- /proc/1/cgroup mentions docker / podman / containerd / kubepods
We do not require ALL signals — engineers running ad-hoc shells inside the test image (e.g. `scripts/test-in-container.sh shell`) inherit the env var but might not have /.dockerenv mounted on every runtime. One signal is enough to honour the "running in a container" intent.
func MustRunInContainer ¶
func MustRunInContainer()
MustRunInContainer is the TestMain-friendly counterpart to RequireContainer. It writes a clear message to stderr and exits non-zero when invoked outside a container, before any test in the package runs. Use from TestMain like:
func TestMain(m *testing.M) {
testenv.MustRunInContainer()
os.Exit(m.Run())
}
func RequireContainer ¶
RequireContainer is the canonical guard for FS-touching tests (integration / e2e / bdd). It must be called as the first line of TestMain (or each TestXxx) in any package whose tests use t.TempDir(), AGENTSYNC_TARGET_ROOT, or otherwise write to disk.
On host execution it calls t.Fatalf with a clear remediation message, which surfaces in `go test` output and short-circuits the rest of the test. Inside the container it is a fast no-op.
Types ¶
This section is empty.