Skip to content
TypeScript

feat(contracts): device hosts as a tagged union with EAS hosts (#21842)

Julius Marmingec273a8f6fa92
diff --git a/apps/server/src/device/DeviceService.test.ts b/apps/server/src/device/DeviceService.test.ts
index 193a42b289a..58dec58369e 100644
--- a/apps/server/src/device/DeviceService.test.ts
+++ b/apps/server/src/device/DeviceService.test.ts
@@ -1245,7 +1245,12 @@ it.effect("reconciles SSH host settings without publishing no-op changes", () =>
const initial = yield* service.state;
expect(yield* update([])).toEqual(initial);
- const host: SshDeviceHostConfig = { id: "remote", label: "Remote", target: "remote-fixture" };
+ const host: SshDeviceHostConfig = {
+ kind: "ssh",
+ id: "remote",
+ label: "Remote",
+ target: "remote-fixture",
+ };
const added = yield* update([host]);
expect(added.hosts.map((entry) => entry.id)).toEqual([LOCAL_DEVICE_HOST_ID, host.id]);
expect(yield* update([{ ...host }])).toEqual(added);
diff --git a/apps/server/src/device/DeviceService.ts b/apps/server/src/device/DeviceService.ts
index 440cd888d2c..f6793bb4d5d 100644
--- a/apps/server/src/device/DeviceService.ts
+++ b/apps/server/src/device/DeviceService.ts
@@ -17,6 +17,8 @@ import {
type DeviceSession,
type DeviceShutdownInput,
type DeviceSummary,
+ type DeviceHostConfig,
+ type EasDeviceHostConfig,
type SshDeviceHostConfig,
type DeviceHostSummary,
LOCAL_DEVICE_HOST_ID,
@@ -916,11 +918,11 @@ export const make = Effect.gen(function* () {
yield* Effect.context<Effect.Services<ReturnType<typeof SshDeviceHost.make>>>();
const configured = new Map<string, { config: SshDeviceHostConfig; scope: Scope.Closeable }>();
const reconcile = Effect.fn("DeviceService.reconcile")(function* (
- configuredHosts: ReadonlyArray<SshDeviceHostConfig>,
+ configuredHosts: ReadonlyArray<DeviceHostConfig>,
) {
- const next = yield* remoteSshDeviceHosts(configuredHosts).pipe(
- Effect.provide(localTargetContext),
- );
+ const next = yield* remoteSshDeviceHosts(
+ configuredHosts.filter((host): host is SshDeviceHostConfig => host.kind === "ssh"),
+ ).pipe(Effect.provide(localTargetContext));
const removed = yield* service.withLifecycleLock(
Effect.gen(function* () {
const removed: Array<{ id: string; scope: Scope.Closeable }> = [];
@@ -989,9 +991,17 @@ export const make = Effect.gen(function* () {
);
});
const changes = yield* settings.subscribeChanges;
- yield* reconcile((yield* settings.getSettings).deviceHosts);
+ // Settings keep EAS hosts apart from SSH hosts; an id both lists use stays the SSH host's.
+ const configuredHosts = (value: {
+ readonly deviceHosts: ReadonlyArray<SshDeviceHostConfig>;
+ readonly easDeviceHosts: ReadonlyArray<EasDeviceHostConfig>;
+ }): ReadonlyArray<DeviceHostConfig> => [
+ ...value.deviceHosts,
+ ...value.easDeviceHosts.filter((host) => !value.deviceHosts.some((ssh) => ssh.id === host.id)),
+ ];
+ yield* reconcile(configuredHosts(yield* settings.getSettings));
yield* changes.pipe(
- Stream.runForEach((value) => reconcile(value.deviceHosts)),
+ Stream.runForEach((value) => reconcile(configuredHosts(value))),
Effect.forkIn(scope),
);
yield* Effect.addFinalizer(() =>
diff --git a/apps/server/src/device/SshDeviceHost.test.ts b/apps/server/src/device/SshDeviceHost.test.ts
index 24c128c6543..cde68d1b50c 100644
--- a/apps/server/src/device/SshDeviceHost.test.ts
+++ b/apps/server/src/device/SshDeviceHost.test.ts
@@ -101,7 +101,7 @@ it.effect("preserves installed status after probes and cleans failed agent activ
}),
);
const host = yield* SshDeviceHost.make(
- { id: "test", label: "Test", target: "test.example" },
+ { kind: "ssh", id: "test", label: "Test", target: "test.example" },
() =>
rejectConfig
? Effect.fail(
@@ -123,7 +123,12 @@ it.effect("preserves installed status after probes and cleans failed agent activ
),
);
yield* host.ensureReady(() => Effect.void);
- yield* SshDeviceHost.probe({ id: "test", label: "Test", target: "test.example" }).pipe(
+ yield* SshDeviceHost.probe({
+ kind: "ssh",
+ id: "test",
+ label: "Test",
+ target: "test.example",
+ }).pipe(
Effect.provide(ServerConfig.layerTest(home, home)),
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
);
diff --git a/apps/server/src/device/localSshDeviceHost.test.ts b/apps/server/src/device/localSshDeviceHost.test.ts
index c9014b06ff8..c93c41c9bab 100644
--- a/apps/server/src/device/localSshDeviceHost.test.ts
+++ b/apps/server/src/device/localSshDeviceHost.test.ts
@@ -11,6 +11,7 @@ import {
} from "./localSshDeviceHost.ts";
const host = (target: string, port?: number) => ({
+ kind: "ssh" as const,
id: target,
label: target,
target,
@@ -78,9 +79,17 @@ it.effect("keeps remote, forwarded, proxied, and unresolved destinations", () =>
it.effect("removes only self targets from a fanned-out host list", () =>
provide(
Effect.gen(function* () {
+ const eas = {
+ kind: "eas" as const,
+ id: "eas",
+ label: "EAS Simulator",
+ maxSessionMinutes: 30,
+ idleMinutes: 10,
+ maxConcurrentSessions: 2,
+ };
expect(
- yield* remoteSshDeviceHosts([host("mac-mini"), host("remote"), host("forwarded")]),
- ).toEqual([host("remote"), host("forwarded")]);
+ yield* remoteSshDeviceHosts([host("mac-mini"), eas, host("remote"), host("forwarded")]),
+ ).toEqual([eas, host("remote"), host("forwarded")]);
}),
),
);
diff --git a/apps/server/src/device/localSshDeviceHost.ts b/apps/server/src/device/localSshDeviceHost.ts
index 187756bb44e..a2fee8c8881 100644
--- a/apps/server/src/device/localSshDeviceHost.ts
+++ b/apps/server/src/device/localSshDeviceHost.ts
@@ -1,6 +1,6 @@
import * as NodeDnsPromises from "node:dns/promises";
import * as NodeNet from "node:net";
-import type { SshDeviceHostConfig } from "@t3tools/contracts";
+import type { DeviceHostConfig, SshDeviceHostConfig } from "@t3tools/contracts";
import * as NodeOS from "node:os";
import * as Context from "effect/Context";
import { runSshCommand } from "@t3tools/ssh/command";
@@ -59,12 +59,15 @@ export const isLocalSshDeviceHost = Effect.fn("isLocalSshDeviceHost")(function*
);
});
-export const remoteSshDeviceHosts = Effect.fn("remoteSshDeviceHosts")(function* (
- hosts: ReadonlyArray<SshDeviceHostConfig>,
-) {
- return yield* Effect.filter(
- hosts,
- (host) => isLocalSshDeviceHost(host).pipe(Effect.map((local) => !local)),
- { concurrency: 4 },
- );
-});
+/** Drops SSH hosts that resolve to this machine; other host kinds pass through. */
+export const remoteSshDeviceHosts = Effect.fn("remoteSshDeviceHosts")(
+ <Host extends DeviceHostConfig>(hosts: ReadonlyArray<Host>) =>
+ Effect.filter(
+ hosts,
+ (host) =>
+ host.kind === "ssh"
+ ? isLocalSshDeviceHost(host).pipe(Effect.map((local) => !local))
+ : Effect.succeed(true),
+ { concurrency: 4 },
+ ),
+);
diff --git a/apps/web/src/components/settings/DeviceHostsSettings.tsx b/apps/web/src/components/settings/DeviceHostsSettings.tsx
index e15d853df97..fb5a1b2517e 100644
--- a/apps/web/src/components/settings/DeviceHostsSettings.tsx
+++ b/apps/web/src/components/settings/DeviceHostsSettings.tsx
@@ -145,7 +145,7 @@ export function DeviceHostsSettings(props: { environmentId: EnvironmentId | null
}
onClick={() => {
setOriginalHost(null);
- setEditing({ id: randomUUID(), label: "", target: "" });
+ setEditing({ kind: "ssh", id: randomUUID(), label: "", target: "" });
}}
>
<PlusIcon className="size-3.5" /> Add host
diff --git a/apps/web/src/components/settings/deviceHostConnectionChecks.test.ts b/apps/web/src/components/settings/deviceHostConnectionChecks.test.ts
index f9b003812bf..7c7570a1fd8 100644
--- a/apps/web/src/components/settings/deviceHostConnectionChecks.test.ts
+++ b/apps/web/src/components/settings/deviceHostConnectionChecks.test.ts
@@ -8,7 +8,7 @@ import {
type DeviceHostCheck,
} from "./deviceHostConnectionChecks";
-const host = { id: "mac", label: "Mac mini", target: "user@mac" };
+const host = { kind: "ssh" as const, id: "mac", label: "Mac mini", target: "user@mac" };
const ids = ["a", "b", "c", "d"].map((id) => EnvironmentId.make(id));
const targets = ids.map((environmentId, index) => ({
environmentId,
diff --git a/apps/web/src/components/settings/deviceHostsSettings.logic.test.ts b/apps/web/src/components/settings/deviceHostsSettings.logic.test.ts
index 274cf7ecd9a..039a3955684 100644
--- a/apps/web/src/components/settings/deviceHostsSettings.logic.test.ts
+++ b/apps/web/src/components/settings/deviceHostsSettings.logic.test.ts
@@ -2,8 +2,13 @@ import { describe, expect, it } from "vite-plus/test";
import { updateDeviceHosts } from "./deviceHostsSettings.logic";
describe("device host changes across environments", () => {
- const shared = { id: "shared", label: "Mac mini", target: "julius@macmini" };
- const local = { id: "other", label: "Android", target: "julius@android" };
+ const shared = {
+ kind: "ssh" as const,
+ id: "shared",
+ label: "Mac mini",
+ target: "julius@macmini",
+ };
+ const local = { kind: "ssh" as const, id: "other", label: "Android", target: "julius@android" };
it("adds to differing host lists without losing environment-specific hosts, including on retry", () => {
const environments = [[], [local], [shared, local]];
diff --git a/packages/contracts/src/device.test.ts b/packages/contracts/src/device.test.ts
index 11587fa5996..f9b76384028 100644
--- a/packages/contracts/src/device.test.ts
+++ b/packages/contracts/src/device.test.ts
@@ -1,5 +1,11 @@
import { describe, expect, it } from "@effect/vitest";
-import { deviceToolInstallMessage } from "./device.ts";
+import { Schema } from "effect";
+import {
+ DeviceServiceState,
+ EasDeviceHostConfigs,
+ SshDeviceHostConfigs,
+ deviceToolInstallMessage,
+} from "./device.ts";
describe("device tool install progress", () => {
it("distinguishes a new install from an upgrade and chooses versions numerically", () => {
@@ -19,3 +25,70 @@ describe("device tool install progress", () => {
).toBe("Updating device hub from 0.10.0 to 0.11.0…");
});
});
+
+const decodeSshHosts = Schema.decodeUnknownSync(SshDeviceHostConfigs);
+const decodeEas = Schema.decodeUnknownSync(EasDeviceHostConfigs);
+const encodeState = Schema.encodeSync(DeviceServiceState);
+const decodeState = Schema.decodeUnknownSync(DeviceServiceState);
+// The host summary as clients decoded it before EAS hosts existed.
+const decodeOlderState = Schema.decodeUnknownSync(
+ Schema.Struct({
+ hosts: Schema.Array(
+ Schema.Struct({ id: Schema.String, kind: Schema.Literals(["local", "ssh"]) }),
+ ),
+ }),
+);
+
+describe("configured device hosts", () => {
+ it("reads SSH hosts saved before hosts had a kind, and bounds EAS sessions", () => {
+ expect(decodeSshHosts([{ id: "mac", label: "Mac mini", target: "julius@mac" }])).toEqual([
+ { kind: "ssh", id: "mac", label: "Mac mini", target: "julius@mac" },
+ ]);
+ expect(decodeEas([{ kind: "eas", id: "eas", label: "EAS Simulator" }])).toEqual([
+ {
+ kind: "eas",
+ id: "eas",
+ label: "EAS Simulator",
+ maxSessionMinutes: 30,
+ idleMinutes: 10,
+ maxConcurrentSessions: 2,
+ },
+ ]);
+ expect(() =>
+ decodeEas([{ kind: "eas", id: "eas", label: "EAS", maxSessionMinutes: 600 }]),
+ ).toThrow();
+ // The default idle limit of 10 is not smaller than a session limit of 10.
+ expect(() =>
+ decodeEas([{ kind: "eas", id: "eas", label: "EAS", maxSessionMinutes: 10 }]),
+ ).toThrow();
+ });
+});
+
+describe("device state for clients from before EAS hosts", () => {
+ const summary = {
+ label: "Host",
+ platforms: [],
+ hubInstalled: true,
+ agentDeviceInstalled: true,
+ };
+ const state = {
+ hosts: [
+ { ...summary, id: "local", kind: "local" as const },
+ { ...summary, id: "eas", kind: "eas" as const },
+ ],
+ hostStatus: "ready" as const,
+ hostStatuses: {},
+ devices: [],
+ sessions: [],
+ onboardingCompleted: true,
+ agentAccessEnabled: true,
+ hubBasePath: "/api/device-hub",
+ revision: 1,
+ };
+
+ it("sends EAS hosts where an older client does not look, and reads them back", () => {
+ const wire = encodeState(state);
+ expect(decodeOlderState(wire).hosts.map((host) => host.id)).toEqual(["local"]);
+ expect(decodeState(wire).hosts).toEqual(state.hosts);
+ });
+});
diff --git a/packages/contracts/src/device.ts b/packages/contracts/src/device.ts
index ce7fda46d33..3529b2ca85d 100644
--- a/packages/contracts/src/device.ts
+++ b/packages/contracts/src/device.ts
@@ -1,4 +1,6 @@
-import { Schema } from "effect";
+import * as Effect from "effect/Effect";
+import * as Schema from "effect/Schema";
+import * as SchemaTransformation from "effect/SchemaTransformation";
import { ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
@@ -10,11 +12,15 @@ export type DeviceHostId = typeof DeviceHostId.Type;
export const LOCAL_DEVICE_HOST_ID = "local" as DeviceHostId;
+const ConfiguredDeviceHostId = DeviceHostId.check(
+ Schema.isPattern(/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/),
+ Schema.makeFilter((id) => id !== "local" || "The local host id is reserved."),
+);
+
export const SshDeviceHostConfig = Schema.Struct({
- id: DeviceHostId.check(
- Schema.isPattern(/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/),
- Schema.makeFilter((id) => id !== "local" || "The local host id is reserved."),
- ),
+ // Hosts saved before EAS hosts existed carry no kind.
+ kind: Schema.Literal("ssh").pipe(Schema.withDecodingDefaultKey(Effect.succeed("ssh" as const))),
+ id: ConfiguredDeviceHostId,
label: TrimmedNonEmptyString,
target: TrimmedNonEmptyString.check(Schema.isPattern(/^[^\s-][^\s]*$/)),
identityFile: Schema.optional(TrimmedNonEmptyString),
@@ -22,13 +28,52 @@ export const SshDeviceHostConfig = Schema.Struct({
});
export type SshDeviceHostConfig = typeof SshDeviceHostConfig.Type;
-export const SshDeviceHostConfigs = Schema.Array(SshDeviceHostConfig).check(
+/**
+ * Cloud simulators from EAS Simulator. Sessions bill the Expo account until
+ * they stop, so every one is bounded. The Expo credential is not stored here.
+ */
+export const EasDeviceHostConfig = Schema.Struct({
+ kind: Schema.Literal("eas"),
+ id: ConfiguredDeviceHostId,
+ label: TrimmedNonEmptyString,
+ /** EAS project that sessions run under, when the project's app config does not name one. */
+ appId: Schema.optional(TrimmedNonEmptyString),
+ /** EAS allows at most 40 minutes on free accounts and 115 on paid ones. */
+ maxSessionMinutes: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 115 })).pipe(
+ Schema.withDecodingDefaultKey(Effect.succeed(30)),
+ ),
+ idleMinutes: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 60 })).pipe(
+ Schema.withDecodingDefaultKey(Effect.succeed(10)),
+ ),
+ maxConcurrentSessions: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 20 })).pipe(
+ Schema.withDecodingDefaultKey(Effect.succeed(2)),
+ ),
+}).check(
+ // EAS requires the idle limit to be smaller than the session limit.
Schema.makeFilter(
- (hosts) =>
- new Set(hosts.map((host) => host.id)).size === hosts.length ||
- "Device host ids must be unique.",
+ (host: { readonly idleMinutes: number; readonly maxSessionMinutes: number }) =>
+ host.idleMinutes < host.maxSessionMinutes ||
+ "Idle minutes must be smaller than session minutes.",
),
);
+export type EasDeviceHostConfig = typeof EasDeviceHostConfig.Type;
+
+export type DeviceHostConfig = SshDeviceHostConfig | EasDeviceHostConfig;
+
+const uniqueHostIds = Schema.makeFilter(
+ (hosts: ReadonlyArray<{ readonly id: string }>) =>
+ new Set(hosts.map((host) => host.id)).size === hosts.length ||
+ "Device host ids must be unique.",
+);
+
+export const SshDeviceHostConfigs = Schema.Array(SshDeviceHostConfig).check(uniqueHostIds);
+
+/**
+ * Kept apart from the SSH hosts in settings: servers and clients from before
+ * EAS hosts decode `deviceHosts` as SSH hosts and would reject the whole file
+ * or snapshot over one EAS entry.
+ */
+export const EasDeviceHostConfigs = Schema.Array(EasDeviceHostConfig).check(uniqueHostIds);
export const DeviceId = TrimmedNonEmptyString.check(Schema.isMaxLength(256));
export type DeviceId = typeof DeviceId.Type;
@@ -64,16 +109,24 @@ export const DeviceToolVersions = Schema.Struct({
});
export type DeviceToolVersions = typeof DeviceToolVersions.Type;
-export const DeviceHostSummary = Schema.Struct({
+const deviceHostSummaryFields = {
id: DeviceHostId,
- kind: Schema.Literals(["local", "ssh"]),
label: TrimmedNonEmptyString,
platforms: Schema.Array(DevicePlatformAvailability),
tools: Schema.optional(DeviceToolVersions),
toolInspectionError: Schema.optional(Schema.String),
hubInstalled: Schema.Boolean,
agentDeviceInstalled: Schema.Boolean,
+};
+const MachineDeviceHostSummary = Schema.Struct({
+ ...deviceHostSummaryFields,
+ kind: Schema.Literals(["local", "ssh"]),
+});
+const EasDeviceHostSummary = Schema.Struct({
+ ...deviceHostSummaryFields,
+ kind: Schema.Literal("eas"),
});
+export const DeviceHostSummary = Schema.Union([MachineDeviceHostSummary, EasDeviceHostSummary]);
export type DeviceHostSummary = typeof DeviceHostSummary.Type;
export const DeviceHostStatus = Schema.Literals([
@@ -95,21 +148,22 @@ export const DeviceSession = Schema.Struct({
});
export type DeviceSession = typeof DeviceSession.Type;
-export const DeviceServiceState = Schema.Struct({
+export const DeviceHostStatuses = Schema.Record(
+ DeviceHostId,
+ Schema.Struct({
+ status: DeviceHostStatus,
+ detail: Schema.optional(Schema.String),
+ androidDiscoveryIncomplete: Schema.optional(Schema.Boolean),
+ }),
+);
+
+const deviceServiceStateFields = {
supportsHostRetry: Schema.optional(Schema.Boolean),
supportsToolUpdate: Schema.optional(Schema.Boolean),
supportsToolInspection: Schema.optional(Schema.Boolean),
- hosts: Schema.Array(DeviceHostSummary),
hostStatus: DeviceHostStatus,
hostStatusDetail: Schema.optional(Schema.String),
- hostStatuses: Schema.Record(
- DeviceHostId,
- Schema.Struct({
- status: DeviceHostStatus,
- detail: Schema.optional(Schema.String),
- androidDiscoveryIncomplete: Schema.optional(Schema.Boolean),
- }),
- ),
+ hostStatuses: DeviceHostStatuses,
devices: Schema.Array(DeviceSummary),
sessions: Schema.Array(DeviceSession),
bootingDevices: Schema.optional(
@@ -119,7 +173,46 @@ export const DeviceServiceState = Schema.Struct({
agentAccessEnabled: Schema.Boolean,
hubBasePath: Schema.String,
revision: Schema.Int,
+};
+
+/**
+ * EAS host summaries travel as `easHosts`: clients from before EAS hosts
+ * decode `hosts` with a `local | ssh` kind and would reject the whole state.
+ * Decoded, every host is in `hosts`.
+ */
+const DeviceServiceStateWire = Schema.Struct({
+ ...deviceServiceStateFields,
+ hosts: Schema.Array(MachineDeviceHostSummary),
+ easHosts: Schema.optional(Schema.Array(EasDeviceHostSummary)),
+});
+const DeviceServiceStateDecoded = Schema.Struct({
+ ...deviceServiceStateFields,
+ hosts: Schema.Array(DeviceHostSummary),
});
+
+export const DeviceServiceState = DeviceServiceStateWire.pipe(
+ Schema.decodeTo(
+ Schema.toType(DeviceServiceStateDecoded),
+ SchemaTransformation.transform<
+ typeof DeviceServiceStateDecoded.Type,
+ typeof DeviceServiceStateWire.Type
+ >({
+ decode: ({ easHosts, ...state }) => ({
+ ...state,
+ hosts: [...state.hosts, ...(easHosts ?? [])],
+ }),
+ encode: (state) => ({
+ ...state,
+ hosts: state.hosts.filter(
+ (host): host is typeof MachineDeviceHostSummary.Type => host.kind !== "eas",
+ ),
+ easHosts: state.hosts.filter(
+ (host): host is typeof EasDeviceHostSummary.Type => host.kind === "eas",
+ ),
+ }),
+ }),
+ ),
+);
export type DeviceServiceState = typeof DeviceServiceState.Type;
export const DeviceListInput = Schema.Struct({
@@ -423,7 +516,7 @@ export const DeviceError = Schema.Union([
export type DeviceError = typeof DeviceError.Type;
export const DeviceToolListResult = Schema.Struct({
- hostStatuses: DeviceServiceState.fields.hostStatuses,
+ hostStatuses: DeviceHostStatuses,
hosts: Schema.Array(DeviceHostSummary),
devices: Schema.Array(DeviceSummary),
open: Schema.Array(Schema.Struct({ hostId: DeviceHostId, deviceId: DeviceId })),
diff --git a/packages/contracts/src/settings.test.ts b/packages/contracts/src/settings.test.ts
index 9f16bbc74a9..e4d55cdf9b5 100644
--- a/packages/contracts/src/settings.test.ts
+++ b/packages/contracts/src/settings.test.ts
@@ -1087,9 +1087,31 @@ describe("ServerSettings environment icon", () => {
const decodeDeviceHostSettings = Schema.decodeSync(ServerSettings);
+// `deviceHosts` as it was decoded before EAS hosts existed: an SSH host needs a target.
+const decodeOlderDeviceHostSettings = Schema.decodeUnknownSync(
+ Schema.Struct({
+ deviceHosts: Schema.Array(Schema.Struct({ id: Schema.String, target: Schema.String })),
+ }),
+);
+
+it("keeps EAS hosts out of the SSH host list servers and clients before EAS hosts decode", () => {
+ const settings = decodeDeviceHostSettings({
+ deviceHosts: [{ id: "mini", label: "Mac mini", target: "user@mini" }],
+ easDeviceHosts: [{ kind: "eas", id: "eas", label: "EAS Simulator" }],
+ });
+ const wire = encodeServerSettings(settings);
+ expect(decodeOlderDeviceHostSettings(wire).deviceHosts).toEqual([
+ { id: "mini", target: "user@mini" },
+ ]);
+ expect(settings.easDeviceHosts.map((host) => host.id)).toEqual(["eas"]);
+});
+
it("validates remote device hosts and rejects ambiguous host ids", () => {
const host = { id: "mini", label: "Mac mini", target: "user@mini", port: 2222 };
- expect(decodeDeviceHostSettings({ deviceHosts: [host] }).deviceHosts).toEqual([host]);
+ // Hosts saved before EAS hosts existed have no `kind`; they are SSH hosts.
+ expect(decodeDeviceHostSettings({ deviceHosts: [host] }).deviceHosts).toEqual([
+ { kind: "ssh", ...host },
+ ]);
expect(() => decodeDeviceHostSettings({ deviceHosts: [host, host] })).toThrow();
expect(() => decodeDeviceHostSettings({ deviceHosts: [{ ...host, id: "local" }] })).toThrow();
expect(() =>
diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.ts
index d4136741fbb..d46ce4e227f 100644
--- a/packages/contracts/src/settings.ts
+++ b/packages/contracts/src/settings.ts
@@ -1,4 +1,4 @@
-import { SshDeviceHostConfigs } from "./device.ts";
+import { EasDeviceHostConfigs, SshDeviceHostConfigs } from "./device.ts";
import {
AuthOrchestrationOperateScope,
AuthSettingsWriteScope,
@@ -1155,6 +1155,7 @@ export const ServerSettings = Schema.Struct({
enableDeviceSupport: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
deviceOnboardingCompleted: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
deviceHosts: SshDeviceHostConfigs.pipe(Schema.withDecodingDefault(Effect.succeed([]))),
+ easDeviceHosts: EasDeviceHostConfigs.pipe(Schema.withDecodingDefault(Effect.succeed([]))),
sidebarAutoSettleAfterDays: Schema.NullOr(SidebarAutoSettleAfterDays).pipe(
Schema.withDecodingDefault(Effect.succeed(DEFAULT_SIDEBAR_AUTO_SETTLE_AFTER_DAYS)),
),
@@ -1471,6 +1472,7 @@ export const ServerSettingsPatch = Schema.Struct({
enableDeviceSupport: Schema.optionalKey(Schema.Boolean),
deviceOnboardingCompleted: Schema.optionalKey(Schema.Boolean),
deviceHosts: Schema.optionalKey(SshDeviceHostConfigs),
+ easDeviceHosts: Schema.optionalKey(EasDeviceHostConfigs),
sidebarAutoSettleAfterDays: Schema.optionalKey(Schema.NullOr(SidebarAutoSettleAfterDays)),
compactIdleThreads: Schema.optionalKey(Schema.Boolean),
sidebarAutoSettleKeepPullRequests: Schema.optionalKey(Schema.Boolean),
diff --git a/packages/shared/src/serverSettings.test.ts b/packages/shared/src/serverSettings.test.ts
index 5d1154e0fc9..97bd1c2f460 100644
--- a/packages/shared/src/serverSettings.test.ts
+++ b/packages/shared/src/serverSettings.test.ts
@@ -86,7 +86,7 @@ describe("serverSettings helpers", () => {
});
});
it("replaces SSH host lists when saving, editing, and removing hosts", () => {
- const host = { id: "mini", label: "Mac mini", target: "mini" };
+ const host = { kind: "ssh" as const, id: "mini", label: "Mac mini", target: "mini" };
const saved = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, { deviceHosts: [host] });
expect(saved.deviceHosts).toEqual([host]);
const replacement = { ...host, target: "other-mini" };
@@ -95,6 +95,25 @@ describe("serverSettings helpers", () => {
expect(applyServerSettingsPatch(edited, { deviceHosts: [] }).deviceHosts).toEqual([]);
});
+ it("replaces EAS host lists the same way", () => {
+ const host = {
+ kind: "eas" as const,
+ id: "eas",
+ label: "EAS Simulator",
+ accessToken: "",
+ maxSessionMinutes: 30,
+ idleMinutes: 10,
+ maxConcurrentSessions: 2,
+ };
+ const saved = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, { easDeviceHosts: [host] });
+ expect(saved.easDeviceHosts).toEqual([host]);
+ const edited = applyServerSettingsPatch(saved, {
+ easDeviceHosts: [{ ...host, maxSessionMinutes: 60 }],
+ });
+ expect(edited.easDeviceHosts).toEqual([{ ...host, maxSessionMinutes: 60 }]);
+ expect(applyServerSettingsPatch(edited, { easDeviceHosts: [] }).easDeviceHosts).toEqual([]);
+ });
+
it("inherits actions, preserves existing actions, and supports empty overrides and reset", () => {
const project = { id: ProjectId.make("project-actions"), scripts: [] };
const action = {