feat: manually mirror opencoze's code from bytedance

Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
fanlv
2025-07-20 17:36:12 +08:00
commit 890153324f
14811 changed files with 1923430 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`encapsulate-generate-service > should generate sub workflow node 1`] = `
{
"data": {
"inputs": {
"spaceId": "1",
"workflowId": "1",
"workflowVersion": "v0.0.1",
},
"nodeMeta": {
"description": "test",
"icon": undefined,
"isImageflow": false,
"title": "test",
},
},
}
`;
exports[`encapsulate-generate-service > should generate workflow json 1`] = `
{
"edges": [
{
"sourceNodeID": "154702",
"targetNodeID": "102906",
},
{
"sourceNodeID": "100001",
"targetNodeID": "154702",
},
{
"sourceNodeID": "102906",
"targetNodeID": "900001",
},
],
"nodes": [
{
"data": {
"nodeMeta": {},
"outputs": [],
},
"id": "100001",
"meta": {
"position": {
"x": 0,
"y": 0,
},
},
"type": "1",
},
{
"data": {
"inputs": {
"inputParameters": [],
"terminatePlan": "returnVariables",
},
"nodeMeta": {},
},
"id": "900001",
"meta": {
"position": {
"x": 1000,
"y": 0,
},
},
"type": "2",
},
{
"data": {},
"id": "154702",
"meta": {
"position": {
"x": 918.2411574431025,
"y": 109.52852376445134,
},
},
"type": "3",
},
{
"data": {
"inputs": {
"spaceId": "test_space_id",
"workflowId": "test_workflow_id",
},
},
"id": "102906",
"meta": {
"position": {
"x": 779.2423264779079,
"y": -161.54447093414998,
},
},
"type": "9",
},
],
}
`;

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2025 coze-dev Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeEach, it, expect } from 'vitest';
import {
WorkflowDocument,
type WorkflowNodeEntity,
} from '@flowgram-adapter/free-layout-editor';
import { complexMock } from '../workflow.mock';
import { createContainer } from '../create-container';
import {
EncapsulateGenerateService,
type GenerateSubWorkflowNodeOptions,
} from '../../src/generate';
describe('encapsulate-generate-service', () => {
let encapsulateGenerateService: EncapsulateGenerateService;
let workflowDocument: WorkflowDocument;
beforeEach(async () => {
const container = createContainer();
workflowDocument = container.get<WorkflowDocument>(WorkflowDocument);
encapsulateGenerateService = container.get<EncapsulateGenerateService>(
EncapsulateGenerateService,
);
await workflowDocument.fromJSON(complexMock);
});
it('should generate workflow json', async () => {
const nodes = ['102906', '154702'].map(id =>
workflowDocument.getNode(id),
) as WorkflowNodeEntity[];
const res = await encapsulateGenerateService.generateWorkflowJSON(nodes);
expect(res).toMatchSnapshot();
});
it('should generate sub workflow node', async () => {
const options: GenerateSubWorkflowNodeOptions = {
workflowId: '1',
name: 'test',
desc: 'test',
spaceId: '1',
};
const res =
await encapsulateGenerateService.generateSubWorkflowNode(options);
expect(res).toMatchSnapshot();
});
});