@app-vitals/agent-admin 1.83.0 → 1.84.1

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.
@@ -25,8 +25,15 @@
25
25
  */
26
26
 
27
27
  import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
28
+ import { DEPLOYMENT_WIDE_ACCOUNT_KEY } from "./github-agent-installation-crawler.ts";
29
+ import { DEFAULT_REFRESH_STALENESS_CAP_MS } from "./github-repo-refresher.ts";
30
+ import {
31
+ buildCachedAccess,
32
+ type CachedOrgInput,
33
+ } from "./github-sync-cached-access.ts";
28
34
  import {
29
35
  identityOf,
36
+ type InstallationCachePort,
30
37
  type InstallationReposPort,
31
38
  NO_INSTALLATION_REASON,
32
39
  } from "./installation-repos-service.ts";
@@ -60,6 +67,8 @@ export const NOT_ADDABLE_REASON = "the bound user cannot push to this repo";
60
67
  export const ALREADY_INSTALLED_REASON = "already on the agent installation";
61
68
  export const NOT_INSTALLED_ORG_REASON =
62
69
  "the agent App is not installed on this org";
70
+ export const REVERIFY_FAILED_REASON =
71
+ "the live permission re-check failed, so the removal was dropped";
63
72
  export const NOT_PRESENT_REASON =
64
73
  "not on the agent installation or in the agent's repos";
65
74
 
@@ -230,9 +239,42 @@ export function planGithubSync(input: GithubSyncPlanInput): GithubSyncPlan {
230
239
  };
231
240
  }
232
241
 
