@app-vitals/agent-admin 1.101.1 → 1.101.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-admin",
3
- "version": "1.101.1",
3
+ "version": "1.101.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/app-vitals/agent.git",
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@anthropic-ai/sdk": "0.137.0",
47
- "@app-vitals/agent-lib": "1.101.1",
47
+ "@app-vitals/agent-lib": "1.101.3",
48
48
  "@hono/zod-openapi": "^1.0.0",
49
49
  "@prisma/adapter-pg": "^7.10.0",
50
50
  "@prisma/client": "^7.10.0",
@@ -0,0 +1,99 @@
1
+ /**
2
+ * admin/src/agent-members.integration.test.ts (ACM-4.1)
3
+ * AgentMemberService reads and writes by memberId; email is resolved through
4
+ * the AccountMember lookup. Rows with a null memberId are skipped.
5
+ *
6
+ * Requires DATABASE_URL_ADMIN_TEST; skips otherwise.
7
+ */
8
+
9
+ import { afterEach, beforeEach, describe, expect, it } from "bun:test";
10
+ import type { PrismaClient } from "../prisma/client/client.ts";
11
+ import { AgentMemberService } from "./agent-members.ts";
12
+ import { resetMemberIdFixture } from "./member-id-test-support.ts";
13
+ import { createAdminPrismaClient } from "./prisma-client.ts";
14
+
15
+ const TEST_DB = process.env.DATABASE_URL_ADMIN_TEST;
16
+ const describeOrSkip = TEST_DB ? describe : describe.skip;
17
+
18
+ describeOrSkip("AgentMemberService by memberId (integration)", () => {
19
+ let prisma: PrismaClient;
20
+ let service: AgentMemberService;
21
+ let aliceId: string;
22
+ let bobId: string;
23
+ let agentId: string;
24
+
25
+ beforeEach(async () => {
26
+ prisma = createAdminPrismaClient(TEST_DB as string);
27
+ const f = await resetMemberIdFixture(prisma);
28
+ aliceId = f.alice.id;
29
+ bobId = f.bob.id;
30
+ agentId = f.agent.id;
31
+ service = new AgentMemberService(prisma);
32
+ });
33
+
34
+ afterEach(async () => {
35
+ await prisma.$disconnect();
36
+ });
37
+
38
+ it("add stamps memberId resolved from the email (case-insensitive)", async () => {
39
+ const row = await service.add(agentId, "alice@acme.com");
40
+ expect(row.memberId).toBe(aliceId);
41
+ const stored = await prisma.agentMember.findUniqueOrThrow({
42
+ where: { id: row.id },
43
+ });
44
+ expect(stored.memberId).toBe(aliceId);
45
+ });
46
+
47
+ it("add inside a transaction resolves memberId through the tx client", async () => {
48
+ await prisma.$transaction(async (tx) => {
49
+ await service.add(agentId, "bob@acme.com", tx);
50
+ });
51
+ const rows = await prisma.agentMember.findMany();
52
+ expect(rows.map((r) => r.memberId)).toEqual([bobId]);
53
+ });
54
+
55
+ it("add for an email with no AccountMember stores a null memberId", async () => {
56
+ const row = await service.add(agentId, "ghost@nowhere.com");
57
+ expect(row.memberId).toBeNull();
58
+ });
59
+
60
+ it("listByEmail and listByMemberId return the member's agents", async () => {
61
+ await service.add(agentId, "alice@acme.com");
62
+ expect((await service.listByEmail("Alice@Acme.com")).length).toBe(1);
63
+ expect((await service.listByMemberId(aliceId)).length).toBe(1);
64
+ expect(await service.listByMemberId(bobId)).toEqual([]);
65
+ });
66
+
67
+ it("exists keys on memberId", async () => {
68
+ await service.add(agentId, "alice@acme.com");
69
+ expect(await service.exists(agentId, "alice@acme.com")).toBe(true);
70
+ expect(await service.exists(agentId, "bob@acme.com")).toBe(false);
71
+ expect(await service.exists(agentId, "ghost@nowhere.com")).toBe(false);
72
+ });
73
+
74
+ it("skips null-memberId rows on every read without crashing", async () => {
75
+ // Legacy row: email only, never backfilled.
76
+ await prisma.agentMember.create({
77
+ data: { agentId, email: "alice@acme.com" },
78
+ });
79
+ expect(await service.listByEmail("alice@acme.com")).toEqual([]);
80
+ expect(await service.exists(agentId, "alice@acme.com")).toBe(false);
81
+ expect(await service.listByAgentId(agentId)).toEqual([]);
82
+ });
83
+
84
+ it("listByAgentId returns rows with the email resolved through the lookup", async () => {
85
+ await service.add(agentId, "alice@acme.com");
86
+ // Stored email drifted from the member's current email.
87
+ await prisma.agentMember.updateMany({ data: { email: "stale@old.com" } });
88
+ const rows = await service.listByAgentId(agentId);
89
+ expect(rows.map((r) => r.email)).toEqual(["alice@acme.com"]);
90
+ });
91
+
92
+ it("remove deletes by row id scoped to the agent", async () => {
93
+ const row = await service.add(agentId, "alice@acme.com");
94
+ await service.remove("other-agent", row.id);
95
+ expect((await service.listByMemberId(aliceId)).length).toBe(1);
96
+ await service.remove(agentId, row.id);
97
+ expect(await service.listByMemberId(aliceId)).toEqual([]);
98
+ });
99
+ });
@@ -2,46 +2,81 @@
2
2
  * agent/src/agent-members.ts
