Path: blob/main/extensions/copilot/src/extension/chronicle/common/test/sessionIndexingPreference.spec.ts
13405 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { describe, expect, it } from 'vitest';6import { SessionIndexingPreference } from '../sessionIndexingPreference';78function createMockConfigService(opts: {9localIndexEnabled?: boolean;10cloudSyncEnabled?: boolean;11excludeRepositories?: string[];12} = {}) {13const configs: Record<string, unknown> = {};14// Map by fullyQualifiedId15configs['github.copilot.chat.localIndex.enabled'] = opts.localIndexEnabled ?? false;16configs['github.copilot.chat.advanced.sessionSearch.cloudSync.enabled'] = opts.cloudSyncEnabled ?? false;17configs['github.copilot.chat.advanced.sessionSearch.cloudSync.excludeRepositories'] = opts.excludeRepositories ?? [];1819return {20getConfig: (key: { fullyQualifiedId: string }) => configs[key.fullyQualifiedId],21} as unknown as import('../../../../platform/configuration/common/configurationService').IConfigurationService;22}2324describe('SessionIndexingPreference', () => {25it('getStorageLevel returns local when no cloud sync', () => {26const pref = new SessionIndexingPreference(createMockConfigService({ localIndexEnabled: true }));27expect(pref.getStorageLevel()).toBe('local');28});2930it('getStorageLevel returns user when cloud sync enabled', () => {31const pref = new SessionIndexingPreference(createMockConfigService({32localIndexEnabled: true,33cloudSyncEnabled: true,34}));35expect(pref.getStorageLevel()).toBe('user');36});3738it('getStorageLevel returns local for excluded repo', () => {39const pref = new SessionIndexingPreference(createMockConfigService({40localIndexEnabled: true,41cloudSyncEnabled: true,42excludeRepositories: ['my-org/private-repo'],43}));44expect(pref.getStorageLevel('my-org/private-repo')).toBe('local');45});4647it('getStorageLevel returns user for non-excluded repo', () => {48const pref = new SessionIndexingPreference(createMockConfigService({49localIndexEnabled: true,50cloudSyncEnabled: true,51excludeRepositories: ['my-org/private-repo'],52}));53expect(pref.getStorageLevel('microsoft/vscode')).toBe('user');54});5556it('hasCloudConsent returns false when cloud sync disabled', () => {57const pref = new SessionIndexingPreference(createMockConfigService({ cloudSyncEnabled: false }));58expect(pref.hasCloudConsent()).toBe(false);59});6061it('hasCloudConsent returns true when cloud sync enabled', () => {62const pref = new SessionIndexingPreference(createMockConfigService({ cloudSyncEnabled: true }));63expect(pref.hasCloudConsent()).toBe(true);64});6566it('hasCloudConsent returns false for excluded repo', () => {67const pref = new SessionIndexingPreference(createMockConfigService({68cloudSyncEnabled: true,69excludeRepositories: ['my-org/*'],70}));71expect(pref.hasCloudConsent('my-org/secret-repo')).toBe(false);72});7374it('hasCloudConsent supports glob patterns', () => {75const pref = new SessionIndexingPreference(createMockConfigService({76cloudSyncEnabled: true,77excludeRepositories: ['private-org/*'],78}));79expect(pref.hasCloudConsent('private-org/repo-a')).toBe(false);80expect(pref.hasCloudConsent('private-org/repo-b')).toBe(false);81expect(pref.hasCloudConsent('public-org/repo-a')).toBe(true);82});83});848586