Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

[codex] Structure release metadata failures (#3467)

Julius Marmingecdd03591efb0
diff --git a/scripts/resolve-nightly-release.test.ts b/scripts/resolve-nightly-release.test.ts
index ecc94c57f..18d6a2a2e 100644
--- a/scripts/resolve-nightly-release.test.ts
+++ b/scripts/resolve-nightly-release.test.ts
@@ -1,7 +1,12 @@
+import * as NodeServices from "@effect/platform-node/NodeServices";
import { assert, it } from "@effect/vitest";
import * as Effect from "effect/Effect";
+import * as FileSystem from "effect/FileSystem";
+import * as Path from "effect/Path";
+import * as PlatformError from "effect/PlatformError";
import {
+ readDesktopBaseVersion,
resolveNightlyBaseVersion,
resolveNightlyReleaseMetadata,
resolveNightlyTargetVersion,
@@ -43,3 +48,49 @@ it("derives nightly metadata including the short commit sha in the release name"
},
);
});
+
+it.layer(NodeServices.layer)("readDesktopBaseVersion", (it) => {
+ it.effect("preserves desktop package read context and its platform cause", () =>
+ Effect.gen(function* () {
+ const fs = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const rootDir = yield* fs.makeTempDirectoryScoped({
+ prefix: "resolve-nightly-release-read-",
+ });
+ const packageJsonPath = path.join(rootDir, "apps/desktop/package.json");
+
+ const error = yield* readDesktopBaseVersion(rootDir).pipe(Effect.flip);
+
+ if (error._tag !== "NightlyReleaseDesktopPackageError") {
+ return assert.fail(`Unexpected error: ${error._tag}`);
+ }
+ assert.equal(error.operation, "read");
+ assert.equal(error.packageJsonPath, packageJsonPath);
+ assert.instanceOf(error.cause, PlatformError.PlatformError);
+ assert.notInclude(error.message, String((error.cause as Error).message));
+ }),
+ );
+
+ it.effect("preserves desktop package decode context and its schema cause", () =>
+ Effect.gen(function* () {
+ const fs = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const rootDir = yield* fs.makeTempDirectoryScoped({
+ prefix: "resolve-nightly-release-decode-",
+ });
+ const packageJsonPath = path.join(rootDir, "apps/desktop/package.json");
+ yield* fs.makeDirectory(path.dirname(packageJsonPath), { recursive: true });
+ yield* fs.writeFileString(packageJsonPath, "{");
+
+ const error = yield* readDesktopBaseVersion(rootDir).pipe(Effect.flip);
+
+ if (error._tag !== "NightlyReleaseDesktopPackageError") {
+ return assert.fail(`Unexpected error: ${error._tag}`);
+ }
+ assert.equal(error.operation, "decode");
+ assert.equal(error.packageJsonPath, packageJsonPath);
+ assert.ok(error.cause !== undefined);
+ assert.notInclude(error.message, String((error.cause as Error).message));
+ }),
+ );
+});
diff --git a/scripts/resolve-nightly-release.ts b/scripts/resolve-nightly-release.ts
index ae6bc323c..adad8c6f4 100644
--- a/scripts/resolve-nightly-release.ts
+++ b/scripts/resolve-nightly-release.ts
@@ -40,6 +40,19 @@ export class InvalidDesktopPackageVersionError extends Schema.TaggedErrorClass<I
}
}
+export class NightlyReleaseDesktopPackageError extends Schema.TaggedErrorClass<NightlyReleaseDesktopPackageError>()(
+ "NightlyReleaseDesktopPackageError",
+ {
+ operation: Schema.Literals(["read", "decode"]),
+ packageJsonPath: Schema.String,
+ cause: Schema.Defect(),
+ },
+) {
+ override get message(): string {
+ return `Failed to ${this.operation} desktop package metadata at ${this.packageJsonPath}.`;
+ }
+}
+
const RepoRoot = Effect.service(Path.Path).pipe(
Effect.flatMap((path) => path.fromFileUrl(new URL("..", import.meta.url))),
);
@@ -77,16 +90,33 @@ export const resolveNightlyReleaseMetadata = (
};
};
-const readDesktopBaseVersion = Effect.fn("readDesktopBaseVersion")(function* (
+export const readDesktopBaseVersion = Effect.fn("readDesktopBaseVersion")(function* (
rootDir: string | undefined,
) {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const workspaceRoot = rootDir ? path.resolve(rootDir) : yield* RepoRoot;
const packageJsonPath = path.join(workspaceRoot, "apps/desktop/package.json");
- const packageJson = yield* fs
- .readFileString(packageJsonPath)
- .pipe(Effect.flatMap(decodeDesktopPackageJson));
+ const packageJsonSource = yield* fs.readFileString(packageJsonPath).pipe(
+ Effect.mapError(
+ (cause) =>
+ new NightlyReleaseDesktopPackageError({
+ operation: "read",
+ packageJsonPath,
+ cause,
+ }),
+ ),
+ );
+ const packageJson = yield* decodeDesktopPackageJson(packageJsonSource).pipe(
+ Effect.mapError(
+ (cause) =>
+ new NightlyReleaseDesktopPackageError({
+ operation: "decode",
+ packageJsonPath,
+ cause,
+ }),
+ ),
+ );
return yield* resolveNightlyTargetVersion(packageJson.version);
});
diff --git a/scripts/resolve-previous-release-tag.test.ts b/scripts/resolve-previous-release-tag.test.ts
index ecf564c00..a9c4832c2 100644
--- a/scripts/resolve-previous-release-tag.test.ts
+++ b/scripts/resolve-previous-release-tag.test.ts
@@ -1,7 +1,33 @@
import { assert, it } from "@effect/vitest";
import * as Effect from "effect/Effect";
+import * as PlatformError from "effect/PlatformError";
+import * as Sink from "effect/Sink";
+import * as Stream from "effect/Stream";
+import { ChildProcessSpawner } from "effect/unstable/process";
-import { resolvePreviousReleaseTag } from "./resolve-previous-release-tag.ts";
+import { listGitTags, resolvePreviousReleaseTag } from "./resolve-previous-release-tag.ts";
+
+const encoder = new TextEncoder();
+
+function mockHandle(options: {
+ readonly exitCode: number;
+ readonly stdout?: string;
+ readonly stderr?: string;
+}) {
+ return ChildProcessSpawner.makeHandle({
+ pid: ChildProcessSpawner.ProcessId(1),
+ exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(options.exitCode)),
+ isRunning: Effect.succeed(false),
+ kill: () => Effect.void,
+ unref: Effect.succeed(Effect.void),
+ stdin: Sink.drain,
+ stdout: Stream.make(encoder.encode(options.stdout ?? "")),
+ stderr: Stream.make(encoder.encode(options.stderr ?? "")),
+ all: Stream.empty,
+ getInputFd: () => Sink.drain,
+ getOutputFd: () => Stream.empty,
+ });
+}
it.effect("selects the latest earlier stable tag and ignores nightlies", () =>
Effect.gen(function* () {
@@ -37,3 +63,68 @@ it.effect("reports the invalid tag with its release channel", () =>
assert.equal(error.message, "Invalid nightly release tag 'v1.2.0'.");
}),
);
+
+it.effect("preserves git tag spawn context and the exact platform cause", () => {
+ const cause = PlatformError.systemError({
+ _tag: "NotFound",
+ module: "ChildProcess",
+ method: "spawn",
+ description: "git was not found",
+ });
+
+ return Effect.gen(function* () {
+ const error = yield* listGitTags("/repo").pipe(
+ Effect.scoped,
+ Effect.provideService(
+ ChildProcessSpawner.ChildProcessSpawner,
+ ChildProcessSpawner.make(() => Effect.fail(cause)),
+ ),
+ Effect.flip,
+ );
+
+ if (error._tag !== "ReleaseTagListProcessError") {
+ return assert.fail(`Unexpected error: ${error._tag}`);
+ }
+ assert.equal(error.operation, "spawn");
+ assert.equal(error.executable, "git");
+ assert.equal(error.argumentCount, 2);
+ assert.equal(error.cwd, "/repo");
+ assert.strictEqual(error.cause, cause);
+ assert.notProperty(error, "args");
+ assert.notInclude(error.message, cause.message);
+ });
+});
+
+it.effect("reports git tag non-zero exits without manufacturing a cause", () =>
+ Effect.gen(function* () {
+ const error = yield* listGitTags("/repo").pipe(
+ Effect.scoped,
+ Effect.provideService(
+ ChildProcessSpawner.ChildProcessSpawner,
+ ChildProcessSpawner.make(() =>
+ Effect.succeed(
+ mockHandle({
+ exitCode: 17,
+ stdout: "v1.2.3\n",
+ stderr: "fatal: repository unavailable\n",
+ }),
+ ),
+ ),
+ ),
+ Effect.flip,
+ );
+
+ if (error._tag !== "ReleaseTagListProcessExitError") {
+ return assert.fail(`Unexpected error: ${error._tag}`);
+ }
+ assert.equal(error.executable, "git");
+ assert.equal(error.argumentCount, 2);
+ assert.equal(error.cwd, "/repo");
+ assert.equal(error.exitCode, 17);
+ assert.equal(error.stdoutLength, 7);
+ assert.equal(error.stderrLength, 30);
+ assert.notProperty(error, "cause");
+ assert.notProperty(error, "stdout");
+ assert.notProperty(error, "stderr");
+ }),
+);
diff --git a/scripts/resolve-previous-release-tag.ts b/scripts/resolve-previous-release-tag.ts
index 8b1f1fc96..83b6e65d1 100644
--- a/scripts/resolve-previous-release-tag.ts
+++ b/scripts/resolve-previous-release-tag.ts
@@ -2,7 +2,6 @@
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
import * as NodeServices from "@effect/platform-node/NodeServices";
-import * as Array from "effect/Array";
import * as Config from "effect/Config";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
@@ -27,6 +26,39 @@ export class InvalidReleaseTagError extends Schema.TaggedErrorClass<InvalidRelea
}
}
+const releaseTagListProcessContext = {
+ executable: Schema.Literal("git"),
+ argumentCount: Schema.Number,
+ cwd: Schema.String,
+};
+
+export class ReleaseTagListProcessError extends Schema.TaggedErrorClass<ReleaseTagListProcessError>()(
+ "ReleaseTagListProcessError",
+ {
+ ...releaseTagListProcessContext,
+ operation: Schema.Literals(["spawn", "communicate", "wait-for-exit"]),
+ cause: Schema.Defect(),
+ },
+) {
+ override get message(): string {
+ return `Failed to list release tags during process operation "${this.operation}".`;
+ }
+}
+
+export class ReleaseTagListProcessExitError extends Schema.TaggedErrorClass<ReleaseTagListProcessExitError>()(
+ "ReleaseTagListProcessExitError",
+ {
+ ...releaseTagListProcessContext,
+ exitCode: Schema.Number,
+ stdoutLength: Schema.Number,
+ stderrLength: Schema.Number,
+ },
+) {
+ override get message(): string {
+ return `Release tag listing exited with code ${this.exitCode}.`;
+ }
+}
+
interface StableVersion {
readonly major: number;
readonly minor: number;
@@ -172,20 +204,80 @@ export const resolvePreviousReleaseTag = (
return candidates[0]?.tag;
});
-const listGitTags = Effect.fn("listGitTags")(function* () {
- const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
- const child = yield* spawner.spawn(ChildProcess.make("git", ["tag", "--list"]));
- const tags = yield* child.stdout.pipe(
+const collectStreamAsString = <E>(stream: Stream.Stream<Uint8Array, E>): Effect.Effect<string, E> =>
+ stream.pipe(
Stream.decodeText(),
Stream.runFold(
() => "",
(acc, chunk) => acc + chunk,
),
- Effect.map(String.split(/\r?\n/)),
- Effect.map(Array.map(String.trim)),
- Effect.map(Array.filter(String.isNonEmpty)),
);
- return tags;
+
+export const listGitTags = Effect.fn("listGitTags")(function* (cwd = process.cwd()) {
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
+ const args = ["tag", "--list"] as const;
+ const context = {
+ executable: "git",
+ argumentCount: args.length,
+ cwd,
+ } as const;
+ const child = yield* spawner.spawn(ChildProcess.make("git", args, { cwd })).pipe(
+ Effect.mapError(
+ (cause) =>
+ new ReleaseTagListProcessError({
+ ...context,
+ operation: "spawn",
+ cause,
+ }),
+ ),
+ );
+ const [stdout, stderr, exitCode] = yield* Effect.all(
+ [
+ collectStreamAsString(child.stdout).pipe(
+ Effect.mapError(
+ (cause) =>
+ new ReleaseTagListProcessError({
+ ...context,
+ operation: "communicate",
+ cause,
+ }),
+ ),
+ ),
+ collectStreamAsString(child.stderr).pipe(
+ Effect.mapError(
+ (cause) =>
+ new ReleaseTagListProcessError({
+ ...context,
+ operation: "communicate",
+ cause,
+ }),
+ ),
+ ),
+ child.exitCode.pipe(
+ Effect.map(Number),
+ Effect.mapError(
+ (cause) =>
+ new ReleaseTagListProcessError({
+ ...context,
+ operation: "wait-for-exit",
+ cause,
+ }),
+ ),
+ ),
+ ],
+ { concurrency: "unbounded" },
+ );
+
+ if (exitCode !== 0) {
+ return yield* new ReleaseTagListProcessExitError({
+ ...context,
+ exitCode,
+ stdoutLength: stdout.length,
+ stderrLength: stderr.length,
+ });
+ }
+
+ return stdout.split(/\r?\n/).map(String.trim).filter(String.isNonEmpty);
});
const writeOutput = Effect.fn("writeOutput")(function* (