Skip to content

Commit 55f20e2

Browse files
committed
Add notebook rehydration null and malformed branch entry guard test
1 parent ca474c4 commit 55f20e2

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

tests/unit/notebook.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,31 @@ test("notebook rehydration clears stale in-memory notebook state when persisted
8787
assert.deepEqual(pi.activeTools, ["notebook_read", "notebook_index"]);
8888
});
8989

90+
test("notebook rehydration ignores null and malformed branch entries", async () => {
91+
const pi = createTestPI();
92+
const state = createState();
93+
registerNotebookRehydration(pi as any, state);
94+
const [handler] = pi.handlers.get("session_start")!;
95+
96+
await handler(
97+
{},
98+
{
99+
sessionManager: {
100+
getBranch: () => [
101+
null,
102+
undefined,
103+
"bad-string",
104+
{ type: "custom", customType: "notebook-entry", data: { epoch: 1, name: "keep", content: "valid" } },
105+
null,
106+
{ customType: "notebook-entry" },
107+
],
108+
},
109+
},
110+
);
111+
112+
assert.equal(state.epoch, 1);
113+
assert.deepEqual(Array.from(state.notebookPages.entries()), [["keep", "valid"]]);
114+
});
90115

91116
test("session_start rehydrates the latest persisted notebook state through the full hook chain", async () => {
92117
const pi = createTestPI();

0 commit comments

Comments
 (0)