ADR-403: A Package’s Test Programs See Its Private Names

Status: Accepted Date: November 18, 2026 Answers: how a test reaches a pure function that is not public API, which “Child environment assembly in Nikaia, Windows case tested directly” (#2119) and the abort lookup move (#2120) found missing (#2130), and which a test of a compiler pass entry met the same way (#1983); decided by the owner (2026-11-18) Related: ADR-269 D22 (a test program is tests/NAME.nika and uses the package as an integration test does) and its test block, which already sees private names; ADR-243 D6 (a deciding condition passed in, as found_on_path takes the platform)

1. Question

The owner’s pattern for a branch no program reaches (2026-11-18): the branch becomes a pure Nikaia function with the deciding condition as an input, and a Nikaia test calls it directly. Such a function is not API:

// crates/nikaia-std/src/runtime/abort.nika  (package `runtime`, within std)
fn lookup(table: ref Vec[(int, String, int)], generated: int) -> (String, int)? { ... }
// crates/nikaia-std/src/runtime/tests/an_unknown_line_is_not_guessed_at.nika
use runtime

fn main() {
    let table = [(10, "main.nika", 3), (20, "main.nika", 7), (30, "lib.nika", 1)]
    println(runtime::lookup(table, 20))   // NK1171 today: no such function
    println(runtime::lookup(table, 11))
}

Today the test sees only what is pub (ADR-269 D22), and for std’s runtime that means an entry with pub = true in std.contracts, which would make lookup a promise to every program. Rust’s unit tests, Go’s _test.go in the same package, Java’s package-private and Zig’s test blocks give the tests of a module what the module sees; Kotlin’s internal, C#’s InternalsVisibleTo and Swift’s @testable import widen the view for named test code. Nikaia already does the first for a test block.

2. Decisions

D1 - A program in a package’s tests/ sees what the package sees.

tests/NAME.nika of a package that uses the package reaches its names that are not pub - functions, types, fields, methods - by the same paths as its public ones, as a test block in the package’s own files does (ADR-269). This changes D22’s “as an integration test does”: the program is still its own program, built and run as D22 says, and its .stdout, .stderr and .stops are judged the same way.

D2 - Nothing else does.

Another package, a program outside the package’s tests/, an example and a tests/ program of a package that depends on this one see only pub names, as before. That a test reaches a name publishes nothing: no contract enters the ledger for it, no std.contracts entry is needed, and the name may change without a version raise.

D3 - std’s packages test their private names with test blocks.

A part of std written in Nikaia with its own manifest (runtime, compiler, within = "std") reaches its private names from a test block in its own files (ADR-269), not from a tests/ directory. lower-std lowers the blocks as functions with the list that names them, compiled into the compiler with no #[cfg(test)] (#2082), and nikaia test --std runs every package’s list. A program in std’s tests/compiler/tests/ is not inside those packages and sees std’s public API only.

Amended by the supervisor (2026-11-18, #2147): the first text gave these packages a tests/ directory under D1 and D4. Its build (#2146) found that std’s packages are not packages of their own in the build: their lowered code is part of nikaia-std and calls pub(crate) Rust beside it (env::pairs from runtime/env.nika), they have no src/ directory, and a within = "std" package used as a dependency is not checked as std. A test block already sees what D1 gives, needs none of that, and is the mechanism #2082 runs std’s tests with; one way, not two.

Changed by ADR-rust-boundary-1 D28: the pub(crate) Rust these packages call is described in std.contracts with pub = false, the general rule D24-D27 give a package’s own Rust.

D4 - A package is built for its own tests as its own crate, with every item pub.

A tests/ program is its own Rust crate and the package another (ADR-286 D19), and the package’s private items are emitted without pub, so rustc refuses what D1 allows (found by the build of this ADR, #2141). The package a tests/ program of its own links is therefore lowered from its source for that program with every item pub: a build of its own, with that choice in its cache key, linked by the package’s own tests/ programs and by nothing else. The package’s ordinary build is unchanged and stays private, so rustc remains the one enforcer ADR-286 D2-D3 keep: no second build sees the widened one. The nikaia-std crate gains no pub item for any test (#2142).

3. Consequences

4. What this does not decide

This site is open source. Improve this page.