diff --git a/extensions/cli/src/e2e/git-branch-display.test.ts b/extensions/cli/src/e2e/git-branch-display.test.ts index 90541d0fe..3838bbf7a 100644 --- a/extensions/cli/src/e2e/git-branch-display.test.ts +++ b/extensions/cli/src/e2e/git-branch-display.test.ts @@ -39,41 +39,45 @@ models: it("should show branch name when in a git repository", async () => { // Initialize a git repo in the test directory process.chdir(context.testDir); - + try { // Initialize git repo execSync("git init", { stdio: "ignore" }); - execSync("git config user.email 'test@example.com'", { stdio: "ignore" }); + execSync("git config user.email 'test@example.com'", { + stdio: "ignore", + }); execSync("git config user.name 'Test User'", { stdio: "ignore" }); - + // Create a test file and initial commit - await fs.writeFile(path.join(context.testDir, "test.txt"), "test content"); + await fs.writeFile( + path.join(context.testDir, "test.txt"), + "test content", + ); execSync("git add .", { stdio: "ignore" }); execSync("git commit -m 'Initial commit'", { stdio: "ignore" }); - + // Create and checkout a test branch const testBranchName = "feature/test-branch"; execSync(`git checkout -b ${testBranchName}`, { stdio: "ignore" }); - + // Create config file await createTestConfig(context, testConfig); - + // Run CLI in TUI mode - it should fail quickly but show the branch in output const result = await runCLI(context, { args: ["--config", context.configPath!, "--help"], timeout: 3000, }); - + // The help command should succeed expect(result.exitCode).toBe(0); expect(result.stdout).toContain("Continue CLI"); - + // Now let's test that our git utils work in this context // We can't easily test the full TUI display, but we can verify the git functions work const { getGitBranch } = await import("../util/git.js"); const branch = getGitBranch(); expect(branch).toBe(testBranchName); - } catch (error) { // Skip test if git is not available or fails console.warn("Skipping git branch test - git not available:", error); @@ -84,91 +88,108 @@ models: it("should handle non-git directory gracefully", async () => { // Don't initialize git in test directory process.chdir(context.testDir); - + await createTestConfig(context, testConfig); - + // Test that git functions return null in non-git directory const { getGitBranch, isGitRepo } = await import("../util/git.js"); - + expect(isGitRepo()).toBe(false); expect(getGitBranch()).toBeNull(); - + // CLI should still work without git const result = await runCLI(context, { args: ["--help"], timeout: 3000, }); - + expect(result.exitCode).toBe(0); expect(result.stdout).toContain("Continue CLI"); }); it("should handle detached HEAD state", async () => { process.chdir(context.testDir); - + try { // Initialize git repo execSync("git init", { stdio: "ignore" }); - execSync("git config user.email 'test@example.com'", { stdio: "ignore" }); + execSync("git config user.email 'test@example.com'", { + stdio: "ignore", + }); execSync("git config user.name 'Test User'", { stdio: "ignore" }); - + // Create initial commit - await fs.writeFile(path.join(context.testDir, "test.txt"), "test content"); + await fs.writeFile( + path.join(context.testDir, "test.txt"), + "test content", + ); execSync("git add .", { stdio: "ignore" }); execSync("git commit -m 'Initial commit'", { stdio: "ignore" }); - + // Create another commit - await fs.writeFile(path.join(context.testDir, "test2.txt"), "test content 2"); + await fs.writeFile( + path.join(context.testDir, "test2.txt"), + "test content 2", + ); execSync("git add .", { stdio: "ignore" }); execSync("git commit -m 'Second commit'", { stdio: "ignore" }); - + // Get first commit hash and checkout to detached HEAD - const firstCommit = execSync("git rev-list --reverse HEAD | head -1", { - encoding: "utf-8" + const firstCommit = execSync("git rev-list --reverse HEAD | head -1", { + encoding: "utf-8", }).trim(); execSync(`git checkout ${firstCommit}`, { stdio: "ignore" }); - + // Test git functions in detached HEAD state const { getGitBranch, isGitRepo } = await import("../util/git.js"); - + expect(isGitRepo()).toBe(true); // In detached HEAD state, git branch --show-current returns empty string // which our function converts to null expect(getGitBranch()).toBeNull(); - } catch (error) { // Skip test if git operations fail - console.warn("Skipping detached HEAD test - git operations failed:", error); + console.warn( + "Skipping detached HEAD test - git operations failed:", + error, + ); return; } }); it("should handle branch names with special characters", async () => { process.chdir(context.testDir); - + try { // Initialize git repo execSync("git init", { stdio: "ignore" }); - execSync("git config user.email 'test@example.com'", { stdio: "ignore" }); + execSync("git config user.email 'test@example.com'", { + stdio: "ignore", + }); execSync("git config user.name 'Test User'", { stdio: "ignore" }); - + // Create initial commit - await fs.writeFile(path.join(context.testDir, "test.txt"), "test content"); + await fs.writeFile( + path.join(context.testDir, "test.txt"), + "test content", + ); execSync("git add .", { stdio: "ignore" }); execSync("git commit -m 'Initial commit'", { stdio: "ignore" }); - + // Create branch with special characters const specialBranchName = "feature/fix-123_with-dashes.and.dots"; execSync(`git checkout -b "${specialBranchName}"`, { stdio: "ignore" }); - + // Test git functions const { getGitBranch } = await import("../util/git.js"); const branch = getGitBranch(); expect(branch).toBe(specialBranchName); - } catch (error) { // Skip test if git operations fail - console.warn("Skipping special characters test - git operations failed:", error); + console.warn( + "Skipping special characters test - git operations failed:", + error, + ); return; } }); @@ -177,45 +198,57 @@ models: describe("getRepoUrlText function with branch", () => { it("should format repo URL with branch correctly", async () => { process.chdir(context.testDir); - + try { // Initialize git repo with remote execSync("git init", { stdio: "ignore" }); - execSync("git config user.email 'test@example.com'", { stdio: "ignore" }); + execSync("git config user.email 'test@example.com'", { + stdio: "ignore", + }); execSync("git config user.name 'Test User'", { stdio: "ignore" }); - + // Add a fake remote - execSync("git remote add origin https://github.com/testuser/testrepo.git", { stdio: "ignore" }); - + execSync( + "git remote add origin https://github.com/testuser/testrepo.git", + { stdio: "ignore" }, + ); + // Create initial commit and branch - await fs.writeFile(path.join(context.testDir, "test.txt"), "test content"); + await fs.writeFile( + path.join(context.testDir, "test.txt"), + "test content", + ); execSync("git add .", { stdio: "ignore" }); execSync("git commit -m 'Initial commit'", { stdio: "ignore" }); execSync("git checkout -b test-branch", { stdio: "ignore" }); - + // Test the formatting function - const { getResponsiveRepoText } = await import("../ui/hooks/useTUIChatHooks.js"); + const { getResponsiveRepoText } = await import( + "../ui/hooks/useTUIChatHooks.js" + ); const repoText = getResponsiveRepoText(); - + // Should include both repo and branch expect(repoText).toContain("testuser/testrepo"); expect(repoText).toContain("test-branch"); expect(repoText).toContain("⊦"); // Branch separator icon - } catch (error) { // Skip test if git operations fail - console.warn("Skipping repo URL formatting test - git operations failed:", error); + console.warn( + "Skipping repo URL formatting test - git operations failed:", + error, + ); return; } }); it("should handle repo URL without branch when not in git repo", async () => { process.chdir(context.testDir); - + // Test without git repo const { getRepoUrlText } = await import("../ui/hooks/useTUIChatHooks.js"); const repoText = getRepoUrlText(); - + // Should not contain branch separator expect(repoText).not.toContain("⊦"); // Should contain the current directory path @@ -223,4 +256,4 @@ models: expect(repoText.length).toBeGreaterThan(0); }); }); -}); \ No newline at end of file +}); diff --git a/extensions/cli/src/ui/TUIChat.tsx b/extensions/cli/src/ui/TUIChat.tsx index fc534cc8e..7d7dbcfa3 100644 --- a/extensions/cli/src/ui/TUIChat.tsx +++ b/extensions/cli/src/ui/TUIChat.tsx @@ -146,7 +146,6 @@ const TUIChat: React.FC = ({ const { services, allServicesReady, isRemoteMode } = useTUIChatServices(remoteUrl); - // Use navigation context const { state: navState, diff --git a/extensions/cli/src/ui/hooks/useTUIChatHooks.test.ts b/extensions/cli/src/ui/hooks/useTUIChatHooks.test.ts index eaed0fc21..c618a5834 100644 --- a/extensions/cli/src/ui/hooks/useTUIChatHooks.test.ts +++ b/extensions/cli/src/ui/hooks/useTUIChatHooks.test.ts @@ -14,13 +14,15 @@ describe("Responsive repo text functionality", () => { // Reset mocks before each test const gitModule = await import("../../util/git.js"); vi.mocked(gitModule.isGitRepo).mockReturnValue(true); - vi.mocked(gitModule.getGitRemoteUrl).mockReturnValue("https://github.com/testuser/testrepo.git"); + vi.mocked(gitModule.getGitRemoteUrl).mockReturnValue( + "https://github.com/testuser/testrepo.git", + ); vi.mocked(gitModule.getGitBranch).mockReturnValue("feature/test-branch"); }); describe("getRepoInfo", () => { it("should extract repo info correctly", () => { const info = getRepoInfo(); - + expect(info.repoName).toBe("testuser/testrepo"); expect(info.branchName).toBe("feature/test-branch"); expect(info.isGitRepo).toBe(true); @@ -28,7 +30,7 @@ describe("Responsive repo text functionality", () => { it("should handle remote URL override", () => { const info = getRepoInfo("https://github.com/override/repo.git"); - + expect(info.repoName).toBe("override/repo"); expect(info.branchName).toBe("feature/test-branch"); expect(info.isGitRepo).toBe(true); @@ -48,7 +50,7 @@ describe("Responsive repo text functionality", () => { it("should prefer branch when both fit individually", () => { // Full text: "testuser/testrepo ⊦ feature/test-branch" (38 chars) - // Repo only: "testuser/testrepo" (17 chars) + // Repo only: "testuser/testrepo" (17 chars) // Branch only: "feature/test-branch" (18 chars) // With width 20, both repo and branch fit, but we prefer branch const result = getResponsiveRepoText(undefined, 20); @@ -58,8 +60,10 @@ describe("Responsive repo text functionality", () => { it("should fallback to repo when branch doesn't fit but repo does", async () => { // Use a long branch name const gitModule = await import("../../util/git.js"); - vi.mocked(gitModule.getGitBranch).mockReturnValue("very-long-feature-branch-name-that-wont-fit"); - + vi.mocked(gitModule.getGitBranch).mockReturnValue( + "very-long-feature-branch-name-that-wont-fit", + ); + const result = getResponsiveRepoText(undefined, 20); // Branch is too long, repo should fit expect(result).toBe("testuser/testrepo"); @@ -68,9 +72,11 @@ describe("Responsive repo text functionality", () => { it("should return branch only when repo doesn't fit but branch does", async () => { // When space is very limited, prefer shorter option const gitModule = await import("../../util/git.js"); - vi.mocked(gitModule.getGitRemoteUrl).mockReturnValue("https://github.com/very-long-repo-name/testrepo.git"); + vi.mocked(gitModule.getGitRemoteUrl).mockReturnValue( + "https://github.com/very-long-repo-name/testrepo.git", + ); vi.mocked(gitModule.getGitBranch).mockReturnValue("main"); - + const result = getResponsiveRepoText(undefined, 10); // "main" (4 chars) should fit, "very-long-repo-name/testrepo" won't expect(result).toBe("main"); @@ -90,17 +96,23 @@ describe("Responsive repo text functionality", () => { const gitModule = await import("../../util/git.js"); vi.mocked(gitModule.isGitRepo).mockReturnValue(false); vi.mocked(gitModule.getGitBranch).mockReturnValue(null); - - const result = getResponsiveRepoText("https://github.com/user/repo.git", 50); + + const result = getResponsiveRepoText( + "https://github.com/user/repo.git", + 50, + ); expect(result).toBe("user/repo"); }); it("should return empty string when repo name is too long in non-git scenario", async () => { const gitModule = await import("../../util/git.js"); vi.mocked(gitModule.isGitRepo).mockReturnValue(false); - - const result = getResponsiveRepoText("https://github.com/very-long-user/repo.git", 8); + + const result = getResponsiveRepoText( + "https://github.com/very-long-user/repo.git", + 8, + ); expect(result).toBe(""); }); }); -}); \ No newline at end of file +}); diff --git a/extensions/cli/src/util/git.test.ts b/extensions/cli/src/util/git.test.ts index 03dccdb71..4ed520801 100644 --- a/extensions/cli/src/util/git.test.ts +++ b/extensions/cli/src/util/git.test.ts @@ -1,6 +1,10 @@ import { beforeEach, describe, expect, it } from "vitest"; -import { getGitBranch, getGitHubActionsRepoUrl, isGitHubActions } from "./git.js"; +import { + getGitBranch, + getGitHubActionsRepoUrl, + isGitHubActions, +} from "./git.js"; describe("git utilities - GitHub Actions detection", () => { beforeEach(() => {