$npx -y skills add tody-agent/codymaster --skill cm-quality-gateUse before any deployment or completion claim. Enforces test gates, evidence-based verification, and frontend safety checks. No deploy without passing. No claims without evidence.
| 1 | # Quality Gate — Test + Verify + Ship Safe |
| 2 | |
| 3 | ## TL;DR |
| 4 | - **Use before** any deployment or completion claim |
| 5 | - **Gates**: tests pass, no secrets, frontend safety, evidence logged |
| 6 | - **Reads**: handoff/exec.json — **Writes**: handoff/quality.json |
| 7 | - **Modes**: OFF | WARNING (default) | SOFT | FULL |
| 8 | - **Vibecoding score**: 0..100 (Phase 2) |
| 9 | |
| 10 | > **Three checkpoints, one skill:** Pre-deploy testing, evidence verification, frontend safety. |
| 11 | |
| 12 | ## The Iron Laws |
| 13 | 1. **NO DEPLOY** without passing `test:gate`. |
| 14 | 2. **NO CLAIMS** without fresh verification output. |
| 15 | 3. **NO FRAGILE FRONTEND** — safety tests are mandatory. |
| 16 | |
| 17 | --- |
| 18 | |
| 19 | ## Phase 0: Infrastructure Setup |
| 20 | > **Goal:** Identify the framework and install the correct testing dependencies. |
| 21 | |
| 22 | 1. **Detect Stack:** Check `package.json` for framework (React, Vue, Astro, etc.) and `wrangler.json(c)`. |
| 23 | 2. **Install Deps:** `npm install -D vitest jsdom acorn` |
| 24 | 3. **Configure:** Create `vitest.config.ts` or `vite.config.ts` with `environment: 'jsdom'`. |
| 25 | 4. **Wire Scripts:** |
| 26 | ```json |
| 27 | { |
| 28 | "scripts": { |
| 29 | "test:gate": "vitest run --reporter=verbose" |
| 30 | } |
| 31 | } |
| 32 | ``` |
| 33 | |
| 34 | --- |
| 35 | |
| 36 | ## Phase 1: The 4 Core Test Layers |
| 37 | Do not combine these files. They form the "Quality Gate." |
| 38 | |
| 39 | ### Layer 1: Frontend Safety (`test/frontend-safety.test.ts`) |
| 40 | Prevents white screens, template corruption, and syntax errors. |
| 41 | ```javascript |
| 42 | test('app.js does not contain catastrophic corruption', () => { |
| 43 | const code = fs.readFileSync('public/static/app.js', 'utf-8'); |
| 44 | expect(code).not.toMatch(/=\s*'[^']*\$\{t\(/); // Bug #1 |
| 45 | expect(code).not.toMatch(/<\s+[a-zA-Z]/); // Bug #2 |
| 46 | }); |
| 47 | ``` |
| 48 | |
| 49 | ### Layer 2: API Routes (`test/api-routes.test.ts`) |
| 50 | Ensures backend endpoints respond correctly. |
| 51 | |
| 52 | ### Layer 3: Business Logic (`test/business-logic.test.ts`) |
| 53 | Tests pure functions, validations, and transformations. |
| 54 | |
| 55 | ### Layer 4: i18n Synchronization (`test/i18n-sync.test.ts`) |
| 56 | Guarantees all language files have identical key counts. |
| 57 | |
| 58 | --- |
| 59 | |
| 60 | ## Phase 2: Execution (The Gates) |
| 61 | |
| 62 | ### Gate 1: Pre-Deploy Testing |
| 63 | **ALWAYS** run `npm run test:gate` before deploying. 0 failures required. |
| 64 | |
| 65 | ### Protocol |
| 66 | |
| 67 | 1. **Check for skip override** (explicit user words only): |
| 68 | - ✅ "skip tests", "skip testing", "deploy without testing" |
| 69 | - ❌ "deploy", "quick deploy", "just push it" (= tests required) |
| 70 | |
| 71 | 2. **Run test gate:** |
| 72 | ```bash |
| 73 | npm run test:gate |
| 74 | ``` |
| 75 | |
| 76 | 3. **Parse results:** total files, total tests, failures, duration |
| 77 | |
| 78 | 4. **Gate decision:** |
| 79 | - 0 failures → proceed to deploy |
| 80 | - Any failures → **STOP. Fix first. Do NOT deploy.** |
| 81 | |
| 82 | ### Anti-Patterns |
| 83 | |
| 84 | | DON'T | DO | |
| 85 | |-------|-----| |
| 86 | | Deploy then test | Test then deploy | |
| 87 | | "Tests passed earlier" | Run fresh test:gate NOW | |
| 88 | | Skip for "small changes" | Every change gets tested | |
| 89 | | Run test + deploy parallel | Sequential: test → gate → deploy | |
| 90 | |
| 91 | ### Gate 2: Evidence Before Claims |
| 92 | **ALWAYS** run the proving command before saying "fixed" or "done." |
| 93 | |
| 94 | ### The Gate Function |
| 95 | |
| 96 | ``` |
| 97 | 1. IDENTIFY → What command proves this claim? |
| 98 | 2. RUN → Execute the FULL command (fresh) |
| 99 | 3. READ → Full output, check exit code |
| 100 | 4. VERIFY → Does output confirm the claim? |
| 101 | 5. ONLY THEN → Make the claim |
| 102 | ``` |
| 103 | |
| 104 | ### Common Failures |
| 105 | |
| 106 | | Claim | Requires | Not Sufficient | |
| 107 | |-------|----------|----------------| |
| 108 | | Tests pass | Test output: 0 failures | "Should pass", previous run | |
| 109 | | Build succeeds | Build: exit 0 | Linter passing | |
| 110 | | Bug fixed | Test symptom: passes | Code changed, assumed fixed | |
| 111 | | Requirements met | Line-by-line checklist | Tests passing | |
| 112 | |
| 113 | ### Red Flags — STOP |
| 114 | - Using "should", "probably", "seems to" |
| 115 | - Expressing satisfaction before verification |
| 116 | - Trusting agent success reports |
| 117 | - ANY wording implying success without running verification |
| 118 | |
| 119 | ### Gate 3: Frontend Integrity |
| 120 | Automated via Layer 1 above. |
| 121 | |
| 122 | ### When |
| 123 | Setting up or enhancing test suites for projects with frontend JavaScript/TypeScript. |
| 124 | |
| 125 | ### The 7 Layers |
| 126 | |
| 127 | | Layer | What it checks | Priority | |
| 128 | |-------|---------------|----------| |
| 129 | | 1. Syntax Validation | JS parses without errors (via acorn) | **CRITICAL** | |
| 130 | | 2. Function Integrity | Named functions exist and are callable | Required | |
| 131 | | 3. Template Safety | HTML templates have matching tags | Required | |
| 132 | | 4. Asset References | Referenced files actually exist | Required | |
| 133 | | 5. Corruption Patterns | Known bad patterns (empty functions, truncation) | Required | |
| 134 | | 6. Import/Export | Module references resolve | Recommended | |
| 135 | | 7. CSS Validation | CSS files parse correctly | Recommended | |
| 136 | |
| 137 | ### Setup |
| 138 | |
| 139 | ```bash |
| 140 | npm install -D vitest acorn |
| 141 | ``` |
| 142 | |
| 143 | ### Layer 1: Syntax Check (Most Critical) |
| 144 | |
| 145 | ```javascript |
| 146 | import { parse } from 'acorn'; |
| 147 | import { readFileSync } from 'fs'; |
| 148 | |
| 149 | test('app.js has valid syntax', () => { |
| 150 | const code = readFileSyn |