AGENT SKILL

speckit-spex-gates-verify

Final verification gate: tests, code hygiene, spec compliance, and drift check

License 许可
Apache-2.0
最近更新
2026-11-14
Stars
★ 1
Forks
0

01 前言 Front Matter

name
speckit-spex-gates-verify
metadata
{ "author": "github-spec-kit", "source": "spex-gates:commands/speckit.spex-gates.verify.md" }
description
Final verification gate: tests, code hygiene, spec compliance, and drift check
compatibility
Requires spec-kit project structure with .specify/ directory

03 SKILL.md 正文

Verification Before Completion (Spec-Aware)

Ship Pipeline Guard

If .specify/.spex-state exists and its status is running, this command is part of an autonomous pipeline. Check the ask field:

  • If ask is "smart" or "never": {harness:suppress-prompts-verify} autonomously, and return immediately so the pipeline can advance.
  • If ask is "always": prompt the user as normal.
if [ -f ".specify/.spex-state" ]; then
  STATUS=$(jq -r '.status // empty' .specify/.spex-state 2>/dev/null)
  ASK=$(jq -r '.ask // "always"' .specify/.spex-state 2>/dev/null)
  if [ "$STATUS" = "running" ] && [ "$ASK" != "always" ]; then
    echo "AUTONOMOUS_MODE=true"
  else
    echo "AUTONOMOUS_MODE=false"
  fi
else
  echo "AUTONOMOUS_MODE=false"
fi

In autonomous mode: do NOT output a completion summary, do NOT ask "Shall I proceed?", do NOT suggest next steps. Complete the verification and return.

Overview

Claiming work is complete without verification is dishonesty, not efficiency.

Core principle: Evidence before claims, always.

Verify implementation is complete by running tests AND validating spec compliance.

Key Steps:

  • Step 0: Closeout gate (blocks on unresolved Critical/Important findings)
  • Step 0a: Smoke test reminder
  • Step 1: Run tests (existing behavior)
  • Step 2: Code hygiene review (mechanical defect detection)
  • Step 3: Validate spec compliance (spec-driven)
  • Step 4: Check for spec drift (spec-driven)
  • Blocks completion if closeout gate, tests, code hygiene, OR spec compliance fails

The Iron Law

NO COMPLETION CLAIMS WITHOUT FRESH VERIFICATION EVIDENCE

If you haven't run the verification command in this message, you cannot claim it passes.

The Gate Function

BEFORE claiming any status or expressing satisfaction:

1. IDENTIFY: What command proves this claim?
2. RUN: Execute the FULL command (fresh, complete)
3. READ: Full output, check exit code, count failures
4. VERIFY: Does output confirm the claim?
   - If NO: State actual status with evidence
   - If YES: State claim WITH evidence
5. CHECK SPEC: Does implementation match spec?
   - If NO: State actual compliance with evidence
   - If YES: State compliance score WITH evidence
6. ONLY THEN: Make the claim

Skip any step = lying, not verifying

When to Use

  • After implementation and code review
  • Before claiming work is complete
  • Before committing/merging/deploying
  • As final gate in the implementation pipeline (via spex-gates hook)

Spec Selection

If a spec path is provided as an argument, use it directly.

Otherwise, attempt branch-based resolution:

.specify/scripts/bash/check-prerequisites.sh --json --paths-only 2>/dev/null

If this succeeds (outputs JSON with FEATURE_SPEC), use the resolved spec path. Parse the JSON to extract FEATURE_SPEC and FEATURE_DIR.

If this fails (not on a feature branch, no matching spec directory), fall back to interactive selection:

find specs/ -name "spec.md" -type f 2>/dev/null | head -20

If specs found: Present list and ask user to select one {harness:interactive-choice-skip}.

If no specs found: Inform user:

No specs found in specs/ directory.

Verification requires a spec to validate against.
Use `speckit-spex-brainstorm` or `/speckit-specify` to create one first.

The Process

0. Closeout Gate

Before any other verification, check whether unresolved Critical or Important findings remain from a deep review.

Resolve the spec directory (reuse the same check-prerequisites.sh logic from the Spec Selection section above):

PREREQS=$(.specify/scripts/bash/check-prerequisites.sh --json --paths-only 2>/dev/null) || true
if [ -n "$PREREQS" ]; then
  FEATURE_DIR=$(echo "$PREREQS" | jq -r '.FEATURE_DIR' 2>/dev/null)
