test(workflow): 补齐条件比较符、节点类型与错误指纹的测试覆盖
- 新增 branch/evaluate-rule.test.ts:覆盖 eq/neq、empty/not_empty、in/not_in、
include/not_include、gt/gte/lt/lte 全部比较符,含无法确定(返回 null)的边界,
以及 @{value(...)} / @{choose(...)} 描述符解析。此前只有 eq 与 gt 有用例。
- 新增未知节点类型与权限证据边界用例:UNKNOWN_TASK_TYPE 硬软门禁、
以及拿不到开通清单(availableNodeTypes 为空)时既不谎报通过也不误报缺失。
错误指纹:
- alert observe() 原先在 SQLite 事务提交后直接 writeFileSync,
落盘失败会把整轮巡检打成失败;而此刻指纹其实已经写入,
下一轮会被当成「未观察过」从而重复提醒。改为捕获异常并以 exportError 返回,
SQLite 仍作为唯一事实来源。
- 新增 alert/index.test.ts,并把原先写在 state/index.test.ts 里的告警用例迁移回来,
修正模块归属错位。
覆盖 1004 个用例,`bun run check` 无错误。
This commit is contained in:
1 parent
71aa9b54a7
commit
cedc4249e5
6 files changed
+271
-38
No files matched your search
@@ -30,9 +30,6 @@ import {
|
||||
sanitizeWorkflowSnapshot,
|
||||
} from "../services.js";
|
||||
import { AuthenticationError, EkbApiError } from "../../../../core/errors.js";
|
||||
import { WorkflowAlertStore } from "../alert/index.js";
|
||||
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
const workflow = (overrides: Partial<WorkflowDetail> = {}): WorkflowDetail => WorkflowDetailSchema.parse({
|
||||
id: "wf-1",
|
||||
@@ -187,33 +184,6 @@ describe("workflow draft state machine", () => {
|
||||
expect(result.state).toBeNull();
|
||||
});
|
||||
|
||||
it("persists workflow alert fingerprints and only reports new counts", () => {
|
||||
const dir = mkdtempSync("hose-workflow-alert-");
|
||||
const file = join(dir, "alerts.json");
|
||||
const store = new WorkflowAlertStore(file);
|
||||
const alert = { id: "corp:platform:wf-1", pipelineId: "wf-1", platformId: "platform-1", pipelineName: "测试流程", errorCount: 1, state: 0, observedAt: 1 };
|
||||
expect(store.observe([alert]).newAlerts).toHaveLength(1);
|
||||
expect(store.observe([{ ...alert, observedAt: 2 }]).newAlerts).toHaveLength(0);
|
||||
expect(store.observe([{ ...alert, errorCount: 2, observedAt: 3 }]).newAlerts).toHaveLength(1);
|
||||
expect(store.observe([]).newAlerts).toHaveLength(0);
|
||||
expect(store.observe([{ ...alert, observedAt: 4 }]).newAlerts).toHaveLength(1);
|
||||
expect(JSON.parse(readFileSync(file, "utf8")).version).toBe(1);
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it("preserves previously observed alerts when a scan is incomplete", () => {
|
||||
const dir = mkdtempSync("hose-workflow-alert-partial-");
|
||||
const file = join(dir, "alerts.json");
|
||||
const store = new WorkflowAlertStore(file);
|
||||
const alert = { id: "corp:platform:wf-1", pipelineId: "wf-1", platformId: "platform-1", pipelineName: "测试流程", errorCount: 1, state: 0, observedAt: 1 };
|
||||
expect(store.observe([alert]).newAlerts).toHaveLength(1);
|
||||
store.observe([], { complete: false });
|
||||
expect(store.observe([{ ...alert, observedAt: 2 }], { complete: false }).newAlerts).toHaveLength(0);
|
||||
store.observe([], { complete: true });
|
||||
expect(store.observe([alert]).newAlerts).toHaveLength(1);
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it("tracks dirty revisions and commits the server snapshot", () => {
|
||||
let state = createWorkflowDraft(workflow());
|
||||
state = patchWorkflowDraft(state, (current) => ({ ...current, label: "已修改" }), ["label"]);
|
||||
|
||||
Reference in new issue
Block a user