242
+ /** One org's lookup-App crawl from the cache (adds are drawn from it). */
243
+ export interface CachedLookupOrg {
244
+ org: string;
245
+ completedAt: Date | null;
246
+ repos: readonly string[];
247
+ }
248
+
249
+ /** Default freshness bound: the refresher's staleness cap (the longest data is left unrefreshed). */
250
+ export const DEFAULT_SYNC_MAX_AGE_MS = DEFAULT_REFRESH_STALENESS_CAP_MS;
251
+
233
252
  export interface GithubSyncDeps {
234
253
  agents: InstallationAgentsPort;
254
+ /** Live resolver; used only when no `cache` is given. */
235
255
  access: GithubAccessPreviewFn;
256
+ /**
257
+ * The repo/access cache (GLC-2.3). When set, access is built from cached
258
+ * rows and an org is used only while its data is complete and fresh.
259
+ */
260
+ cache?: InstallationCachePort;
261
+ /** Cached lookup-App crawl per org, the source of installation adds. */
262
+ lookupRepos?: (
263
+ accountId: string | null | undefined,
264
+ ) => Promise<CachedLookupOrg[]>;
265
+ /** Freshness bound for cached data, ms. Default DEFAULT_SYNC_MAX_AGE_MS. */
266
+ maxAgeMs?: number;
267
+ now?: () => Date;
268
+ /**
269
+ * One live permission call for a removal candidate: true = the user can
270
+ * still push, false = definitively cannot, undefined = could not tell.
271
+ * Apply drops every candidate that is not definitively false.
272
+ */
273
+ verifyPush?: (
274
+ username: string,
275
+ repo: string,
276
+ accountId?: string | null,
277
+ ) => Promise<boolean | undefined>;
236
278
  installation: Pick<
237
279
  InstallationReposPort,
238
280
  "listInstalled" | "addRepos" | "removeRepos"
@@ -308,10 +350,11 @@ export class GithubSyncService {
308
350
  async apply(input: GithubSyncApplyInput): Promise<GithubSyncApplyResult> {
309
351
  const agent = await this.deps.agents.get(input.agentId);
310
352
  if (!agent) return { status: "agent_not_found" };
311
- const plan = await this.planFor(agent, input);
353
+ let plan = await this.planFor(agent, input);
312
354
  if (plan.skipped) {
313
355
  return { status: "skipped", reason: plan.skipReason ?? "skipped" };
314
356
  }
357
+ plan = await this.reverifyRemovals(plan, agent);
315
358
  if (plan.appAdds.length + plan.removedRepos.length === 0) {
316
359
  return { status: "noop", plan };
317
360
  }
@@ -374,6 +417,123 @@ export class GithubSyncService {
374
417
  return { status: "applied", plan, auditId, warnings };
375
418
  }
376
419
 
420
+ /** Drops every removal the live permission call does not confirm (unknown is never none). */
421
+ private async reverifyRemovals(
422
+ plan: GithubSyncPlan,
423
+ agent: InstallationAgentRecord,
424
+ ): Promise<GithubSyncPlan> {
425
+ const verify = this.deps.verifyPush;
426
+ const username = agent.githubUsername?.trim();
427
+ if (!verify || !username || plan.removedRepos.length === 0) return plan;
428
+ const dropped = new Map<string, string>();
429
+ for (const repo of plan.removedRepos) {
430
+ let pushable: boolean | undefined;
431
+ try {
432
+ pushable = await verify(username, repo, agent.accountId);
433
+ } catch {
434
+ pushable = undefined;
435
+ }
436
+ if (pushable === false) continue;
437
+ dropped.set(
438
+ repo,
439
+ pushable === true ? STILL_PUSHABLE_REASON : REVERIFY_FAILED_REASON,
440
+ );
441
+ }
442
+ if (dropped.size === 0) return plan;
443
+ const keep = (repos: string[]) => repos.filter((r) => !dropped.has(r));
444
+ const appRemoves = keep(plan.appRemoves);
445
+ const agentRemoves = keep(plan.agentRemoves);
446
+ return {
447
+ ...plan,
448
+ appRemoves,
449
+ agentRemoves,
450
+ removedRepos: sorted(new Set([...appRemoves, ...agentRemoves])),
451
+ notApplied: [
452
+ ...plan.notApplied,
453
+ ...[...dropped].map(([repo, reason]) => ({ repo, reason })),
454
+ ].sort((a, b) => a.repo.localeCompare(b.repo)),
455
+ };
456
+ }
457
+
458
+ /** Access from the cache (complete and fresh orgs only), with the installed orgs. */
459
+ private async cachedAccess(
460
+ agent: InstallationAgentRecord,
461
+ username: string,
462
+ installed: { org: string; repos: string[] }[],
463
+ ): Promise<UserRepoAccessResult> {
464
+ const cache = this.deps.cache as InstallationCachePort;
465
+ const accountId = agent.accountId || DEPLOYMENT_WIDE_ACCOUNT_KEY;
466
+ const now = (this.deps.now ?? (() => new Date()))();
467
+ const maxAgeMs = this.deps.maxAgeMs ?? DEFAULT_SYNC_MAX_AGE_MS;
468
+ let agentSnaps: Awaited<
469
+ ReturnType<InstallationCachePort["listAgentSnapshots"]>
470
+ > = [];
471
+ let lookup: CachedLookupOrg[] = [];
472
+ let readFailed = false;
473
+ try {
474
+ agentSnaps = await cache.listAgentSnapshots(
475
+ accountId,
476
+ String(agent.appId),
477
+ );
478
+ if (this.deps.lookupRepos)
479
+ lookup = await this.deps.lookupRepos(agent.accountId);
480
+ } catch {
481
+ readFailed = true;
482
+ }
483
+ const key = (s: string) => s.toLowerCase();
484
+ const orgNames = new Map<string, string>();
485
+ for (const i of installed) orgNames.set(key(i.org), i.org);
486
+ for (const r of agent.repos) {
487
+ const o = repoOrg(r);
488
+ if (o && !orgNames.has(key(o))) orgNames.set(key(o), o);
489
+ }
490
+ const inputs: CachedOrgInput[] = [];
491
+ for (const [k, org] of orgNames) {
492
+ const inst = installed.find((i) => key(i.org) === k);
493
+ const snap = agentSnaps.find((s) => key(s.org) === k);
494
+ const lk = lookup.filter((l) => key(l.org) === k);
495
+ const repos = new Map<string, string>();
496
+ for (const r of [
497
+ ...(inst?.repos ?? []),
498
+ ...agent.repos.filter((r) => key(repoOrg(r)) === k),
499
+ ...lk.flatMap((l) => l.repos),
500
+ ]) {
501
+ repos.set(key(r), r);
502
+ }
503
+ const crawls = [
504
+ ...(inst && snap ? [{ completedAt: snap.completedAt }] : []),
505
+ ...lk.map((l) => ({ completedAt: l.completedAt })),
506
+ ];
507
+ let rows: Awaited<ReturnType<InstallationCachePort["getAccessRows"]>> =
508
+ [];
509
+ let failed = readFailed;
510
+ if (!failed && repos.size > 0) {
511
+ try {
512
+ rows = await cache.getAccessRows({
513
+ accountId,
514
+ org,
515
+ username,
516
+ repos: [...repos.values()].map((f) => f.slice(f.indexOf("/") + 1)),
517
+ });
518
+ } catch {
519
+ failed = true;
520
+ }
521
+ }
522
+ inputs.push({
523
+ org,
524
+ crawls,
525
+ // A read failure, an installed org with no crawl, or a lookup source with no crawl of this org.
526
+ crawlMissing:
527
+ failed ||
528
+ (inst !== undefined && !snap) ||
529
+ (this.deps.lookupRepos !== undefined && lk.length === 0),
530
+ repos: [...repos.values()],
531
+ rows,
532
+ });
533
+ }
534
+ return buildCachedAccess({ username, now, maxAgeMs, orgs: inputs });
535
+ }
536
+
377
537
  private async planFor(
378
538
  agent: InstallationAgentRecord,
379
539
  requested?: SyncLists,
@@ -382,22 +542,28 @@ export class GithubSyncService {
382
542
  if (!username) {
383
543
  return skippedPlan(accessSkipReason(username, null) as string);
384
544
  }
385
- const preview = await this.deps.access(username, agent.accountId);
386
- if (preview.status === "unconfigured") {
387
- return skippedPlan("GitHub Apps are not configured");
545
+ let liveAccess: UserRepoAccessResult | null = null;
546
+ if (!this.deps.cache) {
547
+ const preview = await this.deps.access(username, agent.accountId);
548
+ if (preview.status === "unconfigured") {
549
+ return skippedPlan("GitHub Apps are not configured");
550
+ }
551
+ // Whole-call skips need no installation calls.
552
+ const skip = accessSkipReason(username, preview.access);
553
+ if (skip) return skippedPlan(skip);
554
+ liveAccess = preview.access;
388
555
  }
389
- // Whole-call skips need no installation calls.
390
- const skip = accessSkipReason(username, preview.access);
391
- if (skip) return skippedPlan(skip);
392
556
  if (agent.appId === undefined) return skippedPlan(MISSING_APP_ID_REASON);
393
557
  const installed = await this.deps.installation.listInstalled(
394
558
  agent.appId,
395
559
  identityOf(agent),
396
560
  );
397
561
  if (installed.status === "none") return skippedPlan(NO_INSTALLATION_REASON);
562
+ const resolved =
563
+ liveAccess ?? (await this.cachedAccess(agent, username, installed.orgs));
398
564
  return planGithubSync({
399
565
  username,
400
- access: preview.access,
566
+ access: resolved,
401
567
  agentRepos: agent.repos,
402
568
  installationRepos: Object.fromEntries(
403
569
  installed.orgs.map(({ org, repos }) => [org, repos]),
@@ -44,6 +44,12 @@ export interface InstallationRepoView {
44
44
  fullName: string;
45
45
  /** Present only when the bound user's access to this repo is known. */
46
46
  userCanPush?: boolean;
47
+ /** ISO time the bound user's access to this repo was last checked, when a row exists. */
48
+ accessCheckedAt?: string;
49
+ /** Failed access checks for this repo since the last success, when any. */
50
+ accessAttempts?: number;
51
+ /** Last access-check error for this repo, when any. */
52
+ accessError?: string;
47
53
  }
48
54
 
49
55
  /** Sync detail for one org's cached snapshot (all optional, additive). */
@@ -94,6 +100,10 @@ export interface CachedAccessRow {
94
100
  repo: string;
95
101
  status: string;
96
102
  canPush: boolean;
103
+ level?: string | null;
104
+ checkedAt?: Date;
105
+ attempts?: number;
106
+ lastError?: string | null;
97
107
  }
98
108
 
99
109
  /** The slice of GitHubRepoCacheService the list reads; never calls GitHub. */
@@ -198,6 +208,28 @@ export function userPushHints(
198
208
  });
199
209
  }
200
210
 
211
+ /** Adds per-repo checkedAt / attempts / last error from the cached rows (additive). */
212
+ function withAccessDetail(
213
+ views: InstallationRepoView[],
214
+ rows: readonly CachedAccessRow[],
215
+ ): InstallationRepoView[] {
216
+ const byRepo = new Map(rows.map((r) => [r.repo.toLowerCase(), r]));
217
+ return views.map((v) => {
218
+ const row = byRepo.get(
219
+ v.fullName.slice(v.fullName.indexOf("/") + 1).toLowerCase(),
220
+ );
221
+ if (!row) return v;
222
+ return {
223
+ ...v,
224
+ ...(row.checkedAt
225
+ ? { accessCheckedAt: row.checkedAt.toISOString() }
226
+ : {}),
227
+ ...(row.attempts ? { accessAttempts: row.attempts } : {}),
228
+ ...(row.lastError ? { accessError: row.lastError } : {}),
229
+ };
230
+ });
231
+ }
232
+
201
233
  const iso = (d: Date | null): string | undefined =>
202
234
  d ? d.toISOString() : undefined;
203
235
 
@@ -279,7 +311,10 @@ export class InstallationReposService {
279
311
  username,
280
312
  repos: names.map((f) => f.slice(f.indexOf("/") + 1)),
281
313
  });
282
- repos = userPushHints({ cachedRows: rows }, s.org, names);
314
+ repos = withAccessDetail(
315
+ userPushHints({ cachedRows: rows }, s.org, names),
316
+ rows,
317
+ );
283
318
  } catch {
284
319
  // The hint is advisory: a failed cache read omits it.
285
320
  }
@@ -0,0 +1,134 @@
1
+ /**
2
+ * admin/src/platform-routes.ts
3
+ * The single place the platform admin APIs are mounted on a root app.
4
+ *
5
+ * startAdmin (admin-boot.ts) calls mountPlatformApis with real services and
6
+ * buildPlatformAdminSpec (admin-spec.ts) calls it with stub deps, deriving the
7
+ * OpenAPI document from the returned `mounted` list. Adding a platform sub-app
8
+ * therefore means touching this file only.
9
+ *
10
+ * Mount order is part of the contract: every platform API is mounted here,
11
+ * before extension routes and the admin UI (/admin/*), which startAdmin mounts
12
+ * after this call so nothing shadows them.
13
+ */
14
+
15
+ import type { OpenAPIHono } from "@hono/zod-openapi";
16
+ import type { Hono, MiddlewareHandler } from "hono";
17
+ import { createAccountsApp } from "./accounts-api.ts";
18
+ import { createAgentTemplatesApp } from "./agent-templates-api.ts";
19
+ import { type AdminDeps, createAdminApp } from "./agents-api.ts";
20
+ import { createAgentRuntimeApp } from "./api.ts";
21
+ import { createGithubEnterpriseApp } from "./github-enterprise-api.ts";
22
+ import { mountPlatformDoc } from "./platform-doc-route.ts";
23
+ import { createPrincipalsApp } from "./principals-api.ts";
24
+
25
+ type AgentRuntimeDeps = Parameters<typeof createAgentRuntimeApp>[0];
26
+ type AccountsDeps = Parameters<typeof createAccountsApp>[0];
27
+ type PrincipalsDeps = Parameters<typeof createPrincipalsApp>[0];
28
+ type TemplatesDeps = Parameters<typeof createAgentTemplatesApp>[0];
29
+ type GithubEnterpriseDeps = Parameters<typeof createGithubEnterpriseApp>[0];
30
+
31
+ export interface PlatformApiDeps {
32
+ runtime: AgentRuntimeDeps;
33
+ adminApi: AdminDeps;
34
+ /** Flag-gated GET /doc; omitted when no doc route should be mounted. */
35
+ doc?: {
36
+ env: Record<string, string | undefined>;
37
+ auth: MiddlewareHandler;
38
+ };
39
+ accounts: AccountsDeps;
40
+ principals: PrincipalsDeps;
41
+ templates: TemplatesDeps;
42
+ githubEnterprise: GithubEnterpriseDeps;
43
+ }
44
+
45
+ export interface MountedPlatformApp {
46
+ name: string;
47
+ /** Path prefix the app is mounted under on the root. */
48
+ prefix: string;
49
+ // biome-ignore lint/suspicious/noExplicitAny: apps carry differing Env generics
50
+ app: OpenAPIHono<any>;
51
+ /**
52
+ * Whether the app's routes belong in the committed platform spec
53
+ * (admin/openapi.platform.json). `false` only for apps deliberately kept out
54
+ * of it; each such app must say why in `specExclusion`.
55
+ */
56
+ inSpec: boolean;
57
+ specExclusion?: string;
58
+ }
59
+
60
+ export interface MountedPlatformApis {
61
+ /** Every mounted platform app, in mount order. */
62
+ mounted: MountedPlatformApp[];
63
+ // biome-ignore lint/suspicious/noExplicitAny: see MountedPlatformApp.app
64
+ adminApiApp: OpenAPIHono<any>;
65
+ // biome-ignore lint/suspicious/noExplicitAny: see MountedPlatformApp.app
66
+ githubEnterpriseApp: OpenAPIHono<any>;
67
+ templateService: TemplatesDeps["templateService"];
68
+ }
69
+
70
+ /** Mounts every platform admin API on `root`, in the order the boot relies on. */
71
+ export function mountPlatformApis(
72
+ // biome-ignore lint/suspicious/noExplicitAny: the root app carries arbitrary Env generics
73
+ root: Hono<any>,
74
+ deps: PlatformApiDeps,
75
+ ): MountedPlatformApis {
76
+ const mounted: MountedPlatformApp[] = [];
77
+ const mount = (entry: MountedPlatformApp) => {
78
+ root.route(entry.prefix, entry.app);
79
+ mounted.push(entry);
80
+ };
81
+
82
+ // Runtime API — admin key | per-agent bearer | session JWT. Hono strips the
83
+ // /agents prefix before dispatching, so its routes are /:id/config etc.
84
+ mount({
85
+ name: "runtime",
86
+ prefix: "/agents",
87
+ app: createAgentRuntimeApp(deps.runtime),
88
+ inSpec: true,
89
+ });
90
+
91
+ // Admin CRUD API — /agents/:id/* (same prefix as runtime, different sub-paths).
92
+ const adminApiApp = createAdminApp(deps.adminApi);
93
+ mount({ name: "admin", prefix: "/", app: adminApiApp, inSpec: true });
94
+
95
+ // Platform OpenAPI document — GET /doc, flag-gated (not mounted when off).
96
+ if (deps.doc) mountPlatformDoc(root, deps.doc);
97
+
98
+ mount({
99
+ name: "accounts",
100
+ prefix: "/",
101
+ app: createAccountsApp(deps.accounts),
102
+ inSpec: false,
103
+ specExclusion:
104
+ "flag-gated (self-serve signup); never part of the committed platform spec",
105
+ });
106
+ // The three apps below own disjoint prefixes, so their relative order does
107
+ // not affect routing; it is fixed to keep the committed spec's key order.
108
+ const githubEnterpriseApp = createGithubEnterpriseApp(deps.githubEnterprise);
109
+ mount({
110
+ name: "github-enterprise",
111
+ prefix: "/",
112
+ app: githubEnterpriseApp,
113
+ inSpec: true,
114
+ });
115
+ mount({
116
+ name: "templates",
117
+ prefix: "/",
118
+ app: createAgentTemplatesApp(deps.templates),
119
+ inSpec: true,
120
+ });
121
+ mount({
122
+ name: "principals",
123
+ prefix: "/",
124
+ app: createPrincipalsApp(deps.principals),
125
+ inSpec: true,
126
+ });
127
+
128
+ return {
129
+ mounted,
130
+ adminApiApp,
131
+ githubEnterpriseApp,
132
+ templateService: deps.templates.templateService,
133
+ };
134
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * admin/src/platform-routes.unit.test.ts
3
+ *
4
+ * Guards that startAdmin and buildPlatformAdminSpec share one mount list: every
5
+ * app mounted by mountPlatformApis must contribute its OpenAPI paths to the
6
+ * platform spec, unless it is explicitly excluded with a reason.
7
+ */
8
+
9
+ import { describe, expect, it } from "bun:test";
10
+ import { Hono } from "hono";
11
+ import { buildPlatformAdminSpec } from "./admin-spec.ts";
12
+ import { mountPlatformApis, type PlatformApiDeps } from "./platform-routes.ts";
13
+
14
+ // Capture the mounted list through the spec builder's own stub deps by
15
+ // re-running the mount with minimal deps: factories only read deps lazily.
16
+ function mountWithStubs() {
17
+ const noAuth = { validate: async () => null };
18
+ const common = {
19
+ sessionSecret: "dummy-secret-32chars-for-spec-gen",
20
+ agentTokenService: noAuth,
21
+ };
22
+ const deps = {
23
+ runtime: { ...common },
24
+ adminApi: { ...common, provisioner: undefined },
25
+ accounts: { accountService: {}, accountLifecycle: {}, ...common },
26
+ principals: { lookup: {}, ...common },
27
+ templates: {
28
+ templateService: {},
29
+ callerScopeResolver: async () => ({ kind: "all" }),
30
+ ...common,
31
+ },
32
+ githubEnterprise: {
33
+ appService: {},
34
+ agentService: {},
35
+ agentEnvService: {},
36
+ ...common,
37
+ },
38
+ } as unknown as PlatformApiDeps;
39
+ const root = new Hono();
40
+ return { root, result: mountPlatformApis(root, deps) };
41
+ }
42
+
43
+ const toOpenApiPath = (prefix: string, path: string) =>
44
+ `${prefix === "/" ? "" : prefix}${path.replace(/:(\w+)/g, "{$1}")}`;
45
+
46
+ describe("mountPlatformApis", () => {
47
+ const { result } = mountWithStubs();
48
+ const spec = buildPlatformAdminSpec();
49
+
50
+ it("mounts the expected platform apps in order", () => {
51
+ expect(result.mounted.map((m) => m.name)).toEqual([
52
+ "runtime",
53
+ "admin",
54
+ "accounts",
55
+ "github-enterprise",
56
+ "templates",
57
+ "principals",
58
+ ]);
59
+ });
60
+
61
+ it("returns the apps the admin UI wiring needs", () => {
62
+ expect(result.adminApiApp).toBe(
63
+ result.mounted.find((m) => m.name === "admin")?.app as never,
64
+ );
65
+ expect(result.githubEnterpriseApp).toBe(
66
+ result.mounted.find((m) => m.name === "github-enterprise")?.app as never,
67
+ );
68
+ });
69
+
70
+ it("puts every mounted app's OpenAPI paths into buildPlatformAdminSpec()", () => {
71
+ for (const entry of result.mounted.filter((m) => m.inSpec)) {
72
+ const paths = Object.keys(
73
+ entry.app.getOpenAPI31Document({
74
+ openapi: "3.1.0",
75
+ info: { title: entry.name, version: "0.0.0" },
76
+ }).paths ?? {},
77
+ );
78
+ expect(
79
+ paths.length,
80
+ `${entry.name} has no OpenAPI paths`,
81
+ ).toBeGreaterThan(0);
82
+ for (const path of paths) {
83
+ expect(
84
+ Object.keys(spec.paths),
85
+ `${entry.name}: ${path} missing from the platform spec`,
86
+ ).toContain(toOpenApiPath(entry.prefix, path));
87
+ }
88
+ }
89
+ });
90
+
91
+ it("only leaves an app out of the spec with a stated reason", () => {
92
+ const excluded = result.mounted.filter((m) => !m.inSpec);
93
+ expect(excluded.map((m) => m.name)).toEqual(["accounts"]);
94
+ for (const entry of excluded) {
95
+ expect(entry.specExclusion?.length ?? 0).toBeGreaterThan(0);
96
+ }
97
+ });
98
+ });
@@ -37,7 +37,9 @@ export function orgSkipReason(
37
37
  if (result.reason === SELECTED_REPOS_REASON) {
38
38
  return "lookup app is installed on selected repositories only";
39
39
  }
40
- if (result.status === "partial") return "access listing is incomplete";
40
+ if (result.status === "partial") {
41
+ return result.reason ?? "access listing is incomplete";
42
+ }
41
43
  if (result.status !== "ok") return `access lookup failed: ${result.status}`;
42
44
  return undefined;
43
45
  }
@@ -56,3 +58,13 @@ export function accessSkipReason(
56
58
  if (!access.userVerified) return "GitHub user could not be verified";
57
59
  return undefined;
58
60
  }
61
+
62
+ /** Why cached access data cannot justify removals: a crawl or a repo answer is missing. */
63
+ export const INCOMPLETE_ACCESS_REASON = "access data is incomplete";
64
+
65
+ /** Why cached access data cannot justify removals: it is older than the freshness bound. */
66
+ export function staleAccessReason(oldestChecked: Date | undefined): string {
67
+ return oldestChecked
68
+ ? `access data is stale (checked ${oldestChecked.toISOString()})`
69
+ : "access data is stale (check time unknown)";
70
+ }