@asterxsk/kiln 0.1.0 → 0.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.
Files changed (203) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +170 -170
  3. package/agent/AGENTS.md +67 -67
  4. package/agent/README.md +5 -5
  5. package/agent/extensions/AGENTS.md +68 -68
  6. package/agent/extensions/ask-user/index.ts +418 -418
  7. package/agent/extensions/ask-user/package-lock.json +769 -769
  8. package/agent/extensions/ask-user/package.json +19 -19
  9. package/agent/extensions/ask-user/prompt.ts +45 -45
  10. package/agent/extensions/ask-user/tsconfig.json +7 -7
  11. package/agent/extensions/background-terminals/docs/implementation-guide.md +942 -942
  12. package/agent/extensions/background-terminals/index.ts +627 -627
  13. package/agent/extensions/background-terminals/manager.test.ts +735 -735
  14. package/agent/extensions/background-terminals/output.test.ts +109 -109
  15. package/agent/extensions/background-terminals/package-lock.json +769 -769
  16. package/agent/extensions/background-terminals/package.json +17 -17
  17. package/agent/extensions/background-terminals/prompt.test.ts +125 -125
  18. package/agent/extensions/background-terminals/ps.test.ts +82 -82
  19. package/agent/extensions/background-terminals/result-delivery.test.ts +44 -44
  20. package/agent/extensions/background-terminals/src/domain.ts +87 -87
  21. package/agent/extensions/background-terminals/src/manager.ts +907 -907
  22. package/agent/extensions/background-terminals/src/output.ts +84 -84
  23. package/agent/extensions/background-terminals/src/prompt.ts +142 -142
  24. package/agent/extensions/background-terminals/src/result-delivery.ts +27 -27
  25. package/agent/extensions/background-terminals/src/runtime.ts +36 -36
  26. package/agent/extensions/background-terminals/src/ui/output-view.ts +79 -79
  27. package/agent/extensions/background-terminals/src/ui/ps.ts +621 -621
  28. package/agent/extensions/background-terminals/tsconfig.json +7 -7
  29. package/agent/extensions/file-search/index.spec.ts +443 -443
  30. package/agent/extensions/file-search/index.ts +459 -459
  31. package/agent/extensions/file-search/package-lock.json +2253 -2253
  32. package/agent/extensions/file-search/package.json +23 -23
  33. package/agent/extensions/file-search/src/args.ts +122 -122
  34. package/agent/extensions/file-search/src/binaries.ts +422 -422
  35. package/agent/extensions/file-search/src/output.ts +126 -126
  36. package/agent/extensions/file-search/src/process.ts +146 -146
  37. package/agent/extensions/file-search/src/prompt.ts +52 -52
  38. package/agent/extensions/file-search/tsconfig.json +7 -7
  39. package/agent/extensions/modelconf/PLAN.md +915 -915
  40. package/agent/extensions/modelconf/index.ts +296 -296
  41. package/agent/extensions/modelconf/src/ui/ModelConfView.ts +1101 -1101
  42. package/agent/extensions/pi-web-access/CHANGELOG.md +690 -690
  43. package/agent/extensions/pi-web-access/LICENSE +21 -21
  44. package/agent/extensions/pi-web-access/README.md +470 -470
  45. package/agent/extensions/pi-web-access/SECURITY.md +5 -5
  46. package/agent/extensions/pi-web-access/activity.ts +101 -101
  47. package/agent/extensions/pi-web-access/auth-fetch.ts +148 -148
  48. package/agent/extensions/pi-web-access/brightdata-unlocker.ts +272 -272
  49. package/agent/extensions/pi-web-access/chrome-cookies.ts +669 -669
  50. package/agent/extensions/pi-web-access/content-find.ts +139 -139
  51. package/agent/extensions/pi-web-access/credential-source.ts +191 -191
  52. package/agent/extensions/pi-web-access/data-uri-sanitize.ts +406 -406
  53. package/agent/extensions/pi-web-access/datalab-pdf-extract.ts +568 -568
  54. package/agent/extensions/pi-web-access/declared-web-links.ts +173 -173
  55. package/agent/extensions/pi-web-access/evidence/CONTRACT-EVIDENCE.md +496 -496
  56. package/agent/extensions/pi-web-access/evidence/contract-probe.mjs +140 -140
  57. package/agent/extensions/pi-web-access/exa.ts +526 -526
  58. package/agent/extensions/pi-web-access/extract.ts +1196 -1196
  59. package/agent/extensions/pi-web-access/feature-config.ts +29 -29
  60. package/agent/extensions/pi-web-access/fetch-params.ts +111 -111
  61. package/agent/extensions/pi-web-access/gemini-adc.ts +298 -298
  62. package/agent/extensions/pi-web-access/gemini-api.ts +353 -353
  63. package/agent/extensions/pi-web-access/gemini-pdf-extract.ts +108 -108
  64. package/agent/extensions/pi-web-access/gemini-url-context.ts +128 -128
  65. package/agent/extensions/pi-web-access/gemini-web-config.ts +101 -101
  66. package/agent/extensions/pi-web-access/gemini-web.ts +487 -487
  67. package/agent/extensions/pi-web-access/github-api.ts +197 -197
  68. package/agent/extensions/pi-web-access/github-extract.ts +746 -746
  69. package/agent/extensions/pi-web-access/github-issue-pr.ts +700 -700
  70. package/agent/extensions/pi-web-access/index.ts +1737 -1737
  71. package/agent/extensions/pi-web-access/package-lock.json +5808 -5808
  72. package/agent/extensions/pi-web-access/package.json +64 -64
  73. package/agent/extensions/pi-web-access/page-query.ts +96 -96
  74. package/agent/extensions/pi-web-access/pdf-extract.ts +409 -409
  75. package/agent/extensions/pi-web-access/promise-try.d.ts +7 -7
  76. package/agent/extensions/pi-web-access/query-rewrite.ts +51 -51
  77. package/agent/extensions/pi-web-access/render-search-error.ts +170 -170
  78. package/agent/extensions/pi-web-access/rsc-extract.ts +338 -338
  79. package/agent/extensions/pi-web-access/source-check.ts +282 -282
  80. package/agent/extensions/pi-web-access/ssrf-protection.ts +526 -526
  81. package/agent/extensions/pi-web-access/storage.ts +521 -521
  82. package/agent/extensions/pi-web-access/summary-model-scope.ts +125 -125
  83. package/agent/extensions/pi-web-access/test/auth-fetch.test.mjs +208 -208
  84. package/agent/extensions/pi-web-access/test/brightdata-unlocker.test.mjs +840 -840
  85. package/agent/extensions/pi-web-access/test/chrome-cookie-extraction.test.mjs +441 -441
  86. package/agent/extensions/pi-web-access/test/config-path.test.mjs +283 -283
  87. package/agent/extensions/pi-web-access/test/content-find.test.mjs +25 -25
  88. package/agent/extensions/pi-web-access/test/credential-source.test.mjs +118 -118
  89. package/agent/extensions/pi-web-access/test/data-uri-sanitize.test.mjs +210 -210
  90. package/agent/extensions/pi-web-access/test/datalab-pdf-extract.test.mjs +552 -552
  91. package/agent/extensions/pi-web-access/test/declared-web-links.test.mjs +212 -212
  92. package/agent/extensions/pi-web-access/test/fetch-answer-storage.test.mjs +40 -40
  93. package/agent/extensions/pi-web-access/test/fetch-cache-storage.test.mjs +334 -334
  94. package/agent/extensions/pi-web-access/test/fetch-content-domain-policy.test.mjs +95 -95
  95. package/agent/extensions/pi-web-access/test/fetch-modes.test.mjs +53 -53
  96. package/agent/extensions/pi-web-access/test/fetch-not-found-guidance.test.mjs +92 -92
  97. package/agent/extensions/pi-web-access/test/fetch-params.test.mjs +86 -86
  98. package/agent/extensions/pi-web-access/test/fetch-render-call.test.mjs +34 -34
  99. package/agent/extensions/pi-web-access/test/fetch-routing.test.mjs +173 -173
  100. package/agent/extensions/pi-web-access/test/gemini-adc-auth.test.mjs +257 -257
  101. package/agent/extensions/pi-web-access/test/gemini-api-transport.test.mjs +170 -170
  102. package/agent/extensions/pi-web-access/test/gemini-pdf-extract.test.mjs +133 -133
  103. package/agent/extensions/pi-web-access/test/gemini-web-cookie-opt-in.test.mjs +178 -178
  104. package/agent/extensions/pi-web-access/test/gemini-web-header-overflow.test.mjs +148 -148
  105. package/agent/extensions/pi-web-access/test/get-search-content.test.mjs +223 -223
  106. package/agent/extensions/pi-web-access/test/github-extract.test.mjs +378 -378
  107. package/agent/extensions/pi-web-access/test/github-issue-pr.test.mjs +565 -565
  108. package/agent/extensions/pi-web-access/test/inline-content-config.test.mjs +99 -99
  109. package/agent/extensions/pi-web-access/test/lazy-extract-load.test.mjs +118 -118
  110. package/agent/extensions/pi-web-access/test/local-video-oversize.test.mjs +52 -52
  111. package/agent/extensions/pi-web-access/test/package-typebox-dependency.test.mjs +50 -50
  112. package/agent/extensions/pi-web-access/test/page-query.test.mjs +51 -51
  113. package/agent/extensions/pi-web-access/test/pdf-config.test.mjs +140 -140
  114. package/agent/extensions/pi-web-access/test/pdf-extract.test.mjs +500 -500
  115. package/agent/extensions/pi-web-access/test/proxy-transport.test.mjs +286 -286
  116. package/agent/extensions/pi-web-access/test/query-rewrite.test.mjs +52 -52
  117. package/agent/extensions/pi-web-access/test/rsc-fallback.test.mjs +102 -102
  118. package/agent/extensions/pi-web-access/test/search-error-render.test.mjs +152 -152
  119. package/agent/extensions/pi-web-access/test/search-providers.test.mjs +274 -274
  120. package/agent/extensions/pi-web-access/test/source-check.test.mjs +179 -179
  121. package/agent/extensions/pi-web-access/test/ssrf-allow-ranges-config.test.mjs +205 -205
  122. package/agent/extensions/pi-web-access/test/ssrf-protection.test.mjs +456 -456
  123. package/agent/extensions/pi-web-access/test/tool-registration-config.test.mjs +182 -182
  124. package/agent/extensions/pi-web-access/test/youtube-extract-errors.test.mjs +64 -64
  125. package/agent/extensions/pi-web-access/tsconfig.json +11 -11
  126. package/agent/extensions/pi-web-access/utils.ts +451 -451
  127. package/agent/extensions/pi-web-access/video-extract.ts +392 -392
  128. package/agent/extensions/pi-web-access/youtube-extract.ts +328 -328
  129. package/agent/extensions/shared/activity-status.ts +31 -31
  130. package/agent/extensions/shared/child-session.test.ts +270 -270
  131. package/agent/extensions/shared/child-session.ts +148 -148
  132. package/agent/extensions/shared/context-utilization.test.ts +48 -48
  133. package/agent/extensions/shared/context-utilization.ts +47 -47
  134. package/agent/extensions/shared/dashboard-state.ts +99 -99
  135. package/agent/extensions/shared/tool-call-timeout.test.ts +117 -117
  136. package/agent/extensions/shared/tool-call-timeout.ts +104 -104
  137. package/agent/extensions/subagents/by-the-way.test.ts +29 -29
  138. package/agent/extensions/subagents/claude.test.ts +119 -119
  139. package/agent/extensions/subagents/codex.test.ts +102 -102
  140. package/agent/extensions/subagents/context-usage.test.ts +107 -107
  141. package/agent/extensions/subagents/docs/design-plan.md +568 -568
  142. package/agent/extensions/subagents/docs/effect-v4-extension-guide.md +354 -354
  143. package/agent/extensions/subagents/docs/effect-v4-notes.md +571 -571
  144. package/agent/extensions/subagents/index.ts +779 -779
  145. package/agent/extensions/subagents/manager.test.ts +276 -276
  146. package/agent/extensions/subagents/package-lock.json +2244 -2244
  147. package/agent/extensions/subagents/package.json +19 -19
  148. package/agent/extensions/subagents/result-delivery.test.ts +27 -27
  149. package/agent/extensions/subagents/src/backend.ts +73 -73
  150. package/agent/extensions/subagents/src/backends/claude.ts +701 -701
  151. package/agent/extensions/subagents/src/backends/codex.ts +1060 -1060
  152. package/agent/extensions/subagents/src/backends/pi.ts +575 -575
  153. package/agent/extensions/subagents/src/backends/stub.ts +300 -300
  154. package/agent/extensions/subagents/src/by-the-way.ts +21 -21
  155. package/agent/extensions/subagents/src/domain.ts +253 -253
  156. package/agent/extensions/subagents/src/format.ts +74 -74
  157. package/agent/extensions/subagents/src/manager.ts +736 -736
  158. package/agent/extensions/subagents/src/prompt.ts +92 -92
  159. package/agent/extensions/subagents/src/result-delivery.ts +20 -20
  160. package/agent/extensions/subagents/src/runtime.ts +53 -53
  161. package/agent/extensions/subagents/src/ui/takeover.ts +583 -583
  162. package/agent/extensions/subagents/src/ui/transcript.ts +201 -201
  163. package/agent/extensions/subagents/takeover.test.ts +29 -29
  164. package/agent/extensions/subagents/tsconfig.json +7 -7
  165. package/agent/extensions/todo/AGENTS.md +38 -38
  166. package/agent/extensions/todo/LICENSE +21 -21
  167. package/agent/extensions/todo/config.ts +55 -55
  168. package/agent/extensions/todo/index.ts +151 -151
  169. package/agent/extensions/todo/locales/de.json +17 -17
  170. package/agent/extensions/todo/locales/en.json +15 -15
  171. package/agent/extensions/todo/locales/es.json +17 -17
  172. package/agent/extensions/todo/locales/fr.json +17 -17
  173. package/agent/extensions/todo/locales/pt-BR.json +17 -17
  174. package/agent/extensions/todo/locales/pt.json +17 -17
  175. package/agent/extensions/todo/locales/ru.json +17 -17
  176. package/agent/extensions/todo/locales/uk.json +17 -17
  177. package/agent/extensions/todo/locales/zh.json +17 -17
  178. package/agent/extensions/todo/package-lock.json +3358 -3358
  179. package/agent/extensions/todo/package.json +67 -67
  180. package/agent/extensions/todo/state/i18n-bridge.ts +64 -64
  181. package/agent/extensions/todo/state/invariants.ts +20 -20
  182. package/agent/extensions/todo/state/replay.ts +38 -38
  183. package/agent/extensions/todo/state/selectors.ts +107 -107
  184. package/agent/extensions/todo/state/state-reducer.ts +326 -326
  185. package/agent/extensions/todo/state/state.ts +18 -18
  186. package/agent/extensions/todo/state/store.ts +82 -82
  187. package/agent/extensions/todo/state/task-graph.ts +57 -57
  188. package/agent/extensions/todo/todo-overlay.ts +200 -200
  189. package/agent/extensions/todo/todo.ts +155 -155
  190. package/agent/extensions/todo/tool/response-envelope.ts +109 -109
  191. package/agent/extensions/todo/tool/types.ts +206 -206
  192. package/agent/extensions/todo/view/format.ts +177 -177
  193. package/agent/install.ps1 +637 -527
  194. package/agent/install.sh +620 -511
  195. package/agent/keybindings.json +7 -7
  196. package/bin/kiln.js +124 -11
  197. package/package.json +8 -2
  198. package/agent/extensions/taste/index.ts +0 -443
  199. package/agent/extensions/taste/install.ps1 +0 -23
  200. package/agent/extensions/taste/install.sh +0 -21
  201. /package/agent/extensions/{status line → statusline}/index.ts +0 -0
  202. /package/agent/extensions/{status line → statusline}/install.ps1 +0 -0
  203. /package/agent/extensions/{status line → statusline}/install.sh +0 -0
