程序员阿江(Relakkes) 9719726cd2 feat: make quality gates observable and enforceable
The repository now has a measurable PR quality path instead of a loose set of
manual checks. Coverage, quarantine governance, provider smoke, desktop smoke,
and workflow wiring all produce durable reports that contributors and maintainers
can inspect without reconstructing terminal output.

This also fixes the desktop smoke current-runtime path so browser-driven smoke
runs use the desktop default active provider instead of forcing the official
current model, and records that runtime decision as an artifact.

Constraint: Default PR gates must remain non-live and contributor-safe while live model checks stay explicit.
Constraint: Release packaging is still GitHub Actions based, so release preflight must run before the build matrix.
Rejected: Make live provider or desktop smoke mandatory on every PR | secrets, quotas, and model availability are maintainer-controlled.
Rejected: Let PRs lower coverage baselines in the same change | base-branch ratchet comparison must remain authoritative.
Confidence: high
Scope-risk: moderate
Directive: Do not relax coverage or quarantine policy without a maintainer approval label and a fresh quality report.
Tested: ALLOW_CLI_CORE_CHANGE=1 ALLOW_COVERAGE_BASELINE_CHANGE=1 bun run quality:gate --mode pr
Tested: bun run quality:gate --mode baseline --allow-live --only provider-smoke:* --provider-model nvidia-custom:main:nvidia-custom-main --artifacts-dir /tmp/quality-gate-live-smoke
Tested: bun run quality:gate --mode baseline --allow-live --only desktop-smoke:* --provider-model current:current:current-runtime --artifacts-dir /tmp/quality-gate-desktop-smoke-fixed
Tested: git diff --check
Not-tested: Full live release mode with multiple providers in hosted CI; provider credentials and quota remain maintainer-controlled.
2026-05-06 16:25:10 +08:00

90 lines
2.8 KiB
TypeScript

#!/usr/bin/env bun
import { runQualityGate } from './runner'
import { formatProviderTargets, loadProviderIndex, parseBaselineTargetValues } from './providerTargets'
import type { BaselineTarget, QualityGateMode } from './types'
function parseArgs(argv: string[]) {
const args = new Map<string, Array<string | boolean>>()
for (let index = 0; index < argv.length; index += 1) {
const arg = argv[index]
if (!arg.startsWith('--')) {
continue
}
const next = argv[index + 1]
if (next && !next.startsWith('--')) {
args.set(arg, [...(args.get(arg) ?? []), next])
index += 1
} else {
args.set(arg, [...(args.get(arg) ?? []), true])
}
}
return args
}
function firstArg(args: Map<string, Array<string | boolean>>, name: string) {
return args.get(name)?.[0]
}
function hasFlag(args: Map<string, Array<string | boolean>>, name: string) {
return args.has(name)
}
function readMode(value: string | boolean | undefined): QualityGateMode {
if (value === 'pr' || value === 'baseline' || value === 'release') {
return value
}
throw new Error('Usage: bun run quality:gate --mode <pr|baseline|release> [--dry-run] [--allow-live] [--provider-model provider:model[:label]] [--only lane-id|prefix*] [--skip lane-id|prefix*]')
}
function readBaselineTargets(args: Map<string, Array<string | boolean>>): BaselineTarget[] {
const values = (args.get('--provider-model') ?? [])
.filter((value): value is string => typeof value === 'string')
return parseBaselineTargetValues(values)
}
function readStringValues(args: Map<string, Array<string | boolean>>, name: string) {
return (args.get(name) ?? [])
.filter((value): value is string => typeof value === 'string')
.flatMap((value) => value.split(','))
.map((value) => value.trim())
.filter(Boolean)
}
const args = parseArgs(process.argv.slice(2))
if (hasFlag(args, '--list-providers')) {
console.log(formatProviderTargets(loadProviderIndex()))
process.exit(0)
}
const mode = readMode(firstArg(args, '--mode'))
const dryRun = hasFlag(args, '--dry-run')
const allowLive = hasFlag(args, '--allow-live')
const artifactsDir = typeof firstArg(args, '--artifacts-dir') === 'string'
? String(firstArg(args, '--artifacts-dir'))
: undefined
const baselineTargets = readBaselineTargets(args)
const { report, outputDir } = await runQualityGate({
mode,
dryRun,
allowLive,
baselineTargets,
rootDir: process.cwd(),
artifactsDir,
onlyLaneSelectors: readStringValues(args, '--only'),
skipLaneSelectors: readStringValues(args, '--skip'),
})
console.log(`Quality gate report: ${outputDir}/report.md`)
console.log(`Summary: passed=${report.summary.passed} failed=${report.summary.failed} skipped=${report.summary.skipped}`)
if (report.summary.failed > 0) {
process.exit(1)
}