@app-vitals/agent-admin 1.84.1 → 1.85.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.
@@ -1,7 +1,12 @@
1
1
  import { describe, expect, it, test } from "bun:test";
2
+ import type {
3
+ CachedAccessRow,
4
+ InstallationSnapshotRow,
5
+ } from "./installation-repos-service.ts";
2
6
  import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
3
7
  import {
4
8
  GITHUB_SYNC_AUDIT_PLAN_HASH,
9
+ type CachedLookupOrg,
5
10
  GithubSyncService,
6
11
  NOT_ADDABLE_REASON,
7
12
  NOT_PRESENT_REASON,
@@ -603,3 +608,193 @@ describe("GithubSyncService.apply", () => {
603
608
  expect(repos()).toEqual(["acme/a"]);
604
609
  });
605
610
  });
611
+
612
+ describe("skippedOrgs detail", () => {
613
+ const detail = {
614
+ lookupSnapshotFound: true,
615
+ totalRepos: 3,
616
+ reposWithOkAccess: 1,
617
+ reposMissingAnswer: 2,
618
+ errorRows: 1,
619
+ terminalRows: 1,
620
+ };
621
+
622
+ test("planGithubSync carries the org's detail next to the unchanged reason", () => {
623
+ const p = planGithubSync(
624
+ base({
625
+ access: access([
626
+ org("acme", [], {
627
+ status: "partial",
628
+ reason: "access data is incomplete",
629
+ detail,
630
+ }),
631
+ ]),
632
+ }),
633
+ );
634
+ expect(p.skippedOrgs).toEqual([
635
+ { org: "acme", reason: "access data is incomplete", detail },
636
+ ]);
637
+ expect(p.warnings).toEqual(["acme: skipped (access data is incomplete)"]);
638
+ });
639
+
640
+ test("an org with no detail has no detail key", () => {
641
+ const p = planGithubSync(base({ access: access([]) }));
642
+ expect(p.skippedOrgs[0]).toEqual({
643
+ org: "acme",
644
+ reason: "org was not checked",
645
+ });
646
+ });
647
+
648
+ function cachedSvc(
649
+ lookup: Parameters<typeof lookupDeps>[0],
650
+ over: {
651
+ snap?: Partial<InstallationSnapshotRow>;
652
+ rows?: CachedAccessRow[];
653
+ } = {},
654
+ ) {
655
+ return new GithubSyncService({
656
+ agents: {
657
+ get: async () => ({
658
+ id: "ag",
659
+ githubUsername: "octo",
660
+ appId: 7,
661
+ repos: ["acme/a"],
662
+ }),
663
+ setRepos: async () => {},
664
+ },
665
+ access: async () => {
666
+ throw new Error("live resolver must not be used");
667
+ },
668
+ installation: {
669
+ listInstalled: async () => ({
670
+ status: "found",
671
+ orgs: [{ org: "acme", repos: ["acme/a", "acme/b"] }],
672
+ }),
673
+ addRepos: async () => {},
674
+ removeRepos: async () => {},
675
+ },
676
+ audit: { write: async () => "a" },
677
+ now: () => new Date("2026-11-20T12:00:00.000Z"),
678
+ ...(() => {
679
+ const d = lookupDeps(lookup);
680
+ return {
681
+ ...d,
682
+ cache: {
683
+ listAgentSnapshots: async () => [
684
+ { ...(await d.cache.listAgentSnapshots())[0], ...over.snap },
685
+ ],
686
+ getAccessRows: async () =>
687
+ over.rows ?? (await d.cache.getAccessRows()),
688
+ },
689
+ };
690
+ })(),
691
+ });
692
+ }
693
+ const lookupDeps = (lookup: CachedLookupOrg[]) => ({
694
+ cache: {
695
+ listAgentSnapshots: async () => [
696
+ {
697
+ org: "acme",
698
+ completedAt: new Date("2026-11-20T11:00:00.000Z"),
699
+ totalCount: 2,
700
+ lastError: null,
701
+ rateLimitResetAt: null,
702
+ repos: [{ fullName: "acme/a" }, { fullName: "acme/b" }],
703
+ },
704
+ ],
705
+ getAccessRows: async () => [
706
+ { repo: "a", status: "ok", canPush: true },
707
+ { repo: "b", status: "terminal", canPush: false, attempts: 4 },
708
+ ],
709
+ },
710
+ lookupRepos: async () => lookup,
711
+ });
712
+
713
+ it("reports a missing lookup snapshot", async () => {
714
+ const r = await cachedSvc([]).preview("ag");
715
+ if (r.status !== "previewed") throw new Error(r.status);
716
+ expect(r.plan.skippedOrgs[0]).toMatchObject({
717
+ org: "acme",
718
+ reason: "access data is incomplete",
719
+ detail: { lookupSnapshotFound: false },
720
+ });
721
+ });
722
+
723
+ it("reports the lookup crawl's completedAt, lastError and rateLimitResetAt plus row counts", async () => {
724
+ const reset = new Date("2026-11-20T13:00:00.000Z");
725
+ const r = await cachedSvc([
726
+ {
727
+ org: "acme",
728
+ completedAt: null,
729
+ repos: ["acme/a", "acme/b"],
730
+ lastError: "secondary rate limit",
731
+ rateLimitResetAt: reset,
732
+ },
733
+ ]).preview("ag");
734
+ if (r.status !== "previewed") throw new Error(r.status);
735
+ expect(r.plan.skippedOrgs[0]?.detail).toMatchObject({
736
+ lookupSnapshotFound: true,
737
+ totalRepos: 2,
738
+ reposWithOkAccess: 1,
739
+ reposMissingAnswer: 1,
740
+ terminalRows: 1,
741
+ errorRows: 0,
742
+ maxAttempts: 4,
743
+ });
744
+ expect(r.plan.skippedOrgs[0]?.detail?.crawls).toContainEqual({
745
+ completedAt: null,
746
+ lastError: "secondary rate limit",
747
+ rateLimitResetAt: reset.toISOString(),
748
+ });
749
+ });
750
+
751
+ it("reports the installation crawl's lastError and rateLimitResetAt", async () => {
752
+ const r = await cachedSvc(
753
+ [
754
+ {
755
+ org: "acme",
756
+ completedAt: new Date("2026-11-20T11:00:00.000Z"),
757
+ repos: ["acme/a", "acme/b"],
758
+ },
759
+ ],
760
+ {
761
+ snap: { completedAt: null, lastError: "boom", rateLimitResetAt: null },
762
+ },
763
+ ).preview("ag");
764
+ if (r.status !== "previewed") throw new Error(r.status);
765
+ expect(r.plan.skippedOrgs[0]?.detail?.crawls).toContainEqual({
766
+ completedAt: null,
767
+ lastError: "boom",
768
+ rateLimitResetAt: null,
769
+ });
770
+ });
771
+
772
+ it("reports the oldest-checked time and error row count for stale data", async () => {
773
+ const old = new Date("2026-01-01T00:00:00.000Z");
774
+ const r = await cachedSvc(
775
+ [
776
+ {
777
+ org: "acme",
778
+ completedAt: new Date("2026-11-20T11:00:00.000Z"),
779
+ repos: ["acme/a", "acme/b"],
780
+ },
781
+ ],
782
+ {
783
+ rows: [
784
+ { repo: "a", status: "ok", canPush: true, checkedAt: old },
785
+ { repo: "b", status: "ok", canPush: true, checkedAt: old },
786
+ ],
787
+ },
788
+ ).preview("ag");
789
+ if (r.status !== "previewed") throw new Error(r.status);
790
+ expect(r.plan.skippedOrgs[0]).toMatchObject({
791
+ detail: {
792
+ oldestCheckedAt: old.toISOString(),
793
+ reposWithOkAccess: 2,
794
+ reposMissingAnswer: 0,
795
+ errorRows: 0,
796
+ terminalRows: 0,
797
+ },
798
+ });
799
+ });
800
+ });
@@ -11,6 +11,7 @@
11
11
 
