fix(session-manager): match todo filenames exactly
Stop sibling session IDs from colliding in stable JSON storage by requiring an exact todo filename match instead of a substring filter. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -168,6 +168,26 @@ describe("session-manager storage", () => {
|
||||
expect(todos).toEqual([])
|
||||
})
|
||||
|
||||
test("readSessionTodos only reads the exact session todo file", async () => {
|
||||
// given
|
||||
writeFileSync(
|
||||
join(TEST_TODO_DIR, "ses_1.json"),
|
||||
JSON.stringify([{ id: "todo_exact", content: "Exact match", status: "pending" }]),
|
||||
)
|
||||
writeFileSync(
|
||||
join(TEST_TODO_DIR, "ses_10.json"),
|
||||
JSON.stringify([{ id: "todo_collision", content: "Wrong session", status: "completed" }]),
|
||||
)
|
||||
|
||||
// when
|
||||
const todos = await readSessionTodos("ses_1")
|
||||
|
||||
// then
|
||||
expect(todos).toHaveLength(1)
|
||||
expect(todos[0].id).toBe("todo_exact")
|
||||
expect(todos[0].content).toBe("Exact match")
|
||||
})
|
||||
|
||||
test("getSessionInfo returns null for non-existent session", async () => {
|
||||
// when
|
||||
const info = await getSessionInfo("ses_nonexistent")
|
||||
|
||||
@@ -277,7 +277,7 @@ export async function readSessionTodos(sessionID: string): Promise<TodoItem[]> {
|
||||
|
||||
try {
|
||||
const allFiles = await readdir(TODO_DIR)
|
||||
const todoFiles = allFiles.filter((f) => f.includes(sessionID) && f.endsWith(".json"))
|
||||
const todoFiles = allFiles.filter((f) => f === `${sessionID}.json`)
|
||||
|
||||
for (const file of todoFiles) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user