fix: address all Cubic P2 review issues
- session-utils: log SDK errors instead of silent swallow - opencode-message-dir: fix indentation, improve error log format - storage: use session.list for sessionExists (handles empty sessions) - storage.test: use resetStorageClient for proper SDK client cleanup - todo-sync: add content-based fallback for id-less todo removal
This commit is contained in:
@@ -469,23 +469,18 @@ describe("session-manager storage - SDK path (beta mode)", () => {
|
||||
})
|
||||
|
||||
test("SDK path returns empty array when client is not set", async () => {
|
||||
// given - beta mode enabled but no client set
|
||||
//#given beta mode enabled but no client set
|
||||
mock.module("../../shared/opencode-storage-detection", () => ({
|
||||
isSqliteBackend: () => true,
|
||||
resetSqliteBackendCache: () => {},
|
||||
}))
|
||||
|
||||
// Reset SDK client to ensure "client not set" case is exercised
|
||||
const { setStorageClient } = await import("./storage")
|
||||
setStorageClient(null as any)
|
||||
|
||||
// Re-import without setting client
|
||||
const { readSessionMessages } = await import("./storage")
|
||||
|
||||
// when - calling readSessionMessages without client set
|
||||
//#when client is explicitly cleared and messages are requested
|
||||
const { resetStorageClient, readSessionMessages } = await import("./storage")
|
||||
resetStorageClient()
|
||||
const messages = await readSessionMessages("ses_test")
|
||||
|
||||
// then - should return empty array since no client and no JSON fallback
|
||||
//#then should return empty array since no client and no JSON fallback
|
||||
expect(messages).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -141,9 +141,9 @@ export function getMessageDir(sessionID: string): string | null {
|
||||
export async function sessionExists(sessionID: string): Promise<boolean> {
|
||||
if (isSqliteBackend() && sdkClient) {
|
||||
try {
|
||||
const response = await sdkClient.session.messages({ path: { id: sessionID } })
|
||||
const messages = response.data as unknown[] | undefined
|
||||
return Array.isArray(messages) && messages.length > 0
|
||||
const response = await sdkClient.session.list()
|
||||
const sessions = (response.data || []) as Array<{ id?: string }>
|
||||
return sessions.some((s) => s.id === sessionID)
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -168,10 +168,15 @@ export async function syncAllTasksToTodos(
|
||||
|
||||
const finalTodos: TodoInfo[] = [];
|
||||
|
||||
const removedTaskSubjects = new Set(
|
||||
tasks.filter((t) => t.status === "deleted").map((t) => t.subject),
|
||||
);
|
||||
|
||||
for (const existing of currentTodos) {
|
||||
const isInNewTodos = newTodos.some((newTodo) => todosMatch(existing, newTodo));
|
||||
const isRemoved = existing.id && tasksToRemove.has(existing.id);
|
||||
if (!isInNewTodos && !isRemoved) {
|
||||
const isRemovedById = existing.id ? tasksToRemove.has(existing.id) : false;
|
||||
const isRemovedByContent = !existing.id && removedTaskSubjects.has(existing.content);
|
||||
if (!isInNewTodos && !isRemovedById && !isRemovedByContent) {
|
||||
finalTodos.push(existing);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user