Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f43146bb18 | ||
|
|
d866b602b8 |
No files matched your search
@@ -78,6 +78,8 @@ Every skill features an explicit **"Your call"** checkpoint where the agent paus
|
|||||||
| **[`inspect-flake-update`](skills/inspect-flake-update/SKILL.md)** | `/inspect-flake-update` | Inspects updated flake.lock inputs, reviews upstream revisions, runs nix flake check, and drafts commit messages. | 46 lines |
|
| **[`inspect-flake-update`](skills/inspect-flake-update/SKILL.md)** | `/inspect-flake-update` | Inspects updated flake.lock inputs, reviews upstream revisions, runs nix flake check, and drafts commit messages. | 46 lines |
|
||||||
| **[`nix-devshell`](skills/nix-devshell/SKILL.md)** | `/nix-devshell` | Authors, extends, validates, and troubleshoots project Nix development shells from repository evidence. | 75 lines |
|
| **[`nix-devshell`](skills/nix-devshell/SKILL.md)** | `/nix-devshell` | Authors, extends, validates, and troubleshoots project Nix development shells from repository evidence. | 75 lines |
|
||||||
| **[`verify-slice`](skills/verify-slice/SKILL.md)** | `/verify-slice` | Runs risk-proportional verification and PR review across behavioral, state, security, ergonomic, and regression perspectives using falsifiable assertions. | 37 lines |
|
| **[`verify-slice`](skills/verify-slice/SKILL.md)** | `/verify-slice` | Runs risk-proportional verification and PR review across behavioral, state, security, ergonomic, and regression perspectives using falsifiable assertions. | 37 lines |
|
||||||
|
| **[`code-review`](skills/code-review/SKILL.md)** | `/code-review` | Inspects diffs across four isolated axes: Spec & Scope, Standards & Smells, Seam & Test Integrity, and Defensive Invariants. | 42 lines |
|
||||||
|
| **[`tdd`](skills/tdd/SKILL.md)** | `/tdd` | Guides red-green test-driven development through public interface seams, boundary-only mocking, and non-tautological assertions. | 40 lines |
|
||||||
|
|
||||||
### Vault Extensions (`extensions/`)
|
### Vault Extensions (`extensions/`)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -33,7 +33,7 @@ while [[ $# -gt 0 ]]; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Active skills to install
|
# Active skills to install
|
||||||
ACTIVE_PORTABLE_SKILLS=(build-skill diagnose document git-commit inspect-flake-update journal-builder nix-devshell practice reconcile-docs verify-slice)
|
ACTIVE_PORTABLE_SKILLS=(build-skill code-review diagnose document git-commit inspect-flake-update journal-builder nix-devshell practice reconcile-docs tdd verify-slice)
|
||||||
ACTIVE_EXTENSION_SKILLS=(draft-curation commit-logger)
|
ACTIVE_EXTENSION_SKILLS=(draft-curation commit-logger)
|
||||||
|
|
||||||
# Legacy / deprecated skills to clean up or back up if found in target
|
# Legacy / deprecated skills to clean up or back up if found in target
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
---
|
||||||
|
name: code-review
|
||||||
|
description: >-
|
||||||
|
Inspects git diffs, pull requests, and commit ranges across four independent
|
||||||
|
axes: Spec & Scope, Standards & Smells, Seam & Test Integrity, and Defensive
|
||||||
|
Invariants. Use when reviewing code changes before merge or verifying diff
|
||||||
|
quality. Not for live runtime QA: use verify-slice.
|
||||||
|
---
|
||||||
|
|
||||||
|
# Code Review
|
||||||
|
|
||||||
|
## Use when
|
||||||
|
- Reviewing a branch, pull request, work-in-progress diff, or commit range before merge.
|
||||||
|
- Evaluating code structure, defensive invariants, and test seam integrity.
|
||||||
|
- Not for live runtime browser or deployment testing: use `verify-slice`.
|
||||||
|
- Not for debugging an unknown symptom: use `diagnose`.
|
||||||
|
|
||||||
|
## Steps
|
||||||
|
1. **Pin the fixed point and scope.** Resolve the base ref and record its commit SHA via `git rev-parse <base>`. Inspect working-tree state (`git status --short`, unstaged `git diff`, staged `git diff --cached`) alongside committed history (`git diff <base>...HEAD` and `git log <base>..HEAD --oneline`). Report findings distinguished across committed, staged, and unstaged changes.
|
||||||
|
2. **Select execution tier.** Match the change to the risk tiers from [axes](references/axes.md) (`Lightweight`, `Standard`, or `High-Assurance`). Single-agent sequential pass for Lightweight; independent review passes for Standard; isolated subagents per axis for High-Assurance.
|
||||||
|
3. **Inspect the four axes.** Evaluate the diff against each axis independently using [axes](references/axes.md):
|
||||||
|
- **Spec & Scope**: originating requirements satisfied, minimal shared-file footprint, zero scope creep.
|
||||||
|
- **Standards & Smells**: repository rules and Fowler smell diagnostics from [smell-heuristics](references/smell-heuristics.md) (evaluated as confirmed violations, potential smells, or contextual trade-offs).
|
||||||
|
- **Seam & Test Integrity**: tests verify public interface seams, assertions are non-tautological, negative/boundary paths covered, vertical slices prioritized over bulk imagined tests.
|
||||||
|
- **Defensive Invariants**: system properties from [defensive-invariants](references/defensive-invariants.md) (trust boundaries, authority, consistency, failure semantics, resource limits).
|
||||||
|
4. **Record structured findings.** Record every finding using the schema in [finding-schema](references/finding-schema.md) (`ID`, `Axis`, `Severity`, `Evidence`, `Invariant`, `Impact`, `Disposition`). A strong pass on one axis never compensates for a failure on another.
|
||||||
|
5. **Aggregate without silent resolution.** When multiple reviewers or passes disagree, keep the disagreement visible under `Unresolved` until evidence settles it.
|
||||||
|
6. **Recommend runtime verification scenarios.** Identify stateful or high-risk paths that static inspection cannot prove and list them as suggested scenarios for `verify-slice`.
|
||||||
|
7. **Present the review summary.** Group findings by axis and apply the decision matrix from [axes](references/axes.md): `Needs Rework` (confirmed defects require changes), `Blocked` (unresolved Critical/High risks or unestablished scope), or `Ready` (no blocking defects; documented trade-offs accepted by owner). Never authorize release: the human owner decides release.
|
||||||
|
|
||||||
|
## Your call
|
||||||
|
- **Handling findings**: decide whether confirmed findings block merge, trigger a rework loop, or become tracked follow-up issues.
|
||||||
|
- **Adjudicating unresolved disagreements**: resolve conflicting reviewer perspectives or accepted architectural trade-offs.
|
||||||
|
- **Authorizing release**: verification and review evidence inform decisions, but the human owner remains the sole release authority.
|
||||||
|
|
||||||
|
## Done when
|
||||||
|
- All four axes have been inspected across working-tree and committed changes, every finding is recorded with evidence and disposition, candidate runtime scenarios are passed to `verify-slice` if needed, and the human owner has reviewed the findings.
|
||||||
|
|
||||||
|
## Hands off to
|
||||||
|
- `diagnose`: when a finding exposes a root cause that requires deeper troubleshooting.
|
||||||
|
- `verify-slice`: to execute behavioral and runtime verification scenarios.
|
||||||
|
- `git-commit`: when committing review fixes or test adjustments.
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
# Review Axes and Risk Tiers
|
||||||
|
|
||||||
|
Reference for `code-review`. Inspects git diffs across four distinct evaluation dimensions without allowing strength on one axis to compensate for defects on another.
|
||||||
|
|
||||||
|
Derived and adapted from Matt Pocock's skills repository (github.com/mattpocock/skills), combining the multi-axis review discipline with empirical safety and verification invariants.
|
||||||
|
|
||||||
|
## 1. The Four Review Axes
|
||||||
|
|
||||||
|
| Axis | Primary Question | Failure Mode Caught | Core Inspection Questions |
|
||||||
|
| :--- | :--- | :--- | :--- |
|
||||||
|
| **Spec & Scope** | Did we build what was requested, and only that? | Scope creep, missing requirements, leaky abstractions | 1. Does the diff satisfy the originating issue or specification contract?<br/>2. Is there unrequested functionality or premature generalization?<br/>3. Are changes to shared entrypoints (e.g., routers, base config) minimal and additive? |
|
||||||
|
| **Standards & Smells** | Is the implementation maintainable and consistent? | Structural debt, friction with conventions | 1. Does the code adhere to repo standards (`CODING_STANDARDS.md`, linter configs)?<br/>2. Are code smells present that warrant refactoring? (See [smell-heuristics](smell-heuristics.md)).<br/>3. Is naming clear and aligned with domain vocabulary? |
|
||||||
|
| **Seam & Test Integrity** | Do tests prove actual contracts at public interfaces? | Tautological tests, implementation coupling | 1. Are tests verifying public interfaces (seams) rather than mocking private internals?<br/>2. Are assertions non-tautological (do not mirror code logic or pass by construction)?<br/>3. Prefer tests establishing observable behavior through meaningful vertical slices. Batch independent cases when doing so preserves clear contracts and does not substitute test quantity for behavioral evidence. |
|
||||||
|
| **Defensive Invariants** | Does the code preserve critical system properties under stress? | Injection, state desync, unhandled crashes | 1. Are untrusted inputs sanitized before reaching sinks? (See [defensive-invariants](defensive-invariants.md)).<br/>2. Does state reconcile against authoritative sources rather than local heuristic drift?<br/>3. Are failure semantics, timeouts, and resource limits explicit? |
|
||||||
|
|
||||||
|
### Non-Compensation Invariant
|
||||||
|
A strong pass on one axis never excuses a failure on another:
|
||||||
|
- Clean abstractions and zero code smells cannot excuse an unescaped HTML sink or an unhandled conflict.
|
||||||
|
- 100% test coverage cannot excuse unrequested feature drift or broken domain invariants.
|
||||||
|
- Strict spec compliance cannot excuse fragile code structure that breaks repository conventions.
|
||||||
|
|
||||||
|
## 2. Review Recommendations Matrix
|
||||||
|
|
||||||
|
The distinction between recommendations is clear: `Needs Rework` means an established defect requires implementation or test changes; `Blocked` means the review cannot establish sufficient confidence or scope to proceed safely.
|
||||||
|
|
||||||
|
| Condition Observed | Final Recommendation | Action Required |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| **Confirmed Critical or High** | `Needs Rework` | Fix confirmed defects before release review. |
|
||||||
|
| **Confirmed Medium or Low requiring changes** | `Needs Rework` | Apply requested refactoring or test coverage fixes. |
|
||||||
|
| **Unresolved Critical or High** | `Blocked` | Resolve missing evidence or escalate to human owner before proceeding. |
|
||||||
|
| **Unresolved Medium or Low** | `Ready` (Conditional) | Human owner may adjudicate and accept trade-offs without blocking. |
|
||||||
|
| **Scope Inability or Missing Base Ref** | `Blocked` | Establish base commit and diff boundaries before reviewing. |
|
||||||
|
| **No Blocking Findings** | `Ready` | Implementation is structurally sound; proceed to `verify-slice` or release. |
|
||||||
|
|
||||||
|
### Documented Trade-Off Acceptance
|
||||||
|
When a human owner accepts a documented trade-off for a Medium or Low finding, record the finding disposition as `Accepted Trade-off` (distinct from `Rejected`). This preserves audit traceability without misclassifying an intentional compromise as a disproven defect.
|
||||||
|
|
||||||
|
## 3. Risk-Scaled Execution Tiers
|
||||||
|
|
||||||
|
To keep review overhead proportional to risk, execution mode reuses the tiers established in `verify-slice`:
|
||||||
|
|
||||||
|
| Review Risk Tier | Typical Change | Review Execution Strategy |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| **Lightweight** | Copy updates, styling adjustments, isolated bugfixes with no new state or untrusted data. | Single-agent sequential pass inspecting all 4 axes in order. |
|
||||||
|
| **Standard** | New UI components, regular API endpoints, database queries, or schema additions. | Independent review passes over the diff. Subagents may be used when helpful to prevent bias. |
|
||||||
|
| **High-Assurance** | Auth, permissions, payments, concurrent state reconciliation, destructive actions, or core shared libraries. | Fully isolated reviewers for separate axes (e.g., Subagent 1 on Spec, Invariants, and Tests; Subagent 2 on Standards and Smells), followed by independent aggregation. |
|
||||||
|
|
||||||
|
## 4. Aggregation and Anti-Silence Rules
|
||||||
|
|
||||||
|
When multiple passes or subagents inspect a change:
|
||||||
|
1. **Never silently resolve disagreements**: If Reviewer A flags a pattern as a defect and Reviewer B considers it acceptable, record the finding under `Unresolved` with both perspectives cited. The human owner adjudicates.
|
||||||
|
2. **Preserve exact evidence**: Every finding must include exact file paths, line numbers, and code snippets demonstrating the condition.
|
||||||
|
3. **Recommend runtime verification**: Where static analysis cannot verify dynamic timing, rendering, or network failure modes, formulate concrete candidate assertions and pass them to `verify-slice`.
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
# Defensive Invariants
|
||||||
|
|
||||||
|
Reference for `code-review`. Defines system properties that must hold true across backend APIs, frontend clients, CLI tools, and system infrastructure.
|
||||||
|
|
||||||
|
## 1. Core System Properties
|
||||||
|
|
||||||
|
Every change that handles external data, mutable state, or distributed operations must satisfy five defensive properties:
|
||||||
|
|
||||||
|
### A. Trust Boundaries
|
||||||
|
Untrusted data enters the system from HTTP parameters, headers, route variables, environment files, user input forms, external webhook bodies, or database text fields.
|
||||||
|
- **Verification Rule**: Trace every untrusted value from source to sink. Verify safe APIs, parameterization, or contextual encoding (e.g. escaping HTML for DOM text, quoting attribute values, validating URL protocols).
|
||||||
|
- **Anti-pattern**: Relying on HTML sanitization to protect URL targets (`href="javascript:..."`), or interpolating raw strings into SQL, HTML, or shell commands.
|
||||||
|
|
||||||
|
### B. Authority
|
||||||
|
Every piece of mutable state must have a single authoritative owner (usually a database, an authoritative server endpoint, or a dedicated state actor).
|
||||||
|
- **Verification Rule**: Components, views, and CLI tools must never invent duplicate truth or assume their local copy is permanently accurate after out-of-band mutations can occur.
|
||||||
|
- **Anti-pattern**: Mutating local UI counters or status badges via optimistic arithmetic without reconciling against authoritative responses.
|
||||||
|
|
||||||
|
### C. Consistency and Conflict Handling
|
||||||
|
Operations that touch shared or concurrent state must handle collisions and out-of-band updates predictably.
|
||||||
|
- **Verification Rule**: When a mutation encounters a conflict (such as HTTP 409, unique constraint violation, or file lock contention), the system must fetch authoritative state or signal conflict to the operator.
|
||||||
|
- **Anti-pattern**: Swallowing conflicts, or applying a naive local patch (like `counter + 1`) that desynchronizes whenever multiple records or operators mutate state simultaneously.
|
||||||
|
|
||||||
|
### D. Failure Semantics
|
||||||
|
When external calls, network sockets, or sub-processes fail, the system must behave deterministically.
|
||||||
|
- **Verification Rule**: Failure paths must release locks, clean up temporary files, surface understandable error messages, and avoid partial half-committed state. Retries must be idempotent.
|
||||||
|
- **Anti-pattern**: Empty `catch` or `except` blocks, unhandled promise rejections, silent fallback to empty arrays on network failures, or retrying non-idempotent mutations.
|
||||||
|
|
||||||
|
### E. Resource Boundaries
|
||||||
|
Input sizes, execution duration, concurrency, and memory consumption must have explicit boundaries.
|
||||||
|
- **Verification Rule**: Incoming payloads must have size limits; pagination must be enforced; timeouts must guard external calls; file streams and database connections must be closed deterministically.
|
||||||
|
- **Anti-pattern**: Unbounded `SELECT *` queries, unbounded regex evaluations vulnerable to catastrophic backtracking, or reading unbounded streams entirely into memory.
|
||||||
|
|
||||||
|
## 2. Multi-Stack Reference Examples
|
||||||
|
|
||||||
|
| Stack / Context | Property | Concrete Risk | Defect Pattern | Correct Invariant Pattern |
|
||||||
|
| :--- | :--- | :--- | :--- | :--- |
|
||||||
|
| **Frontend / Web** | Trust Boundaries | XSS / DOM Injection | `el.innerHTML = '<span>' + user.name + '</span>'` | Use `textContent`, safe DOM builders, or context-aware `escapeHtml(user.name)`. |
|
||||||
|
| **Frontend / Web** | Consistency | Stale Counters on Conflict | Local counter increment on 409 duplicate check-in. | On 409 conflict, fetch authoritative session/record state from the server. |
|
||||||
|
| **Python / FastAPI** | Resource Boundaries | Memory exhaustion | Reading entire uploaded file via `await file.read()`. | Enforce payload size limits and stream chunks using configured buffer limits. |
|
||||||
|
| **Python / FastAPI** | Consistency | Race conditions | Non-atomic read-then-write on database balance or status. | Use database transactions with explicit row locks (`SELECT ... FOR UPDATE`) or atomic SQL increments. |
|
||||||
|
| **Rust / CLI** | Failure Semantics | Silent partial failure | Ignoring `Result` via `.unwrap_or_default()` on critical I/O. | Bubble up errors with contextual details via `anyhow` or domain error types; clean up staging files. |
|
||||||
|
| **NixOS / Homelab** | Authority | Secret leakage | Baking plaintext API keys into world-readable Nix store derivations. | Reference secret paths resolved at runtime via sops-nix or systemd credentials. |
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
# Finding Schema and Review Output
|
||||||
|
|
||||||
|
Reference for `code-review`. Defines the required structure for reporting findings, ensuring every note is actionable, evidence-backed, and auditable.
|
||||||
|
|
||||||
|
Derived and adapted from Matt Pocock's review principles (github.com/mattpocock/skills), combining side-by-side axis reporting with strict defect provenance and disposition contracts.
|
||||||
|
|
||||||
|
## 1. Finding Record Schema
|
||||||
|
|
||||||
|
Every reported finding must populate all seven fields:
|
||||||
|
|
||||||
|
| Field | Description | Allowed Values / Format |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| **ID** | Stable identifier within this review. | `CR-01`, `CR-02`, etc. |
|
||||||
|
| **Axis** | The review axis that uncovered the finding. | `Spec & Scope`, `Standards & Smells`, `Seam & Test Integrity`, `Defensive Invariants`. |
|
||||||
|
| **Severity** | Potential failure consequence if the defect occurs. Describes impact, not reviewer confidence. | `Critical` (system security breach, data loss, fatal crash), `High` (broken invariant, missing spec requirement), `Medium` (code smell, fragile logic, missing edge test), `Low` (minor style inconsistency, naming). |
|
||||||
|
| **Evidence** | Exact location, change category, and reproducible behavior. | Distinguishes whether the code is committed, staged, or unstaged: e.g. `src/view.ts:L45 (unstaged)` with excerpt. |
|
||||||
|
| **Invariant** | The requirement, contract, or system property violated. | Clear statement of expectation (e.g., "Untrusted DOM values must be escaped before interpolation"). |
|
||||||
|
| **Impact** | Concrete failure consequence if left unaddressed. | What breaks in production, concurrency, or maintenance (e.g., "Stored XSS when name contains `<script>`"). |
|
||||||
|
| **Disposition** | Current evidentiary status of the finding. | `Confirmed` (proven defect backed by evidence), `Rejected` (disproven or false positive), `Unresolved` (open disagreement or missing evidence), `Accepted Trade-off` (conscious compromise approved by owner). |
|
||||||
|
|
||||||
|
## 2. Disposition and Severity Rules
|
||||||
|
|
||||||
|
1. **Blocking status**: Only `Confirmed` findings (Critical, High, or changes-required Medium/Low) trigger a `Needs Rework` verdict.
|
||||||
|
2. **Unresolved findings**: `Unresolved Critical` or `Unresolved High` findings result in a `Blocked` verdict until resolved with evidence or owner adjudication. `Unresolved Medium` or `Low` findings can remain `Ready` if the owner accepts the trade-off.
|
||||||
|
3. **Rejected vs. Accepted Trade-off**:
|
||||||
|
- `Rejected`: The finding was an invalid concern or disproven by facts.
|
||||||
|
- `Accepted Trade-off`: The finding identifies a genuine compromise where the owner explicitly accepts the local cost for an engineering reason.
|
||||||
|
Both remain in the ledger for full audit traceability.
|
||||||
|
4. **Severity vs. confidence**: `Severity` describes potential impact, never reviewer confidence. A suspected high-impact flaw with incomplete evidence must be logged as `High` severity with `Unresolved` disposition, not downgraded to `Low`.
|
||||||
|
|
||||||
|
## 3. Review Report Layout
|
||||||
|
|
||||||
|
The final review summary presented to the user must follow this structure:
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
# Code Review Summary: <branch or commit range>
|
||||||
|
|
||||||
|
## Overview & Scope State
|
||||||
|
- **Base Commit**: `<base-ref>` (`<base-commit-sha>`) -> `<HEAD>` (`<head-commit-sha>`)
|
||||||
|
- **Working Tree State**: Clean / Staged Changes / Unstaged Changes (`git status --short`)
|
||||||
|
- **Assigned Risk Tier**: `Lightweight` | `Standard` | `High-Assurance`
|
||||||
|
- **Execution Mode**: `Sequential` | `Independent Passes` | `Subagent Reviewers`
|
||||||
|
|
||||||
|
## Findings Ledger
|
||||||
|
|
||||||
|
### Confirmed Findings (Needs Rework)
|
||||||
|
| ID | Axis | Severity | State | Location | Invariant Violated | Impact |
|
||||||
|
| :--- | :--- | :--- | :--- | :--- | :--- | :--- |
|
||||||
|
| CR-01 | Defensive Invariants | Critical | Committed | `src/view.ts:L45` | Unescaped dynamic HTML sink | DOM XSS via attendee name |
|
||||||
|
|
||||||
|
### Unresolved Disagreements / Material Risks (Blocked if Critical/High)
|
||||||
|
| ID | Axis | Severity | Location | Competing Perspectives / Open Risk | Decision Needed |
|
||||||
|
| :--- | :--- | :--- | :--- | :--- | :--- |
|
||||||
|
| CR-02 | Standards & Smells | Medium | `src/api.ts:L110` | Reviewer A flags Primitive Obsession; Author notes single call site. | Accept string or introduce domain type |
|
||||||
|
|
||||||
|
### Accepted Trade-offs & Rejected Findings (Audit Traceability)
|
||||||
|
| ID | Axis | Disposition | Location | Rationale / Decision |
|
||||||
|
| :--- | :--- | :--- | :--- | :--- |
|
||||||
|
| CR-03 | Spec & Scope | Rejected | `src/main.ts:L12` | Suspected scope creep confirmed as required wiring for acceptance criterion 2. |
|
||||||
|
| CR-04 | Standards & Smells | Accepted Trade-off | `scripts/seed.py:L10` | Inlined script logic accepted to keep utility independent of core module. |
|
||||||
|
|
||||||
|
## Axis Breakdown
|
||||||
|
- **Spec & Scope**: Pass/Fail summary. Notes on scope containment and shared entrypoints across working-tree and commits.
|
||||||
|
- **Standards & Smells**: Adherence to repo conventions and Fowler smell diagnostics.
|
||||||
|
- **Seam & Test Integrity**: Evaluation of test boundaries, tautological assertions, and vertical slice evidence.
|
||||||
|
- **Defensive Invariants**: Status of trust boundaries, authority, consistency, failure semantics, and resource limits.
|
||||||
|
|
||||||
|
## Recommended Runtime Scenarios for verify-slice
|
||||||
|
List concrete runtime checks or adversarial test cases that static inspection identified as necessary for runtime verification:
|
||||||
|
1. Scenario: Verify out-of-band 409 conflict handling with simultaneous check-in attempts.
|
||||||
|
2. Scenario: Verify input sanitization with payload `<img src=x onerror=alert(1)>`.
|
||||||
|
|
||||||
|
## Overall Recommendation
|
||||||
|
- **Status**: `Ready` | `Needs Rework` | `Blocked`
|
||||||
|
- **Next Action**: State whether to hand off to `verify-slice` for runtime verification, `diagnose` for root-cause fixes, or present to human owner for adjudication.
|
||||||
|
```
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
# Code Smells and Design Diagnostics
|
||||||
|
|
||||||
|
Reference for `code-review`. Treats code smell catalogs as diagnostic heuristics rather than mechanical violation checklists.
|
||||||
|
|
||||||
|
Derived and adapted from Martin Fowler's refactoring catalog as curated in Matt Pocock's skills repository (github.com/mattpocock/skills).
|
||||||
|
|
||||||
|
## 1. Three-Tier Evaluation Framework
|
||||||
|
|
||||||
|
When a reviewer observes a suspicious pattern in the diff, they must classify it into one of three distinct categories:
|
||||||
|
|
||||||
|
1. **Confirmed Violation**: Observable evidence proves the pattern actively damages correctness, testability, or maintainability (e.g., duplicate business logic causing divergent bugfixes, or unreadable obfuscated variable names).
|
||||||
|
2. **Potential Design Smell**: A pattern that warrants architectural inquiry and discussion, but whose harm depends on future evolution (e.g., a function taking six parameters that might benefit from a dedicated parameter struct).
|
||||||
|
3. **Contextual Trade-Off**: An intentional compromise where the author consciously accepted a local cost for a tangible engineering benefit (e.g., inlining logic in a script to keep it self-contained, or using primitive strings in a one-off parser to avoid premature type layers).
|
||||||
|
|
||||||
|
Reviewers must never demand refactoring for a contextual trade-off without demonstrating concrete harm.
|
||||||
|
|
||||||
|
## 2. Fowler Smell Diagnostics
|
||||||
|
|
||||||
|
| Heuristic | What to Look For | When It Is a Problem | When It Is Acceptable |
|
||||||
|
| :--- | :--- | :--- | :--- |
|
||||||
|
| **Primitive Obsession** | Using basic strings, numbers, or dicts for domain concepts (e.g. raw string for currency or unvalidated email). | When parsing, validation, and operations on that concept are duplicated across multiple call sites. | At external system boundaries, simple internal scripts, or when the concept has zero invariant behavior. |
|
||||||
|
| **Feature Envy** | A method or function that accesses data from another module more than its own. | When business rules belonging to Module B are scattered across callers in Module A. | When implementing intentional adapters, serialization mappers, or presentation formatters. |
|
||||||
|
| **Speculative Generality** | Interfaces, generics, hook points, or abstract classes added for hypothetical future needs. | When the abstraction adds indirection today for requirements that do not yet exist. | When building published public libraries with strict semver compatibility commitments. |
|
||||||
|
| **Shotgun Surgery** | A single logical feature change forces scattered micro-edits across many different files. | When related behavior is fragmented across unrelated modules instead of cohesive units. | Cross-cutting infrastructure updates (e.g. updating a dependency signature or logging framework). |
|
||||||
|
| **Divergent Change** | A single file or module is edited frequently for completely different business reasons. | When unrelated concerns (e.g. UI rendering, database persistence, and auth) live in one file. | Cohesive coordinating modules (such as application entrypoints or top-level routers). |
|
||||||
|
| **Mysterious Name** | Variables, functions, or types whose names obscure what they do. | When reading the code requires mental translation or leaves ambiguity about side effects. | Conventional short loop indexes (`i`, `j`) or well-understood mathematical terms in algorithmic loops. |
|
||||||
|
| **Repeated Switches** | Identical `if`/`else` or `match`/`switch` chains repeated across several functions on the same type. | When adding a new type variant requires editing every switch statement manually. | Simple two-branch checks or isolated dispatchers in serialization code. |
|
||||||
|
|
||||||
|
## 3. Commit Cohesion and Granularity
|
||||||
|
|
||||||
|
Commit size is a **diagnostic signal**, not an absolute rule.
|
||||||
|
|
||||||
|
- **The Goal**: Commits should represent cohesive, localizable units of work that can be understood, reviewed, and reverted independently if needed.
|
||||||
|
- **Diagnostic Threshold**: A commit touching more than 350 lines is a signal to inspect whether multiple concerns were bundled together (for example, combining data model types, UI rendering, and a mutation modal into a single commit).
|
||||||
|
- **Legitimate Exceptions**: Generated schemas, lockfile updates, broad renaming refactors, or database seed migrations often legitimately exceed 350 lines while remaining completely cohesive.
|
||||||
|
- **The True Anti-pattern**: Splitting a single atomic change into non-functional fragments, or conversely, combining unrelated feature work and opportunistic refactorings into one commit.
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
---
|
||||||
|
name: tdd
|
||||||
|
description: >-
|
||||||
|
Guides test-driven development through public interface seams using red-green
|
||||||
|
vertical slices, boundary-only mocking, and non-tautological assertions. Use
|
||||||
|
when the user types /tdd, asks for test-first implementation, requests a
|
||||||
|
failing reproduction test for a bug, or writes unit and integration tests. Do
|
||||||
|
not use for trivial fixes, styling, copy, declarative configuration, or
|
||||||
|
routine edits where test-first was not requested.
|
||||||
|
---
|
||||||
|
|
||||||
|
# Test-Driven Development
|
||||||
|
|
||||||
|
## Use when
|
||||||
|
- `/tdd`, or explicit requests for test-first implementation, red-green loops, or bug reproduction tests.
|
||||||
|
- Authoring or refactoring unit and integration tests around behavioral contracts.
|
||||||
|
- Not for trivial two-line fixes, copy, styling, declarative config, or pure wiring: edit directly instead.
|
||||||
|
- Not for pre-merge diff inspection (`code-review`) or live browser/deployment QA (`verify-slice`).
|
||||||
|
|
||||||
|
## Steps
|
||||||
|
1. **Check applicability.** Confirm the task introduces or changes observable logic at a testable boundary. If the change is trivial (typo, styling, static config, pure wiring) and `/tdd` was not explicitly requested, skip this skill and apply the change directly. Read project domain docs (`GLOSSARY.md` or local ADRs) if present so test and interface names match domain terms.
|
||||||
|
2. **Establish the public seam.** Identify the public interface where callers observe behavior without reaching into internals (see [seams-and-mocking](references/seams-and-mocking.md)). If the seam already exists and is unambiguous (such as adding a regression test to an established endpoint or function), proceed directly. Pause to confirm with the human owner only when introducing a new public interface, choosing between multiple candidate seams, or introducing test doubles.
|
||||||
|
3. **Write one failing tracer bullet (Red).** Write a focused test at the agreed seam describing *what* capability or invariant holds, not *how* internals work (see [test-quality](references/test-quality.md)). Derive expected values from an independent source of truth (known literals, worked domain examples, specification rules), never by mirroring the implementation's formula.
|
||||||
|
4. **Verify observable failure.** Run the targeted test command and confirm the test fails for the expected behavioral reason, not a syntax, import, or fixture setup error.
|
||||||
|
5. **Write the minimal implementation (Green).** Write only enough production code to make the failing test pass. Avoid speculative abstractions or untested branches.
|
||||||
|
6. **Cover negative, conflict, and boundary cases.** Once the happy-path slice passes, run additional red-to-green cycles for material failure modes (invalid inputs, conflict states such as `409`, timeouts, or state reconciliation invariants). Batch independent table-driven cases only after a vertical slice establishes the real contract.
|
||||||
|
7. **Clean up and hand off.** Remove duplication and clarify names while keeping the suite green, or defer broader structural cleanup to `code-review`.
|
||||||
|
|
||||||
|
## Your call
|
||||||
|
- **New seams and mock boundaries**: approve proposed public seams and any external mocks vs. real lightweight fixtures (such as an in-memory or temporary test database) before test authoring begins on new interfaces.
|
||||||
|
- **Coverage depth**: decide when edge-case and negative-path slices are sufficient for the risk level of the change.
|
||||||
|
|
||||||
|
## Done when
|
||||||
|
- Every targeted test was observed failing for the expected reason before passing, all tests verify public seams without tautological assertions, and the relevant test suite passes cleanly.
|
||||||
|
|
||||||
|
## Hands off to
|
||||||
|
- `code-review`: to inspect the resulting diff, code smells, defensive invariants, and test seam integrity.
|
||||||
|
- `verify-slice`: when the slice also needs live runtime, browser DOM, or multi-service verification.
|
||||||
|
- `diagnose`: when an unexpected test or fixture failure needs root-cause investigation.
|
||||||
|
- `git-commit`: to commit cohesive vertical slices.
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
# Public Seams and Boundary Mocking
|
||||||
|
|
||||||
|
Reference for `tdd`. Defines how to pick the test boundary, when to use real fixtures versus mocks, and how to shape interfaces so tests survive refactors.
|
||||||
|
|
||||||
|
Derived and adapted from Matt Pocock's `tdd` skill (`github.com/mattpocock/skills`), extended with cross-stack fixture and schema-integrity rules.
|
||||||
|
|
||||||
|
## 1. Choosing the Public Seam
|
||||||
|
|
||||||
|
A **seam** is the public interface where callers observe behavior without reaching into internal functions, private fields, or module wiring.
|
||||||
|
|
||||||
|
When proposing a new seam to the human owner, state two things in one line:
|
||||||
|
- **What it catches**: the behavioral contract verified through this boundary.
|
||||||
|
- **What it misses**: the outer integration layer left to `verify-slice` or higher-level tests.
|
||||||
|
|
||||||
|
| Stack | Typical Public Seam | Avoid Testing Directly |
|
||||||
|
| :--- | :--- | :--- |
|
||||||
|
| **Python API (FastAPI)** | HTTP route contract via `TestClient` / `AsyncClient` or domain service entrypoint | Private helper functions, ORM query-builder internals |
|
||||||
|
| **TypeScript UI** | Rendered component DOM + user events + typed API client boundary | Internal component state variables, private render helpers |
|
||||||
|
| **Rust CLI / Crate** | Public crate functions/traits or CLI command execution (`assert_cmd`) | Private module helpers, internal buffer representations |
|
||||||
|
|
||||||
|
## 2. Where to Mock (System Boundaries Only)
|
||||||
|
|
||||||
|
Mock or fake **external boundaries you do not control**:
|
||||||
|
- Third-party network services (payments, email, external webhooks, OAuth providers).
|
||||||
|
- Wall-clock time, timers, and randomness.
|
||||||
|
- External OS or hardware effects outside deterministic test control.
|
||||||
|
|
||||||
|
Prefer **real lightweight fixtures** over mocks whenever practical:
|
||||||
|
- Temporary or in-memory databases initialized through the real schema/migrations rather than mocked ORM sessions.
|
||||||
|
- Temporary directories (`tmp_path` in `pytest`, `tempfile::TempDir` in Rust) rather than mocked filesystem calls.
|
||||||
|
- Typed domain builders or service calls to seed state. Never maintain ad-hoc raw SQL seed strings that bypass migrations and silently drift from the real schema.
|
||||||
|
|
||||||
|
Never mock **collaborators you own**:
|
||||||
|
- Internal modules, domain services, formatters, or validators within the same codebase. If mocking an internal module feels necessary, the interface boundary is in the wrong place.
|
||||||
|
|
||||||
|
## 3. Shaping Interfaces for Clean Boundary Doubles
|
||||||
|
|
||||||
|
1. **Inject external dependencies explicitly**: Pass clocks, HTTP adapters, or external clients into functions/constructors rather than instantiating globals or reading environment variables inside domain logic.
|
||||||
|
2. **Use operation-specific adapter methods**: Prefer typed boundary methods (`api.getSession(id)`, `api.checkInAttendee(id)`) over a single generic `fetch(url, options)` mock. Operation-specific methods let each test stub one explicit response without reimplementing URL routing conditionals inside test setup.
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
# Test Quality and Anti-Patterns
|
||||||
|
|
||||||
|
Reference for `tdd`. Keeps red-to-green cycles anchored to observable behavior, independent truth, and real failure semantics.
|
||||||
|
|
||||||
|
Derived and adapted from Matt Pocock's `tdd` skill (`github.com/mattpocock/skills`), combined with empirical state-reconciliation and input-safety lessons.
|
||||||
|
|
||||||
|
## 1. Four Test Anti-Patterns to Reject
|
||||||
|
|
||||||
|
### A. Implementation-Coupled Tests
|
||||||
|
- **Smell**: Asserting `toHaveBeenCalledWith` on internal helpers, testing private functions, or verifying state through a side channel (raw table query) when a public read interface exists.
|
||||||
|
- **Tell**: The test breaks during an internal refactor even though caller-observable behavior is unchanged.
|
||||||
|
- **Fix**: Act through the public write seam and assert through the public read seam or rendered output.
|
||||||
|
|
||||||
|
### B. Tautological Assertions
|
||||||
|
- **Smell**: Recomputing the expected value with the same logic as production code, asserting a constant equals itself, or mocking a boundary to return `X` and only asserting `result == X`.
|
||||||
|
- **Tell**: A bug in the formula or contract would change both the code and the expected expression identically, keeping the test green.
|
||||||
|
- **Fix**: Use concrete literals, worked domain examples, or specification tables as an independent source of truth.
|
||||||
|
|
||||||
|
```python
|
||||||
|
# BAD: Recomputes expected value using the same arithmetic
|
||||||
|
def test_calculate_total():
|
||||||
|
items = [Item(price=10), Item(price=5)]
|
||||||
|
assert calculate_total(items) == sum(i.price for i in items)
|
||||||
|
|
||||||
|
# GOOD: Independent literal from worked example
|
||||||
|
def test_calculate_total_sums_item_prices():
|
||||||
|
assert calculate_total([Item(price=10), Item(price=5)]) == 15
|
||||||
|
```
|
||||||
|
|
||||||
|
### C. Optimistic Local-State Illusions
|
||||||
|
- **Smell**: Testing conflict or error recovery (such as HTTP `409 Conflict`) by asserting only that the clicked row changed locally, ignoring sibling records or aggregate counters that changed out-of-band on the server.
|
||||||
|
- **Fix**: Simulate authoritative server state where multiple records diverged out-of-band, and assert that both item state and aggregate counters reconcile with the authoritative read.
|
||||||
|
|
||||||
|
### D. Premature Horizontal Batching
|
||||||
|
- **Smell**: Writing twenty parameterized tests upfront against an imagined interface before one vertical slice works end-to-end.
|
||||||
|
- **Fix**: Drive one tracer-bullet test from Red to Green first so the real contract settles. Once the vertical slice works, batch independent boundary/edge cases (`pytest.mark.parametrize`, `test.each`, Rust table slices) where they clarify the contract without padding test count.
|
||||||
|
|
||||||
|
## 2. Negative and Defensive Slices Worth Adding
|
||||||
|
|
||||||
|
After the primary capability turns green, add focused red-to-green tests for the failure modes present in the slice:
|
||||||
|
- **Conflict and retry paths**: Duplicate submissions, `409` responses, network errors, and idempotent retries.
|
||||||
|
- **Untrusted input boundaries**: Special characters or HTML payloads (`<img src=x onerror=...>`) rendered safely as literal text rather than executable markup.
|
||||||
|
- **Empty and boundary values**: Zero items, maximum capacity limits, missing optional fields, and unauthorized callers.
|
||||||
Reference in new issue
Block a user