Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion apps/server/src/provider/Drivers/AntigravityDriver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import {
type AntigravitySettings,
} from "@t3tools/contracts";
import * as HostProcess from "@t3tools/shared/HostProcess";
import * as Deferred from "effect/Deferred";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
import * as Path from "effect/Path";
import * as Redacted from "effect/Redacted";
import * as Schema from "effect/Schema";
import * as Stream from "effect/Stream";
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
import { HttpClient } from "effect/http";

Expand Down Expand Up @@ -63,6 +65,9 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
readonly enabled?: boolean;
/** Extra instance variables, such as ones a parent T3 turn already exported. */
readonly environment?: ReadonlyArray<{ readonly name: string; readonly value: string }>;
readonly beforeAcquire?: Effect.Effect<void>;
/** Leaves a Google sign-in agy saved in the profile before the driver starts. */
readonly savedSignIn?: boolean;
} = {},
) {
const fs = yield* FileSystem.FileSystem;
Expand Down Expand Up @@ -134,7 +139,11 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
selected: AntigravityInstallation.AntigravityExecutable;
failResolution: boolean;
beforeAcquire: Effect.Effect<void>;
} = { selected: first, failResolution: false, beforeAcquire: Effect.void };
} = {
selected: first,
failResolution: false,
beforeAcquire: options.beforeAcquire ?? Effect.void,
};
const acquisitions: Array<{ binaryPath: string | undefined; path: string | undefined }> = [];
const releases: Array<string | null> = [];
const launches: Array<{
Expand Down Expand Up @@ -213,6 +222,11 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (
return handle;
}),
);
if (options.savedSignIn) {
const acpDirectory = path.join(profileDirectory, "antigravity-acp");
yield* fs.makeDirectory(acpDirectory, { recursive: true });
yield* fs.writeFileString(path.join(acpDirectory, "acp_token.json"), "{}");
}
const instance = yield* AntigravityDriver.create({
instanceId,
displayName: "Google test account",
Expand Down Expand Up @@ -552,6 +566,32 @@ it.layer(layerTest)("AntigravityDriver", (it) => {
}),
);

it.effect.skipIf(windowsHost)(
"loads models at start for a configured Gemini API key or a saved Google sign-in",
() =>
Effect.gen(function* () {
for (const start of [
{ config: { authMethod: "gemini-api-key", apiKey: "fixture-gemini-key" } } as const,
{ savedSignIn: true },
]) {
const release = yield* Deferred.make<void>();
const h = yield* makeHarness({ ...start, beforeAcquire: Deferred.await(release) });
const changes = yield* Stream.toPull(h.instance.snapshot.streamChanges);
yield* Deferred.succeed(release, undefined);
let snapshot = yield* h.instance.snapshot.getSnapshot;
while (snapshot.models.length === 0) snapshot = (yield* changes).at(-1)!;
expect(snapshot.auth.status).toBe("authenticated");
expect(snapshot.models.map((model) => model.slug)).toEqual([
"gemini-test-low",
"gemini-test-high",
]);
expect(h.launches.at(-1)?.geminiApiKey).toBe(
"config" in start ? "fixture-gemini-key" : undefined,
);
}
}),
);

it.effect.skipIf(windowsHost)("keeps the previous catalog when executable resolution fails", () =>
Effect.gen(function* () {
const h = yield* makeHarness();
Expand Down
15 changes: 15 additions & 0 deletions apps/server/src/provider/Drivers/AntigravityDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,21 @@ export const AntigravityDriver: ProviderDriver<
}),
),
);
// Configured credentials, or a Google sign-in agy saved, need no sign-in click, so models
// load now rather than after the first thread. Only once per start: each launch unpacks
// about 1 GB.
const signedIn =
!antigravityAuthUsesBrowser(auth.authMethod) ||
(yield* fileSystem
.exists(path.join(profileDirectory, "antigravity-acp", "acp_token.json"))
.pipe(Effect.orElseSucceed(() => false)));
if (enabled && authConfigIssue === null && signedIn) {
// A fixed message: the cause can carry the agent's raw reply to the key.
yield* refreshModels().pipe(
Effect.catch(() => Effect.logWarning("Antigravity could not load models at start.")),
Effect.forkScoped,
);
}

return {
instanceId,
Expand Down
Loading