Build the image pipeline in the fx graph, with each default declared once in the config #313

Open
opened 2026-10-21 12:50:24 +02:00 by clawbot · 0 comments
Collaborator

Item 7 of 15 of #168: "Build the pipeline in main's fx graph, with the config as the only place defaults live". Starts when the item before it (removing the code nothing uses) is squash-merged to next.

Today (next at 989da78)

handlers.New builds the cache, fetcher, processor, session manager and encrypted-URL generator inside its OnStart hook (initImageService in internal/handlers/handlers.go), so Handlers holds a *database.Database only to hand it on, and its fields are nil until start. Defaults are declared three times: in internal/config (DefaultUpstreamConnectionsPerHost, DefaultUpstreamFetchTimeout, DefaultUpstreamMaxResponseSize and others), in httpfetcher.DefaultConfig() and as imageprocessor.DefaultMaxInputBytes. initImageService copies validated config into httpfetcher.Config field by field, with a positive-value guard the config already enforces, and NewService reads AllowHTTP and MaxResponseSize back out of that struct. "Disk cache off" is CacheMaxBytes == 0 in the config, CacheConfig.DisableDiskCache at the boundary, and Cache.disabled plus a zero-limit check inside.

Definition of done

  • The cache, the fetcher, the processor, the session manager, the encrypted-URL generator and the image service are each an fx provider taking the values it needs, in the fx graph internal/app builds; handlers.New receives them built, and no Handlers field is nil after construction.
  • Handlers holds no *database.Database it does not use itself.
  • Each setting's default is declared once, in internal/config. Constructors take explicit values, with no zero-means-default; httpfetcher.DefaultConfig() and imageprocessor.DefaultMaxInputBytes are gone, and tests that used them build their values explicitly.
  • initImageService and its field-by-field copy are gone; the image service does not read settings back out of the fetcher's config.
  • "Disk cache off" is one value carried from the config to the cache.
  • Startup, shutdown and every route behave as before.

Approval and tests

sneak asked for each main recommendation of #168 to be its own issue, built before 1.0, one at a time in the order listed (#168 (comment)). That instruction is his approval of this item. Existing tests change only as this item needs: they follow code that moves or is renamed, and the tests of code this item removes go with it; no other assertion is weakened or dropped.

Model: opus-5-5

Item 7 of 15 of https://git.eeqj.de/sneak/pixa/issues/168: "Build the pipeline in `main`'s fx graph, with the config as the only place defaults live". Starts when the item before it (removing the code nothing uses) is squash-merged to `next`. ## Today (`next` at `989da78`) `handlers.New` builds the cache, fetcher, processor, session manager and encrypted-URL generator inside its `OnStart` hook (`initImageService` in `internal/handlers/handlers.go`), so `Handlers` holds a `*database.Database` only to hand it on, and its fields are nil until start. Defaults are declared three times: in `internal/config` (`DefaultUpstreamConnectionsPerHost`, `DefaultUpstreamFetchTimeout`, `DefaultUpstreamMaxResponseSize` and others), in `httpfetcher.DefaultConfig()` and as `imageprocessor.DefaultMaxInputBytes`. `initImageService` copies validated config into `httpfetcher.Config` field by field, with a positive-value guard the config already enforces, and `NewService` reads `AllowHTTP` and `MaxResponseSize` back out of that struct. "Disk cache off" is `CacheMaxBytes == 0` in the config, `CacheConfig.DisableDiskCache` at the boundary, and `Cache.disabled` plus a zero-limit check inside. ## Definition of done - The cache, the fetcher, the processor, the session manager, the encrypted-URL generator and the image service are each an fx provider taking the values it needs, in the fx graph `internal/app` builds; `handlers.New` receives them built, and no `Handlers` field is nil after construction. - `Handlers` holds no `*database.Database` it does not use itself. - Each setting's default is declared once, in `internal/config`. Constructors take explicit values, with no zero-means-default; `httpfetcher.DefaultConfig()` and `imageprocessor.DefaultMaxInputBytes` are gone, and tests that used them build their values explicitly. - `initImageService` and its field-by-field copy are gone; the image service does not read settings back out of the fetcher's config. - "Disk cache off" is one value carried from the config to the cache. - Startup, shutdown and every route behave as before. ## Approval and tests sneak asked for each main recommendation of https://git.eeqj.de/sneak/pixa/issues/168 to be its own issue, built before 1.0, one at a time in the order listed (https://git.eeqj.de/sneak/pixa/issues/168#issuecomment-153513). That instruction is his approval of this item. Existing tests change only as this item needs: they follow code that moves or is renamed, and the tests of code this item removes go with it; no other assertion is weakened or dropped. Model: opus-5-5
clawbot added this to the 1.0.0 milestone 2026-10-21 12:50:24 +02:00
clawbot self-assigned this 2026-10-21 12:50:24 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/pixa#313