fix: convert branch-added tests off Effect.runPromise for the lint baseline
The no-manual-effect-runtime-in-tests rule holds legacy files at a frozen occurrence count (projector.test.ts: 20, ProviderCommandReactor.test.ts: 70) and this branch's added tests pushed both over. Converted the two additions to @effect/vitest it.effect with yield*, which also drops the reactor file one below its baseline. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
d1ebcff740
commit
a706e8f5b9
2 files changed
+88
-87
No files matched your search
@@ -2273,45 +2273,45 @@ describe("ProviderCommandReactor", () => {
|
||||
expect(resolvedActivity).toBeUndefined();
|
||||
});
|
||||
|
||||
it("reacts to thread.session.stop by stopping provider session and clearing thread session state", async () => {
|
||||
const harness = await createHarness();
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
effectIt.effect(
|
||||
"reacts to thread.session.stop by stopping provider session and clearing thread session state",
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const harness = yield* Effect.promise(() => createHarness());
|
||||
const now = "2026-01-01T00:00:00.000Z";
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
type: "thread.session.set",
|
||||
commandId: CommandId.make("cmd-session-set-for-stop"),
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
session: {
|
||||
yield* harness.engine.dispatch({
|
||||
type: "thread.session.set",
|
||||
commandId: CommandId.make("cmd-session-set-for-stop"),
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
status: "ready",
|
||||
providerName: "codex",
|
||||
providerInstanceId: ProviderInstanceId.make("codex_work"),
|
||||
runtimeMode: "approval-required",
|
||||
activeTurnId: null,
|
||||
lastError: null,
|
||||
updatedAt: now,
|
||||
},
|
||||
createdAt: now,
|
||||
}),
|
||||
);
|
||||
session: {
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
status: "ready",
|
||||
providerName: "codex",
|
||||
providerInstanceId: ProviderInstanceId.make("codex_work"),
|
||||
runtimeMode: "approval-required",
|
||||
activeTurnId: null,
|
||||
lastError: null,
|
||||
updatedAt: now,
|
||||
},
|
||||
createdAt: now,
|
||||
});
|
||||
|
||||
await Effect.runPromise(
|
||||
harness.engine.dispatch({
|
||||
type: "thread.session.stop",
|
||||
commandId: CommandId.make("cmd-session-stop"),
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
createdAt: now,
|
||||
}),
|
||||
);
|
||||
yield* harness.engine.dispatch({
|
||||
type: "thread.session.stop",
|
||||
commandId: CommandId.make("cmd-session-stop"),
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
createdAt: now,
|
||||
});
|
||||
|
||||
await waitFor(() => harness.stopSession.mock.calls.length === 1);
|
||||
const readModel = await harness.readModel();
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(thread?.session).not.toBeNull();
|
||||
expect(thread?.session?.status).toBe("stopped");
|
||||
expect(thread?.session?.threadId).toBe("thread-1");
|
||||
expect(thread?.session?.providerInstanceId).toBe(ProviderInstanceId.make("codex_work"));
|
||||
expect(thread?.session?.activeTurnId).toBeNull();
|
||||
});
|
||||
yield* Effect.promise(() => waitFor(() => harness.stopSession.mock.calls.length === 1));
|
||||
const readModel = yield* Effect.promise(() => harness.readModel());
|
||||
const thread = readModel.threads.find((entry) => entry.id === ThreadId.make("thread-1"));
|
||||
expect(thread?.session).not.toBeNull();
|
||||
expect(thread?.session?.status).toBe("stopped");
|
||||
expect(thread?.session?.threadId).toBe("thread-1");
|
||||
expect(thread?.session?.providerInstanceId).toBe(ProviderInstanceId.make("codex_work"));
|
||||
expect(thread?.session?.activeTurnId).toBeNull();
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
type OrchestrationEvent,
|
||||
} from "@t3tools/contracts";
|
||||
import * as Effect from "effect/Effect";
|
||||
import { it as effectIt } from "@effect/vitest";
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
|
||||
import { createEmptyReadModel, projectEvent } from "./projector.ts";
|
||||
@@ -488,11 +489,11 @@ describe("orchestration projector", () => {
|
||||
expect(message?.updatedAt).toBe(completeAt);
|
||||
});
|
||||
|
||||
it("replaces an assistant snapshot between legacy appended deltas", async () => {
|
||||
const createdAt = "2026-02-23T09:00:00.000Z";
|
||||
const model = createEmptyReadModel(createdAt);
|
||||
const afterCreate = await Effect.runPromise(
|
||||
projectEvent(
|
||||
effectIt.effect("replaces an assistant snapshot between legacy appended deltas", () =>
|
||||
Effect.gen(function* () {
|
||||
const createdAt = "2026-02-23T09:00:00.000Z";
|
||||
const model = createEmptyReadModel(createdAt);
|
||||
const afterCreate = yield* projectEvent(
|
||||
model,
|
||||
makeEvent({
|
||||
sequence: 1,
|
||||
@@ -516,54 +517,54 @@ describe("orchestration projector", () => {
|
||||
updatedAt: createdAt,
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
);
|
||||
|
||||
const messageEvent = (input: {
|
||||
sequence: number;
|
||||
text: string;
|
||||
streaming: boolean;
|
||||
textOperation?: "replace";
|
||||
}) =>
|
||||
makeEvent({
|
||||
sequence: input.sequence,
|
||||
type: "thread.message-sent",
|
||||
aggregateKind: "thread",
|
||||
aggregateId: "thread-1",
|
||||
occurredAt: createdAt,
|
||||
commandId: `cmd-message-${input.sequence}`,
|
||||
payload: {
|
||||
threadId: "thread-1",
|
||||
messageId: "assistant:msg-replace",
|
||||
role: "assistant",
|
||||
text: input.text,
|
||||
turnId: "turn-1",
|
||||
streaming: input.streaming,
|
||||
...(input.textOperation !== undefined ? { textOperation: input.textOperation } : {}),
|
||||
createdAt,
|
||||
updatedAt: createdAt,
|
||||
},
|
||||
});
|
||||
const messageEvent = (input: {
|
||||
sequence: number;
|
||||
text: string;
|
||||
streaming: boolean;
|
||||
textOperation?: "replace";
|
||||
}) =>
|
||||
makeEvent({
|
||||
sequence: input.sequence,
|
||||
type: "thread.message-sent",
|
||||
aggregateKind: "thread",
|
||||
aggregateId: "thread-1",
|
||||
occurredAt: createdAt,
|
||||
commandId: `cmd-message-${input.sequence}`,
|
||||
payload: {
|
||||
threadId: "thread-1",
|
||||
messageId: "assistant:msg-replace",
|
||||
role: "assistant",
|
||||
text: input.text,
|
||||
turnId: "turn-1",
|
||||
streaming: input.streaming,
|
||||
...(input.textOperation !== undefined ? { textOperation: input.textOperation } : {}),
|
||||
createdAt,
|
||||
updatedAt: createdAt,
|
||||
},
|
||||
});
|
||||
|
||||
let projected = afterCreate;
|
||||
for (const event of [
|
||||
messageEvent({ sequence: 2, text: "Hello wor", streaming: true }),
|
||||
messageEvent({
|
||||
sequence: 3,
|
||||
text: "Hello there",
|
||||
streaming: true,
|
||||
textOperation: "replace",
|
||||
}),
|
||||
messageEvent({ sequence: 4, text: "!", streaming: true }),
|
||||
messageEvent({ sequence: 5, text: "", streaming: false }),
|
||||
]) {
|
||||
projected = await Effect.runPromise(projectEvent(projected, event));
|
||||
}
|
||||
let projected = afterCreate;
|
||||
for (const event of [
|
||||
messageEvent({ sequence: 2, text: "Hello wor", streaming: true }),
|
||||
messageEvent({
|
||||
sequence: 3,
|
||||
text: "Hello there",
|
||||
streaming: true,
|
||||
textOperation: "replace",
|
||||
}),
|
||||
messageEvent({ sequence: 4, text: "!", streaming: true }),
|
||||
messageEvent({ sequence: 5, text: "", streaming: false }),
|
||||
]) {
|
||||
projected = yield* projectEvent(projected, event);
|
||||
}
|
||||
|
||||
const message = projected.threads[0]?.messages[0];
|
||||
expect(message?.text).toBe("Hello there!");
|
||||
expect(message?.streaming).toBe(false);
|
||||
});
|
||||
const message = projected.threads[0]?.messages[0];
|
||||
expect(message?.text).toBe("Hello there!");
|
||||
expect(message?.streaming).toBe(false);
|
||||
}),
|
||||
);
|
||||
|
||||
it("prunes reverted turn messages from in-memory thread snapshot", async () => {
|
||||
const createdAt = "2026-02-23T10:00:00.000Z";
|
||||
|
||||
Reference in new issue
Block a user