Skip to content

Fix tox CI failure: replace invalid {homedir}/tmp with {envtmpdir}/{toxworkdir}#62

Closed
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-ci-failure-in-pr-61
Closed

Fix tox CI failure: replace invalid {homedir}/tmp with {envtmpdir}/{toxworkdir}#62
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-ci-failure-in-pr-61

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 30, 2026

Description

{homedir} is not a valid tox substitution on the CI runner — tox treats it literally, creating a {homedir}/tmp subdirectory inside the repo. The cp -R {toxinidir} destination then falls within the source tree, causing cp: cannot copy a directory into itself. Downstream, coverage-ci fails with No data to combine because tests never ran.

Changes:

  • [testenv] / [testenv:py38]: Replace changedir = {homedir}/tmp and all {homedir}/tmp/... path references with {envtmpdir} — a tox-managed per-env temp dir guaranteed outside the repo
  • Coverage data sharing: Add setenv = COVERAGE_FILE = {toxworkdir}/.coverage so coverage run -p writes .coverage.<host>.<pid> files to the stable .tox/ dir, shared across all envs
  • [testenv:coverage] / [testenv:coverage-ci]: Change changedir to {toxworkdir} so coverage combine runs where the parallel data files were written
  • allowlist_externals: Use bare command names (git, rm, cp) instead of absolute paths with wildcards

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Validated against the CI job logs from job 73814718704 confirming the root cause. The fix was reviewed via automated code review and CodeQL scan (no issues found).

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
Original prompt

Fix CI failure in PR #61 / job 73814718704 for mitre/atomic.

Observed failure (from Actions job logs for jobId 73814718704):

  • During tox env py310, command cp -R /home/runner/work/atomic/atomic '{homedir}/tmp/plugins/atomic' fails with:
    • /usr/bin/cp: cannot copy a directory, '/home/runner/work/atomic/atomic', into itself, '{homedir}/tmp/plugins/atomic'
  • This indicates {homedir}/tmp resolves to a path under the checked-out repository directory on the runner, so {homedir}/tmp/plugins/atomic becomes nested inside {toxinidir} and cp refuses recursion.
  • After tests abort, coverage-ci fails with No data to combine.

Repo context:

  • Workflow: .github/workflows/testing.yml runs tox with matrix envs py310,coverage-ci etc.
  • Tox config: tox.ini currently uses changedir = {homedir}/tmp and hardcodes multiple paths under {homedir}/tmp for git clone, rm -rf, pip install -r, cp -R, and pytest rootdir.

Required changes:

  1. Update tox.ini so the working directory and intermediate files are created in a directory that is guaranteed NOT to be inside the repository (avoid {homedir}/tmp). Prefer tox-provided dirs like {envtmpdir} (per-env) or a stable shared directory under {toxworkdir} if needed.
  2. Update all commands in [testenv] and [testenv:py38] to use the new directory variable consistently:
    • git clone ... target directory
    • rm -rf .../plugins/atomic
    • pip install -r .../requirements.txt
    • cp -R {toxinidir} .../plugins/atomic
    • coverage run ... --rootdir=... plugins/atomic/tests (ensure path to tests is correct after the copy)
  3. Ensure coverage-ci can still find and combine coverage data. If using per-env temp dirs ({envtmpdir}), adjust the strategy so coverage data is in a shared location for combining, or run combine in the same directory where .coverage.* files are written. (A simple approach is to set COVERAGE_FILE to a path under {toxworkdir} and use coverage run -p to produce parallel data files there, or keep a stable shared working dir under {toxworkdir}.)
  4. Keep changes minimal and focused on unblocking the CI failure.

Acceptance criteria:

  • py310/py311/py312/py313 tox envs no longer fail with the recursive copy error.
  • Tests execute and produce coverage files.
  • coverage-ci no longer fails with No data to combine.

Reference PR:

Reference failing job:

  • Actions jobId: 73814718704

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Please find a solution for failing job 73814718704. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

Assistant: The job is failing in the py310 tox environment because the test setup tries to copy the repository into a destination that is inside the repository itself:

From the logs:

  • cp -R /home/runner/work/atomic/atomic '{homedir}/tmp/plugins/atomic'
  • /usr/bin/cp: cannot copy a directory ... into itself

This happens because {homedir}/tmp is resolving to a path under the GitHub Actions workspace (effectively inside the checked-out repo), so {homedir}/tmp/plugins/atomic ends up being nested within {toxinidir}. As a result, cp detects recursion and aborts. The downstream coverage-ci failure (No data to combine) is just a consequence of tests never running.

Fix (recommended): stop using {homedir}/tmp and use tox’s temp dir

Update tox.ini to use {envtmpdir} (or {toxworkdir}) so the clone/copy happens outside the repo and is guaranteed not to be nested.

Patch suggestion for tox.ini (ref: d530b4a3f80d6bbc9a99621258825bc56fa95279)

Replace the shared [testenv] and [testenv:py38] changedir + commands that hardcode {homedir}/tmp with {envtmpdir}:

 [testenv]
 ...
- changedir = {homedir}/tmp
+ changedir = {envtmpdir}
 commands =
-    git clone https://github.com/mitre/caldera.git --recursive {homedir}/tmp
-    rm -rf {homedir}/tmp/plugins/atomic
-    python -m pip install -r {homedir}/tmp/requirements.txt
-    cp -R {toxinidir} {homedir}/tmp/plugins/atomic
-    coverage run -p -m pytest --tb=short --rootdir={homedir}/tmp -Werror plugins/atomic/tests
+    git clone https://github.com/mitre/caldera.git --recursive {envtmpdir}
+    rm -rf {envtmpdir}/plugins/atomic
+    python -m pip install -r {envtmpdir}/requirements.txt
+    cp -R {toxinidir} {envtmpdir}/plugins/atomic
+    coverage run -p -m pytest --tb=short --rootdir={envtmpdir} -Werror plugins/atomic/tests
 allowlist_externals =
     git
     rm
     cp

 [testenv:py38]
 ...
- changedir = {homedir}/tmp
+ changedir = {envtmpdir}
 commands =
-    git clone https://github.com/mitre/caldera.git --recursive {homedir}/tmp
-    rm -rf {homedir}/tmp/plugins/atomic
-    python -m pip install -r {homedir}/tmp/requirements.txt
-    cp -R {toxinidir} {homedir...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

@deacon-mp deacon-mp marked this pull request as ready for review April 30, 2026 16:50
Copilot AI changed the title [WIP] Fix CI failure in PR #61 for mitre/atomic Fix tox CI failure: replace invalid {homedir}/tmp with {envtmpdir}/{toxworkdir} Apr 30, 2026
Copilot AI requested a review from deacon-mp April 30, 2026 16:54
@deacon-mp
Copy link
Copy Markdown
Contributor

Superseded by #63 (which now has CI green and consolidates the tox fix).

@deacon-mp deacon-mp closed this Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants