feat: 支持 Python 代码节点 main 返回输出
- 自动传入节点输入并映射 main 返回字典,兼容历史 _result - 限制脚本输出缓冲并补充运行时与编辑器测试 - 同步 Python 帮助、占位提示和独立可执行补全片段
This commit is contained in:
@@ -71,6 +71,36 @@ describe('codeCompletion utils', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should prefer main return snippets for python output', () => {
|
||||
const completions = createBusinessCompletions('python', []);
|
||||
const mainCompletion = completions.find((item) => item.label === 'main');
|
||||
const resultCompletion = completions.find(
|
||||
(item) => item.label === 'result-object',
|
||||
);
|
||||
|
||||
expect(mainCompletion).toMatchObject({
|
||||
type: 'snippet',
|
||||
detail: '代码节点入口',
|
||||
boost: 1000,
|
||||
});
|
||||
expect(String(mainCompletion?.apply)).toContain('def main(inputs):');
|
||||
expect(String(mainCompletion?.apply)).toContain('return {');
|
||||
expect(String(resultCompletion?.apply)).toContain('def main(inputs):');
|
||||
expect(String(resultCompletion?.apply)).toContain(
|
||||
"return {'message': 'ok', 'data': inputs.get('data')}",
|
||||
);
|
||||
});
|
||||
|
||||
it('should provide standalone 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 /);
|
||||
}
|
||||
});
|
||||
|
||||
it('should detect blocked nodes for comment/string/property contexts', () => {
|
||||
expect(shouldSkipBusinessCompletion('Comment')).toBe(true);
|
||||
expect(shouldSkipBusinessCompletion('LineComment')).toBe(true);
|
||||
|
||||
Reference in New Issue
Block a user