Elffuss BraidHub

kikocis/continue public

main · 5.9 KiBRawPermalink
1import { describe, expect, test } from "vitest";
2
3describe("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(
80 (scenario) =>
81 scenario.from.includes("/") ||
82 scenario.from.includes("~") ||
83 scenario.from.includes(".") ||
84 scenario.to.includes("/") ||
85 scenario.to.includes("~") ||
86 scenario.to.includes("."),
87 );
88 expect(allInvolveLocalConfigs).toBe(true);
89 });
90
91 test("hypothesis: local config loading has different behavior", async () => {
92 // The loadConfiguration function has different code paths:
93
94 const { loadConfiguration } = await import("../configLoader.js");
95
96 // Path 1: Local file loading (lines 176-189 in config.ts)
97 // if (config.startsWith(".") || config.startsWith("/") || config.startsWith("~")) {
98 // const configYaml = await loadConfigYaml(authConfig?.accessToken ?? null, config, organizationId, apiClient);
99 // return configYaml;
100 // }
101
102 // Path 2: Remote assistant slug loading (lines 190-203 in config.ts)
103 // else {
104 // const [ownerSlug, packageSlug] = config.split("/");
105 // const resp = await apiClient.getAssistant({ ownerSlug, packageSlug, ... });
106 // return result.config;
107 // }
108
109 // Hypothesis: The loadConfiguration function works correctly, but something else is different
110 // about how local configs are handled in the ConfigService or service container
111
112 expect(typeof loadConfiguration).toBe("function");
113
114 // The issue might be:
115 // 1. Different state management for local vs remote configs
116 // 2. Assistant slug handling interfering with local configs
117 // 3. Service container reload behavior differs for local configs
118 // 4. Some caching or memoization issue specific to file paths
119 });
120
121 test("investigates assistant slug handling for local configs", async () => {
122 // When switching to a local config, we call updateAssistantSlug(null)
123 // When switching to a remote config, we call updateAssistantSlug(configPath)
124
125 const { updateAssistantSlug, getAssistantSlug } = await import(
126 "../auth/workos.js"
127 );
128
129 expect(typeof updateAssistantSlug).toBe("function");
130 expect(typeof getAssistantSlug).toBe("function");
131
132 // Question: Could the assistant slug clearing/setting be interfering
133 // with the config loading process?
134
135 // In loadConfiguration, when config is undefined, it checks for saved assistant slug:
136 // const assistantSlug = getAssistantSlug(authConfig);
137 // if (assistantSlug) { config = assistantSlug; }
138
139 // Potential issue: If we're switching TO a local config but the assistant slug
140 // is still set from a previous remote config, could that interfere?
141 });
142
143 test("checks if ConfigService state management differs for local configs", async () => {
144 const { ConfigService } = await import("../services/ConfigService.js");
145
146 // The ConfigService.updateConfigPath method should work the same for both types:
147 // 1. Load new config via loadConfiguration(authConfig, newConfigPath, ...)
148 // 2. Update this.currentState = { config, configPath: newConfigPath }
149 // 3. Call serviceContainer.set(CONFIG, this.currentState)
150 // 4. Call serviceContainer.reload(MODEL) and serviceContainer.reload(MCP)
151
152 // But maybe there's a subtle difference in how the state is managed?
153
154 const configService = new ConfigService();
155 expect(typeof configService.getState).toBe("function");
156
157 // The state should be: { config: AssistantUnrolled, configPath: string | undefined }
158 // This should be the same regardless of whether configPath is a file or slug
159 });
160});