Define Promptkit library policies and architecture
This commit is contained in:
@@ -2,12 +2,23 @@
|
||||
|
||||
## Purpose
|
||||
|
||||
This is the inventory of this application's implemented components for contributors.
|
||||
The [architecture policy](../policy/architecture.md) owns normative boundaries
|
||||
and invariants; public behavior belongs in the linked contracts.
|
||||
This document inventories Promptkit's implemented components for contributors.
|
||||
The [architecture policy](../policy/architecture.md) owns durable boundary and
|
||||
dependency rules. See the [development guide](../development.md) for
|
||||
contributor workflow and validation.
|
||||
|
||||
TODO: Add tables below, using the following format:
|
||||
## Implemented Components
|
||||
|
||||
| Component | Implemented responsibility | References |
|
||||
| --- | --- | --- |
|
||||
| | | |
|
||||
| Root `promptkit` package | Establishes the public package boundary for the Go module. It does not yet provide migrated framework behavior or exported APIs. | [Package declaration](../../doc.go) |
|
||||
|
||||
The root `promptkit` package is the sole implemented Go package. No internal
|
||||
framework packages exist yet.
|
||||
|
||||
## Maintenance
|
||||
|
||||
Update this inventory as framework extraction introduces packages or changes
|
||||
component responsibilities. List only implemented components; proposed package
|
||||
boundaries belong in temporary planning documents until their implementation
|
||||
lands.
|
||||
|
||||
@@ -1,13 +1,118 @@
|
||||
# Architecture
|
||||
# Architecture Policy
|
||||
|
||||
This document defines the intended high-level architecture of this application and the
|
||||
invariants that changes must preserve. Implemented component details belong in
|
||||
[Internal Overview](../internal/overview.md) and its linked documents. The
|
||||
reasoning behind significant architectural choices belongs in
|
||||
[ADRs](../adr/).
|
||||
## Purpose
|
||||
|
||||
This document defines Promptkit's current high-level architecture and the
|
||||
durable boundaries that implementation changes must preserve. The
|
||||
[internal component overview](../internal/overview.md) inventories concrete
|
||||
implemented packages without redefining these rules.
|
||||
|
||||
## System Shape
|
||||
|
||||
This application is a small, dependency-light Go application for ...
|
||||
Promptkit is an importable Go library. It does not provide a runnable command,
|
||||
an HTTP service, or another application process.
|
||||
|
||||
TODO: Complete this document.
|
||||
The module root contains package `promptkit`, which is the public facade and the
|
||||
only implemented Go package in the current repository foundation. It declares
|
||||
the module's public package boundary but does not yet provide migrated framework
|
||||
behavior or exported APIs. No internal framework packages currently exist.
|
||||
|
||||
Future framework extraction must follow this dependency direction:
|
||||
|
||||
```text
|
||||
downstream consumers, including Scriptorium
|
||||
|
|
||||
v
|
||||
root promptkit public facade
|
||||
|
|
||||
v
|
||||
internal framework components
|
||||
|
|
||||
v
|
||||
narrow injected abstractions
|
||||
```
|
||||
|
||||
The facade may coordinate internal components. Internal components must depend
|
||||
on narrow abstractions for behavior supplied from outside the library; they
|
||||
must not depend on consumers or on Scriptorium. This diagram constrains future
|
||||
work and does not assert that the internal components already exist.
|
||||
|
||||
## Repository And Consumer Boundary
|
||||
|
||||
Scriptorium is a downstream application that will consume Promptkit through
|
||||
the supported public facade. It is not a Promptkit package and must not become
|
||||
an internal dependency.
|
||||
|
||||
Promptkit owns reusable, application-neutral library behavior. It does not own:
|
||||
|
||||
- binaries or executable packaging;
|
||||
- CLI commands, parsing, streams, or exit codes;
|
||||
- HTTP routes, servers, request DTOs, status mapping, or deployment policy;
|
||||
- application configuration discovery or precedence;
|
||||
- process lifecycle, operational state, or application logging; or
|
||||
- consumer-specific filesystem or security policy.
|
||||
|
||||
Those concerns remain with Scriptorium or another consuming application.
|
||||
|
||||
## Package Ownership
|
||||
|
||||
The module root is the supported public facade. Framework implementation
|
||||
packages belong under Go's `internal/` boundary unless a demonstrated, stable
|
||||
consumer contract requires a public package.
|
||||
|
||||
Each package must have one cohesive responsibility and a clear dependency
|
||||
direction. Internal packages must not expose their types merely to simplify
|
||||
wiring, and the public facade must not leak internal representations through
|
||||
exported signatures. New public packages require a durable consumer need that
|
||||
cannot be served cleanly by the root facade.
|
||||
|
||||
The [internal component overview](../internal/overview.md) must be updated as
|
||||
packages are implemented or their responsibilities change.
|
||||
|
||||
## Exported API Discipline
|
||||
|
||||
Export the smallest contract required by real consumers. Exported declarations
|
||||
must have accurate GoDoc, stable semantics, and tests proportionate to their
|
||||
compatibility risk. Avoid speculative extension points, aliases for internal
|
||||
types, and public constructors that expose assembly details.
|
||||
|
||||
Once an exported API exists, its Go declaration and GoDoc own its exact public
|
||||
contract. Architecture documentation owns boundary rules, not a duplicate API
|
||||
reference.
|
||||
|
||||
## Error Boundaries
|
||||
|
||||
Internal failures must cross the public facade as errors meaningful to a Go
|
||||
consumer without exposing private package types or transport-specific policy.
|
||||
Wrapping should add useful context while preserving any public error identity
|
||||
needed with `errors.Is` or `errors.As`.
|
||||
|
||||
Promptkit must not assign CLI exit codes or HTTP status codes. Consumers map
|
||||
public library outcomes into their own transport behavior.
|
||||
|
||||
## Dependency Injection
|
||||
|
||||
External effects and consumer-selected policy must enter through narrow
|
||||
interfaces or functions at the boundary that uses them. Dependencies should be
|
||||
explicitly supplied during construction or invocation rather than read from
|
||||
consumer configuration or hidden process-global state.
|
||||
|
||||
Interfaces should be owned by the code that consumes the behavior and should
|
||||
contain only the operations that code requires. Provide defaults only for
|
||||
application-neutral behavior; consumer-specific restrictions and adapters
|
||||
remain injected from the consuming project.
|
||||
|
||||
## Repository Independence
|
||||
|
||||
Promptkit must build, test, and validate independently of Scriptorium. Do not
|
||||
commit `go.work`, `go.work.sum`, or a local filesystem `replace` directive.
|
||||
Temporary workspace or replacement configuration may support coordinated local
|
||||
development, but it is not part of either repository's architecture or release
|
||||
state.
|
||||
|
||||
## Current-State Maintenance
|
||||
|
||||
This policy distinguishes present implementation from constraints on future
|
||||
framework extraction. Do not list planned packages as implemented components.
|
||||
When extraction introduces a package, update the internal inventory and the
|
||||
owning contract or subsystem document in the same change.
|
||||
|
||||
@@ -2,112 +2,115 @@
|
||||
|
||||
## Purpose
|
||||
|
||||
This policy assigns each documentation topic to one canonical owner. Its goal is
|
||||
to keep this application's documentation accurate, concise, discoverable, and resistant
|
||||
to drift for users, operators, developers, integrators, and LLM coding agents.
|
||||
This policy assigns each Promptkit documentation topic to one canonical owner.
|
||||
Its goal is to keep documentation for this reusable Go library accurate,
|
||||
concise, discoverable, and resistant to drift for consumers, contributors,
|
||||
maintainers, integrators, and coding agents.
|
||||
|
||||
## Core Rules
|
||||
|
||||
### One Canonical Owner
|
||||
|
||||
Each authoritative fact belongs in one document. A non-owning document may give
|
||||
a short, stable summary for orientation, but it must link to the canonical owner
|
||||
instead of repeating volatile details.
|
||||
Each authoritative fact belongs in one document or source form. A non-owning
|
||||
document may give a short, stable summary for orientation, but it must link to
|
||||
the canonical owner instead of repeating exact contracts.
|
||||
|
||||
Volatile details include commands, flags, configuration fields and defaults,
|
||||
module keys, schemas, file names, paths, status codes, retry behavior, and
|
||||
runtime guarantees. If readers could reasonably treat a statement as a
|
||||
contract, maintain it only in the owning document.
|
||||
Volatile details include exported declarations, accepted inputs, defaults,
|
||||
schemas, file names, paths, error identities, retry behavior, and runtime
|
||||
guarantees. If readers could reasonably treat a statement as a contract,
|
||||
maintain its exact definition only in the owning source.
|
||||
|
||||
### Current And Future Behavior
|
||||
### Current State, Decisions, And Future Work
|
||||
|
||||
Outside `docs/roadmap/`, documentation describes implemented behavior only.
|
||||
Partial features may be described only to their implemented boundary.
|
||||
|
||||
ADRs are the narrow exception: an ADR may record an accepted architectural
|
||||
decision before implementation, but acceptance must not be presented as proof
|
||||
that the behavior exists. The roadmap owns implementation status and sequencing
|
||||
until the decision is implemented. Current architecture, user, operator,
|
||||
integration, and internal documentation are updated when the behavior lands.
|
||||
An accepted architecture decision may describe an approved direction before it
|
||||
is implemented, but acceptance is not evidence that the behavior exists.
|
||||
Current-state documents change when the implementation lands. Temporary
|
||||
roadmaps own future work, sequencing, and implementation status; they do not
|
||||
replace durable policies or current contracts.
|
||||
|
||||
### Audience And Detail
|
||||
|
||||
Write for the document's stated audience and include only the detail needed for
|
||||
its owned topic. User and operator docs should not expose implementation detail.
|
||||
Developer docs should link to user-facing and external contracts rather than
|
||||
restate them.
|
||||
its owned topic. Consumer guidance should not expose incidental implementation
|
||||
detail. Contributor documentation should link to public contracts and durable
|
||||
policies instead of restating them.
|
||||
|
||||
### Examples
|
||||
### Links
|
||||
|
||||
Complete copyable files belong in `examples/`. Documentation may use the
|
||||
smallest illustrative snippet needed to explain its owned topic, but should link
|
||||
to maintained examples instead of embedding a second complete copy.
|
||||
Use descriptive link text and repository-relative links for repository
|
||||
documents. Link to the canonical owner rather than to a duplicate summary.
|
||||
Check every added or changed link and repair or remove links when their target
|
||||
moves or is retired.
|
||||
|
||||
Examples must be valid, secret-free, and tested where practical. Commands and
|
||||
configuration used in documentation should match the application.
|
||||
### Examples And Code Fences
|
||||
|
||||
Complete copyable files belong in `examples/` when maintained examples exist.
|
||||
Documentation may use the smallest illustrative snippet needed for its owned
|
||||
topic, but should link to a maintained example instead of embedding a second
|
||||
complete copy.
|
||||
|
||||
Examples must be valid, secret-free, and tested where practical. Commands,
|
||||
imports, and Go snippets must match the implemented library. Use a language tag
|
||||
on fenced code blocks and make clear when a fragment is illustrative rather
|
||||
than directly runnable.
|
||||
|
||||
### Security And Privacy
|
||||
|
||||
Documentation and examples must not contain real credentials, private keys,
|
||||
private environment dumps, sensitive source material, or private infrastructure
|
||||
details unless intentionally public. Document secret-handling mechanisms, not
|
||||
secret values.
|
||||
private environment dumps, sensitive source material, or private
|
||||
infrastructure details unless intentionally public. Document secret-handling
|
||||
mechanisms, not secret values.
|
||||
|
||||
## Canonical Ownership
|
||||
|
||||
| Topic | Canonical owner | Owned content | Content owned elsewhere |
|
||||
| --- | --- | --- | --- |
|
||||
| Product orientation and minimal end-to-end quickstart | `README.md` | What this application is, why it is useful, one shortest successful invocation, and links onward. | Complete command reference, configuration reference, operational procedures, implementation detail. |
|
||||
| Contributor entry point | `docs/development.md` | Task-oriented reading guide, minimal contributor orientation, baseline validation commands, and links to canonical docs. | Package inventory, architecture rules, subsystem behavior, detailed change recipes. |
|
||||
| Current application architecture | `docs/policy/architecture.md` | System shape, normative ownership, dependency direction, architectural boundaries, invariants, safety properties, and non-goals. | Concrete package inventory, implementation mechanics, contributor procedures, decision history, future work. |
|
||||
| Documentation organization | `docs/policy/documentation.md` | Documentation ownership, audience boundaries, maintenance rules, and ADR/document lifecycle. | Application architecture or product behavior. |
|
||||
| Testing policy | `docs/policy/testing.md` | Test philosophy, risk-based sufficiency, test boundaries, doubles, coverage guidance, regression-test policy, and criteria for adding, rewriting, or deleting tests. | Subsystem behavior, application contracts, subsystem-specific test inventories, and implementation plans. |
|
||||
| CLI contract | `docs/cli.md` | Commands, arguments, flags, invocation semantics, and exit codes. | End-to-end operating procedures, configuration field definitions, runtime filesystem layout, module implementation details. |
|
||||
| Configuration contract | `docs/config.md` | Discovery and precedence, file schema, fields, defaults, environment overrides, validation rules, and user-selectable module or validator keys. | Complete example files, CLI syntax, runtime state lifecycle, module implementation details. |
|
||||
| Operations | `docs/operations.md` | Runtime workflows, physical filesystem and state layout, output, cache, and debug handling, resume, cleanup, permissions, recovery, and operational limits. | CLI flag syntax, configuration field definitions, logical output schemas, implementation mechanics. |
|
||||
| Public HTTP contract, if introduced | `docs/api.md` | Routes, authentication, media types, request and response schemas, status codes, pagination, caching, idempotency, rate limits, and HTTP retry semantics. | Client walkthroughs, upstream or downstream integration internals, implementation detail. |
|
||||
| Consumer guidance, if a public package or API is introduced | `docs/consumers/` | Task-oriented use of the public interface, minimal client examples, and consumer responsibilities. | HTTP wire semantics, external protocol contracts, internal implementation detail. |
|
||||
| External and durable integration contracts | `docs/integrations/` | External file formats and protocols, upstream and downstream contracts, logical output bundle paths and schemas, media types, and compatibility behavior. | Physical runtime placement and lifecycle, internal transformations, CLI syntax, configuration defaults. |
|
||||
| Implemented component inventory | `docs/internal/overview.md` | Current packages and components, their implemented responsibilities, and links to focused internal docs. | Normative architecture, contributor reading policy, external contracts. |
|
||||
| Internal component behavior | Other files under `docs/internal/` | Implementation flow, internal collaborators and state transitions, package-local guarantees and failures, and relevant tests. | Global architecture invariants, configuration definitions and defaults, external schemas, operator procedures. |
|
||||
| Architectural decision history | `docs/adr/` | Significant decisions, context, alternatives, rationale, consequences, and supersession history. | Current behavior reference, implementation status, task sequencing. |
|
||||
| Future work and implementation status | `docs/roadmap/` | Proposed, accepted, deferred, or rejected work; implementation status; sequencing; and task breakdowns. | Implemented behavior reference and architectural decision rationale. |
|
||||
| Complete copyable artifacts | `examples/` | Maintained configuration, inputs, and other files intended to be copied or run. | Field-by-field reference, command reference, prose explanation. |
|
||||
| Project orientation | `README.md` | What Promptkit is, its current usability, module identity, license summary, and links onward. | Exact API contracts, contributor procedures, architecture detail, and release steps. |
|
||||
| Contributor workflow | `docs/development.md` | Task-oriented reading guide, local workflow, validation commands, and repository hygiene. | Architecture rules, API semantics, subsystem behavior, and release procedure. |
|
||||
| Current architecture | `docs/policy/architecture.md` | System shape, normative ownership, dependency direction, package boundaries, invariants, and non-goals. | Concrete component inventory, implementation mechanics, contributor procedures, decision history, and future work. |
|
||||
| Documentation organization | `docs/policy/documentation.md` | Documentation ownership, audience boundaries, maintenance rules, and document lifecycle. | Library architecture or runtime behavior. |
|
||||
| Testing policy | `docs/policy/testing.md` | Test philosophy, risk-based sufficiency, test boundaries, doubles, coverage guidance, regression policy, and test maintenance. | Subsystem behavior, exact public contracts, subsystem-specific test inventories, and implementation plans. |
|
||||
| Release procedure | `docs/release.md`, when present | Required release validation, version and tag procedure, release ordering, and post-publication checks. | General contributor workflow, public API semantics, and decision history. |
|
||||
| Exact exported Go API | Go declarations and GoDoc, as APIs are implemented | Exported names, signatures, types, values, errors, and exact behavioral contracts. | Task-oriented consumer walkthroughs, implementation details, and future API proposals. |
|
||||
| Consumer guidance | `docs/consumers/`, when consumer workflows require dedicated guidance | Task-oriented use of implemented public APIs, minimal examples, and consumer responsibilities. | Exact exported declarations and internal mechanics. |
|
||||
| Durable integration contracts | `docs/integrations/`, when integrations exist | External formats and protocols, compatibility behavior, and upstream or downstream responsibilities. | Internal transformations and public Go declarations. |
|
||||
| Implemented component inventory | `docs/internal/overview.md` | Current packages and components, their implemented responsibilities, and links to focused internal documents. | Normative architecture, contributor workflow, external contracts, and proposed components. |
|
||||
| Internal subsystem behavior | Other files under `docs/internal/`, when a subsystem needs durable detail | Implementation flow, internal collaborators and state transitions, package-local guarantees and failures, and relevant tests. | Global architecture invariants, public API definitions, and future package plans. |
|
||||
| Architectural decision history | `docs/adr/`, when repository-local decisions require records | Significant decisions, context, alternatives, rationale, consequences, and supersession history. | Current behavior reference, implementation status, and task sequencing. |
|
||||
| Temporary feature roadmaps | `docs/roadmap/`, while planned work needs coordination | Proposed or accepted scope, sequencing, gates, and implementation status. | Implemented behavior reference and durable decision rationale. |
|
||||
| Complete copyable artifacts | `examples/`, when maintained examples exist | Valid inputs, Go programs, and other files intended to be copied or run. | Field-by-field reference, exact API declarations, and prose explanation. |
|
||||
|
||||
Documents that do not exist are required only when the corresponding interface
|
||||
or responsibility exists. Do not create placeholder API, consumer, integration,
|
||||
or operations documents for behavior the application does not have.
|
||||
Conditional owners do not require placeholder files or directories. Create a
|
||||
consumer, integration, subsystem, ADR, roadmap, or example document only when
|
||||
the corresponding implemented interface, decision, planned effort, or
|
||||
maintained artifact exists.
|
||||
|
||||
## Boundary Rules
|
||||
|
||||
### Orientation
|
||||
|
||||
The README owns product orientation. The developer guide routes contributors.
|
||||
Architecture owns normative structure. Internal overview owns the current
|
||||
concrete component map. These documents may link to one another but should not
|
||||
maintain parallel package or behavior descriptions.
|
||||
The README owns project orientation. The development guide routes
|
||||
contributors. Architecture owns normative structure. The internal overview
|
||||
owns the current concrete component map. These documents may link to one
|
||||
another but must not maintain parallel package or behavior descriptions.
|
||||
|
||||
### Commands, Configuration, And Operations
|
||||
### Public Contracts And Implementation
|
||||
|
||||
CLI documentation answers how to invoke the application. Configuration
|
||||
documentation answers what settings mean. Operations answers what happens to
|
||||
runtime state and how to operate or recover the application. When a workflow
|
||||
crosses these topics, choose the document that owns the task and link to the
|
||||
other contracts.
|
||||
|
||||
### Contracts And Implementation
|
||||
|
||||
Integration and API documents define externally observable shapes and
|
||||
semantics. Internal documents explain how thos application implements or consumes those
|
||||
contracts. Internal docs may name a field, file, or protocol to identify a
|
||||
dependency, but must link to its canonical contract for the definition.
|
||||
Go declarations and GoDoc own exact exported API contracts once those APIs
|
||||
exist. Consumer and integration documents explain how to use those contracts
|
||||
for a task. Internal documents explain how Promptkit implements them. Internal
|
||||
documentation may identify a public type or external format as a dependency,
|
||||
but must link to its canonical definition rather than restate it.
|
||||
|
||||
### Security Topics
|
||||
|
||||
This policy owns what documentation and examples may contain. Architecture owns
|
||||
application security invariants. Configuration owns credential-supply
|
||||
mechanisms. Operations owns permissions and handling of sensitive runtime
|
||||
artifacts. Internal docs own implementation mechanisms only.
|
||||
library security boundaries and invariants. Public declarations and integration
|
||||
documents own consumer-visible security contracts. Internal documents own
|
||||
implementation mechanisms only.
|
||||
|
||||
## Architecture Decision Records
|
||||
|
||||
@@ -122,23 +125,44 @@ Use sequentially numbered ADR filenames such as
|
||||
6. alternatives considered;
|
||||
7. consequences.
|
||||
|
||||
Treat the decision content of an accepted ADR as immutable. When a decision
|
||||
changes, create a new ADR and update the earlier ADR's status to superseded.
|
||||
Rejected architectural alternatives belong in the ADR; rejected product ideas
|
||||
belong in the roadmap.
|
||||
Use one of these statuses:
|
||||
|
||||
## Maintenance
|
||||
- **Proposed:** the decision is under consideration and may change;
|
||||
- **Accepted:** the decision is approved, whether or not implementation is
|
||||
complete;
|
||||
- **Rejected:** the proposed decision was considered and not adopted;
|
||||
- **Superseded:** a later accepted ADR replaces the accepted decision.
|
||||
|
||||
When behavior changes, update its canonical owner in the same change. If
|
||||
ownership moves, remove the old definition and replace it with a link where
|
||||
navigation remains useful.
|
||||
A proposed ADR transitions to Accepted or Rejected. An Accepted ADR transitions
|
||||
to Superseded only when a later Accepted ADR replaces it. An ADR may be created
|
||||
as Accepted when the decision has already been made.
|
||||
|
||||
Treat the decision content of an Accepted ADR as immutable. A changed decision
|
||||
requires a later ADR rather than a rewrite of the accepted record. A Superseded
|
||||
ADR must link to its replacement, and the replacement must link back. Rejected
|
||||
architectural alternatives belong in the ADR; rejected feature ideas belong in
|
||||
a roadmap when they need to be retained.
|
||||
|
||||
## Document Lifecycle
|
||||
|
||||
Create durable current-state documentation with the implementation it
|
||||
describes. Update its canonical owner in the same change when behavior changes.
|
||||
If ownership moves, remove the old definition and leave a link where navigation
|
||||
remains useful.
|
||||
|
||||
Roadmaps are temporary coordination documents. When their work is complete,
|
||||
record completion, move any still-useful decisions or contracts to their
|
||||
durable owners, update incoming links, and archive or remove the roadmap
|
||||
according to repository practice. Do not preserve completed roadmaps as a
|
||||
second current-state reference.
|
||||
|
||||
Before completing documentation work:
|
||||
|
||||
- verify affected behavior and examples;
|
||||
- check commands, flags, fields, defaults, schemas, and paths against their
|
||||
implementation;
|
||||
- keep unimplemented behavior in the roadmap, subject to the ADR exception;
|
||||
- remove stale references and validate links;
|
||||
- confirm that non-owning documents summarize and link rather than redefine;
|
||||
- check commands, imports, declarations, defaults, schemas, and paths against
|
||||
their implementation;
|
||||
- keep unimplemented behavior in a roadmap, subject to the ADR exception;
|
||||
- validate links and fenced examples;
|
||||
- confirm non-owning documents summarize and link rather than redefine;
|
||||
- remove stale or unsupported claims; and
|
||||
- confirm that no secrets or sensitive private data were added.
|
||||
|
||||
@@ -14,7 +14,7 @@ A test must be:
|
||||
|
||||
- written and reviewed;
|
||||
- understood by future maintainers and coding agents;
|
||||
- executed in local and CI workflows;
|
||||
- executed in maintainer-run validation;
|
||||
- diagnosed when it fails;
|
||||
- updated when legitimate behavior changes;
|
||||
- maintained as fixtures, APIs, and dependencies evolve; and
|
||||
@@ -49,9 +49,40 @@ Examples of appropriate seams include clocks, randomness, subprocesses, remote A
|
||||
|
||||
## Test execution requirements
|
||||
|
||||
Tests in the default suite must be deterministic, offline, and independent of real credentials. They must not invoke paid APIs or depend on mutable external services. Tests that require live infrastructure must be explicitly opt-in and clearly separated from the default suite.
|
||||
Promptkit currently uses maintainer-run validation rather than hosted CI.
|
||||
Maintainers run the repository-documented test, vet, build, formatting,
|
||||
documentation-link, and repository-hygiene checks before accepting changes.
|
||||
Introducing hosted CI later would supplement, not silently redefine, this
|
||||
documented validation model.
|
||||
|
||||
Control clocks, randomness, environment variables, and other process-global or machine-specific state when they affect behavior. Tests should be safe to run repeatedly and alongside other tests without depending on execution order or state left by an earlier test.
|
||||
Tests in the default suite must be deterministic, offline, and independent of
|
||||
real credentials. They must not invoke paid APIs, use live network
|
||||
dependencies, or depend on mutable external services. Tests that require live
|
||||
infrastructure must be explicitly opt-in and clearly separated from the
|
||||
default suite.
|
||||
|
||||
Control clocks, randomness, environment variables, and other process-global or
|
||||
machine-specific state when they affect behavior. Tests must be parallel-safe:
|
||||
they should run repeatedly and alongside other tests without depending on
|
||||
execution order, shared mutable state, fixed ports, or state left by an earlier
|
||||
test.
|
||||
|
||||
## Test types and assets
|
||||
|
||||
Use each test type where it protects a distinct risk:
|
||||
|
||||
- Unit and package tests protect focused behavior and invariants through the
|
||||
narrowest stable boundary.
|
||||
- Contract tests protect exported behavior, compatibility, and error identity
|
||||
relied upon by consumers.
|
||||
- Integration tests use real collaborators when correctness depends on their
|
||||
interaction, while replacing live or nondeterministic external boundaries.
|
||||
- Fixtures should be minimal, synthetic, versioned with the behavior they
|
||||
exercise, and free of credentials or private data.
|
||||
- Golden files are appropriate only when the complete output is intentionally
|
||||
stable and semantic review of updates is practical.
|
||||
- Failure-path tests should cover consequential malformed input, dependency
|
||||
failure, cancellation, partial results, and recovery behavior.
|
||||
|
||||
## What deserves tests
|
||||
|
||||
@@ -63,7 +94,7 @@ Prioritize tests for:
|
||||
4. Failure handling, cancellation, retries, recovery, and partial success.
|
||||
5. Serialization, schemas, compatibility, and round trips.
|
||||
6. Previously observed or plausible regressions.
|
||||
7. Representative integration and end-to-end workflows.
|
||||
7. Representative integration and consumer workflows.
|
||||
|
||||
A package-level contract is behavior relied upon by another package or major collaborator, not every observable detail of a package implementation.
|
||||
|
||||
@@ -81,7 +112,9 @@ This is often the package API, but it may instead be:
|
||||
- a package-level operation when several internal collaborators jointly produce the behavior; or
|
||||
- a larger integration boundary when correctness emerges from interaction with a real dependency.
|
||||
|
||||
Do not force all behavior through oversized end-to-end tests. Do not test every private helper merely because it exists. Choose the boundary that gives durable confidence with the least incidental coupling.
|
||||
Do not force all behavior through oversized consumer-workflow tests. Do not
|
||||
test every private helper merely because it exists. Choose the boundary that
|
||||
gives durable confidence with the least incidental coupling.
|
||||
|
||||
## Test behavior, not implementation
|
||||
|
||||
@@ -165,10 +198,10 @@ Each behavior should have a clear test owner.
|
||||
- Parser tests own parsing cases.
|
||||
- Validator tests own validation rules.
|
||||
- Domain tests own transformations and invariants.
|
||||
- Adapter tests own external integration behavior.
|
||||
- Boundary tests own external integration behavior.
|
||||
- Orchestrator tests own coordination and failure propagation.
|
||||
- CLI tests own argument and configuration mapping.
|
||||
- End-to-end tests prove that representative assembled workflows work.
|
||||
- Consumer-workflow tests prove that representative assembled library use
|
||||
works.
|
||||
|
||||
Higher-level tests should not repeat every lower-level case. A single intentional policy change should not require unrelated edits across many test files.
|
||||
|
||||
@@ -205,13 +238,17 @@ Use:
|
||||
- fuzz tests for parsers, normalization, path handling, and broad input spaces;
|
||||
- golden files only when the complete output is intentionally stable;
|
||||
- integration tests where correctness depends on component interaction; and
|
||||
- a small number of representative end-to-end tests.
|
||||
- a small number of representative consumer-workflow tests.
|
||||
|
||||
Avoid exact error-string assertions unless the wording is itself contractual. Prefer `errors.Is`, `errors.As`, typed errors, or structured error fields.
|
||||
|
||||
At CLI boundaries, prefer exit classifications, structured output, and the smallest stable semantic fragment needed to identify the error. Do not snapshot complete diagnostic wording unless it is contractual.
|
||||
At public API boundaries, prefer stable error identity, structured values, and
|
||||
the smallest semantic fragment needed to identify the failure. Do not snapshot
|
||||
complete diagnostic wording unless it is contractual.
|
||||
|
||||
Golden-file updates must require an explicit local flag. CI must not update golden files automatically, and reviewers must inspect the semantic diff before accepting an update.
|
||||
Golden-file updates must require an explicit local flag. Ordinary validation
|
||||
runs must never update golden files automatically, and maintainers must inspect
|
||||
the semantic diff before accepting an update.
|
||||
|
||||
Keep tests readable and direct. Test helpers and fixture frameworks must earn their own maintenance cost; do not build elaborate test infrastructure for small or isolated needs.
|
||||
|
||||
@@ -221,7 +258,8 @@ Coverage is a diagnostic, not a target.
|
||||
|
||||
Use it to find untested critical branches and unexpectedly weak packages. Do not write low-value tests solely to increase a percentage, and do not infer test quality from coverage alone.
|
||||
|
||||
Pure domain logic will often warrant higher coverage than CLI wiring or external adapters. Uneven coverage is acceptable when it reflects risk.
|
||||
Pure domain logic will often warrant higher coverage than facade wiring or
|
||||
external adapters. Uneven coverage is acceptable when it reflects risk.
|
||||
|
||||
Increasing coverage is valuable only when the newly covered behavior protects a meaningful risk at an acceptable cost.
|
||||
|
||||
@@ -289,7 +327,9 @@ A test suite is sufficient when:
|
||||
- legitimate internal changes usually do not require test edits; and
|
||||
- additional tests would mostly repeat existing protection or preserve inconsequential implementation details.
|
||||
|
||||
Sufficiency is a risk judgment, not a coverage percentage or test count. Reassess it as the application, its users, and the consequences of failure evolve.
|
||||
Sufficiency is a risk judgment, not a coverage percentage or test count.
|
||||
Reassess it as the library, its consumers, and the consequences of failure
|
||||
evolve.
|
||||
|
||||
The governing rule is:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user