Skip to content

[CTX-1708] test(runtime): pin the bar clock timer chain past the pre-armed cap (bitty#2899) - #2901

Merged
Xuepoo merged 1 commit into
mainfrom
ctx-1708-bar-tick
Nov 5, 2026
Merged

Xuepoo merged 1 commit into
mainfrom
ctx-1708-bar-tick

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Priority: P1 | Area: plugins | Labels: fix,P1,area:plugins,area:ui | Milestone: v0.0.33 | RFC: none | Task: CTX-1708

Test-only. Pins the timer model behind the bar clock capsule for bitty#2899. Does not close the issue: the 00:00:00 capsule still needs owner capture (see the issue comment).

What the test proves

The pinned official bar (crates/bitty-runtime/tests/bar-pin, byte-identical to the catalog pin) is driven through a fake runtime clock:

Scenario Ticks advanced Callbacks fired Live rows left Rejections
clock only, 60 s cadence 40 (2400 s) 71 = 1 + 2x31 + 8 1 0
clock only, 60 s cadence 400 (24000 s) 431 = 1 + 2x31 + 368 1 0
fixture mirroring the bar arm_once shape, 1 s cadence 400 431 1 0
one-shot control 1 1, then 0 0 -

So the pre-armed 32-tick chain plus the callback re-arm never runs dry, and no re-arm is rejected. Caps are 64 live rows and 64 pending deadlines; fired rows are pruned before invoke so an at-cap chain cannot deadlock.

Because the capsule text is os.date("%H:%M", os.time()) (real wall clock, not the runtime clock), the test asserts the rendered minute equals the live local minute at every step - which is exactly what catches an epoch/zero formatting fallback - while the version counter proves one ui.update per fired callback.

Tests

  • pinned_bar_clock_ticks_past_the_prearmed_chain
  • pinned_bar_clock_ticks_past_four_hundred_ticks
  • bar_arm_shape_rearm_is_never_rejected (fixture mirroring arm_once, counts E_DEF_LIMIT rejections)
  • one_shot_timer_control_still_fires_once

Adds chrono as a dev-dependency only (local-minute assertion).

Gates

cargo fmt --all -- --check; RUSTFLAGS="-D warnings" cargo clippy -p bitty-runtime --all-targets; cargo test -p bitty-runtime --test bar_clock_tick -> 4 passed; --test bar_activation_budget 2 passed; --test plugin_timers 8 passed; full cargo test -p bitty-runtime green including doctests.

Related

@Xuepoo Xuepoo added this to the v0.0.33 milestone Nov 5, 2026
@Xuepoo Xuepoo added fix Bug fix P1 Priority: high area:ui Area: UI / layout area:plugins labels Nov 5, 2026
@coderabbitai

coderabbitai Bot commented Nov 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 54 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3bf3922a-4071-4300-aa5a-e9fe2d0b96e8
Commits

Reviewing files that changed from the base of the PR and between 9d57df0 and 9ef3aa0.

Files ignored due to path filters: 1

  • Cargo.lock is excluded by !**/*.lock
Files selected for processing: 2

  • crates/bitty-runtime/Cargo.toml
  • crates/bitty-runtime/tests/bar_clock_tick.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@Xuepoo Xuepoo 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.

Independent review — I did not write this code.

Head SHA: 9ef3aa0c2702b027a40687b4f3f2488df7aa4b18 (branch ctx-1708-bar-tick, 1 commit)
Files: Cargo.lock, crates/bitty-runtime/Cargo.toml, crates/bitty-runtime/tests/bar_clock_tick.rs (+482/−0)

1. Test-only in effect — PASS

Non-test files touched: 2, both build metadata, neither changes shipped behaviour.

  • crates/bitty-runtime/Cargo.toml:183 [dev-dependencies]; the added line is crates/bitty-runtime/Cargo.toml:187 chrono.workspace = true. Dev-dependencies are compiled only for tests/benches/examples; cargo build/release output is unchanged.
  • Cargo.lock:445 adds the single string "chrono" to the [[package]] name = "bitty-runtime" dependency list. No new [[package]] entry, no version bump.
  • No crates/*/src/** file is in the diff (gh pr diff --name-only).

crates/bitty-runtime/tests/bar-pin — the plugin under test — is untouched, which is what makes tests 1–2 an end-to-end observation rather than a self-fulfilling fixture.

2. Flake / tautology analysis — PASS

No sleep, no retry, no wall-clock wait anywhere: the only Instant::now() calls are tests/bar_clock_tick.rs:237 and :376, used as the base for the fake clock; deadlines are then computed as base + n·cadence and pumped with pump_due_timers_at(deadline). Whole suite runs in 0.29–0.56 s.

  • pinned_bar_clock_ticks_past_the_prearmed_chain (:282) — not tautological. Drives the real pinned bar through 40 cadence deadlines and asserts the exact fire count 71 (:297-301), exactly one ui.update per fired callback via the band version counter (:259-263), a live-minute capsule on every pump (:265-268), and that another wake stayed armed (:272-275). The count is externally fixed by the bar's chain semantics, not read back from the runtime.
  • pinned_bar_clock_ticks_past_four_hundred_ticks (:326) — same shape, 431 fires (:332-336), still armed after (:337-340), still Active (:342).
  • bar_arm_shape_rearm_is_never_rejected (:391) — asserts rearm_fail == 0 (:434-438) and fires == 431 (:439-443) and pumps == 400 (:433). The counter alone would be weak: the runtime skips an over-cap arm with a silent continue (crates/bitty-runtime/src/plugin_runtime/mod.rs:2257), so a rejected re-arm does not necessarily surface as a Lua error. The fires/pumps pair is what actually catches it — and did, under mutation (below).
  • one_shot_timer_control_still_fires_once (:449) — real control: exactly one fire (:470-471), no wake left (:472), second pump at the same instant delivers 0 (:473-474). It guards against the driver itself over-firing.

Non-tautology was verified by mutation on a throwaway git archive copy of the head tree (repo untouched): making the post-callback arm path refuse any pending deadline (mod.rs:2257, pending >= 1) turned tests 1, 2 and 3 red while the one_shot control stayed green. So the three chain tests bind to the re-arm mechanism, and the control does not depend on it.

Wall-clock boundary: the only real-clock assertion is is_live_local_minute (:201-217), which accepts now, now − 1 min, now + 1 min, so the minute rollover cannot fail it, and the render happens in the same instant as the check (no sleeping). The looser ±1 min window cannot mask staleness because re-render is pinned separately by the per-pump version increment (:259-263).

Repeatability: 12 consecutive runs of the binary, 4/4 pass each time (--test-threads=4, same as CI).

3. Dependency hygiene — PASS

  • Cargo.lock hunk present in this PR: Cargo.lock:445 (+ "chrono",). Required by the project rule and satisfied in the same commit.
  • Version/feature consistency: workspace pin Cargo.toml:74 chrono = { version = "0.4", default-features = false, features = ["clock", "std"] }; the crate opts in with chrono.workspace = true, so it inherits that exact range and feature set — no per-crate feature drift is possible.
  • No unwanted crates: default-features = false (no serde, no wasm-bindgen, no unstable-locales). chrono 0.4.45 was already in the graph as a bitty-lua dependency (Cargo.lock:667), and the diff adds no [[package]] entry, so nothing new enters the supply chain. CI Supply chain (deny/audit) passes.
  • Only Local::now() and format("%H:%M") are used (:209-216), both covered by the clock/std features already enabled by the workspace.

4. MSRV 1.85 — PASS

  • No let-chains. The only compound predicates are a plain if a || b (:206) and while let Some(deadline) = ... (:243, :378). u32::try_from at :261 resolves via the edition-2024 prelude.
  • Verified with the real toolchain on a clean git archive of head (/mnt/data/.../.targets/rev-2901-src, repo checkout untouched):
    • cargo +1.85 check -p bitty-runtime --tests --offline → Finished dev profile ... in 1m 14s, no errors/warnings.
    • cargo +1.85 test -p bitty-runtime --test bar_clock_tick --test plugin_timers --test bar_activation_budget --offline → 4 passed / 8 passed / 2 passed.
  • CI agrees: MSRV 1.85 check pass.

5. Close / issue wiring — PASS

  • Body references only #2899 and #2900, both in non-closing prose ("Pins the timer model behind the bar clock capsule for bitty#2899. Does not close the issue…", "#2900 tracks the real silent-death defect…"). No close(s|d) #N, fix(es|ed) #N or resolve(s|d) #N pattern anywhere in the body.
  • gh pr view 2901 --json closingIssuesReferences → [], so merging closes nothing. Correct: the production defect fix lives outside this PR, and the body says so explicitly.

Nits (non-blocking)

  • The fire counts 71/431 encode the pinned bar's chain arithmetic (:292-296, :330-331). Any bar-pin bump will need these updated in lockstep — worth a line in the pin-bump checklist.
  • Temp data dirs are only removed on the success path (:322, :343); a panic leaves a bitty-bar-clock-* dir in $TMPDIR.
  • is_live_local_minute would also accept a literal 00:00 between 23:59 and 00:01 local. Harmless, and the mutation run showed it does catch a hardcoded 00:00 at any other time.

20/20 CI checks pass at this SHA.

VERDICT: APPROVE

@Xuepoo
Xuepoo merged commit 181ee8d into main Nov 5, 2026
20 checks passed
@Xuepoo
Xuepoo deleted the ctx-1708-bar-tick branch November 5, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:plugins area:ui Area: UI / layout fix Bug fix P1 Priority: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant