import { describe, expect, it } from 'bun:test'; import { resolve } from 'node:path'; import { isCommandersDir } from './claude-sessions'; import { getCommandersDir } from '../../data-path'; const EMAIL = 'pastilhas@officer.dev'; // The live payload's `isCommander` is derived from a cwd read out of a transcript, so it is whatever the // process was actually in — not a path this code composed. These are the shapes that arrive. describe('isCommandersDir', () => { const dir = getCommandersDir(EMAIL); it('recognises the commanders directory', () => { expect(isCommandersDir(EMAIL, dir)).toBe(true); }); it('survives a trailing slash and a .. hop', () => { expect(isCommandersDir(EMAIL, `${dir}/`)).toBe(true); expect(isCommandersDir(EMAIL, `${dir}/sub/..`)).toBe(true); }); it('rejects a sibling and a child', () => { expect(isCommandersDir(EMAIL, resolve(dir, '..'))).toBe(false); expect(isCommandersDir(EMAIL, resolve(dir, 'nested'))).toBe(false); }); // A commander's cwd belongs to the account that owns it. Reading one user's directory as another's // would file their commanders under the wrong person and, in the iPhone swipe order, show them. it('is per account', () => { expect(isCommandersDir('someone-else@officer.dev', dir)).toBe(false); }); it('never throws on rubbish', () => { expect(isCommandersDir(EMAIL, '')).toBe(false); expect(isCommandersDir(EMAIL, '\0')).toBe(false); }); });