import test from 'node:test'; import assert from 'node:assert/strict'; import { buildPageGenerateAgentPrompt } from './prompts/page-generate.mjs'; import { buildPageRefineTargetPromptBlock, buildWechatPageRefineUserMessageTemplate, extractMindSpacePublicHtmlPath, isWechatPageRefineRequestText, } from './page-refine-target.mjs'; test('extractMindSpacePublicHtmlPath parses MindSpace public URLs', () => { assert.equal( extractMindSpacePublicHtmlPath( 'https://m.tkmind.cn/MindSpace/a70ff537-8908-486e-9b6c-042e07cc25db/public/shengsi-3day-guide.html请改详细', ), 'public/shengsi-3day-guide.html', ); assert.equal(extractMindSpacePublicHtmlPath('public/demo.html'), null); }); test('buildPageRefineTargetPromptBlock pins relative path for URL refine', () => { const block = buildPageRefineTargetPromptBlock( 'https://m.tkmind.cn/MindSpace/a70ff537-8908-486e-9b6c-042e07cc25db/public/shengsi-3day-guide.html 页面更详细到时间节点', ); assert.match(block, /public\/shengsi-3day-guide\.html/); assert.match(block, /edit_file/); }); test('buildPageRefineTargetPromptBlock covers refine without URL', () => { const block = buildPageRefineTargetPromptBlock('页面还不够详细,必须详细到时间节点'); assert.match(block, /改页任务/); assert.doesNotMatch(block, /相对路径:public\//); }); test('buildPageGenerateAgentPrompt includes page refine target block', () => { const prompt = buildPageGenerateAgentPrompt({ agentText: 'https://m.tkmind.cn/MindSpace/a70ff537-8908-486e-9b6c-042e07cc25db/public/shengsi-3day-guide.html 把页面更新更详细', }); assert.match(prompt, /改页目标文件/); assert.match(prompt, /public\/shengsi-3day-guide\.html/); }); test('buildWechatPageRefineUserMessageTemplate formats copy-paste message', () => { const text = buildWechatPageRefineUserMessageTemplate({ publicHtmlPath: 'public/shengsi-3day-guide.html', requirements: '按 Day1/Day2/Day3 细化到具体时间点', publicUrl: 'https://m.tkmind.cn/MindSpace/u/public/shengsi-3day-guide.html', }); assert.match(text, /public\/shengsi-3day-guide\.html/); assert.match(text, /Day1/); assert.match(text, /不要新建页面/); }); test('isWechatPageRefineRequestText detects refine intents', () => { assert.equal(isWechatPageRefineRequestText('页面还不够详细'), true); assert.equal(isWechatPageRefineRequestText('帮我推荐跑步路线'), false); });