mirror of
https://github.com/n8n-io/n8n.git
synced 2026-06-04 10:39:23 +02:00
test: Stabilize AI unit tests against cold heavy-load timeouts (#31592)
Co-authored-by: n8n-cat-bot[bot] <n8n-cat-bot[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
e8089b4ec7
commit
098fcb39cb
|
|
@ -1,5 +1,6 @@
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||
import { encodingForModel } from 'src/utils/tokenizer/tiktoken';
|
||||
import {
|
||||
estimateTokensByCharCount,
|
||||
estimateTextSplitsByTokens,
|
||||
|
|
@ -7,6 +8,15 @@ import {
|
|||
} from 'src/utils/tokenizer/token-estimator';
|
||||
|
||||
describe('token-estimator', () => {
|
||||
// Warm both BPE encodings before the timed test bodies. `cl100k_base` (gpt-4) is ~1 MB and
|
||||
// `o200k_base` (gpt-4o) is ~2.2 MB; the first test that touches a fresh encoding pays a
|
||||
// readFile + jsonParse + 200k-entry Tiktoken construct that under CI CPU contention can
|
||||
// exceed the default 5s per-test timeout. Scope the headroom to this hook so the default
|
||||
// per-test timeout still guards every other test in the file.
|
||||
beforeAll(async () => {
|
||||
await Promise.all([encodingForModel('gpt-4'), encodingForModel('gpt-4o')]);
|
||||
}, 30_000);
|
||||
|
||||
describe('estimateTokensByCharCount', () => {
|
||||
it('should estimate tokens for text using default model', () => {
|
||||
const text = 'This is a test text with some content.';
|
||||
|
|
|
|||
|
|
@ -77,6 +77,13 @@ vi.mock('../lifecycles/introspection-analysis', () => ({
|
|||
createIntrospectionAnalysisLifecycle: () => ({}),
|
||||
}));
|
||||
|
||||
// Stub the code-builder module so importing `../cli` doesn't drag in the heavy
|
||||
// langchain / workflow-builder graph. `runEvaluation` is mocked below, so the
|
||||
// generation path never actually invokes `CodeWorkflowBuilder`.
|
||||
vi.mock('@/code-builder', () => ({
|
||||
CodeWorkflowBuilder: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../index', () => ({
|
||||
runEvaluation: (...args: unknown[]): unknown => mockRunEvaluation(...args),
|
||||
createConsoleLifecycle: (...args: unknown[]): unknown => mockCreateConsoleLifecycle(...args),
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user