perf: 优化智能体与工作流幕布渲染性能
- 分阶段加载智能体配置并按需缓存 MCP 工具 - 合并画布状态更新与节点尺寸监听,启用大图可视区域渲染和静态连线 - 隔离 Tinyflow Store 实例并补充数据同步与回归测试
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
|
||||
import './components/TinyflowComponent.svelte';
|
||||
import { Tinyflow } from './Tinyflow';
|
||||
|
||||
const waitForRender = () =>
|
||||
new Promise<void>((resolve) => {
|
||||
setTimeout(resolve, 0);
|
||||
});
|
||||
|
||||
describe('tinyflow store isolation', () => {
|
||||
beforeEach(() => {
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
it('keeps simultaneous canvas data isolated', async () => {
|
||||
const firstContainer = document.createElement('div');
|
||||
const secondContainer = document.createElement('div');
|
||||
document.body.append(firstContainer, secondContainer);
|
||||
|
||||
const first = new Tinyflow({
|
||||
element: firstContainer,
|
||||
data: {
|
||||
nodes: [
|
||||
{ id: 'first-source', position: { x: 0, y: 0 }, data: {} },
|
||||
{ id: 'first-target', position: { x: 300, y: 0 }, data: {} },
|
||||
],
|
||||
edges: [
|
||||
{
|
||||
id: 'first-edge',
|
||||
source: 'first-source',
|
||||
target: 'first-target',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
const second = new Tinyflow({
|
||||
element: secondContainer,
|
||||
data: {
|
||||
nodes: [
|
||||
{ id: 'second-source', position: { x: 0, y: 0 }, data: {} },
|
||||
{ id: 'second-target', position: { x: 300, y: 0 }, data: {} },
|
||||
],
|
||||
edges: [
|
||||
{
|
||||
id: 'second-edge',
|
||||
source: 'second-source',
|
||||
target: 'second-target',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
await waitForRender();
|
||||
|
||||
expect(first.getData()?.nodes.map((node) => node.id)).toEqual([
|
||||
'first-source',
|
||||
'first-target',
|
||||
]);
|
||||
expect(second.getData()?.nodes.map((node) => node.id)).toEqual([
|
||||
'second-source',
|
||||
'second-target',
|
||||
]);
|
||||
|
||||
first.updateData({
|
||||
nodes: [
|
||||
{ id: 'first-updated', position: { x: 100, y: 100 }, data: {} },
|
||||
],
|
||||
edges: [],
|
||||
});
|
||||
await waitForRender();
|
||||
|
||||
expect(first.getData()?.nodes.map((node) => node.id)).toEqual([
|
||||
'first-updated',
|
||||
]);
|
||||
expect(first.getData()?.edges).toEqual([]);
|
||||
expect(second.getData()?.nodes.map((node) => node.id)).toEqual([
|
||||
'second-source',
|
||||
'second-target',
|
||||
]);
|
||||
expect(second.getData()?.edges.map((edge) => edge.id)).toEqual([
|
||||
'second-edge',
|
||||
]);
|
||||
|
||||
first.destroy();
|
||||
second.destroy();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user