The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 24, 22:45 UTC
[codex] Structure preview config failures (#3271)
Co-authored-by: codex <codex@users.noreply.github.com>
Julius Marminge committed
Jun 20, 2026 at 11:25 UTC
2910d9ff0106d06f8fc1c55a44787385118f595a
2 files changed
+107
-21
apps/web/src/browser/previewWebviewConfigState.test.ts
new
+58
@@ -0,0 +1,58 @@
1
+import { describe, expect, it } from "@effect/vitest";
2
+import { EnvironmentId } from "@t3tools/contracts";
3
+import * as Effect from "effect/Effect";
4
+
5
+import {
6
+ loadPreviewWebviewConfig,
7
+ PreviewWebviewBridgeUnavailableError,
8
+ PreviewWebviewConfigLoadError,
9
+} from "./previewWebviewConfigState";
10
+
11
+const environmentId = EnvironmentId.make("environment-1");
12
+
13
+describe("loadPreviewWebviewConfig", () => {
14
+ it.effect("reports a structurally distinct missing-bridge failure", () =>
15
+ Effect.gen(function* () {
16
+ const error = yield* loadPreviewWebviewConfig(environmentId, null).pipe(Effect.flip);
17
+
18
+ expect(error).toBeInstanceOf(PreviewWebviewBridgeUnavailableError);
19
+ expect(error.environmentId).toBe(environmentId);
20
+ expect(error.message).toContain(environmentId);
21
+ expect("cause" in error).toBe(false);
22
+ }),
23
+ );
24
+
25
+ it.effect("preserves the bridge rejection as the load failure cause", () =>
26
+ Effect.gen(function* () {
27
+ const cause = new Error("ipc unavailable");
28
+ const error = yield* loadPreviewWebviewConfig(environmentId, {
29
+ getPreviewConfig: () => Promise.reject(cause),
30
+ }).pipe(Effect.flip);
31
+
32
+ expect(error).toBeInstanceOf(PreviewWebviewConfigLoadError);
33
+ expect(error.environmentId).toBe(environmentId);
34
+ expect(error.cause).toBe(cause);
35
+ expect(error.message).not.toContain(cause.message);
36
+ }),
37
+ );
38
+
39
+ it.effect("forwards the environment id to the bridge", () =>
40
+ Effect.gen(function* () {
41
+ let requestedEnvironmentId: EnvironmentId | null = null;
42
+ const config = {
43
+ partition: "persist:test-preview",
44
+ webPreferences: "sandbox=yes",
45
+ preloadUrl: null,
46
+ };
47
+ const result = yield* loadPreviewWebviewConfig(environmentId, {
48
+ getPreviewConfig: (input) => {
49
+ requestedEnvironmentId = input;
50
+ return Promise.resolve(config);
51
+ },
52
+ });
53
+
54
+ expect(requestedEnvironmentId).toBe(environmentId);
55
+ expect(result).toEqual(config);
56
+ }),
57
+ );
58
+});
apps/web/src/browser/previewWebviewConfigState.ts
+49
-21
@@ -1,8 +1,12 @@
1
import { useAtomValue } from "@effect/atom-react";
2
-import type { DesktopPreviewWebviewConfig, EnvironmentId } from "@t3tools/contracts";
3
-import * as Data from "effect/Data";
2
+import type {
3
+ DesktopPreviewBridge,
4
+ DesktopPreviewWebviewConfig,
5
+ EnvironmentId,
6
+} from "@t3tools/contracts";
7
import * as Effect from "effect/Effect";
8
import * as Option from "effect/Option";
9
+import * as Schema from "effect/Schema";
10
import { AsyncResult, Atom } from "effect/unstable/reactivity";
11
12
import { previewBridge } from "~/components/preview/previewBridge";
@@ -10,27 +14,51 @@ import { previewBridge } from "~/components/preview/previewBridge";
14
const PREVIEW_CONFIG_STALE_TIME_MS = 5 * 60_000;
15
const PREVIEW_CONFIG_IDLE_TTL_MS = 10 * 60_000;
16
13
-class PreviewWebviewConfigError extends Data.TaggedError("PreviewWebviewConfigError")<{
14
- readonly message: string;
15
- readonly cause?: unknown;
16
-}> {}
17
+export class PreviewWebviewBridgeUnavailableError extends Schema.TaggedErrorClass<PreviewWebviewBridgeUnavailableError>()(
18
+ "PreviewWebviewBridgeUnavailableError",
19
+ { environmentId: Schema.String },
20
+) {
21
+ override get message(): string {
22
+ return `Desktop preview configuration is unavailable for environment "${this.environmentId}".`;
23
+ }
24
+}
25
+
26
+export class PreviewWebviewConfigLoadError extends Schema.TaggedErrorClass<PreviewWebviewConfigLoadError>()(
27
+ "PreviewWebviewConfigLoadError",
28
+ {
29
+ environmentId: Schema.String,
30
+ cause: Schema.Defect(),
31
+ },
32
+) {
33
+ override get message(): string {
34
+ return `Failed to load desktop preview configuration for environment "${this.environmentId}".`;
35
+ }
36
+}
37
+
38
+export const PreviewWebviewConfigError = Schema.Union([
39
+ PreviewWebviewBridgeUnavailableError,
40
+ PreviewWebviewConfigLoadError,
41
+]);
42
+export type PreviewWebviewConfigError = typeof PreviewWebviewConfigError.Type;
43
+
44
+type PreviewConfigBridge = Pick<DesktopPreviewBridge, "getPreviewConfig">;
45
+
46
+export const loadPreviewWebviewConfig = (
47
+ environmentId: EnvironmentId,
48
+ bridge: PreviewConfigBridge | null = previewBridge,
49
+): Effect.Effect<DesktopPreviewWebviewConfig, PreviewWebviewConfigError> => {
50
+ if (bridge === null) {
51
+ return Effect.fail(new PreviewWebviewBridgeUnavailableError({ environmentId }));
52
+ }
53
+
54
+ return Effect.tryPromise({
55
+ try: () => bridge.getPreviewConfig(environmentId),
56
+ catch: (cause) => new PreviewWebviewConfigLoadError({ environmentId, cause }),
57
+ });
58
+};
59
60
const previewWebviewConfigAtom = Atom.family((environmentId: EnvironmentId) =>
19
- Atom.make(
20
- Effect.tryPromise({
21
- try: () => {
22
- if (!previewBridge) {
23
- throw new Error("Desktop preview bridge is unavailable.");
24
- }
25
- return previewBridge.getPreviewConfig(environmentId);
26
- },
27
- catch: (cause) =>
28
- new PreviewWebviewConfigError({
29
- message: "Could not load desktop preview configuration.",
30
- cause,
31
- }),
32
- }),
33
- ).pipe(
61
+ Atom.make(loadPreviewWebviewConfig(environmentId)).pipe(
62
Atom.swr({
63
staleTime: PREVIEW_CONFIG_STALE_TIME_MS,
64
revalidateOnMount: true,