Skip to content

Commit f04b0c2

Browse files
committed
fix(ci): surface mutation advisories
1 parent 931594e commit f04b0c2

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎scripts/stryker-diff.mjs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@ export function formatAnnotationCommand(annotation) {
454454
return `::warning file=${escapeWorkflowProperty(annotation.file)},line=${annotation.line},title=Mutation test advisory::${escapeWorkflowData(annotation.message)}`
455455
}
456456

457+
export function formatAdvisoryCommand(advisory) {
458+
return `::warning title=Mutation test advisory::${escapeWorkflowData(advisory)}`
459+
}
460+
457461
export function formatAnnotations(blockingMutants, packageRoot, state = { total: 0, perFile: new Map() }) {
458462
const annotations = []
459463

@@ -578,7 +582,7 @@ export function formatSummary(rows, advisories, manifest = {}) {
578582
"const result = condition ? value : fallback",
579583
"```",
580584
"",
581-
"Broad `all` exclusions and exclusions without a concrete reason are rejected by the gate.",
585+
"Broad `all` exclusions and exclusions without a concrete reason are reported as advisories.",
582586
)
583587
}
584588

@@ -622,6 +626,7 @@ export function formatSummary(rows, advisories, manifest = {}) {
622626
}
623627

624628
export function appendSummary(rows, advisories, manifest) {
629+
for (const advisory of advisories) console.warn(formatAdvisoryCommand(advisory))
625630
if (!process.env.GITHUB_STEP_SUMMARY) return
626631
try {
627632
fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, formatSummary(rows, advisories, manifest))

‎scripts/stryker-diff.test.mjs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
evaluateReport,
1717
executableChangedLines,
1818
formatAnnotations,
19+
formatAdvisoryCommand,
1920
formatAnnotationCommand,
2021
formatBlockingMutants,
2122
formatSummary,
@@ -569,6 +570,13 @@ describe("failure output", () => {
569570
)
570571
})
571572

573+
it("escapes aggregated advisory warnings", () => {
574+
assert.equal(
575+
formatAdvisoryCommand("preflight failed: 100%\nretry"),
576+
"::warning title=Mutation test advisory::preflight failed: 100%25%0Aretry",
577+
)
578+
})
579+
572580
it("reports a Stryker preflight launch error when the binary is missing", () => {
573581
const repo = fs.mkdtempSync(path.join(os.tmpdir(), "stryker-launch-"))
574582
const reportRoot = path.join(repo, "reports")
@@ -611,6 +619,23 @@ describe("failure output", () => {
611619
}
612620
})
613621

622+
it("emits aggregated warnings when the GitHub job summary is unavailable", () => {
623+
const previousSummary = process.env.GITHUB_STEP_SUMMARY
624+
const previousWarn = console.warn
625+
const warnings = []
626+
delete process.env.GITHUB_STEP_SUMMARY
627+
console.warn = (warning) => warnings.push(warning)
628+
629+
try {
630+
appendSummary([], ["manifest invalid\nreview it"], {})
631+
assert.deepEqual(warnings, ["::warning title=Mutation test advisory::manifest invalid%0Areview it"])
632+
} finally {
633+
if (previousSummary === undefined) delete process.env.GITHUB_STEP_SUMMARY
634+
else process.env.GITHUB_STEP_SUMMARY = previousSummary
635+
console.warn = previousWarn
636+
}
637+
})
638+
614639
it("uses the actual tests recorded by Stryker", () => {
615640
assert.deepEqual(
616641
testsFromMutationReport({ testFiles: { "src/value.test.ts": {}, "src/other.spec.ts": {} } }, [

0 commit comments

Comments
 (0)