Skip to content

Commit 2134509

Browse files
committed
test: clickhouse env detection & filesystem write permissions on ENOENT path
Cover two untested code paths from recent PRs: 1. ClickHouse env var detection added in #574 had zero test coverage 2. Filesystem.write chmod fix on the ENOENT retry path (creating parent dirs) was untested Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> https://claude.ai/code/session_01X5hQueMu6AzQ8jwdUnCqPK
1 parent 0d34855 commit 2134509

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

packages/opencode/test/tool/project-scan.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ describe("detectEnvVars", () => {
312312
"PGHOST", "PGPORT", "PGDATABASE", "PGUSER", "PGPASSWORD", "DATABASE_URL",
313313
"MYSQL_HOST", "MYSQL_TCP_PORT", "MYSQL_DATABASE", "MYSQL_USER", "MYSQL_PASSWORD",
314314
"REDSHIFT_HOST", "REDSHIFT_PORT", "REDSHIFT_DATABASE", "REDSHIFT_USER", "REDSHIFT_PASSWORD",
315+
"CLICKHOUSE_HOST", "CLICKHOUSE_URL", "CLICKHOUSE_PORT", "CLICKHOUSE_DB",
316+
"CLICKHOUSE_DATABASE", "CLICKHOUSE_USER", "CLICKHOUSE_USERNAME", "CLICKHOUSE_PASSWORD",
315317
]
316318
for (const v of vars) {
317319
delete process.env[v]
@@ -542,6 +544,35 @@ describe("detectEnvVars", () => {
542544
}
543545
})
544546

547+
test("detects ClickHouse via CLICKHOUSE_HOST", async () => {
548+
clearWarehouseEnvVars()
549+
process.env.CLICKHOUSE_HOST = "clickhouse.example.com"
550+
process.env.CLICKHOUSE_PORT = "8443"
551+
process.env.CLICKHOUSE_DATABASE = "analytics"
552+
process.env.CLICKHOUSE_USER = "default"
553+
554+
const result = await detectEnvVars()
555+
const ch = result.find((r) => r.type === "clickhouse")
556+
expect(ch).toBeDefined()
557+
expect(ch!.signal).toBe("CLICKHOUSE_HOST")
558+
expect(ch!.config.host).toBe("clickhouse.example.com")
559+
expect(ch!.config.port).toBe("8443")
560+
expect(ch!.config.database).toBe("analytics")
561+
expect(ch!.config.user).toBe("default")
562+
})
563+
564+
test("detects ClickHouse via DATABASE_URL with clickhouse+http scheme", async () => {
565+
clearWarehouseEnvVars()
566+
process.env.DATABASE_URL = "clickhouse+http://user:pass@host:8123/db"
567+
568+
const result = await detectEnvVars()
569+
const ch = result.find((r) => r.type === "clickhouse")
570+
expect(ch).toBeDefined()
571+
expect(ch!.type).toBe("clickhouse")
572+
expect(ch!.signal).toBe("DATABASE_URL")
573+
expect(ch!.config.connection_string).toBe("***")
574+
})
575+
545576
test("connection names follow env_ prefix convention", async () => {
546577
clearWarehouseEnvVars()
547578
process.env.SNOWFLAKE_ACCOUNT = "acct"

packages/opencode/test/util/filesystem.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,20 @@ describe("filesystem", () => {
217217

218218
expect(await fs.readFile(filepath, "utf-8")).toBe(content)
219219
})
220+
221+
test("applies permissions when creating parent directories", async () => {
222+
await using tmp = await tmpdir()
223+
const filepath = path.join(tmp.path, "new", "nested", "secret.key")
224+
225+
await Filesystem.write(filepath, "private-key-data", 0o600)
226+
227+
const content = await fs.readFile(filepath, "utf-8")
228+
expect(content).toBe("private-key-data")
229+
if (process.platform !== "win32") {
230+
const stats = await fs.stat(filepath)
231+
expect(stats.mode & 0o777).toBe(0o600)
232+
}
233+
})
220234
})
221235

222236
describe("writeJson()", () => {

0 commit comments

Comments
 (0)