/**
 * @license
 * Copyright 2025 HopCode Team
 * SPDX-License-Identifier: Apache-2.0
 */
import { describe, it, expect, vi } from 'vitest';
import { branchCommand } from './branchCommand.js';
function makeCtx(overrides = {}) {
    const sessionService = {
        sessionExists: vi.fn().mockResolvedValue(overrides.sessionExists ?? true),
    };
    const config = overrides.noConfig
        ? null
        : {
            getSessionId: () => '11111111-1111-1111-1111-111111111111',
            getSessionService: () => sessionService,
        };
    return {
        services: { config, settings: {}, git: undefined, logger: null },
        ui: {
            isIdleRef: { current: overrides.isIdle ?? true },
        },
        session: { stats: {}, sessionShellAllowlist: new Set() },
    };
}
describe('branchCommand', () => {
    it('rejects when config is unavailable', async () => {
        const result = await branchCommand.action(makeCtx({ noConfig: true }), '');
        expect(result).toMatchObject({ type: 'message', messageType: 'error' });
    });
    it('rejects when no conversation exists to branch from', async () => {
        const result = await branchCommand.action(makeCtx({ sessionExists: false }), '');
        expect(result).toMatchObject({ type: 'message', messageType: 'error' });
        expect(result.content).toMatch(/No conversation to branch/);
    });
    it('rejects while streaming or awaiting a tool confirmation', async () => {
        const result = await branchCommand.action(makeCtx({ isIdle: false }), '');
        expect(result).toMatchObject({ type: 'message', messageType: 'error' });
        expect(result.content).toMatch(/in progress/);
    });
    it('returns dialog action with no name when args are empty', async () => {
        const result = await branchCommand.action(makeCtx(), '   ');
        expect(result).toEqual({ type: 'dialog', dialog: 'branch' });
    });
    it('returns dialog action with trimmed name when args are provided', async () => {
        const result = await branchCommand.action(makeCtx(), '  my-branch  ');
        expect(result).toEqual({
            type: 'dialog',
            dialog: 'branch',
            name: 'my-branch',
        });
    });
    it('exposes /fork as an alias', () => {
        expect(branchCommand.altNames).toContain('fork');
    });
});
//# sourceMappingURL=branchCommand.test.js.map