Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion scripts/governance-badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@
);
}

// LEGACY_LABELS - labels an earlier renderer wrote for a lane, per current label.
// A file on the badges branch carrying one of these (and otherwise a valid
// shield badge) is a known predecessor of this lane's badge, so it is
// migrated (replaced with the canonical badge) rather than refused as foreign.
// Any other label stays a refusal. The old K9 lane was labelled "k9-deed L0" + U+2013 + "L2".
const LEGACY_LABELS = Object.freeze({
K9: Object.freeze(["k9-deed L0\u2013L2"]),
});

// inspectBadge - is this text a shield-endpoint object?
//
// pairing: "strict" message must be one of STATE_TABLE's, with exactly the
Expand Down Expand Up @@ -158,7 +167,13 @@
if (badge.schemaVersion !== 1) {
errors.push(`schemaVersion is ${JSON.stringify(badge.schemaVersion)}, expected 1`);
}
if (label !== undefined && badge.label !== label) {
// Own properties only: a label such as "constructor" or "toString" is a valid
// label, and a bare lookup would return the inherited built-in, not an array.
const legacyLabels = label !== undefined && Object.prototype.hasOwnProperty.call(LEGACY_LABELS, label)

Check warning on line 172 in scripts/governance-badge.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'Object.hasOwn()' instead of 'Object.prototype.hasOwnProperty.call()'.

See more on https://sonarcloud.io/project/issues?id=hyperpolymath_Apodeixis.jl&issues=AaHbkm4UUPDpoJKGC8Lj&open=AaHbkm4UUPDpoJKGC8Lj&pullRequest=35
? LEGACY_LABELS[label]
: [];
const legacy = pairing === "loose" && label !== undefined && legacyLabels.includes(badge.label);
if (label !== undefined && badge.label !== label && !legacy) {
errors.push(`label is ${JSON.stringify(badge.label)}, expected ${JSON.stringify(label)}`);
}
if (typeof badge.message !== "string" || badge.message.length === 0) {
Expand Down
29 changes: 29 additions & 0 deletions tests/workflows/governance_badge_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@
["missing final newline", SUCCESS_BADGE.trimEnd(), "success", SUCCESS_BADGE],
["legacy red skipped badge", '{"schemaVersion":1,"label":"K9","message":"skipped","color":"red"}\n', "skipped", SKIPPED_BADGE],
["legacy unrecognised message", '{"schemaVersion":1,"label":"K9","message":"pending","color":"blue"}\n', "success", SUCCESS_BADGE],
["legacy K9 label (k9-deed L0\u2013L2), as published by the earlier renderer", '{"schemaVersion":1,"label":"k9-deed L0\u2013L2","message":"passing","color":"brightgreen"}\n', "success", SUCCESS_BADGE],
]) {
await testWithApi(`existing ${name} is updated to canonical bytes`, {
branchExists: true, fileBytes: bytes,
Expand Down Expand Up @@ -772,6 +773,9 @@
["JSON array", "[]\n"],
["missing schemaVersion", '{"label":"K9","message":"failure","color":"red"}\n'],
["null message", '{"schemaVersion":1,"label":"K9","message":null,"color":"red"}\n'],
["a foreign label that is not a K9 predecessor", '{"schemaVersion":1,"label":"coverage","message":"success","color":"brightgreen"}\n'],
["the legacy K9 label with a missing message", '{"schemaVersion":1,"label":"k9-deed L0\u2013L2","color":"red"}\n'],
["the legacy K9 label with the wrong schemaVersion", '{"schemaVersion":2,"label":"k9-deed L0\u2013L2","message":"passing","color":"brightgreen"}\n'],
...INVALID_BADGES,
]) {
const api = createApi({ branchExists: true, fileBytes: text });
Expand All @@ -791,9 +795,34 @@
equal(api.writes().length, 0, "malformed existing content must not be overwritten");
check(/refused/i.test(out.stderr), `stderr must say refused: ${out.stderr}`);
});
await api.close();

Check warning on line 798 in tests/workflows/governance_badge_test.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected `await` inside a loop.

See more on https://sonarcloud.io/project/issues?id=hyperpolymath_Apodeixis.jl&issues=AaHbkm77UPDpoJKGC8Lk&open=AaHbkm77UPDpoJKGC8Lk&pullRequest=35
}

// A label inherited from Object.prototype is still a valid label. With an
// existing foreign file the legacy lookup must fall back to "no legacy
// labels" and refuse cleanly, not throw a TypeError.
for (const inherited of ["constructor", "toString", "hasOwnProperty"]) {
const api = createApi({ branchExists: true, fileBytes: '{"schemaVersion":1,"label":"coverage","message":"success","color":"brightgreen"}\n' });
const url = await api.listen();

Check warning on line 806 in tests/workflows/governance_badge_test.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected `await` inside a loop.

See more on https://sonarcloud.io/project/issues?id=hyperpolymath_Apodeixis.jl&issues=AaHbkm77UPDpoJKGC8Ll&open=AaHbkm77UPDpoJKGC8Ll&pullRequest=35
await test(`label "${inherited}" over an existing foreign file is refused, not a crash`, async () => {
const out = await runAsync([
"publish",
"--label", inherited,
"--lane-result", "failure",
"--artifact", failureArtifact,
"--branch", BRANCH,
"--path", DEST,
"--repo", "example/template",
"--api-url", url,
]);
equal(out.code, 1, `expected exit 1, got ${out.code}: ${out.stderr}`);
check(!/TypeError/.test(out.stderr), `must not crash with a TypeError: ${out.stderr}`);
check(/refused/i.test(out.stderr), `stderr must say refused: ${out.stderr}`);
equal(api.writes().length, 0, "a foreign file must not be overwritten");
});

Check warning on line 822 in tests/workflows/governance_badge_test.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unexpected `await` inside a loop.

See more on https://sonarcloud.io/project/issues?id=hyperpolymath_Apodeixis.jl&issues=AaHbkm77UPDpoJKGC8Lm&open=AaHbkm77UPDpoJKGC8Lm&pullRequest=35
await api.close();
}

// ---------------------------------------------------------------- 7
section("7. Missing is not the same as broken");

Expand Down
Loading