Skip to content
Back to skills

Coding

ASecurity

State preconditions, postconditions and invariants at module boundaries and make them runnable checks. Use at S03/S05 for level 1 code with logic, public module interfaces, or when a requirement says what must always hold.

  • 24 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added November 22, 2026
ai-agentspythonrustgojavatestingapidocumentation

Works with

  • api

Security analysis

A92/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro scans all 21 files and shows the line behind each finding

Scanned November 22, 2026

npx -y skills add andreibesleaga/GABBE --skill coding --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Coding?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Coding
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/andreibesleaga-coding-75b085c5/badge)](https://www.skillsdirectory.com/skills/andreibesleaga-coding-75b085c5)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: design-by-contract
description: State preconditions, postconditions and invariants at module boundaries and make them runnable checks. Use at S03/S05 for level 1 code with logic, public module interfaces, or when a requirement says what must always hold.
triggers: [design by contract, preconditions, postconditions, invariants, contract at boundary, icontract, assert contracts, module boundary checks]
tags: [coding, testing, contracts, verification]
core: false
context_cost: low
---
# Design by Contract

## Goal
Every public function at a module boundary says what it requires from the caller (precondition), what it guarantees (postcondition), and what stays true for its data (invariant). The statement is code that runs in tests and, where cheap, in production, so a broken promise fails at its source.

## Steps
1. List the boundaries: public functions, API handlers, queue consumers, anything another module or team calls. Done when each has a name.
2. For each, write the three clauses in plain words, taken from the EARS requirement or the spec (S03): "requires amount > 0", "ensures balance_after = balance_before - amount", "invariant balance >= 0". A clause with no requirement behind it is marked "proposed" for the human.
3. Choose the mechanism for the language (checked 2026-11-21):

| Language | Option | Notes |
|---|---|---|
| Python | `icontract` (`pip install icontract`) | `@icontract.require(lambda x: x > 0)`, `@icontract.ensure(lambda result, x: result > x)`, `@icontract.invariant(lambda self: self.x > 0)`; a breach raises `icontract.errors.ViolationError` |
| Python | `deal` (`pip install 'deal[all]'`) | `@deal.post`, `@deal.pure`; `deal.cases(f)` makes a test from the contract; `python3 -m deal lint` and `python3 -m deal test` |
| Java | JML, checked by OpenJML | OpenJML does runtime assertion checking and static verification; take its commands from openjml.org/documentation |
| Any other | guard clause at entry, assertion at exit, invariant method called after each mutator | plain `assert` or an explicit `throw`; no library needed |

4. Write the clauses as code next to the function. Keep each clause side-effect free and cheap.
5. Write one test per clause that breaks it on purpose and expects the failure (precondition: bad argument fails; postcondition: a stub returning a wrong result is caught). Done when each clause has a test that fails when the clause is removed.
6. Decide what stays on in production: cheap preconditions at trust boundaries stay on; expensive postconditions and invariants run in tests and staging. Write the choice in the plan.
7. Feed the contracts to property tests: a precondition is the generator's domain, a postcondition is the assertion (`pbt-strategy.skill.md`).

## Constraints
- Clauses are side-effect free and cheap.
- Every clause traces to a requirement or is marked "proposed" for the human.

## Output Format
Contract code beside each boundary function, one test per clause, and a note in the plan stating which checks stay on in production.

## Limits and safety
- Contracts at a boundary check one call; they do not prove the system. They find faults only when a test drives the code.
- Do not put validation of untrusted input in a contract that production builds strip; use real input validation there.
- Never weaken a clause to make a failing test pass; a failing contract is a finding to fix or to take to the human.
- Debug-only checks (assert statements) can be disabled by the runtime; state in the plan which checks run in production.

Files in this skill

  • agent-trajectory-eval.skill.md4.6 KB
  • artisan-commands.skill.md2.3 KB
  • assurance-ladder.skill.md5 KB
  • browser-tdd.skill.md5.4 KB
  • chaos-fault-injection.skill.md7 KB
  • characterization-tests.skill.md4.3 KB
  • ci-autofix.skill.md2.8 KB
  • clean-coder.skill.md2.8 KB
  • code-review.skill.md4.2 KB
  • debug.skill.md4.6 KB
  • design-by-contract.skill.md3.5 KB
  • documentation.skill.md5.2 KB
  • eval-driven-development.skill.md5.5 KB
  • evals/code-review.eval.yaml1 KB
  • excalidraw.skill.md3.7 KB
  • file-processing.skill.md2.5 KB
  • formal-spec-lightweight.skill.md3.9 KB
  • fuzz-differential-testing.skill.md3.9 KB
  • git-workflow.skill.md5.4 KB
  • incremental-feature.skill.md3.6 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.