2026-05-10 23:12:26 +02:00
|
|
|
import assert from 'node:assert/strict';
|
|
|
|
|
import { describe, it } from 'node:test';
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
buildDockerRunArgs,
|
2026-05-10 23:51:24 +02:00
|
|
|
buildKtxYaml,
|
2026-05-10 23:12:26 +02:00
|
|
|
buildLiveDatabaseIngestArgs,
|
|
|
|
|
buildPostgresUrl,
|
|
|
|
|
buildPostgresReadyArgs,
|
|
|
|
|
buildSeedSql,
|
|
|
|
|
smokeContainerName,
|
|
|
|
|
} from './installed-live-database-smoke.mjs';
|
|
|
|
|
|
|
|
|
|
describe('installed live-database artifact smoke helpers', () => {
|
|
|
|
|
it('builds a deterministic disposable Postgres container command', () => {
|
|
|
|
|
assert.deepEqual(
|
|
|
|
|
buildDockerRunArgs({
|
2026-05-10 23:51:24 +02:00
|
|
|
containerName: 'ktx-live-db-smoke-test',
|
2026-05-10 23:12:26 +02:00
|
|
|
hostPort: 15432,
|
|
|
|
|
image: 'postgres:16-alpine',
|
|
|
|
|
}),
|
|
|
|
|
[
|
|
|
|
|
'run',
|
|
|
|
|
'--rm',
|
|
|
|
|
'-d',
|
|
|
|
|
'--name',
|
2026-05-10 23:51:24 +02:00
|
|
|
'ktx-live-db-smoke-test',
|
2026-05-10 23:12:26 +02:00
|
|
|
'-e',
|
|
|
|
|
'POSTGRES_PASSWORD=postgres', // pragma: allowlist secret
|
|
|
|
|
'-e',
|
2026-05-10 23:51:24 +02:00
|
|
|
'POSTGRES_USER=ktx',
|
2026-05-10 23:12:26 +02:00
|
|
|
'-e',
|
|
|
|
|
'POSTGRES_DB=warehouse',
|
|
|
|
|
'-p',
|
|
|
|
|
'127.0.0.1:15432:5432',
|
|
|
|
|
'postgres:16-alpine',
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('uses a collision-resistant Docker container name prefix', () => {
|
2026-05-10 23:51:24 +02:00
|
|
|
assert.match(smokeContainerName(1234, 5678), /^ktx-live-db-smoke-1234-5678$/);
|
2026-05-10 23:12:26 +02:00
|
|
|
});
|
|
|
|
|
|
2026-05-10 23:51:24 +02:00
|
|
|
it('builds the Postgres URL used by ktx.yaml and daemon introspection', () => {
|
2026-05-10 23:12:26 +02:00
|
|
|
assert.equal(
|
|
|
|
|
buildPostgresUrl(15432),
|
2026-05-10 23:51:24 +02:00
|
|
|
'postgresql://ktx:postgres@127.0.0.1:15432/warehouse', // pragma: allowlist secret
|
2026-05-10 23:12:26 +02:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-14 01:43:06 +02:00
|
|
|
it('writes a public database ingest KTX project config with SQLite local state', () => {
|
2026-05-10 23:12:26 +02:00
|
|
|
assert.equal(
|
2026-05-10 23:51:24 +02:00
|
|
|
buildKtxYaml('postgresql://ktx:postgres@127.0.0.1:15432/warehouse'), // pragma: allowlist secret
|
2026-05-10 23:12:26 +02:00
|
|
|
[
|
|
|
|
|
'connections:',
|
|
|
|
|
' warehouse:',
|
|
|
|
|
' driver: postgres',
|
2026-05-10 23:51:24 +02:00
|
|
|
' url: "postgresql://ktx:postgres@127.0.0.1:15432/warehouse"', // pragma: allowlist secret
|
2026-05-10 23:12:26 +02:00
|
|
|
'storage:',
|
|
|
|
|
' state: sqlite',
|
|
|
|
|
' search: sqlite-fts5',
|
|
|
|
|
'',
|
|
|
|
|
].join('\n'),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('seeds comments and a foreign key for daemon catalog introspection', () => {
|
|
|
|
|
const sql = buildSeedSql();
|
|
|
|
|
|
|
|
|
|
assert.match(sql, /CREATE TABLE customers/);
|
|
|
|
|
assert.match(sql, /CREATE TABLE orders/);
|
|
|
|
|
assert.match(sql, /REFERENCES customers\(id\)/);
|
|
|
|
|
assert.match(sql, /COMMENT ON TABLE orders IS 'Orders captured by the artifact smoke'/);
|
|
|
|
|
assert.match(sql, /COMMENT ON COLUMN orders.amount IS 'Order amount in cents'/);
|
|
|
|
|
assert.match(sql, /INSERT INTO orders/);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('waits for a real SQL connection to the target Postgres database', () => {
|
2026-05-10 23:51:24 +02:00
|
|
|
assert.deepEqual(buildPostgresReadyArgs('ktx-live-db-smoke-test'), [
|
2026-05-10 23:12:26 +02:00
|
|
|
'exec',
|
2026-05-10 23:51:24 +02:00
|
|
|
'ktx-live-db-smoke-test',
|
2026-05-10 23:12:26 +02:00
|
|
|
'psql',
|
|
|
|
|
'-U',
|
2026-05-10 23:51:24 +02:00
|
|
|
'ktx',
|
2026-05-10 23:12:26 +02:00
|
|
|
'-d',
|
|
|
|
|
'warehouse',
|
|
|
|
|
'-v',
|
|
|
|
|
'ON_ERROR_STOP=1',
|
|
|
|
|
'-c',
|
|
|
|
|
'SELECT 1;',
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-14 01:43:06 +02:00
|
|
|
it('builds the installed CLI public database ingest command', () => {
|
2026-05-10 23:12:26 +02:00
|
|
|
assert.deepEqual(buildLiveDatabaseIngestArgs('/tmp/project', 'http://127.0.0.1:8765'), [
|
|
|
|
|
'exec',
|
2026-05-10 23:51:24 +02:00
|
|
|
'ktx',
|
2026-05-10 23:12:26 +02:00
|
|
|
'ingest',
|
|
|
|
|
'warehouse',
|
|
|
|
|
'--project-dir',
|
|
|
|
|
'/tmp/project',
|
2026-05-14 01:43:06 +02:00
|
|
|
'--no-input',
|
2026-05-10 23:12:26 +02:00
|
|
|
]);
|
2026-05-14 01:43:06 +02:00
|
|
|
|
2026-05-10 23:12:26 +02:00
|
|
|
});
|
|
|
|
|
});
|