name: schema-sync-check description: Validate CUE schema sync after editing schemas, Go structs with JSON tags, value-type Validate() methods, enum/disjunction constraints, config defaults, or schema-owned decode behavior. Runs targeted structural and behavioral sync tests and reports mismatches.
Schema Sync Check
Validate that CUE schema definitions and Go struct JSON tags are in sync.
When to Use
Invoke this skill (/schema-sync-check) after:
- Editing any CUE schema file (
*_schema.cue) - Adding or modifying JSON tags on Go structs in
pkg/invowkfile/,pkg/invowkmod/, orinternal/config/ - Renaming CUE fields or Go struct fields
- Adding new CUE definitions with corresponding Go types
- Changing validation/default behavior mirrored between CUE and Go, including
Validate()methods, enum/disjunction values, runtime defaults, and config defaults
What It Checks
Schema Files → Go Structs
| Schema | Go Package | Sync Test |
|---|---|---|
pkg/invowkfile/invowkfile_schema.cue |
pkg/invowkfile/ |
pkg/invowkfile/sync_test.go, pkg/invowkfile/sync_runtime_test.go, pkg/invowkfile/sync_behavioral_test.go, pkg/invowkfile/sync_runtime_behavioral_test.go |
pkg/invowkmod/invowkmod_schema.cue |
pkg/invowkmod/ |
pkg/invowkmod/sync_test.go |
internal/config/config_schema.cue |
internal/config/types.go |
internal/config/sync_test.go |
Sync Test Pattern
The structural sync tests verify:
- Every CUE field name has a matching JSON tag in the Go struct
- Every Go struct JSON tag has a matching CUE field name
- CUE optional fields and Go
omitemptytags are aligned, reported as warnings where the helper cannot prove intent
Behavioral sync tests then cover parser/schema behavior such as runtime defaults, validation constraints, and config decode compatibility. The structural helper does not prove Go/CUE type compatibility by itself.
Workflow
Step 1: Run Sync Tests
go test -v -run Sync ./pkg/invowkfile/ ./pkg/invowkmod/ ./internal/config/
Then run the targeted packages to cover behavioral/default tests whose names do
not include Sync:
go test -v ./pkg/invowkfile/ ./pkg/invowkmod/ ./internal/config/
Step 2: Interpret Results
All tests pass: Schema and Go structs are in sync. No action needed.
Test failures: The output will show which fields are mismatched:
--- FAIL: TestCommandSchemaSync
sync_test.go:142: CUE field "new_field" has no matching Go JSON tag
sync_test.go:148: Go JSON tag "old_field" has no matching CUE field
Step 3: Fix Mismatches
For each mismatch, determine the correct action:
| Mismatch Type | Fix |
|---|---|
| CUE field missing Go tag | Add json:"field_name" tag to Go struct |
| Go tag missing CUE field | Add field to CUE schema definition |
| Field renamed in CUE | Update Go JSON tag to match |
| Field renamed in Go | Update CUE field name to match |
| Field removed from CUE | Remove Go struct field (or add exclusion if field is Go-only) |
| Field removed from Go | Remove CUE field (or verify it's intentionally CUE-only) |
Step 4: Re-verify
After fixes, run the sync tests again to confirm:
go test -v -run Sync ./pkg/invowkfile/ ./pkg/invowkmod/ ./internal/config/
go test -v ./pkg/invowkfile/ ./pkg/invowkmod/ ./internal/config/
Step 5: Run Full Test Suite
Sync changes may affect parsing behavior:
make test
Quick Reference
Adding a New Field
Add to CUE schema with constraints:
new_field: string & =~"^[a-z]+$" & strings.MaxRunes(128)Add to Go struct with JSON tag:
NewField string `json:"new_field"`Run sync check to verify alignment
Adding a New Type
- Define CUE definition:
#NewType: close({ ... }) - Create Go struct with JSON tags
- Add the type to the existing table-driven sync test when possible, or add a
targeted test function with the shared helper:
func TestNewTypeSchemaSync(t *testing.T) { schema, _ := getCUESchema(t) def := schematest.LookupDefinition(t, schema, "#NewType") cueFields := schematest.ExtractCUEFields(t, def) goFields := schematest.ExtractGoJSONTags(t, reflect.TypeFor[NewType]()) schematest.AssertFieldsSync(t, "NewType", cueFields, goFields) }
Common Issues
| Issue | Cause | Fix |
|---|---|---|
omitempty mismatch |
CUE optional (?) vs Go omitempty |
Ensure optional CUE fields use omitempty in Go |
| Helper limitation | schematest.ExtractGoJSONTags is direct-field oriented and treats omitempty as optional; tags such as omitzero need review |
Inspect the helper output and add explicit behavioral coverage when needed |
| Nested struct sync | Inner struct not tested | Add separate sync test for nested type |
| Mapstructure tag | Viper config fields need both tags | Add mapstructure:"field_name" alongside json |
| Stale exclusions | Removed fields still in exclusion list | Clean up sync test exclusions after refactoring |