Repository navigation
Repo tests: pin the post-publish VirusTotal contract instead of the old pre-flight one - #8240
Conversation
…ld pre-flight one The desktop release workflow no longer runs a VirusTotal step inside publish-release. unslothai#8194 moved it into its own virustotal-scan job that runs after the release is published, and unslothai#8193 replaced publish-release's `needs: build` with a "Wait for the build matrix" step so the job can queue for its runner during the build. Five tests still encoded the old shape and fail on main for every PR: TestWorkflowOrdering::test_scan_runs_after_the_release_is_validated TestWorkflowOrdering::test_release_creation_is_deferred_until_after_the_scan TestWorkflowOrdering::test_scan_runs_before_the_assets_are_published TestWorkflowOrdering::test_the_scan_script_is_checked_out_first test_build_matrix_hands_off_assets_without_release_credentials Rewrite them against the current layout rather than dropping the assertions. The scan is a post-publish sweep and is advisory by design, so what is worth pinning is that it cannot be quietly lost: - virustotal-scan exists and `needs: [publish-release]`, so deleting the job or the dependency is red, - the job carries no `if:`, and no step does either except the summary, which is `if: always()` so the verdict survives a failed scan, - the sparse checkout of scripts/virustotal_scan.py is asserted by mechanism rather than by step name, along with the guard that exits 1 when the script is absent, - the scan step does not swallow the script's exit status: no continue-on-error, no `|| true`, no `exit 0`, and no `--fail-threshold` pinned to a value the script treats as never-fail, - continue-on-error appears on exactly one job and on no step of any job that handles a bundle, - the downloaded artifact pattern matches what the build matrix uploads, - publish-release does not re-inline the scan. For the permissions test, the build-to-publish handoff is now gated by the waiter, so assert that instead of `needs: build`: it covers every matrix leg by name, refuses to publish a leg that did not succeed, and refuses to publish a leg whose job record never appeared. Add a check that the new scan job holds no release credentials, since it handles the bundles and uploads them off-box. Docstrings say plainly that this is a post-publish sweep, so a future reader does not go looking for a pre-publish gate that is not there.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ae7d2bbf18
ℹ️ 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".
| assert "refusing to publish, these build jobs did not succeed" in wait_run | ||
| assert "refusing to publish without confirming they ran" in wait_run | ||
| # Every one of those refusals has to be terminal. | ||
| assert wait_run.count("exit 1") >= 3 |
There was a problem hiding this comment.
Bind each waiter refusal to its own terminal exit
If the exit 1 is removed from either the failed-leg or missing-leg branch, this test still passes because the waiter currently contains four exits and the global count remains at least three. In the failed-leg case, all legs are completed, so PENDING becomes zero and the loop can then break and publish artifacts from a failed build. Inspect each refusal branch separately and assert that it terminates.
Useful? React with 👍 / 👎.
| secrets = { | ||
| value | ||
| for step in scan["steps"] | ||
| for value in step.get("env", {}).values() | ||
| if isinstance(value, str) and "secrets." in value | ||
| } | ||
| assert secrets == {"${{ secrets.VIRUS_TOTAL_API_TOKEN }}"} |
There was a problem hiding this comment.
Inspect credential values in every scan-job input
If a repository credential is added as a job-level variable such as RELEASE_TOKEN: ${{ secrets.RELEASE_PAT }}, or passed through an action's with mapping, this test remains green: job-level checks only reject two key names, while the secret-value collection examines only step-level env. That leaves the new no-repository-token boundary unenforced for common credential injection paths; inspect values from job and step env and action inputs, including github.token expressions.
Useful? React with 👍 / 👎.
| download = self._scan_step_map()["Download published assets"] | ||
| assert download["uses"].startswith("actions/download-artifact@") | ||
| assert download["with"]["pattern"] == "desktop-release-*" | ||
| assert download["with"]["merge-multiple"] is True |
There was a problem hiding this comment.
Pin the download path to the scanner input
If the download action's path is removed or changed while the scan command still reads $RUNNER_TEMP/desktop-release-assets, all of these assertions pass even though the script receives a nonexistent directory. collect_paths treats that as an empty target set and the script exits successfully with "no scannable bundles found," so the release is silently left unscanned. Assert that the download destination is the same path passed to the scan invocation.
Useful? React with 👍 / 👎.
| assert checkout["with"]["sparse-checkout"] == "scripts/virustotal_scan.py" | ||
| assert checkout["with"]["persist-credentials"] is False |
There was a problem hiding this comment.
Preserve non-cone mode for the file-only checkout
If sparse-checkout-cone-mode: false is removed, these assertions still pass, but actions/checkout returns to cone mode, where scripts/virustotal_scan.py is not a valid directory pattern for the file-only sparse checkout. The checkout then fails, and the job-level continue-on-error makes the post-publish scan merely advisory-fail rather than scan the release. Assert the non-cone setting alongside the sparse path.
Useful? React with 👍 / 👎.
| invocation = run.split("python3 scripts/virustotal_scan.py", 1)[1] | ||
| for swallow in ("|| true", "|| :", "exit 0", "; true"): | ||
| assert swallow not in invocation, swallow |
There was a problem hiding this comment.
Require the scan invocation to propagate its status
If the invocation is changed to something like python3 scripts/virustotal_scan.py ... || echo "scan unavailable", this test remains green because it only rejects two specific right-hand sides, while the successful echo converts the scan failure into a zero step status. The same bypass is possible by putting the command in an if condition. Require the invocation to remain an unguarded command whose status becomes the step status rather than blacklisting a few spellings.
Useful? React with 👍 / 👎.
| # The script signals a detection by returning 1 from main() once | ||
| # `--fail-threshold` is met (see TestThreshold), so the workflow must not | ||
| # pin the threshold to something the script treats as "never fail" while | ||
| # claiming to gate. It passes no threshold at all today, which leaves the | ||
| # script's advisory default in force and the verdict in the annotations. | ||
| assert "--fail-threshold" not in run |
There was a problem hiding this comment.
Allow positive detection thresholds
If the workflow deliberately adds --fail-threshold 1, this assertion fails even though a positive threshold makes the scan stricter and propagates a nonzero status on detections; the release remains advisory because continue-on-error is on the job. This contradicts the stated contract of rejecting only values the script treats as never-fail. Parse and reject nonpositive threshold values instead of banning the option entirely.
Useful? React with 👍 / 👎.
The rewrite in #8240 left two statements wrapped the way I typed them rather than the way scripts/run_ruff_format.py wants them. pre-commit.ci runs that hook over the whole tree on each PR's merge result, so every open PR inherits the failure the moment it merges main. Formatting only; the file's 79 tests pass unchanged. Co-authored-by: danielhanchen <[email protected]>
What is red
On a pristine
origin/mainworktree,python3 -m pytest tests/security tests/python/test_virustotal_scan.py -qgives 5 failed, 299 passed. This is main's own red, so every PR runningRepo tests (CPU)inherits it.Two workflow changes landed without their tests:
b8dac29fa) moved the VirusTotal scan out ofpublish-releaseinto its ownvirustotal-scanjob that runs after the release is published. FourTestWorkflowOrderingtests look up steps namedVirusTotal pre-flight scanandCheck out the scan scriptinsidepublish-releaseand raiseValueError: ... is not in list.ae59a9cf7) replacedpublish-release'sneeds: buildwith aWait for the build matrixstep so the job can queue for its runner during the build.test_build_matrix_hands_off_assets_without_release_credentialsstill asserts"build" in publish["needs"].Scan-after-publish is the intended posture, so this updates the tests rather than reverting either workflow change.
What the rewritten tests pin
The assertions are re-expressed against the new layout, not dropped. The scan is advisory by design (Defender in the build job is the fail-closed check for Windows), so the control worth keeping is that the sweep cannot be quietly lost:
virustotal-scanexists andneeds: [publish-release]test_the_scan_is_its_own_job_gated_on_publish_releaseif:, and no step-levelif:except the summary'salways()test_the_scan_job_is_not_conditioned_awaytest_the_scan_scans_the_bundles_that_were_publishedcontinue-on-error, no|| true, no|| :, noexit 0, and no--fail-thresholdpinned to a value the script treats as never-failtest_the_scan_step_does_not_swallow_its_own_failurecontinue-on-errorappears on exactly one job and on no step of any job that handles a bundletest_the_advisory_escape_hatch_is_confined_to_the_scan_jobscripts/virustotal_scan.py, asserted by mechanism rather than by the old step name, plus the guard that exits 1 when the script is absenttest_the_scan_job_makes_the_scan_script_availablealways(), since nothing forces a look at acontinue-on-errorjob resulttest_the_scan_verdict_is_always_reportedpublish-releasedoes not re-inline the scantest_the_publish_job_no_longer_runs_the_scanCreate versioned releasestill sits immediately before the upload, so the release is never publicly emptytest_release_creation_stays_immediately_before_the_uploadtest_build_matrix_hands_off_assets_without_release_credentialspermissionsblock, noGITHUB_TOKEN/GH_TOKEN,persist-credentials: false, VirusTotal key onlytest_post_publish_scan_job_holds_no_release_credentials(new)Docstrings now say plainly that this is a post-publish sweep, so a future reader does not go looking for a pre-publish gate that is not there.
One correction to the record
The old step-level comment claimed the scan gated the release. It never did.
DEFAULT_FAIL_THRESHOLD = 0disables the gate inscripts/virustotal_scan.py, and the workflow passes no--fail-threshold, so detections have always surfaced as::warningannotations and a step-summary table while the script exits 0. #8194 did not weaken this; it moved a step-levelcontinue-on-error: trueup to the job. The tests reflect what is actually enforceable instead of asserting a gate that does not exist.Sabotage matrix
Every rewritten and new test was checked by breaking the thing it is supposed to catch, then restoring.
sabotagedandrestoredare pytest exit codes for the named test.virustotal-scanjobneeds: [publish-release]to[prepare-version]if: ${{ false }}continue-on-error: trueon the scan step|| true--fail-threshold 0while claiming to gateif: always()from the summary steppublish-releaseWait for the build matrixgateLEGSlistThe workflow was restored byte-for-byte afterwards; this PR touches no workflow file.
Test run
Before, on
origin/main:After: