|
2 | 2 | import { describe, expect, it } from "vitest"; |
3 | 3 | import { exitCodeFromFindings, runDoctorLintChecks } from "./doctor-lint-flow.js"; |
4 | 4 | import { normalizeHealthCheck } from "./health-check-adapter.js"; |
| 5 | +import { |
| 6 | + clearHealthChecksForTest, |
| 7 | + listHealthChecks, |
| 8 | + registerHealthCheck, |
| 9 | +} from "./health-check-registry.js"; |
5 | 10 | import type { RunnableHealthCheck } from "./health-check-runner-types.js"; |
6 | 11 | import type { HealthCheck, HealthCheckContext } from "./health-checks.js"; |
7 | 12 |
|
@@ -39,6 +44,87 @@ describe("runDoctorLintChecks", () => { |
39 | 44 | expect(result.findings.map((finding) => finding.checkId)).toEqual(["a"]); |
40 | 45 | }); |
41 | 46 |
|
| 47 | + it.each(["array", "set"] as const)( |
| 48 | + "reports conflicting selectors for a registered health check (%s)", |
| 49 | + async (selectorShape) => { |
| 50 | + const checkId = "plugin/example/critical"; |
| 51 | + let detections = 0; |
| 52 | + const existingChecks = listHealthChecks(); |
| 53 | + registerHealthCheck( |
| 54 | + check(checkId, async () => { |
| 55 | + detections += 1; |
| 56 | + return [{ checkId, severity: "error", message: "critical failure" }]; |
| 57 | + }), |
| 58 | + ); |
| 59 | + |
| 60 | + try { |
| 61 | + const selectors = selectorShape === "set" ? new Set([checkId]) : [checkId]; |
| 62 | + const result = await runDoctorLintChecks(ctx, { |
| 63 | + onlyIds: selectors, |
| 64 | + skipIds: selectors, |
| 65 | + }); |
| 66 | + |
| 67 | + expect(detections).toBe(0); |
| 68 | + expect(result.checksRun).toBe(0); |
| 69 | + expect(result.checksSkipped).toBe(1); |
| 70 | + expect(result.findings).toEqual([ |
| 71 | + { |
| 72 | + checkId: "core/doctor/lint-selection", |
| 73 | + severity: "error", |
| 74 | + message: `Health check ${checkId} cannot be selected by --only and excluded by --skip.`, |
| 75 | + path: checkId, |
| 76 | + }, |
| 77 | + ]); |
| 78 | + expect(exitCodeFromFindings(result.findings)).toBe(1); |
| 79 | + } finally { |
| 80 | + clearHealthChecksForTest(); |
| 81 | + for (const existingCheck of existingChecks) { |
| 82 | + registerHealthCheck(existingCheck); |
| 83 | + } |
| 84 | + } |
| 85 | + }, |
| 86 | + ); |
| 87 | + |
| 88 | + it("keeps non-conflicting selection and exclusion filters independent", async () => { |
| 89 | + let selectedDetections = 0; |
| 90 | + let skippedDetections = 0; |
| 91 | + const result = await runDoctorLintChecks(ctx, { |
| 92 | + checks: [ |
| 93 | + check("plugin/example/selected", async () => { |
| 94 | + selectedDetections += 1; |
| 95 | + return []; |
| 96 | + }), |
| 97 | + check("plugin/example/skipped", async () => { |
| 98 | + skippedDetections += 1; |
| 99 | + return []; |
| 100 | + }), |
| 101 | + ], |
| 102 | + onlyIds: ["plugin/example/selected"], |
| 103 | + skipIds: ["plugin/example/skipped"], |
| 104 | + }); |
| 105 | + |
| 106 | + expect(result).toEqual({ findings: [], checksRun: 1, checksSkipped: 1 }); |
| 107 | + expect(selectedDetections).toBe(1); |
| 108 | + expect(skippedDetections).toBe(0); |
| 109 | + }); |
| 110 | + |
| 111 | + it("preserves forward-compatible skips for unregistered plugin checks", async () => { |
| 112 | + let detections = 0; |
| 113 | + const result = await runDoctorLintChecks(ctx, { |
| 114 | + checks: [ |
| 115 | + check("plugin/example/available", async () => { |
| 116 | + detections += 1; |
| 117 | + return []; |
| 118 | + }), |
| 119 | + ], |
| 120 | + skipIds: ["plugin/future/not-loaded"], |
| 121 | + }); |
| 122 | + |
| 123 | + expect(result).toEqual({ findings: [], checksRun: 1, checksSkipped: 0 }); |
| 124 | + expect(detections).toBe(1); |
| 125 | + expect(exitCodeFromFindings(result.findings)).toBe(0); |
| 126 | + }); |
| 127 | + |
42 | 128 | it("skips default-disabled checks unless explicitly selected", async () => { |
43 | 129 | const defaultDisabled = normalizeHealthCheck({ |
44 | 130 | ...check("targeted", async () => [ |
|
0 commit comments