Repository navigation
build: run checks with pre-commit - #94
Conversation
Replace flake8 and black with ruff (lint and format, line length 88). Besides the flake8 rules, ruff checks import order, bugbear, pyupgrade, bandit (security) and logging format rules; the findings are fixed, e.g. f-strings in logging calls. Formatting is unchanged. mypy now checks `tests/` too, and the blanket `ignore_missing_imports` is replaced by an override for Connexion 2, which has no type information. The app reads its config and collections through typed helpers in `cloud_registry.utils` (FOCA 0.14's `get_config()` and `get_collection()`), so the `attr-defined` ignores are gone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Remove trailing whitespace and blank lines at the end of files, as the new pre-commit hooks require. Vendored GA4GH specifications are left as published. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Run all static checks with pre-commit, locally on commit and in CI (`pre-commit run --all-files`), with hooks pinned to commits: - pre-commit-hooks: YAML syntax, whitespace, merge conflicts, large files - ruff (lint and format) and mypy (installed dev dependencies) - semgrep with local rules in `.semgrep/`: Flask debug mode in configs, JWT decoding without verification - gitleaks: secrets in the working tree - ast-grep with rules (and rule tests) in `.ast-grep/`: HTTP status codes as strings, Pydantic v1 `.dict()`, untyped FOCA config access in the app f-strings in logging calls are caught by ruff (`G004`). The README describes the setup. Resolves #31 Closes #73 Co-Authored-By: Claude Opus 5.5 <[email protected]>
- CI installs the runtime requirements, which mypy needs for imports - Test `cloud_registry.utils` - gitleaks scans staged changes on commit and the whole checkout in CI (manual stage), so ignored local files do not block commits - ast-grep runs from the dev requirements, so Dependabot updates it; Dependabot also updates the pre-commit hook revisions - Cache pre-commit environments in CI - Document the rules' limits and how to suppress findings Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop an assertion that only holds for the unit test config, and document the manual-stage gitleaks scan that CI runs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR replaces separate lint, format, type-check, and security workflows with a pinned pre-commit pipeline used consistently by developers and CI, adds tested project-specific Semgrep and ast-grep rules, and updates the application to use typed FOCA configuration/collection helpers while modernizing Python code for the new checks. Sequence diagram for CI static checkssequenceDiagram
participant CI as CI workflow
participant Env as Python environment
participant Cache as Hook environment cache
participant PC as pre-commit
participant Hooks as Checks and security hooks
CI->>Env: Install requirements.txt and requirements_dev.txt
CI->>Cache: Restore or save pre-commit environments
CI->>PC: pre-commit run --all-files --show-diff-on-failure
PC->>Hooks: Run ruff, mypy, ast-grep, semgrep and hygiene hooks
CI->>PC: pre-commit run --all-files --hook-stage manual gitleaks-all
PC->>Hooks: Scan the whole checkout for secrets
Sequence diagram for typed FOCA configuration accesssequenceDiagram
participant Controller as Registry controller
participant Utils as cloud_registry.utils
participant FOCA as FOCA configuration API
participant Mongo as MongoDB collection
Controller->>Utils: get_custom_config()
Utils->>FOCA: get_config()
FOCA-->>Utils: Typed base configuration
Utils-->>Controller: CustomConfig
Controller->>Utils: get_collection(name)
Utils->>FOCA: get_collection(db, collection)
FOCA-->>Utils: Collection
Utils-->>Controller: MongoDB collection
Controller->>Mongo: find, find_one, insert_one or replace_one
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #94 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 6 7 +1
Lines 223 225 +2
=========================================
+ Hits 223 225 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path=".semgrep/cloud-registry.yml" line_range="23-24" />
<code_context>
+ tokens of callers
+ patterns:
+ - pattern-either:
+ - pattern: 'jwt.decode(..., options={..., "verify_signature": False, ...}, ...)'
+ - pattern: "jwt.decode(..., verify=False, ...)"
</code_context>
<issue_to_address>
**Unverified JWT calls pass the check**
When code imports `decode` directly from `jwt` and disables signature verification, the patterns only match calls spelled `jwt.decode`, so Semgrep does not report the direct `decode` call and unverified token decoding passes the security check.
Add patterns that also match directly imported `decode` calls with signature verification disabled.
</issue_to_address>
### Comment 2
<location path=".semgrep/cloud-registry.yml" line_range="14" />
<code_context>
+ include:
+ - "/cloud_registry/config.yaml"
+ - "/deployment/**/*.yaml"
+ pattern-regex: (?im)^\s*debug:\s*['"]?(true|yes|on)['"]?\s*$
+ - id: jwt-decode-without-verification
+ languages: [python]
</code_context>
<issue_to_address>
**Debug-enabled configs evade the check**
When an included YAML config sets `debug` to `true`, `yes`, or `on` followed by a trailing comment, the regex requires the truthy value to end the line, so Semgrep misses the setting and passes the debug-enabled config; the Flask debugger’s code-execution risk remains unflagged, including when the app listens on `0.0.0.0`.
Update the regex to allow trailing YAML comments after the truthy value.
Also at `.semgrep/cloud-registry.yml:13`.
</issue_to_address>
### Comment 3
<location path="docs/api/requirements.txt" line_range="4" />
<code_context>
Sphinx==7.2.6
readthedocs-sphinx-ext==2.2.3
sphinx-rtd-theme==1.3.0
-toml==0.10.0
\ No newline at end of file
+toml==0.10.0
</code_context>
<issue_to_address>
**Clean documentation builds lose TOML**
When the documentation environment is installed from `docs/api/requirements.txt` without unrelated packages already installed, `docs/api/conf.py` still imports `toml` and calls `toml.load`, but removing this requirement leaves a clean documentation environment without that module. Sphinx then fails while loading its configuration.
Keep the `toml` requirement or change the configuration to use a parser available in the supported Python versions.
</issue_to_address>
### Comment 4
<location path=".ast-grep/rules/string-status-code.yml" line_range="15" />
<code_context>
+constraints:
+ CODE:
+ kind: string
+ regex: ^["']\d{3}["']$
</code_context>
<issue_to_address>
**String status variables pass the rule**
When an endpoint stores a string status code in a variable and returns that variable in the response tuple, `CODE` must be a string literal matching three digits, so `status = "201"; return body, status` passes the check even though the returned status code is still a string. The rule therefore misses a case its message says it detects.
Add coverage for common string-valued status variables, or clarify that the rule detects only literal string codes.
</issue_to_address>Sourcery assessment
Approval pending. 4 findings to address first.
Blocking findings: .semgrep/cloud-registry.yml:24, .semgrep/cloud-registry.yml:14, docs/api/requirements.txt:4, .ast-grep/rules/string-status-code.yml:15
The semgrep rule for Flask debug mode missed values followed by a YAML comment. Also state that the status code rule detects string literals only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Run all static checks with pre-commit, locally and in CI (closes #73, resolves #31).
S), logging format (G). The findings are fixed, among them f-strings in logging calls,raise ... from,Dict/Optional→dict/X | None, and the import order. The formatter changes no code.tests/. The blanketignore_missing_importsis replaced by an override for Connexion 2, which ships no types, andwarn_unused_ignoresis on. The app now reads its config through typed helpers incloud_registry/utils.py(get_custom_config(),get_collection(), built on FOCA 0.14'sget_config()/get_collection()). That removes theattr-definedignores. The one left isgetServices.__wrapped__, which Refactor: remove duplicated and unused code #74 removes..pre-commit-config.yaml, hooks pinned to commit SHAs, updated by Dependabot):.semgrep/: Flask debug mode in configs, JWT decoding without verification.--hook-stage manual gitleaks-all).sgconfig.yml, rules and rule tests in.ast-grep/): HTTP status codes as strings, Pydantic v1.dict(), untyped FOCA config access in the app.Verification
pytest: 74 passed (Python 3.10, FOCA 0.14.0).ast-grep scanandast-grep test(3 rules), semgrep (both rules flag planted samples; the repo is clean), gitleaks (working tree and full history: no leaks), check-yaml,pre-commit validate-config.pre-commit runitself could not set up the hook repos locally, because the sandbox proxy blocks it. CI is the first full run.G004). ruff already covers this, so no ast-grep rule duplicates it.Notes
.semgrep/therefore holds only project-specific rules..git-blame-ignore-revsentries: this PR is squash-merged, so those commit hashes won't exist ondev.🤖 Generated with Claude Code
Summary by Sourcery
Centralize local and CI quality checks in a pinned pre-commit configuration while modernizing the codebase to comply with the new linting, typing, and security rules.
New Features:
Bug Fixes:
Enhancements:
CI:
Documentation:
Tests: