Repository navigation
Closed
Labels
priority/p2-mediumPriority P2: standard workscope/ciGitHub Actions workflows, pre-commit hooks, CI gates, and runnersscope/cliCore CLI framework, Typer subcommands, options, and tablestype/bugType bug: the code does not do what it must
Milestone
Description
Problem
A test run writes state outside its temporary directories. Full runs of a copy of 36cfbbb with HOME pointed at an empty directory (more than 9,270 tests passed in each) left the following in that home [measured: 2026-10-07]:
.config/devops-cli/tls/with a CA key and certificate, a server key and certificate, and a full chain.tests/test_k8s.py:676runsenable-tls --stack allwithout--tls-dir, so the command usesDEFAULT_TLS_DIR[code: config/defaults.py:170] and generates a bundle there when none exists [code: commands/k8s/tls_management.py:229-231].- On a developer's machine, the same test uses the developer's own certificate and key from that directory [inference].
.local/share/devops-cli/worktrees/, from the review worktrees oftests/test_git_worktree.py:96andtests/test_review_worktree_regression.py:80.git/worktree.pyimportsCONST_USER_DATA_ROOTby name [code: git/worktree.py:19, :31], so the floor's patch ofcore.repo.CONST_USER_DATA_ROOT[code: tests/conftest.py:308] misses it.- The floor never sets
DEVOPS_CLI_USER_DATA_ROOTeither [code: git/worktree.py:30].
- An empty
.ssh/. A likely writer is_ensure_known_host, which creates~/.sshforknown_hostswhen it is called [code: git/operations.py:139-141] [inference]. - Files from tools and libraries:
.local/state/gh/device-id,.semgrep/and.cache/semgrep_versionfrom the realghand Semgrep runs, which test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 removes, and the library caches.cache/python-tldextract/and.cache/python-entrypoints/.
Outside the home:
- The system temp directory. The run updated
devops_cli_ollama_rr_<uid>[code: ai/client/network.py:94], a round-robin index shared by every xdist worker and every real CLI run of the same user [measured: its modification time moved during the run]. It also leftdevops-k8s-bootstrap.log[code: commands/devcontainer.py:1021] and twotmp*.outfiles of a test's own [code: tests/test_ci.py:980] [measured]. - Home paths are fixed at import. Every home-derived path is computed when its module is imported [code: config/constants.py:15, :21; config/defaults.py:55-56, :170], so setting
HOMEin a fixture is too late. - Not in scope: the checkout's
.dataleaks belong to fix(ai): the durable-run store resolves under the data directory, so tests never write .data/durable_runs.db into the checkout #1036: the durable-run store, which the run left as.data/durable_runs.db[measured], the port-forward state file [code: k8s/port_forward_daemon.py:21] and the docs-ingest directory. Hypothesis's example database,.hypothesis/in the checkout, is gitignored and is Hypothesis's own replay store.
Acceptance criteria
- Home. Each pytest process (each xdist worker, or the one process under
-n 0) runs with an empty home of its own under pytest's base temp. The home is set before devops-cli is first imported, so no home-derived path resolves into the developer's home. Its git config gives tests that commit an identity onexample.com. - Per-test state. Each writer above writes under the test's
tmp_path:- the TLS test passes
--tls-dir; - one function resolves the user data root, for
git/worktree.pyand forcore/repo.py[code: core/repo.py:282, :291], and it honoursDEVOPS_CLI_USER_DATA_ROOT. The floor sets that variable per test and drops its patch at tests/conftest.py:308. The two worktree tests assert that their worktrees are undertmp_path; - the Ollama round-robin index lives under the data directory, and a test asserts that the file appears under
DEVOPS_CLI_DATA_DIRand nowhere in the temp directory; - whatever creates
.ssh/is found and given atmp_pathlocation.
- the TLS test passes
- Temp directory. During a test,
tempfile.gettempdir()returns a directory under itstmp_path, so code that writes the system temp directory writes there instead [code: ai/harness/compaction.py:107, :124; commands/devcontainer.py:1021, :1209]. - Config. Now that the home is redirected, the floor's patch of
config.settings.CONFIG_PATH[code: tests/conftest.py:473] is removed, and the global config layer reads the worker's empty home. - Session check. The workspace tripwire [code: tests/conftest.py:880-917] also fails when the run leaves anything at one of devops-cli's own locations in a worker's home, naming each path. Those locations are
CONST_CONFIG_DIR,CONST_USER_DATA_ROOT,DEFAULT_SSH_KEY_DIRandDEFAULT_LOCAL_BIN_DIR, as computed in that home. Apytestertest shows a test that writes underCONST_CONFIG_DIRfailing the session with that path. - If test(cli): ratchets hold internal patches, private imports and test accommodations in src at today's counts and name each site that would raise one #1309 has landed, its ceilings drop by the two floor patches this PR removes (
CONST_USER_DATA_ROOTandCONFIG_PATH). - (person-run) Run
uv run pytest -p no:cacheproviderin full on a machine where nothing else runs devops-cli. Afterwards, the modification times under~/.config/devops-cliand~/.local/share/devops-cliare unchanged, and the system temp directory has no new devops-cli entry. -
changelog.d/<n>.mdrecords the change;CHANGELOG.mdanddocs/ROADMAP.mdare not edited. -
uv run devops cipasses.
Key questions
- What is in scope? Decided 2026-10-07: tests touch no state outside
tmp_path. That covers the worktrees under the real home, the shared round-robin file and the cwd-relative port-forward state file, related to fix(ai): the durable-run store resolves under the data directory, so tests never write .data/durable_runs.db into the checkout #1036. - Does this item change the port-forward state file? (proposed) No. fix(ai): the durable-run store resolves under the data directory, so tests never write .data/durable_runs.db into the checkout #1036 already carries that fix (consolidated from fix(k8s): resolve the port-forward state file under the repo data root #810), including the criterion that the suite leaves no
.data/k8s/port_forwards.jsonin the checkout, and the measured runs left none. This item adds no second fix that fix(ai): the durable-run store resolves under the data directory, so tests never write .data/durable_runs.db into the checkout #1036 would then replace. - One home per test or per worker? (proposed) Per worker, because the paths are computed at import. The measured run above already passed in such a home, with only a git identity in it. Per-test separation comes from fixing each writer, which the session check enforces. Resolving those paths at call time belongs to the foundation package item (test(cli): Use edge fakes and real git; drop test rebind hooks #1333), which builds on this item's home.
- Why not check the developer's real home instead? (proposed) Other sessions on the same home write there during a run, such as a review started by hand or another agent, so that check would fail on their writes.
- Where does the round-robin index live? (proposed) Under the data directory, which the floor already isolates per test through
DEVOPS_CLI_DATA_DIR. - Should the run also fail on new untracked files in the checkout? (proposed) Not here. fix(ai): the durable-run store resolves under the data directory, so tests never write .data/durable_runs.db into the checkout #1036 owns the checkout's
.dataleaks and adds an invariant on.datapath literals. A checkout-wide check would fail until fix(ai): the durable-run store resolves under the data directory, so tests never write .data/durable_runs.db into the checkout #1036 lands. - Library caches in the worker home? (proposed) They are allowed. They are not devops-cli state, the home is thrown away, and the session check looks only at devops-cli's own locations.
Strategic alignment
- Milestone: none; the roadmap tooling places it. Depends on: none. Blocks: test(cli): Use edge fakes and real git; drop test rebind hooks #1333. Related: fix(ai): the durable-run store resolves under the data directory, so tests never write .data/durable_runs.db into the checkout #1036 (the checkout's
.dataleaks, including the port-forward state file from fix(k8s): resolve the port-forward state file under the repo data root #810), test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 (removes the realghand Semgrep runs, and also edits the root conftest), fix(test): tests never write to the project config, data or tracked files #749 (the workspace tripwire), One data directory across git worktrees #553 (one data directory across worktrees), test(cli): ratchets hold internal patches, private imports and test accommodations in src at today's counts and name each site that would raise one #1309 (the two floor patches removed here lower its count). - Parent: test(cli): tests double only process edges and mirror the source tree #1307 (phase B).
Metadata
Metadata
Assignees
Labels
priority/p2-mediumPriority P2: standard workscope/ciGitHub Actions workflows, pre-commit hooks, CI gates, and runnersscope/cliCore CLI framework, Typer subcommands, options, and tablestype/bugType bug: the code does not do what it must
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 8, 2026
Placed in v0.2.31 on 2026-10-08 at the owner's request ("Populate 10 security and ci issues into each v0.2.30, v0.2.31, and v0.2.32 milestone"). This is a person's placement. Release theme: finding identity v2, URL credential masking, tests that leave no state, the Docker endpoint check and the Argo CD/OTel perimeters. Position 5 of 10 in the release's planned merge order. Its board Status is set to Ready, so the release-start fill keeps it.
fix(ci): tests touch no state outside their temporary directories (#1311
dan-petty-bot commentedon Oct 9, 2026
What changed
#1484, merged into
release/v0.2.31as 8dfb0c1.14 file(s) changed.
How it was verified
Check runs at 7d74a88:
Acceptance Criteria of
docs/agent/tasks/task-1311-tests-touch-no-state-outside-temp.md:-n 0) runs with an empty home under pytest's base temp, configured before devops-cli is imported, with git identity onexample.com.tmp_path:tests/test_k8s.pypasses--tls-dir.user_data_root()resolves user data root honoringDEVOPS_CLI_USER_DATA_ROOTacrosscore/repo.py,git/worktree.py, andtools_lock.isolate_user_data_rootsetsDEVOPS_CLI_USER_DATA_ROOTand drops theCONST_USER_DATA_ROOTpatch.tests/test_git_worktree.pyandtests/test_review_worktree_regression.pyassert worktrees are undertmp_path.DEVOPS_CLI_DATA_DIR) and nowhere in temp directory; tested intests/test_ai_client_network.py._ensure_known_hostaccepts an optionalknown_hostspath so tests write undertmp_path.tempfile.gettempdir()returns a directory undertmp_pathduring each test viaisolate_tempdirfixture.config.settings.CONFIG_PATHintests/conftest.pyis removed, and global config layer reads the worker's empty home.CONST_CONFIG_DIR,CONST_USER_DATA_ROOT,DEFAULT_SSH_KEY_DIR, orDEFAULT_LOCAL_BIN_DIRin a worker's home, naming each leaked path.tests/test_isolation_tripwire.pyverifies a test writing underCONST_CONFIG_DIRfails the session naming the path.changelog.d/1311.mdrecords the change;CHANGELOG.mdanddocs/ROADMAP.mdare not edited.uv run devops cipasses with 100% compliance.feat(release): v0.2.31 (#1490)