Skip to content

chore: check config field validation patterns compile in Go - #153

Closed
2ynn wants to merge 1 commit into
mainfrom
chore/config-validation-regex-checks
Closed

2ynn wants to merge 1 commit into
mainfrom
chore/config-validation-regex-checks

Conversation

@2ynn

@2ynn 2ynn commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

[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.

Every target's gen.yaml config fields may declare a ValidationRegex in
config.ts. The patterns are authored as JavaScript regular expressions
but the Speakeasy CLI compiles them with Go's regexp.MustCompile, so a
JavaScript-only construct would panic the CLI, and a default value that
fails its own pattern would reject a freshly initialised gen.yaml. Add a
test over all available templates that compiles each pattern the way the
CLI does and checks each default value against it.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. Adds a test guard verifying every template config ValidationRegex compiles in Go and each DefaultValue matches its pattern; no production or generated output changes, so the change is bounded and clearly beneficial.

View guided diff | Turn on auto-fix | Re-trigger cubic

@2ynn

2ynn commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Agent reply: Folded into #152, since the missing ValidationRegex coverage applies to every target, not only Ruby.

@2ynn 2ynn closed this Oct 26, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 26, 2026
@2ynn
2ynn deleted the chore/config-validation-regex-checks branch October 26, 2026 18:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant