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
|
import { describe, it, expect } from "bun:test";
import app from "../app";
import {
parseAgentSettingsForm,
type AgentSettingsInput,
} from "../routes/agents";
describe("agents UI — parseAgentSettingsForm", () => {
it("accepts a valid full form", () => {
const parsed = parseAgentSettingsForm({
enabled_kinds: ["triage", "fix"],
daily_budget_cents: "500",
monthly_budget_cents: "10000",
max_runs_per_hour: "30",
paused: "on",
});
expect(parsed.enabledKinds).toEqual(["triage", "fix"]);
expect(parsed.dailyBudgetCents).toBe(500);
expect(parsed.monthlyBudgetCents).toBe(10000);
expect(parsed.maxRunsPerHour).toBe(30);
expect(parsed.paused).toBe(true);
});
it("filters out unknown kinds", () => {
const parsed = parseAgentSettingsForm({
enabled_kinds: ["triage", "hacking", "DROP TABLE"],
});
expect(parsed.enabledKinds).toEqual(["triage"]);
});
it("uses defaults when form is empty", () => {
const parsed = parseAgentSettingsForm({} as AgentSettingsInput);
expect(parsed.enabledKinds).toEqual([]);
expect(parsed.dailyBudgetCents).toBe(100);
expect(parsed.monthlyBudgetCents).toBe(2000);
expect(parsed.maxRunsPerHour).toBe(20);
expect(parsed.paused).toBe(false);
});
it("rejects negative budgets (falls back to default)", () => {
const parsed = parseAgentSettingsForm({
daily_budget_cents: "-50",
monthly_budget_cents: "-1000",
});
expect(parsed.dailyBudgetCents).toBe(100);
expect(parsed.monthlyBudgetCents).toBe(2000);
});
it("caps over-large budgets", () => {
const parsed = parseAgentSettingsForm({
daily_budget_cents: "99999999",
monthly_budget_cents: "99999999999",
max_runs_per_hour: "99999",
});
expect(parsed.dailyBudgetCents).toBe(1_000_000);
expect(parsed.monthlyBudgetCents).toBe(50_000_000);
expect(parsed.maxRunsPerHour).toBe(1000);
});
it("accepts a single kind as a string (form single-select edge)", () => {
const parsed = parseAgentSettingsForm({ enabled_kinds: "heal_bot" });
expect(parsed.enabledKinds).toEqual(["heal_bot"]);
});
it("handles non-numeric budget gracefully", () => {
const parsed = parseAgentSettingsForm({
daily_budget_cents: "abc",
max_runs_per_hour: "xyz",
});
expect(parsed.dailyBudgetCents).toBe(100);
expect(parsed.maxRunsPerHour).toBe(20);
});
it("treats paused=true as true, paused=other as false", () => {
expect(parseAgentSettingsForm({ paused: "true" }).paused).toBe(true);
expect(parseAgentSettingsForm({ paused: "on" }).paused).toBe(true);
expect(parseAgentSettingsForm({ paused: "off" }).paused).toBe(false);
expect(parseAgentSettingsForm({ paused: "1" }).paused).toBe(false);
});
});
describe("agents UI — route auth smokes", () => {
it("POST /:owner/:repo/agents/:id/kill without session → 302 /login", async () => {
const res = await app.fetch(
new Request("http://test/alice/repo/agents/00000000-0000-0000-0000-000000000000/kill", {
method: "POST",
})
);
expect(res.status).toBe(302);
expect(res.headers.get("location")).toMatch(/\/login/);
});
it("GET /:owner/:repo/settings/agents without session → 302 /login", async () => {
const res = await app.fetch(
new Request("http://test/alice/repo/settings/agents")
);
expect(res.status).toBe(302);
expect(res.headers.get("location")).toMatch(/\/login/);
});
it("POST /:owner/:repo/settings/agents without session → 302 /login", async () => {
const res = await app.fetch(
new Request("http://test/alice/repo/settings/agents", {
method: "POST",
body: new URLSearchParams({ daily_budget_cents: "100" }),
})
);
expect(res.status).toBe(302);
expect(res.headers.get("location")).toMatch(/\/login/);
});
it("POST /:owner/:repo/settings/agents/pause without session → 302 /login", async () => {
const res = await app.fetch(
new Request("http://test/alice/repo/settings/agents/pause", {
method: "POST",
})
);
expect(res.status).toBe(302);
expect(res.headers.get("location")).toMatch(/\/login/);
});
it("GET /admin/agents without session → 302 /login", async () => {
const res = await app.fetch(new Request("http://test/admin/agents"));
expect(res.status).toBe(302);
expect(res.headers.get("location")).toMatch(/\/login/);
});
it("POST /admin/agents/pause-all without session → 302 /login", async () => {
const res = await app.fetch(
new Request("http://test/admin/agents/pause-all", { method: "POST" })
);
expect(res.status).toBe(302);
expect(res.headers.get("location")).toMatch(/\/login/);
});
});
|