Skip to content

test: type source parser contracts - #292

Merged
Sinity merged 2 commits into
masterfrom
feature/refactor/sources-test-contracts
Apr 21, 2026
Merged

Sinity merged 2 commits into
masterfrom
feature/refactor/sources-test-contracts

Conversation

@Sinity

@Sinity Sinity commented Apr 21, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • removes explicit dynamic typing from source parser and source gateway tests
  • narrows parser property payloads through typed JSON/sequence helpers before parser calls
  • types sparse null-guard strategies and generated Gemini part payloads without weakening provider contracts

Problem

The source test surface still carried explicit Any/cast(Any) usage around parser payloads, Google Drive import fakes, and adversarial null-guard strategies. That weakened mypy coverage in the parser boundary tests and left generated payload shapes less clear than the production parser contracts they exercise.

Ref #281

Solution

Introduce local type aliases and parser-boundary helpers in tests/unit/sources so object-shaped Hypothesis data is narrowed before parser calls. Replace private-service casts in Drive gateway/auth tests with concrete service/module types, and type the sparse property strategies directly.

Touched files:

  • tests/unit/sources/test_drive_auth.py
  • tests/unit/sources/test_drive_gateway.py
  • tests/unit/sources/test_null_guard_properties.py
  • tests/unit/sources/test_parsers_chatgpt.py
  • tests/unit/sources/test_parsers_props.py

Verification

  • PATH=/tmp/polylogue-281/.cache/codex-bin:$PATH ruff check --fix tests/unit/sources
  • PATH=/tmp/polylogue-281/.cache/codex-bin:$PATH ruff format tests/unit/sources
  • rg -n "\bAny\b|cast(Any|typing import .Any" tests/unit/sources -g ".py"
  • PATH=/tmp/polylogue-281/.cache/codex-bin:$PATH mypy tests/unit/sources
  • PATH=/tmp/polylogue-281/.cache/codex-bin:$PATH pytest -q tests/unit/sources
  • PATH=/tmp/polylogue-281/.cache/codex-bin:$PATH mypy polylogue tests/unit/sources
  • PATH=/tmp/polylogue-281/.cache/codex-bin:$PATH devtools verify --quick
  • PATH=/tmp/polylogue-281/.cache/codex-bin:$PATH git push -u origin feature/refactor/sources-test-contracts

@coderabbitai

coderabbitai Bot commented Apr 21, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Multiple test files are updated to replace broad Any type annotations with explicit, narrower types. Changes include adding type aliases, updating type casts for mocked objects, and tightening parameter annotations across parser and gateway tests, with no modifications to runtime behavior or assertions.

Changes

Cohort / File(s) Summary
Drive Auth & Gateway Tests
tests/unit/sources/test_drive_auth.py, tests/unit/sources/test_drive_gateway.py
Type annotations tightened: ModuleType replaces Any for mocked import returns; _DriveService casting replaces broad Any casts; callback parameter annotations changed from Any to object.
Parser Tests
tests/unit/sources/test_parsers_chatgpt.py, tests/unit/sources/test_parsers_props.py
Type aliases introduced (ProviderCheck, ParseFn, ParserPayload, case types); parameters tightened from Any to specific types; new helper functions added for payload validation and parser wrapping with JSON-safe access.
Null Guard Properties Tests
tests/unit/sources/test_null_guard_properties.py
Replaced Any annotations with explicit TypeAlias-based types and SearchStrategy[...] generics; updated Hypothesis test method signatures with concrete parameter types; removed inline imports.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Hoppy types now bloom with care,
No more Any casting everywhere,
From mocks to parsers, tests shine bright,
With explicit types, we test it right! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.23% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'test: type source parser contracts' directly and concisely summarizes the main change: introducing typing to source parser contract tests.
Description check ✅ Passed The PR description covers all required template sections: Summary explains the changes, Problem states the necessity, Solution details touched files and approach, and Verification lists comprehensive commands executed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/refactor/sources-test-contracts

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.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/unit/sources/test_null_guard_properties.py`:
- Around line 36-40: The GeminiPartPayload type alias is declared as "GeminiPart
| dict[str, object]" but the test generator for the Gemini parts strategy only
emits dict shapes, so tighten the alias by removing the unused GeminiPart arm;
update the GeminiPartPayload TypeAlias to be dict[str, object] (replace the
union that references GeminiPart) so the alias matches the actual produced
values and improves type signal.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 19cf54b6-9283-4910-8d67-cb5640fd248b

📥 Commits

Reviewing files that changed from the base of the PR and between be4f830 and 05c734a.

📒 Files selected for processing (5)
  • tests/unit/sources/test_drive_auth.py
  • tests/unit/sources/test_drive_gateway.py
  • tests/unit/sources/test_null_guard_properties.py
  • tests/unit/sources/test_parsers_chatgpt.py
  • tests/unit/sources/test_parsers_props.py

Comment on lines +36 to +40
TimestampInput: TypeAlias = str | int | float | None
SparseProviderMeta: TypeAlias = dict[str, object] | None
SparseMetadata: TypeAlias = dict[str, object]
SparseMessagePayload: TypeAlias = dict[str, object] | None
GeminiPartPayload: TypeAlias = GeminiPart | dict[str, object]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Aliases are well-scoped; minor: GeminiPart arm of GeminiPartPayload is not exercised.

The Gemini parts strategy (lines 362–370) only produces dict shapes, so the GeminiPart | ... union is wider than what's generated. Harmless and arguably future-proof, but if you want tighter signal, GeminiPartPayload: TypeAlias = dict[str, object] would match the actual generator output.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/sources/test_null_guard_properties.py` around lines 36 - 40, The
GeminiPartPayload type alias is declared as "GeminiPart | dict[str, object]" but
the test generator for the Gemini parts strategy only emits dict shapes, so
tighten the alias by removing the unused GeminiPart arm; update the
GeminiPartPayload TypeAlias to be dict[str, object] (replace the union that
references GeminiPart) so the alias matches the actual produced values and
improves type signal.

@Sinity
Sinity merged commit 9f3cfbe into master Apr 21, 2026
14 checks passed
@Sinity
Sinity deleted the feature/refactor/sources-test-contracts branch April 21, 2026 11:54
Sinity added a commit that referenced this pull request Apr 22, 2026
## Summary
- removes explicit dynamic typing from source parser and source gateway tests
- narrows parser property payloads through typed JSON/sequence helpers before parser calls
- types sparse null-guard strategies and generated Gemini part payloads without weakening provider contracts

## Problem
The source test surface still carried explicit Any/cast(Any) usage around parser payloads, Google Drive import fakes, and adversarial null-guard strategies. That weakened mypy coverage in the parser boundary tests and left generated payload shapes less clear than the production parser contracts they exercise.

Ref #281

## Solution
Introduce local type aliases and parser-boundary helpers in tests/unit/sources so object-shaped Hypothesis data is narrowed before parser calls. Replace private-service casts in Drive gateway/auth tests with concrete service/module types, and type the sparse property strategies directly.

Touched files:
- tests/unit/sources/test_drive_auth.py
- tests/unit/sources/test_drive_gateway.py
- tests/unit/sources/test_null_guard_properties.py
- tests/unit/sources/test_parsers_chatgpt.py
- tests/unit/sources/test_parsers_props.py

## Verification
- PATH=/tmp/polylogue-281/.cache/codex-bin:$PATH ruff check --fix tests/unit/sources
- PATH=/tmp/polylogue-281/.cache/codex-bin:$PATH ruff format tests/unit/sources
- rg -n "\bAny\b|cast\(Any|typing import .*Any" tests/unit/sources -g "*.py"
- PATH=/tmp/polylogue-281/.cache/codex-bin:$PATH mypy tests/unit/sources
- PATH=/tmp/polylogue-281/.cache/codex-bin:$PATH pytest -q tests/unit/sources
- PATH=/tmp/polylogue-281/.cache/codex-bin:$PATH mypy polylogue tests/unit/sources
- PATH=/tmp/polylogue-281/.cache/codex-bin:$PATH devtools verify --quick
- PATH=/tmp/polylogue-281/.cache/codex-bin:$PATH git push -u origin feature/refactor/sources-test-contracts
Sinity added a commit that referenced this pull request Apr 22, 2026
The source test surface still carried explicit `Any`/`cast(Any)`
usage around parser payloads, Google Drive import fakes, and
adversarial null-guard strategies. That weakened mypy coverage in
the parser boundary tests and left generated payload shapes less
clear than the production parser contracts they exercise.

Introduces local type aliases and parser-boundary helpers in
`tests/unit/sources` so object-shaped Hypothesis data narrows
before parser calls. Replaces private-service casts in Drive
gateway/auth tests with concrete service/module types. Types the
sparse null-guard property strategies and generated Gemini part
payloads directly.

Touched: `test_drive_auth.py`, `test_drive_gateway.py`,
`test_null_guard_properties.py`, `test_parsers_chatgpt.py`,
`test_parsers_props.py`.

Verification: ruff + mypy + pytest over `tests/unit/sources`;
devtools verify --quick green.

Ref #281
Sinity added a commit that referenced this pull request Apr 22, 2026
The source test surface still carried explicit `Any`/`cast(Any)`
usage around parser payloads, Google Drive import fakes, and
adversarial null-guard strategies. That weakened mypy coverage in
the parser boundary tests and left generated payload shapes less
clear than the production parser contracts they exercise.

Introduces local type aliases and parser-boundary helpers in
`tests/unit/sources` so object-shaped Hypothesis data narrows
before parser calls. Replaces private-service casts in Drive
gateway/auth tests with concrete service/module types. Types the
sparse null-guard property strategies and generated Gemini part
payloads directly.

Touched: `test_drive_auth.py`, `test_drive_gateway.py`,
`test_null_guard_properties.py`, `test_parsers_chatgpt.py`,
`test_parsers_props.py`.

Verification: ruff + mypy + pytest over `tests/unit/sources`;
devtools verify --quick green.

Ref #281
Sinity added a commit that referenced this pull request Apr 22, 2026
The source test surface still carried explicit `Any`/`cast(Any)`
usage around parser payloads, Google Drive import fakes, and
adversarial null-guard strategies. That weakened mypy coverage in
the parser boundary tests and left generated payload shapes less
clear than the production parser contracts they exercise.

Introduces local type aliases and parser-boundary helpers in
`tests/unit/sources` so object-shaped Hypothesis data narrows
before parser calls. Replaces private-service casts in Drive
gateway/auth tests with concrete service/module types. Types the
sparse null-guard property strategies and generated Gemini part
payloads directly.

Touched: `test_drive_auth.py`, `test_drive_gateway.py`,
`test_null_guard_properties.py`, `test_parsers_chatgpt.py`,
`test_parsers_props.py`.

Verification: ruff + mypy + pytest over `tests/unit/sources`;
devtools verify --quick green.

Ref #281
@Sinity

Sinity commented Apr 28, 2026

Copy link
Copy Markdown
Owner Author

🤖 Post-hoc audit note: this PR received bot review feedback verified against current HEAD as part of #544. 1 finding(s) confirmed still present → tracked in #550.

@Sinity

Sinity commented May 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@Sinity
Sinity requested a review from Copilot May 1, 2026 00:43
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Sinity
Sinity removed the request for review from Copilot May 1, 2026 01:05
@Sinity

Sinity commented May 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Sinity
Sinity requested a review from Copilot May 1, 2026 01:52
@Sinity
Sinity removed the request for review from Copilot May 1, 2026 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant