Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions apps/server/src/orchestration-v2/ProjectionStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,75 @@ it("includes imported runless history when selecting fork context through a run"
});

it.layer(TestLayer)("ProjectionStoreV2", (it) => {
it.effect("does not treat visited or marked-unread state as thread activity", () =>
Effect.gen(function* () {
const projectionStore = yield* ProjectionStoreV2;
const createdAt = yield* DateTime.now;
const visitedOccurredAt = DateTime.add(createdAt, { seconds: 1 });
const markedUnreadOccurredAt = DateTime.add(createdAt, { seconds: 2 });
const threadId = ThreadId.make("thread:projection-read-state");
const projectId = ProjectId.make("project:projection-read-state");
const thread = {
createdBy: "user" as const,
creationSource: "web" as const,
id: threadId,
projectId,
title: "Projection read state",
providerInstanceId,
modelSelection,
runtimeMode: "full-access" as const,
interactionMode: "default" as const,
branch: null,
worktreePath: null,
activeProviderThreadId: null,
lineage: {
parentThreadId: null,
relationshipToParent: null,
rootThreadId: threadId,
},
forkedFrom: null,
createdAt,
updatedAt: createdAt,
archivedAt: null,
settledOverride: null,
settledAt: null,
lastVisitedAt: null,
deletedAt: null,
};

yield* projectionStore.apply({
id: EventId.make("event:projection-read-state:created"),
type: "thread.created",
threadId,
occurredAt: createdAt,
payload: thread,
});
yield* projectionStore.apply({
id: EventId.make("event:projection-read-state:visited"),
type: "thread.visited",
threadId,
occurredAt: visitedOccurredAt,
payload: { ...thread, lastVisitedAt: createdAt },
});

const visited = yield* projectionStore.getThreadProjection(threadId);
assert.deepEqual(visited.thread.lastVisitedAt, createdAt);
assert.deepEqual(visited.thread.updatedAt, createdAt);

yield* projectionStore.apply({
id: EventId.make("event:projection-read-state:marked-unread"),
type: "thread.marked-unread",
threadId,
occurredAt: markedUnreadOccurredAt,
payload: thread,
});

const markedUnread = yield* projectionStore.getThreadProjection(threadId);
assert.isNull(markedUnread.thread.lastVisitedAt);
assert.deepEqual(markedUnread.thread.updatedAt, createdAt);
}),
);

it.effect("only exposes interruptible runs through the shell activeRunId", () =>
Effect.gen(function* () {
const projectionStore = yield* ProjectionStoreV2;
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/orchestration-v2/ProjectionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1812,6 +1812,8 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
event.type !== "thread.unsettled" &&
event.type !== "thread.snoozed" &&
event.type !== "thread.unsnoozed" &&
event.type !== "thread.visited" &&
event.type !== "thread.marked-unread" &&
event.type !== "thread.metadata-updated" &&
event.type !== "thread.runtime-mode-updated" &&
event.type !== "thread.interaction-mode-updated" &&
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/orchestration-v2/runtimeLayer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as DateTime from "effect/DateTime";
import * as Layer from "effect/Layer";
import * as Queue from "effect/Queue";
import * as Stream from "effect/Stream";
import * as TestClock from "effect/testing/TestClock";
import * as SqlClient from "effect/unstable/sql/SqlClient";

import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
Expand Down Expand Up @@ -1335,6 +1336,7 @@ it.layer(SharedApplicationDataPlaneTestLayer)("visited projection", (it) => {
assert.isNull(created.thread.lastVisitedAt);
const createdUpdatedAt = created.thread.updatedAt;

yield* TestClock.adjust("1 second");
yield* orchestrator.dispatch({
type: "thread.visit",
commandId: CommandId.make("runtime-layer-visited-thread-visit"),
Expand Down
Loading