fix: stabilize MindSpace local workflows

Signed-off-by: john <cynell@139.com>
This commit is contained in:
john
2026-07-12 08:12:15 +08:00
parent 32fb2cdeaf
commit a3f669d4e7
9 changed files with 107 additions and 23 deletions
+36 -11
View File
@@ -31,12 +31,22 @@ const BASE_URL = `http://127.0.0.1:${portalPort}`;
const HTML_NAME = 'fruit-theme-test.html';
const USERNAME = 'john';
const JOHN_PASSWORD = process.env.JOHN_PASSWORD ?? process.env.H5_ACCESS_PASSWORD ?? '981122tj';
const publishDir = path.join(root, 'MindSpace', USERNAME);
const htmlPath = path.join(publishDir, HTML_NAME);
const thumbRel = workspaceThumbnailRelativePath(HTML_NAME);
const publicPageUrl = buildPublicUrl(BASE_URL, USERNAME, HTML_NAME);
const publicThumbUrl = buildPublicUrl(BASE_URL, USERNAME, thumbRel);
const agentReplyLink = `[夏日鲜果指南 · 水果主题测试](${publicPageUrl})`;
const thumbPngRel = thumbRel.replace(/\.svg$/i, '.png');
let publishDir = null;
let htmlPath = null;
let publicPageUrl = null;
let publicThumbUrl = null;
const fixtureHtml = `<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="mindspace-cover" content="夏日鲜果指南,美食与水果主题">
<title>夏日鲜果指南</title>
</head>
<body><main><h1>夏日鲜果指南</h1><p>鲜果美食主题测试页面。</p></main></body>
</html>`;
let createdFixture = false;
const portal = spawn(process.execPath, ['server.mjs'], {
cwd: root,
@@ -111,7 +121,7 @@ async function ensureJohnPassword() {
});
assert.equal(response.status, 200, 'john HTTP 登录应成功');
await pool.end();
return cookieHeader(setCookie);
return { cookie: cookieHeader(setCookie), userId: login.user.id };
}
async function main() {
@@ -119,6 +129,20 @@ async function main() {
await waitForPortal();
console.log(`BASE_URL: ${BASE_URL}`);
const { cookie, userId } = await ensureJohnPassword();
console.log('✓ john 本地登录成功');
publishDir = path.join(root, 'MindSpace', userId, 'public');
htmlPath = path.join(publishDir, HTML_NAME);
publicPageUrl = buildPublicUrl(BASE_URL, userId, `public/${HTML_NAME}`);
publicThumbUrl = buildPublicUrl(BASE_URL, userId, `public/${thumbPngRel}`);
try {
await fs.access(htmlPath);
} catch {
await fs.mkdir(publishDir, { recursive: true });
await fs.writeFile(htmlPath, fixtureHtml, 'utf8');
createdFixture = true;
}
const html = await fs.readFile(htmlPath, 'utf8');
assert.match(html, /mindspace-cover/, 'HTML 应包含 mindspace-cover');
@@ -135,17 +159,14 @@ async function main() {
assert.equal(pageCheck.response.status, 200, `公网 HTML 应可访问: ${publicPageUrl}`);
console.log(`✓ 公网 HTML 200: ${publicPageUrl}`);
const thumbCheck = await request(`/MindSpace/${USERNAME}/${thumbRel}`);
const thumbCheck = await request(`/MindSpace/${userId}/public/${thumbPngRel}`);
assert.equal(thumbCheck.response.status, 200, `公网预览图应可访问: ${publicThumbUrl}`);
assert.match(String(thumbCheck.payload), /width="540" height="720"/, '线上预览图为 3:4');
console.log(`✓ 公网预览图 200: ${publicThumbUrl}`);
const agentReplyLink = `[夏日鲜果指南 · 水果主题测试](${publicPageUrl})`;
assert.match(agentReplyLink, /^\[.+\]\(https?:\/\/.+\)$/);
console.log(`✓ Agent 应回复的可点击链接:\n ${agentReplyLink}`);
const cookie = await ensureJohnPassword();
console.log('✓ john 本地登录成功');
const { response: spaceRes, payload: spacePayload } = await request('/api/mindspace/v1/space', {
cookie,
});
@@ -182,4 +203,8 @@ try {
await main();
} finally {
portal.kill('SIGTERM');
if (createdFixture && htmlPath && publishDir) {
await fs.rm(htmlPath, { force: true });
await fs.rm(path.join(publishDir, thumbRel), { force: true });
}
}