@runchr/gstack-antigravity 0.1.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.

Potentially problematic release.


This version of @runchr/gstack-antigravity might be problematic. Click here for more details.

Files changed (297) hide show
  1. package/.agents/rules/ETHOS.md +129 -0
  2. package/.agents/rules/global-gstack.md +117 -0
  3. package/.agents/rules/persona-gstack-autoplan.md +14 -0
  4. package/.agents/rules/persona-gstack-benchmark.md +14 -0
  5. package/.agents/rules/persona-gstack-browse.md +14 -0
  6. package/.agents/rules/persona-gstack-canary.md +14 -0
  7. package/.agents/rules/persona-gstack-careful.md +14 -0
  8. package/.agents/rules/persona-gstack-codex.md +14 -0
  9. package/.agents/rules/persona-gstack-cso.md +14 -0
  10. package/.agents/rules/persona-gstack-design-consultation.md +14 -0
  11. package/.agents/rules/persona-gstack-design-review.md +14 -0
  12. package/.agents/rules/persona-gstack-document-release.md +14 -0
  13. package/.agents/rules/persona-gstack-freeze.md +14 -0
  14. package/.agents/rules/persona-gstack-gstack-upgrade.md +14 -0
  15. package/.agents/rules/persona-gstack-guard.md +14 -0
  16. package/.agents/rules/persona-gstack-investigate.md +14 -0
  17. package/.agents/rules/persona-gstack-land-and-deploy.md +14 -0
  18. package/.agents/rules/persona-gstack-office-hours.md +14 -0
  19. package/.agents/rules/persona-gstack-plan-ceo-review.md +14 -0
  20. package/.agents/rules/persona-gstack-plan-design-review.md +14 -0
  21. package/.agents/rules/persona-gstack-plan-eng-review.md +14 -0
  22. package/.agents/rules/persona-gstack-qa-only.md +14 -0
  23. package/.agents/rules/persona-gstack-qa.md +14 -0
  24. package/.agents/rules/persona-gstack-retro.md +14 -0
  25. package/.agents/rules/persona-gstack-review.md +14 -0
  26. package/.agents/rules/persona-gstack-setup-browser-cookies.md +14 -0
  27. package/.agents/rules/persona-gstack-setup-deploy.md +14 -0
  28. package/.agents/rules/persona-gstack-ship.md +14 -0
  29. package/.agents/rules/persona-gstack-unfreeze.md +14 -0
  30. package/.agents/rules/persona-gstack.md +40 -0
  31. package/.agents/rules/recursive-identities.md +22 -0
  32. package/.agents/workflows/autoplan.md +30 -0
  33. package/.agents/workflows/benchmark.md +31 -0
  34. package/.agents/workflows/browse.md +26 -0
  35. package/.agents/workflows/canary.md +33 -0
  36. package/.agents/workflows/careful.md +22 -0
  37. package/.agents/workflows/codex.md +36 -0
  38. package/.agents/workflows/cso.md +29 -0
  39. package/.agents/workflows/design-consultation.md +28 -0
  40. package/.agents/workflows/design-review.md +28 -0
  41. package/.agents/workflows/document-release.md +32 -0
  42. package/.agents/workflows/freeze.md +17 -0
  43. package/.agents/workflows/gstack-upgrade.md +54 -0
  44. package/.agents/workflows/gstack.md +56 -0
  45. package/.agents/workflows/guard.md +18 -0
  46. package/.agents/workflows/investigate.md +37 -0
  47. package/.agents/workflows/land-and-deploy.md +35 -0
  48. package/.agents/workflows/office-hours.md +27 -0
  49. package/.agents/workflows/plan-ceo-review.md +34 -0
  50. package/.agents/workflows/plan-design-review.md +31 -0
  51. package/.agents/workflows/plan-eng-review.md +28 -0
  52. package/.agents/workflows/qa-only.md +28 -0
  53. package/.agents/workflows/qa.md +73 -0
  54. package/.agents/workflows/retro.md +34 -0
  55. package/.agents/workflows/review.md +30 -0
  56. package/.agents/workflows/setup-browser-cookies.md +15 -0
  57. package/.agents/workflows/setup-cookies.md +8 -0
  58. package/.agents/workflows/setup-deploy.md +21 -0
  59. package/.agents/workflows/ship.md +93 -0
  60. package/.agents/workflows/unfreeze.md +12 -0
  61. package/LICENSE +22 -0
  62. package/README.md +189 -0
  63. package/README_KO.md +191 -0
  64. package/bin/install.js +105 -0
  65. package/gstack-origin/.agents/skills/gstack/SKILL.md +651 -0
  66. package/gstack-origin/.agents/skills/gstack-autoplan/SKILL.md +678 -0
  67. package/gstack-origin/.agents/skills/gstack-benchmark/SKILL.md +482 -0
  68. package/gstack-origin/.agents/skills/gstack-browse/SKILL.md +511 -0
  69. package/gstack-origin/.agents/skills/gstack-canary/SKILL.md +486 -0
  70. package/gstack-origin/.agents/skills/gstack-careful/SKILL.md +50 -0
  71. package/gstack-origin/.agents/skills/gstack-cso/SKILL.md +607 -0
  72. package/gstack-origin/.agents/skills/gstack-design-consultation/SKILL.md +615 -0
  73. package/gstack-origin/.agents/skills/gstack-design-review/SKILL.md +988 -0
  74. package/gstack-origin/.agents/skills/gstack-document-release/SKILL.md +604 -0
  75. package/gstack-origin/.agents/skills/gstack-freeze/SKILL.md +67 -0
  76. package/gstack-origin/.agents/skills/gstack-guard/SKILL.md +62 -0
  77. package/gstack-origin/.agents/skills/gstack-investigate/SKILL.md +415 -0
  78. package/gstack-origin/.agents/skills/gstack-land-and-deploy/SKILL.md +873 -0
  79. package/gstack-origin/.agents/skills/gstack-office-hours/SKILL.md +986 -0
  80. package/gstack-origin/.agents/skills/gstack-plan-ceo-review/SKILL.md +1268 -0
  81. package/gstack-origin/.agents/skills/gstack-plan-design-review/SKILL.md +668 -0
  82. package/gstack-origin/.agents/skills/gstack-plan-eng-review/SKILL.md +826 -0
  83. package/gstack-origin/.agents/skills/gstack-qa/SKILL.md +1006 -0
  84. package/gstack-origin/.agents/skills/gstack-qa-only/SKILL.md +626 -0
  85. package/gstack-origin/.agents/skills/gstack-retro/SKILL.md +1065 -0
  86. package/gstack-origin/.agents/skills/gstack-review/SKILL.md +704 -0
  87. package/gstack-origin/.agents/skills/gstack-setup-browser-cookies/SKILL.md +325 -0
  88. package/gstack-origin/.agents/skills/gstack-setup-deploy/SKILL.md +450 -0
  89. package/gstack-origin/.agents/skills/gstack-ship/SKILL.md +1312 -0
  90. package/gstack-origin/.agents/skills/gstack-unfreeze/SKILL.md +36 -0
  91. package/gstack-origin/.agents/skills/gstack-upgrade/SKILL.md +220 -0
  92. package/gstack-origin/.env.example +5 -0
  93. package/gstack-origin/.github/workflows/skill-docs.yml +17 -0
  94. package/gstack-origin/AGENTS.md +49 -0
  95. package/gstack-origin/ARCHITECTURE.md +359 -0
  96. package/gstack-origin/BROWSER.md +271 -0
  97. package/gstack-origin/CHANGELOG.md +800 -0
  98. package/gstack-origin/CLAUDE.md +284 -0
  99. package/gstack-origin/CONTRIBUTING.md +370 -0
  100. package/gstack-origin/ETHOS.md +129 -0
  101. package/gstack-origin/LICENSE +21 -0
  102. package/gstack-origin/README.md +228 -0
  103. package/gstack-origin/SKILL.md +657 -0
  104. package/gstack-origin/SKILL.md.tmpl +281 -0
  105. package/gstack-origin/TODOS.md +564 -0
  106. package/gstack-origin/VERSION +1 -0
  107. package/gstack-origin/autoplan/SKILL.md +689 -0
  108. package/gstack-origin/autoplan/SKILL.md.tmpl +416 -0
  109. package/gstack-origin/benchmark/SKILL.md +489 -0
  110. package/gstack-origin/benchmark/SKILL.md.tmpl +233 -0
  111. package/gstack-origin/bin/dev-setup +68 -0
  112. package/gstack-origin/bin/dev-teardown +56 -0
  113. package/gstack-origin/bin/gstack-analytics +191 -0
  114. package/gstack-origin/bin/gstack-community-dashboard +113 -0
  115. package/gstack-origin/bin/gstack-config +38 -0
  116. package/gstack-origin/bin/gstack-diff-scope +71 -0
  117. package/gstack-origin/bin/gstack-global-discover.ts +591 -0
  118. package/gstack-origin/bin/gstack-repo-mode +93 -0
  119. package/gstack-origin/bin/gstack-review-log +9 -0
  120. package/gstack-origin/bin/gstack-review-read +12 -0
  121. package/gstack-origin/bin/gstack-slug +15 -0
  122. package/gstack-origin/bin/gstack-telemetry-log +158 -0
  123. package/gstack-origin/bin/gstack-telemetry-sync +127 -0
  124. package/gstack-origin/bin/gstack-update-check +196 -0
  125. package/gstack-origin/browse/SKILL.md +517 -0
  126. package/gstack-origin/browse/SKILL.md.tmpl +141 -0
  127. package/gstack-origin/browse/bin/find-browse +21 -0
  128. package/gstack-origin/browse/bin/remote-slug +14 -0
  129. package/gstack-origin/browse/scripts/build-node-server.sh +48 -0
  130. package/gstack-origin/browse/src/browser-manager.ts +634 -0
  131. package/gstack-origin/browse/src/buffers.ts +137 -0
  132. package/gstack-origin/browse/src/bun-polyfill.cjs +109 -0
  133. package/gstack-origin/browse/src/cli.ts +420 -0
  134. package/gstack-origin/browse/src/commands.ts +111 -0
  135. package/gstack-origin/browse/src/config.ts +150 -0
  136. package/gstack-origin/browse/src/cookie-import-browser.ts +417 -0
  137. package/gstack-origin/browse/src/cookie-picker-routes.ts +207 -0
  138. package/gstack-origin/browse/src/cookie-picker-ui.ts +541 -0
  139. package/gstack-origin/browse/src/find-browse.ts +61 -0
  140. package/gstack-origin/browse/src/meta-commands.ts +269 -0
  141. package/gstack-origin/browse/src/platform.ts +17 -0
  142. package/gstack-origin/browse/src/read-commands.ts +335 -0
  143. package/gstack-origin/browse/src/server.ts +369 -0
  144. package/gstack-origin/browse/src/snapshot.ts +398 -0
  145. package/gstack-origin/browse/src/url-validation.ts +91 -0
  146. package/gstack-origin/browse/src/write-commands.ts +352 -0
  147. package/gstack-origin/browse/test/bun-polyfill.test.ts +72 -0
  148. package/gstack-origin/browse/test/commands.test.ts +1836 -0
  149. package/gstack-origin/browse/test/config.test.ts +250 -0
  150. package/gstack-origin/browse/test/cookie-import-browser.test.ts +397 -0
  151. package/gstack-origin/browse/test/cookie-picker-routes.test.ts +205 -0
  152. package/gstack-origin/browse/test/find-browse.test.ts +50 -0
  153. package/gstack-origin/browse/test/fixtures/basic.html +33 -0
  154. package/gstack-origin/browse/test/fixtures/cursor-interactive.html +22 -0
  155. package/gstack-origin/browse/test/fixtures/dialog.html +15 -0
  156. package/gstack-origin/browse/test/fixtures/empty.html +2 -0
  157. package/gstack-origin/browse/test/fixtures/forms.html +55 -0
  158. package/gstack-origin/browse/test/fixtures/qa-eval-checkout.html +108 -0
  159. package/gstack-origin/browse/test/fixtures/qa-eval-spa.html +98 -0
  160. package/gstack-origin/browse/test/fixtures/qa-eval.html +51 -0
  161. package/gstack-origin/browse/test/fixtures/responsive.html +49 -0
  162. package/gstack-origin/browse/test/fixtures/snapshot.html +55 -0
  163. package/gstack-origin/browse/test/fixtures/spa.html +24 -0
  164. package/gstack-origin/browse/test/fixtures/states.html +17 -0
  165. package/gstack-origin/browse/test/fixtures/upload.html +25 -0
  166. package/gstack-origin/browse/test/gstack-config.test.ts +125 -0
  167. package/gstack-origin/browse/test/gstack-update-check.test.ts +467 -0
  168. package/gstack-origin/browse/test/handoff.test.ts +235 -0
  169. package/gstack-origin/browse/test/path-validation.test.ts +63 -0
  170. package/gstack-origin/browse/test/platform.test.ts +37 -0
  171. package/gstack-origin/browse/test/snapshot.test.ts +467 -0
  172. package/gstack-origin/browse/test/test-server.ts +57 -0
  173. package/gstack-origin/browse/test/url-validation.test.ts +72 -0
  174. package/gstack-origin/canary/SKILL.md +493 -0
  175. package/gstack-origin/canary/SKILL.md.tmpl +220 -0
  176. package/gstack-origin/careful/SKILL.md +59 -0
  177. package/gstack-origin/careful/SKILL.md.tmpl +57 -0
  178. package/gstack-origin/careful/bin/check-careful.sh +112 -0
  179. package/gstack-origin/codex/SKILL.md +677 -0
  180. package/gstack-origin/codex/SKILL.md.tmpl +356 -0
  181. package/gstack-origin/conductor.json +6 -0
  182. package/gstack-origin/cso/SKILL.md +615 -0
  183. package/gstack-origin/cso/SKILL.md.tmpl +376 -0
  184. package/gstack-origin/design-consultation/SKILL.md +625 -0
  185. package/gstack-origin/design-consultation/SKILL.md.tmpl +369 -0
  186. package/gstack-origin/design-review/SKILL.md +998 -0
  187. package/gstack-origin/design-review/SKILL.md.tmpl +262 -0
  188. package/gstack-origin/docs/images/github-2013.png +0 -0
  189. package/gstack-origin/docs/images/github-2026.png +0 -0
  190. package/gstack-origin/docs/skills.md +877 -0
  191. package/gstack-origin/document-release/SKILL.md +613 -0
  192. package/gstack-origin/document-release/SKILL.md.tmpl +357 -0
  193. package/gstack-origin/freeze/SKILL.md +82 -0
  194. package/gstack-origin/freeze/SKILL.md.tmpl +80 -0
  195. package/gstack-origin/freeze/bin/check-freeze.sh +68 -0
  196. package/gstack-origin/gstack-upgrade/SKILL.md +226 -0
  197. package/gstack-origin/gstack-upgrade/SKILL.md.tmpl +224 -0
  198. package/gstack-origin/guard/SKILL.md +82 -0
  199. package/gstack-origin/guard/SKILL.md.tmpl +80 -0
  200. package/gstack-origin/investigate/SKILL.md +435 -0
  201. package/gstack-origin/investigate/SKILL.md.tmpl +196 -0
  202. package/gstack-origin/land-and-deploy/SKILL.md +880 -0
  203. package/gstack-origin/land-and-deploy/SKILL.md.tmpl +575 -0
  204. package/gstack-origin/office-hours/SKILL.md +996 -0
  205. package/gstack-origin/office-hours/SKILL.md.tmpl +624 -0
  206. package/gstack-origin/package.json +55 -0
  207. package/gstack-origin/plan-ceo-review/SKILL.md +1277 -0
  208. package/gstack-origin/plan-ceo-review/SKILL.md.tmpl +838 -0
  209. package/gstack-origin/plan-design-review/SKILL.md +676 -0
  210. package/gstack-origin/plan-design-review/SKILL.md.tmpl +314 -0
  211. package/gstack-origin/plan-eng-review/SKILL.md +836 -0
  212. package/gstack-origin/plan-eng-review/SKILL.md.tmpl +279 -0
  213. package/gstack-origin/qa/SKILL.md +1016 -0
  214. package/gstack-origin/qa/SKILL.md.tmpl +316 -0
  215. package/gstack-origin/qa/references/issue-taxonomy.md +85 -0
  216. package/gstack-origin/qa/templates/qa-report-template.md +126 -0
  217. package/gstack-origin/qa-only/SKILL.md +633 -0
  218. package/gstack-origin/qa-only/SKILL.md.tmpl +101 -0
  219. package/gstack-origin/retro/SKILL.md +1072 -0
  220. package/gstack-origin/retro/SKILL.md.tmpl +833 -0
  221. package/gstack-origin/review/SKILL.md +849 -0
  222. package/gstack-origin/review/SKILL.md.tmpl +259 -0
  223. package/gstack-origin/review/TODOS-format.md +62 -0
  224. package/gstack-origin/review/checklist.md +190 -0
  225. package/gstack-origin/review/design-checklist.md +132 -0
  226. package/gstack-origin/review/greptile-triage.md +220 -0
  227. package/gstack-origin/scripts/analytics.ts +190 -0
  228. package/gstack-origin/scripts/dev-skill.ts +82 -0
  229. package/gstack-origin/scripts/eval-compare.ts +96 -0
  230. package/gstack-origin/scripts/eval-list.ts +116 -0
  231. package/gstack-origin/scripts/eval-select.ts +86 -0
  232. package/gstack-origin/scripts/eval-summary.ts +187 -0
  233. package/gstack-origin/scripts/eval-watch.ts +172 -0
  234. package/gstack-origin/scripts/gen-skill-docs.ts +2414 -0
  235. package/gstack-origin/scripts/skill-check.ts +167 -0
  236. package/gstack-origin/setup +269 -0
  237. package/gstack-origin/setup-browser-cookies/SKILL.md +330 -0
  238. package/gstack-origin/setup-browser-cookies/SKILL.md.tmpl +74 -0
  239. package/gstack-origin/setup-deploy/SKILL.md +459 -0
  240. package/gstack-origin/setup-deploy/SKILL.md.tmpl +220 -0
  241. package/gstack-origin/ship/SKILL.md +1457 -0
  242. package/gstack-origin/ship/SKILL.md.tmpl +528 -0
  243. package/gstack-origin/supabase/config.sh +10 -0
  244. package/gstack-origin/supabase/functions/community-pulse/index.ts +59 -0
  245. package/gstack-origin/supabase/functions/telemetry-ingest/index.ts +135 -0
  246. package/gstack-origin/supabase/functions/update-check/index.ts +37 -0
  247. package/gstack-origin/supabase/migrations/001_telemetry.sql +89 -0
  248. package/gstack-origin/test/analytics.test.ts +277 -0
  249. package/gstack-origin/test/codex-e2e.test.ts +197 -0
  250. package/gstack-origin/test/fixtures/coverage-audit-fixture.ts +76 -0
  251. package/gstack-origin/test/fixtures/eval-baselines.json +7 -0
  252. package/gstack-origin/test/fixtures/qa-eval-checkout-ground-truth.json +43 -0
  253. package/gstack-origin/test/fixtures/qa-eval-ground-truth.json +43 -0
  254. package/gstack-origin/test/fixtures/qa-eval-spa-ground-truth.json +43 -0
  255. package/gstack-origin/test/fixtures/review-eval-design-slop.css +86 -0
  256. package/gstack-origin/test/fixtures/review-eval-design-slop.html +41 -0
  257. package/gstack-origin/test/fixtures/review-eval-enum-diff.rb +30 -0
  258. package/gstack-origin/test/fixtures/review-eval-enum.rb +27 -0
  259. package/gstack-origin/test/fixtures/review-eval-vuln.rb +14 -0
  260. package/gstack-origin/test/gemini-e2e.test.ts +173 -0
  261. package/gstack-origin/test/gen-skill-docs.test.ts +1049 -0
  262. package/gstack-origin/test/global-discover.test.ts +187 -0
  263. package/gstack-origin/test/helpers/codex-session-runner.ts +282 -0
  264. package/gstack-origin/test/helpers/e2e-helpers.ts +239 -0
  265. package/gstack-origin/test/helpers/eval-store.test.ts +548 -0
  266. package/gstack-origin/test/helpers/eval-store.ts +689 -0
  267. package/gstack-origin/test/helpers/gemini-session-runner.test.ts +104 -0
  268. package/gstack-origin/test/helpers/gemini-session-runner.ts +201 -0
  269. package/gstack-origin/test/helpers/llm-judge.ts +130 -0
  270. package/gstack-origin/test/helpers/observability.test.ts +283 -0
  271. package/gstack-origin/test/helpers/session-runner.test.ts +96 -0
  272. package/gstack-origin/test/helpers/session-runner.ts +357 -0
  273. package/gstack-origin/test/helpers/skill-parser.ts +206 -0
  274. package/gstack-origin/test/helpers/touchfiles.ts +260 -0
  275. package/gstack-origin/test/hook-scripts.test.ts +373 -0
  276. package/gstack-origin/test/skill-e2e-browse.test.ts +293 -0
  277. package/gstack-origin/test/skill-e2e-deploy.test.ts +279 -0
  278. package/gstack-origin/test/skill-e2e-design.test.ts +614 -0
  279. package/gstack-origin/test/skill-e2e-plan.test.ts +538 -0
  280. package/gstack-origin/test/skill-e2e-qa-bugs.test.ts +194 -0
  281. package/gstack-origin/test/skill-e2e-qa-workflow.test.ts +412 -0
  282. package/gstack-origin/test/skill-e2e-review.test.ts +535 -0
  283. package/gstack-origin/test/skill-e2e-workflow.test.ts +586 -0
  284. package/gstack-origin/test/skill-e2e.test.ts +3325 -0
  285. package/gstack-origin/test/skill-llm-eval.test.ts +787 -0
  286. package/gstack-origin/test/skill-parser.test.ts +179 -0
  287. package/gstack-origin/test/skill-routing-e2e.test.ts +605 -0
  288. package/gstack-origin/test/skill-validation.test.ts +1520 -0
  289. package/gstack-origin/test/telemetry.test.ts +278 -0
  290. package/gstack-origin/test/touchfiles.test.ts +262 -0
  291. package/gstack-origin/unfreeze/SKILL.md +40 -0
  292. package/gstack-origin/unfreeze/SKILL.md.tmpl +38 -0
  293. package/package.json +38 -0
  294. package/scripts/install-antigravity-skill.ps1 +33 -0
  295. package/scripts/install-antigravity-skill.sh +41 -0
  296. package/scripts/sync-gstack-origin.ps1 +37 -0
  297. package/scripts/sync-gstack-origin.sh +35 -0
