ESLint 升级到 recommended-type-checked + stylistic-type-checked, 引入 perfectionist 导入排序和 import 插件导入验证。 Prettier 显式声明全部格式化参数,消除跨环境差异。 TypeScript 启用 noUnusedLocals 和 noPropertyAccessFromIndexSignature。 完善 ignore 列表,排除 .agents/、bun.lock、data/ 等。 引入 husky + lint-staged(pre-commit)+ commitlint(commit-msg)。 更新 DEVELOPMENT.md 代码质量章节。 修复所有新增规则检测到的类型和风格违规。
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
|
|
import { checkTextRules } from "../../../../../src/server/checker/runner/shared/text";
|
|
|
|
describe("checkTextRules", () => {
|
|
test("无规则返回匹配成功", () => {
|
|
const r = checkTextRules("hello", [], "stdout");
|
|
expect(r.matched).toBe(true);
|
|
expect(r.failure).toBeNull();
|
|
});
|
|
|
|
test("单条 contains 规则匹配成功", () => {
|
|
const r = checkTextRules("build completed successfully", [{ contains: "completed" }], "stdout");
|
|
expect(r.matched).toBe(true);
|
|
});
|
|
|
|
test("单条 contains 规则匹配失败", () => {
|
|
const r = checkTextRules("build completed successfully", [{ contains: "failed" }], "stdout");
|
|
expect(r.matched).toBe(false);
|
|
expect(r.failure!.phase).toBe("stdout");
|
|
expect(r.failure!.path).toBe("stdout[0]");
|
|
});
|
|
|
|
test("多条规则全部通过", () => {
|
|
const r = checkTextRules(
|
|
"version: 3.2.1, build: ok",
|
|
[{ contains: "version" }, { match: "\\d+\\.\\d+\\.\\d+" }],
|
|
"stdout",
|
|
);
|
|
expect(r.matched).toBe(true);
|
|
});
|
|
|
|
test("第一条规则失败立即返回", () => {
|
|
const r = checkTextRules("error occurred", [{ contains: "success" }, { contains: "error" }], "stdout");
|
|
expect(r.matched).toBe(false);
|
|
expect(r.failure!.phase).toBe("stdout");
|
|
expect(r.failure!.path).toBe("stdout[0]");
|
|
});
|
|
|
|
test("stderr phase", () => {
|
|
const r = checkTextRules("warning: deprecated", [{ contains: "warning" }], "stderr");
|
|
expect(r.matched).toBe(true);
|
|
expect(r.failure).toBeNull();
|
|
});
|
|
|
|
test("empty 操作符", () => {
|
|
const r = checkTextRules("", [{ empty: true }], "stderr");
|
|
expect(r.matched).toBe(true);
|
|
});
|
|
});
|