Files
iios/scripts/vitest-global-setup.mjs
maaz519 c4206f9809 fix(iios): thread subject on create, graceful open_thread error, isolated test DB
- openThread/createThread accept a generic `subject` (group name) — stored on the
  thread, echoed via listThreads; kernel never interprets it.
- Gateway open_thread now returns an ACK'd { error } on failure instead of throwing
  (which never acked → clients hung on "loading"). Non-member/missing-thread opens
  fail cleanly.
- Tests run against an isolated `iios_test` database (vitest globalSetup creates +
  migrates it; test.env overrides DATABASE_URL) so `pnpm test` can never TRUNCATE the
  dev database again. Verified: full suite green, dev DB row counts unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-06 19:39:19 +05:30

21 lines
849 B
JavaScript

import { execSync } from 'node:child_process';
// Tests TRUNCATE between cases, so they MUST NOT touch the dev database. Run them
// against an isolated `iios_test` DB (created + migrated here, once, before the suite).
const TEST_URL = 'postgresql://iios:iios@localhost:5434/iios_test?schema=public';
export default function setup() {
try {
execSync(`docker exec iios-db psql -U iios -d postgres -c "CREATE DATABASE iios_test"`, { stdio: 'pipe' });
} catch (e) {
const msg = String(e.stderr ?? e.stdout ?? e);
if (!/already exists/i.test(msg)) {
console.warn(`[vitest] could not create iios_test (is the iios-db container up?): ${msg.slice(0, 160)}`);
}
}
execSync('pnpm --filter @insignia/iios-service exec prisma migrate deploy', {
stdio: 'inherit',
env: { ...process.env, DATABASE_URL: TEST_URL },
});
}