You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dianshang-qianduan/tests/ai-learning-analysis-fallba...

40 lines
2.0 KiB
JavaScript

const fs = require("node:fs");
const path = require("node:path");
const test = require("node:test");
const assert = require("node:assert/strict");
const root = path.resolve(__dirname, "..");
const apiSource = fs.readFileSync(path.join(root, "src/api/AI.js"), "utf8");
const dialogueSource = fs.readFileSync(path.join(root, "src/views/analysis-of-students/dialogue.vue"), "utf8");
const indexApiSource = fs.readFileSync(path.join(root, "src/api/index.js"), "utf8");
const projectStudyTimeSource = fs.readFileSync(path.join(root, "src/api/projectStudyTime.js"), "utf8");
test("learning analysis api treats AI service error text as failure", () => {
const requestBlock = apiSource.match(/export function getLearningAnalysis[\s\S]*?\n}/)?.[0] || "";
assert.match(requestBlock, /\^error\\b\/i/);
assert.match(requestBlock, /throw new Error\(text\)/);
});
test("dialogue page falls back to the AI chat channel with the same learning data", () => {
assert.match(dialogueSource, /openAssistantStream/);
const fallbackBlock = dialogueSource.match(/专用学情分析接口不可用时[\s\S]*?openAssistantStream\([\s\S]*?\);/)?.[0] || "";
assert.match(fallbackBlock, /stuNeed/);
assert.match(fallbackBlock, /JSON\.stringify\(stuData\)/);
});
test("kimi4 stream requests fail loudly on non-2xx responses", () => {
assert.match(dialogueSource, /if \(!resp\.ok \|\| !resp\.body\)/);
});
test("sendMessage never leaves the pending state stuck", () => {
const sendBlock = dialogueSource.match(/const sendMessage = async \(\) => \{[\s\S]*?\n};/)?.[0] || "";
assert.match(sendBlock, /finally\s*\{\s*isRequestPending\.value = false/);
});
test("score apis suppress duplicate interceptor toasts", () => {
const reportBlock = indexApiSource.match(/export const getCurrentExperimentReport[\s\S]*?\n}/)?.[0] || "";
const studyTimeBlock = projectStudyTimeSource.match(/export function getCurrentProjectStudyTime[\s\S]*?\n}/)?.[0] || "";
assert.match(reportBlock, /skipErrorMessage:\s*true/);
assert.match(studyTimeBlock, /skipErrorMessage:\s*true/);
});