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 analysisSource = fs.readFileSync(path.join(root, "src/views/analysis-of-students/analysis.vue"), "utf8"); const dialogueSource = fs.readFileSync(path.join(root, "src/views/analysis-of-students/dialogue.vue"), "utf8"); test("learning analysis request does not send the commerce login token", () => { const requestBlock = apiSource.match(/export function getLearningAnalysis[\s\S]*?\n}/)?.[0] || ""; assert.match(requestBlock, /headers:\s*\{\s*isToken:\s*false\s*}/); assert.match(requestBlock, /params:\s*\{\s*stuNeed\s*}/); }); test("learning analysis page sends current training scores and learning activity data", () => { assert.match(analysisSource, /暂无成绩数据,暂时无法进行AI学情分析/); assert.match(analysisSource, /getCurrentExperimentReport/); assert.match(analysisSource, /getStudyTime/); assert.match(analysisSource, /getUserVisitCount/); assert.match(analysisSource, /trainingScores/); assert.match(analysisSource, /learningData/); assert.match(analysisSource, /learningAnalysisData/); assert.doesNotMatch(analysisSource, /getStuModuleDetail/); assert.match(analysisSource, /completedTaskCount/); assert.match(analysisSource, /if \(!hasScoreData\.value\)/); assert.match(analysisSource, /finally\s*\{\s*scoreLoaded\.value = true/); }); test("AI analysis failure always closes the loading overlay", () => { assert.match(dialogueSource, /learningAnalysisData/); assert.match(dialogueSource, /AI学情分析暂时不可用,请稍后重试/); assert.match(dialogueSource, /finally\s*\{\s*loading\.value = false/); });