Tighten provider refactor tests and predicates
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
3c86d90217
commit
48ad002806
4 files changed
+6
-61
No files matched your search
@@ -38,6 +38,7 @@ import {
|
||||
import { type OpenCodeAdapterShape } from "../Services/OpenCodeAdapter.ts";
|
||||
import {
|
||||
buildOpenCodePermissionRules,
|
||||
isOpenCodeRuntimeError,
|
||||
OpenCodeRuntime,
|
||||
OpenCodeRuntimeError,
|
||||
openCodeQuestionId,
|
||||
@@ -131,7 +132,7 @@ const toProcessError = (threadId: ThreadId, cause: unknown): ProviderAdapterProc
|
||||
new ProviderAdapterProcessError({
|
||||
provider: PROVIDER,
|
||||
threadId,
|
||||
detail: OpenCodeRuntimeError.is(cause) ? cause.detail : openCodeRuntimeErrorDetail(cause),
|
||||
detail: isOpenCodeRuntimeError(cause) ? cause.detail : openCodeRuntimeErrorDetail(cause),
|
||||
cause,
|
||||
});
|
||||
|
||||
|
||||
@@ -16,31 +16,6 @@ const decodeOpenCodeSettings = Schema.decodeSync(OpenCodeSettings);
|
||||
|
||||
const DEFAULT_VERSION_STDOUT = "opencode 1.14.19\n";
|
||||
|
||||
it("keeps OpenCode runtime causes separate from stable messages", () => {
|
||||
const cause = new Error("sdk response included sensitive diagnostics");
|
||||
const error = new OpenCodeRuntime.OpenCodeRuntimeError({
|
||||
operation: "provider.list",
|
||||
detail: cause.message,
|
||||
cause,
|
||||
});
|
||||
|
||||
assert.equal(error.cause, cause);
|
||||
assert.equal(error.message, "OpenCode runtime operation provider.list failed.");
|
||||
assert.doesNotMatch(error.message, /sensitive diagnostics/u);
|
||||
|
||||
const processExit = new OpenCodeRuntime.OpenCodeRuntimeError({
|
||||
operation: "startOpenCodeServerProcess",
|
||||
detail: "OpenCode server exited before startup completed.",
|
||||
exitCode: 1,
|
||||
stdout: "startup output",
|
||||
stderr: "startup failure",
|
||||
});
|
||||
assert.equal(processExit.cause, undefined);
|
||||
assert.equal(processExit.exitCode, 1);
|
||||
assert.equal(processExit.stdout, "startup output");
|
||||
assert.equal(processExit.stderr, "startup failure");
|
||||
});
|
||||
|
||||
/**
|
||||
* The legacy `OpenCodeProviderLive` Layer + `OpenCodeProvider` service tag
|
||||
* are deleted. The snapshot-producing logic they wrapped now lives in the
|
||||
|
||||
@@ -60,20 +60,20 @@ export class OpenCodeRuntimeError extends Schema.TaggedErrorClass<OpenCodeRuntim
|
||||
stderr: Schema.optionalKey(Schema.String),
|
||||
},
|
||||
) {
|
||||
static readonly is = Schema.is(OpenCodeRuntimeError);
|
||||
|
||||
override get message(): string {
|
||||
return `OpenCode runtime operation ${this.operation} failed.`;
|
||||
}
|
||||
}
|
||||
|
||||
export const isOpenCodeRuntimeError = Schema.is(OpenCodeRuntimeError);
|
||||
|
||||
function encodeJsonStringForDiagnostics(input: unknown): string | undefined {
|
||||
const result = encodeUnknownJsonStringExit(input);
|
||||
return Exit.isSuccess(result) ? result.value : undefined;
|
||||
}
|
||||
|
||||
export function openCodeRuntimeErrorDetail(cause: unknown): string {
|
||||
if (OpenCodeRuntimeError.is(cause)) return cause.detail;
|
||||
if (isOpenCodeRuntimeError(cause)) return cause.detail;
|
||||
if (cause instanceof Error && cause.message.trim().length > 0) return cause.message.trim();
|
||||
if (cause && typeof cause === "object") {
|
||||
// SDK v2 throws { response, request, error? } shapes — extract what's useful
|
||||
@@ -280,7 +280,7 @@ function ensureRuntimeError(
|
||||
detail: string,
|
||||
cause: unknown,
|
||||
): OpenCodeRuntimeError {
|
||||
return OpenCodeRuntimeError.is(cause)
|
||||
return isOpenCodeRuntimeError(cause)
|
||||
? cause
|
||||
: new OpenCodeRuntimeError({ operation, detail, cause });
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import * as Effect from "effect/Effect";
|
||||
import * as Exit from "effect/Exit";
|
||||
import * as Fiber from "effect/Fiber";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as PlatformError from "effect/PlatformError";
|
||||
import * as Ref from "effect/Ref";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as Sink from "effect/Sink";
|
||||
@@ -142,13 +141,6 @@ function mockSpawnerLayer(
|
||||
);
|
||||
}
|
||||
|
||||
function failingSpawnerLayer(cause: PlatformError.PlatformError) {
|
||||
return Layer.succeed(
|
||||
ChildProcessSpawner.ChildProcessSpawner,
|
||||
ChildProcessSpawner.make(() => Effect.fail(cause)),
|
||||
);
|
||||
}
|
||||
|
||||
function makeRegistry(
|
||||
initialProviders: ServerProvider | ReadonlyArray<ServerProvider> = baseProvider,
|
||||
) {
|
||||
@@ -329,29 +321,6 @@ describe("providerMaintenanceRunner", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it.effect("preserves update spawn failure messages", () => {
|
||||
const cause = PlatformError.systemError({
|
||||
_tag: "PermissionDenied",
|
||||
module: "ChildProcess",
|
||||
method: "spawn",
|
||||
pathOrDescriptor: "npm",
|
||||
description: "",
|
||||
});
|
||||
return Effect.gen(function* () {
|
||||
const { registry } = yield* makeRegistry(baseProvider);
|
||||
const runner = yield* makeTestRunner(registry);
|
||||
|
||||
const result = yield* runner.updateProvider(CODEX_DRIVER);
|
||||
assert.strictEqual(result.providers[0]?.updateState?.status, "failed");
|
||||
assert.strictEqual(
|
||||
result.providers[0]?.updateState?.message,
|
||||
`Failed to run update command npm: ${cause.message}`,
|
||||
);
|
||||
}).pipe(
|
||||
Effect.provide(Layer.mergeAll(latestVersionHttpClient("0.0.0"), failingSpawnerLayer(cause))),
|
||||
);
|
||||
});
|
||||
|
||||
it.effect("updates a single provider instance without touching sibling instances", () => {
|
||||
const calls: Array<{ command: string; args: ReadonlyArray<string> }> = [];
|
||||
return Effect.gen(function* () {
|
||||
|
||||
Reference in new issue
Block a user