Files
DeepTutor/web/tests/selection-tutor.test.ts
diffaudit-review cdbcacace4 fix: ground selection tutor in source message
Short selections such as rc carried only the raw token and an opaque parent session id. Capture the containing message id, resolve it from the parent session, and provide both the source message and exact selection to the tutor prompt.
2026-08-26 02:25:23 +08:00

46 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import test from "node:test";
import assert from "node:assert/strict";
import {
buildSelectionTutorConfig,
normalizeSelectedText,
selectionTutorKey,
} from "../lib/selection-tutor";
test("normalizes selected chat text without flattening paragraphs", () => {
assert.equal(
normalizeSelectedText(" first line\r\n\r\n\r\n second\tline "),
"first line\n\nsecond line",
);
});
test("selection tutor keys are stable per passage and parent session", () => {
const a = selectionTutorKey("rc", "session-a", 42);
assert.equal(a, selectionTutorKey("rc", "session-a", 42));
assert.notEqual(a, selectionTutorKey("rc", "session-b", 42));
assert.notEqual(a, selectionTutorKey("rc", "session-a", 43));
assert.notEqual(a, selectionTutorKey("wait() blocks", "session-a", 42));
});
test("builds selected text context with its containing message", () => {
assert.deepEqual(
buildSelectionTutorConfig({
selectedText: " rc ",
parentSessionId: "parent-1",
sourceMessageId: 42,
sourceMessageText:
"int rc = fork();\n父进程中的 rc 是子进程 PID,子进程中的 rc 是 0。",
sourceMessageRole: "assistant",
}),
{
selection_tutor_context: {
selected_text: "rc",
parent_session_id: "parent-1",
source_message_id: 42,
source_message_text:
"int rc = fork();\n父进程中的 rc 是子进程 PID,子进程中的 rc 是 0。",
source_message_role: "assistant",
},
},
);
});