fix: linting and address feedback

This commit is contained in:
Nate 2025-08-27 21:42:39 -07:00
parent 626a3c66a0
commit 4d3b2f19ed
8 changed files with 32 additions and 17 deletions

View file

@ -7,7 +7,7 @@ import { compactChatHistory } from "./compaction.js";
import { streamChatResponse } from "./stream/streamChatResponse.js";
// Mock the dependencies
vi.mock("./streamChatResponse.js", () => ({
vi.mock("./stream/streamChatResponse.js", () => ({
streamChatResponse: vi.fn(),
}));

View file

@ -12,7 +12,7 @@ import {
import { streamChatResponse } from "./stream/streamChatResponse.js";
// Mock the streamChatResponse function
vi.mock("./streamChatResponse.js", () => ({
vi.mock("./stream/streamChatResponse.js", () => ({
streamChatResponse: vi.fn(),
}));

View file

@ -0,0 +1,4 @@
/**
* Session-related constants
*/
export const DEFAULT_SESSION_TITLE = "Untitled Session";

View file

@ -6,11 +6,12 @@ import type { ChatHistoryItem, Session, SessionMetadata } from "core/index.js";
import historyManager from "core/util/history.js";
import { v4 as uuidv4 } from "uuid";
import { DEFAULT_SESSION_TITLE } from "./constants/session.js";
import { logger } from "./util/logger.js";
// Re-export SessionMetadata for external consumers
export type { SessionMetadata };
import { logger } from "./util/logger.js";
// Note: We now use UUID-based session IDs instead of terminal-based IDs.
// Each new chat session gets a unique UUID.
// The --resume flag loads the most recent session.
@ -69,7 +70,7 @@ class SessionManager {
if (!this.currentSession) {
this.currentSession = {
sessionId: uuidv4(),
title: "Untitled Session",
title: DEFAULT_SESSION_TITLE,
workspaceDirectory: process.cwd(),
history: [],
};
@ -187,7 +188,7 @@ export function loadSession(): Session | null {
export function createSession(history: ChatHistoryItem[] = []): Session {
const session: Session = {
sessionId: uuidv4(),
title: "Untitled Session",
title: DEFAULT_SESSION_TITLE,
workspaceDirectory: process.cwd(),
history,
};
@ -265,7 +266,7 @@ function getSessionMetadataWithPreview(
return {
sessionId: sessionData.sessionId,
title: sessionData.title || "Untitled Session",
title: sessionData.title || DEFAULT_SESSION_TITLE,
dateCreated: stats.birthtime.toISOString(),
workspaceDirectory: sessionData.workspaceDirectory || "",
firstUserMessage,
@ -360,7 +361,7 @@ export function startNewSession(history: ChatHistoryItem[] = []): Session {
// Create a new session with a new sessionId
const newSession: Session = {
sessionId: uuidv4(),
title: "Untitled Session",
title: DEFAULT_SESSION_TITLE,
workspaceDirectory: process.cwd(),
history,
};

View file

@ -5,11 +5,11 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
import { handleAutoCompaction } from "./streamChatResponse.autoCompaction.js";
// Mock dependencies
vi.mock("./compaction.js", () => ({
vi.mock("../compaction.js", () => ({
compactChatHistory: vi.fn(),
}));
vi.mock("./session.js", () => ({
vi.mock("../session.js", () => ({
createSession: vi.fn((history) => ({
sessionId: "test",
title: "Test",
@ -20,16 +20,16 @@ vi.mock("./session.js", () => ({
updateSessionHistory: vi.fn(),
}));
vi.mock("./util/tokenizer.js", () => ({
vi.mock("../util/tokenizer.js", () => ({
shouldAutoCompact: vi.fn(),
getAutoCompactMessage: vi.fn(),
}));
vi.mock("./util/formatError.js", () => ({
vi.mock("../util/formatError.js", () => ({
formatError: vi.fn((error) => error.message || String(error)),
}));
vi.mock("./util/logger.js", () => ({
vi.mock("../util/logger.js", () => ({
logger: {
info: vi.fn(),
debug: vi.fn(),
@ -70,7 +70,8 @@ describe("handleAutoCompaction", () => {
it("should return original history when auto-compaction is not needed", async () => {
const { shouldAutoCompact } = await import("../util/tokenizer.js");
vi.mocked(shouldAutoCompact).mockReturnValue(false);
const mockedShouldAutoCompact = shouldAutoCompact as any;
mockedShouldAutoCompact.mockReturnValue(false);
const result = await handleAutoCompaction(
mockChatHistory,
@ -113,7 +114,8 @@ describe("handleAutoCompaction", () => {
compactionContent: "Conversation summary...",
};
vi.mocked(compactChatHistory).mockResolvedValue(mockCompactionResult);
const mockedCompactChatHistory = compactChatHistory as any;
mockedCompactChatHistory.mockResolvedValue(mockCompactionResult);
const mockCallbacks = {
onSystemMessage: vi.fn(),
@ -215,7 +217,8 @@ describe("handleAutoCompaction", () => {
compactionContent: "Summary",
};
vi.mocked(compactChatHistory).mockResolvedValue(mockCompactionResult);
const mockedCompactChatHistory = compactChatHistory as any;
mockedCompactChatHistory.mockResolvedValue(mockCompactionResult);
const mockCallbacks = {
onSystemMessage: vi.fn(),

View file

@ -19,6 +19,9 @@ describe("useChat clear command", () => {
let mockOnClear: ReturnType<typeof vi.fn>;
beforeEach(() => {
// Clear all mocks to prevent call history leaking between tests
vi.clearAllMocks();
mockSetChatHistory = vi.fn();
mockExit = vi.fn();
mockOnClear = vi.fn();

View file

@ -5,6 +5,7 @@ import { getLastNPathParts } from "core/util/uri.js";
import { v4 as uuidv4 } from "uuid";
import { compactChatHistory } from "../../compaction.js";
import { DEFAULT_SESSION_TITLE } from "../../constants/session.js";
import {
loadSession,
updateSessionHistory,
@ -422,7 +423,7 @@ export async function generateSessionTitle(
currentSessionTitle?: string,
): Promise<string | undefined> {
// Only generate title for untitled sessions
if (currentSessionTitle && currentSessionTitle !== "Untitled Session") {
if (currentSessionTitle && currentSessionTitle !== DEFAULT_SESSION_TITLE) {
return undefined;
}

View file

@ -19,6 +19,9 @@ vi.mock("./src/systemMessage.js", () => ({
),
}));
// Mock environment for tests
process.env.CONTINUE_GLOBAL_DIR = "/tmp/continue-test";
// Set up global afterEach hook to clear all timers and reset console
afterEach(() => {
// Clear vitest timers