WOPS1 调整巡检告警降噪
Issue: WOPS1, WROAD2C, WREAL1P
这个提交包含在:
@@ -1,6 +1,8 @@
|
||||
const {
|
||||
assertAlertSendAllowed,
|
||||
buildAlertMessage,
|
||||
buildAlertState,
|
||||
evaluateAlertDecision,
|
||||
executeOpsAlert,
|
||||
parseArgs,
|
||||
shouldSendForSummary,
|
||||
@@ -12,9 +14,10 @@ const SENSITIVE_TOKEN = ["ops", "alert", "token", "should", "not", "leak"].join(
|
||||
function baseOptions(overrides = {}) {
|
||||
return {
|
||||
summaryFile: "",
|
||||
recipientEmployeeNos: ["wangshunli", "HYD000006"],
|
||||
recipientEmployeeNos: ["HYD000006"],
|
||||
send: false,
|
||||
force: false,
|
||||
stateFile: "/tmp/wecom-ops-alert-state-test.json",
|
||||
format: "json",
|
||||
reportDir: "/tmp/wecom-ops-alert-test",
|
||||
help: false,
|
||||
@@ -34,12 +37,6 @@ function baseSummary(overrides = {}) {
|
||||
|
||||
function recipientRows(overrides = {}) {
|
||||
return [
|
||||
{
|
||||
employeeNo: "wangshunli",
|
||||
status: "active",
|
||||
archived: false,
|
||||
wecomExternalUserId: SENSITIVE_USER_ID,
|
||||
},
|
||||
{
|
||||
employeeNo: "HYD000006",
|
||||
status: "active",
|
||||
@@ -53,15 +50,16 @@ describe("send-wecom-ops-alert", () => {
|
||||
it("parses recipients and enforces double confirmation", () => {
|
||||
const options = parseArgs([
|
||||
"--summary-file=/tmp/summary.json",
|
||||
"--recipient-employee-no=wangshunli",
|
||||
"--recipient-employee-no",
|
||||
"HYD000006",
|
||||
"--send",
|
||||
"--state-file=/tmp/warch3-state.json",
|
||||
"--format=json",
|
||||
]);
|
||||
|
||||
expect(options.summaryFile).toBe("/tmp/summary.json");
|
||||
expect(options.recipientEmployeeNos).toEqual(["wangshunli", "HYD000006"]);
|
||||
expect(options.recipientEmployeeNos).toEqual(["HYD000006"]);
|
||||
expect(options.stateFile).toBe("/tmp/warch3-state.json");
|
||||
expect(options.send).toBe(true);
|
||||
expect(() => assertAlertSendAllowed(options, {})).toThrow(/WARCH3_OPS_ALERT_SEND=1/);
|
||||
expect(() => assertAlertSendAllowed(options, { WARCH3_OPS_ALERT_SEND: "1" })).not.toThrow();
|
||||
@@ -83,6 +81,54 @@ describe("send-wecom-ops-alert", () => {
|
||||
expect(shouldSendForSummary(summary, baseOptions({ force: true }))).toBe(true);
|
||||
});
|
||||
|
||||
it("records the first PASS_WITH_FINDINGS run as baseline without sending", () => {
|
||||
const summary = baseSummary({
|
||||
findings: [{ source: "approvalArchive", status: "PASS_WITH_FINDINGS", severity: "info", evidenceDigest: "known" }],
|
||||
});
|
||||
const decision = evaluateAlertDecision(summary, baseOptions(), null);
|
||||
|
||||
expect(decision.shouldSend).toBe(false);
|
||||
expect(decision.reason).toBe("baseline_recorded");
|
||||
});
|
||||
|
||||
it("sends when a new finding appears after baseline", () => {
|
||||
const previousSummary = baseSummary({
|
||||
findings: [{ source: "approvalArchive", status: "PASS_WITH_FINDINGS", severity: "info", evidenceDigest: "known" }],
|
||||
});
|
||||
const currentSummary = baseSummary({
|
||||
findings: [
|
||||
{ source: "approvalArchive", status: "PASS_WITH_FINDINGS", severity: "info", evidenceDigest: "known" },
|
||||
{ source: "wecomRuntimeReady", status: "PASS_WITH_FINDINGS", severity: "warn", evidenceDigest: "new" },
|
||||
],
|
||||
});
|
||||
const decision = evaluateAlertDecision(currentSummary, baseOptions(), buildAlertState(previousSummary));
|
||||
|
||||
expect(decision.shouldSend).toBe(true);
|
||||
expect(decision.reason).toBe("new_findings");
|
||||
expect(decision.newFindingKeys).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("skips repeated known findings after baseline", () => {
|
||||
const summary = baseSummary({
|
||||
findings: [{ source: "approvalArchive", status: "PASS_WITH_FINDINGS", severity: "info", evidenceDigest: "known" }],
|
||||
});
|
||||
const decision = evaluateAlertDecision(summary, baseOptions(), buildAlertState(summary));
|
||||
|
||||
expect(decision.shouldSend).toBe(false);
|
||||
expect(decision.reason).toBe("no_new_findings_or_status_worsening");
|
||||
});
|
||||
|
||||
it("sends when status worsens or blocks", () => {
|
||||
const previous = buildAlertState(baseSummary({ status: "PASS_ARCHIVE_OPS_READY", findingCount: 0, findings: [] }));
|
||||
const worsened = evaluateAlertDecision(baseSummary({ status: "PASS_WITH_FINDINGS", findingCount: 0, findings: [] }), baseOptions(), previous);
|
||||
const blocked = evaluateAlertDecision(baseSummary({ status: "SKIP/BLOCKED_BY_EXTERNAL_CONFIG", findingCount: 0, findings: [] }), baseOptions(), null);
|
||||
|
||||
expect(worsened.shouldSend).toBe(true);
|
||||
expect(worsened.reason).toBe("status_worsened");
|
||||
expect(blocked.shouldSend).toBe(true);
|
||||
expect(blocked.reason).toBe("blocked_or_failed");
|
||||
});
|
||||
|
||||
it("dry-runs alert without sending and redacts recipients", async () => {
|
||||
const sendMessageImpl = vi.fn();
|
||||
const report = await executeOpsAlert(baseOptions(), {
|
||||
@@ -94,8 +140,9 @@ describe("send-wecom-ops-alert", () => {
|
||||
generatedAt: "2026-05-20T04:00:00.000Z",
|
||||
});
|
||||
|
||||
expect(report.status).toBe("PASS_ALERT_DRY_RUN_READY");
|
||||
expect(report.delivery.status).toBe("DRY_RUN_READY");
|
||||
expect(report.status).toBe("PASS_ALERT_SKIPPED_NO_FINDINGS");
|
||||
expect(report.delivery.status).toBe("SKIPPED_NO_FINDINGS");
|
||||
expect(report.alertDecision.reason).toBe("baseline_recorded");
|
||||
expect(sendMessageImpl).not.toHaveBeenCalled();
|
||||
const text = JSON.stringify(report);
|
||||
expect(text).not.toContain(SENSITIVE_USER_ID);
|
||||
@@ -119,6 +166,8 @@ describe("send-wecom-ops-alert", () => {
|
||||
sendMessageImpl,
|
||||
env: { WARCH3_OPS_ALERT_SEND: "1" },
|
||||
config: { wecomRequestTimeoutMs: 1000 },
|
||||
priorState: buildAlertState(baseSummary({ status: "PASS_ARCHIVE_OPS_READY", findingCount: 0, findings: [] })),
|
||||
writeAlertState: vi.fn(() => "/tmp/warch3-state.json"),
|
||||
});
|
||||
|
||||
expect(report.status).toBe("PASS_ALERT_SENT");
|
||||
@@ -127,42 +176,16 @@ describe("send-wecom-ops-alert", () => {
|
||||
expect(JSON.stringify(report)).not.toContain(SENSITIVE_USER_ID);
|
||||
});
|
||||
|
||||
it("sends to the valid admin recipient while recording alias gaps", async () => {
|
||||
const sendMessageImpl = vi.fn(async ({ recipientExternalUserIds }) => {
|
||||
expect(recipientExternalUserIds).toEqual([SENSITIVE_USER_ID]);
|
||||
return {
|
||||
ok: true,
|
||||
code: "wecom_app_sent",
|
||||
message: null,
|
||||
response: { errcode: 0, recipientCount: 1 },
|
||||
};
|
||||
});
|
||||
const report = await executeOpsAlert(baseOptions({ send: true }), {
|
||||
summary: baseSummary(),
|
||||
recipientRows: recipientRows({
|
||||
wangshunli: { employeeNo: "missing", wecomExternalUserId: "" },
|
||||
}).filter((row) => row.employeeNo !== "missing"),
|
||||
sendMessageImpl,
|
||||
env: { WARCH3_OPS_ALERT_SEND: "1" },
|
||||
config: { wecomRequestTimeoutMs: 1000 },
|
||||
});
|
||||
|
||||
expect(report.status).toBe("PASS_ALERT_SENT_WITH_CONFIG_GAPS");
|
||||
expect(report.recipientGaps.map((item) => item.id)).toContain("recipient_missing");
|
||||
expect(report.delivery.status).toBe("OK");
|
||||
expect(sendMessageImpl).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("classifies missing binding as config gap", async () => {
|
||||
const report = await executeOpsAlert(baseOptions({ send: true }), {
|
||||
summary: baseSummary(),
|
||||
recipientRows: recipientRows({
|
||||
wangshunli: { wecomExternalUserId: "" },
|
||||
HYD000006: { wecomExternalUserId: "" },
|
||||
}),
|
||||
sendMessageImpl: vi.fn(),
|
||||
env: { WARCH3_OPS_ALERT_SEND: "1" },
|
||||
config: {},
|
||||
priorState: buildAlertState(baseSummary({ status: "PASS_ARCHIVE_OPS_READY", findingCount: 0, findings: [] })),
|
||||
});
|
||||
|
||||
expect(report.status).toBe("PARTIAL_ALERT_NEEDS_CONFIG");
|
||||
@@ -181,6 +204,8 @@ describe("send-wecom-ops-alert", () => {
|
||||
})),
|
||||
env: { WARCH3_OPS_ALERT_SEND: "1" },
|
||||
config: {},
|
||||
priorState: buildAlertState(baseSummary({ status: "PASS_ARCHIVE_OPS_READY", findingCount: 0, findings: [] })),
|
||||
writeAlertState: vi.fn(() => "/tmp/warch3-state.json"),
|
||||
});
|
||||
|
||||
expect(report.status).toBe("SKIP");
|
||||
|
||||
在新工单中引用
屏蔽一个用户