@app-vitals/agent-admin 1.84.1 → 1.84.2
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.84.
|
|
3
|
+
"version": "1.84.2",
|
|
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.84.
|
|
47
|
+
"@app-vitals/agent-lib": "1.84.2",
|
|
48
48
|
"@hono/zod-openapi": "^1.0.0",
|
|
49
49
|
"@prisma/adapter-pg": "^7.10.0",
|
|
50
50
|
"@prisma/client": "^7.10.0",
|
|
@@ -13,6 +13,7 @@ import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
|
|
|
13
13
|
import type { Clock } from "./clock.ts";
|
|
14
14
|
import type { GitHubEnterpriseAppService } from "./github-enterprise-apps.ts";
|
|
15
15
|
import { GithubEnterpriseClient } from "./github-enterprise-client.ts";
|
|
16
|
+
import { DEPLOYMENT_WIDE_ACCOUNT_KEY } from "./github-agent-installation-crawler.ts";
|
|
16
17
|
import { GithubLookupClient } from "./github-lookup-client.ts";
|
|
17
18
|
import { GitHubRepoCacheService } from "./github-repo-cache.ts";
|
|
18
19
|
import type { CrawlStore } from "./github-repo-crawler.ts";
|
|
@@ -158,9 +159,15 @@ export function createGithubSync(
|
|
|
158
159
|
lookupRepos: async (accountId) => {
|
|
159
160
|
const lookup = await lookupClient(accountId);
|
|
160
161
|
if (!lookup) return [];
|
|
161
|
-
// The crawler files a deployment-wide App's snapshots under
|
|
162
|
+
// The crawler files a deployment-wide App's snapshots under
|
|
163
|
+
// DEPLOYMENT_WIDE_ACCOUNT_KEY, so a null-account agent reads that key and
|
|
164
|
+
// an account agent reads its own account plus that key.
|
|
165
|
+
// Note: a real account literally named "deployment" would collide with
|
|
166
|
+
// this fallback key; that is known and deliberately not fixed here.
|
|
162
167
|
const snapshots = await cache.listLookupOrgSnapshots(
|
|
163
|
-
accountId
|
|
168
|
+
accountId
|
|
169
|
+
? [accountId, DEPLOYMENT_WIDE_ACCOUNT_KEY]
|
|
170
|
+
: [DEPLOYMENT_WIDE_ACCOUNT_KEY],
|
|
164
171
|
lookup.appId,
|
|
165
172
|
);
|
|
166
173
|
return snapshots.map((s) => ({
|
|
@@ -5,11 +5,13 @@ import {
|
|
|
5
5
|
fakeOpenWork,
|
|
6
6
|
fakePrisma,
|
|
7
7
|
freshCache,
|
|
8
|
+
withLookupSnapshots,
|
|
8
9
|
} from "./github-installation.fixtures.ts";
|
|
9
10
|
import {
|
|
10
11
|
createGithubInstallationRepos,
|
|
11
12
|
createGithubSync,
|
|
12
13
|
} from "./github-installation-wiring.ts";
|
|
14
|
+
import type { GitHubEnterpriseAppMetadata } from "./github-enterprise-apps.ts";
|
|
13
15
|
import type { InstallationReposPort } from "./installation-repos-service.ts";
|
|
14
16
|
|
|
15
17
|
const noApp = { get: async () => null, getPrivateKey: async () => null };
|
|
@@ -169,3 +171,91 @@ describe("createGithubSync", () => {
|
|
|
169
171
|
expect(state.repos).toEqual(ALL);
|
|
170
172
|
});
|
|
171
173
|
});
|
|
174
|
+
|
|
175
|
+
describe("createGithubSync lookup snapshot read", () => {
|
|
176
|
+
const ALL = ["acme/old", "acme/api"];
|
|
177
|
+
const now = new Date();
|
|
178
|
+
// A real lookupRepos (no syncOverrides): the lookup App's snapshots are read
|
|
179
|
+
// from the cache under the agent's account key, plus the deployment-wide key.
|
|
180
|
+
const build = (
|
|
181
|
+
lookupAccountId: string | null,
|
|
182
|
+
lookupRows: Parameters<typeof withLookupSnapshots>[1],
|
|
183
|
+
agentAccountId?: string,
|
|
184
|
+
) => {
|
|
185
|
+
const { prisma, state } = fakePrisma(
|
|
186
|
+
ALL,
|
|
187
|
+
freshCache("acme", ALL, ["acme/api"], now),
|
|
188
|
+
);
|
|
189
|
+
if (agentAccountId !== undefined) {
|
|
190
|
+
(
|
|
191
|
+
prisma.agent as unknown as { findUnique: () => Promise<unknown> }
|
|
192
|
+
).findUnique = async () => ({
|
|
193
|
+
id: "a1",
|
|
194
|
+
repos: state.repos,
|
|
195
|
+
githubUsername: "dev",
|
|
196
|
+
accountId: agentAccountId,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
withLookupSnapshots(prisma, lookupRows);
|
|
200
|
+
const svc = createGithubSync({
|
|
201
|
+
prisma,
|
|
202
|
+
appService: {
|
|
203
|
+
get: async () =>
|
|
204
|
+
({
|
|
205
|
+
accountId: lookupAccountId,
|
|
206
|
+
appId: "99",
|
|
207
|
+
updatedAt: now,
|
|
208
|
+
}) as unknown as GitHubEnterpriseAppMetadata,
|
|
209
|
+
getPrivateKey: async () => "test-key",
|
|
210
|
+
},
|
|
211
|
+
access: accessFor(["acme/api"]),
|
|
212
|
+
agentEnv: envWith({ GH_APP_ID: "42" }),
|
|
213
|
+
installationRepos: portWith([], ALL),
|
|
214
|
+
now: () => now,
|
|
215
|
+
});
|
|
216
|
+
return { svc, state };
|
|
217
|
+
};
|
|
218
|
+
const lookupAcme = (accountId: string) => ({
|
|
219
|
+
accountId,
|
|
220
|
+
appRef: "99",
|
|
221
|
+
org: "acme",
|
|
222
|
+
completedAt: now,
|
|
223
|
+
repos: ALL.map((fullName) => ({ fullName })),
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('a null-account agent finds the lookup snapshot filed under "deployment"', async () => {
|
|
227
|
+
const { svc, state } = build(null, [lookupAcme("deployment")]);
|
|
228
|
+
const preview = await svc.preview("a1");
|
|
229
|
+
if (preview.status !== "previewed") throw new Error(preview.status);
|
|
230
|
+
// The org is complete and fresh, so it is not skipped for missing lookup data.
|
|
231
|
+
expect(preview.plan.skippedOrgs).toEqual([]);
|
|
232
|
+
const lookupQueries = state.snapshotQueries.filter(
|
|
233
|
+
(q) => (q as { where: { appKind?: string } }).where.appKind === "lookup",
|
|
234
|
+
);
|
|
235
|
+
expect(lookupQueries).toMatchObject([
|
|
236
|
+
{ where: { accountId: { in: ["deployment"] }, appRef: "99" } },
|
|
237
|
+
]);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("an account-scoped agent reads its own account's and the deployment-wide lookup snapshots", async () => {
|
|
241
|
+
const { svc, state } = build("acct-1", [lookupAcme("acct-1")], "acct-1");
|
|
242
|
+
const preview = await svc.preview("a1");
|
|
243
|
+
if (preview.status !== "previewed") throw new Error(preview.status);
|
|
244
|
+
expect(preview.plan.skippedOrgs).toEqual([]);
|
|
245
|
+
const lookupQueries = state.snapshotQueries.filter(
|
|
246
|
+
(q) => (q as { where: { appKind?: string } }).where.appKind === "lookup",
|
|
247
|
+
);
|
|
248
|
+
expect(lookupQueries).toMatchObject([
|
|
249
|
+
{ where: { accountId: { in: ["acct-1", "deployment"] }, appRef: "99" } },
|
|
250
|
+
]);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("with no lookup snapshot under the agent's key, the org is skipped as incomplete", async () => {
|
|
254
|
+
const { svc } = build(null, [lookupAcme("some-other-account")]);
|
|
255
|
+
const preview = await svc.preview("a1");
|
|
256
|
+
if (preview.status !== "previewed") throw new Error(preview.status);
|
|
257
|
+
expect(preview.plan.skippedOrgs).toEqual([
|
|
258
|
+
{ org: "acme", reason: "access data is incomplete" },
|
|
259
|
+
]);
|
|
260
|
+
});
|
|
261
|
+
});
|
|
@@ -126,3 +126,45 @@ export const envWith = (env?: Record<string, string>) => ({
|
|
|
126
126
|
getConfigBundle: async (agentId: string) =>
|
|
127
127
|
env ? { env, agentId, allowedTools: [] } : null,
|
|
128
128
|
});
|
|
129
|
+
|
|
130
|
+
/** A lookup-App snapshot row as the crawler files it, keyed by its SnapshotKey accountId. */
|
|
131
|
+
export interface FakeLookupSnapshot {
|
|
132
|
+
accountId: string;
|
|
133
|
+
appRef: string;
|
|
134
|
+
org: string;
|
|
135
|
+
completedAt: Date;
|
|
136
|
+
repos: { fullName: string }[];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Serves `appKind: "lookup"` reads from `rows` honouring the `accountId.in`
|
|
141
|
+
* and `appRef` filters, so a wrong account key returns nothing. Other reads
|
|
142
|
+
* fall through to the fake's own snapshot rows.
|
|
143
|
+
*/
|
|
144
|
+
export function withLookupSnapshots(
|
|
145
|
+
prisma: PrismaClient,
|
|
146
|
+
rows: FakeLookupSnapshot[],
|
|
147
|
+
) {
|
|
148
|
+
const snapshots = prisma.gitHubRepoSnapshot as unknown as {
|
|
149
|
+
findMany: (args: unknown) => Promise<unknown[]>;
|
|
150
|
+
};
|
|
151
|
+
const base = snapshots.findMany;
|
|
152
|
+
snapshots.findMany = async (args: unknown) => {
|
|
153
|
+
const where = (
|
|
154
|
+
args as {
|
|
155
|
+
where: {
|
|
156
|
+
accountId?: { in: string[] };
|
|
157
|
+
appKind?: string;
|
|
158
|
+
appRef?: string;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
).where;
|
|
162
|
+
if (where.appKind !== "lookup") return base(args);
|
|
163
|
+
await base(args);
|
|
164
|
+
return rows.filter(
|
|
165
|
+
(r) =>
|
|
166
|
+
where.accountId?.in.includes(r.accountId) && r.appRef === where.appRef,
|
|
167
|
+
);
|
|
168
|
+
};
|
|
169
|
+
return prisma;
|
|
170
|
+
}
|
|
@@ -4,11 +4,13 @@ import {
|
|
|
4
4
|
envWith,
|
|
5
5
|
fakePrisma,
|
|
6
6
|
freshCache,
|
|
7
|
+
withLookupSnapshots,
|
|
7
8
|
} from "./github-installation.fixtures.ts";
|
|
8
9
|
import {
|
|
9
10
|
createGithubInstallationRepos,
|
|
10
11
|
createGithubSync,
|
|
11
12
|
} from "./github-installation-wiring.ts";
|
|
13
|
+
import type { GitHubEnterpriseAppMetadata } from "./github-enterprise-apps.ts";
|
|
12
14
|
import type { InstallationReposPort } from "./installation-repos-service.ts";
|
|
13
15
|
|
|
14
16
|
// Sync preview over the real cache service (fake prisma): complete, partial, stale.
|
|
@@ -132,3 +134,57 @@ describe("installation list access detail", () => {
|
|
|
132
134
|
expect(repos[1]?.userCanPush).toBeUndefined();
|
|
133
135
|
});
|
|
134
136
|
});
|
|
137
|
+
|
|
138
|
+
// A null-account agent: the lookup App's crawl is filed under the deployment-wide key.
|
|
139
|
+
describe("sync preview for a null-account agent over the real lookup read", () => {
|
|
140
|
+
it("is not skipped and proposes the expected adds from a complete, fresh cache", async () => {
|
|
141
|
+
const now = new Date();
|
|
142
|
+
const pushable = ["acme/a", "acme/b"];
|
|
143
|
+
const cache = freshCache("acme", REPOS, pushable, now);
|
|
144
|
+
const { prisma, state } = fakePrisma(REPOS, cache);
|
|
145
|
+
withLookupSnapshots(prisma, [
|
|
146
|
+
{
|
|
147
|
+
accountId: "deployment",
|
|
148
|
+
appRef: "77",
|
|
149
|
+
org: "acme",
|
|
150
|
+
completedAt: new Date(now.getTime() - 1000),
|
|
151
|
+
repos: REPOS.map((fullName) => ({ fullName })),
|
|
152
|
+
},
|
|
153
|
+
]);
|
|
154
|
+
const svc = createGithubSync({
|
|
155
|
+
prisma,
|
|
156
|
+
appService: {
|
|
157
|
+
get: async () =>
|
|
158
|
+
({
|
|
159
|
+
accountId: null,
|
|
160
|
+
appId: "77",
|
|
161
|
+
updatedAt: now,
|
|
162
|
+
}) as unknown as GitHubEnterpriseAppMetadata,
|
|
163
|
+
getPrivateKey: async () => "test-key",
|
|
164
|
+
},
|
|
165
|
+
access: accessFor([]), // the live resolver must not be consulted
|
|
166
|
+
agentEnv: envWith({ GH_APP_ID: "42" }),
|
|
167
|
+
// The agent App has only acme/a installed; acme/b is pushable but not added yet.
|
|
168
|
+
installationRepos: {
|
|
169
|
+
listRepos: async () => ({ acme: ["acme/a"] }),
|
|
170
|
+
listInstalled: async () => ({
|
|
171
|
+
status: "found",
|
|
172
|
+
orgs: [{ org: "acme", repos: ["acme/a"] }],
|
|
173
|
+
}),
|
|
174
|
+
addRepos: async () => {},
|
|
175
|
+
removeRepos: async () => {},
|
|
176
|
+
},
|
|
177
|
+
now: () => now,
|
|
178
|
+
});
|
|
179
|
+
const r = await svc.preview("a1");
|
|
180
|
+
if (r.status !== "previewed") throw new Error(r.status);
|
|
181
|
+
expect(r.plan.skippedOrgs).toEqual([]);
|
|
182
|
+
expect(r.plan.appAdds).toEqual(["acme/b"]);
|
|
183
|
+
const lookupQueries = state.snapshotQueries.filter(
|
|
184
|
+
(q) => (q as { where: { appKind?: string } }).where.appKind === "lookup",
|
|
185
|
+
);
|
|
186
|
+
expect(lookupQueries).toMatchObject([
|
|
187
|
+
{ where: { accountId: { in: ["deployment"] } } },
|
|
188
|
+
]);
|
|
189
|
+
});
|
|
190
|
+
});
|