fi

Run the closeout gate script:

CLOSEOUT_GATE=".specify/extensions/spex-gates/scripts/spex-closeout-gate.sh"
if [ -x "$CLOSEOUT_GATE" ] && [ -n "${FEATURE_DIR:-}" ]; then
  GATE_OUTPUT=$("$CLOSEOUT_GATE" "$FEATURE_DIR" 2>&1) || {
    echo "Closeout gate failed: $GATE_OUTPUT"
    # STOP: Do not proceed. Unresolved findings must be fixed and review re-run.
    exit 1
  }
fi

If the gate fails (exit code non-zero): STOP. Report the blocking findings from the gate output and do not proceed to any further verification steps. The developer must fix the findings and re-run the deep review.

If the gate passes (exit code 0, or script not found, or no spec dir): proceed to the next step.

0a. Smoke Test Reminder

Before running verification, check if the spec has acceptance scenarios and whether a smoke test has been recorded:

# Check if spec has acceptance scenarios
SPEC_FILE=""
PREREQS=$(.specify/scripts/bash/check-prerequisites.sh --json --paths-only 2>/dev/null) || true
if [ -n "$PREREQS" ]; then
  FEATURE_DIR=$(echo "$PREREQS" | jq -r '.FEATURE_DIR' 2>/dev/null)
  SPEC_FILE="$FEATURE_DIR/spec.md"
fi

HAS_SCENARIOS=0
if [ -n "$SPEC_FILE" ] && [ -f "$SPEC_FILE" ]; then
  HAS_SCENARIOS=$(grep -c '\*\*Given\*\*' "$SPEC_FILE" 2>/dev/null || echo 0)
fi

# Check if smoke test was recorded
SMOKE_TEST_DONE=false
if [ -f ".specify/.spex-state" ]; then
  SMOKE_TEST_DONE=$(jq -r '.smoke_test_completed // false' .specify/.spex-state 2>/dev/null)
fi

If the spec has acceptance scenarios AND no smoke test was recorded (HAS_SCENARIOS > 0 AND SMOKE_TEST_DONE is not true):

Display a reminder (informational only, does NOT block verification):

NOTE: Acceptance scenarios exist but no smoke test was recorded.
Consider running `/speckit-spex-smoke-test` first to validate runtime behavior.

If a smoke test was recorded or no acceptance scenarios exist: proceed silently.

1. Run Tests

Execute all tests:

# Run full test suite
npm test  # or pytest, go test, etc.

Check results:

  • All tests passing?
  • No flaky tests?
  • Coverage adequate?

If tests fail:

  • STOP: Fix tests before proceeding
  • Do not skip this step
  • Do not claim completion

2. Code Hygiene Review

Before checking spec compliance, review every changed file for mechanical defects. These are craft-level issues that no spec describes but that cause real bugs.

For each function you wrote or modified, check:

Dead Code and Logic

  • [ ] Every conditional branch produces a different outcome (no branches that do the same thing)
  • [ ] Every parameter is actually used to change behavior (no unused parameters)
  • [ ] Every exported function has at least one caller outside tests (no orphaned API surface)
  • [ ] No variables assigned but never read

Copy and Mutation Safety

  • [ ] When copying a data structure, verify whether nested references are shared
  • [ ] If the copy is later mutated, confirm the original is not affected
  • [ ] If a function receives a pointer/reference, verify whether it is expected to mutate or read-only

Cleanup and Consistency

  • [ ] When removing/disabling something, verify all references to it are also cleaned up (no orphaned entries, dangling references, stale indices)
  • [ ] When adding to a collection, verify duplicates are handled (deduplicate or reject)
  • [ ] When deriving a value from an identifier, verify the derivation uses the correct source (e.g., a display name vs an internal ID vs a type name are different things)

Unnecessary Operations

  • [ ] No sorting/ordering when the result doesn't depend on order (counting, summing, existence checks)
  • [ ] No intermediate data structures that serve no purpose (building a list just to iterate it once)

If any issue found: Fix before proceeding. These are not style nits; they are latent bugs.

3. Validate Spec Compliance

Load spec:

cat specs/features/[feature-name].md

Check each requirement and emit a machine-readable compliance matrix:

For each functional requirement in the spec, determine its status. There are exactly two valid statuses:

  • IMPLEMENTED: Code fully implements the requirement. You can point to the function, the test, and the behavior.
  • MISSING: Code does not implement the requirement, or implements it only partially.

