Enable working CI lint autofix + remediate pre-existing ruff/mypy/pytest errors#125
Enable working CI lint autofix + remediate pre-existing ruff/mypy/pytest errors#125cryptoxdog wants to merge 8 commits into
Conversation
…format errors Mechanical, behavior-preserving fixes (import sorting, unused imports, formatting) generated by 'ruff check --fix' and 'ruff format'. No manual edits in this commit. Co-authored-by: Igor Beylin <cryptoxdog@users.noreply.github.com>
These lint/type violations were flagged by ruff check and mypy but have no mechanical --fix. All are behavior-preserving: - N806/PLR1714/SIM103/SIM108: rename shadowed constants, merge comparisons, simplify boolean returns (engine/auth/capabilities.py, engine/contract_enforcement.py, engine/convergence_controller_patch.py, engine/inference_rule_registry.py, engine/scoring/assembler.py) - RUF002/RUF003: replace ambiguous Unicode (en dash, Greek alpha) in comments/docstrings with ASCII equivalents - B905: add explicit zip(strict=True) where lengths are already guaranteed equal (engine/diagnostics/dissimilarity.py) - ASYNC109: rename the timeout parameter to timeout_seconds on GraphToEnrichReturnChannel.drain() / apply_return_channel_targets() to avoid the async-timeout-param false positive, updating all call sites - DTZ003: replace datetime.utcnow() with datetime.now(UTC) in engine/models/outcomes.py (OutcomeRecord.timestamp + cutoff computation, kept consistent to avoid naive/aware comparison bugs) - F841/RUF059/E402: drop or underscore-prefix unused locals, consolidate imports to the top of tests/test_algorithmic_upgrades.py - PLR0915: extract MultiHopTraverser._execute_hop() from traverse() to reduce statement count (pure extraction, no behavior change) - N818: chassis.errors.FeatureNotEnabled is a stable, serialized error name used by API clients, documented as an intentional per-file ignore instead of a breaking rename - mypy unreachable/arg-type: annotate two intentionally-defensive runtime type checks in capabilities.py, and fix a mypy ignore-comment placement mismatch in multihop.py's pre-existing similarity-mode call All touched unit tests re-verified passing; ruff check/format and mypy both clean on these files. Co-authored-by: Igor Beylin <cryptoxdog@users.noreply.github.com>
While removing an unused local (F841, ruff), found that _build_envelope() called build_graph_sync_packet(tenant_tier=..., correlation_id=...), but that factory's real signature only accepts tenant_context and lineage dicts (engine/contract_enforcement.py). This call would raise TypeError on every invocation. Map the arguments onto the actual factory signature instead. This class has no current callers/tests, so this was previously undetected dormant code (mypy call-arg + F401 unused-import findings). Co-authored-by: Igor Beylin <cryptoxdog@users.noreply.github.com>
ci-quality.yml's lint-format job runs mypy with continue-on-error:false, so these were already CI-blocking on every PR to main/develop: - engine/arbitration/engine.py: ArbitrationEngine.resolve() assigned plain str to ArbitrationResult.final_decision (a Literal[...] field); annotate the local with the same Literal so mypy narrows it correctly. _evaluate()'s comparison operators returned Any (object has no __lt__/__le__/__gt__/__ge__ per typeshed); widen the params to Any (they already accept heterogeneous domain-config values) and wrap each comparison in bool(...). - engine/outcomes/engine.py: OutcomeEngine.process() calls GraphDriver.apply_outcome_edge_update() / ScoringAssembler. apply_outcome_feedback(), neither of which exists. This path is dormant -- tests/unit/test_outcomes.py already skips it because DomainPackLoader.allowed_canonical_labels() "never existed" (see reports/GMP-Report-132-Fix-Residual-PreExisting-Issues.md). Documented with type: ignore[attr-defined] plus a note rather than fabricating an implementation. - engine/security/P2_9_llm_schemas.py: explicit str(...) around the narrowed (non-None) LLM response content, since the untyped SDK response otherwise resolves to Any. - engine/compliance/audit_persistence.py: move the asyncpg import (used only in type annotations under `from __future__ import annotations`) behind TYPE_CHECKING (ruff TC002); no runtime change. `mypy engine/` now exits 0 (previously 19 errors across 7 files). Co-authored-by: Igor Beylin <cryptoxdog@users.noreply.github.com>
pytest.ini is the authoritative config (it takes precedence over pyproject.toml's [tool.pytest.ini_options], which pytest ignores whenever a root pytest.ini exists). Its markers list only had unit/integration/security, while pyproject.toml separately declared compliance/performance/slow/contract/finding, which pytest never actually saw. Effect: any pytest invocation using -m (as the pytest-unit pre-commit hook and CI do) failed at collection with "'compliance' not found in `markers` configuration option" as soon as it reached tests/compliance/test_audit.py, aborting the entire run before any unit test executed. Reproduced and confirmed on the pre-change tree. Merge the full marker set into pytest.ini (the active config) and keep pyproject.toml's copy in sync with a note explaining the precedence, so this doesn't silently drift again. Co-authored-by: Igor Beylin <cryptoxdog@users.noreply.github.com>
AGENTS.md, .cursorrules, and docs/CI_PIPELINE.md all document and instruct agents/contributors to run `make lint-fix` to autofix lint failures, and describe `make lint` as the check-only ruff+mypy gate that mirrors CI. Neither existed: the Makefile only had a `lint` target that already mutated the tree via `ruff check . --fix` + `ruff format .` and never ran mypy, so it did not actually match what CI enforces, and `make lint-fix` didn't exist at all. - `make lint` now runs `ruff check .` (no --fix) + `ruff format --check .` + `mypy engine/` -- the same non-mutating checks CI runs, so a clean `make lint` locally is a reliable predictor of a passing CI lint job. - `make lint-fix` is the new autofix entry point: `ruff check . --fix` + `ruff format .` (matches the long-documented but missing command). - `make check` (full local gate) keeps its previous autofix-then-verify behavior for convenience, just relabeled for clarity. Co-authored-by: Igor Beylin <cryptoxdog@users.noreply.github.com>
…workflow .github/workflows/auto-fix-adr.yml (triggered on push to develop / workflow_dispatch) called `python ci/auto_fix_adr.py` and `python ci/check_imports.py`, but the ci/ directory does not exist anywhere in this repo, so the workflow could never run successfully. Ruff already mechanically enforces (and can --fix) the same class of issues that workflow targeted: sorted __all__ (RUF022), Optional[T] -> T | None (UP045), datetime.now() -> datetime.now(UTC) (UP017/DTZ003), zip(strict=True) (B905), unused/unsorted imports (F401/I001), etc. -- see [tool.ruff.lint] in pyproject.toml. Add .github/workflows/lint-autofix.yml: same trigger/safety model (develop push + workflow_dispatch, never pushes directly to a protected branch, opens a PR via peter-evans/create-pull-request instead), but running `ruff check . --fix` + `ruff format .`, with a syntax-validation step and a check that ruff has no remaining autofixable violations before opening the PR. Skips opening a PR when there is nothing to fix. Document both the new workflow and `make lint-fix` as the two ways to autofix lint violations in docs/CI_PIPELINE.md. Co-authored-by: Igor Beylin <cryptoxdog@users.noreply.github.com>
|
❌ Too Many Files Changed ❌ PR Too Large 📋 Best Practices for Large Changes
🚫 This PR is blocked from merging until size limits are met. |
| import engine.gates.compiler as gc | ||
| import engine.sync.generator as sg | ||
| import engine.scoring.assembler as sa | ||
| import engine.sync.generator as sg |
There was a problem hiding this comment.
Reviewed — not applying this one. The two imports serve genuinely different purposes and aren't interchangeable here:
test_sync_generator_uses_parameterized_query(line 37) needs theSyncGeneratorclass to instantiate it:from engine.sync.generator import SyncGenerator.test_eval_exec_not_importable_from_engine(line 74) needs the module objectengine.sync.generatoritself, so it can calldir(mod)and walk its module-level names looking for an eval-like function:import engine.sync.generator as sg.
The suggested fix (from engine.sync.generator import SyncGenerator as sg) would alias the class to sg, not the module — dir(sg) would then return the class's methods/attributes instead of the module's top-level names, silently changing what test_eval_exec_not_importable_from_engine actually checks (defeating its stated purpose: "Engine modules must not expose eval/exec at module level"). Different scopes (separate function bodies), each importing exactly what that test needs, is intentional here rather than an inconsistency to fix.
DomainPackLoader.__init__() takes config_path, not domains_dir (see engine/config/loader.py:53). Both call sites in this file passed domains_dir=..., which raised TypeError before either test could reach the assertions it exists to check. Confirmed pre-existing (reproduced identically on the unmodified main branch, unrelated to this PR). Flagged by github-code-quality[bot] on PR #125; fixing here since it directly blocks two security tests that must run in CI. Note: with the constructor fixed, both tests now progress further but still fail on a separate, pre-existing issue -- domains/plasticos fails DomainSpec validation (scoring.dimensions[].source/computation/ weightkey/defaultweight, sync.endpoints) -- a domain-spec/schema drift issue unrelated to this argument-name bug and out of scope here. Co-authored-by: Igor Beylin <cryptoxdog@users.noreply.github.com>
|
❌ Too Many Files Changed ❌ PR Too Large 📋 Best Practices for Large Changes
🚫 This PR is blocked from merging until size limits are met. |
|
Re: the PR-size policy comment above — agreed, this PR grew too large by trying to fix the whole pre-existing lint/mypy/pytest baseline in one shot. Going forward, new CI-pipeline work (wiring |
Summary
Answers "how do we enable autofix on CI tools and remediate the codebase's existing pre-existing errors?" with a working implementation instead of just docs:
.github/workflows/auto-fix-adr.ymlcalledci/auto_fix_adr.pyandci/check_imports.py, but theci/directory doesn't exist in this repo — it could never succeed. Replaced it with.github/workflows/lint-autofix.yml, which runsruff check --fix+ruff formatagainstdevelop(on push orworkflow_dispatch) and opens a PR with the result. It never pushes directly to a protected branch, and it now covers the same class of fixes the old ADR script targeted (sorted__all__,Optional[T]→T | None,datetime.now(UTC),zip(strict=True), unused/unsorted imports, ...).make lint-fixtarget.AGENTS.md,.cursorrules, anddocs/CI_PIPELINE.mdall documentmake lint-fixas the local autofix command, but it never existed in theMakefile.make lintalso used to mutate the tree (--fix) and skipmypy, so it didn't actually mirror what CI enforces. Nowmake lintis a non-mutating check that matches CI (ruff check+ruff format --check+mypy engine/), andmake lint-fixis the autofix entry point.make lint(and CI'slint/lint-formatjobs) actually pass:ruff check .: 129 → 0 errors (100 via--fix, the rest were non-autofixable: renamed shadowed constants,zip(strict=True), ambiguous Unicode in comments/docstrings, dead unused-var removal, onePLR0915fixed by extracting a helper method, anASYNC109false-positive resolved by a parameter rename, etc.)ruff format .: 60 files reformattedmypy engine/: 19 → 0 errors, including one genuine bug found along the way (GraphSyncClient._build_envelope()was callingbuild_graph_sync_packet(tenant_tier=..., correlation_id=...), but that factory's real signature only acceptstenant_context/lineage— this dormant, untested class would have raisedTypeErroron every call)pytest.iniwas missing thecompliance/performance/slow/contract/findingmarkers thatpyproject.tomlseparately declared (which pytest ignores wheneverpytest.iniexists) — any-m-filtered pytest run (including thepytest-unitpre-commit hook) failed at collection as soon as it reachedtests/compliance/test_audit.py, before running a single test. Merged the marker lists.All changes are commited separately by theme; see individual commit messages for the specifics of each rule/file.
Verification
ruff check ./ruff format --check ./mypy engine/all exit 0make lintpasses end-to-endpytest tests/ -m "unit" ...command now collects and passes (previously aborted at collection)pytest tests/run: identical39 failed, 1570 passed, 35 skipped, 56 xfailed, 22 errorsbefore and after these changes (confirmed against the pre-change tree) — those pre-existing failures are unrelated full-suite ordering/integration issues (missing Docker/Neo4j,constellation_node_sdk,DomainPackLoaderAPI drift, etc.) and are out of scope hereOut of scope (flagged, not fixed)
ci.yml,docker-build.yml,k8s-deploy.yml,supply-chain.yml) pin third-party actions with a corrupted ref format (a full SHA immediately concatenated with a version tag, e.g.@c5a7806660adbe173f04e3e038b0ccdcd758773dv6.1.0), which is not a resolvable git ref. Unrelated to lint/autofix; left untouched to keep this PR scoped.