DevelopOther
@holtkeeper/coverage
The coverage analyzer and analysis kind: runs a checkout’s tests with coverage (or reads an existing report) and records line, function and branch coverage per source file, so coverage can be followed per folder and file across runs.
Public API
Section titled “Public API”coverageAnalyzer—Analyzer<CoverageData, CoverageOptions>, kindcoverage, scoperepo, needscheckout. Options (coverageOptionsSchema):file?: string(--file) — an lcov tracefile or Go cover profile in the checkout to read instead of running the tests, e.g. a report CI left behind.exclude: string[](--exclude, comma-separated) — glob patterns of files to leave out, e.g.src/generated/**.untested: boolean— default true: source files no test loaded count as fully uncovered.components: boolean— default false: component files (.tsx,.jsx) are left out, so components need no tests; turn it on per repository or group through theanalyzers.coveragesetting.install: boolean— default true: install JavaScript dependencies first whennode_modulesis missing (see below).installScripts: boolean(--install-scripts) — default false: let that install run lifecycle scripts, for projects whose tests needpostinstalloutput (Prisma clients, generated code).build: boolean— default true: build workspace packages whose entry files are missing before the tests (see below).goTags: string[](--go-tags, comma-separated) — default none: Go build tags (integration,e2e) of a secondgo testrun per module whose profile is added to the untagged run’s (a statement keeps its highest count). Set it per repository or group in theanalyzers.coveragesetting when tests sit behind//go:buildlines.goTestTimeout: string— default5m: Go’s-timeoutfor each test binary (a Go duration).target: number— default 60 (DEFAULT_COVERAGE_TARGET): line coverage, in percent, the repository should reach. It changes nothing in the run; stored metrics and repository health judge coverage by it. Set it per repository or group in theanalyzers.coveragesetting (coverageTargetSchemavalidates it: a number or numeric string from 0 to 100; null and empty strings fall back to 60).
coverageAnalysis— theAnalysisKind(schema: coverageDataSchema,summarize,metrics,toReport(current, previous));coverageReport(data, { previous?, ref?, compareTo?, generatedAt? })builds the report directly,coverageTree(files)the folder treemap,coverageTone(percent)the tone of a share.analyzeCoverage({ dir, runner, file?, collectors?, exclude?, untested?, install?, installScripts?, build?, go?, log?, signal? }): Promise<CoverageData>— installs, collects and normalizes.go({ tags?, testTimeout? }) configures the Go collector.collectorsreplaces the detected ones (anyCoverageCollectorfrom@holtkeeper/quality-tests).installDependencies({ dir, runner, scripts?, retryDelayMs?, signal? }): Promise<InstallOutcome>—skipped(with a reason),installedorfailed(with the last lines of output); a failure that looks like a network error (npm error network,ECONNRESET,ETIMEDOUT,EAI_AGAIN,ENOTFOUND, registry 5xx) is retried once afterretryDelayMs(5 s); never throws for a failed install.frozenInstallCommand(manager, scripts)is the command.buildWorkspaces({ dir, runner, signal? }): Promise<BuildOutcome>—skipped,builtorfailed(with the packages built before and the last lines of output); never throws for a failed build.unbuiltWorkspaces(dir)lists what it would build, in dependency order.- Helpers:
percentOf(counts),sumCounts(parts).
How coverage is collected
Section titled “How coverage is collected”The JavaScript steps below run only when the checkout has a root package.json, so a Go-only repository logs nothing about them. Jobs install tools but not a project’s dependencies, so first, unless install is off or file is given, installDependencies installs JavaScript dependencies when the checkout has a package.json and a root lockfile but no node_modules: npm ci, bun install --frozen-lockfile, pnpm install --frozen-lockfile, yarn install --immutable (berry) or yarn install --frozen-lockfile (classic), with --ignore-scripts (and npm_config_ignore_scripts/YARN_ENABLE_SCRIPTS) unless installScripts, CI=true, 10 minutes at most. The package manager comes from the lockfile and packageManager (detectPackageManager from @holtkeeper/vuln-js). A failed install is logged and does not stop the run; when no collector then produces a report, the error leads with the failed install (installing dependencies failed (npm ci ...): exit 1: npm error code E404 ..., the last lines of its output without npm’s log-file pointer) and lists the collectors’ errors after it, so a missing test runner (npx canceled due to missing packages) never reads as the cause. The install needs network to the registry: in container execution with the install network policy the job container has none, so set the toolchain setting’s network to full for those repositories. Private registries need credentials the job does not get: route jobs through an egress proxy that adds them (jobs.execution.egress, docker/egress-proxy). Python and other ecosystems are not installed; Go downloads modules itself.
Monorepo tests often import sibling workspace packages through their build output (main: lib/index.js), which a fresh checkout does not have. So next, unless build is off or file is given, buildWorkspaces finds the workspace packages (workspaces in package.json, plain or { packages }, and pnpm-workspace.yaml) whose main, module, types or typings file is missing and that have a build script, and runs <pm> run build in each, dependencies first, 10 minutes each at most. The first failing build stops the step and is logged; the tests run anyway.
Then the collectors of @holtkeeper/quality-tests: the primary framework of each language is detected and run with lcov or Go coverage through the CommandRunner (bun test, vitest, jest, c8 + mocha, node --test, pytest-cov, go test -coverprofile). Failing tests are fine as long as a report is written; collectors that fail are skipped, and the run fails only when none produced a report. Go runs go test -json -timeout=<goTestTimeout> -coverprofile once per module (go.mod files up to four folders deep, GOWORK=off) or once over the members of a root go.work, with GOTOOLCHAIN=local and, per module, GOFLAGS=-mod=mod. A module in which no package’s tests ran counts as failed rather than as a project without tests; packages that did not build, could not load their dependencies or timed out, and packages whose tests failed, are named in the job log, and their files get reason (below); a failed module never labels files of a nested module that ran on its own. Test files behind //go:build tags the run does not set are counted and logged with their tags (3 test file(s) need build tags ...: integration (3)); goTags runs them in a second pass.
Then, per file:
- Test files, configs, declarations and generated files by name, component files unless
components, paths outside the checkout andexcludematches are dropped. - Lines are
DArecords (Go: statements’ lines), functionsFN/FNDA(Go:go tool cover -func), branchesBRDAwith a taken count above zero. - With
untested, source files of the report’s languages that the report does not mention (and that are not generated or type-only) are added with every code line (non-blank, non-comment) uncovered andloaded: false. That count includes lines the tools would not call executable, such as imports, so it errs on the side of more uncovered lines. - Go files with no covered line in a package whose tests could not run get
reason:did not build,dependencies did not loadortests timed out, so the panel does not read them as files without tests.
Tests run once a week, in the default tests-weekly schedule (Wednesday nights, with testids).
interface CoverageData { tools: string[] // collectors that produced a report languages: string[] // js, go, python summary: { lines: Counts; functions?: Counts; branches?: Counts } // over every file below files: { file: string // relative to the checkout lines: Counts functions?: Counts branches?: Counts loaded?: false // no test loaded the file reason?: string // why its tests could not run: did not build, dependencies did not load, tests timed out }[]}interface Counts { covered: number total: number}Report
Section titled “Report”- Metrics — line, function and branch coverage (
percent,better: 'up', good from 80%, bad below 50%), source files, files without tests (better: 'down'). - By folder — treemap down to three levels, sized by lines to cover and colored by coverage.
- Changes (with a previous analysis) — files whose line coverage moved by 1% or more, new files counted from zero.
Metrics
Section titled “Metrics”coverageMetrics(data, { options?, previous? }) is the kind’s metrics, stored with every record as CoverageMetrics:
percent,functions,branches— shares over every file, rounded to 0.01; absent when there is nothing to cover.delta—percentminus the previous record’s, in percentage points; absent without both.target—options.target, or 60 when unset or invalid (coverageTargetOf(options)). Whetherpercentreaches it is judged where it is shown (repository health), not stored.files,untested— source files, and those no test loaded.tools— the tools that produced the record.totals—coverageTotals(data): covered and total lines, functions and branches, files, untested files and their lines.
tools and totals are what Quality › Coverage cards show, so the overview reads metrics only. Records written before they existed lack them; the server recomputes them from the newest record’s data until the next run replaces it.
Summaries
Section titled “Summaries”summary.ts holds the pure helpers Quality › Coverage and the report share:
coverageTotals(data)— lines, functions, branches, file count, files no test loaded and their lines.coverageGroupOf(file)/coverageGroups(files)— coverage per workspace package (packages/<name>,apps/<name>,libs/<name>, …) or top-level folder,ROOT_GROUP(.) for files in the root, most uncovered lines first.worstFiles(files, limit = 10)— files with the most uncovered lines.coverageChanges(data, previous, minPoints = 5)— files whose line coverage moved by at leastminPoints, largest move first; new files count from zero.changedFilesCoverage(data, previous)— line coverage of the files that are new or whose counts differ: the coverage of what changed between two records.
The web panel shows them in Quality › Coverage (/quality/coverage), one card per repository with a side sheet for the breakdown.