Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 108 additions & 1 deletion packages/opencode/test/altimate/connections.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ afterAll(() => { delete process.env.ALTIMATE_TELEMETRY_DISABLED })
import * as Registry from "../../src/altimate/native/connections/registry"
import { detectAuthMethod } from "../../src/altimate/native/connections/registry"
import * as CredentialStore from "../../src/altimate/native/connections/credential-store"
import { parseDbtProfiles } from "../../src/altimate/native/connections/dbt-profiles"
import { parseDbtProfiles, dbtConnectionsToConfigs } from "../../src/altimate/native/connections/dbt-profiles"
import { discoverContainers, containerToConfig } from "../../src/altimate/native/connections/docker-discovery"
import { registerAll } from "../../src/altimate/native/connections/register"

Expand Down Expand Up @@ -534,6 +534,91 @@ warehouse_b:
}
})
// altimate_change end

test("spark adapter maps to databricks", async () => {
const fs = await import("fs")
const os = await import("os")
const path = await import("path")

const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "dbt-test-"))
const profilesPath = path.join(tmpDir, "profiles.yml")

fs.writeFileSync(
profilesPath,
`
spark_project:
outputs:
prod:
type: spark
server_hostname: my-spark-cluster.databricks.com
http_path: /sql/1.0/warehouses/abc123
token: dapi_secret
`,
)

try {
const connections = await parseDbtProfiles(profilesPath)
expect(connections).toHaveLength(1)
expect(connections[0].type).toBe("databricks")
expect(connections[0].config.type).toBe("databricks")
} finally {
fs.rmSync(tmpDir, { recursive: true })
}
})

test("trino adapter maps to postgres (wire-compatible)", async () => {
const fs = await import("fs")
const os = await import("os")
const path = await import("path")

const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "dbt-test-"))
const profilesPath = path.join(tmpDir, "profiles.yml")

fs.writeFileSync(
profilesPath,
`
trino_project:
outputs:
prod:
type: trino
host: trino.example.com
port: 8080
user: analyst
dbname: hive
`,
)

try {
const connections = await parseDbtProfiles(profilesPath)
expect(connections).toHaveLength(1)
expect(connections[0].type).toBe("postgres")
expect(connections[0].config.type).toBe("postgres")
} finally {
fs.rmSync(tmpDir, { recursive: true })
}
})
})

// ---------------------------------------------------------------------------
// dbtConnectionsToConfigs
// ---------------------------------------------------------------------------

describe("dbtConnectionsToConfigs", () => {
test("converts connection array to keyed record", () => {
const connections = [
{ name: "pg_dev", type: "postgres", config: { type: "postgres", host: "localhost" } },
{ name: "sf_prod", type: "snowflake", config: { type: "snowflake", account: "abc" } },
]
const result = dbtConnectionsToConfigs(connections)
expect(Object.keys(result)).toHaveLength(2)
expect(result["pg_dev"].type).toBe("postgres")
expect(result["sf_prod"].type).toBe("snowflake")
})

test("returns empty object for empty array", () => {
const result = dbtConnectionsToConfigs([])
expect(result).toEqual({})
})
})

// ---------------------------------------------------------------------------
Expand All @@ -546,6 +631,28 @@ describe("Docker discovery", () => {
expect(containers).toEqual([])
})

test("containerToConfig creates config with all fields from a fully-populated container", () => {
const container = {
container_id: "abc123def456",
name: "my-postgres",
image: "postgres:16",
db_type: "postgres",
host: "127.0.0.1",
port: 5432,
user: "admin",
password: "secret",
database: "mydb",
status: "running",
}
const config = containerToConfig(container as any)
expect(config.type).toBe("postgres")
expect(config.host).toBe("127.0.0.1")
expect(config.port).toBe(5432)
expect(config.user).toBe("admin")
expect(config.password).toBe("secret")
expect(config.database).toBe("mydb")
})

