69dce53bfdde8a7e3fa111a451fb41684abf5677
3
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
c66c0a2a38 |
refactor(config): move loading into infrastructure/configuration
internal/config both defined the types every package imports and performed
the file I/O to produce them. Importing a settings struct therefore pulled
in a TOML decoder and a YAML decoder, and the shared model owned discovery,
decoding, overlays, defaulting and validation all at once. See
docs/architecture/configuration.md, which requires loading to move out and
internal/config to be dissolved.
internal/config is now types only -- no os, no filepath, no toml. The new
package owns loading, one concern per file:
features.go the closed set of recognised feature files
discovery.go directory scan and classification
decode.go TOML/YAML decoding, format dispatch
defaults.go filling absent values, no errors
validate.go judging supplied values, no mutation
provenance.go which file contributed what
loader.go Loader wiring the above; File/Overlay/Dir
Beyond relocating, this fixes what the old code conflated:
- Defaulting and validation were interleaved. applyAgentDefaults and
applyDispatchDefaults returned validation errors; validateContainers and
validateSingleIdentity quietly mutated the config. There was no point at
which you could see what the operator actually supplied. They are now
separate passes: applyDefaults never fails, validate never writes.
- Errors were fmt.Errorf strings prefixed "config: ", so a caller could not
distinguish operator-fixable input from an unreadable file without
matching message text. Five sentinels now carry that distinction.
- dataHome() read XDG_DATA_HOME directly and discarded the error from
os.UserHomeDir, so defaulting could not be tested without the
environment. It is injectable on Loader and no longer swallows the error.
- Nothing recorded where a value came from. With overlays, feature files
and conf.d/ all able to set the same field, "which file set this?" was
answerable only by re-deriving precedence by hand. Provenance records it.
- Feature files were applied in map iteration order, making load order and
any resulting error arbitrary. Discovery now returns them sorted.
- loadMainConfig reported "no config.yaml or config.toml found in %s" with
an empty string: the directory was lost when it was extracted from
loadDirInto, so the error named no directory.
- Unreadable or malformed conf.d/ extras were skipped silently, which
presents as a setting the operator wrote simply not taking effect.
- Decode errors from the main config were returned bare, without naming
the file that failed to parse.
The 40 loader tests moved with the code and their assertions are unchanged,
so the defaulting and validation rewrite is behaviour-preserving.
Document.Config is the temporary seam: still internal/config.Config, named
as a field so the compromise is visible at each use site, with its deletion
condition recorded in doc.go. Building typed per-domain sections now, while
every consumer still reads config.Config, would mean two shapes kept in sync
by hand with no consumer for the new one; that belongs with the dissolution
work, not ahead of it.
No consumer outside cmd/archied changed.
Verified: go build, go vet, gofmt clean; go test ./internal/config/... and
./internal/infrastructure/configuration/... pass. Pre-existing gateway and
telegram failures are unchanged.
|
||
|
|
a8efbf5046 |
refactor: route tasks on a typed kind, not forge labels
The event bus was inspecting forge issue labels ("bug", "feature",
"bootstrap") to pick a subject. That put a forge vocabulary inside
infrastructure and duplicated the label table already owned by
workflow.Route -- adding a label meant remembering both places, and
nothing would have caught it if you forgot.
The label table now lives once, in internal/workflow, which already owns
label semantics:
- workflow.Kind names the routing category, with labelKinds as the
single label vocabulary and kindWorkflows mapping kind to registry
entry. Route consumes the ordered kind list so a "bug,feature" task
still falls through to feasibility when no tdd workflow is
registered, exactly as the switch did.
- nats.TaskKind is a closed, validated set of subject tokens.
PublishTask rejects an unknown kind rather than silently delivering
it to the default queue; the zero kind means default, so messages
queued before this field decode unchanged.
- The daemon classifies at the publish site and sets TaskEnvelope.Kind.
Also fixes two defects this exposed:
- drainNATS never reached its SQLite fallback. Replacing the old
(nil, nil) no-message signal with ErrNoMessage in
|
||
|
|
492ca209f9 |
refactor(nats): rebuild as infrastructure/eventbus/nats with real boundaries
Relocating internal/nats as-is would have cemented its problems into the approved layout, so this is a rewrite rather than a move. What was wrong: - Conn() *nats.Conn, PublishMsg(*nats.Msg) and Fetch() jetstream.Msg pushed SDK types into all four consumers, so the broker was not replaceable -- the opposite of what dependencies-and-contracts.md requires. - PublishTask took seven positional parameters, six of them strings, where a transposed argument was a silent bug. - Labels travelled as a comma-separated string and were re-split on every publish. - Fetch returned (nil, nil) for 'no message', which every caller had to remember to special-case. - The logger field was stored and never used. - Stream name, consumer name and every timeout were hardcoded constants. - Errors were inconsistently wrapped; several paths returned bare errors. - Connect repeated nc.Close() on each failure branch. What replaces it: - One concern per file: config, errors, subjects, message, client, publisher, consumer. - Publisher/Consumer/Requester interfaces with compile-time assertions, so callers depend on behaviour and can be faked without a broker. - A Message wrapper keeps jetstream types behind the boundary; consumers no longer import the NATS SDK at all. - TaskEnvelope with []string labels and JSON methods preserving the comma-separated wire form for already-queued messages. - Sentinel errors (ErrNoMessage, ErrNotConnected, ErrNoReplyAddress, ErrInvalidConfig) and %w wrapping with operation context throughout. - Config with validation and defaults; a single deferred cleanup in Connect. - CoreConn() as the one documented escape hatch, for the *rpc packages that are themselves NATS infrastructure. Consumers migrated: cmd/archied, cmd/archie-agent, internal/daemon, internal/agentexec. Behaviour, subjects and wire format unchanged. |