This commit is contained in:
SepComet
2026-04-06 16:19:44 +08:00
parent a1ede230bb
commit 79474b53aa
42 changed files with 1264 additions and 18 deletions
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-04-06
@@ -0,0 +1,40 @@
## Context
Step 5 adds regression tests for the client prediction jitter path. Tests are placed in `SyncStrategyTests.cs` alongside existing prediction tests, following the same Arrange-Act-Assert pattern using Unity `GameObject` + `Rigidbody` + `MovementComponent` setup.
## Goals / Non-Goals
**Goals:**
- Test that live prediction and replay produce identical trajectories for non-zero turn input (the `client-prediction-replay` spec requires this).
- Test that `ClientPredictionBuffer` correctly exposes `LastAcknowledgedMoveTick` (the `client-prediction-diagnostics` spec requires this).
- Test that correction magnitude handlers receive valid values from `ControlledPlayerCorrection.Resolve`.
**Non-Goals:**
- No production code changes.
- No new specs — existing specs already define the requirements.
## Tests to Add
### Test 1: Replay trajectory matches live prediction for non-zero turn
```
ReplayPendingInputs_NonZeroTurn_MatchesLivePrediction
```
- Arrange: set up MovementComponent, turn=0.5, throttle=1, total duration=0.10s
- Act: run live step-by-step (ApplyTankMovement × 2 × 0.05s) vs replay (ReplayPendingInputs)
- Assert: positions and headings match within tolerance
### Test 2: ClientPredictionBuffer exposes LastAcknowledgedMoveTick
```
ClientPredictionBuffer_LastAcknowledgedMoveTick_IsExposed
```
- Arrange: buffer with recorded inputs at ticks 10, 11, 12
- Act: apply authoritative state acknowledging tick 11
- Assert: `LastAcknowledgedMoveTick == 11`
### Test 3: Correction magnitude propagates through Reconcile
```
ControlledPlayerCorrection_CorrectionMagnitude_IsComputable
```
- Arrange: predicted pose (0,0,0), authoritative (0.5,0,0), 10° heading diff
- Act: `ControlledPlayerCorrection.Resolve(...)`
- Assert: `result.PositionError > 0`, `result.RotationErrorDegrees > 0`
@@ -0,0 +1,23 @@
## Why
Steps 1-3 fixed the core timing issues but jitter persists. Step 5 adds deterministic regression coverage so the remaining jitter path has verifiable, reproducible tests — making future debugging faster and preventing regressions.
## What Changes
- Add a regression test confirming live prediction and replay produce identical trajectories for non-zero turn input (fills gap between existing zero-turn test and the spec requirement).
- Add regression test for `ClientPredictionBuffer` acknowledged-move-tick exposure per `client-prediction-diagnostics` spec.
- Add regression test confirming the MainUI diagnostic handlers receive correct correction magnitude values.
- All new tests are in `SyncStrategyTests.cs` alongside existing prediction tests.
## Capabilities
### New Capabilities
- (none — this is a test coverage step)
### Modified Capabilities
- (none)
## Impact
- `Assets/Tests/EditMode/Network/SyncStrategyTests.cs` — new test methods added
- No production code changes
@@ -0,0 +1,3 @@
# Spec Changes
No new capabilities introduced. This step adds regression tests for existing spec requirements already defined in `client-prediction-replay` and `client-prediction-diagnostics`.
@@ -0,0 +1,13 @@
## 1. Add regression tests to SyncStrategyTests.cs
- [x] 1.1 Add `ReplayPendingInputs_NonZeroTurn_MatchesLivePrediction` — verifies live prediction and replay produce identical trajectories for turn=0.5, throttle=1, duration=0.10s
- [x] 1.2 Add `ClientPredictionBuffer_LastAcknowledgedMoveTick_IsExposed` — verifies LastAcknowledgedMoveTick is correctly set after authoritative state
- [x] 1.3 Add `ControlledPlayerCorrection_CorrectionMagnitude_IsExposed` — verifies PositionError and RotationErrorDegrees are exposed from ControlledPlayerCorrectionResult
## 2. Verify tests pass
- [x] 2.1 Run Unity Test Runner and confirm all tests pass
## 3. Complete
- [x] 3.1 Mark TODO.md Step 5 as complete