|
| 1 | +import fs from "node:fs/promises"; |
| 2 | +import path from "node:path"; |
| 3 | +import { validateToolArguments } from "openclaw/plugin-sdk/llm"; |
| 4 | +import { afterEach, beforeEach, describe, expect, it } from "vitest"; |
| 5 | +import { |
| 6 | + createOpenClawTestState, |
| 7 | + type OpenClawTestState, |
| 8 | +} from "../../test-utils/openclaw-test-state.js"; |
| 9 | +import { createTrackedTempDirs } from "../../test-utils/tracked-temp-dirs.js"; |
| 10 | +import { createSkillWorkshopTool } from "./skill-workshop-tool.js"; |
| 11 | + |
| 12 | +const tempDirs = createTrackedTempDirs(); |
| 13 | +let testState: OpenClawTestState; |
| 14 | + |
| 15 | +beforeEach(async () => { |
| 16 | + testState = await createOpenClawTestState({ |
| 17 | + layout: "state-only", |
| 18 | + prefix: "openclaw-skill-workshop-description-state-", |
| 19 | + }); |
| 20 | +}); |
| 21 | + |
| 22 | +afterEach(async () => { |
| 23 | + await testState.cleanup(); |
| 24 | + await tempDirs.cleanup(); |
| 25 | +}); |
| 26 | + |
| 27 | +describe("skill_workshop description validation", () => { |
| 28 | + it("lets the proposal service explain overlong descriptions", async () => { |
| 29 | + const workspaceDir = await tempDirs.make("openclaw-skill-workshop-description-limit-"); |
| 30 | + const tool = createSkillWorkshopTool({ workspaceDir, env: testState.env }); |
| 31 | + const args = { |
| 32 | + action: "create" as const, |
| 33 | + name: "Long Description", |
| 34 | + description: "x".repeat(161), |
| 35 | + proposal_content: "# Long Description\n", |
| 36 | + }; |
| 37 | + const call = { |
| 38 | + type: "toolCall" as const, |
| 39 | + id: "call-long-description", |
| 40 | + name: "skill_workshop", |
| 41 | + arguments: args, |
| 42 | + }; |
| 43 | + expect(validateToolArguments(tool, call)).toEqual(args); |
| 44 | + |
| 45 | + await expect(tool.execute(call.id, args)).rejects.toThrow( |
| 46 | + "Skill proposal description is too large (161 bytes, max 160).", |
| 47 | + ); |
| 48 | + }); |
| 49 | + |
| 50 | + it("lets the proposal service explain overlong collection descriptions", async () => { |
| 51 | + const workspaceDir = await tempDirs.make("openclaw-skill-collection-description-limit-"); |
| 52 | + const collectionReconcile = {}; |
| 53 | + const tool = createSkillWorkshopTool({ workspaceDir, env: testState.env, collectionReconcile }); |
| 54 | + const args = { |
| 55 | + action: "reconcile" as const, |
| 56 | + collection: [ |
| 57 | + { |
| 58 | + action: "write" as const, |
| 59 | + name: "long-description", |
| 60 | + description: "x".repeat(161), |
| 61 | + content: "# Long Description\n", |
| 62 | + }, |
| 63 | + ], |
| 64 | + }; |
| 65 | + const call = { |
| 66 | + type: "toolCall" as const, |
| 67 | + id: "call-long-collection-description", |
| 68 | + name: "skill_workshop", |
| 69 | + arguments: args, |
| 70 | + }; |
| 71 | + expect(validateToolArguments(tool, call)).toEqual(args); |
| 72 | + |
| 73 | + await expect(tool.execute(call.id, args)).rejects.toThrow( |
| 74 | + "Skill proposal description is too large (161 bytes, max 160).", |
| 75 | + ); |
| 76 | + await expect( |
| 77 | + fs.access(path.join(workspaceDir, "skills", "long-description", "SKILL.md")), |
| 78 | + ).rejects.toThrow(); |
| 79 | + expect(collectionReconcile).not.toHaveProperty("result"); |
| 80 | + }); |
| 81 | +}); |
0 commit comments