Skip to content

Commit 560cb11

Browse files
fix(server): accept a new Antigravity Google link when authentication is retried
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9a046f5 commit 560cb11

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

‎apps/server/src/provider/AntigravityAuth.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,17 @@ const makeHarness = Effect.fn("makeAuthTestHarness")(function* (
6969
let receiveAuthorizationUrl:
7070
| ((url: string) => Effect.Effect<void, AcpErrors.AcpError>)
7171
| undefined;
72+
let logRequest:
73+
| ((event: AcpSessionRuntime.AcpSessionRequestLogEvent) => Effect.Effect<void>)
74+
| undefined;
7275
let forwarded = 0;
7376
let catalog = ["previous-account-model"];
7477
const auth = yield* makeAntigravityAuth({
7578
instanceId,
7679
makeRuntime: (input) =>
7780
Effect.gen(function* () {
7881
receiveAuthorizationUrl = input.onAuthorizationUrl;
82+
logRequest = input.requestLogger;
7983
events.push("process-open");
8084
yield* Effect.addFinalizer(() =>
8185
Effect.gen(function* () {
@@ -95,6 +99,13 @@ const makeHarness = Effect.fn("makeAuthTestHarness")(function* (
9599
start: () =>
96100
Effect.gen(function* () {
97101
events.push("authenticate");
102+
yield* (
103+
input.requestLogger?.({
104+
method: "authenticate",
105+
payload: { methodId: "oauth-personal" },
106+
status: "started",
107+
}) ?? Effect.void
108+
);
98109
yield* Deferred.succeed(authenticateCalled, undefined);
99110
if (options.interactive !== false && input.onAuthorizationUrl) {
100111
for (const url of options.authorizationUrls ?? [authorizationUrl]) {
@@ -153,6 +164,10 @@ const makeHarness = Effect.fn("makeAuthTestHarness")(function* (
153164
? receiveAuthorizationUrl(url)
154165
: Effect.die("Authorization URL receiver is not ready."),
155166
),
167+
logRequest: (event: AcpSessionRuntime.AcpSessionRequestLogEvent) =>
168+
Effect.suspend(() =>
169+
logRequest ? logRequest(event) : Effect.die("Request logger is not ready."),
170+
),
156171
};
157172
});
158173

@@ -347,6 +362,29 @@ it.layer(NodeServices.layer)("AntigravityAuth", (it) => {
347362
}),
348363
);
349364

365+
it.effect("shows the new Google link when the agent authenticates again", () =>
366+
Effect.gen(function* () {
367+
const harness = yield* makeHarness();
368+
yield* harness.auth.controller.start(owner);
369+
yield* phase(harness.auth, "waiting");
370+
yield* Deferred.succeed(harness.authenticated, undefined);
371+
yield* Deferred.await(harness.sessionRequested);
372+
373+
const retryUrl = authorizationUrl.replace("state=test-state", "state=retry-state");
374+
yield* harness.logRequest({
375+
method: "authenticate",
376+
payload: { methodId: "oauth-personal" },
377+
status: "started",
378+
});
379+
yield* harness.receiveAuthorizationUrl(retryUrl);
380+
const current = yield* harness.auth.controller
381+
.subscribe(owner)
382+
.pipe(Stream.runHead, Effect.map(Option.getOrThrow));
383+
assert.equal(current.phase, "waiting");
384+
assert.equal(current.authorizationUrl, retryUrl);
385+
}),
386+
);
387+
350388
it.effect("does not call a completed Google sign-in expired when no session opens", () =>
351389
Effect.gen(function* () {
352390
const harness = yield* makeHarness();

‎apps/server/src/provider/AntigravityAuth.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,11 @@ export const makeAntigravityAuth = Effect.fn("makeAntigravityAuth")(function* <
305305
const runtime = yield* options.makeRuntime({
306306
onAuthorizationUrl: (url) => receiveAuthorizationUrl(flow, url),
307307
// start() also opens the session, which can hang after authentication succeeds.
308+
// A retry after auth-required starts a new attempt that may show a new Google link.
308309
requestLogger: (event) => {
309-
if (event.method !== "authenticate" || event.status !== "succeeded") return Effect.void;
310-
flow.authenticated = true;
311-
return publishVerifying(flow);
310+
if (event.method !== "authenticate" || event.status === "failed") return Effect.void;
311+
flow.authenticated = event.status === "succeeded";
312+
return flow.authenticated ? publishVerifying(flow) : Effect.void;
312313
},
313314
});
314315
const started = yield* runtime.start();

0 commit comments

Comments
 (0)