Skip to content

Commit cec4a57

Browse files
t3dotggclaude
andcommitted
test(server): cover pinOrderKey retention, reorder, and clear through projections
CodeRabbit follow-ups: - projector: full pin order key lifecycle — fresh pin stores the key, legacy thread.pinned events without the field preserve it, reorder persists the new slot, unpin clears it - snapshot query: thread-1 fixture now carries a persisted pinned_at + pin_order_key, asserting the non-null path end to end through SQLite hydration into both the thread and shell surfaces - docs: topOfPinnedRunOrderKey comment says undefined, matching the type Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 64c0f77 commit cec4a57

3 files changed

Lines changed: 87 additions & 6 deletions

File tree

‎apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.test.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
8787
pending_approval_count,
8888
pending_user_input_count,
8989
has_actionable_proposed_plan,
90+
pinned_at,
91+
pin_order_key,
9092
created_at,
9193
updated_at,
9294
deleted_at
@@ -105,6 +107,8 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
105107
1,
106108
0,
107109
0,
110+
'2026-02-24T00:00:01.000Z',
111+
'gm',
108112
'2026-02-24T00:00:02.000Z',
109113
'2026-02-24T00:00:03.000Z',
110114
NULL
@@ -317,8 +321,8 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
317321
settledAt: null,
318322
snoozedUntil: null,
319323
snoozedAt: null,
320-
pinnedAt: null,
321-
pinOrderKey: null,
324+
pinnedAt: "2026-02-24T00:00:01.000Z",
325+
pinOrderKey: "gm",
322326
titleRegeneration: null,
323327
deletedAt: null,
324328
messages: [
@@ -434,8 +438,8 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
434438
settledAt: null,
435439
snoozedUntil: null,
436440
snoozedAt: null,
437-
pinnedAt: null,
438-
pinOrderKey: null,
441+
pinnedAt: "2026-02-24T00:00:01.000Z",
442+
pinOrderKey: "gm",
439443
titleRegeneration: null,
440444
session: {
441445
threadId: ThreadId.make("thread-1"),

‎apps/server/src/orchestration/projector.pinned.test.ts‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,80 @@ it.effect("projects pin lifecycle events", () =>
7575
expect(unpinned.threads[0]?.pinnedAt).toBeNull();
7676
}),
7777
);
78+
79+
it.effect("projects pin order key lifecycle", () =>
80+
Effect.gen(function* () {
81+
const now = "2026-01-01T00:00:00.000Z";
82+
const created = yield* projectEvent(
83+
createEmptyReadModel(now),
84+
makeEvent({
85+
sequence: 1,
86+
type: "thread.created",
87+
payload: {
88+
threadId: ThreadId.make("thread-1"),
89+
projectId: ProjectId.make("project-1"),
90+
title: "Thread",
91+
modelSelection: { provider: "codex", model: "gpt-5.4" },
92+
runtimeMode: "full-access",
93+
interactionMode: "default",
94+
branch: null,
95+
worktreePath: null,
96+
createdAt: now,
97+
updatedAt: now,
98+
},
99+
}),
100+
);
101+
expect(created.threads[0]?.pinOrderKey ?? null).toBeNull();
102+
103+
// Fresh pin carries the client's slot in the arranged order.
104+
const pinned = yield* projectEvent(
105+
created,
106+
makeEvent({
107+
sequence: 2,
108+
type: "thread.pinned",
109+
payload: {
110+
threadId: ThreadId.make("thread-1"),
111+
pinnedAt: now,
112+
pinOrderKey: "g",
113+
updatedAt: now,
114+
},
115+
}),
116+
);
117+
expect(pinned.threads[0]?.pinOrderKey).toBe("g");
118+
119+
// Re-pins and events from pre-reorder servers omit the field entirely;
120+
// the existing key must survive rather than being nulled out.
121+
const repinned = yield* projectEvent(
122+
pinned,
123+
makeEvent({
124+
sequence: 3,
125+
type: "thread.pinned",
126+
payload: { threadId: ThreadId.make("thread-1"), pinnedAt: now, updatedAt: now },
127+
}),
128+
);
129+
expect(repinned.threads[0]?.pinOrderKey).toBe("g");
130+
131+
// A drag persists the new slot.
132+
const reordered = yield* projectEvent(
133+
repinned,
134+
makeEvent({
135+
sequence: 4,
136+
type: "thread.pin-reordered",
137+
payload: { threadId: ThreadId.make("thread-1"), orderKey: "m", updatedAt: now },
138+
}),
139+
);
140+
expect(reordered.threads[0]?.pinOrderKey).toBe("m");
141+
142+
// Unpin clears the slot: re-pinning is "pin again", not "restore an
143+
// ancient position".
144+
const unpinned = yield* projectEvent(
145+
reordered,
146+
makeEvent({
147+
sequence: 5,
148+
type: "thread.unpinned",
149+
payload: { threadId: ThreadId.make("thread-1"), updatedAt: now },
150+
}),
151+
);
152+
expect(unpinned.threads[0]?.pinOrderKey).toBeNull();
153+
}),
154+
);

‎apps/web/src/hooks/useThreadActions.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ export class ThreadSnoozeBlockedError extends Schema.TaggedErrorClass<ThreadSnoo
100100
}
101101

102102
/** Key that sorts before every arranged pinned thread, so a fresh pin lands
103-
at the top of the run. Null (keyless, sorts with the legacy block) when
104-
key math can't produce one — pinning must never fail on placement. */
103+
at the top of the run. Undefined (keyless, sorts with the legacy block)
104+
when key math can't produce one — pinning must never fail on placement. */
105105
function topOfPinnedRunOrderKey(): string | undefined {
106106
let firstKey: string | null = null;
107107
for (const shell of readThreadShells()) {

0 commit comments

Comments
 (0)