Files
DeepTutor/web/tests/mastery-session.test.ts
Bingxi Zhao (Frank) da856ad670 release: v1.6.9
Ship folder-based workspaces and data migration, daily practice, redesigned
provider and model settings, and streaming conversation improvements.
Synchronize README translations and document the archive/permanent-delete
upgrade behavior in assets/releases/ver1-6-9.md.

Reduce initial JavaScript by deduplicating English resources and loading
animation features after hydration. Keep the existing route size budgets.
Update regression fixtures and browser audits for scoped URLs and the new
settings and learning interfaces.
2026-09-21 02:30:40 +08:00

130 lines
4.3 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);
});