-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettingsInventory.test.ts
More file actions
118 lines (109 loc) Β· 4.85 KB
/
Copy pathsettingsInventory.test.ts
File metadata and controls
118 lines (109 loc) Β· 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import fs from "node:fs";
import path from "node:path";
import { describe, expect, it } from "vitest";
import { parse as parseYaml } from "yaml";
import { ENV, EXTERNAL_ENV } from "../src/settings/index.js";
const ENV_EXAMPLE_PATH = path.join(process.cwd(), ".env.example");
const NUB_JSONC_PATH = path.join(process.cwd(), "nub.jsonc");
const NUB_LOCK_PATH = path.join(process.cwd(), "nub.lock");
const PACKAGE_JSON_PATH = path.join(process.cwd(), "package.json");
function parseEnvExampleKeys(content: string): string[] {
const keys: string[] = [];
for (const line of content.split("\n")) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith("#")) continue;
const eq = trimmed.indexOf("=");
if (eq <= 0) continue;
keys.push(trimmed.slice(0, eq).trim());
}
return keys;
}
describe("settings inventory", () => {
it("ENV keys match loadConfig surface", () => {
const envValues = Object.values(ENV);
expect(envValues).toContain("PORT");
expect(envValues).toContain("DATABASE_URL");
expect(envValues).toContain("POSTHOG_PROJECT_TOKEN");
expect(envValues).toContain("POSTHOG_HOST");
expect(envValues).toContain("REVIEW_SPECIALIST_TIMEOUT_MS");
expect(new Set(envValues).size).toBe(envValues.length);
expect(envValues).toContain("PI_ORCHESTRATOR_PROVIDER");
expect(envValues).toContain("PI_ORCHESTRATOR_MODEL");
expect(envValues).toContain("PI_FALLBACK_PROVIDER");
expect(envValues).toContain("PI_FALLBACK_MODEL");
expect(envValues).toContain("PI_THINKING_CEILING");
expect(envValues).toContain("AGENT_RESUME_SNAPSHOT_KEY");
expect(envValues).toContain("AGENT_RESUME_SNAPSHOT_MARGIN_SECONDS");
expect(envValues).toContain("AGENT_EVENTS_ENABLED");
expect(envValues).toContain("AGENT_EVENTS_RETENTION_SECONDS");
expect(envValues).toContain("FINDING_HISTORY_ENABLED");
expect(envValues).toContain("FINDING_HISTORY_DISMISS_SUPPRESS_AFTER");
expect(envValues).toContain("FINDING_HISTORY_LOOKBACK_DAYS");
expect(envValues).toContain("CODE_INDEX_MODE");
expect(envValues).toContain("CODE_INDEX_WAIT_MS");
expect(envValues).toContain("CODE_INDEX_RETENTION_SECONDS");
expect(envValues.length).toBe(76);
});
it("docs/features.md documents every FEATURE_* key", () => {
const featuresDoc = fs.readFileSync(path.join(process.cwd(), "docs", "features.md"), "utf8");
const featureKeys = Object.values(ENV).filter((key) => key.startsWith("FEATURE_"));
expect(featureKeys.length).toBe(8);
for (const key of featureKeys) {
expect(featuresDoc.includes(key), `missing ${key} in docs/features.md`).toBe(true);
}
});
it(".env.example documents every loadConfig env key", () => {
const content = fs.readFileSync(ENV_EXAMPLE_PATH, "utf8");
const documented = parseEnvExampleKeys(content);
const documentedSet = new Set(documented);
const cataloguedKeys: ReadonlySet<string> = new Set([
...Object.values(ENV),
...Object.values(EXTERNAL_ENV),
]);
for (const key of Object.values(ENV)) {
expect(documentedSet.has(key), `missing ${key} in .env.example`).toBe(true);
}
for (const key of documented) {
expect(cataloguedKeys.has(key), `${key} in .env.example is not catalogued`).toBe(true);
}
});
it("nub.jsonc keeps a 7d cooling window with string excludes", () => {
const config = parseYaml(fs.readFileSync(NUB_JSONC_PATH, "utf8")) as {
install?: {
minimumReleaseAge?: unknown;
minimumReleaseAgeExclude?: unknown;
};
};
expect(config.install?.minimumReleaseAge).toBe("7d");
const excludes = config.install?.minimumReleaseAgeExclude;
expect(Array.isArray(excludes)).toBe(true);
expect((excludes as unknown[]).length).toBeGreaterThan(0);
for (const entry of excludes as unknown[]) {
expect(typeof entry).toBe("string");
expect((entry as string).length).toBeGreaterThan(0);
}
});
it("nub.lock overrides and importers match package.json", () => {
const pkg = JSON.parse(fs.readFileSync(PACKAGE_JSON_PATH, "utf8")) as {
overrides?: Record<string, string>;
workspaces?: string[];
};
const lock = parseYaml(fs.readFileSync(NUB_LOCK_PATH, "utf8")) as {
overrides?: Record<string, string | number>;
importers?: Record<string, unknown>;
};
expect(pkg.overrides).toBeTruthy();
expect(lock.overrides).toBeTruthy();
const pkgOverrides = pkg.overrides!;
const lockOverrides = Object.fromEntries(
Object.entries(lock.overrides!).map(([key, value]) => [key, String(value)]),
);
expect(lockOverrides).toEqual(pkgOverrides);
const workspaces = pkg.workspaces ?? [];
expect(workspaces.length).toBeGreaterThan(0);
for (const workspace of workspaces) {
const importerKey = workspace === "." ? "." : workspace;
expect(lock.importers?.[importerKey], `missing importer ${importerKey}`).toBeTruthy();
}
});
});