Skip to content

Commit 5816881

Browse files
steipetePeter Steinberger
andauthored
fix(doctor): reject contradictory lint check selectors (#117495)
Co-authored-by: Peter Steinberger <[email protected]>
1 parent 0df66f6 commit 5816881

2 files changed

Lines changed: 98 additions & 6 deletions

File tree

‎src/flows/doctor-lint-flow.test.ts‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
import { describe, expect, it } from "vitest";
33
import { exitCodeFromFindings, runDoctorLintChecks } from "./doctor-lint-flow.js";
44
import { normalizeHealthCheck } from "./health-check-adapter.js";
5+
import {
6+
clearHealthChecksForTest,
7+
listHealthChecks,
8+
registerHealthCheck,
9+
} from "./health-check-registry.js";
510
import type { RunnableHealthCheck } from "./health-check-runner-types.js";
611
import type { HealthCheck, HealthCheckContext } from "./health-checks.js";
712

@@ -39,6 +44,87 @@ describe("runDoctorLintChecks", () => {
3944
expect(result.findings.map((finding) => finding.checkId)).toEqual(["a"]);
4045
});
4146

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+
42128
it("skips default-disabled checks unless explicitly selected", async () => {
43129
const defaultDisabled = normalizeHealthCheck({
44130
...check("targeted", async () => [

‎src/flows/doctor-lint-flow.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,20 @@ export async function runDoctorLintChecks(
5050

5151
const findings: HealthFinding[] = [];
5252
for (const id of only) {
53+
let message: string;
5354
if (!allIds.has(id)) {
54-
findings.push({
55-
checkId: "core/doctor/lint-selection",
56-
severity: "error",
57-
message: `Unknown health check id selected by --only: ${id}.`,
58-
path: id,
59-
});
55+
message = `Unknown health check id selected by --only: ${id}.`;
56+
} else if (skip.has(id)) {
57+
message = `Health check ${id} cannot be selected by --only and excluded by --skip.`;
58+
} else {
59+
continue;
6060
}
61+
findings.push({
62+
checkId: "core/doctor/lint-selection",
63+
severity: "error",
64+
message,
65+
path: id,
66+
});
6167
}
6268
for (const check of selected) {
6369
try {

0 commit comments

Comments
 (0)