Skip to content

fix(coverage): materialize trusted uv lock dependencies - #743

Draft
seonghobae wants to merge 20 commits into
mainfrom
fix/trusted-uv-lock-coverage-clean
Draft

fix(coverage): materialize trusted uv lock dependencies#743
seonghobae wants to merge 20 commits into
mainfrom
fix/trusted-uv-lock-coverage-clean

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

What

Extend the central base-commit Python dependency materializer so repositories that rely on uv.lock can produce an offline, fully hash-pinned third-party dependency closure even when a GitHub runner does not already expose the required trusted uv executable.

This clean replacement supersedes stacked bootstrap PR #737 and contains the canonical materializer, focused behavioral and static-security contracts, an explicit 100% branch-coverage gate, and the doctoring design record.

Why

Repositories such as BandScope can pass their own CI but fail the central OpenCode coverage sandbox when the validated base tree contains uv.lock dependency contracts and the coverage runner cannot export them. Missing environment materialization then appears as a misleading source-review failure rather than a dependency-provisioning defect.

Trust boundary

  • Read uv.lock and sibling pyproject.toml only from the exact validated 40-character base commit SHA.
  • Download one fixed official Astral uv archive from a literal HTTPS URL at the network sink.
  • Install one no-proxy opener and reject every redirect before urllib creates a target request.
  • Validate the response origin as HTTPS, releases.astral.sh, and only an absent or explicit default port 443; malformed and nondefault ports fail closed.
  • Bound the download and extracted executable sizes.
  • Verify the archive SHA-256, exact tar member name, regular-file type, complete member length, write mode 0755, and exact reported uv version.
  • Run uv export --frozen --offline --no-cache --no-progress --color never --no-emit-project --no-editable in an isolated temporary project.
  • Provide only fixed PATH, isolated HOME/TMPDIR/XDG directories, UV_NO_ENV_FILE=1, and UV_PYTHON_DOWNLOADS=never; ambient runner variables do not reach the exporter.
  • Keep reconstructed project metadata discovery enabled; --no-config is forbidden because it would also disable the authoritative pyproject.toml input.
  • Reject every nonempty export unless every logical line is a normalized exact package == pin followed only by complete SHA-256 hashes. Option lines, direct/local references, non-SHA-256 algorithms, and truncated digests fail closed.
  • Never expose pull-request-mutable dependency metadata to the networked image-build stage.

Modular boundary

Nested standalone modules are supported because every sibling pyproject.toml/uv.lock pair is read and exported independently from the immutable base revision. True uv workspaces that require additional member metadata are not silently approximated; they remain fail-closed until the exact-base workspace reconstruction contract tracked in #750 is implemented.

TDD and verification contracts

The nine-file change provides permanent evidence for:

  • exact-base-revision reads and path/revision validation;
  • fixed literal URL selection, no dynamic urllib.request.Request, a cached no-proxy/no-redirect opener, and redirect rejection before follow;
  • fixed HTTPS scheme/host validation, absent-or-443 port acceptance, and rejection of malformed or nondefault ports;
  • bounded reads, archive checksum, tar member/type/size, executable mode, and exact version checks;
  • frozen, offline, cacheless, noninteractive, project-excluding export arguments;
  • isolated environment directories and exclusion of arbitrary ambient configuration;
  • no regression to --no-config or UV_NO_CONFIG;
  • orphan-lock and empty-dependency behavior;
  • exporter and process failures that remain fatal;
  • normalized exact pins with complete SHA-256 hashes for all nonempty output;
  • pyproject.toml enables branch measurement and fail_under = 100; and
  • 100% statement/branch coverage and production docstrings for the changed materializer.

The exact current head must pass all central security, coverage, workflow-contract, independent-review, and branch-protection gates after #731 establishes the repaired default-branch baseline.

Standards traceability

docs/doctoring/trusted-uv-lock-materialization.md records the immutable-source, fixed-origin, redirect, default-port, hash, isolated-export, modularity, and verification contracts with APA 7th references to official Astral uv documentation, RFC 3986, and approved SLSA 1.2 materials. The implementation follows those controls without claiming formal SLSA conformance.

Scope

Exactly nine files change:

  • docs/doctoring/trusted-uv-lock-materialization.md
  • pyproject.toml
  • scripts/ci/materialize_base_python_requirements.py
  • tests/test_materialize_base_python_requirements.py
  • tests/test_materialize_uv_export_hash_contract.py
  • tests/test_trusted_uv_download_contract.py
  • tests/test_uv_export_isolation_contract.py
  • tests/test_uv_redirect_and_coverage_contract.py
  • tests/test_uv_redirect_boundary.py

Sequencing

This PR remains draft until the central baseline repair #731 lands. It will then be updated against the repaired main, marked ready, re-reviewed on its exact head, and merged only after required current-head evidence succeeds.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@seonghobae, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 1 minute

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9bec3c12-a837-4407-9330-842597606fe1

📥 Commits

Reviewing files that changed from the base of the PR and between 3f65dbe and 3a15594.

📒 Files selected for processing (9)
  • docs/doctoring/trusted-uv-lock-materialization.md
  • pyproject.toml
  • scripts/ci/materialize_base_python_requirements.py
  • tests/test_materialize_base_python_requirements.py
  • tests/test_materialize_uv_export_hash_contract.py
  • tests/test_trusted_uv_download_contract.py
  • tests/test_uv_export_isolation_contract.py
  • tests/test_uv_redirect_and_coverage_contract.py
  • tests/test_uv_redirect_boundary.py

Comment @coderabbitai help to get the list of available commands.

Comment thread scripts/ci/materialize_base_python_requirements.py Fixed

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

Please review exact current head 2ef7a3661d26aa17636fc562f51531993c21313b. Focus on the trusted-download boundary, isolated uv export environment, strict exact-package/SHA-256 output validation, two-pass immutable-tree orphan detection, fail-closed tracked-metadata read errors, 100% branch/docstring expectations, and the nested-standalone versus true-workspace MSA boundary. This PR remains draft and must not be approved for merge until #731 lands and current-head required checks succeed.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

expected='2ef7a3661d26aa17636fc562f51531993c21313b'
actual="$(git rev-parse HEAD)"
printf 'HEAD=%s\nEXPECTED=%s\n' "$actual" "$expected"
git diff-tree --no-commit-id --name-status -r "$expected"
printf '\n--- IMPLEMENTATION OUTLINE ---\n'
ast-grep outline scripts/ci/materialize_base_python_requirements.py --items all --view expanded
printf '\n--- TEST OUTLINES ---\n'
for f in \
  tests/test_materialize_base_python_requirements.py \
  tests/test_materialize_uv_export_hash_contract.py \
  tests/test_trusted_uv_download_contract.py \
  tests/test_uv_export_isolation_contract.py
do
  printf '\n### %s ###\n' "$f"
  ast-grep outline "$f" --items all --view expanded
done
printf '\n--- IMPLEMENTATION ---\n'
cat -n scripts/ci/materialize_base_python_requirements.py
printf '\n--- FOCUSED TESTS ---\n'
for f in \
  tests/test_materialize_base_python_requirements.py \
  tests/test_materialize_uv_export_hash_contract.py \
  tests/test_trusted_uv_download_contract.py \
  tests/test_uv_export_isolation_contract.py
do
  printf '\n### %s ###\n' "$f"
  cat -n "$f"
done
printf '\n--- DESIGN RECORD ---\n'
cat -n docs/doctoring/trusted-uv-lock-materialization.md

Length of output: 81216


🏁 Script executed:

#!/bin/bash
set -euo pipefail

