-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathdescription.test.ts
More file actions
190 lines (171 loc) · 6.71 KB
/
Copy pathdescription.test.ts
File metadata and controls
190 lines (171 loc) · 6.71 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import { describe, expect, it } from "@effect/vitest";
import { Effect } from "effect";
import {
AuthTemplateSlug,
ConnectionName,
IntegrationSlug,
ProviderItemId,
ProviderKey,
createExecutor,
definePlugin,
type CredentialProvider,
} from "@executor-js/sdk";
import { makeTestConfig } from "@executor-js/sdk/testing";
import { buildExecuteDescription } from "./description";
const memoryProvider = (): CredentialProvider => {
const store = new Map<string, string>();
return {
key: ProviderKey.make("memory"),
writable: true,
get: (id) => Effect.sync(() => store.get(String(id)) ?? null),
set: (id, value) => Effect.sync(() => void store.set(String(id), value)),
has: (id) => Effect.sync(() => store.has(String(id))),
list: () =>
Effect.sync(() =>
Array.from(store.keys()).map((key) => ({
id: ProviderItemId.make(key),
name: key,
})),
),
};
};
const GITHUB = IntegrationSlug.make("github");
const SLACK = IntegrationSlug.make("slack");
const TEMPLATE = AuthTemplateSlug.make("apiKey");
// v2 port: available entries are saved connection prefixes, not integration
// slugs. Multiple saved connections can point at the same integration, and the
// callable path needs `<integration>.<owner>.<connection>`.
const githubPlugin = definePlugin(() => ({
id: "github-plugin" as const,
credentialProviders: [memoryProvider()],
storage: () => ({}),
extension: (ctx) => ({
seed: () =>
ctx.core.integrations.register({
slug: GITHUB,
description: "GitHub",
config: {},
}),
}),
}))();
const slackPlugin = definePlugin(() => ({
id: "slack-plugin" as const,
storage: () => ({}),
extension: (ctx) => ({
seed: () =>
ctx.core.integrations.register({
slug: SLACK,
name: "Slack",
description: "Send and read workspace messages.",
config: {},
}),
}),
}))();
describe("buildExecuteDescription", () => {
it.effect("renders real connection prefixes separately through the real executor flow", () =>
Effect.gen(function* () {
const executor = yield* createExecutor(
makeTestConfig({ plugins: [slackPlugin, githubPlugin] as const }),
);
yield* executor["slack-plugin"].seed();
yield* executor["github-plugin"].seed();
yield* executor.connections.create({
owner: "user",
name: ConnectionName.make("personal"),
integration: GITHUB,
template: TEMPLATE,
value: "user-token",
});
yield* executor.connections.create({
owner: "org",
name: ConnectionName.make("prod"),
integration: GITHUB,
template: TEMPLATE,
value: "org-token",
});
const description = yield* buildExecuteDescription(executor);
// Stable anchor from the workflow preamble.
expect(description).toContain("Execute TypeScript in a sandboxed runtime");
expect(description).toContain("Use `emit(value)` to append user-visible output");
expect(description).toContain("Emit attachments with `emit(result.data)`");
expect(description).toContain("also accepts MCP content blocks");
expect(description).toContain("`emit(ToolFile)` is MIME-based");
expect(description).toContain(
"Returning a `ToolFile`, `ToolResult`, MCP content block, or bare base64 string does not emit content",
);
expect(description).toContain(
"use the separate `execute_cell` and `wait_cell` tools instead of `execute`",
);
expect(description).toContain("Do not use `resume` for execution cells");
expect(description).toContain("## Available connection prefixes");
expect(description).toContain("- `github.org.prod`");
expect(description).toContain("- `github.user.personal`");
expect(description).not.toContain("## Available namespaces");
expect(description).not.toContain("workspace messages");
expect(description).not.toContain("`github-plugin`");
expect(description).not.toContain("`slack-plugin`");
expect(description).not.toContain("- `github`");
const orgIdx = description.indexOf("`github.org.prod`");
const userIdx = description.indexOf("`github.user.personal`");
expect(orgIdx).toBeGreaterThan(-1);
expect(userIdx).toBeGreaterThan(-1);
expect(orgIdx).toBeLessThan(userIdx);
}),
);
it.effect("annotates prefixes with connection or integration descriptions", () =>
Effect.gen(function* () {
const executor = yield* createExecutor(
makeTestConfig({ plugins: [slackPlugin, githubPlugin] as const }),
);
yield* executor["slack-plugin"].seed();
yield* executor["github-plugin"].seed();
yield* executor.connections.create({
owner: "org",
name: ConnectionName.make("prod"),
integration: GITHUB,
template: TEMPLATE,
value: "org-token",
description: "Production org — issues and PRs only.",
});
yield* executor.connections.create({
owner: "user",
name: ConnectionName.make("personal"),
integration: GITHUB,
template: TEMPLATE,
value: "user-token",
});
const description = yield* buildExecuteDescription(executor);
// The curated connection description rides its prefix line.
expect(description).toContain("- `github.org.prod` — Production org — issues and PRs only.");
// No connection description and the integration description ("GitHub")
// just restates the slug — the line stays bare.
expect(description).toContain("- `github.user.personal`");
expect(description).not.toContain("- `github.user.personal` —");
}),
);
it.effect("falls back to a meaningful integration description", () =>
Effect.gen(function* () {
const executor = yield* createExecutor(
makeTestConfig({ plugins: [slackPlugin, githubPlugin] as const }),
);
yield* executor["slack-plugin"].seed();
yield* executor.connections.create({
owner: "org",
name: ConnectionName.make("main"),
integration: SLACK,
template: TEMPLATE,
value: "slack-token",
});
const description = yield* buildExecuteDescription(executor);
expect(description).toContain("- `slack.org.main` — Send and read workspace messages.");
}),
);
it.effect("omits the Available connection prefixes section when no connections exist", () =>
Effect.gen(function* () {
const executor = yield* createExecutor(makeTestConfig({ plugins: [] as const }));
const description = yield* buildExecuteDescription(executor);
expect(description).toContain("Execute TypeScript in a sandboxed runtime");
expect(description).not.toContain("## Available connection prefixes");
}),
);
});