Skip to content

Enable strict validation by default in defineStack()#654

Merged
hotlong merged 6 commits intomainfrom
copilot/analyze-test-issue
Feb 12, 2026
Merged

Enable strict validation by default in defineStack()#654
hotlong merged 6 commits intomainfrom
copilot/analyze-test-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 12, 2026

Field name validation (snake_case requirement) existed in schema but was never enforced. defineStack() defaulted to strict: false, returning config as-is without running Zod validation.

Changes

Breaking Change: defineStack() now validates by default

  • Changed DefineStackOptions.strict default: falsetrue
  • Validation logic: const strict = options?.strict !== false
  • Opt-out available via explicit strict: false

Validation enforcement

  • Field names must match /^[a-z_][a-z0-9_]*$/ (snake_case)
  • Object names, field types, and cross-references validated
  • Clear error messages: "Field names must be lowercase snake_case"

Migration

// Now rejects invalid field names by default
defineStack({
  manifest: {...},
  objects: [{
    name: 'task',
    fields: {
      firstName: { type: 'text' }  // ❌ Error: must be snake_case
    }
  }]
});

// Fix: Use snake_case
fields: {
  first_name: { type: 'text' }  // ✅
}

// Or temporarily bypass (not recommended)
defineStack(config, { strict: false });

Files Modified

  • stack.zod.ts: Default strict=true, updated logic
  • stack.test.ts: Updated tests, added 4 validation tests
  • field-name-validation.test.ts: New direct FieldSchema tests
  • .changeset/strict-validation-by-default.md: Breaking change documentation
Original prompt

按规则,字段名必须是 snake_case,这里的代码是怎么 test 通过的?为什么启动没有报错?

The user has attached the following file paths as relevant context:

  • .github/copilot-instructions.md
  • .github/copilot-instructions.md

Created from VS Code.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectstack-play Ready Ready Preview, Comment Feb 12, 2026 6:00pm
spec Ready Ready Preview, Comment Feb 12, 2026 6:00pm

Request Review

Copilot AI and others added 3 commits February 12, 2026 16:28
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
@github-actions github-actions bot added documentation Improvements or additions to documentation protocol:data tests tooling size/m labels Feb 12, 2026
@hotlong
Copy link
Copy Markdown
Contributor

hotlong commented Feb 12, 2026

@copilot 修正内核所有对象, fix and test

Copilot AI and others added 2 commits February 12, 2026 16:34
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate test passing without errors Enable strict validation by default in defineStack() Feb 12, 2026
Copilot AI requested a review from hotlong February 12, 2026 16:38
@hotlong hotlong marked this pull request as ready for review February 12, 2026 16:39
Copilot AI review requested due to automatic review settings February 12, 2026 16:39
@hotlong hotlong merged commit ef22cf8 into main Feb 12, 2026
1 of 4 checks passed
Copilot stopped work on behalf of hotlong due to an error February 12, 2026 16:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enforces field name validation by changing defineStack() to validate by default. Previously, field names were required to be snake_case per the schema specification, but this validation was never enforced because defineStack() defaulted to strict: false and returned configurations as-is without running Zod validation.

Changes:

  • Changed DefineStackOptions.strict default from false to true to enable validation by default
  • Updated validation logic from if (!options?.strict) to const strict = options?.strict !== false; if (!strict)
  • Updated tests to reflect new default behavior and added comprehensive field name validation tests
  • Created changeset documenting this breaking change with migration guide

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/spec/src/stack.zod.ts Changed default value of strict option from false to true and updated implementation logic to validate by default
packages/spec/src/stack.test.ts Updated existing test expectations for new default behavior and added 4 new tests for field name validation (camelCase rejection, PascalCase rejection, snake_case acceptance, strict=false bypass)
packages/spec/src/data/field-name-validation.test.ts New test file with direct FieldSchema validation tests covering camelCase, PascalCase, snake_case, and optional name cases
FIELD_VALIDATION_FIX.md Comprehensive technical documentation explaining root cause, investigation findings, solution, and migration path
.changeset/strict-validation-by-default.md Breaking change documentation with migration guide, examples, and impact assessment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation protocol:data size/m tests tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants