CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | /**
* Block J12 — Community health scorecard tests.
*
* Pure helpers + route smoke.
*/
import { describe, it, expect } from "bun:test";
import app from "../app";
import {
CHECKLIST,
buildReport,
checklistFromInputs,
isCodeOfConduct,
isContributing,
isLicense,
isPrTemplate,
isReadme,
} from "../lib/community";
describe("community — name matchers", () => {
it("isReadme matches all common spellings", () => {
expect(isReadme("README")).toBe(true);
expect(isReadme("readme.md")).toBe(true);
expect(isReadme("Readme.MD")).toBe(true);
expect(isReadme("README.txt")).toBe(true);
expect(isReadme("README.rst")).toBe(true);
expect(isReadme("readme.markdown")).toBe(true);
});
it("isReadme rejects look-alikes", () => {
expect(isReadme("readme.html")).toBe(false);
expect(isReadme("not-readme.md")).toBe(false);
expect(isReadme("READMEFIRST.md")).toBe(false);
});
it("isLicense matches LICENSE / LICENCE / COPYING variants", () => {
expect(isLicense("LICENSE")).toBe(true);
expect(isLicense("License.md")).toBe(true);
expect(isLicense("LICENCE.txt")).toBe(true);
expect(isLicense("COPYING")).toBe(true);
});
it("isLicense rejects unrelated files", () => {
expect(isLicense("licensing.md")).toBe(false);
expect(isLicense("license-check.md")).toBe(false);
});
it("isCodeOfConduct matches common separators", () => {
expect(isCodeOfConduct("CODE_OF_CONDUCT.md")).toBe(true);
expect(isCodeOfConduct("code-of-conduct.md")).toBe(true);
expect(isCodeOfConduct("CodeOfConduct")).toBe(true);
});
it("isContributing matches case-insensitively", () => {
expect(isContributing("CONTRIBUTING.md")).toBe(true);
expect(isContributing("contributing")).toBe(true);
expect(isContributing("contributing.txt")).toBe(true);
expect(isContributing("contributors.md")).toBe(false);
});
it("isPrTemplate matches expected spellings", () => {
expect(isPrTemplate("pull_request_template.md")).toBe(true);
expect(isPrTemplate("PULL_REQUEST_TEMPLATE")).toBe(true);
expect(isPrTemplate("pull-request-template.md")).toBe(true);
expect(isPrTemplate("PR_TEMPLATE.md")).toBe(false);
});
});
describe("community — CHECKLIST table", () => {
it("exposes eight items with unique keys", () => {
expect(CHECKLIST.length).toBe(8);
const keys = new Set(CHECKLIST.map((c) => c.key));
expect(keys.size).toBe(8);
});
it("marks description/readme/license required; others recommended", () => {
const required = new Set(
CHECKLIST.filter((i) => i.required).map((i) => i.key)
);
expect(required.has("description")).toBe(true);
expect(required.has("readme")).toBe(true);
expect(required.has("license")).toBe(true);
expect(required.has("code_of_conduct")).toBe(false);
expect(required.has("pr_template")).toBe(false);
});
});
describe("community — checklistFromInputs", () => {
const empty = {
rootEntries: [],
githubEntries: [],
issueTemplateDirExists: false,
description: null,
topics: [],
};
it("all-zero input → all checks false", () => {
const r = checklistFromInputs(empty);
for (const key of Object.keys(r) as Array<keyof typeof r>) {
expect(r[key]).toBe(false);
}
});
it("detects README at root + README in .github", () => {
expect(
checklistFromInputs({ ...empty, rootEntries: ["README.md"] }).readme
).toBe(true);
expect(
checklistFromInputs({ ...empty, githubEntries: ["README.md"] }).readme
).toBe(true);
});
it("LICENSE variants all count", () => {
for (const n of ["LICENSE", "License.md", "LICENCE.txt", "COPYING"]) {
expect(
checklistFromInputs({ ...empty, rootEntries: [n] }).license
).toBe(true);
}
});
it("description requires non-empty trimmed text", () => {
expect(checklistFromInputs({ ...empty, description: "" }).description).toBe(false);
expect(
checklistFromInputs({ ...empty, description: " " }).description
).toBe(false);
expect(checklistFromInputs({ ...empty, description: "x" }).description).toBe(true);
});
it("topics requires at least one", () => {
expect(checklistFromInputs({ ...empty, topics: [] }).topics).toBe(false);
expect(checklistFromInputs({ ...empty, topics: ["ai"] }).topics).toBe(true);
});
it("issue_template is present if dir exists OR a single file", () => {
expect(
checklistFromInputs({ ...empty, issueTemplateDirExists: true })
.issue_template
).toBe(true);
expect(
checklistFromInputs({
...empty,
rootEntries: ["ISSUE_TEMPLATE.md"],
}).issue_template
).toBe(true);
expect(
checklistFromInputs({
...empty,
githubEntries: ["ISSUE_TEMPLATE.md"],
}).issue_template
).toBe(true);
});
it("pr_template — accepts .github/ and root spellings", () => {
expect(
checklistFromInputs({
...empty,
githubEntries: ["pull_request_template.md"],
}).pr_template
).toBe(true);
expect(
checklistFromInputs({
...empty,
rootEntries: ["PULL_REQUEST_TEMPLATE.md"],
}).pr_template
).toBe(true);
});
});
describe("community — buildReport", () => {
it("all-false → 0% / meetsRequired false", () => {
const r = buildReport({
description: false,
readme: false,
license: false,
code_of_conduct: false,
contributing: false,
issue_template: false,
pr_template: false,
topics: false,
});
expect(r.score).toBe(0);
expect(r.passed).toBe(0);
expect(r.total).toBe(8);
expect(r.requiredPassed).toBe(0);
expect(r.requiredTotal).toBe(3);
expect(r.meetsRequired).toBe(false);
});
it("all-true → 100% / meetsRequired true", () => {
const r = buildReport({
description: true,
readme: true,
license: true,
code_of_conduct: true,
contributing: true,
issue_template: true,
pr_template: true,
topics: true,
});
expect(r.score).toBe(100);
expect(r.meetsRequired).toBe(true);
});
it("required-only → meetsRequired true, score partial", () => {
const r = buildReport({
description: true,
readme: true,
license: true,
code_of_conduct: false,
contributing: false,
issue_template: false,
pr_template: false,
topics: false,
});
expect(r.meetsRequired).toBe(true);
expect(r.score).toBe(Math.round((3 / 8) * 100));
});
it("preserves CHECKLIST ordering + annotates `present`", () => {
const r = buildReport({
description: true,
readme: false,
license: false,
code_of_conduct: false,
contributing: false,
issue_template: false,
pr_template: false,
topics: false,
});
expect(r.items[0].key).toBe("description");
expect(r.items[0].present).toBe(true);
expect(r.items[1].key).toBe("readme");
expect(r.items[1].present).toBe(false);
});
});
describe("community — route", () => {
it("GET /:o/:r/community on missing repo returns 404", async () => {
const res = await app.request("/alice/nope/community");
expect(res.status).toBe(404);
});
});
|