import { afterEach, beforeEach, describe, expect, it } from 'bun:test'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { E2E_CONFLICT_FIX, E2E_CONFLICT_MESSAGE, runningE2eContainers } from './e2e-guard'; describe('e2e-guard', () => { let prev: string | undefined; beforeEach(() => { prev = process.env.CELILO_DB_PATH; }); afterEach(() => { process.env.CELILO_DB_PATH = prev; }); it('skips the docker check when running against a temp test DB', () => { // Integration tests point CELILO_DB_PATH at os.tmpdir() and must not trip // over a developer's unrelated e2e stack. process.env.CELILO_DB_PATH = join(tmpdir(), 'celilo-test.db'); expect(runningE2eContainers()).toEqual([]); }); it('returns an array and never throws when docker is checked', () => { // A non-temp path defeats the short-circuit, exercising the real docker // path. Result depends on the host's docker state; the contract is "an // array of celilo-e2e-* names, never an exception". process.env.CELILO_DB_PATH = '/opt/celilo/celilo.db'; const result = runningE2eContainers(); expect(Array.isArray(result)).toBe(true); for (const name of result) { expect(name.startsWith('celilo-e2e-')).toBe(true); } }); it('exposes a deploy message that includes the remediation hint', () => { expect(E2E_CONFLICT_MESSAGE).toContain(E2E_CONFLICT_FIX); expect(E2E_CONFLICT_MESSAGE).toContain('mutually exclusive'); }); });