-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompose-next.test.ts
More file actions
96 lines (85 loc) · 3.11 KB
/
Copy pathcompose-next.test.ts
File metadata and controls
96 lines (85 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { describe, expect, test } from "bun:test"
import plugin, { promptFor, VERSION } from "./compose-next.ts"
function invocation(overrides: Record<string, unknown> = {}) {
return {
sessionID: "ses_1",
prompt: { text: "Add a login page" },
delivery: "steer",
...overrides,
} as any
}
function makeCtx(skills: string[] = ["compose-next"]) {
const added: any[] = []
const calls = { prompt: [] as any[] }
const ctx: any = {
skill: { list: async () => ({ location: {}, data: skills.map((id) => ({ id })) }) },
command: { transform: (callback: any) => callback({ add: (definition: any) => added.push(definition) }) },
session: { prompt: async (input: any) => void calls.prompt.push(input) },
}
return { ctx, added, calls }
}
describe("promptFor", () => {
test("attaches the skill and forwards the request", () => {
expect(promptFor("compose-next", invocation())).toEqual({
sessionID: "ses_1",
text: "Add a login page",
files: [],
skills: [{ id: "compose-next" }],
delivery: "steer",
})
})
test("uses a starter message when the user types nothing", () => {
const built = promptFor("compose-next", invocation({ prompt: { text: " " } }))
expect(built.text).toBe("Begin the compose-next workflow.")
})
test("forwards attached files", () => {
const files = [{ uri: "file:///a.md" }]
const built = promptFor("compose-next", invocation({ prompt: { text: "hi", files } }))
expect(built.files).toEqual(files)
})
test("survives a missing prompt", () => {
const built = promptFor("compose-next", invocation({ prompt: undefined }))
expect(built.text).toBe("Begin the compose-next workflow.")
expect(built.files).toEqual([])
})
})
describe("setup", () => {
test("registers the compose-next command", async () => {
const { ctx, added } = makeCtx()
await (plugin as any).setup(ctx)
expect(added.map((definition) => definition.name)).toEqual(["compose-next"])
})
test("still registers when the skill is missing", async () => {
const { ctx, added } = makeCtx([])
await (plugin as any).setup(ctx)
expect(added.map((definition) => definition.name)).toEqual(["compose-next"])
})
})
describe("execute", () => {
test("starts the workflow with the skill attached", async () => {
const { ctx, added, calls } = makeCtx()
await (plugin as any).setup(ctx)
await added[0].execute(invocation())
expect(calls.prompt).toEqual([
{
sessionID: "ses_1",
text: "Add a login page",
files: [],
skills: [{ id: "compose-next" }],
delivery: "steer",
},
])
})
test("starts the workflow on a bare command", async () => {
const { ctx, added, calls } = makeCtx()
await (plugin as any).setup(ctx)
await added[0].execute(invocation({ prompt: { text: "" } }))
expect(calls.prompt[0].text).toBe("Begin the compose-next workflow.")
})
})
describe("version", () => {
test("VERSION matches package.json", async () => {
const pkg = (await Bun.file(new URL("./package.json", import.meta.url)).json()) as { version: string }
expect(VERSION).toBe(pkg.version)
})
})