diff --git a/packages/gittensory-mcp/bin/gittensory-mcp.js b/packages/gittensory-mcp/bin/gittensory-mcp.js index c72aaac2e8..8aa9d61d98 100755 --- a/packages/gittensory-mcp/bin/gittensory-mcp.js +++ b/packages/gittensory-mcp/bin/gittensory-mcp.js @@ -1270,7 +1270,8 @@ function removeProfile(currentConfig, profileName) { delete profiles[profileName]; const remaining = Object.keys(profiles); const activeProfile = currentConfig.activeProfile === profileName ? (profiles[defaultProfileName] ? defaultProfileName : remaining[0] ?? defaultProfileName) : currentConfig.activeProfile; - return normalizeConfig({ ...currentConfig, activeProfile, profiles }); + const session = profileName === defaultProfileName ? undefined : currentConfig.session; + return normalizeConfig({ ...currentConfig, activeProfile, profiles, session }); } function hasPersistedConfigState(currentConfig) { diff --git a/test/unit/mcp-cli.test.ts b/test/unit/mcp-cli.test.ts index 647975187b..f6aae2771a 100644 --- a/test/unit/mcp-cli.test.ts +++ b/test/unit/mcp-cli.test.ts @@ -366,6 +366,38 @@ describe("gittensory-mcp CLI", () => { expect(requests).toEqual(expect.arrayContaining([expect.objectContaining({ url: "/v1/auth/session", authorization: "Bearer session-okto" })])); }); + it("removes the default profile without rehydrating its legacy session token", async () => { + tempDir = mkdtempSync(join(tmpdir(), "gittensory-cli-")); + const configPath = join(tempDir, "config.json"); + writeFileSync( + configPath, + JSON.stringify( + { + apiUrl: "https://api.example.test", + activeProfile: "default", + profiles: { + default: { session: { token: "default-session-token", login: "default-user", scopes: [] } }, + beta: { session: { token: "beta-session-token", login: "beta-user", scopes: [] } }, + }, + session: { token: "default-session-token", login: "default-user", scopes: [] }, + }, + null, + 2, + ), + ); + + const removed = JSON.parse(await runAsync(["profile", "remove", "default", "--json"], { GITTENSORY_CONFIG_DIR: tempDir })) as { status: string; removedProfile: string; activeProfile: string }; + const saved = JSON.parse(readFileSync(configPath, "utf8")) as { activeProfile: string; profiles?: Record; session?: unknown }; + + expect(removed).toMatchObject({ status: "removed", removedProfile: "default", activeProfile: "beta" }); + expect(saved.activeProfile).toBe("beta"); + expect(saved.profiles).not.toHaveProperty("default"); + expect(saved.profiles).toHaveProperty("beta"); + expect(saved.session).toBeUndefined(); + expect(JSON.stringify(saved)).not.toContain("default-session-token"); + expect(JSON.stringify(saved)).toContain("beta-session-token"); + }); + it("logs out only the selected profile and reports missing profiles safely", async () => { tempDir = mkdtempSync(join(tmpdir(), "gittensory-cli-")); const requests: Array<{ url: string | undefined; authorization: string | undefined }> = [];