Skip to content

[AAASM-5568] 🚨 (python-sdk): Clear 44 SonarCloud code smells - #308

Merged
Chisanan232 merged 11 commits into
mainfrom
v0.0.1/AAASM-5568/fix_sonar_smells
Aug 5, 2026
Merged

[AAASM-5568] 🚨 (python-sdk): Clear 44 SonarCloud code smells#308
Chisanan232 merged 11 commits into
mainfrom
v0.0.1/AAASM-5568/fix_sonar_smells

Conversation

@Chisanan232

Copy link
Copy Markdown
Contributor

Description

Clears the 44 SonarCloud code smells on python-sdk main down toward the quality target (<5). These surfaced only after the SonarCloud main branch was corrected from the stale master snapshot to main and re-scanned (AAASM-5562) — the old snapshot falsely reported 3. Nearly all are in test/; one is production code.

Fixes by rule:

  • S8997 ×31 — use pytest's monkeypatch fixture for temporary attribute/env/context modifications instead of manual set-and-restore (auto-restores; manual teardown removed). Across test_runner_spawn_patch, test_crewai_spawn_context, test_edge_emission, test_pydantic_ai_spawn_patch, test_registry, bench latency contracts, etc.
  • S9083 ×8 — remove empty parentheses from no-arg decorators (@pytest.fixture()@pytest.fixture) in cli/conftest and native_core.
  • S9073 ×3 — split composite assert A and B into separate assertions.
  • S5778 ×1 — hoist argument construction out of the pytest.raises block so only the single throwing call remains inside.
  • S3776 ×1 — reduce cognitive complexity 18→<15 in agent_assembly/adapters/openai_agents/patch.py by extracting the tool pre-execution check (only production-code change; pure refactor).

Type of Change

  • ♻️ Refactoring

Breaking Changes

  • No

Related Issues

  • Related JIRA ticket: AAASM-5568 (Epic AAASM-5567)

Testing

  • Unit tests added/updated — the monkeypatch conversions restructure test internals; all covered
  • Integration tests added/updated
  • Manual testing performed
  • No tests required

Verification (worktree, uv): ruff check . clean; full uv run pytest = 1204 passed, 16 skipped (skips are env-gated: native _core not built, optional adapter libs absent), 0 failures. mypy shows only the 4 pre-existing _core/grpc-stub import errors that are identical on main (not introduced here). SonarCloud's cognitive-complexity metric is scanner-only, so the S3776 reduction is confirmed by this PR's SonarCloud analysis.

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Comments added for complex logic
  • Documentation updated if needed — N/A
  • All tests passing

🤖 Generated with Claude Code

Chisanan232 and others added 11 commits August 5, 2026 08:37
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…exity

Cognitive complexity of _wrap_on_invoke_tool drops 18->8 (Sonar S3776)
by moving the governance pre-check into _run_async_tool_pre_execution_check.
No behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sonarqubecloud

sonarqubecloud Bot commented Aug 5, 2026

Copy link
Copy Markdown

@Chisanan232 Chisanan232 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Review — LGTM (Claude Code)

Reviewed against the full standard: requirements/logic, implementation, bugs/regressions, goal match, CI.

Goal match — Clears the 44 code smells surfaced by the corrected main re-scan (AAASM-5568), targeting <5. Scope is exactly the flagged rules; no unrelated changes.

Implementation — Correct and idiomatic:

  • S8997 ×31: manual attr/env/context set-and-restore replaced with pytest monkeypatch (auto-restore; manual teardown removed). This is the sanctioned pattern.
  • S9083 ×8: empty parens dropped only from genuinely no-arg decorators.
  • S9073 ×3: top-level assert A and B split; messages preserved.
  • S5778: arg construction hoisted out of pytest.raises so only the throwing call remains inside.
  • S3776: patch.py tool pre-execution check extracted — production refactor, no behavior change.

No regression — Verified locally (Node/uv, worktree): ruff check . clean; full uv run pytest = 1204 passed, 16 skipped (skips env-gated: native _core unbuilt, optional adapter libs absent), 0 failures. mypy shows only the 4 pre-existing _core/grpc-stub import errors identical on main — not introduced here.

CI — 19 pass / 7 skip / 0 fail. SonarCloud PR analysis: open issues = 0 → all 44 resolved, no new issue introduced.

No missing requirements or logic gaps. 🟢

@Chisanan232
Chisanan232 merged commit aaa6c6c into main Aug 5, 2026
26 checks passed
@Chisanan232
Chisanan232 deleted the v0.0.1/AAASM-5568/fix_sonar_smells branch August 5, 2026 01:02
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.

1 participant