mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-16 13:03:31 +08:00
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.
117 lines
4.3 KiB
TypeScript
117 lines
4.3 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
import { evaluateChangePolicy } from './change-policy'
|
|
|
|
describe('evaluateChangePolicy', () => {
|
|
test('blocks CLI core changes without an override label', () => {
|
|
const result = evaluateChangePolicy([
|
|
'src/commands/help.ts',
|
|
'desktop/src/pages/Settings.tsx',
|
|
])
|
|
|
|
expect(result.blocked).toBe(true)
|
|
expect(result.areas).toContain('cli-core')
|
|
expect(result.areas).toContain('desktop')
|
|
expect(result.areaLabels).toContain('area:cli-core')
|
|
expect(result.areaLabels).toContain('area:desktop')
|
|
expect(result.cliCoreFiles).toEqual(['src/commands/help.ts'])
|
|
})
|
|
|
|
test('allows CLI core changes with a maintainer override label', () => {
|
|
const result = evaluateChangePolicy(
|
|
['src/tools/WebSearchTool/backend.ts'],
|
|
['allow-cli-core-change', 'allow-missing-tests'],
|
|
)
|
|
|
|
expect(result.blocked).toBe(false)
|
|
expect(result.areas).toEqual(['cli-core'])
|
|
expect(result.checks.server).toBe(true)
|
|
})
|
|
|
|
test('keeps docs-only changes on the docs lane', () => {
|
|
const result = evaluateChangePolicy([
|
|
'docs/index.md',
|
|
'README.md',
|
|
])
|
|
|
|
expect(result.blocked).toBe(false)
|
|
expect(result.areas).toEqual(['docs'])
|
|
expect(result.checks.docs).toBe(true)
|
|
expect(result.checks.coverage).toBe(false)
|
|
expect(result.checks.desktop).toBe(false)
|
|
expect(result.checks.desktopNative).toBe(false)
|
|
})
|
|
|
|
test('routes desktop and server changes to desktop and native checks', () => {
|
|
const result = evaluateChangePolicy([
|
|
'desktop/src/pages/Settings.tsx',
|
|
'src/server/ws/handler.ts',
|
|
])
|
|
|
|
expect(result.areas).toEqual(['desktop', 'server'])
|
|
expect(result.checks.desktop).toBe(true)
|
|
expect(result.checks.server).toBe(true)
|
|
expect(result.checks.desktopNative).toBe(true)
|
|
expect(result.checks.coverage).toBe(true)
|
|
expect(result.missingTestSignals).toContain('Desktop product files changed without a desktop test file in the PR.')
|
|
expect(result.missingTestSignals).toContain('Server product files changed without a server test file in the PR.')
|
|
})
|
|
|
|
test('routes adapter changes to adapter and native checks', () => {
|
|
const result = evaluateChangePolicy(['adapters/telegram/index.ts'])
|
|
|
|
expect(result.areas).toEqual(['adapters'])
|
|
expect(result.checks.adapters).toBe(true)
|
|
expect(result.checks.desktopNative).toBe(true)
|
|
expect(result.checks.coverage).toBe(true)
|
|
expect(result.blocked).toBe(true)
|
|
expect(result.missingTestSignals).toEqual(['Adapter product files changed without an adapter test file in the PR.'])
|
|
})
|
|
|
|
test('allows production changes when matching tests are included', () => {
|
|
const result = evaluateChangePolicy([
|
|
'desktop/src/pages/Settings.tsx',
|
|
'desktop/src/pages/Settings.test.tsx',
|
|
])
|
|
|
|
expect(result.blocked).toBe(false)
|
|
expect(result.missingTestSignals).toEqual([])
|
|
})
|
|
|
|
test('blocks coverage baseline and threshold changes without maintainer override', () => {
|
|
const result = evaluateChangePolicy([
|
|
'scripts/quality-gate/coverage-baseline.json',
|
|
'scripts/quality-gate/coverage-thresholds.json',
|
|
])
|
|
|
|
expect(result.blocked).toBe(true)
|
|
expect(result.coveragePolicyFiles).toEqual([
|
|
'scripts/quality-gate/coverage-baseline.json',
|
|
'scripts/quality-gate/coverage-thresholds.json',
|
|
])
|
|
expect(result.blockingReasons).toContain('Coverage baseline or threshold changes require the allow-coverage-baseline-change label and maintainer approval.')
|
|
})
|
|
|
|
test('allows coverage baseline changes with maintainer override', () => {
|
|
const result = evaluateChangePolicy(
|
|
['scripts/quality-gate/coverage-baseline.json'],
|
|
['allow-coverage-baseline-change'],
|
|
)
|
|
|
|
expect(result.blocked).toBe(false)
|
|
})
|
|
|
|
test('normalizes relative and windows-style paths before classification', () => {
|
|
const result = evaluateChangePolicy([
|
|
'./desktop\\src\\pages\\Settings.tsx',
|
|
'./desktop\\src\\pages\\Settings.test.tsx',
|
|
'./scripts\\quality-gate\\coverage.ts',
|
|
])
|
|
|
|
expect(result.files).toContain('desktop/src/pages/Settings.tsx')
|
|
expect(result.files).toContain('scripts/quality-gate/coverage.ts')
|
|
expect(result.areas).toContain('desktop')
|
|
expect(result.checks.coverage).toBe(true)
|
|
expect(result.blocked).toBe(false)
|
|
})
|
|
})
|