Repository navigation
[SDCT-1647] Collect caller commands inside a repository runner's environment - #396
anmarchenko wants to merge 8 commits into
Conversation
select --commands and collect --commands read a commands file that lists each CI job's commands, with their argv, cwd and environment. Each command is collected with its job's env applied, so collection, its probes, the identity Datadog is asked about and the inventory see the command's values. collect writes one inventory per command to --output-dir; select decides every command and rolls them up per job. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…w identical commands with different ids The Python platform read PYTEST_ADDOPTS when it detected the framework, so discovery used ddtest's own options instead of a command's. Two listed commands with different ids but the same contents are two commands, not a duplicate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Windows compares variable names without case, so dd_api_key would set DD_API_KEY there; case-insensitive filesystems give Unit and unit the same inventory file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A command in a commands file can name the runner environment it runs in,
as runner: {suite, environment, invocation, args}. Collection lists the
runner's environments through its TestRunner, finds the command the
referenced one runs, and has the runner run ddtest's worker in that
command's place, so the runner prepares the environment itself.
The worker probes the interpreter the command runs, with the probe
command PythonProbeCommand gives for it, records the identity and
skipping controls the runner sets for the command, and collects the
command with --ddtrace and --collect-only added to the runner's
PYTEST_ADDOPTS. The inventory records that interpreter's runtime and
packages and the runner's identity, and names the runner environment in
its identity. The measured runtime is checked against the environment's
declared Python before any runtime tags apply.
The listing checks the runner's interface by loading it, bounds its
output without a ReadFrom path, and sets a WaitDelay.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: de64ad9 | Docs | View more details | Give us feedback! |
|
@autotest review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3f16b33ebe
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Runner-backed inventories can remain eligible for skipping after runner commands change, leaving newly selected tests unaccounted for. Runner listing also exposes the selection API key to repository code.
🤖 Bits Code Review · Commit 3f16b33
There was a problem hiding this comment.
Runner-definition changes can leave stale inventories eligible to skip jobs, and catalog loading exposes the API key to repository code during select --commands. Additional defects prevent collection or skipping for runner-specific services, quoted pytest arguments, and explicit pytest paths.
🤖 Bits Code Review · Commit 3f16b33
- Record the service the runner gives the command, read while its variables apply, so an inventory whose runner sets DD_SERVICE can skip. - Give the runner no Datadog keys: the listing and collection see the placeholder DD_API_KEY and no DD_APP_KEY. - Find the interpreter a pytest entry point runs inside the prepared environment, from the entry point's own script, including the wrapper uv writes for a relocatable environment. - Read quoted characters in a runner's command as literals, so options such as --ignore-glob='*civisibility*' don't make it a shell program. - Decide a runner inventory only for its own commit: the runner's definitions, wherever the repository keeps them, decide what it collects. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
More details
Commands collect within repository-prepared Python environments;
credentials are sanitized, inventories cannot skip across commits,
pytest probing follows the entry point’s interpreter,
and service identity reflects runner variables.
All four earlier findings are fixed; no new reportable issue remains.
🤖 Bits Code Review · Commit 9fe6afb
…mands-runner-environments # Conflicts: # docs/running.md # internal/platform/python_command.go # internal/selection/collect.go # internal/selection/commands.go
There was a problem hiding this comment.
Runner collection can fingerprint packages that uv replaces before test discovery, leaving a complete inventory describing the wrong environment. Bounded runner listings can also leave descendant processes running after returning.
🤖 Bits Code Review · Commit 9fe6afb
- The worker runs the command, then probes its interpreter, since the command may install dependencies as it starts, as uv run does: the inventory records the packages collection ran with. - The listing runs in its own process group, which a timeout kills, and what is left of the group is killed once the listing returns, so a descendant doesn't outlive it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
The PR collects pytest inside repository runner environments, preserving their runtime and identity; stale package snapshots and surviving listing descendants are now fixed. One issue remains: the new cleanup assertion misidentifies zombies as running processes, causing false test failures in containers without orphan reaping.
🤖 Bits Code Review · Commit 614dc52
Where nothing reaps orphans, as in some containers, the killed descendant stays a zombie, which kill -0 still reports as alive. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
More details
The PR collects pytest inside repository runner environments, recording their runtime, packages, identity, and skipping controls. Package snapshots now follow collection, listing descendants are cleaned up, and the cleanup assertion handles unreaped zombies; the previously failing non-reaping-parent scenario now succeeds, with no open findings.
🤖 Bits Code Review · Commit de64ad9
Stacked on #395.
What
A command in a
select --commands/collect --commandsfile can now name the repository runner environment it runs its tests in:{"id": "vendor-py312", "job": "vendor 3.12", "argv": ["scripts/run-tests", "--venv", "f4cf61b462bb"], "runner": {"suite": "vendor", "environment": "f4cf61b462bb"}}Some repositories' CI jobs don't call pytest: they call the repository's own test runner. In dd-trace-py, a job runs
scripts/run-tests --venv f4cf61b462bb. The runner readstests/suitespec.yml, builds a virtualenv, and runs pytest inside it.runnertells ddtest which of the runner's environments the command runs:suiteis the runner's name for a group of tests. In dd-trace-py,vendoris asuites:entry intests/suitespec.yml, which runspytest {cmdargs} tests/vendor/.environmentis one test environment of that suite, by the id the runner gives it. In dd-trace-py, a suite'smatrixexpands into one environment per Python version and dependency set.f4cf61b462bbis the hash of the vendor suite's Python 3.12 environment withmsgpack~=1.0.0andpytest-randomly, which is what--venvtakes.scripts/run-tests --listprints suites with these hashes.invocationpicks the environment's test command, when it runs more than one.argsare what the job passes after--, which the runner puts in place of{cmdargs}.argvstays the job's command as CI runs it. ddtest records it in the inventory's identity but doesn't parse the runner's command line: the caller, such as the pipeline generator that wrote the job, already knows which environment the job runs, and names it inrunner.Collection lists the runner's environments, finds the command that the referenced one runs, and has the runner run ddtest's worker in that command's place, so the runner prepares the environment as it does for the job. The worker:
platform.PythonProbeCommandfor an interpreter oruv run/poetry run. For apytestentry point, the worker reads the entry point's own interpreter line inside the prepared environment, including the wrapper uv writes for a relocatable environment;_CI_DD_TAGS,DD_CIVISIBILITY_ITR_ENABLED,_DD_CIVISIBILITY_ITR_PREVENT_TEST_SKIPPING, …), which the inventory records in place of ddtest's own;--ddtrace --collect-onlyadded to the runner's ownPYTEST_ADDOPTS.The inventory names the runner environment in its identity, and records that interpreter's runtime and packages. The command stays at
runwhen the measured runtime isn't the Python that the runner declares for the environment (checked before any--runtime-tagsapply), when the runner's command is a shell program (quoted characters are literal) or doesn't run pytest, or when the runner turns skipping off. A runner inventory decides only for its own commit: the runner's definitions, wherever the repository keeps them, decide what it collects. The runner never gets Datadog keys: it sees a placeholderDD_API_KEYand noDD_APP_KEY, and the service it sets for the command is the one the inventory records.Python repositories are supported whose
scripts/run-testsdefines aTestRunnerwith environments by suite, run throughscripts/uv-run-script, as dd-trace-py does. ddtest checks that interface by loading the runner. A source that only mentions--listis not a supported runner. The listing runs with the runner's own inline script dependencies, for at most two minutes, prints at most 16 MiB (the cap has noReadFrompath), and has aWaitDelayso a descendant that holds the output open can't hang it. The runner runs with the command's whole environment.Runners for other platforms join by implementing
commandRunnerininternal/selection/runner.go.planand the decision are unchanged.Why
#395 lets a caller list each CI job's commands, but collects only commands that run pytest directly. Repositories such as dd-trace-py run each job's tests through their own runner, which builds a test environment per suite and Python version and sets the tracer's identity and skipping controls itself. Collecting those commands outside the runner would probe the wrong interpreter and record the wrong identity, so their jobs couldn't skip safely.
E2E testing
Prerequisites: macOS or Linux with
uv, Python 3.12 available touv(uv python install 3.12), and this branch built withmake build. Use a fresh dd-trace-py checkout atmain. The steps use the runner's CI mode (GITLAB_CI=true), which runs on the host. CI mode needs a prebuilt ddtrace wheel, so a released one stands in. UnsetDD_API_KEY: collect then only collects.vendorsuite's Python 3.12 environment hash.scripts/run-tests --list --all-suiteslists it. Use the firstvendorvenv with"python_version": "3.12", calledHASHbelow.commands.json:{"schema_version": 1, "commands": [ {"id": "vendor-py312", "job": "vendor 3.12", "argv": ["scripts/run-tests", "--venv", "HASH"], "env": {"GITLAB_CI": "true", "CI_COMMIT_AUTHOR": "QA <qa@example.com>", "DD_ENV": "ci"}, "runner": {"suite": "vendor", "environment": "HASH"}}]}/path/to/ddtest collect --commands commands.json --output-dir inventories --platform python --framework pytest.Expected: exit 0. The first run builds
.cache/test-environments/HASH. stdout listsvendor-py312withinventories/vendor-py312.json.gz.gzip -dc inventories/vendor-py312.json.gz | jq '{complete, errors, runner: .identity.runner, runtime: .inputs.configurations["runtime.version"], tags: .inputs.configurations, vars: .datadog.variables, counts}'.Expected:
runneris{"suite":"vendor","environment":"HASH"}, andruntimeis a 3.12.x version even when the host's defaultpython3is another one.tagshastest.configuration.env_hash: HASHandtest.configuration.python: 3.12.varsholds the runner's_CI_DD_TAGSand_DD_CIVISIBILITY_ITR_PREVENT_TEST_SKIPPING: "1".countsis non-zero.completeis false, with the errorworker skipping disabled by _DD_CIVISIBILITY_ITR_PREVENT_TEST_SKIPPING: dd-trace-py's runner turns skipping off unless the suite opts in.tests/suitespec.yml, undervendor:→matrix:, addenv: {DD_TRACE_PY_ENABLE_ITR_TEST_SKIPPING_FOR_JOB: 'true'}next tocommand:. Repeat steps 4 and 5.Expected:
complete: true,errors: [], and_DD_CIVISIBILITY_ITR_PREVENT_TEST_SKIPPING: "0". Revert the file afterwards.collectand withjq '.errors':"environment": "nope"→ errorrunner suite "vendor" has no environment nope.--runtime-tags '{"runtime.name":"CPython","runtime.version":"3.13.0","os.platform":"Darwin","os.architecture":"arm64","os.version":"x"}'→ error--runtime-tags declare Python 3.13.0, but the command collects with Python 3.12.x.scripts/run-tests, or with ascripts/run-teststhat defines noTestRunner→ errorrunner listing unavailable: …, and the command is not collected.ddtest select --inventory inventories/vendor-py312.json.gz --output selection.jsonand a Datadog API key. With step 5's inventory, the job's decision isrun.Cleanup: remove
inventories/,commands.json,.cache/test-environments/HASHand.cache/ddtrace-test-wheels/.🤖 Generated with Claude Code