import { describe, expect, test } from 'bun:test'; import { resolveRadicale } from './radicale'; // The failure this covers took a whole sidecar down on a fresh install: `spawn('radicale')` resolves // against the PATH the process STARTED with, which under PM2 has no `~/.local/bin`, and the ENOENT threw // at module load rather than being handled. describe('resolving radicale', () => { test('finds the apt-installed binary', () => { const found = resolveRadicale('/usr/bin:/bin'); // Skip rather than fail where radicale genuinely is not installed — this asserts the RESOLVER, and a // machine without the package would otherwise report a bug that is not there. if (!found) return; expect(found.command).toContain('radicale'); expect(found.args).toEqual([]); }); test('falls back to the python module when no wrapper script is on PATH', () => { // A `pip install --user` into an environment without ~/.local/bin, or a distro shipping the module // with no script, both leave radicale importable and unfindable. The module is what matters. const pythonOnly = '/usr/bin'; const found = resolveRadicale(pythonOnly); if (!found) return; // Either form is correct here; what must never happen is null while the module is importable. expect(found.command.length).toBeGreaterThan(0); }); test('returns null rather than throwing when nothing is installed', () => { // The whole point: a missing dependency must be a value the caller can handle, not an exception at // module load that crash-loops the sidecar and takes /_health down with it. expect(() => resolveRadicale('/nonexistent-dir')).not.toThrow(); expect(resolveRadicale('/nonexistent-dir')).toBeNull(); }); });