fix: update chatStore tests for sub-store refactoring
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled

Tests were referencing old monolithic useChatStore API. Updated to
use useConversationStore for conversation/agent/model state and
useChatStore for message operations. 10→0 failures.
This commit is contained in:
iven
2026-04-06 11:57:46 +08:00
parent 7f9799b7e0
commit 4a23bbeda6
2 changed files with 128 additions and 79 deletions

View File

@@ -1,18 +1,18 @@
/**
* Stabilization Core Path Tests
*
* Covers the 4 critical paths from STABILIZATION_DIRECTIVE.md §5:
* 1. Skill execution invoke no crash result
* 2. Hand trigger emit event frontend receives notification
* 3. Message sending Store invoke streaming response
* 4. Config sync SaaS pull Store update
* Covers the 4 critical paths from STABILIZATION_DIRECTIVE.md 5:
* 1. Skill execution -- invoke -> no crash -> result
* 2. Hand trigger -- emit event -> frontend receives notification
* 3. Message sending -- Store -> invoke -> streaming response
* 4. Config sync -- SaaS pull -> Store update
*/
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { invoke } from '@tauri-apps/api/core';
import { useChatStore, type Message } from '../src/store/chatStore';
// ─── Shared mocks ───
// --- Shared mocks ---
vi.mock('@tauri-apps/api/core', () => ({
invoke: vi.fn(),
@@ -114,11 +114,23 @@ vi.mock('../src/store/chat/conversationStore', () => {
sessionKey: 'test-session-1',
currentModel: 'default',
conversations: [],
currentConversationId: null,
agents: [{ id: 'test-agent-1', name: 'Test Agent' }],
};
return {
useConversationStore: {
getState: () => state,
setState: vi.fn((partial: Record<string, unknown>) => {
if (typeof partial === 'function') {
Object.assign(state, partial(state));
} else {
Object.assign(state, partial);
}
}),
subscribe: vi.fn(),
persist: {
hasHydrated: () => true,
},
...(Object.fromEntries(
Object.keys(state).map((k) => [k, vi.fn()])
)),
@@ -126,7 +138,7 @@ vi.mock('../src/store/chat/conversationStore', () => {
};
});
// ─── 1. Skill Execution ───
// --- 1. Skill Execution ---
describe('Skill execution (SEC2-P0-01)', () => {
beforeEach(() => {
@@ -182,7 +194,7 @@ describe('Skill execution (SEC2-P0-01)', () => {
});
});
// ─── 2. Hand Trigger Event ───
// --- 2. Hand Trigger Event ---
describe('Hand execution event (SEC2-P1-03)', () => {
it('should add hand message to chatStore when hand-execution-complete is received', () => {
@@ -237,7 +249,7 @@ describe('Hand execution event (SEC2-P1-03)', () => {
});
});
// ─── 3. Message Sending ───
// --- 3. Message Sending ---
describe('Message sending flow', () => {
beforeEach(() => {
@@ -304,9 +316,9 @@ describe('Message sending flow', () => {
});
});
// ─── 4. Config Sync ───
// --- 4. Config Sync ---
describe('Config sync (SaaS Store)', () => {
describe('Config sync (SaaS to Store)', () => {
it('should invoke saas-client with correct /api/v1 prefix for templates', async () => {
vi.mocked(invoke).mockResolvedValueOnce([]);
@@ -321,7 +333,7 @@ describe('Config sync (SaaS → Store)', () => {
});
it('should handle store update cycle correctly', () => {
// Simulate a config sync: external data arrives store updates
// Simulate a config sync: external data arrives -> store updates
useChatStore.setState({ isStreaming: false });
expect(useChatStore.getState().isStreaming).toBe(false);