-
Notifications
You must be signed in to change notification settings - Fork 2.6k
chore(tooling): enforce honest coverage reporting #3154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
11bf26b
chore(tooling): enforce honest coverage reporting
cv 63e79d0
test(nim): isolate unified-memory GPU fixtures
cv 1682bd6
Merge remote-tracking branch 'origin/main' into chore/coverage-checks…
cv 803c4f4
merge(main): sync PR 3154
cv 38aebf5
merge(main): resync PR 3154
cv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,39 @@ | ||
| .PHONY: check lint format format-biome lint-ts format-ts check-installer-hash docs docs-strict docs-live docs-clean | ||
|
|
||
| check: | ||
| npx prek run --all-files | ||
| @echo "All checks passed." | ||
| npm run check | ||
|
|
||
| lint: check | ||
| lint: | ||
| npm run check | ||
|
|
||
| # Targeted subproject checks (not part of `make check` — use for focused runs). | ||
| lint-ts: | ||
| cd nemoclaw && npm run check | ||
| npm run lint:ts | ||
|
|
||
| format: format-biome | ||
| format: | ||
| npm run format | ||
|
|
||
| format-biome: | ||
| npx biome format --write . | ||
| npm run format | ||
|
|
||
| format-ts: | ||
| cd nemoclaw && npm run lint:fix && npm run format | ||
| npm run format:ts | ||
|
|
||
| # --- Integrity checks --- | ||
|
|
||
| check-installer-hash: | ||
| bash scripts/check-installer-hash.sh | ||
| npm run check:installer-hash | ||
|
|
||
| # --- Documentation --- | ||
|
|
||
| docs: | ||
| uv run --group docs sphinx-build -b html docs docs/_build/html | ||
| npm run docs | ||
|
|
||
| docs-strict: | ||
| uv run --group docs sphinx-build -W -b html docs docs/_build/html | ||
| npm run docs:strict | ||
|
|
||
| docs-live: | ||
| uv run --group docs sphinx-autobuild docs docs/_build/html --open-browser | ||
| npm run docs:live | ||
|
|
||
| docs-clean: | ||
| rm -rf docs/_build | ||
| npm run docs:clean |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "lines": 22, | ||
| "functions": 31.8, | ||
| "branches": 22, | ||
| "statements": 22 | ||
| "lines": 33.2, | ||
| "functions": 29.8, | ||
| "branches": 23.4, | ||
| "statements": 32.7 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| /** | ||
| * Guard source files against coverage tool exclusion directives. | ||
| * | ||
| * Coverage reports should reflect executable code honestly. If a path is only | ||
| * covered by subprocess integration tests, keep it visible in coverage and let | ||
| * the ratchet baseline account for that instead of hiding it from the report. | ||
| */ | ||
|
|
||
| import fs from "node:fs"; | ||
| import path from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); | ||
| const SCAN_ROOTS = ["bin", "src", "scripts", "test", "nemoclaw/src"]; | ||
| const SOURCE_EXTENSIONS = new Set([".cjs", ".js", ".mjs", ".ts", ".tsx"]); | ||
| const SKIP_DIRS = new Set([".git", "coverage", "dist", "node_modules"]); | ||
| const FORBIDDEN_DIRECTIVE = ["v8", "ignore"].join(" "); | ||
| const FORBIDDEN_DIRECTIVE_PATTERN = new RegExp( | ||
| String.raw`(?:\/\/|\/\*)\s*${FORBIDDEN_DIRECTIVE}\b`, | ||
| ); | ||
|
|
||
| export interface CoverageIgnoreViolation { | ||
| filePath: string; | ||
| line: number; | ||
| column: number; | ||
| text: string; | ||
| } | ||
|
|
||
| export function findCoverageIgnoreDirectives( | ||
| sourceText: string, | ||
| filePath: string, | ||
| ): CoverageIgnoreViolation[] { | ||
| const violations: CoverageIgnoreViolation[] = []; | ||
| for (const [index, lineText] of sourceText.split(/\r?\n/).entries()) { | ||
| const match = FORBIDDEN_DIRECTIVE_PATTERN.exec(lineText); | ||
| if (match) { | ||
| violations.push({ | ||
| filePath, | ||
| line: index + 1, | ||
| column: match.index + 1, | ||
| text: lineText.trim(), | ||
| }); | ||
| } | ||
| } | ||
| return violations; | ||
| } | ||
|
|
||
| export function checkFiles(filePaths: readonly string[]): CoverageIgnoreViolation[] { | ||
| return filePaths.flatMap((filePath) => { | ||
| const absolutePath = path.resolve(REPO_ROOT, filePath); | ||
| return findCoverageIgnoreDirectives( | ||
| fs.readFileSync(absolutePath, "utf-8"), | ||
| path.relative(REPO_ROOT, absolutePath), | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| export function formatViolations(violations: readonly CoverageIgnoreViolation[]): string { | ||
| const directive = FORBIDDEN_DIRECTIVE; | ||
| return [ | ||
| `Coverage exclusion directives are not allowed (${directive}).`, | ||
| "Keep code visible to coverage reports and ratchet the honest baseline instead.", | ||
| "", | ||
| ...violations.map( | ||
| (violation) => | ||
| `${violation.filePath}:${violation.line}:${violation.column} ${violation.text}`, | ||
| ), | ||
| ].join("\n"); | ||
| } | ||
|
|
||
| function sourceFiles(): string[] { | ||
| return SCAN_ROOTS.flatMap((root) => [...walkSourceFiles(path.join(REPO_ROOT, root))]).map( | ||
| (filePath) => path.relative(REPO_ROOT, filePath), | ||
| ); | ||
| } | ||
|
|
||
| function* walkSourceFiles(dir: string): Generator<string> { | ||
| if (!fs.existsSync(dir)) return; | ||
| for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { | ||
| const fullPath = path.join(dir, entry.name); | ||
| if (entry.isDirectory()) { | ||
| if (!SKIP_DIRS.has(entry.name)) yield* walkSourceFiles(fullPath); | ||
| continue; | ||
| } | ||
| if (entry.isFile() && SOURCE_EXTENSIONS.has(path.extname(entry.name))) { | ||
| yield fullPath; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function isScannedSourcePath(filePath: string): boolean { | ||
| return ( | ||
| filePath.length > 0 && | ||
| SCAN_ROOTS.some((root) => filePath === root || filePath.startsWith(`${root}/`)) && | ||
| SOURCE_EXTENSIONS.has(path.extname(filePath)) | ||
| ); | ||
| } | ||
|
|
||
| function normalizeCliPaths(args: readonly string[]): string[] { | ||
| return args | ||
| .filter((arg) => arg !== "--") | ||
| .map((arg) => path.relative(REPO_ROOT, path.resolve(arg))) | ||
| .filter(isScannedSourcePath); | ||
| } | ||
|
|
||
| function main(): void { | ||
| const cliPaths = normalizeCliPaths(process.argv.slice(2)); | ||
| const filePaths = cliPaths.length > 0 ? cliPaths : sourceFiles(); | ||
| const violations = checkFiles(filePaths); | ||
| if (violations.length > 0) { | ||
| console.error(formatViolations(violations)); | ||
| process.exitCode = 1; | ||
| } | ||
| } | ||
|
|
||
| if (fileURLToPath(import.meta.url) === path.resolve(process.argv[1] ?? "")) { | ||
| main(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| /** Runs local repository checks that are not first-class Biome rules. */ | ||
|
|
||
| import { spawnSync } from "node:child_process"; | ||
| import path from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| type CheckCommand = { | ||
| name: string; | ||
| command: string; | ||
| args: string[]; | ||
| }; | ||
|
|
||
| const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../.."); | ||
| const TSX = process.platform === "win32" ? "tsx.cmd" : "tsx"; | ||
| const CHECKS: readonly CheckCommand[] = [ | ||
| { | ||
| name: "direct-credential-env", | ||
| command: TSX, | ||
| args: ["scripts/checks/direct-credential-env.ts", "src/lib/onboard.ts"], | ||
| }, | ||
| { | ||
| name: "no-coverage-ignore", | ||
| command: TSX, | ||
| args: ["scripts/checks/no-coverage-ignore.ts"], | ||
| }, | ||
| { | ||
| name: "layer-import-boundaries", | ||
| command: TSX, | ||
| args: ["scripts/checks/layer-import-boundaries.ts"], | ||
| }, | ||
| ]; | ||
|
|
||
| function main(): void { | ||
| for (const check of CHECKS) { | ||
| const result = spawnSync(check.command, check.args, { | ||
| cwd: REPO_ROOT, | ||
| encoding: "utf-8", | ||
| stdio: "inherit", | ||
| }); | ||
| if (result.status !== 0) { | ||
| console.error(`Check failed: ${check.name}`); | ||
| process.exit(result.status ?? 1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.