Skip to content
Closed
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
28 changes: 28 additions & 0 deletions apps/server/src/provider/AntigravityInstallation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
import * as NodeServices from "@effect/platform-node/NodeServices";
import * as Layer from "effect/Layer";
import { expect, it } from "@effect/vitest";
import { ProviderDriverKind } from "@t3tools/contracts";
import * as HostProcess from "@t3tools/shared/HostProcess";
import * as Digest from "effect/crypto/Digest";
import * as Deferred from "effect/Deferred";
Expand Down Expand Up @@ -1324,3 +1325,30 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("Antigravity inst
}),
);
});

it.each([
{ installedVersion: null, version: "1.6.0", expected: undefined },
{ installedVersion: "1.5.0", version: null, expected: "unknown" },
{ installedVersion: "1.5.0", version: "1.6.0", expected: "behind_latest" },
{ installedVersion: "1.10.0", version: "1.9.0", expected: "current" },
] as const)(
"reports a $expected managed runtime version for $installedVersion against $version",
({ installedVersion, version, expected }) => {
const advisory = AntigravityInstallation.managedRuntimeVersionAdvisory(
{
driver: ProviderDriverKind.make("antigravity"),
operationId: null,
phase: "idle",
downloadedBytes: 0,
totalBytes: null,
version,
installedVersion,
canRemove: true,
message: null,
},
"2026-04-10T00:00:00.000Z",
);
expect(advisory?.status).toBe(expected);
if (advisory) expect(advisory).toMatchObject({ canUpdate: true, updateCommand: null });
},
);
28 changes: 27 additions & 1 deletion apps/server/src/provider/AntigravityInstallation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { resolveProviderCompatibility } from "./providerCompatibility.ts";
import { cliArchiveTarCommand } from "@t3tools/shared/cliRelease";
import { compareSemverVersions } from "@t3tools/shared/semver";
import * as EffectNodeStream from "@effect/platform-node/NodeStream";
import { ProviderDriverKind, type ProviderInstallState } from "@t3tools/contracts";
import {
ProviderDriverKind,
type ProviderInstallState,
type ServerProviderVersionAdvisory,
} from "@t3tools/contracts";
import * as HostProcess from "@t3tools/shared/HostProcess";
import { resolveNodeExecutable, nodeRuntimeUnavailableMessage } from "@t3tools/shared/nodeRuntime";
import { resolveCommandPath } from "@t3tools/shared/shell";
Expand Down Expand Up @@ -173,6 +177,28 @@ function isAntigravityCli(...candidates: ReadonlyArray<string>) {
);
}

/** The managed runtime updates through installation, so it offers an update without a shell command. */
export function managedRuntimeVersionAdvisory(
state: ProviderInstallState,
checkedAt: string,
): ServerProviderVersionAdvisory | undefined {
const currentVersion = state.installedVersion;
if (currentVersion === null) return undefined;
const latestVersion = state.version;
const behind = latestVersion !== null && compareSemverVersions(currentVersion, latestVersion) < 0;
return {
status: latestVersion === null ? "unknown" : behind ? "behind_latest" : "current",
currentVersion,
latestVersion,
updateCommand: null,
canUpdate: true,
checkedAt,
message: behind
? `Install Antigravity ${latestVersion} now or review provider settings.`
: null,
};
}