@@ -1,441 +1,441 @@
1
- import assert from "node:assert/strict";
2
- import { execFileSync, spawnSync } from "node:child_process";
3
- import { createCipheriv, createHash } from "node:crypto";
4
- import { chmodSync, existsSync, mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, symlinkSync } from "node:fs";
5
- import { homedir, tmpdir } from "node:os";
6
- import { dirname, join } from "node:path";
7
- import { test } from "node:test";
8
-
9
- const moduleUrl = new URL("../chrome-cookies.ts", import.meta.url).href;
10
- const python = process.platform === "win32" ? null : "python3";
11
-
12
- function createFixture(home, profile, rows = [], options = {}) {
13
- if (!python) return;
14
- const { browser = "Chrome", targetPlatform = process.platform } = options;
15
- const base = targetPlatform === "darwin"
16
- ? browser === "Brave"
17
- ? join(home, "Library", "Application Support", "BraveSoftware", "Brave-Browser")
18
- : browser === "Helium"
19
- ? join(home, "Library", "Application Support", "net.imput.helium")
20
- : browser === "Arc"
21
- ? join(home, "Library", "Application Support", "Arc", "User Data")
22
- : join(home, "Library", "Application Support", "Google", "Chrome")
23
- : targetPlatform === "win32"
24
- ? browser === "Edge"
25
- ? join(home, "AppData", "Local", "Microsoft", "Edge", "User Data")
26
- : join(home, "AppData", "Local", "Google", "Chrome", "User Data")
27
- : join(home, ".config", "google-chrome");
28
- const dbPath = targetPlatform === "win32" ? join(base, profile, "Network", "Cookies") : join(base, profile, "Cookies");
29
- mkdirSync(dirname(dbPath), { recursive: true });
30
- execFileSync(python, ["-c", `
31
- import json, sqlite3, sys
32
- c = sqlite3.connect(sys.argv[1])
33
- c.execute("create table meta (key text, value integer)")
34
- c.execute("insert into meta values ('version', 24)")
35
- c.execute("create table cookies (name text, value text, host_key text, encrypted_value blob, expires_utc integer)")
36
- for row in json.loads(sys.argv[2]):
37
- encrypted = bytes.fromhex(row[3][4:]) if isinstance(row[3], str) and row[3].startswith('hex:') else row[3]
38
- c.execute("insert into cookies values (?, ?, ?, ?, ?)", [row[0], row[1], row[2], encrypted, row[4]])
39
- c.commit()
40
- c.close()
41
- `, dbPath, JSON.stringify(rows)], { stdio: "ignore" });
42
- if (options.windowsKey) {
43
- writeFileSync(join(base, "Local State"), JSON.stringify({ os_crypt: { encrypted_key: Buffer.concat([Buffer.from("DPAPI"), Buffer.from("protected")]).toString("base64") } }));
44
- }
45
- }
46
-
47
- function encryptWindowsCookie(value, key, version = "v10", hostKey) {
48
- const nonce = Buffer.alloc(12, 7);
49
- const cipher = createCipheriv("aes-256-gcm", key, nonce);
50
- const plaintext = hostKey ? Buffer.concat([createHash("sha256").update(hostKey).digest(), Buffer.from(value)]) : Buffer.from(value);
51
- return Buffer.concat([Buffer.from(version), nonce, cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]).toString("hex");
52
- }
53
-
54
- function writeWindowsDpapiCommand(bin, argsPath) {
55
- const script = "#!/bin/sh\n[ -n \"$ARGS_FILE\" ] && printf '%s\\n' \"$@\" > \"$ARGS_FILE\"\nencoded=0\nfor arg do [ \"$arg\" = \"-EncodedCommand\" ] && encoded=1; [ \"$arg\" = \"$DPAPI_PROTECTED\" ] && exit 1; done\n[ \"$encoded\" = 1 ] || exit 1\n[ \"$PIWA_PROTECTED\" = \"$DPAPI_PROTECTED\" ] || exit 1\nprintf '%s' \"$DPAPI_KEY\"\n";
56
- writeFileSync(join(bin, "powershell.exe"), script);
57
- chmodSync(join(bin, "powershell.exe"), 0o755);
58
- return argsPath ? { ARGS_FILE: argsPath } : {};
59
- }
60
-
61
- function makeEnvironment(home, bin, extra = {}) {
62
- const env = {
63
- ...process.env,
64
- HOME: home,
65
- USERPROFILE: home,
66
- PI_ALLOW_BROWSER_COOKIES: "1",
67
- PATH: `${bin}:${process.env.PATH ?? ""}`,
68
- ...extra,
69
- };
70
- delete env.PI_CODING_AGENT_DIR;
71
- delete env.XDG_CONFIG_HOME;
72
- return env;
73
- }
74
-
75
- function writePasswordCommand(bin, countPath, targetPlatform = process.platform, argsPath) {
76
- const command = targetPlatform === "darwin" ? "security" : "secret-tool";
77
- const script = `#!/bin/sh\nn=0\n[ -f "$COUNT_FILE" ] && n=$(cat "$COUNT_FILE")\nprintf '%s' $((n + 1)) > "$COUNT_FILE"\n[ -n "$ARGS_FILE" ] && printf '%s\\n' "$@" > "$ARGS_FILE"\nprintf peanuts\n`;
78
- writeFileSync(join(bin, command), script);
79
- chmodSync(join(bin, command), 0o755);
80
- return { COUNT_FILE: countPath, ...(argsPath ? { ARGS_FILE: argsPath } : {}) };
81
- }
82
-
83
- function writeFailThenSucceedPasswordCommand(bin, countPath) {
84
- const command = process.platform === "darwin" ? "security" : "secret-tool";
85
- const script = `#!/bin/sh\nn=0\n[ -f "$COUNT_FILE" ] && n=$(cat "$COUNT_FILE")\nn=$((n + 1))\nprintf '%s' $n > "$COUNT_FILE"\n[ "$n" = 1 ] && exit 1\nprintf peanuts\n`;
86
- writeFileSync(join(bin, command), script);
87
- chmodSync(join(bin, command), 0o755);
88
- return { COUNT_FILE: countPath };
89
- }
90
-
91
- function writeFailPasswordCommand(bin, countPath, targetPlatform = process.platform) {
92
- const command = targetPlatform === "darwin" ? "security" : "secret-tool";
93
- const script = `#!/bin/sh\nn=0\n[ -f "$COUNT_FILE" ] && n=$(cat "$COUNT_FILE")\nprintf '%s' $((n + 1)) > "$COUNT_FILE"\nprintf 'sensitive stderr' >&2\nexit 1\n`;
94
- writeFileSync(join(bin, command), script);
95
- chmodSync(join(bin, command), 0o755);
96
- return { COUNT_FILE: countPath };
97
- }
98
-
99
- function runCookies(home, env, options = "{ requiredCookies: ['__Secure-1PSID', '__Secure-1PSIDTS'] }", platformOverride) {
100
- return runCookieScript(env, `const r = await m.getGoogleCookies(${options}); console.log(JSON.stringify({ result: r, diagnostic: m.getLastGoogleCookieDiagnostic(), details: m.getLastGoogleCookieDiagnosticDetails() }));`, platformOverride);
101
- }
102
-
103
- function runCookieScript(env, body, platformOverride) {
104
- const override = platformOverride
105
- ? `Object.defineProperty(process, "platform", { value: ${JSON.stringify(platformOverride)} }); `
106
- : "";
107
- const child = spawnSync(process.execPath, ["--experimental-strip-types", "--input-type=module"], {
108
- encoding: "utf8",
109
- env,
110
- input: `${override}const m = await import(${JSON.stringify(moduleUrl)}); ${body}`,
111
- });
112
- assert.equal(child.status, 0, child.stderr);
113
- return JSON.parse(child.stdout);
114
- }
115
-
116
- function skipWithoutPython(t) {
117
- if (!python) t.skip("fixture creation requires Python on macOS/Linux");
118
- }
119
-
120
- test("cookie extraction remains opt-in even when a browser database exists", (t) => {
121
- skipWithoutPython(t);
122
- const home = mkdtempSync(join(tmpdir(), "pi-cookie-opt-out-"));
123
- const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
124
- createFixture(home, "Default", [["__Secure-1PSID", "one", ".google.com", null, 1]]);
125
- const env = makeEnvironment(home, bin);
126
- delete env.PI_ALLOW_BROWSER_COOKIES;
127
- const result = runCookies(home, env);
128
- assert.equal(result.result, null);
129
- assert.match(result.diagnostic, /disabled/);
130
- rmSync(home, { recursive: true, force: true });
131
- rmSync(bin, { recursive: true, force: true });
132
- });
133
-
134
- test("auto-discovery finds a non-default Chromium profile", (t) => {
135
- skipWithoutPython(t);
136
- const home = mkdtempSync(join(tmpdir(), "pi-cookie-profile-"));
137
- const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
138
- createFixture(home, "Profile 2", [
139
- ["__Secure-1PSID", "one", ".google.com", null, 1],
140
- ["__Secure-1PSIDTS", "two", ".google.com", null, 2],
141
- ]);
142
- const env = makeEnvironment(home, bin);
143
- Object.assign(env, writePasswordCommand(bin, join(home, "password-count")));
144
- const result = runCookies(home, env);
145
- assert.deepEqual(result.result.cookies, { "__Secure-1PSIDTS": "two", "__Secure-1PSID": "one" });
146
- rmSync(home, { recursive: true, force: true });
147
- rmSync(bin, { recursive: true, force: true });
148
- });
149
-
150
- test("auto-discovery finds a Brave profile on macOS", (t) => {
151
- skipWithoutPython(t);
152
- const home = mkdtempSync(join(tmpdir(), "pi-cookie-brave-profile-"));
153
- const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
154
- createFixture(home, "Default", [
155
- ["__Secure-1PSID", "one", ".google.com", null, 1],
156
- ["__Secure-1PSIDTS", "two", ".google.com", null, 2],
157
- ], { browser: "Brave", targetPlatform: "darwin" });
158
- const env = makeEnvironment(home, bin);
159
- const argsPath = join(home, "password-args");
160
- Object.assign(env, writePasswordCommand(bin, join(home, "password-count"), "darwin", argsPath));
161
- const result = runCookies(home, env, undefined, "darwin");
162
- assert.deepEqual(result.result.cookies, { "__Secure-1PSIDTS": "two", "__Secure-1PSID": "one" });
163
- assert.deepEqual(readFileSync(argsPath, "utf8").trim().split("\n"), [
164
- "find-generic-password", "-w", "-a", "Brave", "-s", "Brave Safe Storage",
165
- ]);
166
- rmSync(home, { recursive: true, force: true });
167
- rmSync(bin, { recursive: true, force: true });
168
- });
169
-
170
- test("browser selection checks only the requested preset", (t) => {
171
- skipWithoutPython(t);
172
- const home = mkdtempSync(join(tmpdir(), "pi-cookie-selected-browser-"));
173
- const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
174
- createFixture(home, "Profile 1", [
175
- ["__Secure-1PSID", "helium-one", ".google.com", null, 1],
176
- ["__Secure-1PSIDTS", "helium-two", ".google.com", null, 2],
177
- ], { browser: "Helium", targetPlatform: "darwin" });
178
- createFixture(home, "Profile 1", [
179
- ["__Secure-1PSID", "chrome-one", ".google.com", null, 1],
180
- ["__Secure-1PSIDTS", "chrome-two", ".google.com", null, 2],
181
- ], { browser: "Chrome", targetPlatform: "darwin" });
182
- const env = makeEnvironment(home, bin);
183
- const argsPath = join(home, "password-args");
184
- Object.assign(env, writePasswordCommand(bin, join(home, "password-count"), "darwin", argsPath));
185
- const result = runCookies(home, env, "{ browser: 'helium', profile: 'Profile 1', requiredCookies: ['__Secure-1PSID', '__Secure-1PSIDTS'] }", "darwin");
186
- assert.deepEqual(result.result.cookies, { "__Secure-1PSIDTS": "helium-two", "__Secure-1PSID": "helium-one" });
187
- assert.deepEqual(readFileSync(argsPath, "utf8").trim().split("\n"), [
188
- "find-generic-password", "-w", "-a", "Helium", "-s", "Helium Storage Key",
189
- ]);
190
- rmSync(home, { recursive: true, force: true });
191
- rmSync(bin, { recursive: true, force: true });
192
- });
193
-
194
- test("Windows Chrome profiles decrypt v10 cookies with DPAPI keys", (t) => {
195
- skipWithoutPython(t);
196
- const home = mkdtempSync(join(tmpdir(), "pi-cookie-windows-"));
197
- const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
198
- const argsPath = join(home, "powershell-args");
199
- const key = Buffer.alloc(32, 3);
200
- createFixture(home, "Default", [
201
- ["__Secure-1PSID", "", ".google.com", `hex:${encryptWindowsCookie("one", key, "v10", ".google.com")}`, 1],
202
- ["__Secure-1PSIDTS", "", ".google.com", `hex:${encryptWindowsCookie("two", key, "v10", ".google.com")}`, 2],
203
- ], { targetPlatform: "win32", windowsKey: key });
204
- const protectedValue = Buffer.from("protected").toString("base64");
205
- const env = makeEnvironment(home, bin, { LOCALAPPDATA: join(home, "AppData", "Local"), DPAPI_KEY: key.toString("base64"), DPAPI_PROTECTED: protectedValue, TEMP: tmpdir(), TMP: tmpdir(), ...writeWindowsDpapiCommand(bin, argsPath) });
206
- const result = runCookies(home, env, undefined, "win32");
207
- assert.deepEqual(result.result.cookies, { "__Secure-1PSIDTS": "two", "__Secure-1PSID": "one" });
208
- const args = readFileSync(argsPath, "utf8").trim().split("\n");
209
- assert.equal(args.includes("-EncodedCommand"), true);
210
- assert.equal(args.includes(protectedValue), false);
211
- rmSync(home, { recursive: true, force: true });
212
- rmSync(bin, { recursive: true, force: true });
213
- });
214
-
215
- test("cookie queries keep high Chromium expiry values safe", (t) => {
216
- skipWithoutPython(t);
217
- const home = mkdtempSync(join(tmpdir(), "pi-cookie-high-expiry-"));
218
- const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
219
- createFixture(home, "Profile 2", [
220
- ["__Secure-1PSID", "expired", ".google.com", null, 1],
221
- ["__Secure-1PSID", "future", ".google.com", null, "9223372036854775807"],
222
- ["__Secure-1PSIDTS", "session", ".google.com", null, 0],
223
- ]);
224
- const env = makeEnvironment(home, bin);
225
- Object.assign(env, writePasswordCommand(bin, join(home, "password-count")));
226
- const result = runCookieScript(env, "const r = await m.getBrowserCookiesForHosts({ hosts: ['www.google.com'], requestUrl: new URL('https://www.google.com/'), requiredCookies: ['__Secure-1PSID', '__Secure-1PSIDTS'] }); console.log(JSON.stringify({ result: r, diagnostic: m.getLastBrowserCookieDiagnostic() }));");
227
- assert.deepEqual(result.result.cookies, { "__Secure-1PSID": "future", "__Secure-1PSIDTS": "session" });
228
- rmSync(home, { recursive: true, force: true });
229
- rmSync(bin, { recursive: true, force: true });
230
- });
231
-
232
- test("cookie expiry filtering preserves same-second validity", (t) => {
233
- skipWithoutPython(t);
234
- const home = mkdtempSync(join(tmpdir(), "pi-cookie-subsecond-expiry-"));
235
- const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
236
- const nowMs = 1_700_000_000_500;
237
- const sameSecondFutureChromeMicros = (nowMs + 400 + 11644473600000) * 1000;
238
- createFixture(home, "Profile 2", [
239
- ["__Secure-1PSID", "future", ".google.com", null, sameSecondFutureChromeMicros],
240
- ["__Secure-1PSIDTS", "session", ".google.com", null, 0],
241
- ]);
242
- const env = makeEnvironment(home, bin);
243
- Object.assign(env, writePasswordCommand(bin, join(home, "password-count")));
244
- const result = runCookieScript(env, `Date.now = () => ${nowMs}; const r = await m.getBrowserCookiesForHosts({ hosts: ['www.google.com'], requestUrl: new URL('https://www.google.com/'), requiredCookies: ['__Secure-1PSID', '__Secure-1PSIDTS'] }); console.log(JSON.stringify({ result: r, diagnostic: m.getLastBrowserCookieDiagnostic() }));`);
245
- assert.deepEqual(result.result.cookies, { "__Secure-1PSID": "future", "__Secure-1PSIDTS": "session" });
246
- rmSync(home, { recursive: true, force: true });
247
- rmSync(bin, { recursive: true, force: true });
248
- });
249
-
250
- test("Windows Edge uses the USERPROFILE AppData fallback and reports unsupported v20 cookies", (t) => {
251
- skipWithoutPython(t);
252
- const home = mkdtempSync(join(tmpdir(), "pi-cookie-windows-edge-"));
253
- const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
254
- const key = Buffer.alloc(32, 4);
255
- createFixture(home, "Default", [
256
- ["__Secure-1PSID", "", ".google.com", `hex:${encryptWindowsCookie("one", key, "v20")}`, 1],
257
- ["__Secure-1PSIDTS", "", ".google.com", `hex:${encryptWindowsCookie("two", key, "v20")}`, 2],
258
- ], { browser: "Edge", targetPlatform: "win32", windowsKey: key });
259
- const env = makeEnvironment(home, bin, { DPAPI_KEY: key.toString("base64"), DPAPI_PROTECTED: Buffer.from("protected").toString("base64"), TEMP: tmpdir(), TMP: tmpdir() });
260
- delete env.LOCALAPPDATA;
261
- writeWindowsDpapiCommand(bin);
262
- const result = runCookies(home, env, undefined, "win32");
263
- assert.equal(result.result, null);
264
- assert.match(result.diagnostic, /v20 app-bound cookies are not supported/);
265
- rmSync(home, { recursive: true, force: true });
266
- rmSync(bin, { recursive: true, force: true });
267
- });
268
-
269
- test("required-cookie preflight avoids password invocation for unrelated profiles", (t) => {
270
- skipWithoutPython(t);
271
- const home = mkdtempSync(join(tmpdir(), "pi-cookie-preflight-"));
272
- const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
273
- createFixture(home, "Profile 1", [["NID", "unrelated", ".google.com", null, 1]]);
274
- const countPath = join(home, "password-count");
275
- const env = makeEnvironment(home, bin);
276
- Object.assign(env, writePasswordCommand(bin, countPath));
277
- const result = runCookies(home, env);
278
- assert.equal(result.result, null);
279
- assert.equal(result.diagnostic.includes("required Gemini cookies"), true);
280
- assert.equal(result.details.attempts.some((attempt) => attempt.browser === "Chrome" && attempt.profile === "Profile 1" && attempt.status === "missing-required-cookies"), true);
281
- assert.equal(existsSync(countPath), false);
282
- rmSync(home, { recursive: true, force: true });
283
- rmSync(bin, { recursive: true, force: true });
284
- });
285
-
286
- test("diagnostics report browser profile when password-store access fails", (t) => {
287
- skipWithoutPython(t);
288
- const home = mkdtempSync(join(tmpdir(), "pi-cookie-keychain-failure-"));
289
- const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
290
- createFixture(home, "Default", [
291
- ["__Secure-1PSID", "one", ".google.com", null, 1],
292
- ["__Secure-1PSIDTS", "two", ".google.com", null, 2],
293
- ], { browser: "Helium", targetPlatform: "darwin" });
294
- const env = makeEnvironment(home, bin);
295
- Object.assign(env, writeFailPasswordCommand(bin, join(home, "password-count"), "darwin"));
296
- const result = runCookies(home, env, undefined, "darwin");
297
- assert.equal(result.result, null);
298
- assert.equal(result.diagnostic, "Could not read Helium cookie encryption password");
299
- assert.deepEqual(result.details.attempts[0], { browser: "Helium", profile: "Default", status: "password-read-failed" });
300
- assert.doesNotMatch(JSON.stringify(result), /one|two|peanuts|sensitive stderr/);
301
- rmSync(home, { recursive: true, force: true });
302
- rmSync(bin, { recursive: true, force: true });
303
- });
304
-
305
- test("diagnostics distinguish required cookie decryption failure", (t) => {
306
- skipWithoutPython(t);
307
- const home = mkdtempSync(join(tmpdir(), "pi-cookie-decrypt-failure-"));
308
- const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
309
- const encrypted = `hex:${Buffer.from("v10bad-ciphertext").toString("hex")}`;
310
- createFixture(home, "Profile 2", [
311
- ["__Secure-1PSID", "", ".google.com", encrypted, 1],
312
- ["__Secure-1PSIDTS", "", ".google.com", encrypted, 2],
313
- ]);
314
- const env = makeEnvironment(home, bin);
315
- Object.assign(env, writePasswordCommand(bin, join(home, "password-count")));
316
- const result = runCookies(home, env);
317
- assert.equal(result.result, null);
318
- assert.match(result.diagnostic, /could not be decrypted/);
319
- assert.equal(result.details.attempts.some((attempt) => attempt.browser === "Chrome" && attempt.profile === "Profile 2" && attempt.status === "decryption-failed"), true);
320
- assert.doesNotMatch(JSON.stringify(result), /peanuts|bad-ciphertext/);
321
- rmSync(home, { recursive: true, force: true });
322
- rmSync(bin, { recursive: true, force: true });
323
- });
324
-
325
- test("browser encryption password is cached within a process", (t) => {
326
- skipWithoutPython(t);
327
- const home = mkdtempSync(join(tmpdir(), "pi-cookie-cache-"));
328
- const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
329
- createFixture(home, "Profile 2", [
330
- ["__Secure-1PSID", "one", ".google.com", null, 1],
331
- ["__Secure-1PSIDTS", "two", ".google.com", null, 2],
332
- ]);
333
- const countPath = join(home, "password-count");
334
- const env = makeEnvironment(home, bin);
335
- Object.assign(env, writePasswordCommand(bin, countPath));
336
- const child = spawnSync(process.execPath, ["--experimental-strip-types", "--input-type=module"], {
337
- encoding: "utf8",
338
- env,
339
- input: `const { getGoogleCookies } = await import(${JSON.stringify(moduleUrl)}); await getGoogleCookies({ profile: 'Profile 2', requiredCookies: ['__Secure-1PSID', '__Secure-1PSIDTS'] }); await getGoogleCookies({ profile: 'Profile 2', requiredCookies: ['__Secure-1PSID', '__Secure-1PSIDTS'] });`,
340
- });
341
- assert.equal(child.status, 0, child.stderr);
342
- assert.equal(readFileSync(countPath, "utf8"), "1");
343
- rmSync(home, { recursive: true, force: true });
344
- rmSync(bin, { recursive: true, force: true });
345
- });
346
-
347
- test("failed password lookups are retried instead of cached", (t) => {
348
- skipWithoutPython(t);
349
- const home = mkdtempSync(join(tmpdir(), "pi-cookie-cache-failure-"));
350
- const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
351
- createFixture(home, "Profile 2", [
352
- ["__Secure-1PSID", "one", ".google.com", null, 1],
353
- ["__Secure-1PSIDTS", "two", ".google.com", null, 2],
354
- ]);
355
- const countPath = join(home, "password-count");
356
- const env = makeEnvironment(home, bin);
357
- Object.assign(env, writeFailThenSucceedPasswordCommand(bin, countPath));
358
- const child = spawnSync(process.execPath, ["--experimental-strip-types", "--input-type=module"], {
359
- encoding: "utf8",
360
- env,
361
- input: `const { getGoogleCookies } = await import(${JSON.stringify(moduleUrl)}); const options = { profile: 'Profile 2', requiredCookies: ['__Secure-1PSID', '__Secure-1PSIDTS'] }; const first = await getGoogleCookies(options); const second = await getGoogleCookies(options); console.log(JSON.stringify({ first, second }));`,
362
- });
363
- assert.equal(child.status, 0, child.stderr);
364
- const result = JSON.parse(child.stdout);
365
- assert.equal(result.first, null);
366
- assert.deepEqual(result.second.cookies, { "__Secure-1PSIDTS": "two", "__Secure-1PSID": "one" });
367
- assert.equal(readFileSync(countPath, "utf8"), "2");
368
- rmSync(home, { recursive: true, force: true });
369
- rmSync(bin, { recursive: true, force: true });
370
- });
371
-
372
- test("configured profile names cannot escape the browser profile root", (t) => {
373
- skipWithoutPython(t);
374
- const home = mkdtempSync(join(tmpdir(), "pi-cookie-profile-traversal-"));
375
- const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
376
- const env = makeEnvironment(home, bin);
377
- const result = runCookies(home, env, "{ profile: '../Profile 2', requiredCookies: ['__Secure-1PSID'] }");
378
- assert.equal(result.result, null);
379
- assert.match(result.diagnostic, /profile directory name/);
380
- rmSync(home, { recursive: true, force: true });
381
- rmSync(bin, { recursive: true, force: true });
382
- });
383
-
384
- test("explicit profile symlinks cannot escape the browser profile root", (t) => {
385
- skipWithoutPython(t);
386
- const home = mkdtempSync(join(tmpdir(), "pi-cookie-profile-symlink-"));
387
- const outsideHome = mkdtempSync(join(tmpdir(), "pi-cookie-outside-"));
388
- const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
389
- createFixture(outsideHome, "Outside", [
390
- ["__Secure-1PSID", "one", ".google.com", null, 1],
391
- ["__Secure-1PSIDTS", "two", ".google.com", null, 2],
392
- ]);
393
- const browserRoot = process.platform === "darwin"
394
- ? join(home, "Library", "Application Support", "Google", "Chrome")
395
- : join(home, ".config", "google-chrome");
396
- const outsideProfile = process.platform === "darwin"
397
- ? join(outsideHome, "Library", "Application Support", "Google", "Chrome", "Outside")
398
- : join(outsideHome, ".config", "google-chrome", "Outside");
399
- mkdirSync(browserRoot, { recursive: true });
400
- symlinkSync(outsideProfile, join(browserRoot, "link"), "dir");
401
- const env = makeEnvironment(home, bin);
402
- Object.assign(env, writePasswordCommand(bin, join(home, "password-count")));
403
- const result = runCookies(home, env, "{ profile: 'link', requiredCookies: ['__Secure-1PSID', '__Secure-1PSIDTS'] }");
404
- assert.equal(result.result, null);
405
- assert.match(result.diagnostic, /inside the browser profile root/);
406
- rmSync(home, { recursive: true, force: true });
407
- rmSync(outsideHome, { recursive: true, force: true });
408
- rmSync(bin, { recursive: true, force: true });
409
- });
410
-
411
- test("sqlite3 CLI fallback reads a copied database when node sqlite is unavailable", (t) => {
412
- skipWithoutPython(t);
413
- const home = mkdtempSync(join(tmpdir(), "pi-cookie-fallback-"));
414
- const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
415
- createFixture(home, "Profile 2", [
416
- ["__Secure-1PSID", "one", ".google.com", null, 1],
417
- ["__Secure-1PSIDTS", "two", ".google.com", null, 2],
418
- ]);
419
- const env = makeEnvironment(home, bin, { PI_WEB_ACCESS_DISABLE_NODE_SQLITE: "1" });
420
- Object.assign(env, writePasswordCommand(bin, join(home, "password-count")));
421
- const result = runCookies(home, env);
422
- assert.deepEqual(result.result.cookies, { "__Secure-1PSIDTS": "two", "__Secure-1PSID": "one" });
423
- rmSync(home, { recursive: true, force: true });
424
- rmSync(bin, { recursive: true, force: true });
425
- });
426
-
427
- test("unavailable SQLite backends produce actionable sanitized diagnostics", (t) => {
428
- skipWithoutPython(t);
429
- const home = mkdtempSync(join(tmpdir(), "pi-cookie-diagnostic-"));
430
- const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
431
- createFixture(home, "Profile 2", [["__Secure-1PSID", "one", ".google.com", null, 1]]);
432
- const env = makeEnvironment(home, bin, { PI_WEB_ACCESS_DISABLE_NODE_SQLITE: "1", PATH: bin });
433
- const result = runCookies(home, env);
434
- assert.equal(result.result, null);
435
- assert.match(result.diagnostic, /SQLite backend unavailable/);
436
- assert.equal(result.details.attempts.some((attempt) => attempt.browser === "Chrome" && attempt.profile === "Profile 2" && attempt.status === "sqlite-unavailable"), true);
437
- assert.equal(result.details.attempts.some((attempt) => attempt.browser === "Chrome" && attempt.profile === "Profile 2" && attempt.status === "missing-required-cookies"), false);
438
- assert.doesNotMatch(result.diagnostic, /one|peanuts|stderr|password/i);
439
- rmSync(home, { recursive: true, force: true });
440
- rmSync(bin, { recursive: true, force: true });
441
- });
1
+ import assert from "node:assert/strict";
2
+ import { execFileSync, spawnSync } from "node:child_process";
3
+ import { createCipheriv, createHash } from "node:crypto";
4
+ import { chmodSync, existsSync, mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, symlinkSync } from "node:fs";
5
+ import { homedir, tmpdir } from "node:os";
6
+ import { dirname, join } from "node:path";
7
+ import { test } from "node:test";
8
+
9
+ const moduleUrl = new URL("../chrome-cookies.ts", import.meta.url).href;
10
+ const python = process.platform === "win32" ? null : "python3";
11
+
12
+ function createFixture(home, profile, rows = [], options = {}) {
13
+ if (!python) return;
14
+ const { browser = "Chrome", targetPlatform = process.platform } = options;
15
+ const base = targetPlatform === "darwin"
16
+ ? browser === "Brave"
17
+ ? join(home, "Library", "Application Support", "BraveSoftware", "Brave-Browser")
18
+ : browser === "Helium"
19
+ ? join(home, "Library", "Application Support", "net.imput.helium")
20
+ : browser === "Arc"
21
+ ? join(home, "Library", "Application Support", "Arc", "User Data")
22
+ : join(home, "Library", "Application Support", "Google", "Chrome")
23
+ : targetPlatform === "win32"
24
+ ? browser === "Edge"
25
+ ? join(home, "AppData", "Local", "Microsoft", "Edge", "User Data")
26
+ : join(home, "AppData", "Local", "Google", "Chrome", "User Data")
27
+ : join(home, ".config", "google-chrome");
28
+ const dbPath = targetPlatform === "win32" ? join(base, profile, "Network", "Cookies") : join(base, profile, "Cookies");
29
+ mkdirSync(dirname(dbPath), { recursive: true });
30
+ execFileSync(python, ["-c", `
31
+ import json, sqlite3, sys
32
+ c = sqlite3.connect(sys.argv[1])
33
+ c.execute("create table meta (key text, value integer)")
34
+ c.execute("insert into meta values ('version', 24)")
35
+ c.execute("create table cookies (name text, value text, host_key text, encrypted_value blob, expires_utc integer)")
36
+ for row in json.loads(sys.argv[2]):
37
+ encrypted = bytes.fromhex(row[3][4:]) if isinstance(row[3], str) and row[3].startswith('hex:') else row[3]
38
+ c.execute("insert into cookies values (?, ?, ?, ?, ?)", [row[0], row[1], row[2], encrypted, row[4]])
39
+ c.commit()
40
+ c.close()
41
+ `, dbPath, JSON.stringify(rows)], { stdio: "ignore" });
42
+ if (options.windowsKey) {
43
+ writeFileSync(join(base, "Local State"), JSON.stringify({ os_crypt: { encrypted_key: Buffer.concat([Buffer.from("DPAPI"), Buffer.from("protected")]).toString("base64") } }));
44
+ }
45
+ }
46
+
47
+ function encryptWindowsCookie(value, key, version = "v10", hostKey) {
48
+ const nonce = Buffer.alloc(12, 7);
49
+ const cipher = createCipheriv("aes-256-gcm", key, nonce);
50
+ const plaintext = hostKey ? Buffer.concat([createHash("sha256").update(hostKey).digest(), Buffer.from(value)]) : Buffer.from(value);
51
+ return Buffer.concat([Buffer.from(version), nonce, cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]).toString("hex");
52
+ }
53
+
54
+ function writeWindowsDpapiCommand(bin, argsPath) {
55
+ const script = "#!/bin/sh\n[ -n \"$ARGS_FILE\" ] && printf '%s\\n' \"$@\" > \"$ARGS_FILE\"\nencoded=0\nfor arg do [ \"$arg\" = \"-EncodedCommand\" ] && encoded=1; [ \"$arg\" = \"$DPAPI_PROTECTED\" ] && exit 1; done\n[ \"$encoded\" = 1 ] || exit 1\n[ \"$PIWA_PROTECTED\" = \"$DPAPI_PROTECTED\" ] || exit 1\nprintf '%s' \"$DPAPI_KEY\"\n";
56
+ writeFileSync(join(bin, "powershell.exe"), script);
57
+ chmodSync(join(bin, "powershell.exe"), 0o755);
58
+ return argsPath ? { ARGS_FILE: argsPath } : {};
59
+ }
60
+
61
+ function makeEnvironment(home, bin, extra = {}) {
62
+ const env = {
63
+ ...process.env,
64
+ HOME: home,
65
+ USERPROFILE: home,
66
+ PI_ALLOW_BROWSER_COOKIES: "1",
67
+ PATH: `${bin}:${process.env.PATH ?? ""}`,
68
+ ...extra,
69
+ };
70
+ delete env.PI_CODING_AGENT_DIR;
71
+ delete env.XDG_CONFIG_HOME;
72
+ return env;
73
+ }
74
+
75
+ function writePasswordCommand(bin, countPath, targetPlatform = process.platform, argsPath) {
76
+ const command = targetPlatform === "darwin" ? "security" : "secret-tool";
77
+ const script = `#!/bin/sh\nn=0\n[ -f "$COUNT_FILE" ] && n=$(cat "$COUNT_FILE")\nprintf '%s' $((n + 1)) > "$COUNT_FILE"\n[ -n "$ARGS_FILE" ] && printf '%s\\n' "$@" > "$ARGS_FILE"\nprintf peanuts\n`;
78
+ writeFileSync(join(bin, command), script);
79
+ chmodSync(join(bin, command), 0o755);
80
+ return { COUNT_FILE: countPath, ...(argsPath ? { ARGS_FILE: argsPath } : {}) };
81
+ }
82
+
83
+ function writeFailThenSucceedPasswordCommand(bin, countPath) {
84
+ const command = process.platform === "darwin" ? "security" : "secret-tool";
85
+ const script = `#!/bin/sh\nn=0\n[ -f "$COUNT_FILE" ] && n=$(cat "$COUNT_FILE")\nn=$((n + 1))\nprintf '%s' $n > "$COUNT_FILE"\n[ "$n" = 1 ] && exit 1\nprintf peanuts\n`;
86
+ writeFileSync(join(bin, command), script);
87
+ chmodSync(join(bin, command), 0o755);
88
+ return { COUNT_FILE: countPath };
89
+ }
90
+
91
+ function writeFailPasswordCommand(bin, countPath, targetPlatform = process.platform) {
92
+ const command = targetPlatform === "darwin" ? "security" : "secret-tool";
93
+ const script = `#!/bin/sh\nn=0\n[ -f "$COUNT_FILE" ] && n=$(cat "$COUNT_FILE")\nprintf '%s' $((n + 1)) > "$COUNT_FILE"\nprintf 'sensitive stderr' >&2\nexit 1\n`;
94
+ writeFileSync(join(bin, command), script);
95
+ chmodSync(join(bin, command), 0o755);
96
+ return { COUNT_FILE: countPath };
97
+ }
98
+
99
+ function runCookies(home, env, options = "{ requiredCookies: ['__Secure-1PSID', '__Secure-1PSIDTS'] }", platformOverride) {
100
+ return runCookieScript(env, `const r = await m.getGoogleCookies(${options}); console.log(JSON.stringify({ result: r, diagnostic: m.getLastGoogleCookieDiagnostic(), details: m.getLastGoogleCookieDiagnosticDetails() }));`, platformOverride);
101
+ }
102
+
103
+ function runCookieScript(env, body, platformOverride) {
104
+ const override = platformOverride
105
+ ? `Object.defineProperty(process, "platform", { value: ${JSON.stringify(platformOverride)} }); `
106
+ : "";
107
+ const child = spawnSync(process.execPath, ["--experimental-strip-types", "--input-type=module"], {
108
+ encoding: "utf8",
109
+ env,
110
+ input: `${override}const m = await import(${JSON.stringify(moduleUrl)}); ${body}`,
111
+ });
112
+ assert.equal(child.status, 0, child.stderr);
113
+ return JSON.parse(child.stdout);
114
+ }
115
+
116
+ function skipWithoutPython(t) {
117
+ if (!python) t.skip("fixture creation requires Python on macOS/Linux");
118
+ }
119
+
120
+ test("cookie extraction remains opt-in even when a browser database exists", (t) => {
121
+ skipWithoutPython(t);
122
+ const home = mkdtempSync(join(tmpdir(), "pi-cookie-opt-out-"));
123
+ const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
124
+ createFixture(home, "Default", [["__Secure-1PSID", "one", ".google.com", null, 1]]);
125
+ const env = makeEnvironment(home, bin);
126
+ delete env.PI_ALLOW_BROWSER_COOKIES;
127
+ const result = runCookies(home, env);
128
+ assert.equal(result.result, null);
129
+ assert.match(result.diagnostic, /disabled/);
130
+ rmSync(home, { recursive: true, force: true });
131
+ rmSync(bin, { recursive: true, force: true });
132
+ });
133
+
134
+ test("auto-discovery finds a non-default Chromium profile", (t) => {
135
+ skipWithoutPython(t);
136
+ const home = mkdtempSync(join(tmpdir(), "pi-cookie-profile-"));
137
+ const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
138
+ createFixture(home, "Profile 2", [
139
+ ["__Secure-1PSID", "one", ".google.com", null, 1],
140
+ ["__Secure-1PSIDTS", "two", ".google.com", null, 2],
141
+ ]);
142
+ const env = makeEnvironment(home, bin);
143
+ Object.assign(env, writePasswordCommand(bin, join(home, "password-count")));
144
+ const result = runCookies(home, env);
145
+ assert.deepEqual(result.result.cookies, { "__Secure-1PSIDTS": "two", "__Secure-1PSID": "one" });
146
+ rmSync(home, { recursive: true, force: true });
147
+ rmSync(bin, { recursive: true, force: true });
148
+ });
149
+
150
+ test("auto-discovery finds a Brave profile on macOS", (t) => {
151
+ skipWithoutPython(t);
152
+ const home = mkdtempSync(join(tmpdir(), "pi-cookie-brave-profile-"));
153
+ const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
154
+ createFixture(home, "Default", [
155
+ ["__Secure-1PSID", "one", ".google.com", null, 1],
156
+ ["__Secure-1PSIDTS", "two", ".google.com", null, 2],
157
+ ], { browser: "Brave", targetPlatform: "darwin" });
158
+ const env = makeEnvironment(home, bin);
159
+ const argsPath = join(home, "password-args");
160
+ Object.assign(env, writePasswordCommand(bin, join(home, "password-count"), "darwin", argsPath));
161
+ const result = runCookies(home, env, undefined, "darwin");
162
+ assert.deepEqual(result.result.cookies, { "__Secure-1PSIDTS": "two", "__Secure-1PSID": "one" });
163
+ assert.deepEqual(readFileSync(argsPath, "utf8").trim().split("\n"), [
164
+ "find-generic-password", "-w", "-a", "Brave", "-s", "Brave Safe Storage",
165
+ ]);
166
+ rmSync(home, { recursive: true, force: true });
167
+ rmSync(bin, { recursive: true, force: true });
168
+ });
169
+
170
+ test("browser selection checks only the requested preset", (t) => {
171
+ skipWithoutPython(t);
172
+ const home = mkdtempSync(join(tmpdir(), "pi-cookie-selected-browser-"));
173
+ const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
174
+ createFixture(home, "Profile 1", [
175
+ ["__Secure-1PSID", "helium-one", ".google.com", null, 1],
176
+ ["__Secure-1PSIDTS", "helium-two", ".google.com", null, 2],
177
+ ], { browser: "Helium", targetPlatform: "darwin" });
178
+ createFixture(home, "Profile 1", [
179
+ ["__Secure-1PSID", "chrome-one", ".google.com", null, 1],
180
+ ["__Secure-1PSIDTS", "chrome-two", ".google.com", null, 2],
181
+ ], { browser: "Chrome", targetPlatform: "darwin" });
182
+ const env = makeEnvironment(home, bin);
183
+ const argsPath = join(home, "password-args");
184
+ Object.assign(env, writePasswordCommand(bin, join(home, "password-count"), "darwin", argsPath));
185
+ const result = runCookies(home, env, "{ browser: 'helium', profile: 'Profile 1', requiredCookies: ['__Secure-1PSID', '__Secure-1PSIDTS'] }", "darwin");
186
+ assert.deepEqual(result.result.cookies, { "__Secure-1PSIDTS": "helium-two", "__Secure-1PSID": "helium-one" });
187
+ assert.deepEqual(readFileSync(argsPath, "utf8").trim().split("\n"), [
188
+ "find-generic-password", "-w", "-a", "Helium", "-s", "Helium Storage Key",
189
+ ]);
190
+ rmSync(home, { recursive: true, force: true });
191
+ rmSync(bin, { recursive: true, force: true });
192
+ });
193
+
194
+ test("Windows Chrome profiles decrypt v10 cookies with DPAPI keys", (t) => {
195
+ skipWithoutPython(t);
196
+ const home = mkdtempSync(join(tmpdir(), "pi-cookie-windows-"));
197
+ const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
198
+ const argsPath = join(home, "powershell-args");
199
+ const key = Buffer.alloc(32, 3);
200
+ createFixture(home, "Default", [
201
+ ["__Secure-1PSID", "", ".google.com", `hex:${encryptWindowsCookie("one", key, "v10", ".google.com")}`, 1],
202
+ ["__Secure-1PSIDTS", "", ".google.com", `hex:${encryptWindowsCookie("two", key, "v10", ".google.com")}`, 2],
203
+ ], { targetPlatform: "win32", windowsKey: key });
204
+ const protectedValue = Buffer.from("protected").toString("base64");
205
+ const env = makeEnvironment(home, bin, { LOCALAPPDATA: join(home, "AppData", "Local"), DPAPI_KEY: key.toString("base64"), DPAPI_PROTECTED: protectedValue, TEMP: tmpdir(), TMP: tmpdir(), ...writeWindowsDpapiCommand(bin, argsPath) });
206
+ const result = runCookies(home, env, undefined, "win32");
207
+ assert.deepEqual(result.result.cookies, { "__Secure-1PSIDTS": "two", "__Secure-1PSID": "one" });
208
+ const args = readFileSync(argsPath, "utf8").trim().split("\n");
209
+ assert.equal(args.includes("-EncodedCommand"), true);
210
+ assert.equal(args.includes(protectedValue), false);
211
+ rmSync(home, { recursive: true, force: true });
212
+ rmSync(bin, { recursive: true, force: true });
213
+ });
214
+
215
+ test("cookie queries keep high Chromium expiry values safe", (t) => {
216
+ skipWithoutPython(t);
217
+ const home = mkdtempSync(join(tmpdir(), "pi-cookie-high-expiry-"));
218
+ const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
219
+ createFixture(home, "Profile 2", [
220
+ ["__Secure-1PSID", "expired", ".google.com", null, 1],
221
+ ["__Secure-1PSID", "future", ".google.com", null, "9223372036854775807"],
222
+ ["__Secure-1PSIDTS", "session", ".google.com", null, 0],
223
+ ]);
224
+ const env = makeEnvironment(home, bin);
225
+ Object.assign(env, writePasswordCommand(bin, join(home, "password-count")));
226
+ const result = runCookieScript(env, "const r = await m.getBrowserCookiesForHosts({ hosts: ['www.google.com'], requestUrl: new URL('https://www.google.com/'), requiredCookies: ['__Secure-1PSID', '__Secure-1PSIDTS'] }); console.log(JSON.stringify({ result: r, diagnostic: m.getLastBrowserCookieDiagnostic() }));");
227
+ assert.deepEqual(result.result.cookies, { "__Secure-1PSID": "future", "__Secure-1PSIDTS": "session" });
228
+ rmSync(home, { recursive: true, force: true });
229
+ rmSync(bin, { recursive: true, force: true });
230
+ });
231
+
232
+ test("cookie expiry filtering preserves same-second validity", (t) => {
233
+ skipWithoutPython(t);
234
+ const home = mkdtempSync(join(tmpdir(), "pi-cookie-subsecond-expiry-"));
235
+ const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
236
+ const nowMs = 1_700_000_000_500;
237
+ const sameSecondFutureChromeMicros = (nowMs + 400 + 11644473600000) * 1000;
238
+ createFixture(home, "Profile 2", [
239
+ ["__Secure-1PSID", "future", ".google.com", null, sameSecondFutureChromeMicros],
240
+ ["__Secure-1PSIDTS", "session", ".google.com", null, 0],
241
+ ]);
242
+ const env = makeEnvironment(home, bin);
243
+ Object.assign(env, writePasswordCommand(bin, join(home, "password-count")));
244
+ const result = runCookieScript(env, `Date.now = () => ${nowMs}; const r = await m.getBrowserCookiesForHosts({ hosts: ['www.google.com'], requestUrl: new URL('https://www.google.com/'), requiredCookies: ['__Secure-1PSID', '__Secure-1PSIDTS'] }); console.log(JSON.stringify({ result: r, diagnostic: m.getLastBrowserCookieDiagnostic() }));`);
245
+ assert.deepEqual(result.result.cookies, { "__Secure-1PSID": "future", "__Secure-1PSIDTS": "session" });
246
+ rmSync(home, { recursive: true, force: true });
247
+ rmSync(bin, { recursive: true, force: true });
248
+ });
249
+
250
+ test("Windows Edge uses the USERPROFILE AppData fallback and reports unsupported v20 cookies", (t) => {
251
+ skipWithoutPython(t);
252
+ const home = mkdtempSync(join(tmpdir(), "pi-cookie-windows-edge-"));
253
+ const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
254
+ const key = Buffer.alloc(32, 4);
255
+ createFixture(home, "Default", [
256
+ ["__Secure-1PSID", "", ".google.com", `hex:${encryptWindowsCookie("one", key, "v20")}`, 1],
257
+ ["__Secure-1PSIDTS", "", ".google.com", `hex:${encryptWindowsCookie("two", key, "v20")}`, 2],
258
+ ], { browser: "Edge", targetPlatform: "win32", windowsKey: key });
259
+ const env = makeEnvironment(home, bin, { DPAPI_KEY: key.toString("base64"), DPAPI_PROTECTED: Buffer.from("protected").toString("base64"), TEMP: tmpdir(), TMP: tmpdir() });
260
+ delete env.LOCALAPPDATA;
261
+ writeWindowsDpapiCommand(bin);
262
+ const result = runCookies(home, env, undefined, "win32");
263
+ assert.equal(result.result, null);
264
+ assert.match(result.diagnostic, /v20 app-bound cookies are not supported/);
265
+ rmSync(home, { recursive: true, force: true });
266
+ rmSync(bin, { recursive: true, force: true });
267
+ });
268
+
269
+ test("required-cookie preflight avoids password invocation for unrelated profiles", (t) => {
270
+ skipWithoutPython(t);
271
+ const home = mkdtempSync(join(tmpdir(), "pi-cookie-preflight-"));
272
+ const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
273
+ createFixture(home, "Profile 1", [["NID", "unrelated", ".google.com", null, 1]]);
274
+ const countPath = join(home, "password-count");
275
+ const env = makeEnvironment(home, bin);
276
+ Object.assign(env, writePasswordCommand(bin, countPath));
277
+ const result = runCookies(home, env);
278
+ assert.equal(result.result, null);
279
+ assert.equal(result.diagnostic.includes("required Gemini cookies"), true);
280
+ assert.equal(result.details.attempts.some((attempt) => attempt.browser === "Chrome" && attempt.profile === "Profile 1" && attempt.status === "missing-required-cookies"), true);
281
+ assert.equal(existsSync(countPath), false);
282
+ rmSync(home, { recursive: true, force: true });
283
+ rmSync(bin, { recursive: true, force: true });
284
+ });
285
+
286
+ test("diagnostics report browser profile when password-store access fails", (t) => {
287
+ skipWithoutPython(t);
288
+ const home = mkdtempSync(join(tmpdir(), "pi-cookie-keychain-failure-"));
289
+ const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
290
+ createFixture(home, "Default", [
291
+ ["__Secure-1PSID", "one", ".google.com", null, 1],
292
+ ["__Secure-1PSIDTS", "two", ".google.com", null, 2],
293
+ ], { browser: "Helium", targetPlatform: "darwin" });
294
+ const env = makeEnvironment(home, bin);
295
+ Object.assign(env, writeFailPasswordCommand(bin, join(home, "password-count"), "darwin"));
296
+ const result = runCookies(home, env, undefined, "darwin");
297
+ assert.equal(result.result, null);
298
+ assert.equal(result.diagnostic, "Could not read Helium cookie encryption password");
299
+ assert.deepEqual(result.details.attempts[0], { browser: "Helium", profile: "Default", status: "password-read-failed" });
300
+ assert.doesNotMatch(JSON.stringify(result), /one|two|peanuts|sensitive stderr/);
301
+ rmSync(home, { recursive: true, force: true });
302
+ rmSync(bin, { recursive: true, force: true });
303
+ });
304
+
305
+ test("diagnostics distinguish required cookie decryption failure", (t) => {
306
+ skipWithoutPython(t);
307
+ const home = mkdtempSync(join(tmpdir(), "pi-cookie-decrypt-failure-"));
308
+ const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
309
+ const encrypted = `hex:${Buffer.from("v10bad-ciphertext").toString("hex")}`;
310
+ createFixture(home, "Profile 2", [
311
+ ["__Secure-1PSID", "", ".google.com", encrypted, 1],
312
+ ["__Secure-1PSIDTS", "", ".google.com", encrypted, 2],
313
+ ]);
314
+ const env = makeEnvironment(home, bin);
315
+ Object.assign(env, writePasswordCommand(bin, join(home, "password-count")));
316
+ const result = runCookies(home, env);
317
+ assert.equal(result.result, null);
318
+ assert.match(result.diagnostic, /could not be decrypted/);
319
+ assert.equal(result.details.attempts.some((attempt) => attempt.browser === "Chrome" && attempt.profile === "Profile 2" && attempt.status === "decryption-failed"), true);
320
+ assert.doesNotMatch(JSON.stringify(result), /peanuts|bad-ciphertext/);
321
+ rmSync(home, { recursive: true, force: true });
322
+ rmSync(bin, { recursive: true, force: true });
323
+ });
324
+
325
+ test("browser encryption password is cached within a process", (t) => {
326
+ skipWithoutPython(t);
327
+ const home = mkdtempSync(join(tmpdir(), "pi-cookie-cache-"));
328
+ const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
329
+ createFixture(home, "Profile 2", [
330
+ ["__Secure-1PSID", "one", ".google.com", null, 1],
331
+ ["__Secure-1PSIDTS", "two", ".google.com", null, 2],
332
+ ]);
333
+ const countPath = join(home, "password-count");
334
+ const env = makeEnvironment(home, bin);
335
+ Object.assign(env, writePasswordCommand(bin, countPath));
336
+ const child = spawnSync(process.execPath, ["--experimental-strip-types", "--input-type=module"], {
337
+ encoding: "utf8",
338
+ env,
339
+ input: `const { getGoogleCookies } = await import(${JSON.stringify(moduleUrl)}); await getGoogleCookies({ profile: 'Profile 2', requiredCookies: ['__Secure-1PSID', '__Secure-1PSIDTS'] }); await getGoogleCookies({ profile: 'Profile 2', requiredCookies: ['__Secure-1PSID', '__Secure-1PSIDTS'] });`,
340
+ });
341
+ assert.equal(child.status, 0, child.stderr);
342
+ assert.equal(readFileSync(countPath, "utf8"), "1");
343
+ rmSync(home, { recursive: true, force: true });
344
+ rmSync(bin, { recursive: true, force: true });
345
+ });
346
+
347
+ test("failed password lookups are retried instead of cached", (t) => {
348
+ skipWithoutPython(t);
349
+ const home = mkdtempSync(join(tmpdir(), "pi-cookie-cache-failure-"));
350
+ const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
351
+ createFixture(home, "Profile 2", [
352
+ ["__Secure-1PSID", "one", ".google.com", null, 1],
353
+ ["__Secure-1PSIDTS", "two", ".google.com", null, 2],
354
+ ]);
355
+ const countPath = join(home, "password-count");
356
+ const env = makeEnvironment(home, bin);
357
+ Object.assign(env, writeFailThenSucceedPasswordCommand(bin, countPath));
358
+ const child = spawnSync(process.execPath, ["--experimental-strip-types", "--input-type=module"], {
359
+ encoding: "utf8",
360
+ env,
361
+ input: `const { getGoogleCookies } = await import(${JSON.stringify(moduleUrl)}); const options = { profile: 'Profile 2', requiredCookies: ['__Secure-1PSID', '__Secure-1PSIDTS'] }; const first = await getGoogleCookies(options); const second = await getGoogleCookies(options); console.log(JSON.stringify({ first, second }));`,
362
+ });
363
+ assert.equal(child.status, 0, child.stderr);
364
+ const result = JSON.parse(child.stdout);
365
+ assert.equal(result.first, null);
366
+ assert.deepEqual(result.second.cookies, { "__Secure-1PSIDTS": "two", "__Secure-1PSID": "one" });
367
+ assert.equal(readFileSync(countPath, "utf8"), "2");
368
+ rmSync(home, { recursive: true, force: true });
369
+ rmSync(bin, { recursive: true, force: true });
370
+ });
371
+
372
+ test("configured profile names cannot escape the browser profile root", (t) => {
373
+ skipWithoutPython(t);
374
+ const home = mkdtempSync(join(tmpdir(), "pi-cookie-profile-traversal-"));
375
+ const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
376
+ const env = makeEnvironment(home, bin);
377
+ const result = runCookies(home, env, "{ profile: '../Profile 2', requiredCookies: ['__Secure-1PSID'] }");
378
+ assert.equal(result.result, null);
379
+ assert.match(result.diagnostic, /profile directory name/);
380
+ rmSync(home, { recursive: true, force: true });
381
+ rmSync(bin, { recursive: true, force: true });
382
+ });
383
+
384
+ test("explicit profile symlinks cannot escape the browser profile root", (t) => {
385
+ skipWithoutPython(t);
386
+ const home = mkdtempSync(join(tmpdir(), "pi-cookie-profile-symlink-"));
387
+ const outsideHome = mkdtempSync(join(tmpdir(), "pi-cookie-outside-"));
388
+ const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
389
+ createFixture(outsideHome, "Outside", [
390
+ ["__Secure-1PSID", "one", ".google.com", null, 1],
391
+ ["__Secure-1PSIDTS", "two", ".google.com", null, 2],
392
+ ]);
393
+ const browserRoot = process.platform === "darwin"
394
+ ? join(home, "Library", "Application Support", "Google", "Chrome")
395
+ : join(home, ".config", "google-chrome");
396
+ const outsideProfile = process.platform === "darwin"
397
+ ? join(outsideHome, "Library", "Application Support", "Google", "Chrome", "Outside")
398
+ : join(outsideHome, ".config", "google-chrome", "Outside");
399
+ mkdirSync(browserRoot, { recursive: true });
400
+ symlinkSync(outsideProfile, join(browserRoot, "link"), "dir");
401
+ const env = makeEnvironment(home, bin);
402
+ Object.assign(env, writePasswordCommand(bin, join(home, "password-count")));
403
+ const result = runCookies(home, env, "{ profile: 'link', requiredCookies: ['__Secure-1PSID', '__Secure-1PSIDTS'] }");
404
+ assert.equal(result.result, null);
405
+ assert.match(result.diagnostic, /inside the browser profile root/);
406
+ rmSync(home, { recursive: true, force: true });
407
+ rmSync(outsideHome, { recursive: true, force: true });
408
+ rmSync(bin, { recursive: true, force: true });
409
+ });
410
+
411
+ test("sqlite3 CLI fallback reads a copied database when node sqlite is unavailable", (t) => {
412
+ skipWithoutPython(t);
413
+ const home = mkdtempSync(join(tmpdir(), "pi-cookie-fallback-"));
414
+ const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
415
+ createFixture(home, "Profile 2", [
416
+ ["__Secure-1PSID", "one", ".google.com", null, 1],
417
+ ["__Secure-1PSIDTS", "two", ".google.com", null, 2],
418
+ ]);
419
+ const env = makeEnvironment(home, bin, { PI_WEB_ACCESS_DISABLE_NODE_SQLITE: "1" });
420
+ Object.assign(env, writePasswordCommand(bin, join(home, "password-count")));
421
+ const result = runCookies(home, env);
422
+ assert.deepEqual(result.result.cookies, { "__Secure-1PSIDTS": "two", "__Secure-1PSID": "one" });
423
+ rmSync(home, { recursive: true, force: true });
424
+ rmSync(bin, { recursive: true, force: true });
425
+ });
426
+
427
+ test("unavailable SQLite backends produce actionable sanitized diagnostics", (t) => {
428
+ skipWithoutPython(t);
429
+ const home = mkdtempSync(join(tmpdir(), "pi-cookie-diagnostic-"));
430
+ const bin = mkdtempSync(join(tmpdir(), "pi-cookie-bin-"));
431
+ createFixture(home, "Profile 2", [["__Secure-1PSID", "one", ".google.com", null, 1]]);
432
+ const env = makeEnvironment(home, bin, { PI_WEB_ACCESS_DISABLE_NODE_SQLITE: "1", PATH: bin });
433
+ const result = runCookies(home, env);
434
+ assert.equal(result.result, null);
435
+ assert.match(result.diagnostic, /SQLite backend unavailable/);
436
+ assert.equal(result.details.attempts.some((attempt) => attempt.browser === "Chrome" && attempt.profile === "Profile 2" && attempt.status === "sqlite-unavailable"), true);
437
+ assert.equal(result.details.attempts.some((attempt) => attempt.browser === "Chrome" && attempt.profile === "Profile 2" && attempt.status === "missing-required-cookies"), false);
438
+ assert.doesNotMatch(result.diagnostic, /one|peanuts|stderr|password/i);
439
+ rmSync(home, { recursive: true, force: true });
440
+ rmSync(bin, { recursive: true, force: true });
441
+ });