fix: code validator false positives and null property removal (#294, #293, #611) (#637)

- Fix $() node reference triggering "Invalid $ usage" warning by adding ( and _ to regex lookahead
- Fix helper function primitive returns triggering "Cannot return primitive values" error
- Fix null values in diff engine causing Zod validation errors — null now deletes properties
- Update property removal docs from undefined to null

Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Romuald Członkowski
2026-03-15 11:26:44 +01:00
committed by GitHub
parent 599bc664d0
commit 65ab94deb2
16 changed files with 339 additions and 89 deletions

View File

@@ -1912,6 +1912,55 @@ return [{"json": {"result": result}}]
});
});
it('should not error on primitive return inside helper functions', () => {
context.config = {
language: 'javaScript',
jsCode: 'function isValid(item) { return false; }\nconst items = $input.all();\nreturn items.filter(isValid).map(i => ({json: i.json}));'
};
NodeSpecificValidators.validateCode(context);
const primitiveErrors = context.errors.filter(e => e.message === 'Cannot return primitive values directly');
expect(primitiveErrors).toHaveLength(0);
});
it('should not error on primitive return inside arrow function helpers', () => {
context.config = {
language: 'javaScript',
jsCode: 'const isValid = (item) => { return false; };\nreturn $input.all().filter(isValid).map(i => ({json: i.json}));'
};
NodeSpecificValidators.validateCode(context);
const primitiveErrors = context.errors.filter(e => e.message === 'Cannot return primitive values directly');
expect(primitiveErrors).toHaveLength(0);
});
it('should not error on primitive return inside async function helpers', () => {
context.config = {
language: 'javaScript',
jsCode: 'async function fetchData(url) { return null; }\nconst data = await fetchData("https://api.example.com");\nreturn [{json: {data}}];'
};
NodeSpecificValidators.validateCode(context);
const primitiveErrors = context.errors.filter(e => e.message === 'Cannot return primitive values directly');
expect(primitiveErrors).toHaveLength(0);
});
it('should still error on primitive return without helper functions', () => {
context.config = {
language: 'javaScript',
jsCode: 'return "success";'
};
NodeSpecificValidators.validateCode(context);
expect(context.errors).toContainEqual(expect.objectContaining({
message: 'Cannot return primitive values directly'
}));
});
it('should error on Python primitive return', () => {
context.config = {
language: 'python',
@@ -2038,6 +2087,30 @@ return [{"json": {"result": result}}]
});
});
it('should not warn about $() node reference syntax', () => {
context.config = {
language: 'javaScript',
jsCode: 'const data = $("Previous Node").first().json;\nreturn [{json: data}];'
};
NodeSpecificValidators.validateCode(context);
const dollarWarnings = context.warnings.filter(w => w.message === 'Invalid $ usage detected');
expect(dollarWarnings).toHaveLength(0);
});
it('should not warn about $_ variables', () => {
context.config = {
language: 'javaScript',
jsCode: 'const $_temp = 1;\nreturn [{json: {value: $_temp}}];'
};
NodeSpecificValidators.validateCode(context);
const dollarWarnings = context.warnings.filter(w => w.message === 'Invalid $ usage detected');
expect(dollarWarnings).toHaveLength(0);
});
it('should correct helpers usage', () => {
context.config = {
language: 'javaScript',