// [DEF:frontend.src.components.git.__tests__.git_manager_unfinished_merge_integration:Module]
// @TIER: STANDARD
// @SEMANTICS: git-manager, unfinished-merge, dialog, integration-test
// @PURPOSE: Protect unresolved-merge dialog contract in GitManager pull flow.
// @LAYER: UI Tests
// @RELATION: VERIFIES -> frontend/src/components/git/GitManager.svelte

import { describe, it, expect } from 'vitest';
import fs from 'node:fs';
import path from 'node:path';

const COMPONENT_PATH = path.resolve(
  process.cwd(),
  'src/components/git/GitManager.svelte',
);

describe('GitManager unfinished merge dialog contract', () => {
  it('keeps 409 unfinished-merge detection and WebUI dialog recovery flow in pull handler', () => {
    const source = fs.readFileSync(COMPONENT_PATH, 'utf-8');

    expect(source).toContain('Number(error?.status) !== 409');
    expect(source).toContain("payload.error_code !== 'GIT_UNFINISHED_MERGE'");
    expect(source).toContain('function openUnfinishedMergeDialogFromError(error)');
    expect(source).toContain('showUnfinishedMergeDialog = true;');
    expect(source).toContain('const handledByDialog = openUnfinishedMergeDialogFromError(e);');
    expect(source).toContain('await loadMergeRecoveryState();');
  });

  it('renders unresolved-merge dialog details and web recovery actions', () => {
    const source = fs.readFileSync(COMPONENT_PATH, 'utf-8');

    expect(source).toContain('{#if showUnfinishedMergeDialog && unfinishedMergeContext}');
    expect(source).toContain('unfinishedMergeContext.repositoryPath');
    expect(source).toContain('unfinishedMergeContext.currentBranch');
    expect(source).toContain('unfinishedMergeContext.commands.join');
    expect(source).toContain('handleCopyUnfinishedMergeCommands');
    expect(source).toContain('handleOpenConflictResolver');
    expect(source).toContain('handleAbortUnfinishedMerge');
    expect(source).toContain('handleContinueUnfinishedMerge');
    expect(source).toContain('$t.git?.unfinished_merge?.copy_commands');
  });
});
// [/DEF:frontend.src.components.git.__tests__.git_manager_unfinished_merge_integration:Module]