mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-28 16:06:22 +00:00
test(frontend): repair the vitest suite and run it in CI
This commit is contained in:
@@ -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
|
||||
|
||||
+1
-1
@@ -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";')
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
@@ -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' }])
|
||||
|
||||
@@ -9,7 +9,8 @@ import {
|
||||
} from './core'
|
||||
import type { ContextElement } from '../context'
|
||||
|
||||
vi.mock('../shared', () => ({
|
||||
vi.mock('../shared', async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import('../shared')>()),
|
||||
createToolDef: (_schema: unknown, name: string, description: string) => ({
|
||||
type: 'function',
|
||||
function: {
|
||||
|
||||
@@ -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<typeof vi.fn>
|
||||
let openaiCreate: ReturnType<typeof vi.fn>
|
||||
let openaiResponsesCreate: ReturnType<typeof vi.fn>
|
||||
|
||||
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, {
|
||||
|
||||
@@ -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<string, any> = {}
|
||||
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<string, any> = {}
|
||||
// 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.
|
||||
|
||||
@@ -85,7 +85,9 @@ describe('genWmillTs', () => {
|
||||
|
||||
const dts = genWmillTs(runnables)
|
||||
|
||||
expect(dts).toContain('myflow: (args: { string_input: string }, opts?: { memoryId?: string }) => Promise<any>;')
|
||||
expect(dts).toContain(
|
||||
'myflow: (args: { string_input: string }, opts?: { memoryId?: string }) => Promise<any>;'
|
||||
)
|
||||
})
|
||||
|
||||
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<any>;')
|
||||
expect(genWmillTs(runnables)).toContain(
|
||||
'myflow: (args: { count?: number }, opts?: { memoryId?: string }) => Promise<any>;'
|
||||
)
|
||||
})
|
||||
|
||||
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))
|
||||
|
||||
@@ -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'])
|
||||
})
|
||||
|
||||
@@ -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<string, boolean>).__wmDevPollingDormancyInstalled
|
||||
vi.useRealTimers()
|
||||
vi.unstubAllEnvs()
|
||||
// restoreAllMocks does not undo stubGlobal, and the config sets no unstubGlobals.
|
||||
vi.unstubAllGlobals()
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user