fix: add validation for resourceLocator properties in AI model nodes

This fixes a critical validation gap where AI agents could create invalid
configurations for nodes using resourceLocator properties (primarily AI model
nodes like OpenAI Chat Model v1.2+, Anthropic, Cohere, etc.).

Before this fix, AI agents could incorrectly pass a string value like:
  model: "gpt-4o-mini"

Instead of the required object format:
  model: { mode: "list", value: "gpt-4o-mini" }

These invalid configs would pass validation but fail at runtime in n8n.

Changes:
- Added resourceLocator type validation in config-validator.ts (lines 237-274)
- Validates value is an object with required 'mode' and 'value' properties
- Provides helpful error messages with exact fix suggestions
- Added 10 comprehensive test cases (100% passing)
- Updated version to 2.17.3
- Added CHANGELOG entry

Affected nodes: OpenAI Chat Model (v1.2+), Anthropic, Cohere, DeepSeek,
Groq, Mistral, OpenRouter, xAI Grok Chat Models, and embeddings nodes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
czlonkowski
2025-10-07 16:54:29 +02:00
parent 3332eb09fc
commit e95ac7c335
6 changed files with 314 additions and 3 deletions

View File

@@ -5,6 +5,41 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [2.17.3] - 2025-10-07
### 🔧 Validation
**Fixed critical validation gap for AI model nodes with resourceLocator properties.**
This release adds validation for `resourceLocator` type properties, fixing a critical issue where AI agents could create invalid configurations that passed validation but failed at runtime.
#### Fixed
- **resourceLocator Property Validation**
- **Issue:** No validation existed for `resourceLocator` type properties used in AI model nodes
- **Impact:**
- AI agents could create invalid configurations like `model: "gpt-4o-mini"` (string) instead of `model: {mode: "list", value: "gpt-4o-mini"}` (object)
- Invalid configs passed validation but failed at runtime in n8n
- Affected many langchain nodes: OpenAI Chat Model (v1.2+), Anthropic, Cohere, DeepSeek, Groq, Mistral, OpenRouter, xAI Grok, and embeddings nodes
- **Root Cause:** `validatePropertyTypes()` method in ConfigValidator only validated `string`, `number`, `boolean`, and `options` types - `resourceLocator` was completely missing
- **Fix:** Added comprehensive resourceLocator validation in `config-validator.ts:237-274`
- Validates value is an object (not string, number, null, or array)
- Validates required `mode` property exists and is a string
- Validates required `value` property exists
- Provides helpful error messages with exact fix suggestions
- Example error: `Property 'model' is a resourceLocator and must be an object with 'mode' and 'value' properties, got string`
- Example fix: `Change model to { mode: "list", value: "gpt-4o-mini" } or { mode: "id", value: "gpt-4o-mini" }`
#### Added
- 10 comprehensive test cases for resourceLocator validation covering:
- String value rejection with helpful fix suggestions
- Null and array value rejection
- Missing `mode` or `value` property detection
- Invalid `mode` type detection (e.g., number instead of string)
- Valid resourceLocator acceptance for both "list" and "id" modes
- All tests passing (100% coverage for new validation logic)
## [2.17.1] - 2025-10-07
### 🔧 Telemetry