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
20 changes: 20 additions & 0 deletions packages/client-runtime/src/state/shellReducer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ const stubThread = {
} as const;

describe("applyShellStreamEvent", () => {
it("ignores stale project upserts without mutating the snapshot", () => {
const snapshotWithProject: OrchestrationShellSnapshot = {
...baseSnapshot,
snapshotSequence: 4,
projects: [stubProject],
};

for (const sequence of [3, 4]) {
const next = applyShellStreamEvent(snapshotWithProject, {
kind: "project-upserted",
sequence,
project: { ...stubProject, title: "Stale Title" },
});

expect(next).toBe(snapshotWithProject);
expect(next.snapshotSequence).toBe(4);
expect(next.projects[0]?.title).toBe("Test Project");
}
});

describe("project-upserted", () => {
it("adds a new project", () => {
const event: OrchestrationShellStreamEvent = {
Expand Down
2 changes: 2 additions & 0 deletions packages/client-runtime/src/state/shellReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export function applyShellStreamEvent(
snapshot: OrchestrationShellSnapshot,
event: OrchestrationShellStreamEvent,
): OrchestrationShellSnapshot {
if (event.sequence <= snapshot.snapshotSequence) return snapshot;

switch (event.kind) {
case "project-upserted": {
const projects = snapshot.projects.some((p) => p.id === event.project.id)
Expand Down
Loading