§9.1 line 630-631 教师域: - /shell/teacher/questions (列表,1 页) - /shell/teacher/textbooks + /shell/teacher/textbooks/[id] (列表+详情,2 页) 契约:🟡 混合 - question(id) ✅ 真实单查(schema 第 775-778 行确认) - textbook(id) ✅ 真实单查 - 列表查询 ❌ schema 无 → MSW 兜底 + @contract-pending - textbookChapters(textbookId) ❌ schema 无 → MSW 兜底 新增文件: - src/lib/api/questions.ts (5 hooks) - src/lib/api/textbooks.ts (5 hooks) - src/lib/api/operations/{questions,textbooks}.graphql.ts (10 documents) - src/features/teacher/questions/ (clients + transformations + tests) - src/features/teacher/textbooks/ (clients + transformations + tests) - src/app/shell/teacher/{questions,textbooks}/ (3 page.tsx + 2 loading + 2 error) 修改文件: - src/lib/api/teacher.ts + operations/teacher.graphql.ts → 重命名 legacy widget API 以解决命名冲突: Question → QuestionBankItem Textbook → LegacyTextbook Chapter → LegacyChapter TextbookFilter → LegacyTextbookFilter useTextbooks → useLegacyTextbooks GET_QUESTIONS_DOC → GET_QUESTION_BANK_DOC GET_TEXTBOOKS_DOC → GET_LEGACY_TEXTBOOKS_DOC - src/widgets/teacher/{question-bank,textbook-manager}/index.tsx → 更新引用为重命名后的 legacy API - src/mocks/graphql-data.ts → 添加 questions/textbooks mock + GetQuestionBank/GetLegacyTextbooks handler - src/messages/{zh-CN,en}.json (questions + textbooks i18n) - src/lib/api/{index,operations/index}.ts (导出 questions + textbooks) - src/shared/lib/route-permissions.ts (questions + textbooks 路由权限) - scripts/check-page-count.ts (baseline 37 → 40) DoD 验收(§11.3 11 项): - typecheck 0 errors - lint 0 errors - vitest 469 tests passed (新增 64 tests) - lint:tokens 0 errors - check:pages 40 PASS - route-permissions 已声明 - 三态齐备 - @contract-pending + MSW 兜底 - i18n zh-CN + en 同步 关联:ARCHITECTURE.md §5.3 / §5.4 / §5.5 / §9.1 / §10 P2 / §11.3 / §11.4 契约工单:docs/architecture/issues/contracts/core-edu_contract.md
161 lines
4.2 KiB
TypeScript
161 lines
4.2 KiB
TypeScript
// Page count baseline check (ARCHITECTURE.md §10 P1-8 / §11.6)
|
|
//
|
|
// Asserts that the total page.tsx count never drops below the baseline.
|
|
// Prevents accidental route deletion. When adding new pages, update the
|
|
// baseline in BASELINE.total. Per-category minimums catch regressions
|
|
// in specific areas (dashboards, login, etc.).
|
|
//
|
|
// Usage: tsx scripts/check-page-count.ts
|
|
// Exit: 0 = pass, 1 = below baseline
|
|
//
|
|
// Related: ARCHITECTURE.md §10 P1-8, §11.6 验收纪律
|
|
import * as fs from "node:fs";
|
|
import * as path from "node:path";
|
|
|
|
const APP_DIR = path.resolve(process.cwd(), "src/app");
|
|
|
|
interface Baseline {
|
|
total: number;
|
|
categories: Record<string, { pattern: string; min: number; label: string }>;
|
|
}
|
|
|
|
// Baseline as of P2 (2026-07-22, questions + textbooks modules added). Update when adding pages.
|
|
const BASELINE: Baseline = {
|
|
total: 40,
|
|
categories: {
|
|
dashboards: {
|
|
pattern: "shell/{admin,teacher,student,parent}/page.tsx",
|
|
min: 4,
|
|
label: "Role dashboards (admin/teacher/student/parent)",
|
|
},
|
|
login: {
|
|
pattern: "login/page.tsx",
|
|
min: 1,
|
|
label: "Login page",
|
|
},
|
|
root: {
|
|
pattern: "page.tsx",
|
|
min: 1,
|
|
label: "Root redirect page",
|
|
},
|
|
forbidden: {
|
|
pattern: "shell/forbidden/page.tsx",
|
|
min: 1,
|
|
label: "Forbidden page",
|
|
},
|
|
catchAll: {
|
|
pattern: "shell/[[...route]]/page.tsx",
|
|
min: 1,
|
|
label: "Shell catch-all",
|
|
},
|
|
devTemplates: {
|
|
pattern: "shell/dev/templates/**/page.tsx",
|
|
min: 5,
|
|
label: "Dev template pages",
|
|
},
|
|
},
|
|
};
|
|
|
|
function scanPages(): string[] {
|
|
const pages: string[] = [];
|
|
|
|
function walk(dir: string, base: string): void {
|
|
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
for (const entry of entries) {
|
|
const full = path.join(dir, entry.name);
|
|
const rel = path.relative(base, full).replace(/\\/g, "/");
|
|
if (entry.isDirectory()) {
|
|
walk(full, base);
|
|
} else if (entry.name === "page.tsx") {
|
|
pages.push(rel);
|
|
}
|
|
}
|
|
}
|
|
|
|
walk(APP_DIR, APP_DIR);
|
|
return pages.sort();
|
|
}
|
|
|
|
function matchGlob(pattern: string, relPath: string): boolean {
|
|
// Glob → regex: ** (any path), * (within segment), {a,b} (alternation)
|
|
let result = "";
|
|
let i = 0;
|
|
while (i < pattern.length) {
|
|
const c = pattern[i];
|
|
if (c === "*" && pattern[i + 1] === "*") {
|
|
// ** — match anything including /; skip trailing /
|
|
result += ".*";
|
|
i += 2;
|
|
if (pattern[i] === "/") i++;
|
|
} else if (c === "*") {
|
|
result += "[^/]*";
|
|
i++;
|
|
} else if (c === "{") {
|
|
const end = pattern.indexOf("}", i);
|
|
if (end === -1) {
|
|
result += "\\{";
|
|
i++;
|
|
} else {
|
|
const opts = pattern
|
|
.slice(i + 1, end)
|
|
.split(",")
|
|
.map((s) => s.trim());
|
|
result += `(${opts.join("|")})`;
|
|
i = end + 1;
|
|
}
|
|
} else if (".+?^$()[]|\\".includes(c)) {
|
|
result += `\\${c}`;
|
|
i++;
|
|
} else {
|
|
result += c;
|
|
i++;
|
|
}
|
|
}
|
|
return new RegExp(`^${result}$`).test(relPath);
|
|
}
|
|
|
|
function main(): void {
|
|
const pages = scanPages();
|
|
const total = pages.length;
|
|
|
|
console.log("=== Page Count Baseline Check ===");
|
|
console.log(`Total page.tsx files: ${total} (baseline: ${BASELINE.total})`);
|
|
console.log("");
|
|
|
|
// Per-category check
|
|
let categoryFail = false;
|
|
for (const [, cat] of Object.entries(BASELINE.categories)) {
|
|
const matched = pages.filter((p) => matchGlob(cat.pattern, p));
|
|
const count = matched.length;
|
|
const status = count >= cat.min ? "✅" : "❌";
|
|
if (count < cat.min) categoryFail = true;
|
|
console.log(` ${status} ${cat.label}: ${count} (min ${cat.min})`);
|
|
}
|
|
console.log("");
|
|
|
|
// Total check
|
|
const totalOk = total >= BASELINE.total;
|
|
if (!totalOk) {
|
|
console.log(`❌ Total ${total} < baseline ${BASELINE.total}`);
|
|
}
|
|
|
|
// List all pages
|
|
console.log("Pages:");
|
|
for (const p of pages) {
|
|
console.log(
|
|
` /${p.replace(/\/page\.tsx$/, "").replace(/^page\.tsx$/, "")}`,
|
|
);
|
|
}
|
|
console.log("");
|
|
|
|
if (!totalOk || categoryFail) {
|
|
console.log("Result: FAIL");
|
|
process.exit(1);
|
|
} else {
|
|
console.log(`Result: PASS (${total} pages, all categories meet minimum)`);
|
|
process.exit(0);
|
|
}
|
|
}
|
|
|
|
main();
|