chore: check config field validation patterns compile in Go

Draft
2Y
19h ago
+49-0

[skip changelog]

Why

Config fields in every target's config.ts can declare a ValidationRegex. The patterns are written as JavaScript regular expressions and exported through RegExp.source, but the Speakeasy CLI validates gen.yaml with Go: it rewrites the escaped / that RegExp.source emits, then calls regexp.MustCompile on the result. Nothing in this repository checks that the two agree:

  • A JavaScript-only construct such as lookahead ((?=…)), lookbehind, or a backreference is valid in config.ts but makes regexp.MustCompile panic in the CLI for every user of that target.
  • A DefaultValue that fails its own pattern makes a freshly initialised gen.yaml fail validation.

The generator itself never reads ValidationRegex (only cmd/jsonschema copies it into a JSON Schema pattern), so neither problem shows up in generation or SDK tests.

Today all 269 patterns across the available templates compile in Go, and every pattern with a default accepts it. This test is a guard against regressions.

What changed

  • pkg/templates/config_test.go: TestConfigFieldValidationRegexes runs one subtest per template from templates.GetAvailableTemplates(). For each template it loads the config fields with newSDK both false and true, compiles every ValidationRegex after applying the same slash rewrite as the CLI, and asserts that every DefaultValue matches its pattern.

Per-field accept/reject cases stay in target-specific files next to it (for example pkg/templates/config_ruby_test.go from #152). A default-value check cannot catch a pattern that is too strict when the default still passes.

No generated output changes.

Testing

  • go test ./pkg/templates -run TestConfigFieldValidationRegexes -count=1: passes.
  • Mutation checks, each reverted afterwards:
    • lookahead in a pattern (^(?=O)[A-Za-z]+$): fails with a compile error naming the field;
    • a default that does not match its pattern: fails naming the field, default, and pattern;
    • removing the slash rewrite: fails on the cli target's packageName, whose pattern contains /.
  • make lint: passes.

Public-safety check

  • This change contains no credentials, customer documents, private repository URLs, private filesystem paths, or unredacted private logs.
  • Title, body, comments, and commit messages name no customers or customer-derived identifiers, private paths or trackers, or workflow provenance, and are understandable without private context (.claude/skills/public-repo-communication/SKILL.md).
  • Generated fixtures and review SDK changes are public-safe.
  • I reviewed git diff --check.