From 7c2a86a37fd2cc9e7682fe8183c908516f7b698f Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Sat, 28 Nov 2026 17:00:57 -0500 Subject: [PATCH 1/9] Move docproc's dependencies and pins to their latest cmd/docproc requires go-core v0.14.0, from v0.12.0. Neither v0.13.0's breaking change, EventKind.Raise taking a trailing event.RaiseOptions, nor v0.14.0's new sse package reaches cmd/docproc, which raises no event, so the bump needs no adaptation. cmd/docproc's CHANGELOG is unchanged: its prior entries name a dependency only when it requires the next base release. docproc-mail and docproc-onenote move to Rust 1.100.1 and cargo-deny 0.22.2. Their CHANGELOGs are unchanged, as the toolchain is not their output contract. picture.LibreOfficeImage moves to gotenberg/gotenberg 9.10.3-libreoffice, pinned by its multi-arch index digest from crane, with an Unreleased entry in the base CHANGELOG. The integration tier was not run against the new image. The workflows move to jdx/mise-action v5.4.0. MimeKit, MsgKit, and typed-path stay held with their hold reasons; currency reports only them. --- .github/workflows/ci.yml | 10 +++++----- .github/workflows/release.yml | 2 +- CHANGELOG.md | 5 +++++ cmd/docproc/go.mod | 2 +- cmd/docproc/go.sum | 4 ++-- picture/spec.go | 4 ++-- tools/mail/mise.toml | 4 ++-- tools/onenote/mise.toml | 4 ++-- 8 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9268816..566f301d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -91,7 +91,7 @@ jobs: steps: - uses: actions/checkout@v7.0.1 - - uses: jdx/mise-action@v5.3.0 + - uses: jdx/mise-action@v5.4.0 with: install_args: actionlint shellcheck github:standards-lab/claude-plugins @@ -110,7 +110,7 @@ jobs: steps: - uses: actions/checkout@v7.0.1 - - uses: jdx/mise-action@v5.3.0 + - uses: jdx/mise-action@v5.4.0 with: install_args: go golangci-lint @@ -144,7 +144,7 @@ jobs: if: hashFiles(format('tools/{0}/*.slnx', matrix.tool)) != '' run: sudo apt-get update && sudo apt-get install -y --no-install-recommends clang zlib1g-dev - - uses: jdx/mise-action@v5.3.0 + - uses: jdx/mise-action@v5.4.0 with: working_directory: tools/${{ matrix.tool }} @@ -187,7 +187,7 @@ jobs: steps: - uses: actions/checkout@v7.0.1 - - uses: jdx/mise-action@v5.3.0 + - uses: jdx/mise-action@v5.4.0 with: install_args: go @@ -216,7 +216,7 @@ jobs: - name: Install the NativeAOT prerequisites run: sudo apt-get update && sudo apt-get install -y --no-install-recommends clang zlib1g-dev - - uses: jdx/mise-action@v5.3.0 + - uses: jdx/mise-action@v5.4.0 with: working_directory: tools/ooxml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d0d1b3ff..5c9139b5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -57,7 +57,7 @@ jobs: if: hashFiles(format('tools/{0}/*.slnx', needs.tag.outputs.format)) != '' run: sudo apt-get update && sudo apt-get install -y --no-install-recommends clang zlib1g-dev - - uses: jdx/mise-action@v5.3.0 + - uses: jdx/mise-action@v5.4.0 with: working_directory: tools/${{ needs.tag.outputs.format }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 41ce61f6..9db0bc8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ tool under `tools/` keeps its own. ## [Unreleased] +### Changed + +- `picture.LibreOfficeImage` is `gotenberg/gotenberg:9.10.3-libreoffice`, from 9.10.2-libreoffice, + pinned by its multi-arch index digest. + ## [v0.10.0] - 2026-11-27 This release captures each format's own metadata as a record output named `metadata`: an office diff --git a/cmd/docproc/go.mod b/cmd/docproc/go.mod index 57259783..799d9af1 100644 --- a/cmd/docproc/go.mod +++ b/cmd/docproc/go.mod @@ -5,7 +5,7 @@ go 1.27.4 require ( github.com/standards-lab/docproc v0.10.0 github.com/standards-lab/go-cli-sdk v0.4.0 - github.com/standards-lab/go-core v0.12.0 + github.com/standards-lab/go-core v0.14.0 golang.org/x/sys v0.50.0 ) diff --git a/cmd/docproc/go.sum b/cmd/docproc/go.sum index a5895ae8..b9c84649 100644 --- a/cmd/docproc/go.sum +++ b/cmd/docproc/go.sum @@ -2,8 +2,8 @@ github.com/standards-lab/docproc v0.10.0 h1:4neT6syfThhNA9YmfHKMRt6OXt1MXSI9uJbF github.com/standards-lab/docproc v0.10.0/go.mod h1:ZA8JYQPooA6YA84b00Lpu5AiSL2VSj/u7QnenltqVBA= github.com/standards-lab/go-cli-sdk v0.4.0 h1:232dyKPD5kqshp0BMEVEZaedwJfvnDVqWLv7m1NQWmI= github.com/standards-lab/go-cli-sdk v0.4.0/go.mod h1:7Y1BCcHtuu8Unxc+Hryjlln+0fbiMYa5xY75aueJ/rY= -github.com/standards-lab/go-core v0.12.0 h1:sqrzK6QSppEYpwvVAyiWgzNuOsjfK0Kwe86GPuZpHsU= -github.com/standards-lab/go-core v0.12.0/go.mod h1:Yl/R+gM9YWczsePBCKXdPGh3FSdZ/5i8SapLIh3BDHU= +github.com/standards-lab/go-core v0.14.0 h1:n8FRpoCqE0HErfo5V1iWASipo3ORx36V6ESQhgFZ27E= +github.com/standards-lab/go-core v0.14.0/go.mod h1:Yl/R+gM9YWczsePBCKXdPGh3FSdZ/5i8SapLIh3BDHU= golang.org/x/sys v0.50.0 h1:dkKZEFTEKaLr1sjhs0WiKqoi8Jj5nHbS3Njmx1UoMJs= golang.org/x/sys v0.50.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= golang.org/x/text v0.44.0 h1:YItdp/mQNGnsmrgpcdA5yQ3bnRxCfo/Tj/iByGW9GGo= diff --git a/picture/spec.go b/picture/spec.go index 077751ba..df0432a1 100644 --- a/picture/spec.go +++ b/picture/spec.go @@ -34,8 +34,8 @@ const LibreOfficeMinimum = "24.2" // runs in it under the runner's full lockdown, with no relaxation, so // tool.Image{Ref: LibreOfficeImage} is the whole of it. A caller may run another image, or soffice // on the host through the exec runner. -const LibreOfficeImage = "gotenberg/gotenberg:9.10.2-libreoffice@sha256:" + - "4e262b3ba32cc99dd95455a2ee7e11d2a9b5f8e562e3f9cf8550a16c814e5421" +const LibreOfficeImage = "gotenberg/gotenberg:9.10.3-libreoffice@sha256:" + + "bf3efd63f83fa2ae3f9a8b422aca28984f696a31df94d3159059a1d2c296cc99" // LibreOfficeSpec declares LibreOffice's soffice, minimum 24.2, for either runner's constructor; // the container runner makes it the entrypoint in place of the image's own. soffice --version diff --git a/tools/mail/mise.toml b/tools/mail/mise.toml index d79575c4..4c051d41 100644 --- a/tools/mail/mise.toml +++ b/tools/mail/mise.toml @@ -1,10 +1,10 @@ # docproc-mail's toolchain and its check, publish, golden, mboxrd, currency, and upgrade tasks. # See docs/tool-builds.md [tools] -cargo-deny = "0.22.1" +cargo-deny = "0.22.2" "github:EmbarkStudios/cargo-about" = "0.9.3" jq = "1.8.2" -rust = { version = "1.100.0", profile = "minimal", components = "clippy,rustfmt", targets = "x86_64-unknown-linux-musl,aarch64-unknown-linux-musl" } +rust = { version = "1.100.1", profile = "minimal", components = "clippy,rustfmt", targets = "x86_64-unknown-linux-musl,aarch64-unknown-linux-musl" } shellcheck = "0.11.0" [env] diff --git a/tools/onenote/mise.toml b/tools/onenote/mise.toml index cb6adb09..576836ec 100644 --- a/tools/onenote/mise.toml +++ b/tools/onenote/mise.toml @@ -1,10 +1,10 @@ # docproc-onenote's toolchain and its check, publish, golden, currency, and upgrade tasks. # See docs/tool-builds.md [tools] -cargo-deny = "0.22.1" +cargo-deny = "0.22.2" "github:EmbarkStudios/cargo-about" = "0.9.3" jq = "1.8.2" -rust = { version = "1.100.0", profile = "minimal", components = "clippy,rustfmt", targets = "x86_64-unknown-linux-musl,aarch64-unknown-linux-musl" } +rust = { version = "1.100.1", profile = "minimal", components = "clippy,rustfmt", targets = "x86_64-unknown-linux-musl,aarch64-unknown-linux-musl" } shellcheck = "0.11.0" [env] From 5ded00c50c413166a0b412dc12d47e38ae44f1d7 Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Sat, 28 Nov 2026 17:05:50 -0500 Subject: [PATCH 2/9] Add the settings package: a run's settings as one JSON object settings.Settings holds docproc's 21 run settings, one flat snake-case key per DOCPROC_ variable plus puts, each a pointer field so unset (nil) is told from an explicit zero, which means no bound. A Go caller sets a key with new(v). Decode reads JSON and validates in one step; Validate validates settings built in code. Every refusal names its key and wraps settings.ErrRequest. Decisions: - Decode takes []byte, so every error is the input's: input that isn't one JSON object, an unknown key, a wrong JSON type, or trailing data. - Durations decode as Go duration strings through an unexported wire struct of json.RawMessage fields shadowing the four duration keys, so Settings keeps *time.Duration fields for Go callers. - Validate joins every refusal; the missing required keys are one error. - audio_limit set to zero is refused, as cmd/docproc's parseAudioLimit refuses it, alongside anything audio.NewCutter refuses. - bomb_size stays uint64, as inspect.Options takes it; a negative one is refused at decoding, naming the key. - The package imports audio alone of docproc's packages; the assembly into stages.Options and dispatch.Config is the next slice's. --- settings/doc.go | 49 ++++++++ settings/main_test.go | 11 ++ settings/settings.go | 253 ++++++++++++++++++++++++++++++++++++++ settings/settings_test.go | 239 +++++++++++++++++++++++++++++++++++ 4 files changed, 552 insertions(+) create mode 100644 settings/doc.go create mode 100644 settings/main_test.go create mode 100644 settings/settings.go create mode 100644 settings/settings_test.go diff --git a/settings/doc.go b/settings/doc.go new file mode 100644 index 00000000..de80a045 --- /dev/null +++ b/settings/doc.go @@ -0,0 +1,49 @@ +// Package settings holds a run's settings as one flat JSON object, on the standard library and +// this module's audio package alone: the run bounds a host passes stages.Build in its Options, +// the dispatch.Limits and the release and puts bounds it passes dispatch.New in its Config, and +// the PDF, video, ImageMagick, and audio bounds of the stages' requests. Each key is named for +// the DOCPROC_ variable cmd/docproc reads it from, without the prefix and in snake case. +// +// [Decode] reads the settings from JSON and validates them in one step; [Settings.Validate] +// validates settings a Go caller built, each unset key nil, set with new, such as new(int64(0)). +// The library sets no bound of its own, so every key but four is required, and zero is no bound: +// a required key left unset is refused, every such key named in one error. +// +// key JSON field required +// tool_memory whole bytes stages.Options.Memory yes +// unit_timeout duration stages.Options.Timeout yes +// stream_idle duration stages.Options.Idle yes +// max_parts whole number dispatch.Limits.Parts yes +// max_bytes whole bytes dispatch.Limits.Bytes yes +// max_depth whole number dispatch.Limits.Depth yes +// bomb_ratio number inspect.Options.BombRatio yes +// bomb_size whole bytes inspect.Options.BombSize yes +// archive_entries whole number inspect.Options.Entries yes +// claim_release duration dispatch.Config.Release yes +// concurrency whole number, from 1 stages.Options.Concurrency no, 1 +// pdf_dpi whole number, from 1 document.ImagesRequest.DPI no, document.DefaultDPI +// pdf_text boolean document.ImagesRequest.Text yes +// pdf_max_pixels whole number document.ImagesRequest.MaxPixels yes +// frame_max_side whole number media.Request.MaxSide yes +// magick_area whole number picture.Limits.Area yes +// magick_memory whole bytes picture.Limits.Memory yes +// magick_map whole bytes picture.Limits.Map yes +// magick_disk whole bytes picture.Limits.Disk yes +// audio_limit duration, over 4s audio.Request.Limit no, audio.DefaultWindowLimit +// puts whole number, from 1 dispatch.Config.Puts no, 1 +// +// A duration is a Go duration string, such as "90s" or "10m", as time.ParseDuration reads it; a +// number in its place is refused. Every value is zero or more, and bomb_ratio and bomb_size are +// both zero, for no bomb rule, or both above it. An optional key, unset, takes the default the +// table names: document.DefaultDPI, 150 DPI, and audio.DefaultWindowLimit, 30s; set, it is at +// least 1, or for audio_limit over twice audio.DefaultOverlap, 4s, the shortest window the audio +// cutter takes. A refusal names its key and wraps [ErrRequest], as does input that isn't one JSON +// object, an unknown key, and a value of the wrong JSON type. +// +// Its exported identifiers: +// +// - [Settings] holds a run's settings, one pointer field per key, nil when unset; +// [Settings.Validate] refuses settings a run can't take. +// - [Decode] reads settings from JSON and validates them. +// - [ErrRequest] is refused settings' cause. +package settings diff --git a/settings/main_test.go b/settings/main_test.go new file mode 100644 index 00000000..0766e33b --- /dev/null +++ b/settings/main_test.go @@ -0,0 +1,11 @@ +package settings_test + +import ( + "testing" + + "github.com/standards-lab/docproc/internal/tooltest" +) + +func TestMain(m *testing.M) { + tooltest.Main(m, nil) +} diff --git a/settings/settings.go b/settings/settings.go new file mode 100644 index 00000000..732233e4 --- /dev/null +++ b/settings/settings.go @@ -0,0 +1,253 @@ +package settings + +import ( + "bytes" + "encoding/json" + "errors" + "fmt" + "io" + "math" + "reflect" + "strings" + "time" + + "github.com/standards-lab/docproc/audio" +) + +// ErrRequest is the cause of refused settings: input Decode can't read, or settings Validate +// refuses. +var ErrRequest = errors.New("invalid request") + +// Settings are a run's settings, one key for each, nil when unset. Every key but PDFDPI, +// Concurrency, AudioLimit, and Puts is required, and zero is no bound. +type Settings struct { + // ToolMemory is every tool's memory bound in bytes, tool_memory. + ToolMemory *int64 `json:"tool_memory"` + // UnitTimeout is a unit run's bound, unit_timeout. + UnitTimeout *time.Duration `json:"unit_timeout"` + // StreamIdle is a stream run's idle bound, stream_idle. + StreamIdle *time.Duration `json:"stream_idle"` + // MaxParts is the most parts one dispatch admits, max_parts. + MaxParts *int `json:"max_parts"` + // MaxBytes is the most bytes one dispatch's parts may come to, max_bytes. + MaxBytes *int64 `json:"max_bytes"` + // MaxDepth is the deepest part one dispatch admits, max_depth. + MaxDepth *int `json:"max_depth"` + // BombRatio is the bomb rule's ratio of expanded to compressed size, bomb_ratio. + BombRatio *float64 `json:"bomb_ratio"` + // BombSize is the bomb rule's expanded size in bytes, bomb_size. + BombSize *uint64 `json:"bomb_size"` + // ArchiveEntries is the most entries an archive may hold, archive_entries. + ArchiveEntries *int `json:"archive_entries"` + // ClaimRelease bounds a claim's release once a dispatch's context has ended, claim_release. + ClaimRelease *time.Duration `json:"claim_release"` + // Concurrency is how many of a PDF's pages and an audio part's windows are held at once, + // concurrency. + Concurrency *int `json:"concurrency"` + // PDFDPI is the DPI a PDF's pages are rendered at, pdf_dpi. + PDFDPI *int `json:"pdf_dpi"` + // PDFText is whether a PDF page's text layer is read, pdf_text. + PDFText *bool `json:"pdf_text"` + // PDFMaxPixels is the most pixels a page's PNG may hold, pdf_max_pixels. + PDFMaxPixels *int64 `json:"pdf_max_pixels"` + // FrameMaxSide is the largest side a video frame is written at, in pixels, frame_max_side. + FrameMaxSide *int `json:"frame_max_side"` + // MagickArea is the most pixels one image may hold in ImageMagick's pixel cache, + // magick_area. + MagickArea *int64 `json:"magick_area"` + // MagickMemory is the most bytes of heap the pixel cache may take, magick_memory. + MagickMemory *int64 `json:"magick_memory"` + // MagickMap is the most bytes of the pixel cache that may be memory-mapped, magick_map. + MagickMap *int64 `json:"magick_map"` + // MagickDisk is the most bytes of the pixel cache that may be on disk, magick_disk. + MagickDisk *int64 `json:"magick_disk"` + // AudioLimit is the longest audio window, its overlaps included, audio_limit. + AudioLimit *time.Duration `json:"audio_limit"` + // Puts is the most content puts in flight per dispatch, puts. + Puts *int `json:"puts"` +} + +type wire struct { + Settings + UnitTimeout json.RawMessage `json:"unit_timeout"` + StreamIdle json.RawMessage `json:"stream_idle"` + ClaimRelease json.RawMessage `json:"claim_release"` + AudioLimit json.RawMessage `json:"audio_limit"` +} + +// Decode reads settings from a JSON object and validates them, as Validate does. Input that isn't +// one JSON object, an unknown key, a value of the wrong type, and a duration that isn't a Go +// duration string are each an error wrapping ErrRequest. +func Decode(data []byte) (Settings, error) { + dec := json.NewDecoder(bytes.NewReader(data)) + dec.DisallowUnknownFields() + var w wire + if err := dec.Decode(&w); err != nil { + return Settings{}, decodeError(err) + } + if _, err := dec.Token(); err != io.EOF { + return Settings{}, refuse("the input holds more than one JSON value") + } + s := w.Settings + err := errors.Join( + parseDuration(&s.UnitTimeout, "unit_timeout", w.UnitTimeout), + parseDuration(&s.StreamIdle, "stream_idle", w.StreamIdle), + parseDuration(&s.ClaimRelease, "claim_release", w.ClaimRelease), + parseDuration(&s.AudioLimit, "audio_limit", w.AudioLimit), + ) + if err != nil { + return Settings{}, err + } + if err := s.Validate(); err != nil { + return Settings{}, err + } + return s, nil +} + +func decodeError(err error) error { + var syntax *json.SyntaxError + var typ *json.UnmarshalTypeError + switch { + case errors.As(err, &syntax), errors.Is(err, io.EOF), errors.Is(err, io.ErrUnexpectedEOF): + return refuse("the input isn't JSON: %v", err) + case errors.As(err, &typ) && typ.Field == "": + return refuse("the input is a JSON %s, not an object", typ.Value) + case errors.As(err, &typ): + return refuse("%s: a JSON %s isn't %s", typ.Field, typ.Value, describe(typ.Type)) + } + if name, ok := strings.CutPrefix(err.Error(), "json: unknown field "); ok { + return refuse("unknown key %s", name) + } + return refuse("%v", err) +} + +func describe(t reflect.Type) string { + switch t.Kind() { + case reflect.Uint64: + return "a whole number of zero or more" + case reflect.Int, reflect.Int64: + return "a whole number" + case reflect.Float64: + return "a number" + case reflect.Bool: + return "a boolean" + } + return "a " + t.String() +} + +func parseDuration(dest **time.Duration, key string, raw json.RawMessage) error { + if raw == nil || string(raw) == "null" { + return nil + } + var s string + if err := json.Unmarshal(raw, &s); err != nil { + return refuse("%s: %s isn't a duration string, such as \"90s\" or \"10m\"", key, raw) + } + d, err := time.ParseDuration(s) + if err != nil { + return refuse("%s: %q isn't a duration, such as \"90s\" or \"10m\"", key, s) + } + *dest = &d + return nil +} + +// Validate refuses settings a run can't take, each refusal naming its key and wrapping ErrRequest: +// every required key unset, named in one error; a value below zero; BombRatio not finite, or one +// of BombRatio and BombSize zero and not the other; PDFDPI, Concurrency, or Puts set below 1; and +// AudioLimit set to a limit the audio cutter refuses, or to zero. +func (s Settings) Validate() error { + var errs []error + if missing := s.missing(); len(missing) > 0 { + errs = append(errs, refuse("required keys unset: %s", strings.Join(missing, ", "))) + } + errs = append(errs, + atLeast("tool_memory", s.ToolMemory, 0), + atLeast("unit_timeout", s.UnitTimeout, 0), + atLeast("stream_idle", s.StreamIdle, 0), + atLeast("max_parts", s.MaxParts, 0), + atLeast("max_bytes", s.MaxBytes, 0), + atLeast("max_depth", s.MaxDepth, 0), + atLeast("archive_entries", s.ArchiveEntries, 0), + atLeast("claim_release", s.ClaimRelease, 0), + atLeast("concurrency", s.Concurrency, 1), + atLeast("pdf_dpi", s.PDFDPI, 1), + atLeast("pdf_max_pixels", s.PDFMaxPixels, 0), + atLeast("frame_max_side", s.FrameMaxSide, 0), + atLeast("magick_area", s.MagickArea, 0), + atLeast("magick_memory", s.MagickMemory, 0), + atLeast("magick_map", s.MagickMap, 0), + atLeast("magick_disk", s.MagickDisk, 0), + atLeast("puts", s.Puts, 1), + s.bomb(), + s.audioLimit(), + ) + return errors.Join(errs...) +} + +func (s Settings) missing() []string { + var missing []string + for _, k := range []struct { + key string + set bool + }{ + {"tool_memory", s.ToolMemory != nil}, + {"unit_timeout", s.UnitTimeout != nil}, + {"stream_idle", s.StreamIdle != nil}, + {"max_parts", s.MaxParts != nil}, + {"max_bytes", s.MaxBytes != nil}, + {"max_depth", s.MaxDepth != nil}, + {"bomb_ratio", s.BombRatio != nil}, + {"bomb_size", s.BombSize != nil}, + {"archive_entries", s.ArchiveEntries != nil}, + {"claim_release", s.ClaimRelease != nil}, + {"pdf_text", s.PDFText != nil}, + {"pdf_max_pixels", s.PDFMaxPixels != nil}, + {"frame_max_side", s.FrameMaxSide != nil}, + {"magick_area", s.MagickArea != nil}, + {"magick_memory", s.MagickMemory != nil}, + {"magick_map", s.MagickMap != nil}, + {"magick_disk", s.MagickDisk != nil}, + } { + if !k.set { + missing = append(missing, k.key) + } + } + return missing +} + +func atLeast[T ~int | ~int64](key string, v *T, floor T) error { + switch { + case v == nil || *v >= floor: + return nil + case floor == 0: + return refuse("%s: %v is below zero", key, *v) + } + return refuse("%s: %v is below %v", key, *v, floor) +} + +func (s Settings) bomb() error { + switch { + case s.BombRatio == nil: + return nil + case !(*s.BombRatio >= 0) || math.IsInf(*s.BombRatio, 1): + return refuse("bomb_ratio: %g isn't a finite number of zero or more", *s.BombRatio) + case s.BombSize != nil && (*s.BombRatio == 0) != (*s.BombSize == 0): + return refuse("bomb_ratio and bomb_size: set both above zero, or both to zero for no bomb rule") + } + return nil +} + +func (s Settings) audioLimit() error { + if s.AudioLimit == nil { + return nil + } + if _, err := audio.NewCutter(audio.Request{Limit: *s.AudioLimit}); *s.AudioLimit == 0 || err != nil { + return refuse("audio_limit: %v isn't over %v, twice the %v overlap between windows", + *s.AudioLimit, 2*audio.DefaultOverlap, audio.DefaultOverlap) + } + return nil +} + +func refuse(format string, args ...any) error { + return fmt.Errorf("settings: "+format+": %w", append(args, ErrRequest)...) +} diff --git a/settings/settings_test.go b/settings/settings_test.go new file mode 100644 index 00000000..81770772 --- /dev/null +++ b/settings/settings_test.go @@ -0,0 +1,239 @@ +package settings_test + +import ( + "encoding/json" + "errors" + "math" + "reflect" + "strings" + "testing" + "time" + + "github.com/standards-lab/docproc/settings" +) + +type unset struct{} + +func full() map[string]any { + return map[string]any{ + "tool_memory": 2 << 30, + "unit_timeout": "10m", + "stream_idle": "2m", + "max_parts": 100_000, + "max_bytes": 32 << 30, + "max_depth": 16, + "bomb_ratio": 1000, + "bomb_size": 1 << 30, + "archive_entries": 100_000, + "claim_release": "10s", + "concurrency": 1, + "pdf_dpi": 150, + "pdf_text": true, + "pdf_max_pixels": 64_000_000, + "frame_max_side": 2048, + "magick_area": 256_000_000, + "magick_memory": 1 << 30, + "magick_map": 2 << 30, + "magick_disk": 8 << 30, + "audio_limit": "30s", + "puts": 1, + } +} + +func encode(t *testing.T, edits map[string]any) []byte { + t.Helper() + m := full() + for k, v := range edits { + if _, ok := v.(unset); ok { + delete(m, k) + continue + } + m[k] = v + } + data, err := json.Marshal(m) + if err != nil { + t.Fatal(err) + } + return data +} + +func TestDecodeFull(t *testing.T) { + s, err := settings.Decode(encode(t, nil)) + if err != nil { + t.Fatal(err) + } + want := settings.Settings{ + ToolMemory: new(int64(2 << 30)), + UnitTimeout: new(10 * time.Minute), + StreamIdle: new(2 * time.Minute), + MaxParts: new(100_000), + MaxBytes: new(int64(32 << 30)), + MaxDepth: new(16), + BombRatio: new(1000.0), + BombSize: new(uint64(1 << 30)), + ArchiveEntries: new(100_000), + ClaimRelease: new(10 * time.Second), + Concurrency: new(1), + PDFDPI: new(150), + PDFText: new(true), + PDFMaxPixels: new(int64(64_000_000)), + FrameMaxSide: new(2048), + MagickArea: new(int64(256_000_000)), + MagickMemory: new(int64(1 << 30)), + MagickMap: new(int64(2 << 30)), + MagickDisk: new(int64(8 << 30)), + AudioLimit: new(30 * time.Second), + Puts: new(1), + } + if !reflect.DeepEqual(s, want) { + t.Errorf("Decode = %+v, want %+v", s, want) + } +} + +func TestDecodeAccepts(t *testing.T) { + zeros := map[string]any{"bomb_ratio": 0, "bomb_size": 0, "pdf_text": false} + for _, key := range []string{ + "tool_memory", "max_parts", "max_bytes", "max_depth", "archive_entries", "pdf_max_pixels", + "frame_max_side", "magick_area", "magick_memory", "magick_map", "magick_disk", + } { + zeros[key] = 0 + } + for _, key := range []string{"unit_timeout", "stream_idle", "claim_release"} { + zeros[key] = "0s" + } + for name, edits := range map[string]map[string]any{ + "every required key zero": zeros, + "pdf_dpi unset": {"pdf_dpi": unset{}}, + "audio_limit unset": {"audio_limit": unset{}}, + "concurrency unset": {"concurrency": unset{}}, + "puts unset": {"puts": unset{}}, + "every optional key null": {"pdf_dpi": nil, "audio_limit": nil, "concurrency": nil, "puts": nil}, + "audio_limit just over 4s": {"audio_limit": "4001ms"}, + } { + s, err := settings.Decode(encode(t, edits)) + if err != nil { + t.Errorf("%s: %v", name, err) + continue + } + for key, v := range edits { + if _, ok := v.(unset); (ok || v == nil) && set(s, key) { + t.Errorf("%s: %s set, want nil", name, key) + } + } + } +} + +func set(s settings.Settings, key string) bool { + v := reflect.ValueOf(s) + for i := range v.NumField() { + if strings.Split(v.Type().Field(i).Tag.Get("json"), ",")[0] == key { + return !v.Field(i).IsNil() + } + } + panic("no key " + key) +} + +func TestDecodeRefuses(t *testing.T) { + for name, tc := range map[string]struct { + data []byte + want []string + }{ + "not JSON": {[]byte("tool_memory = 1"), []string{"isn't JSON"}}, + "empty": {nil, []string{"isn't JSON"}}, + "truncated": {[]byte(`{"tool_memory": 1`), []string{"isn't JSON"}}, + "an array": {[]byte(`[]`), []string{"not an object"}}, + "two values": {append(encode(t, nil), []byte(" {}")...), []string{"more than one JSON value"}}, + "an unknown key": {encode(t, map[string]any{"max_part": 1}), []string{`"max_part"`}}, + } { + check(t, name, tc.data, tc.want) + } +} + +func TestDecodeRefusesValues(t *testing.T) { + for name, tc := range map[string]struct { + edits map[string]any + want []string + }{ + "a duration as a number": {map[string]any{"unit_timeout": 600}, []string{"unit_timeout", "duration string"}}, + "an unparsable duration": {map[string]any{"stream_idle": "two minutes"}, []string{"stream_idle", `"two minutes"`}}, + "claim_release as a number": {map[string]any{"claim_release": 10}, []string{"claim_release"}}, + "audio_limit as a number": {map[string]any{"audio_limit": 30}, []string{"audio_limit"}}, + "a count as a string": {map[string]any{"max_parts": "100"}, []string{"max_parts", "whole number"}}, + "a count as a fraction": {map[string]any{"max_depth": 1.5}, []string{"max_depth", "whole number"}}, + "pdf_text as a string": {map[string]any{"pdf_text": "true"}, []string{"pdf_text", "boolean"}}, + "bomb_ratio as a string": {map[string]any{"bomb_ratio": "1000"}, []string{"bomb_ratio", "a number"}}, + "bomb_size below zero": {map[string]any{"bomb_size": -1}, []string{"bomb_size", "zero or more"}}, + "a negative duration": {map[string]any{"unit_timeout": "-1s"}, []string{"unit_timeout", "below zero"}}, + "a negative size": {map[string]any{"tool_memory": -1}, []string{"tool_memory", "below zero"}}, + "a negative count": {map[string]any{"archive_entries": -1}, []string{"archive_entries", "below zero"}}, + "a negative ratio": {map[string]any{"bomb_ratio": -0.5}, []string{"bomb_ratio"}}, + "bomb_ratio alone zero": {map[string]any{"bomb_ratio": 0}, []string{"bomb_ratio and bomb_size"}}, + "bomb_size alone zero": {map[string]any{"bomb_size": 0}, []string{"bomb_ratio and bomb_size"}}, + "pdf_dpi zero": {map[string]any{"pdf_dpi": 0}, []string{"pdf_dpi", "below 1"}}, + "concurrency zero": {map[string]any{"concurrency": 0}, []string{"concurrency", "below 1"}}, + "puts zero": {map[string]any{"puts": 0}, []string{"puts", "below 1"}}, + "audio_limit zero": {map[string]any{"audio_limit": "0s"}, []string{"audio_limit", "4s"}}, + "audio_limit 4s": {map[string]any{"audio_limit": "4s"}, []string{"audio_limit", "4s"}}, + "audio_limit below zero": {map[string]any{"audio_limit": "-30s"}, []string{"audio_limit"}}, + "two refusals at once": { + map[string]any{"max_bytes": -1, "magick_disk": -2}, + []string{"max_bytes: -1 is below zero", "magick_disk: -2 is below zero"}, + }, + } { + check(t, name, encode(t, tc.edits), tc.want) + } +} + +func TestDecodeNamesEveryMissingKey(t *testing.T) { + required := []string{ + "tool_memory", "unit_timeout", "stream_idle", "max_parts", "max_bytes", "max_depth", + "bomb_ratio", "bomb_size", "archive_entries", "claim_release", "pdf_text", + "pdf_max_pixels", "frame_max_side", "magick_area", "magick_memory", "magick_map", + "magick_disk", + } + check(t, "an empty object", []byte(`{}`), []string{"required keys unset: " + strings.Join(required, ", ")}) + for _, key := range required { + check(t, key+" unset", encode(t, map[string]any{key: unset{}}), []string{"required keys unset: " + key + ":"}) + check(t, key+" null", encode(t, map[string]any{key: nil}), []string{"required keys unset: " + key + ":"}) + } +} + +func TestValidate(t *testing.T) { + s, err := settings.Decode(encode(t, nil)) + if err != nil { + t.Fatal(err) + } + if err := s.Validate(); err != nil { + t.Errorf("Validate of decoded settings: %v", err) + } + for name, tc := range map[string]struct { + edit func(*settings.Settings) + want string + }{ + "bomb_ratio NaN": {func(s *settings.Settings) { s.BombRatio = new(math.NaN()) }, "bomb_ratio"}, + "bomb_ratio infinite": {func(s *settings.Settings) { s.BombRatio = new(math.Inf(1)) }, "bomb_ratio"}, + "stream_idle negative": {func(s *settings.Settings) { s.StreamIdle = new(-time.Second) }, "stream_idle: -1s is below zero"}, + "max_depth unset": {func(s *settings.Settings) { s.MaxDepth = nil }, "required keys unset: max_depth"}, + } { + c := s + tc.edit(&c) + err := c.Validate() + if !errors.Is(err, settings.ErrRequest) || !strings.Contains(err.Error(), tc.want) { + t.Errorf("%s: %v, want ErrRequest naming %q", name, err, tc.want) + } + } +} + +func check(t *testing.T, name string, data []byte, want []string) { + t.Helper() + _, err := settings.Decode(data) + if !errors.Is(err, settings.ErrRequest) { + t.Errorf("%s: %v, want ErrRequest", name, err) + return + } + for _, w := range want { + if !strings.Contains(err.Error(), w) { + t.Errorf("%s: %v, want it to name %q", name, err, w) + } + } +} From d00f5584cfe7a537517d58297417f426dab04966 Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Sat, 28 Nov 2026 17:10:07 -0500 Subject: [PATCH 3/9] Assemble settings into the library's shapes settings.Run holds a run's settings as stages.Options, dispatch.Limits, the claim release bound, and the puts in flight, mirroring cmd/docproc's Bounds plus Puts. Settings.Assemble validates first and refuses with ErrRequest, so an unvalidated value never dereferences a nil key. An unset optional key assembles to its default: pdf_dpi to document.DefaultDPI, audio_limit to audio.DefaultWindowLimit, and concurrency and puts to 1. Every option no key covers stays zero, the host's own. settings now imports stages and dispatch; go list -deps shows no cycle and no requirement beyond golang.org/x/text. Tests: a table test from JSON through Decode to the whole Run, every field compared, so uncovered fields are proven zero; refusals of unvalidated values; stages.Build over stand-in document tools, where pdf_dpi and pdf_text change the document stage's identity and the set's inspection options are the assembled ones; and dispatch.New over the assembled Limits, Release, and Puts, where max_bytes decides whether a text input is prepared or limited. docs/api.md gains the Settings section (signatures, key table, required and optional keys, formats, defaults); packages.md, layers.md, the api.md package list, and context/README.md list the package. --- context/README.md | 3 +- docs/api.md | 80 ++++++++++++++++++++++++++- docs/layers.md | 4 +- docs/packages.md | 1 + settings/doc.go | 10 +++- settings/main_test.go | 25 ++++++++- settings/run.go | 81 +++++++++++++++++++++++++++ settings/run_linux_test.go | 110 +++++++++++++++++++++++++++++++++++++ settings/run_test.go | 102 ++++++++++++++++++++++++++++++++++ 9 files changed, 410 insertions(+), 6 deletions(-) create mode 100644 settings/run.go create mode 100644 settings/run_linux_test.go create mode 100644 settings/run_test.go diff --git a/context/README.md b/context/README.md index ef5b0722..edbad8f0 100644 --- a/context/README.md +++ b/context/README.md @@ -32,7 +32,8 @@ tasks' measurements of what v1.ai.processing delivers. [onenote/doc.go](../onenote/doc.go), [sevenzip/doc.go](../sevenzip/doc.go). - **Media** (built): [audio/doc.go](../audio/doc.go), [media/doc.go](../media/doc.go), [picture/doc.go](../picture/doc.go), [document/doc.go](../document/doc.go). -- **Dispatch** (built): [dispatch/doc.go](../dispatch/doc.go), [stages/doc.go](../stages/doc.go). +- **Dispatch** (built): [dispatch/doc.go](../dispatch/doc.go), [stages/doc.go](../stages/doc.go), + [settings/doc.go](../settings/doc.go). - **Stores** (built): [dispatch/dispatchtest/doc.go](../dispatch/dispatchtest/doc.go), [storage/doc.go](../storage/doc.go), [postgres/doc.go](../postgres/doc.go). - **Run directory** (built): [rundir/doc.go](../rundir/doc.go), diff --git a/docs/api.md b/docs/api.md index 4f42edf7..d9e92abc 100644 --- a/docs/api.md +++ b/docs/api.md @@ -61,6 +61,9 @@ dispatch/dispatchtest the Index and Content conformance suites and the fixt stages Build and its Options, Routes and ParseRoutes, the stage adapters, unexported, the failure classification, the identities +settings a run's settings as one JSON object, validated and assembled + into stages.Options, dispatch.Limits, and the release and + puts bounds internal/tooltest, test helpers: the unit tier's stand-in tool, golden sums, and goldentest, mediatest media's stand-in ffmpeg run rundir, rundir/schema cmd/docproc's run directory: its shapes, read and written @@ -69,7 +72,7 @@ metadata the metadata records' shapes, one per format; imports ``` No root package. Another module reaches `dispatch`, `dispatch/dispatchtest`, `route`, `inspect`, -`stages.Build`, `rundir`, and the record types docinfer decodes (the plan records, `metadata`'s +`stages.Build`, `settings`, `rundir`, and the record types docinfer decodes (the plan records, `metadata`'s records, the readers' line types, `email.Threader`); the module builds on every 64-bit platform, and only running a tool needs Linux. @@ -1043,6 +1046,81 @@ How the stages are built, and why: because of a document, so it is the run's; 7zz's 8, out of memory, is the content's, as an allocation refused under the memory bound is. +## Settings + +`settings` holds a run's settings as one flat JSON object, so a host that takes its bounds as +JSON, rather than as `cmd/docproc`'s `DOCPROC_` variables, reads and validates them in one step +and hands them to `stages.Build` and `dispatch.New` as they are. Each key is named for the +variable `cmd/docproc` reads it from, without the prefix and in snake case. It imports the +standard library and docproc's own packages alone. + +```go +package settings +type Settings struct { // one pointer field per key, nil when unset; the json tags are the keys + ToolMemory *int64; UnitTimeout, StreamIdle *time.Duration + MaxParts *int; MaxBytes *int64; MaxDepth *int + BombRatio *float64; BombSize *uint64; ArchiveEntries *int + ClaimRelease *time.Duration; Concurrency, PDFDPI *int; PDFText *bool; PDFMaxPixels *int64 + FrameMaxSide *int; MagickArea, MagickMemory, MagickMap, MagickDisk *int64 + AudioLimit *time.Duration; Puts *int +} +// Decode reads settings from one JSON object and validates them, as Validate does; input that +// isn't one object, an unknown key, and a value of the wrong JSON type are refused too. +func Decode(data []byte) (Settings, error) +func (s Settings) Validate() error // each refusal names its key; every unset required key in one +// Assemble validates s and returns its Run, each optional key left unset at its default. +func (s Settings) Assemble() (Run, error) +type Run struct { + Stages stages.Options // for stages.Build; every option no key covers is the zero value + Limits dispatch.Limits // dispatch.Config.Limits + Release time.Duration // dispatch.Config.Release + Puts int // dispatch.Config.Puts +} +var ErrRequest = errors.New("invalid request") // every refusal wraps it +``` + +The keys, their formats, where each lands, and whether it is required: + +```text +key JSON field required +tool_memory whole bytes stages.Options.Memory yes +unit_timeout duration stages.Options.Timeout yes +stream_idle duration stages.Options.Idle yes +max_parts whole number dispatch.Limits.Parts yes +max_bytes whole bytes dispatch.Limits.Bytes yes +max_depth whole number dispatch.Limits.Depth yes +bomb_ratio number inspect.Options.BombRatio yes +bomb_size whole bytes inspect.Options.BombSize yes +archive_entries whole number inspect.Options.Entries yes +claim_release duration dispatch.Config.Release yes +concurrency whole number, from 1 stages.Options.Concurrency no, 1 +pdf_dpi whole number, from 1 document.ImagesRequest.DPI no, document.DefaultDPI +pdf_text boolean document.ImagesRequest.Text yes +pdf_max_pixels whole number document.ImagesRequest.MaxPixels yes +frame_max_side whole number media.Request.MaxSide yes +magick_area whole number picture.Limits.Area yes +magick_memory whole bytes picture.Limits.Memory yes +magick_map whole bytes picture.Limits.Map yes +magick_disk whole bytes picture.Limits.Disk yes +audio_limit duration, over 4s audio.Request.Limit no, audio.DefaultWindowLimit +puts whole number, from 1 dispatch.Config.Puts no, 1 +``` + +The library ships no policy, so every key but four is required, and zero is no bound: a required +key left unset is refused, never defaulted. The four optional keys are the ones whose library value +already has a default: an unset `pdf_dpi` assembles to `document.DefaultDPI`, 150; an unset +`audio_limit` to `audio.DefaultWindowLimit`, 30s; and an unset `concurrency` or `puts` to 1. Set, +each is at least 1, or for `audio_limit` over 4s, twice `audio.DefaultOverlap`, the shortest window +the audio cutter takes. A duration is a Go duration string, such as `"90s"` or `"10m"`, as +`time.ParseDuration` reads it, and a number in its place is refused; every value is zero or more, +and `bomb_ratio` and `bomb_size` are both zero, for no bomb rule, or both above it. + +`Run.Stages` sets only the fields the table names: `Exclude`, `Env`, `Inspect.Policy`, `Picture`, +`Document.PagesPerProcess`, and every other field of the video, audio, and ImageMagick requests +stay the zero value, each host's own to set before `Build`. A host passes `Run.Limits`, `Release`, +and `Puts` to `dispatch.New`'s `Config`, with the `stages.Set`'s `Inspect` as its `Inspect`, so one +validated value of the inspection options exists. + ## Content The content store holds every output's content by its SHA-256, and a host puts its own texts in diff --git a/docs/layers.md b/docs/layers.md index 07b83cce..924928f4 100644 --- a/docs/layers.md +++ b/docs/layers.md @@ -34,8 +34,8 @@ The boundaries' pages: docs-corpus v0.2.0. - [Consumers of structured text](structured-text.md): the rule that every piece of text exists once. -- [docproc's API](api.md): inspection and routing, running the tools, dispatch, content, the - index, the event shapes, and the run directory. +- [docproc's API](api.md): inspection and routing, running the tools, dispatch, settings, + content, the index, the event shapes, and the run directory. - [The design review](design-review.md): each finding's settled design and disposition. ## Assumptions diff --git a/docs/packages.md b/docs/packages.md index e8b2487f..2af1d3bb 100644 --- a/docs/packages.md +++ b/docs/packages.md @@ -14,6 +14,7 @@ | `dispatch` | The walk over an input's parts to their stages; the Stage contract and its error classes; the content store and its layout, and the index, each with a file and a memory implementation; the shapes of its events, parts, outputs, and warnings; and the Meta keys every stage sets and the record media types. It imports `route` and `inspect` alone. | | `dispatch/dispatchtest` | The Index and Content conformance suites, for every store, the module's own and a provider's, and the fixture stage a host's tests dispatch over. | | `stages` | `Build` and its `Options`: docproc's shipped wiring, each route's stage over its format package and tools, found on the host, under the host's run bounds and requests, with the one failure classification and each stage's identity. `cmd/docproc` is its first caller. | +| `settings` | A run's settings as one flat JSON object, each key named for its `DOCPROC_` variable: `Decode` reads and validates them, refusing every unset required key in one error, and `Settings.Assemble` returns their `Run`, the `stages.Options`, `dispatch.Limits`, and release and puts bounds a host passes `stages.Build` and `dispatch.New`, each unset optional key at its default. It imports no package outside the standard library and docproc. | | `rundir` | `cmd/docproc`'s run directory, read and written: `Open` to read it and `Create` to write it, its runs, the latest that ended, each run's manifest and record, its content store and the path of a content's file, its index, a quarantined part's kept file, and a run's report directory, `runs//report/`. One process writes a run directory. | | `rundir/schema` | The run directory's schema `"2"`: the shapes `cmd/docproc` writes and a reader decodes, a record line, a manifest, an input's file, and a time, each in UTC. It imports no docproc package but `dispatch` and `inspect`. | | `metadata` | The metadata records' shapes, one per format, each a JSON value under a versioned media type `dispatch` declares: `Office`, an office package's properties and the format it was converted from; `PDF`, a PDF's information dictionary, XMP metadata, and version; `Media`, an audio or video file's container format, duration, bit rate, and tags, and its streams; and `Picture`, a picture's EXIF capture time, camera, orientation, size, GPS position, and properties. It imports no docproc package but `dispatch`, so a reader decodes a record without compiling the stages. | diff --git a/settings/doc.go b/settings/doc.go index de80a045..30a1ffcd 100644 --- a/settings/doc.go +++ b/settings/doc.go @@ -1,5 +1,5 @@ // Package settings holds a run's settings as one flat JSON object, on the standard library and -// this module's audio package alone: the run bounds a host passes stages.Build in its Options, +// this module's own packages alone: the run bounds a host passes stages.Build in its Options, // the dispatch.Limits and the release and puts bounds it passes dispatch.New in its Config, and // the PDF, video, ImageMagick, and audio bounds of the stages' requests. Each key is named for // the DOCPROC_ variable cmd/docproc reads it from, without the prefix and in snake case. @@ -40,10 +40,18 @@ // cutter takes. A refusal names its key and wraps [ErrRequest], as does input that isn't one JSON // object, an unknown key, and a value of the wrong JSON type. // +// [Settings.Assemble] validates the settings and assembles them into a [Run], in the shapes the +// library takes them: the stages.Options a host passes stages.Build, each field the table names +// set and every other option the zero value, the host's own, such as Exclude and Env; and the +// dispatch.Limits, Release, and Puts it passes dispatch.New in its Config. An optional key left +// unset assembles to its default. +// // Its exported identifiers: // // - [Settings] holds a run's settings, one pointer field per key, nil when unset; // [Settings.Validate] refuses settings a run can't take. // - [Decode] reads settings from JSON and validates them. +// - [Run] is settings in the library's shapes; [Settings.Assemble] validates settings and +// returns their Run. // - [ErrRequest] is refused settings' cause. package settings diff --git a/settings/main_test.go b/settings/main_test.go index 0766e33b..22991f60 100644 --- a/settings/main_test.go +++ b/settings/main_test.go @@ -1,11 +1,34 @@ package settings_test import ( + "fmt" + "os" "testing" "github.com/standards-lab/docproc/internal/tooltest" ) func TestMain(m *testing.M) { - tooltest.Main(m, nil) + tooltest.Main(m, map[string]tooltest.Program{ + "gs": version("--version", false, "10.08.0", 0), + "qpdf": version("--version", false, "qpdf version 11.9.0", 0), + "pdfdetach": version("-v", true, "pdfdetach version 26.10.0", 99), + "pdftotext": version("-v", true, "pdftotext version 26.10.0", 0), + "pdfinfo": version("-v", true, "pdfinfo version 26.10.0", 0), + }) +} + +func version(flag string, stderr bool, line string, code int) tooltest.Program { + return func(r tooltest.Run) int { + if len(r.Args) == 1 && r.Args[0] == flag { + if stderr { + fmt.Fprintln(os.Stderr, line) + } else { + fmt.Println(line) + } + return code + } + fmt.Fprintf(os.Stderr, "%s stand-in: unexpected arguments %q\n", r.Program, r.Args) + return 2 + } } diff --git a/settings/run.go b/settings/run.go new file mode 100644 index 00000000..8029f385 --- /dev/null +++ b/settings/run.go @@ -0,0 +1,81 @@ +package settings + +import ( + "time" + + "github.com/standards-lab/docproc/audio" + "github.com/standards-lab/docproc/dispatch" + "github.com/standards-lab/docproc/document" + "github.com/standards-lab/docproc/inspect" + "github.com/standards-lab/docproc/media" + "github.com/standards-lab/docproc/picture" + "github.com/standards-lab/docproc/stages" +) + +// Run is a run's settings in the shapes the library takes them, so a host hands them on as they +// are: Stages to stages.Build, and Limits, Release, and Puts to dispatch.New's Config, with the +// stages.Set's Inspect as its Inspect. +type Run struct { + // Stages carry the run bounds, the inspection options, the concurrency, and the PDF, video, + // ImageMagick, and audio bounds. Every option no key covers is the zero value, the host's to + // set: Exclude, Env, Inspect.Policy, Picture, and every other field of the Document, Video, + // Magick, and Audio requests. + Stages stages.Options + // Limits are each dispatch's caps: dispatch.Config.Limits. + Limits dispatch.Limits + // Release bounds a claim's release once a dispatch's context has ended: + // dispatch.Config.Release. + Release time.Duration + // Puts is the most content puts in flight per dispatch: dispatch.Config.Puts. + Puts int +} + +// Assemble validates s, as Validate does, and returns its Run, each optional key left unset at +// its default: PDFDPI at document.DefaultDPI, AudioLimit at audio.DefaultWindowLimit, and +// Concurrency and Puts at 1. Settings Validate refuses are refused with its error, which wraps +// ErrRequest. +func (s Settings) Assemble() (Run, error) { + if err := s.Validate(); err != nil { + return Run{}, err + } + return Run{ + Stages: stages.Options{ + Memory: *s.ToolMemory, + Timeout: *s.UnitTimeout, + Idle: *s.StreamIdle, + Inspect: inspect.Options{ + BombRatio: *s.BombRatio, + BombSize: *s.BombSize, + Entries: *s.ArchiveEntries, + }, + Concurrency: or(s.Concurrency, 1), + Document: document.ImagesRequest{ + DPI: or(s.PDFDPI, document.DefaultDPI), + Text: *s.PDFText, + MaxPixels: *s.PDFMaxPixels, + }, + Video: media.Request{MaxSide: *s.FrameMaxSide}, + Magick: picture.Limits{ + Area: *s.MagickArea, + Memory: *s.MagickMemory, + Map: *s.MagickMap, + Disk: *s.MagickDisk, + }, + Audio: audio.Request{Limit: or(s.AudioLimit, audio.DefaultWindowLimit)}, + }, + Limits: dispatch.Limits{ + Parts: *s.MaxParts, + Bytes: *s.MaxBytes, + Depth: *s.MaxDepth, + }, + Release: *s.ClaimRelease, + Puts: or(s.Puts, 1), + }, nil +} + +func or[T any](v *T, unset T) T { + if v == nil { + return unset + } + return *v +} diff --git a/settings/run_linux_test.go b/settings/run_linux_test.go new file mode 100644 index 00000000..928f9661 --- /dev/null +++ b/settings/run_linux_test.go @@ -0,0 +1,110 @@ +//go:build linux + +package settings_test + +import ( + "errors" + "reflect" + "slices" + "strings" + "testing" + + "github.com/standards-lab/docproc/dispatch" + "github.com/standards-lab/docproc/internal/tooltest" + "github.com/standards-lab/docproc/route" + "github.com/standards-lab/docproc/settings" + "github.com/standards-lab/docproc/stages" +) + +func build(t *testing.T, run settings.Run) stages.Set { + t.Helper() + links := map[string]string{} + for _, program := range []string{"gs", "qpdf", "pdfdetach", "pdftotext", "pdfinfo"} { + links[program] = tooltest.Link(t, t.TempDir(), program, nil) + } + lookup := func(program string) (string, error) { + if link, ok := links[program]; ok { + return link, nil + } + return "", errors.New("not here") + } + run.Stages.Exclude = slices.DeleteFunc(stages.Routes(), func(r route.Route) bool { + return r == route.Document || r == route.Text + }) + set, err := stages.Build(t.Context(), lookup, run.Stages) + if err != nil { + t.Fatal(err) + } + for _, tl := range set.Tools { + if tl.Err != nil { + t.Fatalf("%s: %v", tl.Program, tl.Err) + } + } + return set +} + +func documentIdentity(t *testing.T, set stages.Set) dispatch.Identity { + t.Helper() + row := set.Rows[slices.Index(stages.Routes(), route.Document)] + if row.State != dispatch.Wired { + t.Fatalf("document %s, %q; want it wired", row.State, row.Reason) + } + return row.Stage +} + +func TestAssembledStages(t *testing.T) { + base := map[string]any{"tool_memory": tooltest.Memory, "pdf_dpi": unset{}} + run := assemble(t, base) + set := build(t, run) + if !reflect.DeepEqual(set.Inspect, run.Stages.Inspect) || set.Inspect.BombRatio != 1000 || set.Inspect.Entries != 100_000 { + t.Errorf("the set's inspection options %+v, want the assembled %+v", set.Inspect, run.Stages.Inspect) + } + unsetDPI := documentIdentity(t, set) + + base["pdf_dpi"] = 300 + if id := documentIdentity(t, build(t, assemble(t, base))); id.Config == unsetDPI.Config { + t.Errorf("pdf_dpi 300: the document stage's identity %s, the same as at the default DPI", id) + } + base["pdf_dpi"] = unset{} + base["pdf_text"] = false + if id := documentIdentity(t, build(t, assemble(t, base))); id.Config == unsetDPI.Config { + t.Errorf("pdf_text false: the document stage's identity %s, the same as reading the text", id) + } +} + +func TestAssembledDispatch(t *testing.T) { + const text = "a run's settings, assembled\n" + for name, tc := range map[string]struct { + maxBytes int + want dispatch.Outcome + }{ + "under max_bytes": {len(text), dispatch.Prepared}, + "past max_bytes": {len(text) - 1, dispatch.Limited}, + } { + run := assemble(t, map[string]any{"tool_memory": tooltest.Memory, "max_bytes": tc.maxBytes, "puts": 2}) + set := build(t, run) + d, err := dispatch.New(dispatch.Config{ + Stages: set.Stages, + Index: dispatch.NewMemoryIndex(0), + Content: dispatch.NewMemoryContent(), + Dir: t.TempDir(), + Inspect: set.Inspect, + Limits: run.Limits, + Release: run.Release, + Puts: run.Puts, + }) + if err != nil { + t.Fatal(err) + } + var last dispatch.Event + for ev, err := range d.Dispatch(t.Context(), dispatch.Input{Reader: strings.NewReader(text), Name: "settings.txt"}) { + if err != nil { + t.Fatal(err) + } + last = ev + } + if last.Outcome != tc.want { + t.Errorf("%s: the input %s, %q; want %s", name, last.Outcome, last.Reason, tc.want) + } + } +} diff --git a/settings/run_test.go b/settings/run_test.go new file mode 100644 index 00000000..d85a4c16 --- /dev/null +++ b/settings/run_test.go @@ -0,0 +1,102 @@ +package settings_test + +import ( + "errors" + "reflect" + "testing" + "time" + + "github.com/standards-lab/docproc/audio" + "github.com/standards-lab/docproc/dispatch" + "github.com/standards-lab/docproc/document" + "github.com/standards-lab/docproc/inspect" + "github.com/standards-lab/docproc/media" + "github.com/standards-lab/docproc/picture" + "github.com/standards-lab/docproc/settings" + "github.com/standards-lab/docproc/stages" +) + +func assemble(t *testing.T, edits map[string]any) settings.Run { + t.Helper() + s, err := settings.Decode(encode(t, edits)) + if err != nil { + t.Fatal(err) + } + run, err := s.Assemble() + if err != nil { + t.Fatal(err) + } + return run +} + +func TestAssemble(t *testing.T) { + want := func(concurrency, dpi int, limit time.Duration, puts int) settings.Run { + return settings.Run{ + Stages: stages.Options{ + Memory: 2 << 30, + Timeout: 10 * time.Minute, + Idle: 2 * time.Minute, + Inspect: inspect.Options{BombRatio: 1000, BombSize: 1 << 30, Entries: 100_000}, + Concurrency: concurrency, + Document: document.ImagesRequest{DPI: dpi, Text: true, MaxPixels: 64_000_000}, + Video: media.Request{MaxSide: 2048}, + Magick: picture.Limits{Area: 256_000_000, Memory: 1 << 30, Map: 2 << 30, Disk: 8 << 30}, + Audio: audio.Request{Limit: limit}, + }, + Limits: dispatch.Limits{Parts: 100_000, Bytes: 32 << 30, Depth: 16}, + Release: 10 * time.Second, + Puts: puts, + } + } + for name, tc := range map[string]struct { + edits map[string]any + want settings.Run + }{ + "every key set": { + map[string]any{"concurrency": 4, "pdf_dpi": 300, "audio_limit": "45s", "puts": 3}, + want(4, 300, 45*time.Second, 3), + }, + "every optional key unset": { + map[string]any{"concurrency": unset{}, "pdf_dpi": unset{}, "audio_limit": unset{}, "puts": unset{}}, + want(1, document.DefaultDPI, audio.DefaultWindowLimit, 1), + }, + "optional keys null": { + map[string]any{"concurrency": nil, "pdf_dpi": nil, "audio_limit": nil, "puts": nil}, + want(1, 150, 30*time.Second, 1), + }, + "zero bounds": { + map[string]any{"concurrency": 4, "pdf_dpi": 300, "audio_limit": "45s", "puts": 3, + "tool_memory": 0, "unit_timeout": "0s", "max_bytes": 0, "bomb_ratio": 0, "bomb_size": 0, "pdf_text": false}, + func() settings.Run { + r := want(4, 300, 45*time.Second, 3) + r.Stages.Memory, r.Stages.Timeout, r.Limits.Bytes = 0, 0, 0 + r.Stages.Inspect.BombRatio, r.Stages.Inspect.BombSize = 0, 0 + r.Stages.Document.Text = false + return r + }(), + }, + } { + if got := assemble(t, tc.edits); !reflect.DeepEqual(got, tc.want) { + t.Errorf("%s: assembled\n%+v\nwant\n%+v", name, got, tc.want) + } + } +} + +func TestAssembleRefuses(t *testing.T) { + s, err := settings.Decode(encode(t, nil)) + if err != nil { + t.Fatal(err) + } + for name, edit := range map[string]func(*settings.Settings){ + "the zero value": func(s *settings.Settings) { *s = settings.Settings{} }, + "a required key nil": func(s *settings.Settings) { s.MagickDisk = nil }, + "puts zero": func(s *settings.Settings) { s.Puts = new(0) }, + } { + c := s + edit(&c) + run, err := c.Assemble() + if !errors.Is(err, settings.ErrRequest) || !reflect.DeepEqual(run, settings.Run{}) { + t.Errorf("%s: %+v, %v; want the zero Run and ErrRequest", name, run, err) + } + } +} From 44cbbfc5f21371a3df5dcbf8c28b20d47a6888b1 Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Sat, 28 Nov 2026 17:15:15 -0500 Subject: [PATCH 4/9] cmd/docproc: its bounds are one settings.Settings, assembled into a settings.Run; DOCPROC_PUTS newBounds starts a settings.Settings with all 21 keys at docproc's starting values (puts 1, the old runner const), lets each DOCPROC_ variable override its key through go-core's config.SetFromEnv (unset or empty keeps the starting value), and returns s.Assemble(). The bounds node now holds a settings.Run; the app.Bounds type is gone, and run.Config carries the settings.Run as Bounds in place of its Stages, Limits, and Release, so the runner takes Puts from it. DOCPROC_PUTS is new; docs/command.md gains its row. Refusals: cmd/docproc's parsers keep only the per-variable format checks (a whole number, in range for its type; a Go duration; a number; a switch; bomb_size, unsigned, below zero). Every range and cross-key rule (below zero, below 1, the bomb pair, finite bomb ratio, the audio limit) comes from settings.Validate through Assemble. Each refusal is joined after the parse errors with its settings key mapped to its variable by config.EnvName, the settings package's own naming rule, and the "settings: " prefix and ErrRequest suffix dropped, so the operator sees e.g. "bounds: DOCPROC_PUTS: 0 is below 1" and "bounds: DOCPROC_BOMB_RATIO and DOCPROC_BOMB_SIZE: set both above zero, or both to zero for no bomb rule"; the existing audio-limit message is unchanged. cmd/docproc's go.mod replaces github.com/standards-lab/docproc with ../.., as 0dab39f, 27b1246, and 1e0bff1 did, so its GOWORK=off build and tests take this checkout's settings package until v0.11.0 is tagged; the require stays v0.10.0, and go mod tidy drops v0.10.0's go.sum lines. Tests: bounds_test.go's helpers take settings.Run (startingBounds gains Puts 1) and boundVars lists DOCPROC_PUTS, so the every-variable tests cover it; no assertion changed. New: DOCPROC_PUTS overrides puts and empty keeps 1; 0, -2, and x fail naming DOCPROC_PUTS; zero DOCPROC_CONCURRENCY and DOCPROC_PDF_DPI keep their documented default; the bomb pair's whole message; a parse and a range refusal joined; a bad DOCPROC_PUTS fails docproc run before any tool lookup. Decisions: - DOCPROC_CONCURRENCY and DOCPROC_PDF_DPI at 0 leave their key unset, so Assemble gives 1 and document.DefaultDPI, keeping "zero is 1" and "zero is document.DefaultDPI"; settings refuses an explicit 0 for both. - Refusal text is rewritten from settings' messages rather than duplicated: settings has no structured refusal, and its keys are by design the variables' names. mise run check passes. --- cmd/docproc/go.mod | 2 + cmd/docproc/go.sum | 2 - cmd/docproc/internal/app/app.go | 4 +- cmd/docproc/internal/app/bounds_test.go | 172 ++++++++++++++++--- cmd/docproc/internal/app/doc.go | 5 +- cmd/docproc/internal/app/domain.go | 5 +- cmd/docproc/internal/app/infrastructure.go | 187 ++++++++++----------- cmd/docproc/internal/run/commands.go | 16 +- cmd/docproc/internal/run/doc.go | 19 +-- cmd/docproc/internal/run/runner.go | 10 +- docs/command.md | 1 + 11 files changed, 263 insertions(+), 160 deletions(-) diff --git a/cmd/docproc/go.mod b/cmd/docproc/go.mod index 799d9af1..93fd5b88 100644 --- a/cmd/docproc/go.mod +++ b/cmd/docproc/go.mod @@ -10,3 +10,5 @@ require ( ) require golang.org/x/text v0.44.0 // indirect + +replace github.com/standards-lab/docproc => ../.. diff --git a/cmd/docproc/go.sum b/cmd/docproc/go.sum index b9c84649..1ac05c49 100644 --- a/cmd/docproc/go.sum +++ b/cmd/docproc/go.sum @@ -1,5 +1,3 @@ -github.com/standards-lab/docproc v0.10.0 h1:4neT6syfThhNA9YmfHKMRt6OXt1MXSI9uJbFGOUE19k= -github.com/standards-lab/docproc v0.10.0/go.mod h1:ZA8JYQPooA6YA84b00Lpu5AiSL2VSj/u7QnenltqVBA= github.com/standards-lab/go-cli-sdk v0.4.0 h1:232dyKPD5kqshp0BMEVEZaedwJfvnDVqWLv7m1NQWmI= github.com/standards-lab/go-cli-sdk v0.4.0/go.mod h1:7Y1BCcHtuu8Unxc+Hryjlln+0fbiMYa5xY75aueJ/rY= github.com/standards-lab/go-core v0.14.0 h1:n8FRpoCqE0HErfo5V1iWASipo3ORx36V6ESQhgFZ27E= diff --git a/cmd/docproc/internal/app/app.go b/cmd/docproc/internal/app/app.go index be68f6f7..1304e8b9 100644 --- a/cmd/docproc/internal/app/app.go +++ b/cmd/docproc/internal/app/app.go @@ -7,6 +7,8 @@ import ( "github.com/standards-lab/go-core/graph" "github.com/standards-lab/go-core/lifecycle" + "github.com/standards-lab/docproc/settings" + "github.com/standards-lab/docproc/cmd/docproc/internal/run" ) @@ -60,7 +62,7 @@ func (a *App) Run(ctx context.Context, args []string) int { // comment repeats it. type Nodes struct { LifecycleConfig *graph.Node[lifecycle.Config] - Bounds *graph.Node[Bounds] + Bounds *graph.Node[settings.Run] StageBuilder *graph.Node[run.StageBuilder] RunConfig *graph.Node[run.Config] } diff --git a/cmd/docproc/internal/app/bounds_test.go b/cmd/docproc/internal/app/bounds_test.go index edaf2ea8..e29a388a 100644 --- a/cmd/docproc/internal/app/bounds_test.go +++ b/cmd/docproc/internal/app/bounds_test.go @@ -19,6 +19,7 @@ import ( "github.com/standards-lab/docproc/inspect" "github.com/standards-lab/docproc/media" "github.com/standards-lab/docproc/picture" + "github.com/standards-lab/docproc/settings" "github.com/standards-lab/docproc/stages" "github.com/standards-lab/docproc/cmd/docproc/internal/app" @@ -48,10 +49,11 @@ var boundVars = []string{ "DOCPROC_MAGICK_MAP", "DOCPROC_MAGICK_DISK", "DOCPROC_AUDIO_LIMIT", + "DOCPROC_PUTS", } -func startingBounds() app.Bounds { - return app.Bounds{ +func startingBounds() settings.Run { + return settings.Run{ Stages: stages.Options{ Memory: 2 * gib, Timeout: 10 * time.Minute, @@ -65,6 +67,7 @@ func startingBounds() app.Bounds { }, Limits: dispatch.Limits{Parts: 100_000, Bytes: 32 * gib, Depth: 16}, Release: 10 * time.Second, + Puts: 1, } } @@ -75,12 +78,12 @@ func clearBounds(t *testing.T) { } } -func buildBounds(t *testing.T) (app.Bounds, error) { +func buildBounds(t *testing.T) (settings.Run, error) { t.Helper() a := app.New(cli.Streams{}) sys, err := a.Graph().Build(a.Nodes().Bounds) if err != nil { - return app.Bounds{}, err + return settings.Run{}, err } return sys.Get(a.Nodes().Bounds), nil } @@ -114,29 +117,29 @@ func TestBounds_StartingValuesTakenByStages(t *testing.T) { func TestBounds_EachVariableOverridesItsBound(t *testing.T) { for _, tc := range []struct { name, value string - set func(*app.Bounds) + set func(*settings.Run) }{ - {"DOCPROC_TOOL_MEMORY", "536870912", func(b *app.Bounds) { b.Stages.Memory = 512 << 20 }}, - {"DOCPROC_UNIT_TIMEOUT", "90s", func(b *app.Bounds) { b.Stages.Timeout = 90 * time.Second }}, - {"DOCPROC_STREAM_IDLE", "1m30s", func(b *app.Bounds) { b.Stages.Idle = 90 * time.Second }}, - {"DOCPROC_MAX_PARTS", "50", func(b *app.Bounds) { b.Limits.Parts = 50 }}, - {"DOCPROC_MAX_BYTES", "1048576", func(b *app.Bounds) { b.Limits.Bytes = 1 << 20 }}, - {"DOCPROC_MAX_DEPTH", "4", func(b *app.Bounds) { b.Limits.Depth = 4 }}, - {"DOCPROC_BOMB_RATIO", "250.5", func(b *app.Bounds) { b.Stages.Inspect.BombRatio = 250.5 }}, - {"DOCPROC_BOMB_SIZE", "1024", func(b *app.Bounds) { b.Stages.Inspect.BombSize = 1024 }}, - {"DOCPROC_ARCHIVE_ENTRIES", "10", func(b *app.Bounds) { b.Stages.Inspect.Entries = 10 }}, - {"DOCPROC_CLAIM_RELEASE", "500ms", func(b *app.Bounds) { b.Release = 500 * time.Millisecond }}, - {"DOCPROC_CONCURRENCY", "4", func(b *app.Bounds) { b.Stages.Concurrency = 4 }}, - {"DOCPROC_PDF_DPI", "300", func(b *app.Bounds) { b.Stages.Document.DPI = 300 }}, - {"DOCPROC_PDF_TEXT", "false", func(b *app.Bounds) { b.Stages.Document.Text = false }}, - {"DOCPROC_PDF_MAX_PIXELS", "1000", func(b *app.Bounds) { b.Stages.Document.MaxPixels = 1000 }}, - {"DOCPROC_FRAME_MAX_SIDE", "720", func(b *app.Bounds) { b.Stages.Video.MaxSide = 720 }}, - {"DOCPROC_MAGICK_AREA", "1000000", func(b *app.Bounds) { b.Stages.Magick.Area = 1_000_000 }}, - {"DOCPROC_MAGICK_MEMORY", "1024", func(b *app.Bounds) { b.Stages.Magick.Memory = 1024 }}, - {"DOCPROC_MAGICK_MAP", "2048", func(b *app.Bounds) { b.Stages.Magick.Map = 2048 }}, - {"DOCPROC_MAGICK_DISK", "0", func(b *app.Bounds) { b.Stages.Magick.Disk = 0 }}, - {"DOCPROC_AUDIO_LIMIT", "45s", func(b *app.Bounds) { b.Stages.Audio.Limit = 45 * time.Second }}, - {"DOCPROC_AUDIO_LIMIT", "4001ms", func(b *app.Bounds) { b.Stages.Audio.Limit = 4001 * time.Millisecond }}, + {"DOCPROC_TOOL_MEMORY", "536870912", func(b *settings.Run) { b.Stages.Memory = 512 << 20 }}, + {"DOCPROC_UNIT_TIMEOUT", "90s", func(b *settings.Run) { b.Stages.Timeout = 90 * time.Second }}, + {"DOCPROC_STREAM_IDLE", "1m30s", func(b *settings.Run) { b.Stages.Idle = 90 * time.Second }}, + {"DOCPROC_MAX_PARTS", "50", func(b *settings.Run) { b.Limits.Parts = 50 }}, + {"DOCPROC_MAX_BYTES", "1048576", func(b *settings.Run) { b.Limits.Bytes = 1 << 20 }}, + {"DOCPROC_MAX_DEPTH", "4", func(b *settings.Run) { b.Limits.Depth = 4 }}, + {"DOCPROC_BOMB_RATIO", "250.5", func(b *settings.Run) { b.Stages.Inspect.BombRatio = 250.5 }}, + {"DOCPROC_BOMB_SIZE", "1024", func(b *settings.Run) { b.Stages.Inspect.BombSize = 1024 }}, + {"DOCPROC_ARCHIVE_ENTRIES", "10", func(b *settings.Run) { b.Stages.Inspect.Entries = 10 }}, + {"DOCPROC_CLAIM_RELEASE", "500ms", func(b *settings.Run) { b.Release = 500 * time.Millisecond }}, + {"DOCPROC_CONCURRENCY", "4", func(b *settings.Run) { b.Stages.Concurrency = 4 }}, + {"DOCPROC_PDF_DPI", "300", func(b *settings.Run) { b.Stages.Document.DPI = 300 }}, + {"DOCPROC_PDF_TEXT", "false", func(b *settings.Run) { b.Stages.Document.Text = false }}, + {"DOCPROC_PDF_MAX_PIXELS", "1000", func(b *settings.Run) { b.Stages.Document.MaxPixels = 1000 }}, + {"DOCPROC_FRAME_MAX_SIDE", "720", func(b *settings.Run) { b.Stages.Video.MaxSide = 720 }}, + {"DOCPROC_MAGICK_AREA", "1000000", func(b *settings.Run) { b.Stages.Magick.Area = 1_000_000 }}, + {"DOCPROC_MAGICK_MEMORY", "1024", func(b *settings.Run) { b.Stages.Magick.Memory = 1024 }}, + {"DOCPROC_MAGICK_MAP", "2048", func(b *settings.Run) { b.Stages.Magick.Map = 2048 }}, + {"DOCPROC_MAGICK_DISK", "0", func(b *settings.Run) { b.Stages.Magick.Disk = 0 }}, + {"DOCPROC_AUDIO_LIMIT", "45s", func(b *settings.Run) { b.Stages.Audio.Limit = 45 * time.Second }}, + {"DOCPROC_AUDIO_LIMIT", "4001ms", func(b *settings.Run) { b.Stages.Audio.Limit = 4001 * time.Millisecond }}, } { t.Run(tc.name+"="+tc.value, func(t *testing.T) { clearBounds(t) @@ -156,6 +159,102 @@ func TestBounds_EachVariableOverridesItsBound(t *testing.T) { } } +func TestBounds_PutsOverride(t *testing.T) { + for _, tc := range []struct { + value string + want int + }{ + {"", 1}, + {"4", 4}, + } { + t.Run("DOCPROC_PUTS="+tc.value, func(t *testing.T) { + clearBounds(t) + t.Setenv("DOCPROC_PUTS", tc.value) + + got, err := buildBounds(t) + + if err != nil { + t.Fatalf("Build: %v", err) + } + want := startingBounds() + want.Puts = tc.want + if !reflect.DeepEqual(got, want) { + t.Errorf("bounds = %+v\nwant %+v", got, want) + } + }) + } +} + +func TestBounds_PutsRefused(t *testing.T) { + for _, tc := range []struct{ value, want string }{ + {"0", "bounds: DOCPROC_PUTS: 0 is below 1"}, + {"-2", "bounds: DOCPROC_PUTS: -2 is below 1"}, + {"x", `bounds: DOCPROC_PUTS: "x" is not a whole number`}, + } { + t.Run(tc.value, func(t *testing.T) { + clearBounds(t) + t.Setenv("DOCPROC_PUTS", tc.value) + + _, err := buildBounds(t) + + if err == nil || err.Error() != tc.want { + t.Errorf("Build: %v, want %q", err, tc.want) + } + }) + } +} + +func TestBounds_ZeroIsTheDefault(t *testing.T) { + for _, tc := range []struct { + name string + set func(*settings.Run) + }{ + {"DOCPROC_CONCURRENCY", func(b *settings.Run) { b.Stages.Concurrency = 1 }}, + {"DOCPROC_PDF_DPI", func(b *settings.Run) { b.Stages.Document.DPI = document.DefaultDPI }}, + } { + t.Run(tc.name, func(t *testing.T) { + clearBounds(t) + t.Setenv(tc.name, "0") + + got, err := buildBounds(t) + + if err != nil { + t.Fatalf("Build: %v", err) + } + want := startingBounds() + tc.set(&want) + if !reflect.DeepEqual(got, want) { + t.Errorf("bounds = %+v\nwant %+v", got, want) + } + }) + } +} + +func TestBounds_BombRuleMessage(t *testing.T) { + clearBounds(t) + t.Setenv("DOCPROC_BOMB_SIZE", "0") + + _, err := buildBounds(t) + + want := "bounds: DOCPROC_BOMB_RATIO and DOCPROC_BOMB_SIZE: set both above zero, or both to zero for no bomb rule" + if err == nil || err.Error() != want { + t.Errorf("Build: %v, want %q", err, want) + } +} + +func TestBounds_ParseAndRangeRefusalsJoined(t *testing.T) { + clearBounds(t) + t.Setenv("DOCPROC_PUTS", "many") + t.Setenv("DOCPROC_UNIT_TIMEOUT", "-1s") + + _, err := buildBounds(t) + + want := "bounds: DOCPROC_PUTS: \"many\" is not a whole number\nDOCPROC_UNIT_TIMEOUT: -1s is below zero" + if err == nil || err.Error() != want { + t.Errorf("Build: %v, want %q", err, want) + } +} + func TestBounds_EveryVariableIsRead(t *testing.T) { for _, name := range boundVars { t.Run(name, func(t *testing.T) { @@ -377,3 +476,24 @@ func TestRun_VersionReadsNoBound(t *testing.T) { t.Errorf("nodes built = %q, want none", log) } } + +func TestRun_PutsRefusedBeforeLookup(t *testing.T) { + in := write(t, t.TempDir(), "hello.txt", helloText) + out := filepath.Join(t.TempDir(), "out") + lookup, looked := probes(apptest.NoTools) + + r := runCmd(t, context.Background(), func(a *app.App) { + t.Setenv("DOCPROC_PUTS", "0") + apptest.Tools(a, lookup) + }, in, "--out", out) + + if r.code != process.ExitFailure { + t.Errorf("code = %d, want %d", r.code, process.ExitFailure) + } + if want := "docproc run: bounds: DOCPROC_PUTS: 0 is below 1"; !strings.HasPrefix(r.stderr, want) { + t.Errorf("stderr = %q, want it to start with %q", r.stderr, want) + } + if log := looked.Log(); len(log) != 0 { + t.Errorf("tools looked up = %q, want none", log) + } +} diff --git a/cmd/docproc/internal/app/doc.go b/cmd/docproc/internal/app/doc.go index b80ec5df..ad508fc2 100644 --- a/cmd/docproc/internal/app/doc.go +++ b/cmd/docproc/internal/app/doc.go @@ -7,9 +7,10 @@ // - app.go: [App], [New], and [Nodes], which call the layer files' define and mount functions // in layer order, lowest first; // - infrastructure.go: defineInfrastructure, the configuration, read from DOCPROC_ variables: -// the lifecycle configuration and [Bounds], a run's bounds at docproc's starting values; +// the lifecycle configuration and the bounds, a settings.Settings at docproc's starting +// values, each variable overriding its key, assembled into a settings.Run; // - domain.go: defineDomain and mountDomain, the services over docproc's library, the stage -// builder, stages.Build over the host's tools, and the run config over it and [Bounds], and +// builder, stages.Build over the host's tools, and the run config over it and the bounds, and // the commands, from the command packages under internal/, that run them: run, from // internal/run; // - version.go: the version command, which declares no nodes. diff --git a/cmd/docproc/internal/app/domain.go b/cmd/docproc/internal/app/domain.go index 8477d65b..a7a14f56 100644 --- a/cmd/docproc/internal/app/domain.go +++ b/cmd/docproc/internal/app/domain.go @@ -16,11 +16,8 @@ import ( func defineDomain(g *graph.Graph, n *Nodes) { n.StageBuilder = g.Define("stage builder", newStageBuilder) n.RunConfig = g.Define("run config", func(s *graph.Scope) (run.Config, error) { - b := s.Use(n.Bounds) return run.Config{ - Stages: b.Stages, - Limits: b.Limits, - Release: b.Release, + Bounds: s.Use(n.Bounds), Build: s.Use(n.StageBuilder), Docproc: docprocBuild(), }, nil diff --git a/cmd/docproc/internal/app/infrastructure.go b/cmd/docproc/internal/app/infrastructure.go index 37b0ac6a..4cf15154 100644 --- a/cmd/docproc/internal/app/infrastructure.go +++ b/cmd/docproc/internal/app/infrastructure.go @@ -3,21 +3,15 @@ package app import ( "errors" "fmt" - "math" "strconv" + "strings" "time" "github.com/standards-lab/go-core/config" "github.com/standards-lab/go-core/graph" "github.com/standards-lab/go-core/lifecycle" - "github.com/standards-lab/docproc/audio" - "github.com/standards-lab/docproc/dispatch" - "github.com/standards-lab/docproc/document" - "github.com/standards-lab/docproc/inspect" - "github.com/standards-lab/docproc/media" - "github.com/standards-lab/docproc/picture" - "github.com/standards-lab/docproc/stages" + "github.com/standards-lab/docproc/settings" ) const envPrefix = "DOCPROC" @@ -33,129 +27,126 @@ func newLifecycleConfig(*graph.Scope) (lifecycle.Config, error) { return cfg, err } -// Bounds are a run's bounds, in the shapes the library takes them, so a run hands them on as -// they are: Stages to stages.Build, and Limits and Release to the dispatch.Config, with the -// stages.Set's Inspect, these options validated, as its Inspect. The library sets no bound of -// its own; each here starts at docproc's starting value, which its variable overrides. -type Bounds struct { - // Stages carry the run bounds, the inspection options, and the PDF, audio, video, and - // ImageMagick bounds; every other option is the zero value, so every route is wired and every - // other request is at its own defaults. - Stages stages.Options - // Limits are each dispatch's caps. - Limits dispatch.Limits - // Release bounds a claim's release once a dispatch's context has ended: - // dispatch.Config.Release. - Release time.Duration -} - const gib = 1 << 30 -const ( - bombRatioVar = "bomb ratio" - bombSizeVar = "bomb size" -) - // See docs/command.md, "Configuration". -func newBounds(*graph.Scope) (Bounds, error) { - b := Bounds{ - Stages: stages.Options{ - Memory: 2 * gib, - Timeout: 10 * time.Minute, - Idle: 2 * time.Minute, - Inspect: inspect.Options{BombRatio: 1000, BombSize: 1 * gib, Entries: 100_000}, - - Concurrency: 1, - Document: document.ImagesRequest{DPI: 150, Text: true, MaxPixels: 64_000_000}, - Video: media.Request{MaxSide: 2048}, - Magick: picture.Limits{Area: 256_000_000, Memory: 1 * gib, Map: 2 * gib, Disk: 8 * gib}, - Audio: audio.Request{Limit: 30 * time.Second}, - }, - Limits: dispatch.Limits{Parts: 100_000, Bytes: 32 * gib, Depth: 16}, - Release: 10 * time.Second, +func newBounds(*graph.Scope) (settings.Run, error) { + s := settings.Settings{ + ToolMemory: new(int64(2 * gib)), + UnitTimeout: new(10 * time.Minute), + StreamIdle: new(2 * time.Minute), + MaxParts: new(100_000), + MaxBytes: new(int64(32 * gib)), + MaxDepth: new(16), + BombRatio: new(float64(1000)), + BombSize: new(uint64(1 * gib)), + ArchiveEntries: new(100_000), + ClaimRelease: new(10 * time.Second), + Concurrency: new(1), + PDFDPI: new(150), + PDFText: new(true), + PDFMaxPixels: new(int64(64_000_000)), + FrameMaxSide: new(2048), + MagickArea: new(int64(256_000_000)), + MagickMemory: new(int64(1 * gib)), + MagickMap: new(int64(2 * gib)), + MagickDisk: new(int64(8 * gib)), + AudioLimit: new(30 * time.Second), + Puts: new(1), } errs := []error{ - readEnv(&b.Stages.Memory, "tool memory", parseCount[int64]), - readEnv(&b.Stages.Timeout, "unit timeout", parseDuration), - readEnv(&b.Stages.Idle, "stream idle", parseDuration), - readEnv(&b.Limits.Parts, "max parts", parseCount[int]), - readEnv(&b.Limits.Bytes, "max bytes", parseCount[int64]), - readEnv(&b.Limits.Depth, "max depth", parseCount[int]), - readEnv(&b.Stages.Inspect.BombRatio, bombRatioVar, parseRatio), - readEnv(&b.Stages.Inspect.BombSize, bombSizeVar, parseCount[uint64]), - readEnv(&b.Stages.Inspect.Entries, "archive entries", parseCount[int]), - readEnv(&b.Release, "claim release", parseDuration), - readEnv(&b.Stages.Concurrency, "concurrency", parseCount[int]), - readEnv(&b.Stages.Document.DPI, "pdf dpi", parseCount[int]), - readEnv(&b.Stages.Document.Text, "pdf text", strconv.ParseBool), - readEnv(&b.Stages.Document.MaxPixels, "pdf max pixels", parseCount[int64]), - readEnv(&b.Stages.Video.MaxSide, "frame max side", parseCount[int]), - readEnv(&b.Stages.Magick.Area, "magick area", parseCount[int64]), - readEnv(&b.Stages.Magick.Memory, "magick memory", parseCount[int64]), - readEnv(&b.Stages.Magick.Map, "magick map", parseCount[int64]), - readEnv(&b.Stages.Magick.Disk, "magick disk", parseCount[int64]), - readEnv(&b.Stages.Audio.Limit, "audio limit", parseAudioLimit), + readEnv(&s.ToolMemory, "tool_memory", parseCount[int64]), + readEnv(&s.UnitTimeout, "unit_timeout", parseDuration), + readEnv(&s.StreamIdle, "stream_idle", parseDuration), + readEnv(&s.MaxParts, "max_parts", parseCount[int]), + readEnv(&s.MaxBytes, "max_bytes", parseCount[int64]), + readEnv(&s.MaxDepth, "max_depth", parseCount[int]), + readEnv(&s.BombRatio, "bomb_ratio", parseRatio), + readEnv(&s.BombSize, "bomb_size", parseSize), + readEnv(&s.ArchiveEntries, "archive_entries", parseCount[int]), + readEnv(&s.ClaimRelease, "claim_release", parseDuration), + readZeroIsDefault(&s.Concurrency, "concurrency"), + readZeroIsDefault(&s.PDFDPI, "pdf_dpi"), + readEnv(&s.PDFText, "pdf_text", strconv.ParseBool), + readEnv(&s.PDFMaxPixels, "pdf_max_pixels", parseCount[int64]), + readEnv(&s.FrameMaxSide, "frame_max_side", parseCount[int]), + readEnv(&s.MagickArea, "magick_area", parseCount[int64]), + readEnv(&s.MagickMemory, "magick_memory", parseCount[int64]), + readEnv(&s.MagickMap, "magick_map", parseCount[int64]), + readEnv(&s.MagickDisk, "magick_disk", parseCount[int64]), + readEnv(&s.AudioLimit, "audio_limit", parseDuration), + readEnv(&s.Puts, "puts", parseCount[int]), } - if (b.Stages.Inspect.BombRatio == 0) != (b.Stages.Inspect.BombSize == 0) { - errs = append(errs, fmt.Errorf("%s and %s: set both above zero, or both to zero for no bomb rule", - config.EnvName(envPrefix, bombRatioVar), config.EnvName(envPrefix, bombSizeVar))) - } - return b, errors.Join(errs...) + run, err := s.Assemble() + return run, errors.Join(append(errs, variables(err)...)...) +} + +func readEnv[T any](dest **T, key string, parse func(string) (T, error)) error { + return config.SetFromEnv(dest, config.EnvName(envPrefix, key), parse) } -func readEnv[T any](dest *T, bound string, parse func(string) (T, error)) error { - var v *T - err := config.SetFromEnv(&v, config.EnvName(envPrefix, bound), parse) - if v != nil { - *dest = *v +func readZeroIsDefault(dest **int, key string) error { + err := readEnv(dest, key, parseCount[int]) + if *dest != nil && **dest == 0 { + *dest = nil } return err } -func parseCount[T int | int64 | uint64](s string) (T, error) { +func variables(err error) []error { + if err == nil { + return nil + } + refusals := []error{err} + if joined, ok := err.(interface{ Unwrap() []error }); ok { + refusals = joined.Unwrap() + } + var errs []error + for _, refusal := range refusals { + msg := strings.TrimPrefix(refusal.Error(), "settings: ") + msg = strings.TrimSuffix(msg, ": "+settings.ErrRequest.Error()) + keys, reason, _ := strings.Cut(msg, ": ") + names := strings.Split(keys, " and ") + for i, key := range names { + names[i] = config.EnvName(envPrefix, key) + } + errs = append(errs, fmt.Errorf("%s: %s", strings.Join(names, " and "), reason)) + } + return errs +} + +func parseCount[T int | int64](s string) (T, error) { n, err := strconv.ParseInt(s, 10, 64) switch { case errors.Is(err, strconv.ErrRange), err == nil && int64(T(n)) != n: return 0, fmt.Errorf("%s is out of range", s) case err != nil: return 0, fmt.Errorf("%q is not a whole number", s) - case n < 0: - return 0, fmt.Errorf("%d is below zero", n) } return T(n), nil } -func parseDuration(s string) (time.Duration, error) { - d, err := time.ParseDuration(s) - switch { - case err != nil: - return 0, fmt.Errorf("%q is not a duration, such as 90s or 10m", s) - case d < 0: - return 0, fmt.Errorf("%s is below zero", d) +func parseSize(s string) (uint64, error) { + n, err := parseCount[int64](s) + if err == nil && n < 0 { + return 0, fmt.Errorf("%d is below zero", n) } - return d, nil + return uint64(n), err } -func parseAudioLimit(s string) (time.Duration, error) { - d, err := parseDuration(s) +func parseDuration(s string) (time.Duration, error) { + d, err := time.ParseDuration(s) if err != nil { - return 0, err - } - if _, err := audio.NewPlanner(audio.Request{Limit: d}); d == 0 || err != nil { - return 0, fmt.Errorf("%v isn't over %v, twice the %v overlap between windows", - d, 2*audio.DefaultOverlap, audio.DefaultOverlap) + return 0, fmt.Errorf("%q is not a duration, such as 90s or 10m", s) } return d, nil } func parseRatio(s string) (float64, error) { r, err := strconv.ParseFloat(s, 64) - switch { - case err != nil, math.IsNaN(r), math.IsInf(r, 0): - return 0, fmt.Errorf("%q is not a finite number", s) - case r < 0: - return 0, fmt.Errorf("%g is below zero", r) + if err != nil { + return 0, fmt.Errorf("%q is not a number", s) } return r, nil } diff --git a/cmd/docproc/internal/run/commands.go b/cmd/docproc/internal/run/commands.go index 54149453..2b378a02 100644 --- a/cmd/docproc/internal/run/commands.go +++ b/cmd/docproc/internal/run/commands.go @@ -5,14 +5,13 @@ import ( "io" "runtime" "slices" - "time" "github.com/standards-lab/go-cli-sdk" "github.com/standards-lab/go-core/graph" - "github.com/standards-lab/docproc/dispatch" "github.com/standards-lab/docproc/route" "github.com/standards-lab/docproc/rundir/schema" + "github.com/standards-lab/docproc/settings" "github.com/standards-lab/docproc/stages" ) @@ -23,14 +22,9 @@ type StageBuilder func(ctx context.Context, opts stages.Options) (stages.Set, er // Config is what the run command runs under: the run's bounds, in the library's shapes, the // stage builder, and the docproc build that writes the run. type Config struct { - // Stages are the options the stages are built under; the command adds the routes --exclude - // names to their Exclude. - Stages stages.Options - // Limits are each dispatch's caps, dispatch.Config.Limits. - Limits dispatch.Limits - // Release bounds a claim's release once a dispatch's context has ended, - // dispatch.Config.Release. - Release time.Duration + // Bounds are the run's bounds: the options the stages are built under, to whose Exclude the + // command adds the routes --exclude names, and each dispatch's Limits, Release, and Puts. + Bounds settings.Run // Build builds the stages; it is required. Build StageBuilder // Docproc is what writes the run, the manifest's "docproc". @@ -95,7 +89,7 @@ func command(cfg *graph.Node[Config]) *cli.Command { return err } c := inv.Get(cfg) - c.Stages.Exclude = slices.Concat(c.Stages.Exclude, excluded) + c.Bounds.Stages.Exclude = slices.Concat(c.Bounds.Stages.Exclude, excluded) r := &runner{cfg: c, w: inv.Stdout, out: out, args: inv.Args, inputs: inputs, workers: workers, report: render} return r.run(ctx) }, diff --git a/cmd/docproc/internal/run/doc.go b/cmd/docproc/internal/run/doc.go index 5dee1319..abbec30f 100644 --- a/cmd/docproc/internal/run/doc.go +++ b/cmd/docproc/internal/run/doc.go @@ -14,16 +14,15 @@ // // The run's manifest names its docproc build, its workers, its path arguments, how many inputs they // named, the tools the stage builder tried, and the stage table. Each output's content is in the -// run directory's content store, put there by the dispatcher one at a time per dispatch, since a -// put is a copy on the local disk the workers' dispatches already keep busy, and a part the index -// has seen replays its log, its children's included, through the dispatcher, so every line is this -// run's own. An input's own part line, its last, carries its file's metadata, through os.Stat and -// statx's birth time where the kernel gives one, and its type as net/http.DetectContentType sniffs -// it, and its time, from its first event to its last, both taken on the pool's loop. A quarantined -// part's file is kept in the run directory, and its line names the kept file whenever it exists, -// whether this run or an earlier one kept it; an unread child, as an archive's entry with an unsafe -// name, has no file and no SHA-256, so nothing of it is kept. An input whose dispatch stopped -// before its own event is an error line. +// run directory's content store, put there by the dispatcher, its bounds' Puts at a time per +// dispatch, and a part the index has seen replays its log, its children's included, through the +// dispatcher, so every line is this run's own. An input's own part line, its last, carries its +// file's metadata, through os.Stat and statx's birth time where the kernel gives one, and its type +// as net/http.DetectContentType sniffs it, and its time, from its first event to its last, both +// taken on the pool's loop. A quarantined part's file is kept in the run directory, and its line +// names the kept file whenever it exists, whether this run or an earlier one kept it; an unread +// child, as an archive's entry with an unsafe name, has no file and no SHA-256, so nothing of it is +// kept. An input whose dispatch stopped before its own event is an error line. // // As each input's own event arrives, the terminal prints one line: its path, route, outcome, // outputs, children, and time, a failed part's error cut to its first line and at most 400 runes, diff --git a/cmd/docproc/internal/run/runner.go b/cmd/docproc/internal/run/runner.go index 01e2e21e..cb3365b8 100644 --- a/cmd/docproc/internal/run/runner.go +++ b/cmd/docproc/internal/run/runner.go @@ -18,8 +18,6 @@ import ( "github.com/standards-lab/docproc/cmd/docproc/internal/report" ) -const puts = 1 - type runner struct { cfg Config w io.Writer @@ -31,7 +29,7 @@ type runner struct { } func (r *runner) run(ctx context.Context) error { - set, err := r.cfg.Build(ctx, r.cfg.Stages) + set, err := r.cfg.Build(ctx, r.cfg.Bounds.Stages) if err != nil { return err } @@ -101,10 +99,10 @@ func (r *runner) dispatch(ctx context.Context, set stages.Set, rec *recorder) (e Index: rec.dir.Index(), Content: rec.dir.Content(), Dir: work, - Limits: r.cfg.Limits, + Limits: r.cfg.Bounds.Limits, Inspect: set.Inspect, - Puts: puts, - Release: r.cfg.Release, + Puts: r.cfg.Bounds.Puts, + Release: r.cfg.Bounds.Release, }) if err != nil { return err diff --git a/docs/command.md b/docs/command.md index a1685f4b..c171fbaf 100644 --- a/docs/command.md +++ b/docs/command.md @@ -86,3 +86,4 @@ shutdown. | `DOCPROC_MAGICK_MAP` | The most bytes of the pixel cache that may be memory-mapped (`-limit map`) | 2 GiB | | `DOCPROC_MAGICK_DISK` | The most bytes of the pixel cache that may be on disk (`-limit disk`) | 8 GiB | | `DOCPROC_AUDIO_LIMIT` | The longest audio window, its overlaps included (`Options.Audio.Limit`); a host sets it to its model's request size, the longest audio one request takes. A source no longer than it is one window. It must be over 4s, twice the 2 s overlap between windows, so zero is refused | 30s | +| `DOCPROC_PUTS` | The most content puts in flight per dispatch (`dispatch.Config.Puts`); a put is a copy on the local disk the workers' dispatches already keep busy. It must be at least 1, so zero is refused | 1 | From b2ccbba5fc291118a664b8e7edbff74d039e3aaf Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Sat, 28 Nov 2026 17:18:15 -0500 Subject: [PATCH 5/9] docproc-settings: release documentation; base v0.11.0; storage v0.1.9, postgres v0.1.9, cmd/docproc v0.2.9 - CHANGELOG.md: [Unreleased] becomes [v0.11.0] - 2026-11-28, an empty Unreleased above it and the compare links extended, as d66d5f3 did. Added lists the settings package: Settings, Decode, Validate, ErrRequest, Run, Assemble, the 21 keys, the four optional ones and their defaults; the Gotenberg 9.10.3 entry stays under Changed. The README's go get line names v0.11.0. - storage v0.1.9 and postgres v0.1.9: their CHANGELOGs require base v0.11.0 and say what reaches a caller (nothing stored or indexed changes; no stage identity moves); their README install lines name v0.1.9. - cmd/docproc v0.2.9: Added DOCPROC_PUTS; Changed the move onto settings, every existing variable keeping its meaning, format, and default, the Gotenberg 9.10.3 image as v0.2.8 listed its pin moves, and go-core v0.14.0. Decisions: - The go.mod files don't move here. v0.11.0 isn't tagged, and check:go resolves each module with GOWORK=off, so storage and postgres stay on v0.10.0 and cmd/docproc keeps its replace => ../.. with the require at v0.10.0, as 0dab39f left it. At SHIP, after v0.11.0 is tagged, one commit bumps the three requires to v0.11.0 and drops cmd/docproc's replace, as 0cb2f43 did, before the provider and command tags. - The provider CHANGELOGs and READMEs are written now rather than in that later commit, since the brief puts them in this slice. mise run check passes. --- CHANGELOG.md | 37 ++++++++++++++++++++++++++++++++++++- README.md | 2 +- cmd/docproc/CHANGELOG.md | 27 ++++++++++++++++++++++++++- postgres/CHANGELOG.md | 15 ++++++++++++++- postgres/README.md | 2 +- storage/CHANGELOG.md | 14 +++++++++++++- storage/README.md | 2 +- 7 files changed, 92 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9db0bc8d..eef5b06d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,40 @@ tool under `tools/` keeps its own. ## [Unreleased] +## [v0.11.0] - 2026-11-28 + +This release adds the package `settings`, which holds a run's settings as one flat JSON object, so +a host that takes its bounds as JSON, rather than as cmd/docproc's `DOCPROC_` variables, reads, +validates, and assembles them into the shapes `stages.Build` and `dispatch.New` take. No existing +API changes, `dispatch.Version` stays "1", and the run directory's schema stays "2". + +### Added + +- Package `settings`, on the standard library and docproc's own packages alone. Its 21 keys are + each named for the `DOCPROC_` variable cmd/docproc reads it from, without the prefix and in + snake case: `tool_memory`, `unit_timeout`, `stream_idle`, `max_parts`, `max_bytes`, + `max_depth`, `bomb_ratio`, `bomb_size`, `archive_entries`, `claim_release`, `concurrency`, + `pdf_dpi`, `pdf_text`, `pdf_max_pixels`, `frame_max_side`, `magick_area`, `magick_memory`, + `magick_map`, `magick_disk`, `audio_limit`, and `puts`. The library sets no bound of its own, + so every key but four is required, and zero is no bound. The four optional keys, unset, take a + default: `concurrency` 1, `pdf_dpi` `document.DefaultDPI`, `audio_limit` + `audio.DefaultWindowLimit`, and `puts` 1; set, each is at least 1, or for `audio_limit` over + 4s. A duration is a Go duration string, such as `"90s"`, and `bomb_ratio` and `bomb_size` are + both zero, for no bomb rule, or both above it. The [API page](docs/api.md#settings) states each + key's format and the field it lands in. +- `settings.Settings`, one pointer field per key, nil when unset, so an unset key is told from an + explicit zero; a Go caller sets a key with `new`. +- `settings.Decode`, which reads settings from one JSON object and validates them; input that + isn't one object, an unknown key, a value of the wrong JSON type, and trailing data are refused. +- `Settings.Validate`, which refuses settings a run can't take, each refusal naming its key, and + every unset required key in one error. +- `settings.ErrRequest`, which every refusal wraps. +- `settings.Run`, settings in the library's shapes: the `stages.Options` a host passes + `stages.Build`, each option no key covers the zero value, the host's own; and the + `dispatch.Limits`, `Release`, and `Puts` it passes `dispatch.New` in its `Config`. +- `Settings.Assemble`, which validates settings and returns their `Run`, each optional key left + unset at its default. + ### Changed - `picture.LibreOfficeImage` is `gotenberg/gotenberg:9.10.3-libreoffice`, from 9.10.2-libreoffice, @@ -611,7 +645,8 @@ fixtures scripts stay in the spike. The [limits page](docs/limits.md) states them: each stage's tool's limits, docproc-ooxml's behavior under a memory bound, the Threader's memory, and the formats no stage reads. -[Unreleased]: https://github.com/standards-lab/docproc/compare/v0.10.0...HEAD +[Unreleased]: https://github.com/standards-lab/docproc/compare/v0.11.0...HEAD +[v0.11.0]: https://github.com/standards-lab/docproc/compare/v0.10.0...v0.11.0 [v0.10.0]: https://github.com/standards-lab/docproc/compare/v0.9.0...v0.10.0 [v0.9.0]: https://github.com/standards-lab/docproc/compare/v0.8.0...v0.9.0 [v0.8.0]: https://github.com/standards-lab/docproc/compare/v0.7.0...v0.8.0 diff --git a/README.md b/README.md index d91e5c16..1c09aaf8 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ tags. ## Install ```sh -go get github.com/standards-lab/docproc@v0.10.0 +go get github.com/standards-lab/docproc@v0.11.0 ``` The module's releases are tagged `vX.Y.Z`, and [`CHANGELOG.md`](CHANGELOG.md) states what each diff --git a/cmd/docproc/CHANGELOG.md b/cmd/docproc/CHANGELOG.md index 1e976c86..96a1d990 100644 --- a/cmd/docproc/CHANGELOG.md +++ b/cmd/docproc/CHANGELOG.md @@ -10,6 +10,30 @@ postgres modules, and each system tool under `tools/` keep their own. ## [Unreleased] +## [v0.2.9] - 2026-11-28 + +This release reads its run bounds through the docproc base module's new package `settings`, at +v0.11.0, and adds `DOCPROC_PUTS`. Its exit codes and run directory's schema are unchanged, and +every existing variable keeps its meaning and its default. + +### Added + +- `DOCPROC_PUTS`, the most content puts in flight per dispatch (`dispatch.Config.Puts`), at + least 1, so zero is refused; unset or empty, it is 1, the bound `docproc run` held before. + +### Changed + +- The module requires the docproc base module at v0.11.0, whose + [CHANGELOG](../../CHANGELOG.md) states its changes in full. `docproc run` reads each + `DOCPROC_` variable into its key of a `settings.Settings` and assembles them into a + `settings.Run`, the bounds it passes `stages.Build` and `dispatch.New`. Each variable keeps its + meaning, its format, and its default, `DOCPROC_CONCURRENCY` and `DOCPROC_PDF_DPI` at zero + included. A refused value still fails `docproc run` before any tool is looked up, and its + message names the variable, such as `bounds: DOCPROC_PUTS: 0 is below 1`. +- soffice runs in `gotenberg/gotenberg:9.10.3-libreoffice`, from 9.10.2-libreoffice, pinned by + its multi-arch index digest. +- The module requires go-core v0.14.0, from v0.12.0; nothing `docproc run` does changes with it. + ## [v0.2.8] - 2026-11-27 This release requires the docproc base module at v0.10.0, whose changes reach `docproc run` as @@ -319,7 +343,8 @@ and go-core v0.12.0, in place of the spike's port of go-cli-sdk v0.2.0's. writes, read back through `rundir`, and the report it renders of a fixture run and of a killed run. -[Unreleased]: https://github.com/standards-lab/docproc/compare/cmd/docproc/v0.2.8...HEAD +[Unreleased]: https://github.com/standards-lab/docproc/compare/cmd/docproc/v0.2.9...HEAD +[v0.2.9]: https://github.com/standards-lab/docproc/compare/cmd/docproc/v0.2.8...cmd/docproc/v0.2.9 [v0.2.8]: https://github.com/standards-lab/docproc/compare/cmd/docproc/v0.2.7...cmd/docproc/v0.2.8 [v0.2.7]: https://github.com/standards-lab/docproc/compare/cmd/docproc/v0.2.6...cmd/docproc/v0.2.7 [v0.2.6]: https://github.com/standards-lab/docproc/compare/cmd/docproc/v0.2.5...cmd/docproc/v0.2.6 diff --git a/postgres/CHANGELOG.md b/postgres/CHANGELOG.md index 1cd7bc85..86c580d1 100644 --- a/postgres/CHANGELOG.md +++ b/postgres/CHANGELOG.md @@ -10,6 +10,18 @@ each system tool under `tools/` keep their own. ## [Unreleased] +## [v0.1.9] - 2026-11-28 + +This release requires the docproc base module at v0.11.0. Its exported API is unchanged. + +### Changed + +- The module requires the docproc base module at v0.11.0, from v0.10.0, and passes its + `dispatchtest.Index` suite; its [CHANGELOG](../CHANGELOG.md) states the base module's changes. + The base module adds the package `settings`, a run's settings as one JSON object, and moves + soffice's image. No stage's identity changes, so a run over the index replays a caller's earlier + entries as before. The index itself is unchanged. + ## [v0.1.8] - 2026-11-27 This release requires the docproc base module at v0.10.0. Its exported API is unchanged. @@ -161,7 +173,8 @@ tier runs on; and pgx v5.13.0, whose `database/sql` driver the host's pool must skipped. The host drives it from a sweeper; the age has no default. A non-positive age and a budget below 1 are refused, matching `dispatch.ErrRequest`, and a nil `db` panics. -[Unreleased]: https://github.com/standards-lab/docproc/compare/postgres/v0.1.8...HEAD +[Unreleased]: https://github.com/standards-lab/docproc/compare/postgres/v0.1.9...HEAD +[v0.1.9]: https://github.com/standards-lab/docproc/compare/postgres/v0.1.8...postgres/v0.1.9 [v0.1.8]: https://github.com/standards-lab/docproc/compare/postgres/v0.1.7...postgres/v0.1.8 [v0.1.7]: https://github.com/standards-lab/docproc/compare/postgres/v0.1.6...postgres/v0.1.7 [v0.1.6]: https://github.com/standards-lab/docproc/compare/postgres/v0.1.5...postgres/v0.1.6 diff --git a/postgres/README.md b/postgres/README.md index 92f2f2c4..135683f4 100644 --- a/postgres/README.md +++ b/postgres/README.md @@ -9,7 +9,7 @@ requires the base module, sqlate, sqlate's `postgres` dialect, and pgx. ## Install ```sh -go get github.com/standards-lab/docproc/postgres@v0.1.8 +go get github.com/standards-lab/docproc/postgres@v0.1.9 ``` [`CHANGELOG.md`](CHANGELOG.md) states what each release changes. The package's documentation, diff --git a/storage/CHANGELOG.md b/storage/CHANGELOG.md index b4c48483..fe454b4f 100644 --- a/storage/CHANGELOG.md +++ b/storage/CHANGELOG.md @@ -10,6 +10,17 @@ each system tool under `tools/` keep their own. ## [Unreleased] +## [v0.1.9] - 2026-11-28 + +This release requires the docproc base module at v0.11.0. Its exported API is unchanged. + +### Changed + +- The module requires the docproc base module at v0.11.0, from v0.10.0, and passes its + `dispatchtest.Content` suite; its [CHANGELOG](../CHANGELOG.md) states the base module's changes. + The base module adds the package `settings`, a run's settings as one JSON object, and moves + soffice's image; neither changes what this module stores or how. + ## [v0.1.8] - 2026-11-27 This release requires the docproc base module at v0.10.0. Its exported API is unchanged. @@ -128,7 +139,8 @@ The first release. It requires `github.com/standards-lab/docproc` v0.1.0, whose a missing container; the live tier, under `-tags integration`, runs it over go-storage's S3 provider against the compose harness's SeaweedFS. -[Unreleased]: https://github.com/standards-lab/docproc/compare/storage/v0.1.8...HEAD +[Unreleased]: https://github.com/standards-lab/docproc/compare/storage/v0.1.9...HEAD +[v0.1.9]: https://github.com/standards-lab/docproc/compare/storage/v0.1.8...storage/v0.1.9 [v0.1.8]: https://github.com/standards-lab/docproc/compare/storage/v0.1.7...storage/v0.1.8 [v0.1.7]: https://github.com/standards-lab/docproc/compare/storage/v0.1.6...storage/v0.1.7 [v0.1.6]: https://github.com/standards-lab/docproc/compare/storage/v0.1.5...storage/v0.1.6 diff --git a/storage/README.md b/storage/README.md index 1df1ef5f..57629d67 100644 --- a/storage/README.md +++ b/storage/README.md @@ -11,7 +11,7 @@ requires `s3`, for its live tier alone. ## Install ```sh -go get github.com/standards-lab/docproc/storage@v0.1.8 +go get github.com/standards-lab/docproc/storage@v0.1.9 ``` [`CHANGELOG.md`](CHANGELOG.md) states what each release changes. The package's documentation, From 08cd0fee45f4e43f9ce96c98dcf12c0513be46bf Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Sat, 28 Nov 2026 17:21:17 -0500 Subject: [PATCH 6/9] settings.KeyError: cmd/docproc names a refused key's variable from the refusal, not its text cmd/docproc rewrote settings' error strings, cutting their prefix and suffix and splitting the key off the reason, so a change to settings' wording would silently mis-name a variable. A refused value is now a settings.KeyError carrying its keys and reason, wrapping ErrRequest, as dispatch.StoreError and tool.VersionError carry theirs; cmd/docproc renders it. Every message is unchanged. Standard: construction-and-execution (a refusal matches its package's ErrRequest), consistency with the library's structured errors. --- CHANGELOG.md | 2 + cmd/docproc/internal/app/infrastructure.go | 20 +++++----- docs/api.md | 3 ++ settings/doc.go | 5 ++- settings/settings.go | 43 ++++++++++++++++++---- settings/settings_test.go | 38 +++++++++++++++++++ 6 files changed, 92 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eef5b06d..e1dce9ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,8 @@ API changes, `dispatch.Version` stays "1", and the run directory's schema stays - `Settings.Validate`, which refuses settings a run can't take, each refusal naming its key, and every unset required key in one error. - `settings.ErrRequest`, which every refusal wraps. +- `settings.KeyError`, the refusal of the values of the keys it names, its `Keys` and its + `Reason`, so a host names its own source for each key; it wraps `ErrRequest`. - `settings.Run`, settings in the library's shapes: the `stages.Options` a host passes `stages.Build`, each option no key covers the zero value, the host's own; and the `dispatch.Limits`, `Release`, and `Puts` it passes `dispatch.New` in its `Config`. diff --git a/cmd/docproc/internal/app/infrastructure.go b/cmd/docproc/internal/app/infrastructure.go index 4cf15154..71212546 100644 --- a/cmd/docproc/internal/app/infrastructure.go +++ b/cmd/docproc/internal/app/infrastructure.go @@ -102,16 +102,18 @@ func variables(err error) []error { if joined, ok := err.(interface{ Unwrap() []error }); ok { refusals = joined.Unwrap() } - var errs []error - for _, refusal := range refusals { - msg := strings.TrimPrefix(refusal.Error(), "settings: ") - msg = strings.TrimSuffix(msg, ": "+settings.ErrRequest.Error()) - keys, reason, _ := strings.Cut(msg, ": ") - names := strings.Split(keys, " and ") - for i, key := range names { - names[i] = config.EnvName(envPrefix, key) + errs := make([]error, len(refusals)) + for i, refusal := range refusals { + var ke *settings.KeyError + if !errors.As(refusal, &ke) { + errs[i] = refusal + continue } - errs = append(errs, fmt.Errorf("%s: %s", strings.Join(names, " and "), reason)) + names := make([]string, len(ke.Keys)) + for j, key := range ke.Keys { + names[j] = config.EnvName(envPrefix, key) + } + errs[i] = fmt.Errorf("%s: %s", strings.Join(names, " and "), ke.Reason) } return errs } diff --git a/docs/api.md b/docs/api.md index d9e92abc..62d080d0 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1077,6 +1077,9 @@ type Run struct { Puts int // dispatch.Config.Puts } var ErrRequest = errors.New("invalid request") // every refusal wraps it +// KeyError is the refusal of the values of the keys it names, one key or both bomb_ratio and +// bomb_size; it wraps ErrRequest. Unknown keys and unset required keys aren't KeyErrors. +type KeyError struct { Keys []string; Reason string } ``` The keys, their formats, where each lands, and whether it is required: diff --git a/settings/doc.go b/settings/doc.go index 30a1ffcd..a000136c 100644 --- a/settings/doc.go +++ b/settings/doc.go @@ -38,7 +38,7 @@ // table names: document.DefaultDPI, 150 DPI, and audio.DefaultWindowLimit, 30s; set, it is at // least 1, or for audio_limit over twice audio.DefaultOverlap, 4s, the shortest window the audio // cutter takes. A refusal names its key and wraps [ErrRequest], as does input that isn't one JSON -// object, an unknown key, and a value of the wrong JSON type. +// object, an unknown key, and a value of the wrong JSON type; a refused value is a [KeyError]. // // [Settings.Assemble] validates the settings and assembles them into a [Run], in the shapes the // library takes them: the stages.Options a host passes stages.Build, each field the table names @@ -53,5 +53,6 @@ // - [Decode] reads settings from JSON and validates them. // - [Run] is settings in the library's shapes; [Settings.Assemble] validates settings and // returns their Run. -// - [ErrRequest] is refused settings' cause. +// - [ErrRequest] is refused settings' cause; [KeyError] is the refusal of the values of the +// keys it names, so a host names its own source for each key. package settings diff --git a/settings/settings.go b/settings/settings.go index 732233e4..2110b574 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -18,6 +18,26 @@ import ( // refuses. var ErrRequest = errors.New("invalid request") +// A KeyError is a refusal of the values of the keys it names: one key, or both bomb_ratio and +// bomb_size, and the reason, so a host names its own source for each key, as cmd/docproc names +// its DOCPROC_ variable. It wraps ErrRequest. Every refusal of a key's value is a KeyError; the +// refusals of input that isn't one JSON object, an unknown key, and unset required keys aren't. +type KeyError struct { + // Keys are the refused keys, as the JSON names them. + Keys []string + // Reason is why the values are refused, such as "-1 is below zero". + Reason string +} + +// Error is "settings: " and the keys, joined with " and ", the reason, and ErrRequest's text, +// each separated by ": ". +func (e *KeyError) Error() string { + return fmt.Sprintf("settings: %s: %s: %v", strings.Join(e.Keys, " and "), e.Reason, ErrRequest) +} + +// Unwrap returns ErrRequest. +func (e *KeyError) Unwrap() error { return ErrRequest } + // Settings are a run's settings, one key for each, nil when unset. Every key but PDFDPI, // Concurrency, AudioLimit, and Puts is required, and zero is no bound. type Settings struct { @@ -113,7 +133,7 @@ func decodeError(err error) error { case errors.As(err, &typ) && typ.Field == "": return refuse("the input is a JSON %s, not an object", typ.Value) case errors.As(err, &typ): - return refuse("%s: a JSON %s isn't %s", typ.Field, typ.Value, describe(typ.Type)) + return refuseKey(typ.Field, "a JSON %s isn't %s", typ.Value, describe(typ.Type)) } if name, ok := strings.CutPrefix(err.Error(), "json: unknown field "); ok { return refuse("unknown key %s", name) @@ -141,11 +161,11 @@ func parseDuration(dest **time.Duration, key string, raw json.RawMessage) error } var s string if err := json.Unmarshal(raw, &s); err != nil { - return refuse("%s: %s isn't a duration string, such as \"90s\" or \"10m\"", key, raw) + return refuseKey(key, "%s isn't a duration string, such as \"90s\" or \"10m\"", raw) } d, err := time.ParseDuration(s) if err != nil { - return refuse("%s: %q isn't a duration, such as \"90s\" or \"10m\"", key, s) + return refuseKey(key, "%q isn't a duration, such as \"90s\" or \"10m\"", s) } *dest = &d return nil @@ -220,9 +240,9 @@ func atLeast[T ~int | ~int64](key string, v *T, floor T) error { case v == nil || *v >= floor: return nil case floor == 0: - return refuse("%s: %v is below zero", key, *v) + return refuseKey(key, "%v is below zero", *v) } - return refuse("%s: %v is below %v", key, *v, floor) + return refuseKey(key, "%v is below %v", *v, floor) } func (s Settings) bomb() error { @@ -230,9 +250,12 @@ func (s Settings) bomb() error { case s.BombRatio == nil: return nil case !(*s.BombRatio >= 0) || math.IsInf(*s.BombRatio, 1): - return refuse("bomb_ratio: %g isn't a finite number of zero or more", *s.BombRatio) + return refuseKey("bomb_ratio", "%g isn't a finite number of zero or more", *s.BombRatio) case s.BombSize != nil && (*s.BombRatio == 0) != (*s.BombSize == 0): - return refuse("bomb_ratio and bomb_size: set both above zero, or both to zero for no bomb rule") + return &KeyError{ + Keys: []string{"bomb_ratio", "bomb_size"}, + Reason: "set both above zero, or both to zero for no bomb rule", + } } return nil } @@ -242,7 +265,7 @@ func (s Settings) audioLimit() error { return nil } if _, err := audio.NewCutter(audio.Request{Limit: *s.AudioLimit}); *s.AudioLimit == 0 || err != nil { - return refuse("audio_limit: %v isn't over %v, twice the %v overlap between windows", + return refuseKey("audio_limit", "%v isn't over %v, twice the %v overlap between windows", *s.AudioLimit, 2*audio.DefaultOverlap, audio.DefaultOverlap) } return nil @@ -251,3 +274,7 @@ func (s Settings) audioLimit() error { func refuse(format string, args ...any) error { return fmt.Errorf("settings: "+format+": %w", append(args, ErrRequest)...) } + +func refuseKey(key, format string, args ...any) error { + return &KeyError{Keys: []string{key}, Reason: fmt.Sprintf(format, args...)} +} diff --git a/settings/settings_test.go b/settings/settings_test.go index 81770772..ce555592 100644 --- a/settings/settings_test.go +++ b/settings/settings_test.go @@ -5,6 +5,7 @@ import ( "errors" "math" "reflect" + "slices" "strings" "testing" "time" @@ -237,3 +238,40 @@ func check(t *testing.T, name string, data []byte, want []string) { } } } + +func TestKeyError(t *testing.T) { + for name, tc := range map[string]struct { + edits map[string]any + keys []string + reason string + }{ + "a value below zero": {map[string]any{"max_bytes": -1}, []string{"max_bytes"}, "-1 is below zero"}, + "a value below 1": {map[string]any{"puts": 0}, []string{"puts"}, "0 is below 1"}, + "the bomb rule half off": {map[string]any{"bomb_size": 0}, []string{"bomb_ratio", "bomb_size"}, "set both above zero, or both to zero for no bomb rule"}, + "a wrong JSON type": {map[string]any{"pdf_text": "true"}, []string{"pdf_text"}, "a JSON string isn't a boolean"}, + "an unparsable duration": {map[string]any{"unit_timeout": "soon"}, []string{"unit_timeout"}, `"soon" isn't a duration, such as "90s" or "10m"`}, + } { + _, err := settings.Decode(encode(t, tc.edits)) + var ke *settings.KeyError + if !errors.As(err, &ke) || !errors.Is(err, settings.ErrRequest) { + t.Errorf("%s: %v, want a KeyError wrapping ErrRequest", name, err) + continue + } + if !slices.Equal(ke.Keys, tc.keys) || ke.Reason != tc.reason { + t.Errorf("%s: KeyError %q, %q; want %q, %q", name, ke.Keys, ke.Reason, tc.keys, tc.reason) + } + if want := "settings: " + strings.Join(tc.keys, " and ") + ": " + tc.reason + ": invalid request"; err.Error() != want { + t.Errorf("%s: %q, want %q", name, err, want) + } + } + for name, data := range map[string][]byte{ + "an unknown key": encode(t, map[string]any{"max_part": 1}), + "a required key unset": encode(t, map[string]any{"max_depth": unset{}}), + } { + _, err := settings.Decode(data) + var ke *settings.KeyError + if !errors.Is(err, settings.ErrRequest) || errors.As(err, &ke) { + t.Errorf("%s: %v, want ErrRequest and no KeyError", name, err) + } + } +} From 7ea21696adde979da9aa80cef044d2d5b58c7a8b Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Sat, 28 Nov 2026 17:28:05 -0500 Subject: [PATCH 7/9] Editor pass: settings docs and changelog prose tightened; bunrei note wires stages and dispatch from a settings.Run --- CHANGELOG.md | 14 +++++++------- cmd/docproc/CHANGELOG.md | 6 +++--- context/bunrei.md | 3 ++- docs/api.md | 27 ++++++++++++++------------- docs/command.md | 2 +- 5 files changed, 27 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1dce9ca..57ceefd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,8 +26,8 @@ API changes, `dispatch.Version` stays "1", and the run directory's schema stays `magick_map`, `magick_disk`, `audio_limit`, and `puts`. The library sets no bound of its own, so every key but four is required, and zero is no bound. The four optional keys, unset, take a default: `concurrency` 1, `pdf_dpi` `document.DefaultDPI`, `audio_limit` - `audio.DefaultWindowLimit`, and `puts` 1; set, each is at least 1, or for `audio_limit` over - 4s. A duration is a Go duration string, such as `"90s"`, and `bomb_ratio` and `bomb_size` are + `audio.DefaultWindowLimit`, and `puts` 1. Set, `audio_limit` is over 4s and each other is at + least 1. A duration is a Go duration string, such as `"90s"`, and `bomb_ratio` and `bomb_size` are both zero, for no bomb rule, or both above it. The [API page](docs/api.md#settings) states each key's format and the field it lands in. - `settings.Settings`, one pointer field per key, nil when unset, so an unset key is told from an @@ -37,11 +37,11 @@ API changes, `dispatch.Version` stays "1", and the run directory's schema stays - `Settings.Validate`, which refuses settings a run can't take, each refusal naming its key, and every unset required key in one error. - `settings.ErrRequest`, which every refusal wraps. -- `settings.KeyError`, the refusal of the values of the keys it names, its `Keys` and its - `Reason`, so a host names its own source for each key; it wraps `ErrRequest`. -- `settings.Run`, settings in the library's shapes: the `stages.Options` a host passes - `stages.Build`, each option no key covers the zero value, the host's own; and the - `dispatch.Limits`, `Release`, and `Puts` it passes `dispatch.New` in its `Config`. +- `settings.KeyError`, which refuses the values of the keys in its `Keys` for its `Reason`, so a + host names its own source for each key; it wraps `ErrRequest`. +- `settings.Run`, the settings in the library's shapes: the `stages.Options` a host passes + `stages.Build`, every option no key covers left at its zero value for the host to set; and the + `dispatch.Limits`, `Release`, and `Puts` the host passes `dispatch.New` in its `Config`. - `Settings.Assemble`, which validates settings and returns their `Run`, each optional key left unset at its default. diff --git a/cmd/docproc/CHANGELOG.md b/cmd/docproc/CHANGELOG.md index 96a1d990..92ee5acc 100644 --- a/cmd/docproc/CHANGELOG.md +++ b/cmd/docproc/CHANGELOG.md @@ -27,9 +27,9 @@ every existing variable keeps its meaning and its default. [CHANGELOG](../../CHANGELOG.md) states its changes in full. `docproc run` reads each `DOCPROC_` variable into its key of a `settings.Settings` and assembles them into a `settings.Run`, the bounds it passes `stages.Build` and `dispatch.New`. Each variable keeps its - meaning, its format, and its default, `DOCPROC_CONCURRENCY` and `DOCPROC_PDF_DPI` at zero - included. A refused value still fails `docproc run` before any tool is looked up, and its - message names the variable, such as `bounds: DOCPROC_PUTS: 0 is below 1`. + meaning, its format, and its default, and `DOCPROC_CONCURRENCY` and `DOCPROC_PDF_DPI` still read + zero as their default. A refused value still fails `docproc run` before any tool is looked up, + and its message names the variable, such as `bounds: DOCPROC_PUTS: 0 is below 1`. - soffice runs in `gotenberg/gotenberg:9.10.3-libreoffice`, from 9.10.2-libreoffice, pinned by its multi-arch index digest. - The module requires go-core v0.14.0, from v0.12.0; nothing `docproc run` does changes with it. diff --git a/context/bunrei.md b/context/bunrei.md index 0dd643cc..aef5b4fc 100644 --- a/context/bunrei.md +++ b/context/bunrei.md @@ -76,7 +76,8 @@ data-intelligence.md queues these asks of go-messaging's NATS provider, sized by ## Assumptions -- Assumes Bunrei wires docproc's `stages` as `cmd/docproc` does. +- Assumes Bunrei wires docproc's `stages` and `dispatch` from a `settings.Run`, as `cmd/docproc` + does. - Assumes one `docinfer.Bounds` per replica, shared by its pipelines, one per profile. - Assumes Bunrei speaks Chat Completions to the gateway, its consumer key the bearer token. - Assumes the consumer stores chunks by their identity, so a batch a redelivered job repeats changes diff --git a/docs/api.md b/docs/api.md index 62d080d0..9adc2b5a 100644 --- a/docs/api.md +++ b/docs/api.md @@ -72,9 +72,9 @@ metadata the metadata records' shapes, one per format; imports ``` No root package. Another module reaches `dispatch`, `dispatch/dispatchtest`, `route`, `inspect`, -`stages.Build`, `settings`, `rundir`, and the record types docinfer decodes (the plan records, `metadata`'s -records, the readers' line types, `email.Threader`); the module builds on every 64-bit platform, and -only running a tool needs Linux. +`stages.Build`, `settings`, `rundir`, and the record types docinfer decodes (the plan records, +`metadata`'s records, the readers' line types, `email.Threader`); the module builds on every 64-bit +platform, and only running a tool needs Linux. ## Inspection and routing @@ -1067,7 +1067,7 @@ type Settings struct { // one pointer field per key, nil when unset; the json ta // Decode reads settings from one JSON object and validates them, as Validate does; input that // isn't one object, an unknown key, and a value of the wrong JSON type are refused too. func Decode(data []byte) (Settings, error) -func (s Settings) Validate() error // each refusal names its key; every unset required key in one +func (s Settings) Validate() error // each refusal names its key; one names every unset required key // Assemble validates s and returns its Run, each optional key left unset at its default. func (s Settings) Assemble() (Run, error) type Run struct { @@ -1112,17 +1112,18 @@ puts whole number, from 1 dispatch.Config.Puts no, The library ships no policy, so every key but four is required, and zero is no bound: a required key left unset is refused, never defaulted. The four optional keys are the ones whose library value already has a default: an unset `pdf_dpi` assembles to `document.DefaultDPI`, 150; an unset -`audio_limit` to `audio.DefaultWindowLimit`, 30s; and an unset `concurrency` or `puts` to 1. Set, -each is at least 1, or for `audio_limit` over 4s, twice `audio.DefaultOverlap`, the shortest window -the audio cutter takes. A duration is a Go duration string, such as `"90s"` or `"10m"`, as -`time.ParseDuration` reads it, and a number in its place is refused; every value is zero or more, -and `bomb_ratio` and `bomb_size` are both zero, for no bomb rule, or both above it. - -`Run.Stages` sets only the fields the table names: `Exclude`, `Env`, `Inspect.Policy`, `Picture`, +`audio_limit` to `audio.DefaultWindowLimit`, 30s; and an unset `concurrency` or `puts` to 1. A set +`pdf_dpi`, `concurrency`, or `puts` is at least 1, and a set `audio_limit` is over 4s, twice +`audio.DefaultOverlap`, the shortest window the audio cutter takes. A duration is a Go duration +string, such as `"90s"` or `"10m"`, as `time.ParseDuration` reads it, and a number in its place is +refused; every value is zero or more, and `bomb_ratio` and `bomb_size` are both zero, for no bomb +rule, or both above it. + +`Run.Stages` sets only the fields the table names. `Exclude`, `Env`, `Inspect.Policy`, `Picture`, `Document.PagesPerProcess`, and every other field of the video, audio, and ImageMagick requests stay the zero value, each host's own to set before `Build`. A host passes `Run.Limits`, `Release`, -and `Puts` to `dispatch.New`'s `Config`, with the `stages.Set`'s `Inspect` as its `Inspect`, so one -validated value of the inspection options exists. +and `Puts` to `dispatch.New` in its `Config`, with the `stages.Set`'s `Inspect` as its `Inspect`, so +the dispatcher and the stages share one validated value of the inspection options. ## Content diff --git a/docs/command.md b/docs/command.md index c171fbaf..faeb51c0 100644 --- a/docs/command.md +++ b/docs/command.md @@ -86,4 +86,4 @@ shutdown. | `DOCPROC_MAGICK_MAP` | The most bytes of the pixel cache that may be memory-mapped (`-limit map`) | 2 GiB | | `DOCPROC_MAGICK_DISK` | The most bytes of the pixel cache that may be on disk (`-limit disk`) | 8 GiB | | `DOCPROC_AUDIO_LIMIT` | The longest audio window, its overlaps included (`Options.Audio.Limit`); a host sets it to its model's request size, the longest audio one request takes. A source no longer than it is one window. It must be over 4s, twice the 2 s overlap between windows, so zero is refused | 30s | -| `DOCPROC_PUTS` | The most content puts in flight per dispatch (`dispatch.Config.Puts`); a put is a copy on the local disk the workers' dispatches already keep busy. It must be at least 1, so zero is refused | 1 | +| `DOCPROC_PUTS` | The most content puts in flight per dispatch (`dispatch.Config.Puts`); each put copies to the local disk, which the workers' dispatches already keep busy. It must be at least 1, so zero is refused | 1 | From 6cbb32c578a3acd46eaa090281cd3249b1fb59a3 Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Sat, 28 Nov 2026 21:14:31 -0500 Subject: [PATCH 8/9] Rename the puts setting to output_writes The settings key puts becomes output_writes, settings.Settings.Puts and settings.Run.Puts become OutputWrites, and cmd/docproc's DOCPROC_PUTS becomes DOCPROC_OUTPUT_WRITES, in code, tests, doc comments, docs, and the unreleased v0.11.0 and cmd/docproc v0.2.9 changelog entries. - dispatch.Config.Puts, shipped in v0.10.0, keeps its name; the key table maps output_writes to it, and Run.OutputWrites is passed as Puts. - The docs describe the key as the most outputs one part writes to the content store at once, at least 1, default 1. - Behavior is unchanged: optional, default 1, a value below 1 refused naming output_writes (DOCPROC_OUTPUT_WRITES in cmd/docproc). --- CHANGELOG.md | 18 ++++++----- cmd/docproc/CHANGELOG.md | 9 +++--- cmd/docproc/internal/app/bounds_test.go | 36 +++++++++++----------- cmd/docproc/internal/app/infrastructure.go | 4 +-- cmd/docproc/internal/run/commands.go | 2 +- cmd/docproc/internal/run/doc.go | 4 +-- cmd/docproc/internal/run/runner.go | 2 +- docs/api.md | 26 ++++++++-------- docs/command.md | 2 +- docs/packages.md | 2 +- settings/doc.go | 12 ++++---- settings/run.go | 17 +++++----- settings/run_linux_test.go | 4 +-- settings/run_test.go | 18 +++++------ settings/settings.go | 12 ++++---- settings/settings_test.go | 12 ++++---- 16 files changed, 93 insertions(+), 87 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57ceefd8..05addd65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,13 +23,14 @@ API changes, `dispatch.Version` stays "1", and the run directory's schema stays snake case: `tool_memory`, `unit_timeout`, `stream_idle`, `max_parts`, `max_bytes`, `max_depth`, `bomb_ratio`, `bomb_size`, `archive_entries`, `claim_release`, `concurrency`, `pdf_dpi`, `pdf_text`, `pdf_max_pixels`, `frame_max_side`, `magick_area`, `magick_memory`, - `magick_map`, `magick_disk`, `audio_limit`, and `puts`. The library sets no bound of its own, - so every key but four is required, and zero is no bound. The four optional keys, unset, take a - default: `concurrency` 1, `pdf_dpi` `document.DefaultDPI`, `audio_limit` - `audio.DefaultWindowLimit`, and `puts` 1. Set, `audio_limit` is over 4s and each other is at - least 1. A duration is a Go duration string, such as `"90s"`, and `bomb_ratio` and `bomb_size` are - both zero, for no bomb rule, or both above it. The [API page](docs/api.md#settings) states each - key's format and the field it lands in. + `magick_map`, `magick_disk`, `audio_limit`, and `output_writes`. The library sets no bound of its + own, so every key but four is required, and zero is no bound. The four optional keys, unset, take + a default: `concurrency` 1, `pdf_dpi` `document.DefaultDPI`, `audio_limit` + `audio.DefaultWindowLimit`, and `output_writes`, the most outputs one part writes to the content + store at once, 1. Set, `audio_limit` is over 4s and each other is at least 1. A duration is a + Go duration string, such as `"90s"`, and `bomb_ratio` and `bomb_size` are both zero, for no bomb + rule, or both above it. The [API page](docs/api.md#settings) states each key's format and the + field it lands in. - `settings.Settings`, one pointer field per key, nil when unset, so an unset key is told from an explicit zero; a Go caller sets a key with `new`. - `settings.Decode`, which reads settings from one JSON object and validates them; input that @@ -41,7 +42,8 @@ API changes, `dispatch.Version` stays "1", and the run directory's schema stays host names its own source for each key; it wraps `ErrRequest`. - `settings.Run`, the settings in the library's shapes: the `stages.Options` a host passes `stages.Build`, every option no key covers left at its zero value for the host to set; and the - `dispatch.Limits`, `Release`, and `Puts` the host passes `dispatch.New` in its `Config`. + `dispatch.Limits`, `Release`, and `OutputWrites`, as `Puts`, the host passes `dispatch.New` in + its `Config`. - `Settings.Assemble`, which validates settings and returns their `Run`, each optional key left unset at its default. diff --git a/cmd/docproc/CHANGELOG.md b/cmd/docproc/CHANGELOG.md index 92ee5acc..0ca0b6bf 100644 --- a/cmd/docproc/CHANGELOG.md +++ b/cmd/docproc/CHANGELOG.md @@ -13,13 +13,14 @@ postgres modules, and each system tool under `tools/` keep their own. ## [v0.2.9] - 2026-11-28 This release reads its run bounds through the docproc base module's new package `settings`, at -v0.11.0, and adds `DOCPROC_PUTS`. Its exit codes and run directory's schema are unchanged, and +v0.11.0, and adds `DOCPROC_OUTPUT_WRITES`. Its exit codes and run directory's schema are unchanged, and every existing variable keeps its meaning and its default. ### Added -- `DOCPROC_PUTS`, the most content puts in flight per dispatch (`dispatch.Config.Puts`), at - least 1, so zero is refused; unset or empty, it is 1, the bound `docproc run` held before. +- `DOCPROC_OUTPUT_WRITES`, the most outputs one part writes to the content store at once + (`dispatch.Config.Puts`), at least 1, so zero is refused; unset or empty, it is 1, the bound + `docproc run` held before. ### Changed @@ -29,7 +30,7 @@ every existing variable keeps its meaning and its default. `settings.Run`, the bounds it passes `stages.Build` and `dispatch.New`. Each variable keeps its meaning, its format, and its default, and `DOCPROC_CONCURRENCY` and `DOCPROC_PDF_DPI` still read zero as their default. A refused value still fails `docproc run` before any tool is looked up, - and its message names the variable, such as `bounds: DOCPROC_PUTS: 0 is below 1`. + and its message names the variable, such as `bounds: DOCPROC_OUTPUT_WRITES: 0 is below 1`. - soffice runs in `gotenberg/gotenberg:9.10.3-libreoffice`, from 9.10.2-libreoffice, pinned by its multi-arch index digest. - The module requires go-core v0.14.0, from v0.12.0; nothing `docproc run` does changes with it. diff --git a/cmd/docproc/internal/app/bounds_test.go b/cmd/docproc/internal/app/bounds_test.go index e29a388a..963222f8 100644 --- a/cmd/docproc/internal/app/bounds_test.go +++ b/cmd/docproc/internal/app/bounds_test.go @@ -49,7 +49,7 @@ var boundVars = []string{ "DOCPROC_MAGICK_MAP", "DOCPROC_MAGICK_DISK", "DOCPROC_AUDIO_LIMIT", - "DOCPROC_PUTS", + "DOCPROC_OUTPUT_WRITES", } func startingBounds() settings.Run { @@ -65,9 +65,9 @@ func startingBounds() settings.Run { Magick: picture.Limits{Area: 256_000_000, Memory: 1 * gib, Map: 2 * gib, Disk: 8 * gib}, Audio: audio.Request{Limit: 30 * time.Second}, }, - Limits: dispatch.Limits{Parts: 100_000, Bytes: 32 * gib, Depth: 16}, - Release: 10 * time.Second, - Puts: 1, + Limits: dispatch.Limits{Parts: 100_000, Bytes: 32 * gib, Depth: 16}, + Release: 10 * time.Second, + OutputWrites: 1, } } @@ -159,7 +159,7 @@ func TestBounds_EachVariableOverridesItsBound(t *testing.T) { } } -func TestBounds_PutsOverride(t *testing.T) { +func TestBounds_OutputWritesOverride(t *testing.T) { for _, tc := range []struct { value string want int @@ -167,9 +167,9 @@ func TestBounds_PutsOverride(t *testing.T) { {"", 1}, {"4", 4}, } { - t.Run("DOCPROC_PUTS="+tc.value, func(t *testing.T) { + t.Run("DOCPROC_OUTPUT_WRITES="+tc.value, func(t *testing.T) { clearBounds(t) - t.Setenv("DOCPROC_PUTS", tc.value) + t.Setenv("DOCPROC_OUTPUT_WRITES", tc.value) got, err := buildBounds(t) @@ -177,7 +177,7 @@ func TestBounds_PutsOverride(t *testing.T) { t.Fatalf("Build: %v", err) } want := startingBounds() - want.Puts = tc.want + want.OutputWrites = tc.want if !reflect.DeepEqual(got, want) { t.Errorf("bounds = %+v\nwant %+v", got, want) } @@ -185,15 +185,15 @@ func TestBounds_PutsOverride(t *testing.T) { } } -func TestBounds_PutsRefused(t *testing.T) { +func TestBounds_OutputWritesRefused(t *testing.T) { for _, tc := range []struct{ value, want string }{ - {"0", "bounds: DOCPROC_PUTS: 0 is below 1"}, - {"-2", "bounds: DOCPROC_PUTS: -2 is below 1"}, - {"x", `bounds: DOCPROC_PUTS: "x" is not a whole number`}, + {"0", "bounds: DOCPROC_OUTPUT_WRITES: 0 is below 1"}, + {"-2", "bounds: DOCPROC_OUTPUT_WRITES: -2 is below 1"}, + {"x", `bounds: DOCPROC_OUTPUT_WRITES: "x" is not a whole number`}, } { t.Run(tc.value, func(t *testing.T) { clearBounds(t) - t.Setenv("DOCPROC_PUTS", tc.value) + t.Setenv("DOCPROC_OUTPUT_WRITES", tc.value) _, err := buildBounds(t) @@ -244,12 +244,12 @@ func TestBounds_BombRuleMessage(t *testing.T) { func TestBounds_ParseAndRangeRefusalsJoined(t *testing.T) { clearBounds(t) - t.Setenv("DOCPROC_PUTS", "many") + t.Setenv("DOCPROC_OUTPUT_WRITES", "many") t.Setenv("DOCPROC_UNIT_TIMEOUT", "-1s") _, err := buildBounds(t) - want := "bounds: DOCPROC_PUTS: \"many\" is not a whole number\nDOCPROC_UNIT_TIMEOUT: -1s is below zero" + want := "bounds: DOCPROC_OUTPUT_WRITES: \"many\" is not a whole number\nDOCPROC_UNIT_TIMEOUT: -1s is below zero" if err == nil || err.Error() != want { t.Errorf("Build: %v, want %q", err, want) } @@ -477,20 +477,20 @@ func TestRun_VersionReadsNoBound(t *testing.T) { } } -func TestRun_PutsRefusedBeforeLookup(t *testing.T) { +func TestRun_OutputWritesRefusedBeforeLookup(t *testing.T) { in := write(t, t.TempDir(), "hello.txt", helloText) out := filepath.Join(t.TempDir(), "out") lookup, looked := probes(apptest.NoTools) r := runCmd(t, context.Background(), func(a *app.App) { - t.Setenv("DOCPROC_PUTS", "0") + t.Setenv("DOCPROC_OUTPUT_WRITES", "0") apptest.Tools(a, lookup) }, in, "--out", out) if r.code != process.ExitFailure { t.Errorf("code = %d, want %d", r.code, process.ExitFailure) } - if want := "docproc run: bounds: DOCPROC_PUTS: 0 is below 1"; !strings.HasPrefix(r.stderr, want) { + if want := "docproc run: bounds: DOCPROC_OUTPUT_WRITES: 0 is below 1"; !strings.HasPrefix(r.stderr, want) { t.Errorf("stderr = %q, want it to start with %q", r.stderr, want) } if log := looked.Log(); len(log) != 0 { diff --git a/cmd/docproc/internal/app/infrastructure.go b/cmd/docproc/internal/app/infrastructure.go index 71212546..27b2661d 100644 --- a/cmd/docproc/internal/app/infrastructure.go +++ b/cmd/docproc/internal/app/infrastructure.go @@ -52,7 +52,7 @@ func newBounds(*graph.Scope) (settings.Run, error) { MagickMap: new(int64(2 * gib)), MagickDisk: new(int64(8 * gib)), AudioLimit: new(30 * time.Second), - Puts: new(1), + OutputWrites: new(1), } errs := []error{ @@ -76,7 +76,7 @@ func newBounds(*graph.Scope) (settings.Run, error) { readEnv(&s.MagickMap, "magick_map", parseCount[int64]), readEnv(&s.MagickDisk, "magick_disk", parseCount[int64]), readEnv(&s.AudioLimit, "audio_limit", parseDuration), - readEnv(&s.Puts, "puts", parseCount[int]), + readEnv(&s.OutputWrites, "output_writes", parseCount[int]), } run, err := s.Assemble() return run, errors.Join(append(errs, variables(err)...)...) diff --git a/cmd/docproc/internal/run/commands.go b/cmd/docproc/internal/run/commands.go index 2b378a02..0f63ad07 100644 --- a/cmd/docproc/internal/run/commands.go +++ b/cmd/docproc/internal/run/commands.go @@ -23,7 +23,7 @@ type StageBuilder func(ctx context.Context, opts stages.Options) (stages.Set, er // stage builder, and the docproc build that writes the run. type Config struct { // Bounds are the run's bounds: the options the stages are built under, to whose Exclude the - // command adds the routes --exclude names, and each dispatch's Limits, Release, and Puts. + // command adds the routes --exclude names, and each dispatch's Limits, Release, and OutputWrites. Bounds settings.Run // Build builds the stages; it is required. Build StageBuilder diff --git a/cmd/docproc/internal/run/doc.go b/cmd/docproc/internal/run/doc.go index abbec30f..535e6f6a 100644 --- a/cmd/docproc/internal/run/doc.go +++ b/cmd/docproc/internal/run/doc.go @@ -14,8 +14,8 @@ // // The run's manifest names its docproc build, its workers, its path arguments, how many inputs they // named, the tools the stage builder tried, and the stage table. Each output's content is in the -// run directory's content store, put there by the dispatcher, its bounds' Puts at a time per -// dispatch, and a part the index has seen replays its log, its children's included, through the +// run directory's content store, written there by the dispatcher, its bounds' OutputWrites at once +// per part, and a part the index has seen replays its log, its children's included, through the // dispatcher, so every line is this run's own. An input's own part line, its last, carries its // file's metadata, through os.Stat and statx's birth time where the kernel gives one, and its type // as net/http.DetectContentType sniffs it, and its time, from its first event to its last, both diff --git a/cmd/docproc/internal/run/runner.go b/cmd/docproc/internal/run/runner.go index cb3365b8..59443405 100644 --- a/cmd/docproc/internal/run/runner.go +++ b/cmd/docproc/internal/run/runner.go @@ -101,7 +101,7 @@ func (r *runner) dispatch(ctx context.Context, set stages.Set, rec *recorder) (e Dir: work, Limits: r.cfg.Bounds.Limits, Inspect: set.Inspect, - Puts: r.cfg.Bounds.Puts, + Puts: r.cfg.Bounds.OutputWrites, Release: r.cfg.Bounds.Release, }) if err != nil { diff --git a/docs/api.md b/docs/api.md index 9adc2b5a..a0bc1b11 100644 --- a/docs/api.md +++ b/docs/api.md @@ -63,7 +63,7 @@ stages Build and its Options, Routes and ParseRoutes, the st identities settings a run's settings as one JSON object, validated and assembled into stages.Options, dispatch.Limits, and the release and - puts bounds + output-writes bounds internal/tooltest, test helpers: the unit tier's stand-in tool, golden sums, and goldentest, mediatest media's stand-in ffmpeg run rundir, rundir/schema cmd/docproc's run directory: its shapes, read and written @@ -1062,7 +1062,7 @@ type Settings struct { // one pointer field per key, nil when unset; the json ta BombRatio *float64; BombSize *uint64; ArchiveEntries *int ClaimRelease *time.Duration; Concurrency, PDFDPI *int; PDFText *bool; PDFMaxPixels *int64 FrameMaxSide *int; MagickArea, MagickMemory, MagickMap, MagickDisk *int64 - AudioLimit *time.Duration; Puts *int + AudioLimit *time.Duration; OutputWrites *int } // Decode reads settings from one JSON object and validates them, as Validate does; input that // isn't one object, an unknown key, and a value of the wrong JSON type are refused too. @@ -1071,10 +1071,10 @@ func (s Settings) Validate() error // each refusal names its key; one names ever // Assemble validates s and returns its Run, each optional key left unset at its default. func (s Settings) Assemble() (Run, error) type Run struct { - Stages stages.Options // for stages.Build; every option no key covers is the zero value - Limits dispatch.Limits // dispatch.Config.Limits - Release time.Duration // dispatch.Config.Release - Puts int // dispatch.Config.Puts + Stages stages.Options // for stages.Build; every option no key covers is the zero value + Limits dispatch.Limits // dispatch.Config.Limits + Release time.Duration // dispatch.Config.Release + OutputWrites int // dispatch.Config.Puts } var ErrRequest = errors.New("invalid request") // every refusal wraps it // KeyError is the refusal of the values of the keys it names, one key or both bomb_ratio and @@ -1106,14 +1106,15 @@ magick_memory whole bytes picture.Limits.Memory yes magick_map whole bytes picture.Limits.Map yes magick_disk whole bytes picture.Limits.Disk yes audio_limit duration, over 4s audio.Request.Limit no, audio.DefaultWindowLimit -puts whole number, from 1 dispatch.Config.Puts no, 1 +output_writes whole number, from 1 dispatch.Config.Puts no, 1 ``` The library ships no policy, so every key but four is required, and zero is no bound: a required key left unset is refused, never defaulted. The four optional keys are the ones whose library value already has a default: an unset `pdf_dpi` assembles to `document.DefaultDPI`, 150; an unset -`audio_limit` to `audio.DefaultWindowLimit`, 30s; and an unset `concurrency` or `puts` to 1. A set -`pdf_dpi`, `concurrency`, or `puts` is at least 1, and a set `audio_limit` is over 4s, twice +`audio_limit` to `audio.DefaultWindowLimit`, 30s; and an unset `concurrency` or `output_writes`, +the most outputs one part writes to the content store at once, to 1. A set `pdf_dpi`, +`concurrency`, or `output_writes` is at least 1, and a set `audio_limit` is over 4s, twice `audio.DefaultOverlap`, the shortest window the audio cutter takes. A duration is a Go duration string, such as `"90s"` or `"10m"`, as `time.ParseDuration` reads it, and a number in its place is refused; every value is zero or more, and `bomb_ratio` and `bomb_size` are both zero, for no bomb @@ -1121,9 +1122,10 @@ rule, or both above it. `Run.Stages` sets only the fields the table names. `Exclude`, `Env`, `Inspect.Policy`, `Picture`, `Document.PagesPerProcess`, and every other field of the video, audio, and ImageMagick requests -stay the zero value, each host's own to set before `Build`. A host passes `Run.Limits`, `Release`, -and `Puts` to `dispatch.New` in its `Config`, with the `stages.Set`'s `Inspect` as its `Inspect`, so -the dispatcher and the stages share one validated value of the inspection options. +stay the zero value, each host's own to set before `Build`. A host passes `Run.Limits` and +`Release` to `dispatch.New` in its `Config`, and `OutputWrites` as its `Puts`, with the +`stages.Set`'s `Inspect` as its `Inspect`, so the dispatcher and the stages share one validated +value of the inspection options. ## Content diff --git a/docs/command.md b/docs/command.md index faeb51c0..52035bfb 100644 --- a/docs/command.md +++ b/docs/command.md @@ -86,4 +86,4 @@ shutdown. | `DOCPROC_MAGICK_MAP` | The most bytes of the pixel cache that may be memory-mapped (`-limit map`) | 2 GiB | | `DOCPROC_MAGICK_DISK` | The most bytes of the pixel cache that may be on disk (`-limit disk`) | 8 GiB | | `DOCPROC_AUDIO_LIMIT` | The longest audio window, its overlaps included (`Options.Audio.Limit`); a host sets it to its model's request size, the longest audio one request takes. A source no longer than it is one window. It must be over 4s, twice the 2 s overlap between windows, so zero is refused | 30s | -| `DOCPROC_PUTS` | The most content puts in flight per dispatch (`dispatch.Config.Puts`); each put copies to the local disk, which the workers' dispatches already keep busy. It must be at least 1, so zero is refused | 1 | +| `DOCPROC_OUTPUT_WRITES` | The most outputs one part writes to the content store at once (`dispatch.Config.Puts`); each write copies to the local disk, which the workers' dispatches already keep busy. It must be at least 1, so zero is refused | 1 | diff --git a/docs/packages.md b/docs/packages.md index 2af1d3bb..0c5e202e 100644 --- a/docs/packages.md +++ b/docs/packages.md @@ -14,7 +14,7 @@ | `dispatch` | The walk over an input's parts to their stages; the Stage contract and its error classes; the content store and its layout, and the index, each with a file and a memory implementation; the shapes of its events, parts, outputs, and warnings; and the Meta keys every stage sets and the record media types. It imports `route` and `inspect` alone. | | `dispatch/dispatchtest` | The Index and Content conformance suites, for every store, the module's own and a provider's, and the fixture stage a host's tests dispatch over. | | `stages` | `Build` and its `Options`: docproc's shipped wiring, each route's stage over its format package and tools, found on the host, under the host's run bounds and requests, with the one failure classification and each stage's identity. `cmd/docproc` is its first caller. | -| `settings` | A run's settings as one flat JSON object, each key named for its `DOCPROC_` variable: `Decode` reads and validates them, refusing every unset required key in one error, and `Settings.Assemble` returns their `Run`, the `stages.Options`, `dispatch.Limits`, and release and puts bounds a host passes `stages.Build` and `dispatch.New`, each unset optional key at its default. It imports no package outside the standard library and docproc. | +| `settings` | A run's settings as one flat JSON object, each key named for its `DOCPROC_` variable: `Decode` reads and validates them, refusing every unset required key in one error, and `Settings.Assemble` returns their `Run`, the `stages.Options`, `dispatch.Limits`, and release and output-writes bounds a host passes `stages.Build` and `dispatch.New`, each unset optional key at its default. It imports no package outside the standard library and docproc. | | `rundir` | `cmd/docproc`'s run directory, read and written: `Open` to read it and `Create` to write it, its runs, the latest that ended, each run's manifest and record, its content store and the path of a content's file, its index, a quarantined part's kept file, and a run's report directory, `runs//report/`. One process writes a run directory. | | `rundir/schema` | The run directory's schema `"2"`: the shapes `cmd/docproc` writes and a reader decodes, a record line, a manifest, an input's file, and a time, each in UTC. It imports no docproc package but `dispatch` and `inspect`. | | `metadata` | The metadata records' shapes, one per format, each a JSON value under a versioned media type `dispatch` declares: `Office`, an office package's properties and the format it was converted from; `PDF`, a PDF's information dictionary, XMP metadata, and version; `Media`, an audio or video file's container format, duration, bit rate, and tags, and its streams; and `Picture`, a picture's EXIF capture time, camera, orientation, size, GPS position, and properties. It imports no docproc package but `dispatch`, so a reader decodes a record without compiling the stages. | diff --git a/settings/doc.go b/settings/doc.go index a000136c..666ff8c5 100644 --- a/settings/doc.go +++ b/settings/doc.go @@ -1,8 +1,8 @@ // Package settings holds a run's settings as one flat JSON object, on the standard library and // this module's own packages alone: the run bounds a host passes stages.Build in its Options, -// the dispatch.Limits and the release and puts bounds it passes dispatch.New in its Config, and -// the PDF, video, ImageMagick, and audio bounds of the stages' requests. Each key is named for -// the DOCPROC_ variable cmd/docproc reads it from, without the prefix and in snake case. +// the dispatch.Limits and the release and output-writes bounds it passes dispatch.New in its +// Config, and the PDF, video, ImageMagick, and audio bounds of the stages' requests. Each key is +// named for the DOCPROC_ variable cmd/docproc reads it from, without the prefix and in snake case. // // [Decode] reads the settings from JSON and validates them in one step; [Settings.Validate] // validates settings a Go caller built, each unset key nil, set with new, such as new(int64(0)). @@ -30,7 +30,7 @@ // magick_map whole bytes picture.Limits.Map yes // magick_disk whole bytes picture.Limits.Disk yes // audio_limit duration, over 4s audio.Request.Limit no, audio.DefaultWindowLimit -// puts whole number, from 1 dispatch.Config.Puts no, 1 +// output_writes whole number, from 1 dispatch.Config.Puts no, 1 // // A duration is a Go duration string, such as "90s" or "10m", as time.ParseDuration reads it; a // number in its place is refused. Every value is zero or more, and bomb_ratio and bomb_size are @@ -43,8 +43,8 @@ // [Settings.Assemble] validates the settings and assembles them into a [Run], in the shapes the // library takes them: the stages.Options a host passes stages.Build, each field the table names // set and every other option the zero value, the host's own, such as Exclude and Env; and the -// dispatch.Limits, Release, and Puts it passes dispatch.New in its Config. An optional key left -// unset assembles to its default. +// dispatch.Limits, Release, and OutputWrites, as Puts, it passes dispatch.New in its Config. An +// optional key left unset assembles to its default. // // Its exported identifiers: // diff --git a/settings/run.go b/settings/run.go index 8029f385..bfdc6e29 100644 --- a/settings/run.go +++ b/settings/run.go @@ -13,8 +13,8 @@ import ( ) // Run is a run's settings in the shapes the library takes them, so a host hands them on as they -// are: Stages to stages.Build, and Limits, Release, and Puts to dispatch.New's Config, with the -// stages.Set's Inspect as its Inspect. +// are: Stages to stages.Build, and Limits, Release, and OutputWrites, as Puts, to dispatch.New's +// Config, with the stages.Set's Inspect as its Inspect. type Run struct { // Stages carry the run bounds, the inspection options, the concurrency, and the PDF, video, // ImageMagick, and audio bounds. Every option no key covers is the zero value, the host's to @@ -26,14 +26,15 @@ type Run struct { // Release bounds a claim's release once a dispatch's context has ended: // dispatch.Config.Release. Release time.Duration - // Puts is the most content puts in flight per dispatch: dispatch.Config.Puts. - Puts int + // OutputWrites is the most outputs one part writes to the content store at once: + // dispatch.Config.Puts. + OutputWrites int } // Assemble validates s, as Validate does, and returns its Run, each optional key left unset at // its default: PDFDPI at document.DefaultDPI, AudioLimit at audio.DefaultWindowLimit, and -// Concurrency and Puts at 1. Settings Validate refuses are refused with its error, which wraps -// ErrRequest. +// Concurrency and OutputWrites at 1. Settings Validate refuses are refused with its error, which +// wraps ErrRequest. func (s Settings) Assemble() (Run, error) { if err := s.Validate(); err != nil { return Run{}, err @@ -68,8 +69,8 @@ func (s Settings) Assemble() (Run, error) { Bytes: *s.MaxBytes, Depth: *s.MaxDepth, }, - Release: *s.ClaimRelease, - Puts: or(s.Puts, 1), + Release: *s.ClaimRelease, + OutputWrites: or(s.OutputWrites, 1), }, nil } diff --git a/settings/run_linux_test.go b/settings/run_linux_test.go index 928f9661..f96c6d37 100644 --- a/settings/run_linux_test.go +++ b/settings/run_linux_test.go @@ -81,7 +81,7 @@ func TestAssembledDispatch(t *testing.T) { "under max_bytes": {len(text), dispatch.Prepared}, "past max_bytes": {len(text) - 1, dispatch.Limited}, } { - run := assemble(t, map[string]any{"tool_memory": tooltest.Memory, "max_bytes": tc.maxBytes, "puts": 2}) + run := assemble(t, map[string]any{"tool_memory": tooltest.Memory, "max_bytes": tc.maxBytes, "output_writes": 2}) set := build(t, run) d, err := dispatch.New(dispatch.Config{ Stages: set.Stages, @@ -91,7 +91,7 @@ func TestAssembledDispatch(t *testing.T) { Inspect: set.Inspect, Limits: run.Limits, Release: run.Release, - Puts: run.Puts, + Puts: run.OutputWrites, }) if err != nil { t.Fatal(err) diff --git a/settings/run_test.go b/settings/run_test.go index d85a4c16..6a4753fc 100644 --- a/settings/run_test.go +++ b/settings/run_test.go @@ -30,7 +30,7 @@ func assemble(t *testing.T, edits map[string]any) settings.Run { } func TestAssemble(t *testing.T) { - want := func(concurrency, dpi int, limit time.Duration, puts int) settings.Run { + want := func(concurrency, dpi int, limit time.Duration, outputWrites int) settings.Run { return settings.Run{ Stages: stages.Options{ Memory: 2 << 30, @@ -43,9 +43,9 @@ func TestAssemble(t *testing.T) { Magick: picture.Limits{Area: 256_000_000, Memory: 1 << 30, Map: 2 << 30, Disk: 8 << 30}, Audio: audio.Request{Limit: limit}, }, - Limits: dispatch.Limits{Parts: 100_000, Bytes: 32 << 30, Depth: 16}, - Release: 10 * time.Second, - Puts: puts, + Limits: dispatch.Limits{Parts: 100_000, Bytes: 32 << 30, Depth: 16}, + Release: 10 * time.Second, + OutputWrites: outputWrites, } } for name, tc := range map[string]struct { @@ -53,19 +53,19 @@ func TestAssemble(t *testing.T) { want settings.Run }{ "every key set": { - map[string]any{"concurrency": 4, "pdf_dpi": 300, "audio_limit": "45s", "puts": 3}, + map[string]any{"concurrency": 4, "pdf_dpi": 300, "audio_limit": "45s", "output_writes": 3}, want(4, 300, 45*time.Second, 3), }, "every optional key unset": { - map[string]any{"concurrency": unset{}, "pdf_dpi": unset{}, "audio_limit": unset{}, "puts": unset{}}, + map[string]any{"concurrency": unset{}, "pdf_dpi": unset{}, "audio_limit": unset{}, "output_writes": unset{}}, want(1, document.DefaultDPI, audio.DefaultWindowLimit, 1), }, "optional keys null": { - map[string]any{"concurrency": nil, "pdf_dpi": nil, "audio_limit": nil, "puts": nil}, + map[string]any{"concurrency": nil, "pdf_dpi": nil, "audio_limit": nil, "output_writes": nil}, want(1, 150, 30*time.Second, 1), }, "zero bounds": { - map[string]any{"concurrency": 4, "pdf_dpi": 300, "audio_limit": "45s", "puts": 3, + map[string]any{"concurrency": 4, "pdf_dpi": 300, "audio_limit": "45s", "output_writes": 3, "tool_memory": 0, "unit_timeout": "0s", "max_bytes": 0, "bomb_ratio": 0, "bomb_size": 0, "pdf_text": false}, func() settings.Run { r := want(4, 300, 45*time.Second, 3) @@ -90,7 +90,7 @@ func TestAssembleRefuses(t *testing.T) { for name, edit := range map[string]func(*settings.Settings){ "the zero value": func(s *settings.Settings) { *s = settings.Settings{} }, "a required key nil": func(s *settings.Settings) { s.MagickDisk = nil }, - "puts zero": func(s *settings.Settings) { s.Puts = new(0) }, + "output_writes zero": func(s *settings.Settings) { s.OutputWrites = new(0) }, } { c := s edit(&c) diff --git a/settings/settings.go b/settings/settings.go index 2110b574..439fef6a 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -39,7 +39,7 @@ func (e *KeyError) Error() string { func (e *KeyError) Unwrap() error { return ErrRequest } // Settings are a run's settings, one key for each, nil when unset. Every key but PDFDPI, -// Concurrency, AudioLimit, and Puts is required, and zero is no bound. +// Concurrency, AudioLimit, and OutputWrites is required, and zero is no bound. type Settings struct { // ToolMemory is every tool's memory bound in bytes, tool_memory. ToolMemory *int64 `json:"tool_memory"` @@ -83,8 +83,8 @@ type Settings struct { MagickDisk *int64 `json:"magick_disk"` // AudioLimit is the longest audio window, its overlaps included, audio_limit. AudioLimit *time.Duration `json:"audio_limit"` - // Puts is the most content puts in flight per dispatch, puts. - Puts *int `json:"puts"` + // OutputWrites is the most outputs one part writes to the content store at once, output_writes. + OutputWrites *int `json:"output_writes"` } type wire struct { @@ -173,8 +173,8 @@ func parseDuration(dest **time.Duration, key string, raw json.RawMessage) error // Validate refuses settings a run can't take, each refusal naming its key and wrapping ErrRequest: // every required key unset, named in one error; a value below zero; BombRatio not finite, or one -// of BombRatio and BombSize zero and not the other; PDFDPI, Concurrency, or Puts set below 1; and -// AudioLimit set to a limit the audio cutter refuses, or to zero. +// of BombRatio and BombSize zero and not the other; PDFDPI, Concurrency, or OutputWrites set below +// 1; and AudioLimit set to a limit the audio cutter refuses, or to zero. func (s Settings) Validate() error { var errs []error if missing := s.missing(); len(missing) > 0 { @@ -197,7 +197,7 @@ func (s Settings) Validate() error { atLeast("magick_memory", s.MagickMemory, 0), atLeast("magick_map", s.MagickMap, 0), atLeast("magick_disk", s.MagickDisk, 0), - atLeast("puts", s.Puts, 1), + atLeast("output_writes", s.OutputWrites, 1), s.bomb(), s.audioLimit(), ) diff --git a/settings/settings_test.go b/settings/settings_test.go index ce555592..ecc8d4b8 100644 --- a/settings/settings_test.go +++ b/settings/settings_test.go @@ -37,7 +37,7 @@ func full() map[string]any { "magick_map": 2 << 30, "magick_disk": 8 << 30, "audio_limit": "30s", - "puts": 1, + "output_writes": 1, } } @@ -84,7 +84,7 @@ func TestDecodeFull(t *testing.T) { MagickMap: new(int64(2 << 30)), MagickDisk: new(int64(8 << 30)), AudioLimit: new(30 * time.Second), - Puts: new(1), + OutputWrites: new(1), } if !reflect.DeepEqual(s, want) { t.Errorf("Decode = %+v, want %+v", s, want) @@ -107,8 +107,8 @@ func TestDecodeAccepts(t *testing.T) { "pdf_dpi unset": {"pdf_dpi": unset{}}, "audio_limit unset": {"audio_limit": unset{}}, "concurrency unset": {"concurrency": unset{}}, - "puts unset": {"puts": unset{}}, - "every optional key null": {"pdf_dpi": nil, "audio_limit": nil, "concurrency": nil, "puts": nil}, + "output_writes unset": {"output_writes": unset{}}, + "every optional key null": {"pdf_dpi": nil, "audio_limit": nil, "concurrency": nil, "output_writes": nil}, "audio_limit just over 4s": {"audio_limit": "4001ms"}, } { s, err := settings.Decode(encode(t, edits)) @@ -172,7 +172,7 @@ func TestDecodeRefusesValues(t *testing.T) { "bomb_size alone zero": {map[string]any{"bomb_size": 0}, []string{"bomb_ratio and bomb_size"}}, "pdf_dpi zero": {map[string]any{"pdf_dpi": 0}, []string{"pdf_dpi", "below 1"}}, "concurrency zero": {map[string]any{"concurrency": 0}, []string{"concurrency", "below 1"}}, - "puts zero": {map[string]any{"puts": 0}, []string{"puts", "below 1"}}, + "output_writes zero": {map[string]any{"output_writes": 0}, []string{"output_writes", "below 1"}}, "audio_limit zero": {map[string]any{"audio_limit": "0s"}, []string{"audio_limit", "4s"}}, "audio_limit 4s": {map[string]any{"audio_limit": "4s"}, []string{"audio_limit", "4s"}}, "audio_limit below zero": {map[string]any{"audio_limit": "-30s"}, []string{"audio_limit"}}, @@ -246,7 +246,7 @@ func TestKeyError(t *testing.T) { reason string }{ "a value below zero": {map[string]any{"max_bytes": -1}, []string{"max_bytes"}, "-1 is below zero"}, - "a value below 1": {map[string]any{"puts": 0}, []string{"puts"}, "0 is below 1"}, + "a value below 1": {map[string]any{"output_writes": 0}, []string{"output_writes"}, "0 is below 1"}, "the bomb rule half off": {map[string]any{"bomb_size": 0}, []string{"bomb_ratio", "bomb_size"}, "set both above zero, or both to zero for no bomb rule"}, "a wrong JSON type": {map[string]any{"pdf_text": "true"}, []string{"pdf_text"}, "a JSON string isn't a boolean"}, "an unparsable duration": {map[string]any{"unit_timeout": "soon"}, []string{"unit_timeout"}, `"soon" isn't a duration, such as "90s" or "10m"`}, From 1cc4d4f9504b10b18c491be7a651eee415da1788 Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Sat, 28 Nov 2026 21:16:25 -0500 Subject: [PATCH 9/9] Line width and wording: rewrap the v0.2.9 changelog lede; run.Config.Bounds names OutputWrites as dispatch's Puts - cmd/docproc/CHANGELOG.md: the v0.2.9 lede's first line ran to 103 columns after the rename; rewrapped to 100. - run.Config.Bounds' doc ran to 100+ columns and called OutputWrites a dispatch's field; it now reads "the Limits, Release, and OutputWrites, as Puts, each dispatch takes", as settings.Run's doc does. --- cmd/docproc/CHANGELOG.md | 4 ++-- cmd/docproc/internal/run/commands.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/docproc/CHANGELOG.md b/cmd/docproc/CHANGELOG.md index 0ca0b6bf..d03e63ea 100644 --- a/cmd/docproc/CHANGELOG.md +++ b/cmd/docproc/CHANGELOG.md @@ -13,8 +13,8 @@ postgres modules, and each system tool under `tools/` keep their own. ## [v0.2.9] - 2026-11-28 This release reads its run bounds through the docproc base module's new package `settings`, at -v0.11.0, and adds `DOCPROC_OUTPUT_WRITES`. Its exit codes and run directory's schema are unchanged, and -every existing variable keeps its meaning and its default. +v0.11.0, and adds `DOCPROC_OUTPUT_WRITES`. Its exit codes and run directory's schema are +unchanged, and every existing variable keeps its meaning and its default. ### Added diff --git a/cmd/docproc/internal/run/commands.go b/cmd/docproc/internal/run/commands.go index 0f63ad07..068733f6 100644 --- a/cmd/docproc/internal/run/commands.go +++ b/cmd/docproc/internal/run/commands.go @@ -23,7 +23,8 @@ type StageBuilder func(ctx context.Context, opts stages.Options) (stages.Set, er // stage builder, and the docproc build that writes the run. type Config struct { // Bounds are the run's bounds: the options the stages are built under, to whose Exclude the - // command adds the routes --exclude names, and each dispatch's Limits, Release, and OutputWrites. + // command adds the routes --exclude names, and the Limits, Release, and OutputWrites, as Puts, + // each dispatch takes. Bounds settings.Run // Build builds the stages; it is required. Build StageBuilder