Skip to content

Testing and Scheduling

Once separates which tests should run from where and when they run. That separation keeps affected-test selection conservative, makes exact requests auditable, and lets scheduling evolve without changing test identity.

Start here whether you are declaring a test target for the first time or planning work for an existing target. Full ecosystem guides cover build and test targets together. Test-runner reference pages provide focused, copyable declarations for runner-only integrations.

Start With Your Runner

Keep the native runner as the source of truth for test collection and execution. Choose the matching target kind, make its prerequisite available, and let Once record stable test identities around it:

RunnerTarget declarationPrerequisiteDefault automatic batch
pytestpytest_testThe selected Python interpreter can import pytestOne test file
Ruby Specificationrspec_testThe selected Ruby interpreter can load the runnerOne specification file
Minitestminitest_testThe selected Ruby interpreter can load MinitestOne test file
Vitestvitest_testThe package-local Vitest entry point is installedOne test file
Jestjest_testThe package-local Jest entry point is installedOne test file

Each target kind ships a runnable starter. Retrieve the one that matches your runner when you want a complete manifest and source layout:

sh
# Python with pytest
once query example pytest_test pytest-test-minimal --format json

# Ruby Specification
once query example rspec_test rspec-test-minimal --format json

# Ruby with Minitest
once query example minitest_test minitest-test-minimal --format json

# JavaScript or TypeScript with Vitest
once query example vitest_test vitest-test-minimal --format json

# JavaScript or TypeScript with Jest
once query example jest_test jest-test-minimal --format json

After copying or adapting the declaration, use the same first-run workflow for every runner. The bundled starters name their target tests:

sh
once query schema pytest_test
once test tests --format json
once query test-manifest tests --format json
once test tests --jobs 4 --format json

Replace pytest_test with the chosen kind when querying its schema. The first complete run discovers stable units and writes the manifest. Its structured response keeps that executed work in plan and shows the batches available to the next run in next_plan. The next run can schedule those units as independent file batches across the requested workers. Set batching = "case" in a pytest, Ruby Specification, Vitest, or Jest target only when its fixtures and startup costs make case-level batches worthwhile. Python, Ruby, and Node.js executable attributes accept names on the executable search path, absolute paths, and workspace-relative paths. A pytest target with no python attribute automatically tries .venv/bin/python before the host executable search path. Set a portable project path explicitly when the repository uses a different runtime layout.

Start With the Safety Model

LayerDecidesStable output
SelectionWhich test targets or explicit units belong in the runSelection reasons and safety level
PlanHow selected work is divided into semantic batchesPlan and batch identifiers
ScheduleWhich worker takes each batch and attemptPlacement, timing, and status
ResultsWhat the runner observedNormalized suites, cases, attempts, and artifacts

Affected selection is conservative. Once starts from changed graph inputs, walks reverse dependencies, and selects complete test targets. Missing ownership also selects tests instead of silently skipping them.

Exact unit selection is different. It is allowed only when the target kind declares a lossless translation from a stable Once unit identifier to native runner arguments. Unsupported or stale unit requests fail during planning.

The boundary is deliberately ecosystem-neutral. Rust validates generic test information and result records, builds graph-based plans, and schedules opaque batches. A Starlark target kind owns runner discovery, command arguments, filter translation, result normalization, and platform requirements. Adding a test ecosystem should therefore require a target kind, not a branch in the planner or executor.

Discover the Test Surface

List test targets before choosing one:

sh
once query tests --format json

Run a complete target once to establish current discovery data:

sh
once test tests/unit --format json
once query test-manifest tests/unit --format json

The manifest reports:

  • source, which distinguishes normalized discovery from a whole-target fallback;
  • listing_supported, which states whether the target kind can expose stable units;
  • case_filtering, which is runner_args only when exact execution is safe;
  • sharding, which states whether Once may create automatic batches and whether their granularity is file, case, or target;
  • discovery_fingerprint, which ties the unit list to the declared inputs that can change discovery; and
  • units, the stable identifiers observed in the latest complete run.

A filtered run does not replace the complete manifest. Agents can run one case for quick feedback without forgetting the other cases discovered by the last whole-target run.

Plan Affected Tests Before Running

Inspect the immutable plan for changed workspace paths:

sh
once query test-plan \
  --changed-path src/library.rs \
  --format json

Each selected test includes a reason. The current affected policy emits one complete test scope per selected target. When that target has a current manifest and supports exact filtering, the plan divides the complete scope into stable file or case batches. This changes scheduling granularity without using test impact as permission to omit a discovered case.

