Skip to content

Commit 61df1eb

Browse files
committed
fix(tui): refresh auth runtime after login
1 parent f1e891f commit 61df1eb

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎src/tui/tui-pty-local.e2e.test.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type MockModelBehavior = {
6161
type MockModelRequest = {
6262
method: string;
6363
path: string;
64+
authorization?: string;
6465
body: Record<string, unknown>;
6566
};
6667

@@ -348,7 +349,12 @@ async function startRoutedMockModelServer(
348349
const body = await readJsonRequest(req);
349350
if (url.pathname === "/v1/responses" || url.pathname === "/responses") {
350351
const modelId = typeof body.model === "string" ? body.model : "";
351-
const request = { method: req.method, path: url.pathname, body };
352+
const request = {
353+
method: req.method,
354+
path: url.pathname,
355+
authorization: req.headers.authorization,
356+
body,
357+
};
352358
const behavior = behaviors[modelId];
353359
if (!behavior) {
354360
rejectedRequests.push(request);
@@ -1471,7 +1477,7 @@ describe("TUI PTY real backends", () => {
14711477
"authenticates a manifest-discovered provider and resumes the unchanged local model",
14721478
async ({ onTestFinished }) => {
14731479
const pluginId = "t05-local-auth-fixture";
1474-
const providerId = "t05-local-auth-provider";
1480+
const providerId = "tui-pty-mock";
14751481
const profileId = `${providerId}:default`;
14761482
const sentinel = `t05-${randomUUID()}`;
14771483
const expectedDigest = createHash("sha256").update(sentinel).digest("hex");
@@ -1616,6 +1622,7 @@ export default {
16161622
onTimeout: () => new Error("post-auth prompt did not reach the mock provider"),
16171623
});
16181624
expect(fixture.mockModel.requests()[0]?.body.model).toBe("gpt-5.5");
1625+
expect(fixture.mockModel.requests()[0]?.authorization).toBe(`Bearer ${sentinel}`);
16191626
await fixture.run.waitForOutput("LOCAL_AUTH_RESPONSE", LOCAL_OUTPUT_TIMEOUT_MS);
16201627

16211628
await fixture.run.write("/exit\r", { delay: false });

‎src/tui/tui.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
tryResolveDefaultAgentId,
2020
} from "../agents/agent-scope.js";
2121
import { reloadSharedAuthStoreOwnership } from "../agents/auth-profiles/path-resolve.js";
22+
import { clearRuntimeAuthProfileStoreSnapshots } from "../agents/auth-profiles/runtime-snapshots.js";
2223
import { normalizeThinkLevel } from "../auto-reply/thinking.shared.js";
2324
import { formatCliCommand } from "../cli/command-format.js";
2425
import { getRuntimeConfig, type OpenClawConfig } from "../config/config.js";
@@ -1405,7 +1406,12 @@ async function runTuiUnlocked(opts: RunTuiOptions): Promise<TuiResult> {
14051406
const outcome = `argv=${commandArgv} exitCode=${String(result.exitCode)} signal=${String(result.signal)}`;
14061407
if (result.exitCode === 0 && !result.signal) {
14071408
tuiAuthLog.info(`auth child finished: ${outcome}`);
1408-
reloadSharedAuthStoreOwnership();
1409+
if (!codexBin) {
1410+
reloadSharedAuthStoreOwnership();
1411+
// The auth child persisted outside this process. Invalidate the
1412+
// published generation so retained local runtimes rebuild from it.
1413+
clearRuntimeAuthProfileStoreSnapshots();
1414+
}
14091415
} else {
14101416
tuiAuthLog.error(`auth child failed: ${outcome}`);
14111417
}

0 commit comments

Comments
 (0)