Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion extensions/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 99 additions & 3 deletions extensions/cli/src/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ describe("SessionManager", () => {
const firstSession = createSession();
const firstSessionId = firstSession.sessionId;

vi.mocked(uuidv4).mockReturnValue("new-uuid-456" as any);
vi.mocked(uuidv4).mockReturnValue("new-uuid-456");

const secondSession = startNewSession();

Expand All @@ -381,7 +381,7 @@ describe("SessionManager", () => {
},
];

vi.mocked(uuidv4).mockReturnValue("new-uuid-789" as any);
vi.mocked(uuidv4).mockReturnValue("new-uuid-789");

const session = startNewSession(history);

Expand All @@ -392,7 +392,7 @@ describe("SessionManager", () => {
it("should set the new session as current", () => {
const originalSession = createSession();

vi.mocked(uuidv4).mockReturnValue("new-session-id" as any);
vi.mocked(uuidv4).mockReturnValue("new-session-id");

const newSession = startNewSession();
const currentSession = getCurrentSession();
Expand All @@ -401,4 +401,100 @@ describe("SessionManager", () => {
expect(currentSession).not.toBe(originalSession);
});
});

describe("session isolation", () => {
it("should not pollute new sessions with previous session history", () => {
// Simulate first CLI session
vi.mocked(uuidv4).mockReturnValue("session-1");
const session1 = createSession();
const history1: ChatHistoryItem[] = [
{
message: {
role: "user",
content: "Tell me about dogs",
},
contextItems: [],
},
{
message: {
role: "assistant",
content: "Dogs are loyal companions...",
},
contextItems: [],
},
];
updateSessionHistory(history1);

// Simulate starting a new CLI session (without --resume)
vi.mocked(uuidv4).mockReturnValue("session-2");
const session2 = startNewSession([]);

// New session should have clean state
expect(session2.sessionId).toBe("session-2");
expect(session2.sessionId).not.toBe(session1.sessionId);
expect(session2.history).toEqual([]);
expect(session2.history.length).toBe(0);
});

it("should create independent sessions for concurrent operations", () => {
// Create first session with some data
vi.mocked(uuidv4).mockReturnValue("concurrent-1");
const session1 = createSession();
updateSessionTitle("Session 1");
updateSessionHistory([
{
message: {
role: "user",
content: "First session message",
},
contextItems: [],
},
]);

// Start a new session
vi.mocked(uuidv4).mockReturnValue("concurrent-2");
const session2 = startNewSession([]);

// Verify session2 is clean
expect(session2.title).toBe("Untitled Session");
expect(session2.history).toEqual([]);
expect(session2.sessionId).not.toBe(session1.sessionId);
});

it("should properly clear session state when transitioning between sessions", () => {
// First session with complex history
vi.mocked(uuidv4).mockReturnValue("complex-session-1");
const session1 = createSession();
updateSessionTitle("Complex Session");
const complexHistory: ChatHistoryItem[] = [
{
message: {
role: "user",
content: "What were we discussing?",
},
contextItems: [],
},
{
message: {
role: "assistant",
content: "We were discussing dogs earlier.",
},
contextItems: [],
},
];
updateSessionHistory(complexHistory);

// Verify first session has data
expect(getCurrentSession().history.length).toBe(2);

// Start fresh session
vi.mocked(uuidv4).mockReturnValue("fresh-session-2");
const session2 = startNewSession([]);

// Verify clean state
expect(session2.history.length).toBe(0);
expect(session2.title).toBe("Untitled Session");
expect(getCurrentSession().sessionId).toBe("fresh-session-2");
});
});
});
Loading