diff --git a/.github/workflows/frontend-check.yml b/.github/workflows/frontend-check.yml index 0a70c8dd05..8fcfe40127 100644 --- a/.github/workflows/frontend-check.yml +++ b/.github/workflows/frontend-check.yml @@ -30,3 +30,16 @@ jobs: NODE_OPTIONS: --max-old-space-size=8192 run: cd frontend && npm ci && npm run lint && npm run generate-backend-client && npm run check + + unit_tests: + runs-on: ubicloud-standard-8 + steps: + - uses: actions/checkout@v4.4.0 + - uses: actions/setup-node@v7.1.0 + with: + node-version: 24 + cache: "npm" + cache-dependency-path: "frontend/package-lock.json" + - name: "vitest" + timeout-minutes: 10 + run: cd frontend && npm ci && npm run generate-backend-client && npx vitest run diff --git a/frontend/src/lib/components/apps/components/display/dbtable/queries/alterTable.test.ts b/frontend/src/lib/components/apps/components/display/dbtable/queries/alterTable.test.ts index e7dde31597..63e72a8eef 100644 --- a/frontend/src/lib/components/apps/components/display/dbtable/queries/alterTable.test.ts +++ b/frontend/src/lib/components/apps/components/display/dbtable/queries/alterTable.test.ts @@ -179,7 +179,7 @@ describe('makeAlterTableQueries', () => { ) expect(normalize(queries[0])).toBe( - normalize('ALTER TABLE posts DROP CONSTRAINT fk_posts_user;') + normalize('ALTER TABLE posts DROP CONSTRAINT "fk_posts_user";') ) }) diff --git a/frontend/src/lib/components/copilot/chat/ContextManager.test.ts b/frontend/src/lib/components/copilot/chat/ContextManager.test.ts index cefa894255..9944bb8704 100644 --- a/frontend/src/lib/components/copilot/chat/ContextManager.test.ts +++ b/frontend/src/lib/components/copilot/chat/ContextManager.test.ts @@ -22,6 +22,8 @@ vi.mock('$lib/editorLangUtils', () => ({ langToExt: () => 'ts' })) +import ContextManager from './ContextManager.svelte' + describe('ContextManager', () => { beforeEach(() => { listResource.mockReset() @@ -29,7 +31,7 @@ describe('ContextManager', () => { const scriptOptions = { lang: 'bun' as const, - code: 'export async function main() {}', + getCode: () => 'export async function main() {}', error: undefined, args: {}, path: 'f/scripts/example', @@ -37,7 +39,6 @@ describe('ContextManager', () => { } it('loads db resources when switching from global to script in the same workspace', async () => { - const { default: ContextManager } = await import('./ContextManager.svelte') const manager = new ContextManager() listResource.mockResolvedValueOnce([{ path: 'f/db/main' }]) @@ -54,7 +55,6 @@ describe('ContextManager', () => { }) it('refreshes db resources after switching workspaces through global mode', async () => { - const { default: ContextManager } = await import('./ContextManager.svelte') const manager = new ContextManager() listResource .mockResolvedValueOnce([{ path: 'f/db/workspace-a' }]) diff --git a/frontend/src/lib/components/copilot/chat/app/core.test.ts b/frontend/src/lib/components/copilot/chat/app/core.test.ts index edd0797c83..6a50932660 100644 --- a/frontend/src/lib/components/copilot/chat/app/core.test.ts +++ b/frontend/src/lib/components/copilot/chat/app/core.test.ts @@ -9,7 +9,8 @@ import { } from './core' import type { ContextElement } from '../context' -vi.mock('../shared', () => ({ +vi.mock('../shared', async (importOriginal) => ({ + ...(await importOriginal()), createToolDef: (_schema: unknown, name: string, description: string) => ({ type: 'function', function: { diff --git a/frontend/src/lib/components/copilot/lib.anthropicRouting.test.ts b/frontend/src/lib/components/copilot/lib.anthropicRouting.test.ts index 52d58863c6..5c7a00e31c 100644 --- a/frontend/src/lib/components/copilot/lib.anthropicRouting.test.ts +++ b/frontend/src/lib/components/copilot/lib.anthropicRouting.test.ts @@ -62,6 +62,19 @@ vi.mock('@leeoniya/ufuzzy', () => ({ } })) +import { + getCompletion, + getFimCompletion, + getModelMaxTokens, + getNonStreamingCompletion, + getNonStreamingMetadataCompletion, + getResponseFromEvent, + getStreamedCompletionText, + METADATA_MAX_TOKENS, + testKey, + workspaceAIClients +} from './lib' + function streamOf(chunks: unknown[]): any { return (async function* () { for (const chunk of chunks) { @@ -81,9 +94,7 @@ let anthropicStream: ReturnType let openaiCreate: ReturnType let openaiResponsesCreate: ReturnType -async function setupClients() { - const { workspaceAIClients } = await import('./lib') - +function setupClients() { anthropicCreate = vi.fn().mockResolvedValue({ content: [ { type: 'text', text: 'Hel' }, @@ -115,9 +126,7 @@ async function setupClients() { } as any) } -beforeEach(async () => { - await setupClients() -}) +beforeEach(setupClients) afterEach(() => { vi.restoreAllMocks() @@ -126,7 +135,6 @@ afterEach(() => { describe('Anthropic Messages API routing', () => { it('getNonStreamingCompletion routes Foundry Claude through the Anthropic client', async () => { - const { getNonStreamingCompletion } = await import('./lib') h.currentModel = { provider: 'azure_foundry', model: 'claude-sonnet-5' } const response = await getNonStreamingCompletion(messages, new AbortController()) @@ -143,7 +151,6 @@ describe('Anthropic Messages API routing', () => { }) it('getNonStreamingCompletion routes native Anthropic through the Anthropic client', async () => { - const { getNonStreamingCompletion } = await import('./lib') h.currentModel = { provider: 'anthropic', model: 'claude-opus-4-8' } await getNonStreamingCompletion(messages, new AbortController()) @@ -153,7 +160,6 @@ describe('Anthropic Messages API routing', () => { }) it('getNonStreamingCompletion keeps non-Claude Foundry models on the OpenAI path', async () => { - const { getNonStreamingCompletion } = await import('./lib') h.currentModel = { provider: 'azure_foundry', model: 'gpt-4o' } await getNonStreamingCompletion(messages, new AbortController()) @@ -163,7 +169,6 @@ describe('Anthropic Messages API routing', () => { }) it('getCompletion adapts the Anthropic stream into OpenAI text chunks', async () => { - const { getCompletion, getResponseFromEvent } = await import('./lib') h.currentModel = { provider: 'azure_foundry', model: 'claude-sonnet-5' } const completion = await getCompletion(messages, new AbortController()) @@ -183,8 +188,6 @@ describe('Anthropic Messages API routing', () => { }) it('testKey routes Foundry Claude through the Anthropic client', async () => { - const { testKey } = await import('./lib') - await testKey({ resourcePath: 'u/admin/foundry', model: 'claude-sonnet-5', @@ -200,7 +203,6 @@ describe('Anthropic Messages API routing', () => { }) it('raises the Claude output budget only from Opus 4.5 on', async () => { - const { getModelMaxTokens } = await import('./lib') // 4.5+ matches Sonnet's budget... for (const model of ['claude-opus-4-5', 'claude-opus-4-8', 'claude-opus-5']) { expect(getModelMaxTokens('anthropic', model)).toBe(64000) @@ -214,8 +216,6 @@ describe('Anthropic Messages API routing', () => { }) it('caps max_tokens for metadata completions so the Anthropic SDK stays non-streaming', async () => { - const { getNonStreamingCompletion, getNonStreamingMetadataCompletion, METADATA_MAX_TOKENS } = - await import('./lib') // claude-sonnet defaults to 64000 max_tokens; the Anthropic SDK refuses a // non-streaming request that large (>10min worst case), which silently broke // session auto-rename and the other metadata generators. @@ -231,8 +231,6 @@ describe('Anthropic Messages API routing', () => { }) it('getStreamedCompletionText streams the capped request and falls back off the Responses API', async () => { - const { getStreamedCompletionText, workspaceAIClients } = await import('./lib') - h.currentModel = { provider: 'anthropic', model: 'claude-sonnet-4-6' } expect( await getStreamedCompletionText(messages, new AbortController(), { maxTokensCap: 8000 }) @@ -287,7 +285,6 @@ describe('Anthropic Messages API routing', () => { }) it('getStreamedCompletionText rejects when the stream is cut or stopped midway', async () => { - const { getStreamedCompletionText } = await import('./lib') h.currentModel = { provider: 'deepseek', model: 'deepseek-chat' } // A hop closing the response early ends the iteration cleanly, with no @@ -312,8 +309,6 @@ describe('Anthropic Messages API routing', () => { }) it('caps max_output_tokens for metadata completions on the OpenAI Responses path', async () => { - const { getNonStreamingCompletion, getNonStreamingMetadataCompletion, METADATA_MAX_TOKENS } = - await import('./lib') // OpenAI/Azure non-streaming routes through the Responses API; the cap must // reach it too, not just the Anthropic and chat.completions paths. h.currentModel = { provider: 'openai', model: 'gpt-4o' } @@ -328,7 +323,6 @@ describe('Anthropic Messages API routing', () => { }) it('getFimCompletion no-ops for Anthropic Messages API models', async () => { - const { getFimCompletion } = await import('./lib') const fetchSpy = vi.spyOn(globalThis, 'fetch') for (const provider of ['anthropic', 'azure_foundry'] as const) { @@ -362,7 +356,6 @@ describe('OpenRouter prompt caching', () => { it.each(['anthropic/claude-sonnet-5', '~anthropic/claude-sonnet-latest'])( 'breaks on the system prompt and the newest user turn for %s', async (model) => { - const { getCompletion } = await import('./lib') h.currentModel = { provider: 'openrouter', model } await getCompletion([...conversation], new AbortController(), undefined, { @@ -383,7 +376,6 @@ describe('OpenRouter prompt caching', () => { ) it('leaves other OpenRouter upstreams alone', async () => { - const { getCompletion } = await import('./lib') h.currentModel = { provider: 'openrouter', model: 'openai/gpt-5.1' } await getCompletion([...conversation], new AbortController(), undefined, { diff --git a/frontend/src/lib/components/copilot/lib.toolCalls.test.ts b/frontend/src/lib/components/copilot/lib.toolCalls.test.ts index b5bd24d6fa..fea7075195 100644 --- a/frontend/src/lib/components/copilot/lib.toolCalls.test.ts +++ b/frontend/src/lib/components/copilot/lib.toolCalls.test.ts @@ -59,6 +59,8 @@ vi.mock('@leeoniya/ufuzzy', () => ({ } })) +import { getCompletion, getModelMaxTokens, parseOpenAICompletion } from './lib' + function streamOf(chunks: unknown[]): any { return (async function* () { for (const chunk of chunks) { @@ -92,7 +94,6 @@ function createTool(fn = vi.fn().mockResolvedValue('tool ok')) { describe('parseOpenAICompletion tool call arguments', () => { it('does not execute nor persist a tool call whose streamed arguments are truncated', async () => { - const { parseOpenAICompletion } = await import('./lib') const fn = vi.fn() const callbacks = createCallbacks() const messages: ChatCompletionMessageParam[] = [] @@ -135,7 +136,6 @@ describe('parseOpenAICompletion tool call arguments', () => { }) it('keeps braces inside string arguments out of the object-depth count', async () => { - const { parseOpenAICompletion } = await import('./lib') const fn = vi.fn().mockResolvedValue('tool ok') const messages: ChatCompletionMessageParam[] = [] @@ -166,7 +166,6 @@ describe('parseOpenAICompletion tool call arguments', () => { }) it('marks only the executing tool call as loading when one message has several', async () => { - const { parseOpenAICompletion } = await import('./lib') const statuses: Record = {} const callbacks = createCallbacks() callbacks.setToolStatus.mockImplementation((id: string, patch: any) => { @@ -215,7 +214,6 @@ describe('parseOpenAICompletion tool call arguments', () => { }) it('never leaves a call both queued and loading when deltas interleave', async () => { - const { parseOpenAICompletion } = await import('./lib') const statuses: Record = {} // Merged state after every patch: a call demoted to queued then re-promoted // by an interleaved delta must never keep both flags set at once. @@ -255,7 +253,6 @@ describe('parseOpenAICompletion tool call arguments', () => { }) it('executes a tool call with valid streamed arguments and keeps them verbatim', async () => { - const { parseOpenAICompletion } = await import('./lib') const fn = vi.fn().mockResolvedValue('tool ok') const messages: ChatCompletionMessageParam[] = [] @@ -288,7 +285,6 @@ describe('parseOpenAICompletion tool call arguments', () => { describe('output token limit', () => { it('follows the model through every host that serves it', async () => { - const { getModelMaxTokens } = await import('./lib') expect(getModelMaxTokens('deepseek', 'deepseek-flash')).toBe(131072) expect(getModelMaxTokens('azure_foundry', 'DeepSeek-V4-Pro')).toBe(131072) expect(getModelMaxTokens('openrouter', 'deepseek/deepseek-v4-pro')).toBe(131072) @@ -300,7 +296,6 @@ describe('output token limit', () => { }) it('gives a model outside the table room to think only when the request asks it to', async () => { - const { getModelMaxTokens } = await import('./lib') expect(getModelMaxTokens('openrouter', 'x-ai/grok-4.3', 'high')).toBe(32768) expect(getModelMaxTokens('openrouter', 'x-ai/grok-4.3', 'none')).toBe(8192) expect(getModelMaxTokens('openrouter', 'x-ai/grok-4.3')).toBe(8192) @@ -316,7 +311,6 @@ describe('output token limit', () => { }) it('sizes the budget from the effort the same request carries', async () => { - const { getCompletion } = await import('./lib') const create = vi.fn() await getCompletion([], new AbortController(), undefined, { @@ -329,7 +323,6 @@ describe('output token limit', () => { }) it('fails a response cut off at the output token limit instead of ending the turn', async () => { - const { parseOpenAICompletion } = await import('./lib') const { OutputTokenLimitError } = await import('./chat/outputTokenLimit') // Thinking counts toward max_tokens, so the cap can land before any answer. diff --git a/frontend/src/lib/components/raw_apps/utils.test.ts b/frontend/src/lib/components/raw_apps/utils.test.ts index dd55ea666c..e6ea2b6eeb 100644 --- a/frontend/src/lib/components/raw_apps/utils.test.ts +++ b/frontend/src/lib/components/raw_apps/utils.test.ts @@ -85,7 +85,9 @@ describe('genWmillTs', () => { const dts = genWmillTs(runnables) - expect(dts).toContain('myflow: (args: { string_input: string }, opts?: { memoryId?: string }) => Promise;') + expect(dts).toContain( + 'myflow: (args: { string_input: string }, opts?: { memoryId?: string }) => Promise;' + ) }) it('leaves ctx fields out of the args type, the server fills them', () => { @@ -102,7 +104,9 @@ describe('genWmillTs', () => { } } - expect(genWmillTs(runnables)).toContain('myflow: (args: { count?: number }, opts?: { memoryId?: string }) => Promise;') + expect(genWmillTs(runnables)).toContain( + 'myflow: (args: { count?: number }, opts?: { memoryId?: string }) => Promise;' + ) }) it('quotes flow input names that are not valid identifiers', () => { @@ -268,7 +272,8 @@ describe('canonicalRawAppDiffValue', () => { files: { '/App.tsx': 'export default 1' }, runnables: { a: { type: 'inline', inlineScript: { content: 'main()', language: 'bun' } } }, data: { tables: [] }, - policy: { execution_mode: 'publisher' } + policy: { execution_mode: 'publisher' }, + parent_version: 2 } expect(canonicalRawAppDiffValue(deployed)).toEqual(canonicalRawAppDiffValue(draft)) diff --git a/frontend/src/lib/components/sessions/sessionSharing.test.ts b/frontend/src/lib/components/sessions/sessionSharing.test.ts index a7720666fa..0e775ddecb 100644 --- a/frontend/src/lib/components/sessions/sessionSharing.test.ts +++ b/frontend/src/lib/components/sessions/sessionSharing.test.ts @@ -48,7 +48,8 @@ describe('readSessionSnapshot', () => { content: 'Run', showDetails: false, blockedByPlanMode: false, - declinedByUser: false + declinedByUser: false, + readsAgent: false }) expect(snapshot.artifacts.map((a) => a.id)).toEqual(['a']) }) diff --git a/frontend/src/lib/utils/devPollingDormancy.dom.test.ts b/frontend/src/lib/utils/devPollingDormancy.dom.test.ts index 8e8c852753..be52d2356a 100644 --- a/frontend/src/lib/utils/devPollingDormancy.dom.test.ts +++ b/frontend/src/lib/utils/devPollingDormancy.dom.test.ts @@ -23,11 +23,13 @@ describe('devPollingDormancy', () => { }) afterEach(() => { + // `window` is `globalThis` here. useRealTimers deletes any timer global it did not install + // itself, so restoring before it would leave Node with no `clearInterval` for jsdom's teardown. + vi.useRealTimers() window.setInterval = original.setInterval window.clearInterval = original.clearInterval // The install guard lives on `window`, so it is part of the global state to restore. delete (window as unknown as Record).__wmDevPollingDormancyInstalled - vi.useRealTimers() vi.unstubAllEnvs() // restoreAllMocks does not undo stubGlobal, and the config sets no unstubGlobals. vi.unstubAllGlobals() diff --git a/frontend/src/lib/utils_workspace_deploy.test.ts b/frontend/src/lib/utils_workspace_deploy.test.ts index 5db05d041a..99fefb2aea 100644 --- a/frontend/src/lib/utils_workspace_deploy.test.ts +++ b/frontend/src/lib/utils_workspace_deploy.test.ts @@ -275,11 +275,12 @@ describe('scoping a refusal to the kinds the server gates', () => { 'resource', 'resource_type', 'variable', - 'folder' + 'folder', + 'data_pipeline' ] as const) { expect(kindGatedByDeployRules(k)).toBe(true) } - for (const k of ['schedule', 'http_trigger', 'email_trigger', 'data_pipeline'] as const) { + for (const k of ['schedule', 'http_trigger', 'email_trigger'] as const) { expect(kindGatedByDeployRules(k)).toBe(false) } })