3
3
  * AgentMemberService — authorized human members per agent (access control).
4
4
  *
5
- * Membership rows are keyed by [agentId, email] (unique constraint) — an
6
- * email can be a member of multiple agents, and an agent can have multiple
7
- * member emails.
5
+ * ACM-4.1: reads and writes key on AgentMember.memberId (AccountMember.id).
6
+ * Callers still pass emails; they are resolved to a member id through the
7
+ * AccountMember lookup, and emails handed back are resolved the same way. Rows
8
+ * whose memberId is null (not yet backfilled) are skipped. The [agentId, email]
9
+ * unique constraint stays in place and still guards duplicate adds.
8
10
  */
9
11
 
10
12
  import type { AgentMember, PrismaClient } from "../prisma/client/client.ts";
13
+ import { normalizeEmail } from "./account-email.ts";
14
+ import { PrincipalLookupService } from "./principal-lookup.ts";
11
15
  import type { PrismaTransactionClient } from "./prisma-tx.ts";
12
16
 
13
17
  export type { AgentMember };
14
18
 
15
19
  export class AgentMemberService {
16
- constructor(private prisma: PrismaClient) {}
20
+ private readonly lookup: PrincipalLookupService;
21
+
22
+ constructor(private prisma: PrismaClient) {
23
+ this.lookup = new PrincipalLookupService(prisma);
24
+ }
25
+
26
+ private async memberIdForEmail(email: string): Promise<string | null> {
27
+ return (await this.lookup.findIdByEmail(email))?.id ?? null;
28
+ }
17
29
 
18
30
  /**
19
- * List all memberships for a given agent.
31
+ * List all memberships for a given agent. Rows with a null memberId, or a
32
+ * memberId that no longer resolves, are skipped; `email` on each returned
33
+ * row is the member's current email from the lookup.
20
34
  */
21
35
  async listByAgentId(agentId: string): Promise<AgentMember[]> {
22
- return this.prisma.agentMember.findMany({ where: { agentId } });
36
+ const rows = await this.prisma.agentMember.findMany({
37
+ where: { agentId, memberId: { not: null } },
38
+ });
39
+ const { principals } = await this.lookup.resolveMany(
40
+ rows.flatMap((r) => (r.memberId ? [r.memberId] : [])),
41
+ );
42
+ const emails = new Map(principals.map((p) => [p.id, p.email]));
43
+ return rows.flatMap((r) => {
44
+ const email = r.memberId ? emails.get(r.memberId) : null;
45
+ return email ? [{ ...r, email }] : [];
46
+ });
47
+ }
48
+
49
+ /** List all memberships for a given AccountMember id. */
50
+ async listByMemberId(memberId: string): Promise<AgentMember[]> {
51
+ return this.prisma.agentMember.findMany({ where: { memberId } });
23
52
  }
24
53
 
25
54
  /**
26
- * List all memberships for a given email, case-sensitive as stored.
27
- * Callers are expected to lowercase the email before calling.
55
+ * List all memberships for the member owning `email` (case-insensitive).
56
+ * Empty when the email has no AccountMember.
28
57
  */
29
58
  async listByEmail(email: string): Promise<AgentMember[]> {
30
- return this.prisma.agentMember.findMany({ where: { email } });
59
+ const memberId = await this.memberIdForEmail(email);
60
+ return memberId ? this.listByMemberId(memberId) : [];
31
61
  }
32
62
 
33
63
  /**
34
- * Returns whether a membership row exists for the given agentId+email pair.
64
+ * Returns whether the member owning `email` has a membership row for the agent.
35
65
  */
36
66
  async exists(agentId: string, email: string): Promise<boolean> {
37
- const membership = await this.prisma.agentMember.findUnique({
38
- where: { agentId_email: { agentId, email } },
67
+ const memberId = await this.memberIdForEmail(email);
68
+ if (!memberId) return false;
69
+ const membership = await this.prisma.agentMember.findFirst({
70
+ where: { agentId, memberId },
71
+ select: { id: true },
39
72
  });
40
73
  return membership !== null;
41
74
  }
42
75
 
43
76
  /**
44
- * Create a membership row for the given agentId and email.
77
+ * Create a membership row for the given agentId and email, stamped with the
78
+ * email's AccountMember id (null when the email has no member yet — such a
79
+ * row is skipped by reads until backfilled).
45
80
  * Throws (unique-constraint violation) if the membership already exists —
46
81
  * callers are expected to catch and handle "already a member" as a no-op.
47
82
  *
@@ -54,7 +89,14 @@ export class AgentMemberService {
54
89
  email: string,
55
90
  client: PrismaTransactionClient = this.prisma,
56
91
  ): Promise<AgentMember> {
57
- return client.agentMember.create({ data: { agentId, email } });
92
+ const normalized = normalizeEmail(email);
93
+ const member = await client.accountMember.findUnique({
94
+ where: { email: normalized },
95
+ select: { id: true },
96
+ });
97
+ return client.agentMember.create({
98
+ data: { agentId, email: normalized, memberId: member?.id ?? null },
99
+ });
58
100
  }
59
101
 
60
102
  /**
@@ -96,6 +96,22 @@ const CODING_TYPE: SpecialtyType = {
96
96
  * specialty. tryGetType() returns undefined (no fallback) for anything
97
97
  * not in the map, mirroring SpecialtyTypes's real contract.
98
98
  */
99
+ // ACM-4.1: AgentMember reads key on memberId, so seeded members need an
100
+ // AccountMember to resolve through.
101
+ async function seedAgentMember(
102
+ prisma: PrismaClient,
103
+ agentId: string,
104
+ email: string,
105
+ ) {
106
+ const account = await prisma.account.create({ data: { name: "Acme" } });
107
+ const member = await prisma.accountMember.create({
108
+ data: { accountId: account.id, email, role: "member" },
109
+ });
110
+ await prisma.agentMember.create({
111
+ data: { agentId, email, memberId: member.id },
112
+ });
113
+ }
114
+
99
115
  function fakeSpecialtyTypes(
100
116
  byType: Record<string, SpecialtyType> = { coding: CODING_TYPE },
101
117
  ): SpecialtyTypeResolver {
@@ -181,6 +197,8 @@ describeOrSkip("admin CRUD API (integration)", () => {
181
197
  await prisma.agentEnv.deleteMany();
182
198
  await prisma.agentMember.deleteMany();
183
199
  await prisma.agent.deleteMany();
200
+ await prisma.accountMember.deleteMany();
201
+ await prisma.account.deleteMany();
184
202
 
185
203
  agentId = await createAgent(prisma);
186
204
  cookie = await makeSessionCookie();
@@ -615,9 +633,7 @@ describeOrSkip("admin CRUD API (integration)", () => {
615
633
  Cookie: `admin_session=${cookie}`,
616
634
  },
617
635
  });
618
- await prisma.agentMember.create({
619
- data: { agentId, email: "member@example.com" },
620
- });
636
+ await seedAgentMember(prisma, agentId, "member@example.com");
621
637
 
622
638
  const secondPatchRes = await app.request(`/agents/${agentId}`, {
623
639
  method: "PATCH",
@@ -745,6 +761,8 @@ describeOrSkip("PATCH /agents/:id podServiceAccountName (integration)", () => {
745
761
  await prisma.agentEnv.deleteMany();
746
762
  await prisma.agentMember.deleteMany();
747
763
  await prisma.agent.deleteMany();
764
+ await prisma.accountMember.deleteMany();
765
+ await prisma.account.deleteMany();
748
766
  agentId = await createAgent(prisma);
749
767
  cookie = await makeSessionCookie();
750
768
  reconciled.length = 0;
@@ -784,9 +802,7 @@ describeOrSkip("PATCH /agents/:id podServiceAccountName (integration)", () => {
784
802
  SESSION_SECRET,
785
803
  "HS256",
786
804
  );
787
- await prisma.agentMember.create({
788
- data: { agentId, email: "member@example.com" },
789
- });
805
+ await seedAgentMember(prisma, agentId, "member@example.com");
790
806
  const res = await patch(
791
807
  appWith(true),
792
808
  { podServiceAccountName: "sa" },
@@ -814,7 +814,12 @@ describe("AgentService.getById", () => {
814
814
  },
815
815
  ],
816
816
  }) as unknown as FakePrisma;
817
- const service = new AgentService(prisma as never);
817
+ // ACM-4.1: AgentMemberService resolves emails through AccountMember and is
818
+ // covered by agent-members.integration.test.ts; here it is a seeded double.
819
+ const service = new AgentService(prisma as never, undefined, {
820
+ listByAgentId: async (agentId: string) =>
821
+ (await prisma.agentMember.findMany({ where: { agentId } })) as never,
822
+ });
818
823
 
819
824
  const result = await service.getById("a1");
820
825
 
@@ -45,6 +45,45 @@ export function lookupAccountKeys(accountId?: string | null): string[] {
45
45
  : [DEPLOYMENT_WIDE_ACCOUNT_KEY];
46
46
  }
47
47
 
48
+ /**
49
+ * Reads per-user access rows under every key in lookupAccountKeys(accountId)
50
+ * and merges them. The writer files rows under the resolved lookup App's scope
51
+ * key, which is DEPLOYMENT_WIDE_ACCOUNT_KEY when an account's agent falls back
52
+ * to a deployment-wide lookup App, so a single-key read under the agent's own
53
+ * account finds nothing. For the same repo the agent's own account row wins
54
+ * over the deployment row. Read-side only; the store keeps its single-key shape.
55
+ */
56
+ export async function getAccessRowsAcrossKeys<R extends { repo: string }>(
57
+ store: {
58
+ getAccessRows(query: {
59
+ accountId: string;
60
+ org: string;
61
+ username: string;
62
+ repos: string[];
63
+ }): Promise<R[]>;
64
+ },
65
+ query: {
66
+ accountId?: string | null;
67
+ org: string;
68
+ username: string;
69
+ repos: string[];
70
+ },
71
+ ): Promise<R[]> {
72
+ const merged = new Map<string, R>();
73
+ for (const accountId of lookupAccountKeys(query.accountId)) {
74
+ const rows = await store.getAccessRows({
75
+ accountId,
76
+ org: query.org,
77
+ username: query.username,
78
+ repos: query.repos,
79
+ });
80
+ for (const row of rows) {
81
+ if (!merged.has(row.repo)) merged.set(row.repo, row);
82
+ }
83
+ }
84
+ return [...merged.values()];
85
+ }
86
+
48
87
  /** The slice of the installer client the crawl needs. */
49
88
  export type AgentInstallationClient = Pick<
50
89
  InstallationRepoClient,
@@ -11,6 +11,7 @@ import {
11
11
  agentInstallationPageSource,
12
12
  crawlAgentInstallation,
13
13
  DEPLOYMENT_WIDE_ACCOUNT_KEY,
14
+ getAccessRowsAcrossKeys,
14
15
  lookupAccountKeys,
15
16
  type AgentInstallationClient,
16
17
  } from "./github-agent-installation-crawler.ts";
@@ -451,3 +452,72 @@ describe("crawlAgentInstallation repository selection (GIS-1.1)", () => {
451
452
  expect(selection(store)).toBe("selected");
452
453
  });
453
454
  });
455
+
456
+ describe("getAccessRowsAcrossKeys", () => {
457
+ type Row = { repo: string; canPush: boolean; from: string };
458
+
459
+ /** A store keyed by accountId; records each query it receives. */
460
+ const storeOf = (byKey: Record<string, Row[]>) => {
461
+ const queried: string[] = [];
462
+ return {
463
+ queried,
464
+ async getAccessRows(q: {
465
+ accountId: string;
466
+ org: string;
467
+ username: string;
468
+ repos: string[];
469
+ }) {
470
+ queried.push(q.accountId);
471
+ return (byKey[q.accountId] ?? []).filter((r) =>
472
+ q.repos.includes(r.repo),
473
+ );
474
+ },
475
+ };
476
+ };
477
+ const query = {
478
+ accountId: "acct",
479
+ org: "acme",
480
+ username: "octocat",
481
+ repos: ["a", "b"],
482
+ };
483
+
484
+ it("the agent's own account row wins over a deployment row for the same repo", async () => {
485
+ const store = storeOf({
486
+ acct: [{ repo: "a", canPush: false, from: "own" }],
487
+ [DEPLOYMENT_WIDE_ACCOUNT_KEY]: [
488
+ { repo: "a", canPush: true, from: "deployment" },
489
+ ],
490
+ });
491
+ const rows = await getAccessRowsAcrossKeys(store, query);
492
+ expect(rows).toEqual([{ repo: "a", canPush: false, from: "own" }]);
493
+ expect(store.queried).toEqual(["acct", DEPLOYMENT_WIDE_ACCOUNT_KEY]);
494
+ });
495
+
496
+ it("uses a deployment row when there is no own row, and merges the rest", async () => {
497
+ const store = storeOf({
498
+ acct: [{ repo: "b", canPush: true, from: "own" }],
499
+ [DEPLOYMENT_WIDE_ACCOUNT_KEY]: [
500
+ { repo: "a", canPush: true, from: "deployment" },
501
+ ],
502
+ });
503
+ const rows = await getAccessRowsAcrossKeys(store, query);
504
+ expect(rows.map((r) => [r.repo, r.from]).sort()).toEqual([
505
+ ["a", "deployment"],
506
+ ["b", "own"],
507
+ ]);
508
+ });
509
+
510
+ it("an agent with no account reads only the deployment key", async () => {
511
+ const store = storeOf({
512
+ [DEPLOYMENT_WIDE_ACCOUNT_KEY]: [
513
+ { repo: "a", canPush: true, from: "deployment" },
514
+ ],
515
+ });
516
+ const rows = await getAccessRowsAcrossKeys(store, {
517
+ ...query,
518
+ accountId: null,
519
+ });
520
+ expect(rows).toHaveLength(1);
521
+ expect(store.queried).toEqual([DEPLOYMENT_WIDE_ACCOUNT_KEY]);
522
+ });
523
+ });
@@ -161,7 +161,7 @@ describeOrSkip("GitHub repo cache round trip (integration)", () => {
161
161
  ({
162
162
  get: async (role: string, scope?: string | null) => {
163
163
  if (role !== "lookup") return null;
164
- const found = apps.byScope.get(scope ?? null);
164
+ const found = apps.byScope.get(scope ?? null) ?? apps.byScope.get(null);
165
165
  if (!found) return null;
166
166
  return {
167
167
  appId: LOOKUP_APP_ID,
@@ -171,7 +171,10 @@ describeOrSkip("GitHub repo cache round trip (integration)", () => {
171
171
  };
172
172
  },
173
173
  getPrivateKey: async (role: string, scope?: string | null) =>
174
- role === "lookup" && apps.byScope.has(scope ?? null) ? "pem" : null,
174
+ role === "lookup" &&
175
+ (apps.byScope.has(scope ?? null) || apps.byScope.has(null))
176
+ ? "pem"
177
+ : null,
175
178
  }) as unknown as GitHubEnterpriseAppService;
176
179
 
177
180
  /** Run the real refresher until every target is crawled and backfilled. */
@@ -190,7 +193,9 @@ describeOrSkip("GitHub repo cache round trip (integration)", () => {
190
193
  return out;
191
194
  },
192
195
  async lookupApp(scope) {
193
- const found = apps.byScope.get(scope);
196
+ // As the stored-App resolver does: the scope's own App, else the
197
+ // deployment-wide one.
198
+ const found = apps.byScope.get(scope) ?? apps.byScope.get(null);
194
199
  if (!found) return null;
195
200
  return {
196
201
  accountId: found.ownerAccountId,
@@ -402,4 +407,41 @@ describeOrSkip("GitHub repo cache round trip (integration)", () => {
402
407
  reposOf("acme"),
403
408
  );
404
409
  });
410
+
411
+ it("account-scoped agent on a deployment-wide lookup App: access rows under the deployment key still reach Sync and the installation list (GFU-3.1)", async () => {
412
+ const acct = await makeAccount("roundtrip-fallback");
413
+ const agentId = await makeAgent(acct);
414
+ // Only the deployment-wide lookup App exists; the account has none, so
415
+ // the writer files the per-user access rows under DEPLOYMENT_WIDE_ACCOUNT_KEY.
416
+ const apps: Apps = {
417
+ byScope: new Map([[null, { ownerAccountId: null, orgs: ["acme"] }]]),
418
+ };
419
+ const installer = await refresh(apps, acct);
420
+
421
+ const rowKeys = await prisma.gitHubRepoAccess.findMany({
422
+ where: { username: USERNAME },
423
+ });
424
+ expect(rowKeys.length).toBeGreaterThan(0);
425
+ expect(
426
+ rowKeys.every((r) => r.accountId === DEPLOYMENT_WIDE_ACCOUNT_KEY),
427
+ ).toBe(true);
428
+
429
+ // Sync preview: the access data is complete, not "incomplete".
430
+ const sync = createGithubSync(wiring(apps, installer));
431
+ const preview = await sync.preview(agentId);
432
+ if (preview.status !== "previewed") throw new Error(preview.status);
433
+ expect(preview.plan.skippedOrgs).toEqual([]);
434
+ expect(JSON.stringify(preview)).not.toContain("access data is incomplete");
435
+
436
+ // Installation list: repos carry access hints read from the deployment rows.
437
+ const list = await createGithubInstallationRepos(
438
+ wiring(apps, installer),
439
+ ).list(agentId);
440
+ if (list.status !== "ok") throw new Error(list.status);
441
+ const repos = list.orgs[0]?.repos ?? [];
442
+ expect(repos.map((r) => r.fullName).sort()).toEqual(reposOf("acme"));
443
+ expect(
444
+ repos.some((r) => Object.keys(r).some((k) => k !== "fullName")),
445
+ ).toBe(true);
446
+ });
405
447
  });
@@ -34,7 +34,10 @@
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
+ import {
38
+ DEPLOYMENT_WIDE_ACCOUNT_KEY,
39
+ getAccessRowsAcrossKeys,
40
+ } from "./github-agent-installation-crawler.ts";
38
41
  import {
39
42
  GITHUB_APPS_STATE_REASONS,
40
43
  type GithubAppsState,
@@ -755,8 +758,8 @@ export class GithubSyncService {
755
758
  let failed = readFailed;
756
759
  if (!failed && repos.size > 0) {
757
760
  try {
758
- rows = await cache.getAccessRows({
759
- accountId,
761
+ rows = await getAccessRowsAcrossKeys(cache, {
762
+ accountId: agent.accountId,
760
763
  org,
761
764
  username,
762
765
  repos: [...repos.values()].map((f) => f.slice(f.indexOf("/") + 1)),
@@ -13,7 +13,10 @@ import {
13
13
  type GithubAppsStateFn,
14
14
  } from "./github-apps-state.ts";
15
15
  import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
16
- import { DEPLOYMENT_WIDE_ACCOUNT_KEY } from "./github-agent-installation-crawler.ts";
16
+ import {
17
+ DEPLOYMENT_WIDE_ACCOUNT_KEY,
18
+ getAccessRowsAcrossKeys,
19
+ } from "./github-agent-installation-crawler.ts";
17
20
  import {
18
21
  type AppIdentity,
19
22
  type AppInstallationPort,
@@ -317,8 +320,8 @@ export class InstallationReposService {
317
320
  }));
318
321
  if (cache && username && s.completedAt && names.length > 0) {
319
322
  try {
320
- const rows = await cache.getAccessRows({
321
- accountId,
323
+ const rows = await getAccessRowsAcrossKeys(cache, {
324
+ accountId: agent.accountId,
322
325
  org: s.org,
323
326
  username,
324
327
  repos: names.map((f) => f.slice(f.indexOf("/") + 1)),
@@ -0,0 +1,29 @@
1
+ /**
2
+ * admin/src/member-id-test-support.ts
3
+ * Shared seed helpers for the ACM-4.1 per-table memberId integration tests.
4
+ * Wipes the four per-user tables plus accounts, then seeds one account with
5
+ * two members and one agent.
6
+ */
7
+
8
+ import type { PrismaClient } from "../prisma/client/client.ts";
9
+
10
+ export async function resetMemberIdFixture(prisma: PrismaClient) {
11
+ await prisma.userNotificationPrefs.deleteMany();
12
+ await prisma.chatThreadWatch.deleteMany();
13
+ await prisma.pushSubscription.deleteMany();
14
+ await prisma.agentMember.deleteMany();
15
+ await prisma.accountMember.deleteMany();
16
+ await prisma.agent.deleteMany();
17
+ await prisma.account.deleteMany();
18
+ const account = await prisma.account.create({ data: { name: "Acme" } });
19
+ const alice = await prisma.accountMember.create({
20
+ data: { accountId: account.id, email: "alice@acme.com", role: "owner" },
21
+ });
22
+ const bob = await prisma.accountMember.create({
23
+ data: { accountId: account.id, email: "bob@acme.com", role: "member" },
24
+ });
25
+ const agent = await prisma.agent.create({
26
+ data: { id: "acm41-agent", name: "acm41-agent" },
27
+ });
28
+ return { alice, bob, agent };
29
+ }