Skip to content

test(floor): every test sees the same tokenizer cache, mounts, process table, PATH and programs on every host, and no skip depends on the host #2165

Closed

Description

@dan-petty

What happened

The hermetic floor leaves some host state visible to tests, so the same test can take a different path in the devcontainer and on a stock GitHub runner. CI run 40123645251 on ubuntu-24.04 skipped 45 tests at df8e2ee, and the devcontainer skipped 1. The test-suite audit of 2026-10-24 found these gaps:

  • Tokenizer cache. _resolve_tiktoken_cache_dir reads the tiktoken cache from the environment, from ~/.cache/tiktoken, and then from fixed directories. The devcontainer image holds the BPE file in one of them, and the runner does not. So token counts in tests come from tiktoken in the devcontainer and from the fallback counter on the runner. The audit saw tests/test_agent.py:34, tests/test_model_contract.py:122 and tests/test_review_group_analysis.py:1700 open /usr/local/share/tiktoken/....
  • Mounts. ci/diagnostics.py reads the host's /proc/mounts when the caller gives no mounts text. 11 dry-run tests in tests/test_ci_dry_run.py and tests/test_docs.py:294 read it.
  • Process table. k8s/port_forward_daemon.py reads /proc/<pid>/stat. 6 tests in tests/test_k8s_port_forward_daemon.py read the stat file of a real process.
  • PATH. scanner_fake puts its stand-ins in front of the real PATH. A tool that the fake does not record is still found on the host, which holds the scanners in the devcontainer and not on the runner.
  • Program lookups. About 27 tests make a real shutil.which lookup of bandit, gitleaks, ruff, semgrep, kube-linter, pluto or mypy (section 2.which-real), for example tests/ai/review/test_runner.py:261 and tests/review/test_review_tool_binary_digest.py:126-231.
  • Skips that the host decides. tests/test_data_dir_worktrees.py:156 and tests/test_repos.py:522 (the git version), tests/test_repos.py:758 (non-UTF-8 names), tests/test_consolidation_core_paths.py:49, :68, :83, tests/test_repomap.py:163, :189, tests/test_review_defenses_and_verification.py:35 and tests/test_subsystem_containment_and_redaction.py:49 (symlinks), tests/test_openblas_worker_threads.py:26 (/proc/self/status), tests/test_security_checkov.py:429 (libyaml) and tests/test_code_metrics.py:358 (pre-commit).

What should happen

Every test sees the same tokenizer, mounts, process table, PATH and programs on every host, and no skip depends on the host.

Evidence

At b170358:

  • src/devops_cli/ai/context_budget.py:27-39.
  • src/devops_cli/ci/diagnostics.py:10, :19-27.
  • src/devops_cli/k8s/port_forward_daemon.py:21.
  • tests/support/fakes/scanners.py:188-198, with PATH at :194.
  • tests/conftest.py:1375-1395: the collection hook that skips bwrap and live items where the program is missing.
  • .data/agent/scratch/audit/full_list.txt of the 2026-10-24 audit, sections 2.host-files, 2.which-real and 2.host-skips.

Acceptance criteria

  • Tests first: with the floor's tokenizer cache, a test that counts tokens gets the same count in the devcontainer and on the runner.
  • No test opens a file under /proc, /usr/local/share/tiktoken or another host path outside tmp_path, the repository and the interpreter. A floor check fails a test that does.
  • scanner_fake builds PATH without the host's directories, and no test makes a real shutil.which lookup of a scanner.
  • rg -n "pytest.mark.skipif|pytest.skip\(" tests shows no skip that reads the host: no git version, file system, /proc, libyaml or installed program.
  • A default run in the devcontainer and on the stock runner reports the same number of skipped tests. The pull request gives both counts.
  • uv run devops ci passes.

Follows ADR 0007 as #2143 amends it. Related: #1331 decides that tests select the fallback token counter and keeps one live tiktoken test; under #2143 that test reads a recorded encoding instead. The bwrap skips belong to #2149, and the live skips to #2170.

Source: #2143

Proposed design

Problem statement

The hermetic test floor leaves host state visible to tests. The same test takes a different path in the devcontainer and on a stock GitHub runner. CI run 40123645251 skipped 45 tests on ubuntu-24.04, and the devcontainer skipped 1. The audit of 2026-10-24 found gaps in the tokenizer cache, mounts, process table, PATH, program lookups, and host-decided skips.

