feat: 新增板块 05「测试开发工程师」,把 testdev-learning-path 接入导航路由

- portal.data.js 新增模块 testdev(dir: 测试开发工程师)与资料 testdev-learning-path,统计取站点实测值:7 阶段 / 32 模块 / 219 知识要点
- index.html、README.md、DEPLOY.md 同步为五个板块,公网验证清单补 testdev 入口
- testdev 的 51 个页面补上 data-portal-back,返回按钮直达 #/testdev/testdev-learning-path
- 自检:check-portal.js 通过(5 板块 / 7 份资料);add-back-links.js --check 通过(505 页全就绪)
This commit is contained in:
2026-10-16 08:58:10 +08:00
parent 84aa0143a8
commit 4f64ce94d6
64 changed files with 27184 additions and 14 deletions

View File

@@ -0,0 +1,178 @@
#!/usr/bin/env node
/* ==========================================================================
模块目录页生成器(阶段 0)
用法:node tools/build-module-index.js [站点根目录,默认本文件的上一级]
作用:读取 tools/modules-plan.json 里的模块级元数据(标题 / 副标题 / 导语 /
建议投入 / 前后模块),再扫描 modules/<dir>/NN-*.html 解析出每章的 h2 标题与
全部 h3 小节,生成模块目录页 modules/<dir>/index.html。
为什么章节标题不写在 plan 里:目录页与正文必须永远一致。从正文解析,
就不会出现「改了正文章节标题、目录页还是旧的」这类问题。
幂等:可重复运行;生成后建议再跑一次 tools/build-nav.js 同步侧栏目录树。
========================================================================== */
const fs = require("fs");
const path = require("path");
const root = process.argv[2] || path.resolve(__dirname, "..");
const MODDIR = path.join(root, "modules");
const PLAN = path.join(__dirname, "modules-plan.json");
/* ---------- 读取 JSONC(允许 /* *​/ 注释) ---------- */
function readPlan(p) {
const raw = fs.readFileSync(p, "utf8")
.replace(/\/\*[\s\S]*?\*\//g, "")
.replace(/^\s*\/\/.*$/gm, "");
return JSON.parse(raw);
}
const esc = s => String(s).replace(/&/g, "&amp;").replace(/</g, "&lt;")
.replace(/>/g, "&gt;").replace(/"/g, "&quot;");
const stripTags = s => s.replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim();
const decode = s => s.replace(/&lt;/g, "<").replace(/&gt;/g, ">")
.replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&nbsp;/g, " ").replace(/&amp;/g, "&");
const plain = s => decode(stripTags(s));
const stripNo = s => s.replace(/^\s*\d+(?:\.\d+)*\s*[\.、]?\s*/, "").trim();
const plan = readPlan(PLAN);
const stage = plan.stage;
const mods = plan.modules;
/* ---------- 逐模块生成 ---------- */
let written = 0;
const report = [];
mods.forEach((m, mi) => {
const modPath = path.join(MODDIR, m.dir);
if (!fs.existsSync(modPath)) throw new Error(`模块目录不存在:modules/${m.dir}`);
const files = fs.readdirSync(modPath).filter(f => /^\d\d-.*\.html$/.test(f)).sort();
if (!files.length) throw new Error(`modules/${m.dir} 下没有 NN-*.html 章节页`);
const chapters = files.map(file => {
const html = fs.readFileSync(path.join(modPath, file), "utf8");
const h2 = html.match(/<h2 id="[^"]*">([\s\S]*?)<\/h2>/);
if (!h2) throw new Error(`modules/${m.dir}/${file}: 找不到 h2 章节标题`);
const title = plain(h2[1].replace(/<span class="n">\d+<\/span>/, ""));
const sections = [...html.matchAll(/<h3 id="([^"]+)">([\s\S]*?)<\/h3>/g)]
.map(x => ({ id: x[1], label: stripNo(plain(x[2])) }));
// 字数口径:只统计中文汉字(代码与英文命令不计入「千字」,否则会被严重高估)
const chars = (stripTags(html).match(/[\u4e00-\u9fff]/g) || []).length;
return { file, title, sections, chars };
});
const chapItems = chapters.map((c, i) => {
const secs = c.sections.length
? `\n <div class="ci-secs">${c.sections.map(s => `<a href="${c.file}#${s.id}">${esc(s.label)}</a>`).join("")}</div>`
: "";
return ` <li class="chap-item">
<div class="ci-head">
<span class="ci-no">${i + 1}</span>
<a class="ci-title" href="${c.file}">${esc(c.title)}</a>
<a class="ci-go" href="${c.file}">进入 →</a>
</div>${secs}
</li>`;
}).join("\n");
const totalSecs = chapters.reduce((n, c) => n + c.sections.length, 0);
const totalK = Math.round(chapters.reduce((n, c) => n + c.chars, 0) / 1000);
const prev = mi === 0
? { href: `${plan.brand.home}#${stage.id}`, k: "← 上一模块", v: `已经是阶段 0 的第一个模块` }
: { href: `../${mods[mi - 1].dir}/index.html`, k: "← 上一模块", v: mods[mi - 1].title };
const next = mi === mods.length - 1
? { href: `${plan.brand.home}#${stage.id}`, k: "阶段 0 完成 →", v: "回到学习路径,进入阶段 1 · 会测" }
: { href: `../${mods[mi + 1].dir}/index.html`, k: "下一模块 →", v: mods[mi + 1].title };
const html = `<!DOCTYPE html>
<html lang="zh-CN" data-theme="light">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>${esc(m.title)} · ${stage.anchorText} 模块 ${mi + 1} · ${esc(plan.brand.siteName)}</title>
<meta name="description" content="${esc(m.title)} 模块目录:共 ${chapters.length} 章、${totalSecs} 个小节。">
<link rel="stylesheet" href="../../assets/doc.css">
</head>
<body>
<header class="topbar">
<div class="tb-in">
<a class="brand" href="${plan.brand.home}"><span class="logo">${esc(plan.brand.logo)}</span><div>从零到成熟<small>测试开发 · 模块详解</small></div></a>
<div class="crumbs">
<a href="${plan.brand.home}">学习路径</a><span class="sep">/</span>
<a href="${plan.brand.home}#${stage.id}">${esc(stage.anchorText)}</a><span class="sep">/</span>
<b>${esc(m.title)}</b>
</div>
<div class="spacer"></div>
<button class="btn" id="tocToggle">☰ 导航</button>
<button class="btn" id="themeBtn" title="切换到深色主题">深色</button>
</div>
</header>
<div class="layout" id="layout">
<aside class="sidebar">
<h2>章节目录</h2>
<nav id="chapters"></nav>
<div class="side-foot">
<a class="btn" href="index.html">← 模块目录</a>
<a class="btn" href="${plan.brand.home}">学习路径</a>
</div>
</aside>
<div class="mask" id="mask"></div>
<main class="main-col">
<article>
<div class="modhero">
<span class="mh-no">${stage.anchorText} · 模块 ${mi + 1} / ${mods.length}</span>
<h1>${esc(m.title)}</h1>
<p class="mh-sub">${esc(m.sub)}</p>
<div class="mh-meta">
<span>共 <b>${chapters.length}</b> 章</span>
<span><b>${totalSecs}</b> 个小节</span>
<span>约 <b>${totalK}</b> 千字</span>
<span>${esc(m.hours)}</span>
</div>
</div>
<p class="lead">
${m.lead}
</p>
<h2 id="chapters-list">章节目录</h2>
<ol class="chaplist">
${chapItems}
</ol>
<div class="box tip">
<span class="bt">怎么用这一模块</span>
<p>左侧第一栏是<b>章节</b>,可以在整章之间跳转;第二栏是<b>本章小节</b>,进入某章后会显示该章的内容大纲并跟随滚动高亮。</p>
<p>每章结尾都可以用底部的「上一章 / 下一章」连续阅读。每章内部的代码块右上角可以直接复制,点顶栏的「深色 / 浅色」可以切换主题。</p>
</div>
</article>
<nav class="pager">
<a class="prev" href="${prev.href}"><span class="k">${prev.k}</span><span class="v">${esc(prev.v)}</span></a>
<a class="next" href="${next.href}"><span class="k">${next.k}</span><span class="v">${esc(next.v)}</span></a>
</nav>
<p class="foot">
${esc(m.title)} · 模块目录<br>
<a href="${plan.brand.home}">返回学习路径</a>
</p>
</main>
</div>
<button id="toTop" title="回到顶部">↑</button>
<script src="../../assets/doc.js"></script>
<script src="../../../../assets/back.js"></script>
</body>
</html>
`;
fs.writeFileSync(path.join(modPath, "index.html"), html, "utf8");
written++;
report.push(`modules/${m.dir}/index.html:${chapters.length} 章 / ${totalSecs} 小节 / 约 ${totalK} 千字`);
});
console.log(report.join("\n"));
console.log(`\n共生成 ${written} 个模块目录页。下一步:node tools/build-nav.js`);

View File

@@ -0,0 +1,91 @@
#!/usr/bin/env node
/* ==========================================================================
侧栏目录树生成器
用法:node tools/build-nav.js [站点根目录,默认本文件的上一级]
作用:扫描每个模块目录下的 NN-*.html,采集「章节标题 + 小节(h3)」,
然后重写所有页面侧栏里的 <nav id="chapters">,生成默认全部展开的目录树:
1 为什么测试工程师要先看懂系统与网络
2 进程、内存与文件描述符
· 进程与线程:一个服务到底占了多少
· 内存:RSS、虚拟内存与 OOM
3 …
当前章标为 active(其子导航加 current,供 doc.js 做滚动高亮),
本章小节用页内锚点,其它章的小节链接到「章节页 + 锚点」。
新增 / 删除 / 重排章节后重新执行本脚本即可,幂等可重复运行。
========================================================================== */
const fs = require("fs");
const path = require("path");
const root = process.argv[2] || path.resolve(__dirname, "..");
const MODDIR = path.join(root, "modules");
const esc = s => String(s).replace(/&/g, "&amp;").replace(/</g, "&lt;")
.replace(/>/g, "&gt;").replace(/"/g, "&quot;");
const stripTags = s => s.replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim();
const decode = s => s.replace(/&lt;/g, "<").replace(/&gt;/g, ">")
.replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&nbsp;/g, " ").replace(/&amp;/g, "&");
const plain = s => decode(stripTags(s));
const stripNo = s => s.replace(/^\s*\d+(?:\.\d+)*\s*[\.、]?\s*/, "").trim();
let pages = 0;
for (const dir of fs.readdirSync(MODDIR, { withFileTypes: true })) {
if (!dir.isDirectory()) continue;
const modPath = path.join(MODDIR, dir.name);
const files = fs.readdirSync(modPath).filter(f => /^\d\d-.*\.html$/.test(f)).sort();
if (!files.length) continue;
/* ---------- 1. 采集每一章的标题与小节 ---------- */
const chapters = files.map(file => {
const html = fs.readFileSync(path.join(modPath, file), "utf8");
const num = parseInt(file.slice(0, 2), 10);
const h2 = html.match(/<h2 id="[^"]*">([\s\S]*?)<\/h2>/);
if (!h2) throw new Error(`${dir.name}/${file}: 找不到 h2 章节标题`);
const title = plain(h2[1].replace(/<span class="n">\d+<\/span>/, ""));
const sections = [...html.matchAll(/<h3 id="([^"]+)">([\s\S]*?)<\/h3>/g)]
.map(m => ({ id: m[1], label: stripNo(plain(m[2])) }));
return { num, file, title, sections };
});
/* ---------- 2. 生成目录树 ---------- */
const buildNav = curNum => chapters.map(c => {
const row = c.num === curNum
? `<span class="toc-a active" aria-current="page"><i class="cn">${c.num}</i>${esc(c.title)}</span>`
: `<a class="toc-a" href="${c.file}"><i class="cn">${c.num}</i>${esc(c.title)}</a>`;
if (!c.sections.length) return row;
const sub = c.sections.map(s => {
const href = c.num === curNum ? `#${s.id}` : `${c.file}#${s.id}`;
return `<a class="toc-a lv3" href="${href}">${esc(s.label)}</a>`;
}).join("");
return row + `<div class="subnav${c.num === curNum ? " current" : ""}">${sub}</div>`;
}).join("");
/* ---------- 3. 写回每个章节页 ---------- */
const NAV_RE = /<nav id="chapters">[\s\S]*?<\/nav>/;
for (const c of chapters) {
const p = path.join(modPath, c.file);
const before = fs.readFileSync(p, "utf8");
if (!NAV_RE.test(before)) throw new Error(`${dir.name}/${c.file}: 未找到 #chapters,无法替换`);
fs.writeFileSync(p, before.replace(NAV_RE, `<nav id="chapters">${buildNav(c.num)}</nav>`), "utf8");
pages++;
}
/* ---------- 4. 写回模块目录页(没有当前章) ---------- */
const idx = path.join(modPath, "index.html");
if (fs.existsSync(idx)) {
const before = fs.readFileSync(idx, "utf8");
if (!NAV_RE.test(before)) throw new Error(`${dir.name}/index.html: 未找到 #chapters,无法替换`);
fs.writeFileSync(idx, before.replace(NAV_RE, `<nav id="chapters">${buildNav(0)}</nav>`), "utf8");
pages++;
}
const secCount = chapters.reduce((n, c) => n + c.sections.length, 0);
console.log(`modules/${dir.name}:${chapters.length} 章 / ${secCount} 个小节已展开`);
}
console.log(`\n共更新 ${pages} 个页面。`);

View File

@@ -0,0 +1,78 @@
#!/usr/bin/env node
/* ==========================================================================
术语表自检:扫描所有模块章节页,检查示例命名是否统一
用法:node tools/check-glossary.js [站点根目录,默认本文件的上一级]
规则写在 tools/glossary.json 里(canonical 是正确写法,forbidden 是正则 + 提示)。
为什么要单独一个脚本:check-pages.js 管结构与链接,这个脚本管「一个概念一个名字」,
两者失败原因不同,分开跑更容易定位;也可以单独挂到 CI 的 lint 阶段。
退出码:0 全部通过;1 有命中(列出文件、行号、片段与修改建议)。
========================================================================== */
const fs = require("fs");
const path = require("path");
const root = process.argv[2] || path.resolve(__dirname, "..");
const MODDIR = path.join(root, "modules");
const glossary = JSON.parse(
fs.readFileSync(path.join(__dirname, "glossary.json"), "utf8")
.replace(/\/\*[\s\S]*?\*\//g, "")
.replace(/^\s*\/\/.*$/gm, "")
);
const rules = glossary.forbidden.map(r => ({ re: new RegExp(r.re, "g"), hint: r.hint, src: r.re }));
function walk(dir, out = []) {
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
const p = path.join(dir, e.name);
if (e.isDirectory()) walk(p, out);
else if (e.name.endsWith(".html")) out.push(p);
}
return out;
}
const files = fs.existsSync(MODDIR) ? walk(MODDIR) : [];
const hits = [];
for (const file of files) {
const rel = path.relative(root, file).replace(/\\/g, "/");
const lines = fs.readFileSync(file, "utf8").split(/\r?\n/);
lines.forEach((line, i) => {
for (const rule of rules) {
rule.re.lastIndex = 0;
const m = rule.re.exec(line);
if (!m) continue;
// 允许在行尾写 // glossary-ok 明确豁免(例如引用第三方系统的真实表名)
if (/glossary-ok/.test(line)) continue;
hits.push({
rel,
line: i + 1,
text: m[0],
hint: rule.hint,
snippet: line.trim().slice(0, 110)
});
}
});
}
if (!hits.length) {
console.log(`OK 术语统一:扫描 ${files.length} 个页面,未发现命名漂移。`);
process.exit(0);
}
console.error(`发现 ${hits.length} 处命名漂移(共 ${files.length} 个页面):\n`);
const byFile = new Map();
for (const h of hits) {
if (!byFile.has(h.rel)) byFile.set(h.rel, []);
byFile.get(h.rel).push(h);
}
for (const [rel, list] of byFile) {
console.error(`${rel}(${list.length} 处)`);
for (const h of list.slice(0, 12)) {
console.error(` :${h.line} 「${h.text}」→ ${h.hint}`);
console.error(` ${h.snippet}`);
}
if (list.length > 12) console.error(` …… 其余 ${list.length - 12} 处省略`);
}
console.error("\n改完重跑本脚本;确认某处是刻意保留的,可在该行加注释 // glossary-ok 豁免。");
process.exit(1);

View File

@@ -0,0 +1,229 @@
#!/usr/bin/env node
/* ==========================================================================
页面自检工具:校验目录页、模块目录页与全部章节页
用法:node tools/check-pages.js [站点根目录,默认本文件的上一级]
检查项:
- 每个页面的 title / article / 标签配对
- 代码块是否标注 data-lang、内部 < 是否转义
- 提示框类名、表格是否用 tablewrap 包裹、是否有内联 style / <style>
- 所有站内链接是否存在、锚点是否真实可达
- 章节页是否含章节目录、小节导航、定位条、上一/下一章,h3 是否全部带 id
- 模块目录页是否含 modhero / chaplist / 章节目录侧栏
- 同一模块所有页面的侧栏目录树是否一致
- index.html 的 PAGES 路由表指向的文件是否存在
========================================================================== */
const fs = require("fs");
const path = require("path");
const root = process.argv[2] || path.resolve(__dirname, "..");
const problems = [];
const info = [];
const must = (c, m) => { if (!c) problems.push(m); };
const read = p => fs.readFileSync(p, "utf8");
const stripTags = s => s.replace(/<[^>]+>/g, "");
const ALLOWED_BOX = new Set(["", "note", "tip", "warn", "danger", "ok", "case", "lab", "pit"]);
function walk(dir, out = []) {
for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
const p = path.join(dir, e.name);
if (e.isDirectory()) { if (e.name !== "assets" && e.name !== "tools") walk(p, out); }
else if (e.name.endsWith(".html")) out.push(p);
}
return out;
}
const pages = walk(root).filter(p => !path.basename(p).startsWith("."));
must(pages.length > 5, "页面数量异常:" + pages.length);
/* 建立 id 索引,供锚点校验 */
const idIndex = new Map();
for (const p of pages) {
const html = read(p);
const ids = new Set([...html.matchAll(/\sid="([^"]+)"/g)].map(m => m[1]));
// 目录页的阶段锚点由 JS 生成,从 STAGES 数据里补上
if (path.resolve(p) === path.resolve(root, "index.html")) {
[...html.matchAll(/^\s*id:"([^"]+)"/gm)].forEach(m => ids.add(m[1]));
}
idIndex.set(path.resolve(p), ids);
}
for (const p of pages) {
const rel = path.relative(root, p).replace(/\\/g, "/");
const html = read(p);
const markup = html.replace(/<script[\s\S]*?<\/script>/g, ""); // 去掉脚本,避免把 JS 模板当链接
const isRootIndex = rel === "index.html";
must(/<title>[^<]+<\/title>/.test(html), `${rel}: 缺少 title`);
if (!isRootIndex) must(html.includes("<article>"), `${rel}: 缺少 article`);
const pres = markup.match(/<pre[\s\S]*?<\/pre>/g) || [];
pres.forEach((blk, i) => {
if (!/data-lang=/.test(blk)) problems.push(`${rel}: 第 ${i + 1} 个 <pre> 未标注 data-lang`);
const body = blk.replace(/^<pre[^>]*>/, "").replace(/<\/pre>$/, "");
if (/</.test(body)) problems.push(`${rel}: 第 ${i + 1} 个 <pre> 内有未转义的 <`);
});
if (!isRootIndex) {
if (/<style[\s>]/.test(markup)) problems.push(`${rel}: 不应出现 <style> 标签`);
const inline = (markup.match(/\sstyle="/g) || []).length;
if (inline) problems.push(`${rel}: 有 ${inline} 处内联 style`);
}
for (const m of markup.matchAll(/<div class="box([^"]*)"/g)) {
for (const cls of m[1].trim().split(/\s+/).filter(Boolean)) {
if (!ALLOWED_BOX.has(cls)) problems.push(`${rel}: 提示框用了不在规范内的类 box.${cls}`);
}
}
const tables = (markup.match(/<table[\s>]/g) || []).length;
const wrapped = (markup.match(/class="tablewrap"/g) || []).length;
if (tables !== wrapped) problems.push(`${rel}: 表格 ${tables} 个,tablewrap 包裹 ${wrapped} 个`);
for (const t of ["div", "section", "article", "aside", "nav", "main", "details", "table", "ul", "ol", "li", "thead", "tbody", "tr", "td", "th", "pre", "p", "span"]) {
const o = (markup.match(new RegExp("<" + t + "(?=[\\s>])", "g")) || []).length;
const c = (markup.match(new RegExp("</" + t + ">", "g")) || []).length;
if (o !== c) problems.push(`${rel}: <${t}> 开合不匹配 ${o}/${c}`);
}
const links = [...markup.matchAll(/href="(?!https?:|mailto:)([^"]+)"/g)].map(m => m[1]);
for (const l of new Set(links)) {
const [file, hash] = l.split("#");
const target = file ? path.resolve(path.dirname(p), file) : path.resolve(p);
if (file && !fs.existsSync(target)) { problems.push(`${rel}: 死链 ${l}`); continue; }
if (hash && idIndex.has(target) && !idIndex.get(target).has(hash)) {
problems.push(`${rel}: 锚点不存在 ${l}`);
}
}
const isChapter = /^modules\/[^/]+\/\d\d-/.test(rel);
if (isChapter) {
must(html.includes('id="chapters"'), `${rel}: 缺少章节目录侧栏 #chapters`);
must(!html.includes('id="sections"'), `${rel}: 侧栏应已合并为单栏,仍存在 #sections`);
must(/<h2 id="/.test(html), `${rel}: 缺少 h2 章节标题`);
must(html.includes('class="chapnav"'), `${rel}: 缺少章节目录定位条`);
must(html.includes('class="pager"'), `${rel}: 缺少上一/下一章导航`);
must(html.includes('href="index.html"'), `${rel}: 缺少返回模块目录链接`);
must(html.includes('href="../../assets/doc.css"'), `${rel}: doc.css 路径不对`);
must(html.includes('src="../../assets/doc.js"'), `${rel}: doc.js 路径不对`);
const h3count = (html.match(/<h3 id="/g) || []).length;
const h3any = (html.match(/<h3[ >]/g) || []).length;
must(h3count === h3any, `${rel}: 有 h3 未补 id(${h3count}/${h3any})`);
// h3 的编号必须是「章号.序号」(自测/清单类小节允许 sec-x1 这类 id)
const chapNo = parseInt(path.basename(rel).slice(0, 2), 10);
for (const h of html.matchAll(/<h3 id="([^"]+)">([\s\S]*?)<\/h3>/g)) {
if (!/^sec-(\d+|x\d+)$/.test(h[1].replace(/-\d+$/, "")) && !/^sec-(\d+|x)/.test(h[1])) {
problems.push(`${rel}: h3 id 命名不规范 ${h[1]}`);
}
const label = h[2].replace(/<[^>]+>/g, "").replace(/\s+/g, " ").trim();
if (!new RegExp(`^${chapNo}\\.\\d+`).test(label)) {
problems.push(`${rel}: h3「${label.slice(0, 30)}」编号与章号不一致(应为 ${chapNo}.x)`);
}
}
// 当前章必须被标记为 active,否则侧栏不知道把小节挂到哪
must(/class="toc-a active"[^>]*aria-current="page"/.test(html), `${rel}: 当前章未标记 active`);
// chapnav 里的章号 / 总章数 / 小节数必须与文件和目录真实情况一致
const navPos = html.match(/第 <b class="pos">(\d+)<\/b> \/ (\d+) 章/);
if (!navPos) problems.push(`${rel}: chapnav 缺少「第 N / M 章」`);
else {
const moduleFiles = fs.readdirSync(path.dirname(p)).filter(f => /^\d\d-.*\.html$/.test(f));
if (Number(navPos[1]) !== chapNo) problems.push(`${rel}: chapnav 章号 ${navPos[1]} ≠ 文件名 ${chapNo}`);
if (Number(navPos[2]) !== moduleFiles.length) problems.push(`${rel}: chapnav 总章数 ${navPos[2]} ≠ 目录实际 ${moduleFiles.length} 章`);
}
const navSecs = html.match(/本章 (\d+) 小节/);
const secCount = (html.match(/<h3 id="/g) || []).length;
if (secCount && !navSecs) problems.push(`${rel}: 有 ${secCount} 个小节但 chapnav 未写「本章 N 小节」`);
if (navSecs && Number(navSecs[1]) !== secCount) problems.push(`${rel}: chapnav 小节数 ${navSecs[1]} ≠ 实际 ${secCount}`);
}
if (/^modules\/[^/]+\/index\.html$/.test(rel)) {
must(html.includes('class="modhero"'), `${rel}: 缺少模块头部`);
must(html.includes('class="chaplist"'), `${rel}: 缺少章节目录列表`);
must(html.includes('id="chapters"'), `${rel}: 缺少章节目录侧栏 #chapters`);
must(html.includes('href="../../assets/doc.css"'), `${rel}: doc.css 路径不对`);
}
info.push(`${rel} ~${stripTags(html).replace(/\s+/g, "").length} 字 · 代码块 ${pres.length}`);
}
/* 侧栏目录树一致性:同一模块的每个页面都必须列出全部章节与全部小节 */
const modDirs = new Map();
for (const p of pages) {
const rel = path.relative(root, p).replace(/\\/g, "/");
const mm = rel.match(/^(modules\/[^/]+)\//);
if (!mm) continue;
if (!modDirs.has(mm[1])) modDirs.set(mm[1], []);
modDirs.get(mm[1]).push(p);
}
for (const [mod, list] of modDirs) {
const chapterFiles = fs.readdirSync(path.join(root, mod))
.filter(f => /^\d\d-.*\.html$/.test(f)).sort();
let expectedSecs = null;
for (const p of list) {
const rel = path.relative(root, p).replace(/\\/g, "/");
const nav = read(p).match(/<nav id="chapters">([\s\S]*?)<\/nav>/);
must(!!nav, `${rel}: 缺少 #chapters 目录树`);
if (!nav) continue;
// 每个章节文件都应出现在导航里(当前章是 span,其余是链接)
for (const f of chapterFiles) {
const self = rel.endsWith("/" + f);
if (self) continue;
must(nav[1].includes(`href="${f}"`), `${rel}: 目录树缺少章节 ${f}`);
}
const secs = (nav[1].match(/class="toc-a lv3"/g) || []).length;
const chapRows = (nav[1].match(/class="toc-a( active)?"/g) || []).length;
must(chapRows === chapterFiles.length, `${rel}: 目录树章节数 ${chapRows} ≠ ${chapterFiles.length}`);
if (expectedSecs === null) expectedSecs = secs;
else must(secs === expectedSecs, `${rel}: 目录树小节数 ${secs} 与本模块其它页面(${expectedSecs})不一致`);
}
info.push(`${mod}:目录树 ${chapterFiles.length} 章 / ${expectedSecs} 小节,已同步到 ${list.length} 个页面`);
}
/* 目录页路由 */
const index = read(path.join(root, "index.html"));
const m = index.match(/<script>([\s\S]*?)<\/script>\s*<\/body>/);
must(!!m, "index.html: 找不到主 script");
if (m) {
try { new Function(m[1]); } catch (e) { problems.push("index.html 脚本语法错误:" + e.message); }
const cut = m[1].indexOf("/* ============================ 工具");
const d = new Function(m[1].slice(0, cut) + "\nreturn {STAGES, PAGES};")();
for (const [k, v] of Object.entries(d.PAGES)) {
must(fs.existsSync(path.join(root, v)), `路由 ${k} 目标不存在:${v}`);
}
const stageIds = d.STAGES.map(s => s.id);
const s0 = d.STAGES.find(s => s.id === "s0");
if (s0) {
s0.modules.forEach((mod, i) => {
must(d.PAGES[`s0-${i}`], `阶段 0 第 ${i + 1} 个模块「${mod.t}」未在 PAGES 里登记详解页`);
});
}
// 登记的路由必须指向「同一个模块」:目录页的模块名要和模块页的 h1 一致,
// 阶段与模块的顺序也不能错位(这是最容易出的一类登记错误)。
for (const st of d.STAGES) {
st.modules.forEach((mod, i) => {
const route = d.PAGES[`${st.id}-${i}`];
if (!route) return;
const target = path.join(root, route);
if (!fs.existsSync(target)) return; // 上面已经报过死链
const h1 = read(target).match(/<h1>([^<]+)<\/h1>/);
if (!h1) { problems.push(`路由 ${st.id}-${i}:${route} 缺少模块标题 h1`); return; }
const title = h1[1].replace(/&amp;/g, "&").trim();
if (title !== mod.t) {
problems.push(`路由 ${st.id}-${i} 指向的模块标题「${title}」与目录页模块名「${mod.t}」不一致`);
}
});
}
const registered = Object.keys(d.PAGES).length;
const detailModules = d.STAGES.reduce((n, s) => n + s.modules.filter((_, i) => d.PAGES[`${s.id}-${i}`]).length, 0);
info.push(`index.html 路由:${registered} 条,阶段 ${stageIds.length} 个,已上线模块 ${detailModules} 个`);
}
info.sort();
console.log(info.join("\n"));
if (problems.length) {
console.error("\n发现 " + problems.length + " 个问题:");
problems.slice(0, 80).forEach(x => console.error(" - " + x));
process.exit(1);
}
console.log(`\nOK 全部校验通过(共 ${pages.length} 个页面)`);

View File

@@ -0,0 +1,73 @@
/* ==========================================================================
术语表(全站统一的示例命名)
tools/check-glossary.js 会按这里的规则扫描所有模块章节页,
防止「一个概念多个名字」的漂移再次出现。
规则:
canonical —— 正确写法(人工维护,供参考)
forbidden —— 正则 + 说明;命中即报错
新增规则时注意:正则区分大小写、用 \b 卡住词边界,
避免把英文散文里的普通词(例如 "orders" 作为普通名词)误伤 —— 命中后按提示改成规范名即可。
========================================================================== */
{
"canonical": {
"服务": {
"gateway": "网关,8000",
"order-api": "订单服务,8080",
"pay-api": "支付服务,8081",
"stock-api": "库存服务,8082",
"coupon-api": "优惠券服务,8083"
},
"表": {
"t_order": "订单主表:order_id, order_no, user_id, total_amount, discount_amount, freight_amount, pay_amount, status, coupon_id, create_time, pay_time, finish_time, update_time, remark",
"t_order_item": "订单明细:item_id, order_id, sku_id, sku_name, price, quantity, item_amount",
"t_pay_flow": "支付流水:flow_id, pay_no, order_id, order_no, channel, pay_amount, pay_status, pay_time",
"t_coupon": "优惠券:coupon_id, coupon_code, user_id, face_value, min_amount, discount_amount, status, order_id, use_time, expire_time",
"t_stock": "库存辅助表:sku_id, sku_code, total_qty, locked_qty, sold_qty(available_qty = total_qty - locked_qty - sold_qty,是算出来的,不落库)"
},
"状态取值": {
"t_order.status": "10 待支付 / 20 已支付 / 30 已发货 / 40 已完成 / 50 已取消 / 60 已退款",
"t_pay_flow.pay_status": "10 处理中 / 20 成功 / 30 失败",
"t_coupon.status": "10 未使用 / 20 已使用 / 30 已过期"
},
"Go": {
"示例服务 module": "mall(多包服务示例,如 mall/internal/order)",
"CLI 交付物 module": "qa/tdcheck"
}
},
"forbidden": [
{ "re": "\\border-svc\\b", "hint": "服务名统一为 order-api" },
{ "re": "\\border-service\\b", "hint": "服务名统一为 order-api" },
{ "re": "\\borders-api\\b", "hint": "服务名统一为 order-api" },
{ "re": "\\bpay-svc\\b", "hint": "服务名统一为 pay-api" },
{ "re": "\\bstock-svc\\b", "hint": "服务名统一为 stock-api" },
{ "re": "\\bcoupon-svc\\b", "hint": "服务名统一为 coupon-api" },
{ "re": "\\binventory-svc\\b", "hint": "服务名统一为 stock-api" },
{ "re": "(?<![/\\w-])order-pay(?![-\\w])", "hint": "服务名拆成 order-api / pay-api(分支名里的 order-pay 是功能名,可加 // glossary-ok 豁免)" },
{ "re": "\\b(FROM|JOIN|INTO|UPDATE|TABLE|ON)\\s+orders\\b", "hint": "表名统一为 t_order" },
{ "re": "\\borders\\.(?!csv|json|txt|html|go|log|sql|yaml|yml|md|xlsx|sh)(\\w)", "hint": "表名统一为 t_order(字段引用写 t_order.xxx)" },
{ "re": "\\b(FROM|JOIN|INTO|UPDATE|TABLE|ON)\\s+payments\\b", "hint": "表名统一为 t_pay_flow" },
{ "re": "\\bpayments\\.(?!csv|json|txt|html|go|log|sql|yaml|yml|md|xlsx|sh)(\\w)", "hint": "表名统一为 t_pay_flow" },
{ "re": "\\b(FROM|JOIN|INTO|UPDATE|TABLE|ON)\\s+inventory\\b", "hint": "库存表统一为 t_stock(sku_id, sku_code, total_qty, locked_qty, sold_qty)" },
{ "re": "\\binventory\\s*表", "hint": "库存表统一为 t_stock" },
{ "re": "\\b(orders|payments|order_info|payment_record|coupon_usage)\\s*表", "hint": "表名统一为 t_order / t_pay_flow / t_coupon" },
{ "re": "\\border_info\\b", "hint": "表名统一为 t_order" },
{ "re": "\\bpayment_record\\b", "hint": "表名统一为 t_pay_flow" },
{ "re": "\\bcoupon_usage\\b", "hint": "券的核销状态在 t_coupon.status 与 use_time 上" },
{ "re": "\\bt_payment\\b", "hint": "表名统一为 t_pay_flow" },
{ "re": "\\bt_pay\\b(?!_flow)", "hint": "表名统一为 t_pay_flow" },
{ "re": "\\bbuyer_id\\b", "hint": "字段统一为 user_id" },
{ "re": "\\bcreated_at\\b", "hint": "字段统一为 create_time" },
{ "re": "\\bout_trade_no\\b", "hint": "字段统一为 pay_no(支付流水号)" },
{ "re": "'(PAID|PENDING|WAIT_PAY|SHIPPED|CANCELLED|CANCELED)'", "hint": "订单状态统一用数字取值(10 待支付 / 20 已支付 / 30 已发货 / 40 已完成 / 50 已取消 / 60 已退款)" },
{ "re": "'(SUCCESS|CREATED|NEW)'", "hint": "支付/订单状态统一用数字取值" },
{ "re": "status=PAID", "hint": "状态统一写 status=20(已支付)" },
{ "re": "example\\.com/qa/", "hint": "Go 示例模块路径统一为 qa/tdcheck" },
{ "re": "\\bqa/testdata\\b", "hint": "Go CLI 交付物模块路径统一为 qa/tdcheck" },
{ "re": "\\btestdev/ordercli\\b", "hint": "Go 示例模块路径统一为 qa/tdcheck" }
]
}

View File

@@ -0,0 +1,51 @@
/* ==========================================================================
阶段 0 模块元数据
用途:tools/build-module-index.js 依据本文件生成每个模块的目录页(index.html)。
章节标题与小节标题不写在这里 —— 目录页直接从章节 HTML 里解析,保证与正文永远一致;
本文件只维护「模块级」信息:标题、副标题、建议投入、导语、前后模块关系。
新增模块:追加一个对象,然后在 index.html 的 PAGES 表里登记路由。
========================================================================== */
{
"stage": {
"id": "s0",
"num": "0",
"title": "打地基",
"sub": "计算机 · Go 工程 · Linux · 数据库",
"anchorText": "阶段 0 · 打地基"
},
"brand": {
"logo": "QA",
"siteName": "测试开发工程师从零到成熟",
"home": "../../index.html"
},
"modules": [
{
"dir": "s0-01-network",
"title": "计算机与网络基础",
"sub": "进程 · TCP · HTTP · 抓包 · 调用链",
"hours": "建议投入 18–24 小时",
"lead": "<b>模块定位:</b>阶段 0 的第 1 个模块。测试工程师 80% 的争论都发生在「这到底是谁的问题」上,而这类争论几乎都能用系统与网络的知识终结。<br><br><b>学完之后你应该能:</b>给一个「页面报 500 / 接口偶发超时」的现场,在 10 分钟内判断是前端、网络、网关还是后端的问题,并说清判断依据;能对任意一个被测接口画出从浏览器到数据库的调用链。<br><br><b>学习方式:</b>一半时间在敲命令(curl、ss、tcpdump、mitmproxy),一半时间在画图和归因。看懂一次真实抓包,胜过读十篇文章。"
},
{
"dir": "s0-02-golang",
"title": "编程基础:Golang 与工程化",
"sub": "语法 · 错误处理 · 接口与并发 · 工程结构",
"hours": "建议投入 30–40 小时",
"lead": "<b>模块定位:</b>阶段 0 的第 2 个模块,也是整条路线里最不能省的一个。后面的单元测试、接口自动化框架、测试平台后端全部是 Go 代码,这一层没打好,后面只能抄别人的代码改。<br><br><b>学完之后你应该能:</b>独立写出带错误处理、接口依赖注入、超时控制的 Go 程序;读懂一个陌生 Go 服务从 main 到数据库的请求路径;交付一个自己写的测试数据生成与校验 CLI。<br><br><b>学习方式:</b>只读书不动手等于没学。每个知识点都写一个能跑起来的最小程序,最后合成一个 CLI 交付物。"
},
{
"dir": "s0-03-linux-git",
"title": "Linux、Shell 与 Git",
"sub": "命令行 · 日志 · 脚本 · 版本协作",
"hours": "建议投入 20–28 小时",
"lead": "<b>模块定位:</b>阶段 0 的第 3 个模块。测试环境出问题时,能救你的不是界面而是命令行:看进程、翻日志、查端口、起停服务、写脚本,以及用 Git 把这一切留下来。<br><br><b>学完之后你应该能:</b>在没有任何监控的情况下定位「服务为什么起不来」;用一条管道从日志里捞出失败请求 TOP10;写出带 <code>set -euo pipefail</code> 与 <code>trap</code> 的可复用脚本;用 <code>git bisect</code> 找到引入缺陷的那次提交。<br><br><b>学习方式:</b>准备一个 Linux 环境(WSL 或虚拟机均可),所有命令都要真的敲一遍,脚本要真的能跑。"
},
{
"dir": "s0-04-database",
"title": "数据库与 SQL",
"sub": "查询 · 连接 · 校验 · 造数与清理",
"hours": "建议投入 20–26 小时",
"lead": "<b>模块定位:</b>阶段 0 的第 4 个模块。界面上显示「下单成功」不算成功,数据落对了才算。能自己写 SQL 的测试工程师,定位效率和话语权完全不一样。<br><br><b>学完之后你应该能:</b>用 SQL 独立验证一条业务规则(金额对账、状态流转、无孤儿数据、无重复支付);针对一套订单与支付表结构写出 10 条可重复执行的校验 SQL;造出可追溯、可清理的测试数据。<br><br><b>学习方式:</b>找一个能随便造数的开发库,边学边写;每条校验 SQL 都要能说清「结果应该是几行、出现几行说明什么」。"
}
]
}