@gotgenes/pi-permission-system 1.2.1 → 3.0.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.
@@ -5,11 +5,10 @@ import {
5
5
  mkdtempSync,
6
6
  readFileSync,
7
7
  rmSync,
8
- unlinkSync,
9
8
  writeFileSync,
10
9
  } from "node:fs";
11
10
  import { tmpdir } from "node:os";
12
- import { join, resolve } from "node:path";
11
+ import { dirname, join, resolve } from "node:path";
13
12
  import { test } from "vitest";
14
13
  import { BashFilter } from "../src/bash-filter.js";
15
14
  import {
@@ -17,8 +16,8 @@ import {
17
16
  createBeforeAgentStartPromptStateKey,
18
17
  shouldApplyCachedAgentStartState,
19
18
  } from "../src/before-agent-start-cache.js";
19
+ import { getGlobalConfigPath } from "../src/config-paths.js";
20
20
  import {
21
- CONFIG_PATH,
22
21
  DEFAULT_EXTENSION_CONFIG,
23
22
  loadPermissionSystemConfig,
24
23
  savePermissionSystemConfig,
@@ -156,20 +155,13 @@ function createToolCallHarness(
156
155
  const prompts: string[] = [];
157
156
  const handlers: Record<string, MockHandler> = {};
158
157
  const originalAgentDir = process.env.PI_CODING_AGENT_DIR;
159
- const originalExtensionConfig = existsSync(CONFIG_PATH)
160
- ? readFileSync(CONFIG_PATH, "utf8")
161
- : null;
162
-
158
+ const globalConfigPath = getGlobalConfigPath(baseDir);
163
159
  mkdirSync(join(baseDir, "agents"), { recursive: true });
160
+ mkdirSync(dirname(globalConfigPath), { recursive: true });
164
161
  mkdirSync(cwd, { recursive: true });
165
162
  writeFileSync(
166
- join(baseDir, "pi-permissions.jsonc"),
167
- `${JSON.stringify(config, null, 2)}\n`,
168
- "utf8",
169
- );
170
- writeFileSync(
171
- CONFIG_PATH,
172
- `${JSON.stringify(DEFAULT_EXTENSION_CONFIG, null, 2)}\n`,
163
+ globalConfigPath,
164
+ `${JSON.stringify({ ...DEFAULT_EXTENSION_CONFIG, ...config }, null, 2)}\n`,
173
165
  "utf8",
174
166
  );
175
167
 
@@ -208,13 +200,6 @@ function createToolCallHarness(
208
200
  createMockContext(cwd, prompts, options),
209
201
  ),
210
202
  );
211
- if (originalExtensionConfig === null) {
212
- if (existsSync(CONFIG_PATH)) {
213
- unlinkSync(CONFIG_PATH);
214
- }
215
- } else {
216
- writeFileSync(CONFIG_PATH, originalExtensionConfig, "utf8");
217
- }
218
203
  rmSync(baseDir, { recursive: true, force: true });
219
204
  },
220
205
  };
@@ -1818,7 +1803,9 @@ permission:
1818
1803
  test("PermissionManager reads config from PI_CODING_AGENT_DIR when set", () => {
1819
1804
  const baseDir = mkdtempSync(join(tmpdir(), "pi-permission-system-envdir-"));
1820
1805
  const agentsDir = join(baseDir, "agents");
1806
+ const newConfigPath = getGlobalConfigPath(baseDir);
1821
1807
  mkdirSync(agentsDir, { recursive: true });
1808
+ mkdirSync(dirname(newConfigPath), { recursive: true });
1822
1809
 
1823
1810
  const config: GlobalPermissionConfig = {
1824
1811
  defaultPolicy: {
@@ -1834,11 +1821,7 @@ test("PermissionManager reads config from PI_CODING_AGENT_DIR when set", () => {
1834
1821
  skills: {},
1835
1822
  special: {},
1836
1823
  };
1837
- writeFileSync(
1838
- join(baseDir, "pi-permissions.jsonc"),
1839
- JSON.stringify(config),
1840
- "utf8",
1841
- );
1824
+ writeFileSync(newConfigPath, JSON.stringify(config), "utf8");
1842
1825
 
1843
1826
  const original = process.env.PI_CODING_AGENT_DIR;
1844
1827
  process.env.PI_CODING_AGENT_DIR = baseDir;
@@ -1,19 +1,9 @@
1
- import {
2
- existsSync,
3
- mkdirSync,
4
- mkdtempSync,
5
- readFileSync,
6
- rmSync,
7
- unlinkSync,
8
- writeFileSync,
9
- } from "node:fs";
1
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
10
2
  import { tmpdir } from "node:os";
11
- import { join } from "node:path";
3
+ import { dirname, join } from "node:path";
12
4
  import { afterEach, beforeEach, describe, expect, test } from "vitest";
13
- import {
14
- CONFIG_PATH,
15
- DEFAULT_EXTENSION_CONFIG,
16
- } from "../src/extension-config.js";
5
+ import { getGlobalConfigPath } from "../src/config-paths.js";
6
+ import { DEFAULT_EXTENSION_CONFIG } from "../src/extension-config.js";
17
7
  import piPermissionSystemExtension from "../src/index.js";
18
8
  import type { GlobalPermissionConfig } from "../src/types.js";
19
9
 
@@ -28,16 +18,13 @@ type MockHandler = (
28
18
  describe("session_start handler consolidation", () => {
29
19
  let baseDir: string;
30
20
  let originalAgentDir: string | undefined;
31
- let originalExtensionConfig: string | null;
32
-
33
21
  beforeEach(() => {
34
22
  baseDir = mkdtempSync(join(tmpdir(), "pi-permission-session-start-"));
35
23
  originalAgentDir = process.env.PI_CODING_AGENT_DIR;
36
- originalExtensionConfig = existsSync(CONFIG_PATH)
37
- ? readFileSync(CONFIG_PATH, "utf8")
38
- : null;
39
24
 
25
+ const globalConfigPath = getGlobalConfigPath(baseDir);
40
26
  mkdirSync(join(baseDir, "agents"), { recursive: true });
27
+ mkdirSync(dirname(globalConfigPath), { recursive: true });
41
28
 
42
29
  const config: GlobalPermissionConfig = {
43
30
  defaultPolicy: {
@@ -49,13 +36,8 @@ describe("session_start handler consolidation", () => {
49
36
  },
50
37
  };
51
38
  writeFileSync(
52
- join(baseDir, "pi-permissions.jsonc"),
53
- `${JSON.stringify(config, null, 2)}\n`,
54
- "utf8",
55
- );
56
- writeFileSync(
57
- CONFIG_PATH,
58
- `${JSON.stringify(DEFAULT_EXTENSION_CONFIG, null, 2)}\n`,
39
+ globalConfigPath,
40
+ `${JSON.stringify({ ...DEFAULT_EXTENSION_CONFIG, ...config }, null, 2)}\n`,
59
41
  "utf8",
60
42
  );
61
43
 
@@ -68,13 +50,6 @@ describe("session_start handler consolidation", () => {
68
50
  } else {
69
51
  process.env.PI_CODING_AGENT_DIR = originalAgentDir;
70
52
  }
71
- if (originalExtensionConfig === null) {
72
- if (existsSync(CONFIG_PATH)) {
73
- unlinkSync(CONFIG_PATH);
74
- }
75
- } else {
76
- writeFileSync(CONFIG_PATH, originalExtensionConfig, "utf8");
77
- }
78
53
  rmSync(baseDir, { recursive: true, force: true });
79
54
  });
80
55