@@ -0,0 +1,250 @@
1
+ import { describe, test, expect } from 'bun:test';
2
+ import { resolveConfig, ensureStateDir, readVersionHash, getGitRoot, getRemoteSlug } from '../src/config';
3
+ import * as fs from 'fs';
4
+ import * as path from 'path';
5
+ import * as os from 'os';
6
+
7
+ describe('config', () => {
8
+ describe('getGitRoot', () => {
9
+ test('returns a path when in a git repo', () => {
10
+ const root = getGitRoot();
11
+ expect(root).not.toBeNull();
12
+ expect(fs.existsSync(path.join(root!, '.git'))).toBe(true);
13
+ });
14
+ });
15
+
16
+ describe('resolveConfig', () => {
17
+ test('uses git root by default', () => {
18
+ const config = resolveConfig({});
19
+ const gitRoot = getGitRoot();
20
+ expect(gitRoot).not.toBeNull();
21
+ expect(config.projectDir).toBe(gitRoot);
22
+ expect(config.stateDir).toBe(path.join(gitRoot!, '.gstack'));
23
+ expect(config.stateFile).toBe(path.join(gitRoot!, '.gstack', 'browse.json'));
24
+ });
25
+
26
+ test('derives paths from BROWSE_STATE_FILE when set', () => {
27
+ const stateFile = '/tmp/test-config/.gstack/browse.json';
28
+ const config = resolveConfig({ BROWSE_STATE_FILE: stateFile });
29
+ expect(config.stateFile).toBe(stateFile);
30
+ expect(config.stateDir).toBe('/tmp/test-config/.gstack');
31
+ expect(config.projectDir).toBe('/tmp/test-config');
32
+ });
33
+
34
+ test('log paths are in stateDir', () => {
35
+ const config = resolveConfig({});
36
+ expect(config.consoleLog).toBe(path.join(config.stateDir, 'browse-console.log'));
37
+ expect(config.networkLog).toBe(path.join(config.stateDir, 'browse-network.log'));
38
+ expect(config.dialogLog).toBe(path.join(config.stateDir, 'browse-dialog.log'));
39
+ });
40
+ });
41
+
42
+ describe('ensureStateDir', () => {
43
+ test('creates directory if it does not exist', () => {
44
+ const tmpDir = path.join(os.tmpdir(), `browse-config-test-${Date.now()}`);
45
+ const config = resolveConfig({ BROWSE_STATE_FILE: path.join(tmpDir, '.gstack', 'browse.json') });
46
+ expect(fs.existsSync(config.stateDir)).toBe(false);
47
+ ensureStateDir(config);
48
+ expect(fs.existsSync(config.stateDir)).toBe(true);
49
+ // Cleanup
50
+ fs.rmSync(tmpDir, { recursive: true, force: true });
51
+ });
52
+
53
+ test('is a no-op if directory already exists', () => {
54
+ const tmpDir = path.join(os.tmpdir(), `browse-config-test-${Date.now()}`);
55
+ const stateDir = path.join(tmpDir, '.gstack');
56
+ fs.mkdirSync(stateDir, { recursive: true });
57
+ const config = resolveConfig({ BROWSE_STATE_FILE: path.join(stateDir, 'browse.json') });
58
+ ensureStateDir(config); // should not throw
59
+ expect(fs.existsSync(config.stateDir)).toBe(true);
60
+ // Cleanup
61
+ fs.rmSync(tmpDir, { recursive: true, force: true });
62
+ });
63
+
64
+ test('adds .gstack/ to .gitignore if not present', () => {
65
+ const tmpDir = path.join(os.tmpdir(), `browse-gitignore-test-${Date.now()}`);
66
+ fs.mkdirSync(tmpDir, { recursive: true });
67
+ fs.writeFileSync(path.join(tmpDir, '.gitignore'), 'node_modules/\n');
68
+ const config = resolveConfig({ BROWSE_STATE_FILE: path.join(tmpDir, '.gstack', 'browse.json') });
69
+ ensureStateDir(config);
70
+ const content = fs.readFileSync(path.join(tmpDir, '.gitignore'), 'utf-8');
71
+ expect(content).toContain('.gstack/');
72
+ expect(content).toBe('node_modules/\n.gstack/\n');
73
+ fs.rmSync(tmpDir, { recursive: true, force: true });
74
+ });
75
+
76
+ test('does not duplicate .gstack/ in .gitignore', () => {
77
+ const tmpDir = path.join(os.tmpdir(), `browse-gitignore-test-${Date.now()}`);
78
+ fs.mkdirSync(tmpDir, { recursive: true });
79
+ fs.writeFileSync(path.join(tmpDir, '.gitignore'), 'node_modules/\n.gstack/\n');
80
+ const config = resolveConfig({ BROWSE_STATE_FILE: path.join(tmpDir, '.gstack', 'browse.json') });
81
+ ensureStateDir(config);
82
+ const content = fs.readFileSync(path.join(tmpDir, '.gitignore'), 'utf-8');
83
+ expect(content).toBe('node_modules/\n.gstack/\n');
84
+ fs.rmSync(tmpDir, { recursive: true, force: true });
85
+ });
86
+
87
+ test('handles .gitignore without trailing newline', () => {
88
+ const tmpDir = path.join(os.tmpdir(), `browse-gitignore-test-${Date.now()}`);
89
+ fs.mkdirSync(tmpDir, { recursive: true });
90
+ fs.writeFileSync(path.join(tmpDir, '.gitignore'), 'node_modules');
91
+ const config = resolveConfig({ BROWSE_STATE_FILE: path.join(tmpDir, '.gstack', 'browse.json') });
92
+ ensureStateDir(config);
93
+ const content = fs.readFileSync(path.join(tmpDir, '.gitignore'), 'utf-8');
94
+ expect(content).toBe('node_modules\n.gstack/\n');
95
+ fs.rmSync(tmpDir, { recursive: true, force: true });
96
+ });
97
+
98
+ test('logs warning to browse-server.log on non-ENOENT gitignore error', () => {
99
+ const tmpDir = path.join(os.tmpdir(), `browse-gitignore-test-${Date.now()}`);
100
+ fs.mkdirSync(tmpDir, { recursive: true });
101
+ // Create a read-only .gitignore (no .gstack/ entry → would try to append)
102
+ fs.writeFileSync(path.join(tmpDir, '.gitignore'), 'node_modules/\n');
103
+ fs.chmodSync(path.join(tmpDir, '.gitignore'), 0o444);
104
+ const config = resolveConfig({ BROWSE_STATE_FILE: path.join(tmpDir, '.gstack', 'browse.json') });
105
+ ensureStateDir(config); // should not throw
106
+ // Verify warning was written to server log
107
+ const logPath = path.join(config.stateDir, 'browse-server.log');
108
+ expect(fs.existsSync(logPath)).toBe(true);
109
+ const logContent = fs.readFileSync(logPath, 'utf-8');
110
+ expect(logContent).toContain('Warning: could not update .gitignore');
111
+ // .gitignore should remain unchanged
112
+ const gitignoreContent = fs.readFileSync(path.join(tmpDir, '.gitignore'), 'utf-8');
113
+ expect(gitignoreContent).toBe('node_modules/\n');
114
+ // Cleanup
115
+ fs.chmodSync(path.join(tmpDir, '.gitignore'), 0o644);
116
+ fs.rmSync(tmpDir, { recursive: true, force: true });
117
+ });
118
+
119
+ test('skips if no .gitignore exists', () => {
120
+ const tmpDir = path.join(os.tmpdir(), `browse-gitignore-test-${Date.now()}`);
121
+ fs.mkdirSync(tmpDir, { recursive: true });
122
+ const config = resolveConfig({ BROWSE_STATE_FILE: path.join(tmpDir, '.gstack', 'browse.json') });
123
+ ensureStateDir(config);
124
+ expect(fs.existsSync(path.join(tmpDir, '.gitignore'))).toBe(false);
125
+ fs.rmSync(tmpDir, { recursive: true, force: true });
126
+ });
127
+ });
128
+
129
+ describe('getRemoteSlug', () => {
130
+ test('returns owner-repo format for current repo', () => {
131
+ const slug = getRemoteSlug();
132
+ // This repo has an origin remote — should return a slug
133
+ expect(slug).toBeTruthy();
134
+ expect(slug).toMatch(/^[a-zA-Z0-9._-]+-[a-zA-Z0-9._-]+$/);
135
+ });
136
+
137
+ test('parses SSH remote URLs', () => {
138
+ // Test the regex directly since we can't mock Bun.spawnSync easily
139
+ const url = 'git@github.com:garrytan/gstack.git';
140
+ const match = url.match(/[:/]([^/]+)\/([^/]+?)(?:\.git)?$/);
141
+ expect(match).not.toBeNull();
142
+ expect(`${match![1]}-${match![2]}`).toBe('garrytan-gstack');
143
+ });
144
+
145
+ test('parses HTTPS remote URLs', () => {
146
+ const url = 'https://github.com/garrytan/gstack.git';
147
+ const match = url.match(/[:/]([^/]+)\/([^/]+?)(?:\.git)?$/);
148
+ expect(match).not.toBeNull();
149
+ expect(`${match![1]}-${match![2]}`).toBe('garrytan-gstack');
150
+ });
151
+
152
+ test('parses HTTPS remote URLs without .git suffix', () => {
153
+ const url = 'https://github.com/garrytan/gstack';
154
+ const match = url.match(/[:/]([^/]+)\/([^/]+?)(?:\.git)?$/);
155
+ expect(match).not.toBeNull();
156
+ expect(`${match![1]}-${match![2]}`).toBe('garrytan-gstack');
157
+ });
158
+ });
159
+
160
+ describe('readVersionHash', () => {
161
+ test('returns null when .version file does not exist', () => {
162
+ const result = readVersionHash('/nonexistent/path/browse');
163
+ expect(result).toBeNull();
164
+ });
165
+
166
+ test('reads version from .version file adjacent to execPath', () => {
167
+ const tmpDir = path.join(os.tmpdir(), `browse-version-test-${Date.now()}`);
168
+ fs.mkdirSync(tmpDir, { recursive: true });
169
+ const versionFile = path.join(tmpDir, '.version');
170
+ fs.writeFileSync(versionFile, 'abc123def\n');
171
+ const result = readVersionHash(path.join(tmpDir, 'browse'));
172
+ expect(result).toBe('abc123def');
173
+ // Cleanup
174
+ fs.rmSync(tmpDir, { recursive: true, force: true });
175
+ });
176
+ });
177
+ });
178
+
179
+ describe('resolveServerScript', () => {
180
+ // Import the function from cli.ts
181
+ const { resolveServerScript } = require('../src/cli');
182
+
183
+ test('uses BROWSE_SERVER_SCRIPT env when set', () => {
184
+ const result = resolveServerScript({ BROWSE_SERVER_SCRIPT: '/custom/server.ts' }, '', '');
185
+ expect(result).toBe('/custom/server.ts');
186
+ });
187
+
188
+ test('finds server.ts adjacent to cli.ts in dev mode', () => {
189
+ const srcDir = path.resolve(__dirname, '../src');
190
+ const result = resolveServerScript({}, srcDir, '');
191
+ expect(result).toBe(path.join(srcDir, 'server.ts'));
192
+ });
193
+
194
+ test('throws when server.ts cannot be found', () => {
195
+ expect(() => resolveServerScript({}, '/nonexistent/$bunfs', '/nonexistent/browse'))
196
+ .toThrow('Cannot find server.ts');
197
+ });
198
+ });
199
+
200
+ describe('resolveNodeServerScript', () => {
201
+ const { resolveNodeServerScript } = require('../src/cli');
202
+
203
+ test('finds server-node.mjs in dist from dev mode', () => {
204
+ const srcDir = path.resolve(__dirname, '../src');
205
+ const distFile = path.resolve(srcDir, '..', 'dist', 'server-node.mjs');
206
+ const fs = require('fs');
207
+ // Only test if the file exists (it may not be built yet)
208
+ if (fs.existsSync(distFile)) {
209
+ const result = resolveNodeServerScript(srcDir, '');
210
+ expect(result).toBe(distFile);
211
+ }
212
+ });
213
+
214
+ test('returns null when server-node.mjs does not exist', () => {
215
+ const result = resolveNodeServerScript('/nonexistent/$bunfs', '/nonexistent/browse');
216
+ expect(result).toBeNull();
217
+ });
218
+
219
+ test('finds server-node.mjs adjacent to compiled binary', () => {
220
+ const distDir = path.resolve(__dirname, '../dist');
221
+ const distFile = path.join(distDir, 'server-node.mjs');
222
+ const fs = require('fs');
223
+ if (fs.existsSync(distFile)) {
224
+ const result = resolveNodeServerScript('/$bunfs/something', path.join(distDir, 'browse'));
225
+ expect(result).toBe(distFile);
226
+ }
227
+ });
228
+ });
229
+
230
+ describe('version mismatch detection', () => {
231
+ test('detects when versions differ', () => {
232
+ const stateVersion = 'abc123';
233
+ const currentVersion = 'def456';
234
+ expect(stateVersion !== currentVersion).toBe(true);
235
+ });
236
+
237
+ test('no mismatch when versions match', () => {
238
+ const stateVersion = 'abc123';
239
+ const currentVersion = 'abc123';
240
+ expect(stateVersion !== currentVersion).toBe(false);
241
+ });
242
+
243
+ test('no mismatch when either version is null', () => {
244
+ const currentVersion: string | null = null;
245
+ const stateVersion: string | undefined = 'abc123';
246
+ // Version mismatch only triggers when both are present
247
+ const shouldRestart = currentVersion !== null && stateVersion !== undefined && currentVersion !== stateVersion;
248
+ expect(shouldRestart).toBe(false);
249
+ });
250
+ });
@@ -0,0 +1,397 @@
1
+ /**
2
+ * Unit tests for cookie-import-browser.ts
3
+ *
4
+ * Uses a fixture SQLite database with cookies encrypted using a known test key.
5
+ * Mocks Keychain access to return the test password.
6
+ *
7
+ * Test key derivation (matches real Chromium pipeline):
8
+ * password = "test-keychain-password"
9
+ * key = PBKDF2(password, "saltysalt", 1003, 16, sha1)
10
+ *
11
+ * Encryption: AES-128-CBC with IV = 16 × 0x20, prefix "v10"
12
+ * First 32 bytes of plaintext = HMAC-SHA256 tag (random for tests)
13
+ * Remaining bytes = actual cookie value
14
+ */
15
+
16
+ import { describe, test, expect, beforeAll, afterAll, mock } from 'bun:test';
17
+ import { Database } from 'bun:sqlite';
18
+ import * as crypto from 'crypto';
19
+ import * as fs from 'fs';
20
+ import * as path from 'path';
21
+ import * as os from 'os';
22
+
23
+ // ─── Test Constants ─────────────────────────────────────────────
24
+
25
+ const TEST_PASSWORD = 'test-keychain-password';
26
+ const TEST_KEY = crypto.pbkdf2Sync(TEST_PASSWORD, 'saltysalt', 1003, 16, 'sha1');
27
+ const IV = Buffer.alloc(16, 0x20);
28
+ const CHROMIUM_EPOCH_OFFSET = 11644473600000000n;
29
+
30
+ // Fixture DB path
31
+ const FIXTURE_DIR = path.join(import.meta.dir, 'fixtures');
32
+ const FIXTURE_DB = path.join(FIXTURE_DIR, 'test-cookies.db');
33
+
34
+ // ─── Encryption Helper ──────────────────────────────────────────
35
+
36
+ function encryptCookieValue(value: string): Buffer {
37
+ // 32-byte HMAC tag (random for test) + actual value
38
+ const hmacTag = crypto.randomBytes(32);
39
+ const plaintext = Buffer.concat([hmacTag, Buffer.from(value, 'utf-8')]);
40
+
41
+ // PKCS7 pad to AES block size (16 bytes)
42
+ const blockSize = 16;
43
+ const padLen = blockSize - (plaintext.length % blockSize);
44
+ const padded = Buffer.concat([plaintext, Buffer.alloc(padLen, padLen)]);
45
+
46
+ const cipher = crypto.createCipheriv('aes-128-cbc', TEST_KEY, IV);
47
+ cipher.setAutoPadding(false); // We padded manually
48
+ const encrypted = Buffer.concat([cipher.update(padded), cipher.final()]);
49
+
50
+ // Prefix with "v10"
51
+ return Buffer.concat([Buffer.from('v10'), encrypted]);
52
+ }
53
+
54
+ function chromiumEpoch(unixSeconds: number): bigint {
55
+ return BigInt(unixSeconds) * 1000000n + CHROMIUM_EPOCH_OFFSET;
56
+ }
57
+
58
+ // ─── Create Fixture Database ────────────────────────────────────
59
+
60
+ function createFixtureDb() {
61
+ fs.mkdirSync(FIXTURE_DIR, { recursive: true });
62
+ if (fs.existsSync(FIXTURE_DB)) fs.unlinkSync(FIXTURE_DB);
63
+
64
+ const db = new Database(FIXTURE_DB);
65
+ db.run(`CREATE TABLE cookies (
66
+ host_key TEXT NOT NULL,
67
+ name TEXT NOT NULL,
68
+ value TEXT NOT NULL DEFAULT '',
69
+ encrypted_value BLOB NOT NULL DEFAULT x'',
70
+ path TEXT NOT NULL DEFAULT '/',
71
+ expires_utc INTEGER NOT NULL DEFAULT 0,
72
+ is_secure INTEGER NOT NULL DEFAULT 0,
73
+ is_httponly INTEGER NOT NULL DEFAULT 0,
74
+ has_expires INTEGER NOT NULL DEFAULT 0,
75
+ samesite INTEGER NOT NULL DEFAULT 1
76
+ )`);
77
+
78
+ const insert = db.prepare(`INSERT INTO cookies
79
+ (host_key, name, value, encrypted_value, path, expires_utc, is_secure, is_httponly, has_expires, samesite)
80
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`);
81
+
82
+ const futureExpiry = Number(chromiumEpoch(Math.floor(Date.now() / 1000) + 86400 * 365));
83
+ const pastExpiry = Number(chromiumEpoch(Math.floor(Date.now() / 1000) - 86400));
84
+
85
+ // Domain 1: .github.com — 3 encrypted cookies
86
+ insert.run('.github.com', 'session_id', '', encryptCookieValue('abc123'), '/', futureExpiry, 1, 1, 1, 1);
87
+ insert.run('.github.com', 'user_token', '', encryptCookieValue('token-xyz'), '/', futureExpiry, 1, 0, 1, 0);
88
+ insert.run('.github.com', 'theme', '', encryptCookieValue('dark'), '/', futureExpiry, 0, 0, 1, 2);
89
+
90
+ // Domain 2: .google.com — 2 cookies
91
+ insert.run('.google.com', 'NID', '', encryptCookieValue('google-nid-value'), '/', futureExpiry, 1, 1, 1, 0);
92
+ insert.run('.google.com', 'SID', '', encryptCookieValue('google-sid-value'), '/', futureExpiry, 1, 1, 1, 1);
93
+
94
+ // Domain 3: .example.com — 1 unencrypted cookie (value field set, no encrypted_value)
95
+ insert.run('.example.com', 'plain_cookie', 'hello-world', Buffer.alloc(0), '/', futureExpiry, 0, 0, 1, 1);
96
+
97
+ // Domain 4: .expired.com — 1 expired cookie (should be filtered out)
98
+ insert.run('.expired.com', 'old', '', encryptCookieValue('expired-value'), '/', pastExpiry, 0, 0, 1, 1);
99
+
100
+ // Domain 5: .session.com — session cookie (has_expires=0)
101
+ insert.run('.session.com', 'sess', '', encryptCookieValue('session-value'), '/', 0, 1, 1, 0, 1);
102
+
103
+ // Domain 6: .corrupt.com — cookie with garbage encrypted_value
104
+ insert.run('.corrupt.com', 'bad', '', Buffer.from('v10' + 'not-valid-ciphertext-at-all'), '/', futureExpiry, 0, 0, 1, 1);
105
+
106
+ // Domain 7: .mixed.com — one good, one corrupt
107
+ insert.run('.mixed.com', 'good', '', encryptCookieValue('mixed-good'), '/', futureExpiry, 0, 0, 1, 1);
108
+ insert.run('.mixed.com', 'bad', '', Buffer.from('v10' + 'garbage-data-here!!!'), '/', futureExpiry, 0, 0, 1, 1);
109
+
110
+ db.close();
111
+ }
112
+
113
+ // ─── Mock Setup ─────────────────────────────────────────────────
114
+ // We need to mock:
115
+ // 1. The Keychain access (getKeychainPassword) to return TEST_PASSWORD
116
+ // 2. The cookie DB path resolution to use our fixture DB
117
+
118
+ // We'll import the module after setting up the mocks
119
+ let findInstalledBrowsers: any;
120
+ let listDomains: any;
121
+ let importCookies: any;
122
+ let CookieImportError: any;
123
+
124
+ beforeAll(async () => {
125
+ createFixtureDb();
126
+
127
+ // Mock Bun.spawn to return test password for keychain access
128
+ const origSpawn = Bun.spawn;
129
+ // @ts-ignore - monkey-patching for test
130
+ Bun.spawn = function(cmd: any, opts: any) {
131
+ // Intercept security find-generic-password calls
132
+ if (Array.isArray(cmd) && cmd[0] === 'security' && cmd[1] === 'find-generic-password') {
133
+ const service = cmd[3]; // -s <service>
134
+ // Return test password for any known test service
135
+ return {
136
+ stdout: new ReadableStream({
137
+ start(controller) {
138
+ controller.enqueue(new TextEncoder().encode(TEST_PASSWORD + '\n'));
139
+ controller.close();
140
+ }
141
+ }),
142
+ stderr: new ReadableStream({
143
+ start(controller) { controller.close(); }
144
+ }),
145
+ exited: Promise.resolve(0),
146
+ kill: () => {},
147
+ };
148
+ }
149
+ // Pass through other spawn calls
150
+ return origSpawn(cmd, opts);
151
+ };
152
+
153
+ // Import the module (uses our mocked Bun.spawn)
154
+ const mod = await import('../src/cookie-import-browser');
155
+ findInstalledBrowsers = mod.findInstalledBrowsers;
156
+ listDomains = mod.listDomains;
157
+ importCookies = mod.importCookies;
158
+ CookieImportError = mod.CookieImportError;
159
+ });
160
+
161
+ afterAll(() => {
162
+ // Clean up fixture DB
163
+ try { fs.unlinkSync(FIXTURE_DB); } catch {}
164
+ try { fs.rmdirSync(FIXTURE_DIR); } catch {}
165
+ });
166
+
167
+ // ─── Helper: Override DB path for tests ─────────────────────────
168
+ // The real code resolves paths via ~/Library/Application Support/<browser>/Default/Cookies
169
+ // We need to test against our fixture DB directly. We'll test the pure decryption functions
170
+ // by calling importCookies with a browser that points to our fixture.
171
+ // Since the module uses a hardcoded registry, we test the decryption logic via a different approach:
172
+ // We'll directly call the internal decryption by setting up the DB in the expected location.
173
+
174
+ // For the unit tests below, we test the decryption pipeline by:
175
+ // 1. Creating encrypted cookies with known values
176
+ // 2. Decrypting them with the module's decryption logic
177
+ // The actual DB path resolution is tested separately.
178
+
179
+ // ─── Tests ──────────────────────────────────────────────────────
180
+
181
+ describe('Cookie Import Browser', () => {
182
+
183
+ describe('Decryption Pipeline', () => {
184
+ test('encrypts and decrypts round-trip correctly', () => {
185
+ // Verify our test helper produces valid ciphertext
186
+ const encrypted = encryptCookieValue('hello-world');
187
+ expect(encrypted.slice(0, 3).toString()).toBe('v10');
188
+
189
+ // Decrypt manually to verify
190
+ const ciphertext = encrypted.slice(3);
191
+ const decipher = crypto.createDecipheriv('aes-128-cbc', TEST_KEY, IV);
192
+ const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
193
+ // Skip 32-byte HMAC tag
194
+ const value = plaintext.slice(32).toString('utf-8');
195
+ expect(value).toBe('hello-world');
196
+ });
197
+
198
+ test('handles empty encrypted_value', () => {
199
+ const encrypted = encryptCookieValue('');
200
+ const ciphertext = encrypted.slice(3);
201
+ const decipher = crypto.createDecipheriv('aes-128-cbc', TEST_KEY, IV);
202
+ const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
203
+ // 32-byte tag + empty value → slice(32) = empty
204
+ expect(plaintext.length).toBe(32); // just the HMAC tag, padded to block boundary? Actually 32 + 0 padded = 48
205
+ // With PKCS7 padding: 32 bytes + 16 bytes of padding = 48 bytes padded → decrypts to 32 bytes + padding removed = 32 bytes
206
+ });
207
+
208
+ test('handles special characters in cookie values', () => {
209
+ const specialValue = 'a=b&c=d; path=/; expires=Thu, 01 Jan 2099';
210
+ const encrypted = encryptCookieValue(specialValue);
211
+ const ciphertext = encrypted.slice(3);
212
+ const decipher = crypto.createDecipheriv('aes-128-cbc', TEST_KEY, IV);
213
+ const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
214
+ expect(plaintext.slice(32).toString('utf-8')).toBe(specialValue);
215
+ });
216
+ });
217
+
218
+ describe('Fixture DB Structure', () => {
219
+ test('fixture DB has correct domain counts', () => {
220
+ const db = new Database(FIXTURE_DB, { readonly: true });
221
+ const rows = db.query(
222
+ `SELECT host_key, COUNT(*) as count FROM cookies GROUP BY host_key ORDER BY count DESC`
223
+ ).all() as any[];
224
+ db.close();
225
+
226
+ const counts = Object.fromEntries(rows.map((r: any) => [r.host_key, r.count]));
227
+ expect(counts['.github.com']).toBe(3);
228
+ expect(counts['.google.com']).toBe(2);
229
+ expect(counts['.example.com']).toBe(1);
230
+ expect(counts['.expired.com']).toBe(1);
231
+ expect(counts['.session.com']).toBe(1);
232
+ expect(counts['.corrupt.com']).toBe(1);
233
+ expect(counts['.mixed.com']).toBe(2);
234
+ });
235
+
236
+ test('encrypted cookies in fixture have v10 prefix', () => {
237
+ const db = new Database(FIXTURE_DB, { readonly: true });
238
+ const rows = db.query(
239
+ `SELECT name, encrypted_value FROM cookies WHERE host_key = '.github.com'`
240
+ ).all() as any[];
241
+ db.close();
242
+
243
+ for (const row of rows) {
244
+ const ev = Buffer.from(row.encrypted_value);
245
+ expect(ev.slice(0, 3).toString()).toBe('v10');
246
+ }
247
+ });
248
+
249
+ test('decrypts all github.com cookies from fixture DB', () => {
250
+ const db = new Database(FIXTURE_DB, { readonly: true });
251
+ const rows = db.query(
252
+ `SELECT name, value, encrypted_value FROM cookies WHERE host_key = '.github.com'`
253
+ ).all() as any[];
254
+ db.close();
255
+
256
+ const expected: Record<string, string> = {
257
+ 'session_id': 'abc123',
258
+ 'user_token': 'token-xyz',
259
+ 'theme': 'dark',
260
+ };
261
+
262
+ for (const row of rows) {
263
+ const ev = Buffer.from(row.encrypted_value);
264
+ if (ev.length === 0) continue;
265
+ const ciphertext = ev.slice(3);
266
+ const decipher = crypto.createDecipheriv('aes-128-cbc', TEST_KEY, IV);
267
+ const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
268
+ const value = plaintext.slice(32).toString('utf-8');
269
+ expect(value).toBe(expected[row.name]);
270
+ }
271
+ });
272
+
273
+ test('unencrypted cookie uses value field directly', () => {
274
+ const db = new Database(FIXTURE_DB, { readonly: true });
275
+ const row = db.query(
276
+ `SELECT value, encrypted_value FROM cookies WHERE host_key = '.example.com'`
277
+ ).get() as any;
278
+ db.close();
279
+
280
+ expect(row.value).toBe('hello-world');
281
+ expect(Buffer.from(row.encrypted_value).length).toBe(0);
282
+ });
283
+ });
284
+
285
+ describe('sameSite Mapping', () => {
286
+ test('maps sameSite values correctly', () => {
287
+ // Read from fixture DB and verify mapping
288
+ const db = new Database(FIXTURE_DB, { readonly: true });
289
+
290
+ // samesite=0 → None
291
+ const none = db.query(`SELECT samesite FROM cookies WHERE name = 'user_token'`).get() as any;
292
+ expect(none.samesite).toBe(0);
293
+
294
+ // samesite=1 → Lax
295
+ const lax = db.query(`SELECT samesite FROM cookies WHERE name = 'session_id'`).get() as any;
296
+ expect(lax.samesite).toBe(1);
297
+
298
+ // samesite=2 → Strict
299
+ const strict = db.query(`SELECT samesite FROM cookies WHERE name = 'theme'`).get() as any;
300
+ expect(strict.samesite).toBe(2);
301
+
302
+ db.close();
303
+ });
304
+ });
305
+
306
+ describe('Chromium Epoch Conversion', () => {
307
+ test('converts Chromium epoch to Unix timestamp correctly', () => {
308
+ // Round-trip: pick a known Unix timestamp, convert to Chromium, convert back
309
+ const knownUnix = 1704067200; // 2024-01-01T00:00:00Z
310
+ const chromiumTs = BigInt(knownUnix) * 1000000n + CHROMIUM_EPOCH_OFFSET;
311
+ const unixTs = Number((chromiumTs - CHROMIUM_EPOCH_OFFSET) / 1000000n);
312
+ expect(unixTs).toBe(knownUnix);
313
+ });
314
+
315
+ test('session cookies (has_expires=0) get expires=-1', () => {
316
+ const db = new Database(FIXTURE_DB, { readonly: true });
317
+ const row = db.query(
318
+ `SELECT has_expires, expires_utc FROM cookies WHERE host_key = '.session.com'`
319
+ ).get() as any;
320
+ db.close();
321
+ expect(row.has_expires).toBe(0);
322
+ // When has_expires=0, the module should return expires=-1
323
+ });
324
+ });
325
+
326
+ describe('Error Handling', () => {
327
+ test('CookieImportError has correct properties', () => {
328
+ const err = new CookieImportError('test message', 'test_code', 'retry');
329
+ expect(err.message).toBe('test message');
330
+ expect(err.code).toBe('test_code');
331
+ expect(err.action).toBe('retry');
332
+ expect(err.name).toBe('CookieImportError');
333
+ expect(err instanceof Error).toBe(true);
334
+ });
335
+
336
+ test('CookieImportError without action', () => {
337
+ const err = new CookieImportError('no action', 'some_code');
338
+ expect(err.action).toBeUndefined();
339
+ });
340
+ });
341
+
342
+ describe('Browser Registry', () => {
343
+ test('findInstalledBrowsers returns array', () => {
344
+ const browsers = findInstalledBrowsers();
345
+ expect(Array.isArray(browsers)).toBe(true);
346
+ // Each entry should have the right shape
347
+ for (const b of browsers) {
348
+ expect(b).toHaveProperty('name');
349
+ expect(b).toHaveProperty('dataDir');
350
+ expect(b).toHaveProperty('keychainService');
351
+ expect(b).toHaveProperty('aliases');
352
+ }
353
+ });
354
+ });
355
+
356
+ describe('Corrupt Data Handling', () => {
357
+ test('garbage ciphertext produces decryption error', () => {
358
+ const garbage = Buffer.from('v10' + 'this-is-not-valid-ciphertext!!');
359
+ const ciphertext = garbage.slice(3);
360
+ expect(() => {
361
+ const decipher = crypto.createDecipheriv('aes-128-cbc', TEST_KEY, IV);
362
+ Buffer.concat([decipher.update(ciphertext), decipher.final()]);
363
+ }).toThrow();
364
+ });
365
+ });
366
+
367
+ describe('Profile Validation', () => {
368
+ test('rejects path traversal in profile names', () => {
369
+ // The validateProfile function should reject profiles with / or ..
370
+ // We can't call it directly (internal), but we can test via listDomains
371
+ // which calls validateProfile
372
+ expect(() => listDomains('chrome', '../etc')).toThrow(/Invalid profile/);
373
+ expect(() => listDomains('chrome', 'Default/../../etc')).toThrow(/Invalid profile/);
374
+ });
375
+
376
+ test('rejects control characters in profile names', () => {
377
+ expect(() => listDomains('chrome', 'Default\x00evil')).toThrow(/Invalid profile/);
378
+ });
379
+ });
380
+
381
+ describe('Unknown Browser', () => {
382
+ test('throws for unknown browser name', () => {
383
+ expect(() => listDomains('firefox')).toThrow(/Unknown browser.*firefox/i);
384
+ });
385
+
386
+ test('error includes list of supported browsers', () => {
387
+ try {
388
+ listDomains('firefox');
389
+ throw new Error('Should have thrown');
390
+ } catch (err: any) {
391
+ expect(err.code).toBe('unknown_browser');
392
+ expect(err.message).toContain('comet');
393
+ expect(err.message).toContain('chrome');
394
+ }
395
+ });
396
+ });
397
+ });