Skip to content

test(renderer): fuzz chat projection replay invariants#916

Closed
luoye520ww wants to merge 1 commit into
KunAgent:developfrom
luoye520ww:codex/event-projection-fuzz-tests
Closed

test(renderer): fuzz chat projection replay invariants#916
luoye520ww wants to merge 1 commit into
KunAgent:developfrom
luoye520ww:codex/event-projection-fuzz-tests

Conversation

@luoye520ww

Copy link
Copy Markdown
Collaborator

Problem

SSE reconnect and replay can deliver duplicated, out-of-order, late terminal, and cross-thread projection actions. Existing reducer tests covered a few hand-written sequences but did not exercise combinations of those events.

Root cause

There was no deterministic replay/fuzz harness for the pure chat projection reducer, so reducer invariants could regress without a reproducible sequence.

Scope

This PR adds renderer test coverage only. It does not change reducer behavior, SSE transport, or runtime state.

Changes

  • Generate deterministic bounded action sequences from three fixed seeds.
  • Include duplicate sequence observations, delta replay, approval/input replay, runtime errors, terminal events, and snapshots.
  • Assert replaying the same sequence is deterministic and never throws.
  • Assert a snapshot for another thread cannot replace the active timeline or sequence.
  • Keep the existing reducer regression suite unchanged.

Safety

  • No production code or persisted data changes.
  • The generator uses fixed seeds and bounded input, so failures are reproducible.
  • The cross-thread assertion protects the active thread from foreign replay data.

Typecheck

```text
npm.cmd run typecheck
npm.cmd --prefix kun run typecheck
```

Passed.

Tests

```text
npm.cmd exec vitest run src/renderer/src/store/chat-projection-reducer.test.ts src/renderer/src/store/chat-projection-reducer.fuzz.test.ts
npm.cmd run lint
npm.cmd run build
git diff --check
```

Results: 10 reducer tests passed; lint, build, and diff checks passed.

Review performed

  • Reducer determinism
  • Duplicate/replay handling
  • Cross-thread isolation
  • Bounded deterministic generation
  • Test validity and scope

Non-goals

This PR does not add property-test dependencies or change the event transport. A future PR can connect sequence-gap recovery to the reducer using the existing SSE contracts.

Part of the SSE/replay reliability work.

@luoye520ww

Copy link
Copy Markdown
Collaborator Author

Superseded by consolidated IPC/SSE reliability PR #945, which passed Typecheck, Linux, macOS, and Windows packaged checks. Closing this duplicate to keep the review surface focused.

@luoye520ww luoye520ww closed this Jul 14, 2026
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