feat(hint): persist the vs_ai idle-hint wait (wall-clock + read sanitiser)
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Has been skipped
CI / integration (pull_request) Has been skipped
CI / ui (pull_request) Successful in 1m28s
CI / conformance (pull_request) Successful in 11s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m44s
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Has been skipped
CI / integration (pull_request) Has been skipped
CI / ui (pull_request) Successful in 1m28s
CI / conformance (pull_request) Successful in 11s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m44s
Per the owner's call, the idle-hint gate now PERSISTS across leaving and reopening the app, instead of the session-scoped monotonic clock: the unlock is a wall-clock instant (hintUnlockAtMs) stamped from the robot's reply, stored on the local record, carried on the game view + the opponent_moved move delta, and read through a sanitiser that caps it at now + the window. So: - the wait survives a relaunch (a stuck turn is not forgotten); - a device clock set BACK cannot freeze the gate (the cap bounds the remaining to the window and self-heals on the next read); - a clock set FORWARD just opens the hint early -- accepted as harmless for a solo game. - lib/hints.ts hintGateRemainingMs now takes the unlock instant + clamps to the window. - localgame: re-add hintUnlockAtMs to the record/meta; stamp it off the robot's reply; sanitise on read (a shared hintUnlock helper feeds stateView + the opponent_moved event). - gamedelta + PushEvent: the move delta carries hintUnlockAtMs so the view stays fresh. - Game.svelte: hintUnlockAt derives from the view; the tick + lock + toast unchanged. - offline.spec.ts: also assert the lock survives a reload (the wait persisted). - Docs FUNCTIONAL(+_ru)/ARCHITECTURE updated (persist + sanitiser, not monotonic-resets).
This commit is contained in:
@@ -31,19 +31,25 @@ describe('hintsLeft', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('hintGateRemainingMs (the vs_ai idle-hint gate, monotonic)', () => {
|
||||
it('is 0 when the gate is open — a null start (the human first move, or a non-gated game)', () => {
|
||||
expect(hintGateRemainingMs(null, 5000, 1000)).toBe(0);
|
||||
describe('hintGateRemainingMs (the vs_ai idle-hint gate)', () => {
|
||||
it('is 0 when the gate is open — no unlock time (the human first move, or a non-gated game)', () => {
|
||||
expect(hintGateRemainingMs(undefined, 5000, 1000)).toBe(0);
|
||||
expect(hintGateRemainingMs(0, 5000, 1000)).toBe(0);
|
||||
});
|
||||
|
||||
it('is 0 once the idle window has fully elapsed', () => {
|
||||
expect(hintGateRemainingMs(0, 1000, 1000)).toBe(0);
|
||||
expect(hintGateRemainingMs(0, 1500, 1000)).toBe(0);
|
||||
it('is 0 once the unlock instant has passed (the gate is open)', () => {
|
||||
expect(hintGateRemainingMs(1000, 1000, 1000)).toBe(0);
|
||||
expect(hintGateRemainingMs(1000, 1500, 1000)).toBe(0);
|
||||
});
|
||||
|
||||
it('counts down the monotonic time remaining while still gated (only the delta matters)', () => {
|
||||
expect(hintGateRemainingMs(0, 400, 1000)).toBe(600);
|
||||
expect(hintGateRemainingMs(1000, 1400, 1000)).toBe(600);
|
||||
it('is the wall-clock time remaining while still gated', () => {
|
||||
expect(hintGateRemainingMs(1000, 400, 1000)).toBe(600);
|
||||
});
|
||||
|
||||
it('clamps to the window, so a clock set back cannot freeze the gate above the window', () => {
|
||||
// now shoved far into the past (device clock moved back): the raw remaining would exceed the
|
||||
// window, but the cap keeps it at the window so the wait stays bounded and self-heals.
|
||||
expect(hintGateRemainingMs(1000, -100_000, 1000)).toBe(1000);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user