Download packages/cli/src/ui/utils/clipboardUtils.windows.test.ts from SaylorTwift/gemini-cli: direct link, hf CLI and curl.
- Browser
- Download file 2.01 kB
-
https://huggingface.co/SaylorTwift/gemini-cli/resolve/main/packages/cli/src/ui/utils/clipboardUtils.windows.test.ts
- Command line
-
hf download hf://SaylorTwift/gemini-cli/packages/cli/src/ui/utils/clipboardUtils.windows.test.ts
-
curl -L -o clipboardUtils.windows.test.ts https://huggingface.co/SaylorTwift/gemini-cli/resolve/main/packages/cli/src/ui/utils/clipboardUtils.windows.test.ts
2.01 kB
| /** | |
| * @license | |
| * Copyright 2025 Google LLC | |
| * SPDX-License-Identifier: Apache-2.0 | |
| */ | |
| import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; | |
| import * as fs from 'node:fs/promises'; | |
| import { saveClipboardImage } from './clipboardUtils.js'; | |
| // Mock dependencies | |
| vi.mock('node:fs/promises'); | |
| vi.mock('@google/gemini-cli-core', async (importOriginal) => { | |
| const actual = | |
| await importOriginal<typeof import('@google/gemini-cli-core')>(); | |
| return { | |
| ...actual, | |
| spawnAsync: vi.fn(), | |
| Storage: class { | |
| getProjectTempDir = vi.fn(() => "C:\\User's Files"); | |
| initialize = vi.fn(() => Promise.resolve(undefined)); | |
| }, | |
| }; | |
| }); | |
| describe('saveClipboardImage Windows Path Escaping', () => { | |
| const originalPlatform = process.platform; | |
| beforeEach(() => { | |
| vi.resetAllMocks(); | |
| Object.defineProperty(process, 'platform', { | |
| value: 'win32', | |
| }); | |
| // Mock fs calls to succeed | |
| vi.mocked(fs.mkdir).mockResolvedValue(undefined); | |
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | |
| vi.mocked(fs.stat).mockResolvedValue({ size: 100 } as any); | |
| }); | |
| afterEach(() => { | |
| Object.defineProperty(process, 'platform', { | |
| value: originalPlatform, | |
| }); | |
| }); | |
| it('should escape single quotes in path for PowerShell script', async () => { | |
| const { spawnAsync } = await import('@google/gemini-cli-core'); | |
| vi.mocked(spawnAsync).mockResolvedValue({ | |
| stdout: 'success', | |
| stderr: '', | |
| } as any); // eslint-disable-line @typescript-eslint/no-explicit-any | |
| const targetDir = "C:\\User's Files"; | |
| await saveClipboardImage(targetDir); | |
| expect(spawnAsync).toHaveBeenCalled(); | |
| const args = vi.mocked(spawnAsync).mock.calls[0][1]; | |
| const script = args[2]; | |
| // The path C:\User's Files\.gemini-clipboard\clipboard-....png | |
| // should be escaped in the script as 'C:\User''s Files\...' | |
| // Check if the script contains the escaped path | |
| expect(script).toMatch(/'C:\\User''s Files/); | |
| }); | |
| }); | |