Skip to content

Add snooker cue#283

Draft
ekiefl wants to merge 1 commit intomainfrom
ek/snooker-cue
Draft

Add snooker cue#283
ekiefl wants to merge 1 commit intomainfrom
ek/snooker-cue

Conversation

@ekiefl
Copy link
Owner

@ekiefl ekiefl commented Mar 24, 2026

No description provided.

Update test fixtures to match current CueSpecs schema.
@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2b8f3be3-cc38-44f6-99eb-632df17347b8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ek/snooker-cue

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.

@ekiefl
Copy link
Owner Author

ekiefl commented Mar 24, 2026

Fixture patching

Removing field-level defaults from CueSpecs broke deserialization of old msgpack test fixtures. Some were missing shaft_radius_at_tip and shaft_radius_at_butt; the case1-4 fixtures also had a stale butt_radius key and were missing end_mass.

The fixtures were patched with the script below, then round-tripped through pooltool's own System.load/System.save to ensure canonical serialization format.

import msgpack
from pathlib import Path

from pooltool.system.datatypes import System

DEFAULTS = {
    "brand": "Pooltool",
    "M": 0.567,
    "length": 1.4732,
    "tip_radius": 0.0106045,
    "shaft_radius_at_tip": 0.0065,
    "shaft_radius_at_butt": 0.02,
    "end_mass": 0.170097 / 30,
}
EXPECTED_KEYS = set(DEFAULTS.keys())


def patch_specs(specs: dict) -> bool:
    changed = False
    for k in list(specs.keys()):
        if k not in EXPECTED_KEYS:
            del specs[k]
            changed = True
    for k, v in DEFAULTS.items():
        if k not in specs:
            specs[k] = v
            changed = True
    return changed


def patch_fixture(path: Path) -> bool:
    with open(path, "rb") as f:
        data = msgpack.unpackb(f.read(), raw=False)

    changed = patch_specs(data["cue"]["specs"])

    if "events" in data:
        for event in data["events"]:
            if "agents" in event:
                for agent in event["agents"]:
                    if isinstance(agent, dict):
                        for state_key in ("initial", "final"):
                            state = agent.get(state_key)
                            if isinstance(state, dict) and "specs" in state:
                                changed |= patch_specs(state["specs"])

    if changed:
        with open(path, "wb") as f:
            f.write(msgpack.packb(data, use_bin_type=True))

    return changed


tests_dir = Path("tests")
fixtures = sorted(tests_dir.rglob("*.msgpack"))

for p in fixtures:
    patched = patch_fixture(p)
    status = "Patched" if patched else "OK"
    print(f"{status}: {p.relative_to(tests_dir)}")

print("\nRound-tripping through pooltool serializer...")
for p in fixtures:
    s = System.load(p)
    s.save(p)
    print(f"Re-saved: {p.relative_to(tests_dir)}")

@ekiefl ekiefl changed the title Move CueSpecs defaults into classmethods Add snooker cue Mar 24, 2026
@codecov
Copy link

codecov bot commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 46.23%. Comparing base (d77c2ed) to head (dda07fb).

Files with missing lines Patch % Lines
pooltool/objects/cue/datatypes.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #283   +/-   ##
=======================================
  Coverage   46.23%   46.23%           
=======================================
  Files         144      144           
  Lines       10287    10287           
=======================================
  Hits         4756     4756           
  Misses       5531     5531           
Flag Coverage Δ
service 46.23% <88.88%> (ø)
service-no-ani 56.33% <88.88%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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