Skip to content

Commit 291964e

Browse files
committed
fix(ci): preserve mutation annotation punctuation
1 parent f04839a commit 291964e

2 files changed

Lines changed: 25 additions & 10 deletions

File tree

scripts/stryker-diff.mjs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,16 @@ export function mutantCounts(report) {
422422
return counts
423423
}
424424

425-
function escapeWorkflowValue(value) {
426-
return String(value)
427-
.replaceAll("%", "%25")
428-
.replaceAll("\r", "%0D")
429-
.replaceAll("\n", "%0A")
430-
.replaceAll(":", "%3A")
431-
.replaceAll(",", "%2C")
425+
function escapeWorkflowData(value) {
426+
return String(value).replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A")
427+
}
428+
429+
function escapeWorkflowProperty(value) {
430+
return escapeWorkflowData(value).replaceAll(":", "%3A").replaceAll(",", "%2C")
431+
}
432+
433+
export function formatAnnotationCommand(annotation) {
434+
return `::error file=${escapeWorkflowProperty(annotation.file)},line=${annotation.line},title=Mutation test gap::${escapeWorkflowData(annotation.message)}`
432435
}
433436

434437
export function formatAnnotations(blockingMutants, packageRoot, state = { total: 0, perFile: new Map() }) {
@@ -682,9 +685,7 @@ export function runManifest(repoRoot, manifest, reportRoot) {
682685
packageEntry.runRoot ?? packageEntry.root,
683686
annotationState,
684687
)) {
685-
console.log(
686-
`::error file=${escapeWorkflowValue(annotation.file)},line=${annotation.line},title=Mutation test gap::${escapeWorkflowValue(annotation.message)}`,
687-
)
688+
console.log(formatAnnotationCommand(annotation))
688689
}
689690
evaluateReport(report, packageEntry)
690691
rows.push({

scripts/stryker-diff.test.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
evaluateReport,
1616
executableChangedLines,
1717
formatAnnotations,
18+
formatAnnotationCommand,
1819
formatBlockingMutants,
1920
formatSummary,
2021
mutantCounts,
@@ -432,6 +433,19 @@ describe("failure output", () => {
432433
assert.equal(state.total, 20)
433434
})
434435

436+
it("preserves punctuation in annotation messages while escaping properties", () => {
437+
const command = formatAnnotationCommand({
438+
file: "src/value:one,two.ts",
439+
line: 4,
440+
message: "Survived mutant (replacement: left, right). 100% reproducible.",
441+
})
442+
443+
assert.equal(
444+
command,
445+
"::error file=src/value%3Aone%2Ctwo.ts,line=4,title=Mutation test gap::Survived mutant (replacement: left, right). 100%25 reproducible.",
446+
)
447+
})
448+
435449
it("uses the actual tests recorded by Stryker", () => {
436450
assert.deepEqual(
437451
testsFromMutationReport({ testFiles: { "src/value.test.ts": {}, "src/other.spec.ts": {} } }, [

0 commit comments

Comments
 (0)