Acceptance criteria

  • Criterion 1: A test that counts tokens gets the same count in the devcontainer and on the runner with the floor's tokenizer cache.
    Verification: Run the token-counting test in both environments and confirm the counts match.
  • Criterion 2: No test opens a file under /proc, /usr/local/share/tiktoken, or another host path outside tmp_path, the repository, and the interpreter.
    Verification: A floor check fails a test that opens such a path. Run the full suite and confirm no test triggers this failure.
  • Criterion 3: scanner_fake builds PATH without the host's directories, and no test makes a real shutil.which lookup of a scanner.
    Verification: Run rg -n "shutil.which" tests and confirm no test calls it for a scanner. Run the scanner tests and confirm they pass.
  • Criterion 4: No skip in the test suite reads the host for git version, file system, /proc, libyaml, or an installed program.
    Verification: Run rg -n "pytest.mark.skipif|pytest.skip\(" tests and confirm no skip reads the host.
  • Criterion 5: A default run in the devcontainer and on the stock runner reports the same number of skipped tests.
    Verification: Run the test suite in both environments, compare the skip counts, and record both counts in the pull request.
  • Criterion 6: uv run devops ci passes.
    Verification: Run uv run devops ci and confirm exit code 0.

Key questions

  • Where does the recorded tiktoken encoding file live?: In tests/fixtures/. A test that needs real token counts reads the file from there. (proposed)
  • Which host-decided skips does this issue remove, and which belong to other issues?: This issue removes all host-decided skips except bwrap (which belongs to test(sandbox): the host sandbox and the sandbox tool executor are tested through the process fake on every runner, src detects no mock, and the real bwrap cases are an opt-in contract suite #2149) and live (which belongs to test(cli): live marks sit on the tests that start a program, not on whole modules #2170). (proposed)
  • What is the seam through which ci/diagnostics.py receives a fixed mounts table?: The function that reads /proc/mounts when the caller gives no mounts text already takes a mounts parameter. The floor supplies the fixed table through that parameter. [sources: src/devops_cli/ci/diagnostics.py:19-27]
  • What is the seam through which k8s/port_forward_daemon.py receives a fixed process table?: The code at line 21 reads /proc//stat. The floor supplies a fixed process table through the existing seam so no test reads /proc. [sources: src/devops_cli/k8s/port_forward_daemon.py:21]
  • How does a program lookup (shutil.which) get answered in the hermetic floor?: A program lookup goes to the process fake, which answers it. No test makes a real shutil.which lookup of a scanner. (proposed)
  • What does the floor point the tiktoken cache at?: An empty directory of the test. A test that needs real token counts reads a recorded encoding file from tests/fixtures/. (proposed)
  • What does scanner_fake put on PATH?: Only the fake's stand-ins and the interpreter's directory. The host's directories are excluded. (proposed)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#2143

Activity

  1. added
    source/agent
    type/test
    on Oct 24, 2026
  2. dan-petty commented on Oct 24, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Type: type/test. The candidate proposes changes to the test environment and how tests run, which is a test type of change.
    • Priority: P1-High. The issue impacts test consistency and reliability across different environments, affecting CI runs.
    • Value: High. Fixing host state visibility ensures reliable testing across devcontainer and GitHub runners.
    • Effort: High. Changing the hermetic floor requires significant refactoring of test infrastructure and tooling.
    • Related: test(ci): the suite's slowest tests run on recorded scanner and installer results, not real semgrep, gitleaks, bandit, uv audit, uv pip sync or sudo #1666, which asks for a different change. Both items address test environment consistency but the candidate focuses on host state visibility while #1666 targets slow tests using real tools.
  3. dan-petty commented on Oct 27, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at 0abf552 (see proposed design in issue body).

  4. added
    priority/p1-high
    status/ready
    effort/high
    value/high
    on Oct 28, 2026
  5. dan-petty commented on Oct 31, 2026

    @dan-petty
    OwnerAuthor

    New evidence for this issue, found on 2026-10-31 while a pull request ran uv run devops ci in the devcontainer:

    tests/commands/test_scan_outcomes_and_gating.py::test_scan_report_skips_named_scanners fails here and passes on the GitHub runner. The devcontainer has kube-linter in ~/.local/bin, and the runner has not. The test reaches the real program:

    Failed: process edge reached without a fake: kube-linter lint /tmp/pytest-of-vscode/.../test_scan_report_skips_named_s0 --format jso...
    

    So the test sees a different PATH on each host. A test that skips a scanner by name still starts the others that it finds on PATH. The fix is the one this issue asks for: the floor gives every test the same PATH and programs. The test also needs a fake for kube-linter.

  6. added 8 commits that reference this issue on Oct 31, 2026
    267574a
    66e986a
    cb14cf5
    fca39c9
    74aea1b
    1aa0ea5
    0f793c6
    6dbbcd4
  7. added
    status/in-review
    and removed
    status/ready
    on Nov 1, 2026
  8. removed
    status/in-review
    on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/highpriority/p1-highsource/agenttype/testvalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions