Repository navigation
test: lift fixtures.py 88% to 99% and vision_image.py 80% to 98% #771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
seonghobae
wants to merge
12
commits into
main
Choose a base branch
from
test/fixtures-vision-coverage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e9d73b1
test: lift fixtures.py 88% to 99% and vision_image.py 80% to 98%
cf8b9e1
test(fixtures): remove unused test imports
fc78678
Merge branch 'main' into test/fixtures-vision-coverage
seonghobae 237ea97
test: generate oversized image in Pillow
e53c163
test: make vision fallback coverage deterministic
e51e47c
Merge current main into test/fixtures-vision-coverage
042c99e
Merge remote-tracking branch 'origin/main' into codex/pr771-refresh
51c2c9d
test(vision): verify patched payload ceiling
d3f531f
merge(main): converge coverage tests onto current protected base
seonghobae 50d6823
chore(stack): converge fixture coverage with protected main
seonghobae d5e83b6
chore(tests): converge fixture coverage with protected main
seonghobae 9a4dbfc
chore: converge fixture coverage onto protected main
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| """Direct branch tests for fixture cast, commit clock, and vision compression. | ||
|
|
||
| The end-to-end suites exercise fixtures and vision images only on the | ||
| happy path. These tests drive the remaining branches: the A-100 / B-200 / | ||
| unknown fixture casts, the calendar commitment clock helper, and the | ||
| bounded-JPEG re-encode loop that steps quality and resizes an oversized | ||
| image until it fits the vision payload ceiling. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import io | ||
| from unittest.mock import patch | ||
|
|
||
| from PIL import Image | ||
|
|
||
| from lineageweave.fixtures import ( | ||
| calendar_commitment_occurred_at, | ||
| fixture_thread_cast, | ||
| ) | ||
| from lineageweave.vision_image import _MAX_VISION_IMAGE_BYTES, _encode_bounded_jpeg | ||
|
|
||
|
|
||
| def _alpha_title() -> str: | ||
| from lineageweave.fixtures import sample_records | ||
|
|
||
| return next( | ||
| record.label | ||
| for record in sample_records() | ||
| if record.secondary_key == "proj-alpha" | ||
| ) | ||
|
|
||
|
|
||
| def _beta_title() -> str: | ||
| from lineageweave.fixtures import sample_records | ||
|
|
||
| return next( | ||
| record.label | ||
| for record in sample_records() | ||
| if record.secondary_key == "proj-beta" | ||
| ) | ||
|
|
||
|
|
||
| def test_fixture_thread_cast_alpha_and_beta_and_unknown() -> None: | ||
| alpha_cast = fixture_thread_cast(_alpha_title()) | ||
| assert alpha_cast is not None | ||
| assert alpha_cast.organization_name == "Northridge Grid" | ||
| assert alpha_cast.person_names == ("Ada West", "Priya Nair") | ||
|
|
||
| beta_cast = fixture_thread_cast(_beta_title()) | ||
| assert beta_cast is not None | ||
| assert beta_cast.organization_name == "Westfield Power" | ||
| assert beta_cast.person_names == ("Jordan Hale",) | ||
|
|
||
| assert fixture_thread_cast("A completely unknown title") is None | ||
|
|
||
|
|
||
| def test_calendar_commitment_occurred_at_is_a_positive_iso_week_date() -> None: | ||
| value = calendar_commitment_occurred_at() | ||
| assert value.year == 2026 | ||
| assert value.month == 1 | ||
| assert value.day == 5 | ||
| assert value.isocalendar().week == 2 | ||
|
|
||
|
|
||
| def test_bounded_jpeg_encodes_a_tiny_image_directly() -> None: | ||
| image = Image.new("RGB", (8, 8), color=(120, 40, 200)) | ||
| payload = _encode_bounded_jpeg(image) | ||
| assert len(payload) <= _MAX_VISION_IMAGE_BYTES | ||
| with Image.open(io.BytesIO(payload)) as decoded: | ||
| assert decoded.format == "JPEG" | ||
|
|
||
|
|
||
| def test_bounded_jpeg_resize_fallback_reaches_minimum_size() -> None: | ||
| image = Image.new("RGB", (8, 8), color=(120, 40, 200)) | ||
| with patch("lineageweave.vision_image._MAX_VISION_IMAGE_BYTES", 1): | ||
| payload = _encode_bounded_jpeg(image) | ||
| assert len(payload) <= _MAX_VISION_IMAGE_BYTES | ||
|
github-actions[bot] marked this conversation as resolved.
Resolved
|
||
| with Image.open(io.BytesIO(payload)) as decoded: | ||
| assert decoded.size == (2, 2) | ||
| assert decoded.format == "JPEG" | ||
|
|
||
|
|
||
| def test_bounded_jpeg_preserves_a_tiny_image_without_resizing() -> None: | ||
| image = Image.new("RGB", (1, 1), color=(10, 20, 30)) | ||
| payload = _encode_bounded_jpeg(image) | ||
| assert len(payload) <= _MAX_VISION_IMAGE_BYTES | ||
| with Image.open(io.BytesIO(payload)) as decoded: | ||
| assert decoded.size == (1, 1) | ||
|
|
||
| def test_ambiguous_fixture_posts_are_nonempty_and_refer_synthetic_people() -> None: | ||
| """Both ambiguity fixtures stay demo-safe and reference real names.""" | ||
| from lineageweave.fixtures import ( | ||
| ambiguous_entity_relationship_post, | ||
| ambiguous_keyman_post, | ||
| ) | ||
|
|
||
| keyman_title, keyman_body = ambiguous_keyman_post() | ||
| assert keyman_title and keyman_body | ||
| assert "Priya" in keyman_body and "Jordan Hale" in keyman_body | ||
|
|
||
| rel_title, rel_body, org_names = ambiguous_entity_relationship_post() | ||
| assert rel_title and rel_body | ||
| assert "Meridian Utilities" in org_names and "Colby Insulation" in org_names | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.