Reconcile linked-folder UI and book route integration

This commit is contained in:
Bingxi Zhao (Frank)
2026-09-23 10:48:46 +08:00
parent a6d15e4730
commit 2dcc5871df
16 changed files with 143 additions and 199 deletions

View File

@@ -113,6 +113,7 @@ function BookPageInner() {
const [view, setView] = useState<View>(requestedBookId ? 'opening' : requestedLearningCreation() ? 'creator' : 'list')
const [selectedBookId, setSelectedBookId] = useState<string | null>(null)
const selectionRequestRef = useRef(0)
const [detail, setDetail] = useState<BookDetail | null>(null)
const [selectedPageId, setSelectedPageId] = useState<string | null>(null)
@@ -205,10 +206,12 @@ function BookPageInner() {
* content to draw a sidebar meant a multi-chapter book cost hundreds of
* kilobytes per refresh. `hydratePage` fills in the one page that matters.
*/
const loadBookDetail = useCallback(async (id: string) => {
const loadBookDetail = useCallback(async (id: string, shouldApply: () => boolean = () => true) => {
const data = await bookApi.get(id, { includeBlocks: false })
revisionRef.current = data.book.revision
setDetail(data)
if (shouldApply()) {
revisionRef.current = data.book.revision
setDetail(data)
}
return data
}, [])
@@ -400,6 +403,7 @@ function BookPageInner() {
const handleSelectBook = useCallback(
async (id: string | null, openPageId?: string | null) => {
const requestId = ++selectionRequestRef.current
if (!id) {
setSelectedBookId(null)
setDetail(null)
@@ -412,7 +416,8 @@ function BookPageInner() {
router.push(targetPath)
}
setSelectedBookId(id)
const data = await loadBookDetail(id)
const data = await loadBookDetail(id, () => selectionRequestRef.current === requestId)
if (selectionRequestRef.current !== requestId) return
const hasReadableContent = data.pages.some(
p => p.status !== 'pending' || (p.block_count ?? p.blocks.length) > 0
)
@@ -447,6 +452,7 @@ function BookPageInner() {
// Resource identity belongs in the path: /books/<book>[/pages/<page>].
useEffect(() => {
if (!requestedBookId) {
lastDeepLinkedBookId.current = null
if (selectedBookId) void handleSelectBook(null)
return
}
@@ -457,6 +463,7 @@ function BookPageInner() {
// to say so and hand the reader back; otherwise the shell is where they
// stay. Selecting nothing returns to the library and to its URL.
void handleSelectBook(requestedBookId, requestedPageId).catch(err => {
if (lastDeepLinkedBookId.current !== requestedBookId) return
notify(
t('{{action}} failed: {{reason}}', {
action: t('Open book'),
@@ -983,9 +990,14 @@ function BookPageInner() {
// ── Render ─────────────────────────────────────────────────────────
// A client-side route change may arrive before the next book's detail.
// Keep the previous reader, sidebar, and activity out of the new URL.
const displayView = requestedBookId && (selectedBookId !== requestedBookId || detail?.book.id !== requestedBookId)
? 'opening' : view
return (
<div className="flex h-full w-full">
{view !== 'list' && view !== 'creator' && (
{displayView !== 'list' && displayView !== 'creator' && displayView !== 'opening' && (
<BookSidebar
book={detail?.book || pendingBook || null}
onBackToLibrary={() => void handleSelectBook(null)}
@@ -1007,7 +1019,7 @@ function BookPageInner() {
two readouts disagreed about what to show. Fixed slot above the
view: it changes height only when the reader asks it to. */}
<div className="flex min-w-0 flex-1 flex-col overflow-hidden">
{view !== 'list' && (
{displayView !== 'list' && displayView !== 'opening' && (
<BookGenerationActivity
book={detail?.book || pendingBook || null}
pages={detail?.pages || []}
@@ -1026,15 +1038,15 @@ function BookPageInner() {
/>
)}
<div className="min-h-0 flex-1 overflow-hidden">
{view === 'opening' && (
<div className="flex h-full w-full items-center justify-center gap-2 text-[12px] text-[var(--muted-foreground)]">
{displayView === 'opening' && (
<div role="status" aria-busy="true" className="flex h-full w-full items-center justify-center gap-2 text-[12px] text-[var(--muted-foreground)]">
<Loader2 className="h-4 w-4 animate-spin" />
<BookLoadingText />
</div>
)}
{creation.dialog}
{view === 'list' && (
{displayView === 'list' && (
<BookLibrary
books={books}
loading={loadingBooks}
@@ -1050,7 +1062,7 @@ function BookPageInner() {
/>
)}
{view === 'creator' && (
{displayView === 'creator' && (
<div className="h-full overflow-y-auto [scrollbar-gutter:stable]">
<div className="mx-auto max-w-4xl px-6 pt-6">
<button type="button" onClick={() => void handleSelectBook(null)} className="inline-flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground"><ArrowLeft size={14} />{t('All books')}</button>
@@ -1066,7 +1078,7 @@ function BookPageInner() {
</div>
)}
{view === 'spine' && detail?.spine && (
{displayView === 'spine' && detail?.spine && (
<div className="flex h-full flex-col overflow-hidden">
<div className="flex-1 overflow-hidden">
<SpineEditor
@@ -1085,7 +1097,7 @@ function BookPageInner() {
</div>
)}
{view === 'reader' && (
{displayView === 'reader' && (
// Column layout so banners push the reader down instead of
// overflowing it — `PageReader` fills whatever height is left.
<div className="flex h-full flex-col overflow-hidden">
@@ -1193,7 +1205,7 @@ function BookPageInner() {
</div>
)}
{view === 'spine' && !detail?.spine && (
{displayView === 'spine' && !detail?.spine && (
<div className="flex h-full items-center justify-center text-[var(--muted-foreground)]">
<Loader2 className="mr-2 h-4 w-4 animate-spin" /> {t('Loading spine…')}
</div>
@@ -1201,7 +1213,7 @@ function BookPageInner() {
</div>
</div>
{view === 'reader' && !chatOpen && (
{displayView === 'reader' && !chatOpen && (
<button
onClick={() => setChatOpen(true)}
className="absolute bottom-4 right-4 inline-flex items-center gap-2 rounded-full bg-[var(--primary)] px-4 py-2 text-sm font-medium text-[var(--primary-foreground)] shadow-lg hover:opacity-90"
@@ -1211,7 +1223,7 @@ function BookPageInner() {
</button>
)}
{view === 'reader' && chatOpen && (
{displayView === 'reader' && chatOpen && (
<BookChatPanel
book={detail?.book || null}
page={selectedPage}

View File

@@ -29,7 +29,6 @@ import ChatComposer from "@/components/chat/home/ChatComposer";
import type { ContextBudget } from "@/components/chat/home/ContextBudgetChip";
import type { ResourceSelection } from "@/features/chat/ChatStateAdapter";
import type { CapabilityDef } from "@/features/capabilities/presentation";
import type { ResourceSelection } from "@/features/chat/ChatStateAdapter";
import type { ComposerResourceCatalog } from "@/hooks/useComposerResources";
import type { SelectedHistorySession } from "@/components/chat/HistorySessionPicker";
import type { SelectedQuestionEntry } from "@/components/chat/QuestionBankPicker";
@@ -910,9 +909,6 @@ function StandaloneComposerImpl({
onResourceSelectionChange={onResourceSelectionChange}
personaSelectorOpen={personaSelectorOpen}
onPersonaSelectorOpenChange={setPersonaSelectorOpen}
resourceCatalog={resourceCatalog}
resourceSelection={resourceSelection}
onResourceSelectionChange={onResourceSelectionChange}
llmOptions={llmOptions}
activeLLMDefault={activeLLMDefault}
llmSelection={llmSelection}

View File

@@ -167,24 +167,6 @@ export default function KbDocumentsSection({
}
};
const percent = resolveProgressPercent(kb.progress);
const showTaskLogs =
task?.kind === "upload" ||
task?.kind === "sync" ||
task?.kind === "create" ||
task?.kind === "reindex" ||
task?.kind === "retry";
const taskLogTitle =
task?.kind === "create"
? t("Create Process")
: task?.kind === "retry"
? t("Retry Process")
: task?.kind === "reindex"
? t("Re-index Process")
: task?.kind === "sync"
? t("Sync Process")
: t("Upload Process");
return (
<div className="space-y-5">
<div>

View File

@@ -12,6 +12,7 @@ import { useTranslation } from "react-i18next";
import type { TaskState } from "@/hooks/useKnowledgeProgress";
import {
formatKnowledgeTimestamp,
knowledgeBaseRef,
resolveProgressPercent,
type KnowledgeBase,
} from "@/lib/knowledge-helpers";
@@ -39,6 +40,7 @@ export default function KbLinkedFoldersSection({
onSyncFolder,
}: KbLinkedFoldersSectionProps) {
const { t } = useTranslation();
const kbRef = knowledgeBaseRef(kb);
const [folders, setFolders] = useState<LinkedFolderInfo[]>([]);
const [loading, setLoading] = useState(true);
const [loadError, setLoadError] = useState<string | null>(null);
@@ -61,7 +63,7 @@ export default function KbLinkedFoldersSection({
setLoadError(null);
setError(null);
try {
const result = await listLinkedFolders(kb.name, {
const result = await listLinkedFolders(kbRef, {
signal: controller.signal,
});
setFolders(result);
@@ -79,7 +81,7 @@ export default function KbLinkedFoldersSection({
window.clearTimeout(timeout);
setLoading(false);
}
}, [kb.name, t]);
}, [kbRef, t]);
useEffect(() => {
void refresh();

View File

@@ -48,7 +48,6 @@ import KbSettingsSection from "./KbSettingsSection";
import KbGitHubSourcesSection from "./KbGitHubSourcesSection";
import KbLinkedFoldersSection from "./KbLinkedFoldersSection";
import KbWebSourcesSection from "./KbWebSourcesSection";
import KbLinkedFoldersSection from "./KbLinkedFoldersSection";
import KbMarginNoteDevicesSection from "./KbMarginNoteDevicesSection";
import KnowledgeEngineIcon, {
knowledgeSourceIconId,
@@ -327,14 +326,14 @@ export default function KnowledgeBaseDetail({
)}
{activeSection === "folders" && (
<KbLinkedFoldersSection
key={kb.name}
key={knowledgeBaseRef(kb)}
kb={kb}
task={task}
onLinkFolder={async (folderPath) => {
await onLinkFolder(kb.name, folderPath);
await onLinkFolder(knowledgeBaseRef(kb), folderPath);
}}
onUnlinkFolder={(folderId) => onUnlinkFolder(kb.name, folderId)}
onSyncFolder={(folderId) => onSyncFolder(kb.name, folderId)}
onUnlinkFolder={(folderId) => onUnlinkFolder(knowledgeBaseRef(kb), folderId)}
onSyncFolder={(folderId) => onSyncFolder(knowledgeBaseRef(kb), folderId)}
/>
)}
{activeSection === "versions" && (
@@ -359,13 +358,6 @@ export default function KnowledgeBaseDetail({
{activeSection === "github" && (
<KbGitHubSourcesSection kbName={knowledgeBaseRef(kb)} />
)}
{activeSection === "folders" && (
<KbLinkedFoldersSection
key={kb.name}
kbName={kb.name}
readOnly={kb.read_only === true}
/>
)}
{activeSection === "web" && (
<KbWebSourcesSection kbName={knowledgeBaseRef(kb)} />
)}

View File

@@ -14,7 +14,6 @@ import {
} from "lucide-react";
import { useTranslation } from "react-i18next";
import { ConfirmDialog } from "@/components/ui/ConfirmDialog";
import Tooltip from "@/components/common/Tooltip";
import NotebookRecordActions from "@/components/notebook/NotebookRecordActions";
import { notify } from "@/lib/notifications";
import type { NotebookRecordItem, NotebookSummary } from "@/lib/notebook-api";
@@ -255,11 +254,11 @@ export default function NotebookRecordRow({
{timestamp}
</span>
<Tooltip label={t("Edit record")} side="bottom">
<button
type="button"
disabled={busy}
aria-label={t("Edit record")}
title={t("Edit record")}
onClick={() => {
if (!expanded) onToggle();
startEditing();
@@ -268,7 +267,6 @@ export default function NotebookRecordRow({
>
<Pencil size={14} />
</button>
</Tooltip>
<NotebookRecordActions
targets={moveTargets}

View File

@@ -69,8 +69,6 @@ export function MasteryComposer({
const resourceCatalog = useComposerResources(state.workspaceId, workspaces);
// Pins the turn to the tutor loop; returns no capabilities to offer.
useWorkspaceChatActions({ pinnedCapability: MASTERY_CAPABILITY_VALUE });
const { workspaces } = useChatWorkspaces();
const resourceCatalog = useComposerResources(state.workspaceId, workspaces);
const contextBudget = useContextBudget(state.messages);
const { t } = useTranslation();

View File

@@ -16,7 +16,6 @@ export {
export type {
AddGitHubSourcePayload,
AddWebSourcePayload,
FolderSyncResult,
GitHubSource,
GitHubSyncResult,
LinkedFolderInfo,

View File

@@ -24,7 +24,6 @@ export type {
LightRagServerProbe,
LinkedFolderInfo,
LinkedFolderProbe,
LinkedFolderInfo,
LlamaIndexConfig,
ModelKindOptions,
ModelOption,

View File

@@ -11,11 +11,14 @@ const fixture = vi.hoisted(() => ({
push: vi.fn(),
replace: vi.fn(),
notify: vi.fn(),
t: (key: string) => key,
t: (key: string, values?: Record<string, string>) =>
key.replace(/{{(\w+)}}/g, (_match, name: string) => values?.[name] ?? ""),
}));
vi.mock("next/navigation", () => ({
useParams: () => fixture.params,
usePathname: () => "/learning/books",
useSearchParams: () => new URLSearchParams(),
useRouter: () => ({
push: fixture.push,
replace: fixture.replace,
@@ -32,6 +35,11 @@ vi.mock("@/lib/notifications", () => ({
notify: fixture.notify,
}));
vi.mock("@/components/learning/LibraryWorkspace", () => ({
useLearningCreation: () => ({ begin: vi.fn(), dialog: null }),
requestedLearningCreation: () => false,
}));
vi.mock("@/lib/book-api", () => ({
BookApiError: class BookApiError extends Error {
status = 500;
@@ -52,40 +60,40 @@ vi.mock("@/lib/use-book-stream", () => ({
bookEventPageId: () => null,
}));
vi.mock("@/app/(workspace)/books/components/BookLibrary", () => ({
vi.mock("@/app/(workspace)/learning/books/components/BookLibrary", () => ({
default: () => <div data-testid="book-library" />,
}));
vi.mock("@/app/(workspace)/books/components/BookCreator", () => ({
vi.mock("@/app/(workspace)/learning/books/components/BookCreator", () => ({
default: () => <div data-testid="book-creator" />,
}));
vi.mock("@/app/(workspace)/books/components/SpineEditor", () => ({
vi.mock("@/app/(workspace)/learning/books/components/SpineEditor", () => ({
default: () => <div data-testid="spine-editor" />,
}));
vi.mock("@/app/(workspace)/books/components/BookSidebar", () => ({
vi.mock("@/app/(workspace)/learning/books/components/BookSidebar", () => ({
default: () => <div data-testid="book-sidebar" />,
}));
vi.mock("@/app/(workspace)/books/components/BookGenerationActivity", () => ({
vi.mock("@/app/(workspace)/learning/books/components/BookGenerationActivity", () => ({
default: () => <div data-testid="book-generation" />,
}));
vi.mock("@/app/(workspace)/books/components/BookPausedBanner", () => ({
vi.mock("@/app/(workspace)/learning/books/components/BookPausedBanner", () => ({
default: () => null,
}));
vi.mock("@/app/(workspace)/books/components/BookHealthBanner", () => ({
vi.mock("@/app/(workspace)/learning/books/components/BookHealthBanner", () => ({
default: () => null,
}));
vi.mock("@/app/(workspace)/books/components/BookChatPanel", () => ({
vi.mock("@/app/(workspace)/learning/books/components/BookChatPanel", () => ({
default: () => null,
}));
vi.mock("@/app/(workspace)/books/components/LearningCapturePanel", () => ({
vi.mock("@/app/(workspace)/learning/books/components/LearningCapturePanel", () => ({
default: () => null,
}));
vi.mock("@/app/(workspace)/books/components/PageReader", () => ({
default: ({ page }: { page?: { id: string } | null }) => (
<div data-testid="page-reader">{page?.id || "no-page"}</div>
vi.mock("@/app/(workspace)/learning/books/components/PageReader", () => ({
default: ({ page, bookId }: { page?: { id: string } | null; bookId?: string }) => (
<div data-testid="page-reader" data-book-id={bookId}>{page?.id || "no-page"}</div>
),
}));
import BookPage from "@/app/(workspace)/books/BooksRoute";
import BookPage from "@/app/(workspace)/learning/books/BooksRoute";
function readyDetail() {
const progress = {
@@ -122,7 +130,7 @@ function readyDetail() {
beforeEach(() => {
fixture.params = {};
fixture.get.mockReset();
fixture.list.mockReset().mockResolvedValue({ books: [], can_create: true });
fixture.list.mockReset().mockReturnValue(new Promise(() => undefined));
fixture.getPage.mockReset();
fixture.listLearningCaptures
.mockReset()
@@ -130,10 +138,10 @@ beforeEach(() => {
fixture.markVisited
.mockReset()
.mockResolvedValue({ progress: readyDetail().progress });
fixture.push.mockReset();
fixture.replace.mockReset().mockImplementation(() => {
fixture.push.mockReset().mockImplementation(() => {
fixture.params = {};
});
fixture.replace.mockReset();
fixture.notify.mockReset();
});
@@ -174,6 +182,57 @@ describe("book deep-link loading", () => {
expect(screen.queryByTestId("book-library")).not.toBeInTheDocument();
});
it("hides the previous book while a client route opens a different book", async () => {
fixture.params = { bookId: "book-1" };
let resolveNext!: (value: ReturnType<typeof readyDetail>) => void;
fixture.get.mockImplementation((id: string) =>
id === "book-1"
? Promise.resolve(readyDetail())
: new Promise((resolve) => {
resolveNext = resolve;
}),
);
const { rerender } = render(<BookPage />);
expect(await screen.findByTestId("page-reader")).toHaveTextContent("page-1");
fixture.params = { bookId: "book-2" };
rerender(<BookPage />);
expect(screen.getByRole("status")).toHaveAttribute("aria-busy", "true");
expect(screen.queryByTestId("page-reader")).not.toBeInTheDocument();
expect(screen.queryByTestId("book-sidebar")).not.toBeInTheDocument();
expect(screen.queryByTestId("book-generation")).not.toBeInTheDocument();
const next = readyDetail();
next.book.id = "book-2";
next.pages[0].book_id = "book-2";
await act(async () => resolveNext(next));
expect(await screen.findByTestId("page-reader")).toHaveAttribute("data-book-id", "book-2");
});
it("ignores an earlier book response that arrives after the new route", async () => {
fixture.params = { bookId: "book-1" };
let resolveOld!: (value: ReturnType<typeof readyDetail>) => void;
const next = readyDetail();
next.book.id = "book-2";
next.pages[0].book_id = "book-2";
fixture.get.mockImplementation((id: string) =>
id === "book-1"
? new Promise((resolve) => {
resolveOld = resolve;
})
: Promise.resolve(next),
);
const { rerender } = render(<BookPage />);
expect(screen.getByRole("status")).toBeInTheDocument();
fixture.params = { bookId: "book-2" };
rerender(<BookPage />);
expect(await screen.findByTestId("page-reader")).toHaveAttribute("data-book-id", "book-2");
await act(async () => resolveOld(readyDetail()));
expect(screen.getByTestId("page-reader")).toHaveAttribute("data-book-id", "book-2");
expect(screen.queryByRole("status")).not.toBeInTheDocument();
});
it("still renders the library at the books root route", async () => {
let resolveBooks!: (value: { books: never[]; can_create: boolean }) => void;
fixture.list.mockReturnValue(
@@ -205,14 +264,14 @@ describe("book deep-link loading", () => {
render(<BookPage />);
await waitFor(() => {
expect(fixture.replace).toHaveBeenCalledWith("/books");
expect(fixture.push).toHaveBeenCalledWith("/learning/books");
expect(screen.getByTestId("book-library")).toBeInTheDocument();
});
await act(async () => {
resolveBooks({ books: [], can_create: true });
});
expect(screen.queryByRole("status")).not.toBeInTheDocument();
expect(fixture.notify).toHaveBeenCalledWith("Book not found", {
expect(fixture.notify).toHaveBeenCalledWith("Open book failed: Book not found", {
tone: "error",
durationMs: 8000,
});

View File

@@ -1,118 +0,0 @@
import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
import { afterEach, beforeEach, expect, it, vi } from "vitest";
import KbLinkedFoldersSection from "@/components/knowledge/KbLinkedFoldersSection";
const api = vi.hoisted(() => ({
list: vi.fn(),
link: vi.fn(),
unlink: vi.fn(),
sync: vi.fn(),
startTask: vi.fn(),
}));
vi.mock("@/features/knowledge/api/sources", () => ({
listLinkedFolders: api.list,
linkFolder: api.link,
unlinkFolder: api.unlink,
syncLinkedFolder: api.sync,
}));
vi.mock("@/hooks/useKnowledgeProgress", () => ({
useKnowledgeProgress: () => ({
startTask: api.startTask,
tasksByKb: {},
progressByKb: {},
}),
}));
vi.mock("react-i18next", () => ({
useTranslation: () => ({ t: (key: string) => key }),
}));
const folder = {
id: "folder-1",
path: "/tmp/research-notes",
added_at: "2026-09-09T12:00:00",
file_count: 4,
last_sync: null,
};
beforeEach(() => {
api.list.mockReset().mockResolvedValue([]);
api.link.mockReset().mockResolvedValue(folder);
api.unlink.mockReset().mockResolvedValue(undefined);
api.sync.mockReset().mockResolvedValue({
message: "No new or modified files to sync",
file_count: 0,
});
api.startTask.mockReset();
});
afterEach(cleanup);
it("links a folder and refreshes the list", async () => {
api.list.mockResolvedValueOnce([]).mockResolvedValueOnce([folder]);
render(<KbLinkedFoldersSection kbName="kb" />);
fireEvent.click(await screen.findByRole("button", { name: "Link folder" }));
fireEvent.change(screen.getByLabelText("Folder path"), {
target: { value: "/tmp/research-notes" },
});
fireEvent.click(screen.getByRole("button", { name: /^Link$/ }));
await waitFor(() => expect(api.link).toHaveBeenCalledWith("kb", "/tmp/research-notes"));
await waitFor(() => expect(screen.getByText("/tmp/research-notes")).toBeVisible());
expect(screen.getByText("Folder linked.")).toBeVisible();
});
it("reports a completed no-op sync", async () => {
api.list.mockResolvedValue([folder]);
render(<KbLinkedFoldersSection kbName="kb" />);
fireEvent.click(await screen.findByRole("button", { name: "Sync now" }));
expect(await screen.findByText("No new or modified files to sync.")).toBeVisible();
expect(api.sync).toHaveBeenCalledWith("kb", "folder-1");
});
it("shows the last successful sync time", async () => {
api.list.mockResolvedValue([
{ ...folder, last_sync: "2026-09-09T12:00:00" },
]);
render(<KbLinkedFoldersSection kbName="kb" />);
expect(
await screen.findByText((_, element) =>
Boolean(element?.textContent?.startsWith("Last synced:")),
),
).toBeVisible();
});
it("unlinks a folder and refreshes the list", async () => {
api.list.mockResolvedValue([folder]);
render(<KbLinkedFoldersSection kbName="kb" />);
fireEvent.click(await screen.findByRole("button", { name: "Unlink folder" }));
await waitFor(() => expect(api.unlink).toHaveBeenCalledWith("kb", "folder-1"));
expect(await screen.findByText("Folder unlinked.")).toBeVisible();
});
it("streams a changed-folder sync through the shared task hook", async () => {
api.list.mockResolvedValue([folder]);
api.sync.mockResolvedValue({
message: "Syncing 2 files from linked folder",
file_count: 2,
task_id: "folder-task",
});
render(<KbLinkedFoldersSection kbName="kb" />);
fireEvent.click(await screen.findByRole("button", { name: "Sync now" }));
await waitFor(() =>
expect(api.startTask).toHaveBeenCalledWith(
expect.objectContaining({ kbName: "kb", taskId: "folder-task" }),
),
);
});

View File

@@ -39,6 +39,22 @@ afterEach(() => {
vi.restoreAllMocks();
});
it("loads linked folders with the qualified workspace KB reference", async () => {
const qualified = "workspace:course-1:kb:papers";
render(
<KbLinkedFoldersSection
kb={{ ...kb, id: qualified }}
onLinkFolder={vi.fn()}
onUnlinkFolder={vi.fn()}
onSyncFolder={vi.fn()}
/>,
);
await waitFor(() =>
expect(fixture.list).toHaveBeenCalledWith(qualified, expect.any(Object)),
);
});
it("links a folder without automatically starting its first sync", async () => {
const onLinkFolder = vi.fn().mockResolvedValue(undefined);
const onUnlinkFolder = vi.fn().mockResolvedValue(undefined);

View File

@@ -51,6 +51,9 @@ const kb = {
const actions = {
onCreate: vi.fn(),
onUpload: vi.fn(),
onLinkFolder: vi.fn(),
onUnlinkFolder: vi.fn(),
onSyncFolder: vi.fn(),
onReindex: vi.fn(),
onUpdatePendingIndexingPolicy: vi.fn(),
onRetry: vi.fn(),

View File

@@ -85,6 +85,9 @@ it("shows detail guidance while files and downloads remain accessible", async ()
history={[]}
onCreate={vi.fn()}
onUpload={vi.fn()}
onLinkFolder={vi.fn()}
onUnlinkFolder={vi.fn()}
onSyncFolder={vi.fn()}
onReindex={vi.fn()}
onRetry={vi.fn()}
onSetDefault={vi.fn()}

View File

@@ -315,6 +315,9 @@ it.each(["header", "documents"])(
history={[]}
onCreate={vi.fn()}
onUpload={vi.fn()}
onLinkFolder={vi.fn()}
onUnlinkFolder={vi.fn()}
onSyncFolder={vi.fn()}
onReindex={reindex}
onRetry={retry}
onSetDefault={vi.fn()}

View File

@@ -64,11 +64,11 @@ test("linked-folder API methods preserve encoded resource identifiers", async ()
}
assert.equal(
requests[0].url,
requests[0].url.split("?")[0],
"/api/knowledge-bases/Team%20Notes%2F2026/linked-folders",
);
assert.equal(
requests[1].url,
requests[1].url.split("?")[0],
"/api/knowledge-bases/Team%20Notes%2F2026/link-folder",
);
assert.equal(requests[1].init?.method, "POST");
@@ -76,12 +76,12 @@ test("linked-folder API methods preserve encoded resource identifiers", async ()
folder_path: "/notes",
});
assert.equal(
requests[2].url,
requests[2].url.split("?")[0],
"/api/knowledge-bases/Team%20Notes%2F2026/linked-folders/folder%2F1",
);
assert.equal(requests[2].init?.method, "DELETE");
assert.equal(
requests[3].url,
requests[3].url.split("?")[0],
"/api/knowledge-bases/Team%20Notes%2F2026/sync-folder/folder%2F1",
);
assert.equal(requests[3].init?.method, "POST");