@gotgenes/pi-permission-system 10.2.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.
@@ -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
+ });
@@ -7,6 +7,7 @@ const mockRequestApproval = vi.fn();
7
7
  // ── Imports ─────────────────────────────────────────────────────────────────
8
8
 
9
9
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
10
+ import type { ConfigReader } from "#src/config-store";
10
11
  import { DEFAULT_EXTENSION_CONFIG } from "#src/extension-config";
11
12
  import type { PermissionPromptDecision } from "#src/permission-dialog";
12
13
  import type { PromptPermissionDetails } from "#src/permission-prompter";
@@ -38,11 +39,17 @@ function makeDetails(
38
39
  };
39
40
  }
40
41
 
42
+ function makeConfigReader(
43
+ config: Partial<typeof DEFAULT_EXTENSION_CONFIG> = {},
44
+ ): ConfigReader {
45
+ return { current: () => ({ ...DEFAULT_EXTENSION_CONFIG, ...config }) };
46
+ }
47
+
41
48
  function makeDeps(
42
49
  overrides?: Partial<PermissionPrompterDeps>,
43
50
  ): PermissionPrompterDeps {
44
51
  return {
45
- getConfig: () => ({ ...DEFAULT_EXTENSION_CONFIG, yoloMode: false }),
52
+ config: makeConfigReader(),
46
53
  writeReviewLog: vi.fn(),
47
54
  events: { emit: vi.fn(), on: vi.fn().mockReturnValue(() => undefined) },
48
55
  forwarder: { requestApproval: mockRequestApproval },
@@ -70,7 +77,7 @@ describe("PermissionPrompter", () => {
70
77
  on: vi.fn().mockReturnValue(() => undefined),
71
78
  };
72
79
  const deps = makeDeps({
73
- getConfig: () => ({ ...DEFAULT_EXTENSION_CONFIG, yoloMode: true }),
80
+ config: makeConfigReader({ yoloMode: true }),
74
81
  events,
75
82
  });
76
83
  const prompter = new PermissionPrompter(deps);
@@ -92,7 +99,7 @@ describe("PermissionPrompter", () => {
92
99
  it("logs permission_request.auto_approved in yolo mode", async () => {
93
100
  const writeReviewLog = vi.fn();
94
101
  const deps = makeDeps({
95
- getConfig: () => ({ ...DEFAULT_EXTENSION_CONFIG, yoloMode: true }),
102
+ config: makeConfigReader({ yoloMode: true }),
96
103
  writeReviewLog,
97
104
  });
98
105
  const prompter = new PermissionPrompter(deps);
@@ -108,7 +115,7 @@ describe("PermissionPrompter", () => {
108
115
  it("does not log permission_request.waiting in yolo mode", async () => {
109
116
  const writeReviewLog = vi.fn();
110
117
  const deps = makeDeps({
111
- getConfig: () => ({ ...DEFAULT_EXTENSION_CONFIG, yoloMode: true }),
118
+ config: makeConfigReader({ yoloMode: true }),
112
119
  writeReviewLog,
113
120
  });
114
121
  const prompter = new PermissionPrompter(deps);
@@ -123,7 +130,7 @@ describe("PermissionPrompter", () => {
123
130
 
124
131
  it("does not call confirmPermission with yoloMode even when ctx has UI", async () => {
125
132
  const deps = makeDeps({
126
- getConfig: () => ({ ...DEFAULT_EXTENSION_CONFIG, yoloMode: true }),
133
+ config: makeConfigReader({ yoloMode: true }),
127
134
  });
128
135
  const prompter = new PermissionPrompter(deps);
129
136
 
@@ -17,6 +17,8 @@ vi.mock("../src/active-agent", () => ({
17
17
 
18
18
  // ── Test helpers ───────────────────────────────────────────────────────────
19
19
 
20
+ import type { SessionConfigStore } from "#src/config-store";
21
+ import { DEFAULT_EXTENSION_CONFIG } from "#src/extension-config";
20
22
  import type { ExtensionPaths } from "#src/extension-paths";
21
23
  import type { ForwardingController } from "#src/forwarding-manager";
22
24
  import type { ScopedPermissionManager } from "#src/permission-manager";
@@ -66,11 +68,22 @@ function makeLogger(): SessionLogger {
66
68
  };
67
69
  }
68
70
 
71
+ function makeConfigStore(
72
+ overrides: Partial<SessionConfigStore> = {},
73
+ ): SessionConfigStore {
74
+ return {
75
+ current:
76
+ overrides.current ??
77
+ vi
78
+ .fn<() => typeof DEFAULT_EXTENSION_CONFIG>()
79
+ .mockReturnValue({ ...DEFAULT_EXTENSION_CONFIG }),
80
+ refresh: overrides.refresh ?? vi.fn<(ctx?: ExtensionContext) => void>(),
81
+ logResolvedPaths: overrides.logResolvedPaths ?? vi.fn<() => void>(),
82
+ };
83
+ }
84
+
69
85
  function makeRuntimeDeps(): PermissionSessionRuntimeDeps {
70
86
  return {
71
- refreshExtensionConfig: vi.fn(),
72
- logResolvedConfigPaths: vi.fn(),
73
- getConfig: vi.fn().mockReturnValue({}),
74
87
  canRequestPermissionConfirmation: vi.fn().mockReturnValue(true),
75
88
  promptPermission: vi
76
89
  .fn()
@@ -116,12 +129,14 @@ function createSession(overrides?: {
116
129
  logger?: SessionLogger;
117
130
  forwarding?: ForwardingController;
118
131
  permissionManager?: ScopedPermissionManager;
132
+ configStore?: SessionConfigStore;
119
133
  runtimeDeps?: PermissionSessionRuntimeDeps;
120
134
  }): {
121
135
  session: PermissionSession;
122
136
  paths: ExtensionPaths;
123
137
  logger: SessionLogger;
124
138
  forwarding: ForwardingController;
139
+ configStore: SessionConfigStore;
125
140
  runtimeDeps: PermissionSessionRuntimeDeps;
126
141
  } {
127
142
  const paths = makePaths(overrides?.paths);
@@ -129,15 +144,17 @@ function createSession(overrides?: {
129
144
  const forwarding = overrides?.forwarding ?? makeForwarding();
130
145
  const permissionManager =
131
146
  overrides?.permissionManager ?? makePermissionManager();
147
+ const configStore = overrides?.configStore ?? makeConfigStore();
132
148
  const runtimeDeps = overrides?.runtimeDeps ?? makeRuntimeDeps();
133
149
  const session = new PermissionSession(
134
150
  paths,
135
151
  logger,
136
152
  forwarding,
137
153
  permissionManager,
154
+ configStore,
138
155
  runtimeDeps,
139
156
  );
140
- return { session, paths, logger, forwarding, runtimeDeps };
157
+ return { session, paths, logger, forwarding, configStore, runtimeDeps };
141
158
  }
142
159
 
143
160
  // ── Tests ──────────────────────────────────────────────────────────────────
@@ -484,11 +501,12 @@ describe("PermissionSession", () => {
484
501
 
485
502
  describe("infrastructure paths", () => {
486
503
  it("getInfrastructureReadDirs combines piInfrastructureDirs and piInfrastructureReadPaths", () => {
487
- const runtimeDeps = makeRuntimeDeps();
488
- (runtimeDeps.getConfig as ReturnType<typeof vi.fn>).mockReturnValue({
489
- piInfrastructureReadPaths: ["/extra/path"],
504
+ const configStore = makeConfigStore({
505
+ current: vi.fn().mockReturnValue({
506
+ piInfrastructureReadPaths: ["/extra/path"],
507
+ }),
490
508
  });
491
- const { session } = createSession({ runtimeDeps });
509
+ const { session } = createSession({ configStore });
492
510
  expect(session.getInfrastructureReadDirs()).toEqual([
493
511
  "/test/agent",
494
512
  "/test/agent/git",
@@ -506,36 +524,36 @@ describe("PermissionSession", () => {
506
524
  });
507
525
 
508
526
  describe("config delegation", () => {
509
- it("refreshConfig delegates to runtimeDeps", () => {
510
- const { session, runtimeDeps } = createSession();
527
+ it("refreshConfig delegates to configStore.refresh", () => {
528
+ const { session, configStore } = createSession();
511
529
  const ctx = makeCtx();
512
530
  session.refreshConfig(ctx);
513
- expect(runtimeDeps.refreshExtensionConfig).toHaveBeenCalledWith(ctx);
531
+ expect(configStore.refresh).toHaveBeenCalledWith(ctx);
514
532
  });
515
533
 
516
- it("logResolvedConfigPaths delegates to runtimeDeps", () => {
517
- const { session, runtimeDeps } = createSession();
534
+ it("logResolvedConfigPaths delegates to configStore.logResolvedPaths", () => {
535
+ const { session, configStore } = createSession();
518
536
  session.logResolvedConfigPaths();
519
- expect(runtimeDeps.logResolvedConfigPaths).toHaveBeenCalled();
537
+ expect(configStore.logResolvedPaths).toHaveBeenCalled();
520
538
  });
521
539
 
522
- it("config getter delegates to runtimeDeps.getConfig", () => {
523
- const runtimeDeps = makeRuntimeDeps();
524
- const fakeConfig = { debugLog: true };
525
- (runtimeDeps.getConfig as ReturnType<typeof vi.fn>).mockReturnValue(
526
- fakeConfig,
527
- );
528
- const { session } = createSession({ runtimeDeps });
540
+ it("config getter delegates to configStore.current()", () => {
541
+ const fakeConfig = { debugLog: true } as typeof DEFAULT_EXTENSION_CONFIG;
542
+ const configStore = makeConfigStore({
543
+ current: vi.fn().mockReturnValue(fakeConfig),
544
+ });
545
+ const { session } = createSession({ configStore });
529
546
  expect(session.config).toBe(fakeConfig);
530
547
  });
531
548
 
532
549
  it("getToolPreviewLimits returns resolved preview limits from config", () => {
533
- const runtimeDeps = makeRuntimeDeps();
534
- (runtimeDeps.getConfig as ReturnType<typeof vi.fn>).mockReturnValue({
535
- toolInputPreviewMaxLength: 400,
536
- toolTextSummaryMaxLength: 120,
550
+ const configStore = makeConfigStore({
551
+ current: vi.fn().mockReturnValue({
552
+ toolInputPreviewMaxLength: 400,
553
+ toolTextSummaryMaxLength: 120,
554
+ }),
537
555
  });
538
- const { session } = createSession({ runtimeDeps });
556
+ const { session } = createSession({ configStore });
539
557
  const limits = session.getToolPreviewLimits();
540
558
  expect(limits.toolInputPreviewMaxLength).toBe(400);
541
559
  expect(limits.toolTextSummaryMaxLength).toBe(120);