Skip to content

fix(python-security-analysis): detect repo state instead of hardcoding uv sync/run --frozen - #158

Merged
williaby merged 4 commits into
mainfrom
chore/python-security-analysis-detect-state
May 25, 2026
Merged

williaby merged 4 commits into
mainfrom
chore/python-security-analysis-detect-state

Conversation

@williaby

@williaby williaby commented May 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Applies the detect-state pattern from PR #156 (python-compatibility.yml) and PR #157 (python-fips-compatibility.yml) to both jobs in python-security-analysis.yml. Repairs Security Analysis across 6 uv repos and surfaces an actionable error on the 4 Poetry repos being migrated.

After review (#158 comment), restructured to mirror the proven SonarCloud-safe pattern from python-compatibility.yml: split install steps into uv-locked / uv-no-lock variants, expose literal --frozen on the Bandit uv run step, and use inline NOSONAR(S8541,S8544) only on the uv-no-lock install (where no uv.lock exists by design). See docs/sonarcloud-nosonar-patterns.md for the empirical NOSONAR placement rules.

Root cause

Both codeql and python-security jobs hardcoded uv sync --frozen / uv run --frozen, crashing on:

Caller state Symptom
No pyproject.toml uv errors with no context
uv repo without uv.lock --frozen requires uv.lock
Poetry repo uv cannot read poetry projects

Fix

Detect-state step added to both codeql and python-security jobs. Logic identical to PR #156 / #157.

State Behavior
skip No pyproject.toml. Step notice + skip uv calls.
uv-locked uv sync --frozen $NO_BUILD_FLAG (literal --frozen, no NOSONAR needed for S8544)
uv-no-lock uv sync $NO_BUILD_FLAG # NOSONAR(S8541,S8544): ... (single-line run: so inline NOSONAR is honored)
poetry-not-supported Fails fast with actionable error pointing at migration issues

Bandit Static Analysis step: literal uv run --frozen $NO_BUILD_FLAG bandit ... with preceding-line # NOSONAR(S8541). No FROZEN_FLAG env indirection (SonarCloud cannot follow it; see PR #157's findings).

Notes:

  • codeql install uses --no-dev, python-security (Bandit) uses --all-extras. Both preserved.
  • Detect-state block is duplicated across both jobs by GHA design (each job runs on its own runner). Both blocks now carry reciprocal "keep in sync" comments.

Affected downstream repos (10)

Outcome Repos
Repaired (6) audio-processor, dna, fragrance-rater, image-preprocessing-detector, python-libs, rag-processor
Still failing (intentional, awaits migration) (4) PromptCraft (#328), ledgerbase (#147), data_ingestor (#38), pp-security-master (#38)

Test plan

  • Pre-commit passes locally
  • SonarCloud Quality Gate: OK (Critical findings resolved by restructure in commit 774408d)
  • After merge, spot-check 2 @main callers (e.g., audio-processor, dna): confirm Security Analysis succeeds
  • Spot-check 1 Poetry repo: confirm new actionable error appears

Reference: docs/audits/cve-scan-coverage-2026-05-25.md (CI Repair Sprint).

Related: #155, #156, #157.

Generated with Claude Code

Copilot AI review requested due to automatic review settings May 25, 2026 20:33
@coderabbitai

coderabbitai Bot commented May 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@williaby, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 4 minutes and 6 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

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.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4a76f0dd-097e-4db8-b022-2d62c673f091

📥 Commits

Reviewing files that changed from the base of the PR and between 8f6d040 and 2b6c48e.

📒 Files selected for processing (1)
  • .github/workflows/python-security-analysis.yml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/python-security-analysis-detect-state

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copilot AI 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.

Pull request overview

Updates the org reusable workflow python-security-analysis.yml to detect the caller repository state at runtime, so uv-based installs and scans do not assume pyproject.toml and uv.lock always exist.

Changes:

  • Add a repo-state detection step to both the CodeQL and Bandit jobs to classify callers as skip, uv-locked, uv-no-lock, or poetry-not-supported.
  • Collapse uv install commands to a single step per job by computing a FROZEN_FLAG env var instead of hardcoding --frozen.
  • Gate CodeQL init/build/analyze, Bandit run, and artifact upload based on the detected repo state.

Comment on lines +154 to +164
echo "state=skip" >> $GITHUB_OUTPUT
echo "::notice::No pyproject.toml found at repo root; CodeQL analysis will be skipped. Remove the python-security-analysis.yml caller from this repo if it does not need Python security scanning."
elif [ -f poetry.lock ] || grep -qE '^\[tool\.poetry(\.|])' pyproject.toml; then
echo "state=poetry-not-supported" >> $GITHUB_OUTPUT
echo "::error::This repo uses Poetry. The python-security-analysis.yml reusable workflow is uv-only by org policy. Convert this repo to uv before re-enabling Python security analysis."
exit 1
elif [ -f uv.lock ]; then
echo "state=uv-locked" >> $GITHUB_OUTPUT
echo "Detected: uv with lockfile"
else
echo "state=uv-no-lock" >> $GITHUB_OUTPUT
Comment on lines +160 to +166
elif [ -f uv.lock ]; then
echo "state=uv-locked" >> $GITHUB_OUTPUT
echo "Detected: uv with lockfile"
else
echo "state=uv-no-lock" >> $GITHUB_OUTPUT
echo "Detected: uv without lockfile (PEP 621 pyproject.toml only); will sync without --frozen"
fi
Comment on lines +273 to +283
echo "state=skip" >> $GITHUB_OUTPUT
echo "::notice::No pyproject.toml found at repo root; Bandit SAST will be skipped. Remove the python-security-analysis.yml caller from this repo if it does not need Python security scanning."
elif [ -f poetry.lock ] || grep -qE '^\[tool\.poetry(\.|])' pyproject.toml; then
echo "state=poetry-not-supported" >> $GITHUB_OUTPUT
echo "::error::This repo uses Poetry. The python-security-analysis.yml reusable workflow is uv-only by org policy. Convert this repo to uv before re-enabling Python security analysis."
exit 1
elif [ -f uv.lock ]; then
echo "state=uv-locked" >> $GITHUB_OUTPUT
echo "Detected: uv with lockfile"
else
echo "state=uv-no-lock" >> $GITHUB_OUTPUT
Comment on lines +143 to +150
# Detect the repo state before attempting uv sync. The reusable workflow is uv-only
# by org policy (poetry repos are being converted to uv in separate work), but it is
# still called by some repos that don't have a pyproject.toml (template / docs-only
# forks like DeQA-Doc) and by uv-managed repos that haven't yet committed a uv.lock.
# Hardcoding `uv sync --frozen` failed for both categories. Auto-detection skips
# cleanly when pyproject is absent and drops --frozen when no lockfile exists yet.
# Poetry repos are explicitly rejected with an actionable error.
- name: Detect repo state
Comment on lines +267 to +270
# Detect repo state. Same logic as the codeql job above; each job runs
# on its own runner so the detect step must be repeated per job.
- name: Detect repo state
id: detect
@williaby
williaby force-pushed the chore/python-security-analysis-detect-state branch from 31672c6 to 774408d Compare May 25, 2026 21:41
williaby added a commit that referenced this pull request May 25, 2026
…narCloud

Applies the same restructure pattern landed in PR #157 (python-fips) and
PR #158 (python-security-analysis) to python-ci.yml. See
docs/sonarcloud-nosonar-patterns.md for the full background.

Changes across both jobs in python-ci.yml (quality-checks and
matrix-testing):

1. Split Install dependencies steps into uv-locked / uv-no-lock variants.
   uv-locked uses literal uv sync --all-extras --frozen $NO_BUILD_FLAG;
   uv-no-lock carries inline NOSONAR(S8541,S8544) with rationale.

2. Drop FROZEN_FLAG env var from every downstream step in both jobs:
   - Ruff formatter check, Ruff linter, BasedPyright
   - Dead code detection with Vulture
   - Unit / integration / security tests (3 pytest invocations)
   - Combined coverage report (4 coverage invocations)
   - Security scan with Bandit (2 invocations, if/else branches)
   - Dependency vulnerability scan with pip-audit (2 invocations)
   - Matrix test runner

3. Replace every $FROZEN_FLAG with literal --frozen on uv run lines.

4. Add # NOSONAR(S8541) as a preceding bash comment to every uv run line
   in the run: blocks (17 total).

5. Update the echo error-message hint in Ruff formatter check from
   uv run $FROZEN_FLAG to uv run --frozen so the displayed remediation
   command matches what the workflow now executes.

Trade-off: matches sibling design. No new install runtime; the install
step was already running unconditionally on every CI job. Quality
gate should flip to A on new code after re-analysis.

Verified locally: pre-commit clean (yamllint, em-dash, secrets,
commitizen); FROZEN_FLAG completely removed from the file; no empty
env: blocks; indentation preserved across if/else shell branches.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@williaby

Copy link
Copy Markdown
Collaborator Author

PR Review

BUILD FAILING — SonarCloud Quality Gate is ERROR (PR-introduced; passes on main). BRANCH BEHIND — rebase required before merge.

Reviewer status: Copilot was not requested (ruleset gap); CodeRabbit was rate-limited (org out of credits). Only the local agent pipeline and SonarQube produced findings.


Critical (must fix before merge)

  • [SonarQube S8541 + S8544] .github/workflows/python-security-analysis.yml#L312
    Two MAJOR security findings on the Bandit uv run $FROZEN_FLAG $NO_BUILD_FLAG bandit ... line. SonarCloud cannot prove statically that either flag will be non-empty, so it flags both "omitting --no-build" and "using dependencies without locking resolved versions." This is the cause of the Quality Gate ERROR (new_security_rating=3, threshold=1). The two uv sync lines in this same PR carry # NOSONAR S8541; the uv run line does not.
    Fix: add # NOSONAR S8541 to the uv run line, mirroring the convention established in PR feat(workflows): add no-build opt-out input to all reusable workflows #112 and applied on the two install lines.

  • [CI] SonarCloud Code Analysis: FAILURE — PR-introduced. Resolving the two SonarQube findings above will clear the gate.

Important (should fix)

  • [Maintenance] .github/workflows/python-security-analysis.yml#L140-L176 and L264-L293: detect-state step is duplicated byte-for-byte across both jobs. The second copy explains why; the first has no reciprocal pointer. Add a "keep in sync" comment, or extract to a composite action under .github/actions/detect-uv-state/.

  • [PR description vs diff] Body claims the "single-install-step pattern with FROZEN_FLAG env + # NOSONAR S8541" is applied. True for the two uv sync lines, but the Bandit uv run line was missed; that omission is exactly what SonarCloud is now flagging.

Suggested

  • [Defense in depth] The state=skip branch silently bypasses CodeQL and Bandit for any caller without a root pyproject.toml. ::notice:: annotations surface but do not mark the run as degraded. Consider ::warning:: or a job-level scanned: true/false output callers can assert on.

Informational

  • # shellcheck disable=SC2086 placement is asymmetric across uv sync (single-line run:, no disable) vs uv run (multi-line block, has disable). Not breaking — actionlint passed — but worth a comment explaining why only the multi-line block needs it.

Recommended order: (1) add NOSONAR to L312 to clear the gate, (2) rebase on main, (3) optional: add the sync-pointer comment.

🤖 Generated with Claude Code

@williaby

Copy link
Copy Markdown
Collaborator Author

PR Fix: Resolved

Applied the structural fix pattern proven on PR #157. SonarCloud Quality Gate: OK (Security Rating A on new code). All 2 open MAJOR vulnerabilities resolved.

Commit (774408d) — fix(quality): restructure python-security-analysis to expose literal --frozen for SonarCloud

Changes:

  • CodeQL job install: Split into uv-locked / uv-no-lock variants. uv-locked uses literal uv sync --no-dev --frozen $NO_BUILD_FLAG; uv-no-lock carries inline # NOSONAR(S8541,S8544) with rationale.
  • Bandit job install: Same split.
  • Bandit Static Analysis step: Drop FROZEN_FLAG env, use literal uv run --frozen $NO_BUILD_FLAG bandit with preceding-line # NOSONAR(S8541). Added shell: bash explicitly.

Final state: CI 20 SUCCESS / 4 SKIPPED / 0 FAILURE; SonarCloud 0 open vulnerabilities; branch rebased on main. Ready for merge review.

See docs/sonarcloud-nosonar-patterns.md (PR #157, merged) for the team-level background on which NOSONAR placements SonarCloud honors and which it doesn't.

Generated with Claude Code

williaby added a commit that referenced this pull request May 25, 2026
…-frozen (#159)

* fix(python-ci): detect repo state instead of hardcoding uv sync/run --frozen

Same pattern as PR #156 (python-compatibility.yml) and #157 (python-fips-compatibility.yml).

Root cause: the quality-checks and matrix-testing jobs ran `uv sync --all-extras --frozen` and `uv run --frozen` unconditionally, crashing on (1) repos without pyproject.toml, (2) uv-managed repos without uv.lock yet, and (3) Poetry repos that should not be served by this uv-only workflow. Added a Detect repo state step in both jobs that emits one of four states (skip, uv-locked, uv-no-lock, poetry-not-supported) and gated every install and test step on that state. uv run sites now read FROZEN_FLAG from the detect step so the --frozen flag is dropped only when no lockfile exists. The Validate source layout precondition (per project_python_ci_audit_2026_05.md) is preserved unchanged. The llm-governance job does not use uv and was not modified.

Impact: repairs CI across the uv repos in the fleet. The 4 Poetry repos
(PromptCraft, ledgerbase, data_ingestor, pp-security-master) surface the
new actionable error directing to their migration tracking issues
(williaby/PromptCraft#328, williaby/ledgerbase#147,
williaby/data_ingestor#38, ByronWilliamsCPA/pp-security-master#38).

Reference: docs/audits/cve-scan-coverage-2026-05-25.md (CI Repair Sprint).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* refactor(python-ci): collapse install steps via FROZEN_FLAG env + NOSONAR S8541

Follow up to PR #156 team feedback. Step-level branching for uv-locked vs
uv-no-lock just shuffles the S8541 finding to the without-frozen branch
(allowing builds is intentional and configurable via the no-build input).
Collapsing to a single Install dependencies step with FROZEN_FLAG env var
indirection plus # NOSONAR S8541 suppression matches the established
convention in python-mutation.yml (lines 159-169) and halves the YAML
maintenance surface.

Applied to both quality-checks and matrix-testing jobs. The 9 downstream
uv run steps already used the FROZEN_FLAG pattern; only the 2 install
steps needed collapsing.

Layout-precondition hardening from project_python_ci_audit_2026_05 is
preserved untouched.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

* fix(quality): restructure python-ci to expose literal --frozen for SonarCloud

Applies the same restructure pattern landed in PR #157 (python-fips) and
PR #158 (python-security-analysis) to python-ci.yml. See
docs/sonarcloud-nosonar-patterns.md for the full background.

Changes across both jobs in python-ci.yml (quality-checks and
matrix-testing):

1. Split Install dependencies steps into uv-locked / uv-no-lock variants.
   uv-locked uses literal uv sync --all-extras --frozen $NO_BUILD_FLAG;
   uv-no-lock carries inline NOSONAR(S8541,S8544) with rationale.

2. Drop FROZEN_FLAG env var from every downstream step in both jobs:
   - Ruff formatter check, Ruff linter, BasedPyright
   - Dead code detection with Vulture
   - Unit / integration / security tests (3 pytest invocations)
   - Combined coverage report (4 coverage invocations)
   - Security scan with Bandit (2 invocations, if/else branches)
   - Dependency vulnerability scan with pip-audit (2 invocations)
   - Matrix test runner

3. Replace every $FROZEN_FLAG with literal --frozen on uv run lines.

4. Add # NOSONAR(S8541) as a preceding bash comment to every uv run line
   in the run: blocks (17 total).

5. Update the echo error-message hint in Ruff formatter check from
   uv run $FROZEN_FLAG to uv run --frozen so the displayed remediation
   command matches what the workflow now executes.

Trade-off: matches sibling design. No new install runtime; the install
step was already running unconditionally on every CI job. Quality
gate should flip to A on new code after re-analysis.

Verified locally: pre-commit clean (yamllint, em-dash, secrets,
commitizen); FROZEN_FLAG completely removed from the file; no empty
env: blocks; indentation preserved across if/else shell branches.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
williaby and others added 4 commits May 25, 2026 14:50
…g uv sync/run --frozen

Same pattern as PR #156 (python-compatibility.yml) and #157 (python-fips-compatibility.yml).

Root cause: codeql and python-security (Bandit) jobs hardcoded
`uv sync --frozen` and `uv run --frozen`, which failed on three caller
categories: repos without pyproject.toml (DeQA-Doc), uv-managed repos
without uv.lock yet, and Poetry repos (uv cannot parse poetry projects).

Fix: detect-state step + gated install/run steps in both jobs (codeql,
python-security). Each job has its own Detect step because every job
runs on a fresh runner with a fresh checkout. The detect step exits 1
with an actionable error for Poetry repos, prints a job summary notice
when pyproject.toml is absent, and drops --frozen when uv.lock is not
yet present.

Impact: repairs Security Analysis across the uv repos in the fleet. The 4
Poetry repos (PromptCraft, ledgerbase, data_ingestor, pp-security-master)
surface the new actionable error directing to their migration tracking
issues (williaby/PromptCraft#328, williaby/ledgerbase#147,
williaby/data_ingestor#38, ByronWilliamsCPA/pp-security-master#38).

Reference: docs/audits/cve-scan-coverage-2026-05-25.md (CI Repair Sprint).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…nv + NOSONAR S8541

Follow up to PR #156 team feedback. Step-level branching for uv-locked vs
uv-no-lock just shuffles the S8541 finding to the without-frozen branch
(allowing builds is intentional and configurable via the no-build input).
Collapsing to a single Install dependencies step with FROZEN_FLAG env var
indirection plus # NOSONAR S8541 suppression matches the established
convention in python-mutation.yml (lines 159-169) and halves the YAML
maintenance surface.

Applied to both codeql and python-security jobs.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…--frozen for SonarCloud

Applies the same restructure pattern landed in PR #157 (python-fips-
compatibility.yml) to python-security-analysis.yml. See
docs/sonarcloud-nosonar-patterns.md for the full background; the short
version is that SonarCloud cannot follow $FROZEN_FLAG env-var
indirection, and preceding-line NOSONAR(S8541,S8544) inside a `|` block
is not honored.

Changes to both jobs in python-security-analysis.yml:

CodeQL job (lines 169-183):
1. Split Install dependencies into uv-locked / uv-no-lock variants.
   uv-locked uses literal `uv sync --no-dev --frozen $NO_BUILD_FLAG`;
   uv-no-lock carries inline NOSONAR(S8541,S8544) with rationale.

Python SAST (Bandit) job (lines 295-332):
2. Same Install split.
3. Bandit Static Analysis step: drop FROZEN_FLAG env, use literal
   `uv run --frozen $NO_BUILD_FLAG bandit ...` with preceding-line
   NOSONAR(S8541). Add shell: bash explicitly.

Trade-off: adds ~1-2 min of cache-friendly install runtime to the
uv-no-lock path on the CodeQL job; matches sibling design.

Verified locally: pre-commit clean (yamllint, em-dash, secrets);
FROZEN_FLAG completely removed from the file.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…to detect-state block

The python-security job's detect-state block already references the codeql
job ("Same logic as the codeql job above; each job runs on its own
runner..."), but the codeql block had no reciprocal pointer. Adds a
one-line "Mirrored in the python-security job below; keep both blocks in
sync" comment so future edits in either direction surface the duplication
constraint.

Pure comment change; no behavior delta. Pre-commit clean.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@williaby
williaby force-pushed the chore/python-security-analysis-detect-state branch from 774408d to 2b6c48e Compare May 25, 2026 21:52
@williaby

Copy link
Copy Markdown
Collaborator Author

Review supersession + cleanup

My earlier review comment was based on PR HEAD 31672c6 and recommended a simple inline # NOSONAR S8541 on the Bandit uv run line. That recommendation was wrong for that line per docs/sonarcloud-nosonar-patterns.md: inside a run: | block with both flags dynamic, NOSONAR is not honored by SonarCloud's githubactions rule set.

You arrived at the correct fix independently in commit 774408d, mirroring python-compatibility.yml exactly (split install steps + literal --frozen on the run step).

Current state of PR head (after rebase + cleanup push):

  • SonarCloud Quality Gate: OK
  • CI checks: all SUCCESS / SKIPPED
  • New-code-period vulnerabilities: 0 (verified via inNewCodePeriod=true API query; 2 stale entries with line: null are vestigial pointers to earlier head SHAs and not in the current scope)
  • Merge state: rebased onto main, force-pushed with --force-with-lease
  • History: original 3 commits preserved; 1 new commit (2b6c48e) adds the reciprocal "keep in sync" pointer to the CodeQL detect-state block so future edits to either block surface the duplication constraint

Original review findings, final disposition:

Tier Finding Resolution
Critical SonarCloud S8541 + S8544 on uv run $FROZEN_FLAG Resolved in 774408d via restructure to literal --frozen
Critical SonarCloud CI failure Resolved (Quality Gate OK)
Important Duplicated detect-state block with no reciprocal pointer Resolved in 2b6c48e (this push)
Important PR description drift after restructure Updated above
Suggested state=skip defense-in-depth (notice vs warning) Acknowledged; kept as ::notice:: per established pattern
Informational shellcheck disable asymmetry Acknowledged; behavior unchanged after restructure

Ready for merge once you've eyeballed the comment commit.

🤖 Generated with Claude Code

@sonarqubecloud

Copy link
Copy Markdown

@williaby
williaby merged commit 80a226d into main May 25, 2026
24 checks passed
@williaby
williaby deleted the chore/python-security-analysis-detect-state branch May 25, 2026 21:54
williaby added a commit that referenced this pull request May 26, 2026
…njection

Addresses CodeQL alerts #182 and #183 (py/code-injection) and Important findings
from /pr-review on PR #166.

Critical:
- Map steps.extras.outputs.flag to env UV_EXTRAS on both install steps so it
  reaches bash as a variable value rather than being interpolated into the run:
  script via GitHub-side template expansion. Template expansion runs before bash
  sees the line; without env mapping, any shell metacharacters in flag would
  become script text. The flag derives from inputs.extra-dependencies, a
  caller-controlled reusable workflow input.
- Add #CRITICAL / #VERIFY RAD annotations near the install steps documenting
  the env-mapping invariant per project CLAUDE.md.

Pattern alignment with PRs #156/#158/#160:
- Remove NOSONAR(S8541) on the uv-locked install step. The canonical precedent
  keeps the locked install line bare on the rationale that literal --frozen
  makes the line scanner-clean; only the uv-no-lock branch carries NOSONAR.

Polish:
- Strip leading space in FLAG accumulator so the for-loop branch produces the
  same shape as --all-extras and empty branches.
- Escape ] explicitly in poetry detection regex for reader clarity (functional
  no-op; the original was correct ERE).
- Document why the downstream if: conditions use the positive disjunction
  (state == 'uv-locked' || state == 'uv-no-lock') rather than the shorter
  negative form; the negative form would incorrectly run downstream steps when
  steps.detect.outputs.state is empty after an upstream failure.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
williaby added a commit that referenced this pull request May 26, 2026
The previous commit (6fa51ff) removed NOSONAR(S8541) on the uv-locked install
line on the assumption that it would match the #156/#158/#160 precedent of
keeping the locked-install line bare. SonarCloud's Quality Gate on PR #166
empirically rejected this assumption: S8541 (security rating C) fires on this
line regardless of the literal --frozen, because $NO_BUILD_FLAG remains a
dynamic env var.

Why this workflow differs from #156/#158/#160: the install steps in those PRs
likely resolve to a literal --no-build, no flag, or no install at all on the
locked path. python-sonarcloud.yml's locked install step uses dynamic
$NO_BUILD_FLAG (the no-build: workflow input is opt-out by design for PEP 517
consumers like hatchling), so S8541 matches.

Restored the inline NOSONAR(S8541) and updated the header comment to document
the empirical divergence so a future reader does not re-attempt the same
"match precedent" cleanup.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
williaby added a commit that referenced this pull request May 26, 2026
* fix(python-sonarcloud): detect repo state instead of hardcoding uv sync --frozen

Apply the split-install detect-state pattern established by merged PRs #156-#160.
Branches on pyproject.toml + lockfile presence: skip when no pyproject, fail
fast on poetry repos with actionable error, use --frozen on uv-locked repos
and bare uv sync on uv-no-lock repos.

Install step is split into two if-guarded variants so SonarCloud sees literal
--frozen on the uv-locked path (S8544 cannot fire). The uv-no-lock variant
inlines NOSONAR(S8541,S8544) with rationale; uv.lock does not exist by design
on that path. The shell branching on extra-dependencies input is preserved
inside each install step (flattening to step variants would obscure intent).

The pytest run step uses literal --frozen with a preceding-line NOSONAR(S8541)
for --no-build only; this placement is honored when the underlying line is
otherwise clean per python-mutation.yml:159-169 precedent. Downstream analysis
steps (Verify coverage, SonarCloud Scan, Wait, Check Quality Gate, Quality Gate
Summary, Upload coverage artifacts, Fail on Quality Gate) gain detect-state
guards so the skip path exits the job cleanly.

* fix(python-sonarcloud): inline NOSONAR per uv sync line in uv-no-lock install step

Preceding-line NOSONAR(S8541,S8544) inside the uv-no-lock install step's
multi-line run block is not honored by SonarCloud's githubactions rule set
(documented anti-pattern in docs/sonarcloud-nosonar-patterns.md). Moving
suppression to inline trailing comments on each of the three uv sync lines
within the block. The step-level rationale moves into the header comment.

Verified: SonarCloud PR #166 flagged S8541 L293 + S8544 L293, L299, L301 (the
three uv sync lines). Lines 280 and 282 (uv-locked path, literal --frozen)
were NOT flagged, confirming preceding-line NOSONAR(S8541) is honored when
the underlying line is otherwise clean of S8544.

* fix(python-sonarcloud): collapse install steps to single-line for SonarCloud

SonarCloud's githubactions rule set ignores NOSONAR (both preceding-line
and inline) inside multi-line run: | blocks for S8541/S8544. Even with
inline trailing NOSONAR per uv sync line, PR #166 commit bb31ec1 still
flagged 5 vulnerabilities (L296, L302, L304).

Restructure: extract the EXTRA_DEPENDENCIES branching into a separate
Resolve extras flag step that outputs steps.extras.outputs.flag, then
collapse each install step to a single-line run: shape. This is the only
reliable Pattern A position for SonarCloud (per docs/sonarcloud-nosonar-patterns.md).

Two install steps remain (uv-locked, uv-no-lock); the resolve step
unconditionally handles all three extras-modes and outputs a literal
flag string consumed by both.

* fix(python-sonarcloud): map UV_EXTRAS via env to block GHA template injection

Addresses CodeQL alerts #182 and #183 (py/code-injection) and Important findings
from /pr-review on PR #166.

Critical:
- Map steps.extras.outputs.flag to env UV_EXTRAS on both install steps so it
  reaches bash as a variable value rather than being interpolated into the run:
  script via GitHub-side template expansion. Template expansion runs before bash
  sees the line; without env mapping, any shell metacharacters in flag would
  become script text. The flag derives from inputs.extra-dependencies, a
  caller-controlled reusable workflow input.
- Add #CRITICAL / #VERIFY RAD annotations near the install steps documenting
  the env-mapping invariant per project CLAUDE.md.

Pattern alignment with PRs #156/#158/#160:
- Remove NOSONAR(S8541) on the uv-locked install step. The canonical precedent
  keeps the locked install line bare on the rationale that literal --frozen
  makes the line scanner-clean; only the uv-no-lock branch carries NOSONAR.

Polish:
- Strip leading space in FLAG accumulator so the for-loop branch produces the
  same shape as --all-extras and empty branches.
- Escape ] explicitly in poetry detection regex for reader clarity (functional
  no-op; the original was correct ERE).
- Document why the downstream if: conditions use the positive disjunction
  (state == 'uv-locked' || state == 'uv-no-lock') rather than the shorter
  negative form; the negative form would incorrectly run downstream steps when
  steps.detect.outputs.state is empty after an upstream failure.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(python-sonarcloud): re-add NOSONAR(S8541) on uv-locked install line

The previous commit (6fa51ff) removed NOSONAR(S8541) on the uv-locked install
line on the assumption that it would match the #156/#158/#160 precedent of
keeping the locked-install line bare. SonarCloud's Quality Gate on PR #166
empirically rejected this assumption: S8541 (security rating C) fires on this
line regardless of the literal --frozen, because $NO_BUILD_FLAG remains a
dynamic env var.

Why this workflow differs from #156/#158/#160: the install steps in those PRs
likely resolve to a literal --no-build, no flag, or no install at all on the
locked path. python-sonarcloud.yml's locked install step uses dynamic
$NO_BUILD_FLAG (the no-build: workflow input is opt-out by design for PEP 517
consumers like hatchling), so S8541 matches.

Restored the inline NOSONAR(S8541) and updated the header comment to document
the empirical divergence so a future reader does not re-attempt the same
"match precedent" cleanup.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
williaby added a commit that referenced this pull request May 26, 2026
…c --frozen

Apply the split-install detect-state pattern (see python-mutation.yml:159-169
for the original NOSONAR S8541 precedent, and PR #160 / python-release.yml for
the canonical split-install exemplar). Branches on pyproject.toml + lockfile
presence: skip when no pyproject, fail fast on poetry repos with actionable
error, install with literal --frozen on uv-locked path, install without
--frozen on uv-no-lock path (uv sync generates the lockfile).

Downstream pre-commit run step uses literal --frozen because the install
step guaranteed uv.lock exists by then; preceding-line NOSONAR(S8541) is
honored when the underlying line has a literal --frozen token (only the
--no-build flag remains dynamic).

Avoids the documented anti-pattern: dynamic \$FROZEN_FLAG inside run: |
block scalars is not suppressed by preceding-line NOSONAR (empirical
finding from PRs #157/#158/#159; see BWCPA/.github docs/sonarcloud-nosonar-patterns.md).

Verification: actionlint passes (with -shellcheck= per documented
embedded-shellcheck limitation in feedback_actionlint_shellcheck_embed).
williaby added a commit that referenced this pull request May 26, 2026
…c --frozen (#164)

* fix(python-precommit): detect repo state instead of hardcoding uv sync --frozen

Apply the split-install detect-state pattern (see python-mutation.yml:159-169
for the original NOSONAR S8541 precedent, and PR #160 / python-release.yml for
the canonical split-install exemplar). Branches on pyproject.toml + lockfile
presence: skip when no pyproject, fail fast on poetry repos with actionable
error, install with literal --frozen on uv-locked path, install without
--frozen on uv-no-lock path (uv sync generates the lockfile).

Downstream pre-commit run step uses literal --frozen because the install
step guaranteed uv.lock exists by then; preceding-line NOSONAR(S8541) is
honored when the underlying line has a literal --frozen token (only the
--no-build flag remains dynamic).

Avoids the documented anti-pattern: dynamic \$FROZEN_FLAG inside run: |
block scalars is not suppressed by preceding-line NOSONAR (empirical
finding from PRs #157/#158/#159; see BWCPA/.github docs/sonarcloud-nosonar-patterns.md).

Verification: actionlint passes (with -shellcheck= per documented
embedded-shellcheck limitation in feedback_actionlint_shellcheck_embed).

* fix(python-precommit): suppress success summary on skip path

When the detect step sets state=skip (no pyproject.toml), the workflow
should not emit the generic "All pre-commit hooks passed" summary; the
"Skip notice" step already provides the correct user-facing message and
the success line is misleading because nothing ran.

Gate the Pre-Commit Summary step on state != 'skip' so skipped runs
render only the skip notice. Behavior on uv-locked, uv-no-lock, and
poetry-not-supported paths is unchanged.

Flagged independently by Copilot and CodeRabbit on PR #164 review.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
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