Files
distributor/docs/internal/state.md

55 lines
2.7 KiB
Markdown
Raw Normal View History

# Destination State Internals
Audience: developers and LLM coding agents changing `internal/state`.
2026-05-31 02:13:58 +00:00
## Purpose
`internal/state` parses, validates, serializes, and compares `.distributor.json` destination state.
2026-05-31 02:13:58 +00:00
## Inputs And Outputs
2026-05-31 02:13:58 +00:00
Inputs are destination state JSON, constructed state values, current source manifest, pipeline id, destination id, and whether the destination path has content without state. Outputs are validated state values, JSON bytes, comparison outcomes, and human-readable reasons.
2026-05-31 02:13:58 +00:00
## Boundaries
2026-05-31 02:13:58 +00:00
The package does not inspect storage backends, mutate files, choose transfer policy, build publish outputs, generate URLs, or parse config. Publish planning consumes state comparison outcomes.
2026-05-31 02:13:58 +00:00
The external destination state contract is documented in `docs/integrations/destination-state.md`.
2026-05-31 02:13:58 +00:00
## Config Fields Used
2026-05-31 02:13:58 +00:00
None directly. Destination ids, pipeline ids, and link URLs originate from config but are supplied as values by callers.
2026-05-31 02:13:58 +00:00
## Adapters Used
2026-05-31 02:13:58 +00:00
None.
2026-06-01 21:42:00 +00:00
## State And Manifest Behavior
2026-05-31 02:13:58 +00:00
`.distributor.json` schema version is `1`. Required fields are `pipeline_id`, `destination_id`, `published_at`, `source.manifest`, and `outputs`. `distributor_version` and `links` are optional.
2026-05-31 02:13:58 +00:00
Embedded source manifests are parsed and validated through `internal/bundle`, which delegates source manifest semantics to `pkg/bundle`. Output records require clean paths, `source` or `generated` kind, valid source paths, lowercase SHA-256 digests, non-negative sizes, and transform ids for generated outputs. Stored URLs must pass `internal/link` validation.
2026-05-31 02:13:58 +00:00
## Skip And Resume Behavior
2026-05-31 04:06:48 +00:00
Comparison is pure. It returns outcomes for absent state, unmanaged content, invalid state, pipeline/destination mismatch, same source manifest, older destination, newer destination, same-created digest conflict, and different source id conflict. It does not decide whether to skip, replace, force, or fail; publish planning maps outcomes to actions.
2026-05-31 04:06:48 +00:00
## Failure Behavior
2026-05-31 02:13:58 +00:00
Parsing rejects invalid JSON, trailing data, missing required fields, invalid timestamps, invalid embedded manifests, duplicate outputs, invalid output paths, unsupported output kinds, missing generated transforms, invalid URLs, invalid digests, and negative sizes.
2026-05-31 02:13:58 +00:00
## Tests To Inspect
2026-05-31 02:13:58 +00:00
- `internal/state/distributor_test.go`
- `internal/state/compare_test.go`
- `internal/publish/*_test.go`
2026-05-31 04:06:48 +00:00
## Architectural Invariants
2026-05-31 04:06:48 +00:00
- `.distributor.json` is the destination sentinel and state record.
- Comparison does not mutate storage.
- Embedded source manifests use the source bundle contract.
2026-05-31 04:06:48 +00:00
- Generated outputs always record a transform id.
2026-06-01 21:42:00 +00:00
- Stored URLs are optional and must be absolute HTTP or HTTPS URLs when present.
2026-05-31 04:06:48 +00:00
- `distributor_version` is diagnostic metadata, not a comparison key.