Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix: restore formatting and deterministic CI checks

NoxsMedia86aa5d0edf36
diff --git a/deeptutor/learning/tests/test_mastery_mode.py b/deeptutor/learning/tests/test_mastery_mode.py
index 83f80aec3..eae7def2f 100644
--- a/deeptutor/learning/tests/test_mastery_mode.py
+++ b/deeptutor/learning/tests/test_mastery_mode.py
@@ -8,6 +8,7 @@ that is exactly where the guarantee now is.
from __future__ import annotations
import json
+from pathlib import Path
import pytest
@@ -397,16 +398,18 @@ async def test_a_built_goal_reports_its_identity_too(path_id):
def _pack(language: str) -> dict:
import yaml
- return yaml.safe_load(
- open(f"deeptutor/capabilities/mastery/prompts/{language}/mastery_loop.yaml")
- )
+ prompts = Path(__file__).resolve().parents[2] / "capabilities" / "mastery" / "prompts"
+ return yaml.safe_load((prompts / language / "mastery_loop.yaml").read_text(encoding="utf-8"))
-def test_study_never_offers_to_do_the_reviewing_itself():
+def test_study_never_offers_to_do_the_reviewing_itself(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
"""The sentence this guards taught the tutor that due reviews are study's
to handle, so "I want to review" was answered by quizzing a due item
without leaving study — the learner asked for a mode and got a workaround.
"""
+ monkeypatch.chdir(tmp_path)
for language in ("zh", "en"):
study = _pack(language)["session"]["study"]
assert "mastery_status" in study
@@ -416,7 +419,10 @@ def test_study_never_offers_to_do_the_reviewing_itself():
assert "review" in study
-def test_naming_an_activity_is_documented_as_a_mode_request():
+def test_naming_an_activity_is_documented_as_a_mode_request(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ monkeypatch.chdir(tmp_path)
for language in ("zh", "en"):
playbook = _pack(language)["playbook"]
assert "mastery_mode" in playbook
@@ -424,9 +430,12 @@ def test_naming_an_activity_is_documented_as_a_mode_request():
assert marker in playbook, language
-def test_the_outline_metaphor_is_gone_from_learner_facing_copy():
+def test_the_outline_metaphor_is_gone_from_learner_facing_copy(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
"""'Map' was a metaphor the product does not use anywhere the learner can
see; the word is 'outline'."""
+ monkeypatch.chdir(tmp_path)
for language in ("zh", "en"):
pack = _pack(language)
blob = "\n".join(
diff --git a/deeptutor/skills/builtin/docx/SKILL.md b/deeptutor/skills/builtin/docx/SKILL.md
index 999b6baa0..8c059544c 100644
--- a/deeptutor/skills/builtin/docx/SKILL.md
+++ b/deeptutor/skills/builtin/docx/SKILL.md
@@ -83,6 +83,7 @@ doc.save("out.docx")
check = Document("out.docx")
assert check.paragraphs, "generated DOCX has no paragraphs"
import zipfile
+
with zipfile.ZipFile("out.docx") as package:
assert package.testzip() is None, "generated DOCX has a corrupt ZIP member"
```
diff --git a/deeptutor/skills/builtin/xlsx/SKILL.md b/deeptutor/skills/builtin/xlsx/SKILL.md
index 25e1e6dfe..ec937edfe 100644
--- a/deeptutor/skills/builtin/xlsx/SKILL.md
+++ b/deeptutor/skills/builtin/xlsx/SKILL.md
@@ -107,6 +107,7 @@ wb.save("out.xlsx")
check = load_workbook("out.xlsx", data_only=False)
assert check.sheetnames, "generated workbook has no worksheets"
import zipfile
+
with zipfile.ZipFile("out.xlsx") as package:
assert package.testzip() is None, "generated XLSX has a corrupt ZIP member"
```
diff --git a/web/components/sidebar/SidebarShell.tsx b/web/components/sidebar/SidebarShell.tsx
index 91aa81395..ef632de7f 100644
--- a/web/components/sidebar/SidebarShell.tsx
+++ b/web/components/sidebar/SidebarShell.tsx
@@ -1,6 +1,7 @@
"use client";
import Image from "next/image";
+import dynamic from "next/dynamic";
import Link from "next/link";
import { usePathname, useRouter } from "next/navigation";
import {
@@ -14,7 +15,6 @@ import { useAppShell } from "@/context/AppShellContext";
import { BookText, PanelLeftClose, PanelLeftOpen } from "lucide-react";
import { useTranslation } from "react-i18next";
import { BrandGlyph } from "@/components/common/BrandIcon";
-import OrganizedSessionList from "@/components/courses/OrganizedSessionList";
import SessionList from "@/components/SessionList";
import { useSidebarDrawer } from "@/components/layout/AppShell";
import { useDevice } from "@/hooks/useDevice";
@@ -37,6 +37,25 @@ import {
const GITHUB_REPO_URL = "https://github.com/HKUDS/DeepTutor";
const DOCS_URL = "https://deeptutor.info/";
+// Session data arrives after mount; defer its organization UI with it so
+// every workspace route does not download it as part of the initial shell.
+const OrganizedSessionList = dynamic(
+ () => import("@/components/courses/OrganizedSessionList"),
+ {
+ ssr: false,
+ loading: () => (
+ <div aria-busy="true" className="space-y-1.5 px-2 py-1">
+ {[1, 2, 3].map((i) => (
+ <div
+ key={i}
+ className="h-4 w-3/4 animate-pulse rounded bg-[var(--muted)]/40"
+ />
+ ))}
+ </div>
+ ),
+ },
+);
+
interface SidebarShellProps {
sessions?: SessionSummary[];
activeSessionId?: string | null;
diff --git a/web/features/co-writer/components/CoWriterWorkspace.tsx b/web/features/co-writer/components/CoWriterWorkspace.tsx
index 8fc97059b..7b2249fd7 100644
--- a/web/features/co-writer/components/CoWriterWorkspace.tsx
+++ b/web/features/co-writer/components/CoWriterWorkspace.tsx
@@ -71,9 +71,7 @@ import { useSelectionEdit } from "@/features/co-writer/hooks/useSelectionEdit";
import { useSplitPane } from "@/features/co-writer/hooks/useSplitPane";
import { useSynchronizedScroll } from "@/features/co-writer/hooks/useSynchronizedScroll";
import { useDocumentLifecycle } from "@/features/co-writer/hooks/useDocumentLifecycle";
-import SaveToNotebookModal, {
- type NotebookSavePayload,
-} from "@/components/notebook/SaveToNotebookModal";
+import type { NotebookSavePayload } from "@/components/notebook/SaveToNotebookModal";
import { CO_WRITER_SAMPLE_TEMPLATE } from "@/app/(workspace)/co-writer/sampleTemplate";
const MarkdownRenderer = dynamic(
@@ -83,6 +81,11 @@ const MarkdownRenderer = dynamic(
},
);
+const SaveToNotebookModal = dynamic(
+ () => import("@/components/notebook/SaveToNotebookModal"),
+ { ssr: false },
+);
+
type EditAction = "rewrite" | "shorten" | "expand";
type SelectionMode = EditAction | "none";
type SourceOption = "none" | "rag" | "web";
diff --git a/web/tests/co-writer-lazy-notebook.spec.tsx b/web/tests/co-writer-lazy-notebook.spec.tsx
new file mode 100644
index 000000000..d4f449bd9
--- /dev/null
+++ b/web/tests/co-writer-lazy-notebook.spec.tsx
@@ -0,0 +1,48 @@
+import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
+import { expect, it, vi } from "vitest";
+import CoWriterWorkspace from "@/features/co-writer/components/CoWriterWorkspace";
+
+vi.mock("next/navigation", () => ({ useRouter: () => ({ push: vi.fn() }) }));
+vi.mock("react-i18next", () => ({
+ useTranslation: () => ({ t: (key: string) => key, i18n: { language: "en" } }),
+}));
+vi.mock("@/components/common/MarkdownRenderer", () => ({ default: () => null }));
+vi.mock("@/features/knowledge/api/catalog", () => ({
+ listKnowledgeBases: vi.fn().mockResolvedValue([]),
+}));
+vi.mock("@/lib/co-writer-api", () => ({
+ getCoWriterDocument: vi.fn().mockResolvedValue({
+ id: "document-1",
+ title: "Existing document",
+ content: "Existing draft content",
+ updated_at: 1,
+ }),
+ updateCoWriterDocument: vi.fn().mockResolvedValue({}),
+ exportCoWriterDocx: vi.fn(),
+}));
+vi.mock("@/lib/notebook-api", () => ({
+ listNotebooks: vi.fn().mockResolvedValue([{ id: "notebook-1", name: "My notebook" }]),
+ createNotebook: vi.fn(),
+}));
+
+it("opens and closes the dynamically loaded notebook picker without changing the draft", async () => {
+ vi.stubGlobal(
+ "ResizeObserver",
+ class {
+ observe() {}
+ disconnect() {}
+ },
+ );
+ try {
+ render(<CoWriterWorkspace docId="document-1" />);
+ expect(await screen.findByDisplayValue("Existing draft content")).toBeInTheDocument();
+ fireEvent.click(screen.getByRole("button", { name: "Save to Notebook" }));
+ const dialog = await screen.findByRole("dialog", { name: "Save to Notebook" });
+ expect(await within(dialog).findByText("My notebook")).toBeInTheDocument();
+ fireEvent.click(within(dialog).getByRole("button", { name: "Close" }));
+ await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
+ expect(screen.getByDisplayValue("Existing draft content")).toBeInTheDocument();
+ } finally {
+ vi.unstubAllGlobals();
+ }
+});
diff --git a/web/tests/sidebar-lazy-history.spec.tsx b/web/tests/sidebar-lazy-history.spec.tsx
new file mode 100644
index 000000000..3ac3d3666
--- /dev/null
+++ b/web/tests/sidebar-lazy-history.spec.tsx
@@ -0,0 +1,72 @@
+import { act, fireEvent, render, screen } from "@testing-library/react";
+import { expect, it, vi } from "vitest";
+import { SidebarShell } from "@/components/sidebar/SidebarShell";
+
+const fixture = vi.hoisted(() => ({ push: vi.fn(), close: vi.fn() }));
+
+vi.mock("next/navigation", () => ({
+ usePathname: () => "/co-writer",
+ useRouter: () => ({ push: fixture.push }),
+}));
+vi.mock("next/image", () => ({ default: () => null }));
+vi.mock("react-i18next", () => ({
+ useTranslation: () => ({ t: (key: string) => key, i18n: { language: "en" } }),
+}));
+vi.mock("@/context/AppShellContext", () => ({
+ useAppShell: () => ({ sidebarCollapsed: false, setSidebarCollapsed: vi.fn() }),
+}));
+vi.mock("@/components/layout/AppShell", () => ({
+ useSidebarDrawer: () => ({ close: fixture.close }),
+}));
+vi.mock("@/hooks/useDevice", () => ({
+ useDevice: () => ({ isMobile: false }),
+}));
+vi.mock("@/components/sidebar/VersionBadge", () => ({
+ VersionBadge: () => null,
+}));
+
+it("loads conversation history while navigation remains usable, then preserves session actions", async () => {
+ const onSelect = vi.fn();
+ const onRename = vi.fn();
+ const onOrganize = vi.fn();
+ const { container } = render(
+ <SidebarShell
+ showSessions
+ sessions={[
+ {
+ id: "session-1",
+ session_id: "session-1",
+ title: "Retained session",
+ created_at: 1,
+ updated_at: 1,
+ message_count: 1,
+ last_message: "Hello",
+ },
+ ]}
+ onSelectSession={onSelect}
+ onRenameSession={onRename}
+ onDeleteSession={vi.fn()}
+ onOrganizeSession={onOrganize}
+ />,
+ );
+ expect(container.querySelector('[aria-busy="true"]')).toBeInTheDocument();
+ expect(screen.getByRole("link", { name: "Co-Writer" })).toHaveAttribute("href", "/co-writer");
+
+ fireEvent.click(await screen.findByText("Retained session"));
+ expect(onSelect).toHaveBeenCalledWith("session-1");
+ expect(fixture.close).toHaveBeenCalled();
+ expect(container.querySelector('[aria-busy="true"]')).not.toBeInTheDocument();
+
+ fireEvent.click(screen.getByRole("button", { name: "Conversation actions" }));
+ fireEvent.click(screen.getByRole("menuitem", { name: "Pin" }));
+ expect(onOrganize).toHaveBeenCalledWith("session-1", { pinned: true });
+
+ fireEvent.click(screen.getByRole("button", { name: "Conversation actions" }));
+ fireEvent.click(screen.getByRole("menuitem", { name: "Rename chat" }));
+ const input = screen.getByDisplayValue("Retained session");
+ fireEvent.change(input, { target: { value: "Renamed session" } });
+ await act(async () => {
+ fireEvent.keyDown(input, { key: "Enter" });
+ });
+ expect(onRename).toHaveBeenCalledWith("session-1", "Renamed session");
+});