head='2ef7a3661d26aa17636fc562f51531993c21313b'
printf '%s\n' '--- REF AND MERGE-BASE DISCOVERY ---'
git remote -v
git branch -a --contains "$head" || true
for ref in origin/main origin/master main master; do
  if git rev-parse --verify --quiet "$ref" >/dev/null; then
    base="$(git merge-base "$ref" "$head")"
    printf 'REF=%s MERGE_BASE=%s\n' "$ref" "$base"
    git diff --name-status "$base" "$head"
  fi
done

printf '%s\n' '--- PULL REQUEST METADATA ---'
gh pr view 743 --repo ContextualWisdomLab/.github --json baseRefName,baseRefOid,headRefName,headRefOid,isDraft,state,mergeStateStatus,statusCheckRollup

printf '%s\n' '--- REDIRECT AND OUTPUT-VALIDATION CALL SITES ---'
rg -n -C 4 --glob '*.py' \
  'geturl\(\)|urlparse\(|TRUSTED_UV_ARCHIVE_URL|_is_fully_hash_pinned_requirement|UV_EXACT_REQUIREMENT_RE|UV_SHA256_HASH_RE' \
  scripts tests

printf '%s\n' '--- QUALITY CONFIGURATION CANDIDATES ---'
fd -H -t f '^(pyproject\.toml|pytest\.ini|setup\.cfg|tox\.ini|\.coveragerc|ruff\.toml)$' . \
  -E .git -E node_modules -E dist -E build \
  -x sh -c 'printf "\n### %s ###\n" "$1"; cat -n "$1"' sh {}

printf '%s\n' '--- DOCSTRING AND COVERAGE REFERENCES ---'
rg -n -C 3 --hidden \
  '(branch\s*=\s*true|--cov-branch|fail_under|docstring|pydocstyle|D[0-9]{3}|materialize_base_python_requirements)' \
  -g '!**/.git/**' -g '!**/node_modules/**' -g '!**/dist/**' -g '!**/build/**' .

Length of output: 109425


@seonghobae Review completed for exact head 2ef7a3661d26aa17636fc562f51531993c21313b.

I found two blockers.

  1. Medium — The redirect check does not enforce the complete fixed HTTPS origin.
    In scripts/ci/materialize_base_python_requirements.py, Line 146 checks only scheme and hostname. It accepts https://releases.astral.sh:444/.... A URL origin includes the port. This permits a redirect to a different service endpoint while the stated contract requires the fixed Astral HTTPS origin.

    Reject a final URL unless its port is absent or 443. Add a regression test for a redirect to https://releases.astral.sh:444/....

  2. Medium — The stated 100% branch-coverage contract is not enforced.
    pyproject.toml, Lines 17-23, configures 100% statement coverage but does not set branch = true. The inspected coverage invocation also does not include --branch. Therefore, the requirement in docs/doctoring/trusted-uv-lock-materialization.md, Line 108, for 100% statement and branch coverage is not measurable or enforced.

    Enable branch coverage in the repository coverage configuration or in the trusted coverage command. Then add branch tests until the 100% threshold passes.

The reviewed implementation otherwise matches the requested boundaries:

  • Base-tree inventory and exact-base git show reads are present.
  • Orphan detection uses the first regular-blob inventory pass.
  • A read failure for an inventoried pyproject.toml propagates as fatal.
  • The uv export environment is allowlisted and isolated.
  • --no-config and UV_NO_CONFIG are absent.
  • Nonempty export output requires exact pins and complete SHA-256 hashes.
  • Nested standalone pairs are handled independently.
  • True workspace reconstruction remains fail-closed and documented.

I did not execute repository tests because the review sandbox prohibits execution of repository code. Pull request #743 is still draft and blocked with queued checks. It must not be approved until #731 lands and required checks pass on the updated current head.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Comment on lines +140 to +144
with urllib.request.urlopen( # nosec B310 -- literal HTTPS URL plus SHA pin
"https://releases.astral.sh/github/uv/releases/download/0.12.1/"
"uv-x86_64-unknown-linux-gnu.tar.gz",
timeout=TRUSTED_UV_DOWNLOAD_TIMEOUT_SECONDS,
) as response:

