mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-01-30 06:22:04 +00:00
* docs: Update CLAUDE.md with development notes * chore: update n8n to v1.116.2 - Updated n8n from 1.115.2 to 1.116.2 - Updated n8n-core from 1.114.0 to 1.115.1 - Updated n8n-workflow from 1.112.0 to 1.113.0 - Updated @n8n/n8n-nodes-langchain from 1.114.1 to 1.115.1 - Rebuilt node database with 542 nodes - Updated version to 2.20.7 - Updated n8n version badge in README - All changes will be validated in CI with full test suite Conceived by Romuald Członkowski - www.aiadvisors.pl/en 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: regenerate package-lock.json to sync with updated dependencies Fixes CI failure caused by package-lock.json being out of sync with the updated n8n dependencies. - Regenerated with npm install to ensure all dependency versions match - Resolves "npm ci" sync errors in CI pipeline 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: align FTS5 tests with production boosting logic Tests were failing because they used raw FTS5 ranking instead of the exact-match boosting logic that production uses. Updated both test files to replicate production search behavior from src/mcp/server.ts. - Updated node-fts5-search.test.ts to use production boosting - Updated database-population.test.ts to use production boosting - Both tests now use JOIN + CASE statement for exact-match prioritization This makes tests more accurate and less brittle to FTS5 ranking changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: prioritize exact matches in FTS5 search with case-insensitive comparison Root cause: SQL ORDER BY was sorting by FTS5 rank first, then CASE statement. Since ranks are unique, the CASE boosting never applied. Additionally, the CASE statement used case-sensitive comparison which failed to match nodes like "Webhook" when searching for "webhook". Changes: - Changed ORDER BY from "rank, CASE" to "CASE, rank" in production code - Added LOWER() for case-insensitive exact match detection - Updated both test files to match the corrected SQL logic - Exact matches now consistently rank first regardless of FTS5 score Impact: - Improves search quality by ensuring exact matches appear first - More efficient SQL (less JavaScript sorting needed) - Tests now accurately validate production search behavior - Fixes 2/705 failing integration tests Verified: - Both tests pass locally after fix - SQL query tested with SQLite CLI showing webhook ranks 1st 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * docs: update CHANGELOG with FTS5 search fix details Added comprehensive documentation for the FTS5 search ranking bug fix: - Problem description with SQL examples showing wrong ORDER BY - Root cause analysis explaining why CASE statement never applied - Case-sensitivity issue details - Complete fix description for production code and tests - Impact section covering search quality, performance, and testing - Verified search results showing exact matches ranking first This documents the critical bug fix that ensures exact matches appear first in search results (webhook, http, code, etc.) with case-insensitive matching. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
309 lines
11 KiB
TypeScript
309 lines
11 KiB
TypeScript
/**
|
|
* CI validation tests - validates committed database in repository
|
|
*
|
|
* Purpose: Every PR should validate the database currently committed in git
|
|
* - Database is updated via n8n updates (see MEMORY_N8N_UPDATE.md)
|
|
* - CI always checks the committed database passes validation
|
|
* - If database missing from repo, tests FAIL (critical issue)
|
|
*
|
|
* Tests verify:
|
|
* 1. Database file exists in repo
|
|
* 2. All tables are populated
|
|
* 3. FTS5 index is synchronized
|
|
* 4. Critical searches work
|
|
* 5. Performance baselines met
|
|
*/
|
|
import { describe, it, expect, beforeAll } from 'vitest';
|
|
import { createDatabaseAdapter } from '../../../src/database/database-adapter';
|
|
import { NodeRepository } from '../../../src/database/node-repository';
|
|
import * as fs from 'fs';
|
|
|
|
// Database path - must be committed to git
|
|
const dbPath = './data/nodes.db';
|
|
const dbExists = fs.existsSync(dbPath);
|
|
|
|
describe('CI Database Population Validation', () => {
|
|
// First test: Database must exist in repository
|
|
it('[CRITICAL] Database file must exist in repository', () => {
|
|
expect(dbExists,
|
|
`CRITICAL: Database not found at ${dbPath}! ` +
|
|
'Database must be committed to git. ' +
|
|
'If this is a fresh checkout, the database is missing from the repository.'
|
|
).toBe(true);
|
|
});
|
|
});
|
|
|
|
// Only run remaining tests if database exists
|
|
describe.skipIf(!dbExists)('Database Content Validation', () => {
|
|
let db: any;
|
|
let repository: NodeRepository;
|
|
|
|
beforeAll(async () => {
|
|
// ALWAYS use production database path for CI validation
|
|
// Ignore NODE_DB_PATH env var which might be set to :memory: by vitest
|
|
db = await createDatabaseAdapter(dbPath);
|
|
repository = new NodeRepository(db);
|
|
console.log('✅ Database found - running validation tests');
|
|
});
|
|
|
|
describe('[CRITICAL] Database Must Have Data', () => {
|
|
it('MUST have nodes table populated', () => {
|
|
const count = db.prepare('SELECT COUNT(*) as count FROM nodes').get();
|
|
|
|
expect(count.count,
|
|
'CRITICAL: nodes table is EMPTY! Run: npm run rebuild'
|
|
).toBeGreaterThan(0);
|
|
|
|
expect(count.count,
|
|
`WARNING: Expected at least 500 nodes, got ${count.count}. Check if both n8n packages were loaded.`
|
|
).toBeGreaterThanOrEqual(500);
|
|
});
|
|
|
|
it('MUST have FTS5 table created', () => {
|
|
const result = db.prepare(`
|
|
SELECT name FROM sqlite_master
|
|
WHERE type='table' AND name='nodes_fts'
|
|
`).get();
|
|
|
|
expect(result,
|
|
'CRITICAL: nodes_fts FTS5 table does NOT exist! Schema is outdated. Run: npm run rebuild'
|
|
).toBeDefined();
|
|
});
|
|
|
|
it('MUST have FTS5 index populated', () => {
|
|
const ftsCount = db.prepare('SELECT COUNT(*) as count FROM nodes_fts').get();
|
|
|
|
expect(ftsCount.count,
|
|
'CRITICAL: FTS5 index is EMPTY! Searches will return zero results. Run: npm run rebuild'
|
|
).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('MUST have FTS5 synchronized with nodes', () => {
|
|
const nodesCount = db.prepare('SELECT COUNT(*) as count FROM nodes').get();
|
|
const ftsCount = db.prepare('SELECT COUNT(*) as count FROM nodes_fts').get();
|
|
|
|
expect(ftsCount.count,
|
|
`CRITICAL: FTS5 out of sync! nodes: ${nodesCount.count}, FTS5: ${ftsCount.count}. Run: npm run rebuild`
|
|
).toBe(nodesCount.count);
|
|
});
|
|
});
|
|
|
|
describe('[CRITICAL] Production Search Scenarios Must Work', () => {
|
|
const criticalSearches = [
|
|
{ term: 'webhook', expectedNode: 'nodes-base.webhook', description: 'webhook node (39.6% user adoption)' },
|
|
{ term: 'merge', expectedNode: 'nodes-base.merge', description: 'merge node (10.7% user adoption)' },
|
|
{ term: 'code', expectedNode: 'nodes-base.code', description: 'code node (59.5% user adoption)' },
|
|
{ term: 'http', expectedNode: 'nodes-base.httpRequest', description: 'http request node (55.1% user adoption)' },
|
|
{ term: 'split', expectedNode: 'nodes-base.splitInBatches', description: 'split in batches node' },
|
|
];
|
|
|
|
criticalSearches.forEach(({ term, expectedNode, description }) => {
|
|
it(`MUST find ${description} via FTS5 search`, () => {
|
|
const results = db.prepare(`
|
|
SELECT node_type FROM nodes_fts
|
|
WHERE nodes_fts MATCH ?
|
|
`).all(term);
|
|
|
|
expect(results.length,
|
|
`CRITICAL: FTS5 search for "${term}" returned ZERO results! This was a production failure case.`
|
|
).toBeGreaterThan(0);
|
|
|
|
const nodeTypes = results.map((r: any) => r.node_type);
|
|
expect(nodeTypes,
|
|
`CRITICAL: Expected node "${expectedNode}" not found in FTS5 search results for "${term}"`
|
|
).toContain(expectedNode);
|
|
});
|
|
|
|
it(`MUST find ${description} via LIKE fallback search`, () => {
|
|
const results = db.prepare(`
|
|
SELECT node_type FROM nodes
|
|
WHERE node_type LIKE ? OR display_name LIKE ? OR description LIKE ?
|
|
`).all(`%${term}%`, `%${term}%`, `%${term}%`);
|
|
|
|
expect(results.length,
|
|
`CRITICAL: LIKE search for "${term}" returned ZERO results! Fallback is broken.`
|
|
).toBeGreaterThan(0);
|
|
|
|
const nodeTypes = results.map((r: any) => r.node_type);
|
|
expect(nodeTypes,
|
|
`CRITICAL: Expected node "${expectedNode}" not found in LIKE search results for "${term}"`
|
|
).toContain(expectedNode);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('[REQUIRED] All Tables Must Be Populated', () => {
|
|
it('MUST have both n8n-nodes-base and langchain nodes', () => {
|
|
const baseNodesCount = db.prepare(`
|
|
SELECT COUNT(*) as count FROM nodes
|
|
WHERE package_name = 'n8n-nodes-base'
|
|
`).get();
|
|
|
|
const langchainNodesCount = db.prepare(`
|
|
SELECT COUNT(*) as count FROM nodes
|
|
WHERE package_name = '@n8n/n8n-nodes-langchain'
|
|
`).get();
|
|
|
|
expect(baseNodesCount.count,
|
|
'CRITICAL: No n8n-nodes-base nodes found! Package loading failed.'
|
|
).toBeGreaterThan(400); // Should have ~438 nodes
|
|
|
|
expect(langchainNodesCount.count,
|
|
'CRITICAL: No langchain nodes found! Package loading failed.'
|
|
).toBeGreaterThan(90); // Should have ~98 nodes
|
|
});
|
|
|
|
it('MUST have AI tools identified', () => {
|
|
const aiToolsCount = db.prepare(`
|
|
SELECT COUNT(*) as count FROM nodes
|
|
WHERE is_ai_tool = 1
|
|
`).get();
|
|
|
|
expect(aiToolsCount.count,
|
|
'WARNING: No AI tools found. Check AI tool detection logic.'
|
|
).toBeGreaterThan(260); // Should have ~269 AI tools
|
|
});
|
|
|
|
it('MUST have trigger nodes identified', () => {
|
|
const triggersCount = db.prepare(`
|
|
SELECT COUNT(*) as count FROM nodes
|
|
WHERE is_trigger = 1
|
|
`).get();
|
|
|
|
expect(triggersCount.count,
|
|
'WARNING: No trigger nodes found. Check trigger detection logic.'
|
|
).toBeGreaterThan(100); // Should have ~108 triggers
|
|
});
|
|
|
|
it('MUST have templates table (optional but recommended)', () => {
|
|
const templatesCount = db.prepare('SELECT COUNT(*) as count FROM templates').get();
|
|
|
|
if (templatesCount.count === 0) {
|
|
console.warn('WARNING: No workflow templates found. Run: npm run fetch:templates');
|
|
}
|
|
// This is not critical, so we don't fail the test
|
|
expect(templatesCount.count).toBeGreaterThanOrEqual(0);
|
|
});
|
|
});
|
|
|
|
describe('[VALIDATION] FTS5 Triggers Must Be Active', () => {
|
|
it('MUST have all FTS5 triggers created', () => {
|
|
const triggers = db.prepare(`
|
|
SELECT name FROM sqlite_master
|
|
WHERE type='trigger' AND name LIKE 'nodes_fts_%'
|
|
`).all();
|
|
|
|
expect(triggers.length,
|
|
'CRITICAL: FTS5 triggers are missing! Index will not stay synchronized.'
|
|
).toBe(3);
|
|
|
|
const triggerNames = triggers.map((t: any) => t.name);
|
|
expect(triggerNames).toContain('nodes_fts_insert');
|
|
expect(triggerNames).toContain('nodes_fts_update');
|
|
expect(triggerNames).toContain('nodes_fts_delete');
|
|
});
|
|
|
|
it('MUST have FTS5 index properly ranked', () => {
|
|
const results = db.prepare(`
|
|
SELECT
|
|
n.node_type,
|
|
rank
|
|
FROM nodes n
|
|
JOIN nodes_fts ON n.rowid = nodes_fts.rowid
|
|
WHERE nodes_fts MATCH 'webhook'
|
|
ORDER BY
|
|
CASE
|
|
WHEN LOWER(n.display_name) = LOWER('webhook') THEN 0
|
|
WHEN LOWER(n.display_name) LIKE LOWER('%webhook%') THEN 1
|
|
WHEN LOWER(n.node_type) LIKE LOWER('%webhook%') THEN 2
|
|
ELSE 3
|
|
END,
|
|
rank
|
|
LIMIT 5
|
|
`).all();
|
|
|
|
expect(results.length,
|
|
'CRITICAL: FTS5 ranking not working. Search quality will be degraded.'
|
|
).toBeGreaterThan(0);
|
|
|
|
// Exact match should be in top results (using production boosting logic with CASE-first ordering)
|
|
const topNodes = results.slice(0, 3).map((r: any) => r.node_type);
|
|
expect(topNodes,
|
|
'WARNING: Exact match "nodes-base.webhook" not in top 3 ranked results'
|
|
).toContain('nodes-base.webhook');
|
|
});
|
|
});
|
|
|
|
describe('[PERFORMANCE] Search Performance Baseline', () => {
|
|
it('FTS5 search should be fast (< 100ms for simple query)', () => {
|
|
const start = Date.now();
|
|
|
|
db.prepare(`
|
|
SELECT node_type FROM nodes_fts
|
|
WHERE nodes_fts MATCH 'webhook'
|
|
LIMIT 20
|
|
`).all();
|
|
|
|
const duration = Date.now() - start;
|
|
|
|
if (duration > 100) {
|
|
console.warn(`WARNING: FTS5 search took ${duration}ms (expected < 100ms). Database may need optimization.`);
|
|
}
|
|
|
|
expect(duration).toBeLessThan(1000); // Hard limit: 1 second
|
|
});
|
|
|
|
it('LIKE search should be reasonably fast (< 500ms for simple query)', () => {
|
|
const start = Date.now();
|
|
|
|
db.prepare(`
|
|
SELECT node_type FROM nodes
|
|
WHERE node_type LIKE ? OR display_name LIKE ? OR description LIKE ?
|
|
LIMIT 20
|
|
`).all('%webhook%', '%webhook%', '%webhook%');
|
|
|
|
const duration = Date.now() - start;
|
|
|
|
if (duration > 500) {
|
|
console.warn(`WARNING: LIKE search took ${duration}ms (expected < 500ms). Consider optimizing.`);
|
|
}
|
|
|
|
expect(duration).toBeLessThan(2000); // Hard limit: 2 seconds
|
|
});
|
|
});
|
|
|
|
describe('[DOCUMENTATION] Database Quality Metrics', () => {
|
|
it('should have high documentation coverage', () => {
|
|
const withDocs = db.prepare(`
|
|
SELECT COUNT(*) as count FROM nodes
|
|
WHERE documentation IS NOT NULL AND documentation != ''
|
|
`).get();
|
|
|
|
const total = db.prepare('SELECT COUNT(*) as count FROM nodes').get();
|
|
const coverage = (withDocs.count / total.count) * 100;
|
|
|
|
console.log(`📚 Documentation coverage: ${coverage.toFixed(1)}% (${withDocs.count}/${total.count})`);
|
|
|
|
expect(coverage,
|
|
'WARNING: Documentation coverage is low. Some nodes may not have help text.'
|
|
).toBeGreaterThan(80); // At least 80% coverage
|
|
});
|
|
|
|
it('should have properties extracted for most nodes', () => {
|
|
const withProps = db.prepare(`
|
|
SELECT COUNT(*) as count FROM nodes
|
|
WHERE properties_schema IS NOT NULL AND properties_schema != '[]'
|
|
`).get();
|
|
|
|
const total = db.prepare('SELECT COUNT(*) as count FROM nodes').get();
|
|
const coverage = (withProps.count / total.count) * 100;
|
|
|
|
console.log(`🔧 Properties extraction: ${coverage.toFixed(1)}% (${withProps.count}/${total.count})`);
|
|
|
|
expect(coverage,
|
|
'WARNING: Many nodes have no properties extracted. Check parser logic.'
|
|
).toBeGreaterThan(70); // At least 70% should have properties
|
|
});
|
|
});
|
|
});
|