"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const watch_cli_1 = require("../walls/07-runtime/watcher/watch-cli");
describe('watch-cli parser (cell watch events --limit/--type)', () => {
    describe('parseWatchFlags', () => {
        it('returns all positional args when no flags present', () => {
            const r = (0, watch_cli_1.parseWatchFlags)(['fivo-cell', '/path/to/dir']);
            expect(r.positional).toEqual(['fivo-cell', '/path/to/dir']);
        });
        it('strips --limit N flag from positional list', () => {
            const r = (0, watch_cli_1.parseWatchFlags)(['fivo-cell', '--limit', '10']);
            expect(r.positional).toEqual(['fivo-cell']);
        });
        it('strips --limit=N form', () => {
            const r = (0, watch_cli_1.parseWatchFlags)(['fivo-cell', '--limit=10']);
            expect(r.positional).toEqual(['fivo-cell']);
        });
        it('strips --type file_save flag', () => {
            const r = (0, watch_cli_1.parseWatchFlags)(['fivo-cell', '--type', 'file_save']);
            expect(r.positional).toEqual(['fivo-cell']);
        });
        it('strips --type=file_save form', () => {
            const r = (0, watch_cli_1.parseWatchFlags)(['fivo-cell', '--type=file_save']);
            expect(r.positional).toEqual(['fivo-cell']);
        });
        it('handles flags before and after positional args (regression for v4.1.8 bug where --limit became project name)', () => {
            const r = (0, watch_cli_1.parseWatchFlags)(['--limit', '3', 'fivo-cell', '--type', 'file_save']);
            expect(r.positional).toEqual(['fivo-cell']);
        });
        it('ignores unknown --flags without breaking (treats them as no-arg switches)', () => {
            const r = (0, watch_cli_1.parseWatchFlags)(['fivo-cell', '--unknown', 'value', '/dir']);
            expect(r.positional).toEqual(['fivo-cell', 'value', '/dir']);
        });
        it('returns empty list when only flags provided', () => {
            const r = (0, watch_cli_1.parseWatchFlags)(['--limit', '5', '--type', 'file_save']);
            expect(r.positional).toEqual([]);
        });
        it('handles --limit at end of args (no value)', () => {
            const r = (0, watch_cli_1.parseWatchFlags)(['fivo-cell', '--limit']);
            expect(r.positional).toEqual(['fivo-cell']);
        });
    });
    describe('parseWatchLimit', () => {
        it('returns default when no flag present', () => {
            expect((0, watch_cli_1.parseWatchLimit)(['fivo-cell'])).toBe(watch_cli_1.DEFAULT_EVENT_LIMIT);
            expect((0, watch_cli_1.parseWatchLimit)([])).toBe(watch_cli_1.DEFAULT_EVENT_LIMIT);
        });
        it('parses --limit N form', () => {
            expect((0, watch_cli_1.parseWatchLimit)(['fivo-cell', '--limit', '50'])).toBe(50);
        });
        it('parses --limit=N form', () => {
            expect((0, watch_cli_1.parseWatchLimit)(['fivo-cell', '--limit=42'])).toBe(42);
        });
        it('clamps absurdly large values to MAX_EVENT_LIMIT', () => {
            expect((0, watch_cli_1.parseWatchLimit)(['--limit', '99999'])).toBe(watch_cli_1.MAX_EVENT_LIMIT);
        });
        it('falls back to default for non-numeric input', () => {
            expect((0, watch_cli_1.parseWatchLimit)(['--limit', 'abc'])).toBe(watch_cli_1.DEFAULT_EVENT_LIMIT);
        });
        it('falls back to default for zero or negative', () => {
            expect((0, watch_cli_1.parseWatchLimit)(['--limit', '0'])).toBe(watch_cli_1.DEFAULT_EVENT_LIMIT);
            expect((0, watch_cli_1.parseWatchLimit)(['--limit', '-5'])).toBe(watch_cli_1.DEFAULT_EVENT_LIMIT);
        });
        it('uses custom fallback when provided', () => {
            expect((0, watch_cli_1.parseWatchLimit)([], 100)).toBe(100);
        });
    });
    describe('parseWatchEventType', () => {
        it('returns undefined when no flag present', () => {
            expect((0, watch_cli_1.parseWatchEventType)(['fivo-cell'])).toBeUndefined();
            expect((0, watch_cli_1.parseWatchEventType)([])).toBeUndefined();
        });
        it('parses --type T form', () => {
            expect((0, watch_cli_1.parseWatchEventType)(['--type', 'file_save'])).toBe('file_save');
        });
        it('parses --type=T form', () => {
            expect((0, watch_cli_1.parseWatchEventType)(['--type=file_delete'])).toBe('file_delete');
        });
        it('works with positional args before/after', () => {
            expect((0, watch_cli_1.parseWatchEventType)(['fivo-cell', '--type', 'git_commit'])).toBe('git_commit');
            expect((0, watch_cli_1.parseWatchEventType)(['--type', 'file_rename', 'fivo-cell'])).toBe('file_rename');
        });
    });
    describe('isValidEventType', () => {
        it('accepts all known event types', () => {
            for (const t of ['file_save', 'file_create', 'file_delete', 'file_rename', 'git_commit', 'package_change']) {
                expect((0, watch_cli_1.isValidEventType)(t)).toBe(true);
            }
        });
        it('rejects unknown types', () => {
            expect((0, watch_cli_1.isValidEventType)('foo')).toBe(false);
            expect((0, watch_cli_1.isValidEventType)('FILE_SAVE')).toBe(false);
            expect((0, watch_cli_1.isValidEventType)(undefined)).toBe(false);
            expect((0, watch_cli_1.isValidEventType)('')).toBe(false);
        });
    });
});
//# sourceMappingURL=watch-cli.test.js.map