@runchr/gstack-antigravity 0.1.0 → 0.1.2
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.
- package/.agents/skills/gstack/.agents/skills/gstack/SKILL.md +651 -0
- package/.agents/skills/gstack/.agents/skills/gstack-autoplan/SKILL.md +678 -0
- package/.agents/skills/gstack/.agents/skills/gstack-benchmark/SKILL.md +482 -0
- package/.agents/skills/gstack/.agents/skills/gstack-browse/SKILL.md +511 -0
- package/.agents/skills/gstack/.agents/skills/gstack-canary/SKILL.md +486 -0
- package/.agents/skills/gstack/.agents/skills/gstack-careful/SKILL.md +50 -0
- package/.agents/skills/gstack/.agents/skills/gstack-cso/SKILL.md +607 -0
- package/.agents/skills/gstack/.agents/skills/gstack-design-consultation/SKILL.md +615 -0
- package/.agents/skills/gstack/.agents/skills/gstack-design-review/SKILL.md +988 -0
- package/.agents/skills/gstack/.agents/skills/gstack-document-release/SKILL.md +604 -0
- package/.agents/skills/gstack/.agents/skills/gstack-freeze/SKILL.md +67 -0
- package/.agents/skills/gstack/.agents/skills/gstack-guard/SKILL.md +62 -0
- package/.agents/skills/gstack/.agents/skills/gstack-investigate/SKILL.md +415 -0
- package/.agents/skills/gstack/.agents/skills/gstack-land-and-deploy/SKILL.md +873 -0
- package/.agents/skills/gstack/.agents/skills/gstack-office-hours/SKILL.md +986 -0
- package/.agents/skills/gstack/.agents/skills/gstack-plan-ceo-review/SKILL.md +1268 -0
- package/.agents/skills/gstack/.agents/skills/gstack-plan-design-review/SKILL.md +668 -0
- package/.agents/skills/gstack/.agents/skills/gstack-plan-eng-review/SKILL.md +826 -0
- package/.agents/skills/gstack/.agents/skills/gstack-qa/SKILL.md +1006 -0
- package/.agents/skills/gstack/.agents/skills/gstack-qa-only/SKILL.md +626 -0
- package/.agents/skills/gstack/.agents/skills/gstack-retro/SKILL.md +1065 -0
- package/.agents/skills/gstack/.agents/skills/gstack-review/SKILL.md +704 -0
- package/.agents/skills/gstack/.agents/skills/gstack-setup-browser-cookies/SKILL.md +325 -0
- package/.agents/skills/gstack/.agents/skills/gstack-setup-deploy/SKILL.md +450 -0
- package/.agents/skills/gstack/.agents/skills/gstack-ship/SKILL.md +1312 -0
- package/.agents/skills/gstack/.agents/skills/gstack-unfreeze/SKILL.md +36 -0
- package/.agents/skills/gstack/.agents/skills/gstack-upgrade/SKILL.md +220 -0
- package/.agents/skills/gstack/.env.example +5 -0
- package/.agents/skills/gstack/.github/workflows/skill-docs.yml +17 -0
- package/.agents/skills/gstack/AGENTS.md +49 -0
- package/.agents/skills/gstack/ARCHITECTURE.md +359 -0
- package/.agents/skills/gstack/BROWSER.md +271 -0
- package/.agents/skills/gstack/CHANGELOG.md +800 -0
- package/.agents/skills/gstack/CLAUDE.md +284 -0
- package/.agents/skills/gstack/CONTRIBUTING.md +370 -0
- package/.agents/skills/gstack/ETHOS.md +129 -0
- package/.agents/skills/gstack/LICENSE +21 -0
- package/.agents/skills/gstack/README.md +228 -0
- package/.agents/skills/gstack/SKILL.md +657 -0
- package/.agents/skills/gstack/SKILL.md.tmpl +281 -0
- package/.agents/skills/gstack/TODOS.md +564 -0
- package/.agents/skills/gstack/VERSION +1 -0
- package/.agents/skills/gstack/autoplan/SKILL.md +689 -0
- package/.agents/skills/gstack/autoplan/SKILL.md.tmpl +416 -0
- package/.agents/skills/gstack/benchmark/SKILL.md +489 -0
- package/.agents/skills/gstack/benchmark/SKILL.md.tmpl +233 -0
- package/.agents/skills/gstack/bin/dev-setup +68 -0
- package/.agents/skills/gstack/bin/dev-teardown +56 -0
- package/.agents/skills/gstack/bin/gstack-analytics +191 -0
- package/.agents/skills/gstack/bin/gstack-community-dashboard +113 -0
- package/.agents/skills/gstack/bin/gstack-config +38 -0
- package/.agents/skills/gstack/bin/gstack-diff-scope +71 -0
- package/.agents/skills/gstack/bin/gstack-global-discover.ts +591 -0
- package/.agents/skills/gstack/bin/gstack-repo-mode +93 -0
- package/.agents/skills/gstack/bin/gstack-review-log +9 -0
- package/.agents/skills/gstack/bin/gstack-review-read +12 -0
- package/.agents/skills/gstack/bin/gstack-slug +15 -0
- package/.agents/skills/gstack/bin/gstack-telemetry-log +158 -0
- package/.agents/skills/gstack/bin/gstack-telemetry-sync +127 -0
- package/.agents/skills/gstack/bin/gstack-update-check +196 -0
- package/.agents/skills/gstack/browse/SKILL.md +517 -0
- package/.agents/skills/gstack/browse/SKILL.md.tmpl +141 -0
- package/.agents/skills/gstack/browse/bin/find-browse +21 -0
- package/.agents/skills/gstack/browse/bin/remote-slug +14 -0
- package/.agents/skills/gstack/browse/scripts/build-node-server.sh +48 -0
- package/.agents/skills/gstack/browse/src/browser-manager.ts +634 -0
- package/.agents/skills/gstack/browse/src/buffers.ts +137 -0
- package/.agents/skills/gstack/browse/src/bun-polyfill.cjs +109 -0
- package/.agents/skills/gstack/browse/src/cli.ts +420 -0
- package/.agents/skills/gstack/browse/src/commands.ts +111 -0
- package/.agents/skills/gstack/browse/src/config.ts +150 -0
- package/.agents/skills/gstack/browse/src/cookie-import-browser.ts +417 -0
- package/.agents/skills/gstack/browse/src/cookie-picker-routes.ts +207 -0
- package/.agents/skills/gstack/browse/src/cookie-picker-ui.ts +541 -0
- package/.agents/skills/gstack/browse/src/find-browse.ts +61 -0
- package/.agents/skills/gstack/browse/src/meta-commands.ts +269 -0
- package/.agents/skills/gstack/browse/src/platform.ts +17 -0
- package/.agents/skills/gstack/browse/src/read-commands.ts +335 -0
- package/.agents/skills/gstack/browse/src/server.ts +369 -0
- package/.agents/skills/gstack/browse/src/snapshot.ts +398 -0
- package/.agents/skills/gstack/browse/src/url-validation.ts +91 -0
- package/.agents/skills/gstack/browse/src/write-commands.ts +352 -0
- package/.agents/skills/gstack/browse/test/bun-polyfill.test.ts +72 -0
- package/.agents/skills/gstack/browse/test/commands.test.ts +1836 -0
- package/.agents/skills/gstack/browse/test/config.test.ts +250 -0
- package/.agents/skills/gstack/browse/test/cookie-import-browser.test.ts +397 -0
- package/.agents/skills/gstack/browse/test/cookie-picker-routes.test.ts +205 -0
- package/.agents/skills/gstack/browse/test/find-browse.test.ts +50 -0
- package/.agents/skills/gstack/browse/test/fixtures/basic.html +33 -0
- package/.agents/skills/gstack/browse/test/fixtures/cursor-interactive.html +22 -0
- package/.agents/skills/gstack/browse/test/fixtures/dialog.html +15 -0
- package/.agents/skills/gstack/browse/test/fixtures/empty.html +2 -0
- package/.agents/skills/gstack/browse/test/fixtures/forms.html +55 -0
- package/.agents/skills/gstack/browse/test/fixtures/qa-eval-checkout.html +108 -0
- package/.agents/skills/gstack/browse/test/fixtures/qa-eval-spa.html +98 -0
- package/.agents/skills/gstack/browse/test/fixtures/qa-eval.html +51 -0
- package/.agents/skills/gstack/browse/test/fixtures/responsive.html +49 -0
- package/.agents/skills/gstack/browse/test/fixtures/snapshot.html +55 -0
- package/.agents/skills/gstack/browse/test/fixtures/spa.html +24 -0
- package/.agents/skills/gstack/browse/test/fixtures/states.html +17 -0
- package/.agents/skills/gstack/browse/test/fixtures/upload.html +25 -0
- package/.agents/skills/gstack/browse/test/gstack-config.test.ts +125 -0
- package/.agents/skills/gstack/browse/test/gstack-update-check.test.ts +467 -0
- package/.agents/skills/gstack/browse/test/handoff.test.ts +235 -0
- package/.agents/skills/gstack/browse/test/path-validation.test.ts +63 -0
- package/.agents/skills/gstack/browse/test/platform.test.ts +37 -0
- package/.agents/skills/gstack/browse/test/snapshot.test.ts +467 -0
- package/.agents/skills/gstack/browse/test/test-server.ts +57 -0
- package/.agents/skills/gstack/browse/test/url-validation.test.ts +72 -0
- package/.agents/skills/gstack/canary/SKILL.md +493 -0
- package/.agents/skills/gstack/canary/SKILL.md.tmpl +220 -0
- package/.agents/skills/gstack/careful/SKILL.md +59 -0
- package/.agents/skills/gstack/careful/SKILL.md.tmpl +57 -0
- package/.agents/skills/gstack/careful/bin/check-careful.sh +112 -0
- package/.agents/skills/gstack/codex/SKILL.md +677 -0
- package/.agents/skills/gstack/codex/SKILL.md.tmpl +356 -0
- package/.agents/skills/gstack/conductor.json +6 -0
- package/.agents/skills/gstack/cso/SKILL.md +615 -0
- package/.agents/skills/gstack/cso/SKILL.md.tmpl +376 -0
- package/.agents/skills/gstack/design-consultation/SKILL.md +625 -0
- package/.agents/skills/gstack/design-consultation/SKILL.md.tmpl +369 -0
- package/.agents/skills/gstack/design-review/SKILL.md +998 -0
- package/.agents/skills/gstack/design-review/SKILL.md.tmpl +262 -0
- package/.agents/skills/gstack/docs/images/github-2013.png +0 -0
- package/.agents/skills/gstack/docs/images/github-2026.png +0 -0
- package/.agents/skills/gstack/docs/skills.md +877 -0
- package/.agents/skills/gstack/document-release/SKILL.md +613 -0
- package/.agents/skills/gstack/document-release/SKILL.md.tmpl +357 -0
- package/.agents/skills/gstack/freeze/SKILL.md +82 -0
- package/.agents/skills/gstack/freeze/SKILL.md.tmpl +80 -0
- package/.agents/skills/gstack/freeze/bin/check-freeze.sh +68 -0
- package/.agents/skills/gstack/gstack-upgrade/SKILL.md +226 -0
- package/.agents/skills/gstack/gstack-upgrade/SKILL.md.tmpl +224 -0
- package/.agents/skills/gstack/guard/SKILL.md +82 -0
- package/.agents/skills/gstack/guard/SKILL.md.tmpl +80 -0
- package/.agents/skills/gstack/investigate/SKILL.md +435 -0
- package/.agents/skills/gstack/investigate/SKILL.md.tmpl +196 -0
- package/.agents/skills/gstack/land-and-deploy/SKILL.md +880 -0
- package/.agents/skills/gstack/land-and-deploy/SKILL.md.tmpl +575 -0
- package/.agents/skills/gstack/office-hours/SKILL.md +996 -0
- package/.agents/skills/gstack/office-hours/SKILL.md.tmpl +624 -0
- package/.agents/skills/gstack/package.json +55 -0
- package/.agents/skills/gstack/plan-ceo-review/SKILL.md +1277 -0
- package/.agents/skills/gstack/plan-ceo-review/SKILL.md.tmpl +838 -0
- package/.agents/skills/gstack/plan-design-review/SKILL.md +676 -0
- package/.agents/skills/gstack/plan-design-review/SKILL.md.tmpl +314 -0
- package/.agents/skills/gstack/plan-eng-review/SKILL.md +836 -0
- package/.agents/skills/gstack/plan-eng-review/SKILL.md.tmpl +279 -0
- package/.agents/skills/gstack/qa/SKILL.md +1016 -0
- package/.agents/skills/gstack/qa/SKILL.md.tmpl +316 -0
- package/.agents/skills/gstack/qa/references/issue-taxonomy.md +85 -0
- package/.agents/skills/gstack/qa/templates/qa-report-template.md +126 -0
- package/.agents/skills/gstack/qa-only/SKILL.md +633 -0
- package/.agents/skills/gstack/qa-only/SKILL.md.tmpl +101 -0
- package/.agents/skills/gstack/retro/SKILL.md +1072 -0
- package/.agents/skills/gstack/retro/SKILL.md.tmpl +833 -0
- package/.agents/skills/gstack/review/SKILL.md +849 -0
- package/.agents/skills/gstack/review/SKILL.md.tmpl +259 -0
- package/.agents/skills/gstack/review/TODOS-format.md +62 -0
- package/.agents/skills/gstack/review/checklist.md +190 -0
- package/.agents/skills/gstack/review/design-checklist.md +132 -0
- package/.agents/skills/gstack/review/greptile-triage.md +220 -0
- package/.agents/skills/gstack/scripts/analytics.ts +190 -0
- package/.agents/skills/gstack/scripts/dev-skill.ts +82 -0
- package/.agents/skills/gstack/scripts/eval-compare.ts +96 -0
- package/.agents/skills/gstack/scripts/eval-list.ts +116 -0
- package/.agents/skills/gstack/scripts/eval-select.ts +86 -0
- package/.agents/skills/gstack/scripts/eval-summary.ts +187 -0
- package/.agents/skills/gstack/scripts/eval-watch.ts +172 -0
- package/.agents/skills/gstack/scripts/gen-skill-docs.ts +2414 -0
- package/.agents/skills/gstack/scripts/skill-check.ts +167 -0
- package/.agents/skills/gstack/setup +269 -0
- package/.agents/skills/gstack/setup-browser-cookies/SKILL.md +330 -0
- package/.agents/skills/gstack/setup-browser-cookies/SKILL.md.tmpl +74 -0
- package/.agents/skills/gstack/setup-deploy/SKILL.md +459 -0
- package/.agents/skills/gstack/setup-deploy/SKILL.md.tmpl +220 -0
- package/.agents/skills/gstack/ship/SKILL.md +1457 -0
- package/.agents/skills/gstack/ship/SKILL.md.tmpl +528 -0
- package/.agents/skills/gstack/supabase/config.sh +10 -0
- package/.agents/skills/gstack/supabase/functions/community-pulse/index.ts +59 -0
- package/.agents/skills/gstack/supabase/functions/telemetry-ingest/index.ts +135 -0
- package/.agents/skills/gstack/supabase/functions/update-check/index.ts +37 -0
- package/.agents/skills/gstack/supabase/migrations/001_telemetry.sql +89 -0
- package/.agents/skills/gstack/test/analytics.test.ts +277 -0
- package/.agents/skills/gstack/test/codex-e2e.test.ts +197 -0
- package/.agents/skills/gstack/test/fixtures/coverage-audit-fixture.ts +76 -0
- package/.agents/skills/gstack/test/fixtures/eval-baselines.json +7 -0
- package/.agents/skills/gstack/test/fixtures/qa-eval-checkout-ground-truth.json +43 -0
- package/.agents/skills/gstack/test/fixtures/qa-eval-ground-truth.json +43 -0
- package/.agents/skills/gstack/test/fixtures/qa-eval-spa-ground-truth.json +43 -0
- package/.agents/skills/gstack/test/fixtures/review-eval-design-slop.css +86 -0
- package/.agents/skills/gstack/test/fixtures/review-eval-design-slop.html +41 -0
- package/.agents/skills/gstack/test/fixtures/review-eval-enum-diff.rb +30 -0
- package/.agents/skills/gstack/test/fixtures/review-eval-enum.rb +27 -0
- package/.agents/skills/gstack/test/fixtures/review-eval-vuln.rb +14 -0
- package/.agents/skills/gstack/test/gemini-e2e.test.ts +173 -0
- package/.agents/skills/gstack/test/gen-skill-docs.test.ts +1049 -0
- package/.agents/skills/gstack/test/global-discover.test.ts +187 -0
- package/.agents/skills/gstack/test/helpers/codex-session-runner.ts +282 -0
- package/.agents/skills/gstack/test/helpers/e2e-helpers.ts +239 -0
- package/.agents/skills/gstack/test/helpers/eval-store.test.ts +548 -0
- package/.agents/skills/gstack/test/helpers/eval-store.ts +689 -0
- package/.agents/skills/gstack/test/helpers/gemini-session-runner.test.ts +104 -0
- package/.agents/skills/gstack/test/helpers/gemini-session-runner.ts +201 -0
- package/.agents/skills/gstack/test/helpers/llm-judge.ts +130 -0
- package/.agents/skills/gstack/test/helpers/observability.test.ts +283 -0
- package/.agents/skills/gstack/test/helpers/session-runner.test.ts +96 -0
- package/.agents/skills/gstack/test/helpers/session-runner.ts +357 -0
- package/.agents/skills/gstack/test/helpers/skill-parser.ts +206 -0
- package/.agents/skills/gstack/test/helpers/touchfiles.ts +260 -0
- package/.agents/skills/gstack/test/hook-scripts.test.ts +373 -0
- package/.agents/skills/gstack/test/skill-e2e-browse.test.ts +293 -0
- package/.agents/skills/gstack/test/skill-e2e-deploy.test.ts +279 -0
- package/.agents/skills/gstack/test/skill-e2e-design.test.ts +614 -0
- package/.agents/skills/gstack/test/skill-e2e-plan.test.ts +538 -0
- package/.agents/skills/gstack/test/skill-e2e-qa-bugs.test.ts +194 -0
- package/.agents/skills/gstack/test/skill-e2e-qa-workflow.test.ts +412 -0
- package/.agents/skills/gstack/test/skill-e2e-review.test.ts +535 -0
- package/.agents/skills/gstack/test/skill-e2e-workflow.test.ts +586 -0
- package/.agents/skills/gstack/test/skill-e2e.test.ts +3325 -0
- package/.agents/skills/gstack/test/skill-llm-eval.test.ts +787 -0
- package/.agents/skills/gstack/test/skill-parser.test.ts +179 -0
- package/.agents/skills/gstack/test/skill-routing-e2e.test.ts +605 -0
- package/.agents/skills/gstack/test/skill-validation.test.ts +1520 -0
- package/.agents/skills/gstack/test/telemetry.test.ts +278 -0
- package/.agents/skills/gstack/test/touchfiles.test.ts +262 -0
- package/.agents/skills/gstack/unfreeze/SKILL.md +40 -0
- package/.agents/skills/gstack/unfreeze/SKILL.md.tmpl +38 -0
- package/README.md +12 -7
- package/README_KO.md +12 -6
- package/package.json +3 -2
|
@@ -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
|
+
});
|