mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 10:20:23 +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.
176 lines
6.6 KiB
TypeScript
176 lines
6.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
buildStartTurnInput,
|
|
legacySendMessageInput,
|
|
} from "../features/chat/controllers/buildStartTurnInput";
|
|
import type { StartTurnInput } from "../features/chat/model/start-turn";
|
|
import { ApiError } from "../shared/api/errors";
|
|
|
|
test("media-only turns are valid while a completely empty turn is rejected", () => {
|
|
const attachments = [{ type: "image" as const, filename: "figure.png", base64: "YWJj" }];
|
|
const wire = buildStartTurnInput({ content: "", attachments });
|
|
assert.equal(wire.content, "");
|
|
assert.deepEqual(wire.attachments, attachments);
|
|
assert.throws(() => buildStartTurnInput({ content: "", attachments: [] }), /must not be empty/);
|
|
});
|
|
|
|
test("plain, quiz, research, and visualize turns use one typed mapper", () => {
|
|
const matrix: StartTurnInput[] = [
|
|
{ content: "hello", capability: "chat" },
|
|
{
|
|
content: "quiz me",
|
|
capability: "deep_question",
|
|
capabilityConfig: { difficulty: "medium" },
|
|
allowedCapabilityConfigKeys: ["difficulty"],
|
|
},
|
|
{
|
|
content: "research",
|
|
capability: "deep_research",
|
|
capabilityConfig: { breadth: 3 },
|
|
allowedCapabilityConfigKeys: ["breadth"],
|
|
},
|
|
{
|
|
content: "draw",
|
|
capability: "visualize",
|
|
capabilityConfig: { render_type: "mermaid" },
|
|
allowedCapabilityConfigKeys: ["render_type"],
|
|
},
|
|
];
|
|
for (const input of matrix) {
|
|
const wire = buildStartTurnInput(input);
|
|
assert.equal(wire.type, "start_turn");
|
|
assert.equal(wire.protocol_version, "2.0");
|
|
assert.equal(wire.capability, input.capability);
|
|
}
|
|
});
|
|
|
|
test("Reading, Mastery, references, edit, and budget are explicit", () => {
|
|
const wire = buildStartTurnInput({
|
|
content: "continue",
|
|
sessionId: "session-1",
|
|
workspaceMode: "immersive_reading",
|
|
masteryPathId: "path-1",
|
|
readingWorkspaceId: "reading-1",
|
|
readingMaterialId: "material-1",
|
|
readingMaterialRevision: 2,
|
|
readingViewport: { locator: 4, selection: "proof" },
|
|
parentMessageId: 9,
|
|
subagentConsultBudget: 3,
|
|
notebookReferences: [{ notebook_id: "nb", record_ids: ["r1"] }],
|
|
bookReferences: [{ book_id: "book", page_ids: ["p1"] }],
|
|
readingReferences: [
|
|
{ material_id: "material-1", revision: 2, locators: [4] },
|
|
],
|
|
attachments: [{ type: "document", filename: "notes.pdf", url: "/a" }],
|
|
});
|
|
assert.equal(wire.parent_message_id, 9);
|
|
assert.equal(wire.subagent_consult_budget, 3);
|
|
assert.equal(wire.reading_viewport?.locator, 4);
|
|
});
|
|
|
|
test("waiting-input replies stay commands and runtime config cannot leak into capability config", () => {
|
|
assert.throws(
|
|
() =>
|
|
buildStartTurnInput({
|
|
content: "bad",
|
|
capabilityConfig: { _persist_user_message: false },
|
|
}),
|
|
(error) => error instanceof ApiError && error.code === "invalid_turn_input",
|
|
);
|
|
assert.throws(
|
|
() =>
|
|
buildStartTurnInput({
|
|
content: "bad",
|
|
capabilityConfig: { unexpected: true },
|
|
allowedCapabilityConfigKeys: ["difficulty"],
|
|
}),
|
|
/Unsupported/,
|
|
);
|
|
|
|
const wire = buildStartTurnInput({ content: "ok" });
|
|
assert.equal("subagent_consult_budget" in (wire.config ?? {}), false);
|
|
});
|
|
|
|
test("optional routing fields preserve omitted versus explicit null", () => {
|
|
const omitted = buildStartTurnInput({ content: "append" });
|
|
const explicit = buildStartTurnInput({
|
|
content: "root edit",
|
|
capability: null,
|
|
parentMessageId: null,
|
|
});
|
|
|
|
assert.equal("parent_message_id" in omitted, false);
|
|
assert.equal(explicit.parent_message_id, null);
|
|
assert.equal(explicit.capability, null);
|
|
});
|
|
|
|
test("a draft's reply language selector is explicit and a normal turn preserves the session choice", () => {
|
|
const normal = buildStartTurnInput({ content: "Continue", sessionId: "session-1", language: "en" });
|
|
const fixed = buildStartTurnInput({
|
|
content: "用法语教我数学",
|
|
language: "zh",
|
|
replyLanguageOverride: "fr",
|
|
});
|
|
const cleared = buildStartTurnInput({ content: "Use default", replyLanguageOverride: null });
|
|
|
|
assert.equal("reply_language_override" in normal, false);
|
|
assert.equal(fixed.reply_language_override, "fr");
|
|
assert.equal(fixed.language, "zh");
|
|
assert.equal(cleared.reply_language_override, null);
|
|
});
|
|
|
|
test("the positional compatibility adapter produces object-shaped input", () => {
|
|
const input = legacySendMessageInput(
|
|
{ content: "legacy", config: { difficulty: "hard" } },
|
|
{
|
|
capability: "deep_question",
|
|
allowedCapabilityConfigKeys: ["difficulty"],
|
|
sessionId: "session-1",
|
|
},
|
|
);
|
|
assert.equal(input.content, "legacy");
|
|
assert.deepEqual(input.capabilityConfig, { difficulty: "hard" });
|
|
assert.equal(buildStartTurnInput(input).session_id, "session-1");
|
|
});
|
|
|
|
test("consultation selections travel as runtime fields, not capability config", () => {
|
|
for (const capability of ["chat", "deep_solve", "visualize"]) {
|
|
for (const selection of [{}, { consultPartnerId: "partner-1" }, { partnerDiscussionGroupId: "group-1" }]) {
|
|
const wire = buildStartTurnInput({ content: "什么是agent", capability, ...selection });
|
|
assert.deepEqual(wire.config, {});
|
|
assert.equal(wire.consult_partner_id, selection.consultPartnerId);
|
|
assert.equal(wire.partner_discussion_group_id, selection.partnerDiscussionGroupId);
|
|
}
|
|
}
|
|
for (const key of ["consult_partner_id", "partner_discussion_group_id"]) {
|
|
assert.throws(() => buildStartTurnInput({ content: "hi", capabilityConfig: { [key]: "id" } }), /must use its typed turn property/);
|
|
}
|
|
});
|
|
|
|
test("a turn handed to someone names them as a typed property", () => {
|
|
const wire = buildStartTurnInput({ content: "Why does BM25 saturate?", answerBy: "partner:p1" });
|
|
assert.equal(wire.answer_by, "partner:p1");
|
|
assert.deepEqual(wire.config, {});
|
|
assert.equal(buildStartTurnInput({ content: "hi" }).answer_by, undefined);
|
|
assert.throws(
|
|
() => buildStartTurnInput({ content: "hi", capabilityConfig: { answer_by: "partner:p1" } }),
|
|
/must use its typed turn property/,
|
|
);
|
|
});
|
|
|
|
test("a note companion turn names its page and, when generating, the block", () => {
|
|
const wire = buildStartTurnInput({
|
|
content: "fill it",
|
|
capability: "chat",
|
|
noteDocumentId: "0c2d24985c4f",
|
|
noteGeneration: { block_id: "timeline-learning", kind: "timeline" },
|
|
});
|
|
assert.equal(wire.note_document_id, "0c2d24985c4f");
|
|
assert.deepEqual(wire.note_generation, { block_id: "timeline-learning", kind: "timeline" });
|
|
const plain = buildStartTurnInput({ content: "hello", capability: "chat" });
|
|
assert.equal("note_document_id" in plain, false);
|
|
assert.equal("note_generation" in plain, false);
|
|
});
|