feat: extract set_fields rule forces Int fields on gff_json merge targets (#40)
test / test (push) Successful in 1m27s
build-binaries / build-binaries (push) Successful in 2m22s
build-image / publish (push) Successful in 15s

Adds a `set_fields` option to `extract.merge.gff_json` rules: forces existing Int fields to a fixed value on every extract, applied after preserve_fields/merge_lists so the forced value always wins. Fields absent from the document stay absent. Rule targets can now be globs (e.g. `areas/*.are.json`).

Motivation: sow-module area weather chances must stay 0 (scripted regional weather owns weather); this makes the extract pipeline enforce it instead of a post-extract script.

Covered by `TestExtractSetsConfiguredGFFJSONFields`; `make check` passes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Reviewed-on: #40
Co-authored-by: vickydotbat <vickydotbat@tutamail.com>
Co-committed-by: vickydotbat <vickydotbat@tutamail.com>
This commit was merged in pull request #40.
This commit is contained in:
2026-07-14 16:36:40 +00:00
committed by archvillainette
parent 5ebef57160
commit 4ee28fee4f
3 changed files with 148 additions and 14 deletions
+18
View File
@@ -281,6 +281,15 @@ type ExtractGFFJSONMergeRule struct {
Target string `json:"target" yaml:"target"`
PreserveFields []string `json:"preserve_fields" yaml:"preserve_fields"`
MergeLists []ExtractListMergeRule `json:"merge_lists" yaml:"merge_lists"`
SetFields []ExtractSetFieldRule `json:"set_fields" yaml:"set_fields"`
}
// ExtractSetFieldRule forces an Int field to a fixed value on every extract,
// overriding whatever the toolset saved. Fields absent from the extracted
// document are left absent.
type ExtractSetFieldRule struct {
Field string `json:"field" yaml:"field"`
Value int32 `json:"value" yaml:"value"`
}
type ExtractListMergeRule struct {
@@ -980,6 +989,12 @@ func validateExtractMergeConfig(config ExtractMergeConfig) []error {
seenTargets[normalized] = struct{}{}
}
for setIndex, setRule := range rule.SetFields {
if strings.TrimSpace(setRule.Field) == "" {
failures = append(failures, fmt.Errorf("%s.set_fields[%d].field must not be empty", prefix, setIndex))
}
}
for listIndex, listRule := range rule.MergeLists {
listPrefix := fmt.Sprintf("%s.merge_lists[%d]", prefix, listIndex)
if strings.TrimSpace(listRule.Field) == "" {
@@ -1346,6 +1361,9 @@ func normalizeConfig(cfg *Config) {
}
cfg.Extract.Merge.GFFJSON[i].Target = target
cfg.Extract.Merge.GFFJSON[i].PreserveFields = normalizeStringSlice(cfg.Extract.Merge.GFFJSON[i].PreserveFields)
for j := range cfg.Extract.Merge.GFFJSON[i].SetFields {
cfg.Extract.Merge.GFFJSON[i].SetFields[j].Field = strings.TrimSpace(cfg.Extract.Merge.GFFJSON[i].SetFields[j].Field)
}
for j := range cfg.Extract.Merge.GFFJSON[i].MergeLists {
cfg.Extract.Merge.GFFJSON[i].MergeLists[j].Field = strings.TrimSpace(cfg.Extract.Merge.GFFJSON[i].MergeLists[j].Field)
cfg.Extract.Merge.GFFJSON[i].MergeLists[j].KeyField = strings.TrimSpace(cfg.Extract.Merge.GFFJSON[i].MergeLists[j].KeyField)