Compare commits

...
Author SHA1 Message Date
Julius Marmingeandcodex d3d8c4912b refactor(client-runtime): structure unavailable RPC errors
Co-authored-by: codex <[email protected]>
2026-06-20 18:11:55 -07:00
2 changed files with 33 additions and 4 deletions

No files matched your search

+26 -1
View File
@@ -25,7 +25,13 @@ import {
import * as EnvironmentSupervisor from "../connection/supervisor.ts";
import * as RpcSession from "../rpc/session.ts";
import type { WsRpcProtocolClient } from "../rpc/protocol.ts";
import { EnvironmentRpcRequestObserver, request, runStream, subscribe } from "./client.ts";
import {
EnvironmentRpcRequestObserver,
EnvironmentRpcUnavailableError,
request,
runStream,
subscribe,
} from "./client.ts";
const TARGET = new PrimaryConnectionTarget({
environmentId: EnvironmentId.make("environment-1"),
@@ -77,6 +83,25 @@ const makeHarness = Effect.fn("TestEnvironmentRpc.makeHarness")(function* () {
});
describe("environment RPC", () => {
it.effect("describes unavailable environments from structured context", () =>
Effect.gen(function* () {
const { supervisor } = yield* makeHarness();
const error = yield* request(WS_METHODS.cloudGetRelayClientStatus, {}).pipe(
Effect.provideService(EnvironmentSupervisor.EnvironmentSupervisor, supervisor),
Effect.flip,
);
expect(error).toEqual(
new EnvironmentRpcUnavailableError({
environmentId: TARGET.environmentId,
environmentLabel: TARGET.label,
}),
);
expect(error.message).toBe("Test environment is not connected.");
}),
);
it.effect("observes unary requests until they complete", () =>
Effect.gen(function* () {
const observations: string[] = [];
+7 -3
View File
@@ -16,9 +16,13 @@ export class EnvironmentRpcUnavailableError extends Schema.TaggedErrorClass<Envi
"EnvironmentRpcUnavailableError",
{
environmentId: Schema.String,
message: Schema.String,
environmentLabel: Schema.String,
},
) {}
) {
override get message(): string {
return `${this.environmentLabel} is not connected.`;
}
}
export interface EnvironmentRpcRequestObservation {
readonly environmentId: string;
@@ -94,7 +98,7 @@ const currentSession = Effect.fn("EnvironmentRpc.currentSession")(function* () {
Effect.fail(
new EnvironmentRpcUnavailableError({
environmentId: supervisor.target.environmentId,
message: `${supervisor.target.label} is not connected.`,
environmentLabel: supervisor.target.label,
}),
),
onSome: Effect.succeed,