@app-vitals/agent-admin 1.91.0 → 1.92.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.
@@ -34,30 +34,30 @@
34
34
  */
35
35
 
36
36
  import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
37
+ import { DEPLOYMENT_WIDE_ACCOUNT_KEY } from "./github-agent-installation-crawler.ts";
37
38
  import {
38
39
  GITHUB_APPS_STATE_REASONS,
39
40
  type GithubAppsState,
40
41
  type GithubAppsStateFn,
41
42
  } from "./github-apps-state.ts";
42
- import { DEPLOYMENT_WIDE_ACCOUNT_KEY } from "./github-agent-installation-crawler.ts";
43
43
  import { DEFAULT_REFRESH_STALENESS_CAP_MS } from "./github-repo-refresher.ts";
44
44
  import {
45
45
  buildCachedAccess,
46
46
  type CachedOrgInput,
47
47
  } from "./github-sync-cached-access.ts";
48
48
  import {
49
- identityOf,
50
- type InstallationCachePort,
51
- type InstallationReposPort,
52
- NO_INSTALLATION_REASON,
53
- } from "./installation-repos-service.ts";
54
- import {
55
- MAX_UNCONFIRMED_REMOVALS,
56
- MISSING_APP_ID_REASON,
57
49
  type InstallationAgentRecord,
58
50
  type InstallationAgentsPort,
59
51
  type InstallationAuditPort,
52
+ MAX_UNCONFIRMED_REMOVALS,
53
+ MISSING_APP_ID_REASON,
60
54
  } from "./installation-ports.ts";
55
+ import {
56
+ type InstallationCachePort,
57
+ type InstallationReposPort,
58
+ identityOf,
59
+ NO_INSTALLATION_REASON,
60
+ } from "./installation-repos-service.ts";
61
61
  import type { OpenWorkItem, OpenWorkPort } from "./reconcile-open-work.ts";
