From 1e8ece8d59826680ba0a3697d1a136ba2a548c5b Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 29 Sep 2026 06:03:05 +0000 Subject: [PATCH 1/6] ci(pypi): qualify local wheelhouse installs with a fail-closed aggregate (#4631) Add a dispatch-only, credential-free Python wheelhouse qualification lane for the selected linux/x86_64 pip and uv matrix. Discriminating negative controls reject missing, skipped, failed, unsupported, zero-subject, mismatched, PATH/Cargo, planted-binary, and publication rows. Live installed-use analysis remains #4626, so a wheel install without a nonzero discriminator still cannot pass. Co-authored-by: Steven Zimmerman, CPA --- .../python-wheelhouse-qualification.yml | 127 ++ CHANGELOG.md | 7 + docs/DOCUMENTATION.md | 2 + docs/PYPI_NPM_DISTRIBUTION.md | 4 +- docs/PYTHON_WHEELHOUSE_QUALIFICATION.md | 42 + policy/ci-lane-whitelist.toml | 10 + policy/ci-risk-packs.toml | 2 +- policy/python-wheelhouse-qualification.toml | 19 + policy/workflow_allowlist.txt | 1 + xtask/src/command.rs | 11 + xtask/src/dispatch.rs | 1 + xtask/src/main.rs | 2 +- xtask/src/policy/distribution/mod.rs | 1 + xtask/src/policy/distribution/wheelhouse.rs | 1087 +++++++++++++++++ xtask/src/policy/mod.rs | 4 + 15 files changed, 1317 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/python-wheelhouse-qualification.yml create mode 100644 docs/PYTHON_WHEELHOUSE_QUALIFICATION.md create mode 100644 policy/python-wheelhouse-qualification.toml create mode 100644 xtask/src/policy/distribution/wheelhouse.rs diff --git a/.github/workflows/python-wheelhouse-qualification.yml b/.github/workflows/python-wheelhouse-qualification.yml new file mode 100644 index 00000000000..dadc892b6c0 --- /dev/null +++ b/.github/workflows/python-wheelhouse-qualification.yml @@ -0,0 +1,127 @@ +name: Python Wheelhouse Qualification + +on: + workflow_dispatch: + inputs: + candidate_sha: + description: "Immutable candidate commit SHA (40 hexadecimal characters)" + required: true + type: string + +# Credential-free wheelhouse rehearsal for #4631. No registry write, OIDC, +# secret, tag, or release permission exists on this workflow. +permissions: + contents: read + +concurrency: + group: python-wheelhouse-qualification-${{ inputs.candidate_sha }} + cancel-in-progress: false + +jobs: + qualify: + name: local wheelhouse pip and uv rows + runs-on: ubuntu-latest + timeout-minutes: 60 + env: + CANDIDATE_SHA: ${{ inputs.candidate_sha }} + CARGO_TERM_COLOR: always + steps: + - name: Initialize receipt root + run: | + set -euo pipefail + base="${RUNNER_TEMP}/ripr-python-wheelhouse" + mkdir -p "${base}/receipts/rows" "${base}/wheelhouse" "${base}/consumer" "${base}/decoy" + echo "QUAL_ROOT=${base}/receipts" >> "$GITHUB_ENV" + echo "WHEELHOUSE=${base}/wheelhouse" >> "$GITHUB_ENV" + echo "CONSUMER_ROOT=${base}/consumer" >> "$GITHUB_ENV" + echo "DECOY_ROOT=${base}/decoy" >> "$GITHUB_ENV" + + - name: Checkout immutable candidate + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + ref: ${{ inputs.candidate_sha }} + fetch-depth: 1 + persist-credentials: false + + - name: Verify candidate identity + run: | + set -euo pipefail + [[ "${CANDIDATE_SHA}" =~ ^[0-9a-fA-F]{40}$ ]] + test "$(git rev-parse HEAD)" = "${CANDIDATE_SHA,,}" + test "$(git rev-parse HEAD^{tree})" + python3 -c "import json,os,pathlib,subprocess; p=pathlib.Path(os.environ['QUAL_ROOT'])/'candidate-identity.json'; p.write_text(json.dumps({'source_commit':subprocess.check_output(['git','rev-parse','HEAD'],text=True).strip(),'source_tree':subprocess.check_output(['git','rev-parse','HEAD^{tree}'],text=True).strip(),'limitations':[],'non_claims':['no PyPI publication','no compatibility-floor claim','no support-tier promotion']},indent=2)+'\n')" + + - name: Set up Rust + uses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4 # 1.95 + with: + toolchain: 1.95.0 + + - name: Stage local wheelhouse + run: | + set -euo pipefail + shopt -s nullglob + cp dist/wheels/*.whl "${WHEELHOUSE}/" 2>/dev/null || true + cp packaging/python/dist/*.whl "${WHEELHOUSE}/" 2>/dev/null || true + python3 -m pip install --user uv + printf '%s\n' '#!/bin/sh' 'echo planted-wrong-path' > "${DECOY_ROOT}/ripr" + chmod +x "${DECOY_ROOT}/ripr" + + - name: Isolated pip and uv wheelhouse installs + run: | + set -euo pipefail + export PIP_NO_INDEX=1 UV_OFFLINE=1 + if python3 -m pip install --no-index cowsay; then network=false; else network=true; fi + export PATH="${CONSUMER_ROOT}/venv/bin:${CONSUMER_ROOT}/uv/bin:${DECOY_ROOT}:/usr/bin:/bin" + cargo_ok=false; ambient=false; planted=false; source_ok=false + if command -v cargo >/dev/null || command -v rustc >/dev/null; then cargo_ok=true; fi + if [ -x /usr/bin/ripr ] || [ -x /bin/ripr ]; then ambient=true; fi + if [ "$(command -v ripr 2>/dev/null || true)" = "${DECOY_ROOT}/ripr" ] && [ "$(ripr)" = "planted-wrong-path" ]; then planted=true; fi + case ":$PATH:" in *:"${GITHUB_WORKSPACE}":*) source_ok=true;; esac + shopt -s nullglob + wheels=("${WHEELHOUSE}"/*.whl) + if [ ${#wheels[@]} -eq 0 ]; then + echo "no staged wheels; required pip/uv rows stay missing pending #4490" >&2 + exit 0 + fi + python3 -m venv "${CONSUMER_ROOT}/venv" + "${CONSUMER_ROOT}/venv/bin/pip" install --no-index --find-links "${WHEELHOUSE}" ripr-rs + mkdir -p "${CONSUMER_ROOT}/uv/bin" + PATH="${HOME}/.local/bin:${PATH}" UV_TOOL_BIN_DIR="${CONSUMER_ROOT}/uv/bin" UV_TOOL_DIR="${CONSUMER_ROOT}/uv/tools" UV_FIND_LINKS="${WHEELHOUSE}" HOME="${CONSUMER_ROOT}" uv tool install --offline ripr-rs + pip_bin="${CONSUMER_ROOT}/venv/bin/ripr" + uv_bin="${CONSUMER_ROOT}/uv/bin/ripr" + test -x "${pip_bin}" && test "${pip_bin}" != "${DECOY_ROOT}/ripr" + test -x "${uv_bin}" && test "${uv_bin}" != "${DECOY_ROOT}/ripr" + test "$(command -v ripr)" != "${DECOY_ROOT}/ripr" + python3 - "$pip_bin" "$uv_bin" "$cargo_ok" "$source_ok" "$ambient" "$planted" "$network" <<'PY' + import hashlib, json, os, pathlib, sys + wheel = next(pathlib.Path(os.environ["WHEELHOUSE"]).glob("*.whl")) + sha = hashlib.sha256(wheel.read_bytes()).hexdigest() + root = pathlib.Path(os.environ["QUAL_ROOT"]) / "rows" + root.mkdir(parents=True, exist_ok=True) + def digest(path): + return hashlib.sha256(pathlib.Path(path).read_bytes()).hexdigest() + def flag(index): + return sys.argv[index] == "true" + def write(client, binary): + row = {"client": client, "os": "linux", "arch": "x86_64", "status": "failed", + "wheel_filename": wheel.name, "wheel_sha256": sha, "payload_sha256": digest(binary), + "subject_count": 0, "cargo_reachable": flag(3), "source_checkout_reachable": flag(4), + "ambient_ripr_reachable": flag(5), "planted_wrong_path_detected": flag(6), + "network_disabled_after_staging": flag(7), + "limitations": ["installed-use analysis is owned by #4626; subject_count stays 0 so this row cannot pass"]} + (root / f"{client}.json").write_text(json.dumps(row, indent=2) + "\n") + write("pip", sys.argv[1]); write("uv", sys.argv[2]) + PY + + - name: Evaluate wheelhouse aggregate + if: always() + run: cargo xtask qualify-python-wheelhouse --receipts "${QUAL_ROOT}" + + - name: Upload Actions-only receipts + if: always() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 + with: + name: python-wheelhouse-qualification-${{ inputs.candidate_sha }} + path: ${{ runner.temp }}/ripr-python-wheelhouse/receipts + if-no-files-found: error + retention-days: 5 diff --git a/CHANGELOG.md b/CHANGELOG.md index f12d0066924..89383d4b42a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,13 @@ are scoped or reviewed. ## Unreleased +### Added + +- CI: a dispatch-only local-wheelhouse qualification lane records pip and uv + isolation facts and evaluates a fail-closed aggregate. Missing, skipped, + zero-subject, or mismatched rows cannot pass. No PyPI credentials or + publication (#4631). + ### Fixed - Security: Rust source discovery skips symlinked `.rs` entries, as the diff --git a/docs/DOCUMENTATION.md b/docs/DOCUMENTATION.md index 37c0462e805..aa804a0a651 100644 --- a/docs/DOCUMENTATION.md +++ b/docs/DOCUMENTATION.md @@ -127,6 +127,8 @@ Current how-to docs: - [Installation verification](INSTALLATION_VERIFICATION.md) - [Windows packaged qualification](WINDOWS_PACKAGED_QUALIFICATION.md) - exact candidate Windows CLI and VSIX rehearsal with Actions-only receipts +- [Python wheelhouse qualification](PYTHON_WHEELHOUSE_QUALIFICATION.md) - exact + candidate local-wheelhouse pip/uv rehearsal with a fail-closed aggregate - [First successful PR workflow](FIRST_PR_WORKFLOW.md) - [First successful PR demo](demo/first-successful-pr.md) - [Start-here convergence receipts](handoffs/2026-05-22-start-here-surface-convergence-receipts.md) diff --git a/docs/PYPI_NPM_DISTRIBUTION.md b/docs/PYPI_NPM_DISTRIBUTION.md index 9fed7bda45d..9de84abe142 100644 --- a/docs/PYPI_NPM_DISTRIBUTION.md +++ b/docs/PYPI_NPM_DISTRIBUTION.md @@ -161,7 +161,9 @@ exact package -> clean install -> useful analysis -> supported next step ``` Use a local wheelhouse and isolated npm test registry seeded with the actual -artifacts. Remove source checkout, Rust and ambient ripr from consumer reach; +artifacts. The wheelhouse aggregate and no-publish workflow live in +[Python wheelhouse qualification](PYTHON_WHEELHOUSE_QUALIFICATION.md). Remove +source checkout, Rust and ambient ripr from consumer reach; retain the package-manager runtime and required Git. Exercise offline execution after installation, native platform baselines and scripts-disabled npm. diff --git a/docs/PYTHON_WHEELHOUSE_QUALIFICATION.md b/docs/PYTHON_WHEELHOUSE_QUALIFICATION.md new file mode 100644 index 00000000000..5b40b0cbac4 --- /dev/null +++ b/docs/PYTHON_WHEELHOUSE_QUALIFICATION.md @@ -0,0 +1,42 @@ +# Python wheelhouse qualification + +`Python Wheelhouse Qualification` is an Actions-only rehearsal lane for +[#4631](https://github.com/EffortlessMetrics/ripr-swarm/issues/4631). It +installs candidate wheels from a local wheelhouse with pip and uv, then +evaluates a fail-closed aggregate. It is not a publisher and does not replace +[#4490](https://github.com/EffortlessMetrics/ripr-swarm/issues/4490), +[#4626](https://github.com/EffortlessMetrics/ripr-swarm/issues/4626), or the +generic cross-channel DTO in +[#4630](https://github.com/EffortlessMetrics/ripr-swarm/issues/4630). + +## Invocation + +Dispatch `.github/workflows/python-wheelhouse-qualification.yml` with: + +- `candidate_sha`: the full 40-character immutable candidate commit SHA. + +The job checks out that SHA with `contents: read` and `persist-credentials: +false`, stages `dist/wheels` or `packaging/python/dist` when present, installs +through isolated pip and uv consumers, and retains receipts as an Actions +artifact for 5 days. + +## Gate + +`cargo xtask qualify-python-wheelhouse --receipts ` is the +authority. A required linux/x86_64 pip or uv row can pass only when it records +exact wheel and payload digests, a nonzero subject count, no Cargo/source +checkout/ambient `ripr` escape, a detected planted wrong-PATH binary, and +network disabled after staging. Failed, `not_run`, unsupported, missing, +zero-subject, or mismatched rows cannot satisfy the aggregate. + +When this candidate has no staged wheels, the required rows stay missing and +the aggregate cannot pass. That is the honest result until #4490 produces a +wheelhouse. Installed-use analysis remains #4626; a wheel install without a +nonzero discriminator still cannot pass. + +## Claim boundary + +A passing run would establish that the named candidate's selected linux/x86_64 +wheel installed from a local wheelhouse through pip and uv with the isolation +controls above. It does not establish PyPI publication, a compatibility floor, +a support-tier promotion, or the five-target matrix. diff --git a/policy/ci-lane-whitelist.toml b/policy/ci-lane-whitelist.toml index 6e76c910f01..1bb768885d0 100644 --- a/policy/ci-lane-whitelist.toml +++ b/policy/ci-lane-whitelist.toml @@ -309,6 +309,16 @@ estimated_lem = 60 artifact_families = ["release-readiness"] description = "Cross-platform server archive and manifest proof. Actual build commands come from the workflow matrix." +[[lane]] +id = "python-wheelhouse" +posture = "on_demand_release" +workflow = ".github/workflows/python-wheelhouse-qualification.yml" +jobs = ["qualify"] +commands = ["cargo xtask qualify-python-wheelhouse --receipts "] +estimated_lem = 20 +artifact_families = ["release-readiness"] +description = "Dispatch-only local-wheelhouse pip/uv qualification (#4631). Fail-closed aggregate; no registry write." + [[lane]] id = "release-readiness-proof" posture = "on_demand_release" diff --git a/policy/ci-risk-packs.toml b/policy/ci-risk-packs.toml index b557afb61a8..eac193ad6ca 100644 --- a/policy/ci-risk-packs.toml +++ b/policy/ci-risk-packs.toml @@ -101,7 +101,7 @@ reason = "VS Code extension implementation, package, or tests need editor-loop p paths = ["docs/RELEASE.md", "docs/RELEASE_BINARIES.md", "docs/RELEASE_MARKETPLACE.md", "docs/PUBLISHING.md", ".github/workflows/publish-extension.yml", ".github/workflows/release-server-binaries.yml", "Cargo.toml", "Cargo.lock"] required = ["rust", "policy", "security-posture"] advisory = ["coverage"] -on_demand = ["release-package", "publish-dry-run", "vsix-package", "extension-marketplace-publish", "server-archive", "release-readiness-proof"] +on_demand = ["release-package", "publish-dry-run", "vsix-package", "extension-marketplace-publish", "server-archive", "python-wheelhouse", "release-readiness-proof"] artifact_families = ["release-readiness"] estimated_lem = 60 owner = "repo-maintainers" diff --git a/policy/python-wheelhouse-qualification.toml b/policy/python-wheelhouse-qualification.toml new file mode 100644 index 00000000000..d1ce7d5f166 --- /dev/null +++ b/policy/python-wheelhouse-qualification.toml @@ -0,0 +1,19 @@ +schema_version = "1.0" +policy_state = "credential-free-rehearsal" +enforcement = "workflow_dispatch_only" +owner = "repo-maintainers" +workflow = ".github/workflows/python-wheelhouse-qualification.yml" +issues = [4631, 4493] +channel = "pypi-wheelhouse" +publication = "forbidden" +secrets = "forbidden" +receipt_transport = "actions_artifact_only" +max_artifact_retention_days = 5 +admitted_os = "linux" +admitted_arch = "x86_64" +required_clients = ["pip", "uv"] + +# This lane qualifies local-wheelhouse installs for the selected OS/arch. +# It does not build the ripr-rs adapter, claim compatibility floors, or +# authorize publication. Missing, skipped, zero-subject, or mismatched rows +# cannot pass the aggregate. diff --git a/policy/workflow_allowlist.txt b/policy/workflow_allowlist.txt index 9e56e05bc96..3dfa9799bba 100644 --- a/policy/workflow_allowlist.txt +++ b/policy/workflow_allowlist.txt @@ -33,4 +33,5 @@ .github/workflows/ub-review.yml|0|ub-review workflow delegates entirely to the EffortlessMetrics/ub-review action (no inline run blocks); see #1469. .github/workflows/windows-advisory.yml|15|Advisory Windows lane runs a multi-step log-to-verdict pipeline in YAML; the cargo xtask windows-advisory-summary command is the verdict authority. .github/workflows/windows-packaged-qualification.yml|50|On-demand exact-candidate Windows package and VSIX rehearsal must retain identity checks, isolated CLI/editor journeys, and Actions-only receipts in one workflow. +.github/workflows/python-wheelhouse-qualification.yml|50|On-demand local-wheelhouse pip/uv qualification writes isolation facts and a fail-closed aggregate; credential-free, artifact-only, no publication. .github/workflows/zed-extension.yml|1|Zed extension workflow keeps each run block to one Cargo command. diff --git a/xtask/src/command.rs b/xtask/src/command.rs index f13ab2d98bc..337a29fc789 100644 --- a/xtask/src/command.rs +++ b/xtask/src/command.rs @@ -137,6 +137,7 @@ pub(crate) enum XtaskCommand { CheckPositioningLanguage, CheckDocRoles, CheckReleaseTargets, + QualifyPythonWheelhouse(Vec), VscodeCompile, VscodePackage, VscodeTest, @@ -296,6 +297,7 @@ impl XtaskCommand { "check-positioning-language" => Self::CheckPositioningLanguage, "check-doc-roles" => Self::CheckDocRoles, "check-release-targets" => Self::CheckReleaseTargets, + "qualify-python-wheelhouse" => Self::QualifyPythonWheelhouse(rest), "vscode-compile" => Self::VscodeCompile, "vscode-package" => Self::VscodePackage, "vscode-test" => Self::VscodeTest, @@ -512,6 +514,7 @@ pub(crate) fn known_commands() -> Vec<&'static str> { "check-positioning-language", "check-doc-roles", "check-release-targets", + "qualify-python-wheelhouse --receipts ", "vscode-compile", "vscode-package", "vscode-test", @@ -1846,6 +1849,14 @@ pub(crate) fn command_catalog() -> Vec { true, "Checks policy/release-targets.toml for internal release graph integrity offline; never reads GitHub and never qualifies or publishes a candidate.", ), + command_entry( + "qualify-python-wheelhouse --receipts ", + "non_mutating_check", + "target/ripr/reports/python-wheelhouse-qualification.{json,md}", + false, + false, + "Fail-closed local-wheelhouse aggregate for pip/uv rows: missing, skipped, zero-subject, mismatched, PATH/Cargo, or planted-binary rows cannot pass. Dispatch-only; never publishes.", + ), command_entry( "vscode-compile", "non_mutating_check", diff --git a/xtask/src/dispatch.rs b/xtask/src/dispatch.rs index f71b6bb601c..8b41289aaa2 100644 --- a/xtask/src/dispatch.rs +++ b/xtask/src/dispatch.rs @@ -196,6 +196,7 @@ pub(crate) fn execute(command: XtaskCommand) -> Result<(), String> { XtaskCommand::CheckPositioningLanguage => super::check_positioning_language(), XtaskCommand::CheckDocRoles => super::check_doc_roles(), XtaskCommand::CheckReleaseTargets => super::check_release_targets(), + XtaskCommand::QualifyPythonWheelhouse(args) => super::qualify_python_wheelhouse(&args), XtaskCommand::VscodeCompile => super::vscode_compile(), XtaskCommand::VscodePackage => super::vscode_package(), XtaskCommand::VscodeTest => super::vscode_test(), diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 9aa53fe20f7..42c220677b1 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -253,7 +253,7 @@ use policy::{ check_droid_review_config, check_executable_files, check_file_policy, check_local_context, check_network_policy, check_no_panic_family, check_positioning_language, check_process_policy, check_product_copy, check_proof_packs, check_release_targets, check_static_language, - check_workflows, + check_workflows, qualify_python_wheelhouse, }; use public_api_surface::public_api_surface; #[cfg(test)] diff --git a/xtask/src/policy/distribution/mod.rs b/xtask/src/policy/distribution/mod.rs index c28dbc6ebd1..f0c447f820b 100644 --- a/xtask/src/policy/distribution/mod.rs +++ b/xtask/src/policy/distribution/mod.rs @@ -2,6 +2,7 @@ mod contract; mod crate_targets; mod targets; mod version; +mod wheelhouse; mod workflow; use std::fs; diff --git a/xtask/src/policy/distribution/wheelhouse.rs b/xtask/src/policy/distribution/wheelhouse.rs new file mode 100644 index 00000000000..25f0fb388ef --- /dev/null +++ b/xtask/src/policy/distribution/wheelhouse.rs @@ -0,0 +1,1087 @@ +//! Fail-closed local-wheelhouse qualification for the PyPI channel (#4631). +//! +//! The generic cross-channel package-qualification DTO remains #4630. This +//! owner is the wheelhouse row/aggregate gate and the no-publish consumer +//! workflow that feeds it. + +use std::collections::{BTreeMap, BTreeSet}; +use std::fs; +use std::path::{Path, PathBuf}; + +use serde::{Deserialize, Serialize}; + +pub(crate) const POLICY_PATH: &str = "policy/python-wheelhouse-qualification.toml"; +pub(crate) const WORKFLOW_PATH: &str = ".github/workflows/python-wheelhouse-qualification.yml"; +const WORKFLOW_TEXT: &str = + include_str!("../../../../.github/workflows/python-wheelhouse-qualification.yml"); +const POLICY_TEXT: &str = include_str!("../../../../policy/python-wheelhouse-qualification.toml"); + +const EXPECTED_CHANNEL: &str = "pypi-wheelhouse"; +const EXPECTED_SCHEMA: &str = "1.0"; + +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[serde(deny_unknown_fields)] +pub(crate) struct WheelhousePolicy { + pub(crate) schema_version: String, + pub(crate) policy_state: String, + pub(crate) enforcement: String, + pub(crate) owner: String, + pub(crate) workflow: String, + pub(crate) issues: Vec, + pub(crate) channel: String, + pub(crate) publication: String, + pub(crate) secrets: String, + pub(crate) receipt_transport: String, + pub(crate) max_artifact_retention_days: u32, + pub(crate) admitted_os: String, + pub(crate) admitted_arch: String, + pub(crate) required_clients: Vec, +} + +#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[serde(rename_all = "snake_case")] +pub(crate) enum WheelhouseRowStatus { + Passed, + Failed, + NotRun, + Unsupported, +} + +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[serde(deny_unknown_fields)] +pub(crate) struct WheelhouseRow { + pub(crate) client: String, + pub(crate) os: String, + pub(crate) arch: String, + pub(crate) status: WheelhouseRowStatus, + #[serde(default)] + pub(crate) wheel_filename: String, + #[serde(default)] + pub(crate) wheel_sha256: String, + #[serde(default)] + pub(crate) payload_sha256: String, + #[serde(default)] + pub(crate) subject_count: u64, + pub(crate) cargo_reachable: bool, + pub(crate) source_checkout_reachable: bool, + pub(crate) ambient_ripr_reachable: bool, + pub(crate) planted_wrong_path_detected: bool, + pub(crate) network_disabled_after_staging: bool, + #[serde(default)] + pub(crate) limitations: Vec, +} + +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[serde(deny_unknown_fields)] +pub(crate) struct WheelhouseReceipt { + pub(crate) schema_version: String, + pub(crate) channel: String, + pub(crate) source_commit: String, + pub(crate) source_tree: String, + pub(crate) publication_authority: bool, + pub(crate) artifact_retention_days: u32, + pub(crate) rows: Vec, + #[serde(default)] + pub(crate) limitations: Vec, + #[serde(default)] + pub(crate) non_claims: Vec, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize)] +pub(crate) struct WheelhouseGate { + pub(crate) passed: bool, + pub(crate) reasons: Vec, +} + +pub(crate) fn parse_policy(path: &str, text: &str) -> Result { + toml::from_str(text).map_err(|err| format!("{path}: invalid wheelhouse policy: {err}")) +} + +pub(crate) fn load_policy() -> Result { + parse_policy(POLICY_PATH, POLICY_TEXT) +} + +pub(crate) fn parse_receipt(path: &str, text: &str) -> Result { + serde_json::from_str(text).map_err(|err| format!("{path}: invalid wheelhouse receipt: {err}")) +} + +pub(crate) fn evaluate_wheelhouse( + policy: &WheelhousePolicy, + receipt: &WheelhouseReceipt, +) -> WheelhouseGate { + let mut reasons = Vec::new(); + validate_policy(policy, &mut reasons); + if receipt.schema_version != EXPECTED_SCHEMA { + reasons.push(format!( + "receipt schema_version must be {EXPECTED_SCHEMA}, got {}", + receipt.schema_version + )); + } + if receipt.channel != policy.channel || receipt.channel != EXPECTED_CHANNEL { + reasons.push(format!( + "receipt channel must be {}, got {}", + policy.channel, receipt.channel + )); + } + if !is_commit_sha(&receipt.source_commit) { + reasons.push("source_commit must be a lowercase 40-character hex SHA".to_string()); + } + if !is_commit_sha(&receipt.source_tree) { + reasons.push("source_tree must be a lowercase 40-character hex SHA".to_string()); + } + if receipt.publication_authority { + reasons.push( + "publication_authority must be false; this lane has no registry write".to_string(), + ); + } + if receipt.artifact_retention_days == 0 + || receipt.artifact_retention_days > policy.max_artifact_retention_days + { + reasons.push(format!( + "artifact_retention_days must be 1..={}, got {}", + policy.max_artifact_retention_days, receipt.artifact_retention_days + )); + } + if receipt + .non_claims + .iter() + .any(|claim| claim.trim().is_empty()) + { + reasons.push("non_claims must not contain empty entries".to_string()); + } + + let required = required_row_ids(policy); + if required.is_empty() { + reasons.push("policy required_clients produced zero required rows".to_string()); + } + + let mut seen = BTreeMap::new(); + for (index, row) in receipt.rows.iter().enumerate() { + let id = row_id(row); + if seen.insert(id.clone(), index).is_some() { + reasons.push(format!("duplicate row `{id}`")); + } + if row.os != policy.admitted_os || row.arch != policy.admitted_arch { + if row.status == WheelhouseRowStatus::Passed { + reasons.push(format!( + "row `{id}` is outside the admitted {os}/{arch} matrix and cannot pass", + os = policy.admitted_os, + arch = policy.admitted_arch + )); + } + } + if !policy + .required_clients + .iter() + .any(|client| client == &row.client) + && row.status == WheelhouseRowStatus::Passed + { + reasons.push(format!( + "row `{id}` uses a client outside the required set and cannot pass" + )); + } + if row.status == WheelhouseRowStatus::Passed { + reasons.extend(passed_row_violations(row, &id)); + } + } + + for id in &required { + match seen.get(id).copied() { + None => reasons.push(format!( + "required row `{id}` is missing; skipped or unobserved work cannot pass" + )), + Some(index) => { + let row = &receipt.rows[index]; + if row.status != WheelhouseRowStatus::Passed { + reasons.push(format!( + "required row `{id}` is {:?}; failed, not_run, or unsupported rows cannot satisfy the aggregate", + row.status + )); + } + } + } + } + + reasons.extend(mismatched_identity_reasons(receipt, &required)); + WheelhouseGate { + passed: reasons.is_empty(), + reasons, + } +} + +pub(crate) fn run(args: &[String]) -> Result<(), String> { + let receipts = parse_run_args(args)?; + let policy = load_policy()?; + let receipt = load_receipt_from_path(&receipts)?; + let gate = evaluate_wheelhouse(&policy, &receipt); + write_gate_reports(&receipts, &receipt, &gate)?; + if gate.passed { + Ok(()) + } else { + Err(format!( + "python wheelhouse qualification did not pass:\n- {}", + gate.reasons.join("\n- ") + )) + } +} + +fn parse_run_args(args: &[String]) -> Result { + match args { + [flag, path] if flag == "--receipts" => { + if path.starts_with('-') { + return Err("qualify-python-wheelhouse --receipts requires a path".to_string()); + } + Ok(PathBuf::from(path)) + } + _ => { + Err("usage: cargo xtask qualify-python-wheelhouse --receipts ".to_string()) + } + } +} + +fn load_receipt_from_path(path: &Path) -> Result { + if path.is_dir() { + assemble_receipt_dir(path) + } else { + let text = fs::read_to_string(path) + .map_err(|err| format!("failed to read {}: {err}", path.display()))?; + parse_receipt(&path.display().to_string(), &text) + } +} + +fn assemble_receipt_dir(dir: &Path) -> Result { + let identity_path = dir.join("candidate-identity.json"); + let identity_text = fs::read_to_string(&identity_path) + .map_err(|err| format!("failed to read {}: {err}", identity_path.display()))?; + let identity: CandidateIdentity = serde_json::from_str(&identity_text).map_err(|err| { + format!( + "{}: invalid candidate identity: {err}", + identity_path.display() + ) + })?; + let rows_dir = dir.join("rows"); + let mut rows = Vec::new(); + if rows_dir.is_dir() { + let mut files = fs::read_dir(&rows_dir) + .map_err(|err| format!("failed to read {}: {err}", rows_dir.display()))? + .collect::, _>>() + .map_err(|err| format!("failed to list {}: {err}", rows_dir.display()))?; + files.sort_by_key(|entry| entry.file_name()); + for entry in files { + let path = entry.path(); + if path.extension().and_then(|ext| ext.to_str()) != Some("json") { + continue; + } + let text = fs::read_to_string(&path) + .map_err(|err| format!("failed to read {}: {err}", path.display()))?; + rows.push(parse_row(&path.display().to_string(), &text)?); + } + } + let policy = load_policy()?; + Ok(WheelhouseReceipt { + schema_version: EXPECTED_SCHEMA.to_string(), + channel: policy.channel, + source_commit: identity.source_commit, + source_tree: identity.source_tree, + publication_authority: false, + artifact_retention_days: policy.max_artifact_retention_days, + rows, + limitations: identity.limitations, + non_claims: identity.non_claims, + }) +} + +fn parse_row(path: &str, text: &str) -> Result { + serde_json::from_str(text).map_err(|err| format!("{path}: invalid wheelhouse row: {err}")) +} + +fn write_gate_reports( + receipts: &Path, + receipt: &WheelhouseReceipt, + gate: &WheelhouseGate, +) -> Result<(), String> { + let report = GateReport { + schema_version: EXPECTED_SCHEMA, + channel: EXPECTED_CHANNEL, + passed: gate.passed, + reasons: &gate.reasons, + receipt, + }; + let json = serde_json::to_string_pretty(&report) + .map_err(|err| format!("failed to render wheelhouse gate JSON: {err}"))?; + let markdown = render_gate_markdown(&report); + let reports = Path::new("target/ripr/reports"); + fs::create_dir_all(reports) + .map_err(|err| format!("failed to create {}: {err}", reports.display()))?; + let report_json = reports.join("python-wheelhouse-qualification.json"); + let report_md = reports.join("python-wheelhouse-qualification.md"); + fs::write(report_json, format!("{json}\n")) + .map_err(|err| format!("failed to write {}: {err}", report_json.display()))?; + fs::write(report_md, markdown) + .map_err(|err| format!("failed to write {}: {err}", report_md.display()))?; + if receipts.is_dir() { + let copy_json = receipts.join("wheelhouse-qualification.json"); + fs::write(©_json, format!("{json}\n")) + .map_err(|err| format!("failed to write {}: {err}", copy_json.display()))?; + } + Ok(()) +} + +fn render_gate_markdown(report: &GateReport<'_>) -> String { + let mut lines = vec![ + "# Python wheelhouse qualification".to_string(), + String::new(), + format!("Status: {}", if report.passed { "pass" } else { "failed" }), + format!("Channel: {}", report.channel), + format!("Source commit: {}", report.receipt.source_commit), + format!("Source tree: {}", report.receipt.source_tree), + format!( + "Publication authority: {}", + report.receipt.publication_authority + ), + format!( + "Artifact retention days: {}", + report.receipt.artifact_retention_days + ), + String::new(), + "## Rows".to_string(), + String::new(), + ]; + if report.receipt.rows.is_empty() { + lines.push("- none".to_string()); + } else { + for row in &report.receipt.rows { + lines.push(format!( + "- `{}`: {:?} subjects={} wheel={} payload={}", + row_id(row), + row.status, + row.subject_count, + nonempty_or_dash(&row.wheel_sha256), + nonempty_or_dash(&row.payload_sha256) + )); + } + } + if !report.reasons.is_empty() { + lines.push(String::new()); + lines.push("## Reasons".to_string()); + lines.push(String::new()); + for reason in report.reasons { + lines.push(format!("- {reason}")); + } + } + lines.push(String::new()); + lines.join("\n") +} + +fn nonempty_or_dash(value: &str) -> &str { + if value.is_empty() { "-" } else { value } +} + +fn validate_policy(policy: &WheelhousePolicy, reasons: &mut Vec) { + if policy.schema_version != EXPECTED_SCHEMA { + reasons.push(format!( + "policy schema_version must be {EXPECTED_SCHEMA}, got {}", + policy.schema_version + )); + } + if policy.channel != EXPECTED_CHANNEL { + reasons.push(format!( + "policy channel must be {EXPECTED_CHANNEL}, got {}", + policy.channel + )); + } + if policy.publication != "forbidden" || policy.secrets != "forbidden" { + reasons.push("policy must forbid publication and secrets".to_string()); + } + if policy.enforcement != "workflow_dispatch_only" { + reasons.push("policy enforcement must be workflow_dispatch_only".to_string()); + } + if policy.workflow != WORKFLOW_PATH { + reasons.push(format!( + "policy workflow must be {WORKFLOW_PATH}, got {}", + policy.workflow + )); + } + if policy.max_artifact_retention_days == 0 || policy.max_artifact_retention_days > 7 { + reasons.push("policy max_artifact_retention_days must be 1..=7".to_string()); + } + if policy.required_clients.is_empty() { + reasons.push("policy required_clients must not be empty".to_string()); + } +} + +fn required_row_ids(policy: &WheelhousePolicy) -> BTreeSet { + policy + .required_clients + .iter() + .map(|client| format!("{client}:{}:{}", policy.admitted_os, policy.admitted_arch)) + .collect() +} + +fn row_id(row: &WheelhouseRow) -> String { + format!("{}:{}:{}", row.client, row.os, row.arch) +} + +fn passed_row_violations(row: &WheelhouseRow, id: &str) -> Vec { + let mut reasons = Vec::new(); + if row.wheel_filename.trim().is_empty() { + reasons.push(format!("passed row `{id}` is missing wheel_filename")); + } + if !is_content_digest(&row.wheel_sha256) { + reasons.push(format!( + "passed row `{id}` must record a nonempty lowercase 64-hex wheel digest" + )); + } + if !is_content_digest(&row.payload_sha256) { + reasons.push(format!( + "passed row `{id}` must record a nonempty lowercase 64-hex payload digest" + )); + } + if row.wheel_sha256 == row.payload_sha256 && is_content_digest(&row.wheel_sha256) { + reasons.push(format!( + "passed row `{id}` wheel and payload digests must not be identical; container hash is not installed-payload identity" + )); + } + if row.subject_count == 0 { + reasons.push(format!( + "passed row `{id}` has zero subjects; zero-subject work cannot pass" + )); + } + if row.cargo_reachable { + reasons.push(format!("passed row `{id}` still has Cargo reachable")); + } + if row.source_checkout_reachable { + reasons.push(format!( + "passed row `{id}` still has a source checkout reachable" + )); + } + if row.ambient_ripr_reachable { + reasons.push(format!( + "passed row `{id}` still has an ambient ripr reachable" + )); + } + if !row.planted_wrong_path_detected { + reasons.push(format!( + "passed row `{id}` did not detect the planted wrong-PATH binary" + )); + } + if !row.network_disabled_after_staging { + reasons.push(format!( + "passed row `{id}` did not disable network after staging" + )); + } + reasons +} + +fn mismatched_identity_reasons( + receipt: &WheelhouseReceipt, + required: &BTreeSet, +) -> Vec { + let mut reasons = Vec::new(); + let mut wheel_hashes = BTreeSet::new(); + let mut payload_hashes = BTreeSet::new(); + for row in &receipt.rows { + let id = row_id(row); + if !required.contains(&id) || row.status != WheelhouseRowStatus::Passed { + continue; + } + if is_content_digest(&row.wheel_sha256) { + wheel_hashes.insert(row.wheel_sha256.as_str()); + } + if is_content_digest(&row.payload_sha256) { + payload_hashes.insert(row.payload_sha256.as_str()); + } + } + if wheel_hashes.len() > 1 { + reasons.push( + "required passed rows record mismatched wheel digests for the same wheelhouse" + .to_string(), + ); + } + if payload_hashes.len() > 1 { + reasons.push( + "required passed rows record mismatched payload digests for the same installed binary" + .to_string(), + ); + } + reasons +} + +fn is_commit_sha(value: &str) -> bool { + value.len() == 40 && is_lowercase_hex(value) +} + +fn is_content_digest(value: &str) -> bool { + value.len() == 64 && is_lowercase_hex(value) && value.bytes().any(|byte| byte != b'0') +} + +fn is_lowercase_hex(value: &str) -> bool { + !value.is_empty() + && value + .bytes() + .all(|byte| matches!(byte, b'0'..=b'9' | b'a'..=b'f')) +} + +#[derive(Deserialize)] +#[serde(deny_unknown_fields)] +struct CandidateIdentity { + source_commit: String, + source_tree: String, + #[serde(default)] + limitations: Vec, + #[serde(default)] + non_claims: Vec, +} + +#[derive(Serialize)] +struct GateReport<'a> { + schema_version: &'static str, + channel: &'static str, + passed: bool, + reasons: &'a [String], + receipt: &'a WheelhouseReceipt, +} + +#[cfg(test)] +mod tests { + use super::*; + + const COMMIT: &str = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; + const TREE: &str = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; + const WHEEL_SHA: &str = "1111111111111111111111111111111111111111111111111111111111111111"; + const PAYLOAD_SHA: &str = "2222222222222222222222222222222222222222222222222222222222222222"; + + fn policy() -> Result { + parse_policy(POLICY_PATH, POLICY_TEXT) + } + + fn passed_row(client: &str) -> WheelhouseRow { + WheelhouseRow { + client: client.to_string(), + os: "linux".to_string(), + arch: "x86_64".to_string(), + status: WheelhouseRowStatus::Passed, + wheel_filename: "ripr_rs-0.11.0-py3-none-linux_x86_64.whl".to_string(), + wheel_sha256: WHEEL_SHA.to_string(), + payload_sha256: PAYLOAD_SHA.to_string(), + subject_count: 3, + cargo_reachable: false, + source_checkout_reachable: false, + ambient_ripr_reachable: false, + planted_wrong_path_detected: true, + network_disabled_after_staging: true, + limitations: Vec::new(), + } + } + + fn valid_receipt() -> WheelhouseReceipt { + WheelhouseReceipt { + schema_version: EXPECTED_SCHEMA.to_string(), + channel: EXPECTED_CHANNEL.to_string(), + source_commit: COMMIT.to_string(), + source_tree: TREE.to_string(), + publication_authority: false, + artifact_retention_days: 5, + rows: vec![passed_row("pip"), passed_row("uv")], + limitations: Vec::new(), + non_claims: vec![ + "no PyPI publication".to_string(), + "no compatibility-floor claim".to_string(), + ], + } + } + + fn reasons(receipt: WheelhouseReceipt) -> Result, String> { + Ok(evaluate_wheelhouse(&policy()?, &receipt).reasons) + } + + fn must_reject(receipt: WheelhouseReceipt, needle: &str) -> Result<(), String> { + let reasons = reasons(receipt)?; + if reasons.iter().any(|reason| reason.contains(needle)) { + Ok(()) + } else { + Err(format!( + "expected a reason containing {needle:?}, got {reasons:#?}" + )) + } + } + + #[test] + fn committed_policy_matches_the_selected_linux_x64_matrix() -> Result<(), String> { + let policy = policy()?; + assert_eq!(policy.channel, EXPECTED_CHANNEL); + assert_eq!(policy.admitted_os, "linux"); + assert_eq!(policy.admitted_arch, "x86_64"); + assert_eq!(policy.required_clients, ["pip", "uv"]); + assert_eq!(policy.max_artifact_retention_days, 5); + assert_eq!(policy.publication, "forbidden"); + assert_eq!(policy.secrets, "forbidden"); + assert_eq!(policy.workflow, WORKFLOW_PATH); + assert!(policy.issues.contains(&4631)); + Ok(()) + } + + #[test] + fn matching_pip_and_uv_rows_pass() -> Result<(), String> { + let gate = evaluate_wheelhouse(&policy()?, &valid_receipt()); + if !gate.passed { + return Err(format!("expected pass, got {:#?}", gate.reasons)); + } + if !gate.reasons.is_empty() { + return Err(format!("expected no reasons, got {:#?}", gate.reasons)); + } + Ok(()) + } + + #[test] + fn missing_required_uv_row_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows.retain(|row| row.client != "uv"); + must_reject(receipt, "required row `uv:linux:x86_64` is missing") + } + + #[test] + fn not_run_required_row_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows[1].status = WheelhouseRowStatus::NotRun; + receipt.rows[1].subject_count = 0; + must_reject(receipt, "`uv:linux:x86_64` is NotRun") + } + + #[test] + fn failed_required_row_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows[0].status = WheelhouseRowStatus::Failed; + must_reject(receipt, "`pip:linux:x86_64` is Failed") + } + + #[test] + fn unsupported_required_row_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows[0].status = WheelhouseRowStatus::Unsupported; + must_reject(receipt, "`pip:linux:x86_64` is Unsupported") + } + + #[test] + fn zero_subject_passed_row_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows[0].subject_count = 0; + must_reject(receipt, "zero subjects") + } + + #[test] + fn missing_wheel_digest_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows[0].wheel_sha256.clear(); + must_reject(receipt, "wheel digest") + } + + #[test] + fn placeholder_zero_payload_digest_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows[0].payload_sha256 = "0".repeat(64); + must_reject(receipt, "payload digest") + } + + #[test] + fn identical_wheel_and_payload_digests_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows[0].payload_sha256 = WHEEL_SHA.to_string(); + receipt.rows[1].payload_sha256 = WHEEL_SHA.to_string(); + must_reject(receipt, "must not be identical") + } + + #[test] + fn cargo_escape_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows[0].cargo_reachable = true; + must_reject(receipt, "Cargo reachable") + } + + #[test] + fn source_checkout_escape_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows[0].source_checkout_reachable = true; + must_reject(receipt, "source checkout") + } + + #[test] + fn ambient_ripr_escape_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows[0].ambient_ripr_reachable = true; + must_reject(receipt, "ambient ripr") + } + + #[test] + fn undetected_planted_path_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows[0].planted_wrong_path_detected = false; + must_reject(receipt, "planted wrong-PATH") + } + + #[test] + fn network_left_enabled_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows[0].network_disabled_after_staging = false; + must_reject(receipt, "disable network after staging") + } + + #[test] + fn mismatched_wheel_digests_across_clients_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows[1].wheel_sha256 = + "3333333333333333333333333333333333333333333333333333333333333333".to_string(); + must_reject(receipt, "mismatched wheel digests") + } + + #[test] + fn publication_authority_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.publication_authority = true; + must_reject(receipt, "publication_authority") + } + + #[test] + fn unbounded_retention_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.artifact_retention_days = 90; + must_reject(receipt, "artifact_retention_days") + } + + #[test] + fn macos_passed_row_cannot_widen_the_matrix() -> Result<(), String> { + let mut receipt = valid_receipt(); + let mut extra = passed_row("pip"); + extra.os = "macos".to_string(); + extra.arch = "arm64".to_string(); + receipt.rows.push(extra); + must_reject(receipt, "outside the admitted linux/x86_64 matrix") + } + + #[test] + fn unknown_receipt_fields_are_rejected() -> Result<(), String> { + match parse_receipt( + "fixture.json", + r#"{"schema_version":"1.0","channel":"pypi-wheelhouse","source_commit":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa","source_tree":"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb","publication_authority":false,"artifact_retention_days":5,"rows":[],"pypi_token":"secret"}"#, + ) { + Ok(_) => Err("unknown credential field must fail closed".to_string()), + Err(err) if err.contains("unknown field") => Ok(()), + Err(err) => Err(format!("expected unknown field error, got {err}")), + } + } + + #[test] + fn uppercase_commit_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.source_commit = COMMIT.to_ascii_uppercase(); + must_reject(receipt, "source_commit") + } + + #[test] + fn round_trip_json_preserves_a_valid_receipt() -> Result<(), String> { + let receipt = valid_receipt(); + let encoded = serde_json::to_string(&receipt).map_err(|err| err.to_string())?; + let decoded = parse_receipt("round-trip.json", &encoded)?; + assert_eq!(decoded, receipt); + Ok(()) + } + + #[test] + fn missing_receipts_argument_is_refused() -> Result<(), String> { + match parse_run_args(&[]) { + Ok(_) => Err("usage must be required".to_string()), + Err(err) if err.contains("--receipts") => Ok(()), + Err(err) => Err(format!("expected --receipts usage, got {err}")), + } + } + + #[test] + fn dash_prefixed_receipts_path_is_refused() -> Result<(), String> { + match parse_run_args(&["--receipts".to_string(), "-evil".to_string()]) { + Ok(_) => Err("dash-prefixed receipts path must be refused".to_string()), + Err(err) if err.contains("--receipts") => Ok(()), + Err(err) => Err(format!("expected --receipts usage, got {err}")), + } + } + + #[test] + fn duplicate_required_row_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows.push(passed_row("pip")); + must_reject(receipt, "duplicate row `pip:linux:x86_64`") + } + + #[test] + fn extra_client_passed_row_cannot_widen_the_matrix() -> Result<(), String> { + let mut receipt = valid_receipt(); + let mut extra = passed_row("poetry"); + extra.payload_sha256 = + "4444444444444444444444444444444444444444444444444444444444444444".to_string(); + receipt.rows.push(extra); + must_reject(receipt, "outside the required set") + } + + #[test] + fn empty_wheel_filename_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows[0].wheel_filename.clear(); + must_reject(receipt, "missing wheel_filename") + } + + #[test] + fn zero_retention_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.artifact_retention_days = 0; + must_reject(receipt, "artifact_retention_days") + } + + #[test] + fn empty_non_claim_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.non_claims.push(" ".to_string()); + must_reject(receipt, "non_claims") + } + + #[test] + fn uppercase_wheel_digest_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows[0].wheel_sha256 = WHEEL_SHA.to_ascii_uppercase(); + receipt.rows[1].wheel_sha256 = WHEEL_SHA.to_ascii_uppercase(); + must_reject(receipt, "wheel digest") + } + + #[test] + fn unknown_row_fields_are_rejected() -> Result<(), String> { + match parse_row( + "row.json", + r#"{"client":"pip","os":"linux","arch":"x86_64","status":"failed","cargo_reachable":false,"source_checkout_reachable":false,"ambient_ripr_reachable":false,"planted_wrong_path_detected":false,"network_disabled_after_staging":false,"pypi_token":"secret"}"#, + ) { + Ok(_) => Err("unknown credential field on a row must fail closed".to_string()), + Err(err) if err.contains("unknown field") => Ok(()), + Err(err) => Err(format!("expected unknown field error, got {err}")), + } + } + + #[test] + fn publication_allowed_policy_cannot_pass() -> Result<(), String> { + let mut policy = policy()?; + policy.publication = "allowed".to_string(); + let gate = evaluate_wheelhouse(&policy, &valid_receipt()); + if gate + .reasons + .iter() + .any(|reason| reason.contains("forbid publication")) + { + Ok(()) + } else { + Err(format!( + "expected publication forbidden reason, got {:#?}", + gate.reasons + )) + } + } + + fn write_identity(root: &Path) -> Result<(), String> { + fs::create_dir_all(root.join("rows")).map_err(|err| err.to_string())?; + let identity = serde_json::json!({ + "source_commit": COMMIT, + "source_tree": TREE, + "limitations": ["fixture"], + "non_claims": ["no PyPI publication"] + }); + fs::write( + root.join("candidate-identity.json"), + format!("{identity}\n"), + ) + .map_err(|err| err.to_string()) + } + + fn temp_root(label: &str) -> PathBuf { + std::env::temp_dir().join(format!("ripr-wheelhouse-{}-{label}", std::process::id())) + } + + #[test] + fn assemble_dir_with_no_row_files_cannot_pass() -> Result<(), String> { + let root = temp_root("missing-rows"); + write_identity(&root)?; + let receipt = assemble_receipt_dir(&root)?; + let gate = evaluate_wheelhouse(&policy()?, &receipt); + let _ = fs::remove_dir_all(&root); + if gate.passed { + return Err("missing rows must not pass".to_string()); + } + if gate + .reasons + .iter() + .any(|reason| reason.contains("required row `pip:linux:x86_64` is missing")) + { + Ok(()) + } else { + Err(format!( + "missing pip row was not reported: {:#?}", + gate.reasons + )) + } + } + + #[test] + fn assemble_dir_with_zero_subject_failed_rows_cannot_pass() -> Result<(), String> { + let root = temp_root("zero-subject-rows"); + write_identity(&root)?; + for client in ["pip", "uv"] { + let mut row = passed_row(client); + row.status = WheelhouseRowStatus::Failed; + row.subject_count = 0; + fs::write( + root.join("rows").join(format!("{client}.json")), + format!( + "{}\n", + serde_json::to_string(&row).map_err(|err| err.to_string())? + ), + ) + .map_err(|err| err.to_string())?; + } + let receipt = assemble_receipt_dir(&root)?; + let gate = evaluate_wheelhouse(&policy()?, &receipt); + let _ = fs::remove_dir_all(&root); + if gate.passed { + return Err("zero-subject failed rows must not pass".to_string()); + } + if gate + .reasons + .iter() + .any(|reason| reason.contains("`pip:linux:x86_64` is Failed")) + { + Ok(()) + } else { + Err(format!( + "failed pip row was not reported: {:#?}", + gate.reasons + )) + } + } + + #[test] + fn assemble_dir_with_matching_passed_rows_passes() -> Result<(), String> { + let root = temp_root("passed-rows"); + write_identity(&root)?; + for client in ["pip", "uv"] { + let row = passed_row(client); + fs::write( + root.join("rows").join(format!("{client}.json")), + format!( + "{}\n", + serde_json::to_string(&row).map_err(|err| err.to_string())? + ), + ) + .map_err(|err| err.to_string())?; + } + let receipt = assemble_receipt_dir(&root)?; + let gate = evaluate_wheelhouse(&policy()?, &receipt); + let _ = fs::remove_dir_all(&root); + if gate.passed { + Ok(()) + } else { + Err(format!("expected assembled pass, got {:#?}", gate.reasons)) + } + } + + fn workflow_lines() -> Vec<&'static str> { + WORKFLOW_TEXT + .lines() + .map(str::trim) + .filter(|line| !line.is_empty() && !line.starts_with('#')) + .collect() + } + + #[test] + fn workflow_is_read_only_dispatch_only_and_non_publishing() { + let lines = workflow_lines(); + assert!(lines.iter().any(|line| *line == "workflow_dispatch:")); + assert!(!lines.iter().any(|line| line.starts_with("pull_request:"))); + assert!(!lines.iter().any(|line| line.starts_with("push:"))); + assert_eq!( + lines.iter().find(|line| line.starts_with("contents:")), + Some(&"contents: read") + ); + assert!(!WORKFLOW_TEXT.contains("id-token")); + assert!(!WORKFLOW_TEXT.contains("secrets.")); + assert!(!WORKFLOW_TEXT.contains("twine")); + assert!(!WORKFLOW_TEXT.contains("pypi.org/legacy")); + assert!(!WORKFLOW_TEXT.contains("gh release")); + assert!( + lines + .iter() + .any(|line| line.contains("persist-credentials: false")) + ); + assert!(lines.iter().any(|line| *line == "if-no-files-found: error")); + assert!(lines.iter().any(|line| *line == "retention-days: 5")); + assert!( + WORKFLOW_TEXT + .contains("actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a") + ); + assert!( + WORKFLOW_TEXT.contains("actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803") + ); + } + + #[test] + fn workflow_installs_from_a_local_wheelhouse_with_isolation_controls() { + let text = WORKFLOW_TEXT; + assert!(text.contains("pip install --no-index --find-links")); + assert!(text.contains("uv tool install --offline")); + assert!(text.contains("PIP_NO_INDEX=1")); + assert!(text.contains("UV_OFFLINE=1")); + assert!(text.contains("planted-wrong-path")); + assert!(text.contains("command -v cargo")); + assert!(text.contains("command -v rustc")); + assert!(text.contains("command -v ripr")); + assert!(text.contains(r#"= "${DECOY_ROOT}/ripr""#)); + assert!(text.contains("/usr/bin/ripr")); + assert!(text.contains("cargo xtask qualify-python-wheelhouse --receipts")); + assert!(text.contains("python3 -m pip install --no-index cowsay")); + assert!(text.contains(r#""status": "failed""#)); + assert!(text.contains(r#""subject_count": 0"#)); + assert!(text.contains("flag(3)")); + assert!(text.contains("flag(7)")); + } + + #[test] + fn workflow_run_blocks_stay_within_the_visible_budget() { + let mut max_non_empty = 0usize; + let lines: Vec<&str> = WORKFLOW_TEXT.lines().collect(); + let mut idx = 0usize; + while idx < lines.len() { + let line = lines[idx]; + let trimmed = line.trim_start(); + if let Some(rest) = trimmed.strip_prefix("run:") { + let indent = line.len() - trimmed.len(); + let run_value = rest.trim(); + if matches!(run_value, "|" | ">" | "|-" | ">-") { + let mut next_idx = idx + 1; + let mut non_empty = 0usize; + while next_idx < lines.len() { + let next = lines[next_idx]; + let next_trimmed = next.trim_start(); + let next_indent = next.len() - next_trimmed.len(); + if !next_trimmed.is_empty() && next_indent <= indent { + break; + } + if !next_trimmed.is_empty() { + non_empty += 1; + } + next_idx += 1; + } + max_non_empty = max_non_empty.max(non_empty); + idx = next_idx; + continue; + } + } + idx += 1; + } + assert!( + max_non_empty <= 50, + "largest run block has {max_non_empty} non-empty lines" + ); + } +} diff --git a/xtask/src/policy/mod.rs b/xtask/src/policy/mod.rs index df4661e2483..7b63ea732f7 100644 --- a/xtask/src/policy/mod.rs +++ b/xtask/src/policy/mod.rs @@ -53,3 +53,7 @@ pub(crate) fn check_release_targets() -> Result<(), String> { Err(failures.join("\n")) } } + +pub(crate) fn qualify_python_wheelhouse(args: &[String]) -> Result<(), String> { + distribution::wheelhouse::run(args) +} From e0a1588d36feb9e93bff85034a7fd39520f4c7bb Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 29 Sep 2026 06:06:02 +0000 Subject: [PATCH 2/6] fix(xtask): export wheelhouse module and borrow report paths (#4631) The qualify entrypoint needs crate-visible access to the wheelhouse owner, and the gate-report writer must not move PathBufs before using them in error messages. Co-authored-by: Steven Zimmerman, CPA --- xtask/src/policy/distribution/mod.rs | 2 +- xtask/src/policy/distribution/wheelhouse.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/xtask/src/policy/distribution/mod.rs b/xtask/src/policy/distribution/mod.rs index f0c447f820b..121dbbb033b 100644 --- a/xtask/src/policy/distribution/mod.rs +++ b/xtask/src/policy/distribution/mod.rs @@ -2,7 +2,7 @@ mod contract; mod crate_targets; mod targets; mod version; -mod wheelhouse; +pub(crate) mod wheelhouse; mod workflow; use std::fs; diff --git a/xtask/src/policy/distribution/wheelhouse.rs b/xtask/src/policy/distribution/wheelhouse.rs index 25f0fb388ef..f5924631a1e 100644 --- a/xtask/src/policy/distribution/wheelhouse.rs +++ b/xtask/src/policy/distribution/wheelhouse.rs @@ -315,9 +315,9 @@ fn write_gate_reports( .map_err(|err| format!("failed to create {}: {err}", reports.display()))?; let report_json = reports.join("python-wheelhouse-qualification.json"); let report_md = reports.join("python-wheelhouse-qualification.md"); - fs::write(report_json, format!("{json}\n")) + fs::write(&report_json, format!("{json}\n")) .map_err(|err| format!("failed to write {}: {err}", report_json.display()))?; - fs::write(report_md, markdown) + fs::write(&report_md, markdown) .map_err(|err| format!("failed to write {}: {err}", report_md.display()))?; if receipts.is_dir() { let copy_json = receipts.join("wheelhouse-qualification.json"); From 97e5636d079960803e521e1b33f22c61fcfab7be Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 29 Sep 2026 06:07:50 +0000 Subject: [PATCH 3/6] test(xtask): pin uppercase digest letters and the quoted pip install (#4631) The previous uppercase fixture used only digits, so to_ascii_uppercase could not discriminate. Match the isolated pip invocation as written, including the quoted binary path. Co-authored-by: Steven Zimmerman, CPA --- xtask/src/policy/distribution/wheelhouse.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xtask/src/policy/distribution/wheelhouse.rs b/xtask/src/policy/distribution/wheelhouse.rs index f5924631a1e..d7f780ee77e 100644 --- a/xtask/src/policy/distribution/wheelhouse.rs +++ b/xtask/src/policy/distribution/wheelhouse.rs @@ -845,8 +845,8 @@ mod tests { #[test] fn uppercase_wheel_digest_cannot_pass() -> Result<(), String> { let mut receipt = valid_receipt(); - receipt.rows[0].wheel_sha256 = WHEEL_SHA.to_ascii_uppercase(); - receipt.rows[1].wheel_sha256 = WHEEL_SHA.to_ascii_uppercase(); + receipt.rows[0].wheel_sha256 = + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_ascii_uppercase(); must_reject(receipt, "wheel digest") } @@ -1028,7 +1028,7 @@ mod tests { #[test] fn workflow_installs_from_a_local_wheelhouse_with_isolation_controls() { let text = WORKFLOW_TEXT; - assert!(text.contains("pip install --no-index --find-links")); + assert!(text.contains("install --no-index --find-links")); assert!(text.contains("uv tool install --offline")); assert!(text.contains("PIP_NO_INDEX=1")); assert!(text.contains("UV_OFFLINE=1")); From 86c02bad6d60b62273ff602c8eaa04ffb6fc3c2a Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 29 Sep 2026 06:11:21 +0000 Subject: [PATCH 4/6] fix(xtask): mark wheelhouse qualify as CI-enforced and drop unused include (#4631) The dispatch-only workflow fails the job when the aggregate fails, so the catalog must record ci_enforced. Keep the workflow text include in tests only so non-test builds stay warning-clean. Co-authored-by: Steven Zimmerman, CPA --- xtask/src/command.rs | 2 +- xtask/src/policy/distribution/wheelhouse.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/xtask/src/command.rs b/xtask/src/command.rs index 337a29fc789..cdd30c1be9e 100644 --- a/xtask/src/command.rs +++ b/xtask/src/command.rs @@ -1854,7 +1854,7 @@ pub(crate) fn command_catalog() -> Vec { "non_mutating_check", "target/ripr/reports/python-wheelhouse-qualification.{json,md}", false, - false, + true, "Fail-closed local-wheelhouse aggregate for pip/uv rows: missing, skipped, zero-subject, mismatched, PATH/Cargo, or planted-binary rows cannot pass. Dispatch-only; never publishes.", ), command_entry( diff --git a/xtask/src/policy/distribution/wheelhouse.rs b/xtask/src/policy/distribution/wheelhouse.rs index d7f780ee77e..8221e643a95 100644 --- a/xtask/src/policy/distribution/wheelhouse.rs +++ b/xtask/src/policy/distribution/wheelhouse.rs @@ -12,6 +12,7 @@ use serde::{Deserialize, Serialize}; pub(crate) const POLICY_PATH: &str = "policy/python-wheelhouse-qualification.toml"; pub(crate) const WORKFLOW_PATH: &str = ".github/workflows/python-wheelhouse-qualification.yml"; +#[cfg(test)] const WORKFLOW_TEXT: &str = include_str!("../../../../.github/workflows/python-wheelhouse-qualification.yml"); const POLICY_TEXT: &str = include_str!("../../../../policy/python-wheelhouse-qualification.toml"); From 176cac3708dad42abd59419636c994410790c098 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 29 Sep 2026 06:15:04 +0000 Subject: [PATCH 5/6] fix(xtask): satisfy clippy on wheelhouse matrix checks and workflow pins (#4631) Co-authored-by: Steven Zimmerman, CPA --- xtask/src/policy/distribution/wheelhouse.rs | 27 +++++++++------------ 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/xtask/src/policy/distribution/wheelhouse.rs b/xtask/src/policy/distribution/wheelhouse.rs index 8221e643a95..1c557e62e6e 100644 --- a/xtask/src/policy/distribution/wheelhouse.rs +++ b/xtask/src/policy/distribution/wheelhouse.rs @@ -162,19 +162,16 @@ pub(crate) fn evaluate_wheelhouse( if seen.insert(id.clone(), index).is_some() { reasons.push(format!("duplicate row `{id}`")); } - if row.os != policy.admitted_os || row.arch != policy.admitted_arch { - if row.status == WheelhouseRowStatus::Passed { - reasons.push(format!( - "row `{id}` is outside the admitted {os}/{arch} matrix and cannot pass", - os = policy.admitted_os, - arch = policy.admitted_arch - )); - } + if (row.os != policy.admitted_os || row.arch != policy.admitted_arch) + && row.status == WheelhouseRowStatus::Passed + { + reasons.push(format!( + "row `{id}` is outside the admitted {os}/{arch} matrix and cannot pass", + os = policy.admitted_os, + arch = policy.admitted_arch + )); } - if !policy - .required_clients - .iter() - .any(|client| client == &row.client) + if !policy.required_clients.contains(&row.client) && row.status == WheelhouseRowStatus::Passed { reasons.push(format!( @@ -998,7 +995,7 @@ mod tests { #[test] fn workflow_is_read_only_dispatch_only_and_non_publishing() { let lines = workflow_lines(); - assert!(lines.iter().any(|line| *line == "workflow_dispatch:")); + assert!(lines.contains(&"workflow_dispatch:")); assert!(!lines.iter().any(|line| line.starts_with("pull_request:"))); assert!(!lines.iter().any(|line| line.starts_with("push:"))); assert_eq!( @@ -1015,8 +1012,8 @@ mod tests { .iter() .any(|line| line.contains("persist-credentials: false")) ); - assert!(lines.iter().any(|line| *line == "if-no-files-found: error")); - assert!(lines.iter().any(|line| *line == "retention-days: 5")); + assert!(lines.contains(&"if-no-files-found: error")); + assert!(lines.contains(&"retention-days: 5")); assert!( WORKFLOW_TEXT .contains("actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a") From 4142151d0b42a10ac8a0e1451a6eec6401045c45 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 29 Sep 2026 06:30:51 +0000 Subject: [PATCH 6/6] fix(ci): probe wheelhouse network and checkout honestly (#4631) Replace the cowsay/--no-index stand-in with an independent pypi.org URL probe, record source-checkout reachability from a readable Cargo.toml in the consumer cwd, hash the one staged wheel instead of the first glob, and reject mixed filenames across required passed rows. Route the new workflow, policy, and docs onto the release_surface path pack. Co-authored-by: Steven Zimmerman, CPA --- .../python-wheelhouse-qualification.yml | 13 ++--- docs/PYTHON_WHEELHOUSE_QUALIFICATION.md | 31 ++++++++---- policy/ci-risk-packs.toml | 2 +- xtask/src/policy/distribution/wheelhouse.rs | 50 ++++++++++++++++++- 4 files changed, 78 insertions(+), 18 deletions(-) diff --git a/.github/workflows/python-wheelhouse-qualification.yml b/.github/workflows/python-wheelhouse-qualification.yml index dadc892b6c0..2c5af55dbc9 100644 --- a/.github/workflows/python-wheelhouse-qualification.yml +++ b/.github/workflows/python-wheelhouse-qualification.yml @@ -69,18 +69,19 @@ jobs: - name: Isolated pip and uv wheelhouse installs run: | set -euo pipefail + cd "${CONSUMER_ROOT}" export PIP_NO_INDEX=1 UV_OFFLINE=1 - if python3 -m pip install --no-index cowsay; then network=false; else network=true; fi + if python3 -c "import urllib.request; urllib.request.urlopen('https://pypi.org', timeout=5)"; then network=false; else network=true; fi export PATH="${CONSUMER_ROOT}/venv/bin:${CONSUMER_ROOT}/uv/bin:${DECOY_ROOT}:/usr/bin:/bin" cargo_ok=false; ambient=false; planted=false; source_ok=false if command -v cargo >/dev/null || command -v rustc >/dev/null; then cargo_ok=true; fi if [ -x /usr/bin/ripr ] || [ -x /bin/ripr ]; then ambient=true; fi if [ "$(command -v ripr 2>/dev/null || true)" = "${DECOY_ROOT}/ripr" ] && [ "$(ripr)" = "planted-wrong-path" ]; then planted=true; fi - case ":$PATH:" in *:"${GITHUB_WORKSPACE}":*) source_ok=true;; esac + if test -r "${GITHUB_WORKSPACE}/Cargo.toml"; then source_ok=true; fi shopt -s nullglob wheels=("${WHEELHOUSE}"/*.whl) - if [ ${#wheels[@]} -eq 0 ]; then - echo "no staged wheels; required pip/uv rows stay missing pending #4490" >&2 + if [ ${#wheels[@]} -ne 1 ]; then + echo "need exactly one staged wheel; required pip/uv rows stay missing pending #4490" >&2 exit 0 fi python3 -m venv "${CONSUMER_ROOT}/venv" @@ -92,9 +93,9 @@ jobs: test -x "${pip_bin}" && test "${pip_bin}" != "${DECOY_ROOT}/ripr" test -x "${uv_bin}" && test "${uv_bin}" != "${DECOY_ROOT}/ripr" test "$(command -v ripr)" != "${DECOY_ROOT}/ripr" - python3 - "$pip_bin" "$uv_bin" "$cargo_ok" "$source_ok" "$ambient" "$planted" "$network" <<'PY' + python3 - "$pip_bin" "$uv_bin" "$cargo_ok" "$source_ok" "$ambient" "$planted" "$network" "${wheels[0]}" <<'PY' import hashlib, json, os, pathlib, sys - wheel = next(pathlib.Path(os.environ["WHEELHOUSE"]).glob("*.whl")) + wheel = pathlib.Path(sys.argv[8]) sha = hashlib.sha256(wheel.read_bytes()).hexdigest() root = pathlib.Path(os.environ["QUAL_ROOT"]) / "rows" root.mkdir(parents=True, exist_ok=True) diff --git a/docs/PYTHON_WHEELHOUSE_QUALIFICATION.md b/docs/PYTHON_WHEELHOUSE_QUALIFICATION.md index 5b40b0cbac4..442adea398d 100644 --- a/docs/PYTHON_WHEELHOUSE_QUALIFICATION.md +++ b/docs/PYTHON_WHEELHOUSE_QUALIFICATION.md @@ -18,25 +18,36 @@ Dispatch `.github/workflows/python-wheelhouse-qualification.yml` with: The job checks out that SHA with `contents: read` and `persist-credentials: false`, stages `dist/wheels` or `packaging/python/dist` when present, installs through isolated pip and uv consumers, and retains receipts as an Actions -artifact for 5 days. +artifact for 5 days. Staging must yield exactly one wheel; zero or mixed +filenames leave the required rows missing. The workflow hashes that one staged +path rather than the first glob match. + +Network isolation is an independent `urllib.request.urlopen('https://pypi.org')` +probe after `PIP_NO_INDEX`/`UV_OFFLINE` are set. Source-checkout reachability +is whether `${GITHUB_WORKSPACE}/Cargo.toml` is readable from the consumer +working directory. This lane does not add a sandbox or filesystem unmount, so +those probes typically remain true on GitHub-hosted runners and fail closed. ## Gate `cargo xtask qualify-python-wheelhouse --receipts ` is the authority. A required linux/x86_64 pip or uv row can pass only when it records -exact wheel and payload digests, a nonzero subject count, no Cargo/source -checkout/ambient `ripr` escape, a detected planted wrong-PATH binary, and -network disabled after staging. Failed, `not_run`, unsupported, missing, -zero-subject, or mismatched rows cannot satisfy the aggregate. +exact wheel and payload digests, a matching wheel filename across required +passed rows, a nonzero subject count, no Cargo/source checkout/ambient `ripr` +escape, a detected planted wrong-PATH binary, and network disabled after +staging. Failed, `not_run`, unsupported, missing, zero-subject, or mismatched +rows cannot satisfy the aggregate. -When this candidate has no staged wheels, the required rows stay missing and -the aggregate cannot pass. That is the honest result until #4490 produces a -wheelhouse. Installed-use analysis remains #4626; a wheel install without a -nonzero discriminator still cannot pass. +When this candidate has no staged wheels, or more than one, the required rows +stay missing and the aggregate cannot pass. That is the honest result until +#4490 produces a single wheelhouse artifact. Installed-use analysis remains +#4626; a wheel install without a nonzero discriminator still cannot pass. ## Claim boundary A passing run would establish that the named candidate's selected linux/x86_64 wheel installed from a local wheelhouse through pip and uv with the isolation controls above. It does not establish PyPI publication, a compatibility floor, -a support-tier promotion, or the five-target matrix. +a support-tier promotion, or the five-target matrix. A green pip `--no-index` +install is not network isolation; a PATH that omits the checkout is not a +source-checkout barrier. diff --git a/policy/ci-risk-packs.toml b/policy/ci-risk-packs.toml index eac193ad6ca..a0652a4b706 100644 --- a/policy/ci-risk-packs.toml +++ b/policy/ci-risk-packs.toml @@ -98,7 +98,7 @@ owner = "repo-maintainers" reason = "VS Code extension implementation, package, or tests need editor-loop proof." [risk_pack.release_surface] -paths = ["docs/RELEASE.md", "docs/RELEASE_BINARIES.md", "docs/RELEASE_MARKETPLACE.md", "docs/PUBLISHING.md", ".github/workflows/publish-extension.yml", ".github/workflows/release-server-binaries.yml", "Cargo.toml", "Cargo.lock"] +paths = ["docs/RELEASE.md", "docs/RELEASE_BINARIES.md", "docs/RELEASE_MARKETPLACE.md", "docs/PUBLISHING.md", "docs/PYTHON_WHEELHOUSE_QUALIFICATION.md", ".github/workflows/publish-extension.yml", ".github/workflows/release-server-binaries.yml", ".github/workflows/python-wheelhouse-qualification.yml", "policy/python-wheelhouse-qualification.toml", "Cargo.toml", "Cargo.lock"] required = ["rust", "policy", "security-posture"] advisory = ["coverage"] on_demand = ["release-package", "publish-dry-run", "vsix-package", "extension-marketplace-publish", "server-archive", "python-wheelhouse", "release-readiness-proof"] diff --git a/xtask/src/policy/distribution/wheelhouse.rs b/xtask/src/policy/distribution/wheelhouse.rs index 1c557e62e6e..dc0b636410c 100644 --- a/xtask/src/policy/distribution/wheelhouse.rs +++ b/xtask/src/policy/distribution/wheelhouse.rs @@ -476,6 +476,7 @@ fn mismatched_identity_reasons( required: &BTreeSet, ) -> Vec { let mut reasons = Vec::new(); + let mut wheel_names = BTreeSet::new(); let mut wheel_hashes = BTreeSet::new(); let mut payload_hashes = BTreeSet::new(); for row in &receipt.rows { @@ -483,6 +484,9 @@ fn mismatched_identity_reasons( if !required.contains(&id) || row.status != WheelhouseRowStatus::Passed { continue; } + if !row.wheel_filename.trim().is_empty() { + wheel_names.insert(row.wheel_filename.as_str()); + } if is_content_digest(&row.wheel_sha256) { wheel_hashes.insert(row.wheel_sha256.as_str()); } @@ -490,6 +494,12 @@ fn mismatched_identity_reasons( payload_hashes.insert(row.payload_sha256.as_str()); } } + if wheel_names.len() > 1 { + reasons.push( + "required passed rows record mismatched wheel filenames for the same wheelhouse" + .to_string(), + ); + } if wheel_hashes.len() > 1 { reasons.push( "required passed rows record mismatched wheel digests for the same wheelhouse" @@ -732,6 +742,37 @@ mod tests { must_reject(receipt, "mismatched wheel digests") } + #[test] + fn mixed_wheel_filenames_cannot_pass() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows[1].wheel_filename = "other-client.whl".to_string(); + must_reject(receipt, "mismatched wheel filenames") + } + + #[test] + fn mixed_filenames_on_failed_rows_do_not_trip_the_identity_gate() -> Result<(), String> { + let mut receipt = valid_receipt(); + receipt.rows[1].status = WheelhouseRowStatus::Failed; + receipt.rows[1].wheel_filename = "other-client.whl".to_string(); + let reasons = reasons(receipt)?; + if reasons + .iter() + .any(|reason| reason.contains("mismatched wheel filenames")) + { + return Err( + "failed-row filename mismatch must not be treated as identity drift".to_string(), + ); + } + if reasons + .iter() + .any(|reason| reason.contains("required row `uv:linux:x86_64`")) + { + Ok(()) + } else { + Err(format!("expected a required-row failure, got {reasons:#?}")) + } + } + #[test] fn publication_authority_cannot_pass() -> Result<(), String> { let mut receipt = valid_receipt(); @@ -1037,7 +1078,14 @@ mod tests { assert!(text.contains(r#"= "${DECOY_ROOT}/ripr""#)); assert!(text.contains("/usr/bin/ripr")); assert!(text.contains("cargo xtask qualify-python-wheelhouse --receipts")); - assert!(text.contains("python3 -m pip install --no-index cowsay")); + assert!(text.contains("urllib.request.urlopen('https://pypi.org'")); + assert!(text.contains(r#"cd "${CONSUMER_ROOT}""#)); + assert!(text.contains(r#"test -r "${GITHUB_WORKSPACE}/Cargo.toml""#)); + assert!(text.contains("${#wheels[@]} -ne 1")); + assert!(text.contains(r#""${wheels[0]}""#)); + assert!(text.contains("pathlib.Path(sys.argv[8])")); + assert!(!text.contains("cowsay")); + assert!(!text.contains(".glob(\"*.whl\")")); assert!(text.contains(r#""status": "failed""#)); assert!(text.contains(r#""subject_count": 0"#)); assert!(text.contains("flag(3)"));