@indigoai-us/hq-cli 5.60.0 → 5.62.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/dist/commands/agents.d.ts +109 -0
- package/dist/commands/agents.js +385 -0
- package/dist/commands/db-migrate.d.ts +6 -0
- package/dist/commands/db-migrate.js +42 -0
- package/dist/commands/db-provision.d.ts +15 -0
- package/dist/commands/db-provision.js +78 -0
- package/dist/commands/db-sql.d.ts +9 -0
- package/dist/commands/db-sql.js +81 -0
- package/dist/commands/db-status.d.ts +7 -0
- package/dist/commands/db-status.js +70 -0
- package/dist/commands/db.d.ts +9 -0
- package/dist/commands/db.js +23 -0
- package/dist/commands/integrations.d.ts +78 -0
- package/dist/commands/integrations.js +309 -0
- package/dist/commands/members.js +4 -4
- package/dist/commands/outposts.d.ts +60 -0
- package/dist/commands/outposts.js +255 -0
- package/dist/commands/pack-install.d.ts +7 -1
- package/dist/commands/pack-install.js +86 -15
- package/dist/commands/packs.d.ts +2 -1
- package/dist/commands/packs.js +13 -8
- package/dist/commands/secrets.d.ts +13 -0
- package/dist/commands/secrets.js +149 -10
- package/dist/commands/skill.d.ts +153 -0
- package/dist/commands/skill.js +593 -0
- package/dist/commands/workers.d.ts +48 -0
- package/dist/commands/workers.js +229 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +14 -240
- package/dist/lib/db/control-plane.d.ts +45 -0
- package/dist/lib/db/control-plane.js +81 -0
- package/dist/lib/db/local.d.ts +49 -0
- package/dist/lib/db/local.js +106 -0
- package/dist/lib/db/migrate.d.ts +41 -0
- package/dist/lib/db/migrate.js +104 -0
- package/dist/lib/db/paths.d.ts +56 -0
- package/dist/lib/db/paths.js +103 -0
- package/dist/lib/db/remote-engine.d.ts +58 -0
- package/dist/lib/db/remote-engine.js +90 -0
- package/dist/lib/db/remote-sql.d.ts +22 -0
- package/dist/lib/db/remote-sql.js +39 -0
- package/dist/lib/db/sql.d.ts +49 -0
- package/dist/lib/db/sql.js +132 -0
- package/dist/main.d.ts +7 -0
- package/dist/main.js +272 -0
- package/dist/utils/cognito-session.js +3 -3
- package/dist/utils/sandbox-runner-client.d.ts +13 -0
- package/dist/utils/sandbox-runner-client.js +83 -6
- package/dist/utils/version-check.d.ts +6 -0
- package/dist/utils/version-check.js +78 -2
- package/package.json +9 -1
- package/pnpm-workspace.yaml +2 -0
- package/src/commands/agents.test.ts +297 -0
- package/src/commands/agents.ts +561 -0
- package/src/commands/db-migrate.ts +55 -0
- package/src/commands/db-provision.ts +102 -0
- package/src/commands/db-sql.ts +124 -0
- package/src/commands/db-status.ts +100 -0
- package/src/commands/db.ts +26 -0
- package/src/commands/integrations.test.ts +284 -0
- package/src/commands/integrations.ts +438 -0
- package/src/commands/members.ts +2 -2
- package/src/commands/outposts.test.ts +177 -0
- package/src/commands/outposts.ts +338 -0
- package/src/commands/pack-install.ts +115 -18
- package/src/commands/pack-update-cache.test.ts +149 -0
- package/src/commands/packs.ts +28 -7
- package/src/commands/secrets.parse-destination.test.ts +38 -0
- package/src/commands/secrets.test.ts +342 -0
- package/src/commands/secrets.ts +227 -13
- package/src/commands/skill.test.ts +770 -0
- package/src/commands/skill.ts +796 -0
- package/src/commands/workers.test.ts +158 -0
- package/src/commands/workers.ts +298 -0
- package/src/index.test.ts +32 -0
- package/src/index.ts +11 -274
- package/src/lib/db/control-plane.test.ts +59 -0
- package/src/lib/db/control-plane.ts +113 -0
- package/src/lib/db/local.test.ts +81 -0
- package/src/lib/db/local.ts +148 -0
- package/src/lib/db/migrate.test.ts +133 -0
- package/src/lib/db/migrate.ts +137 -0
- package/src/lib/db/paths.test.ts +112 -0
- package/src/lib/db/paths.ts +128 -0
- package/src/lib/db/remote-engine.test.ts +44 -0
- package/src/lib/db/remote-engine.ts +148 -0
- package/src/lib/db/remote-sql.test.ts +32 -0
- package/src/lib/db/remote-sql.ts +62 -0
- package/src/lib/db/sql.test.ts +106 -0
- package/src/lib/db/sql.ts +192 -0
- package/src/main.ts +314 -0
- package/src/utils/cognito-session.ts +1 -1
- package/src/utils/sandbox-runner-client.test.ts +128 -0
- package/src/utils/sandbox-runner-client.ts +100 -4
- package/src/utils/version-check.test.ts +30 -0
- package/src/utils/version-check.ts +72 -0
- package/test/commands/db-tenant-isolation.test.ts +94 -0
- package/test/commands/db.test.ts +85 -0
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local SQL execution helpers (vault-databases US-004).
|
|
3
|
+
*
|
|
4
|
+
* Company scope is path-bound via resolveLocalDbPath — callers must pass the
|
|
5
|
+
* resolved company slug from HQ session/flags. Path overrides that open
|
|
6
|
+
* another company's DB are denied unless an explicit dangerous flag is set.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import Database from "better-sqlite3";
|
|
10
|
+
|
|
11
|
+
import type { LocalDb } from "./local.js";
|
|
12
|
+
import { openLocalDb } from "./local.js";
|
|
13
|
+
import {
|
|
14
|
+
normalizeCompanySlugForLocalDb,
|
|
15
|
+
resolveLocalDbDir,
|
|
16
|
+
resolveLocalDbPath,
|
|
17
|
+
type LocalDbPathEnv,
|
|
18
|
+
} from "./paths.js";
|
|
19
|
+
|
|
20
|
+
export interface SqlRunOptions extends LocalDbPathEnv {
|
|
21
|
+
company: string;
|
|
22
|
+
sql: string;
|
|
23
|
+
/** Allow INSERT/UPDATE/DELETE/DDL. Default false (read-only). */
|
|
24
|
+
write?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Dangerous: open an absolute DB path instead of the company canonical path.
|
|
27
|
+
* Denied unless allowCrossCompanyPath is true.
|
|
28
|
+
*/
|
|
29
|
+
dbPathOverride?: string;
|
|
30
|
+
/** Explicit dangerous flag to open a non-canonical local DB path. Default false. */
|
|
31
|
+
allowCrossCompanyPath?: boolean;
|
|
32
|
+
/** Output format */
|
|
33
|
+
format?: "jsonl" | "table";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface SqlRunResult {
|
|
37
|
+
columns: string[];
|
|
38
|
+
rows: Record<string, unknown>[];
|
|
39
|
+
changes: number;
|
|
40
|
+
readonly: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const WRITE_PATTERN =
|
|
44
|
+
/^\s*(INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|ALTER|TRUNCATE|REINDEX|VACUUM|BEGIN|COMMIT|ROLLBACK)\b/i;
|
|
45
|
+
|
|
46
|
+
/** Always forbidden — opens other files/DBs and breaks company path isolation. */
|
|
47
|
+
const FORBIDDEN_SQL_PATTERN =
|
|
48
|
+
/\b(ATTACH|DETACH|LOAD_EXTENSION)\b/i;
|
|
49
|
+
|
|
50
|
+
export function stripSqlNoise(sql: string): string {
|
|
51
|
+
return sql
|
|
52
|
+
.replace(/^\s*--[^\n]*\n/gm, "")
|
|
53
|
+
.replace(/^\s*\/\*[\s\S]*?\*\//gm, "")
|
|
54
|
+
.trim();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function isWriteSql(sql: string): boolean {
|
|
58
|
+
return WRITE_PATTERN.test(stripSqlNoise(sql));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Statements that must never run via `hq db sql`, even with --write.
|
|
63
|
+
* ATTACH/DETACH would let a company-scoped session open another company's
|
|
64
|
+
* vault.db by absolute path (category-1 isolation).
|
|
65
|
+
*/
|
|
66
|
+
export function assertSqlAllowed(sql: string): void {
|
|
67
|
+
const stripped = stripSqlNoise(sql);
|
|
68
|
+
if (FORBIDDEN_SQL_PATTERN.test(stripped)) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
"ATTACH/DETACH/LOAD_EXTENSION are not allowed via hq db sql (tenant isolation); use the company-canonical local path only",
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Resolve which file path to open, enforcing company isolation by default.
|
|
77
|
+
*/
|
|
78
|
+
export function resolveSqlDbPath(opts: SqlRunOptions): string {
|
|
79
|
+
const company = normalizeCompanySlugForLocalDb(opts.company);
|
|
80
|
+
const canonical = resolveLocalDbPath(company, opts);
|
|
81
|
+
|
|
82
|
+
if (!opts.dbPathOverride) {
|
|
83
|
+
return canonical;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (opts.dbPathOverride === canonical) {
|
|
87
|
+
return canonical;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!opts.allowCrossCompanyPath) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
"cross-company or path override denied: refusing to open a non-canonical local DB path without --allow-cross-company-path (dangerous)",
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return opts.dbPathOverride;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function openByPath(dbPath: string): LocalDb {
|
|
100
|
+
const db = new Database(dbPath);
|
|
101
|
+
db.pragma("journal_mode = WAL");
|
|
102
|
+
db.pragma("foreign_keys = ON");
|
|
103
|
+
return db;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Execute SQL against the company local vault DB.
|
|
108
|
+
*/
|
|
109
|
+
export function runLocalSql(opts: SqlRunOptions): SqlRunResult {
|
|
110
|
+
const sql = opts.sql?.trim();
|
|
111
|
+
if (!sql) {
|
|
112
|
+
throw new Error("SQL statement is required");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
assertSqlAllowed(sql);
|
|
116
|
+
|
|
117
|
+
const writeRequested = !!opts.write;
|
|
118
|
+
if (isWriteSql(sql) && !writeRequested) {
|
|
119
|
+
throw new Error(
|
|
120
|
+
"write/DDL statement blocked in read-only mode; pass --write to allow (prefer hq db migrate for schema changes)",
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const dbPath = resolveSqlDbPath(opts);
|
|
125
|
+
const usingCanonical =
|
|
126
|
+
!opts.dbPathOverride || opts.dbPathOverride === resolveLocalDbPath(opts.company, opts);
|
|
127
|
+
|
|
128
|
+
const db: LocalDb = usingCanonical
|
|
129
|
+
? openLocalDb(opts.company, opts)
|
|
130
|
+
: openByPath(dbPath);
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
if (!writeRequested) {
|
|
134
|
+
db.pragma("query_only = ON");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const stmt = db.prepare(sql);
|
|
138
|
+
if (stmt.reader) {
|
|
139
|
+
const rows = stmt.all() as Record<string, unknown>[];
|
|
140
|
+
const columns =
|
|
141
|
+
rows.length > 0
|
|
142
|
+
? Object.keys(rows[0] as object)
|
|
143
|
+
: stmt.columns().map((c) => c.name);
|
|
144
|
+
return {
|
|
145
|
+
columns,
|
|
146
|
+
rows,
|
|
147
|
+
changes: 0,
|
|
148
|
+
readonly: !writeRequested,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const info = stmt.run();
|
|
153
|
+
return {
|
|
154
|
+
columns: ["changes", "lastInsertRowid"],
|
|
155
|
+
rows: [
|
|
156
|
+
{
|
|
157
|
+
changes: info.changes,
|
|
158
|
+
lastInsertRowid: Number(info.lastInsertRowid),
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
changes: info.changes,
|
|
162
|
+
readonly: !writeRequested,
|
|
163
|
+
};
|
|
164
|
+
} finally {
|
|
165
|
+
db.close();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function formatSqlResult(
|
|
170
|
+
result: SqlRunResult,
|
|
171
|
+
format: "jsonl" | "table" = "jsonl",
|
|
172
|
+
): string {
|
|
173
|
+
if (format === "jsonl") {
|
|
174
|
+
if (result.rows.length === 0) {
|
|
175
|
+
return JSON.stringify({ columns: result.columns, rows: 0 });
|
|
176
|
+
}
|
|
177
|
+
return result.rows.map((r) => JSON.stringify(r)).join("\n");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const cols = result.columns;
|
|
181
|
+
if (cols.length === 0) return "(no columns)";
|
|
182
|
+
const header = cols.join("\t");
|
|
183
|
+
const body = result.rows
|
|
184
|
+
.map((r) => cols.map((c) => String(r[c] ?? "")).join("\t"))
|
|
185
|
+
.join("\n");
|
|
186
|
+
return body ? `${header}\n${body}` : header;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Test helper: company dir for isolation assertions. */
|
|
190
|
+
export function companyLocalDbDir(company: string, env?: LocalDbPathEnv): string {
|
|
191
|
+
return resolveLocalDbDir(company, env);
|
|
192
|
+
}
|