There is NO "PARTIAL" status. There is NO "COMPLIANT (with documented gap)" status. There is NO "IMPLEMENTED (known limitation)" status. If the code doesn't fully do what the spec says MUST happen, the status is MISSING.

Functional Requirement 1: [From spec]
  Status: IMPLEMENTED | MISSING
  Evidence: [file:line where it's implemented, or why it's missing]

Functional Requirement 2: [From spec]
  Status: IMPLEMENTED | MISSING
  Evidence: [file:line where it's implemented, or why it's missing]

After checking ALL requirements, emit a machine-readable gate result block:

SPEC_COMPLIANCE_RESULT:
  total: N
  implemented: N
  missing: N
  percentage: XX%
  gate: PASS | FAIL

The gate value is determined mechanically: if missing > 0, the gate is FAIL. No exceptions. No judgment calls. No "but it's a known gap." If the spec says MUST and the code doesn't, it's MISSING, and the gate is FAIL.

Anti-rationalization guardrails (read these before making your compliance decision):

You WILL be tempted to let partial compliance pass. You will find plausible reasons. All of them are wrong:

Rationalization Why it's wrong
"It's a known gap" Known gaps are still gaps. MISSING.
"It's documented as future work" Future work means not implemented. MISSING.
"There's a workaround" Workarounds are not implementations. MISSING.
"The spec assumption section mentions this" Assumptions don't override MUST requirements. MISSING.
"It's only partially implemented" Partial is not complete. MISSING.
"The user knows about this" User awareness doesn't change compliance. MISSING.

The only valid paths when the gate is FAIL:

  1. Implement the missing requirement, then re-run verify
  2. Run /speckit-spex-evolve to formally remove or defer the requirement from the spec, then re-run verify

If compliance = 100%: Proceed to next step. If compliance < 100%: STOP. Do not proceed. Report the MISSING requirements and suggest the two valid resolution paths above.

4. Check for Spec Drift

Compare:

  • What spec says NOW
  • What code does NOW
  • Any divergence?

Common drift sources:

  • Spec updated but code not
  • Code changed but spec not
  • Undocumented additions
  • Forgotten requirements

If drift detected:

  • Document each instance
  • Use speckit-spex-evolve to reconcile
  • Do not proceed with drift

5. Verify Success Criteria

From spec, check each criterion:

Success Criteria (from spec):
- [ ] Criterion 1: [Description]
      Status: Met / Not met
      Evidence: [How verified]

- [ ] Criterion 2: [Description]
      ...

All criteria must be met.

If any criterion not met:

  • STOP: Criterion not met
  • Implement missing piece
  • Re-verify

6. Generate Verification Report

Report structure:

# Verification Report: [Feature Name]

**Date:** YYYY-MM-DD
**Spec:** specs/features/[feature].md

## Test Results

**Status:** PASS / FAIL

[Test output]

**Summary:**
- Total: X tests
- Passed: X
- Failed: X
- Coverage: XX%

## Spec Compliance

**Status:** COMPLIANT / NON-COMPLIANT

**Compliance Score:** XX%

### Requirements Status
- Functional: X/X (XX%)
- Error Cases: X/X (XX%)
- Edge Cases: X/X (XX%)
- Non-Functional: X/X (XX%)

### Deviations
[List any deviations found]

## Spec Drift Check

**Status:** NO DRIFT / DRIFT DETECTED

[Details if drift found]

## Success Criteria

**Status:** ALL MET / INCOMPLETE

- [x] Criterion 1
- [x] Criterion 2
...

## Overall Status

**VERIFIED - Ready for completion**

OR

**NOT VERIFIED - Issues must be resolved**

**Blocking Issues:**
- [Issue 1]
- [Issue 2]

**Next Steps:**
[What needs to be done]

7. Make Go/No-Go Decision

All conditions must be true:

  • [x] All tests passing
  • [x] Code hygiene review clean (no dead code, no mutation bugs, no orphans)
  • [x] SPEC_COMPLIANCE_RESULT.gate is PASS (100% compliance, zero MISSING)
  • [x] No spec drift
  • [x] All success criteria met

If ALL true:

  • VERIFIED: Proceed to completion
  • Safe to commit/merge/deploy
  • Write verification marker so the commit gate hook allows the commit:
    touch "${TMPDIR:-/tmp}/.claude-spex-verified-${SESSION_ID}"
    
    (The SESSION_ID is available from the hook context. If not, use a stable session identifier.)