Copy link
Copy Markdown
Contributor Author

Addressed both exact-head CodeRabbit blockers in 3a15594b9a5085fcbac002471c8f532ac130e40f.

  • The downloader now rejects malformed ports and every nondefault port even when scheme and hostname match; only an absent port or explicit 443 is accepted. Existing no-proxy and pre-follow redirect rejection remain intact.
  • pyproject.toml now enables branch measurement with fail_under = 100, and a permanent contract test pins both settings.
  • Regression tests cover port 444, malformed ports, explicit 443, and the coverage configuration. Doctoring and the nine-file PR contract now record the fixed-origin and branch-evidence boundaries.

@coderabbitai review
@opencode-agent @cwl-noema-review Please independently review exact head 3a15594b9a5085fcbac002471c8f532ac130e40f. Submit APPROVE only after exact-head workflows prove 100% statement/branch coverage, complete docstrings, and no remaining trust-boundary defect.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

expected='3a15594b9a5085fcbac002471c8f532ac130e40f'
actual="$(git rev-parse HEAD)"
printf 'HEAD=%s\nEXPECTED=%s\n' "$actual" "$expected"
if [ "$actual" != "$expected" ]; then
  printf 'ERROR: checked-out HEAD does not match requested commit.\n' >&2
  exit 2
fi

printf '\n--- PR METADATA AND CHECKS ---\n'
gh pr view 743 --repo ContextualWisdomLab/.github \
  --json isDraft,state,mergeStateStatus,baseRefName,baseRefOid,headRefName,headRefOid,statusCheckRollup

printf '\n--- DIFF FROM PRIOR REVIEWED HEAD ---\n'
git diff --find-renames --find-copies --stat \
  2ef7a3661d26aa17636fc562f51531993c21313b "$expected"
git diff --find-renames --find-copies --unified=80 \
  2ef7a3661d26aa17636fc562f51531993c21313b "$expected" -- \
  scripts/ci/materialize_base_python_requirements.py \
  pyproject.toml \
  tests \
  docs/doctoring/trusted-uv-lock-materialization.md

printf '\n--- SOURCE OUTLINE ---\n'
ast-grep outline scripts/ci/materialize_base_python_requirements.py --items all --view expanded

printf '\n--- URL VALIDATION AND DOWNLOAD BOUNDARY ---\n'
rg -n -C 12 --glob '*.py' \
  'urlparse\(|\.port\b|geturl\(\)|TRUSTED_UV_ARCHIVE_URL|build_opener|HTTPRedirectHandler|ProxyHandler|urlopen\(|Request\(' \
  scripts tests

printf '\n--- COVERAGE CONFIGURATION AND CONTRACTS ---\n'
cat -n pyproject.toml
rg -n -C 8 --glob '*.py' \
  '(branch\s*=\s*true|fail_under\s*=\s*100|coverage|port 444|:444|malformed|explicit.*443|default.*port)' \
  tests

printf '\n--- DOCSTRING STATIC CHECK ---\n'
python3 - <<'PY'
import ast
from pathlib import Path
path = Path("scripts/ci/materialize_base_python_requirements.py")
tree = ast.parse(path.read_text(encoding="utf-8"))
missing = []
for node in ast.walk(tree):
    if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):
        if not ast.get_docstring(node):
            missing.append((type(node).__name__, node.name, node.lineno))
print("missing_docstrings=", missing)
PY

printf '\n--- RELEVANT DOCUMENTATION ---\n'
rg -n -C 7 \
  '(origin|port|redirect|branch coverage|100%|workspace|nested standalone)' \
  docs/doctoring/trusted-uv-lock-materialization.md

