fix(KB-058): resolve API naming conflict and TypeScript errors
This commit is contained in:
@@ -437,7 +437,7 @@ export function createTerminalSession(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Kill a PTY terminal session */
|
/** Kill a PTY terminal session */
|
||||||
export function killTerminalSession(sessionId: string): Promise<{ killed: boolean }> {
|
export function killPtyTerminalSession(sessionId: string): Promise<{ killed: boolean }> {
|
||||||
return api<{ killed: boolean }>(`/terminal/sessions/${encodeURIComponent(sessionId)}`, {
|
return api<{ killed: boolean }>(`/terminal/sessions/${encodeURIComponent(sessionId)}`, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useState, useEffect, useRef, useCallback } from "react";
|
import { useState, useEffect, useRef, useCallback } from "react";
|
||||||
import { X, Trash2, Terminal as TerminalIcon, RefreshCw } from "lucide-react";
|
import { X, Trash2, Terminal as TerminalIcon, RefreshCw } from "lucide-react";
|
||||||
import { useTerminal } from "../hooks/useTerminal";
|
import { useTerminal } from "../hooks/useTerminal";
|
||||||
import { createTerminalSession, killTerminalSession } from "../api";
|
import { createTerminalSession, killPtyTerminalSession } from "../api";
|
||||||
import type { Terminal as XTerm, ITerminalAddon } from "@xterm/xterm";
|
import type { Terminal as XTerm, ITerminalAddon } from "@xterm/xterm";
|
||||||
|
|
||||||
import "@xterm/xterm/css/xterm.css";
|
import "@xterm/xterm/css/xterm.css";
|
||||||
@@ -184,7 +184,7 @@ export function TerminalModal({ isOpen, onClose, initialCommand }: TerminalModal
|
|||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
// Cleanup session on close
|
// Cleanup session on close
|
||||||
if (sessionId) {
|
if (sessionId) {
|
||||||
killTerminalSession(sessionId).catch(() => {
|
killPtyTerminalSession(sessionId).catch(() => {
|
||||||
// Ignore errors during cleanup
|
// Ignore errors during cleanup
|
||||||
});
|
});
|
||||||
setSessionId(null);
|
setSessionId(null);
|
||||||
@@ -308,7 +308,7 @@ export function TerminalModal({ isOpen, onClose, initialCommand }: TerminalModal
|
|||||||
const handleRestart = useCallback(async () => {
|
const handleRestart = useCallback(async () => {
|
||||||
// Kill current session
|
// Kill current session
|
||||||
if (sessionId) {
|
if (sessionId) {
|
||||||
await killTerminalSession(sessionId).catch(() => {
|
await killPtyTerminalSession(sessionId).catch(() => {
|
||||||
// Ignore errors
|
// Ignore errors
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ vi.mock("../../hooks/useTerminal", () => ({
|
|||||||
|
|
||||||
vi.mock("../../api", () => ({
|
vi.mock("../../api", () => ({
|
||||||
createTerminalSession: vi.fn(),
|
createTerminalSession: vi.fn(),
|
||||||
killTerminalSession: vi.fn(),
|
killPtyTerminalSession: vi.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const mockUseTerminal = vi.mocked(useTerminalModule.useTerminal);
|
const mockUseTerminal = vi.mocked(useTerminalModule.useTerminal);
|
||||||
const mockCreateTerminalSession = vi.mocked(apiModule.createTerminalSession);
|
const mockCreateTerminalSession = vi.mocked(apiModule.createTerminalSession);
|
||||||
const mockKillTerminalSession = vi.mocked(apiModule.killTerminalSession);
|
const mockKillPtyTerminalSession = vi.mocked(apiModule.killPtyTerminalSession);
|
||||||
|
|
||||||
describe("TerminalModal", () => {
|
describe("TerminalModal", () => {
|
||||||
const mockOnClose = vi.fn();
|
const mockOnClose = vi.fn();
|
||||||
@@ -43,7 +43,7 @@ describe("TerminalModal", () => {
|
|||||||
shell: "/bin/bash",
|
shell: "/bin/bash",
|
||||||
cwd: "/project",
|
cwd: "/project",
|
||||||
});
|
});
|
||||||
mockKillTerminalSession.mockResolvedValue({ killed: true });
|
mockKillPtyTerminalSession.mockResolvedValue({ killed: true });
|
||||||
mockUseTerminal.mockReturnValue(createMockTerminalState());
|
mockUseTerminal.mockReturnValue(createMockTerminalState());
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -130,7 +130,7 @@ describe("TerminalModal", () => {
|
|||||||
rerender(<TerminalModal isOpen={false} onClose={mockOnClose} />);
|
rerender(<TerminalModal isOpen={false} onClose={mockOnClose} />);
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(mockKillTerminalSession).toHaveBeenCalledWith("test-session-123");
|
expect(mockKillPtyTerminalSession).toHaveBeenCalledWith("test-session-123");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||||
import { TerminalService } from "./terminal-service";
|
import { TerminalService } from "./terminal-service.js";
|
||||||
|
|
||||||
// Mock node-pty
|
// Mock node-pty
|
||||||
const mockPtyProcess = {
|
const mockPtyProcess = {
|
||||||
@@ -153,8 +153,8 @@ describe("TerminalService", () => {
|
|||||||
const sessions = service.getAllSessions();
|
const sessions = service.getAllSessions();
|
||||||
|
|
||||||
expect(sessions).toHaveLength(2);
|
expect(sessions).toHaveLength(2);
|
||||||
expect(sessions.some((s) => s.id === session1?.id)).toBe(true);
|
expect(sessions.some((s: { id: string }) => s.id === session1?.id)).toBe(true);
|
||||||
expect(sessions.some((s) => s.id === session2?.id)).toBe(true);
|
expect(sessions.some((s: { id: string }) => s.id === session2?.id)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("cleans up all sessions", async () => {
|
it("cleans up all sessions", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user