postgresai 0.16.0-dev.1 → 0.16.0-dev.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/bin/postgres-ai.ts +728 -6
- package/dist/bin/postgres-ai.js +2496 -255
- package/dist/sql/06.helpers.sql +0 -122
- package/dist/sql/sql/06.helpers.sql +0 -122
- package/lib/dblab.ts +457 -0
- package/lib/init.ts +0 -8
- package/lib/joe.ts +730 -0
- package/lib/mcp-server.ts +597 -0
- package/lib/supabase.ts +0 -18
- package/package.json +1 -1
- package/sql/06.helpers.sql +0 -122
- package/test/dblab.cli.test.ts +339 -0
- package/test/dblab.test.ts +408 -0
- package/test/init.integration.test.ts +9 -79
- package/test/joe.cli.test.ts +298 -0
- package/test/joe.test.ts +726 -0
- package/test/monitoring.test.ts +54 -3
package/test/monitoring.test.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
import {
|
|
20
20
|
registerMonitoringInstance,
|
|
21
21
|
resolveAdoptedProject,
|
|
22
|
+
planMonitoringRegistration,
|
|
22
23
|
} from "../bin/postgres-ai";
|
|
23
24
|
|
|
24
25
|
/**
|
|
@@ -241,12 +242,13 @@ describe("registerMonitoringInstance", () => {
|
|
|
241
242
|
});
|
|
242
243
|
|
|
243
244
|
// Issue platform-all#311: console-provisioned installs pass instance_id so
|
|
244
|
-
// the platform adopts the provisioned instance
|
|
245
|
-
//
|
|
245
|
+
// the platform adopts the provisioned instance and returns its real project
|
|
246
|
+
// — the CLI sends NO project_name on the adopt path (the hardcoded
|
|
247
|
+
// "postgres-ai-monitoring" default was removed).
|
|
246
248
|
test("includes instance_id in body when adopting a provisioned instance", async () => {
|
|
247
249
|
const instanceId = "019eb300-3f2a-7a75-b54d-4f10572b25b8";
|
|
248
250
|
|
|
249
|
-
await registerMonitoringInstance("key",
|
|
251
|
+
await registerMonitoringInstance("key", undefined, opts({ instanceId }));
|
|
250
252
|
|
|
251
253
|
const body = JSON.parse(fetchCalls[0].options.body as string);
|
|
252
254
|
expect(body.instance_id).toBe(instanceId);
|
|
@@ -255,6 +257,22 @@ describe("registerMonitoringInstance", () => {
|
|
|
255
257
|
expect(headers["instance-id"]).toBeUndefined();
|
|
256
258
|
});
|
|
257
259
|
|
|
260
|
+
test("omits project_name from the body when undefined (adopt path)", async () => {
|
|
261
|
+
await registerMonitoringInstance("key", undefined, opts({ instanceId: "i" }));
|
|
262
|
+
|
|
263
|
+
const body = JSON.parse(fetchCalls[0].options.body as string);
|
|
264
|
+
// The adopt path sends no name; the platform returns the real project.
|
|
265
|
+
expect("project_name" in body).toBe(false);
|
|
266
|
+
expect(body.api_token).toBe("key");
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test("omits project_name from the body when empty/whitespace", async () => {
|
|
270
|
+
await registerMonitoringInstance("key", " ", opts({ instanceId: "i" }));
|
|
271
|
+
|
|
272
|
+
const body = JSON.parse(fetchCalls[0].options.body as string);
|
|
273
|
+
expect("project_name" in body).toBe(false);
|
|
274
|
+
});
|
|
275
|
+
|
|
258
276
|
test("omits instance_id from the body for legacy self-registration", async () => {
|
|
259
277
|
await registerMonitoringInstance("key", "my-project", opts());
|
|
260
278
|
|
|
@@ -262,6 +280,8 @@ describe("registerMonitoringInstance", () => {
|
|
|
262
280
|
// PostgREST matches the 3-arg function via its default — the key must be
|
|
263
281
|
// ABSENT (not null) so legacy CLIs and the new one hit the same overload.
|
|
264
282
|
expect("instance_id" in body).toBe(false);
|
|
283
|
+
// A real project name still rides in the body for legacy registration.
|
|
284
|
+
expect(body.project_name).toBe("my-project");
|
|
265
285
|
});
|
|
266
286
|
|
|
267
287
|
test("a 200 with {project_id, project_name} returns a populated result", async () => {
|
|
@@ -323,6 +343,37 @@ describe("registerMonitoringInstance", () => {
|
|
|
323
343
|
});
|
|
324
344
|
});
|
|
325
345
|
|
|
346
|
+
describe("planMonitoringRegistration — mon local-install registration decision", () => {
|
|
347
|
+
test("instance id present → adopt, no project name required", () => {
|
|
348
|
+
const plan = planMonitoringRegistration({ instanceId: "i-123" });
|
|
349
|
+
expect(plan.kind).toBe("adopt");
|
|
350
|
+
expect(plan.projectName).toBeUndefined();
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
test("instance id present + project → adopt, carries the trimmed name", () => {
|
|
354
|
+
const plan = planMonitoringRegistration({ instanceId: "i-123", project: " prod-db " });
|
|
355
|
+
expect(plan.kind).toBe("adopt");
|
|
356
|
+
expect(plan.projectName).toBe("prod-db");
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
test("no instance id + no project → error-missing-project (exit 1 path)", () => {
|
|
360
|
+
const plan = planMonitoringRegistration({});
|
|
361
|
+
expect(plan.kind).toBe("error-missing-project");
|
|
362
|
+
expect(plan.projectName).toBeUndefined();
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
test("no instance id + empty/whitespace project → error-missing-project", () => {
|
|
366
|
+
expect(planMonitoringRegistration({ project: "" }).kind).toBe("error-missing-project");
|
|
367
|
+
expect(planMonitoringRegistration({ project: " " }).kind).toBe("error-missing-project");
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
test("no instance id + real project → legacy self-register with the trimmed name", () => {
|
|
371
|
+
const plan = planMonitoringRegistration({ project: " my-project " });
|
|
372
|
+
expect(plan.kind).toBe("self-register");
|
|
373
|
+
expect(plan.projectName).toBe("my-project");
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
|
|
326
377
|
describe("resolveAdoptedProject — what gets persisted to .pgwatch-config", () => {
|
|
327
378
|
test("prefers the numeric project_id over the name (survives renames)", () => {
|
|
328
379
|
expect(resolveAdoptedProject({ projectId: 42, projectName: "prod-db" })).toBe("42");
|