Length of output: 202609


🏁 Script executed:

#!/bin/bash
set -euo pipefail

expected='3a15594b9a5085fcbac002471c8f532ac130e40f'
test "$(git rev-parse HEAD)" = "$expected"

printf '%s\n' '--- PR BASE, HEAD, AND DECLARED FILE SET ---'
gh pr view 743 --repo ContextualWisdomLab/.github \
  --json baseRefOid,headRefOid,isDraft,state,mergeStateStatus \
  --jq '{baseRefOid,headRefOid,isDraft,state,mergeStateStatus}'
base="$(gh pr view 743 --repo ContextualWisdomLab/.github --json baseRefOid --jq .baseRefOid)"
git diff --name-status "$base" "$expected"

printf '%s\n' '--- IMPLEMENTATION: TRUSTED DOWNLOAD ---'
rg -n -C 30 \
  '^def _download_trusted_uv_archive|^def _install_trusted_uv|^class .*Redirect|^def .*opener|urlparse\(|parsed\.port|\.hostname|\.scheme|urlopen\(' \
  scripts/ci/materialize_base_python_requirements.py

printf '%s\n' '--- IMPLEMENTATION: UV EXPORT ISOLATION AND VALIDATION ---'
rg -n -C 20 \
  '^def _run_uv_export|^def _export_uv_lock|UV_NO_ENV_FILE|UV_PYTHON_DOWNLOADS|XDG_|--no-config|--frozen|--offline|--no-cache|_is_fully_hash_pinned_requirement|UV_EXACT_REQUIREMENT_RE|UV_SHA256_HASH_RE' \
  scripts/ci/materialize_base_python_requirements.py

printf '%s\n' '--- COVERAGE CONFIGURATION ---'
sed -n '1,80p' pyproject.toml

printf '%s\n' '--- NEW REGRESSION CONTRACT ---'
cat -n tests/test_uv_redirect_and_coverage_contract.py

printf '%s\n' '--- REDIRECT BOUNDARY TESTS ---'
cat -n tests/test_uv_redirect_boundary.py

printf '%s\n' '--- EXACT-HEAD CHECK RUNS ---'
gh api \
  'repos/ContextualWisdomLab/.github/commits/3a15594b9a5085fcbac002471c8f532ac130e40f/check-runs?per_page=100' \
  --jq '.check_runs[] | [.name, .status, (.conclusion // "PENDING"), .details_url] | `@tsv`'

printf '%s\n' '--- EXACT-HEAD WORKFLOW RUNS ---'
gh run list --repo ContextualWisdomLab/.github \
  --commit "$expected" --limit 100 \
  --json databaseId,name,status,conclusion,event,workflowName,url \
  --jq '.[] | [.databaseId, .workflowName, .name, .event, .status, (.conclusion // "PENDING"), .url] | `@tsv`'

Length of output: 33277


@seonghobae Review completed for exact head 3a15594b9a5085fcbac002471c8f532ac130e40f.

The two prior blockers are resolved.

  • The downloader now rejects malformed ports and nondefault ports. It accepts only an absent port or port 443 after it validates the HTTPS scheme and releases.astral.sh host.
  • The regression contract covers port 444, a malformed port, and explicit port 443.
  • pyproject.toml now enables branch measurement with branch = true and enforces fail_under = 100.
  • The coverage contract test checks both settings.
  • Static inspection found no missing docstrings in scripts/ci/materialize_base_python_requirements.py.
  • The exact PR diff contains the declared nine files.
  • I found no additional source-level defect in the reviewed trusted-download boundary, isolated uv export environment, strict export validation, immutable-tree orphan handling, or standalone-module/workspace boundary.

I did not approve the PR. It remains a draft. Its merge state is BLOCKED. All observed exact-head workflows are queued. Approval must wait for #731, an updated exact head if required, and successful required current-head checks that prove the coverage and docstring gates.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants