Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be2bb4f4c3 | ||
|
|
3907e5e8c5 | ||
|
|
c8989287d3 | ||
|
|
8ec1958540 | ||
|
|
86650a03bb | ||
|
|
2742cd8a0c | ||
|
|
79affb0e06 | ||
|
|
74dbb98a40 |
No files matched your search
@@ -9,7 +9,17 @@ import {
|
||||
type OrchestrationEvent,
|
||||
type OrchestrationThread,
|
||||
} from "@t3tools/contracts";
|
||||
import { Effect, Exit, Layer, ManagedRuntime, Option, Schedule, Scope, Stream } from "effect";
|
||||
import {
|
||||
Effect,
|
||||
Exit,
|
||||
Layer,
|
||||
ManagedRuntime,
|
||||
Option,
|
||||
Schedule,
|
||||
Schema,
|
||||
Scope,
|
||||
Stream,
|
||||
} from "effect";
|
||||
|
||||
import { CheckpointStoreLive } from "../src/checkpointing/Layers/CheckpointStore.ts";
|
||||
import { CheckpointStore } from "../src/checkpointing/Services/CheckpointStore.ts";
|
||||
@@ -75,20 +85,27 @@ export function gitShowFileAtRef(cwd: string, ref: string, filePath: string): st
|
||||
return runGit(cwd, ["show", `${ref}:${filePath}`]);
|
||||
}
|
||||
|
||||
function waitFor<A>(
|
||||
read: Effect.Effect<A, unknown>,
|
||||
class WaitForTimeoutError extends Schema.TaggedErrorClass<WaitForTimeoutError>()(
|
||||
"WaitForTimeoutError",
|
||||
{
|
||||
description: Schema.String,
|
||||
},
|
||||
) {}
|
||||
|
||||
function waitFor<A, E>(
|
||||
read: Effect.Effect<A, E>,
|
||||
predicate: (value: A) => boolean,
|
||||
description: string,
|
||||
timeoutMs?: number,
|
||||
): Effect.Effect<A, never>;
|
||||
function waitFor<A, B extends A>(
|
||||
read: Effect.Effect<A, unknown>,
|
||||
function waitFor<A, B extends A, E>(
|
||||
read: Effect.Effect<A, E>,
|
||||
predicate: (value: A) => value is B,
|
||||
description: string,
|
||||
timeoutMs?: number,
|
||||
): Effect.Effect<B, never>;
|
||||
function waitFor<A>(
|
||||
read: Effect.Effect<A, unknown>,
|
||||
function waitFor<A, E>(
|
||||
read: Effect.Effect<A, E>,
|
||||
predicate: (value: A) => boolean,
|
||||
description: string,
|
||||
timeoutMs = 3000,
|
||||
@@ -106,12 +123,26 @@ function waitFor<A>(
|
||||
while: (error) => error === RETRY_SIGNAL,
|
||||
}),
|
||||
Effect.mapError((error) =>
|
||||
error === RETRY_SIGNAL ? new Error(`Timed out waiting for ${description}.`) : error,
|
||||
error === RETRY_SIGNAL ? new WaitForTimeoutError({ description }) : error,
|
||||
),
|
||||
Effect.orDie,
|
||||
);
|
||||
}
|
||||
|
||||
class OrchestrationHarnessRuntimeError extends Schema.TaggedErrorClass<OrchestrationHarnessRuntimeError>()(
|
||||
"OrchestrationHarnessRuntimeError",
|
||||
{
|
||||
operation: Schema.String,
|
||||
cause: Schema.optional(Schema.Defect),
|
||||
},
|
||||
) {}
|
||||
|
||||
const tryRuntimePromise = <A>(operation: string, run: () => Promise<A>) =>
|
||||
Effect.tryPromise({
|
||||
try: run,
|
||||
catch: (cause) => new OrchestrationHarnessRuntimeError({ operation, cause }),
|
||||
});
|
||||
|
||||
export interface OrchestrationIntegrationHarness {
|
||||
readonly rootDir: string;
|
||||
readonly workspaceDir: string;
|
||||
@@ -152,8 +183,7 @@ export interface OrchestrationIntegrationHarness {
|
||||
}
|
||||
|
||||
export const makeOrchestrationIntegrationHarness = Effect.gen(function* () {
|
||||
const sleep = (ms: number) =>
|
||||
Effect.promise(() => new Promise<void>((resolve) => setTimeout(resolve, ms)));
|
||||
const sleep = (ms: number) => Effect.sleep(ms);
|
||||
const adapterHarness = yield* makeTestProviderAdapterHarness;
|
||||
|
||||
const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "t3-orchestration-integration-"));
|
||||
@@ -215,30 +245,34 @@ export const makeOrchestrationIntegrationHarness = Effect.gen(function* () {
|
||||
);
|
||||
|
||||
const runtime = ManagedRuntime.make(layer);
|
||||
const engine = yield* Effect.promise(() =>
|
||||
const engine = yield* tryRuntimePromise("load OrchestrationEngine service", () =>
|
||||
runtime.runPromise(Effect.service(OrchestrationEngineService)),
|
||||
);
|
||||
const reactor = yield* Effect.promise(() =>
|
||||
).pipe(Effect.orDie);
|
||||
const reactor = yield* tryRuntimePromise("load OrchestrationReactor service", () =>
|
||||
runtime.runPromise(Effect.service(OrchestrationReactor)),
|
||||
);
|
||||
const snapshotQuery = yield* Effect.promise(() =>
|
||||
).pipe(Effect.orDie);
|
||||
const snapshotQuery = yield* tryRuntimePromise("load ProjectionSnapshotQuery service", () =>
|
||||
runtime.runPromise(Effect.service(ProjectionSnapshotQuery)),
|
||||
);
|
||||
const providerService = yield* Effect.promise(() =>
|
||||
).pipe(Effect.orDie);
|
||||
const providerService = yield* tryRuntimePromise("load ProviderService service", () =>
|
||||
runtime.runPromise(Effect.service(ProviderService)),
|
||||
);
|
||||
const checkpointStore = yield* Effect.promise(() =>
|
||||
).pipe(Effect.orDie);
|
||||
const checkpointStore = yield* tryRuntimePromise("load CheckpointStore service", () =>
|
||||
runtime.runPromise(Effect.service(CheckpointStore)),
|
||||
);
|
||||
const checkpointRepository = yield* Effect.promise(() =>
|
||||
runtime.runPromise(Effect.service(ProjectionCheckpointRepository)),
|
||||
);
|
||||
const pendingApprovalRepository = yield* Effect.promise(() =>
|
||||
runtime.runPromise(Effect.service(ProjectionPendingApprovalRepository)),
|
||||
);
|
||||
).pipe(Effect.orDie);
|
||||
const checkpointRepository = yield* tryRuntimePromise(
|
||||
"load ProjectionCheckpointRepository service",
|
||||
() => runtime.runPromise(Effect.service(ProjectionCheckpointRepository)),
|
||||
).pipe(Effect.orDie);
|
||||
const pendingApprovalRepository = yield* tryRuntimePromise(
|
||||
"load ProjectionPendingApprovalRepository service",
|
||||
() => runtime.runPromise(Effect.service(ProjectionPendingApprovalRepository)),
|
||||
).pipe(Effect.orDie);
|
||||
|
||||
const scope = yield* Effect.promise(() => Effect.runPromise(Scope.make("sequential")));
|
||||
yield* Effect.promise(() => runtime.runPromise(reactor.start.pipe(Scope.provide(scope))));
|
||||
const scope = yield* Scope.make("sequential");
|
||||
yield* tryRuntimePromise("start OrchestrationReactor", () =>
|
||||
runtime.runPromise(reactor.start.pipe(Scope.provide(scope))),
|
||||
).pipe(Effect.orDie);
|
||||
yield* sleep(10);
|
||||
|
||||
const waitForThread: OrchestrationIntegrationHarness["waitForThread"] = (
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import { Effect, Exit, Option } from "effect";
|
||||
import { Effect, Option, Schema } from "effect";
|
||||
|
||||
import type { TestTurnResponse } from "./TestProviderAdapter.integration.ts";
|
||||
import {
|
||||
@@ -45,8 +45,14 @@ function nowIso() {
|
||||
return new Date().toISOString();
|
||||
}
|
||||
|
||||
const sleep = (ms: number) =>
|
||||
Effect.promise(() => new Promise<void>((resolve) => setTimeout(resolve, ms)));
|
||||
class IntegrationWaitTimeoutError extends Schema.TaggedErrorClass<IntegrationWaitTimeoutError>()(
|
||||
"IntegrationWaitTimeoutError",
|
||||
{
|
||||
description: Schema.String,
|
||||
},
|
||||
) {}
|
||||
|
||||
const sleep = (ms: number) => Effect.sleep(ms);
|
||||
|
||||
function waitForSync<A>(
|
||||
read: () => A,
|
||||
@@ -63,7 +69,7 @@ function waitForSync<A>(
|
||||
return value;
|
||||
}
|
||||
if (Date.now() >= deadline) {
|
||||
return yield* Effect.die(new Error(`Timed out waiting for ${description}.`));
|
||||
return yield* Effect.die(new IntegrationWaitTimeoutError({ description }));
|
||||
}
|
||||
yield* sleep(10);
|
||||
}
|
||||
@@ -133,24 +139,6 @@ const startTurn = (input: {
|
||||
createdAt: nowIso(),
|
||||
});
|
||||
|
||||
it.live("always removes integration temp dirs when shutdown fails", () =>
|
||||
Effect.gen(function* () {
|
||||
const harness = yield* makeOrchestrationIntegrationHarness;
|
||||
const rootDir = harness.rootDir;
|
||||
const originalStopAll = harness.providerService.stopAll.bind(harness.providerService);
|
||||
|
||||
(
|
||||
harness.providerService as unknown as {
|
||||
stopAll: typeof harness.providerService.stopAll;
|
||||
}
|
||||
).stopAll = () => originalStopAll().pipe(Effect.andThen(Effect.fail(new Error("boom"))));
|
||||
|
||||
const disposeExit = yield* Effect.exit(harness.dispose);
|
||||
assert.equal(Exit.isFailure(disposeExit), true);
|
||||
assert.equal(fs.existsSync(rootDir), false);
|
||||
}),
|
||||
);
|
||||
|
||||
it.live("runs a single turn end-to-end and persists checkpoint state in sqlite + git", () =>
|
||||
withHarness((harness) =>
|
||||
Effect.gen(function* () {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
|
||||
import { Effect, FileSystem, Layer, Option, Path, Stream } from "effect";
|
||||
import { Effect, FileSystem, Layer, Option, Path, Schema, Stream } from "effect";
|
||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
|
||||
import { TextGenerationError } from "../Errors.ts";
|
||||
@@ -40,7 +40,7 @@ function normalizeCodexError(
|
||||
error: unknown,
|
||||
fallback: string,
|
||||
): TextGenerationError {
|
||||
if (error instanceof TextGenerationError) {
|
||||
if (Schema.is(TextGenerationError)(error)) {
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -129,9 +129,9 @@ const makeCodexTextGeneration = Effect.gen(function* () {
|
||||
const path = yield* Path.Path;
|
||||
const commandSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
||||
|
||||
const readStreamAsString = (
|
||||
const readStreamAsString = <E>(
|
||||
operation: string,
|
||||
stream: Stream.Stream<Uint8Array, unknown>,
|
||||
stream: Stream.Stream<Uint8Array, E>,
|
||||
): Effect.Effect<string, TextGenerationError> =>
|
||||
Effect.gen(function* () {
|
||||
let text = "";
|
||||
|
||||
@@ -6,7 +6,7 @@ import { it } from "@effect/vitest";
|
||||
import { Effect, FileSystem, Layer, PlatformError, Scope } from "effect";
|
||||
import { expect } from "vitest";
|
||||
|
||||
import { GitHubCliError, TextGenerationError } from "../Errors.ts";
|
||||
import { GitCommandError, GitHubCliError, TextGenerationError } from "../Errors.ts";
|
||||
import { type GitManagerShape } from "../Services/GitManager.ts";
|
||||
import {
|
||||
type GitHubCliShape,
|
||||
@@ -23,7 +23,7 @@ interface FakeGhScenario {
|
||||
prListSequence?: string[];
|
||||
createdPrUrl?: string;
|
||||
defaultBranch?: string;
|
||||
failWith?: Error;
|
||||
failWith?: GitHubCliError;
|
||||
}
|
||||
|
||||
interface FakeGitTextGeneration {
|
||||
@@ -32,7 +32,7 @@ interface FakeGitTextGeneration {
|
||||
branch: string | null;
|
||||
stagedSummary: string;
|
||||
stagedPatch: string;
|
||||
}) => Effect.Effect<{ subject: string; body: string }, unknown>;
|
||||
}) => Effect.Effect<{ subject: string; body: string }, TextGenerationError>;
|
||||
generatePrContent: (input: {
|
||||
cwd: string;
|
||||
baseBranch: string;
|
||||
@@ -40,7 +40,7 @@ interface FakeGitTextGeneration {
|
||||
commitSummary: string;
|
||||
diffSummary: string;
|
||||
diffPatch: string;
|
||||
}) => Effect.Effect<{ title: string; body: string }, unknown>;
|
||||
}) => Effect.Effect<{ title: string; body: string }, TextGenerationError>;
|
||||
}
|
||||
|
||||
function makeTempDir(
|
||||
@@ -58,7 +58,7 @@ function runGit(
|
||||
allowNonZeroExit = false,
|
||||
): Effect.Effect<
|
||||
{ readonly code: number; readonly stdout: string; readonly stderr: string },
|
||||
unknown,
|
||||
GitCommandError,
|
||||
GitService
|
||||
> {
|
||||
return Effect.gen(function* () {
|
||||
@@ -74,7 +74,7 @@ function runGit(
|
||||
|
||||
function initRepo(
|
||||
cwd: string,
|
||||
): Effect.Effect<void, unknown, FileSystem.FileSystem | Scope.Scope | GitService> {
|
||||
): Effect.Effect<void, PlatformError.PlatformError | GitCommandError, FileSystem.FileSystem | Scope.Scope | GitService> {
|
||||
return Effect.gen(function* () {
|
||||
const fs = yield* FileSystem.FileSystem;
|
||||
yield* runGit(cwd, ["init", "--initial-branch=main"]);
|
||||
@@ -88,7 +88,7 @@ function initRepo(
|
||||
|
||||
function createBareRemote(): Effect.Effect<
|
||||
string,
|
||||
unknown,
|
||||
PlatformError.PlatformError | GitCommandError,
|
||||
FileSystem.FileSystem | Scope.Scope | GitService
|
||||
> {
|
||||
return Effect.gen(function* () {
|
||||
@@ -139,34 +139,6 @@ function createTextGeneration(overrides: Partial<FakeGitTextGeneration> = {}): T
|
||||
};
|
||||
}
|
||||
|
||||
const normalizeGhError = (error: Error): GitHubCliError => {
|
||||
if (error.message.includes("Command not found: gh")) {
|
||||
return new GitHubCliError({
|
||||
operation: "execute",
|
||||
detail: "GitHub CLI (`gh`) is required but not available on PATH.",
|
||||
cause: error,
|
||||
});
|
||||
}
|
||||
const lower = error.message.toLowerCase();
|
||||
if (
|
||||
lower.includes("authentication failed") ||
|
||||
lower.includes("not logged in") ||
|
||||
lower.includes("gh auth login") ||
|
||||
lower.includes("no oauth token")
|
||||
) {
|
||||
return new GitHubCliError({
|
||||
operation: "execute",
|
||||
detail: "GitHub CLI is not authenticated. Run `gh auth login` and retry.",
|
||||
cause: error,
|
||||
});
|
||||
}
|
||||
return new GitHubCliError({
|
||||
operation: "execute",
|
||||
detail: error.message,
|
||||
cause: error,
|
||||
});
|
||||
};
|
||||
|
||||
function createGitHubCliWithFakeGh(scenario: FakeGhScenario = {}): {
|
||||
service: GitHubCliShape;
|
||||
ghCalls: string[];
|
||||
@@ -179,7 +151,7 @@ function createGitHubCliWithFakeGh(scenario: FakeGhScenario = {}): {
|
||||
ghCalls.push(args.join(" "));
|
||||
|
||||
if (scenario.failWith) {
|
||||
return Effect.fail(normalizeGhError(scenario.failWith));
|
||||
return Effect.fail(scenario.failWith);
|
||||
}
|
||||
|
||||
if (args[0] === "pr" && args[1] === "list") {
|
||||
@@ -373,7 +345,10 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
|
||||
const { manager } = yield* makeManager({
|
||||
ghScenario: {
|
||||
failWith: new Error("Command not found: gh"),
|
||||
failWith: new GitHubCliError({
|
||||
operation: "execute",
|
||||
detail: "GitHub CLI (`gh`) is required but not available on PATH.",
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -600,7 +575,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
action: "commit_push",
|
||||
}).pipe(
|
||||
Effect.flip,
|
||||
Effect.map((error) => (error instanceof Error ? error.message : String(error))),
|
||||
Effect.map((error) => error.message),
|
||||
);
|
||||
expect(errorMessage).toContain("detached HEAD");
|
||||
}),
|
||||
@@ -617,7 +592,10 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
|
||||
const { manager } = yield* makeManager({
|
||||
ghScenario: {
|
||||
failWith: new Error("Command not found: gh"),
|
||||
failWith: new GitHubCliError({
|
||||
operation: "execute",
|
||||
detail: "GitHub CLI (`gh`) is required but not available on PATH.",
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -626,7 +604,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
action: "commit_push_pr",
|
||||
}).pipe(
|
||||
Effect.flip,
|
||||
Effect.map((error) => (error instanceof Error ? error.message : String(error))),
|
||||
Effect.map((error) => error.message),
|
||||
);
|
||||
expect(errorMessage).toContain("GitHub CLI (`gh`) is required");
|
||||
}),
|
||||
@@ -643,7 +621,10 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
|
||||
const { manager } = yield* makeManager({
|
||||
ghScenario: {
|
||||
failWith: new Error("authentication failed"),
|
||||
failWith: new GitHubCliError({
|
||||
operation: "execute",
|
||||
detail: "GitHub CLI is not authenticated. Run `gh auth login` and retry.",
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -652,7 +633,7 @@ it.layer(GitManagerTestLayer)("GitManager", (it) => {
|
||||
action: "commit_push_pr",
|
||||
}).pipe(
|
||||
Effect.flip,
|
||||
Effect.map((error) => (error instanceof Error ? error.message : String(error))),
|
||||
Effect.map((error) => error.message),
|
||||
);
|
||||
expect(errorMessage).toContain("gh auth login");
|
||||
}),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { it, assert } from "@effect/vitest";
|
||||
import { Effect, Layer } from "effect";
|
||||
import { Effect, Layer, Schema } from "effect";
|
||||
|
||||
import { GitCommandError } from "../Errors.ts";
|
||||
import { GitServiceLive } from "./GitService.ts";
|
||||
@@ -50,7 +50,7 @@ layer("GitServiceLive", (it) => {
|
||||
|
||||
assert.equal(result._tag, "Failure");
|
||||
if (result._tag === "Failure") {
|
||||
assert.ok(result.failure instanceof GitCommandError);
|
||||
assert.ok(Schema.is(GitCommandError)(result.failure));
|
||||
assert.equal(result.failure.operation, "GitProcess.test.failOnNonZero");
|
||||
assert.equal(result.failure.command, "git rev-parse --verify __definitely_missing_ref__");
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* @module GitServiceLive
|
||||
*/
|
||||
import { Effect, Layer, Option, Stream } from "effect";
|
||||
import { Effect, Layer, Option, Schema, Stream } from "effect";
|
||||
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
|
||||
import { GitCommandError } from "../Errors.ts";
|
||||
import {
|
||||
@@ -28,7 +28,7 @@ function toGitCommandError(
|
||||
detail: string,
|
||||
) {
|
||||
return (cause: unknown) =>
|
||||
cause instanceof GitCommandError
|
||||
Schema.is(GitCommandError)(cause)
|
||||
? cause
|
||||
: new GitCommandError({
|
||||
operation: input.operation,
|
||||
@@ -39,9 +39,9 @@ function toGitCommandError(
|
||||
});
|
||||
}
|
||||
|
||||
const collectOutput = Effect.fn(function* (
|
||||
const collectOutput = Effect.fn(function* <E>(
|
||||
input: Pick<ExecuteGitInput, "operation" | "cwd" | "args">,
|
||||
stream: Stream.Stream<Uint8Array, unknown>,
|
||||
stream: Stream.Stream<Uint8Array, E>,
|
||||
maxOutputBytes: number,
|
||||
): Effect.fn.Return<string, GitCommandError> {
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
@@ -211,13 +211,7 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
|
||||
});
|
||||
|
||||
assert.isTrue(configState.keybindings.some((entry) => entry.command === "terminal.toggle"));
|
||||
assert.isFalse(
|
||||
configState.keybindings.some(
|
||||
(entry) =>
|
||||
// @ts-expect-error - invalid command
|
||||
entry.command === "invalid.command",
|
||||
),
|
||||
);
|
||||
assert.isFalse(configState.keybindings.some((entry) => String(entry.command) === "invalid.command"));
|
||||
assert.deepEqual(configState.issues, [
|
||||
{
|
||||
kind: "keybindings.invalid-entry",
|
||||
|
||||
@@ -117,7 +117,10 @@ export const launchDetached = (launch: EditorLaunch) =>
|
||||
});
|
||||
|
||||
const make = Effect.gen(function* () {
|
||||
const open = yield* Effect.promise(() => import("open"));
|
||||
const open = yield* Effect.tryPromise({
|
||||
try: () => import("open"),
|
||||
catch: (cause) => new OpenError({ message: "failed to load browser opener", cause }),
|
||||
});
|
||||
|
||||
return {
|
||||
openBrowser: (target) =>
|
||||
|
||||
@@ -40,9 +40,10 @@ function decodeForEvent<A>(
|
||||
eventType: OrchestrationEvent["type"],
|
||||
field: string,
|
||||
): Effect.Effect<A, OrchestrationProjectorDecodeError> {
|
||||
return Schema.decodeUnknownEffect(schema)(value).pipe(
|
||||
Effect.mapError(toProjectorDecodeError(`${eventType}:${field}`)),
|
||||
) as Effect.Effect<A, OrchestrationProjectorDecodeError>;
|
||||
return Effect.try({
|
||||
try: () => Schema.decodeUnknownSync(schema as any)(value),
|
||||
catch: (error) => toProjectorDecodeError(`${eventType}:${field}`)(error as Schema.SchemaError),
|
||||
});
|
||||
}
|
||||
|
||||
function retainThreadMessagesAfterRevert(
|
||||
|
||||
@@ -17,6 +17,7 @@ import { ProviderCommandReactorLive } from "./orchestration/Layers/ProviderComma
|
||||
import { OrchestrationProjectionPipelineLive } from "./orchestration/Layers/ProjectionPipeline";
|
||||
import { OrchestrationProjectionSnapshotQueryLive } from "./orchestration/Layers/ProjectionSnapshotQuery";
|
||||
import { ProviderRuntimeIngestionLive } from "./orchestration/Layers/ProviderRuntimeIngestion";
|
||||
import { ProviderUnsupportedError } from "./provider/Errors";
|
||||
import { makeCodexAdapterLive } from "./provider/Layers/CodexAdapter";
|
||||
import { ProviderAdapterRegistryLive } from "./provider/Layers/ProviderAdapterRegistry";
|
||||
import { makeProviderServiceLive } from "./provider/Layers/ProviderService";
|
||||
@@ -35,7 +36,7 @@ import { NodePtyAdapterLive } from "./terminal/Layers/NodePTY";
|
||||
|
||||
export function makeServerProviderLayer(): Layer.Layer<
|
||||
ProviderService,
|
||||
unknown,
|
||||
ProviderUnsupportedError,
|
||||
SqlClient.SqlClient | ServerConfig
|
||||
> {
|
||||
return Effect.gen(function* () {
|
||||
|
||||
@@ -323,14 +323,14 @@ describe("WebSocket Server", () => {
|
||||
|
||||
async function createTestServer(
|
||||
options: {
|
||||
persistenceLayer?: Layer.Layer<SqlClient.SqlClient, any>;
|
||||
persistenceLayer?: Layer.Layer<SqlClient.SqlClient, never>;
|
||||
cwd?: string;
|
||||
autoBootstrapProjectFromCwd?: boolean;
|
||||
logWebSocketEvents?: boolean;
|
||||
devUrl?: string;
|
||||
authToken?: string;
|
||||
stateDir?: string;
|
||||
providerLayer?: Layer.Layer<ProviderService, unknown>;
|
||||
providerLayer?: Layer.Layer<ProviderService, never>;
|
||||
open?: OpenShape;
|
||||
gitManager?: GitManagerShape;
|
||||
gitCore?: Pick<GitCoreShape, "listBranches" | "initRepo" | "pullCurrentBranch">;
|
||||
|
||||
+34
-20
@@ -66,14 +66,14 @@ export interface ServerShape {
|
||||
*/
|
||||
readonly start: Effect.Effect<
|
||||
http.Server,
|
||||
unknown,
|
||||
ServerLifecycleError,
|
||||
Scope.Scope | ServerRuntimeServices | ServerConfig
|
||||
>;
|
||||
|
||||
/**
|
||||
* Wait for process shutdown signals.
|
||||
*/
|
||||
readonly stopSignal: Effect.Effect<unknown, never>;
|
||||
readonly stopSignal: Effect.Effect<void, never>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,7 +165,7 @@ class RouteRequestError extends Schema.TaggedErrorClass<RouteRequestError>()("Ro
|
||||
|
||||
export const createServer = Effect.fn(function* (): Effect.fn.Return<
|
||||
http.Server,
|
||||
unknown, // TODO: This should not be unknown
|
||||
ServerLifecycleError,
|
||||
Scope.Scope | ServerRuntimeServices | ServerConfig
|
||||
> {
|
||||
const serverConfig = yield* ServerConfig;
|
||||
@@ -338,21 +338,27 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
|
||||
yield* Scope.provide(orchestrationReactor.start, subscriptionsScope);
|
||||
|
||||
if (autoBootstrapProjectFromCwd) {
|
||||
const snapshot = yield* projectionReadModelQuery.getSnapshot();
|
||||
const existing = snapshot.projects.find((project) => project.workspaceRoot === cwd);
|
||||
if (!existing) {
|
||||
const createdAt = new Date().toISOString();
|
||||
const projectName = path.basename(cwd) || "project";
|
||||
yield* orchestrationEngine.dispatch({
|
||||
type: "project.create",
|
||||
commandId: CommandId.makeUnsafe(crypto.randomUUID()),
|
||||
projectId: ProjectId.makeUnsafe(crypto.randomUUID()),
|
||||
title: projectName,
|
||||
workspaceRoot: cwd,
|
||||
defaultModel: "gpt-5-codex",
|
||||
createdAt,
|
||||
});
|
||||
}
|
||||
yield* Effect.gen(function* () {
|
||||
const snapshot = yield* projectionReadModelQuery.getSnapshot();
|
||||
const existing = snapshot.projects.find((project) => project.workspaceRoot === cwd);
|
||||
if (!existing) {
|
||||
const createdAt = new Date().toISOString();
|
||||
const projectName = path.basename(cwd) || "project";
|
||||
yield* orchestrationEngine.dispatch({
|
||||
type: "project.create",
|
||||
commandId: CommandId.makeUnsafe(crypto.randomUUID()),
|
||||
projectId: ProjectId.makeUnsafe(crypto.randomUUID()),
|
||||
title: projectName,
|
||||
workspaceRoot: cwd,
|
||||
defaultModel: "gpt-5-codex",
|
||||
createdAt,
|
||||
});
|
||||
}
|
||||
}).pipe(
|
||||
Effect.mapError(
|
||||
(cause) => new ServerLifecycleError({ operation: "autoBootstrapProject", cause }),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const routeRequest = Effect.fnUntraced(function* (request: WebSocketRequest) {
|
||||
@@ -389,7 +395,13 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
|
||||
|
||||
case WS_METHODS.projectsSearchEntries: {
|
||||
const body = stripRequestTag(request.body);
|
||||
return yield* Effect.promise(() => searchWorkspaceEntries(body));
|
||||
return yield* Effect.tryPromise({
|
||||
try: () => searchWorkspaceEntries(body),
|
||||
catch: (cause) =>
|
||||
new RouteRequestError({
|
||||
message: `Failed to search workspace entries: ${String(cause)}`,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
case WS_METHODS.shellOpenInEditor: {
|
||||
@@ -612,7 +624,9 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
|
||||
);
|
||||
yield* Effect.addFinalizer(() => Effect.sync(() => unsubscribeTerminalEvents()));
|
||||
|
||||
yield* NodeHttpServer.make(() => httpServer, listenOptions);
|
||||
yield* NodeHttpServer.make(() => httpServer, listenOptions).pipe(
|
||||
Effect.mapError((cause) => new ServerLifecycleError({ operation: "httpServerListen", cause })),
|
||||
);
|
||||
|
||||
yield* Effect.addFinalizer(() =>
|
||||
Effect.all([
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
},
|
||||
"test": {
|
||||
"dependsOn": ["^build"],
|
||||
"cache": false,
|
||||
"outputs": []
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user