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:
@@ -21,10 +21,10 @@ export function getMessageDir(sessionID: string): string | null {
|
||||
return sessionPath
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
log(`Error reading message directory: ${error}`)
|
||||
return null
|
||||
}
|
||||
} catch (error) {
|
||||
log("[opencode-message-dir] Failed to scan message directories", { sessionID, error: String(error) })
|
||||
return null
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
@@ -1,22 +1,22 @@
|
||||
import { findNearestMessageWithFields, findNearestMessageWithFieldsFromSDK } from "../features/hook-message-injector"
|
||||
import { getMessageDir } from "./opencode-message-dir"
|
||||
import { isSqliteBackend } from "./opencode-storage-detection"
|
||||
import { log } from "./logger"
|
||||
import type { PluginInput } from "@opencode-ai/plugin"
|
||||
|
||||
export async function isCallerOrchestrator(sessionID?: string, client?: PluginInput["client"]): Promise<boolean> {
|
||||
if (!sessionID) return false
|
||||
|
||||
// Beta mode: use SDK if client provided
|
||||
if (isSqliteBackend() && client) {
|
||||
try {
|
||||
const nearest = await findNearestMessageWithFieldsFromSDK(client, sessionID)
|
||||
return nearest?.agent?.toLowerCase() === "atlas"
|
||||
} catch {
|
||||
} catch (error) {
|
||||
log("[session-utils] SDK orchestrator check failed", { sessionID, error: String(error) })
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Stable mode: use JSON files
|
||||
const messageDir = getMessageDir(sessionID)
|
||||
if (!messageDir) return false
|
||||
const nearest = findNearestMessageWithFields(messageDir)
|
||||
|
||||
@@ -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