fix(web): clear persisted sim_id on reset (review round 2)

reset() now calls socket.clearSimId() so the next play() starts a fresh
simulation (CreateSimulation) instead of re-attaching to the old, reset
sim still alive within its TTL. Test asserts the post-reset play emits
CreateSimulation, not AttachSimulation.

Task: server-side-simulation review round 2, issue 001.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
vinihcrosaandClaude Opus 4.8 committed 2026-07-05 12:23:38 -03:00
1 parent 0e736320d3
commit 07b9538a2c
3 files changed
+19 -3

No files matched your search

@@ -3,7 +3,7 @@ provider: manual
pr: 2
round: 2
round_created_at: 2026-07-05T15:16:15Z
status: pending
status: resolved
file: apps/web/src/stores/simulationStore.ts
line: 141
severity: medium
@@ -46,5 +46,5 @@ Add a store test asserting that after `reset()` a subsequent `play()` emits
## Triage
- Decision: `UNREVIEWED`
- Notes:
- Decision: `VALID`
- Notes: Confirmed — `clearSimId()` was only called on the "unknown simulation" error, never on reset, so localStorage kept the id and the next play() re-attached to the old sim. Fixed: `reset()` now calls `socket.clearSimId()` before closing. Test added: "clears the persisted sim id so the next play starts a fresh simulation" asserts the next play() emits CreateSimulation, not AttachSimulation. Full suite green (248 web tests, turbo 7/7).
@@ -202,4 +202,17 @@ describe('simulationStore — reset', () => {
expect(store().simId).toBeNull()
expect(store().scenarioVessels).toEqual([])
})
it('clears the persisted sim id so the next play starts a fresh simulation', () => {
createSession()
expect(storage.getItem('ymir.simId')).toBe('sim-1')
store().reset()
expect(storage.getItem('ymir.simId')).toBeNull()
store().play(0.05)
lastWs().open()
const msgs = lastWs().sentMessages
expect(msgs.some((m) => m.type === 'CreateSimulation')).toBe(true)
expect(msgs.some((m) => m.type === 'AttachSimulation')).toBe(false)
})
})
+3
View File
@@ -141,6 +141,9 @@ export const useSimulationStore = create<SimulationStore>((set, get) => {
reset() {
const { socket, simId } = get()
if (socket && simId) socket.send({ type: 'Reset', simId })
// Forget the persisted sim id so the next play() starts a fresh
// simulation instead of re-attaching to the old (reset) one.
socket?.clearSimId()
socket?.close()
pendingPlayDt = null
set({ status: 'idle', error: null, state: null, connection: 'idle', socket: null, simId: null, scenarioVessels: [] })