Repository navigation
refactor: reduce SDK complexity and improve CRAP analysis - #1242
marandaneto wants to merge 3 commits into
Conversation
…e-ai-crewai in the uv group across 1 directory (#1241) chore(deps): bump langgraph Bumps the uv group with 1 update in the /examples/example-ai-langgraph directory: [langgraph](https://github.com/langchain-ai/langgraph). Updates `langgraph` from 1.2.12 to 1.2.14 - [Release notes](https://github.com/langchain-ai/langgraph/releases) - [Commits](langchain-ai/langgraph@1.2.12...1.2.14) --- updated-dependencies: - dependency-name: langgraph dependency-version: 1.2.14 dependency-type: direct:production dependency-group: uv ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
posthog-python Compliance ReportDate: 2026-11-12T13:03:41.869984+00:00 ✅ All Tests Passed!270/270 tests passed Capture_V1 Tests✅ 95/95 tests passed View Details
Capture_Ai Tests✅ 5/5 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
Feature_Flags_V4 Tests✅ 149/149 tests passed View Details
Feature_Flags_Local_Evaluation Tests✅ 4/4 tests passed View Details
|
|
Test changes are mostly additive, rather than changing expectations to accommodate the refactor:
No existing SDK tests were deleted or weakened to make the refactoring pass. The new SDK contract tests were also checked against the corresponding pre-refactor implementations to verify that they protect existing behavior. Separately, tooling tests reproduce the CRAP-scoring and API-discovery bugs before their fixes. The API-checker test entrypoint now runs the complete pytest suite instead of manually calling only its original two tests. |
PR overviewNo security issues were found in this pull request. Reviews
|
💡 Motivation and Context
This draft records the SDK-wide CRAP cleanup experiment. CRAP combines function complexity with test coverage. We wanted to measure the change required to keep every production function below 10, rather than checking only
utils.py.The existing calculator counted comments, docstrings, and blank lines as uncovered code. This fixes the checker to use executable statements, then refactors complex functions into private helpers and adds contract tests for coverage gaps. SDK behavior and public signatures are intended to remain unchanged. The relevant SDK specifications were checked, with no intentional behavior divergence.
Stacked on #1239 with
chore/remove-mutation-testsas the base. Mutation-test removal is excluded from this PR's diff.Changes
Client.before_sendrecord. This does not introduce a runtime API.Measured result and rollout boundary
Fresh combined coverage covers all 143 production Python files. The count drops from 226 CRAP failures to zero. All 2,435 measured functions have complexity below 10, with a maximum CRAP score of 9.79. Helper extraction adds 378 functions. The SDK refactor alone changes 69 production files and 25 test files.
CI still enforces the corrected utils-only gate. This draft does not enable SDK-wide enforcement. Reproducing the SDK-wide result in CI requires merging coverage from the full suite and the MCP variants. That collection and merge step remains a follow-up.
💚 How did you test it?
make public_api_check, warning-as-error import, actionlint, andgit diff --checkpass.925fc71268364e89785c21e569528d71a810029dagainstorigin/chore/remove-mutation-testsand reported no actionable findings. An earlier cache-TTL finding was rejected after checking the unchanged final guard, comparing 10 inputs againstmain, and passing seven related LangChain tests. Missing TTL counts still returnNone.The branch also contains a merge from
mainthat updates three example dependency files. Those files remain visible in this stacked diff until the parent branch incorporates that commit. SDK production and test sources are unchanged from the full-suite validation above. The merged TOML files parse successfully, and the focused checks were rerun after the merge.📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Pi used Git, uv, pytest, Docker, GitHub CLI, and autoreview. Independent workers used separate worktrees, followed by read-only preservation reviews. The Pi session is local and has no published transcript link. Human review is required.