Updated tests to be different for bash and powershell

This commit is contained in:
Dev Randalpura
2026-03-03 14:05:37 -05:00
parent 2bea3074b3
commit aa94f3b404
@@ -5,11 +5,23 @@
*/ */
import { renderWithProviders } from '../../test-utils/render.js'; import { renderWithProviders } from '../../test-utils/render.js';
import { describe, it, expect, vi } from 'vitest'; import { describe, it, expect, vi, beforeEach } from 'vitest';
import { SessionSummaryDisplay } from './SessionSummaryDisplay.js'; import { SessionSummaryDisplay } from './SessionSummaryDisplay.js';
import * as SessionContext from '../contexts/SessionContext.js'; import * as SessionContext from '../contexts/SessionContext.js';
import type { SessionMetrics } from '../contexts/SessionContext.js'; import type { SessionMetrics } from '../contexts/SessionContext.js';
import { ToolCallDecision } from '@google/gemini-cli-core'; import {
ToolCallDecision,
getShellConfiguration,
} from '@google/gemini-cli-core';
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
const actual =
await importOriginal<typeof import('@google/gemini-cli-core')>();
return {
...actual,
getShellConfiguration: vi.fn(),
};
});
vi.mock('../contexts/SessionContext.js', async (importOriginal) => { vi.mock('../contexts/SessionContext.js', async (importOriginal) => {
const actual = await importOriginal<typeof SessionContext>(); const actual = await importOriginal<typeof SessionContext>();
@@ -19,6 +31,7 @@ vi.mock('../contexts/SessionContext.js', async (importOriginal) => {
}; };
}); });
const getShellConfigurationMock = vi.mocked(getShellConfiguration);
const useSessionStatsMock = vi.mocked(SessionContext.useSessionStats); const useSessionStatsMock = vi.mocked(SessionContext.useSessionStats);
const renderWithMockedStats = async ( const renderWithMockedStats = async (
@@ -70,6 +83,14 @@ describe('<SessionSummaryDisplay />', () => {
}, },
}; };
beforeEach(() => {
getShellConfigurationMock.mockReturnValue({
executable: 'bash',
argsPrefix: ['-c'],
shell: 'bash',
});
});
it('renders the summary display with a title', async () => { it('renders the summary display with a title', async () => {
const metrics: SessionMetrics = { const metrics: SessionMetrics = {
...emptyMetrics, ...emptyMetrics,
@@ -102,7 +123,8 @@ describe('<SessionSummaryDisplay />', () => {
unmount(); unmount();
}); });
it('renders a standard UUID-formatted session ID in the footer', async () => { describe('Session ID escaping', () => {
it('renders a standard UUID-formatted session ID in the footer (bash)', async () => {
const uuidSessionId = '1234-abcd-5678-efgh'; const uuidSessionId = '1234-abcd-5678-efgh';
const { lastFrame, unmount } = await renderWithMockedStats( const { lastFrame, unmount } = await renderWithMockedStats(
emptyMetrics, emptyMetrics,
@@ -115,7 +137,7 @@ describe('<SessionSummaryDisplay />', () => {
unmount(); unmount();
}); });
it('sanitizes a malicious session ID in the footer', async () => { it('sanitizes a malicious session ID in the footer (bash)', async () => {
const maliciousSessionId = "'; rm -rf / #"; const maliciousSessionId = "'; rm -rf / #";
const { lastFrame, unmount } = await renderWithMockedStats( const { lastFrame, unmount } = await renderWithMockedStats(
emptyMetrics, emptyMetrics,
@@ -127,4 +149,43 @@ describe('<SessionSummaryDisplay />', () => {
expect(output).toContain('gemini --resume "\'; rm -rf / #"'); expect(output).toContain('gemini --resume "\'; rm -rf / #"');
unmount(); unmount();
}); });
it('renders a standard UUID-formatted session ID in the footer (powershell)', async () => {
getShellConfigurationMock.mockReturnValue({
executable: 'powershell.exe',
argsPrefix: ['-NoProfile', '-Command'],
shell: 'powershell',
});
const uuidSessionId = '1234-abcd-5678-efgh';
const { lastFrame, unmount } = await renderWithMockedStats(
emptyMetrics,
uuidSessionId,
);
const output = lastFrame();
// PowerShell wraps strings in single quotes
expect(output).toContain("gemini --resume '1234-abcd-5678-efgh'");
unmount();
});
it('sanitizes a malicious session ID in the footer (powershell)', async () => {
getShellConfigurationMock.mockReturnValue({
executable: 'powershell.exe',
argsPrefix: ['-NoProfile', '-Command'],
shell: 'powershell',
});
const maliciousSessionId = "'; rm -rf / #";
const { lastFrame, unmount } = await renderWithMockedStats(
emptyMetrics,
maliciousSessionId,
);
const output = lastFrame();
// PowerShell wraps in single quotes and escapes internal single quotes by doubling them
expect(output).toContain("gemini --resume '''; rm -rf / #'");
unmount();
});
});
}); });