-
-
Notifications
You must be signed in to change notification settings - Fork 539
fix(config): load legacy Windows antigravity config so account switching settings are applied #406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+140
−3
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { afterEach, beforeEach, describe, expect, it } from "vitest"; | ||
| import { __testExports, loadConfig } from "./loader"; | ||
|
|
||
| describe("config loader legacy Windows migration", () => { | ||
| let tempRoot: string; | ||
| let previousConfigDir: string | undefined; | ||
| let previousAppData: string | undefined; | ||
|
|
||
| beforeEach(() => { | ||
| tempRoot = mkdtempSync(join(tmpdir(), "antigravity-config-")); | ||
|
|
||
| previousConfigDir = process.env.OPENCODE_CONFIG_DIR; | ||
| previousAppData = process.env.APPDATA; | ||
|
|
||
| process.env.OPENCODE_CONFIG_DIR = join(tempRoot, "new-config"); | ||
| process.env.APPDATA = join(tempRoot, "legacy-appdata"); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| if (previousConfigDir === undefined) { | ||
| delete process.env.OPENCODE_CONFIG_DIR; | ||
| } else { | ||
| process.env.OPENCODE_CONFIG_DIR = previousConfigDir; | ||
| } | ||
|
|
||
| if (previousAppData === undefined) { | ||
| delete process.env.APPDATA; | ||
| } else { | ||
| process.env.APPDATA = previousAppData; | ||
| } | ||
|
|
||
| rmSync(tempRoot, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| it("migrates %APPDATA%/opencode/antigravity.json to current config path", () => { | ||
| const legacyDir = join(process.env.APPDATA!, "opencode"); | ||
| const legacyPath = join(legacyDir, "antigravity.json"); | ||
| const expectedPath = join(process.env.OPENCODE_CONFIG_DIR!, "antigravity.json"); | ||
|
|
||
| mkdirSync(legacyDir, { recursive: true }); | ||
| writeFileSync(legacyPath, JSON.stringify({ scheduling_mode: "performance_first" }), "utf-8"); | ||
|
|
||
| const resolvedPath = __testExports.resolveUserConfigPath("win32"); | ||
|
|
||
| expect(resolvedPath).toBe(expectedPath); | ||
| expect(existsSync(expectedPath)).toBe(true); | ||
| expect(existsSync(legacyPath)).toBe(false); | ||
| }); | ||
|
|
||
| it("loads settings from migrated legacy config", () => { | ||
| const legacyDir = join(process.env.APPDATA!, "opencode"); | ||
| const legacyPath = join(legacyDir, "antigravity.json"); | ||
|
|
||
| mkdirSync(legacyDir, { recursive: true }); | ||
| writeFileSync( | ||
| legacyPath, | ||
| JSON.stringify({ | ||
| account_selection_strategy: "round-robin", | ||
| scheduling_mode: "performance_first", | ||
| switch_on_first_rate_limit: true, | ||
| max_rate_limit_wait_seconds: 5, | ||
| }), | ||
| "utf-8", | ||
| ); | ||
|
|
||
| // Force legacy -> new path migration even when tests run on non-Windows CI. | ||
| __testExports.resolveUserConfigPath("win32"); | ||
|
|
||
| const loaded = loadConfig(tempRoot); | ||
|
|
||
| expect(loaded.account_selection_strategy).toBe("round-robin"); | ||
| expect(loaded.scheduling_mode).toBe("performance_first"); | ||
| expect(loaded.switch_on_first_rate_limit).toBe(true); | ||
| expect(loaded.max_rate_limit_wait_seconds).toBe(5); | ||
|
|
||
| const migratedPath = join(process.env.OPENCODE_CONFIG_DIR!, "antigravity.json"); | ||
| const persisted = JSON.parse(readFileSync(migratedPath, "utf-8")) as Record<string, unknown>; | ||
| expect(persisted.scheduling_mode).toBe("performance_first"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
unlinkSyncfails after a successfulcopyFileSync, the log is misleading and the return value is suboptimal.When
copyFileSync(Line 74) succeeds butunlinkSync(Line 75) throws, the exception propagates to the outercatch(Line 79), which logs "Failed to migrate" and returnslegacyPath. At that pointnewPathalready contains the correct config, so:legacyPathis harmless this run (same content), but on the next run both files exist andnewPathwins (Line 64), so the user silently flips paths between invocations.Consider catching
unlinkSyncfailures separately so you can still returnnewPathand log a more accurate warning about the leftover legacy file.Suggested fix
} catch { copyFileSync(legacyPath, newPath); - unlinkSync(legacyPath); - log.info("Migrated Windows config via copy+delete", { from: legacyPath, to: newPath }); + try { + unlinkSync(legacyPath); + } catch (unlinkError) { + log.warn("Migrated config but could not remove legacy file", { + legacyPath, + error: String(unlinkError), + }); + } + log.info("Migrated Windows config via copy+delete", { from: legacyPath, to: newPath }); }🤖 Prompt for AI Agents