diff --git a/apps/server/src/http.ts b/apps/server/src/http.ts index fc7a9ef13a..b05c6baf01 100644 --- a/apps/server/src/http.ts +++ b/apps/server/src/http.ts @@ -279,28 +279,26 @@ export const staticAndDevRouteLayer = HttpRouter.add( } } - const fileInfo = yield* fileSystem.stat(filePath).pipe(Effect.orElseSucceed(() => null)); - if (!fileInfo || fileInfo.type !== "File") { + const fileInfo = yield* Effect.option(fileSystem.stat(filePath)); + if (Option.isNone(fileInfo) || fileInfo.value.type !== "File") { const indexPath = path.resolve(staticRoot, "index.html"); - const indexData = yield* fileSystem - .readFile(indexPath) - .pipe(Effect.orElseSucceed(() => null)); - if (!indexData) { + const indexData = yield* Effect.option(fileSystem.readFile(indexPath)); + if (Option.isNone(indexData)) { return HttpServerResponse.text("Not Found", { status: 404 }); } - return HttpServerResponse.uint8Array(indexData, { + return HttpServerResponse.uint8Array(indexData.value, { status: 200, contentType: "text/html; charset=utf-8", }); } const contentType = Mime.getType(filePath) ?? "application/octet-stream"; - const data = yield* fileSystem.readFile(filePath).pipe(Effect.orElseSucceed(() => null)); - if (!data) { + const data = yield* Effect.option(fileSystem.readFile(filePath)); + if (Option.isNone(data)) { return HttpServerResponse.text("Internal Server Error", { status: 500 }); } - return HttpServerResponse.uint8Array(data, { + return HttpServerResponse.uint8Array(data.value, { status: 200, contentType, }); diff --git a/packages/client-runtime/src/state/vcsAction.test.ts b/packages/client-runtime/src/state/vcsAction.test.ts index dac852c166..5ff61ec105 100644 --- a/packages/client-runtime/src/state/vcsAction.test.ts +++ b/packages/client-runtime/src/state/vcsAction.test.ts @@ -3,7 +3,7 @@ import { type GitActionProgressEvent, type GitRunStackedActionResult, } from "@t3tools/contracts"; -import { describe, expect, it } from "@effect/vitest"; +import { assert, describe, expect, it } from "@effect/vitest"; import * as Cause from "effect/Cause"; import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; @@ -64,7 +64,7 @@ function progress(event: T): T { } describe("vcsActionState", () => { - it("preserves malformed target key diagnostics and the native cause without copying the key", () => { + it("preserves malformed target key diagnostics without copying the key", () => { const key = "not-json-with-credential=do-not-log"; let error: unknown; @@ -74,16 +74,17 @@ describe("vcsActionState", () => { error = cause; } - expect(error).toBeInstanceOf(VcsActionTargetKeyParseError); - expect(error).toMatchObject({ keyLength: key.length, cause: expect.any(SyntaxError) }); - expect(error).not.toHaveProperty("key"); - expect((error as Error).message).not.toContain(key); + assert.instanceOf(error, VcsActionTargetKeyParseError); + assert.equal(error.keyLength, key.length); + assert.isDefined(error.cause); + assert.isFalse("key" in error); + assert.notInclude(error.message, key); }); it("rejects invalid target key shapes", () => { const key = JSON.stringify([environmentId]); - expect(() => parseVcsActionTargetKey(key)).toThrowError(VcsActionTargetKeyParseError); + assert.throws(() => parseVcsActionTargetKey(key), VcsActionTargetKeyParseError); }); it("projects phase and hook progress without owning the async operation", () => { @@ -245,12 +246,15 @@ describe("vcsActionState", () => { }); it("keys presentation state only when the environment and repository are known", () => { - expect( - getVcsActionTargetKey({ - environmentId, - cwd, - }), - ).toBe(JSON.stringify([environmentId, cwd])); + const key = getVcsActionTargetKey({ + environmentId, + cwd, + }); + if (key === null) { + assert.fail("Expected a resolved target key."); + } + assert.equal(key, JSON.stringify([environmentId, cwd])); + assert.deepEqual(parseVcsActionTargetKey(key), { environmentId, cwd }); expect(getVcsActionTargetKey({ environmentId: null, cwd })).toBeNull(); expect( getVcsActionTargetKey({ diff --git a/packages/client-runtime/src/state/vcsAction.ts b/packages/client-runtime/src/state/vcsAction.ts index f2cba39cf9..b2a38ff9bf 100644 --- a/packages/client-runtime/src/state/vcsAction.ts +++ b/packages/client-runtime/src/state/vcsAction.ts @@ -157,9 +157,10 @@ export const EMPTY_VCS_ACTION_STATE = Object.freeze({ const nowMs = (): number => DateTime.toEpochMillis(DateTime.nowUnsafe()); let nextLocalActionId = 0; -const decodeVcsActionTargetKey = Schema.decodeUnknownSync( - Schema.Tuple([EnvironmentId, Schema.String]), -); +const VcsActionTargetKey = Schema.Tuple([EnvironmentId, Schema.String]); +const VcsActionTargetKeyJson = Schema.fromJsonString(VcsActionTargetKey); +const decodeVcsActionTargetKey = Schema.decodeUnknownSync(VcsActionTargetKeyJson); +const encodeVcsActionTargetKey = Schema.encodeSync(VcsActionTargetKeyJson); export const vcsActionStateAtom = Atom.family((key: string) => { return Atom.make(EMPTY_VCS_ACTION_STATE).pipe( @@ -177,12 +178,12 @@ export function getVcsActionTargetKey(target: VcsActionTarget): string | null { if (target.environmentId === null || target.cwd === null) { return null; } - return JSON.stringify([target.environmentId, target.cwd]); + return encodeVcsActionTargetKey([target.environmentId, target.cwd]); } export function parseVcsActionTargetKey(key: string): ResolvedVcsActionTarget { try { - const [environmentId, cwd] = decodeVcsActionTargetKey(JSON.parse(key)); + const [environmentId, cwd] = decodeVcsActionTargetKey(key); return { environmentId, cwd }; } catch (cause) { throw new VcsActionTargetKeyParseError({ keyLength: key.length, cause }); @@ -232,7 +233,7 @@ export function createVcsActionTransportId( target: ResolvedVcsActionTarget, actionId: string, ): string { - const targetKey = JSON.stringify([target.environmentId, target.cwd]); + const targetKey = encodeVcsActionTargetKey([target.environmentId, target.cwd]); return `${targetKey.length}:${targetKey}${actionId}`; }