@gotgenes/pi-permission-system 10.1.0 → 10.3.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/CHANGELOG.md +14 -0
- package/package.json +1 -1
- package/src/config-modal.ts +7 -10
- package/src/config-store.ts +243 -0
- package/src/index.ts +11 -15
- package/src/permission-manager.ts +69 -3
- package/src/permission-prompter.ts +3 -3
- package/src/permission-session.ts +13 -28
- package/src/runtime.ts +34 -203
- package/test/config-modal.test.ts +15 -10
- package/test/config-store.test.ts +452 -0
- package/test/handlers/external-directory-integration.test.ts +81 -176
- package/test/handlers/gates/bash-path.test.ts +26 -44
- package/test/handlers/gates/runner.test.ts +27 -119
- package/test/handlers/tool-call.test.ts +44 -153
- package/test/helpers/gate-fixtures.ts +66 -2
- package/test/helpers/handler-fixtures.ts +83 -2
- package/test/permission-manager-unified.test.ts +159 -1
- package/test/permission-prompter.test.ts +12 -5
- package/test/permission-session.test.ts +111 -120
- package/test/runtime.test.ts +11 -275
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
// ── Module mocks (hoisted) ─────────────────────────────────────────────────
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
mockLoadAndMergeConfigs,
|
|
7
|
+
mockLoadUnifiedConfig,
|
|
8
|
+
mockSyncPermissionSystemStatus,
|
|
9
|
+
mockBuildResolvedConfigLogEntry,
|
|
10
|
+
mockExistsSync,
|
|
11
|
+
mockMkdirSync,
|
|
12
|
+
mockWriteFileSync,
|
|
13
|
+
mockRenameSync,
|
|
14
|
+
mockUnlinkSync,
|
|
15
|
+
} = vi.hoisted(() => ({
|
|
16
|
+
mockLoadAndMergeConfigs: vi.fn(),
|
|
17
|
+
mockLoadUnifiedConfig: vi.fn(),
|
|
18
|
+
mockSyncPermissionSystemStatus: vi.fn(),
|
|
19
|
+
mockBuildResolvedConfigLogEntry: vi.fn(),
|
|
20
|
+
mockExistsSync: vi.fn<(path: string) => boolean>(),
|
|
21
|
+
mockMkdirSync: vi.fn(),
|
|
22
|
+
mockWriteFileSync: vi.fn(),
|
|
23
|
+
mockRenameSync: vi.fn(),
|
|
24
|
+
mockUnlinkSync: vi.fn(),
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
vi.mock("../src/config-loader", () => ({
|
|
28
|
+
loadAndMergeConfigs: mockLoadAndMergeConfigs,
|
|
29
|
+
loadUnifiedConfig: mockLoadUnifiedConfig,
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
vi.mock("../src/status", () => ({
|
|
33
|
+
syncPermissionSystemStatus: mockSyncPermissionSystemStatus,
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
vi.mock("../src/config-reporter", () => ({
|
|
37
|
+
buildResolvedConfigLogEntry: mockBuildResolvedConfigLogEntry,
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
vi.mock("node:fs", () => ({
|
|
41
|
+
existsSync: mockExistsSync,
|
|
42
|
+
mkdirSync: mockMkdirSync,
|
|
43
|
+
writeFileSync: mockWriteFileSync,
|
|
44
|
+
renameSync: mockRenameSync,
|
|
45
|
+
unlinkSync: mockUnlinkSync,
|
|
46
|
+
default: {
|
|
47
|
+
existsSync: mockExistsSync,
|
|
48
|
+
mkdirSync: mockMkdirSync,
|
|
49
|
+
writeFileSync: mockWriteFileSync,
|
|
50
|
+
renameSync: mockRenameSync,
|
|
51
|
+
unlinkSync: mockUnlinkSync,
|
|
52
|
+
},
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
// ── Imports ────────────────────────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
import type {
|
|
58
|
+
ExtensionCommandContext,
|
|
59
|
+
ExtensionContext,
|
|
60
|
+
} from "@earendil-works/pi-coding-agent";
|
|
61
|
+
import {
|
|
62
|
+
ConfigStore,
|
|
63
|
+
type ConfigStoreDeps,
|
|
64
|
+
type ResolvedPolicyPathProvider,
|
|
65
|
+
type RuntimeContextRef,
|
|
66
|
+
} from "#src/config-store";
|
|
67
|
+
import { DEFAULT_EXTENSION_CONFIG } from "#src/extension-config";
|
|
68
|
+
import type { ResolvedPolicyPaths } from "#src/policy-loader";
|
|
69
|
+
|
|
70
|
+
// ── Helpers ────────────────────────────────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
function makeContextRef(
|
|
73
|
+
initialCtx: ExtensionContext | null = null,
|
|
74
|
+
): RuntimeContextRef & { _ctx: ExtensionContext | null } {
|
|
75
|
+
const ref = {
|
|
76
|
+
_ctx: initialCtx,
|
|
77
|
+
get: () => ref._ctx,
|
|
78
|
+
set: (ctx: ExtensionContext) => {
|
|
79
|
+
ref._ctx = ctx;
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
return ref;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function makePolicyPathProvider(
|
|
86
|
+
paths?: Partial<ResolvedPolicyPaths>,
|
|
87
|
+
): ResolvedPolicyPathProvider {
|
|
88
|
+
return {
|
|
89
|
+
getResolvedPolicyPaths: vi.fn(
|
|
90
|
+
(): ResolvedPolicyPaths => ({
|
|
91
|
+
globalConfigPath: "/agent/config.json",
|
|
92
|
+
globalConfigExists: false,
|
|
93
|
+
projectConfigPath: null,
|
|
94
|
+
projectConfigExists: false,
|
|
95
|
+
agentsDir: "/agent/agents",
|
|
96
|
+
agentsDirExists: false,
|
|
97
|
+
projectAgentsDir: null,
|
|
98
|
+
projectAgentsDirExists: false,
|
|
99
|
+
...paths,
|
|
100
|
+
}),
|
|
101
|
+
),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function makeLogger() {
|
|
106
|
+
return {
|
|
107
|
+
writeDebugLog:
|
|
108
|
+
vi.fn<(event: string, details?: Record<string, unknown>) => void>(),
|
|
109
|
+
writeReviewLog:
|
|
110
|
+
vi.fn<(event: string, details?: Record<string, unknown>) => void>(),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function makeCtx(overrides: Partial<ExtensionContext> = {}): ExtensionContext {
|
|
115
|
+
return {
|
|
116
|
+
cwd: "/test/project",
|
|
117
|
+
hasUI: false,
|
|
118
|
+
ui: { notify: vi.fn(), setStatus: vi.fn() },
|
|
119
|
+
sessionManager: { getEntries: vi.fn(), addEntry: vi.fn() },
|
|
120
|
+
...overrides,
|
|
121
|
+
} as unknown as ExtensionContext;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function makeCommandCtx(
|
|
125
|
+
overrides: Partial<ExtensionCommandContext> = {},
|
|
126
|
+
): ExtensionCommandContext {
|
|
127
|
+
return {
|
|
128
|
+
cwd: "/test/project",
|
|
129
|
+
ui: { notify: vi.fn(), setStatus: vi.fn() },
|
|
130
|
+
...overrides,
|
|
131
|
+
} as unknown as ExtensionCommandContext;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function makeStore(overrides: Partial<ConfigStoreDeps> = {}): {
|
|
135
|
+
store: ConfigStore;
|
|
136
|
+
contextRef: RuntimeContextRef & { _ctx: ExtensionContext | null };
|
|
137
|
+
logger: ReturnType<typeof makeLogger>;
|
|
138
|
+
} {
|
|
139
|
+
const contextRef = makeContextRef();
|
|
140
|
+
const logger = makeLogger();
|
|
141
|
+
const deps: ConfigStoreDeps = {
|
|
142
|
+
agentDir: "/test/agent",
|
|
143
|
+
context: contextRef,
|
|
144
|
+
policyPaths: makePolicyPathProvider(),
|
|
145
|
+
logger,
|
|
146
|
+
...overrides,
|
|
147
|
+
};
|
|
148
|
+
return { store: new ConfigStore(deps), contextRef, logger };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ── Tests ──────────────────────────────────────────────────────────────────
|
|
152
|
+
|
|
153
|
+
describe("ConfigStore", () => {
|
|
154
|
+
beforeEach(() => {
|
|
155
|
+
mockLoadAndMergeConfigs.mockReset().mockReturnValue({
|
|
156
|
+
merged: { ...DEFAULT_EXTENSION_CONFIG },
|
|
157
|
+
issues: [],
|
|
158
|
+
});
|
|
159
|
+
mockLoadUnifiedConfig.mockReset().mockReturnValue({ config: {} });
|
|
160
|
+
mockSyncPermissionSystemStatus.mockReset();
|
|
161
|
+
mockBuildResolvedConfigLogEntry
|
|
162
|
+
.mockReset()
|
|
163
|
+
.mockReturnValue({ resolved: true });
|
|
164
|
+
mockExistsSync.mockReset().mockReturnValue(false);
|
|
165
|
+
mockMkdirSync.mockReset();
|
|
166
|
+
mockWriteFileSync.mockReset();
|
|
167
|
+
mockRenameSync.mockReset();
|
|
168
|
+
mockUnlinkSync.mockReset();
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// ── current() ─────────────────────────────────────────────────────────
|
|
172
|
+
|
|
173
|
+
describe("current()", () => {
|
|
174
|
+
it("returns DEFAULT_EXTENSION_CONFIG before any refresh", () => {
|
|
175
|
+
const { store } = makeStore();
|
|
176
|
+
expect(store.current()).toEqual(DEFAULT_EXTENSION_CONFIG);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// ── refresh() ─────────────────────────────────────────────────────────
|
|
181
|
+
|
|
182
|
+
describe("refresh()", () => {
|
|
183
|
+
it("calls loadAndMergeConfigs with agentDir and cwd from context", () => {
|
|
184
|
+
const { store, contextRef } = makeStore();
|
|
185
|
+
contextRef._ctx = makeCtx({ cwd: "/my/project" });
|
|
186
|
+
store.refresh();
|
|
187
|
+
expect(mockLoadAndMergeConfigs).toHaveBeenCalledWith(
|
|
188
|
+
"/test/agent",
|
|
189
|
+
"/my/project",
|
|
190
|
+
expect.any(String),
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("updates context via context.set when ctx is provided", () => {
|
|
195
|
+
const { store, contextRef } = makeStore();
|
|
196
|
+
const ctx = makeCtx({ cwd: "/new/project" });
|
|
197
|
+
store.refresh(ctx);
|
|
198
|
+
expect(contextRef._ctx).toBe(ctx);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("does not overwrite context when ctx is omitted", () => {
|
|
202
|
+
const { store, contextRef } = makeStore();
|
|
203
|
+
const existing = makeCtx();
|
|
204
|
+
contextRef._ctx = existing;
|
|
205
|
+
store.refresh();
|
|
206
|
+
expect(contextRef._ctx).toBe(existing);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("updates current() with normalized merged result", () => {
|
|
210
|
+
const { store } = makeStore();
|
|
211
|
+
mockLoadAndMergeConfigs.mockReturnValue({
|
|
212
|
+
merged: { debugLog: true, permissionReviewLog: false, yoloMode: false },
|
|
213
|
+
issues: [],
|
|
214
|
+
});
|
|
215
|
+
store.refresh();
|
|
216
|
+
expect(store.current().debugLog).toBe(true);
|
|
217
|
+
expect(store.current().permissionReviewLog).toBe(false);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("writes config.loaded debug log", () => {
|
|
221
|
+
const { store, logger } = makeStore();
|
|
222
|
+
store.refresh();
|
|
223
|
+
expect(logger.writeDebugLog).toHaveBeenCalledWith(
|
|
224
|
+
"config.loaded",
|
|
225
|
+
expect.objectContaining({ debugLog: false }),
|
|
226
|
+
);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("sets warning when issues are present", () => {
|
|
230
|
+
const { store } = makeStore();
|
|
231
|
+
const ctx = makeCtx({ hasUI: false });
|
|
232
|
+
mockLoadAndMergeConfigs.mockReturnValue({
|
|
233
|
+
merged: { ...DEFAULT_EXTENSION_CONFIG },
|
|
234
|
+
issues: ["legacy config detected"],
|
|
235
|
+
});
|
|
236
|
+
store.refresh(ctx);
|
|
237
|
+
// Verify the warning is tracked (next identical call should not re-notify)
|
|
238
|
+
const mockNotify = vi.fn();
|
|
239
|
+
const ctx2 = makeCtx({
|
|
240
|
+
hasUI: true,
|
|
241
|
+
ui: { notify: mockNotify } as never,
|
|
242
|
+
});
|
|
243
|
+
mockLoadAndMergeConfigs.mockReturnValue({
|
|
244
|
+
merged: { ...DEFAULT_EXTENSION_CONFIG },
|
|
245
|
+
issues: ["legacy config detected"],
|
|
246
|
+
});
|
|
247
|
+
store.refresh(ctx2);
|
|
248
|
+
// Same warning — should not re-notify
|
|
249
|
+
expect(mockNotify).not.toHaveBeenCalled();
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it("notifies UI when a new warning appears and hasUI is true", () => {
|
|
253
|
+
const mockNotify = vi.fn();
|
|
254
|
+
const { store } = makeStore();
|
|
255
|
+
const ctx = makeCtx({ hasUI: true, ui: { notify: mockNotify } as never });
|
|
256
|
+
mockLoadAndMergeConfigs.mockReturnValue({
|
|
257
|
+
merged: { ...DEFAULT_EXTENSION_CONFIG },
|
|
258
|
+
issues: ["new warning"],
|
|
259
|
+
});
|
|
260
|
+
store.refresh(ctx);
|
|
261
|
+
expect(mockNotify).toHaveBeenCalledWith("new warning", "warning");
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("does not re-notify the same warning on subsequent calls", () => {
|
|
265
|
+
const mockNotify = vi.fn();
|
|
266
|
+
const { store } = makeStore();
|
|
267
|
+
const ctx = makeCtx({ hasUI: true, ui: { notify: mockNotify } as never });
|
|
268
|
+
mockLoadAndMergeConfigs.mockReturnValue({
|
|
269
|
+
merged: { ...DEFAULT_EXTENSION_CONFIG },
|
|
270
|
+
issues: ["persistent warning"],
|
|
271
|
+
});
|
|
272
|
+
store.refresh(ctx);
|
|
273
|
+
store.refresh(ctx);
|
|
274
|
+
expect(mockNotify).toHaveBeenCalledTimes(1);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it("clears warning when no issues on next refresh", () => {
|
|
278
|
+
const mockNotify = vi.fn();
|
|
279
|
+
const { store } = makeStore();
|
|
280
|
+
// First call: set a warning
|
|
281
|
+
const ctxWithUI = makeCtx({
|
|
282
|
+
hasUI: true,
|
|
283
|
+
ui: { notify: mockNotify } as never,
|
|
284
|
+
});
|
|
285
|
+
mockLoadAndMergeConfigs.mockReturnValue({
|
|
286
|
+
merged: { ...DEFAULT_EXTENSION_CONFIG },
|
|
287
|
+
issues: ["warning"],
|
|
288
|
+
});
|
|
289
|
+
store.refresh(ctxWithUI);
|
|
290
|
+
// Second call: no issues — warning should clear
|
|
291
|
+
mockLoadAndMergeConfigs.mockReturnValue({
|
|
292
|
+
merged: { ...DEFAULT_EXTENSION_CONFIG },
|
|
293
|
+
issues: [],
|
|
294
|
+
});
|
|
295
|
+
store.refresh();
|
|
296
|
+
// Third call: same warning reappears — should notify again (dedup cleared)
|
|
297
|
+
mockLoadAndMergeConfigs.mockReturnValue({
|
|
298
|
+
merged: { ...DEFAULT_EXTENSION_CONFIG },
|
|
299
|
+
issues: ["warning"],
|
|
300
|
+
});
|
|
301
|
+
store.refresh(ctxWithUI);
|
|
302
|
+
expect(mockNotify).toHaveBeenCalledTimes(2);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("calls syncPermissionSystemStatus when hasUI is true", () => {
|
|
306
|
+
const { store } = makeStore();
|
|
307
|
+
const ctx = makeCtx({ hasUI: true });
|
|
308
|
+
store.refresh(ctx);
|
|
309
|
+
expect(mockSyncPermissionSystemStatus).toHaveBeenCalledWith(
|
|
310
|
+
ctx,
|
|
311
|
+
expect.any(Object),
|
|
312
|
+
);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("does not call syncPermissionSystemStatus when hasUI is false", () => {
|
|
316
|
+
const { store } = makeStore();
|
|
317
|
+
const ctx = makeCtx({ hasUI: false });
|
|
318
|
+
store.refresh(ctx);
|
|
319
|
+
expect(mockSyncPermissionSystemStatus).not.toHaveBeenCalled();
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
// ── save() ─────────────────────────────────────────────────────────────
|
|
324
|
+
|
|
325
|
+
describe("save()", () => {
|
|
326
|
+
it("writes merged config to the global path", () => {
|
|
327
|
+
const { store } = makeStore();
|
|
328
|
+
mockLoadUnifiedConfig.mockReturnValue({
|
|
329
|
+
config: { permission: { "*": "ask" } },
|
|
330
|
+
});
|
|
331
|
+
const next = { ...DEFAULT_EXTENSION_CONFIG, debugLog: true };
|
|
332
|
+
const ctx = makeCommandCtx();
|
|
333
|
+
store.save(next, ctx);
|
|
334
|
+
expect(mockWriteFileSync).toHaveBeenCalledWith(
|
|
335
|
+
expect.stringContaining(".tmp"),
|
|
336
|
+
expect.stringContaining('"debugLog": true'),
|
|
337
|
+
"utf-8",
|
|
338
|
+
);
|
|
339
|
+
expect(mockRenameSync).toHaveBeenCalled();
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it("updates current() after a successful save", () => {
|
|
343
|
+
const { store } = makeStore();
|
|
344
|
+
const next = { ...DEFAULT_EXTENSION_CONFIG, debugLog: true };
|
|
345
|
+
store.save(next, makeCommandCtx());
|
|
346
|
+
expect(store.current().debugLog).toBe(true);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
it("calls syncPermissionSystemStatus after a successful save", () => {
|
|
350
|
+
const { store } = makeStore();
|
|
351
|
+
const ctx = makeCommandCtx();
|
|
352
|
+
store.save({ ...DEFAULT_EXTENSION_CONFIG }, ctx);
|
|
353
|
+
expect(mockSyncPermissionSystemStatus).toHaveBeenCalledWith(
|
|
354
|
+
ctx,
|
|
355
|
+
expect.any(Object),
|
|
356
|
+
);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("writes config.saved debug log after a successful save", () => {
|
|
360
|
+
const { store, logger } = makeStore();
|
|
361
|
+
store.save({ ...DEFAULT_EXTENSION_CONFIG }, makeCommandCtx());
|
|
362
|
+
expect(logger.writeDebugLog).toHaveBeenCalledWith(
|
|
363
|
+
"config.saved",
|
|
364
|
+
expect.objectContaining({ debugLog: false }),
|
|
365
|
+
);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it("notifies with error and returns early when write fails", () => {
|
|
369
|
+
const mockNotify = vi.fn();
|
|
370
|
+
const ctx = makeCommandCtx({ ui: { notify: mockNotify } as never });
|
|
371
|
+
const { store, logger } = makeStore();
|
|
372
|
+
mockMkdirSync.mockImplementation(() => {
|
|
373
|
+
throw new Error("disk full");
|
|
374
|
+
});
|
|
375
|
+
store.save({ ...DEFAULT_EXTENSION_CONFIG }, ctx);
|
|
376
|
+
expect(mockNotify).toHaveBeenCalledWith(
|
|
377
|
+
expect.stringContaining("Failed to save"),
|
|
378
|
+
"error",
|
|
379
|
+
);
|
|
380
|
+
// current() is not updated on failure
|
|
381
|
+
expect(store.current()).toEqual(DEFAULT_EXTENSION_CONFIG);
|
|
382
|
+
// no debug log on failure
|
|
383
|
+
expect(logger.writeDebugLog).not.toHaveBeenCalledWith(
|
|
384
|
+
"config.saved",
|
|
385
|
+
expect.anything(),
|
|
386
|
+
);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it("attempts cleanup of tmp file when write fails and tmp exists", () => {
|
|
390
|
+
const ctx = makeCommandCtx();
|
|
391
|
+
const { store } = makeStore();
|
|
392
|
+
mockMkdirSync.mockImplementation(() => {
|
|
393
|
+
throw new Error("disk full");
|
|
394
|
+
});
|
|
395
|
+
mockExistsSync.mockReturnValue(true);
|
|
396
|
+
store.save({ ...DEFAULT_EXTENSION_CONFIG }, ctx);
|
|
397
|
+
expect(mockUnlinkSync).toHaveBeenCalled();
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
// ── logResolvedPaths() ─────────────────────────────────────────────────
|
|
402
|
+
|
|
403
|
+
describe("logResolvedPaths()", () => {
|
|
404
|
+
it("writes config.resolved to both review and debug logs", () => {
|
|
405
|
+
const { store, logger } = makeStore();
|
|
406
|
+
store.logResolvedPaths();
|
|
407
|
+
expect(logger.writeReviewLog).toHaveBeenCalledWith(
|
|
408
|
+
"config.resolved",
|
|
409
|
+
expect.any(Object),
|
|
410
|
+
);
|
|
411
|
+
expect(logger.writeDebugLog).toHaveBeenCalledWith(
|
|
412
|
+
"config.resolved",
|
|
413
|
+
expect.any(Object),
|
|
414
|
+
);
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
it("calls getResolvedPolicyPaths from the provider", () => {
|
|
418
|
+
const mockProvider = makePolicyPathProvider();
|
|
419
|
+
const { store } = makeStore({ policyPaths: mockProvider });
|
|
420
|
+
store.logResolvedPaths();
|
|
421
|
+
expect(mockProvider.getResolvedPolicyPaths).toHaveBeenCalled();
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
it("passes legacy detection results to buildResolvedConfigLogEntry", () => {
|
|
425
|
+
const { store, contextRef } = makeStore();
|
|
426
|
+
contextRef._ctx = makeCtx({ cwd: "/some/project" });
|
|
427
|
+
// Make one legacy path exist
|
|
428
|
+
mockExistsSync.mockImplementation((p: string) =>
|
|
429
|
+
p.includes("policies.json"),
|
|
430
|
+
);
|
|
431
|
+
store.logResolvedPaths();
|
|
432
|
+
expect(mockBuildResolvedConfigLogEntry).toHaveBeenCalledWith(
|
|
433
|
+
expect.objectContaining({
|
|
434
|
+
legacyGlobalPolicyDetected: expect.any(Boolean),
|
|
435
|
+
legacyProjectPolicyDetected: expect.any(Boolean),
|
|
436
|
+
legacyExtensionConfigDetected: expect.any(Boolean),
|
|
437
|
+
}),
|
|
438
|
+
);
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
it("does not check project legacy path when context has no cwd", () => {
|
|
442
|
+
const { store } = makeStore(); // contextRef._ctx = null
|
|
443
|
+
store.logResolvedPaths();
|
|
444
|
+
// existsSync called for global and ext-config legacy paths only (not project)
|
|
445
|
+
const calls = mockExistsSync.mock.calls.map(([p]: [string]) => p);
|
|
446
|
+
const projectCalls = calls.filter(
|
|
447
|
+
(p) => p.includes("/null/") || p.includes("null"),
|
|
448
|
+
);
|
|
449
|
+
expect(projectCalls).toHaveLength(0);
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
});
|