Expand description
Portable helpers for CortexKit tests. Use this crate as a dev-dependency only.
Scratch fixtures preserve failure evidence, executables are published as
immutable ckdev-* copies, and daemon builders enforce an ambient-root fence.
Structs§
- Cached
Sibling Binary - Paths to the cached Cargo target directory and the executable used by tests.
A
ck-*artifact is copied to a separateckdev-*publication before running, so its execution path is not the path where Cargo wrote the build output. - Scratch
Dir - Owned scratch fixture. Drop removes it unless unwinding or explicitly kept.
- Subc
Daemon Binary - The platform daemon
ck-subc, built from thesubconscioussibling checkout. Its executable path is private so callers can only spawn it through a builder that redirects its directory variables and owns its process lifetime. - Test
Daemon - Owns the parent pipe and process group. Drop is bounded and synchronous, so when a test panics, the daemon is torn down before the test’s scratch directory is deleted.
- Test
Daemon Command - Command builder whose only spawn operation returns an owned
TestDaemon. It enforces scratch-root isolation and keeps the child tied to a lifetime pipe. Unix consumers requirepython3on PATH to run the process-lifetime watcher.
Constants§
- PRIVILEGED_
TESTS_ ENV - Opt-in variable for tests requiring passwordless sudo, namespaces, or root.
- STABLE_
BIN_ DIR - Shared executable directory exempt from the scratch age sweep.
Functions§
- assert_
test_ binary_ spawns - Assert that Rust test sources in these directories stage production-named
artifacts with
ckdev_binarybefore spawning them. Comments are ignored. This lexical guard covers direct paths and simple raw-path bindings, not arbitrary data flow. Pair it withdev_commandfor runtime name refusal. Missing directories or an empty source scan panic rather than pass silently. - build_
sibling_ binary - Build a sibling using a cache key derived from its current source revision and caller-selected adjacent dependency checkouts. The same dependency names are checked again after compilation to reject sources changed during the build.
- cached_
sibling_ binary - Resolve an immutable executable, building only on a cache miss.
revisionmay be an explicit pin rather than the live checkout’s HEAD. The builder receives a staging Cargo target directory and must producedebug/<bin>. A sibling-wide OS lock covers publication and pruning, including across processes; dropping the file releases it even when a builder panics. - cached_
sibling_ binary_ with_ target - Resolve both paths so a caller can track or restrict where Cargo writes build files separately from the executable path used to start test processes.
- checked_
output - Execute a prepared command, returning an error with the exit code or signal
number and name on failure. Plain
Command::outputdoes not reject failed exits. - ckdev_
binary - Publish a built executable under a content-addressed
ckdev-*name. Already-dev-named paths pass through. Unix copies live under/tmp, never$TMPDIR, to avoid per-user temporary-directory execution assessment delays. A child writes a private staging copy, then an atomic rename publishes it. This avoids hard-link execution failures and writable descriptors inherited by concurrently spawned children. Published files are read-only, verified against their digest on reuse, and pruned after three days. Usechecked_outputto report failed child exits, including signal names. - ckdev_
file_ name - The
ckdev-name for a built binary’s file name:ck-subcbecomesckdev-subc,ckbecomesckdev-ck, any other namenbecomesckdev-n, and a name that already starts withckdev-is returned as it is. A trailing.exestays at the end, so Windows still runs the result. - describe_
exit_ status - Human-readable child failure, including Unix signal kills rather than
None. - dev_
command - A
Commandforprogramthat refuses (panics) whenprogramhas a production executable name. Use it for every test spawn of a CortexKit binary, with a path made byckdev_binary. - exempt_
production_ executable - Validate a caller-supplied exact
(test name, executable stem)exemption. The calling test thread must also match; exemptions cannot be borrowed. Returnsprogramwhen the test namedtestis the one test allowed to place an executable withprogram’s production name (the exemption table in this crate); panics for any other test or name. A trailing.exeis ignored, so the exemption holds on Windows too. - fenced_
command - Build a command with no inherited environment except the allowlisted PATH,
locale, timezone, user-name, and backtrace variables. Inherited API keys,
tokens, and module identity variables are removed; HOME, XDG directories,
and TMPDIR instead point beneath scratch. A
ck-*program is copied to a reusableckdev-*executable before the command is constructed. Usecrate::TestDaemonCommandwhen roots must also resist later overrides and the child must terminate with the test harness. - fenced_
command_ with_ roots - Like
fenced_command, with caller-selected directory variables redirected beneath scratch. Each pair is(variable, plain subdirectory name); built-in variables cannot be replaced. Invalid names, duplicates, and symlink roots panic. As with a standardCommand, later.envcalls can override these values;crate::TestDaemonCommand::fenced_rootenforces them again when spawning. - fenced_
subc_ daemon_ env - Create directories beneath scratch and return their environment assignments. HOME, all five XDG directory variables, and TMPDIR point into this test tree so a daemon and its children do not write to the user’s normal directories.
- fenced_
subc_ env_ dir - Return the scratch subdirectory assigned to a built-in directory variable,
such as
XDG_DATA_HOME. Unknown variable names panic rather than resolving to a directory that the child never uses. - is_
production_ executable_ name - Executable names a test must never run a process under.
- pinned_
sibling_ build_ revision - Return a cache key combining an archived source revision with caller-supplied dependency names and full commit SHAs. Changing any dependency pin produces a new key; fetching or unpacking those source revisions is up to the caller.
- privileged_
tests_ enabled - Returns true only for
CORTEXKIT_PRIVILEGED_TESTS=1; otherwise prints a skip reason. - refuse_
production_ executable - Panics when
programwould run under a production executable name (seeis_production_executable_name). Call it before spawning any CortexKit binary from a test;dev_commandandckdev_binaryalready do. - scratch_
root - Per-process scratch root, keyed by PID and the kernel’s versioned start identity. Unsupported platforms use an unknown identity, which cleanup always preserves.
- shared_
scratch_ root - Shared root under the system temp directory. Initialization sweeps stale fixtures.
- sibling_
build_ revision - Include the source revisions of caller-named adjacent path-dependency checkouts
in the build cache key. Missing checkouts and
repoitself are skipped. Names must be plain directory names; order is significant in the hash. - sibling_
cache_ root - Return a user-owned directory outside the source checkouts for compiled sibling builds. Downloading or unpacking pinned source trees is the caller’s responsibility; this cache stores build outputs, not those source trees.
- sibling_
cargo_ build - Build with a locked sibling manifest and an isolated, caller-owned target directory.
- sibling_
checkout - Adjacent checkout, falling back to the primary checkout’s sibling for linked worktrees.
CORTEXKIT_TEST_WORKSPACE_ROOTcan explicitly select the consuming workspace. - sibling_
revision - Return a cache key derived from the checkout’s HEAD and source bytes, not its directory location. Staged changes, unstaged changes, and untracked non-ignored files contribute, so each local edit invalidates a cached build.
- sibling_
target_ dir - Caller workspace’s
target/sibling-target/<name>; never writes into the sibling. - sign_
test_ binary - Best-effort macOS signing. The explicit identity wins over
CORTEXKIT_TEST_SIGNING_IDENTITY; without either, signing is skipped. PassSome(OsStr::new("-"))to select ad-hoc signing without a certificate or a signing identity from the user’s keychain. Already-valid signatures are left alone; other platforms do nothing. - stable_
executable - Single-file form of
stable_executable_dir. - stable_
executable_ dir - Immutable content-addressed fake executables shared across processes. Do not modify or delete the returned directory. Each complete file is copied by a child and atomically renamed, so concurrent readers never see a partial write.
- stage_
test_ binary - Compatibility staging:
ck-*artifacts becomeckdev-*; other names pass through. - wait_
until_ gone - Wait for a PID to be positively known dead. Unknown never counts as gone. On unsupported platforms the result is false after the timeout.
- warm_
exec_ fenced - Run
--versionwith the same environment fence used by test daemons. Assessment is best-effort; failed exits are reported with code or signal.