2025-08-20 10:55:47 +09:00
|
|
|
|
/**
|
|
|
|
|
|
* @license
|
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import { describe, it, expect, vi } from 'vitest';
|
2025-08-25 22:11:27 +02:00
|
|
|
|
import * as os from 'node:os';
|
2025-08-20 10:55:47 +09:00
|
|
|
|
import * as path from 'node:path';
|
|
|
|
|
|
|
|
|
|
|
|
vi.mock('fs', async (importOriginal) => {
|
|
|
|
|
|
const actual = await importOriginal<typeof import('fs')>();
|
|
|
|
|
|
return {
|
|
|
|
|
|
...actual,
|
|
|
|
|
|
mkdirSync: vi.fn(),
|
|
|
|
|
|
};
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
import { Storage } from './storage.js';
|
2025-10-14 02:31:39 +09:00
|
|
|
|
import { GEMINI_DIR } from '../utils/paths.js';
|
2025-08-20 10:55:47 +09:00
|
|
|
|
|
|
|
|
|
|
describe('Storage – getGlobalSettingsPath', () => {
|
|
|
|
|
|
it('returns path to ~/.gemini/settings.json', () => {
|
2025-10-14 02:31:39 +09:00
|
|
|
|
const expected = path.join(os.homedir(), GEMINI_DIR, 'settings.json');
|
2025-08-20 10:55:47 +09:00
|
|
|
|
expect(Storage.getGlobalSettingsPath()).toBe(expected);
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('Storage – additional helpers', () => {
|
|
|
|
|
|
const projectRoot = '/tmp/project';
|
|
|
|
|
|
const storage = new Storage(projectRoot);
|
|
|
|
|
|
|
|
|
|
|
|
it('getWorkspaceSettingsPath returns project/.gemini/settings.json', () => {
|
2025-10-14 02:31:39 +09:00
|
|
|
|
const expected = path.join(projectRoot, GEMINI_DIR, 'settings.json');
|
2025-08-20 10:55:47 +09:00
|
|
|
|
expect(storage.getWorkspaceSettingsPath()).toBe(expected);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('getUserCommandsDir returns ~/.gemini/commands', () => {
|
2025-10-14 02:31:39 +09:00
|
|
|
|
const expected = path.join(os.homedir(), GEMINI_DIR, 'commands');
|
2025-08-20 10:55:47 +09:00
|
|
|
|
expect(Storage.getUserCommandsDir()).toBe(expected);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('getProjectCommandsDir returns project/.gemini/commands', () => {
|
2025-10-14 02:31:39 +09:00
|
|
|
|
const expected = path.join(projectRoot, GEMINI_DIR, 'commands');
|
2025-08-20 10:55:47 +09:00
|
|
|
|
expect(storage.getProjectCommandsDir()).toBe(expected);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-12-30 13:35:52 -08:00
|
|
|
|
it('getUserSkillsDir returns ~/.gemini/skills', () => {
|
|
|
|
|
|
const expected = path.join(os.homedir(), GEMINI_DIR, 'skills');
|
|
|
|
|
|
expect(Storage.getUserSkillsDir()).toBe(expected);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('getProjectSkillsDir returns project/.gemini/skills', () => {
|
|
|
|
|
|
const expected = path.join(projectRoot, GEMINI_DIR, 'skills');
|
|
|
|
|
|
expect(storage.getProjectSkillsDir()).toBe(expected);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-12-17 22:46:55 -05:00
|
|
|
|
it('getUserAgentsDir returns ~/.gemini/agents', () => {
|
|
|
|
|
|
const expected = path.join(os.homedir(), GEMINI_DIR, 'agents');
|
|
|
|
|
|
expect(Storage.getUserAgentsDir()).toBe(expected);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('getProjectAgentsDir returns project/.gemini/agents', () => {
|
|
|
|
|
|
const expected = path.join(projectRoot, GEMINI_DIR, 'agents');
|
|
|
|
|
|
expect(storage.getProjectAgentsDir()).toBe(expected);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-08-20 10:55:47 +09:00
|
|
|
|
it('getMcpOAuthTokensPath returns ~/.gemini/mcp-oauth-tokens.json', () => {
|
|
|
|
|
|
const expected = path.join(
|
|
|
|
|
|
os.homedir(),
|
2025-10-14 02:31:39 +09:00
|
|
|
|
GEMINI_DIR,
|
2025-08-20 10:55:47 +09:00
|
|
|
|
'mcp-oauth-tokens.json',
|
|
|
|
|
|
);
|
|
|
|
|
|
expect(Storage.getMcpOAuthTokensPath()).toBe(expected);
|
|
|
|
|
|
});
|
2025-09-08 14:44:56 -07:00
|
|
|
|
|
|
|
|
|
|
it('getGlobalBinDir returns ~/.gemini/tmp/bin', () => {
|
2025-10-14 02:31:39 +09:00
|
|
|
|
const expected = path.join(os.homedir(), GEMINI_DIR, 'tmp', 'bin');
|
2025-09-08 14:44:56 -07:00
|
|
|
|
expect(Storage.getGlobalBinDir()).toBe(expected);
|
|
|
|
|
|
});
|
2025-08-20 10:55:47 +09:00
|
|
|
|
});
|