forked from anomalyco/opencode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem.test.ts
More file actions
149 lines (137 loc) · 4.43 KB
/
Copy pathsystem.test.ts
File metadata and controls
149 lines (137 loc) · 4.43 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { describe, expect, test } from "bun:test"
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
import { Effect, Layer } from "effect"
import type { Agent } from "../../src/agent/agent"
import { NamedError } from "@opencode-ai/core/util/error"
import { Skill } from "../../src/skill"
import { Permission } from "../../src/permission"
import type { Provider } from "../../src/provider/provider"
import { SystemPrompt } from "../../src/session/system"
import { MCP } from "../../src/mcp"
import { testEffect } from "../lib/effect"
const skills: Skill.Info[] = [
{
name: "zeta-skill",
description: "Zeta skill.",
location: "/tmp/zeta-skill/SKILL.md",
content: "# zeta-skill",
},
{
name: "alpha-skill",
description: "Alpha skill.",
location: "/tmp/alpha-skill/SKILL.md",
content: "# alpha-skill",
},
{
name: "middle-skill",
description: "Middle skill.",
location: "/tmp/middle-skill/SKILL.md",
content: "# middle-skill",
},
{
name: "manual-skill",
location: "/tmp/manual-skill/SKILL.md",
content: "# manual-skill",
},
]
const build: Agent.Info = {
name: "build",
mode: "primary",
permission: Permission.fromConfig({ "*": "allow" }),
options: {},
}
const it = testEffect(
LayerNode.compile(SystemPrompt.node, [
[
MCP.node,
Layer.mock(MCP.Service, {
instructions: () =>
Effect.succeed([
{
name: "guide-server",
instructions: "Use lookup before mutate.",
tools: [],
},
{
name: "tool-server",
instructions: "Prefer search before update.",
tools: ["tool-server_search", "tool-server_update"],
},
]),
}),
],
[
Skill.node,
Layer.succeed(
Skill.Service,
Skill.Service.of({
get: (name) => Effect.succeed(skills.find((skill) => skill.name === name)),
require: (name) => {
const info = skills.find((skill) => skill.name === name)
if (info) return Effect.succeed(info)
return Effect.fail(new Skill.NotFoundError({ name, available: skills.map((skill) => skill.name) }))
},
all: () => Effect.succeed(skills),
dirs: () => Effect.succeed([]),
available: () => Effect.succeed(skills),
}),
),
],
]),
)
describe("session.system", () => {
test("selects the Meta prompt for Muse Spark model IDs", () => {
expect(SystemPrompt.provider({ api: { id: "meta/muse-spark-preview" } } as Provider.Model)[0]).toContain(
"Meta Muse Spark",
)
})
it.effect("skills output is sorted by name and stable across calls", () =>
Effect.gen(function* () {
const prompt = yield* SystemPrompt.Service
const first = yield* prompt.skills(build)
const second = yield* prompt.skills(build)
const output = first ?? (yield* Effect.fail(new NamedError.Unknown({ message: "missing skills output" })))
expect(first).toBe(second)
const alpha = output.indexOf("<name>alpha-skill</name>")
const middle = output.indexOf("<name>middle-skill</name>")
const zeta = output.indexOf("<name>zeta-skill</name>")
expect(alpha).toBeGreaterThan(-1)
expect(middle).toBeGreaterThan(alpha)
expect(zeta).toBeGreaterThan(middle)
expect(output).not.toContain("manual-skill")
}),
)
it.effect("MCP output includes connected server instructions", () =>
Effect.gen(function* () {
const prompt = yield* SystemPrompt.Service
const output = yield* prompt.mcp(build)
expect(output).toBe(
[
"<mcp_instructions>",
' <server name="guide-server">',
" Use lookup before mutate.",
" </server>",
' <server name="tool-server">',
" Prefer search before update.",
" </server>",
"</mcp_instructions>",
].join("\n"),
)
}),
)
it.effect("MCP output omits servers when all advertised tools are denied", () =>
Effect.gen(function* () {
const prompt = yield* SystemPrompt.Service
const output = yield* prompt.mcp(build, Permission.fromConfig({ "tool-server_*": "deny" }))
expect(output).toBe(
[
"<mcp_instructions>",
' <server name="guide-server">',
" Use lookup before mutate.",
" </server>",
"</mcp_instructions>",
].join("\n"),
)
}),
)
})