repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | #!/usr/bin/env node |
| #2 | /** |
| #3 | * 测试命令 |
| #4 | * 用于验证 Agent 配置文件的格式和唯一性 |
| #5 | */ |
| #6 | import { readJSONSync } from 'fs-extra'; |
| #7 | import { resolve } from 'node:path'; |
| #8 | import pMap from 'p-map'; |
| #9 | |
| #10 | import { agents, agentsDir, config, root } from '../core/constants'; |
| #11 | import { Logger } from '../utils/logger'; |
| #12 | import { checkUniqueIdentifier, formatAndCheckSchema } from '../validators/agent-validator'; |
| #13 | |
| #14 | /** |
| #15 | * 执行测试流程 |
| #16 | */ |
| #17 | const runTest = async () => { |
| #18 | Logger.split('开始验证 Agent 文件'); |
| #19 | const startTime = Date.now(); |
| #20 | |
| #21 | const validFiles = agents.filter((file) => file.isFile()); |
| #22 | Logger.info('待验证文件数量', validFiles.length); |
| #23 | |
| #24 | // 并行验证所有 Agent 文件 |
| #25 | const results = await pMap( |
| #26 | validFiles, |
| #27 | async (file, index) => { |
| #28 | const filePath = resolve(agentsDir, file.name); |
| #29 | const relativePath = filePath.replace(root, ''); |
| #30 | |
| #31 | Logger.progress(index + 1, validFiles.length, `验证 ${relativePath}`); |
| #32 | |
| #33 | try { |
| #34 | const agent = readJSONSync(filePath); |
| #35 | formatAndCheckSchema(agent); // 验证 Schema |
| #36 | Logger.success('Schema 验证通过', file.name); |
| #37 | return agent.identifier; |
| #38 | } catch (error) { |
| #39 | Logger.error('Schema 验证失败', `${file.name}: ${error}`); |
| #40 | throw error; |
| #41 | } |
| #42 | }, |
| #43 | { concurrency: config.concurrency }, // 使用配置中的并发数控制 |
| #44 | ); |
| #45 | |
| #46 | Logger.start('检查标识符唯一性'); |
| #47 | checkUniqueIdentifier(results); // 检查标识符唯一性 |
| #48 | Logger.success('标识符唯一性检查通过'); |
| #49 | |
| #50 | const duration = Date.now() - startTime; |
| #51 | Logger.stats({ |
| #52 | 总耗时: `${duration}ms`, |
| #53 | 验证文件数量: validFiles.length, |
| #54 | 验证通过: results.length, |
| #55 | }); |
| #56 | |
| #57 | Logger.success('所有验证完成'); |
| #58 | }; |
| #59 | |
| #60 | // 执行测试 |
| #61 | await runTest(); |
| #62 | |
| #63 | |
| #64 |