| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { |
| 4 | appendCodexArtifactTemplateUsePrompt, |
| 5 | codexArtifactTemplatePresentationLabel, |
| 6 | codexArtifactTemplateUsePrompt, |
| 7 | resolveCodexArtifactTemplate, |
| 8 | type CodexArtifactTemplate, |
| 9 | } from "./codexArtifactTemplates.ts"; |
| 10 | |
| 11 | const HELLO_WORLD_TEMPLATE: CodexArtifactTemplate = { |
| 12 | artifactKind: "document", |
| 13 | displayName: "Hello World", |
| 14 | skillDirectory: "/Users/test/.codex/skills/artifact-template-hello-world", |
| 15 | skillName: "artifact-template-hello-world", |
| 16 | }; |
| 17 | |
| 18 | describe("artifact template presentation", () => { |
| 19 | it("shares labels and copy text across clients", () => { |
| 20 | expect(codexArtifactTemplatePresentationLabel("document")).toBe("Document template"); |
| 21 | }); |
| 22 | }); |
| 23 | |
| 24 | describe("resolveCodexArtifactTemplate", () => { |
| 25 | it("accepts the template metadata emitted by Codex", () => { |
| 26 | expect( |
| 27 | resolveCodexArtifactTemplate({ |
| 28 | artifact_kind: "document", |
| 29 | display_name: " Hello World ", |
| 30 | skill_directory: "/Users/test/.codex/skills/artifact-template-hello-world", |
| 31 | skill_name: "artifact-template-hello-world", |
| 32 | }), |
| 33 | ).toEqual(HELLO_WORLD_TEMPLATE); |
| 34 | }); |
| 35 | |
| 36 | it.each([ |
| 37 | String.raw`C:\Users\test\.codex\skills\artifact-template-hello-world`, |
| 38 | String.raw`\\server\share\artifact-template-hello-world`, |
| 39 | "//server/share/artifact-template-hello-world", |
| 40 | ])("accepts absolute Windows skill directories: %s", (skillDirectory) => { |
| 41 | expect( |
| 42 | resolveCodexArtifactTemplate({ |
| 43 | artifact_kind: "image", |
| 44 | display_name: "Reference image", |
| 45 | gallery_kind: "product-design", |
| 46 | skill_directory: skillDirectory, |
| 47 | skill_name: "artifact-template-reference-image", |
| 48 | }), |
| 49 | ).toMatchObject({ |
| 50 | artifactKind: "image", |
| 51 | galleryKind: "product-design", |
| 52 | skillDirectory, |
| 53 | }); |
| 54 | }); |
| 55 | |
| 56 | it.each([ |
| 57 | { artifact_kind: "unknown" }, |
| 58 | { display_name: " " }, |
| 59 | { skill_directory: "relative/template" }, |
| 60 | { skill_name: "hello-world" }, |
| 61 | { gallery_kind: null }, |
| 62 | { gallery_kind: "unknown" }, |
| 63 | ])("rejects malformed template metadata: %o", (override) => { |
| 64 | expect( |
| 65 | resolveCodexArtifactTemplate({ |
| 66 | artifact_kind: "document", |
| 67 | display_name: "Hello World", |
| 68 | skill_directory: "/templates/hello-world", |
| 69 | skill_name: "artifact-template-hello-world", |
| 70 | ...override, |
| 71 | }), |
| 72 | ).toBeNull(); |
| 73 | }); |
| 74 | }); |
| 75 | |
| 76 | describe("codexArtifactTemplateUsePrompt", () => { |
| 77 | it("builds the same document follow-up shape as Codex", () => { |
| 78 | expect(codexArtifactTemplateUsePrompt(HELLO_WORLD_TEMPLATE)).toBe( |
| 79 | "Create a document using this $artifact-template-hello-world about…", |
| 80 | ); |
| 81 | }); |
| 82 | |
| 83 | it("uses the artifact-specific image wording", () => { |
| 84 | expect( |
| 85 | codexArtifactTemplateUsePrompt({ |
| 86 | ...HELLO_WORLD_TEMPLATE, |
| 87 | artifactKind: "image", |
| 88 | }), |
| 89 | ).toBe("Create an image using this $artifact-template-hello-world of…"); |
| 90 | }); |
| 91 | }); |
| 92 | |
| 93 | describe("appendCodexArtifactTemplateUsePrompt", () => { |
| 94 | const prompt = "Create a document using this $artifact-template-hello-world about…"; |
| 95 | |
| 96 | it("adds the prompt to an empty draft", () => { |
| 97 | expect(appendCodexArtifactTemplateUsePrompt("", HELLO_WORLD_TEMPLATE)).toBe(prompt); |
| 98 | }); |
| 99 | |
| 100 | it("preserves existing draft text", () => { |
| 101 | expect(appendCodexArtifactTemplateUsePrompt("Write about otters", HELLO_WORLD_TEMPLATE)).toBe( |
| 102 | `Write about otters ${prompt}`, |
| 103 | ); |
| 104 | }); |
| 105 | |
| 106 | it.each([prompt, `${prompt}\n`, `Notes\n\n${prompt}`])( |
| 107 | "does not append the same final prompt twice: %s", |
| 108 | (draft) => { |
| 109 | expect(appendCodexArtifactTemplateUsePrompt(draft, HELLO_WORLD_TEMPLATE)).toBe(draft); |
| 110 | }, |
| 111 | ); |
| 112 | |
| 113 | it("does not mistake text containing the prompt for a final prompt", () => { |
| 114 | const draft = `${prompt}\nAdditional instructions`; |
| 115 | expect(appendCodexArtifactTemplateUsePrompt(draft, HELLO_WORLD_TEMPLATE)).toBe( |
| 116 | `${draft} ${prompt}`, |
| 117 | ); |
| 118 | }); |
| 119 | }); |