import { describe, expect, test } from "bun:test"; import { normalizeTargetExpect } from "../../../../../src/server/checker/runner/cpu/normalize"; describe("normalizeTargetExpect (cpu)", () => { test("无 expect 直接返回", () => { const target = { cpu: {}, id: "test", type: "cpu" }; expect(normalizeTargetExpect(target)).toEqual(target); }); test("expect 为非对象直接返回", () => { const target = { cpu: {}, expect: "not-an-object", id: "test", type: "cpu" }; expect(normalizeTargetExpect(target)).toEqual(target); }); test("ValueMatcher 简写展开", () => { const target = { cpu: {}, expect: { usagePercent: 85 }, id: "test", type: "cpu" }; const result = normalizeTargetExpect(target); expect((result.expect as Record)["usagePercent"]).toEqual({ equals: 85 }); }); test("已经是 matcher 对象的不变", () => { const target = { cpu: {}, expect: { usagePercent: { lte: 85 } }, id: "test", type: "cpu" }; const result = normalizeTargetExpect(target); expect((result.expect as Record)["usagePercent"]).toEqual({ lte: 85 }); }); test("多个字段同时展开", () => { const target = { cpu: {}, expect: { idlePercent: 15, maxCoreUsagePercent: { lte: 95 }, usagePercent: 85 }, id: "test", type: "cpu", }; const result = normalizeTargetExpect(target); const expectObj = result.expect as Record; expect(expectObj["idlePercent"]).toEqual({ equals: 15 }); expect(expectObj["maxCoreUsagePercent"]).toEqual({ lte: 95 }); expect(expectObj["usagePercent"]).toEqual({ equals: 85 }); }); });