If ANY false:

  • NOT VERIFIED: Block completion
  • Fix issues before proceeding
  • Re-run verification after fixes

8. Completion Celebration

After all verification passes (go decision is positive), check if a state file exists:

STATE_FILE=".specify/.spex-state"
if [ -f "$STATE_FILE" ]; then
  MODE=$(jq -r '.mode // empty' "$STATE_FILE" 2>/dev/null)
fi

If a state file exists (flow or ship mode), display a celebration:

  1. Compute stats:

    FEATURE=$(jq -r '.feature_branch // "unknown"' "$STATE_FILE" 2>/dev/null)
    STARTED=$(jq -r '.started_at // empty' "$STATE_FILE" 2>/dev/null)
    SPEC_DIR=$(jq -r '.spec_dir // empty' "$STATE_FILE" 2>/dev/null)
    # If spec_dir not in state (ship mode), derive from branch
    [ -z "$SPEC_DIR" ] && SPEC_DIR="specs/$FEATURE"
    REVIEW_COUNT=$(ls "$SPEC_DIR"/REVIEW-*.md 2>/dev/null | wc -l | tr -d ' ')
    COMMIT_COUNT=$(git rev-list --count main..HEAD 2>/dev/null || echo "?")
    
    • Duration: compute from started_at to now (human-readable, e.g., "2h 15m" or "3d 4h")
    • If started_at is empty, skip duration
  2. Display celebration banner:

    +-------------------------------------------+
    |                                           |
    |   ALL CHECKS PASSED                       |
    |                                           |
    |   Feature:  <feature_branch>              |
    |   Duration: <duration>                    |
    |   Reviews:  <count> passed                |
    |   Commits:  <count>                       |
    |                                           |
    |   <random sign-off message>               |
    |                                           |
    +-------------------------------------------+
    
  3. Sign-off message pool (select one randomly):

    • "Ship it!"
    • "Another one bites the dust."
    • "That's a wrap."
    • "Clean as a whistle."
    • "Nailed it."
    • "Spec met. Code shipped. Coffee earned."
    • "Nothing left to prove."
  4. Remove state file after displaying:

    rm -f "$STATE_FILE"
    

If no state file exists, skip the celebration (no-op).

Common Failures

Claim Requires Not Sufficient
Tests pass Test command output: 0 failures Previous run, "should pass"
Spec compliant Line-by-line requirement check "Looks complete"
Linter clean Linter output: 0 errors Partial check
Build succeeds Build command: exit 0 Linter passing
Bug fixed Test original symptom: passes Code changed
Requirements met Line-by-line checklist Tests passing

Red Flags - STOP

  • Using "should", "probably", "seems to"
  • Expressing satisfaction before verification ("Great!", "Perfect!", "Done!")
  • About to commit/push/PR without verification
  • Relying on partial verification
  • Thinking "just this once"
  • Tired and wanting work over
  • ANY wording implying success without having run verification
  • Modified CLAUDE.md without explicit user request (CLAUDE.md is user-maintained, never auto-update)

Rationalization Prevention

Excuse Reality
"Should work now" RUN the verification
"I'm confident" Confidence is not evidence
"Just this once" No exceptions
"Tests pass" Did you check spec compliance?
"Spec compliant" Did you run the tests?
"I'm tired" Exhaustion is not an excuse
"Partial check is enough" Partial proves nothing

Quality Gates

This command enforces quality gates:

  1. All tests must pass
  2. Code hygiene review clean (mechanical defects)
  3. 100% spec compliance required
  4. No spec drift allowed
  5. All success criteria must be met

No exceptions. No shortcuts.

These gates exist to prevent:

  • Incomplete implementations
  • Untested code
  • Spec/code divergence
  • False claims of completion

Remember

Verification is not optional.

  • Don't skip verification "just this once"
  • Don't claim completion without verification
  • Don't ignore failing gates

Verification failures are information.

  • Tests failing? Code has bugs
  • Spec compliance failing? Missing features
  • Drift detected? Synchronization problem
  • Criteria not met? Work incomplete

No shortcuts for verification.

Run the command. Read the output. Check the spec. THEN claim the result.

Fix issues, don't rationalize past them.

Evidence before assertions. Always.

This is non-negotiable.

04 同仓库更多 Skills