Skip to content

Commit 48c3ad4

Browse files
authored
Merge pull request #15 from StiensWout/codex/fix/guard-shell-reducer-stale-sequence
2 parents 28107e8 + e801af8 commit 48c3ad4

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

packages/client-runtime/src/state/shellReducer.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ const stubThread = {
4444
} as const;
4545

4646
describe("applyShellStreamEvent", () => {
47+
it("ignores stale project upserts without mutating the snapshot", () => {
48+
const snapshotWithProject: OrchestrationShellSnapshot = {
49+
...baseSnapshot,
50+
snapshotSequence: 4,
51+
projects: [stubProject],
52+
};
53+
54+
for (const sequence of [3, 4]) {
55+
const next = applyShellStreamEvent(snapshotWithProject, {
56+
kind: "project-upserted",
57+
sequence,
58+
project: { ...stubProject, title: "Stale Title" },
59+
});
60+
61+
expect(next).toBe(snapshotWithProject);
62+
expect(next.snapshotSequence).toBe(4);
63+
expect(next.projects[0]?.title).toBe("Test Project");
64+
}
65+
});
66+
4767
describe("project-upserted", () => {
4868
it("adds a new project", () => {
4969
const event: OrchestrationShellStreamEvent = {

packages/client-runtime/src/state/shellReducer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export function applyShellStreamEvent(
1313
snapshot: OrchestrationShellSnapshot,
1414
event: OrchestrationShellStreamEvent,
1515
): OrchestrationShellSnapshot {
16+
if (event.sequence <= snapshot.snapshotSequence) return snapshot;
17+
1618
switch (event.kind) {
1719
case "project-upserted": {
1820
const projects = snapshot.projects.some((p) => p.id === event.project.id)

0 commit comments

Comments
 (0)