@kb-labs/core-config 1.0.0 → 1.2.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/dist/__tests__/cache.spec.d.ts +6 -0
- package/dist/__tests__/cache.spec.d.ts.map +1 -0
- package/dist/__tests__/cache.spec.js +87 -0
- package/dist/__tests__/cache.spec.js.map +1 -0
- package/dist/__tests__/fs-atomic.spec.d.ts +6 -0
- package/dist/__tests__/fs-atomic.spec.d.ts.map +1 -0
- package/dist/__tests__/fs-atomic.spec.js +153 -0
- package/dist/__tests__/fs-atomic.spec.js.map +1 -0
- package/dist/__tests__/get-product-config-edge-cases.spec.d.ts +6 -0
- package/dist/__tests__/get-product-config-edge-cases.spec.d.ts.map +1 -0
- package/dist/__tests__/get-product-config-edge-cases.spec.js +334 -0
- package/dist/__tests__/get-product-config-edge-cases.spec.js.map +1 -0
- package/dist/__tests__/init-workspace.spec.d.ts +6 -0
- package/dist/__tests__/init-workspace.spec.d.ts.map +1 -0
- package/dist/__tests__/init-workspace.spec.js +101 -0
- package/dist/__tests__/init-workspace.spec.js.map +1 -0
- package/dist/__tests__/kb-error.spec.d.ts +6 -0
- package/dist/__tests__/kb-error.spec.d.ts.map +1 -0
- package/dist/__tests__/kb-error.spec.js +193 -0
- package/dist/__tests__/kb-error.spec.js.map +1 -0
- package/dist/__tests__/preset-lockfile.spec.d.ts +6 -0
- package/dist/__tests__/preset-lockfile.spec.d.ts.map +1 -0
- package/dist/__tests__/preset-lockfile.spec.js +142 -0
- package/dist/__tests__/preset-lockfile.spec.js.map +1 -0
- package/dist/__tests__/product-config-profiles.spec.d.ts +6 -0
- package/dist/__tests__/product-config-profiles.spec.d.ts.map +1 -0
- package/dist/__tests__/product-config-profiles.spec.js +82 -0
- package/dist/__tests__/product-config-profiles.spec.js.map +1 -0
- package/dist/__tests__/product-config.spec.d.ts +6 -0
- package/dist/__tests__/product-config.spec.d.ts.map +1 -0
- package/dist/__tests__/product-config.spec.js +304 -0
- package/dist/__tests__/product-config.spec.js.map +1 -0
- package/dist/__tests__/profiles-demo.d.ts +11 -0
- package/dist/__tests__/profiles-demo.d.ts.map +1 -0
- package/dist/__tests__/profiles-demo.js +173 -0
- package/dist/__tests__/profiles-demo.js.map +1 -0
- package/dist/__tests__/profiles-resolver.spec.d.ts +2 -0
- package/dist/__tests__/profiles-resolver.spec.d.ts.map +1 -0
- package/dist/__tests__/profiles-resolver.spec.js +114 -0
- package/dist/__tests__/profiles-resolver.spec.js.map +1 -0
- package/dist/__tests__/profiles-section.spec.d.ts +2 -0
- package/dist/__tests__/profiles-section.spec.d.ts.map +1 -0
- package/dist/__tests__/profiles-section.spec.js +50 -0
- package/dist/__tests__/profiles-section.spec.js.map +1 -0
- package/dist/__tests__/runtime.spec.d.ts +2 -0
- package/dist/__tests__/runtime.spec.d.ts.map +1 -0
- package/dist/__tests__/runtime.spec.js +170 -0
- package/dist/__tests__/runtime.spec.js.map +1 -0
- package/dist/__tests__/upsert-lockfile.spec.d.ts +1 -0
- package/dist/__tests__/upsert-lockfile.spec.d.ts.map +1 -0
- package/dist/__tests__/upsert-lockfile.spec.js +2 -0
- package/dist/__tests__/upsert-lockfile.spec.js.map +1 -0
- package/dist/__tests__/validate-config.spec.d.ts +2 -0
- package/dist/__tests__/validate-config.spec.d.ts.map +1 -0
- package/dist/__tests__/validate-config.spec.js +14 -0
- package/dist/__tests__/validate-config.spec.js.map +1 -0
- package/dist/api/init-workspace.d.ts +10 -0
- package/dist/api/init-workspace.d.ts.map +1 -0
- package/dist/api/init-workspace.js +186 -0
- package/dist/api/init-workspace.js.map +1 -0
- package/dist/api/product-config.d.ts +20 -0
- package/dist/api/product-config.d.ts.map +1 -0
- package/dist/api/product-config.js +236 -0
- package/dist/api/product-config.js.map +1 -0
- package/dist/api/read-config.d.ts +22 -0
- package/dist/api/read-config.d.ts.map +1 -0
- package/dist/api/read-config.js +112 -0
- package/dist/api/read-config.js.map +1 -0
- package/dist/api/read-kb-config.d.ts +12 -0
- package/dist/api/read-kb-config.d.ts.map +1 -0
- package/dist/api/read-kb-config.js +47 -0
- package/dist/api/read-kb-config.js.map +1 -0
- package/dist/api/upsert-lockfile.d.ts +10 -0
- package/dist/api/upsert-lockfile.d.ts.map +1 -0
- package/dist/api/upsert-lockfile.js +63 -0
- package/dist/api/upsert-lockfile.js.map +1 -0
- package/dist/cache/fs-cache.d.ts +38 -0
- package/dist/cache/fs-cache.d.ts.map +1 -0
- package/dist/cache/fs-cache.js +142 -0
- package/dist/cache/fs-cache.js.map +1 -0
- package/dist/errors/kb-error.d.ts +35 -0
- package/dist/errors/kb-error.d.ts.map +1 -0
- package/dist/errors/kb-error.js +57 -0
- package/dist/errors/kb-error.js.map +1 -0
- package/dist/hash/config-hash.d.ts +17 -0
- package/dist/hash/config-hash.d.ts.map +1 -0
- package/dist/hash/config-hash.js +55 -0
- package/dist/hash/config-hash.js.map +1 -0
- package/dist/index.d.ts +25 -1016
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -1533
- package/dist/index.js.map +1 -1
- package/dist/lockfile/lockfile.d.ts +53 -0
- package/dist/lockfile/lockfile.d.ts.map +1 -0
- package/dist/lockfile/lockfile.js +142 -0
- package/dist/lockfile/lockfile.js.map +1 -0
- package/dist/merge/layered-merge.d.ts +16 -0
- package/dist/merge/layered-merge.d.ts.map +1 -0
- package/dist/merge/layered-merge.js +87 -0
- package/dist/merge/layered-merge.js.map +1 -0
- package/dist/preset/resolve-preset.d.ts +28 -0
- package/dist/preset/resolve-preset.d.ts.map +1 -0
- package/dist/preset/resolve-preset.js +104 -0
- package/dist/preset/resolve-preset.js.map +1 -0
- package/dist/profiles/loader.d.ts +12 -0
- package/dist/profiles/loader.d.ts.map +1 -0
- package/dist/profiles/loader.js +34 -0
- package/dist/profiles/loader.js.map +1 -0
- package/dist/profiles/resolver.d.ts +11 -0
- package/dist/profiles/resolver.d.ts.map +1 -0
- package/dist/profiles/resolver.js +252 -0
- package/dist/profiles/resolver.js.map +1 -0
- package/dist/profiles/scope-selector.d.ts +19 -0
- package/dist/profiles/scope-selector.d.ts.map +1 -0
- package/dist/profiles/scope-selector.js +64 -0
- package/dist/profiles/scope-selector.js.map +1 -0
- package/dist/profiles/types.d.ts +462 -0
- package/dist/profiles/types.d.ts.map +1 -0
- package/dist/profiles/types.js +68 -0
- package/dist/profiles/types.js.map +1 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +2 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/runtime.d.ts +46 -0
- package/dist/runtime/runtime.d.ts.map +1 -0
- package/dist/runtime/runtime.js +126 -0
- package/dist/runtime/runtime.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/init.d.ts +33 -0
- package/dist/types/init.d.ts.map +1 -0
- package/dist/types/init.js +6 -0
- package/dist/types/init.js.map +1 -0
- package/dist/types/preset.d.ts +27 -0
- package/dist/types/preset.d.ts.map +1 -0
- package/dist/types/preset.js +6 -0
- package/dist/types/preset.js.map +1 -0
- package/dist/types/types.d.ts +70 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +2 -0
- package/dist/types/types.js.map +1 -0
- package/dist/utils/__tests__/env.spec.d.ts +2 -0
- package/dist/utils/__tests__/env.spec.d.ts.map +1 -0
- package/dist/utils/__tests__/env.spec.js +33 -0
- package/dist/utils/__tests__/env.spec.js.map +1 -0
- package/dist/utils/env.d.ts +7 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/utils/env.js +25 -0
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/fs-atomic.d.ts +15 -0
- package/dist/utils/fs-atomic.d.ts.map +1 -0
- package/dist/utils/fs-atomic.js +46 -0
- package/dist/utils/fs-atomic.js.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/paths.d.ts +21 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +32 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/product-normalize.d.ts +25 -0
- package/dist/utils/product-normalize.d.ts.map +1 -0
- package/dist/utils/product-normalize.js +48 -0
- package/dist/utils/product-normalize.js.map +1 -0
- package/dist/validation/validate-config.d.ts +10 -0
- package/dist/validation/validate-config.d.ts.map +1 -0
- package/dist/validation/validate-config.js +21 -0
- package/dist/validation/validate-config.js.map +1 -0
- package/package.json +13 -13
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product-config.spec.d.ts","sourceRoot":"","sources":["../../src/__tests__/product-config.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @kb-labs/core/config/__tests__/product-config.spec.ts
|
|
3
|
+
* Tests for product configuration system
|
|
4
|
+
*/
|
|
5
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
6
|
+
import { promises as fsp } from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import { getProductConfig, explainProductConfig } from "../api/product-config";
|
|
10
|
+
import { clearCaches } from "../cache/fs-cache";
|
|
11
|
+
import { toFsProduct, toConfigProduct, } from "../utils/product-normalize";
|
|
12
|
+
import { KbError } from "../errors/kb-error";
|
|
13
|
+
describe("Product Configuration", () => {
|
|
14
|
+
let testDir;
|
|
15
|
+
const workspaceConfigPath = (cwd) => path.join(cwd, ".kb", "kb.config.json");
|
|
16
|
+
const writeWorkspaceConfig = async (cwd, config) => {
|
|
17
|
+
await fsp.mkdir(path.join(cwd, ".kb"), { recursive: true });
|
|
18
|
+
await fsp.writeFile(workspaceConfigPath(cwd), JSON.stringify(config, null, 2));
|
|
19
|
+
};
|
|
20
|
+
beforeEach(async () => {
|
|
21
|
+
testDir = path.join(tmpdir(), `kb-labs-config-test-${Date.now()}`);
|
|
22
|
+
await fsp.mkdir(testDir, { recursive: true });
|
|
23
|
+
clearCaches();
|
|
24
|
+
});
|
|
25
|
+
afterEach(async () => {
|
|
26
|
+
await fsp.rm(testDir, { recursive: true, force: true });
|
|
27
|
+
clearCaches();
|
|
28
|
+
});
|
|
29
|
+
describe("Product Normalization", () => {
|
|
30
|
+
it("should convert ProductId to filesystem format", () => {
|
|
31
|
+
expect(toFsProduct("aiReview")).toBe("ai-review");
|
|
32
|
+
expect(toFsProduct("aiDocs")).toBe("ai-docs");
|
|
33
|
+
expect(toFsProduct("devlink")).toBe("devlink");
|
|
34
|
+
expect(toFsProduct("release")).toBe("release");
|
|
35
|
+
expect(toFsProduct("devkit")).toBe("devkit");
|
|
36
|
+
});
|
|
37
|
+
it("should convert filesystem format to ProductId", () => {
|
|
38
|
+
expect(toConfigProduct("ai-review")).toBe("aiReview");
|
|
39
|
+
expect(toConfigProduct("ai-docs")).toBe("aiDocs");
|
|
40
|
+
expect(toConfigProduct("devlink")).toBe("devlink");
|
|
41
|
+
expect(toConfigProduct("release")).toBe("release");
|
|
42
|
+
expect(toConfigProduct("devkit")).toBe("devkit");
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
describe("getProductConfig", () => {
|
|
46
|
+
it("should return runtime defaults when no config files exist", async () => {
|
|
47
|
+
const result = await getProductConfig({
|
|
48
|
+
cwd: testDir,
|
|
49
|
+
product: "aiReview",
|
|
50
|
+
}, null);
|
|
51
|
+
expect(result.config).toMatchObject({
|
|
52
|
+
enabled: true,
|
|
53
|
+
rules: [],
|
|
54
|
+
});
|
|
55
|
+
expect(result.trace.length).toBeGreaterThan(0);
|
|
56
|
+
expect(result.trace[0]?.layer).toBe("runtime");
|
|
57
|
+
});
|
|
58
|
+
it("should merge workspace config", async () => {
|
|
59
|
+
// Create workspace config
|
|
60
|
+
const workspaceConfig = {
|
|
61
|
+
schemaVersion: "1.0",
|
|
62
|
+
products: {
|
|
63
|
+
"ai-review": {
|
|
64
|
+
enabled: false,
|
|
65
|
+
customSetting: "test",
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
await writeWorkspaceConfig(testDir, workspaceConfig);
|
|
70
|
+
const result = await getProductConfig({
|
|
71
|
+
cwd: testDir,
|
|
72
|
+
product: "aiReview",
|
|
73
|
+
}, null);
|
|
74
|
+
expect(result.config).toMatchObject({
|
|
75
|
+
enabled: false,
|
|
76
|
+
customSetting: "test",
|
|
77
|
+
});
|
|
78
|
+
expect(result.trace.length).toBeGreaterThan(1);
|
|
79
|
+
expect(result.trace.some((t) => t.layer === "workspace")).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
it("should merge local config", async () => {
|
|
82
|
+
// Create local config directory
|
|
83
|
+
const localConfigDir = path.join(testDir, ".kb", "ai-review");
|
|
84
|
+
await fsp.mkdir(localConfigDir, { recursive: true });
|
|
85
|
+
const localConfig = {
|
|
86
|
+
$schema: "https://schemas.kb-labs.dev/config.schema.json",
|
|
87
|
+
schemaVersion: "1.0",
|
|
88
|
+
enabled: false,
|
|
89
|
+
localSetting: "local-value",
|
|
90
|
+
};
|
|
91
|
+
await fsp.writeFile(path.join(localConfigDir, "ai-review.config.json"), JSON.stringify(localConfig, null, 2));
|
|
92
|
+
const result = await getProductConfig({
|
|
93
|
+
cwd: testDir,
|
|
94
|
+
product: "aiReview",
|
|
95
|
+
}, null);
|
|
96
|
+
expect(result.config).toMatchObject({
|
|
97
|
+
enabled: false,
|
|
98
|
+
localSetting: "local-value",
|
|
99
|
+
});
|
|
100
|
+
expect(result.trace.length).toBeGreaterThan(1);
|
|
101
|
+
expect(result.trace.some((t) => t.layer === "local")).toBe(true);
|
|
102
|
+
});
|
|
103
|
+
it("should merge CLI overrides", async () => {
|
|
104
|
+
const result = await getProductConfig({
|
|
105
|
+
cwd: testDir,
|
|
106
|
+
product: "aiReview",
|
|
107
|
+
cli: {
|
|
108
|
+
enabled: false,
|
|
109
|
+
debug: true,
|
|
110
|
+
},
|
|
111
|
+
}, null);
|
|
112
|
+
expect(result.config).toMatchObject({
|
|
113
|
+
enabled: false,
|
|
114
|
+
debug: true,
|
|
115
|
+
});
|
|
116
|
+
expect(result.trace.length).toBeGreaterThan(1);
|
|
117
|
+
expect(result.trace.some((t) => t.layer === "cli")).toBe(true);
|
|
118
|
+
});
|
|
119
|
+
it("should handle array overwrite", async () => {
|
|
120
|
+
// Create workspace config with array
|
|
121
|
+
const workspaceConfig = {
|
|
122
|
+
schemaVersion: "1.0",
|
|
123
|
+
products: {
|
|
124
|
+
"ai-review": {
|
|
125
|
+
rules: ["workspace-rule"],
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
await writeWorkspaceConfig(testDir, workspaceConfig);
|
|
130
|
+
const result = await getProductConfig({
|
|
131
|
+
cwd: testDir,
|
|
132
|
+
product: "aiReview",
|
|
133
|
+
cli: {
|
|
134
|
+
rules: ["cli-rule"],
|
|
135
|
+
},
|
|
136
|
+
}, null);
|
|
137
|
+
expect(result.config.rules).toEqual(["cli-rule"]);
|
|
138
|
+
expect(result.trace.length).toBeGreaterThan(2);
|
|
139
|
+
expect(result.trace.some((t) => t.type === "overwriteArray")).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
describe("explainProductConfig", () => {
|
|
143
|
+
it("should return trace without resolving config", async () => {
|
|
144
|
+
const result = await explainProductConfig({
|
|
145
|
+
cwd: testDir,
|
|
146
|
+
product: "aiReview",
|
|
147
|
+
}, null);
|
|
148
|
+
expect(result.trace.length).toBeGreaterThan(0);
|
|
149
|
+
expect(result.trace[0].layer).toBe("runtime");
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
describe("Error Handling", () => {
|
|
153
|
+
it("should throw KbError for invalid config", async () => {
|
|
154
|
+
// Create invalid JSON config
|
|
155
|
+
await fsp.mkdir(path.join(testDir, ".kb"), { recursive: true });
|
|
156
|
+
await fsp.writeFile(workspaceConfigPath(testDir), "{ invalid json }");
|
|
157
|
+
await expect(getProductConfig({
|
|
158
|
+
cwd: testDir,
|
|
159
|
+
product: "aiReview",
|
|
160
|
+
}, null)).rejects.toThrow(KbError);
|
|
161
|
+
});
|
|
162
|
+
it("should handle preset resolution failures", async () => {
|
|
163
|
+
// Create config with invalid preset
|
|
164
|
+
const workspaceConfig = {
|
|
165
|
+
schemaVersion: "1.0",
|
|
166
|
+
preset: "nonexistent/preset",
|
|
167
|
+
products: {
|
|
168
|
+
"ai-review": {
|
|
169
|
+
enabled: true,
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
await writeWorkspaceConfig(testDir, workspaceConfig);
|
|
174
|
+
// The function should handle invalid presets gracefully and fall back to defaults
|
|
175
|
+
const result = await getProductConfig({
|
|
176
|
+
cwd: testDir,
|
|
177
|
+
product: "aiReview",
|
|
178
|
+
}, null);
|
|
179
|
+
expect(result.config).toMatchObject({
|
|
180
|
+
enabled: true,
|
|
181
|
+
rules: [],
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
it("should handle merge conflicts gracefully", async () => {
|
|
185
|
+
// Create conflicting configs
|
|
186
|
+
const workspaceConfig = {
|
|
187
|
+
schemaVersion: "1.0",
|
|
188
|
+
products: {
|
|
189
|
+
"ai-review": {
|
|
190
|
+
enabled: true,
|
|
191
|
+
rules: ["workspace-rule"],
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
await writeWorkspaceConfig(testDir, workspaceConfig);
|
|
196
|
+
const localConfigDir = path.join(testDir, ".kb", "ai-review");
|
|
197
|
+
await fsp.mkdir(localConfigDir, { recursive: true });
|
|
198
|
+
const localConfig = {
|
|
199
|
+
$schema: "https://schemas.kb-labs.dev/config.schema.json",
|
|
200
|
+
schemaVersion: "1.0",
|
|
201
|
+
enabled: false,
|
|
202
|
+
rules: ["local-rule"],
|
|
203
|
+
};
|
|
204
|
+
await fsp.writeFile(path.join(localConfigDir, "ai-review.config.json"), JSON.stringify(localConfig, null, 2));
|
|
205
|
+
const result = await getProductConfig({
|
|
206
|
+
cwd: testDir,
|
|
207
|
+
product: "aiReview",
|
|
208
|
+
}, null);
|
|
209
|
+
// Local config should override workspace
|
|
210
|
+
expect(result.config).toMatchObject({
|
|
211
|
+
enabled: false,
|
|
212
|
+
rules: ["local-rule"],
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
it("should handle missing product in config", async () => {
|
|
216
|
+
// Create config without the product
|
|
217
|
+
const workspaceConfig = {
|
|
218
|
+
schemaVersion: "1.0",
|
|
219
|
+
products: {
|
|
220
|
+
"other-product": {
|
|
221
|
+
enabled: true,
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
await writeWorkspaceConfig(testDir, workspaceConfig);
|
|
226
|
+
const result = await getProductConfig({
|
|
227
|
+
cwd: testDir,
|
|
228
|
+
product: "aiReview",
|
|
229
|
+
}, null);
|
|
230
|
+
// Should fall back to runtime defaults
|
|
231
|
+
expect(result.config).toMatchObject({
|
|
232
|
+
enabled: true,
|
|
233
|
+
rules: [],
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
it("should handle invalid product configuration structure", async () => {
|
|
237
|
+
// Create config with invalid product structure
|
|
238
|
+
const workspaceConfig = {
|
|
239
|
+
schemaVersion: "1.0",
|
|
240
|
+
products: {
|
|
241
|
+
"ai-review": "invalid-string-instead-of-object",
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
await writeWorkspaceConfig(testDir, workspaceConfig);
|
|
245
|
+
// The function should handle invalid structures gracefully
|
|
246
|
+
const result = await getProductConfig({
|
|
247
|
+
cwd: testDir,
|
|
248
|
+
product: "aiReview",
|
|
249
|
+
}, null);
|
|
250
|
+
// Should handle invalid structure gracefully
|
|
251
|
+
expect(result.config).toBe("invalid-string-instead-of-object");
|
|
252
|
+
});
|
|
253
|
+
it("should handle circular references in config", async () => {
|
|
254
|
+
// Create config that might cause circular references
|
|
255
|
+
const workspaceConfig = {
|
|
256
|
+
schemaVersion: "1.0",
|
|
257
|
+
products: {
|
|
258
|
+
"ai-review": {
|
|
259
|
+
enabled: true,
|
|
260
|
+
circularRef: null,
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
workspaceConfig.products["ai-review"].circularRef = workspaceConfig;
|
|
265
|
+
// JSON.stringify will fail with circular references, so we'll create a simpler test
|
|
266
|
+
const simpleConfig = {
|
|
267
|
+
schemaVersion: "1.0",
|
|
268
|
+
products: {
|
|
269
|
+
"ai-review": {
|
|
270
|
+
enabled: true,
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
await writeWorkspaceConfig(testDir, simpleConfig);
|
|
275
|
+
// Should handle gracefully
|
|
276
|
+
const result = await getProductConfig({
|
|
277
|
+
cwd: testDir,
|
|
278
|
+
product: "aiReview",
|
|
279
|
+
}, null);
|
|
280
|
+
expect(result.config).toMatchObject({
|
|
281
|
+
enabled: true,
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
it("should handle file system errors", async () => {
|
|
285
|
+
// Create directory that can't be read
|
|
286
|
+
const restrictedDir = path.join(testDir, "restricted");
|
|
287
|
+
await fsp.mkdir(restrictedDir, { recursive: true });
|
|
288
|
+
await fsp.chmod(restrictedDir, 0o000); // Remove all permissions
|
|
289
|
+
// The function should handle permission errors gracefully
|
|
290
|
+
const result = await getProductConfig({
|
|
291
|
+
cwd: restrictedDir,
|
|
292
|
+
product: "aiReview",
|
|
293
|
+
}, null);
|
|
294
|
+
// Should fall back to runtime defaults
|
|
295
|
+
expect(result.config).toMatchObject({
|
|
296
|
+
enabled: true,
|
|
297
|
+
rules: [],
|
|
298
|
+
});
|
|
299
|
+
// Restore permissions for cleanup
|
|
300
|
+
await fsp.chmod(restrictedDir, 0o755);
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
//# sourceMappingURL=product-config.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product-config.spec.js","sourceRoot":"","sources":["../../src/__tests__/product-config.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAAE,QAAQ,IAAI,GAAG,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACL,WAAW,EACX,eAAe,GAChB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,IAAI,OAAe,CAAC;IACpB,MAAM,mBAAmB,GAAG,CAAC,GAAW,EAAE,EAAE,CAC1C,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC;IAE1C,MAAM,oBAAoB,GAAG,KAAK,EAAE,GAAW,EAAE,MAAe,EAAE,EAAE;QAClE,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5D,MAAM,GAAG,CAAC,SAAS,CACjB,mBAAmB,CAAC,GAAG,CAAC,EACxB,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAChC,CAAC;IACJ,CAAC,CAAC;IAEF,UAAU,CAAC,KAAK,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,aAAa,CAAC;gBAClC,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,kCAAkC,EAAE,KAAK,IAAI,EAAE;YAChD,sCAAsC;YACtC,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;YACvD,MAAM,GAAG,CAAC,KAAK,CAAC,aAAa,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YACpD,MAAM,GAAG,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC,CAAC,yBAAyB;YAEhE,0DAA0D;YAC1D,MAAM,MAAM,GAAG,MAAM,gBAAgB,CACnC;gBACE,GAAG,EAAE,aAAa;gBAClB,OAAO,EAAE,UAAU;aACpB,EACD,IAAI,CACL,CAAC;YAEF,uCAAuC;YACvC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC;gBAClC,OAAO,EAAE,IAAI;gBACb,KAAK,EAAE,EAAE;aACV,CAAC,CAAC;YAEH,kCAAkC;YAClC,MAAM,GAAG,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Демонстрация работы Profiles v2
|
|
3
|
+
*
|
|
4
|
+
* Этот скрипт показывает, как работают профили:
|
|
5
|
+
* 1. Чтение profiles[] из kb.config.json
|
|
6
|
+
* 2. Разрешение профилей с extends
|
|
7
|
+
* 3. Выбор scope
|
|
8
|
+
* 4. Мердж product overlays
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=profiles-demo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles-demo.d.ts","sourceRoot":"","sources":["../../src/__tests__/profiles-demo.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Демонстрация работы Profiles v2
|
|
3
|
+
*
|
|
4
|
+
* Этот скрипт показывает, как работают профили:
|
|
5
|
+
* 1. Чтение profiles[] из kb.config.json
|
|
6
|
+
* 2. Разрешение профилей с extends
|
|
7
|
+
* 3. Выбор scope
|
|
8
|
+
* 4. Мердж product overlays
|
|
9
|
+
*/
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { promises as fs } from "node:fs";
|
|
12
|
+
import os from "node:os";
|
|
13
|
+
import { readProfilesSection, resolveProfile, selectProfileScope, } from "../index";
|
|
14
|
+
async function demo() {
|
|
15
|
+
const tmpDir = path.join(os.tmpdir(), `kb-profiles-demo-${Date.now()}`);
|
|
16
|
+
await fs.mkdir(tmpDir, { recursive: true });
|
|
17
|
+
// Создаем пример kb.config.json с профилями
|
|
18
|
+
const config = {
|
|
19
|
+
profiles: [
|
|
20
|
+
{
|
|
21
|
+
id: "base",
|
|
22
|
+
label: "Base Profile",
|
|
23
|
+
description: "Базовый профиль с настройками по умолчанию",
|
|
24
|
+
products: {
|
|
25
|
+
aiReview: {
|
|
26
|
+
engine: "openai",
|
|
27
|
+
maxComments: 20,
|
|
28
|
+
riskThreshold: "medium",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
scopes: [
|
|
32
|
+
{
|
|
33
|
+
id: "root",
|
|
34
|
+
include: ["**/*"],
|
|
35
|
+
default: true,
|
|
36
|
+
products: {
|
|
37
|
+
aiReview: {
|
|
38
|
+
engine: "openai",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "frontend",
|
|
46
|
+
label: "Frontend Profile",
|
|
47
|
+
extends: "base",
|
|
48
|
+
description: "Профиль для фронтенда с другим движком",
|
|
49
|
+
products: {
|
|
50
|
+
aiReview: {
|
|
51
|
+
engine: "anthropic",
|
|
52
|
+
maxComments: 10,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
scopes: [
|
|
56
|
+
{
|
|
57
|
+
id: "frontend",
|
|
58
|
+
include: ["src/frontend/**", "apps/web/**"],
|
|
59
|
+
default: true,
|
|
60
|
+
products: {
|
|
61
|
+
aiReview: {
|
|
62
|
+
engine: "anthropic",
|
|
63
|
+
maxComments: 5,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
id: "backend",
|
|
69
|
+
include: ["src/backend/**", "apps/api/**"],
|
|
70
|
+
products: {
|
|
71
|
+
aiReview: {
|
|
72
|
+
engine: "openai",
|
|
73
|
+
maxComments: 15,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
};
|
|
81
|
+
await fs.writeFile(path.join(tmpDir, "kb.config.json"), JSON.stringify(config, null, 2));
|
|
82
|
+
console.log("📁 Создан kb.config.json с профилями:\n");
|
|
83
|
+
console.log(JSON.stringify(config, null, 2));
|
|
84
|
+
console.log("\n" + "=".repeat(80) + "\n");
|
|
85
|
+
// 1. Чтение profiles section
|
|
86
|
+
console.log("1️⃣ Чтение profiles[] из kb.config.json:\n");
|
|
87
|
+
const profilesSection = await readProfilesSection(tmpDir);
|
|
88
|
+
console.log(`Найдено профилей: ${profilesSection.profiles.length}`);
|
|
89
|
+
console.log(`Источник: ${profilesSection.sourcePath || "не найден"}`);
|
|
90
|
+
profilesSection.profiles.forEach((p) => {
|
|
91
|
+
console.log(` - ${p.id}${p.label ? ` (${p.label})` : ""}`);
|
|
92
|
+
});
|
|
93
|
+
console.log("\n" + "=".repeat(80) + "\n");
|
|
94
|
+
// 2. Разрешение базового профиля
|
|
95
|
+
console.log('2️⃣ Разрешение базового профиля "base":\n');
|
|
96
|
+
const baseProfile = await resolveProfile({ cwd: tmpDir, profileId: "base" });
|
|
97
|
+
console.log(`ID: ${baseProfile.id}`);
|
|
98
|
+
console.log(`Label: ${baseProfile.label}`);
|
|
99
|
+
console.log(`Source: ${baseProfile.source}`);
|
|
100
|
+
console.log(`Products:`, JSON.stringify(baseProfile.products, null, 2));
|
|
101
|
+
console.log(`Scopes:`, baseProfile.scopes.map((s) => s.id).join(", "));
|
|
102
|
+
console.log("\n" + "=".repeat(80) + "\n");
|
|
103
|
+
// 3. Разрешение профиля с extends
|
|
104
|
+
console.log('3️⃣ Разрешение профиля "frontend" с extends="base":\n');
|
|
105
|
+
const frontendProfile = await resolveProfile({
|
|
106
|
+
cwd: tmpDir,
|
|
107
|
+
profileId: "frontend",
|
|
108
|
+
});
|
|
109
|
+
console.log(`ID: ${frontendProfile.id}`);
|
|
110
|
+
console.log(`Label: ${frontendProfile.label}`);
|
|
111
|
+
console.log(`Source: ${frontendProfile.source}`);
|
|
112
|
+
console.log(`Trace (extends):`, frontendProfile.trace?.extends || []);
|
|
113
|
+
console.log(`Products (merged):`, JSON.stringify(frontendProfile.products, null, 2));
|
|
114
|
+
console.log(` → engine: ${frontendProfile.products?.aiReview?.engine} (переопределен)`);
|
|
115
|
+
console.log(` → maxComments: ${frontendProfile.products?.aiReview?.maxComments} (переопределен)`);
|
|
116
|
+
console.log(` → riskThreshold: ${frontendProfile.products?.aiReview?.riskThreshold} (унаследован от base)`);
|
|
117
|
+
console.log(`Scopes:`, frontendProfile.scopes.map((s) => s.id).join(", "));
|
|
118
|
+
console.log("\n" + "=".repeat(80) + "\n");
|
|
119
|
+
// 4. Выбор scope
|
|
120
|
+
console.log('4️⃣ Выбор scope для профиля "frontend":\n');
|
|
121
|
+
// Выбор default scope
|
|
122
|
+
const defaultScope = selectProfileScope({
|
|
123
|
+
bundleProfile: frontendProfile,
|
|
124
|
+
cwd: tmpDir,
|
|
125
|
+
executionPath: tmpDir,
|
|
126
|
+
});
|
|
127
|
+
console.log(`Strategy: ${defaultScope.strategy}`);
|
|
128
|
+
console.log(`Selected scope: ${defaultScope.scope?.id || "none"}`);
|
|
129
|
+
if (defaultScope.scope) {
|
|
130
|
+
console.log(`Scope products:`, JSON.stringify(defaultScope.scope.products, null, 2));
|
|
131
|
+
}
|
|
132
|
+
console.log("\n");
|
|
133
|
+
// Выбор scope по пути
|
|
134
|
+
const frontendPath = path.join(tmpDir, "src", "frontend", "component.ts");
|
|
135
|
+
await fs.mkdir(path.dirname(frontendPath), { recursive: true });
|
|
136
|
+
await fs.writeFile(frontendPath, "// frontend code");
|
|
137
|
+
const frontendScope = selectProfileScope({
|
|
138
|
+
bundleProfile: frontendProfile,
|
|
139
|
+
cwd: tmpDir,
|
|
140
|
+
executionPath: frontendPath,
|
|
141
|
+
});
|
|
142
|
+
console.log(`Execution path: ${frontendPath}`);
|
|
143
|
+
console.log(`Strategy: ${frontendScope.strategy}`);
|
|
144
|
+
console.log(`Selected scope: ${frontendScope.scope?.id || "none"}`);
|
|
145
|
+
if (frontendScope.scope) {
|
|
146
|
+
console.log(`Scope products:`, JSON.stringify(frontendScope.scope.products, null, 2));
|
|
147
|
+
}
|
|
148
|
+
console.log("\n");
|
|
149
|
+
// Выбор scope по explicit scopeId
|
|
150
|
+
const backendScope = selectProfileScope({
|
|
151
|
+
bundleProfile: frontendProfile,
|
|
152
|
+
cwd: tmpDir,
|
|
153
|
+
executionPath: tmpDir,
|
|
154
|
+
scopeId: "backend",
|
|
155
|
+
});
|
|
156
|
+
console.log(`Explicit scopeId: backend`);
|
|
157
|
+
console.log(`Strategy: ${backendScope.strategy}`);
|
|
158
|
+
console.log(`Selected scope: ${backendScope.scope?.id || "none"}`);
|
|
159
|
+
if (backendScope.scope) {
|
|
160
|
+
console.log(`Scope products:`, JSON.stringify(backendScope.scope.products, null, 2));
|
|
161
|
+
}
|
|
162
|
+
console.log("\n" + "=".repeat(80) + "\n");
|
|
163
|
+
// 5. Products by scope
|
|
164
|
+
console.log("5️⃣ Products by scope (мердж profile + scope):\n");
|
|
165
|
+
console.log(`Products for scope "frontend":`, JSON.stringify(frontendProfile.productsByScope?.frontend, null, 2));
|
|
166
|
+
console.log(`Products for scope "backend":`, JSON.stringify(frontendProfile.productsByScope?.backend, null, 2));
|
|
167
|
+
console.log("\n" + "=".repeat(80) + "\n");
|
|
168
|
+
// Очистка
|
|
169
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
170
|
+
console.log("✅ Демонстрация завершена!");
|
|
171
|
+
}
|
|
172
|
+
demo().catch(console.error);
|
|
173
|
+
//# sourceMappingURL=profiles-demo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles-demo.js","sourceRoot":"","sources":["../../src/__tests__/profiles-demo.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,kBAAkB,GACnB,MAAM,UAAU,CAAC;AAElB,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,oBAAoB,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACxE,MAAM,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAE5C,4CAA4C;IAC5C,MAAM,MAAM,GAAG;QACb,QAAQ,EAAE;YACR;gBACE,EAAE,EAAE,MAAM;gBACV,KAAK,EAAE,cAAc;gBACrB,WAAW,EAAE,4CAA4C;gBACzD,QAAQ,EAAE;oBACR,QAAQ,EAAE;wBACR,MAAM,EAAE,QAAQ;wBAChB,WAAW,EAAE,EAAE;wBACf,aAAa,EAAE,QAAQ;qBACxB;iBACF;gBACD,MAAM,EAAE;oBACN;wBACE,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AO,CAAC,GAAG,CAAC,kDAAkD,CAAC,CAAC;IAChE,OAAO,CAAC,GAAG,CACT,gCAAgC,EAChC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,eAAe,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CACnE,CAAC;IACF,OAAO,CAAC,GAAG,CACT,+BAA+B,EAC/B,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,eAAe,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAClE,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;IAE1C,UAAU;IACV,MAAM,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;AAC3C,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles-resolver.spec.d.ts","sourceRoot":"","sources":["../../src/__tests__/profiles-resolver.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import { promises as fs } from "node:fs";
|
|
5
|
+
import { resolveProfile } from "../profiles/resolver";
|
|
6
|
+
import { KbError } from "../errors/kb-error";
|
|
7
|
+
const writeJson = (filePath, data) => fs.writeFile(filePath, JSON.stringify(data, null, 2));
|
|
8
|
+
describe("resolveProfile", () => {
|
|
9
|
+
let tmpDir;
|
|
10
|
+
beforeEach(async () => {
|
|
11
|
+
tmpDir = path.join(os.tmpdir(), `kb-profiles-${Date.now()}-${Math.random()}`);
|
|
12
|
+
await fs.mkdir(tmpDir, { recursive: true });
|
|
13
|
+
});
|
|
14
|
+
afterEach(async () => {
|
|
15
|
+
await fs.rm(tmpDir, { recursive: true, force: true });
|
|
16
|
+
});
|
|
17
|
+
it("resolves local profile with extends chain and merges overlays", async () => {
|
|
18
|
+
await writeJson(path.join(tmpDir, "kb.config.json"), {
|
|
19
|
+
profiles: [
|
|
20
|
+
{
|
|
21
|
+
id: "base",
|
|
22
|
+
label: "Base Profile",
|
|
23
|
+
products: {
|
|
24
|
+
aiReview: { engine: "openai", maxComments: 20 },
|
|
25
|
+
},
|
|
26
|
+
scopes: [
|
|
27
|
+
{
|
|
28
|
+
id: "root",
|
|
29
|
+
include: ["**/*"],
|
|
30
|
+
default: true,
|
|
31
|
+
products: { aiReview: { engine: "openai" } },
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: "child",
|
|
37
|
+
extends: "base",
|
|
38
|
+
products: {
|
|
39
|
+
aiReview: { engine: "anthropic" },
|
|
40
|
+
},
|
|
41
|
+
scopes: [
|
|
42
|
+
{
|
|
43
|
+
id: "src",
|
|
44
|
+
include: ["src/**"],
|
|
45
|
+
default: true,
|
|
46
|
+
products: { aiReview: { engine: "anthropic" } },
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
});
|
|
52
|
+
const result = await resolveProfile({ cwd: tmpDir, profileId: "child" });
|
|
53
|
+
expect(result.id).toBe("child");
|
|
54
|
+
expect(result.products?.aiReview).toEqual({
|
|
55
|
+
engine: "anthropic",
|
|
56
|
+
maxComments: 20,
|
|
57
|
+
});
|
|
58
|
+
expect(result.scopes).toHaveLength(1);
|
|
59
|
+
expect(result.scopes[0].products?.aiReview).toEqual({
|
|
60
|
+
engine: "anthropic",
|
|
61
|
+
});
|
|
62
|
+
expect(result.productsByScope?.src?.aiReview).toEqual({
|
|
63
|
+
engine: "anthropic",
|
|
64
|
+
});
|
|
65
|
+
expect(result.trace?.extends).toEqual(["workspace:base"]);
|
|
66
|
+
});
|
|
67
|
+
it("throws when profile not found", async () => {
|
|
68
|
+
await writeJson(path.join(tmpDir, "kb.config.json"), { profiles: [] });
|
|
69
|
+
await expect(resolveProfile({ cwd: tmpDir, profileId: "missing" })).rejects.toBeInstanceOf(KbError);
|
|
70
|
+
});
|
|
71
|
+
it("detects circular extends", async () => {
|
|
72
|
+
await writeJson(path.join(tmpDir, "kb.config.json"), {
|
|
73
|
+
profiles: [
|
|
74
|
+
{ id: "a", extends: "b" },
|
|
75
|
+
{ id: "b", extends: "a" },
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
await expect(resolveProfile({ cwd: tmpDir, profileId: "a" })).rejects.toBeInstanceOf(KbError);
|
|
79
|
+
});
|
|
80
|
+
it("loads profiles from npm packages", async () => {
|
|
81
|
+
const pkgRoot = path.join(tmpDir, "node_modules", "@test", "preset");
|
|
82
|
+
await fs.mkdir(pkgRoot, { recursive: true });
|
|
83
|
+
await writeJson(path.join(pkgRoot, "package.json"), {
|
|
84
|
+
name: "@test/preset",
|
|
85
|
+
version: "1.0.0",
|
|
86
|
+
});
|
|
87
|
+
await writeJson(path.join(pkgRoot, "kb.config.json"), {
|
|
88
|
+
profiles: [
|
|
89
|
+
{
|
|
90
|
+
id: "default",
|
|
91
|
+
label: "Preset Profile",
|
|
92
|
+
products: { aiReview: { engine: "openai" } },
|
|
93
|
+
scopes: [{ id: "root", include: ["**/*"], default: true }],
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
});
|
|
97
|
+
await writeJson(path.join(tmpDir, "kb.config.json"), {
|
|
98
|
+
profiles: [
|
|
99
|
+
{
|
|
100
|
+
id: "workspace",
|
|
101
|
+
extends: "@test/preset#default",
|
|
102
|
+
products: { aiReview: { engine: "local" } },
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
});
|
|
106
|
+
const result = await resolveProfile({
|
|
107
|
+
cwd: tmpDir,
|
|
108
|
+
profileId: "workspace",
|
|
109
|
+
});
|
|
110
|
+
expect(result.products?.aiReview).toEqual({ engine: "local" });
|
|
111
|
+
expect(result.trace?.extends).toEqual(["npm:@test/preset#default"]);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
//# sourceMappingURL=profiles-resolver.spec.js.map
|