postgresai 0.14.0-dev.9 → 0.14.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.
- package/README.md +161 -61
- package/bin/postgres-ai.ts +2821 -461
- package/bun.lock +258 -0
- package/bunfig.toml +20 -0
- package/dist/bin/postgres-ai.js +31667 -1575
- package/dist/sql/01.role.sql +16 -0
- package/dist/sql/02.extensions.sql +8 -0
- package/dist/sql/03.permissions.sql +77 -0
- package/dist/sql/04.optional_rds.sql +6 -0
- package/dist/sql/05.optional_self_managed.sql +8 -0
- package/dist/sql/06.helpers.sql +439 -0
- package/dist/sql/sql/01.role.sql +16 -0
- package/dist/sql/sql/02.extensions.sql +8 -0
- package/dist/sql/sql/03.permissions.sql +77 -0
- package/dist/sql/sql/04.optional_rds.sql +6 -0
- package/dist/sql/sql/05.optional_self_managed.sql +8 -0
- package/dist/sql/sql/06.helpers.sql +439 -0
- package/dist/sql/sql/uninit/01.helpers.sql +5 -0
- package/dist/sql/sql/uninit/02.permissions.sql +30 -0
- package/dist/sql/sql/uninit/03.role.sql +27 -0
- package/dist/sql/uninit/01.helpers.sql +5 -0
- package/dist/sql/uninit/02.permissions.sql +30 -0
- package/dist/sql/uninit/03.role.sql +27 -0
- package/lib/auth-server.ts +124 -106
- package/lib/checkup-api.ts +432 -0
- package/lib/checkup-dictionary.ts +114 -0
- package/lib/checkup-summary.ts +283 -0
- package/lib/checkup.ts +1512 -0
- package/lib/config.ts +6 -3
- package/lib/init.ts +669 -187
- package/lib/issues.ts +848 -193
- package/lib/mcp-server.ts +392 -92
- package/lib/metrics-loader.ts +127 -0
- package/lib/supabase.ts +837 -0
- package/lib/util.ts +61 -0
- package/package.json +24 -11
- package/packages/postgres-ai/README.md +26 -0
- package/packages/postgres-ai/bin/postgres-ai.js +27 -0
- package/packages/postgres-ai/package.json +27 -0
- package/scripts/embed-checkup-dictionary.ts +106 -0
- package/scripts/embed-metrics.ts +154 -0
- package/scripts/generate-release-notes.ts +433 -0
- package/sql/01.role.sql +16 -0
- package/sql/02.extensions.sql +8 -0
- package/sql/03.permissions.sql +77 -0
- package/sql/04.optional_rds.sql +6 -0
- package/sql/05.optional_self_managed.sql +8 -0
- package/sql/06.helpers.sql +439 -0
- package/sql/uninit/01.helpers.sql +5 -0
- package/sql/uninit/02.permissions.sql +30 -0
- package/sql/uninit/03.role.sql +27 -0
- package/test/auth.test.ts +258 -0
- package/test/checkup.integration.test.ts +348 -0
- package/test/checkup.test.ts +1797 -0
- package/test/config-consistency.test.ts +36 -0
- package/test/init.integration.test.ts +509 -0
- package/test/init.test.ts +1253 -0
- package/test/issues.cli.test.ts +538 -0
- package/test/issues.test.ts +456 -0
- package/test/mcp-server.test.ts +1527 -0
- package/test/schema-validation.test.ts +81 -0
- package/test/supabase.test.ts +709 -0
- package/test/test-utils.ts +128 -0
- package/tsconfig.json +12 -20
- package/dist/bin/postgres-ai.d.ts +0 -3
- package/dist/bin/postgres-ai.d.ts.map +0 -1
- package/dist/bin/postgres-ai.js.map +0 -1
- package/dist/lib/auth-server.d.ts +0 -31
- package/dist/lib/auth-server.d.ts.map +0 -1
- package/dist/lib/auth-server.js +0 -263
- package/dist/lib/auth-server.js.map +0 -1
- package/dist/lib/config.d.ts +0 -45
- package/dist/lib/config.d.ts.map +0 -1
- package/dist/lib/config.js +0 -181
- package/dist/lib/config.js.map +0 -1
- package/dist/lib/init.d.ts +0 -64
- package/dist/lib/init.d.ts.map +0 -1
- package/dist/lib/init.js +0 -403
- package/dist/lib/init.js.map +0 -1
- package/dist/lib/issues.d.ts +0 -75
- package/dist/lib/issues.d.ts.map +0 -1
- package/dist/lib/issues.js +0 -336
- package/dist/lib/issues.js.map +0 -1
- package/dist/lib/mcp-server.d.ts +0 -9
- package/dist/lib/mcp-server.d.ts.map +0 -1
- package/dist/lib/mcp-server.js +0 -168
- package/dist/lib/mcp-server.js.map +0 -1
- package/dist/lib/pkce.d.ts +0 -32
- package/dist/lib/pkce.d.ts.map +0 -1
- package/dist/lib/pkce.js +0 -101
- package/dist/lib/pkce.js.map +0 -1
- package/dist/lib/util.d.ts +0 -27
- package/dist/lib/util.d.ts.map +0 -1
- package/dist/lib/util.js +0 -46
- package/dist/lib/util.js.map +0 -1
- package/dist/package.json +0 -46
- package/test/init.integration.test.cjs +0 -269
- package/test/init.test.cjs +0 -90
|
@@ -0,0 +1,1797 @@
|
|
|
1
|
+
import { describe, test, expect } from "bun:test";
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
import type { Client } from "pg";
|
|
4
|
+
|
|
5
|
+
// Import from source directly since we're using Bun
|
|
6
|
+
import * as checkup from "../lib/checkup";
|
|
7
|
+
import * as api from "../lib/checkup-api";
|
|
8
|
+
import { createMockClient } from "./test-utils";
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function runCli(args: string[], env: Record<string, string> = {}) {
|
|
12
|
+
const cliPath = resolve(import.meta.dir, "..", "bin", "postgres-ai.ts");
|
|
13
|
+
const bunBin = typeof process.execPath === "string" && process.execPath.length > 0 ? process.execPath : "bun";
|
|
14
|
+
const result = Bun.spawnSync([bunBin, cliPath, ...args], {
|
|
15
|
+
env: { ...process.env, ...env },
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
status: result.exitCode,
|
|
19
|
+
stdout: new TextDecoder().decode(result.stdout),
|
|
20
|
+
stderr: new TextDecoder().decode(result.stderr),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Unit tests for parseVersionNum
|
|
25
|
+
describe("parseVersionNum", () => {
|
|
26
|
+
test("parses PG 16.3 version number", () => {
|
|
27
|
+
const result = checkup.parseVersionNum("160003");
|
|
28
|
+
expect(result.major).toBe("16");
|
|
29
|
+
expect(result.minor).toBe("3");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("parses PG 15.7 version number", () => {
|
|
33
|
+
const result = checkup.parseVersionNum("150007");
|
|
34
|
+
expect(result.major).toBe("15");
|
|
35
|
+
expect(result.minor).toBe("7");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("parses PG 14.12 version number", () => {
|
|
39
|
+
const result = checkup.parseVersionNum("140012");
|
|
40
|
+
expect(result.major).toBe("14");
|
|
41
|
+
expect(result.minor).toBe("12");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("handles empty string", () => {
|
|
45
|
+
const result = checkup.parseVersionNum("");
|
|
46
|
+
expect(result.major).toBe("");
|
|
47
|
+
expect(result.minor).toBe("");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("handles null/undefined", () => {
|
|
51
|
+
const result = checkup.parseVersionNum(null as any);
|
|
52
|
+
expect(result.major).toBe("");
|
|
53
|
+
expect(result.minor).toBe("");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("handles short string", () => {
|
|
57
|
+
const result = checkup.parseVersionNum("123");
|
|
58
|
+
expect(result.major).toBe("");
|
|
59
|
+
expect(result.minor).toBe("");
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Unit tests for createBaseReport
|
|
64
|
+
describe("createBaseReport", () => {
|
|
65
|
+
test("creates correct structure", () => {
|
|
66
|
+
const report = checkup.createBaseReport("A002", "Postgres major version", "test-node");
|
|
67
|
+
|
|
68
|
+
expect(report.checkId).toBe("A002");
|
|
69
|
+
expect(report.checkTitle).toBe("Postgres major version");
|
|
70
|
+
expect(typeof report.version).toBe("string");
|
|
71
|
+
expect(report.version!.length).toBeGreaterThan(0);
|
|
72
|
+
expect(typeof report.build_ts).toBe("string");
|
|
73
|
+
expect(report.nodes.primary).toBe("test-node");
|
|
74
|
+
expect(report.nodes.standbys).toEqual([]);
|
|
75
|
+
expect(report.results).toEqual({});
|
|
76
|
+
expect(typeof report.timestamptz).toBe("string");
|
|
77
|
+
// Verify timestamp is ISO format
|
|
78
|
+
expect(new Date(report.timestamptz).toISOString()).toBe(report.timestamptz);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("uses provided node name", () => {
|
|
82
|
+
const report = checkup.createBaseReport("A003", "Postgres settings", "my-custom-node");
|
|
83
|
+
expect(report.nodes.primary).toBe("my-custom-node");
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Tests for CHECK_INFO
|
|
88
|
+
describe("CHECK_INFO and REPORT_GENERATORS", () => {
|
|
89
|
+
// Express-mode checks that have generators
|
|
90
|
+
const expressCheckIds = ["A002", "A003", "A004", "A007", "A013", "D001", "D004", "F001", "G001", "G003", "H001", "H002", "H004"];
|
|
91
|
+
|
|
92
|
+
test("CHECK_INFO contains all express-mode checks", () => {
|
|
93
|
+
for (const checkId of expressCheckIds) {
|
|
94
|
+
expect(checkup.CHECK_INFO[checkId]).toBeDefined();
|
|
95
|
+
expect(typeof checkup.CHECK_INFO[checkId]).toBe("string");
|
|
96
|
+
expect(checkup.CHECK_INFO[checkId].length).toBeGreaterThan(0);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("CHECK_INFO titles are loaded from embedded dictionary", () => {
|
|
101
|
+
// Verify a few known titles match the API dictionary
|
|
102
|
+
// These are canonical titles from postgres.ai/api/general/checkup_dictionary
|
|
103
|
+
expect(checkup.CHECK_INFO["A002"]).toBe("Postgres major version");
|
|
104
|
+
expect(checkup.CHECK_INFO["H001"]).toBe("Invalid indexes");
|
|
105
|
+
expect(checkup.CHECK_INFO["H002"]).toBe("Unused indexes");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("REPORT_GENERATORS has function for each check", () => {
|
|
109
|
+
for (const checkId of expressCheckIds) {
|
|
110
|
+
expect(typeof checkup.REPORT_GENERATORS[checkId]).toBe("function");
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test("REPORT_GENERATORS and CHECK_INFO have same keys", () => {
|
|
115
|
+
const generatorKeys = Object.keys(checkup.REPORT_GENERATORS).sort();
|
|
116
|
+
const infoKeys = Object.keys(checkup.CHECK_INFO).sort();
|
|
117
|
+
expect(generatorKeys).toEqual(infoKeys);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Tests for formatBytes
|
|
122
|
+
describe("formatBytes", () => {
|
|
123
|
+
test("formats zero bytes", () => {
|
|
124
|
+
expect(checkup.formatBytes(0)).toBe("0 B");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("formats bytes", () => {
|
|
128
|
+
expect(checkup.formatBytes(500)).toBe("500.00 B");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("formats kibibytes", () => {
|
|
132
|
+
expect(checkup.formatBytes(1024)).toBe("1.00 KiB");
|
|
133
|
+
expect(checkup.formatBytes(1536)).toBe("1.50 KiB");
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("formats mebibytes", () => {
|
|
137
|
+
expect(checkup.formatBytes(1048576)).toBe("1.00 MiB");
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test("formats gibibytes", () => {
|
|
141
|
+
expect(checkup.formatBytes(1073741824)).toBe("1.00 GiB");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("handles negative bytes", () => {
|
|
145
|
+
expect(checkup.formatBytes(-1024)).toBe("-1.00 KiB");
|
|
146
|
+
expect(checkup.formatBytes(-1048576)).toBe("-1.00 MiB");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("handles edge cases", () => {
|
|
150
|
+
expect(checkup.formatBytes(NaN)).toBe("NaN B");
|
|
151
|
+
expect(checkup.formatBytes(Infinity)).toBe("Infinity B");
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// Mock client tests for report generators
|
|
156
|
+
describe("Report generators with mock client", () => {
|
|
157
|
+
test("getPostgresVersion extracts version info", async () => {
|
|
158
|
+
const mockClient = createMockClient({
|
|
159
|
+
versionRows: [
|
|
160
|
+
{ name: "server_version", setting: "16.3" },
|
|
161
|
+
{ name: "server_version_num", setting: "160003" },
|
|
162
|
+
],
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const version = await checkup.getPostgresVersion(mockClient as any);
|
|
166
|
+
expect(version.version).toBe("16.3");
|
|
167
|
+
expect(version.server_version_num).toBe("160003");
|
|
168
|
+
expect(version.server_major_ver).toBe("16");
|
|
169
|
+
expect(version.server_minor_ver).toBe("3");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("getSettings transforms rows to keyed object", async () => {
|
|
173
|
+
const mockClient = createMockClient({
|
|
174
|
+
settingsRows: [
|
|
175
|
+
{
|
|
176
|
+
tag_setting_name: "shared_buffers",
|
|
177
|
+
tag_setting_value: "16384",
|
|
178
|
+
tag_unit: "8kB",
|
|
179
|
+
tag_category: "Resource Usage / Memory",
|
|
180
|
+
tag_vartype: "integer",
|
|
181
|
+
is_default: 1,
|
|
182
|
+
setting_normalized: "134217728", // 16384 * 8192
|
|
183
|
+
unit_normalized: "bytes",
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
tag_setting_name: "work_mem",
|
|
187
|
+
tag_setting_value: "4096",
|
|
188
|
+
tag_unit: "kB",
|
|
189
|
+
tag_category: "Resource Usage / Memory",
|
|
190
|
+
tag_vartype: "integer",
|
|
191
|
+
is_default: 1,
|
|
192
|
+
setting_normalized: "4194304", // 4096 * 1024
|
|
193
|
+
unit_normalized: "bytes",
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const settings = await checkup.getSettings(mockClient as any);
|
|
199
|
+
expect("shared_buffers" in settings).toBe(true);
|
|
200
|
+
expect("work_mem" in settings).toBe(true);
|
|
201
|
+
expect(settings.shared_buffers.setting).toBe("16384");
|
|
202
|
+
expect(settings.shared_buffers.unit).toBe("8kB");
|
|
203
|
+
// pretty_value is now computed from setting_normalized
|
|
204
|
+
expect(settings.shared_buffers.pretty_value).toBe("128.00 MiB");
|
|
205
|
+
expect(settings.work_mem.pretty_value).toBe("4.00 MiB");
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test("generateA002 creates report with version data", async () => {
|
|
209
|
+
const mockClient = createMockClient({
|
|
210
|
+
versionRows: [
|
|
211
|
+
{ name: "server_version", setting: "16.3" },
|
|
212
|
+
{ name: "server_version_num", setting: "160003" },
|
|
213
|
+
],
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
const report = await checkup.generateA002(mockClient as any, "test-node");
|
|
217
|
+
expect(report.checkId).toBe("A002");
|
|
218
|
+
expect(report.checkTitle).toBe("Postgres major version");
|
|
219
|
+
expect(report.nodes.primary).toBe("test-node");
|
|
220
|
+
expect("test-node" in report.results).toBe(true);
|
|
221
|
+
expect("version" in report.results["test-node"].data).toBe(true);
|
|
222
|
+
expect(report.results["test-node"].data.version.version).toBe("16.3");
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test("generateA003 creates report with settings and version", async () => {
|
|
226
|
+
const mockClient = createMockClient({
|
|
227
|
+
versionRows: [
|
|
228
|
+
{ name: "server_version", setting: "16.3" },
|
|
229
|
+
{ name: "server_version_num", setting: "160003" },
|
|
230
|
+
],
|
|
231
|
+
settingsRows: [
|
|
232
|
+
{
|
|
233
|
+
tag_setting_name: "shared_buffers",
|
|
234
|
+
tag_setting_value: "16384",
|
|
235
|
+
tag_unit: "8kB",
|
|
236
|
+
tag_category: "Resource Usage / Memory",
|
|
237
|
+
tag_vartype: "integer",
|
|
238
|
+
is_default: 1,
|
|
239
|
+
setting_normalized: "134217728",
|
|
240
|
+
unit_normalized: "bytes",
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
const report = await checkup.generateA003(mockClient as any, "test-node");
|
|
246
|
+
expect(report.checkId).toBe("A003");
|
|
247
|
+
expect(report.checkTitle).toBe("Postgres settings");
|
|
248
|
+
expect("test-node" in report.results).toBe(true);
|
|
249
|
+
expect("shared_buffers" in report.results["test-node"].data).toBe(true);
|
|
250
|
+
expect(report.results["test-node"].postgres_version).toBeTruthy();
|
|
251
|
+
expect(report.results["test-node"].postgres_version!.version).toBe("16.3");
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test("generateA013 creates report with minor version data", async () => {
|
|
255
|
+
const mockClient = createMockClient({
|
|
256
|
+
versionRows: [
|
|
257
|
+
{ name: "server_version", setting: "16.3" },
|
|
258
|
+
{ name: "server_version_num", setting: "160003" },
|
|
259
|
+
],
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
const report = await checkup.generateA013(mockClient as any, "test-node");
|
|
263
|
+
expect(report.checkId).toBe("A013");
|
|
264
|
+
expect(report.checkTitle).toBe("Postgres minor version");
|
|
265
|
+
expect(report.nodes.primary).toBe("test-node");
|
|
266
|
+
expect("test-node" in report.results).toBe(true);
|
|
267
|
+
expect("version" in report.results["test-node"].data).toBe(true);
|
|
268
|
+
expect(report.results["test-node"].data.version.server_minor_ver).toBe("3");
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
test("generateAllReports returns reports for all checks", async () => {
|
|
272
|
+
const mockClient = createMockClient({
|
|
273
|
+
versionRows: [
|
|
274
|
+
{ name: "server_version", setting: "16.3" },
|
|
275
|
+
{ name: "server_version_num", setting: "160003" },
|
|
276
|
+
],
|
|
277
|
+
settingsRows: [
|
|
278
|
+
{
|
|
279
|
+
tag_setting_name: "shared_buffers",
|
|
280
|
+
tag_setting_value: "16384",
|
|
281
|
+
tag_unit: "8kB",
|
|
282
|
+
tag_category: "Resource Usage / Memory",
|
|
283
|
+
tag_vartype: "integer",
|
|
284
|
+
is_default: 0, // Non-default for A007
|
|
285
|
+
setting_normalized: "134217728",
|
|
286
|
+
unit_normalized: "bytes",
|
|
287
|
+
},
|
|
288
|
+
],
|
|
289
|
+
databaseSizesRows: [{ datname: "postgres", size_bytes: "1073741824" }],
|
|
290
|
+
dbStatsRows: [{
|
|
291
|
+
numbackends: 5,
|
|
292
|
+
xact_commit: 100,
|
|
293
|
+
xact_rollback: 1,
|
|
294
|
+
blks_read: 1000,
|
|
295
|
+
blks_hit: 9000,
|
|
296
|
+
tup_returned: 500,
|
|
297
|
+
tup_fetched: 400,
|
|
298
|
+
tup_inserted: 50,
|
|
299
|
+
tup_updated: 30,
|
|
300
|
+
tup_deleted: 10,
|
|
301
|
+
deadlocks: 0,
|
|
302
|
+
temp_files: 0,
|
|
303
|
+
temp_bytes: 0,
|
|
304
|
+
postmaster_uptime_s: 864000
|
|
305
|
+
}],
|
|
306
|
+
connectionStatesRows: [{ state: "active", count: 2 }, { state: "idle", count: 3 }],
|
|
307
|
+
uptimeRows: [{ start_time: new Date("2024-01-01T00:00:00Z"), uptime: "10 days" }],
|
|
308
|
+
invalidIndexesRows: [],
|
|
309
|
+
unusedIndexesRows: [],
|
|
310
|
+
redundantIndexesRows: [],
|
|
311
|
+
sensitiveColumnsRows: [],
|
|
312
|
+
}
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
const reports = await checkup.generateAllReports(mockClient as any, "test-node");
|
|
316
|
+
expect("A002" in reports).toBe(true);
|
|
317
|
+
expect("A003" in reports).toBe(true);
|
|
318
|
+
expect("A004" in reports).toBe(true);
|
|
319
|
+
expect("A007" in reports).toBe(true);
|
|
320
|
+
expect("A013" in reports).toBe(true);
|
|
321
|
+
expect("H001" in reports).toBe(true);
|
|
322
|
+
expect("H002" in reports).toBe(true);
|
|
323
|
+
expect("H004" in reports).toBe(true);
|
|
324
|
+
// S001 is only available in Python reporter, not in CLI express mode
|
|
325
|
+
expect(reports.A002.checkId).toBe("A002");
|
|
326
|
+
expect(reports.A003.checkId).toBe("A003");
|
|
327
|
+
expect(reports.A004.checkId).toBe("A004");
|
|
328
|
+
expect(reports.A007.checkId).toBe("A007");
|
|
329
|
+
expect(reports.A013.checkId).toBe("A013");
|
|
330
|
+
expect(reports.H001.checkId).toBe("H001");
|
|
331
|
+
expect(reports.H002.checkId).toBe("H002");
|
|
332
|
+
expect(reports.H004.checkId).toBe("H004");
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
// Tests for A007 (Altered settings)
|
|
337
|
+
describe("A007 - Altered settings", () => {
|
|
338
|
+
test("getAlteredSettings returns non-default settings", async () => {
|
|
339
|
+
const mockClient = createMockClient({
|
|
340
|
+
settingsRows: [
|
|
341
|
+
{ tag_setting_name: "shared_buffers", tag_setting_value: "256MB", tag_unit: "", tag_category: "Resource Usage / Memory", tag_vartype: "string", is_default: 0, setting_normalized: null, unit_normalized: null },
|
|
342
|
+
{ tag_setting_name: "work_mem", tag_setting_value: "64MB", tag_unit: "", tag_category: "Resource Usage / Memory", tag_vartype: "string", is_default: 0, setting_normalized: null, unit_normalized: null },
|
|
343
|
+
{ tag_setting_name: "default_setting", tag_setting_value: "on", tag_unit: "", tag_category: "Other", tag_vartype: "bool", is_default: 1, setting_normalized: null, unit_normalized: null },
|
|
344
|
+
],
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
const settings = await checkup.getAlteredSettings(mockClient as any);
|
|
348
|
+
expect("shared_buffers" in settings).toBe(true);
|
|
349
|
+
expect("work_mem" in settings).toBe(true);
|
|
350
|
+
expect("default_setting" in settings).toBe(false); // Should be filtered out
|
|
351
|
+
expect(settings.shared_buffers.value).toBe("256MB");
|
|
352
|
+
expect(settings.work_mem.value).toBe("64MB");
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
test("generateA007 creates report with altered settings", async () => {
|
|
356
|
+
const mockClient = createMockClient({
|
|
357
|
+
versionRows: [
|
|
358
|
+
{ name: "server_version", setting: "16.3" },
|
|
359
|
+
{ name: "server_version_num", setting: "160003" },
|
|
360
|
+
],
|
|
361
|
+
settingsRows: [
|
|
362
|
+
{ tag_setting_name: "max_connections", tag_setting_value: "200", tag_unit: "", tag_category: "Connections and Authentication", tag_vartype: "integer", is_default: 0, setting_normalized: null, unit_normalized: null },
|
|
363
|
+
],
|
|
364
|
+
}
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
const report = await checkup.generateA007(mockClient as any, "test-node");
|
|
368
|
+
expect(report.checkId).toBe("A007");
|
|
369
|
+
expect(report.checkTitle).toBe("Altered settings");
|
|
370
|
+
expect(report.nodes.primary).toBe("test-node");
|
|
371
|
+
expect("test-node" in report.results).toBe(true);
|
|
372
|
+
expect("max_connections" in report.results["test-node"].data).toBe(true);
|
|
373
|
+
expect(report.results["test-node"].data.max_connections.value).toBe("200");
|
|
374
|
+
expect(report.results["test-node"].postgres_version).toBeTruthy();
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
// Tests for A004 (Cluster information)
|
|
379
|
+
describe("A004 - Cluster information", () => {
|
|
380
|
+
test("getDatabaseSizes returns database sizes", async () => {
|
|
381
|
+
const mockClient = createMockClient({
|
|
382
|
+
databaseSizesRows: [
|
|
383
|
+
{ datname: "postgres", size_bytes: "1073741824" },
|
|
384
|
+
{ datname: "mydb", size_bytes: "536870912" },
|
|
385
|
+
],
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
const sizes = await checkup.getDatabaseSizes(mockClient as any);
|
|
389
|
+
expect("postgres" in sizes).toBe(true);
|
|
390
|
+
expect("mydb" in sizes).toBe(true);
|
|
391
|
+
expect(sizes.postgres).toBe(1073741824);
|
|
392
|
+
expect(sizes.mydb).toBe(536870912);
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
test("getClusterInfo returns cluster metrics", async () => {
|
|
396
|
+
const mockClient = createMockClient({
|
|
397
|
+
dbStatsRows: [{
|
|
398
|
+
numbackends: 10,
|
|
399
|
+
xact_commit: 1000,
|
|
400
|
+
xact_rollback: 5,
|
|
401
|
+
blks_read: 500,
|
|
402
|
+
blks_hit: 9500,
|
|
403
|
+
tup_returned: 5000,
|
|
404
|
+
tup_fetched: 4000,
|
|
405
|
+
tup_inserted: 100,
|
|
406
|
+
tup_updated: 50,
|
|
407
|
+
tup_deleted: 25,
|
|
408
|
+
deadlocks: 0,
|
|
409
|
+
temp_files: 2,
|
|
410
|
+
temp_bytes: 1048576,
|
|
411
|
+
postmaster_uptime_s: 2592000, // 30 days
|
|
412
|
+
}],
|
|
413
|
+
connectionStatesRows: [
|
|
414
|
+
{ state: "active", count: 3 },
|
|
415
|
+
{ state: "idle", count: 7 },
|
|
416
|
+
],
|
|
417
|
+
uptimeRows: [{
|
|
418
|
+
start_time: new Date("2024-01-01T00:00:00Z"),
|
|
419
|
+
uptime: "30 days",
|
|
420
|
+
}],
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
const info = await checkup.getClusterInfo(mockClient as any);
|
|
424
|
+
expect("total_connections" in info).toBe(true);
|
|
425
|
+
expect("cache_hit_ratio" in info).toBe(true);
|
|
426
|
+
expect("connections_active" in info).toBe(true);
|
|
427
|
+
expect("connections_idle" in info).toBe(true);
|
|
428
|
+
expect("start_time" in info).toBe(true);
|
|
429
|
+
expect(info.total_connections.value).toBe("10");
|
|
430
|
+
expect(info.cache_hit_ratio.value).toBe("95.00");
|
|
431
|
+
expect(info.connections_active.value).toBe("3");
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
test("generateA004 creates report with cluster info and database sizes", async () => {
|
|
435
|
+
const mockClient = createMockClient({
|
|
436
|
+
versionRows: [
|
|
437
|
+
{ name: "server_version", setting: "16.3" },
|
|
438
|
+
{ name: "server_version_num", setting: "160003" },
|
|
439
|
+
],
|
|
440
|
+
databaseSizesRows: [
|
|
441
|
+
{ datname: "postgres", size_bytes: "1073741824" },
|
|
442
|
+
],
|
|
443
|
+
dbStatsRows: [{
|
|
444
|
+
numbackends: 5,
|
|
445
|
+
xact_commit: 100,
|
|
446
|
+
xact_rollback: 1,
|
|
447
|
+
blks_read: 100,
|
|
448
|
+
blks_hit: 900,
|
|
449
|
+
tup_returned: 500,
|
|
450
|
+
tup_fetched: 400,
|
|
451
|
+
tup_inserted: 50,
|
|
452
|
+
tup_updated: 30,
|
|
453
|
+
tup_deleted: 10,
|
|
454
|
+
deadlocks: 0,
|
|
455
|
+
temp_files: 0,
|
|
456
|
+
temp_bytes: 0,
|
|
457
|
+
postmaster_uptime_s: 864000,
|
|
458
|
+
}],
|
|
459
|
+
connectionStatesRows: [{ state: "active", count: 2 }],
|
|
460
|
+
uptimeRows: [{ start_time: new Date("2024-01-01T00:00:00Z"), uptime: "10 days" }],
|
|
461
|
+
}
|
|
462
|
+
);
|
|
463
|
+
|
|
464
|
+
const report = await checkup.generateA004(mockClient as any, "test-node");
|
|
465
|
+
expect(report.checkId).toBe("A004");
|
|
466
|
+
expect(report.checkTitle).toBe("Cluster information");
|
|
467
|
+
expect(report.nodes.primary).toBe("test-node");
|
|
468
|
+
expect("test-node" in report.results).toBe(true);
|
|
469
|
+
|
|
470
|
+
const data = report.results["test-node"].data;
|
|
471
|
+
expect("general_info" in data).toBe(true);
|
|
472
|
+
expect("database_sizes" in data).toBe(true);
|
|
473
|
+
expect("total_connections" in data.general_info).toBe(true);
|
|
474
|
+
expect("postgres" in data.database_sizes).toBe(true);
|
|
475
|
+
expect(data.database_sizes.postgres).toBe(1073741824);
|
|
476
|
+
expect(report.results["test-node"].postgres_version).toBeTruthy();
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
// Tests for H001 (Invalid indexes)
|
|
481
|
+
describe("H001 - Invalid indexes", () => {
|
|
482
|
+
test("getInvalidIndexes returns invalid indexes", async () => {
|
|
483
|
+
const mockClient = createMockClient({
|
|
484
|
+
invalidIndexesRows: [
|
|
485
|
+
{ schema_name: "public", table_name: "users", index_name: "users_email_idx", relation_name: "users", index_size_bytes: "1048576", index_definition: "CREATE INDEX users_email_idx ON public.users USING btree (email)", supports_fk: false },
|
|
486
|
+
],
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
const indexes = await checkup.getInvalidIndexes(mockClient as any);
|
|
490
|
+
expect(indexes.length).toBe(1);
|
|
491
|
+
expect(indexes[0].schema_name).toBe("public");
|
|
492
|
+
expect(indexes[0].table_name).toBe("users");
|
|
493
|
+
expect(indexes[0].index_name).toBe("users_email_idx");
|
|
494
|
+
expect(indexes[0].index_size_bytes).toBe(1048576);
|
|
495
|
+
expect(indexes[0].index_size_pretty).toBeTruthy();
|
|
496
|
+
expect(indexes[0].index_definition).toMatch(/^CREATE INDEX/);
|
|
497
|
+
expect(indexes[0].relation_name).toBe("users");
|
|
498
|
+
expect(indexes[0].supports_fk).toBe(false);
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
test("generateH001 creates report with invalid indexes", async () => {
|
|
502
|
+
const mockClient = createMockClient({
|
|
503
|
+
versionRows: [
|
|
504
|
+
{ name: "server_version", setting: "16.3" },
|
|
505
|
+
{ name: "server_version_num", setting: "160003" },
|
|
506
|
+
],
|
|
507
|
+
invalidIndexesRows: [
|
|
508
|
+
{ schema_name: "public", table_name: "orders", index_name: "orders_status_idx", relation_name: "orders", index_size_bytes: "2097152", index_definition: "CREATE INDEX orders_status_idx ON public.orders USING btree (status)", supports_fk: false },
|
|
509
|
+
],
|
|
510
|
+
}
|
|
511
|
+
);
|
|
512
|
+
|
|
513
|
+
const report = await checkup.generateH001(mockClient as any, "test-node");
|
|
514
|
+
expect(report.checkId).toBe("H001");
|
|
515
|
+
expect(report.checkTitle).toBe("Invalid indexes");
|
|
516
|
+
expect("test-node" in report.results).toBe(true);
|
|
517
|
+
|
|
518
|
+
// Data is now keyed by database name
|
|
519
|
+
const data = report.results["test-node"].data;
|
|
520
|
+
expect("testdb" in data).toBe(true);
|
|
521
|
+
const dbData = data["testdb"] as any;
|
|
522
|
+
expect(dbData.invalid_indexes).toBeTruthy();
|
|
523
|
+
expect(dbData.total_count).toBe(1);
|
|
524
|
+
expect(dbData.total_size_bytes).toBe(2097152);
|
|
525
|
+
expect(dbData.total_size_pretty).toBeTruthy();
|
|
526
|
+
expect(dbData.database_size_bytes).toBeTruthy();
|
|
527
|
+
expect(dbData.database_size_pretty).toBeTruthy();
|
|
528
|
+
expect(report.results["test-node"].postgres_version).toBeTruthy();
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
test("getInvalidIndexes returns decision tree fields including valid_duplicate_definition", async () => {
|
|
532
|
+
const mockClient = createMockClient({
|
|
533
|
+
invalidIndexesRows: [
|
|
534
|
+
{
|
|
535
|
+
schema_name: "public",
|
|
536
|
+
table_name: "users",
|
|
537
|
+
index_name: "users_email_idx_invalid",
|
|
538
|
+
relation_name: "users",
|
|
539
|
+
index_size_bytes: "1048576",
|
|
540
|
+
index_definition: "CREATE INDEX users_email_idx_invalid ON public.users USING btree (email)",
|
|
541
|
+
supports_fk: false,
|
|
542
|
+
is_pk: false,
|
|
543
|
+
is_unique: false,
|
|
544
|
+
constraint_name: null,
|
|
545
|
+
table_row_estimate: "5000",
|
|
546
|
+
has_valid_duplicate: true,
|
|
547
|
+
valid_index_name: "users_email_idx",
|
|
548
|
+
valid_index_definition: "CREATE INDEX users_email_idx ON public.users USING btree (email)",
|
|
549
|
+
},
|
|
550
|
+
],
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
const indexes = await checkup.getInvalidIndexes(mockClient as any);
|
|
554
|
+
expect(indexes.length).toBe(1);
|
|
555
|
+
expect(indexes[0].is_pk).toBe(false);
|
|
556
|
+
expect(indexes[0].is_unique).toBe(false);
|
|
557
|
+
expect(indexes[0].constraint_name).toBeNull();
|
|
558
|
+
expect(indexes[0].table_row_estimate).toBe(5000);
|
|
559
|
+
expect(indexes[0].has_valid_duplicate).toBe(true);
|
|
560
|
+
expect(indexes[0].valid_duplicate_name).toBe("users_email_idx");
|
|
561
|
+
expect(indexes[0].valid_duplicate_definition).toBe("CREATE INDEX users_email_idx ON public.users USING btree (email)");
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
test("getInvalidIndexes handles has_valid_duplicate: false with null values", async () => {
|
|
565
|
+
const mockClient = createMockClient({
|
|
566
|
+
invalidIndexesRows: [
|
|
567
|
+
{
|
|
568
|
+
schema_name: "public",
|
|
569
|
+
table_name: "orders",
|
|
570
|
+
index_name: "orders_status_idx_invalid",
|
|
571
|
+
relation_name: "orders",
|
|
572
|
+
index_size_bytes: "524288",
|
|
573
|
+
index_definition: "CREATE INDEX orders_status_idx_invalid ON public.orders USING btree (status)",
|
|
574
|
+
supports_fk: false,
|
|
575
|
+
is_pk: false,
|
|
576
|
+
is_unique: false,
|
|
577
|
+
constraint_name: null,
|
|
578
|
+
table_row_estimate: "100000",
|
|
579
|
+
has_valid_duplicate: false,
|
|
580
|
+
valid_index_name: null,
|
|
581
|
+
valid_index_definition: null,
|
|
582
|
+
},
|
|
583
|
+
],
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
const indexes = await checkup.getInvalidIndexes(mockClient as Client);
|
|
587
|
+
expect(indexes.length).toBe(1);
|
|
588
|
+
expect(indexes[0].has_valid_duplicate).toBe(false);
|
|
589
|
+
expect(indexes[0].valid_duplicate_name).toBeNull();
|
|
590
|
+
expect(indexes[0].valid_duplicate_definition).toBeNull();
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
test("getInvalidIndexes handles is_pk: true with constraint", async () => {
|
|
594
|
+
const mockClient = createMockClient({
|
|
595
|
+
invalidIndexesRows: [
|
|
596
|
+
{
|
|
597
|
+
schema_name: "public",
|
|
598
|
+
table_name: "accounts",
|
|
599
|
+
index_name: "accounts_pkey_invalid",
|
|
600
|
+
relation_name: "accounts",
|
|
601
|
+
index_size_bytes: "262144",
|
|
602
|
+
index_definition: "CREATE UNIQUE INDEX accounts_pkey_invalid ON public.accounts USING btree (id)",
|
|
603
|
+
supports_fk: true,
|
|
604
|
+
is_pk: true,
|
|
605
|
+
is_unique: true,
|
|
606
|
+
constraint_name: "accounts_pkey",
|
|
607
|
+
table_row_estimate: "500",
|
|
608
|
+
has_valid_duplicate: false,
|
|
609
|
+
valid_index_name: null,
|
|
610
|
+
valid_index_definition: null,
|
|
611
|
+
},
|
|
612
|
+
],
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
const indexes = await checkup.getInvalidIndexes(mockClient as Client);
|
|
616
|
+
expect(indexes.length).toBe(1);
|
|
617
|
+
expect(indexes[0].is_pk).toBe(true);
|
|
618
|
+
expect(indexes[0].is_unique).toBe(true);
|
|
619
|
+
expect(indexes[0].constraint_name).toBe("accounts_pkey");
|
|
620
|
+
expect(indexes[0].supports_fk).toBe(true);
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
test("getInvalidIndexes handles is_unique: true without PK", async () => {
|
|
624
|
+
const mockClient = createMockClient({
|
|
625
|
+
invalidIndexesRows: [
|
|
626
|
+
{
|
|
627
|
+
schema_name: "public",
|
|
628
|
+
table_name: "users",
|
|
629
|
+
index_name: "users_email_unique_invalid",
|
|
630
|
+
relation_name: "users",
|
|
631
|
+
index_size_bytes: "131072",
|
|
632
|
+
index_definition: "CREATE UNIQUE INDEX users_email_unique_invalid ON public.users USING btree (email)",
|
|
633
|
+
supports_fk: false,
|
|
634
|
+
is_pk: false,
|
|
635
|
+
is_unique: true,
|
|
636
|
+
constraint_name: "users_email_unique",
|
|
637
|
+
table_row_estimate: "25000",
|
|
638
|
+
has_valid_duplicate: true,
|
|
639
|
+
valid_index_name: "users_email_unique_idx",
|
|
640
|
+
valid_index_definition: "CREATE UNIQUE INDEX users_email_unique_idx ON public.users USING btree (email)",
|
|
641
|
+
},
|
|
642
|
+
],
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
const indexes = await checkup.getInvalidIndexes(mockClient as Client);
|
|
646
|
+
expect(indexes.length).toBe(1);
|
|
647
|
+
expect(indexes[0].is_pk).toBe(false);
|
|
648
|
+
expect(indexes[0].is_unique).toBe(true);
|
|
649
|
+
expect(indexes[0].constraint_name).toBe("users_email_unique");
|
|
650
|
+
expect(indexes[0].has_valid_duplicate).toBe(true);
|
|
651
|
+
});
|
|
652
|
+
// Top-level structure tests removed - covered by schema-validation.test.ts
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
// Tests for H001 decision tree recommendation logic
|
|
656
|
+
describe("H001 - Decision tree recommendations", () => {
|
|
657
|
+
// Helper to create a minimal InvalidIndex for testing
|
|
658
|
+
const createTestIndex = (overrides: Partial<checkup.InvalidIndex> = {}): checkup.InvalidIndex => ({
|
|
659
|
+
schema_name: "public",
|
|
660
|
+
table_name: "test_table",
|
|
661
|
+
index_name: "test_idx",
|
|
662
|
+
relation_name: "public.test_table",
|
|
663
|
+
index_size_bytes: 1024,
|
|
664
|
+
index_size_pretty: "1 KiB",
|
|
665
|
+
index_definition: "CREATE INDEX test_idx ON public.test_table USING btree (col)",
|
|
666
|
+
supports_fk: false,
|
|
667
|
+
is_pk: false,
|
|
668
|
+
is_unique: false,
|
|
669
|
+
constraint_name: null,
|
|
670
|
+
table_row_estimate: 100000, // Large table by default
|
|
671
|
+
has_valid_duplicate: false,
|
|
672
|
+
valid_duplicate_name: null,
|
|
673
|
+
valid_duplicate_definition: null,
|
|
674
|
+
...overrides,
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
test("returns DROP when has_valid_duplicate is true", () => {
|
|
678
|
+
const index = createTestIndex({ has_valid_duplicate: true, valid_duplicate_name: "existing_idx" });
|
|
679
|
+
expect(checkup.getInvalidIndexRecommendation(index)).toBe("DROP");
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
test("returns DROP even when is_pk is true if has_valid_duplicate is true", () => {
|
|
683
|
+
// has_valid_duplicate takes precedence over is_pk
|
|
684
|
+
const index = createTestIndex({
|
|
685
|
+
has_valid_duplicate: true,
|
|
686
|
+
is_pk: true,
|
|
687
|
+
is_unique: true,
|
|
688
|
+
});
|
|
689
|
+
expect(checkup.getInvalidIndexRecommendation(index)).toBe("DROP");
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
test("returns RECREATE when is_pk is true and no valid duplicate", () => {
|
|
693
|
+
const index = createTestIndex({
|
|
694
|
+
is_pk: true,
|
|
695
|
+
is_unique: true,
|
|
696
|
+
constraint_name: "test_pkey",
|
|
697
|
+
});
|
|
698
|
+
expect(checkup.getInvalidIndexRecommendation(index)).toBe("RECREATE");
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
test("returns RECREATE when is_unique is true (non-PK) and no valid duplicate", () => {
|
|
702
|
+
const index = createTestIndex({
|
|
703
|
+
is_unique: true,
|
|
704
|
+
constraint_name: "test_unique",
|
|
705
|
+
});
|
|
706
|
+
expect(checkup.getInvalidIndexRecommendation(index)).toBe("RECREATE");
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
test("returns RECREATE for small table (< 10K rows) without valid duplicate", () => {
|
|
710
|
+
const index = createTestIndex({ table_row_estimate: 5000 });
|
|
711
|
+
expect(checkup.getInvalidIndexRecommendation(index)).toBe("RECREATE");
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
test("returns RECREATE for table at threshold boundary (9999 rows)", () => {
|
|
715
|
+
const index = createTestIndex({ table_row_estimate: 9999 });
|
|
716
|
+
expect(checkup.getInvalidIndexRecommendation(index)).toBe("RECREATE");
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
test("returns UNCERTAIN for large table (>= 10K rows) at threshold boundary", () => {
|
|
720
|
+
const index = createTestIndex({ table_row_estimate: 10000 });
|
|
721
|
+
expect(checkup.getInvalidIndexRecommendation(index)).toBe("UNCERTAIN");
|
|
722
|
+
});
|
|
723
|
+
|
|
724
|
+
test("returns UNCERTAIN for large table without valid duplicate or constraint", () => {
|
|
725
|
+
const index = createTestIndex({ table_row_estimate: 1000000 });
|
|
726
|
+
expect(checkup.getInvalidIndexRecommendation(index)).toBe("UNCERTAIN");
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
test("returns UNCERTAIN for empty table (0 rows) with no valid duplicate - edge case", () => {
|
|
730
|
+
// Empty table should be RECREATE (< 10K threshold)
|
|
731
|
+
const index = createTestIndex({ table_row_estimate: 0 });
|
|
732
|
+
expect(checkup.getInvalidIndexRecommendation(index)).toBe("RECREATE");
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
test("decision tree priority: has_valid_duplicate > is_pk > small_table", () => {
|
|
736
|
+
// Even with PK and small table, has_valid_duplicate should win
|
|
737
|
+
const index = createTestIndex({
|
|
738
|
+
has_valid_duplicate: true,
|
|
739
|
+
is_pk: true,
|
|
740
|
+
is_unique: true,
|
|
741
|
+
table_row_estimate: 100,
|
|
742
|
+
});
|
|
743
|
+
expect(checkup.getInvalidIndexRecommendation(index)).toBe("DROP");
|
|
744
|
+
});
|
|
745
|
+
|
|
746
|
+
test("decision tree priority: is_pk > small_table", () => {
|
|
747
|
+
// is_pk should return RECREATE regardless of table size
|
|
748
|
+
const index = createTestIndex({
|
|
749
|
+
is_pk: true,
|
|
750
|
+
is_unique: true,
|
|
751
|
+
table_row_estimate: 1000000, // Large table
|
|
752
|
+
});
|
|
753
|
+
expect(checkup.getInvalidIndexRecommendation(index)).toBe("RECREATE");
|
|
754
|
+
});
|
|
755
|
+
});
|
|
756
|
+
|
|
757
|
+
// Tests for H002 (Unused indexes)
|
|
758
|
+
describe("H002 - Unused indexes", () => {
|
|
759
|
+
test("getUnusedIndexes returns unused indexes", async () => {
|
|
760
|
+
const mockClient = createMockClient({
|
|
761
|
+
unusedIndexesRows: [
|
|
762
|
+
{
|
|
763
|
+
schema_name: "public",
|
|
764
|
+
table_name: "products",
|
|
765
|
+
index_name: "products_old_idx",
|
|
766
|
+
index_definition: "CREATE INDEX products_old_idx ON public.products USING btree (old_column)",
|
|
767
|
+
reason: "Never Used Indexes",
|
|
768
|
+
index_size_bytes: "4194304",
|
|
769
|
+
idx_scan: "0",
|
|
770
|
+
idx_is_btree: true,
|
|
771
|
+
supports_fk: false,
|
|
772
|
+
},
|
|
773
|
+
],
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
const indexes = await checkup.getUnusedIndexes(mockClient as any);
|
|
777
|
+
expect(indexes.length).toBe(1);
|
|
778
|
+
expect(indexes[0].schema_name).toBe("public");
|
|
779
|
+
expect(indexes[0].index_name).toBe("products_old_idx");
|
|
780
|
+
expect(indexes[0].index_size_bytes).toBe(4194304);
|
|
781
|
+
expect(indexes[0].idx_scan).toBe(0);
|
|
782
|
+
expect(indexes[0].supports_fk).toBe(false);
|
|
783
|
+
expect(indexes[0].index_definition).toBeTruthy();
|
|
784
|
+
expect(indexes[0].idx_is_btree).toBe(true);
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
test("generateH002 creates report with unused indexes", async () => {
|
|
788
|
+
const mockClient = createMockClient({
|
|
789
|
+
versionRows: [
|
|
790
|
+
{ name: "server_version", setting: "16.3" },
|
|
791
|
+
{ name: "server_version_num", setting: "160003" },
|
|
792
|
+
],
|
|
793
|
+
unusedIndexesRows: [
|
|
794
|
+
{
|
|
795
|
+
schema_name: "public",
|
|
796
|
+
table_name: "logs",
|
|
797
|
+
index_name: "logs_created_idx",
|
|
798
|
+
index_definition: "CREATE INDEX logs_created_idx ON public.logs USING btree (created_at)",
|
|
799
|
+
reason: "Never Used Indexes",
|
|
800
|
+
index_size_bytes: "8388608",
|
|
801
|
+
idx_scan: "0",
|
|
802
|
+
idx_is_btree: true,
|
|
803
|
+
supports_fk: false,
|
|
804
|
+
},
|
|
805
|
+
],
|
|
806
|
+
}
|
|
807
|
+
);
|
|
808
|
+
|
|
809
|
+
const report = await checkup.generateH002(mockClient as any, "test-node");
|
|
810
|
+
expect(report.checkId).toBe("H002");
|
|
811
|
+
expect(report.checkTitle).toBe("Unused indexes");
|
|
812
|
+
expect("test-node" in report.results).toBe(true);
|
|
813
|
+
|
|
814
|
+
// Data is now keyed by database name
|
|
815
|
+
const data = report.results["test-node"].data;
|
|
816
|
+
expect("testdb" in data).toBe(true);
|
|
817
|
+
const dbData = data["testdb"] as any;
|
|
818
|
+
expect(dbData.unused_indexes).toBeTruthy();
|
|
819
|
+
expect(dbData.total_count).toBe(1);
|
|
820
|
+
expect(dbData.total_size_bytes).toBe(8388608);
|
|
821
|
+
expect(dbData.total_size_pretty).toBeTruthy();
|
|
822
|
+
expect(dbData.stats_reset).toBeTruthy();
|
|
823
|
+
expect(report.results["test-node"].postgres_version).toBeTruthy();
|
|
824
|
+
});
|
|
825
|
+
// Top-level structure tests removed - covered by schema-validation.test.ts
|
|
826
|
+
});
|
|
827
|
+
|
|
828
|
+
// Tests for H004 (Redundant indexes)
|
|
829
|
+
describe("H004 - Redundant indexes", () => {
|
|
830
|
+
test("getRedundantIndexes returns redundant indexes", async () => {
|
|
831
|
+
const mockClient = createMockClient({
|
|
832
|
+
redundantIndexesRows: [
|
|
833
|
+
{
|
|
834
|
+
schema_name: "public",
|
|
835
|
+
table_name: "orders",
|
|
836
|
+
index_name: "orders_user_id_idx",
|
|
837
|
+
relation_name: "orders",
|
|
838
|
+
access_method: "btree",
|
|
839
|
+
reason: "public.orders_user_id_created_idx",
|
|
840
|
+
index_size_bytes: "2097152",
|
|
841
|
+
table_size_bytes: "16777216",
|
|
842
|
+
index_usage: "0",
|
|
843
|
+
supports_fk: false,
|
|
844
|
+
index_definition: "CREATE INDEX orders_user_id_idx ON public.orders USING btree (user_id)",
|
|
845
|
+
redundant_to_json: JSON.stringify([
|
|
846
|
+
{ index_name: "public.orders_user_id_created_idx", index_definition: "CREATE INDEX orders_user_id_created_idx ON public.orders USING btree (user_id, created_at)", index_size_bytes: 1048576 }
|
|
847
|
+
]),
|
|
848
|
+
},
|
|
849
|
+
],
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
const indexes = await checkup.getRedundantIndexes(mockClient as any);
|
|
853
|
+
expect(indexes.length).toBe(1);
|
|
854
|
+
expect(indexes[0].schema_name).toBe("public");
|
|
855
|
+
expect(indexes[0].index_name).toBe("orders_user_id_idx");
|
|
856
|
+
expect(indexes[0].reason).toBe("public.orders_user_id_created_idx");
|
|
857
|
+
expect(indexes[0].index_size_bytes).toBe(2097152);
|
|
858
|
+
expect(indexes[0].supports_fk).toBe(false);
|
|
859
|
+
expect(indexes[0].index_definition).toBeTruthy();
|
|
860
|
+
expect(indexes[0].relation_name).toBe("orders");
|
|
861
|
+
// Verify redundant_to is populated with definitions and sizes
|
|
862
|
+
expect(indexes[0].redundant_to).toBeInstanceOf(Array);
|
|
863
|
+
expect(indexes[0].redundant_to.length).toBe(1);
|
|
864
|
+
expect(indexes[0].redundant_to[0].index_name).toBe("public.orders_user_id_created_idx");
|
|
865
|
+
expect(indexes[0].redundant_to[0].index_definition).toContain("CREATE INDEX");
|
|
866
|
+
expect(indexes[0].redundant_to[0].index_size_bytes).toBe(1048576);
|
|
867
|
+
expect(indexes[0].redundant_to[0].index_size_pretty).toBe("1.00 MiB");
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
test("generateH004 creates report with redundant indexes", async () => {
|
|
871
|
+
const mockClient = createMockClient({
|
|
872
|
+
versionRows: [
|
|
873
|
+
{ name: "server_version", setting: "16.3" },
|
|
874
|
+
{ name: "server_version_num", setting: "160003" },
|
|
875
|
+
],
|
|
876
|
+
redundantIndexesRows: [
|
|
877
|
+
{
|
|
878
|
+
schema_name: "public",
|
|
879
|
+
table_name: "products",
|
|
880
|
+
index_name: "products_category_idx",
|
|
881
|
+
relation_name: "products",
|
|
882
|
+
access_method: "btree",
|
|
883
|
+
reason: "public.products_category_name_idx",
|
|
884
|
+
index_size_bytes: "4194304",
|
|
885
|
+
table_size_bytes: "33554432",
|
|
886
|
+
index_usage: "5",
|
|
887
|
+
supports_fk: false,
|
|
888
|
+
index_definition: "CREATE INDEX products_category_idx ON public.products USING btree (category)",
|
|
889
|
+
redundant_to_json: JSON.stringify([
|
|
890
|
+
{ index_name: "public.products_category_name_idx", index_definition: "CREATE INDEX products_category_name_idx ON public.products USING btree (category, name)", index_size_bytes: 2097152 }
|
|
891
|
+
]),
|
|
892
|
+
},
|
|
893
|
+
],
|
|
894
|
+
}
|
|
895
|
+
);
|
|
896
|
+
|
|
897
|
+
const report = await checkup.generateH004(mockClient as any, "test-node");
|
|
898
|
+
expect(report.checkId).toBe("H004");
|
|
899
|
+
expect(report.checkTitle).toBe("Redundant indexes");
|
|
900
|
+
expect("test-node" in report.results).toBe(true);
|
|
901
|
+
|
|
902
|
+
// Data is now keyed by database name
|
|
903
|
+
const data = report.results["test-node"].data;
|
|
904
|
+
expect("testdb" in data).toBe(true);
|
|
905
|
+
const dbData = data["testdb"] as any;
|
|
906
|
+
expect(dbData.redundant_indexes).toBeTruthy();
|
|
907
|
+
expect(dbData.total_count).toBe(1);
|
|
908
|
+
expect(dbData.total_size_bytes).toBe(4194304);
|
|
909
|
+
expect(dbData.total_size_pretty).toBeTruthy();
|
|
910
|
+
expect(dbData.database_size_bytes).toBeTruthy();
|
|
911
|
+
expect(report.results["test-node"].postgres_version).toBeTruthy();
|
|
912
|
+
});
|
|
913
|
+
// Top-level structure tests removed - covered by schema-validation.test.ts
|
|
914
|
+
});
|
|
915
|
+
|
|
916
|
+
// CLI tests
|
|
917
|
+
describe("CLI tests", () => {
|
|
918
|
+
test("checkup command exists and shows help", () => {
|
|
919
|
+
const r = runCli(["checkup", "--help"]);
|
|
920
|
+
expect(r.status).toBe(0);
|
|
921
|
+
expect(r.stdout).toMatch(/express mode/i);
|
|
922
|
+
expect(r.stdout).toMatch(/--check-id/);
|
|
923
|
+
expect(r.stdout).toMatch(/--node-name/);
|
|
924
|
+
expect(r.stdout).toMatch(/--output/);
|
|
925
|
+
expect(r.stdout).toMatch(/upload/);
|
|
926
|
+
expect(r.stdout).toMatch(/--json/);
|
|
927
|
+
});
|
|
928
|
+
|
|
929
|
+
test("checkup --help shows available check IDs", () => {
|
|
930
|
+
const r = runCli(["checkup", "--help"]);
|
|
931
|
+
expect(r.status).toBe(0);
|
|
932
|
+
expect(r.stdout).toMatch(/A002/);
|
|
933
|
+
expect(r.stdout).toMatch(/A003/);
|
|
934
|
+
expect(r.stdout).toMatch(/A004/);
|
|
935
|
+
expect(r.stdout).toMatch(/A007/);
|
|
936
|
+
expect(r.stdout).toMatch(/A013/);
|
|
937
|
+
expect(r.stdout).toMatch(/H001/);
|
|
938
|
+
expect(r.stdout).toMatch(/H002/);
|
|
939
|
+
expect(r.stdout).toMatch(/H004/);
|
|
940
|
+
});
|
|
941
|
+
|
|
942
|
+
test("checkup without connection shows help", () => {
|
|
943
|
+
const r = runCli(["checkup"]);
|
|
944
|
+
expect(r.status).not.toBe(0);
|
|
945
|
+
// Should show full help (options + examples), like `checkup --help`
|
|
946
|
+
expect(r.stdout).toMatch(/generate health check reports/i);
|
|
947
|
+
expect(r.stdout).toMatch(/--check-id/);
|
|
948
|
+
expect(r.stdout).toMatch(/available checks/i);
|
|
949
|
+
expect(r.stdout).toMatch(/A002/);
|
|
950
|
+
});
|
|
951
|
+
|
|
952
|
+
test("checkup --help shows --upload and --no-upload options", () => {
|
|
953
|
+
const r = runCli(["checkup", "--help"]);
|
|
954
|
+
expect(r.status).toBe(0);
|
|
955
|
+
expect(r.stdout).toMatch(/--upload/);
|
|
956
|
+
expect(r.stdout).toMatch(/--no-upload/);
|
|
957
|
+
});
|
|
958
|
+
|
|
959
|
+
test("checkup --no-upload is recognized as valid option", () => {
|
|
960
|
+
// Should not produce "unknown option" error for --no-upload
|
|
961
|
+
const r = runCli(["checkup", "postgresql://test:test@localhost:5432/test", "--no-upload"]);
|
|
962
|
+
// Connection will fail, but option parsing should succeed
|
|
963
|
+
expect(r.stderr).not.toMatch(/unknown option/i);
|
|
964
|
+
expect(r.stderr).not.toMatch(/did you mean/i);
|
|
965
|
+
});
|
|
966
|
+
|
|
967
|
+
test("checkup --upload is recognized as valid option", () => {
|
|
968
|
+
// Should not produce "unknown option" error for --upload
|
|
969
|
+
const r = runCli(["checkup", "postgresql://test:test@localhost:5432/test", "--upload"]);
|
|
970
|
+
// Connection will fail, but option parsing should succeed
|
|
971
|
+
expect(r.stderr).not.toMatch(/unknown option/i);
|
|
972
|
+
expect(r.stderr).not.toMatch(/did you mean/i);
|
|
973
|
+
});
|
|
974
|
+
|
|
975
|
+
test("checkup --json does not imply --no-upload (decoupled behavior)", () => {
|
|
976
|
+
// Use empty config dir to ensure no API key is configured
|
|
977
|
+
const env = { XDG_CONFIG_HOME: "/tmp/postgresai-test-empty-config" };
|
|
978
|
+
// --json alone should NOT disable upload - when --upload is explicitly requested
|
|
979
|
+
// with --json, it should require API key (proving upload is not disabled)
|
|
980
|
+
const r = runCli(["checkup", "postgresql://test:test@localhost:5432/test", "--json", "--upload"], env);
|
|
981
|
+
// Should fail with "API key is required" because upload is enabled
|
|
982
|
+
expect(r.stderr).toMatch(/API key is required/i);
|
|
983
|
+
expect(r.stderr).not.toMatch(/unknown option/i);
|
|
984
|
+
});
|
|
985
|
+
|
|
986
|
+
test("checkup --json --no-upload explicitly disables upload", () => {
|
|
987
|
+
// Use empty config dir to ensure no API key is configured
|
|
988
|
+
const env = { XDG_CONFIG_HOME: "/tmp/postgresai-test-empty-config" };
|
|
989
|
+
// --json with --no-upload should disable upload (no API key error)
|
|
990
|
+
const r = runCli(["checkup", "postgresql://test:test@localhost:5432/test", "--json", "--no-upload"], env);
|
|
991
|
+
// Should NOT show "API key is required" because upload is disabled
|
|
992
|
+
expect(r.stderr).not.toMatch(/API key is required/i);
|
|
993
|
+
expect(r.stderr).not.toMatch(/unknown option/i);
|
|
994
|
+
});
|
|
995
|
+
|
|
996
|
+
test("checkup --upload requires API key", () => {
|
|
997
|
+
// Use empty config dir to ensure no API key is configured
|
|
998
|
+
const env = { XDG_CONFIG_HOME: "/tmp/postgresai-test-empty-config" };
|
|
999
|
+
// --upload explicitly requests upload, should fail without API key
|
|
1000
|
+
const r = runCli(["checkup", "postgresql://test:test@localhost:5432/test", "--upload"], env);
|
|
1001
|
+
expect(r.stderr).toMatch(/API key is required/i);
|
|
1002
|
+
});
|
|
1003
|
+
|
|
1004
|
+
test("checkup --no-upload does not require API key", () => {
|
|
1005
|
+
// Use empty config dir to ensure no API key is configured
|
|
1006
|
+
const env = { XDG_CONFIG_HOME: "/tmp/postgresai-test-empty-config" };
|
|
1007
|
+
// --no-upload disables upload, should not require API key
|
|
1008
|
+
const r = runCli(["checkup", "postgresql://test:test@localhost:5432/test", "--no-upload"], env);
|
|
1009
|
+
expect(r.stderr).not.toMatch(/API key is required/i);
|
|
1010
|
+
});
|
|
1011
|
+
|
|
1012
|
+
test("checkup --help shows --markdown option", () => {
|
|
1013
|
+
const r = runCli(["checkup", "--help"]);
|
|
1014
|
+
expect(r.status).toBe(0);
|
|
1015
|
+
expect(r.stdout).toMatch(/--markdown/);
|
|
1016
|
+
expect(r.stdout).toMatch(/output markdown to stdout/i);
|
|
1017
|
+
});
|
|
1018
|
+
|
|
1019
|
+
test("checkup --markdown is recognized as valid option", () => {
|
|
1020
|
+
// Should not produce "unknown option" error for --markdown
|
|
1021
|
+
const r = runCli(["checkup", "postgresql://test:test@localhost:5432/test", "--markdown", "--no-upload"]);
|
|
1022
|
+
// Connection will fail, but option parsing should succeed
|
|
1023
|
+
expect(r.stderr).not.toMatch(/unknown option/i);
|
|
1024
|
+
expect(r.stderr).not.toMatch(/did you mean/i);
|
|
1025
|
+
});
|
|
1026
|
+
|
|
1027
|
+
test("checkup --markdown works without API key", () => {
|
|
1028
|
+
// Use empty config dir to ensure no API key is configured
|
|
1029
|
+
const env = { XDG_CONFIG_HOME: "/tmp/postgresai-test-empty-config" };
|
|
1030
|
+
// --markdown should work even without API key
|
|
1031
|
+
const r = runCli(["checkup", "postgresql://test:test@localhost:5432/test", "--markdown", "--no-upload"], env);
|
|
1032
|
+
// Connection will fail, but --markdown flag should be recognized
|
|
1033
|
+
expect(r.status).not.toBe(0);
|
|
1034
|
+
expect(r.stderr).not.toMatch(/unknown option/i);
|
|
1035
|
+
expect(r.stderr).not.toMatch(/API key is required/i);
|
|
1036
|
+
});
|
|
1037
|
+
|
|
1038
|
+
test("checkup with --no-upload and no output flags shows summary", () => {
|
|
1039
|
+
// This test verifies that when running with --no-upload and no output flags,
|
|
1040
|
+
// the user gets a summary of checks.
|
|
1041
|
+
// Note: This will fail to connect, but we can still verify behavior.
|
|
1042
|
+
const env = { XDG_CONFIG_HOME: "/tmp/postgresai-test-empty-config" };
|
|
1043
|
+
const r = runCli(["checkup", "postgresql://test:test@localhost:5432/test", "--no-upload"], env);
|
|
1044
|
+
|
|
1045
|
+
// The command will fail due to connection error, but if it succeeded,
|
|
1046
|
+
// it should show the summary. We can't test the success case without a real DB,
|
|
1047
|
+
// but we verify the option parsing is correct (tested above in other tests).
|
|
1048
|
+
// The actual summary output is tested in integration tests.
|
|
1049
|
+
expect(r.status).not.toBe(0); // Will fail due to connection
|
|
1050
|
+
});
|
|
1051
|
+
|
|
1052
|
+
test("checkup rejects --json and --markdown together", () => {
|
|
1053
|
+
const env = { XDG_CONFIG_HOME: "/tmp/postgresai-test-empty-config" };
|
|
1054
|
+
const r = runCli(["checkup", "postgresql://test:test@localhost:5432/test", "--json", "--markdown", "--no-upload"], env);
|
|
1055
|
+
|
|
1056
|
+
// Should fail with mutual exclusivity error
|
|
1057
|
+
expect(r.status).not.toBe(0);
|
|
1058
|
+
expect(r.stderr).toMatch(/mutually exclusive/i);
|
|
1059
|
+
});
|
|
1060
|
+
|
|
1061
|
+
// Argument parsing tests for check ID / connection string recognition
|
|
1062
|
+
test("checkup with check ID but no connection shows specific error", () => {
|
|
1063
|
+
const r = runCli(["checkup", "H002"]);
|
|
1064
|
+
expect(r.status).not.toBe(0);
|
|
1065
|
+
expect(r.stderr).toMatch(/connection string required/i);
|
|
1066
|
+
expect(r.stderr).toMatch(/H002/);
|
|
1067
|
+
});
|
|
1068
|
+
|
|
1069
|
+
test("checkup recognizes valid check ID patterns", () => {
|
|
1070
|
+
// Valid check IDs: A002, H002, F004, etc.
|
|
1071
|
+
for (const checkId of ["A002", "H002", "F004", "K003", "a002", "h002"]) {
|
|
1072
|
+
const r = runCli(["checkup", checkId]);
|
|
1073
|
+
expect(r.status).not.toBe(0);
|
|
1074
|
+
expect(r.stderr).toMatch(/connection string required/i);
|
|
1075
|
+
}
|
|
1076
|
+
});
|
|
1077
|
+
|
|
1078
|
+
test("checkup does not treat connection string as check ID", () => {
|
|
1079
|
+
// Connection strings should not be parsed as check IDs
|
|
1080
|
+
const r = runCli(["checkup", "postgresql://test:test@localhost:5432/test", "--no-upload"]);
|
|
1081
|
+
// Should not show "connection string required" error
|
|
1082
|
+
expect(r.stderr).not.toMatch(/connection string required/i);
|
|
1083
|
+
});
|
|
1084
|
+
|
|
1085
|
+
test("checkup with check ID and connection string works", () => {
|
|
1086
|
+
// pgai checkup H002 postgresql://...
|
|
1087
|
+
const r = runCli(["checkup", "H002", "postgresql://test:test@localhost:5432/test", "--no-upload"]);
|
|
1088
|
+
// Should not show "connection string required" error
|
|
1089
|
+
expect(r.stderr).not.toMatch(/connection string required/i);
|
|
1090
|
+
// Connection will fail but argument parsing should succeed
|
|
1091
|
+
expect(r.stderr).not.toMatch(/unknown option/i);
|
|
1092
|
+
});
|
|
1093
|
+
|
|
1094
|
+
test("checkup with --check-id option works", () => {
|
|
1095
|
+
// pgai checkup --check-id H002 postgresql://...
|
|
1096
|
+
const r = runCli(["checkup", "--check-id", "H002", "postgresql://test:test@localhost:5432/test", "--no-upload"]);
|
|
1097
|
+
// Should not show "connection string required" error
|
|
1098
|
+
expect(r.stderr).not.toMatch(/connection string required/i);
|
|
1099
|
+
expect(r.stderr).not.toMatch(/unknown option/i);
|
|
1100
|
+
});
|
|
1101
|
+
});
|
|
1102
|
+
|
|
1103
|
+
// Tests for checkup-api module
|
|
1104
|
+
describe("checkup-api", () => {
|
|
1105
|
+
test("formatRpcErrorForDisplay formats details/hint nicely", () => {
|
|
1106
|
+
const err = new api.RpcError({
|
|
1107
|
+
rpcName: "checkup_report_file_post",
|
|
1108
|
+
statusCode: 402,
|
|
1109
|
+
payloadText: JSON.stringify({
|
|
1110
|
+
hint: "Start an express checkup subscription for the organization or contact support.",
|
|
1111
|
+
details: "Checkup report uploads require an active checkup subscription",
|
|
1112
|
+
}),
|
|
1113
|
+
payloadJson: {
|
|
1114
|
+
hint: "Start an express checkup subscription for the organization or contact support.",
|
|
1115
|
+
details: "Checkup report uploads require an active checkup subscription.",
|
|
1116
|
+
},
|
|
1117
|
+
});
|
|
1118
|
+
const lines = api.formatRpcErrorForDisplay(err);
|
|
1119
|
+
const text = lines.join("\n");
|
|
1120
|
+
expect(text).toMatch(/RPC checkup_report_file_post failed: HTTP 402/);
|
|
1121
|
+
expect(text).toMatch(/Details:/);
|
|
1122
|
+
expect(text).toMatch(/Hint:/);
|
|
1123
|
+
});
|
|
1124
|
+
|
|
1125
|
+
test("withRetry succeeds on first attempt", async () => {
|
|
1126
|
+
let attempts = 0;
|
|
1127
|
+
const result = await api.withRetry(async () => {
|
|
1128
|
+
attempts++;
|
|
1129
|
+
return "success";
|
|
1130
|
+
});
|
|
1131
|
+
expect(result).toBe("success");
|
|
1132
|
+
expect(attempts).toBe(1);
|
|
1133
|
+
});
|
|
1134
|
+
|
|
1135
|
+
test("withRetry retries on retryable errors and succeeds", async () => {
|
|
1136
|
+
let attempts = 0;
|
|
1137
|
+
const result = await api.withRetry(
|
|
1138
|
+
async () => {
|
|
1139
|
+
attempts++;
|
|
1140
|
+
if (attempts < 3) {
|
|
1141
|
+
throw new Error("connection timeout");
|
|
1142
|
+
}
|
|
1143
|
+
return "success after retry";
|
|
1144
|
+
},
|
|
1145
|
+
{ maxAttempts: 3, initialDelayMs: 10 }
|
|
1146
|
+
);
|
|
1147
|
+
expect(result).toBe("success after retry");
|
|
1148
|
+
expect(attempts).toBe(3);
|
|
1149
|
+
});
|
|
1150
|
+
|
|
1151
|
+
test("withRetry calls onRetry callback", async () => {
|
|
1152
|
+
let attempts = 0;
|
|
1153
|
+
const retryLogs: string[] = [];
|
|
1154
|
+
await api.withRetry(
|
|
1155
|
+
async () => {
|
|
1156
|
+
attempts++;
|
|
1157
|
+
if (attempts < 2) {
|
|
1158
|
+
throw new Error("socket hang up");
|
|
1159
|
+
}
|
|
1160
|
+
return "ok";
|
|
1161
|
+
},
|
|
1162
|
+
{ maxAttempts: 3, initialDelayMs: 10 },
|
|
1163
|
+
(attempt, _err, delayMs) => {
|
|
1164
|
+
retryLogs.push(`attempt ${attempt}, delay ${delayMs}ms`);
|
|
1165
|
+
}
|
|
1166
|
+
);
|
|
1167
|
+
expect(retryLogs.length).toBe(1);
|
|
1168
|
+
expect(retryLogs[0]).toMatch(/attempt 1/);
|
|
1169
|
+
});
|
|
1170
|
+
|
|
1171
|
+
test("withRetry does not retry on non-retryable errors", async () => {
|
|
1172
|
+
let attempts = 0;
|
|
1173
|
+
try {
|
|
1174
|
+
await api.withRetry(
|
|
1175
|
+
async () => {
|
|
1176
|
+
attempts++;
|
|
1177
|
+
throw new Error("invalid input");
|
|
1178
|
+
},
|
|
1179
|
+
{ maxAttempts: 3, initialDelayMs: 10 }
|
|
1180
|
+
);
|
|
1181
|
+
} catch (err) {
|
|
1182
|
+
expect((err as Error).message).toBe("invalid input");
|
|
1183
|
+
}
|
|
1184
|
+
expect(attempts).toBe(1);
|
|
1185
|
+
});
|
|
1186
|
+
|
|
1187
|
+
test("withRetry does not retry on 4xx RpcError", async () => {
|
|
1188
|
+
let attempts = 0;
|
|
1189
|
+
try {
|
|
1190
|
+
await api.withRetry(
|
|
1191
|
+
async () => {
|
|
1192
|
+
attempts++;
|
|
1193
|
+
throw new api.RpcError({
|
|
1194
|
+
rpcName: "test",
|
|
1195
|
+
statusCode: 400,
|
|
1196
|
+
payloadText: "bad request",
|
|
1197
|
+
payloadJson: null,
|
|
1198
|
+
});
|
|
1199
|
+
},
|
|
1200
|
+
{ maxAttempts: 3, initialDelayMs: 10 }
|
|
1201
|
+
);
|
|
1202
|
+
} catch (err) {
|
|
1203
|
+
expect(err).toBeInstanceOf(api.RpcError);
|
|
1204
|
+
}
|
|
1205
|
+
expect(attempts).toBe(1);
|
|
1206
|
+
});
|
|
1207
|
+
|
|
1208
|
+
test("withRetry retries on 5xx RpcError", async () => {
|
|
1209
|
+
let attempts = 0;
|
|
1210
|
+
try {
|
|
1211
|
+
await api.withRetry(
|
|
1212
|
+
async () => {
|
|
1213
|
+
attempts++;
|
|
1214
|
+
throw new api.RpcError({
|
|
1215
|
+
rpcName: "test",
|
|
1216
|
+
statusCode: 503,
|
|
1217
|
+
payloadText: "service unavailable",
|
|
1218
|
+
payloadJson: null,
|
|
1219
|
+
});
|
|
1220
|
+
},
|
|
1221
|
+
{ maxAttempts: 2, initialDelayMs: 10 }
|
|
1222
|
+
);
|
|
1223
|
+
} catch (err) {
|
|
1224
|
+
expect(err).toBeInstanceOf(api.RpcError);
|
|
1225
|
+
}
|
|
1226
|
+
expect(attempts).toBe(2);
|
|
1227
|
+
});
|
|
1228
|
+
|
|
1229
|
+
test("withRetry retries on timeout errors", async () => {
|
|
1230
|
+
// Tests that timeout-like error messages are considered retryable
|
|
1231
|
+
let attempts = 0;
|
|
1232
|
+
try {
|
|
1233
|
+
await api.withRetry(
|
|
1234
|
+
async () => {
|
|
1235
|
+
attempts++;
|
|
1236
|
+
throw new Error("RPC test timed out after 30000ms (no response)");
|
|
1237
|
+
},
|
|
1238
|
+
{ maxAttempts: 3, initialDelayMs: 10 }
|
|
1239
|
+
);
|
|
1240
|
+
} catch (err) {
|
|
1241
|
+
expect(err).toBeInstanceOf(Error);
|
|
1242
|
+
expect((err as Error).message).toContain("timed out");
|
|
1243
|
+
}
|
|
1244
|
+
expect(attempts).toBe(3); // Should retry on timeout
|
|
1245
|
+
});
|
|
1246
|
+
|
|
1247
|
+
test("withRetry retries on ECONNRESET errors", async () => {
|
|
1248
|
+
// Tests that connection reset errors are considered retryable
|
|
1249
|
+
let attempts = 0;
|
|
1250
|
+
try {
|
|
1251
|
+
await api.withRetry(
|
|
1252
|
+
async () => {
|
|
1253
|
+
attempts++;
|
|
1254
|
+
const err = new Error("connection reset") as Error & { code: string };
|
|
1255
|
+
err.code = "ECONNRESET";
|
|
1256
|
+
throw err;
|
|
1257
|
+
},
|
|
1258
|
+
{ maxAttempts: 2, initialDelayMs: 10 }
|
|
1259
|
+
);
|
|
1260
|
+
} catch (err) {
|
|
1261
|
+
expect(err).toBeInstanceOf(Error);
|
|
1262
|
+
}
|
|
1263
|
+
expect(attempts).toBe(2); // Should retry on ECONNRESET
|
|
1264
|
+
});
|
|
1265
|
+
});
|
|
1266
|
+
|
|
1267
|
+
// Tests for checkup-summary module
|
|
1268
|
+
describe("checkup-summary", () => {
|
|
1269
|
+
const summary = require("../lib/checkup-summary");
|
|
1270
|
+
|
|
1271
|
+
test("generateCheckSummary for H001 with no issues", () => {
|
|
1272
|
+
const report = {
|
|
1273
|
+
results: {
|
|
1274
|
+
"node1": {
|
|
1275
|
+
data: {
|
|
1276
|
+
"db1": {
|
|
1277
|
+
invalid_indexes: [],
|
|
1278
|
+
total_count: 0,
|
|
1279
|
+
total_size_bytes: 0,
|
|
1280
|
+
total_size_pretty: "0 bytes",
|
|
1281
|
+
database_size_bytes: 1000000,
|
|
1282
|
+
database_size_pretty: "1 MB"
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
};
|
|
1288
|
+
const result = summary.generateCheckSummary("H001", report);
|
|
1289
|
+
expect(result.status).toBe("ok");
|
|
1290
|
+
expect(result.message).toMatch(/no invalid/i);
|
|
1291
|
+
});
|
|
1292
|
+
|
|
1293
|
+
test("generateCheckSummary for H001 with invalid indexes", () => {
|
|
1294
|
+
const report = {
|
|
1295
|
+
results: {
|
|
1296
|
+
"node1": {
|
|
1297
|
+
data: {
|
|
1298
|
+
"db1": {
|
|
1299
|
+
invalid_indexes: [{}, {}, {}],
|
|
1300
|
+
total_count: 3,
|
|
1301
|
+
total_size_bytes: 1024 * 1024 * 245,
|
|
1302
|
+
total_size_pretty: "245 MiB",
|
|
1303
|
+
database_size_bytes: 1000000000,
|
|
1304
|
+
database_size_pretty: "1 GB"
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
};
|
|
1310
|
+
const result = summary.generateCheckSummary("H001", report);
|
|
1311
|
+
expect(result.status).toBe("warning");
|
|
1312
|
+
expect(result.message).toMatch(/3 invalid indexes/i);
|
|
1313
|
+
expect(result.message).toMatch(/245 MiB/i);
|
|
1314
|
+
});
|
|
1315
|
+
|
|
1316
|
+
test("generateCheckSummary for H002 with no issues", () => {
|
|
1317
|
+
const report = {
|
|
1318
|
+
results: {
|
|
1319
|
+
"node1": {
|
|
1320
|
+
data: {
|
|
1321
|
+
"db1": {
|
|
1322
|
+
unused_indexes: [],
|
|
1323
|
+
total_count: 0,
|
|
1324
|
+
total_size_bytes: 0,
|
|
1325
|
+
total_size_pretty: "0 bytes",
|
|
1326
|
+
database_size_bytes: 1000000,
|
|
1327
|
+
database_size_pretty: "1 MB",
|
|
1328
|
+
stats_reset: {}
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
};
|
|
1334
|
+
const result = summary.generateCheckSummary("H002", report);
|
|
1335
|
+
expect(result.status).toBe("ok");
|
|
1336
|
+
expect(result.message).toMatch(/all indexes utilized/i);
|
|
1337
|
+
});
|
|
1338
|
+
|
|
1339
|
+
test("generateCheckSummary for H002 with unused indexes", () => {
|
|
1340
|
+
const report = {
|
|
1341
|
+
results: {
|
|
1342
|
+
"node1": {
|
|
1343
|
+
data: {
|
|
1344
|
+
"db1": {
|
|
1345
|
+
unused_indexes: [{}, {}],
|
|
1346
|
+
total_count: 2,
|
|
1347
|
+
total_size_bytes: 1024 * 1024 * 150,
|
|
1348
|
+
total_size_pretty: "150 MiB",
|
|
1349
|
+
database_size_bytes: 1000000000,
|
|
1350
|
+
database_size_pretty: "1 GB",
|
|
1351
|
+
stats_reset: {}
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
};
|
|
1357
|
+
const result = summary.generateCheckSummary("H002", report);
|
|
1358
|
+
expect(result.status).toBe("warning");
|
|
1359
|
+
expect(result.message).toMatch(/2 unused indexes/i);
|
|
1360
|
+
expect(result.message).toMatch(/150 MiB/i);
|
|
1361
|
+
});
|
|
1362
|
+
|
|
1363
|
+
test("generateCheckSummary for H004 with redundant indexes", () => {
|
|
1364
|
+
const report = {
|
|
1365
|
+
results: {
|
|
1366
|
+
"node1": {
|
|
1367
|
+
data: {
|
|
1368
|
+
"db1": {
|
|
1369
|
+
redundant_indexes: [{}, {}, {}, {}],
|
|
1370
|
+
total_count: 4,
|
|
1371
|
+
total_size_bytes: 1024 * 1024 * 1024 * 1.2,
|
|
1372
|
+
total_size_pretty: "1.2 GiB",
|
|
1373
|
+
database_size_bytes: 10000000000,
|
|
1374
|
+
database_size_pretty: "10 GB"
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
const result = summary.generateCheckSummary("H004", report);
|
|
1381
|
+
expect(result.status).toBe("warning");
|
|
1382
|
+
expect(result.message).toMatch(/4 redundant indexes/i);
|
|
1383
|
+
expect(result.message).toMatch(/1\.2 GiB/i);
|
|
1384
|
+
});
|
|
1385
|
+
|
|
1386
|
+
test("generateCheckSummary for A003 (settings)", () => {
|
|
1387
|
+
const report = {
|
|
1388
|
+
results: {
|
|
1389
|
+
"node1": {
|
|
1390
|
+
data: {
|
|
1391
|
+
"setting1": "value1",
|
|
1392
|
+
"setting2": "value2"
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
};
|
|
1397
|
+
const result = summary.generateCheckSummary("A003", report);
|
|
1398
|
+
expect(result.status).toBe("info");
|
|
1399
|
+
expect(result.message).toBe("2 settings collected");
|
|
1400
|
+
});
|
|
1401
|
+
|
|
1402
|
+
test("generateCheckSummary for A002 with PostgreSQL 17", () => {
|
|
1403
|
+
const report = {
|
|
1404
|
+
results: {
|
|
1405
|
+
"node1": {
|
|
1406
|
+
data: {
|
|
1407
|
+
version: {
|
|
1408
|
+
version: "17.2",
|
|
1409
|
+
server_version_num: "170002",
|
|
1410
|
+
server_major_ver: "17",
|
|
1411
|
+
server_minor_ver: "2"
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
};
|
|
1417
|
+
const result = summary.generateCheckSummary("A002", report);
|
|
1418
|
+
expect(result.status).toBe("ok");
|
|
1419
|
+
expect(result.message).toBe("PostgreSQL 17");
|
|
1420
|
+
});
|
|
1421
|
+
|
|
1422
|
+
test("generateCheckSummary for A002 with PostgreSQL 15", () => {
|
|
1423
|
+
const report = {
|
|
1424
|
+
results: {
|
|
1425
|
+
"node1": {
|
|
1426
|
+
data: {
|
|
1427
|
+
version: {
|
|
1428
|
+
version: "15.4",
|
|
1429
|
+
server_version_num: "150004",
|
|
1430
|
+
server_major_ver: "15",
|
|
1431
|
+
server_minor_ver: "4"
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
};
|
|
1437
|
+
const result = summary.generateCheckSummary("A002", report);
|
|
1438
|
+
expect(result.status).toBe("info");
|
|
1439
|
+
expect(result.message).toBe("PostgreSQL 15");
|
|
1440
|
+
});
|
|
1441
|
+
|
|
1442
|
+
test("generateCheckSummary for A002 with old PostgreSQL 11", () => {
|
|
1443
|
+
const report = {
|
|
1444
|
+
results: {
|
|
1445
|
+
"node1": {
|
|
1446
|
+
data: {
|
|
1447
|
+
version: {
|
|
1448
|
+
version: "11.8",
|
|
1449
|
+
server_version_num: "110008",
|
|
1450
|
+
server_major_ver: "11",
|
|
1451
|
+
server_minor_ver: "8"
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
};
|
|
1457
|
+
const result = summary.generateCheckSummary("A002", report);
|
|
1458
|
+
expect(result.status).toBe("warning");
|
|
1459
|
+
expect(result.message).toMatch(/PostgreSQL 11.*consider upgrading/i);
|
|
1460
|
+
});
|
|
1461
|
+
|
|
1462
|
+
test("generateCheckSummary for A013 with version", () => {
|
|
1463
|
+
const report = {
|
|
1464
|
+
results: {
|
|
1465
|
+
"node1": {
|
|
1466
|
+
data: {
|
|
1467
|
+
version: {
|
|
1468
|
+
version: "17.2",
|
|
1469
|
+
server_version_num: "170002",
|
|
1470
|
+
server_major_ver: "17",
|
|
1471
|
+
server_minor_ver: "2"
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
};
|
|
1477
|
+
const result = summary.generateCheckSummary("A013", report);
|
|
1478
|
+
expect(result.status).toBe("info");
|
|
1479
|
+
expect(result.message).toBe("Version 17.2");
|
|
1480
|
+
});
|
|
1481
|
+
|
|
1482
|
+
test("generateCheckSummary handles empty results", () => {
|
|
1483
|
+
const report = { results: {} };
|
|
1484
|
+
const result = summary.generateCheckSummary("H001", report);
|
|
1485
|
+
expect(result.status).toBe("info");
|
|
1486
|
+
expect(result.message).toBe("No data");
|
|
1487
|
+
});
|
|
1488
|
+
|
|
1489
|
+
test("generateCheckSummary handles unknown check ID", () => {
|
|
1490
|
+
const report = {
|
|
1491
|
+
results: {
|
|
1492
|
+
"node1": { data: {} }
|
|
1493
|
+
}
|
|
1494
|
+
};
|
|
1495
|
+
const result = summary.generateCheckSummary("UNKNOWN", report);
|
|
1496
|
+
expect(result.status).toBe("info");
|
|
1497
|
+
expect(result.message).toBe("Check completed");
|
|
1498
|
+
});
|
|
1499
|
+
|
|
1500
|
+
test("generateCheckSummary for D001 (logging settings)", () => {
|
|
1501
|
+
const report = {
|
|
1502
|
+
results: {
|
|
1503
|
+
"node1": {
|
|
1504
|
+
data: {
|
|
1505
|
+
"log_destination": { value: "stderr" },
|
|
1506
|
+
"log_line_prefix": { value: "%m [%p] " }
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
};
|
|
1511
|
+
const result = summary.generateCheckSummary("D001", report);
|
|
1512
|
+
expect(result.status).toBe("info");
|
|
1513
|
+
expect(result.message).toBe("2 logging settings collected");
|
|
1514
|
+
});
|
|
1515
|
+
|
|
1516
|
+
test("generateCheckSummary for D004 (pg_stat_statements)", () => {
|
|
1517
|
+
const report = {
|
|
1518
|
+
results: {
|
|
1519
|
+
"node1": {
|
|
1520
|
+
data: {
|
|
1521
|
+
"pg_stat_statements.max": { value: "5000" },
|
|
1522
|
+
"pg_stat_statements.track": { value: "all" }
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
};
|
|
1527
|
+
const result = summary.generateCheckSummary("D004", report);
|
|
1528
|
+
expect(result.status).toBe("info");
|
|
1529
|
+
expect(result.message).toBe("2 pg_stat_statements settings collected");
|
|
1530
|
+
});
|
|
1531
|
+
|
|
1532
|
+
test("generateCheckSummary for F001 (autovacuum)", () => {
|
|
1533
|
+
const report = {
|
|
1534
|
+
results: {
|
|
1535
|
+
"node1": {
|
|
1536
|
+
data: {
|
|
1537
|
+
"autovacuum": { value: "on" },
|
|
1538
|
+
"autovacuum_max_workers": { value: "3" }
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
};
|
|
1543
|
+
const result = summary.generateCheckSummary("F001", report);
|
|
1544
|
+
expect(result.status).toBe("info");
|
|
1545
|
+
expect(result.message).toBe("2 autovacuum settings collected");
|
|
1546
|
+
});
|
|
1547
|
+
|
|
1548
|
+
test("generateCheckSummary for G001 (memory settings)", () => {
|
|
1549
|
+
const report = {
|
|
1550
|
+
results: {
|
|
1551
|
+
"node1": {
|
|
1552
|
+
data: {
|
|
1553
|
+
"shared_buffers": { value: "128MB" },
|
|
1554
|
+
"work_mem": { value: "4MB" }
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
};
|
|
1559
|
+
const result = summary.generateCheckSummary("G001", report);
|
|
1560
|
+
expect(result.status).toBe("info");
|
|
1561
|
+
expect(result.message).toBe("2 memory settings collected");
|
|
1562
|
+
});
|
|
1563
|
+
|
|
1564
|
+
test("generateCheckSummary for G003 with deadlocks", () => {
|
|
1565
|
+
const report = {
|
|
1566
|
+
results: {
|
|
1567
|
+
"node1": {
|
|
1568
|
+
data: {
|
|
1569
|
+
settings: {
|
|
1570
|
+
"lock_timeout": { value: "0" }
|
|
1571
|
+
},
|
|
1572
|
+
deadlock_stats: {
|
|
1573
|
+
deadlocks: 5,
|
|
1574
|
+
conflicts: 0,
|
|
1575
|
+
stats_reset: "2025-01-01"
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
};
|
|
1581
|
+
const result = summary.generateCheckSummary("G003", report);
|
|
1582
|
+
expect(result.status).toBe("warning");
|
|
1583
|
+
expect(result.message).toBe("5 deadlocks detected");
|
|
1584
|
+
});
|
|
1585
|
+
|
|
1586
|
+
test("generateCheckSummary for G003 without deadlocks", () => {
|
|
1587
|
+
const report = {
|
|
1588
|
+
results: {
|
|
1589
|
+
"node1": {
|
|
1590
|
+
data: {
|
|
1591
|
+
settings: {
|
|
1592
|
+
"lock_timeout": { value: "0" },
|
|
1593
|
+
"statement_timeout": { value: "0" }
|
|
1594
|
+
},
|
|
1595
|
+
deadlock_stats: {
|
|
1596
|
+
deadlocks: 0,
|
|
1597
|
+
conflicts: 0
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
};
|
|
1603
|
+
const result = summary.generateCheckSummary("G003", report);
|
|
1604
|
+
expect(result.status).toBe("info");
|
|
1605
|
+
expect(result.message).toBe("2 timeout/lock settings collected");
|
|
1606
|
+
});
|
|
1607
|
+
|
|
1608
|
+
// Edge cases: empty data
|
|
1609
|
+
test("generateCheckSummary for A003 with no settings", () => {
|
|
1610
|
+
const report = {
|
|
1611
|
+
results: {
|
|
1612
|
+
"node1": {
|
|
1613
|
+
data: {}
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
};
|
|
1617
|
+
const result = summary.generateCheckSummary("A003", report);
|
|
1618
|
+
expect(result.status).toBe("info");
|
|
1619
|
+
expect(result.message).toBe("No settings found");
|
|
1620
|
+
});
|
|
1621
|
+
|
|
1622
|
+
test("generateCheckSummary for A004 with no data", () => {
|
|
1623
|
+
const report = {
|
|
1624
|
+
results: {
|
|
1625
|
+
"node1": {}
|
|
1626
|
+
}
|
|
1627
|
+
};
|
|
1628
|
+
const result = summary.generateCheckSummary("A004", report);
|
|
1629
|
+
expect(result.status).toBe("info");
|
|
1630
|
+
expect(result.message).toBe("Cluster information collected");
|
|
1631
|
+
});
|
|
1632
|
+
|
|
1633
|
+
test("generateCheckSummary for A004 with no database_sizes", () => {
|
|
1634
|
+
const report = {
|
|
1635
|
+
results: {
|
|
1636
|
+
"node1": {
|
|
1637
|
+
data: {
|
|
1638
|
+
general_info: {}
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
};
|
|
1643
|
+
const result = summary.generateCheckSummary("A004", report);
|
|
1644
|
+
expect(result.status).toBe("info");
|
|
1645
|
+
expect(result.message).toBe("Cluster information collected");
|
|
1646
|
+
});
|
|
1647
|
+
|
|
1648
|
+
test("generateCheckSummary for A007 with no altered settings", () => {
|
|
1649
|
+
const report = {
|
|
1650
|
+
results: {
|
|
1651
|
+
"node1": {
|
|
1652
|
+
data: {}
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
};
|
|
1656
|
+
const result = summary.generateCheckSummary("A007", report);
|
|
1657
|
+
expect(result.status).toBe("ok");
|
|
1658
|
+
expect(result.message).toBe("No altered settings");
|
|
1659
|
+
});
|
|
1660
|
+
|
|
1661
|
+
test("generateCheckSummary for A002 with no version data", () => {
|
|
1662
|
+
const report = {
|
|
1663
|
+
results: {
|
|
1664
|
+
"node1": {
|
|
1665
|
+
data: {}
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
};
|
|
1669
|
+
const result = summary.generateCheckSummary("A002", report);
|
|
1670
|
+
expect(result.status).toBe("info");
|
|
1671
|
+
expect(result.message).toBe("Version checked");
|
|
1672
|
+
});
|
|
1673
|
+
|
|
1674
|
+
test("generateCheckSummary for D001 with no settings", () => {
|
|
1675
|
+
const report = {
|
|
1676
|
+
results: {
|
|
1677
|
+
"node1": {
|
|
1678
|
+
data: {}
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
};
|
|
1682
|
+
const result = summary.generateCheckSummary("D001", report);
|
|
1683
|
+
expect(result.status).toBe("info");
|
|
1684
|
+
expect(result.message).toBe("No logging settings found");
|
|
1685
|
+
});
|
|
1686
|
+
|
|
1687
|
+
test("generateCheckSummary for D004 with no settings", () => {
|
|
1688
|
+
const report = {
|
|
1689
|
+
results: {
|
|
1690
|
+
"node1": {
|
|
1691
|
+
data: {}
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
};
|
|
1695
|
+
const result = summary.generateCheckSummary("D004", report);
|
|
1696
|
+
expect(result.status).toBe("info");
|
|
1697
|
+
expect(result.message).toBe("No pg_stat_statements settings found");
|
|
1698
|
+
});
|
|
1699
|
+
|
|
1700
|
+
test("generateCheckSummary for F001 with no settings", () => {
|
|
1701
|
+
const report = {
|
|
1702
|
+
results: {
|
|
1703
|
+
"node1": {
|
|
1704
|
+
data: {}
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1708
|
+
const result = summary.generateCheckSummary("F001", report);
|
|
1709
|
+
expect(result.status).toBe("info");
|
|
1710
|
+
expect(result.message).toBe("No autovacuum settings found");
|
|
1711
|
+
});
|
|
1712
|
+
|
|
1713
|
+
test("generateCheckSummary for G001 with no settings", () => {
|
|
1714
|
+
const report = {
|
|
1715
|
+
results: {
|
|
1716
|
+
"node1": {
|
|
1717
|
+
data: {}
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
};
|
|
1721
|
+
const result = summary.generateCheckSummary("G001", report);
|
|
1722
|
+
expect(result.status).toBe("info");
|
|
1723
|
+
expect(result.message).toBe("No memory settings found");
|
|
1724
|
+
});
|
|
1725
|
+
|
|
1726
|
+
test("generateCheckSummary for G003 with no settings or deadlock_stats", () => {
|
|
1727
|
+
const report = {
|
|
1728
|
+
results: {
|
|
1729
|
+
"node1": {
|
|
1730
|
+
data: {}
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
};
|
|
1734
|
+
const result = summary.generateCheckSummary("G003", report);
|
|
1735
|
+
expect(result.status).toBe("info");
|
|
1736
|
+
expect(result.message).toBe("No timeout/lock settings found");
|
|
1737
|
+
});
|
|
1738
|
+
|
|
1739
|
+
test("generateCheckSummary for H001 with no invalid indexes", () => {
|
|
1740
|
+
const report = {
|
|
1741
|
+
results: {
|
|
1742
|
+
"node1": {
|
|
1743
|
+
data: {
|
|
1744
|
+
"db1": {
|
|
1745
|
+
invalid_indexes: [],
|
|
1746
|
+
total_count: 0,
|
|
1747
|
+
total_size_bytes: 0
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
};
|
|
1753
|
+
const result = summary.generateCheckSummary("H001", report);
|
|
1754
|
+
expect(result.status).toBe("ok");
|
|
1755
|
+
expect(result.message).toBe("No invalid indexes");
|
|
1756
|
+
});
|
|
1757
|
+
|
|
1758
|
+
test("generateCheckSummary for H002 with all indexes utilized", () => {
|
|
1759
|
+
const report = {
|
|
1760
|
+
results: {
|
|
1761
|
+
"node1": {
|
|
1762
|
+
data: {
|
|
1763
|
+
"db1": {
|
|
1764
|
+
unused_indexes: [],
|
|
1765
|
+
total_count: 0,
|
|
1766
|
+
total_size_bytes: 0
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
};
|
|
1772
|
+
const result = summary.generateCheckSummary("H002", report);
|
|
1773
|
+
expect(result.status).toBe("ok");
|
|
1774
|
+
expect(result.message).toBe("All indexes utilized");
|
|
1775
|
+
});
|
|
1776
|
+
|
|
1777
|
+
test("generateCheckSummary for H004 with no redundant indexes", () => {
|
|
1778
|
+
const report = {
|
|
1779
|
+
results: {
|
|
1780
|
+
"node1": {
|
|
1781
|
+
data: {
|
|
1782
|
+
"db1": {
|
|
1783
|
+
redundant_indexes: [],
|
|
1784
|
+
total_count: 0,
|
|
1785
|
+
total_size_bytes: 0
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
};
|
|
1791
|
+
const result = summary.generateCheckSummary("H004", report);
|
|
1792
|
+
expect(result.status).toBe("ok");
|
|
1793
|
+
expect(result.message).toBe("No redundant indexes");
|
|
1794
|
+
});
|
|
1795
|
+
});
|
|
1796
|
+
|
|
1797
|
+
|