fix: address remaining Cubic review comments (P2 issues)
- Add content-based fallback matching for todos without ids - Add TODO comment for exported but unused SDK functions - Add resetStorageClient() for test isolation - Fixes todo duplication risk on beta (SQLite backend)
This commit is contained in:
parent
07da116671
commit
4b2410d0a2
@ -49,6 +49,11 @@ function convertSDKMessageToStoredMessage(msg: SDKMessage): StoredMessage | null
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: These SDK-based functions are exported for future use when hooks migrate to async.
|
||||||
|
// Currently, callers still use the sync JSON-based functions which return null on beta.
|
||||||
|
// Migration requires making callers async, which is a larger refactoring.
|
||||||
|
// See: https://github.com/code-yeongyu/oh-my-opencode/pull/1837
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the nearest message with required fields using SDK (for beta/SQLite backend).
|
* Finds the nearest message with required fields using SDK (for beta/SQLite backend).
|
||||||
* Uses client.session.messages() to fetch message data from SQLite.
|
* Uses client.session.messages() to fetch message data from SQLite.
|
||||||
|
|||||||
@ -475,6 +475,10 @@ describe("session-manager storage - SDK path (beta mode)", () => {
|
|||||||
resetSqliteBackendCache: () => {},
|
resetSqliteBackendCache: () => {},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
// Reset client to ensure "client not set" case is exercised
|
||||||
|
const { resetStorageClient } = await import("./storage")
|
||||||
|
resetStorageClient()
|
||||||
|
|
||||||
// Re-import without setting client
|
// Re-import without setting client
|
||||||
const { readSessionMessages } = await import("./storage")
|
const { readSessionMessages } = await import("./storage")
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,10 @@ export function setStorageClient(client: PluginInput["client"]): void {
|
|||||||
sdkClient = client
|
sdkClient = client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function resetStorageClient(): void {
|
||||||
|
sdkClient = null
|
||||||
|
}
|
||||||
|
|
||||||
export async function getMainSessions(options: GetMainSessionsOptions): Promise<SessionMetadata[]> {
|
export async function getMainSessions(options: GetMainSessionsOptions): Promise<SessionMetadata[]> {
|
||||||
// Beta mode: use SDK
|
// Beta mode: use SDK
|
||||||
if (isSqliteBackend() && sdkClient) {
|
if (isSqliteBackend() && sdkClient) {
|
||||||
|
|||||||
@ -47,6 +47,13 @@ function extractPriority(
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function todosMatch(todo1: TodoInfo, todo2: TodoInfo): boolean {
|
||||||
|
if (todo1.id && todo2.id) {
|
||||||
|
return todo1.id === todo2.id;
|
||||||
|
}
|
||||||
|
return todo1.content === todo2.content;
|
||||||
|
}
|
||||||
|
|
||||||
export function syncTaskToTodo(task: Task): TodoInfo | null {
|
export function syncTaskToTodo(task: Task): TodoInfo | null {
|
||||||
const todoStatus = mapTaskStatusToTodoStatus(task.status);
|
const todoStatus = mapTaskStatusToTodoStatus(task.status);
|
||||||
|
|
||||||
@ -100,8 +107,9 @@ export async function syncTaskTodoUpdate(
|
|||||||
path: { id: sessionID },
|
path: { id: sessionID },
|
||||||
});
|
});
|
||||||
const currentTodos = extractTodos(response);
|
const currentTodos = extractTodos(response);
|
||||||
const nextTodos = currentTodos.filter((todo) => !todo.id || todo.id !== task.id);
|
const taskTodo = syncTaskToTodo(task);
|
||||||
const todo = syncTaskToTodo(task);
|
const nextTodos = currentTodos.filter((todo) => !taskTodo || !todosMatch(todo, taskTodo));
|
||||||
|
const todo = taskTodo;
|
||||||
|
|
||||||
if (todo) {
|
if (todo) {
|
||||||
nextTodos.push(todo);
|
nextTodos.push(todo);
|
||||||
@ -150,10 +158,11 @@ export async function syncAllTasksToTodos(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const finalTodos: TodoInfo[] = [];
|
const finalTodos: TodoInfo[] = [];
|
||||||
const newTodoIds = new Set(newTodos.map((t) => t.id).filter((id) => id !== undefined));
|
|
||||||
|
|
||||||
for (const existing of currentTodos) {
|
for (const existing of currentTodos) {
|
||||||
if ((!existing.id || !newTodoIds.has(existing.id)) && !tasksToRemove.has(existing.id || "")) {
|
const isInNewTodos = newTodos.some((newTodo) => todosMatch(existing, newTodo));
|
||||||
|
const isRemoved = existing.id && tasksToRemove.has(existing.id);
|
||||||
|
if (!isInNewTodos && !isRemoved) {
|
||||||
finalTodos.push(existing);
|
finalTodos.push(existing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user