The first run, a changed test input, or an incomplete manifest produces one whole-target batch. That run refreshes discovery. Later plans may then split the same target automatically. A stale manifest never filters against an old unit list.

Run the same selection through the dynamic scheduler:

sh
once test \
  --changed-path src/library.rs \
  --jobs 4 \
  --format json

--jobs caps concurrent local workers. It does not change selection, plan identity, or batch identity.

Inspect recent attempts and measured durations afterward:

sh
once query test-attempts --limit 20 --format json

Run One Exact Unit

Choose an identifier returned by the current complete manifest:

sh
once query test-plan \
  --target tests/unit \
  --test-unit 'tests/unit::returns_greeting' \
  --format json

once test tests/unit \
  --test-unit 'tests/unit::returns_greeting' \
  --format json

Planning verifies both conditions before it creates an exact batch:

  1. the target declares case_filtering = "runner_args"; and
  2. the requested identifier is present in the persisted complete manifest.

Run the whole target again when discovery is missing or stale. Do not construct runner-specific filters from names that Once did not return.

Understand Current Ecosystem Coverage

Target kindStable unit discoveryExact unit executionAutomatic granularity
pytest_testYesYesFile by default, optional case
vitest_testYesYesFile by default, optional case
jest_testYesYesFile by default, optional case
rspec_test for Ruby SpecificationYesYesFile by default, optional case
minitest_testOne unit per fileYes, by fileFile
rust_testYesYesTarget
android_local_testYesYesTarget
android_instrumentation_testYes, from a completed device runYes, through the instrumentation class argumentTarget
apple_test_bundle with Swift TestingYesNot yetTarget
shellspec_testYesNot yetTarget
zig_testSuite-level fallbackNot yetTarget
elixir_testSummary counts onlyNot yetTarget

Unsupported ecosystems still participate in conservative affected selection and target-level scheduling. Once reports the limitation instead of guessing a native filter.

Treat Sharding As Scheduling

The scheduler creates stable batches, orders them using recent uncached durations, and lets idle workers pull the next batch. This avoids the duration skew of a fixed partition while keeping the plan independent from the requested worker count.

Dynamic-language runners default to file batches because files commonly share imports, fixtures, database setup, and interpreter startup. Every discovered case from one file stays in the same batch. Historical batch durations let Once balance those stable files without coupling the plan to four, eight, or any other fixed number of workers. A target can opt into case granularity when its runner and setup make smaller batches worthwhile.

Concurrent batches write results, logs, and native output below isolated batch directories. After all batches finish, Once validates and merges them into one canonical target result. The plan contains no provider-specific or worker-specific assignment, so local or future remote placement does not redefine test identity.

Add Selection to a Project Module

Project-local Starlark test kinds use the same discovery and planning surfaces as built-in kinds. Query the live contract instead of copying a provider shape:

sh
once query module-contract --format json

The returned test_starter includes the complete once_test_info provider, normalized result paths, action declaration, and filter plumbing. test_target_starter shows the matching manifest table, and normalized_test_result_example is the machine-readable output contract. Its adapter receives:

  • --once-results <path>;
  • --once-log <path>;
  • --once-target <target>; and
  • one repeated --once-test-unit <identifier> for each exact filter.

The adapter writes once.test_results.v1, uses stable target-qualified case identifiers, honors every requested filter, and exits unsuccessfully for a failed or unknown selection. Once rejects incomplete normalized results before using them for discovery or accepting a scheduled batch. Validate the module and workspace before the first run:

sh
once query validate-module modules/testing.star --format json
once query validate-workspace --format json

After a complete run, the normal manifest, exact-plan, affected-plan, and scheduler commands work without a parallel project-specific interface. See the modules reference for the full authoring contract.

Agent Checklist

For a coding agent, the safe loop is short:

  1. Query test targets and capabilities.
  2. Inspect an affected plan before running change-scoped tests.
  3. Run a complete target before relying on its manifest.
  4. Request an exact unit only when the manifest declares runner argument filtering.
  5. Treat prioritization and worker count as ordering, never as permission to remove tests.
  6. Read normalized results and schedule attempts instead of scraping native runner output.

With --format json, command failures return an once.error.v1 record on standard output and keep diagnostic logs on standard error. Agents can use the process status for control flow and the structured error.message field for repairs.

The same operations are available through the Model Context Protocol tools. The tool reference maps each tool to its matching terminal command.

Released under an open-source license.