cc-haha/scripts/pr/quality-contract.test.ts
程序员阿江(Relakkes) 84bcdb5f52 fix: restore release gate checks
Keep provider ordering compatible with older desktop store state, keep workspace traversal blocked even when external changed-file roots are registered, and align the quality-contract test with the current AGENTS wording.

Tested: bun test scripts/pr/quality-contract.test.ts

Tested: cd desktop && bun run test -- src/__tests__/generalSettings.test.tsx src/__tests__/skillsSettings.test.tsx src/__tests__/pluginsSettings.test.tsx src/__tests__/diagnosticsSettings.test.tsx --run

Tested: bun run check:policy

Tested: bun run check:desktop

Tested: bun test src/server/__tests__/workspace-service.test.ts -t 'does not allow relative traversal'

Tested: bun test src/server/__tests__/sessions.test.ts -t 'workspace/file and tree should reject traversal|workspace/diff should reject traversal' --timeout=20000

Confidence: high

Scope-risk: narrow
2026-06-13 12:09:57 +08:00

93 lines
5.4 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('## Persistent Storage Compatibility')
expect(agents).toContain('Any change to local JSON, `localStorage`, or app config persistence formats must ship with a forward migration')
expect(agents).toContain('`~/.claude/settings.json` is user-owned shared state')
expect(agents).toContain('persistence upgrade gate')
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 PR readiness, 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` is intentionally run and 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 prePushHook = readFileSync('scripts/git-hooks/pre-push', 'utf8')
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(packageJson.scripts?.['quality:push']).toBe('bun run quality:gate --mode pr --skip coverage')
expect(packageJson.scripts?.['check:persistence-upgrade']).toBe('bun run scripts/quality-gate/persistence-upgrade.ts')
expect(packageJson.scripts?.['check:native']).toContain('electron:package:dir')
expect(packageJson.scripts?.['check:native']).toContain('test:package-smoke:current')
expect(packageJson.scripts?.['test:package-smoke:current']).toBe('bun run scripts/quality-gate/package-smoke/current.ts')
expect(prePushHook).toContain('non-blocking')
expect(prePushHook).not.toContain('\nbun run quality:push\n')
expect(prePushHook).not.toContain('quality:gate')
expect(prePushHook).not.toContain('quality:smoke')
expect(contributing).toContain('bun run verify')
expect(contributing).toContain('bun run quality:push')
expect(contributing).toContain('push 不再自动运行本地质量门禁')
expect(contributing).toContain('AI Coding Agent 修复循环')
expect(englishContributing).toContain('bun run verify')
expect(englishContributing).toContain('bun run quality:push')
expect(englishContributing).toContain('push no longer runs a local quality gate')
expect(englishContributing).toContain('AI Coding Agent Fix Loop')
expect(rootContributing).toContain('bun run verify')
expect(rootContributing).toContain('bun run quality:push')
expect(rootContributing).toContain('不再自动运行本地质量门禁')
})
test('keeps desktop native CI aligned with Electron packaging', () => {
const prQuality = readFileSync('.github/workflows/pr-quality.yml', 'utf8')
const buildSidecars = readFileSync('desktop/scripts/build-sidecars.ts', 'utf8')
expect(prQuality).toContain('run: bun run check:native')
expect(prQuality).not.toContain('dtolnay/rust-toolchain')
expect(prQuality).not.toContain('swatinem/rust-cache')
expect(prQuality).not.toContain('libwebkit2gtk')
expect(prQuality).not.toContain('libayatana-appindicator')
expect(buildSidecars).not.toContain("Bun.spawn(['rustc'")
expect(buildSidecars).toContain("process.platform")
expect(buildSidecars).toContain("process.arch")
})
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')
})
})