n8n/packages/@n8n/instance-ai/evaluations/binaryChecks/checks/no-unnecessary-code-nodes.ts
Benjamin Schroth c961849226
feat(ai-builder): Add sub-agent evaluation harness with binary checks (no-changelog) (#28289)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-24 07:50:46 +00:00

24 lines
696 B
TypeScript

import type { BinaryCheck } from '../types';
const CODE_NODE_TYPE = 'n8n-nodes-base.code';
export const noUnnecessaryCodeNodes: BinaryCheck = {
name: 'no_unnecessary_code_nodes',
description: 'No code nodes in the workflow (prefer built-in nodes)',
kind: 'deterministic',
run(workflow, ctx) {
if (ctx.annotations?.code_necessary === true) {
return { pass: true, comment: 'Code marked as necessary by annotation' };
}
const codeNodes = (workflow.nodes ?? []).filter((n) => n.type === CODE_NODE_TYPE);
return {
pass: codeNodes.length === 0,
...(codeNodes.length > 0
? { comment: `Code node(s) found: ${codeNodes.map((n) => n.name).join(', ')}` }
: {}),
};
},
};