Skip to content

Repo tests: pin the post-publish VirusTotal contract instead of the old pre-flight one - #8240

Merged
danielhanchen merged 1 commit into
unslothai:mainfrom
danielhanchen:fix/vtscan-tests
Aug 9, 2026
Merged

danielhanchen merged 1 commit into
unslothai:mainfrom
danielhanchen:fix/vtscan-tests

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

What is red

On a pristine origin/main worktree, python3 -m pytest tests/security tests/python/test_virustotal_scan.py -q gives 5 failed, 299 passed. This is main's own red, so every PR running Repo tests (CPU) inherits it.

Two workflow changes landed without their tests:

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:

Pinned Test
virustotal-scan exists and needs: [publish-release] test_the_scan_is_its_own_job_gated_on_publish_release
No job-level if:, and no step-level if: except the summary's always() test_the_scan_job_is_not_conditioned_away
The downloaded artifact pattern matches what the build matrix uploads, and lands before the scan step test_the_scan_scans_the_bundles_that_were_published
The scan step does not swallow the script's exit status: no continue-on-error, no || true, no || :, no exit 0, and no --fail-threshold pinned to a value the script treats as never-fail test_the_scan_step_does_not_swallow_its_own_failure
continue-on-error appears on exactly one job and on no step of any job that handles a bundle test_the_advisory_escape_hatch_is_confined_to_the_scan_job
The sparse checkout of scripts/virustotal_scan.py, asserted by mechanism rather than by the old step name, plus the guard that exits 1 when the script is absent test_the_scan_job_makes_the_scan_script_available
The step summary is written on always(), since nothing forces a look at a continue-on-error job result test_the_scan_verdict_is_always_reported
publish-release does not re-inline the scan test_the_publish_job_no_longer_runs_the_scan
Create versioned release still sits immediately before the upload, so the release is never publicly empty test_release_creation_stays_immediately_before_the_upload
The build-to-publish handoff gate: the waiter covers every matrix leg by name, refuses a leg that did not succeed, and refuses a leg whose job record never appeared test_build_matrix_hands_off_assets_without_release_credentials
The new scan job holds no release credentials: no permissions block, no GITHUB_TOKEN/GH_TOKEN, persist-credentials: false, VirusTotal key only test_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 = 0 disables the gate in scripts/virustotal_scan.py, and the workflow passes no --fail-threshold, so detections have always surfaced as ::warning annotations and a step-summary table while the script exits 0. #8194 did not weaken this; it moved a step-level continue-on-error: true up 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. sabotaged and restored are pytest exit codes for the named test.

Sabotage sabotaged restored
Delete the virustotal-scan job 1 0
needs: [publish-release] to [prepare-version] 1 0
Condition the job away with if: ${{ false }} 1 0
continue-on-error: true on the scan step 1 0
Swallow the script exit with || true 1 0
Pin --fail-threshold 0 while claiming to gate 1 0
Remove the sparse checkout from the scan job 1 0
Sparse-checkout a different path 1 0
Drop the missing-script guard 1 0
Download a pattern that matches no bundle 1 0
Drop if: always() from the summary step 1 0
Re-inline a VirusTotal step into publish-release 1 0
Remove the Wait for the build matrix gate 1 0
Drop a leg from the waiter's LEGS list 1 0
Let the waiter tolerate a missing job record 1 0
Persist credentials in the scan job checkout 1 0
Hand the scan job a repository token 1 0

The workflow was restored byte-for-byte afterwards; this PR touches no workflow file.

Test run

Before, on origin/main:

5 failed, 299 passed
EXIT=1

After:

310 passed
EXIT=0

…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.
@danielhanchen
danielhanchen merged commit b844e55 into unslothai:main Aug 9, 2026
10 of 19 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +76 to +79
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +122 to +128
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 }}"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +892 to +895
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +1003 to +1004
assert checkout["with"]["sparse-checkout"] == "scripts/virustotal_scan.py"
assert checkout["with"]["persist-credentials"] is False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +960 to +962
invocation = run.split("python3 scripts/virustotal_scan.py", 1)[1]
for swallow in ("|| true", "|| :", "exit 0", "; true"):
assert swallow not in invocation, swallow

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +964 to +969
# 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

danielhanchen added a commit that referenced this pull request Aug 9, 2026
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]>
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.

1 participant