Skip to content

Commit a176b7c

Browse files
committed
Fix tests after removing weak default rules
1 parent 5ec273b commit a176b7c

1 file changed

Lines changed: 44 additions & 26 deletions

File tree

tests/config.test.ts

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async function createTempRepo(): Promise<string> {
1919
await mkdir(path.join(rootDir, "src"), { recursive: true });
2020
await writeFile(
2121
path.join(rootDir, "src", "comments.ts"),
22-
"// Add more validation if needed\nexport const commentExample = true;\n",
22+
"function loadValue(input: string) {\n return Promise.resolve(input);\n}\n\nexport async function fetchData(id: string) {\n return await loadValue(id);\n}\n",
2323
);
2424
return rootDir;
2525
}
@@ -52,25 +52,34 @@ describe("rule config support", () => {
5252
const rootDir = await createTempRepo();
5353
const result = await analyzeRepository(
5454
rootDir,
55-
withRuleConfig("comments.placeholder-comments", { enabled: false }),
55+
withRuleConfig("defensive.async-noise", { enabled: false }),
5656
createDefaultRegistry(),
5757
);
5858

59-
expect(result.findings).toHaveLength(0);
59+
expect(
60+
result.findings.filter((finding) => finding.ruleId === "defensive.async-noise"),
61+
).toHaveLength(0);
6062
});
6163

6264
test("can weight a rule via config", async () => {
6365
const rootDir = await createTempRepo();
6466
const baseline = await analyzeRepository(rootDir, DEFAULT_CONFIG, createDefaultRegistry());
6567
const weighted = await analyzeRepository(
6668
rootDir,
67-
withRuleConfig("comments.placeholder-comments", { weight: 2 }),
69+
withRuleConfig("defensive.async-noise", { weight: 2 }),
6870
createDefaultRegistry(),
6971
);
7072

71-
expect(baseline.findings).toHaveLength(1);
72-
expect(weighted.findings).toHaveLength(1);
73-
expect(weighted.findings[0]?.score).toBeCloseTo((baseline.findings[0]?.score ?? 0) * 2, 6);
73+
const baselineAsyncNoise = baseline.findings.find(
74+
(finding) => finding.ruleId === "defensive.async-noise",
75+
);
76+
const weightedAsyncNoise = weighted.findings.find(
77+
(finding) => finding.ruleId === "defensive.async-noise",
78+
);
79+
80+
expect(baselineAsyncNoise).toBeDefined();
81+
expect(weightedAsyncNoise).toBeDefined();
82+
expect(weightedAsyncNoise?.score).toBeCloseTo((baselineAsyncNoise?.score ?? 0) * 2, 6);
7483
});
7584

7685
test("loadConfig reads slop-scan.config.json", async () => {
@@ -104,47 +113,56 @@ describe("rule config support", () => {
104113
const rootDir = await createTempRepo();
105114
await writeFile(
106115
path.join(rootDir, "src", "nested.ts"),
107-
"// Add more validation if needed\nexport const nested = true;\n",
116+
"function fetchRemote(input: string) {\n return Promise.resolve(input);\n}\n\nexport async function loadValue(id: string) {\n return await fetchRemote(id);\n}\n",
108117
);
109118

110119
const result = await analyzeRepository(
111120
rootDir,
112121
withPathOverride(["src/comments.ts"], {
113-
"comments.placeholder-comments": { enabled: false },
122+
"defensive.async-noise": { enabled: false },
114123
}),
115124
createDefaultRegistry(),
116125
);
117126

118-
expect(result.findings).toHaveLength(1);
119-
expect(result.findings[0]?.path).toBe("src/nested.ts");
127+
const asyncNoiseFindings = result.findings.filter(
128+
(finding) => finding.ruleId === "defensive.async-noise",
129+
);
130+
131+
expect(asyncNoiseFindings).toHaveLength(1);
132+
expect(asyncNoiseFindings[0]?.path).toBe("src/nested.ts");
120133
});
121134

122135
test("can apply a path-scoped directory override", async () => {
123136
const rootDir = await createTempRepo();
124137

125-
for (const dirName of ["src/rules/defensive", "src/other/defensive"]) {
126-
for (let index = 0; index < 6; index += 1) {
127-
await mkdir(path.join(rootDir, dirName), { recursive: true });
128-
await writeFile(
129-
path.join(rootDir, dirName, `file-${index}.ts`),
130-
`export const value${index} = ${index};\n`,
131-
);
132-
}
133-
}
138+
await mkdir(path.join(rootDir, "src/rules/defensive"), { recursive: true });
139+
await writeFile(
140+
path.join(rootDir, "src/rules/defensive/service.ts"),
141+
"function fetchRule(input: string) {\n return Promise.resolve(input);\n}\n\nexport async function loadRule(id: string) {\n return await fetchRule(id);\n}\n",
142+
);
143+
144+
await mkdir(path.join(rootDir, "src/other/defensive"), { recursive: true });
145+
await writeFile(
146+
path.join(rootDir, "src/other/defensive/service.ts"),
147+
"function fetchOther(input: string) {\n return Promise.resolve(input);\n}\n\nexport async function loadOther(id: string) {\n return await fetchOther(id);\n}\n",
148+
);
134149

135150
const result = await analyzeRepository(
136151
rootDir,
137152
withPathOverride(["src/rules/**"], {
138-
"structure.over-fragmentation": { enabled: false },
153+
"defensive.async-noise": { enabled: false },
139154
}),
140155
createDefaultRegistry(),
141156
);
142157

143-
const fragmentationFindings = result.findings.filter(
144-
(finding) => finding.ruleId === "structure.over-fragmentation",
158+
const asyncNoiseFindings = result.findings.filter(
159+
(finding) => finding.ruleId === "defensive.async-noise",
145160
);
146161

147-
expect(fragmentationFindings.map((finding) => finding.path)).toEqual(["src/other/defensive"]);
162+
expect(asyncNoiseFindings.map((finding) => finding.path).sort()).toEqual([
163+
"src/comments.ts",
164+
"src/other/defensive/service.ts",
165+
]);
148166
});
149167

150168
test("loadConfig reads path-scoped overrides", async () => {
@@ -156,7 +174,7 @@ describe("rule config support", () => {
156174
{
157175
files: ["src/comments.ts"],
158176
rules: {
159-
"comments.placeholder-comments": { enabled: false },
177+
"defensive.async-noise": { enabled: false },
160178
},
161179
},
162180
],
@@ -169,7 +187,7 @@ describe("rule config support", () => {
169187
{
170188
files: ["src/comments.ts"],
171189
rules: {
172-
"comments.placeholder-comments": { enabled: false },
190+
"defensive.async-noise": { enabled: false },
173191
},
174192
},
175193
]);

0 commit comments

Comments
 (0)