Files
distributor/docs/internal/ingest.md

52 lines
2.5 KiB
Markdown
Raw Normal View History

2026-06-03 15:05:56 +00:00
# Ingestion Internals
Audience: developers and LLM coding agents changing `internal/ingest`.
2026-06-03 15:05:56 +00:00
## Purpose
`internal/ingest` validates upload content types, extracts uploaded source bundle archives into local temporary storage, validates extracted bundles, and commits accepted bundles to per-run staging directories.
## Inputs And Outputs
2026-06-03 15:05:56 +00:00
Inputs are a context, upload body reader, content type, pipeline staging path, run id, maximum uploaded size, maximum extracted size, and maximum file count. Output is a `StagedBundle` containing the committed local bundle root and parsed manifest.
2026-06-03 15:05:56 +00:00
## Boundaries
The package does not authenticate HTTP requests, manage upload queues, track upload status, publish destinations, load config, or start an HTTP server. Those responsibilities live in `internal/app`.
2026-06-03 15:05:56 +00:00
The HTTP API contract is documented in `docs/integrations/http-upload.md`.
2026-06-03 15:05:56 +00:00
## Config Fields Used
2026-06-03 15:05:56 +00:00
The package does not read config directly. The app layer passes effective values derived from `source.staging_path`, `source.max_upload_size`, and HTTP server defaults.
2026-06-03 15:05:56 +00:00
## Adapters Used
2026-06-03 15:05:56 +00:00
The package uses the local filesystem directly for temporary archive storage, extraction, validation, and final staging path promotion. It does not use the storage backend abstraction.
2026-06-03 15:05:56 +00:00
## State And Manifest Behavior
2026-06-03 15:05:56 +00:00
Accepted archives must contain exactly one root-level `manifest.json`. After extraction, the package validates the staged root through `pkg/bundle`, including manifest parsing, source path rules, file existence, regular-file checks, file sizes, file SHA-256 digests, and bundle digest.
2026-06-03 15:05:56 +00:00
## Skip And Resume Behavior
2026-06-03 15:05:56 +00:00
The package has no resume behavior. A successful call commits one complete staged bundle root. Failed calls remove temporary data created by that call.
2026-06-03 15:05:56 +00:00
## Failure Behavior
2026-06-03 15:05:56 +00:00
Failures include unsupported content type, unsafe run id, missing staging path, non-positive limits, oversize upload body, oversize extracted content, too many files, unsafe archive paths, duplicate files, nested manifests, unsupported tar entry types, gzip/tar read errors, bundle validation errors, and filesystem errors.
2026-06-03 15:05:56 +00:00
## Tests To Inspect
2026-06-03 15:05:56 +00:00
- `internal/ingest/archive_test.go`
- `internal/app/upload_*_test.go`
- `pkg/bundle/*_test.go`
2026-06-03 15:05:56 +00:00
## Architectural Invariants
2026-06-03 15:05:56 +00:00
- Invalid archives never commit a staged root.
- Archive paths remain clean relative slash-separated paths.
- Only directories and regular files are accepted from tar archives.
- Source bundle validation happens before final staging path promotion.
- Upload authentication and queueing remain outside this package.