mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-15 12:53:31 +08:00
Contributors and coding agents need one local command that both reports and enforces the quality contract. This change turns the PR gate into the shared verification entrypoint, adds path-selected local lanes, tightens coverage accounting around changed lines, and documents the repair loop in contributor and agent-facing guidance. Constraint: Ordinary PR verification must stay non-live and runnable without provider credentials Constraint: Coverage policy updates in this commit require maintainer approval before push/merge Rejected: Keep quality guidance only in docs | agents need executable scripts and AGENTS.md instructions to follow the loop consistently Confidence: high Scope-risk: broad Directive: Do not bypass `bun run verify` for production changes; fix failed lanes and coverage reports instead of lowering thresholds Tested: bun run check:policy Tested: ALLOW_CLI_CORE_CHANGE=1 ALLOW_COVERAGE_BASELINE_CHANGE=1 bun run verify Not-tested: live provider baseline; no provider credentials were required for this non-live PR gate
59 lines
3.1 KiB
TypeScript
59 lines
3.1 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
describe('feature quality contract', () => {
|
|
test('keeps the agent-facing implementation contract explicit', () => {
|
|
const agents = readFileSync('AGENTS.md', 'utf8')
|
|
|
|
expect(agents).toContain('## Feature Quality Contract')
|
|
expect(agents).toContain('Production code changes under `desktop/src`, `src/server`, `src/tools`, `src/utils`, or `adapters` must include a same-area test file')
|
|
expect(agents).toContain('Coverage is part of the feature, not an afterthought.')
|
|
expect(agents).toContain('changed executable production line must meet the changed-line coverage gate')
|
|
expect(agents).toContain('E2E is required when the feature crosses process boundaries')
|
|
expect(agents).toContain('AI agents must include this evidence')
|
|
expect(agents).toContain('Unified local entrypoint: `bun run verify`')
|
|
expect(agents).toContain('If `bun run verify` fails, do not stop at reporting the failure')
|
|
})
|
|
|
|
test('keeps PR authors accountable for tests, coverage, E2E, and risk', () => {
|
|
const template = readFileSync('.github/pull_request_template.md', 'utf8')
|
|
|
|
expect(template).toContain('## Feature Quality Contract')
|
|
expect(template).toContain('Changed surface:')
|
|
expect(template).toContain('Tests added or updated:')
|
|
expect(template).toContain('Coverage evidence:')
|
|
expect(template).toContain('changed-line coverage')
|
|
expect(template).toContain('E2E / live-model evidence:')
|
|
expect(template).toContain('Known risk / rollback:')
|
|
expect(template).toContain('I added or updated same-area tests')
|
|
})
|
|
|
|
test('keeps the one-command verification entrypoint documented', () => {
|
|
const packageJson = JSON.parse(readFileSync('package.json', 'utf8')) as {
|
|
scripts?: Record<string, string>
|
|
}
|
|
const contributing = readFileSync('docs/guide/contributing.md', 'utf8')
|
|
const englishContributing = readFileSync('docs/en/guide/contributing.md', 'utf8')
|
|
const rootContributing = readFileSync('CONTRIBUTING.md', 'utf8')
|
|
|
|
expect(packageJson.scripts?.verify).toBe('bun run quality:pr')
|
|
expect(packageJson.scripts?.['quality:verify']).toBe('bun run quality:pr')
|
|
expect(contributing).toContain('bun run verify')
|
|
expect(contributing).toContain('AI Coding Agent 修复循环')
|
|
expect(englishContributing).toContain('bun run verify')
|
|
expect(englishContributing).toContain('AI Coding Agent Fix Loop')
|
|
expect(rootContributing).toContain('bun run verify')
|
|
})
|
|
|
|
test('keeps general AI coding tools pointed at the same quality bar', () => {
|
|
const instructions = readFileSync('.github/copilot-instructions.md', 'utf8')
|
|
|
|
expect(instructions).toContain('Follow the repository contract in `AGENTS.md`')
|
|
expect(instructions).toContain('Add same-area tests with the production change')
|
|
expect(instructions).toContain('Preserve or improve the coverage ratchet')
|
|
expect(instructions).toContain('changed-line coverage threshold')
|
|
expect(instructions).toContain('E2E or agent-browser smoke')
|
|
expect(instructions).toContain('include changed files, tests added, coverage report path')
|
|
})
|
|
})
|