@herdctl/core 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/__tests__/agent.test.js +31 -13
- package/dist/config/__tests__/agent.test.js.map +1 -1
- package/dist/config/__tests__/merge.test.js +9 -2
- package/dist/config/__tests__/merge.test.js.map +1 -1
- package/dist/config/__tests__/schema.test.js +350 -1
- package/dist/config/__tests__/schema.test.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +3 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/schema.d.ts +828 -24
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +118 -6
- package/dist/config/schema.js.map +1 -1
- package/dist/fleet-manager/__tests__/coverage.test.js +11 -332
- package/dist/fleet-manager/__tests__/coverage.test.js.map +1 -1
- package/dist/fleet-manager/__tests__/errors.test.js +1 -49
- package/dist/fleet-manager/__tests__/errors.test.js.map +1 -1
- package/dist/fleet-manager/__tests__/integration.test.js +109 -0
- package/dist/fleet-manager/__tests__/integration.test.js.map +1 -1
- package/dist/fleet-manager/__tests__/reload.test.js +1 -1
- package/dist/fleet-manager/__tests__/reload.test.js.map +1 -1
- package/dist/fleet-manager/config-reload.d.ts +164 -0
- package/dist/fleet-manager/config-reload.d.ts.map +1 -0
- package/dist/fleet-manager/config-reload.js +445 -0
- package/dist/fleet-manager/config-reload.js.map +1 -0
- package/dist/fleet-manager/context.d.ts +76 -0
- package/dist/fleet-manager/context.d.ts.map +1 -0
- package/dist/fleet-manager/context.js +11 -0
- package/dist/fleet-manager/context.js.map +1 -0
- package/dist/fleet-manager/errors.d.ts +0 -25
- package/dist/fleet-manager/errors.d.ts.map +1 -1
- package/dist/fleet-manager/errors.js +0 -38
- package/dist/fleet-manager/errors.js.map +1 -1
- package/dist/fleet-manager/event-emitters.d.ts +123 -0
- package/dist/fleet-manager/event-emitters.d.ts.map +1 -0
- package/dist/fleet-manager/event-emitters.js +136 -0
- package/dist/fleet-manager/event-emitters.js.map +1 -0
- package/dist/fleet-manager/event-types.d.ts +0 -15
- package/dist/fleet-manager/event-types.d.ts.map +1 -1
- package/dist/fleet-manager/fleet-manager.d.ts +40 -653
- package/dist/fleet-manager/fleet-manager.d.ts.map +1 -1
- package/dist/fleet-manager/fleet-manager.js +95 -1720
- package/dist/fleet-manager/fleet-manager.js.map +1 -1
- package/dist/fleet-manager/index.d.ts +13 -2
- package/dist/fleet-manager/index.d.ts.map +1 -1
- package/dist/fleet-manager/index.js +19 -6
- package/dist/fleet-manager/index.js.map +1 -1
- package/dist/fleet-manager/job-control.d.ts +64 -0
- package/dist/fleet-manager/job-control.d.ts.map +1 -0
- package/dist/fleet-manager/job-control.js +296 -0
- package/dist/fleet-manager/job-control.js.map +1 -0
- package/dist/fleet-manager/log-streaming.d.ts +171 -0
- package/dist/fleet-manager/log-streaming.d.ts.map +1 -0
- package/dist/fleet-manager/log-streaming.js +503 -0
- package/dist/fleet-manager/log-streaming.js.map +1 -0
- package/dist/fleet-manager/schedule-executor.d.ts +63 -0
- package/dist/fleet-manager/schedule-executor.d.ts.map +1 -0
- package/dist/fleet-manager/schedule-executor.js +209 -0
- package/dist/fleet-manager/schedule-executor.js.map +1 -0
- package/dist/fleet-manager/schedule-management.d.ts +71 -0
- package/dist/fleet-manager/schedule-management.d.ts.map +1 -0
- package/dist/fleet-manager/schedule-management.js +171 -0
- package/dist/fleet-manager/schedule-management.js.map +1 -0
- package/dist/fleet-manager/status-queries.d.ts +105 -0
- package/dist/fleet-manager/status-queries.d.ts.map +1 -0
- package/dist/fleet-manager/status-queries.js +247 -0
- package/dist/fleet-manager/status-queries.js.map +1 -0
- package/dist/fleet-manager/types.d.ts +0 -39
- package/dist/fleet-manager/types.d.ts.map +1 -1
- package/dist/runner/__tests__/job-executor.test.js +206 -1
- package/dist/runner/__tests__/job-executor.test.js.map +1 -1
- package/dist/runner/job-executor.d.ts +9 -0
- package/dist/runner/job-executor.d.ts.map +1 -1
- package/dist/runner/job-executor.js +78 -4
- package/dist/runner/job-executor.js.map +1 -1
- package/dist/runner/types.d.ts +2 -0
- package/dist/runner/types.d.ts.map +1 -1
- package/dist/scheduler/__tests__/cron.test.d.ts +2 -0
- package/dist/scheduler/__tests__/cron.test.d.ts.map +1 -0
- package/dist/scheduler/__tests__/cron.test.js +867 -0
- package/dist/scheduler/__tests__/cron.test.js.map +1 -0
- package/dist/scheduler/__tests__/scheduler.test.js +164 -5
- package/dist/scheduler/__tests__/scheduler.test.js.map +1 -1
- package/dist/scheduler/cron.d.ts +126 -0
- package/dist/scheduler/cron.d.ts.map +1 -0
- package/dist/scheduler/cron.js +390 -0
- package/dist/scheduler/cron.js.map +1 -0
- package/dist/scheduler/errors.d.ts +81 -1
- package/dist/scheduler/errors.d.ts.map +1 -1
- package/dist/scheduler/errors.js +81 -6
- package/dist/scheduler/errors.js.map +1 -1
- package/dist/scheduler/index.d.ts +1 -0
- package/dist/scheduler/index.d.ts.map +1 -1
- package/dist/scheduler/index.js +2 -0
- package/dist/scheduler/index.js.map +1 -1
- package/dist/scheduler/schedule-runner.d.ts +2 -2
- package/dist/scheduler/schedule-runner.d.ts.map +1 -1
- package/dist/scheduler/schedule-runner.js +20 -8
- package/dist/scheduler/schedule-runner.js.map +1 -1
- package/dist/scheduler/scheduler.d.ts +4 -4
- package/dist/scheduler/scheduler.d.ts.map +1 -1
- package/dist/scheduler/scheduler.js +86 -20
- package/dist/scheduler/scheduler.js.map +1 -1
- package/dist/scheduler/types.d.ts +1 -1
- package/dist/scheduler/types.d.ts.map +1 -1
- package/dist/state/schemas/job-metadata.d.ts +2 -2
- package/package.json +33 -8
- package/.turbo/turbo-build.log +0 -4
- package/.turbo/turbo-test.log +0 -219
- package/.turbo/turbo-typecheck.log +0 -4
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/coverage-final.json +0 -51
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -251
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -210
- package/coverage/src/config/index.html +0 -191
- package/coverage/src/config/index.ts.html +0 -442
- package/coverage/src/config/interpolate.ts.html +0 -652
- package/coverage/src/config/loader.ts.html +0 -1501
- package/coverage/src/config/merge.ts.html +0 -823
- package/coverage/src/config/parser.ts.html +0 -1213
- package/coverage/src/config/schema.ts.html +0 -1123
- package/coverage/src/fleet-manager/errors.ts.html +0 -2326
- package/coverage/src/fleet-manager/event-types.ts.html +0 -1219
- package/coverage/src/fleet-manager/fleet-manager.ts.html +0 -7030
- package/coverage/src/fleet-manager/index.html +0 -206
- package/coverage/src/fleet-manager/index.ts.html +0 -469
- package/coverage/src/fleet-manager/job-manager.ts.html +0 -2074
- package/coverage/src/fleet-manager/job-queue.ts.html +0 -2479
- package/coverage/src/fleet-manager/types.ts.html +0 -2602
- package/coverage/src/index.html +0 -116
- package/coverage/src/index.ts.html +0 -181
- package/coverage/src/runner/errors.ts.html +0 -1006
- package/coverage/src/runner/index.html +0 -191
- package/coverage/src/runner/index.ts.html +0 -256
- package/coverage/src/runner/job-executor.ts.html +0 -1429
- package/coverage/src/runner/message-processor.ts.html +0 -1150
- package/coverage/src/runner/sdk-adapter.ts.html +0 -658
- package/coverage/src/runner/types.ts.html +0 -559
- package/coverage/src/scheduler/errors.ts.html +0 -388
- package/coverage/src/scheduler/index.html +0 -206
- package/coverage/src/scheduler/index.ts.html +0 -244
- package/coverage/src/scheduler/interval.ts.html +0 -652
- package/coverage/src/scheduler/schedule-runner.ts.html +0 -1411
- package/coverage/src/scheduler/schedule-state.ts.html +0 -718
- package/coverage/src/scheduler/scheduler.ts.html +0 -1795
- package/coverage/src/scheduler/types.ts.html +0 -733
- package/coverage/src/state/directory.ts.html +0 -736
- package/coverage/src/state/errors.ts.html +0 -376
- package/coverage/src/state/fleet-state.ts.html +0 -937
- package/coverage/src/state/index.html +0 -221
- package/coverage/src/state/index.ts.html +0 -322
- package/coverage/src/state/job-metadata.ts.html +0 -1420
- package/coverage/src/state/job-output.ts.html +0 -1033
- package/coverage/src/state/schemas/fleet-state.ts.html +0 -445
- package/coverage/src/state/schemas/index.html +0 -176
- package/coverage/src/state/schemas/index.ts.html +0 -286
- package/coverage/src/state/schemas/job-metadata.ts.html +0 -628
- package/coverage/src/state/schemas/job-output.ts.html +0 -616
- package/coverage/src/state/schemas/session-info.ts.html +0 -361
- package/coverage/src/state/session.ts.html +0 -844
- package/coverage/src/state/types.ts.html +0 -262
- package/coverage/src/state/utils/atomic.ts.html +0 -748
- package/coverage/src/state/utils/index.html +0 -146
- package/coverage/src/state/utils/index.ts.html +0 -103
- package/coverage/src/state/utils/reads.ts.html +0 -1621
- package/coverage/src/work-sources/adapters/github.ts.html +0 -3583
- package/coverage/src/work-sources/adapters/index.html +0 -131
- package/coverage/src/work-sources/adapters/index.ts.html +0 -277
- package/coverage/src/work-sources/errors.ts.html +0 -298
- package/coverage/src/work-sources/index.html +0 -176
- package/coverage/src/work-sources/index.ts.html +0 -529
- package/coverage/src/work-sources/manager.ts.html +0 -1324
- package/coverage/src/work-sources/registry.ts.html +0 -619
- package/coverage/src/work-sources/types.ts.html +0 -568
- package/dist/fleet-manager/__tests__/event-helpers.test.d.ts +0 -7
- package/dist/fleet-manager/__tests__/event-helpers.test.d.ts.map +0 -1
- package/dist/fleet-manager/__tests__/event-helpers.test.js +0 -368
- package/dist/fleet-manager/__tests__/event-helpers.test.js.map +0 -1
- package/src/config/__tests__/agent.test.ts +0 -864
- package/src/config/__tests__/interpolate.test.ts +0 -644
- package/src/config/__tests__/loader.test.ts +0 -784
- package/src/config/__tests__/merge.test.ts +0 -751
- package/src/config/__tests__/parser.test.ts +0 -533
- package/src/config/__tests__/schema.test.ts +0 -873
- package/src/config/index.ts +0 -119
- package/src/config/interpolate.ts +0 -189
- package/src/config/loader.ts +0 -472
- package/src/config/merge.ts +0 -246
- package/src/config/parser.ts +0 -376
- package/src/config/schema.ts +0 -346
- package/src/fleet-manager/__tests__/coverage.test.ts +0 -2869
- package/src/fleet-manager/__tests__/errors.test.ts +0 -660
- package/src/fleet-manager/__tests__/event-helpers.test.ts +0 -448
- package/src/fleet-manager/__tests__/integration.test.ts +0 -1209
- package/src/fleet-manager/__tests__/job-control.test.ts +0 -283
- package/src/fleet-manager/__tests__/job-manager.test.ts +0 -869
- package/src/fleet-manager/__tests__/job-queue.test.ts +0 -401
- package/src/fleet-manager/__tests__/reload.test.ts +0 -751
- package/src/fleet-manager/__tests__/status-queries.test.ts +0 -595
- package/src/fleet-manager/__tests__/trigger.test.ts +0 -601
- package/src/fleet-manager/errors.ts +0 -747
- package/src/fleet-manager/event-types.ts +0 -378
- package/src/fleet-manager/fleet-manager.ts +0 -2315
- package/src/fleet-manager/index.ts +0 -128
- package/src/fleet-manager/job-manager.ts +0 -663
- package/src/fleet-manager/job-queue.ts +0 -798
- package/src/fleet-manager/types.ts +0 -839
- package/src/index.ts +0 -32
- package/src/runner/__tests__/errors.test.ts +0 -382
- package/src/runner/__tests__/job-executor.test.ts +0 -1708
- package/src/runner/__tests__/message-processor.test.ts +0 -960
- package/src/runner/__tests__/sdk-adapter.test.ts +0 -626
- package/src/runner/errors.ts +0 -307
- package/src/runner/index.ts +0 -57
- package/src/runner/job-executor.ts +0 -448
- package/src/runner/message-processor.ts +0 -355
- package/src/runner/sdk-adapter.ts +0 -191
- package/src/runner/types.ts +0 -158
- package/src/scheduler/__tests__/errors.test.ts +0 -159
- package/src/scheduler/__tests__/interval.test.ts +0 -515
- package/src/scheduler/__tests__/schedule-runner.test.ts +0 -798
- package/src/scheduler/__tests__/schedule-state.test.ts +0 -671
- package/src/scheduler/__tests__/scheduler.test.ts +0 -1280
- package/src/scheduler/errors.ts +0 -101
- package/src/scheduler/index.ts +0 -53
- package/src/scheduler/interval.ts +0 -189
- package/src/scheduler/schedule-runner.ts +0 -442
- package/src/scheduler/schedule-state.ts +0 -211
- package/src/scheduler/scheduler.ts +0 -570
- package/src/scheduler/types.ts +0 -216
- package/src/state/__tests__/directory.test.ts +0 -595
- package/src/state/__tests__/fleet-state.test.ts +0 -868
- package/src/state/__tests__/job-metadata-schema.test.ts +0 -414
- package/src/state/__tests__/job-metadata.test.ts +0 -831
- package/src/state/__tests__/job-output.test.ts +0 -856
- package/src/state/__tests__/session-schema.test.ts +0 -378
- package/src/state/__tests__/session.test.ts +0 -604
- package/src/state/directory.ts +0 -217
- package/src/state/errors.ts +0 -97
- package/src/state/fleet-state.ts +0 -284
- package/src/state/index.ts +0 -79
- package/src/state/job-metadata.ts +0 -445
- package/src/state/job-output.ts +0 -316
- package/src/state/schemas/__tests__/job-output.test.ts +0 -338
- package/src/state/schemas/fleet-state.ts +0 -120
- package/src/state/schemas/index.ts +0 -67
- package/src/state/schemas/job-metadata.ts +0 -181
- package/src/state/schemas/job-output.ts +0 -177
- package/src/state/schemas/session-info.ts +0 -92
- package/src/state/session.ts +0 -253
- package/src/state/types.ts +0 -59
- package/src/state/utils/__tests__/atomic.test.ts +0 -723
- package/src/state/utils/__tests__/reads.test.ts +0 -1071
- package/src/state/utils/atomic.ts +0 -221
- package/src/state/utils/index.ts +0 -6
- package/src/state/utils/reads.ts +0 -512
- package/src/work-sources/__tests__/github.test.ts +0 -1800
- package/src/work-sources/__tests__/manager.test.ts +0 -529
- package/src/work-sources/__tests__/registry.test.ts +0 -477
- package/src/work-sources/__tests__/types.test.ts +0 -479
- package/src/work-sources/adapters/github.ts +0 -1166
- package/src/work-sources/adapters/index.ts +0 -64
- package/src/work-sources/errors.ts +0 -71
- package/src/work-sources/index.ts +0 -148
- package/src/work-sources/manager.ts +0 -413
- package/src/work-sources/registry.ts +0 -178
- package/src/work-sources/types.ts +0 -161
- package/tsconfig.json +0 -9
- package/vitest.config.ts +0 -19
|
@@ -1,864 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { writeFile, mkdir, rm } from "node:fs/promises";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import {
|
|
6
|
-
parseAgentConfig,
|
|
7
|
-
validateAgentConfig,
|
|
8
|
-
safeParseAgentConfig,
|
|
9
|
-
loadAgentConfig,
|
|
10
|
-
resolveAgentPath,
|
|
11
|
-
AgentValidationError,
|
|
12
|
-
AgentYamlSyntaxError,
|
|
13
|
-
FileReadError,
|
|
14
|
-
} from "../parser.js";
|
|
15
|
-
import {
|
|
16
|
-
AgentConfigSchema,
|
|
17
|
-
IdentitySchema,
|
|
18
|
-
SessionSchema,
|
|
19
|
-
ScheduleSchema,
|
|
20
|
-
McpServerSchema,
|
|
21
|
-
AgentChatSchema,
|
|
22
|
-
} from "../schema.js";
|
|
23
|
-
import type { AgentConfig } from "../schema.js";
|
|
24
|
-
|
|
25
|
-
describe("AgentConfigSchema", () => {
|
|
26
|
-
it("validates minimal agent config with just name", () => {
|
|
27
|
-
const result = AgentConfigSchema.safeParse({ name: "test-agent" });
|
|
28
|
-
expect(result.success).toBe(true);
|
|
29
|
-
if (result.success) {
|
|
30
|
-
expect(result.data.name).toBe("test-agent");
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("validates complete agent config with all fields", () => {
|
|
35
|
-
const config = {
|
|
36
|
-
name: "bragdoc-coder",
|
|
37
|
-
description: "A coding assistant agent",
|
|
38
|
-
workspace: "/home/agent/workspace",
|
|
39
|
-
repo: "https://github.com/example/repo",
|
|
40
|
-
identity: {
|
|
41
|
-
name: "Cody",
|
|
42
|
-
role: "developer",
|
|
43
|
-
personality: "helpful and concise",
|
|
44
|
-
},
|
|
45
|
-
system_prompt: "You are a helpful coding assistant.",
|
|
46
|
-
work_source: {
|
|
47
|
-
type: "github",
|
|
48
|
-
labels: {
|
|
49
|
-
ready: "ready",
|
|
50
|
-
in_progress: "in-progress",
|
|
51
|
-
},
|
|
52
|
-
cleanup_in_progress: true,
|
|
53
|
-
},
|
|
54
|
-
schedules: {
|
|
55
|
-
main: {
|
|
56
|
-
type: "interval",
|
|
57
|
-
interval: "5m",
|
|
58
|
-
prompt: "Check for new issues",
|
|
59
|
-
},
|
|
60
|
-
daily: {
|
|
61
|
-
type: "cron",
|
|
62
|
-
expression: "0 9 * * *",
|
|
63
|
-
prompt: "Daily check",
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
session: {
|
|
67
|
-
max_turns: 50,
|
|
68
|
-
timeout: "30m",
|
|
69
|
-
model: "claude-sonnet-4-20250514",
|
|
70
|
-
},
|
|
71
|
-
permissions: {
|
|
72
|
-
mode: "acceptEdits",
|
|
73
|
-
allowed_tools: ["Read", "Edit", "Write", "Bash"],
|
|
74
|
-
denied_tools: ["WebSearch"],
|
|
75
|
-
bash: {
|
|
76
|
-
allowed_commands: ["git", "npm"],
|
|
77
|
-
denied_patterns: ["rm -rf /"],
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
mcp_servers: {
|
|
81
|
-
github: {
|
|
82
|
-
command: "npx",
|
|
83
|
-
args: ["-y", "@modelcontextprotocol/server-github"],
|
|
84
|
-
env: {
|
|
85
|
-
GITHUB_TOKEN: "${GITHUB_TOKEN}",
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
filesystem: {
|
|
89
|
-
url: "http://localhost:3000/mcp",
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
chat: {
|
|
93
|
-
discord: {
|
|
94
|
-
channel_ids: ["123456789", "987654321"],
|
|
95
|
-
respond_to_mentions: true,
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
model: "claude-sonnet-4-20250514",
|
|
99
|
-
max_turns: 100,
|
|
100
|
-
permission_mode: "bypassPermissions",
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const result = AgentConfigSchema.safeParse(config);
|
|
104
|
-
expect(result.success).toBe(true);
|
|
105
|
-
if (result.success) {
|
|
106
|
-
expect(result.data.name).toBe("bragdoc-coder");
|
|
107
|
-
expect(result.data.description).toBe("A coding assistant agent");
|
|
108
|
-
expect(result.data.identity?.name).toBe("Cody");
|
|
109
|
-
expect(result.data.schedules?.main.type).toBe("interval");
|
|
110
|
-
expect(result.data.schedules?.daily.type).toBe("cron");
|
|
111
|
-
expect(result.data.mcp_servers?.github.command).toBe("npx");
|
|
112
|
-
expect(result.data.chat?.discord?.channel_ids).toContain("123456789");
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("rejects agent config without name", () => {
|
|
117
|
-
const result = AgentConfigSchema.safeParse({
|
|
118
|
-
description: "An agent without a name",
|
|
119
|
-
});
|
|
120
|
-
expect(result.success).toBe(false);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("rejects invalid permission mode", () => {
|
|
124
|
-
const result = AgentConfigSchema.safeParse({
|
|
125
|
-
name: "test-agent",
|
|
126
|
-
permission_mode: "invalid-mode",
|
|
127
|
-
});
|
|
128
|
-
expect(result.success).toBe(false);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("accepts workspace as string path", () => {
|
|
132
|
-
const result = AgentConfigSchema.safeParse({
|
|
133
|
-
name: "test-agent",
|
|
134
|
-
workspace: "/path/to/workspace",
|
|
135
|
-
});
|
|
136
|
-
expect(result.success).toBe(true);
|
|
137
|
-
if (result.success) {
|
|
138
|
-
expect(result.data.workspace).toBe("/path/to/workspace");
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("accepts workspace as full workspace object", () => {
|
|
143
|
-
const result = AgentConfigSchema.safeParse({
|
|
144
|
-
name: "test-agent",
|
|
145
|
-
workspace: {
|
|
146
|
-
root: "/path/to/workspace",
|
|
147
|
-
auto_clone: false,
|
|
148
|
-
clone_depth: 5,
|
|
149
|
-
default_branch: "develop",
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
expect(result.success).toBe(true);
|
|
153
|
-
if (result.success) {
|
|
154
|
-
const workspace = result.data.workspace;
|
|
155
|
-
expect(typeof workspace).toBe("object");
|
|
156
|
-
if (typeof workspace === "object" && workspace !== null) {
|
|
157
|
-
expect(workspace.root).toBe("/path/to/workspace");
|
|
158
|
-
expect(workspace.auto_clone).toBe(false);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it("rejects negative max_turns", () => {
|
|
164
|
-
const result = AgentConfigSchema.safeParse({
|
|
165
|
-
name: "test-agent",
|
|
166
|
-
max_turns: -1,
|
|
167
|
-
});
|
|
168
|
-
expect(result.success).toBe(false);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it("rejects non-integer max_turns", () => {
|
|
172
|
-
const result = AgentConfigSchema.safeParse({
|
|
173
|
-
name: "test-agent",
|
|
174
|
-
max_turns: 1.5,
|
|
175
|
-
});
|
|
176
|
-
expect(result.success).toBe(false);
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
describe("IdentitySchema", () => {
|
|
181
|
-
it("parses empty identity", () => {
|
|
182
|
-
const result = IdentitySchema.safeParse({});
|
|
183
|
-
expect(result.success).toBe(true);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it("parses complete identity", () => {
|
|
187
|
-
const identity = {
|
|
188
|
-
name: "Claude",
|
|
189
|
-
role: "assistant",
|
|
190
|
-
personality: "helpful and friendly",
|
|
191
|
-
};
|
|
192
|
-
const result = IdentitySchema.safeParse(identity);
|
|
193
|
-
expect(result.success).toBe(true);
|
|
194
|
-
if (result.success) {
|
|
195
|
-
expect(result.data.name).toBe("Claude");
|
|
196
|
-
expect(result.data.role).toBe("assistant");
|
|
197
|
-
expect(result.data.personality).toBe("helpful and friendly");
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
describe("SessionSchema", () => {
|
|
203
|
-
it("parses empty session", () => {
|
|
204
|
-
const result = SessionSchema.safeParse({});
|
|
205
|
-
expect(result.success).toBe(true);
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it("parses complete session", () => {
|
|
209
|
-
const session = {
|
|
210
|
-
max_turns: 100,
|
|
211
|
-
timeout: "1h",
|
|
212
|
-
model: "claude-opus-4-20250514",
|
|
213
|
-
};
|
|
214
|
-
const result = SessionSchema.safeParse(session);
|
|
215
|
-
expect(result.success).toBe(true);
|
|
216
|
-
if (result.success) {
|
|
217
|
-
expect(result.data.max_turns).toBe(100);
|
|
218
|
-
expect(result.data.timeout).toBe("1h");
|
|
219
|
-
expect(result.data.model).toBe("claude-opus-4-20250514");
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it("rejects non-positive max_turns", () => {
|
|
224
|
-
const result = SessionSchema.safeParse({ max_turns: 0 });
|
|
225
|
-
expect(result.success).toBe(false);
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
describe("ScheduleSchema", () => {
|
|
230
|
-
it("parses interval schedule", () => {
|
|
231
|
-
const schedule = {
|
|
232
|
-
type: "interval",
|
|
233
|
-
interval: "5m",
|
|
234
|
-
prompt: "Check for updates",
|
|
235
|
-
};
|
|
236
|
-
const result = ScheduleSchema.safeParse(schedule);
|
|
237
|
-
expect(result.success).toBe(true);
|
|
238
|
-
if (result.success) {
|
|
239
|
-
expect(result.data.type).toBe("interval");
|
|
240
|
-
expect(result.data.interval).toBe("5m");
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it("parses cron schedule", () => {
|
|
245
|
-
const schedule = {
|
|
246
|
-
type: "cron",
|
|
247
|
-
expression: "0 9 * * 1-5",
|
|
248
|
-
prompt: "Morning check",
|
|
249
|
-
};
|
|
250
|
-
const result = ScheduleSchema.safeParse(schedule);
|
|
251
|
-
expect(result.success).toBe(true);
|
|
252
|
-
if (result.success) {
|
|
253
|
-
expect(result.data.type).toBe("cron");
|
|
254
|
-
expect(result.data.expression).toBe("0 9 * * 1-5");
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
it("parses webhook schedule", () => {
|
|
259
|
-
const schedule = {
|
|
260
|
-
type: "webhook",
|
|
261
|
-
prompt: "Handle webhook",
|
|
262
|
-
};
|
|
263
|
-
const result = ScheduleSchema.safeParse(schedule);
|
|
264
|
-
expect(result.success).toBe(true);
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
it("parses chat schedule", () => {
|
|
268
|
-
const schedule = {
|
|
269
|
-
type: "chat",
|
|
270
|
-
};
|
|
271
|
-
const result = ScheduleSchema.safeParse(schedule);
|
|
272
|
-
expect(result.success).toBe(true);
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
it("parses schedule with work_source override", () => {
|
|
276
|
-
const schedule = {
|
|
277
|
-
type: "interval",
|
|
278
|
-
interval: "10m",
|
|
279
|
-
work_source: {
|
|
280
|
-
type: "github",
|
|
281
|
-
labels: {
|
|
282
|
-
ready: "urgent",
|
|
283
|
-
},
|
|
284
|
-
},
|
|
285
|
-
};
|
|
286
|
-
const result = ScheduleSchema.safeParse(schedule);
|
|
287
|
-
expect(result.success).toBe(true);
|
|
288
|
-
if (result.success) {
|
|
289
|
-
expect(result.data.work_source?.labels?.ready).toBe("urgent");
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it("rejects invalid schedule type", () => {
|
|
294
|
-
const result = ScheduleSchema.safeParse({
|
|
295
|
-
type: "invalid",
|
|
296
|
-
});
|
|
297
|
-
expect(result.success).toBe(false);
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
describe("McpServerSchema", () => {
|
|
302
|
-
it("parses command-based MCP server", () => {
|
|
303
|
-
const server = {
|
|
304
|
-
command: "npx",
|
|
305
|
-
args: ["-y", "@modelcontextprotocol/server-github"],
|
|
306
|
-
env: {
|
|
307
|
-
GITHUB_TOKEN: "token",
|
|
308
|
-
},
|
|
309
|
-
};
|
|
310
|
-
const result = McpServerSchema.safeParse(server);
|
|
311
|
-
expect(result.success).toBe(true);
|
|
312
|
-
if (result.success) {
|
|
313
|
-
expect(result.data.command).toBe("npx");
|
|
314
|
-
expect(result.data.args).toContain("-y");
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
it("parses URL-based MCP server", () => {
|
|
319
|
-
const server = {
|
|
320
|
-
url: "http://localhost:3000/mcp",
|
|
321
|
-
};
|
|
322
|
-
const result = McpServerSchema.safeParse(server);
|
|
323
|
-
expect(result.success).toBe(true);
|
|
324
|
-
if (result.success) {
|
|
325
|
-
expect(result.data.url).toBe("http://localhost:3000/mcp");
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
it("parses empty MCP server config", () => {
|
|
330
|
-
const result = McpServerSchema.safeParse({});
|
|
331
|
-
expect(result.success).toBe(true);
|
|
332
|
-
});
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
describe("AgentChatSchema", () => {
|
|
336
|
-
it("parses empty chat config", () => {
|
|
337
|
-
const result = AgentChatSchema.safeParse({});
|
|
338
|
-
expect(result.success).toBe(true);
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
it("parses discord chat config", () => {
|
|
342
|
-
const chat = {
|
|
343
|
-
discord: {
|
|
344
|
-
channel_ids: ["123", "456"],
|
|
345
|
-
respond_to_mentions: false,
|
|
346
|
-
},
|
|
347
|
-
};
|
|
348
|
-
const result = AgentChatSchema.safeParse(chat);
|
|
349
|
-
expect(result.success).toBe(true);
|
|
350
|
-
if (result.success) {
|
|
351
|
-
expect(result.data.discord?.channel_ids).toHaveLength(2);
|
|
352
|
-
expect(result.data.discord?.respond_to_mentions).toBe(false);
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
it("applies default respond_to_mentions", () => {
|
|
357
|
-
const chat = {
|
|
358
|
-
discord: {
|
|
359
|
-
channel_ids: ["123"],
|
|
360
|
-
},
|
|
361
|
-
};
|
|
362
|
-
const result = AgentChatSchema.safeParse(chat);
|
|
363
|
-
expect(result.success).toBe(true);
|
|
364
|
-
if (result.success) {
|
|
365
|
-
expect(result.data.discord?.respond_to_mentions).toBe(true);
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
describe("parseAgentConfig", () => {
|
|
371
|
-
it("parses valid agent YAML", () => {
|
|
372
|
-
const yaml = `
|
|
373
|
-
name: test-agent
|
|
374
|
-
description: A test agent
|
|
375
|
-
`;
|
|
376
|
-
const config = parseAgentConfig(yaml);
|
|
377
|
-
expect(config.name).toBe("test-agent");
|
|
378
|
-
expect(config.description).toBe("A test agent");
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
it("parses complete agent YAML from SPEC example", () => {
|
|
382
|
-
const yaml = `
|
|
383
|
-
name: bragdoc-coder
|
|
384
|
-
description: A coding assistant for the bragdoc project
|
|
385
|
-
workspace: ~/projects/bragdoc
|
|
386
|
-
repo: https://github.com/example/bragdoc
|
|
387
|
-
|
|
388
|
-
identity:
|
|
389
|
-
name: Cody
|
|
390
|
-
role: developer
|
|
391
|
-
|
|
392
|
-
work_source:
|
|
393
|
-
type: github
|
|
394
|
-
labels:
|
|
395
|
-
ready: "ready"
|
|
396
|
-
in_progress: "in-progress"
|
|
397
|
-
|
|
398
|
-
schedules:
|
|
399
|
-
main:
|
|
400
|
-
type: interval
|
|
401
|
-
interval: "5m"
|
|
402
|
-
prompt: Check for new issues
|
|
403
|
-
|
|
404
|
-
permissions:
|
|
405
|
-
mode: acceptEdits
|
|
406
|
-
allowed_tools:
|
|
407
|
-
- Read
|
|
408
|
-
- Edit
|
|
409
|
-
- Write
|
|
410
|
-
- Bash
|
|
411
|
-
bash:
|
|
412
|
-
allowed_commands:
|
|
413
|
-
- git
|
|
414
|
-
- npm
|
|
415
|
-
- pnpm
|
|
416
|
-
|
|
417
|
-
mcp_servers:
|
|
418
|
-
github:
|
|
419
|
-
command: npx
|
|
420
|
-
args:
|
|
421
|
-
- "-y"
|
|
422
|
-
- "@modelcontextprotocol/server-github"
|
|
423
|
-
|
|
424
|
-
model: claude-sonnet-4-20250514
|
|
425
|
-
max_turns: 100
|
|
426
|
-
`;
|
|
427
|
-
const config = parseAgentConfig(yaml, "/path/to/agent.yaml");
|
|
428
|
-
expect(config.name).toBe("bragdoc-coder");
|
|
429
|
-
expect(config.workspace).toBe("~/projects/bragdoc");
|
|
430
|
-
expect(config.repo).toBe("https://github.com/example/bragdoc");
|
|
431
|
-
expect(config.identity?.name).toBe("Cody");
|
|
432
|
-
expect(config.work_source?.type).toBe("github");
|
|
433
|
-
expect(config.schedules?.main.type).toBe("interval");
|
|
434
|
-
expect(config.permissions?.mode).toBe("acceptEdits");
|
|
435
|
-
expect(config.mcp_servers?.github.command).toBe("npx");
|
|
436
|
-
expect(config.model).toBe("claude-sonnet-4-20250514");
|
|
437
|
-
expect(config.max_turns).toBe(100);
|
|
438
|
-
});
|
|
439
|
-
|
|
440
|
-
it("throws AgentYamlSyntaxError for invalid YAML", () => {
|
|
441
|
-
const yaml = `
|
|
442
|
-
name: test-agent
|
|
443
|
-
bad: indentation
|
|
444
|
-
`;
|
|
445
|
-
expect(() => parseAgentConfig(yaml, "/path/to/agent.yaml")).toThrow(
|
|
446
|
-
AgentYamlSyntaxError
|
|
447
|
-
);
|
|
448
|
-
});
|
|
449
|
-
|
|
450
|
-
it("includes file path in AgentYamlSyntaxError", () => {
|
|
451
|
-
const yaml = `name: test
|
|
452
|
-
bad: indent`;
|
|
453
|
-
try {
|
|
454
|
-
parseAgentConfig(yaml, "/path/to/agent.yaml");
|
|
455
|
-
expect.fail("Should have thrown");
|
|
456
|
-
} catch (error) {
|
|
457
|
-
expect(error).toBeInstanceOf(AgentYamlSyntaxError);
|
|
458
|
-
const yamlError = error as AgentYamlSyntaxError;
|
|
459
|
-
expect(yamlError.filePath).toBe("/path/to/agent.yaml");
|
|
460
|
-
expect(yamlError.message).toContain("/path/to/agent.yaml");
|
|
461
|
-
}
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
it("throws AgentValidationError for missing required fields", () => {
|
|
465
|
-
const yaml = `
|
|
466
|
-
description: An agent without a name
|
|
467
|
-
`;
|
|
468
|
-
expect(() => parseAgentConfig(yaml, "/path/to/agent.yaml")).toThrow(
|
|
469
|
-
AgentValidationError
|
|
470
|
-
);
|
|
471
|
-
});
|
|
472
|
-
|
|
473
|
-
it("includes file path and field info in AgentValidationError", () => {
|
|
474
|
-
const yaml = `
|
|
475
|
-
description: Missing name field
|
|
476
|
-
`;
|
|
477
|
-
try {
|
|
478
|
-
parseAgentConfig(yaml, "/path/to/agent.yaml");
|
|
479
|
-
expect.fail("Should have thrown");
|
|
480
|
-
} catch (error) {
|
|
481
|
-
expect(error).toBeInstanceOf(AgentValidationError);
|
|
482
|
-
const validationError = error as AgentValidationError;
|
|
483
|
-
expect(validationError.filePath).toBe("/path/to/agent.yaml");
|
|
484
|
-
expect(validationError.message).toContain("/path/to/agent.yaml");
|
|
485
|
-
expect(validationError.issues).toHaveLength(1);
|
|
486
|
-
expect(validationError.issues[0].path).toBe("name");
|
|
487
|
-
}
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
it("throws AgentValidationError for empty file", () => {
|
|
491
|
-
const yaml = "";
|
|
492
|
-
expect(() => parseAgentConfig(yaml, "/path/to/agent.yaml")).toThrow(
|
|
493
|
-
AgentValidationError
|
|
494
|
-
);
|
|
495
|
-
});
|
|
496
|
-
|
|
497
|
-
it("throws AgentValidationError for invalid permission mode", () => {
|
|
498
|
-
const yaml = `
|
|
499
|
-
name: test-agent
|
|
500
|
-
permission_mode: invalid
|
|
501
|
-
`;
|
|
502
|
-
expect(() => parseAgentConfig(yaml)).toThrow(AgentValidationError);
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
it("reports multiple validation errors", () => {
|
|
506
|
-
const yaml = `
|
|
507
|
-
max_turns: "not-a-number"
|
|
508
|
-
permission_mode: invalid
|
|
509
|
-
`;
|
|
510
|
-
try {
|
|
511
|
-
parseAgentConfig(yaml);
|
|
512
|
-
expect.fail("Should have thrown");
|
|
513
|
-
} catch (error) {
|
|
514
|
-
expect(error).toBeInstanceOf(AgentValidationError);
|
|
515
|
-
const validationError = error as AgentValidationError;
|
|
516
|
-
expect(validationError.issues.length).toBeGreaterThanOrEqual(2);
|
|
517
|
-
}
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
it("uses default file path when not provided", () => {
|
|
521
|
-
const yaml = `description: missing name`;
|
|
522
|
-
try {
|
|
523
|
-
parseAgentConfig(yaml);
|
|
524
|
-
expect.fail("Should have thrown");
|
|
525
|
-
} catch (error) {
|
|
526
|
-
expect(error).toBeInstanceOf(AgentValidationError);
|
|
527
|
-
const validationError = error as AgentValidationError;
|
|
528
|
-
expect(validationError.filePath).toBe("<unknown>");
|
|
529
|
-
}
|
|
530
|
-
});
|
|
531
|
-
});
|
|
532
|
-
|
|
533
|
-
describe("validateAgentConfig", () => {
|
|
534
|
-
it("validates a valid config object", () => {
|
|
535
|
-
const config = {
|
|
536
|
-
name: "test-agent",
|
|
537
|
-
description: "A test agent",
|
|
538
|
-
};
|
|
539
|
-
const validated = validateAgentConfig(config);
|
|
540
|
-
expect(validated.name).toBe("test-agent");
|
|
541
|
-
});
|
|
542
|
-
|
|
543
|
-
it("throws AgentValidationError for invalid object", () => {
|
|
544
|
-
const config = {
|
|
545
|
-
description: "Missing name",
|
|
546
|
-
};
|
|
547
|
-
expect(() => validateAgentConfig(config, "/path/to/agent.yaml")).toThrow(
|
|
548
|
-
AgentValidationError
|
|
549
|
-
);
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
it("includes file path in error", () => {
|
|
553
|
-
try {
|
|
554
|
-
validateAgentConfig({}, "/custom/path.yaml");
|
|
555
|
-
expect.fail("Should have thrown");
|
|
556
|
-
} catch (error) {
|
|
557
|
-
expect(error).toBeInstanceOf(AgentValidationError);
|
|
558
|
-
const validationError = error as AgentValidationError;
|
|
559
|
-
expect(validationError.filePath).toBe("/custom/path.yaml");
|
|
560
|
-
}
|
|
561
|
-
});
|
|
562
|
-
});
|
|
563
|
-
|
|
564
|
-
describe("safeParseAgentConfig", () => {
|
|
565
|
-
it("returns success for valid YAML", () => {
|
|
566
|
-
const yaml = `
|
|
567
|
-
name: test-agent
|
|
568
|
-
description: Test
|
|
569
|
-
`;
|
|
570
|
-
const result = safeParseAgentConfig(yaml);
|
|
571
|
-
expect(result.success).toBe(true);
|
|
572
|
-
if (result.success) {
|
|
573
|
-
expect(result.data.name).toBe("test-agent");
|
|
574
|
-
}
|
|
575
|
-
});
|
|
576
|
-
|
|
577
|
-
it("returns error for invalid YAML syntax", () => {
|
|
578
|
-
const yaml = `
|
|
579
|
-
name: test
|
|
580
|
-
bad: indent
|
|
581
|
-
`;
|
|
582
|
-
const result = safeParseAgentConfig(yaml, "/path/to/agent.yaml");
|
|
583
|
-
expect(result.success).toBe(false);
|
|
584
|
-
if (!result.success) {
|
|
585
|
-
expect(result.error).toBeInstanceOf(AgentYamlSyntaxError);
|
|
586
|
-
}
|
|
587
|
-
});
|
|
588
|
-
|
|
589
|
-
it("returns error for schema validation failure", () => {
|
|
590
|
-
const yaml = `
|
|
591
|
-
description: missing name
|
|
592
|
-
`;
|
|
593
|
-
const result = safeParseAgentConfig(yaml, "/path/to/agent.yaml");
|
|
594
|
-
expect(result.success).toBe(false);
|
|
595
|
-
if (!result.success) {
|
|
596
|
-
expect(result.error).toBeInstanceOf(AgentValidationError);
|
|
597
|
-
}
|
|
598
|
-
});
|
|
599
|
-
});
|
|
600
|
-
|
|
601
|
-
describe("resolveAgentPath", () => {
|
|
602
|
-
it("returns absolute paths unchanged", () => {
|
|
603
|
-
const result = resolveAgentPath("/absolute/path/agent.yaml", "/base/dir");
|
|
604
|
-
expect(result).toBe("/absolute/path/agent.yaml");
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
it("resolves relative paths from base path", () => {
|
|
608
|
-
const result = resolveAgentPath("./agents/test.yaml", "/base/dir");
|
|
609
|
-
expect(result).toBe("/base/dir/agents/test.yaml");
|
|
610
|
-
});
|
|
611
|
-
|
|
612
|
-
it("resolves paths without ./ prefix", () => {
|
|
613
|
-
const result = resolveAgentPath("agents/test.yaml", "/base/dir");
|
|
614
|
-
expect(result).toBe("/base/dir/agents/test.yaml");
|
|
615
|
-
});
|
|
616
|
-
|
|
617
|
-
it("handles parent directory references", () => {
|
|
618
|
-
const result = resolveAgentPath("../other/agent.yaml", "/base/dir");
|
|
619
|
-
expect(result).toBe("/base/other/agent.yaml");
|
|
620
|
-
});
|
|
621
|
-
});
|
|
622
|
-
|
|
623
|
-
describe("loadAgentConfig", () => {
|
|
624
|
-
let testDir: string;
|
|
625
|
-
|
|
626
|
-
beforeEach(async () => {
|
|
627
|
-
testDir = join(tmpdir(), `herdctl-test-${Date.now()}`);
|
|
628
|
-
await mkdir(testDir, { recursive: true });
|
|
629
|
-
});
|
|
630
|
-
|
|
631
|
-
afterEach(async () => {
|
|
632
|
-
await rm(testDir, { recursive: true, force: true });
|
|
633
|
-
});
|
|
634
|
-
|
|
635
|
-
it("loads and parses an agent file", async () => {
|
|
636
|
-
const agentPath = join(testDir, "agent.yaml");
|
|
637
|
-
await writeFile(
|
|
638
|
-
agentPath,
|
|
639
|
-
`
|
|
640
|
-
name: test-agent
|
|
641
|
-
description: A test agent
|
|
642
|
-
model: claude-sonnet-4-20250514
|
|
643
|
-
`
|
|
644
|
-
);
|
|
645
|
-
|
|
646
|
-
const config = await loadAgentConfig(agentPath);
|
|
647
|
-
expect(config.name).toBe("test-agent");
|
|
648
|
-
expect(config.model).toBe("claude-sonnet-4-20250514");
|
|
649
|
-
});
|
|
650
|
-
|
|
651
|
-
it("resolves relative path from fleet config", async () => {
|
|
652
|
-
const agentsDir = join(testDir, "agents");
|
|
653
|
-
await mkdir(agentsDir, { recursive: true });
|
|
654
|
-
|
|
655
|
-
const agentPath = join(agentsDir, "test.yaml");
|
|
656
|
-
await writeFile(
|
|
657
|
-
agentPath,
|
|
658
|
-
`
|
|
659
|
-
name: relative-agent
|
|
660
|
-
`
|
|
661
|
-
);
|
|
662
|
-
|
|
663
|
-
const fleetConfigPath = join(testDir, "herdctl.yaml");
|
|
664
|
-
const config = await loadAgentConfig("./agents/test.yaml", fleetConfigPath);
|
|
665
|
-
expect(config.name).toBe("relative-agent");
|
|
666
|
-
});
|
|
667
|
-
|
|
668
|
-
it("throws FileReadError for non-existent file", async () => {
|
|
669
|
-
await expect(loadAgentConfig("/non/existent/agent.yaml")).rejects.toThrow(
|
|
670
|
-
FileReadError
|
|
671
|
-
);
|
|
672
|
-
});
|
|
673
|
-
|
|
674
|
-
it("includes file path in FileReadError", async () => {
|
|
675
|
-
const nonExistentPath = "/non/existent/agent.yaml";
|
|
676
|
-
try {
|
|
677
|
-
await loadAgentConfig(nonExistentPath);
|
|
678
|
-
expect.fail("Should have thrown");
|
|
679
|
-
} catch (error) {
|
|
680
|
-
expect(error).toBeInstanceOf(FileReadError);
|
|
681
|
-
const fileError = error as FileReadError;
|
|
682
|
-
expect(fileError.filePath).toBe(nonExistentPath);
|
|
683
|
-
expect(fileError.message).toContain(nonExistentPath);
|
|
684
|
-
}
|
|
685
|
-
});
|
|
686
|
-
|
|
687
|
-
it("throws AgentYamlSyntaxError for invalid YAML file", async () => {
|
|
688
|
-
const agentPath = join(testDir, "invalid.yaml");
|
|
689
|
-
await writeFile(
|
|
690
|
-
agentPath,
|
|
691
|
-
`
|
|
692
|
-
name: test
|
|
693
|
-
bad: indent
|
|
694
|
-
`
|
|
695
|
-
);
|
|
696
|
-
|
|
697
|
-
await expect(loadAgentConfig(agentPath)).rejects.toThrow(
|
|
698
|
-
AgentYamlSyntaxError
|
|
699
|
-
);
|
|
700
|
-
});
|
|
701
|
-
|
|
702
|
-
it("throws AgentValidationError for invalid config file", async () => {
|
|
703
|
-
const agentPath = join(testDir, "invalid-config.yaml");
|
|
704
|
-
await writeFile(
|
|
705
|
-
agentPath,
|
|
706
|
-
`
|
|
707
|
-
description: Missing name field
|
|
708
|
-
`
|
|
709
|
-
);
|
|
710
|
-
|
|
711
|
-
await expect(loadAgentConfig(agentPath)).rejects.toThrow(
|
|
712
|
-
AgentValidationError
|
|
713
|
-
);
|
|
714
|
-
});
|
|
715
|
-
|
|
716
|
-
it("handles complex agent with all fields", async () => {
|
|
717
|
-
const agentPath = join(testDir, "complex.yaml");
|
|
718
|
-
await writeFile(
|
|
719
|
-
agentPath,
|
|
720
|
-
`
|
|
721
|
-
name: complex-agent
|
|
722
|
-
description: A fully configured agent
|
|
723
|
-
workspace: ~/workspace
|
|
724
|
-
repo: https://github.com/example/repo
|
|
725
|
-
|
|
726
|
-
identity:
|
|
727
|
-
name: Ava
|
|
728
|
-
role: assistant
|
|
729
|
-
personality: helpful
|
|
730
|
-
|
|
731
|
-
work_source:
|
|
732
|
-
type: github
|
|
733
|
-
labels:
|
|
734
|
-
ready: "ready"
|
|
735
|
-
|
|
736
|
-
schedules:
|
|
737
|
-
polling:
|
|
738
|
-
type: interval
|
|
739
|
-
interval: "10m"
|
|
740
|
-
|
|
741
|
-
session:
|
|
742
|
-
max_turns: 50
|
|
743
|
-
timeout: "1h"
|
|
744
|
-
model: claude-opus-4-20250514
|
|
745
|
-
|
|
746
|
-
permissions:
|
|
747
|
-
mode: bypassPermissions
|
|
748
|
-
allowed_tools:
|
|
749
|
-
- Read
|
|
750
|
-
- Write
|
|
751
|
-
|
|
752
|
-
mcp_servers:
|
|
753
|
-
test:
|
|
754
|
-
command: node
|
|
755
|
-
args:
|
|
756
|
-
- server.js
|
|
757
|
-
|
|
758
|
-
chat:
|
|
759
|
-
discord:
|
|
760
|
-
channel_ids:
|
|
761
|
-
- "123456"
|
|
762
|
-
|
|
763
|
-
model: claude-sonnet-4-20250514
|
|
764
|
-
max_turns: 100
|
|
765
|
-
permission_mode: acceptEdits
|
|
766
|
-
`
|
|
767
|
-
);
|
|
768
|
-
|
|
769
|
-
const config = await loadAgentConfig(agentPath);
|
|
770
|
-
expect(config.name).toBe("complex-agent");
|
|
771
|
-
expect(config.identity?.name).toBe("Ava");
|
|
772
|
-
expect(config.schedules?.polling.type).toBe("interval");
|
|
773
|
-
expect(config.session?.max_turns).toBe(50);
|
|
774
|
-
expect(config.permissions?.mode).toBe("bypassPermissions");
|
|
775
|
-
expect(config.mcp_servers?.test.command).toBe("node");
|
|
776
|
-
expect(config.chat?.discord?.channel_ids).toContain("123456");
|
|
777
|
-
});
|
|
778
|
-
});
|
|
779
|
-
|
|
780
|
-
describe("Error classes", () => {
|
|
781
|
-
it("AgentValidationError has correct properties", () => {
|
|
782
|
-
const mockZodError = {
|
|
783
|
-
issues: [
|
|
784
|
-
{ path: ["name"], message: "Required", code: "invalid_type" },
|
|
785
|
-
{ path: ["max_turns"], message: "Expected number", code: "invalid_type" },
|
|
786
|
-
],
|
|
787
|
-
} as never;
|
|
788
|
-
|
|
789
|
-
const error = new AgentValidationError(mockZodError, "/path/to/agent.yaml");
|
|
790
|
-
expect(error.name).toBe("AgentValidationError");
|
|
791
|
-
expect(error.filePath).toBe("/path/to/agent.yaml");
|
|
792
|
-
expect(error.issues).toHaveLength(2);
|
|
793
|
-
expect(error.message).toContain("/path/to/agent.yaml");
|
|
794
|
-
expect(error.message).toContain("name: Required");
|
|
795
|
-
expect(error.message).toContain("max_turns: Expected number");
|
|
796
|
-
});
|
|
797
|
-
|
|
798
|
-
it("AgentYamlSyntaxError has correct properties", () => {
|
|
799
|
-
const mockYamlError = {
|
|
800
|
-
message: "Bad indentation",
|
|
801
|
-
linePos: [{ line: 5, col: 3 }],
|
|
802
|
-
} as never;
|
|
803
|
-
|
|
804
|
-
const error = new AgentYamlSyntaxError(mockYamlError, "/path/to/agent.yaml");
|
|
805
|
-
expect(error.name).toBe("AgentYamlSyntaxError");
|
|
806
|
-
expect(error.filePath).toBe("/path/to/agent.yaml");
|
|
807
|
-
expect(error.line).toBe(5);
|
|
808
|
-
expect(error.column).toBe(3);
|
|
809
|
-
expect(error.message).toContain("/path/to/agent.yaml");
|
|
810
|
-
expect(error.message).toContain("line 5");
|
|
811
|
-
expect(error.message).toContain("column 3");
|
|
812
|
-
});
|
|
813
|
-
|
|
814
|
-
it("AgentYamlSyntaxError handles missing position", () => {
|
|
815
|
-
const mockYamlError = {
|
|
816
|
-
message: "Unknown error",
|
|
817
|
-
linePos: undefined,
|
|
818
|
-
} as never;
|
|
819
|
-
|
|
820
|
-
const error = new AgentYamlSyntaxError(mockYamlError, "/path/to/agent.yaml");
|
|
821
|
-
expect(error.line).toBeUndefined();
|
|
822
|
-
expect(error.column).toBeUndefined();
|
|
823
|
-
expect(error.message).toContain("/path/to/agent.yaml");
|
|
824
|
-
});
|
|
825
|
-
|
|
826
|
-
it("FileReadError has correct properties", () => {
|
|
827
|
-
const cause = new Error("ENOENT: no such file");
|
|
828
|
-
const error = new FileReadError("/path/to/agent.yaml", cause);
|
|
829
|
-
expect(error.name).toBe("FileReadError");
|
|
830
|
-
expect(error.filePath).toBe("/path/to/agent.yaml");
|
|
831
|
-
expect(error.message).toContain("/path/to/agent.yaml");
|
|
832
|
-
expect(error.message).toContain("ENOENT");
|
|
833
|
-
});
|
|
834
|
-
|
|
835
|
-
it("FileReadError works without cause", () => {
|
|
836
|
-
const error = new FileReadError("/path/to/agent.yaml");
|
|
837
|
-
expect(error.name).toBe("FileReadError");
|
|
838
|
-
expect(error.message).toContain("/path/to/agent.yaml");
|
|
839
|
-
});
|
|
840
|
-
});
|
|
841
|
-
|
|
842
|
-
describe("type safety", () => {
|
|
843
|
-
it("returns properly typed AgentConfig", () => {
|
|
844
|
-
const yaml = `
|
|
845
|
-
name: test-agent
|
|
846
|
-
description: A test
|
|
847
|
-
model: claude-sonnet-4-20250514
|
|
848
|
-
max_turns: 50
|
|
849
|
-
permission_mode: acceptEdits
|
|
850
|
-
`;
|
|
851
|
-
const config: AgentConfig = parseAgentConfig(yaml);
|
|
852
|
-
|
|
853
|
-
// TypeScript compilation verifies these types
|
|
854
|
-
const _name: string = config.name;
|
|
855
|
-
const _description: string | undefined = config.description;
|
|
856
|
-
const _model: string | undefined = config.model;
|
|
857
|
-
const _maxTurns: number | undefined = config.max_turns;
|
|
858
|
-
|
|
859
|
-
expect(_name).toBe("test-agent");
|
|
860
|
-
expect(_description).toBe("A test");
|
|
861
|
-
expect(_model).toBe("claude-sonnet-4-20250514");
|
|
862
|
-
expect(_maxTurns).toBe(50);
|
|
863
|
-
});
|
|
864
|
-
});
|