test("containerToConfig omits undefined optional fields", () => {
const container = {
container_id: "def456",
Expand Down
86 changes: 86 additions & 0 deletions packages/opencode/test/altimate/ssh-tunnel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { describe, test, expect, afterEach } from "bun:test"
import { extractSshConfig, closeTunnel, closeAllTunnels, getActiveTunnel } from "../../src/altimate/native/connections/ssh-tunnel"

afterEach(() => {
closeAllTunnels()
})

// ---------------------------------------------------------------------------
// extractSshConfig — pure function that extracts SSH tunnel config
// ---------------------------------------------------------------------------

describe("extractSshConfig", () => {
test("returns null when no ssh_host is present", () => {
const result = extractSshConfig({ type: "postgres", host: "db.example.com", port: 5432 })
expect(result).toBeNull()
})

test("extracts full SSH config with all fields", () => {
const result = extractSshConfig({
type: "postgres",
host: "db.internal",
port: 5433,
ssh_host: "bastion.example.com",
ssh_port: 2222,
ssh_user: "deployer",
ssh_password: "secret",
})
expect(result).toEqual({
ssh_host: "bastion.example.com",
ssh_port: 2222,
ssh_user: "deployer",
ssh_password: "secret",
ssh_private_key: undefined,
host: "db.internal",
port: 5433,
})
})

test("applies defaults for ssh_port, ssh_user, host, port", () => {
const result = extractSshConfig({
type: "postgres",
ssh_host: "bastion.example.com",
})
expect(result).not.toBeNull()
expect(result!.ssh_port).toBe(22)
expect(result!.ssh_user).toBe("root")
expect(result!.host).toBe("127.0.0.1")
expect(result!.port).toBe(5432)
})

test("throws when connection_string is used with SSH tunnel", () => {
expect(() => extractSshConfig({
type: "postgres",
ssh_host: "bastion.example.com",
connection_string: "postgresql://user:pass@host:5432/db",
})).toThrow("Cannot use SSH tunnel with connection_string")
})

test("supports private key authentication", () => {
const result = extractSshConfig({
type: "snowflake",
host: "db.internal",
port: 443,
ssh_host: "bastion.example.com",
ssh_private_key: "-----BEGIN OPENSSH PRIVATE KEY-----\nAAA...",
})
expect(result).not.toBeNull()
expect(result!.ssh_private_key).toBe("-----BEGIN OPENSSH PRIVATE KEY-----\nAAA...")
expect(result!.ssh_password).toBeUndefined()
})
})

// ---------------------------------------------------------------------------
// closeTunnel / getActiveTunnel — idempotent operations on empty state
// ---------------------------------------------------------------------------

describe("SSH tunnel state management", () => {
test("closeTunnel is a no-op for non-existent tunnel", () => {
closeTunnel("nonexistent-tunnel-name")
expect(getActiveTunnel("nonexistent-tunnel-name")).toBeUndefined()
})

test("getActiveTunnel returns undefined for non-existent tunnel", () => {
expect(getActiveTunnel("nonexistent")).toBeUndefined()
})
})
5 changes: 5 additions & 0 deletions packages/opencode/test/altimate/telemetry-safety.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ describe("Telemetry Safety: Helper functions never throw", () => {
expect(detectAuthMethod({ type: "duckdb" })).toBe("file")
expect(detectAuthMethod({ type: "sqlite" })).toBe("file")
expect(detectAuthMethod({ type: "postgres" })).toBe("unknown")
// MongoDB auth detection
expect(detectAuthMethod({ type: "mongodb", connection_string: "mongodb://localhost" })).toBe("connection_string")
expect(detectAuthMethod({ type: "mongodb", password: "secret" })).toBe("password")
expect(detectAuthMethod({ type: "mongodb" })).toBe("connection_string")
expect(detectAuthMethod({ type: "mongo" })).toBe("connection_string")
// Edge cases
expect(detectAuthMethod({} as any)).toBe("unknown")
expect(detectAuthMethod({ type: "" })).toBe("unknown")
Expand Down
7 changes: 6 additions & 1 deletion test/sanity/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ COPY --chown=testuser packages/opencode/script/postinstall.mjs /home/testuser/.a
COPY --chown=testuser packages/opencode/package.json /home/testuser/.altimate-install/package.json
COPY --chown=testuser .opencode/skills/ /home/testuser/.altimate-install/skills/

# Install altimate-core native binding (required at runtime)
# Install altimate-core native binding (required at runtime).
# NOTE: Database drivers (pg, snowflake-sdk, mysql2, etc.) are NOT installed here
# because a real `npm install -g altimate-code` doesn't install them either —
# they're optionalDependencies in the workspace @altimateai/drivers package which
# is never published. This is issue #295. Driver resolvability tests are expected
# to FAIL here, proving the bug exists for real users.
RUN cd /home/testuser/.altimate-install && \
echo '{"dependencies":{"@altimateai/altimate-core":"latest"}}' > package.json && \
bun install && \
Expand Down
16 changes: 10 additions & 6 deletions test/sanity/ci-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,25 @@ if [ "$MODE" = "--full" ] || [ "$MODE" = "full" ]; then
echo "=== Full CI (Docker) ==="

# Driver E2E with Docker containers
run_step "Docker Services Up" docker compose -f "$REPO_ROOT/test/sanity/docker-compose.yml" up -d postgres mysql mssql redshift
run_step "Docker Services Up" docker compose -f "$REPO_ROOT/test/sanity/docker-compose.yml" up -d postgres mysql mssql redshift mongodb

echo " Waiting for services to be healthy..."
HEALTHY=0
for _wait in $(seq 1 30); do
HEALTHY=$(docker compose -f "$REPO_ROOT/test/sanity/docker-compose.yml" ps --format json 2>/dev/null | grep -c '"healthy"' || echo "0")
if [ "$HEALTHY" -ge 4 ]; then break; fi
if [ "$HEALTHY" -ge 5 ]; then break; fi
sleep 2
done

if [ "$HEALTHY" -lt 4 ]; then
echo " >>> Docker Services: FAILED ($HEALTHY/4 healthy after 60s)"
if [ "$HEALTHY" -lt 5 ]; then
echo " >>> Docker Services: FAILED ($HEALTHY/5 healthy after 60s)"
EXIT_CODE=1
else
echo " >>> Docker Services: $HEALTHY/4 healthy"
echo " >>> Docker Services: $HEALTHY/5 healthy"
fi

# Skip driver tests if services aren't healthy
if [ "$HEALTHY" -lt 4 ]; then
if [ "$HEALTHY" -lt 5 ]; then
echo " SKIP: Driver E2E tests (services not healthy)"
else

Expand All @@ -88,6 +88,10 @@ if [ "$MODE" = "--full" ] || [ "$MODE" = "full" ]; then
TEST_REDSHIFT_HOST=127.0.0.1 TEST_REDSHIFT_PORT=15439 TEST_REDSHIFT_PASSWORD=testpass123 \
bun test test/altimate/drivers-docker-e2e.test.ts --timeout 30000"

run_step "Driver E2E (mongodb)" bash -c "cd $REPO_ROOT/packages/opencode && \
TEST_MONGODB_HOST=127.0.0.1 TEST_MONGODB_PORT=17017 \
bun test test/altimate/drivers-mongodb-e2e.test.ts --timeout 30000"

# Full sanity suite in Docker
run_step "Sanity Suite (Docker)" docker compose -f "$REPO_ROOT/test/sanity/docker-compose.yml" \
up --build --abort-on-container-exit --exit-code-from sanity
Expand Down
19 changes: 14 additions & 5 deletions test/sanity/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ services:
- TEST_REDSHIFT_HOST=redshift
- TEST_REDSHIFT_PORT=5432
- TEST_REDSHIFT_PASSWORD=testpass123
- TEST_MONGODB_HOST=mongodb
- TEST_MONGODB_PORT=27017
depends_on:
postgres:
condition: service_healthy
mysql:
condition: service_healthy
mssql:
condition: service_healthy
redshift:
mongodb:
condition: service_healthy
# mysql, mssql, redshift are for driver E2E tests (ci-local.sh --full),
# not the sanity shell scripts. Don't block sanity on them.

postgres:
image: postgres:16-alpine
Expand Down Expand Up @@ -74,3 +74,12 @@ services:
test: pg_isready
interval: 5s
retries: 10

mongodb:
image: mongo:7
ports:
- "17017:27017"
healthcheck:
test: mongosh --eval "db.adminCommand('ping')" --quiet
interval: 5s
retries: 10
Loading
Loading