fix: 修复代码节点补全与参数同步边界

- 保持 main 参数运行协议并在失焦或销毁前刷新输出分析

- 按输入名称生成 JavaScript 和 Python 补全且隐藏旧版 _result

- 补充复杂签名与命名参数补全测试
This commit is contained in:
2026-08-03 17:27:00 +08:00
parent a75ae9a843
commit 7bcaf69fc0
6 changed files with 171 additions and 151 deletions

View File

@@ -25,9 +25,12 @@ describe('codeCompletion utils', () => {
]);
expect(completions[0]).toMatchObject({
label: '_result',
type: 'variable',
label: 'main',
type: 'snippet',
boost: 1000,
});
expect(String(completions[0].apply)).toContain('def main(question):');
expect(completions.some((item) => item.label === '_result')).toBe(false);
expect(
completions.filter((item) => item.label === 'input.text').length,
@@ -53,7 +56,10 @@ describe('codeCompletion utils', () => {
});
it('should prefer main return snippets for javascript output', () => {
const completions = createBusinessCompletions('javascript', []);
const completions = createBusinessCompletions('javascript', [
{ name: 'data', resolved: true },
{ name: 'question', resolved: true },
]);
const mainCompletion = completions.find((item) => item.label === 'main');
const resultCompletion = completions.find(
(item) => item.label === 'result-object',
@@ -64,15 +70,21 @@ describe('codeCompletion utils', () => {
detail: '代码节点入口',
boost: 1000,
});
expect(String(mainCompletion?.apply)).toContain('function main');
expect(String(mainCompletion?.apply)).toContain(
'function main(data, question)',
);
expect(String(mainCompletion?.apply)).toContain('return {');
expect(String(mainCompletion?.apply)).not.toContain('_result');
expect(String(resultCompletion?.apply)).toBe(
"return { message: 'ok', data };",
);
});
it('should prefer main return snippets for python output', () => {
const completions = createBusinessCompletions('python', []);
const completions = createBusinessCompletions('python', [
{ name: 'data', resolved: true },
{ name: 'question', resolved: true },
]);
const mainCompletion = completions.find((item) => item.label === 'main');
const resultCompletion = completions.find(
(item) => item.label === 'result-object',
@@ -83,21 +95,27 @@ describe('codeCompletion utils', () => {
detail: '代码节点入口',
boost: 1000,
});
expect(String(mainCompletion?.apply)).toContain('def main(inputs):');
expect(String(mainCompletion?.apply)).toContain(
'def main(data, question):',
);
expect(String(mainCompletion?.apply)).toContain('return {');
expect(String(resultCompletion?.apply)).toContain('def main(inputs):');
expect(String(mainCompletion?.apply)).not.toContain('_result');
expect(String(resultCompletion?.apply)).toContain(
"return {'message': 'ok', 'data': inputs.get('data')}",
'def main(data, question):',
);
expect(String(resultCompletion?.apply)).toContain(
"return {'message': 'ok', 'data': data}",
);
});
it('should provide standalone python snippets', () => {
it('should not expose the legacy object-input contract in python snippets', () => {
const completions = createBusinessCompletions('python', []);
const snippets = completions.filter((item) => item.type === 'snippet');
expect(snippets).toHaveLength(4);
for (const snippet of snippets) {
expect(String(snippet.apply)).toMatch(/^def main\(inputs\):\n /);
expect(String(snippet.apply)).not.toContain('inputs');
expect(String(snippet.apply)).not.toContain('_result');
}
});