@app-vitals/agent-runtime 1.69.1 → 1.71.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/boot.ts CHANGED
@@ -98,7 +98,7 @@ import {
98
98
  } from "./sessions.ts";
99
99
  import { ensureAgentHome, installPlugins, runMiseStartup } from "./setup.ts";
100
100
  import { SCRIPTS_BIN } from "./scripts-bin.ts";
101
- import { setupGitHubAuth } from "./setup-github-auth.ts";
101
+ import { checkCredentialHelper, setupGitHubAuth } from "./setup-github-auth.ts";
102
102
  import { HttpShipwrightRuntimeClient } from "./shipwright-runtime-client.ts";
103
103
  import { createSlackApp, hasSlackCredentials } from "./slack.ts";
104
104
  import {
@@ -250,6 +250,10 @@ export async function startAgent(
250
250
  apiUrl: config.shipwright.apiUrl,
251
251
  agentId: config.shipwright.agentId,
252
252
  apiKey: config.shipwright.apiKey,
253
+ checkCredentialHelper: () =>
254
+ checkCredentialHelper(
255
+ join(SCRIPTS_BIN, "git-credential-shipwright.sh"),
256
+ ),
253
257
  repoAccessProbe: createRepoAccessProbe({
254
258
  fetch,
255
259
  clock: SystemClock(),
@@ -19,6 +19,7 @@ import type {
19
19
  InstallationState,
20
20
  InstallationsSnapshot,
21
21
  } from "./github-installations.ts";
22
+ import type { CredentialHelperCheck } from "./setup-github-auth.ts";
22
23
  import type { RepoAccessEntry, RepoAccessProbe } from "./repo-access-probe.ts";
23
24
 
24
25
  export const INSTALLATIONS_HEARTBEAT_MS = 30 * 60 * 1000;
@@ -41,7 +42,21 @@ const REASON_TEXT: Record<NonNullable<InstallationState["reason"]>, string> = {
41
42
  mint_rejected: "installation token mint rejected",
42
43
  };
43
44
 
44
- function toReported(i: InstallationState): ReportedInstallation {
45
+ /** Constant on purpose: the helper path and raw check reason stay off the wire. */
46
+ export const CREDENTIAL_HELPER_BROKEN_TEXT = "git credential helper not found";
47
+
48
+ function toReported(
49
+ i: InstallationState,
50
+ helperBroken: boolean,
51
+ ): ReportedInstallation {
52
+ if (helperBroken) {
53
+ return {
54
+ owner: i.owner ?? "unknown",
55
+ installationId: i.id,
56
+ state: "broken",
57
+ lastError: CREDENTIAL_HELPER_BROKEN_TEXT,
58
+ };
59
+ }
45
60
  return {
46
61
  owner: i.owner ?? "unknown",
47
62
  installationId: i.id,
@@ -62,6 +77,11 @@ interface HttpGitHubInstallationsReporterOptions {
62
77
  * scope change); the reporter just merges whatever it returns into the PUT.
63
78
  */
64
79
  repoAccessProbe?: RepoAccessProbe;
80
+ /**
81
+ * CHP-1.3: evaluated on every report so the broken state clears itself once
82
+ * the helper is fixed. A failing check marks every installation broken.
83
+ */
84
+ checkCredentialHelper?: () => CredentialHelperCheck;
65
85
  }
66
86
 
67
87
  export class HttpGitHubInstallationsReporter
@@ -82,7 +102,10 @@ export class HttpGitHubInstallationsReporter
82
102
 
83
103
  async report(snapshot: InstallationsSnapshot): Promise<void> {
84
104
  try {
85
- const installations = snapshot.installations.map(toReported);
105
+ const helperBroken = this.opts.checkCredentialHelper?.().ok === false;
106
+ const installations = snapshot.installations.map((i) =>
107
+ toReported(i, helperBroken),
108
+ );
86
109
  const signature = JSON.stringify(installations);
87
110
  const probed = await this.opts.repoAccessProbe?.run();
88
111
  if (probed) this.lastRepos = probed;
@@ -5,6 +5,7 @@
5
5
 
6
6
  import { describe, expect, test } from "bun:test";
7
7
  import type { InstallationsSnapshot } from "./github-installations.ts";
8
+ import type { CredentialHelperCheck } from "./setup-github-auth.ts";
8
9
  import type { RepoAccessEntry, RepoAccessProbe } from "./repo-access-probe.ts";
9
10
  import {
10
11
  HttpGitHubInstallationsReporter,
@@ -35,6 +36,7 @@ function snap(
35
36
  function harness(
36
37
  responses: (Response | Error)[] = [],
37
38
  repoAccessProbe?: RepoAccessProbe,
39
+ checkCredentialHelper?: () => CredentialHelperCheck,
38
40
  ) {
39
41
  let nowMs = Date.UTC(2026, 0, 1);
40
42
  const calls: { url: string; init: RequestInit | undefined }[] = [];
@@ -52,6 +54,7 @@ function harness(
52
54
  fetchFn,
53
55
  clock: { now: () => new Date(nowMs) },
54
56
  repoAccessProbe,
57
+ checkCredentialHelper,
55
58
  });
56
59
  return {
57
60
  reporter,
@@ -214,3 +217,60 @@ describe("HttpGitHubInstallationsReporter repo access (COS-44.1)", () => {
214
217
  ).toEqual(["installations", "reportedAt"]);
215
218
  });
216
219
  });
220
+
221
+ describe("credential helper check (CHP-1.3)", () => {
222
+ test("failing check reports every installation broken with constant lastError", async () => {
223
+ const h = harness([], undefined, () => ({
224
+ ok: false,
225
+ reason: "missing /secret/path",
226
+ }));
227
+ await h.reporter.report(
228
+ snap("ok", [
229
+ { id: 2, owner: "beta", pinned: false, health: "ok", reason: null },
230
+ ]),
231
+ );
232
+ const raw = String(h.calls[0].init?.body);
233
+ const body = JSON.parse(raw);
234
+ expect(body.installations).toEqual([
235
+ {
236
+ owner: "acme",
237
+ installationId: 1,
238
+ state: "broken",
239
+ lastError: "git credential helper not found",
240
+ },
241
+ {
242
+ owner: "beta",
243
+ installationId: 2,
244
+ state: "broken",
245
+ lastError: "git credential helper not found",
246
+ },
247
+ ]);
248
+ expect(raw).not.toContain("/secret/path");
249
+ });
250
+
251
+ test("passing check leaves the health/reason mapping unchanged", async () => {
252
+ const h = harness([], undefined, () => ({ ok: true }));
253
+ await h.reporter.report(snap("broken"));
254
+ const body = JSON.parse(String(h.calls[0].init?.body));
255
+ expect(body.installations[0].lastError).toBe(
256
+ "installation token mint rejected",
257
+ );
258
+ });
259
+
260
+ test("ok <-> broken flip posts immediately inside the heartbeat window and recovers", async () => {
261
+ let check: CredentialHelperCheck = { ok: true };
262
+ const h = harness([], undefined, () => check);
263
+ await h.reporter.report(snap());
264
+ h.advance(1_000);
265
+ check = { ok: false, reason: "missing" };
266
+ await h.reporter.report(snap());
267
+ h.advance(1_000);
268
+ check = { ok: true };
269
+ await h.reporter.report(snap());
270
+ expect(h.calls).toHaveLength(3);
271
+ const states = h.calls.map(
272
+ (c) => JSON.parse(String(c.init?.body)).installations[0].state,
273
+ );
274
+ expect(states).toEqual(["ok", "broken", "ok"]);
275
+ });
276
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-runtime",
3
- "version": "1.69.1",
3
+ "version": "1.71.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.69.1",
45
- "@app-vitals/agent-lib": "1.69.1",
44
+ "@app-vitals/agent-admin": "1.71.0",
45
+ "@app-vitals/agent-lib": "1.71.0",
46
46
  "@octokit/auth-app": "^8.2.0",
47
47
  "@sentry/bun": "^10.63.0",
48
48
  "@slack/bolt": "^5.0.0",
@@ -221,6 +221,34 @@ describe("setupGitHubAuth — App path", () => {
221
221
  expect(credHelperCall).toContain("status 1");
222
222
  });
223
223
 
224
+ test("missing credential helper logs an error naming the path and still writes the config", async () => {
225
+ const { getToken, startBackgroundRefresh } = makeTokenManager();
226
+ const spawnSync = makeSpawnSync(0);
227
+ const errorSpy = mock((..._args: unknown[]) => {});
228
+
229
+ const result = await setupGitHubAuth({
230
+ env: {
231
+ GH_APP_ID: "123",
232
+ GH_APP_INSTALLATION_ID: "456",
233
+ GH_APP_PRIVATE_KEY: "fake-private-key",
234
+ },
235
+ createTokenManager: mock(() => ({ getToken, startBackgroundRefresh })),
236
+ getBotIdentity: makeBotIdentity(),
237
+ spawnSync,
238
+ writeToken: makeWriteToken(),
239
+ tokenPath: TEST_TOKEN_PATH,
240
+ credentialHelperPath: TEST_HELPER_PATH,
241
+ logger: { error: errorSpy },
242
+ });
243
+
244
+ expect(result).toBe(true);
245
+ expect(errorSpy).toHaveBeenCalledTimes(1);
246
+ expect(errorSpy.mock.calls[0]?.[0] as string).toContain(TEST_HELPER_PATH);
247
+ expect(spawnSync.mock.calls.map((c) => c[1].join(" "))).toContain(
248
+ `config --global credential.https://github.com.helper !${TEST_HELPER_PATH}`,
249
+ );
250
+ });
251
+
224
252
  test("background refresh callback rewrites the token file only — no env mutation, no further spawnSync calls", async () => {
225
253
  let capturedCallback: ((t: string) => Promise<void>) | null = null;
226
254
  const getToken = mock(async () => "ghs_first_token");
@@ -18,6 +18,7 @@
18
18
  * callers gate repeat calls on that result (github-auth-startup.ts).
19
19
  */
20
20
 
21
+ import { accessSync, constants, statSync } from "node:fs";
21
22
  import type { TokenFilesInput } from "./gh-token-files.ts";
22
23
  import type { BotIdentity } from "./github-app-auth.ts";
23
24
  import type { InstallationsSnapshot } from "./github-installations.ts";
@@ -72,6 +73,25 @@ export interface GitHubInstallationsDeps {
72
73
  onActivated?: (manager: InstallationsManagerLike) => void;
73
74
  }
74
75
 
76
+ export type CredentialHelperCheck =
77
+ | { ok: true }
78
+ | { ok: false; reason: string };
79
+
80
+ /** Verifies the git credential helper exists and is an executable file. */
81
+ export function checkCredentialHelper(path: string): CredentialHelperCheck {
82
+ try {
83
+ if (!statSync(path).isFile()) return { ok: false, reason: "not a file" };
84
+ accessSync(path, constants.X_OK);
85
+ return { ok: true };
86
+ } catch (err) {
87
+ const code = (err as NodeJS.ErrnoException).code;
88
+ return {
89
+ ok: false,
90
+ reason: code === "ENOENT" ? "missing" : "not executable",
91
+ };
92
+ }
93
+ }
94
+
75
95
  function runOrWarn(
76
96
  spawnSync: GitHubAuthDeps["spawnSync"],
77
97
  cmd: string,
@@ -152,6 +172,13 @@ async function configureAppGit(deps: GitHubAuthDeps): Promise<AppIdentity> {
152
172
  env,
153
173
  logger,
154
174
  );
175
+ // Log and continue: a bad helper path breaks git auth but must not fail boot.
176
+ const helper = checkCredentialHelper(credentialHelperPath);
177
+ if (!helper.ok) {
178
+ (logger ?? console).error(
179
+ `[entrypoint] git credential helper ${credentialHelperPath} is ${helper.reason} — git auth will fail`,
180
+ );
181
+ }
155
182
  // Makes git send the repo path to the helper so it can pick the per-owner
156
183
  // token. Host-scoped only; the helper ignores it unless gh-token.d exists.
157
184
  runOrWarn(
@@ -0,0 +1,39 @@
1
+ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
2
+ import { chmodSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { checkCredentialHelper } from "./setup-github-auth.ts";
6
+
7
+ describe("checkCredentialHelper", () => {
8
+ let dir: string;
9
+ beforeEach(() => {
10
+ dir = mkdtempSync(join(tmpdir(), "cred-helper-"));
11
+ });
12
+ afterEach(() => rmSync(dir, { recursive: true, force: true }));
13
+
14
+ test("ok for an executable file", () => {
15
+ const p = join(dir, "helper.sh");
16
+ writeFileSync(p, "#!/bin/sh\n");
17
+ chmodSync(p, 0o755);
18
+ expect(checkCredentialHelper(p)).toEqual({ ok: true });
19
+ });
20
+
21
+ test("fails for a missing path", () => {
22
+ expect(checkCredentialHelper(join(dir, "nope"))).toEqual({
23
+ ok: false,
24
+ reason: "missing",
25
+ });
26
+ });
27
+
28
+ test("fails for a non-executable file", () => {
29
+ const p = join(dir, "helper.sh");
30
+ writeFileSync(p, "#!/bin/sh\n");
31
+ chmodSync(p, 0o644);
32
+ const r = checkCredentialHelper(p);
33
+ expect(r.ok).toBe(false);
34
+ });
35
+
36
+ test("fails for a directory", () => {
37
+ expect(checkCredentialHelper(dir).ok).toBe(false);
38
+ });
39
+ });