12
12
  import {
13
13
  type OrgAccessResult,
14
+ type OrgSkipDetail,
14
15
  SELECTED_REPOS_REASON,
15
16
  type UserRepoAccessResult,
16
17
  } from "./user-repo-access-resolver.ts";
@@ -18,6 +19,8 @@ import {
18
19
  export interface OrgSkip {
19
20
  org: string;
20
21
  reason: string;
22
+ /** Why the org was skipped, when known (cached-data orgs). */
23
+ detail?: OrgSkipDetail;
21
24
  }
22
25
 
23
26
  export function repoOrg(fullName: string): string {
@@ -51,6 +51,31 @@ export interface ResolvedRepoAccess {
51
51
  canPush: boolean;
52
52
  }
53
53
 
54
+ /** Why a cached-data org was skipped: what the cache did and did not answer. All members optional. */
55
+ export interface OrgSkipDetail {
56
+ /** Whether the lookup-App crawl snapshot for the org exists (undefined when not applicable). */
57
+ lookupSnapshotFound?: boolean;
58
+ /** Each crawl snapshot the org depends on. */
59
+ crawls?: {
60
+ completedAt: string | null;
61
+ lastError?: string | null;
62
+ rateLimitResetAt?: string | null;
63
+ }[];
64
+ totalRepos?: number;
65
+ /** Repos with an ok access row. */
66
+ reposWithOkAccess?: number;
67
+ /** Repos without an ok access row. */
68
+ reposMissingAnswer?: number;
69
+ errorRows?: number;
70
+ terminalRows?: number;
71
+ /** Highest attempts count among the access rows. */
72
+ maxAttempts?: number;
73
+ /** Distinct lastError values of the error/terminal rows (at most 3). */
74
+ rowErrors?: string[];
75
+ /** Oldest check time (ISO) when the data is stale. */
76
+ oldestCheckedAt?: string;
77
+ }
78
+
54
79
  export interface OrgAccessResult {
55
80
  org: string;
56
81
  status: OrgAccessStatus;
@@ -60,6 +85,8 @@ export interface OrgAccessResult {
60
85
  unresolved: number;
61
86
  /** Why the org is not "ok" when the cause is the lookup install scope. */
62
87
  reason?: string;
88
+ /** Extra context for a partial org built from cached data. */
89
+ detail?: OrgSkipDetail;
63
90
  }
64
91
 
65
92
  /** Shown when the lookup App is installed on selected repositories only. */