* test(web): add comprehensive tests for all Pinia stores
* test(web): add edge case tests for Pinia stores
* test(web): document race condition bugs in ui and world stores
* fix(web): fix race condition bugs in ui and world stores
- ui.ts: Add detailRequestId counter to prevent stale responses from
overwriting fresh data when reselecting the same target
- world.ts: Add eventsRequestId counter to prevent stale responses
when filter changes rapidly via resetEvents
- Update tests to verify the fix works correctly
* fix(web): fix race condition in fetchInitStatus
- Add fetchStatusRequestId counter to prevent stale responses from
overwriting fresh data when fetchInitStatus is called rapidly
- Add test that first proves the bug exists, then verifies the fix
* fix(web): fix race condition in fetchState
Add fetchStateRequestId counter to prevent stale responses from
overwriting fresh data when fetchState is called rapidly.
* test(web): add missing edge case tests for world store
- Add changePhenomenon API failure test
- Add initialize concurrent calls test
- Add getPhenomenaList concurrent calls test
Total: 108 tests
* test(web): add comprehensive socket store tests
- Add init() duplicate call guard test
- Add setup listener tests
- Add message handling tests (tick, game_reinitialized)
- Add status change handling tests
Total: 118 tests
* test(web): add missing socket message handling tests
- Add llm_config_required message tests
- Add unknown message type test
Total: 121 tests
* test(web): add handleTick edge case tests
- Add test for avatars without id (ignored)
- Add test for empty events array
- Add test for events filtered to empty
Total: 124 tests
* test: add edge case tests for game initialization
* test: add 3 more edge case tests for game initialization
* test: add 8 more edge case tests for comprehensive coverage
* docs: add comprehensive coverage report to test file header
Use single-pass regex replacement instead of multiple replaceAll calls.
This prevents shorter names from matching inside already-replaced longer names.
For example, with names '张三' and '张三丰', the text '张三丰是大师' now
correctly highlights only '张三丰', not '张三' within it.
* fix: make cooldown_action decorator properly await async finish()
The decorator was incorrectly wrapping the async finish() method with a sync
wrapper, causing cooldown to be recorded BEFORE the action actually executed.
This fix:
- Changes wrapper to async def finish()
- Awaits original_finish() before recording cooldown
- Ensures cooldown is only recorded on successful execution
Fixes#74
* test: add test to verify cooldown not recorded on failure
This test actually reveals the async/await bug:
- Creates a FailingAction that raises in finish()
- Verifies cooldown is NOT recorded when action fails
- Fails with buggy sync wrapper, passes with async fix
- Test LLM response parsing (list and dict formats)
- Test null params conversion to empty dict
- Test invalid format handling and skipping
- Test emotion update logic with all emotion types
- Test fallback to CALM on invalid/missing emotion
- Test batch avatar processing
- Test AI.decide wrapper returns NULL_EVENT
- Test thinking field variants (avatar_thinking vs thinking)
- Add testing strategy documentation to test file
Closes#63
PR #32 changed Technique.sect (str) to Technique.sect_id (int), but
fortune.py was not updated. This caused AttributeError when fortune
event triggered and tried to access t.sect.
Error: 'Technique' object has no attribute 'sect'
Ensures all tests have deterministic random behavior by setting
random.seed(42) before each test. This prevents flaky tests caused
by random number generation.
Closes#44
When avatars overlap (e.g., during sparring, talking, dual cultivation),
it's hard to click on them directly. This adds the ability to click on
colored avatar names in the event panel to open their detail view.
- Modify highlightAvatarNames to include data-avatar-id attribute
- Add click event delegation in EventPanel
- Add hover styles for clickable names
The region_names dictionary was a redundant index that needed manual
sync when HistoryManager modified region names. This caused bugs where
resolve_query couldn't find regions by their new (history-modified) names.
Instead of maintaining two data structures (regions[id] and region_names[name]),
we now only use regions[id] as the single source of truth. The _resolve_region
function iterates over regions.values() to find matches by name.
This approach:
- Eliminates the sync bug entirely
- Simplifies the codebase
- Has negligible performance impact (region count is small)
Co-authored-by: Zihao Xu <xzhseh@gmail.com>
The test_passive_update_loop test was flaky because when misfortune
randomly triggers during sim.step(), it calls StoryTeller.tell_story
which wasn't mocked, causing real LLM API calls to fail in CI.
Added StoryTeller.tell_story to the mock_llm_managers fixture.
The pause indicator was showing 'paused' while the game was still running
because isManualPaused was being modified by both user actions (clicking
pause button) and system actions (opening menu).
Changes:
- systemStore: pause()/resume() no longer modify isManualPaused, only
togglePause() does (with optimistic update + rollback on failure)
- useGameControl: consolidate 3 overlapping watches into 1 clean watch
that only handles menu open/close without polluting manual pause state
- App.vue: explicitly call resumeGame() API when game initializes
Verify that:
1. Avatar without sect knows current location's region
2. Avatar with sect knows their sect headquarters
3. Avatar without sect does not automatically know sect regions
4. Avatar only knows their own sect's headquarters, not others
* fix: CSV column name mismatches in data loading
- sect.py: Fix headquarter_name/headquarter_desc -> name/desc when reading sect_region.csv
- sect.py: Move sid initialization before technique lookup to fix unbound variable bug
- technique.py: Change sect (name) to sect_id (int) to match technique.csv column
- elixir.py: Remove redundant get_int(row, "id") that reads non-existent column
These fixes ensure:
1. Sect headquarters display correct location names (e.g., "大千光极城" instead of "不夜城")
2. Sect techniques are correctly associated and displayed
3. Technique sect restrictions work properly
* fix: update main.py to use sect_id, add CSV loading tests
- main.py: Change technique.sect to technique.sect_id in API response
- Add tests/test_csv_loading.py to verify CSV column names match code
* test: add API test for /api/meta/game_data endpoint
Verify that techniques in API response use sect_id field (not sect)
* fix: add None check for hq_region in AvatarFactory
Remove redundant code that adds sect headquarters to known_regions.
This logic is already handled by Avatar._init_known_regions() which
uses sect_id matching (more reliable than name-based lookup).
The removed code was causing a flaky test (~1% failure rate) because
resolve_query returns None in test environments with simplified maps.