mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 06:19:43 +08:00
Remove course pages, APIs and the course_study capability. Add anchored note threads and reviewed learning-block generation, queued and withdrawable chat messages, quote attachments, side chats, and the calendar/favorites/navigation updates. Keep preview's existing backend architecture. Wire the new features through its Python application and existing chat engine, retain legacy selected-text requests, persist mid-turn messages in replay, and restore note context when regenerating. Leave stored user data intact. Validate frontend contracts, dependency boundaries, types, 1290 node tests, 840 rendered tests, lint, localization and the production build. Exercise session/notes/API regressions, 53 chat-engine tests and 20 Python/native integration tests with isolated runtime data.
135 lines
4.5 KiB
TypeScript
135 lines
4.5 KiB
TypeScript
import { readingSessionIdFromPath } from "../lib/learning-routes";
|
|
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
masteryPathIdOf,
|
|
readingWorkspaceIdOf,
|
|
sessionRoute,
|
|
} from "../lib/mastery-session";
|
|
import type { SessionSummary } from "../lib/session-api";
|
|
import { workspaceActionNeedsConfiguration } from "../lib/workspace-mode";
|
|
|
|
function session(preferences: SessionSummary["preferences"]): SessionSummary {
|
|
return {
|
|
id: "session-1",
|
|
session_id: "session-1",
|
|
title: "Learning session",
|
|
created_at: 1,
|
|
updated_at: 1,
|
|
message_count: 1,
|
|
last_message: "hello",
|
|
preferences,
|
|
};
|
|
}
|
|
|
|
test("mastery ownership survives switching the per-turn action", () => {
|
|
const item = session({
|
|
workspace_mode: "mastery_path",
|
|
mastery_path_id: "path-42",
|
|
capability: "deep_research",
|
|
});
|
|
|
|
assert.equal(masteryPathIdOf(item), "path-42");
|
|
});
|
|
|
|
test("reading ownership survives switching the per-turn action", () => {
|
|
const item = session({
|
|
workspace_mode: "immersive_reading",
|
|
reading_workspace_id: "reading-42",
|
|
capability: "visualize",
|
|
});
|
|
|
|
assert.equal(readingWorkspaceIdOf(item), "reading-42");
|
|
});
|
|
|
|
test("capability and retired session-kind fields do not claim workspace ownership", () => {
|
|
assert.equal(
|
|
masteryPathIdOf(
|
|
session({ capability: "mastery_path", mastery_path_id: "legacy-path" }),
|
|
),
|
|
"",
|
|
);
|
|
assert.equal(
|
|
readingWorkspaceIdOf(
|
|
session({
|
|
capability: "immersive_reading",
|
|
session_kind: "immersive_reading",
|
|
reading_workspace_id: "legacy-reading",
|
|
}),
|
|
),
|
|
"",
|
|
);
|
|
});
|
|
|
|
test("unrelated sessions do not inherit stale learning ids", () => {
|
|
assert.equal(
|
|
masteryPathIdOf(
|
|
session({ capability: "chat", mastery_path_id: "stale-path" }),
|
|
),
|
|
"",
|
|
);
|
|
assert.equal(
|
|
readingWorkspaceIdOf(
|
|
session({ capability: "chat", reading_workspace_id: "stale-reading" }),
|
|
),
|
|
"",
|
|
);
|
|
});
|
|
|
|
test("configured workspace actions do not bypass their settings", () => {
|
|
assert.equal(workspaceActionNeedsConfiguration("deep_question"), true);
|
|
assert.equal(workspaceActionNeedsConfiguration("visualize"), true);
|
|
assert.equal(workspaceActionNeedsConfiguration("deep_research"), true);
|
|
assert.equal(workspaceActionNeedsConfiguration("deep_solve"), false);
|
|
assert.equal(workspaceActionNeedsConfiguration(""), false);
|
|
});
|
|
|
|
/* ── Reading URLs, both directions ──────────────────────────────────────
|
|
The workspace writes the first turn's session id into the address bar with
|
|
the native history API, because moving between `/learning/reading/<ws>` and
|
|
`/learning/reading/<ws>/sessions/<id>` through the router unmounts the whole reader
|
|
mid-answer. That only holds together if reading the URL back agrees with
|
|
writing it: were they to disagree, the first question of a conversation
|
|
would land on a URL the workspace then reads as "start a new one". */
|
|
|
|
test("a reading conversation route round-trips through the path parser", () => {
|
|
const route = sessionRoute(
|
|
session({
|
|
workspace_mode: "immersive_reading",
|
|
reading_workspace_id: "rw_42",
|
|
}),
|
|
);
|
|
|
|
assert.equal(route, "/learning/reading/rw_42/sessions/session-1?dt_workspace=");
|
|
assert.equal(readingSessionIdFromPath(route), "session-1");
|
|
});
|
|
|
|
test("a bare collection URL means a new conversation, not a stored one", () => {
|
|
assert.equal(readingSessionIdFromPath("/learning/reading/rw_42"), null);
|
|
assert.equal(readingSessionIdFromPath("/learning/reading/rw_42/sessions"), null);
|
|
assert.equal(readingSessionIdFromPath("/learning/reading/rw_42/sessions/"), null);
|
|
assert.equal(readingSessionIdFromPath("/learning/reading"), null);
|
|
});
|
|
|
|
test("reading session ids survive URL encoding and trailing path noise", () => {
|
|
assert.equal(
|
|
readingSessionIdFromPath("/learning/reading/rw%2042/sessions/unified_1_a%2Fb"),
|
|
"unified_1_a/b",
|
|
);
|
|
assert.equal(
|
|
readingSessionIdFromPath("/learning/reading/rw_42/sessions/abc?tab=notes"),
|
|
"abc",
|
|
);
|
|
});
|
|
|
|
test("only reading URLs are read as reading conversations", () => {
|
|
assert.equal(readingSessionIdFromPath("/chat/abc"), null);
|
|
assert.equal(readingSessionIdFromPath("/learning/mastery/p1/sessions/abc"), null);
|
|
});
|
|
|
|
test("a note companion conversation opens back on its page with its thread", () => {
|
|
const item = session({ note_document_id: "0c2d24985c4f" });
|
|
assert.match(sessionRoute(item), /^\/co-writer\/0c2d24985c4f\?chat=session-1/);
|
|
});
|