Skip to content

Commit cc8ceaf

Browse files
authored
Merge branch 'Zoo-Code-Org:main' into bugfix_for_1240_505
2 parents dc2666d + ba46d1f commit cc8ceaf

15 files changed

Lines changed: 535 additions & 42 deletions

‎.coderabbit.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ reviews:
159159
mode: error
160160
custom_checks:
161161
- name: Regression evidence
162-
mode: error
162+
mode: warning
163163
instructions: >-
164164
Fail only when a concrete changed behavior lacks focused coverage at the lowest valid
165165
test layer, tests merely mirror implementation, an affected error/negative/unset branch
@@ -181,7 +181,7 @@ reviews:
181181
behavior is missing, or a persisted default is not propagated to a consumer. Cite the
182182
changed path and a plausible triggering scenario; pass when no such changed path exists.
183183
- name: Lifecycle resource cleanup
184-
mode: error
184+
mode: warning
185185
instructions: >-
186186
Fail only when a concrete changed lifecycle path can leak a listener, watcher, provider,
187187
timer, task, or other resource, or can duplicate work after cancellation, disposal, or

‎.github/workflows/code-qa.yml‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,20 @@ jobs:
150150
restore-keys: |
151151
${{ runner.os }}-turbo-${{ hashFiles('**/pnpm-lock.yaml') }}-
152152
${{ runner.os }}-turbo-
153-
- name: Run non-core coverage
154-
run: pnpm turbo run test:coverage --filter="!@roo-code/core" --log-order grouped --output-logs new-only
153+
- name: Run non-extension package coverage
154+
run: pnpm turbo run test:coverage --filter="!@roo-code/core" --filter="!zoo-code" --log-order grouped --output-logs new-only
155+
- name: Run extension unit coverage
156+
run: pnpm turbo run test:coverage:unit --filter="zoo-code" --log-order grouped --output-logs new-only
157+
- name: Verify extension coverage contract
158+
run: pnpm --dir src run verify:coverage-contract
159+
- name: Run extension dist smoke test
160+
run: pnpm turbo run test:dist --filter="zoo-code" --log-order grouped --output-logs new-only
155161
- name: Run core unit coverage
156162
run: pnpm turbo run test:coverage:unit --filter="@roo-code/core" --log-order grouped --output-logs new-only
157163
- name: Run core integration coverage
158164
run: pnpm turbo run test:coverage:integration --filter="@roo-code/core" --log-order grouped --output-logs new-only
165+
- name: Verify extension unit coverage report
166+
run: node src/scripts/verify-lcov.mjs src/coverage/unit/lcov.info
159167
- name: Save Turbo cache
160168
if: steps.turbo-cache.outputs.cache-hit != 'true'
161169
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
@@ -177,7 +185,7 @@ jobs:
177185
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
178186
with:
179187
files: >-
180-
src/coverage/lcov.info,
188+
src/coverage/unit/lcov.info,
181189
packages/cloud/coverage/lcov.info,
182190
packages/telemetry/coverage/lcov.info,
183191
apps/cli/coverage/lcov.info
@@ -214,7 +222,7 @@ jobs:
214222
with:
215223
name: coverage-reports-${{ matrix.name }}
216224
path: |
217-
src/coverage/lcov.info
225+
src/coverage/unit/lcov.info
218226
webview-ui/coverage/lcov.info
219227
packages/cloud/coverage/lcov.info
220228
packages/telemetry/coverage/lcov.info

