| 1 | import { describe, expect, test } from 'vitest'; |
| 2 | |
| 3 | describe('Local Config Switching Investigation', () => { |
| 4 | test('understands local vs remote config paths', () => { |
| 5 | // Document the different types of config paths: |
| 6 | |
| 7 | const configTypes = { |
| 8 | localFilePaths: [ |
| 9 | '~/.continue/config.yaml', |
| 10 | './config.yaml', |
| 11 | '/absolute/path/to/config.yaml' |
| 12 | ], |
| 13 | remoteAssistantSlugs: [ |
| 14 | 'continuedev/default-agent', |
| 15 | 'myorg/custom-assistant', |
| 16 | 'user/my-assistant' |
| 17 | ], |
| 18 | undefinedMeansDefault: undefined // Uses saved assistant slug or first assistant |
| 19 | }; |
| 20 | |
| 21 | // The isFilePath method checks for these patterns: |
| 22 | const isFilePath = (configPath: string) => { |
| 23 | return ( |
| 24 | configPath.startsWith(".") || |
| 25 | configPath.startsWith("/") || |
| 26 | configPath.startsWith("~") |
| 27 | ); |
| 28 | }; |
| 29 | |
| 30 | // Verify our understanding |
| 31 | configTypes.localFilePaths.forEach(path => { |
| 32 | expect(isFilePath(path)).toBe(true); |
| 33 | }); |
| 34 | |
| 35 | configTypes.remoteAssistantSlugs.forEach(slug => { |
| 36 | expect(isFilePath(slug)).toBe(false); |
| 37 | }); |
| 38 | }); |
| 39 | |
| 40 | test('documents the local config switching problem', () => { |
| 41 | // User reported issue: "Switching configs always works except when I'm using a local config" |
| 42 | |
| 43 | const problemScenarios = [ |
| 44 | { |
| 45 | name: 'Remote to Remote switching', |
| 46 | from: 'continuedev/default-agent', |
| 47 | to: 'myorg/custom-assistant', |
| 48 | works: true, |
| 49 | reason: 'Both are assistant slugs, normal flow works' |
| 50 | }, |
| 51 | { |
| 52 | name: 'Remote to Local switching', |
| 53 | from: 'continuedev/default-agent', |
| 54 | to: '~/.continue/config.yaml', |
| 55 | works: false, // This is the reported issue |
| 56 | reason: 'UNKNOWN - this is what we need to debug' |
| 57 | }, |
| 58 | { |
| 59 | name: 'Local to Remote switching', |
| 60 | from: '~/.continue/config.yaml', |
| 61 | to: 'continuedev/default-agent', |
| 62 | works: false, // Likely also broken |
| 63 | reason: 'UNKNOWN - probably same root cause' |
| 64 | }, |
| 65 | { |
| 66 | name: 'Local to Local switching', |
| 67 | from: '~/.continue/config.yaml', |
| 68 | to: './other-config.yaml', |
| 69 | works: false, // Likely also broken |
| 70 | reason: 'UNKNOWN - probably same root cause' |
| 71 | } |
| 72 | ]; |
| 73 | |
| 74 | // The problem is specifically with local configs |
| 75 | const brokenScenarios = problemScenarios.filter(s => !s.works); |
| 76 | expect(brokenScenarios.length).toBeGreaterThan(0); |
| 77 | |
| 78 | // All broken scenarios involve local configs |
| 79 | const allInvolveLocalConfigs = brokenScenarios.every(scenario => |
| 80 | scenario.from.includes('/') || scenario.from.includes('~') || scenario.from.includes('.') || |
| 81 | scenario.to.includes('/') || scenario.to.includes('~') || scenario.to.includes('.') |
| 82 | ); |
| 83 | expect(allInvolveLocalConfigs).toBe(true); |
| 84 | }); |
| 85 | |
| 86 | test('hypothesis: local config loading has different behavior', async () => { |
| 87 | // The loadConfiguration function has different code paths: |
| 88 | |
| 89 | const { loadConfiguration } = await import('../configLoader.js'); |
| 90 | |
| 91 | // Path 1: Local file loading (lines 176-189 in config.ts) |
| 92 | // if (config.startsWith(".") || config.startsWith("/") || config.startsWith("~")) { |
| 93 | // const configYaml = await loadConfigYaml(authConfig?.accessToken ?? null, config, organizationId, apiClient); |
| 94 | // return configYaml; |
| 95 | // } |
| 96 | |
| 97 | // Path 2: Remote assistant slug loading (lines 190-203 in config.ts) |
| 98 | // else { |
| 99 | // const [ownerSlug, packageSlug] = config.split("/"); |
| 100 | // const resp = await apiClient.getAssistant({ ownerSlug, packageSlug, ... }); |
| 101 | // return result.config; |
| 102 | // } |
| 103 | |
| 104 | // Hypothesis: The loadConfiguration function works correctly, but something else is different |
| 105 | // about how local configs are handled in the ConfigService or service container |
| 106 | |
| 107 | expect(typeof loadConfiguration).toBe('function'); |
| 108 | |
| 109 | // The issue might be: |
| 110 | // 1. Different state management for local vs remote configs |
| 111 | // 2. Assistant slug handling interfering with local configs |
| 112 | // 3. Service container reload behavior differs for local configs |
| 113 | // 4. Some caching or memoization issue specific to file paths |
| 114 | }); |
| 115 | |
| 116 | test('investigates assistant slug handling for local configs', async () => { |
| 117 | // When switching to a local config, we call updateAssistantSlug(null) |
| 118 | // When switching to a remote config, we call updateAssistantSlug(configPath) |
| 119 | |
| 120 | const { updateAssistantSlug, getAssistantSlug } = await import('../auth/workos.js'); |
| 121 | |
| 122 | expect(typeof updateAssistantSlug).toBe('function'); |
| 123 | expect(typeof getAssistantSlug).toBe('function'); |
| 124 | |
| 125 | // Question: Could the assistant slug clearing/setting be interfering |
| 126 | // with the config loading process? |
| 127 | |
| 128 | // In loadConfiguration, when config is undefined, it checks for saved assistant slug: |
| 129 | // const assistantSlug = getAssistantSlug(authConfig); |
| 130 | // if (assistantSlug) { config = assistantSlug; } |
| 131 | |
| 132 | // Potential issue: If we're switching TO a local config but the assistant slug |
| 133 | // is still set from a previous remote config, could that interfere? |
| 134 | }); |
| 135 | |
| 136 | test('checks if ConfigService state management differs for local configs', async () => { |
| 137 | const { ConfigService } = await import('../services/ConfigService.js'); |
| 138 | |
| 139 | // The ConfigService.updateConfigPath method should work the same for both types: |
| 140 | // 1. Load new config via loadConfiguration(authConfig, newConfigPath, ...) |
| 141 | // 2. Update this.currentState = { config, configPath: newConfigPath } |
| 142 | // 3. Call serviceContainer.set(CONFIG, this.currentState) |
| 143 | // 4. Call serviceContainer.reload(MODEL) and serviceContainer.reload(MCP) |
| 144 | |
| 145 | // But maybe there's a subtle difference in how the state is managed? |
| 146 | |
| 147 | const configService = new ConfigService(); |
| 148 | expect(typeof configService.getState).toBe('function'); |
| 149 | |
| 150 | // The state should be: { config: AssistantUnrolled, configPath: string | undefined } |
| 151 | // This should be the same regardless of whether configPath is a file or slug |
| 152 | }); |
| 153 | }); |