@app-vitals/agent-runtime 1.106.2 → 1.107.0
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/cron-handler.unit.test.ts +1 -1
- package/gh-helpers.ts +36 -5
- package/gh-helpers.unit.test.ts +44 -0
- package/package.json +3 -3
|
@@ -1216,7 +1216,7 @@ describe("handleCronRequest — legacy transcript feature flags", () => {
|
|
|
1216
1216
|
fetchCalls.push(args);
|
|
1217
1217
|
return Promise.resolve(new Response("{}"));
|
|
1218
1218
|
}) as typeof fetch;
|
|
1219
|
-
//
|
|
1219
|
+
// An older admin may still emit these keys; the runtime must ignore them.
|
|
1220
1220
|
agentFeaturesRef.set({
|
|
1221
1221
|
transcriptUpload: true,
|
|
1222
1222
|
loopTranscriptUpload: true,
|
package/gh-helpers.ts
CHANGED
|
@@ -50,6 +50,28 @@ export function githubOwnerOfSource(source: string): string | null {
|
|
|
50
50
|
return slug === null ? null : ownerOfRepo(slug);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/** stderr patterns that mean the gh token is invalid or expired. */
|
|
54
|
+
const GH_AUTH_STDERR = /Bad credentials|HTTP 401/;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Thrown by the gh helpers when gh fails with an authentication error
|
|
58
|
+
* (HTTP 401 / "Bad credentials"). Message format matches the plain Error
|
|
59
|
+
* thrown for other failures, so existing consumers are unaffected.
|
|
60
|
+
*/
|
|
61
|
+
export class GhAuthError extends Error {
|
|
62
|
+
constructor(message: string) {
|
|
63
|
+
super(message);
|
|
64
|
+
this.name = "GhAuthError";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Build the failure error: GhAuthError on 401, plain Error otherwise. */
|
|
69
|
+
function ghFailure(message: string, stderr: string): Error {
|
|
70
|
+
return GH_AUTH_STDERR.test(stderr)
|
|
71
|
+
? new GhAuthError(message)
|
|
72
|
+
: new Error(message);
|
|
73
|
+
}
|
|
74
|
+
|
|
53
75
|
/**
|
|
54
76
|
* Run a gh CLI command and return the parsed JSON output.
|
|
55
77
|
* Throws on non-zero exit.
|
|
@@ -66,7 +88,10 @@ export async function ghJson<T>(args: string[], owner: string): Promise<T> {
|
|
|
66
88
|
proc.exited,
|
|
67
89
|
]);
|
|
68
90
|
if (status !== 0) {
|
|
69
|
-
throw
|
|
91
|
+
throw ghFailure(
|
|
92
|
+
`gh ${args.join(" ")} failed (exit ${status}): ${stderr}`,
|
|
93
|
+
stderr,
|
|
94
|
+
);
|
|
70
95
|
}
|
|
71
96
|
return JSON.parse(stdout) as T;
|
|
72
97
|
}
|
|
@@ -86,7 +111,10 @@ export async function ghRun(args: string[], owner: string): Promise<void> {
|
|
|
86
111
|
proc.exited,
|
|
87
112
|
]);
|
|
88
113
|
if (status !== 0) {
|
|
89
|
-
throw
|
|
114
|
+
throw ghFailure(
|
|
115
|
+
`gh ${args.join(" ")} failed (exit ${status}): ${stderr}`,
|
|
116
|
+
stderr,
|
|
117
|
+
);
|
|
90
118
|
}
|
|
91
119
|
}
|
|
92
120
|
|
|
@@ -98,8 +126,8 @@ const GH_TRANSIENT_STDERR = /HTTP 50[234]\b|timed? ?out/i;
|
|
|
98
126
|
* Run a gh API graphql command and return the raw response.
|
|
99
127
|
*
|
|
100
128
|
* Retries (exponential backoff) when gh fails with a transient gateway error
|
|
101
|
-
* (HTTP 502/503/504 or a timeout). Any other failure —
|
|
102
|
-
* throws immediately. After exhausting retries the last error is thrown in
|
|
129
|
+
* (HTTP 502/503/504 or a timeout). Any other failure — query errors —
|
|
130
|
+
* throws immediately; auth failures (401) throw GhAuthError. After exhausting retries the last error is thrown in
|
|
103
131
|
* the same format as a non-retried failure.
|
|
104
132
|
*
|
|
105
133
|
* `owner` is required and set as SHIPWRIGHT_GH_OWNER in the spawned env for
|
|
@@ -130,7 +158,10 @@ export async function ghGraphql<T>(
|
|
|
130
158
|
attempt >= GH_GRAPHQL_MAX_ATTEMPTS ||
|
|
131
159
|
!GH_TRANSIENT_STDERR.test(stderr)
|
|
132
160
|
) {
|
|
133
|
-
throw
|
|
161
|
+
throw ghFailure(
|
|
162
|
+
`gh api graphql failed (exit ${status}): ${stderr}`,
|
|
163
|
+
stderr,
|
|
164
|
+
);
|
|
134
165
|
}
|
|
135
166
|
await Bun.sleep(baseDelayMs * 2 ** (attempt - 1));
|
|
136
167
|
}
|
package/gh-helpers.unit.test.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
import { tmpdir } from "node:os";
|
|
17
17
|
import { join } from "node:path";
|
|
18
18
|
import {
|
|
19
|
+
GhAuthError,
|
|
19
20
|
getCurrentUser,
|
|
20
21
|
ghGraphql,
|
|
21
22
|
ghJson,
|
|
@@ -295,3 +296,46 @@ describe("githubRepoSlugOfSource", () => {
|
|
|
295
296
|
expect(githubRepoSlugOfSource("https://example.test/a/b")).toBeNull();
|
|
296
297
|
});
|
|
297
298
|
});
|
|
299
|
+
|
|
300
|
+
describe("GhAuthError", () => {
|
|
301
|
+
let tmpDir: string;
|
|
302
|
+
let savedPath: string | undefined;
|
|
303
|
+
|
|
304
|
+
beforeEach(() => {
|
|
305
|
+
tmpDir = mkdtempSync(join(tmpdir(), "gh-auth-error-test-"));
|
|
306
|
+
savedPath = process.env.PATH;
|
|
307
|
+
process.env.PATH = `${tmpDir}:${savedPath}`;
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
afterEach(() => {
|
|
311
|
+
if (savedPath !== undefined) process.env.PATH = savedPath;
|
|
312
|
+
rmSync(tmpDir, { recursive: true, force: true });
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
const calls: [string, () => Promise<unknown>][] = [
|
|
316
|
+
["ghGraphql", () => ghGraphql("query { x }", "acme", { baseDelayMs: 1 })],
|
|
317
|
+
["ghJson", () => ghJson(["pr", "list"], "acme")],
|
|
318
|
+
["ghRun", () => ghRun(["pr", "merge"], "acme")],
|
|
319
|
+
];
|
|
320
|
+
|
|
321
|
+
for (const [name, call] of calls) {
|
|
322
|
+
test(`${name} throws GhAuthError on Bad credentials`, async () => {
|
|
323
|
+
writeFailingGhBinary(tmpDir, 1, "HTTP 401: Bad credentials");
|
|
324
|
+
const err = (await call().catch((e) => e)) as Error;
|
|
325
|
+
expect(err).toBeInstanceOf(GhAuthError);
|
|
326
|
+
expect(err.message).toContain("failed (exit 1): HTTP 401: Bad credentials");
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
test(`${name} throws GhAuthError on bare HTTP 401`, async () => {
|
|
330
|
+
writeFailingGhBinary(tmpDir, 1, "gh: HTTP 401");
|
|
331
|
+
expect(await call().catch((e) => e)).toBeInstanceOf(GhAuthError);
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
test(`${name} keeps a plain Error for non-401 failures`, async () => {
|
|
335
|
+
writeFailingGhBinary(tmpDir, 1, "net/http: TLS handshake timeout");
|
|
336
|
+
const err = (await call().catch((e) => e)) as Error;
|
|
337
|
+
expect(err).toBeInstanceOf(Error);
|
|
338
|
+
expect(err).not.toBeInstanceOf(GhAuthError);
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-runtime",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.107.0",
|
|
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.
|
|
45
|
-
"@app-vitals/agent-lib": "1.
|
|
44
|
+
"@app-vitals/agent-admin": "1.107.0",
|
|
45
|
+
"@app-vitals/agent-lib": "1.107.0",
|
|
46
46
|
"@octokit/auth-app": "^8.2.0",
|
|
47
47
|
"@sentry/bun": "^10.63.0",
|
|
48
48
|
"@slack/bolt": "^5.0.0",
|