@indigoai-us/hq-cli 5.77.13 → 5.78.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.
- package/CHANGELOG.md +34 -0
- package/assets/scaffold/core/scripts/archive-old-threads.sh +86 -0
- package/assets/scaffold/core/scripts/backfill-company-skill-mirrors.sh +73 -0
- package/assets/scaffold/core/scripts/backfill-workspace-mirror.sh +51 -0
- package/assets/scaffold/core/scripts/codex-skill-bridge.sh +550 -0
- package/assets/scaffold/core/scripts/detect-stale-core-policy-mirror.sh +185 -0
- package/assets/scaffold/core/scripts/hq-status-summary.sh +187 -0
- package/assets/scaffold/core/scripts/ontology-readme-drift.sh +264 -0
- package/assets/scaffold/core/scripts/qmd-reindex-after-sync.sh +93 -0
- package/assets/scaffold/core/scripts/rebuild-all-indexes.sh +69 -0
- package/assets/scaffold/core/scripts/rebuild-companies-index.sh +206 -0
- package/assets/scaffold/core/scripts/rebuild-company-knowledge-index.sh +127 -0
- package/assets/scaffold/core/scripts/rebuild-orchestrator-index.sh +86 -0
- package/assets/scaffold/core/scripts/rebuild-projects-index.sh +105 -0
- package/assets/scaffold/core/scripts/rebuild-public-knowledge-index.sh +83 -0
- package/assets/scaffold/core/scripts/rebuild-reports-index.sh +114 -0
- package/assets/scaffold/core/scripts/rebuild-social-drafts-index.sh +135 -0
- package/assets/scaffold/core/scripts/rebuild-threads-index.sh +82 -0
- package/assets/scaffold/core/scripts/rebuild-workers-index.sh +97 -0
- package/assets/scaffold/core/scripts/resize-screenshot.sh +47 -0
- package/assets/scaffold/core/scripts/token-usage-report.sh +254 -0
- package/assets/scaffold/core/scripts/worktree.sh +136 -0
- package/dist/commands/agents.js +28 -12
- package/dist/commands/api-keys.js +100 -20
- package/dist/commands/core.d.ts +90 -0
- package/dist/commands/core.js +279 -0
- package/dist/commands/files-browse.d.ts +21 -0
- package/dist/commands/files-browse.js +145 -24
- package/dist/commands/files.js +33 -7
- package/dist/commands/members.js +16 -5
- package/dist/commands/pack-install.d.ts +14 -0
- package/dist/commands/pack-install.js +51 -2
- package/dist/commands/pkg-install.js +43 -0
- package/dist/commands/run.js +8 -0
- package/dist/commands/secrets.js +125 -65
- package/dist/main.js +6 -0
- package/dist/utils/api-key-command-gate.d.ts +45 -0
- package/dist/utils/api-key-command-gate.js +51 -0
- package/dist/utils/hq-roots.d.ts +91 -0
- package/dist/utils/hq-roots.js +212 -0
- package/dist/utils/resolve-vault-credential.d.ts +63 -3
- package/dist/utils/resolve-vault-credential.js +152 -6
- package/dist/utils/run-bundled-script.d.ts +66 -0
- package/dist/utils/run-bundled-script.js +80 -0
- package/dist/utils/vault-api.d.ts +21 -0
- package/dist/utils/vault-api.js +74 -3
- package/package.json +7 -1
- package/.claude/policies/hq-cli-interactive-reads-use-sts-vend.md +0 -49
- package/.github/workflows/ci.yml +0 -46
- package/.github/workflows/publish.yml +0 -36
- package/.github/workflows/scripts/smoke-test-pkg.sh +0 -97
- package/e2e/cli.test.ts +0 -128
- package/eslint.config.js +0 -37
- package/pnpm-workspace.yaml +0 -4
- package/scripts/chmod-bins.mjs +0 -49
- package/scripts/generate-dsn.mjs +0 -26
- package/scripts/generate-scan-packages-table.mjs +0 -113
- package/scripts/smoke-sources-signals.sh +0 -103
- package/src/bin/hq-auth-refresh.ts +0 -43
- package/src/cli-version.ts +0 -13
- package/src/commands/__fixtures__/make-tar.ts +0 -126
- package/src/commands/_patterns.ts +0 -10
- package/src/commands/add.ts +0 -75
- package/src/commands/agents.test.ts +0 -527
- package/src/commands/agents.ts +0 -923
- package/src/commands/api-keys.test.ts +0 -291
- package/src/commands/api-keys.ts +0 -382
- package/src/commands/artifact-verify.test.ts +0 -177
- package/src/commands/auth.test.ts +0 -82
- package/src/commands/auth.ts +0 -213
- package/src/commands/billing.test.ts +0 -158
- package/src/commands/billing.ts +0 -146
- package/src/commands/channels.test.ts +0 -74
- package/src/commands/channels.ts +0 -91
- package/src/commands/cloud-demote.test.ts +0 -401
- package/src/commands/cloud-demote.ts +0 -278
- package/src/commands/cloud-provision.test.ts +0 -1117
- package/src/commands/cloud-provision.ts +0 -942
- package/src/commands/cloud.pull-all.test.ts +0 -711
- package/src/commands/cloud.pull-per-company.test.ts +0 -188
- package/src/commands/cloud.push-all.test.ts +0 -485
- package/src/commands/cloud.scope-excluded-warning.test.ts +0 -22
- package/src/commands/cloud.selectors.test.ts +0 -208
- package/src/commands/cloud.status.test.ts +0 -160
- package/src/commands/cloud.test.ts +0 -41
- package/src/commands/cloud.ts +0 -2130
- package/src/commands/company.test.ts +0 -202
- package/src/commands/company.ts +0 -148
- package/src/commands/creators.test.ts +0 -60
- package/src/commands/creators.ts +0 -117
- package/src/commands/crm.test.ts +0 -179
- package/src/commands/crm.ts +0 -236
- package/src/commands/db-migrate.ts +0 -55
- package/src/commands/db-provision.ts +0 -114
- package/src/commands/db-sql.ts +0 -124
- package/src/commands/db-status.ts +0 -108
- package/src/commands/db.ts +0 -26
- package/src/commands/dm.test.ts +0 -748
- package/src/commands/dm.ts +0 -1226
- package/src/commands/feedback.test.ts +0 -413
- package/src/commands/feedback.ts +0 -169
- package/src/commands/files-browse.test.ts +0 -1249
- package/src/commands/files-browse.ts +0 -1506
- package/src/commands/files-delete.test.ts +0 -484
- package/src/commands/files-recovery.test.ts +0 -370
- package/src/commands/files.test.ts +0 -722
- package/src/commands/files.ts +0 -1446
- package/src/commands/group-grants.test.ts +0 -330
- package/src/commands/group-grants.ts +0 -455
- package/src/commands/groups.test.ts +0 -44
- package/src/commands/groups.ts +0 -368
- package/src/commands/integrations.test.ts +0 -633
- package/src/commands/integrations.ts +0 -507
- package/src/commands/list.ts +0 -85
- package/src/commands/login.ts +0 -52
- package/src/commands/logout.ts +0 -30
- package/src/commands/marketplace-install.test.ts +0 -543
- package/src/commands/marketplace-security.test.ts +0 -646
- package/src/commands/mcp-registration.test.ts +0 -2787
- package/src/commands/mcp-registration.ts +0 -2612
- package/src/commands/mcp-status.test.ts +0 -483
- package/src/commands/mcp-status.ts +0 -575
- package/src/commands/mcp-status.us011.test.ts +0 -243
- package/src/commands/meetings.test.ts +0 -522
- package/src/commands/meetings.ts +0 -789
- package/src/commands/members.test.ts +0 -1474
- package/src/commands/members.ts +0 -1181
- package/src/commands/onboard-identity-guard.test.ts +0 -99
- package/src/commands/onboard-identity-guard.ts +0 -103
- package/src/commands/onboard-join.test.ts +0 -96
- package/src/commands/onboard-join.ts +0 -101
- package/src/commands/onboard-warning.test.ts +0 -26
- package/src/commands/onboard-warning.ts +0 -12
- package/src/commands/onboard.ts +0 -267
- package/src/commands/outposts-heartbeat.test.ts +0 -299
- package/src/commands/outposts-heartbeat.ts +0 -310
- package/src/commands/outposts-replica-sync.test.ts +0 -272
- package/src/commands/outposts-self-deploy.test.ts +0 -243
- package/src/commands/outposts.test.ts +0 -1039
- package/src/commands/outposts.ts +0 -1935
- package/src/commands/pack-install-secret-authorization.test.ts +0 -115
- package/src/commands/pack-install.test.ts +0 -1469
- package/src/commands/pack-install.ts +0 -2247
- package/src/commands/pack-update-cache.test.ts +0 -149
- package/src/commands/packs.test.ts +0 -88
- package/src/commands/packs.ts +0 -622
- package/src/commands/people.test.ts +0 -807
- package/src/commands/people.ts +0 -422
- package/src/commands/pkg-install.dispatch.test.ts +0 -71
- package/src/commands/pkg-install.ts +0 -215
- package/src/commands/pkg-list.test.ts +0 -79
- package/src/commands/pkg-list.ts +0 -13
- package/src/commands/pkg-remove.ts +0 -71
- package/src/commands/pkg-update.ts +0 -189
- package/src/commands/publish.test.ts +0 -650
- package/src/commands/publish.ts +0 -580
- package/src/commands/reindex.test.ts +0 -259
- package/src/commands/reindex.ts +0 -274
- package/src/commands/rescue.test.ts +0 -39
- package/src/commands/rescue.ts +0 -210
- package/src/commands/run.env-local.test.ts +0 -88
- package/src/commands/run.test.ts +0 -45
- package/src/commands/run.ts +0 -184
- package/src/commands/safe-extract.test.ts +0 -459
- package/src/commands/safe-extract.ts +0 -444
- package/src/commands/secrets-scope.test.ts +0 -56
- package/src/commands/secrets-scope.ts +0 -32
- package/src/commands/secrets.parse-destination.test.ts +0 -38
- package/src/commands/secrets.test.ts +0 -2037
- package/src/commands/secrets.ts +0 -2240
- package/src/commands/signals.ts +0 -351
- package/src/commands/skill.test.ts +0 -770
- package/src/commands/skill.ts +0 -796
- package/src/commands/sources.ts +0 -362
- package/src/commands/sync-mode.test.ts +0 -366
- package/src/commands/sync-mode.ts +0 -387
- package/src/commands/sync-narrow.test.ts +0 -633
- package/src/commands/sync-narrow.ts +0 -555
- package/src/commands/sync.ts +0 -165
- package/src/commands/team-sync.ts +0 -628
- package/src/commands/update.ts +0 -71
- package/src/commands/whoami.ts +0 -83
- package/src/commands/workers.test.ts +0 -158
- package/src/commands/workers.ts +0 -301
- package/src/index.test.ts +0 -32
- package/src/index.ts +0 -20
- package/src/lib/db/control-plane.test.ts +0 -59
- package/src/lib/db/control-plane.ts +0 -113
- package/src/lib/db/local.test.ts +0 -81
- package/src/lib/db/local.ts +0 -148
- package/src/lib/db/migrate.test.ts +0 -133
- package/src/lib/db/migrate.ts +0 -137
- package/src/lib/db/paths.test.ts +0 -112
- package/src/lib/db/paths.ts +0 -128
- package/src/lib/db/remote-engine.test.ts +0 -44
- package/src/lib/db/remote-engine.ts +0 -148
- package/src/lib/db/remote-sql.test.ts +0 -32
- package/src/lib/db/remote-sql.ts +0 -62
- package/src/lib/db/sql.test.ts +0 -106
- package/src/lib/db/sql.ts +0 -192
- package/src/lib/hq-cloud-dep.smoke.test.ts +0 -75
- package/src/lib/local-tree-diff.test.ts +0 -301
- package/src/lib/local-tree-diff.ts +0 -362
- package/src/lib/narrow-hint-banner.test.ts +0 -235
- package/src/lib/narrow-hint-banner.ts +0 -212
- package/src/lib/plan-limit-nag.test.ts +0 -317
- package/src/lib/plan-limit-nag.ts +0 -264
- package/src/main.ts +0 -371
- package/src/node-preflight.test.ts +0 -60
- package/src/node-preflight.ts +0 -67
- package/src/outpost/session-heartbeat-bounds.test.ts +0 -195
- package/src/outpost/session-heartbeat-guard.test.ts +0 -105
- package/src/outpost/session-heartbeat-publisher.test.ts +0 -178
- package/src/outpost/session-heartbeat-publisher.ts +0 -186
- package/src/outpost/session-heartbeat-retain-guard.test.ts +0 -126
- package/src/outpost/session-heartbeat.test.ts +0 -459
- package/src/outpost/session-heartbeat.ts +0 -877
- package/src/packaging.test.ts +0 -109
- package/src/run/__fixtures__/discover-schemas/example.env.schema +0 -4
- package/src/run/discover-schemas.test.ts +0 -153
- package/src/run/discover-schemas.ts +0 -79
- package/src/run/hq-plugin.test.ts +0 -371
- package/src/run/hq-plugin.ts +0 -277
- package/src/run/varlock-shape.test.ts +0 -57
- package/src/schemas/hq-package.schema.json +0 -155
- package/src/sentry-before-send.test.ts +0 -359
- package/src/sentry-before-send.ts +0 -221
- package/src/sentry-epipe.test.ts +0 -37
- package/src/sentry-release.test.ts +0 -54
- package/src/sentry.test.ts +0 -24
- package/src/sentry.ts +0 -54
- package/src/strategies/link.ts +0 -62
- package/src/strategies/merge.ts +0 -142
- package/src/types.ts +0 -146
- package/src/utils/__fixtures__/scan-packages.generated-block.sh +0 -23
- package/src/utils/auth-error.test.ts +0 -40
- package/src/utils/auth-error.ts +0 -42
- package/src/utils/billing-gate.test.ts +0 -95
- package/src/utils/billing-gate.ts +0 -228
- package/src/utils/breadcrumb-buffer.ts +0 -18
- package/src/utils/cli-telemetry.test.ts +0 -153
- package/src/utils/cli-telemetry.ts +0 -61
- package/src/utils/cognito-session.machine.test.ts +0 -109
- package/src/utils/cognito-session.refresh.test.ts +0 -84
- package/src/utils/cognito-session.test.ts +0 -328
- package/src/utils/cognito-session.ts +0 -448
- package/src/utils/company-selection-error.test.ts +0 -42
- package/src/utils/company-selection-error.ts +0 -45
- package/src/utils/contribution-table.ts +0 -83
- package/src/utils/environmental-error.test.ts +0 -45
- package/src/utils/environmental-error.ts +0 -39
- package/src/utils/epipe.test.ts +0 -28
- package/src/utils/epipe.ts +0 -29
- package/src/utils/expected-cli-error.test.ts +0 -28
- package/src/utils/expected-cli-error.ts +0 -39
- package/src/utils/feedback-diagnostics.test.ts +0 -183
- package/src/utils/feedback-diagnostics.ts +0 -123
- package/src/utils/feedback-screenshots.test.ts +0 -134
- package/src/utils/feedback-screenshots.ts +0 -124
- package/src/utils/feedback-versions.test.ts +0 -98
- package/src/utils/feedback-versions.ts +0 -68
- package/src/utils/git.ts +0 -74
- package/src/utils/integrity.ts +0 -59
- package/src/utils/intercepted-process-exit.test.ts +0 -37
- package/src/utils/intercepted-process-exit.ts +0 -36
- package/src/utils/login-provider.test.ts +0 -42
- package/src/utils/login-provider.ts +0 -30
- package/src/utils/manifest.test.ts +0 -167
- package/src/utils/manifest.ts +0 -131
- package/src/utils/pack-contributions.test.ts +0 -603
- package/src/utils/pack-contributions.ts +0 -450
- package/src/utils/people.ts +0 -215
- package/src/utils/registry-client.ts +0 -204
- package/src/utils/registry.ts +0 -90
- package/src/utils/resolve-vault-credential.test.ts +0 -69
- package/src/utils/resolve-vault-credential.ts +0 -60
- package/src/utils/sandbox-runner-client.test.ts +0 -279
- package/src/utils/sandbox-runner-client.ts +0 -260
- package/src/utils/secrets-cache.ts +0 -183
- package/src/utils/sentry-identity.ts +0 -45
- package/src/utils/settle-with-timeout.test.ts +0 -21
- package/src/utils/settle-with-timeout.ts +0 -22
- package/src/utils/user-yaml-error.test.ts +0 -24
- package/src/utils/user-yaml-error.ts +0 -30
- package/src/utils/vault-api.test.ts +0 -536
- package/src/utils/vault-api.ts +0 -382
- package/src/utils/version-check.test.ts +0 -176
- package/src/utils/version-check.ts +0 -155
- package/src/utils/version-gate.test.ts +0 -1024
- package/src/utils/version-gate.ts +0 -702
- package/test/commands/db-tenant-isolation.test.ts +0 -94
- package/test/commands/db.test.ts +0 -85
- package/test/commands/signals.test.ts +0 -207
- package/test/commands/sources.test.ts +0 -231
- package/test/e2e/smoke-install-mcp.sh +0 -113
- package/test/fixtures/hq-pack-smoke-mcp/mcp/smoke-http.json +0 -1
- package/test/fixtures/hq-pack-smoke-mcp/package.yaml +0 -11
- package/test/fixtures/signals/action_item/sample.md +0 -16
- package/test/fixtures/signals/summary/sample.md +0 -12
- package/test/fixtures/sources/meetings/sample.md +0 -25
- package/test/helpers/cli-runner.ts +0 -150
- package/test/helpers/s3-list-mock.ts +0 -79
- package/test/helpers/vault-service-mock.ts +0 -295
- package/test/sources-signals/smoke.test.ts +0 -228
- package/tsconfig.json +0 -20
- package/vitest.config.ts +0 -11
- package/vitest.e2e.config.ts +0 -7
package/src/lib/db/paths.test.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for local vault DB path helpers (vault-databases US-002).
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import fs from "node:fs";
|
|
6
|
-
import os from "node:os";
|
|
7
|
-
import path from "node:path";
|
|
8
|
-
|
|
9
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
LOCAL_DB_IGNORE_PATTERNS,
|
|
13
|
-
LOCAL_VAULT_DB_FILENAME,
|
|
14
|
-
describeLocalDbIgnoreRules,
|
|
15
|
-
ensureLocalDbDir,
|
|
16
|
-
normalizeCompanySlugForLocalDb,
|
|
17
|
-
resolveLocalDbDir,
|
|
18
|
-
resolveLocalDbPath,
|
|
19
|
-
resolveLocalDbRoot,
|
|
20
|
-
} from "./paths.js";
|
|
21
|
-
|
|
22
|
-
const tempHomes: string[] = [];
|
|
23
|
-
|
|
24
|
-
function makeTempHome(): string {
|
|
25
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "hq-db-paths-"));
|
|
26
|
-
tempHomes.push(dir);
|
|
27
|
-
return dir;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
afterEach(() => {
|
|
31
|
-
while (tempHomes.length > 0) {
|
|
32
|
-
const dir = tempHomes.pop();
|
|
33
|
-
if (dir) {
|
|
34
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe("resolveLocalDbPath", () => {
|
|
40
|
-
it("resolves indigo under documented root ending with vault.db", () => {
|
|
41
|
-
const home = makeTempHome();
|
|
42
|
-
const p = resolveLocalDbPath("indigo", { home });
|
|
43
|
-
expect(p).toBe(path.join(home, ".hq", "db", "indigo", LOCAL_VAULT_DB_FILENAME));
|
|
44
|
-
expect(p.endsWith(path.join("indigo", "vault.db"))).toBe(true);
|
|
45
|
-
expect(p.startsWith(resolveLocalDbRoot({ home }))).toBe(true);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("resolves a second company slug (acme) distinctly", () => {
|
|
49
|
-
const home = makeTempHome();
|
|
50
|
-
const indigo = resolveLocalDbPath("indigo", { home });
|
|
51
|
-
const acme = resolveLocalDbPath("acme", { home });
|
|
52
|
-
expect(acme).toBe(path.join(home, ".hq", "db", "acme", "vault.db"));
|
|
53
|
-
expect(indigo).not.toBe(acme);
|
|
54
|
-
expect(path.dirname(indigo)).not.toBe(path.dirname(acme));
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("normalizes slug casing to lowercase", () => {
|
|
58
|
-
const home = makeTempHome();
|
|
59
|
-
expect(resolveLocalDbPath("Indigo", { home })).toBe(
|
|
60
|
-
resolveLocalDbPath("indigo", { home }),
|
|
61
|
-
);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe("normalizeCompanySlugForLocalDb", () => {
|
|
66
|
-
it("rejects empty and path-traversal slugs", () => {
|
|
67
|
-
expect(() => normalizeCompanySlugForLocalDb("")).toThrow(/required/i);
|
|
68
|
-
expect(() => normalizeCompanySlugForLocalDb("../etc")).toThrow(/invalid/i);
|
|
69
|
-
expect(() => normalizeCompanySlugForLocalDb("a/b")).toThrow(/invalid/i);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe("ensureLocalDbDir", () => {
|
|
74
|
-
it("creates parent directories for a new company slug and is writable", () => {
|
|
75
|
-
const home = makeTempHome();
|
|
76
|
-
const dir = ensureLocalDbDir("newco", { home });
|
|
77
|
-
expect(fs.existsSync(dir)).toBe(true);
|
|
78
|
-
expect(fs.statSync(dir).isDirectory()).toBe(true);
|
|
79
|
-
// Writable: can create a probe file then remove it (no secrets left).
|
|
80
|
-
const probe = path.join(dir, ".write-probe");
|
|
81
|
-
fs.writeFileSync(probe, "ok", { mode: 0o600 });
|
|
82
|
-
expect(fs.readFileSync(probe, "utf8")).toBe("ok");
|
|
83
|
-
fs.unlinkSync(probe);
|
|
84
|
-
// Does not create the .db file itself.
|
|
85
|
-
expect(fs.existsSync(resolveLocalDbPath("newco", { home }))).toBe(false);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("is idempotent when the directory already exists", () => {
|
|
89
|
-
const home = makeTempHome();
|
|
90
|
-
const first = ensureLocalDbDir("acme", { home });
|
|
91
|
-
const second = ensureLocalDbDir("acme", { home });
|
|
92
|
-
expect(first).toBe(second);
|
|
93
|
-
expect(fs.existsSync(first)).toBe(true);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe("resolveLocalDbDir / ignore docs", () => {
|
|
98
|
-
it("dir is parent of vault.db path", () => {
|
|
99
|
-
const home = makeTempHome();
|
|
100
|
-
expect(resolveLocalDbDir("indigo", { home })).toBe(
|
|
101
|
-
path.dirname(resolveLocalDbPath("indigo", { home })),
|
|
102
|
-
);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("documents *.db and .data ignore patterns", () => {
|
|
106
|
-
expect(LOCAL_DB_IGNORE_PATTERNS.some((p) => p.includes("*.db"))).toBe(true);
|
|
107
|
-
expect(LOCAL_DB_IGNORE_PATTERNS.some((p) => p.includes(".data"))).toBe(true);
|
|
108
|
-
const docs = describeLocalDbIgnoreRules();
|
|
109
|
-
expect(docs).toMatch(/\.hq\/db/);
|
|
110
|
-
expect(docs).toMatch(/\*\.db/);
|
|
111
|
-
});
|
|
112
|
-
});
|
package/src/lib/db/paths.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vault database path conventions (C1 local tier).
|
|
3
|
-
*
|
|
4
|
-
* Canonical layout (locked by vault-databases PRD):
|
|
5
|
-
* ~/.hq/db/{companySlug}/vault.db
|
|
6
|
-
*
|
|
7
|
-
* Binary DB files are machine-local. They must never live under companies/
|
|
8
|
-
* so hq-sync / git cannot treat them as vault text. Migrations remain vault
|
|
9
|
-
* text at companies/{co}/db/migrations/*.sql (handled by migrate stories).
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import fs from "node:fs";
|
|
13
|
-
import os from "node:os";
|
|
14
|
-
import path from "node:path";
|
|
15
|
-
|
|
16
|
-
/** Default filename for the per-company local vault SQLite file. */
|
|
17
|
-
export const LOCAL_VAULT_DB_FILENAME = "vault.db";
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Glob-style ignore patterns for binary / local DB artifacts.
|
|
21
|
-
* Apply in gitignore and hq-sync ignore configuration for any tree that
|
|
22
|
-
* might accidentally host these files. Primary storage is under ~/.hq/db/
|
|
23
|
-
* (outside the vault), but skills must still ignore stray `*.db` / `.data/`.
|
|
24
|
-
*/
|
|
25
|
-
export const LOCAL_DB_IGNORE_PATTERNS: readonly string[] = [
|
|
26
|
-
"**/*.db",
|
|
27
|
-
"**/*.db-wal",
|
|
28
|
-
"**/*.db-shm",
|
|
29
|
-
"**/*.db-journal",
|
|
30
|
-
"**/.data/**",
|
|
31
|
-
// Explicit machine-local root (if a tool ever materializes a relative copy)
|
|
32
|
-
"**/.hq/db/**",
|
|
33
|
-
];
|
|
34
|
-
|
|
35
|
-
export interface LocalDbPathEnv {
|
|
36
|
-
/** Override home directory (tests inject temp dirs). Defaults to os.homedir(). */
|
|
37
|
-
home?: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Resolve the machine-local root that holds all company vault DBs:
|
|
42
|
-
* `{home}/.hq/db`.
|
|
43
|
-
*/
|
|
44
|
-
export function resolveLocalDbRoot(env?: LocalDbPathEnv): string {
|
|
45
|
-
const home = (env?.home ?? os.homedir()).trim();
|
|
46
|
-
if (!home) {
|
|
47
|
-
throw new Error(
|
|
48
|
-
"cannot resolve local DB root: home directory is empty (set home or os.homedir())",
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
return path.join(home, ".hq", "db");
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Normalize and validate a company slug used in the local path.
|
|
56
|
-
* Tenant isolation still requires HQ identity/membership at the command layer;
|
|
57
|
-
* this only rejects empty / path-traversal slugs so we never open arbitrary paths.
|
|
58
|
-
*/
|
|
59
|
-
export function normalizeCompanySlugForLocalDb(companySlug: string): string {
|
|
60
|
-
const slug = companySlug.trim().toLowerCase();
|
|
61
|
-
if (!slug) {
|
|
62
|
-
throw new Error("company slug is required for local DB path resolution");
|
|
63
|
-
}
|
|
64
|
-
if (
|
|
65
|
-
slug.includes("/") ||
|
|
66
|
-
slug.includes("\\") ||
|
|
67
|
-
slug.includes("..") ||
|
|
68
|
-
slug === "." ||
|
|
69
|
-
slug.includes("\0")
|
|
70
|
-
) {
|
|
71
|
-
throw new Error(
|
|
72
|
-
`invalid company slug for local DB path: ${JSON.stringify(companySlug)}`,
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
return slug;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Canonical path for a company's local vault SQLite file:
|
|
80
|
-
* `~/.hq/db/{companySlug}/vault.db`.
|
|
81
|
-
*/
|
|
82
|
-
export function resolveLocalDbPath(
|
|
83
|
-
companySlug: string,
|
|
84
|
-
env?: LocalDbPathEnv,
|
|
85
|
-
): string {
|
|
86
|
-
const slug = normalizeCompanySlugForLocalDb(companySlug);
|
|
87
|
-
return path.join(resolveLocalDbRoot(env), slug, LOCAL_VAULT_DB_FILENAME);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Directory that contains the company's vault.db (and WAL side files).
|
|
92
|
-
*/
|
|
93
|
-
export function resolveLocalDbDir(
|
|
94
|
-
companySlug: string,
|
|
95
|
-
env?: LocalDbPathEnv,
|
|
96
|
-
): string {
|
|
97
|
-
return path.dirname(resolveLocalDbPath(companySlug, env));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Ensure the company local DB directory exists and is writable.
|
|
102
|
-
* Creates parent directories recursively. Does not create the .db file
|
|
103
|
-
* and does not write secrets into the tree.
|
|
104
|
-
*
|
|
105
|
-
* @returns absolute path of the directory
|
|
106
|
-
*/
|
|
107
|
-
export function ensureLocalDbDir(
|
|
108
|
-
companySlug: string,
|
|
109
|
-
env?: LocalDbPathEnv,
|
|
110
|
-
): string {
|
|
111
|
-
const dir = resolveLocalDbDir(companySlug, env);
|
|
112
|
-
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
113
|
-
// Verify writable without leaving secrets or DB content behind.
|
|
114
|
-
fs.accessSync(dir, fs.constants.W_OK);
|
|
115
|
-
return dir;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Human-readable documentation of ignore rules for operators and agents.
|
|
120
|
-
*/
|
|
121
|
-
export function describeLocalDbIgnoreRules(): string {
|
|
122
|
-
return [
|
|
123
|
-
"Local vault databases live at ~/.hq/db/{company}/vault.db (outside the vault tree).",
|
|
124
|
-
"Never place *.db under companies/ — binary DB state is not vault-synced.",
|
|
125
|
-
"Ignore patterns:",
|
|
126
|
-
...LOCAL_DB_IGNORE_PATTERNS.map((p) => ` - ${p}`),
|
|
127
|
-
].join("\n");
|
|
128
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Remote engine registry + mock (vault-databases US-007).
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { beforeEach, describe, expect, it } from "vitest";
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
_resetRemoteEngineRegistryForTests,
|
|
9
|
-
createMockRemoteEngine,
|
|
10
|
-
getRemoteEngine,
|
|
11
|
-
registerRemoteEngine,
|
|
12
|
-
} from "./remote-engine.js";
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
_resetRemoteEngineRegistryForTests();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe("RemoteDbEngine mock", () => {
|
|
19
|
-
it("provision and healthCheck work without AWS", async () => {
|
|
20
|
-
const mock = createMockRemoteEngine("mock");
|
|
21
|
-
registerRemoteEngine(mock);
|
|
22
|
-
|
|
23
|
-
const engine = getRemoteEngine("mock");
|
|
24
|
-
const first = await engine.provision({
|
|
25
|
-
companyUid: "cmp_x",
|
|
26
|
-
companySlug: "x",
|
|
27
|
-
});
|
|
28
|
-
expect(first.status).toBe("ready");
|
|
29
|
-
expect(first.resourceArn).toContain("cmp_x");
|
|
30
|
-
|
|
31
|
-
const second = await engine.provision({
|
|
32
|
-
companyUid: "cmp_x",
|
|
33
|
-
companySlug: "x",
|
|
34
|
-
});
|
|
35
|
-
expect(second.status).toBe("existing");
|
|
36
|
-
expect(second.resourceArn).toBe(first.resourceArn);
|
|
37
|
-
|
|
38
|
-
const health = await engine.healthCheck(first.resourceArn);
|
|
39
|
-
expect(health.healthy).toBe(true);
|
|
40
|
-
|
|
41
|
-
// Secret payload must not be a printable postgres URL in mock either
|
|
42
|
-
expect(JSON.stringify(first.connectionSecret)).not.toMatch(/postgres:\/\//i);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pluggable remote vault DB engine interface (vault-databases US-007).
|
|
3
|
-
*
|
|
4
|
-
* Default shipped adapter id: aurora-dsql.
|
|
5
|
-
* This module is interface + registry only — no production AWS provision here.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/** Connection material written only to secrets stores — never CLI stdout. */
|
|
9
|
-
export interface RemoteConnectionSecretPayload {
|
|
10
|
-
/** Opaque secret body (e.g. JSON with host/user/password or IAM token recipe). */
|
|
11
|
-
payload: Record<string, unknown>;
|
|
12
|
-
/** Suggested vault/Secrets Manager key suffix (namespaced by company elsewhere). */
|
|
13
|
-
secretNameHint: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface RemoteProvisionRequest {
|
|
17
|
-
companyUid: string;
|
|
18
|
-
companySlug: string;
|
|
19
|
-
region?: string;
|
|
20
|
-
/** Engine-specific options (cluster params, etc.). */
|
|
21
|
-
options?: Record<string, unknown>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface RemoteProvisionResult {
|
|
25
|
-
engineId: string;
|
|
26
|
-
resourceArn: string;
|
|
27
|
-
region: string;
|
|
28
|
-
status: "ready" | "provisioning" | "failed" | "existing";
|
|
29
|
-
/** Secret payload to store — callers must not print. */
|
|
30
|
-
connectionSecret: RemoteConnectionSecretPayload;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface RemoteHealth {
|
|
34
|
-
engineId: string;
|
|
35
|
-
resourceArn: string;
|
|
36
|
-
healthy: boolean;
|
|
37
|
-
status: string;
|
|
38
|
-
checkedAt: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Remote Postgres-class engine adapter.
|
|
43
|
-
* Implementations live in control plane (hq-pro) for real AWS; CLI may mock.
|
|
44
|
-
*/
|
|
45
|
-
export interface RemoteDbEngine {
|
|
46
|
-
readonly id: string;
|
|
47
|
-
provision(req: RemoteProvisionRequest): Promise<RemoteProvisionResult>;
|
|
48
|
-
deprovision(companyUid: string, resourceArn: string): Promise<void>;
|
|
49
|
-
connectionSecretPayload(
|
|
50
|
-
companyUid: string,
|
|
51
|
-
resourceArn: string,
|
|
52
|
-
): Promise<RemoteConnectionSecretPayload>;
|
|
53
|
-
healthCheck(resourceArn: string): Promise<RemoteHealth>;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/** Default engine selection (PRD decision). */
|
|
57
|
-
export const DEFAULT_REMOTE_ENGINE_ID = "aurora-dsql";
|
|
58
|
-
|
|
59
|
-
const registry = new Map<string, RemoteDbEngine>();
|
|
60
|
-
|
|
61
|
-
export function registerRemoteEngine(engine: RemoteDbEngine): void {
|
|
62
|
-
registry.set(engine.id, engine);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function getRemoteEngine(id: string = DEFAULT_REMOTE_ENGINE_ID): RemoteDbEngine {
|
|
66
|
-
const engine = registry.get(id);
|
|
67
|
-
if (!engine) {
|
|
68
|
-
throw new Error(
|
|
69
|
-
`remote DB engine not registered: ${id} (available: ${[...registry.keys()].join(", ") || "none"})`,
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
return engine;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function listRemoteEngineIds(): string[] {
|
|
76
|
-
return [...registry.keys()];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Clear registry (tests only). */
|
|
80
|
-
export function _resetRemoteEngineRegistryForTests(): void {
|
|
81
|
-
registry.clear();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* In-memory mock engine for unit tests — no AWS.
|
|
86
|
-
*/
|
|
87
|
-
export function createMockRemoteEngine(
|
|
88
|
-
id = "mock",
|
|
89
|
-
): RemoteDbEngine {
|
|
90
|
-
const resources = new Map<string, { companyUid: string; region: string }>();
|
|
91
|
-
|
|
92
|
-
return {
|
|
93
|
-
id,
|
|
94
|
-
async provision(req) {
|
|
95
|
-
const existing = [...resources.entries()].find(
|
|
96
|
-
([, v]) => v.companyUid === req.companyUid,
|
|
97
|
-
);
|
|
98
|
-
if (existing) {
|
|
99
|
-
const [arn, meta] = existing;
|
|
100
|
-
return {
|
|
101
|
-
engineId: id,
|
|
102
|
-
resourceArn: arn,
|
|
103
|
-
region: meta.region,
|
|
104
|
-
status: "existing",
|
|
105
|
-
connectionSecret: {
|
|
106
|
-
payload: { mock: true, companyUid: req.companyUid },
|
|
107
|
-
secretNameHint: `db/remote/${req.companySlug}`,
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
const arn = `arn:mock:db:${req.companyUid}`;
|
|
112
|
-
const region = req.region ?? "us-east-1";
|
|
113
|
-
resources.set(arn, { companyUid: req.companyUid, region });
|
|
114
|
-
return {
|
|
115
|
-
engineId: id,
|
|
116
|
-
resourceArn: arn,
|
|
117
|
-
region,
|
|
118
|
-
status: "ready",
|
|
119
|
-
connectionSecret: {
|
|
120
|
-
payload: { mock: true, companyUid: req.companyUid },
|
|
121
|
-
secretNameHint: `db/remote/${req.companySlug}`,
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
},
|
|
125
|
-
async deprovision(companyUid, resourceArn) {
|
|
126
|
-
const meta = resources.get(resourceArn);
|
|
127
|
-
if (meta && meta.companyUid === companyUid) {
|
|
128
|
-
resources.delete(resourceArn);
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
async connectionSecretPayload(companyUid, resourceArn) {
|
|
132
|
-
return {
|
|
133
|
-
payload: { mock: true, companyUid, resourceArn },
|
|
134
|
-
secretNameHint: `db/remote/${companyUid}`,
|
|
135
|
-
};
|
|
136
|
-
},
|
|
137
|
-
async healthCheck(resourceArn) {
|
|
138
|
-
const ok = resources.has(resourceArn);
|
|
139
|
-
return {
|
|
140
|
-
engineId: id,
|
|
141
|
-
resourceArn,
|
|
142
|
-
healthy: ok,
|
|
143
|
-
status: ok ? "ready" : "missing",
|
|
144
|
-
checkedAt: new Date().toISOString(),
|
|
145
|
-
};
|
|
146
|
-
},
|
|
147
|
-
};
|
|
148
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Remote SQL helper tests (US-010).
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, expect, it } from "vitest";
|
|
6
|
-
|
|
7
|
-
import { runRemoteSql } from "./remote-sql.js";
|
|
8
|
-
|
|
9
|
-
describe("runRemoteSql", () => {
|
|
10
|
-
it("returns rows without connection string in output", async () => {
|
|
11
|
-
const result = await runRemoteSql({
|
|
12
|
-
company: "indigo",
|
|
13
|
-
sql: "SELECT 1 AS n",
|
|
14
|
-
getConnectionConfig: async () => ({ host: "mock", mock: true }),
|
|
15
|
-
execute: async () => [{ n: 1 }],
|
|
16
|
-
});
|
|
17
|
-
expect(result.rows).toEqual([{ n: 1 }]);
|
|
18
|
-
expect(JSON.stringify(result)).not.toMatch(/postgres:\/\//i);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("clear error when no remote binding", async () => {
|
|
22
|
-
await expect(
|
|
23
|
-
runRemoteSql({
|
|
24
|
-
company: "indigo",
|
|
25
|
-
sql: "SELECT 1",
|
|
26
|
-
getConnectionConfig: async () => {
|
|
27
|
-
throw new Error("no remote binding");
|
|
28
|
-
},
|
|
29
|
-
}),
|
|
30
|
-
).rejects.toThrow(/provision/i);
|
|
31
|
-
});
|
|
32
|
-
});
|
package/src/lib/db/remote-sql.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Remote SQL via secrets-exec style injection (US-010).
|
|
3
|
-
*
|
|
4
|
-
* Connection string never appears in argv, logs, or stdout.
|
|
5
|
-
* Local remains default when --remote is absent (handled by command layer).
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export interface RemoteSqlOptions {
|
|
9
|
-
company: string;
|
|
10
|
-
sql: string;
|
|
11
|
-
/** Injected secret material — never log. */
|
|
12
|
-
getConnectionConfig: () => Promise<Record<string, unknown>>;
|
|
13
|
-
/** Execute against remote; tests inject mock. */
|
|
14
|
-
execute?: (
|
|
15
|
-
config: Record<string, unknown>,
|
|
16
|
-
sql: string,
|
|
17
|
-
) => Promise<Record<string, unknown>[]>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface RemoteSqlResult {
|
|
21
|
-
rows: Record<string, unknown>[];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function assertNoLeak(label: string, value: unknown): void {
|
|
25
|
-
const s = typeof value === "string" ? value : JSON.stringify(value);
|
|
26
|
-
if (/postgres:\/\//i.test(s) || /postgresql:\/\//i.test(s)) {
|
|
27
|
-
throw new Error(`${label}: connection string leak blocked`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Run SQL on remote tier using vault-bound credentials.
|
|
33
|
-
*/
|
|
34
|
-
export async function runRemoteSql(
|
|
35
|
-
opts: RemoteSqlOptions,
|
|
36
|
-
): Promise<RemoteSqlResult> {
|
|
37
|
-
if (!opts.sql?.trim()) {
|
|
38
|
-
throw new Error("SQL statement is required");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let config: Record<string, unknown>;
|
|
42
|
-
try {
|
|
43
|
-
config = await opts.getConnectionConfig();
|
|
44
|
-
} catch (e) {
|
|
45
|
-
const msg = e instanceof Error ? e.message : "no remote binding";
|
|
46
|
-
throw new Error(
|
|
47
|
-
`remote SQL unavailable: ${msg}. Run \`hq db provision --company ${opts.company}\` first.`,
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
assertNoLeak("connection config", config);
|
|
52
|
-
|
|
53
|
-
if (!opts.execute) {
|
|
54
|
-
throw new Error(
|
|
55
|
-
"remote SQL executor not configured in this build (adapter pending live DSQL wire-up)",
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const rows = await opts.execute(config, opts.sql);
|
|
60
|
-
assertNoLeak("remote sql rows", rows);
|
|
61
|
-
return { rows };
|
|
62
|
-
}
|
package/src/lib/db/sql.test.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Local SQL execution tests (vault-databases US-004).
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import fs from "node:fs";
|
|
6
|
-
import os from "node:os";
|
|
7
|
-
import path from "node:path";
|
|
8
|
-
|
|
9
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
10
|
-
|
|
11
|
-
import { openLocalDb } from "./local.js";
|
|
12
|
-
import { resolveLocalDbPath } from "./paths.js";
|
|
13
|
-
import {
|
|
14
|
-
formatSqlResult,
|
|
15
|
-
resolveSqlDbPath,
|
|
16
|
-
runLocalSql,
|
|
17
|
-
} from "./sql.js";
|
|
18
|
-
|
|
19
|
-
const tempHomes: string[] = [];
|
|
20
|
-
|
|
21
|
-
function makeTempHome(): string {
|
|
22
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "hq-db-sql-"));
|
|
23
|
-
tempHomes.push(dir);
|
|
24
|
-
return dir;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
afterEach(() => {
|
|
28
|
-
while (tempHomes.length > 0) {
|
|
29
|
-
const dir = tempHomes.pop();
|
|
30
|
-
if (dir) fs.rmSync(dir, { recursive: true, force: true });
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe("runLocalSql", () => {
|
|
35
|
-
it("SELECT happy path returns rows as jsonl-friendly records", () => {
|
|
36
|
-
const home = makeTempHome();
|
|
37
|
-
const db = openLocalDb("alpha", { home });
|
|
38
|
-
db.exec("CREATE TABLE smoke (id INTEGER PRIMARY KEY, name TEXT)");
|
|
39
|
-
db.prepare("INSERT INTO smoke (name) VALUES (?)").run("hello");
|
|
40
|
-
db.close();
|
|
41
|
-
|
|
42
|
-
const result = runLocalSql({
|
|
43
|
-
company: "alpha",
|
|
44
|
-
home,
|
|
45
|
-
sql: "SELECT id, name FROM smoke ORDER BY id",
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
expect(result.rows).toEqual([{ id: 1, name: "hello" }]);
|
|
49
|
-
expect(formatSqlResult(result, "jsonl")).toContain('"name":"hello"');
|
|
50
|
-
expect(JSON.stringify(result)).not.toMatch(/postgres:\/\//i);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("blocks write SQL without --write", () => {
|
|
54
|
-
const home = makeTempHome();
|
|
55
|
-
openLocalDb("alpha", { home }).close();
|
|
56
|
-
|
|
57
|
-
expect(() =>
|
|
58
|
-
runLocalSql({
|
|
59
|
-
company: "alpha",
|
|
60
|
-
home,
|
|
61
|
-
sql: "CREATE TABLE t (id INTEGER)",
|
|
62
|
-
}),
|
|
63
|
-
).toThrow(/read-only/i);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("denies cross-company path override by default", () => {
|
|
67
|
-
const home = makeTempHome();
|
|
68
|
-
openLocalDb("alpha", { home }).close();
|
|
69
|
-
openLocalDb("beta", { home }).close();
|
|
70
|
-
|
|
71
|
-
const betaPath = resolveLocalDbPath("beta", { home });
|
|
72
|
-
|
|
73
|
-
expect(() =>
|
|
74
|
-
resolveSqlDbPath({
|
|
75
|
-
company: "alpha",
|
|
76
|
-
home,
|
|
77
|
-
sql: "SELECT 1",
|
|
78
|
-
dbPathOverride: betaPath,
|
|
79
|
-
}),
|
|
80
|
-
).toThrow(/denied/i);
|
|
81
|
-
|
|
82
|
-
expect(() =>
|
|
83
|
-
runLocalSql({
|
|
84
|
-
company: "alpha",
|
|
85
|
-
home,
|
|
86
|
-
sql: "SELECT 1",
|
|
87
|
-
dbPathOverride: betaPath,
|
|
88
|
-
}),
|
|
89
|
-
).toThrow(/denied/i);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("rejects ATTACH even with --write (tenant isolation)", () => {
|
|
93
|
-
const home = makeTempHome();
|
|
94
|
-
openLocalDb("alpha", { home }).close();
|
|
95
|
-
const betaPath = resolveLocalDbPath("beta", { home });
|
|
96
|
-
|
|
97
|
-
expect(() =>
|
|
98
|
-
runLocalSql({
|
|
99
|
-
company: "alpha",
|
|
100
|
-
home,
|
|
101
|
-
write: true,
|
|
102
|
-
sql: `ATTACH DATABASE '${betaPath}' AS other`,
|
|
103
|
-
}),
|
|
104
|
-
).toThrow(/ATTACH|tenant isolation/i);
|
|
105
|
-
});
|
|
106
|
-
});
|