Skip to main content
AI Generated Content
πŸ€– This documentation was generated with AI assistance. Please report any issues you find.

Versioning & Contracts

Pikku tracks the "contract" of each function β€” its name and input/output schemas β€” and detects when contracts change between releases. This prevents accidental breaking changes when multiple clients depend on your API.

How It Works​

  1. Each function's contract is hashed (function key + input schema + output schema β†’ 16-char hex hash)
  2. Hashes are stored in a version manifest (versions.json)
  3. On each build, the CLI compares current contracts against the manifest
  4. If a contract changed without a version bump, the build fails

Quick Start​

Initialize the manifest​

npx pikku versions-init

This creates versions.json with the current contract hashes for all your functions.

Check for breaking changes​

npx pikku versions-check

Compares current function contracts against the manifest. Fails if:

  • A published contract was modified (input/output schema changed)
  • A version bump is required but not applied

Update the manifest​

npx pikku versions-update

Records the current contracts into the manifest. Run this after bumping function versions.

Version Manifest​

The manifest file (versions.json) tracks contract history:

{
"manifestVersion": 1,
"contracts": {
"createTodo": {
"latest": 1,
"versions": {
"1": "a1b2c3d4e5f6g7h8"
}
},
"getTodos": {
"latest": 2,
"versions": {
"1": "i9j0k1l2m3n4o5p6",
"2": "q7r8s9t0u1v2w3x4"
}
}
}
}

Each function entry contains:

  • latest β€” The current version number
  • versions β€” A map of version numbers to contract hashes

Versioning Rules​

The contract system enforces strict rules:

RuleDescription
ImmutabilityPublished version hashes cannot change
Sequential versioningNew versions must be latest + 1
No gapsCannot skip version numbers (e.g., 1 β†’ 3)
Change detectionModified contracts require a version bump
Manifest consistencyThe latest field must match the highest version key

Contract Hashes​

A contract hash is computed from:

  • The function key (name)
  • The input JSON schema
  • The output JSON schema

If any of these change, the hash changes, indicating a potentially breaking modification.

Error Codes​

CodeNameDescription
PKU860MANIFEST_MISSINGVersion manifest not found β€” run versions-init
PKU861FUNCTION_VERSION_MODIFIEDContract hash changed for an existing version (immutable)
PKU862CONTRACT_CHANGED_REQUIRES_BUMPLatest contract changed without a version bump
PKU863VERSION_REGRESSION_OR_CONFLICTNew version is ≀ latest but not in the manifest
PKU864VERSION_GAP_NOT_ALLOWEDVersion skips a number (e.g., 1 β†’ 3)
PKU865MANIFEST_INTEGRITY_ERRORlatest field doesn't match the highest version key

CI Integration​

Add contract checking to your CI pipeline to catch breaking changes before they're deployed:

# GitHub Actions example
- name: Check API contracts
run: npx pikku versions-check

If a function's input or output schema changed, the check fails and the developer must explicitly bump the version number β€” making breaking changes intentional rather than accidental.

Workflow​

  1. Develop β€” Change function inputs/outputs as needed
  2. Check β€” npx pikku versions-check detects the contract change
  3. Bump β€” Increment the function's version number
  4. Update β€” npx pikku versions-update records the new contract
  5. Commit β€” Check in the updated versions.json