function isRunning(state: ProviderInstallState) {
return (
state.phase === "downloading" || state.phase === "extracting" || state.phase === "verifying"
Expand Down
16 changes: 16 additions & 0 deletions apps/server/src/provider/Drivers/AntigravityDriver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
import { expect, it } from "@effect/vitest";
import {
ANTIGRAVITY_DEFAULT_MODEL,
ProviderDriverKind,
ProviderInstanceId,
ProviderSessionId,
ThreadId,
type AntigravitySettings,
type ProviderInstallState,
} from "@t3tools/contracts";
import * as HostProcess from "@t3tools/shared/HostProcess";
import * as Effect from "effect/Effect";
Expand Down Expand Up @@ -36,6 +38,17 @@ import * as ProviderHostLive from "../ProviderHostLive.ts";
import * as ServerSecretStore from "../../auth/ServerSecretStore.ts";

const hostPlatform = HostProcess.Platform.defaultValue();
const idleInstallState: ProviderInstallState = {
driver: ProviderDriverKind.make("antigravity"),
operationId: null,
phase: "idle",
downloadedBytes: 0,
totalBytes: null,
version: null,
installedVersion: null,
canRemove: false,
message: null,
};
const windowsHost = hostPlatform === "win32";
const decodeRequest = Schema.decodeEffect(
Schema.fromJsonString(
Expand Down Expand Up @@ -147,6 +160,8 @@ const makeHarness = Effect.fn("makeAntigravityDriverHarness")(function* (

const layerInstallation = Layer.mock(AntigravityInstallation.AntigravityInstallation)({
managedDirectory: root,
state: Effect.succeed(idleInstallState),
checkForUpdate: Effect.void,
resolve: () =>
Effect.gen(function* () {
if (controls.failResolution) {
Expand Down Expand Up @@ -570,6 +585,7 @@ it.layer(layerTest)("AntigravityDriver", (it) => {
Effect.provide(
Layer.mock(AntigravityInstallation.AntigravityInstallation)({
managedDirectory: config.stateDir,
state: Effect.succeed(idleInstallState),
resolve: () => Effect.die("unused"),
acquire: () => Effect.die("unused"),
}),
Expand Down
19 changes: 16 additions & 3 deletions apps/server/src/provider/Drivers/AntigravityDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,20 @@ export const AntigravityDriver: ProviderDriver<
accentColor,
continuationGroupKey: continuationIdentity.continuationKey,
});
const classifyModels = (draft: ServerProviderDraft) =>
currentCatalog.pipe(
Effect.map((catalog) => stampIdentity(ModelCatalog.applyModelCatalog(draft, catalog))),
// `resolve` picks the managed runtime whenever no custom executable is set.
const usesManagedRuntime = settings.binaryPath.trim() === "";
const classifyModels = Effect.fn("AntigravityDriver.classifyModels")(function* (
draft: ServerProviderDraft,
) {
const catalog = yield* currentCatalog;
const provider = stampIdentity(ModelCatalog.applyModelCatalog(draft, catalog));
if (!usesManagedRuntime) return provider;
const versionAdvisory = AntigravityInstallation.managedRuntimeVersionAdvisory(
yield* installation.state,
provider.checkedAt,
);
return versionAdvisory ? { ...provider, versionAdvisory } : provider;
});

const makeRuntime = Effect.fn("AntigravityDriver.makeRuntime")(function* (
input: Omit<AntigravityAcpRuntimeInput, "spawn" | "childProcessSpawner">,
Expand Down Expand Up @@ -388,8 +398,11 @@ export const AntigravityDriver: ProviderDriver<
// The probe must not spawn. The agent is a PyInstaller one-file bundle
// that unpacks about 1 GB per launch, and the health check runs every
// minute.
const driverScope = yield* Effect.scope;
const probe = Effect.gen(function* () {
yield* modelCatalog.refreshInBackground;
// Hourly at most; a newer release republishes this instance through its install state.
if (usesManagedRuntime) yield* Effect.forkIn(installation.checkForUpdate, driverScope);
if (authConfigIssue !== null) {
return yield* new ProviderSetupError({
instanceId,
Expand Down
95 changes: 95 additions & 0 deletions apps/server/src/provider/providerMaintenanceRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { describe, it, assert } from "@effect/vitest";
import {
ProviderDriverKind,
ProviderInstanceId,
type ProviderInstallState,
type ServerProvider,
type ServerProviderUpdateState,
} from "@t3tools/contracts";
Expand All @@ -29,6 +30,7 @@ import * as ServerSettings from "../serverSettings.ts";
import * as SourceControlProviderRegistry from "../sourceControl/SourceControlProviderRegistry.ts";
import * as TextGeneration from "../textGeneration/TextGeneration.ts";
import * as TextGenerators from "../textGeneration/TextGenerators.ts";
import * as ProviderInstallation from "./providerInstallation.ts";
import * as ProviderInstallationGate from "./ProviderInstallationGate.ts";
import * as ProviderInstanceRegistry from "./ProviderInstanceRegistry.ts";
import * as ProviderRegistry from "./ProviderRegistry.ts";
Expand All @@ -37,11 +39,13 @@ import * as ProviderMaintenanceRunner from "./providerMaintenanceRunner.ts";
import * as ProviderLatestVersions from "@t3tools/provider-core/server/ProviderLatestVersions";
import {
enrichProviderSnapshotWithVersionAdvisory,
makeManualOnlyProviderMaintenanceCapabilities,
makeProviderMaintenanceCapabilities,
type ProviderMaintenanceCapabilities,
} from "@t3tools/provider-core/server/maintenanceResolver";
const isServerProviderUpdateError = Schema.is(ServerProviderUpdateError);

const ANTIGRAVITY_DRIVER = ProviderDriverKind.make("antigravity");
const CODEX_DRIVER = ProviderDriverKind.make("codex");
const NATIVE_CLI_DRIVER = ProviderDriverKind.make("nativeCli");
const OPENCODE_DRIVER = ProviderDriverKind.make("opencode");
Expand All @@ -54,6 +58,9 @@ const encoder = new TextEncoder();
const layerNonWindowsPlatform = Layer.succeed(HostProcess.Platform, "linux");

function lifecycleFor(provider: ProviderDriverKind): ProviderMaintenanceCapabilities {
if (provider === ANTIGRAVITY_DRIVER) {
return makeManualOnlyProviderMaintenanceCapabilities({ provider, packageName: null });
}
if (provider === NATIVE_CLI_DRIVER) {
return makeProviderMaintenanceCapabilities({
provider,
Expand Down Expand Up @@ -249,6 +256,12 @@ const makeTestRunner = (
})),
},
latestVersions: Layer.Layer<ProviderLatestVersions.ProviderLatestVersions> = ProviderLatestVersions.layer,
installation: ProviderInstallation.ProviderInstallation["Service"] = {
start: () => Effect.die("unexpected managed install"),
cancel: () => Effect.die("unexpected managed install"),
subscribe: () => Stream.die("unexpected managed install"),
remove: () => Effect.die("unexpected managed install"),
},
) =>
Effect.service(ProviderMaintenanceRunner.ProviderMaintenanceRunner).pipe(
Effect.provide(
Expand All @@ -264,6 +277,7 @@ const makeTestRunner = (
refreshInBackground: Effect.void,
}),
latestVersions,
Layer.succeed(ProviderInstallation.ProviderInstallation, installation),
// Layers memoize by reference, so a test that provides the gate shares it.
ProviderInstallationGate.layer,
),
Expand All @@ -289,6 +303,87 @@ function layerFailingLatestLookupAfterFirst() {
}

describe("providerMaintenanceRunner", () => {
it.effect("updates a managed runtime by reinstalling it and reports the install outcome", () =>
Effect.gen(function* () {
const antigravity: ServerProvider = {
...baseProvider,
instanceId: ProviderInstanceId.make("antigravity"),
driver: ANTIGRAVITY_DRIVER,
versionAdvisory: {
status: "behind_latest",
currentVersion: "1.5.0",
latestVersion: "1.6.0",
updateCommand: null,
canUpdate: true,
checkedAt: baseProvider.checkedAt,
message: null,
},
};
const installState = (
phase: ProviderInstallState["phase"],
message: string | null = null,
): ProviderInstallState => ({
driver: ANTIGRAVITY_DRIVER,
operationId: "op-1",
phase,
downloadedBytes: 0,
totalBytes: null,
version: "1.6.0",
installedVersion: "1.5.0",
canRemove: true,
message,
});
const run = (ending: ProviderInstallState) =>
Effect.gen(function* () {
const { registry, updateStatesRef } = yield* makeRegistry(antigravity);
const updater = yield* makeTestRunner(registry, undefined, undefined, {
start: () => Effect.succeed(installState("downloading")),
cancel: () => Effect.die("unused"),
// A stale operation and repeated byte progress must not reach the update state.
subscribe: () =>
Stream.make(
{ ...installState("succeeded"), operationId: "op-0" },
installState("downloading"),
{ ...installState("downloading"), downloadedBytes: 10 },
installState("verifying"),
ending,
),
remove: () => Effect.die("unused"),
});
yield* updater.updateProvider({
provider: ANTIGRAVITY_DRIVER,
instanceId: antigravity.instanceId,
});
return (yield* Ref.get(updateStatesRef)).map((state) => [state.status, state.message]);
});

const progress = [
["queued", "Waiting for another provider update to finish."],
["running", "Starting the update"],
["running", "Downloading the update"],
["running", "Verifying the update"],
];
assert.deepStrictEqual(yield* run(installState("succeeded")), [
...progress,
["succeeded", "Provider updated."],
]);
assert.deepStrictEqual(yield* run(installState("failed", "Checksum mismatch.")), [
...progress,
["failed", "Checksum mismatch."],
]);
}).pipe(
Effect.provide(
Layer.mergeAll(
layerNonWindowsPlatform,
layerLatestVersionHttpClient("1.0.0"),
layerMockSpawner(() => {
throw new Error("a managed runtime update must not run a command");
}),
),
),
),
);

it.effect("runs the allowlisted provider update command and records success", () => {
const calls: Array<{ command: string; args: ReadonlyArray<string> }> = [];
return Effect.gen(function* () {
Expand Down
Loading
Loading