feat: 接入 mnote web tree shell 与主页链路整理
- 增加 mnote-web tree/command 支持与前端 MnoteWebTreeShell 集成 - 调整 sidebar、documents、runtime config 与 dev/prod server 配套逻辑 - 补充 homepage/tree shell smoke 脚本并更新 harness 进度文件
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
"use strict";
|
||||
|
||||
// 说明:
|
||||
// - 这是一条最小首页入口 smoke,不验证完整业务流。
|
||||
// - 它只验证 3000 主站入口链路是否可达,并明确 3104 不是首页可进入的前置条件。
|
||||
// - 未登录场景允许 "/" 返回 30x 到 "/auth",也允许直接返回 HTML。
|
||||
|
||||
const BASE_URL = (process.env.MNOTE_UI_BASE_URL || "http://127.0.0.1:3000").replace(/\/+$/, "");
|
||||
const MNOTE_WEB_BASE_URL = (process.env.MNOTE_WEB_SMOKE_BASE_URL || "http://127.0.0.1:3104").replace(/\/+$/, "");
|
||||
const TIMEOUT_MS = Number(process.env.MNOTE_SMOKE_TIMEOUT_MS || 8000);
|
||||
|
||||
function assert(condition, message) {
|
||||
if (!condition) {
|
||||
throw new Error(message);
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchWithTimeout(url, init = {}) {
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(new Error(`请求超时: ${url}`)), TIMEOUT_MS);
|
||||
try {
|
||||
return await fetch(url, {
|
||||
redirect: "manual",
|
||||
cache: "no-store",
|
||||
...init,
|
||||
signal: controller.signal,
|
||||
});
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
}
|
||||
|
||||
async function readSnippet(response) {
|
||||
const text = await response.text().catch(() => "");
|
||||
return text.slice(0, 200);
|
||||
}
|
||||
|
||||
async function probeMnoteWeb() {
|
||||
try {
|
||||
const response = await fetchWithTimeout(`${MNOTE_WEB_BASE_URL}/health`, {
|
||||
method: "GET",
|
||||
});
|
||||
return {
|
||||
reachable: true,
|
||||
status: response.status,
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
reachable: false,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async function validateAuthEntry() {
|
||||
const response = await fetchWithTimeout(`${BASE_URL}/auth`, { method: "GET" });
|
||||
const contentType = response.headers.get("content-type") || "";
|
||||
const snippet = await readSnippet(response);
|
||||
|
||||
assert(response.ok, `/auth 请求失败: ${response.status} ${snippet}`);
|
||||
assert(
|
||||
contentType.includes("text/html"),
|
||||
`/auth 返回了非 HTML 内容: ${contentType || "<empty>"} ${snippet}`,
|
||||
);
|
||||
|
||||
return {
|
||||
status: response.status,
|
||||
contentType,
|
||||
};
|
||||
}
|
||||
|
||||
async function validateRootEntry() {
|
||||
const response = await fetchWithTimeout(`${BASE_URL}/`, { method: "GET" });
|
||||
const location = response.headers.get("location");
|
||||
const contentType = response.headers.get("content-type") || "";
|
||||
const snippet = await readSnippet(response);
|
||||
|
||||
const isRedirectToAllowedTarget =
|
||||
response.status >= 300 &&
|
||||
response.status < 400 &&
|
||||
typeof location === "string" &&
|
||||
(location.includes("/auth") || location.includes("/documents/"));
|
||||
|
||||
const isHtmlOk =
|
||||
response.ok &&
|
||||
contentType.includes("text/html");
|
||||
|
||||
assert(
|
||||
isRedirectToAllowedTarget || isHtmlOk,
|
||||
`/ 返回了不符合预期的结果: status=${response.status} location=${location || "<empty>"} contentType=${contentType || "<empty>"} snippet=${snippet}`,
|
||||
);
|
||||
|
||||
return {
|
||||
status: response.status,
|
||||
location,
|
||||
contentType,
|
||||
};
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const mnoteWeb = await probeMnoteWeb();
|
||||
const authEntry = await validateAuthEntry();
|
||||
const rootEntry = await validateRootEntry();
|
||||
|
||||
console.log(
|
||||
JSON.stringify(
|
||||
{
|
||||
ok: true,
|
||||
baseUrl: BASE_URL,
|
||||
mnoteWebBaseUrl: MNOTE_WEB_BASE_URL,
|
||||
mnoteWeb,
|
||||
authEntry,
|
||||
rootEntry,
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error instanceof Error ? error.stack || error.message : String(error));
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user