"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const simple_git_1 = require("simple-git");
const os = __importStar(require("os"));
const path = __importStar(require("path"));
const fs = __importStar(require("fs"));
describe('Project Directory Messages and User Guidance', () => {
    describe('Git commit without project directory', () => {
        it('should generate helpful message for missing project directory', () => {
            // This is the expected message when no project directory is set
            const expectedMessage = `⚠️ No project directory set for git tracking!

To track git changes in your project, please set your project directory using one of these methods:

1. When starting a new session:
   context_session_start with projectDir: "/path/to/your/project"

2. For the current session:
   context_set_project_dir with projectDir: "/path/to/your/project"

This allows the MCP server to track git changes in your actual project directory.`;
            // Verify the message format is correct
            expect(expectedMessage).toContain('⚠️ No project directory set');
            expect(expectedMessage).toContain('context_session_start with projectDir:');
            expect(expectedMessage).toContain('context_set_project_dir with projectDir:');
            expect(expectedMessage).toContain('track git changes in your actual project directory');
        });
    });
    describe('Session start messages', () => {
        it('should generate tip message when no project directory provided', () => {
            const tipMessage = 'Tip: To enable git tracking, start with projectDir parameter or use context_set_project_dir';
            expect(tipMessage).toContain('To enable git tracking');
            expect(tipMessage).toContain('projectDir parameter');
            expect(tipMessage).toContain('context_set_project_dir');
        });
        it('should include project directory info in session start message', () => {
            const projectPath = '/Users/test/my-project';
            const sessionMessage = `Session started: Test Session
ID: abc-123
Description: Testing project directory
Branch: master
Project directory: ${projectPath}
Git detected: Yes`;
            expect(sessionMessage).toContain(`Project directory: ${projectPath}`);
            expect(sessionMessage).toContain('Git detected: Yes');
        });
    });
    describe('Set project directory messages', () => {
        it('should show success message with git detection', () => {
            const projectPath = '/Users/test/my-project';
            const successMessage = `Project directory set successfully!

Path: ${projectPath}
Git repository: ✓ Detected
Current branch: main
Status: Clean (no uncommitted changes)

You can now use git-related features like context_git_commit.`;
            expect(successMessage).toContain('Project directory set successfully!');
            expect(successMessage).toContain(`Path: ${projectPath}`);
            expect(successMessage).toContain('Git repository: ✓ Detected');
            expect(successMessage).toContain('Current branch:');
            expect(successMessage).toContain('context_git_commit');
        });
        it('should show message for non-git directory', () => {
            const projectPath = '/Users/test/non-git-project';
            const nonGitMessage = `Project directory set successfully!

Path: ${projectPath}
Git repository: ✗ Not found

Tip: Initialize git with 'git init' to enable git tracking features.`;
            expect(nonGitMessage).toContain('Project directory set successfully!');
            expect(nonGitMessage).toContain('Git repository: ✗ Not found');
            expect(nonGitMessage).toContain("Initialize git with 'git init'");
        });
        it('should show error for missing session', () => {
            const errorMessage = 'No active session. Please start a session first with context_session_start.';
            expect(errorMessage).toContain('No active session');
            expect(errorMessage).toContain('context_session_start');
        });
    });
    describe('Git status messages', () => {
        let tempRepoPath;
        let git;
        beforeEach(async () => {
            tempRepoPath = path.join(os.tmpdir(), `test-git-messages-${Date.now()}`);
            fs.mkdirSync(tempRepoPath, { recursive: true });
            git = (0, simple_git_1.simpleGit)(tempRepoPath);
            await git.init();
            await git.addConfig('user.name', 'Test User');
            await git.addConfig('user.email', 'test@example.com');
        });
        afterEach(() => {
            fs.rmSync(tempRepoPath, { recursive: true, force: true });
        });
        it('should format clean repository status', async () => {
            fs.writeFileSync(path.join(tempRepoPath, 'README.md'), '# Test');
            await git.add('.');
            await git.commit('Initial commit');
            const status = await git.status();
            const statusMessage = `Status: ${status.isClean() ? 'Clean (no uncommitted changes)' : 'Has uncommitted changes'}`;
            expect(statusMessage).toBe('Status: Clean (no uncommitted changes)');
        });
        it('should format dirty repository status', async () => {
            fs.writeFileSync(path.join(tempRepoPath, 'README.md'), '# Test');
            await git.add('.');
            await git.commit('Initial commit');
            // Make changes
            fs.writeFileSync(path.join(tempRepoPath, 'new.txt'), 'new content');
            const status = await git.status();
            const statusMessage = `Status: ${status.isClean() ? 'Clean (no uncommitted changes)' : 'Has uncommitted changes'}`;
            expect(statusMessage).toBe('Status: Has uncommitted changes');
        });
    });
    describe('Checkpoint messages with git info', () => {
        it('should include git info in checkpoint creation message', () => {
            const checkpointMessage = `Created checkpoint: Feature Save
ID: checkpoint-123
Context items: 5
Cached files: 3
Git branch: feature/user-auth
Git status: captured`;
            expect(checkpointMessage).toContain('Git branch: feature/user-auth');
            expect(checkpointMessage).toContain('Git status: captured');
        });
        it('should show none for git branch when no project directory', () => {
            const checkpointMessage = `Created checkpoint: Quick Save
ID: checkpoint-456
Context items: 2
Cached files: 0
Git branch: none
Git status: not captured`;
            expect(checkpointMessage).toContain('Git branch: none');
            expect(checkpointMessage).toContain('Git status: not captured');
        });
    });
    describe('Error handling messages', () => {
        it('should handle git command failures gracefully', () => {
            const errorMessage = 'Git commit failed: No changes to commit';
            expect(errorMessage).toContain('Git commit failed:');
            expect(errorMessage).toContain('No changes to commit');
        });
        it('should handle invalid directory paths', () => {
            const invalidPathMessage = `Project directory set successfully!

Path: /invalid/path/that/does/not/exist
Git repository: ✗ Not found

Directory may not exist or may not be accessible.`;
            expect(invalidPathMessage).toContain('Git repository: ✗ Not found');
            expect(invalidPathMessage).toContain('Directory may not exist');
        });
    });
});
