From 022526d372cb43215839e8ac265554ce11fb794c Mon Sep 17 00:00:00 2001 From: Mutasem Aldmour Date: Tue, 24 Feb 2026 15:01:52 +0100 Subject: [PATCH] fix(workflow-sdk): Use worker-specific temp dir to prevent flaky schema validation tests Multiple Jest workers running validation tests in parallel all shared the same hardcoded temp dir (os.tmpdir()/n8n-schema-tests). This caused a race condition where one worker would delete and regenerate schemas while another was reading them, causing loadSchema() to return null and INVALID_PARAMETER warnings to not be generated. Fix by suffixing the temp dir with JEST_WORKER_ID so each worker has its own isolated schema directory. Co-Authored-By: Claude Sonnet 4.6 --- .../@n8n/workflow-sdk/src/validation/test-schema-setup.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/@n8n/workflow-sdk/src/validation/test-schema-setup.ts b/packages/@n8n/workflow-sdk/src/validation/test-schema-setup.ts index b2d6e7e9fb1..f8b69cac0a8 100644 --- a/packages/@n8n/workflow-sdk/src/validation/test-schema-setup.ts +++ b/packages/@n8n/workflow-sdk/src/validation/test-schema-setup.ts @@ -14,7 +14,11 @@ import * as path from 'path'; import { setSchemaBaseDirs, getSchemaBaseDirs } from './schema-validator'; import { generateNodeDefinitions } from '../generate-types/generate-node-defs-cli'; -const SCHEMA_TEST_DIR = path.join(os.tmpdir(), 'n8n-schema-tests'); +// Use a worker-specific directory to prevent race conditions when multiple Jest +// workers run schema-using tests in parallel (they would otherwise concurrently +// delete and regenerate schemas into the same shared temp directory). +const WORKER_ID = process.env.JEST_WORKER_ID ?? '0'; +const SCHEMA_TEST_DIR = path.join(os.tmpdir(), `n8n-schema-tests-${WORKER_ID}`); const STAMP_FILE = path.join(SCHEMA_TEST_DIR, '.generator-hash'); let originalBaseDirs: string[] | undefined;