| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- import { describe, expect, it } from "vitest";
- import type { ZCodeTaskMeta } from "@zcode/shared";
- import { buildTaskEntityKey, buildTaskListCacheDescriptor } from "@/lib/taskQueryCache.js";
- import {
- resolveQuickPickConversationNavigation,
- selectQuickPickConversationTaskIds,
- } from "@/lib/quickPickConversationNavigation.js";
- function createTask(taskId: string, updatedAt: number, workspaceIdentity?: string): ZCodeTaskMeta {
- return {
- taskId,
- traceId: `trace-${taskId}`,
- title: taskId,
- workspacePath: "/workspace",
- ...(workspaceIdentity ? { workspaceIdentity } : {}),
- createdAt: updatedAt,
- updatedAt,
- mode: "default",
- };
- }
- describe("quickPickConversationNavigation", () => {
- it("resolves previous and next from the ordered task ids", () => {
- expect(
- resolveQuickPickConversationNavigation({
- taskIds: ["newest", "middle", "oldest"],
- activeTaskId: "middle",
- }),
- ).toMatchObject({
- canSelectPreviousConversation: true,
- canSelectNextConversation: true,
- previousTaskId: "newest",
- nextTaskId: "oldest",
- });
- });
- it("uses edge availability when the active task is at the list boundary", () => {
- expect(
- resolveQuickPickConversationNavigation({
- taskIds: ["newest", "oldest"],
- activeTaskId: "newest",
- }),
- ).toMatchObject({
- canSelectPreviousConversation: false,
- canSelectNextConversation: true,
- previousTaskId: null,
- nextTaskId: "oldest",
- });
- });
- it("prefers workspace task query cache over stale fallback ids", () => {
- const tasks = [createTask("cache-new", 3), createTask("cache-old", 1)];
- const descriptor = buildTaskListCacheDescriptor({
- kind: "workspace",
- workspaceScopes: [{ workspacePath: "/workspace" }],
- sortBy: "updated",
- search: "",
- expanded: true,
- });
- const taskMetaByEntityKey = Object.fromEntries(
- tasks.map((task) => [buildTaskEntityKey(task), task]),
- );
- const taskIds = selectQuickPickConversationTaskIds({
- workspacePath: "/workspace",
- resultsByQueryKey: {
- workspace: {
- taskKeys: tasks.map(buildTaskEntityKey),
- total: tasks.length,
- hasMore: false,
- invalidationVersion: 0,
- fetchedAt: 1,
- stale: false,
- partial: false,
- loadingShardKeys: [],
- failedShardKeys: [],
- descriptor,
- },
- },
- taskMetaByEntityKey,
- fallbackTaskIds: ["fallback-only"],
- });
- expect(taskIds).toEqual(["cache-new", "cache-old"]);
- });
- it("falls back to old task ids before task query cache is ready", () => {
- expect(
- selectQuickPickConversationTaskIds({
- workspacePath: "/workspace",
- resultsByQueryKey: {},
- taskMetaByEntityKey: {},
- fallbackTaskIds: ["fallback-new", "fallback-old"],
- }),
- ).toEqual(["fallback-new", "fallback-old"]);
- });
- });
|