beads/internal/storage
Stephanie Jarmak 05c7835e9d
feat(storage): honor .beads/config.yaml types.custom in server-side validation (#4024) (#4026)
* feat(storage): honor .beads/config.yaml types.custom in server-side validation (#4024)

ResolveCustomTypesInTx previously consulted config.GetCustomTypesFromYAML
only in a narrow error-fallback path: when both the custom_types table AND
the types.custom config-string read had failed. As a result, a project that
declared types.custom in .beads/config.yaml (the version-controlled config
shape that downstream wrappers like gastownhall/gascity expect) could not
create or update beads of those types — server-side schema validation
rejected them because it never saw the YAML entries.

Overlay model (per #4024's proposed behavior):
  - Built-in types stay as the enforced floor (handled by IsValidWithCustom).
  - Database custom_types are the next layer (operator-/agent-installed types).
  - .beads/config.yaml types.custom is the topmost union-add (project-extension
    types declared in version-controlled config).
  - A bead whose type is in none of the three still fails validation cleanly.

Extracts mergeWithYAMLCustomTypes(dbTypes, yamlGetter) as a pure helper so
the union logic is unit-testable without sql.Tx mocking. The new helper:
  - Preserves order: DB types first, YAML-only types appended in declared order.
  - Dedupes whitespace-trimmed entries.
  - Drops empty/whitespace-only entries.
  - Tolerates nil getter and nil dbTypes.

Tests in internal/storage/issueops/config_helpers_test.go:
  - TestMergeWithYAMLCustomTypes — 7 table cases: both empty, yaml-only,
    db-only, db+disjoint-yaml union, db+overlapping-yaml dedup, yaml
    internal-dup dedup, whitespace dropping.
  - TestMergeWithYAMLCustomTypes_NilGetter — explicit nil-getter guard.

The pre-existing ResolveCustomTypesInTx error-fallback path is preserved:
when the config-string read errors AND YAML has types, return the YAML
overlay anyway with the original error — so a stable-bd project running
pre-#3691 doesn't lose its types.custom validation just because the
config-string read errored.

Downstream context: this unblocks gastownhall/gascity#2154 (the Gas City
side, which writes types.custom into .beads/config.yaml via
gc-beads-bd.sh's ensure_types_custom_in_yaml). Once this lands and bd
deployments adopt the fixed build, Gas City projects no longer need the
fallback workaround of mirroring types.custom into the database side.

* fix: address PR #4026 review findings (#4024)

Two findings from Copilot review:

1. ResolveCustomTypesInTx returned the YAML overlay alongside a non-nil
   error when the in-tx config-string read failed. In-tx callers
   (NewBatchContext, UpdateIssueInTx) treat any error as fatal, so the
   YAML-fallback path was effectively unreachable on pre-migration /
   degraded DBs — defeating the #4024 overlay goal precisely in the
   scenario the overlay was meant to cover. Mirror
   ResolveCustomStatusesDetailedInTx: when YAML supplies types, return
   them with a nil error; otherwise propagate the DB error. Extracted
   into customTypesYAMLFallback for unit testing without sql.Tx mocking.

2. getConfigList (the helper backing GetCustomTypesFromYAML /
   GetInfraTypesFromYAML / GetCustomStatusesFromYAML) used
   viper.GetString + comma-split, which silently ignored the YAML
   sequence form named in #4024 (`types: { custom: [step, wisp] }`).
   List-form .beads/config.yaml declarations therefore yielded an empty
   overlay. Try viper.GetStringSlice first (supports both block-list
   and inline-flow syntaxes), keeping the comma-split fallback for the
   legacy `types.custom = "step,wisp"` string form.

Tests: TestCustomTypesYAMLFallback covers the fallback decision;
TestGetCustomTypesFromYAML_ListForm and TestGetCustomTypesFromYAML_InlineListForm
pin both YAML sequence syntaxes.

Refs: gastownhall/beads#4024

---------

Co-authored-by: sjarmak <stephanie.jarmak1@gmail.com>
2026-05-21 10:26:53 -07:00
..
dberrors fix(storage): preserve mixed issue and wisp reads (#3991) 2026-05-21 06:50:42 -07:00
dbproxy /{cmd,internal}: tweaks before merge 2026-05-10 07:09:32 -07:00
dolt fix(storage): preserve mixed issue and wisp reads (#3991) 2026-05-21 06:50:42 -07:00
doltutil /internal/storage: some lint 2026-05-06 10:48:43 -07:00
domain /internal/storage: cleanup 2026-05-20 14:58:19 -07:00
embeddeddolt perf(get): query primary issues before wisp fallback (#4003) 2026-05-18 03:37:02 -07:00
fs /{cmd,internal}: refactoring 2026-05-19 15:37:37 -07:00
git /{cmd,internal}: refactoring 2026-05-19 15:37:37 -07:00
issueops feat(storage): honor .beads/config.yaml types.custom in server-side validation (#4024) (#4026) 2026-05-21 10:26:53 -07:00
schema fix(storage): preserve mixed issue and wisp reads (#3991) 2026-05-21 06:50:42 -07:00
uow /internal/storage: cleanup 2026-05-20 14:58:19 -07:00
versioncontrolops /{cmd,internal}: wip, removing ignored table code 2026-05-12 09:53:56 -07:00
advanced_queries.go /internal/storage: add interfaces for methods not covered by Storage 2026-03-06 15:30:10 -08:00
annotation_queries.go Update internal/storage/annotation_queries.go 2026-03-06 15:40:56 -08:00
batch.go refactor: remove JSONL storage layer from core Go files (bd-9ni.2) 2026-02-22 21:52:18 -08:00
bulk_issues.go /{cmd,internal}: remove more code 2026-05-15 09:05:29 -07:00
compaction.go /internal/storage: add interfaces for methods not covered by Storage 2026-03-06 15:30:10 -08:00
config_metadata.go feat: custom status categories (active/wip/done/frozen) 2026-03-21 12:35:03 -07:00
dependency_queries.go /{cmd,internal}: remove dead code 2026-05-15 09:05:29 -07:00
federation.go /internal/storage: add interfaces for methods not covered by Storage 2026-03-06 15:30:10 -08:00
history_viewer.go /internal/storage: add interfaces for methods not covered by Storage 2026-03-06 15:30:10 -08:00
hook_decorator.go feat: add JSONL bulk dep add (#3530) 2026-04-27 04:51:46 -07:00
hook_decorator_test.go feat: move hook firing into storage layer via decorator (#2891) 2026-03-31 14:32:01 -07:00
infra_types.go /{cmd,internal}: embeddeddolt list 2026-03-18 15:21:36 -07:00
merge_slot.go feat: add MergeSlot methods to Storage interface (fix-merge PR #2787) 2026-03-26 19:34:21 -07:00
metadata.go fix: quote dotted metadata keys in JSON path expressions (#2865) 2026-03-27 23:50:25 -07:00
metadata_jsonpath_test.go fix: quote dotted metadata keys in JSON path expressions (#2865) 2026-03-27 23:50:25 -07:00
metadata_schema_test.go feat: config-driven metadata schema enforcement (GH#1416 Phase 2) (#2027) 2026-02-24 22:24:56 -08:00
metadata_test.go feat: allow UpdateIssue metadata updates via json.RawMessage/[]byte (#1417) 2026-02-03 17:55:23 -08:00
remote.go feat: add --remote flag to bd dolt push/pull commands (#3211) 2026-04-20 18:02:33 -07:00
storage.go Add atomic ready claim (GH-3570) 2026-04-28 07:11:13 -07:00
sync.go /internal/storage: add interfaces for methods not covered by Storage 2026-03-06 15:30:10 -08:00
version_control.go fix(bootstrap): commit issue_prefix to config table (GH#3216) (#3247) 2026-04-13 13:54:50 -07:00
versioned.go refactor: remove gastown/Gas Town string references from beads code and docs (bd-1ue8) 2026-03-20 18:39:50 -07:00