‎.github/workflows/label-pr-review-state.yml‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ jobs:
8787
const codeRabbitLogin = 'coderabbitai[bot]';
8888
const codeRabbitLogins = new Set([codeRabbitLogin, 'coderabbitai']);
8989
const codeRabbitActiveLabel = 'coderabbit-review-active';
90+
const codeRabbitEligibleBotLogins = new Set(['zoomote[bot]']);
9091
const reviewGateName = 'Zoo Code / PR review gate';
9192
const reconciliationCheckName = 'Zoo Code / reconcile PR review state';
9293
@@ -660,6 +661,8 @@ jobs:
660661
review => review.state === 'CHANGES_REQUESTED'
661662
);
662663
const automatedAuthor = pr.user?.type === 'Bot';
664+
const codeRabbitEligibleAuthor = !automatedAuthor ||
665+
codeRabbitEligibleBotLogins.has(pr.user?.login.toLowerCase());
663666
const codeRabbitReviewComplete = freshCodeRabbitReview?.state === 'APPROVED';
664667
const codeRabbitChangesRequested = freshCodeRabbitReview?.state === 'CHANGES_REQUESTED';
665668
const maintainerApproval = freshMaintainerReviews
@@ -676,7 +679,7 @@ jobs:
676679
if (codeRabbitChangesRequested || maintainerChangeRequest) {
677680
desiredLabel = 'awaiting-author';
678681
phase = codeRabbitChangesRequested ? 'coderabbit-changes' : 'maintainer-changes';
679-
} else if (automatedAuthor) {
682+
} else if (!codeRabbitEligibleAuthor) {
680683
if (pr.draft) {
681684
desiredLabel = null;
682685
phase = 'draft';
@@ -736,7 +739,7 @@ jobs:
736739
737740
core.info(
738741
`PR #${pr.number}: CI passing, reviews=${latest.size}, ` +
739-
`coderabbit=${freshCodeRabbitReview?.state ?? (automatedAuthor ? 'optional' : 'pending')}, ` +
742+
`coderabbit=${freshCodeRabbitReview?.state ?? (codeRabbitEligibleAuthor ? 'pending' : 'optional')}, ` +
740743
`maintainer=${maintainerApproval?.state ?? 'pending'} → ${desiredLabel ?? '(none)'}`
741744
);
742745

‎scripts/stryker-diff.mjs‎

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -460,26 +460,36 @@ export function formatAdvisoryCommand(advisory) {
460460

461461
export function formatAnnotations(blockingMutants, packageRoot, state = { total: 0, perFile: new Map() }) {
462462
const annotations = []
463+
const mutantsByLocation = new Map()
463464

464-
for (const mutant of blockingMutants.sort((left, right) => {
465+
for (const mutant of [...blockingMutants].sort((left, right) => {
465466
const pathOrder = left.filePath.localeCompare(right.filePath)
466467
return pathOrder || left.location.start.line - right.location.start.line
467468
})) {
468469
const repositoryPath = path.posix.join(packageRoot, mutant.filePath.replaceAll("\\", "/"))
469470
const key = `${repositoryPath}:${mutant.location.start.line}`
471+
const group = mutantsByLocation.get(key) ?? { repositoryPath, mutants: [] }
472+
group.mutants.push(mutant)
473+
mutantsByLocation.set(key, group)
474+
}
475+
476+
for (const [key, { repositoryPath, mutants }] of mutantsByLocation) {
470477
const fileCount = state.perFile.get(repositoryPath) ?? 0
471-
if (annotations.some((annotation) => annotation.key === key) || fileCount >= 7 || state.total >= 20) continue
478+
if (fileCount >= 7 || state.total >= 20) continue
472479

480+
const mutant = mutants[0]
473481
const replacement = String(mutant.replacement ?? "")
474482
.replace(/\s+/g, " ")
475483
.trim()
476484
.slice(0, 160)
485+
const location = `${repositoryPath}:${mutant.location.start.line}`
486+
const detail = `${mutant.status} ${mutant.mutatorName} mutant${replacement ? ` (replacement: ${replacement})` : ""}`
477487
annotations.push({
478488
key,
479489
file: repositoryPath,
480490
line: mutant.location.start.line,
481491
message:
482-
`${mutant.status} ${mutant.mutatorName} mutant${replacement ? ` (replacement: ${replacement})` : ""}. ` +
492+
`${location}: ${mutants.length === 1 ? detail : `${mutants.length} mutation test gaps; example: ${detail}`}. ` +
483493
"See the job summary for the complete list and resolution guidance.",
484494
})
485495
state.perFile.set(repositoryPath, fileCount + 1)
@@ -652,16 +662,18 @@ export function evaluateReport(report, packageEntry) {
652662
"The result is inconclusive; consider fixing flaky or slow tests, or reducing the changed scope.",
653663
)
654664
}
655-
if (counts.blocking.length > 0) {
656-
advisories.push(
657-
`${packageEntry.id} has ${counts.survived} surviving and ${counts.noCoverage} uncovered changed-code mutants. ` +
658-
"Consider adding or strengthening focused tests.",
659-
)
660-
}
661665
return { ...counts, advisories }
662666
}
663667

664-
export function runManifest(repoRoot, manifest, reportRoot) {
668+
export function runManifest(
669+
repoRoot,
670+
manifest,
671+
reportRoot,
672+
{
673+
runMutation = runStryker,
674+
readMutationReport = (reportPath) => JSON.parse(fs.readFileSync(reportPath, "utf8")),
675+
} = {},
676+
) {
665677
const rows = []
666678
const advisories = [...(manifest.advisories ?? [])]
667679
const annotationState = { total: 0, perFile: new Map() }
@@ -677,7 +689,7 @@ export function runManifest(repoRoot, manifest, reportRoot) {
677689
if (packageEntry.discoverRelatedTests) {
678690
packageEntry.testFiles = discoverRelatedTestFiles(repoRoot, packageEntry, reportDirectory)
679691
}
680-
const preflightOutput = stripAnsi(runStryker(repoRoot, packageEntry, reportRoot, true))
692+
const preflightOutput = stripAnsi(runMutation(repoRoot, packageEntry, reportRoot, true))
681693
const mutantMatch = /Instrumented \d+ source file\(s\) with (\d+) mutant\(s\)/.exec(preflightOutput)
682694
if (!mutantMatch) throw new Error(`${packageEntry.id} preflight did not report a mutant count`)
683695
const generatedMutants = Number(mutantMatch[1])
@@ -707,9 +719,9 @@ export function runManifest(repoRoot, manifest, reportRoot) {
707719
continue
708720
}
709721

710-
runStryker(repoRoot, packageEntry, reportRoot, false)
722+
runMutation(repoRoot, packageEntry, reportRoot, false)
711723
const jsonReportPath = path.join(reportRoot, packageEntry.id, "mutation.json")
712-
const report = JSON.parse(fs.readFileSync(jsonReportPath, "utf8"))
724+
const report = readMutationReport(jsonReportPath)
713725
packageEntry.testFiles = testsFromMutationReport(report, packageEntry.testFiles)
714726
counts = evaluateReport(report, packageEntry)
715727
for (const annotation of formatAnnotations(
@@ -729,7 +741,7 @@ export function runManifest(repoRoot, manifest, reportRoot) {
729741
reportPath,
730742
changedLines: packageEntry.changedExecutableLines,
731743
...counts,
732-
result: counts.advisories.length > 0 ? "Advisory findings" : "Passed",
744+
result: counts.blocking.length > 0 || counts.advisories.length > 0 ? "Advisory findings" : "Passed",
733745
})
734746
} catch (error) {
735747
advisories.push(error.message)

‎scripts/stryker-diff.test.mjs‎

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,43 @@ describe("failure output", () => {
529529
for (const mutant of manyMutants) assert.ok(grouped.includes(mutant.mutatorName))
530530
})
531531

532+
it("emits one distinguishable annotation per source location", () => {
533+
const mutants = [
534+
blocking[2],
535+
blocking[1],
536+
{
537+
filePath: "utils/other.ts",
538+
status: "NoCoverage",
539+
mutatorName: "ConditionalExpression",
540+
replacement: "true",
541+
location: { start: { line: 9 } },
542+
},
543+
blocking[0],
544+
]
545+
const originalOrder = [...mutants]
546+
const annotations = formatAnnotations(mutants, "src")
547+
548+
assert.equal(annotations.length, 2)
549+
assert.deepEqual(mutants, originalOrder)
550+
assert.match(
551+
annotations[0].message,
552+
/^src\/core\/value\.ts:4: 2 mutation test gaps; example: NoCoverage StringLiteral mutant \(replacement: "left \| right"\)/,
553+
)
554+
assert.match(
555+
annotations[1].message,
556+
/^src\/utils\/other\.ts:9: 2 mutation test gaps; example: Survived BooleanLiteral mutant \(replacement: false\)/,
557+
)
558+
})
559+
560+
it("prefixes singleton annotations with their source location", () => {
561+
const [annotation] = formatAnnotations([blocking[2]], "src")
562+
563+
assert.equal(
564+
annotation.message,
565+
"src/utils/other.ts:9: Survived BooleanLiteral mutant (replacement: false). See the job summary for the complete list and resolution guidance.",
566+
)
567+
})
568+
532569
it("shares annotation limits across packages", () => {
533570
const state = { total: 0, perFile: new Map() }
534571
const first = formatAnnotations(
@@ -605,6 +642,50 @@ describe("failure output", () => {
605642
}
606643
})
607644

645+
it("classifies successful package rows from blocking mutants", () => {
646+
const repo = fs.mkdtempSync(path.join(os.tmpdir(), "stryker-success-"))
647+
const packageEntry = {
648+
id: "core",
649+
root: "packages/core",
650+
vitestConfig: "vitest.unit.config.ts",
651+
selectors: ["src/value.ts:1-1"],
652+
changedExecutableLines: 1,
653+
}
654+
const execute = (report) =>
655+
runManifest(repo, { packages: [{ ...packageEntry }] }, path.join(repo, "reports"), {
656+
runMutation: (_repoRoot, _entry, _reportRoot, dryRunOnly) =>
657+
dryRunOnly ? "Instrumented 1 source file(s) with 1 mutant(s)" : "",
658+
readMutationReport: () => report,
659+
})[0]
660+
661+
try {
662+
const advisoryRow = execute({
663+
files: {
664+
"src/value.ts": {
665+
mutants: [
666+
{
667+
status: "Survived",
668+
mutatorName: "BooleanLiteral",
669+
replacement: "false",
670+
location: { start: { line: 1 } },
671+
},
672+
],
673+
},
674+
},
675+
})
676+
assert.equal(advisoryRow.result, "Advisory findings")
677+
assert.deepEqual(advisoryRow.advisories, [])
678+
679+
const passedRow = execute({
680+
files: { "src/value.ts": { mutants: [{ status: "Killed", location: { start: { line: 1 } } }] } },
681+
})
682+
assert.equal(passedRow.result, "Passed")
683+
assert.deepEqual(passedRow.advisories, [])
684+
} finally {
685+
fs.rmSync(repo, { recursive: true, force: true })
686+
}
687+
})
688+
608689
it("does not fail when the GitHub job summary cannot be written", () => {
609690
const previousSummary = process.env.GITHUB_STEP_SUMMARY
610691
const summaryDirectory = fs.mkdtempSync(path.join(os.tmpdir(), "stryker-summary-"))
@@ -681,7 +762,7 @@ describe("failure output", () => {
681762
describe("report evaluation", () => {
682763
const packageEntry = { id: "core", root: "packages/core" }
683764

684-
it("reports surviving and uncovered changed-code mutants as advisory", () => {
765+
it("reports surviving and uncovered mutants through detailed annotations without a redundant aggregate", () => {
685766
const report = {
686767
files: {
687768
"src/value.ts": {
@@ -704,7 +785,7 @@ describe("report evaluation", () => {
704785
}
705786

706787
const result = evaluateReport(report, packageEntry)
707-
assert.match(result.advisories.join("\n"), /1 surviving and 1 uncovered/)
788+
assert.deepEqual(result.advisories, [])
708789
assert.equal(formatAnnotations(mutantCounts(report).blocking, packageEntry.root).length, 2)
709790
})
710791

‎src/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@
442442
"lint": "eslint . --ext=ts --max-warnings=0",
443443
"check-types": "tsc --noEmit",
444444
"test": "vitest run",
445+
"verify:coverage-contract": "node scripts/verify-coverage-contract.mjs",
445446
"test:unit": "vitest run --config vitest.unit.config.ts",
446447
"test:dist": "vitest run --config vitest.dist.config.ts",
447448
"test:coverage": "vitest run --coverage",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { spawnSync } from "node:child_process"
2+
import process from "node:process"
3+
4+
const pnpm = process.platform === "win32" ? process.env.npm_execpath : "pnpm"
5+
if (!pnpm) throw new Error("pnpm executable path is unavailable")
6+
const command = process.platform === "win32" ? process.execPath : pnpm
7+
const args = process.platform === "win32" ? [pnpm] : []
8+
const result = spawnSync(
9+
command,
10+
[...args, "turbo", "run", "test:coverage:unit", "test:dist", "--filter=zoo-code", "--dry=json"],
11+
{ encoding: "utf8" },
12+
)
13+
if (result.status !== 0) {
14+
const details = [result.error?.message, result.signal, result.stderr, result.stdout].filter(Boolean).join("\n")
15+
throw new Error(details || `pnpm exited with status ${result.status ?? "unknown"}`)
16+
}
17+
18+
const graph = JSON.parse(result.stdout)
19+
const coverageTask = graph.tasks.find(({ taskId }) => taskId === "zoo-code#test:coverage:unit")
20+
const distTask = graph.tasks.find(({ taskId }) => taskId === "zoo-code#test:dist")
21+
if (!coverageTask) throw new Error("Unit coverage task missing")
22+
if (graph.tasks.some(({ taskId }) => taskId === "zoo-code#prepare:tree-sitter-wasms"))
23+
throw new Error("Removed WASM preparation task remains in the graph")
24+
if (coverageTask.dependencies.includes("zoo-code#bundle")) throw new Error("Unit coverage must not depend on bundle")
25+
if (!coverageTask.dependencies.includes("@roo-code/types#build"))
26+
throw new Error("Unit coverage must depend on the types build")
27+
if (!Object.hasOwn(coverageTask.inputs, "package.json")) throw new Error("Unit coverage must hash package.json")
28+
if (!coverageTask.hashOfExternalDependencies) throw new Error("Unit coverage must hash external dependencies")
29+
if (!distTask?.dependencies.includes("zoo-code#bundle")) throw new Error("Dist smoke test must depend on bundle")

‎src/scripts/verify-lcov.mjs‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import fs from "node:fs"
2+
import process from "node:process"
3+
import { fileURLToPath } from "node:url"
4+
5+
export function verifyLcov(content) {
6+
let inRecord = false
7+
let anyCovered = false
8+
let linesFound
9+
let linesHit
10+
11+
for (const line of content.split(/\r?\n/)) {
12+
if (line.startsWith("SF:")) {
13+
if (inRecord) throw new Error("LCOV source record is not terminated")
14+
if (!line.slice(3)) throw new Error("LCOV source path is empty")
15+
inRecord = true
16+
linesFound = undefined
17+
linesHit = undefined
18+
} else if (line.startsWith("LF:")) {
19+
if (!inRecord) throw new Error("LCOV line count is outside a source record")
20+
if (linesFound !== undefined) throw new Error("LCOV source record has duplicate line counts")
21+
const found = line.slice(3)
22+
if (!/^\d+$/.test(found)) throw new Error("LCOV line count is not a decimal integer")
23+
linesFound = BigInt(found)
24+
} else if (line.startsWith("LH:")) {
25+
if (!inRecord) throw new Error("LCOV hit count is outside a source record")
26+
if (linesHit !== undefined) throw new Error("LCOV source record has duplicate hit counts")
27+
const hits = line.slice(3)
28+
if (!/^\d+$/.test(hits)) throw new Error("LCOV hit count is not a decimal integer")
29+
linesHit = BigInt(hits)
30+
} else if (line === "end_of_record") {
31+
if (!inRecord) throw new Error("LCOV terminator is outside a source record")
32+
if (linesFound === undefined || linesHit === undefined)
33+
throw new Error("LCOV source record has incomplete line summaries")
34+
if (linesHit > linesFound) throw new Error("LCOV hit count exceeds lines found")
35+
if (linesHit > 0n) anyCovered = true
36+
inRecord = false
37+
}
38+
}
39+
40+
if (inRecord) throw new Error("LCOV source record is not terminated")
41+
if (!anyCovered) throw new Error("LCOV report has no covered lines")
42+
}
43+
44+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
45+
verifyLcov(fs.readFileSync(process.argv[2], "utf8"))
46+
}

0 commit comments

Comments
 (0)