From d42810e47d7a107100634b16edabdce7602b2bd3 Mon Sep 17 00:00:00 2001 From: Neko Ayaka Date: Mon, 27 Apr 2026 16:28:36 +0800 Subject: [PATCH] chore(stage-ui): prevent using node:assert --- .../use-chat-history-scroll.test.ts | 6 +++--- .../components/scenarios/chat/utils.test.ts | 20 +++++++++---------- .../src/stores/exports.contract.test.ts | 3 +++ .../orchestrator/spark-notify.test.ts | 19 ++++++++++++++++++ 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/packages/stage-ui/src/components/scenarios/chat/composables/use-chat-history-scroll.test.ts b/packages/stage-ui/src/components/scenarios/chat/composables/use-chat-history-scroll.test.ts index 04eebf1f7..b0b194edc 100644 --- a/packages/stage-ui/src/components/scenarios/chat/composables/use-chat-history-scroll.test.ts +++ b/packages/stage-ui/src/components/scenarios/chat/composables/use-chat-history-scroll.test.ts @@ -2,8 +2,6 @@ import type { ChatHistoryItem } from '../../../../types/chat' -import assert from 'node:assert/strict' - import { afterEach, describe, expect, it, vi } from 'vitest' import { effectScope, nextTick, ref } from 'vue' @@ -253,7 +251,9 @@ describe('useChatHistoryScroll', () => { scrollIntoView.mockClear() const firstNode = container.querySelector('[data-chat-message-key="user-1"]') - assert.ok(firstNode) + expect(firstNode).not.toBeNull() + if (!firstNode) + throw new Error('Expected first chat node to exist.') firstNode.dispatchEvent(new PointerEvent('pointerover', { bubbles: true })) await flushDom() diff --git a/packages/stage-ui/src/components/scenarios/chat/utils.test.ts b/packages/stage-ui/src/components/scenarios/chat/utils.test.ts index a80f047b1..9b5c9a610 100644 --- a/packages/stage-ui/src/components/scenarios/chat/utils.test.ts +++ b/packages/stage-ui/src/components/scenarios/chat/utils.test.ts @@ -1,8 +1,6 @@ import type { ChatHistoryItem } from '../../../types/chat' -import assert from 'node:assert/strict' - -import { describe, it } from 'vitest' +import { describe, expect, it } from 'vitest' import { getChatHistoryItemKey } from './utils' @@ -13,8 +11,8 @@ describe('getChatHistoryItemKey', () => { const userMessage: ChatHistoryItem = { role: 'user', content: 'hi', createdAt, id: 'user-1' } const assistantMessage: ChatHistoryItem = { role: 'assistant', content: 'hello', createdAt, id: 'assistant-1', slices: [], tool_results: [] } - assert.equal(getChatHistoryItemKey(userMessage, 0), 'user-1') - assert.equal(getChatHistoryItemKey(assistantMessage, 1), 'assistant-1') + expect(getChatHistoryItemKey(userMessage, 0)).toBe('user-1') + expect(getChatHistoryItemKey(assistantMessage, 1)).toBe('assistant-1') }) it('falls back to a role + timestamp + index composite when ids are missing', () => { @@ -23,20 +21,20 @@ describe('getChatHistoryItemKey', () => { const userMessage: ChatHistoryItem = { role: 'user', content: 'hi', createdAt } const assistantMessage: ChatHistoryItem = { role: 'assistant', content: 'hello', createdAt, slices: [], tool_results: [] } - assert.equal(getChatHistoryItemKey(userMessage, 0), 'user:1700000000000:0') - assert.equal(getChatHistoryItemKey(assistantMessage, 1), 'assistant:1700000000000:1') + expect(getChatHistoryItemKey(userMessage, 0)).toBe('user:1700000000000:0') + expect(getChatHistoryItemKey(assistantMessage, 1)).toBe('assistant:1700000000000:1') }) it('falls back to index when message is missing', () => { - assert.equal(getChatHistoryItemKey(undefined, 0), 0) - assert.equal(getChatHistoryItemKey(undefined, 1), 1) + expect(getChatHistoryItemKey(undefined, 0)).toBe(0) + expect(getChatHistoryItemKey(undefined, 1)).toBe(1) }) it('falls back to a role + index composite when ids and timestamps are missing', () => { const userMessage: ChatHistoryItem = { role: 'user', content: 'hi' } const assistantMessage: ChatHistoryItem = { role: 'assistant', content: 'hello', slices: [], tool_results: [] } - assert.equal(getChatHistoryItemKey(userMessage, 0), 'user:0') - assert.equal(getChatHistoryItemKey(assistantMessage, 1), 'assistant:1') + expect(getChatHistoryItemKey(userMessage, 0)).toBe('user:0') + expect(getChatHistoryItemKey(assistantMessage, 1)).toBe('assistant:1') }) }) diff --git a/packages/stage-ui/src/stores/exports.contract.test.ts b/packages/stage-ui/src/stores/exports.contract.test.ts index 20b9b3062..f4e6d867e 100644 --- a/packages/stage-ui/src/stores/exports.contract.test.ts +++ b/packages/stage-ui/src/stores/exports.contract.test.ts @@ -39,10 +39,12 @@ describe('stage-ui exports contract', () => { './stores/analytics/posthog', './stores/analytics/privacy-policy', './stores/character', + './stores/character/orchestrator/spark-notify-agent', './stores/modules/vision', './stores/providers/aliyun', './stores/settings', './stores/settings/analytics', + './tools/mcp', './types', './types/*', './utils', @@ -58,6 +60,7 @@ describe('stage-ui exports contract', () => { expect(exportsMap['./stores']).toBe('./src/stores/index.ts') expect(exportsMap['./stores/*']).toBe('./src/stores/*.ts') + expect(exportsMap['./tools/mcp']).toBe('./src/tools/mcp.ts') expect(exportsMap['./types']).toBe('./src/types/index.ts') expect(exportsMap['./types/*']).toBe('./src/types/*.ts') }) diff --git a/packages/stage-ui/src/tools/character/orchestrator/spark-notify.test.ts b/packages/stage-ui/src/tools/character/orchestrator/spark-notify.test.ts index 6a31fb831..978a49912 100644 --- a/packages/stage-ui/src/tools/character/orchestrator/spark-notify.test.ts +++ b/packages/stage-ui/src/tools/character/orchestrator/spark-notify.test.ts @@ -11,6 +11,7 @@ describe('tools/character/orchestrator/spark-notify', () => { onCommands: () => undefined, }) + expect(tools).toHaveLength(2) for (const name of ['builtIn_sparkNoResponse', 'builtIn_sparkCommand']) { const entry = tools.find(tool => tool.function.name === name) expect(entry, `missing tool: ${name}`).toBeDefined() @@ -93,4 +94,22 @@ describe('tools/character/orchestrator/spark-notify', () => { expect(schema.properties).toEqual({}) expect(schema.additionalProperties).toBe(false) }) + + it('can disable no-response and spark-command tools independently', async () => { + const onlyCommand = await createSparkNotifyTools({ + onNoResponse: () => undefined, + onCommands: () => undefined, + allowNoResponse: false, + allowSparkCommand: true, + }) + expect(onlyCommand.tools.map(tool => tool.function.name)).toEqual(['builtIn_sparkCommand']) + + const none = await createSparkNotifyTools({ + onNoResponse: () => undefined, + onCommands: () => undefined, + allowNoResponse: false, + allowSparkCommand: false, + }) + expect(none.tools).toHaveLength(0) + }) })