@app-vitals/agent-runtime 1.107.1 → 1.107.3
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.
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent/src/runtime/agent-config-client.integration.test.ts
|
|
3
|
+
*
|
|
4
|
+
* Integration test of the runtime config-sync path (the `getConfig` adapter
|
|
5
|
+
* wired in entrypoint-main.ts: AgentConfigClient -> HttpShipwrightRuntimeClient)
|
|
6
|
+
* against a real fake admin server on localhost (Bun.serve, real sockets).
|
|
7
|
+
*
|
|
8
|
+
* Covers: success, non-2xx, timeout and malformed-body paths, plus the
|
|
9
|
+
* RecordedAgentConfigClient cassette double.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { afterAll, beforeAll, describe, expect, it } from "bun:test";
|
|
13
|
+
import type { AgentConfigResponse } from "@app-vitals/agent-admin";
|
|
14
|
+
import {
|
|
15
|
+
type AgentConfigClient,
|
|
16
|
+
RecordedAgentConfigClient,
|
|
17
|
+
} from "./agent-config-client.ts";
|
|
18
|
+
import {
|
|
19
|
+
HttpShipwrightRuntimeClient,
|
|
20
|
+
ShipwrightClientError,
|
|
21
|
+
} from "./shipwright-runtime-client.ts";
|
|
22
|
+
|
|
23
|
+
const API_KEY = "test-bearer-key";
|
|
24
|
+
|
|
25
|
+
const SAMPLE_CONFIG: AgentConfigResponse = {
|
|
26
|
+
specialty: "coding",
|
|
27
|
+
env: { ANTHROPIC_MODEL: "claude-sonnet-4-6" },
|
|
28
|
+
allowedTools: ["Read", "Bash"],
|
|
29
|
+
plugins: [{ marketplace: "shipwright", plugin: "my-plugin" }],
|
|
30
|
+
repos: [],
|
|
31
|
+
reviewAuthorAllowlist: [],
|
|
32
|
+
patchAuthorAllowlist: [],
|
|
33
|
+
restrictSlackToMembers: false,
|
|
34
|
+
memberEmails: [],
|
|
35
|
+
autoPostReviews: true,
|
|
36
|
+
allowSelfReview: false,
|
|
37
|
+
minConfidence: 75,
|
|
38
|
+
maxFindings: 5,
|
|
39
|
+
cleanupMergedWorktrees: true,
|
|
40
|
+
cleanupAfterDays: 14,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// Agent id selects the fake server's behaviour.
|
|
44
|
+
let server: ReturnType<typeof Bun.serve>;
|
|
45
|
+
let seenAuth: string | null = null;
|
|
46
|
+
|
|
47
|
+
beforeAll(() => {
|
|
48
|
+
server = Bun.serve({
|
|
49
|
+
port: 0,
|
|
50
|
+
async fetch(req) {
|
|
51
|
+
const match = new URL(req.url).pathname.match(
|
|
52
|
+
/^\/agents\/([^/]+)\/config$/,
|
|
53
|
+
);
|
|
54
|
+
if (!match) return new Response("not found", { status: 404 });
|
|
55
|
+
seenAuth = req.headers.get("Authorization");
|
|
56
|
+
switch (match[1]) {
|
|
57
|
+
case "ok":
|
|
58
|
+
return Response.json(SAMPLE_CONFIG);
|
|
59
|
+
case "missing":
|
|
60
|
+
return Response.json({ error: "Not found" }, { status: 404 });
|
|
61
|
+
case "denied":
|
|
62
|
+
return Response.json({ error: "Unauthorized" }, { status: 401 });
|
|
63
|
+
case "boom":
|
|
64
|
+
return Response.json({ error: "Internal" }, { status: 500 });
|
|
65
|
+
case "malformed":
|
|
66
|
+
return new Response("{not json", {
|
|
67
|
+
status: 200,
|
|
68
|
+
headers: { "Content-Type": "application/json" },
|
|
69
|
+
});
|
|
70
|
+
case "slow":
|
|
71
|
+
await Bun.sleep(2_000);
|
|
72
|
+
return Response.json(SAMPLE_CONFIG);
|
|
73
|
+
default:
|
|
74
|
+
return new Response("not found", { status: 404 });
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
afterAll(() => {
|
|
81
|
+
server.stop(true);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
function makeClient(timeoutMs?: number): AgentConfigClient {
|
|
85
|
+
const http = new HttpShipwrightRuntimeClient({
|
|
86
|
+
apiUrl: `http://localhost:${server.port}`,
|
|
87
|
+
apiKey: API_KEY,
|
|
88
|
+
fetchFn:
|
|
89
|
+
timeoutMs === undefined
|
|
90
|
+
? undefined
|
|
91
|
+
: (url, init) => {
|
|
92
|
+
const signal = AbortSignal.timeout(timeoutMs);
|
|
93
|
+
return url instanceof Request
|
|
94
|
+
? fetch(new Request(url, { signal }))
|
|
95
|
+
: fetch(url, { ...init, signal });
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
// Same adapter shape as entrypoint-main.ts
|
|
99
|
+
return { getConfig: (id) => http.getAgentConfigBundle(id) };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
describe("runtime config client against a fake admin server", () => {
|
|
103
|
+
it("returns the config and sends the bearer token on 200", async () => {
|
|
104
|
+
const result = await makeClient().getConfig("ok");
|
|
105
|
+
|
|
106
|
+
expect(result).toEqual(SAMPLE_CONFIG);
|
|
107
|
+
expect(seenAuth).toBe(`Bearer ${API_KEY}`);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it.each([
|
|
111
|
+
["missing", 404],
|
|
112
|
+
["denied", 401],
|
|
113
|
+
["boom", 500],
|
|
114
|
+
])(
|
|
115
|
+
"throws ShipwrightClientError with the status for %s",
|
|
116
|
+
async (id, status) => {
|
|
117
|
+
const err = await makeClient()
|
|
118
|
+
.getConfig(id)
|
|
119
|
+
.catch((e) => e);
|
|
120
|
+
|
|
121
|
+
expect(err).toBeInstanceOf(ShipwrightClientError);
|
|
122
|
+
expect(err.statusCode).toBe(status);
|
|
123
|
+
expect(err.message).toContain(`/agents/${id}/config`);
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
it("rejects when the server is slower than the caller's timeout", async () => {
|
|
128
|
+
const start = Date.now();
|
|
129
|
+
const err = await makeClient(100)
|
|
130
|
+
.getConfig("slow")
|
|
131
|
+
.catch((e) => e);
|
|
132
|
+
|
|
133
|
+
expect(err).toBeInstanceOf(Error);
|
|
134
|
+
expect(err).not.toBeInstanceOf(ShipwrightClientError);
|
|
135
|
+
expect(Date.now() - start).toBeLessThan(1_500);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("rejects (without a ShipwrightClientError) on a malformed 200 body", async () => {
|
|
139
|
+
const err = await makeClient()
|
|
140
|
+
.getConfig("malformed")
|
|
141
|
+
.catch((e) => e);
|
|
142
|
+
|
|
143
|
+
expect(err).toBeInstanceOf(Error);
|
|
144
|
+
expect(err).not.toBeInstanceOf(ShipwrightClientError);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("RecordedAgentConfigClient returns its cassette for any agent id", async () => {
|
|
148
|
+
const client = new RecordedAgentConfigClient(SAMPLE_CONFIG);
|
|
149
|
+
|
|
150
|
+
expect(await client.getConfig("a")).toEqual(SAMPLE_CONFIG);
|
|
151
|
+
expect(await client.getConfig("b")).toEqual(SAMPLE_CONFIG);
|
|
152
|
+
});
|
|
153
|
+
});
|
package/claude.ts
CHANGED
|
@@ -225,7 +225,9 @@ const CONNECTION_LOST_MID_RESPONSE = "Connection lost mid-response";
|
|
|
225
225
|
function _isConnectionLostMidResponse(err: unknown): err is ClaudeRunError {
|
|
226
226
|
return (
|
|
227
227
|
err instanceof ClaudeRunError &&
|
|
228
|
-
|
|
228
|
+
// resultMessage can be undefined at runtime (CLI is_error result with no
|
|
229
|
+
// result text); a TypeError here would mask the original ClaudeRunError.
|
|
230
|
+
err.resultMessage?.includes(CONNECTION_LOST_MID_RESPONSE) === true
|
|
229
231
|
);
|
|
230
232
|
}
|
|
231
233
|
|
|
@@ -749,7 +751,7 @@ export function createRunClaude(
|
|
|
749
751
|
throw new ClaudeRunError(
|
|
750
752
|
`claude exited ${exitCode}: api_error_status=${result.api_error_status ?? "unknown"} ${result.result}`,
|
|
751
753
|
result.api_error_status,
|
|
752
|
-
result.result,
|
|
754
|
+
result.result ?? "",
|
|
753
755
|
result.session_id,
|
|
754
756
|
result.modelUsage ?? modelUsage,
|
|
755
757
|
telemetry,
|
|
@@ -789,7 +791,7 @@ export function createRunClaude(
|
|
|
789
791
|
throw new ClaudeRunError(
|
|
790
792
|
`claude error: ${result.result}`,
|
|
791
793
|
result.api_error_status,
|
|
792
|
-
result.result,
|
|
794
|
+
result.result ?? "",
|
|
793
795
|
result.session_id,
|
|
794
796
|
result.modelUsage ?? modelUsage,
|
|
795
797
|
telemetry,
|
package/claude.unit.test.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Note: Identity injection removed — identity is now handled via CLAUDE.md in the workspace.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import "./test-env.ts";
|
|
9
|
+
import "./test-support/test-env.ts";
|
|
10
10
|
import { beforeEach, describe, expect, mock, test } from "bun:test";
|
|
11
11
|
import {
|
|
12
12
|
existsSync,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
import { tmpdir } from "node:os";
|
|
19
19
|
import { join } from "node:path";
|
|
20
20
|
import type { ErrorCapturingClient } from "@app-vitals/agent-lib/sentry";
|
|
21
|
-
import { TEST_AGENT_HOME } from "./test-env.ts";
|
|
21
|
+
import { TEST_AGENT_HOME } from "./test-support/test-env.ts";
|
|
22
22
|
|
|
23
23
|
const MODEL = "claude-opus-4-6";
|
|
24
24
|
const WORKSPACE = join(TEST_AGENT_HOME, "workspace");
|
|
@@ -1521,6 +1521,41 @@ describe("connection-lost-mid-response retry", () => {
|
|
|
1521
1521
|
expect(capturedExceptions).toHaveLength(0);
|
|
1522
1522
|
});
|
|
1523
1523
|
|
|
1524
|
+
test("is_error result with no result text rethrows ClaudeRunError, not a TypeError (error-7854213708)", async () => {
|
|
1525
|
+
const noResultText = JSON.stringify({
|
|
1526
|
+
type: "result",
|
|
1527
|
+
subtype: "error",
|
|
1528
|
+
session_id: "sess-undef",
|
|
1529
|
+
is_error: true,
|
|
1530
|
+
api_error_status: 403,
|
|
1531
|
+
});
|
|
1532
|
+
const mockSpawn = mock(
|
|
1533
|
+
() =>
|
|
1534
|
+
fakeProc(noResultText, "", 1) as ReturnType<typeof Bun.spawn>,
|
|
1535
|
+
);
|
|
1536
|
+
|
|
1537
|
+
mockGetSession.mockClear();
|
|
1538
|
+
mockGetSession.mockReturnValue(undefined);
|
|
1539
|
+
capturedMessages = [];
|
|
1540
|
+
capturedExceptions = [];
|
|
1541
|
+
|
|
1542
|
+
const { ClaudeRunError } = await import("./claude.ts");
|
|
1543
|
+
const runClaude = createRunClaude(
|
|
1544
|
+
mockSpawn as typeof Bun.spawn,
|
|
1545
|
+
testSessions,
|
|
1546
|
+
MODEL,
|
|
1547
|
+
WORKSPACE,
|
|
1548
|
+
fakeSentryClient,
|
|
1549
|
+
);
|
|
1550
|
+
|
|
1551
|
+
const err = await runClaude("hello").catch((e) => e);
|
|
1552
|
+
expect(err).toBeInstanceOf(ClaudeRunError);
|
|
1553
|
+
expect(err).not.toBeInstanceOf(TypeError);
|
|
1554
|
+
expect((err as InstanceType<typeof ClaudeRunError>).apiErrorStatus).toBe(
|
|
1555
|
+
403,
|
|
1556
|
+
);
|
|
1557
|
+
});
|
|
1558
|
+
|
|
1524
1559
|
test("does not retry a second time when the retry also hits connection-lost-mid-response", async () => {
|
|
1525
1560
|
const mockSpawn = mock(
|
|
1526
1561
|
() =>
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boot smoke for the container entrypoint (runtime/entrypoint-main.ts).
|
|
3
|
+
*
|
|
4
|
+
* Spawns the real entrypoint as a subprocess — the same way the Dockerfile
|
|
5
|
+
* ENTRYPOINT does — against a fake admin API (Bun.serve) and PATH shims for
|
|
6
|
+
* every external binary the startup sequence shells out to (git, gh, mise,
|
|
7
|
+
* claude, bun). Every fake appends to one shared log, so the test can assert
|
|
8
|
+
* the real ordering: config fetch → GitHub auth → mise → plugins → server spawn.
|
|
9
|
+
* A failing step must exit non-zero and must not reach the later steps.
|
|
10
|
+
*
|
|
11
|
+
* Nothing real is touched: HOME and AGENT_HOME are temp dirs, and the "agent
|
|
12
|
+
* server" is a `bun` shim that records its argv and exits with a chosen code.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
16
|
+
import {
|
|
17
|
+
chmodSync,
|
|
18
|
+
mkdirSync,
|
|
19
|
+
mkdtempSync,
|
|
20
|
+
readFileSync,
|
|
21
|
+
rmSync,
|
|
22
|
+
writeFileSync,
|
|
23
|
+
} from "node:fs";
|
|
24
|
+
import { tmpdir } from "node:os";
|
|
25
|
+
import { join } from "node:path";
|
|
26
|
+
import type { Server } from "bun";
|
|
27
|
+
|
|
28
|
+
const ENTRYPOINT = join(import.meta.dir, "entrypoint-main.ts");
|
|
29
|
+
const AGENT_ID = "agent-smoke-1";
|
|
30
|
+
const API_KEY = "smoke-key";
|
|
31
|
+
|
|
32
|
+
let root: string;
|
|
33
|
+
let logPath: string;
|
|
34
|
+
let server: Server<unknown> | undefined;
|
|
35
|
+
let configStatus = 200;
|
|
36
|
+
|
|
37
|
+
const CONFIG_BODY = {
|
|
38
|
+
specialty: "coding",
|
|
39
|
+
env: { SMOKE_APPLIED: "yes" },
|
|
40
|
+
allowedTools: ["Read"],
|
|
41
|
+
plugins: [],
|
|
42
|
+
marketplaces: [],
|
|
43
|
+
repos: [],
|
|
44
|
+
reviewAuthorAllowlist: [],
|
|
45
|
+
patchAuthorAllowlist: [],
|
|
46
|
+
restrictSlackToMembers: false,
|
|
47
|
+
memberEmails: [],
|
|
48
|
+
autoPostReviews: true,
|
|
49
|
+
allowSelfReview: false,
|
|
50
|
+
minConfidence: 75,
|
|
51
|
+
maxFindings: 5,
|
|
52
|
+
cleanupMergedWorktrees: true,
|
|
53
|
+
cleanupAfterDays: 14,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
function log(line: string): void {
|
|
57
|
+
writeFileSync(logPath, `${line}\n`, { flag: "a" });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function readLog(): string[] {
|
|
61
|
+
return readFileSync(logPath, "utf8").split("\n").filter(Boolean);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Writes an executable shim that logs "<name> <args>" then exits `code`. */
|
|
65
|
+
function writeShim(dir: string, name: string, code = 0): void {
|
|
66
|
+
const path = join(dir, name);
|
|
67
|
+
writeFileSync(
|
|
68
|
+
path,
|
|
69
|
+
`#!/bin/sh\necho "${name} $*" >> "${logPath}"\nexit ${code}\n`,
|
|
70
|
+
);
|
|
71
|
+
chmodSync(path, 0o755);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function startFakeAdmin(): string {
|
|
75
|
+
server = Bun.serve({
|
|
76
|
+
port: 0,
|
|
77
|
+
fetch(req) {
|
|
78
|
+
const url = new URL(req.url);
|
|
79
|
+
if (url.pathname === `/agents/${AGENT_ID}/config`) {
|
|
80
|
+
log(`config-fetch auth=${req.headers.get("authorization")}`);
|
|
81
|
+
if (configStatus !== 200) {
|
|
82
|
+
return new Response("boom", { status: configStatus });
|
|
83
|
+
}
|
|
84
|
+
return Response.json(CONFIG_BODY);
|
|
85
|
+
}
|
|
86
|
+
log(`unexpected-request ${req.method} ${url.pathname}`);
|
|
87
|
+
return new Response("not found", { status: 404 });
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
return `http://127.0.0.1:${server.port}`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function runEntrypoint(opts: {
|
|
94
|
+
apiUrl?: string;
|
|
95
|
+
serverExitCode?: number;
|
|
96
|
+
extraEnv?: Record<string, string>;
|
|
97
|
+
}): Promise<{ exitCode: number; stderr: string }> {
|
|
98
|
+
const bin = join(root, "bin");
|
|
99
|
+
mkdirSync(bin, { recursive: true });
|
|
100
|
+
for (const name of ["git", "gh", "mise", "claude"]) writeShim(bin, name);
|
|
101
|
+
// The "agent server": the entrypoint spawns `bun run <index.ts>` and exits
|
|
102
|
+
// with that process's exit code.
|
|
103
|
+
writeShim(bin, "bun", opts.serverExitCode ?? 0);
|
|
104
|
+
|
|
105
|
+
const home = join(root, "home");
|
|
106
|
+
const agentHome = join(root, "agent-home");
|
|
107
|
+
mkdirSync(home, { recursive: true });
|
|
108
|
+
// runMiseStartup only shells out to mise when the workspace declares tools.
|
|
109
|
+
mkdirSync(join(agentHome, "workspace"), { recursive: true });
|
|
110
|
+
writeFileSync(join(agentHome, "workspace", "mise.toml"), "[tools]\n");
|
|
111
|
+
|
|
112
|
+
const env: Record<string, string> = {
|
|
113
|
+
PATH: `${bin}:/usr/bin:/bin`,
|
|
114
|
+
HOME: home,
|
|
115
|
+
AGENT_HOME: agentHome,
|
|
116
|
+
SHIPWRIGHT_AGENT_ID: AGENT_ID,
|
|
117
|
+
SHIPWRIGHT_API_KEY: API_KEY,
|
|
118
|
+
SHIPWRIGHT_AGENT_API_KEY: API_KEY,
|
|
119
|
+
SHIPWRIGHT_STARTUP_TIMEOUT_MS: "20000",
|
|
120
|
+
...(opts.apiUrl ? { SHIPWRIGHT_API_URL: opts.apiUrl } : {}),
|
|
121
|
+
...opts.extraEnv,
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const proc = Bun.spawn([process.execPath, "run", ENTRYPOINT], {
|
|
125
|
+
env,
|
|
126
|
+
stdout: "pipe",
|
|
127
|
+
stderr: "pipe",
|
|
128
|
+
});
|
|
129
|
+
const [stderr] = await Promise.all([
|
|
130
|
+
new Response(proc.stderr).text(),
|
|
131
|
+
new Response(proc.stdout).text(),
|
|
132
|
+
]);
|
|
133
|
+
const exitCode = await proc.exited;
|
|
134
|
+
return { exitCode, stderr };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
beforeEach(() => {
|
|
138
|
+
root = mkdtempSync(join(tmpdir(), "entrypoint-smoke-"));
|
|
139
|
+
logPath = join(root, "calls.log");
|
|
140
|
+
writeFileSync(logPath, "");
|
|
141
|
+
configStatus = 200;
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
afterEach(() => {
|
|
145
|
+
server?.stop(true);
|
|
146
|
+
server = undefined;
|
|
147
|
+
rmSync(root, { recursive: true, force: true });
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe("entrypoint-main boot smoke", () => {
|
|
151
|
+
test("runs the startup steps in order and hands off to the agent server", async () => {
|
|
152
|
+
const apiUrl = startFakeAdmin();
|
|
153
|
+
|
|
154
|
+
const { exitCode, stderr } = await runEntrypoint({ apiUrl });
|
|
155
|
+
|
|
156
|
+
expect(stderr).not.toContain("FATAL");
|
|
157
|
+
expect(exitCode).toBe(0);
|
|
158
|
+
|
|
159
|
+
const calls = readLog();
|
|
160
|
+
const index = (prefix: string) =>
|
|
161
|
+
calls.findIndex((c) => c.startsWith(prefix));
|
|
162
|
+
|
|
163
|
+
const fetchIdx = index("config-fetch");
|
|
164
|
+
const gitIdx = index("git config --global safe.directory");
|
|
165
|
+
const miseIdx = index("mise trust");
|
|
166
|
+
const miseInstallIdx = index("mise install");
|
|
167
|
+
const serverIdx = index("bun run");
|
|
168
|
+
|
|
169
|
+
expect(fetchIdx).toBe(0);
|
|
170
|
+
expect(calls[fetchIdx]).toBe(`config-fetch auth=Bearer ${API_KEY}`);
|
|
171
|
+
expect(gitIdx).toBeGreaterThan(fetchIdx);
|
|
172
|
+
expect(miseIdx).toBeGreaterThan(gitIdx);
|
|
173
|
+
// The server spawn is last, and points at the repo-root index.ts.
|
|
174
|
+
expect(serverIdx).toBe(calls.length - 1);
|
|
175
|
+
expect(miseInstallIdx).toBeGreaterThan(miseIdx);
|
|
176
|
+
expect(serverIdx).toBeGreaterThan(miseInstallIdx);
|
|
177
|
+
expect(calls[serverIdx]).toBe(
|
|
178
|
+
`bun run ${join(import.meta.dir, "..", "index.ts")}`,
|
|
179
|
+
);
|
|
180
|
+
expect(calls.some((c) => c.startsWith("unexpected-request"))).toBe(false);
|
|
181
|
+
}, 30_000);
|
|
182
|
+
|
|
183
|
+
test("propagates the agent server's exit code", async () => {
|
|
184
|
+
const apiUrl = startFakeAdmin();
|
|
185
|
+
|
|
186
|
+
const { exitCode } = await runEntrypoint({ apiUrl, serverExitCode: 7 });
|
|
187
|
+
|
|
188
|
+
expect(exitCode).toBe(7);
|
|
189
|
+
}, 30_000);
|
|
190
|
+
|
|
191
|
+
test("a failing config fetch exits non-zero before any later step runs", async () => {
|
|
192
|
+
configStatus = 500;
|
|
193
|
+
const apiUrl = startFakeAdmin();
|
|
194
|
+
|
|
195
|
+
const { exitCode, stderr } = await runEntrypoint({ apiUrl });
|
|
196
|
+
|
|
197
|
+
expect(exitCode).not.toBe(0);
|
|
198
|
+
expect(stderr).toContain("FATAL: failed to fetch agent config");
|
|
199
|
+
const calls = readLog();
|
|
200
|
+
expect(calls).toHaveLength(1);
|
|
201
|
+
expect(calls[0]).toStartWith("config-fetch");
|
|
202
|
+
}, 30_000);
|
|
203
|
+
|
|
204
|
+
test("missing required variables exit non-zero without any network or spawn", async () => {
|
|
205
|
+
// No SHIPWRIGHT_API_URL passed → entrypoint must fail fast. The fake
|
|
206
|
+
// admin runs so any stray request would show up in the log.
|
|
207
|
+
startFakeAdmin();
|
|
208
|
+
const { exitCode, stderr } = await runEntrypoint({});
|
|
209
|
+
|
|
210
|
+
expect(exitCode).not.toBe(0);
|
|
211
|
+
expect(stderr).toContain("missing required variable: SHIPWRIGHT_API_URL");
|
|
212
|
+
expect(readLog()).toEqual([]);
|
|
213
|
+
}, 30_000);
|
|
214
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import * as errors from "./errors.ts";
|
|
3
|
+
|
|
4
|
+
const { ApiError } = errors;
|
|
5
|
+
|
|
6
|
+
const CASES: Array<[string, number, string]> = [
|
|
7
|
+
["NotFoundError", 404, "Not found"],
|
|
8
|
+
["ConflictError", 409, "Conflict"],
|
|
9
|
+
["BadRequestError", 400, "Bad request"],
|
|
10
|
+
["ForbiddenError", 403, "Forbidden"],
|
|
11
|
+
["UnprocessableEntityError", 422, "Unprocessable entity"],
|
|
12
|
+
["BadGatewayError", 502, "Bad gateway"],
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
describe("ApiError", () => {
|
|
16
|
+
it("carries statusCode and message and is an Error", () => {
|
|
17
|
+
const err = new ApiError(418, "teapot");
|
|
18
|
+
expect(err).toBeInstanceOf(Error);
|
|
19
|
+
expect(err.statusCode).toBe(418);
|
|
20
|
+
expect(err.message).toBe("teapot");
|
|
21
|
+
expect(err.name).toBe("ApiError");
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe.each(CASES)("%s", (name, status, defaultMessage) => {
|
|
26
|
+
const Ctor = (errors as unknown as Record<string, new (m?: string) => InstanceType<typeof ApiError>>)[name]!;
|
|
27
|
+
|
|
28
|
+
it("maps to its HTTP status with a default message", () => {
|
|
29
|
+
const err = new Ctor();
|
|
30
|
+
expect(err.statusCode).toBe(status);
|
|
31
|
+
expect(err.message).toBe(defaultMessage);
|
|
32
|
+
expect(err.name).toBe(name);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("accepts a custom message", () => {
|
|
36
|
+
expect(new Ctor("custom").message).toBe("custom");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("is an ApiError and Error (instanceof survives subclassing)", () => {
|
|
40
|
+
const err = new Ctor();
|
|
41
|
+
expect(err).toBeInstanceOf(Ctor);
|
|
42
|
+
expect(err).toBeInstanceOf(ApiError);
|
|
43
|
+
expect(err).toBeInstanceOf(Error);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("serializes to the { error } body the handler emits", () => {
|
|
47
|
+
const err = new Ctor("boom");
|
|
48
|
+
expect({ error: err.message }).toEqual({ error: "boom" });
|
|
49
|
+
expect(String(err)).toBe(`${name}: boom`);
|
|
50
|
+
});
|
|
51
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-runtime",
|
|
3
|
-
"version": "1.107.
|
|
3
|
+
"version": "1.107.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/app-vitals/agent.git",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"./workspace-paths": "./workspace-paths.ts"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@app-vitals/agent-admin": "1.107.
|
|
45
|
-
"@app-vitals/agent-lib": "1.107.
|
|
44
|
+
"@app-vitals/agent-admin": "1.107.3",
|
|
45
|
+
"@app-vitals/agent-lib": "1.107.3",
|
|
46
46
|
"@octokit/auth-app": "^8.2.0",
|
|
47
47
|
"@sentry/bun": "^10.63.0",
|
|
48
48
|
"@slack/bolt": "^5.0.0",
|
|
File without changes
|