62
62
  import {
63
63
  accessSkipReason,
@@ -88,6 +88,8 @@ export const REVERIFY_FAILED_REASON =
88
88
  "the live permission re-check failed, so the removal was dropped";
89
89
  export const NOT_PRESENT_REASON =
90
90
  "not on the agent installation or in the agent's repos";
91
+ export const ARCHIVED_REASON =
92
+ "the repo is archived (read-only), so it is not added to the installation";
91
93
 
92
94
  /** GitHub caps the repositories in a selection-switch PATCH at 50. */
93
95
  export const MAX_SELECTION_PATCH_REPOS = 50;
@@ -129,6 +131,13 @@ export interface GithubSyncPlanInput {
129
131
  * every eligible repo is a candidate.
130
132
  */
131
133
  requested?: SyncLists;
134
+ /**
135
+ * Archived repos (owner/repo). They are never an installation add: an
136
+ * archived repo is read-only. An archived repo already on the installation
137
+ * is still removed when the access answer says the user cannot push. The
138
+ * agent's own repos are unaffected.
139
+ */
140
+ archivedRepos?: readonly string[];
132
141
  }
133
142
 
134
143
  export interface NotAppliedRepo {
@@ -254,8 +263,18 @@ export function planGithubSync(input: GithubSyncPlanInput): GithubSyncPlan {
254
263
  return false;
255
264
  };
256
265
 
266
+ const archived = new Set((input.archivedRepos ?? []).map(lower));
267
+ // Adds only; checked before orgUsable, so an archived repo never reports its
268
+ // org skipped. Removals of installed archived repos take the normal path.
269
+ const isArchived = (repo: string): boolean => {
270
+ if (!archived.has(lower(repo))) return false;
271
+ leave(repo, ARCHIVED_REASON);
272
+ return true;
273
+ };
274
+
257
275
  const appAdds = new Set<string>();
258
276
  for (const repo of new Set(addCandidates)) {
277
+ if (isArchived(repo)) continue;
259
278
  if (!orgUsable(repo)) continue;
260
279
  if (!installedOrgs.has(lower(repoOrg(repo)))) {
261
280
  leave(repo, NOT_INSTALLED_ORG_REASON);
@@ -294,6 +313,8 @@ export function planGithubSync(input: GithubSyncPlanInput): GithubSyncPlan {
294
313
  }
295
314
  return out;
296
315
  };
316
+ // An archived repo still on the installation is removed like any other once
317
+ // the user lacks push (least privilege); only adds skip archived repos.
297
318
  const confirmedAppRemoves = removable(appRemoveCandidates, installed);
298
319
  const agentRemoves = removable(agentRemoveCandidates, configured);
299
320
 
@@ -336,7 +357,14 @@ export function planGithubSync(input: GithubSyncPlanInput): GithubSyncPlan {
336
357
  export interface CachedLookupOrg {
337
358
  org: string;
338
359
  completedAt: Date | null;
360
+ /** The org's non-archived repos (owner/repo). */
339
361
  repos: readonly string[];
362
+ /**
363
+ * The org's archived repos (owner/repo), kept out of `repos`. GitHub Sync
364
+ * never adds or removes them and needs no access answer for them, except
365
+ * for one the agent has configured.
366
+ */
367
+ archivedRepos?: readonly string[];
340
368
  lastError?: string | null;
341
369
  rateLimitResetAt?: Date | null;
342
370
  }
@@ -639,13 +667,20 @@ export class GithubSyncService {
639
667
  };
640
668
  }
641
669
 
642
- /** Access from the cache (complete and fresh orgs only), with the installed orgs. */
670
+ /**
671
+ * Access from the cache (complete and fresh orgs only), with the installed
672
+ * orgs, plus the archived repos the lookup crawl reported. An archived repo
673
+ * is left out of an org's required access rows unless the agent has it
674
+ * configured or it is on the installation (the refresher probes those so a
675
+ * removal has an answer), since it does not check the others.
676
+ */
643
677
  private async cachedAccess(
644
678
  agent: InstallationAgentRecord,
645
679
  username: string,
646
680
  installed: { org: string; repos: string[] }[],
647
681
  ): Promise<{
648
682
  access: UserRepoAccessResult;
683
+ archivedRepos: string[];
649
684
  selections: Record<string, "all" | "selected" | null>;
650
685
  }> {
651
686
  const cache = this.deps.cache as InstallationCachePort;
@@ -668,6 +703,10 @@ export class GithubSyncService {
668
703
  readFailed = true;
669
704
  }
670
705
  const key = (s: string) => s.toLowerCase();
706
+ const archivedRepos = lookup.flatMap((l) => l.archivedRepos ?? []);
707
+ const archived = new Set(archivedRepos.map(key));
708
+ const configuredKeys = new Set(agent.repos.map(key));
709
+ const installedKeys = new Set(installed.flatMap((i) => i.repos.map(key)));
671
710
  const orgNames = new Map<string, string>();
672
711
  for (const i of installed) orgNames.set(key(i.org), i.org);
673
712
  for (const r of agent.repos) {
@@ -685,6 +724,12 @@ export class GithubSyncService {
685
724
  ...agent.repos.filter((r) => key(repoOrg(r)) === k),
686
725
  ...lk.flatMap((l) => l.repos),
687
726
  ]) {
727
+ if (
728
+ archived.has(key(r)) &&
729
+ !configuredKeys.has(key(r)) &&
730
+ !installedKeys.has(key(r))
731
+ )
732
+ continue;
688
733
  repos.set(key(r), r);
689
734
  }
690
735
  const crawls = [
@@ -742,6 +787,7 @@ export class GithubSyncService {
742
787
  }
743
788
  return {
744
789
  access: buildCachedAccess({ username, now, maxAgeMs, orgs: inputs }),
790
+ archivedRepos,
745
791
  selections,
746
792
  };
747
793
  }
@@ -788,11 +834,11 @@ export class GithubSyncService {
788
834
  if (installed.status === "none") {
789
835
  return none(skippedPlan(NO_INSTALLATION_REASON));
790
836
  }
837
+ // The live resolver reports no archived flag, so only the cached path
838
+ // leaves archived repos alone.
791
839
  const cached = liveAccess
792
840
  ? undefined
793
841
  : await this.cachedAccess(agent, username, installed.orgs);
794
- const resolved =
795
- liveAccess ?? (cached as { access: UserRepoAccessResult }).access;
796
842
  // The live path never reads the crawl cache, so every selection is unknown.
797
843
  const selections = cached?.selections;
798
844
  const installationRepos = Object.fromEntries(
@@ -800,7 +846,10 @@ export class GithubSyncService {
800
846
  );
801
847
  const plan = planGithubSync({
802
848
  username,
803
- access: resolved,
849
+ access: liveAccess ?? (cached?.access as UserRepoAccessResult),
850
+ ...(cached && cached.archivedRepos.length > 0
851
+ ? { archivedRepos: cached.archivedRepos }
852
+ : {}),
804
853
  agentRepos: agent.repos,
805
854
  installationRepos,
806
855
  ...(selections ? { selections } : {}),
@@ -5,6 +5,7 @@ import type {
5
5
  } from "./installation-repos-service.ts";
6
6
  import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
7
7
  import {
8
+ ARCHIVED_REASON,
8
9
  GITHUB_SYNC_AUDIT_PLAN_HASH,
9
10
  type CachedLookupOrg,
10
11
  GithubSyncService,
@@ -250,6 +251,70 @@ describe("planGithubSync (confirmed lists)", () => {
250
251
  });
251
252
  });
252
253
 
254
+ describe("planGithubSync (archived repos)", () => {
255
+ // acme/d is pushable and acme/c is not; both are archived.
256
+ const archivedRepos = ["ACME/d", "acme/c"];
257
+
258
+ test("an archived repo is never an add, but an installed one the user cannot push is removed", () => {
259
+ const p = planGithubSync(base({ archivedRepos }));
260
+ expect(p.appAdds).toEqual(["acme/e"]);
261
+ expect(p.appRemoves).toEqual(["acme/b", "acme/c"]);
262
+ expect(p.skippedOrgs).toEqual([]);
263
+ });
264
+
265
+ test("the agent's own archived repo keeps the normal removal rule", () => {
266
+ const p = planGithubSync(
267
+ base({ archivedRepos, agentRepos: ["acme/a", "acme/c"] }),
268
+ );
269
+ expect(p.agentRemoves).toEqual(["acme/c"]);
270
+ expect(p.appRemoves).toEqual(["acme/b", "acme/c"]);
271
+ });
272
+
273
+ test("an archived add does not skip its org when the org has no access answer for it", () => {
274
+ const p = planGithubSync(
275
+ base({
276
+ archivedRepos: ["other/old"],
277
+ installationRepos: { acme: ["acme/a"] },
278
+ requested: { appAdds: ["other/old"], appRemoves: [], agentRemoves: [] },
279
+ }),
280
+ );
281
+ expect(p.skippedOrgs).toEqual([]);
282
+ expect(p.notApplied).toEqual([{ repo: "other/old", reason: ARCHIVED_REASON }]);
283
+ });
284
+
285
+ test("an installed archived repo in an unchecked org is kept, not removed", () => {
286
+ const p = planGithubSync(
287
+ base({
288
+ archivedRepos: ["other/old"],
289
+ installationRepos: { acme: ["acme/a"], other: ["other/old"] },
290
+ }),
291
+ );
292
+ expect(p.appRemoves).toEqual([]);
293
+ expect(p.skippedOrgs.map((o) => o.org)).toEqual(["other"]);
294
+ });
295
+
296
+ test("confirmed archived adds are reported as left alone; removals proceed", () => {
297
+ const p = planGithubSync(
298
+ base({
299
+ archivedRepos,
300
+ requested: {
301
+ appAdds: ["acme/d"],
302
+ appRemoves: ["acme/c"],
303
+ agentRemoves: [],
304
+ },
305
+ }),
306
+ );
307
+ expect([p.appAdds, p.appRemoves]).toEqual([[], ["acme/c"]]);
308
+ expect(p.notApplied).toEqual([{ repo: "acme/d", reason: ARCHIVED_REASON }]);
309
+ });
310
+
311
+ test("without archivedRepos nothing changes", () => {
312
+ expect(planGithubSync(base({ archivedRepos: [] }))).toEqual(
313
+ planGithubSync(base()),
314
+ );
315
+ });
316
+ });
317
+
253
318
  // ─── Service ────────────────────────────────────────────────────────────────
254
319
 
255
320
  function harness(
@@ -41,7 +41,7 @@ export function renderPushToggle(args: PushToggleArgs): string {
41
41
  return `
42
42
  <div class="push-toggle" id="push-toggle" style="margin:8px 0;font-size:13px">
43
43
  <button type="button" id="push-toggle-btn" class="btn btn-secondary" style="display:none">Enable notifications</button>
44
- <span id="push-toggle-status" style="color:#6b7280"></span>
44
+ <span id="push-toggle-status" style="color:var(--vos-text-muted)"></span>
45
45
  </div>
46
46
  <script>
47
47
  (function() {