Skip to content

fix: Add auto-fix suggestions for definition issues in the warning dialog, starting with relation field type mismatch fixes#818

Merged
kingston merged 1 commit into
mainfrom
kingston/eng-1073-suggest-auto-fixes-for-issues
Mar 12, 2026
Merged

fix: Add auto-fix suggestions for definition issues in the warning dialog, starting with relation field type mismatch fixes#818
kingston merged 1 commit into
mainfrom
kingston/eng-1073-suggest-auto-fixes-for-issues

Conversation

@kingston

@kingston kingston commented Mar 12, 2026

Copy link
Copy Markdown
Collaborator
  • Also introduce sandbox for Claude Code

Summary by CodeRabbit

  • New Features

    • Added automatic fix suggestions for relation field type mismatches.
    • Introduced "Apply fix" action in warning dialogs to automatically resolve detected issues with visual feedback and status notifications.
  • Tests

    • Enhanced test coverage for auto-fix functionality and issue resolution.

…alog, starting with relation field type mismatch fixes

+ Also introduce sandbox for Claude Code
@changeset-bot

changeset-bot Bot commented Mar 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 08003c2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 21 packages
Name Type
@baseplate-dev/project-builder-lib Patch
@baseplate-dev/project-builder-web Patch
@baseplate-dev/create-project Patch
@baseplate-dev/project-builder-cli Patch
@baseplate-dev/project-builder-common Patch
@baseplate-dev/project-builder-dev Patch
@baseplate-dev/project-builder-server Patch
@baseplate-dev/plugin-auth Patch
@baseplate-dev/plugin-email Patch
@baseplate-dev/plugin-queue Patch
@baseplate-dev/plugin-rate-limit Patch
@baseplate-dev/plugin-storage Patch
@baseplate-dev/project-builder-test Patch
@baseplate-dev/code-morph Patch
@baseplate-dev/core-generators Patch
@baseplate-dev/fastify-generators Patch
@baseplate-dev/react-generators Patch
@baseplate-dev/sync Patch
@baseplate-dev/tools Patch
@baseplate-dev/ui-components Patch
@baseplate-dev/utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Mar 12, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR introduces an auto-fix system for definition issues. It adds infrastructure to create and apply fixes (createIssueFixSetter), implements a concrete fix for relation type mismatches (createTypeMismatchFix), extends the DefinitionIssueFix type to support full definition mutations, and integrates fix-application UI into the warning dialog with tests and configuration updates.

Changes

Cohort / File(s) Summary
Configuration & Setup
.changeset/suggest-auto-fixes-for-issues.md, .claude/settings.json, .vscode/tasks.json
New changeset documenting auto-fix patches; adds MCP and Git permissions; adds "Reset to Main" task for workspace cleanup.
Type Definitions
packages/project-builder-lib/src/schema/creator/definition-issue-types.ts
Extends DefinitionIssueFix interface: makes apply optional, adds applySetter for full definition mutations, updates comments to distinguish field-level vs. definition-level fixes.
Fix Infrastructure
packages/project-builder-lib/src/parser/definition-issue-utils.ts, packages/project-builder-lib/src/parser/definition-issue-utils.unit.test.ts, packages/project-builder-lib/src/parser/index.ts
New createIssueFixSetter utility that converts fixes to draft mutators; handles both applySetter and apply patterns; exported from parser module; includes comprehensive unit tests for three fix scenarios.
Relation Type Mismatch Fix
packages/project-builder-lib/src/parser/definition-issue-checkers/relation-type-mismatch-checker.ts, packages/project-builder-lib/src/parser/definition-issue-checkers/relation-type-mismatch-checker.unit.test.ts
Implements createTypeMismatchFix helper to auto-correct local scalar field types to match foreign field types; attaches fix to issues when types mismatch; tests validate fix application via Immer produce and type alignment.
UI Fix Application
packages/project-builder-web/src/components/definition-warning-dialog/definition-warning-dialog.tsx
Adds handleApplyFix handler, applies fixes via saveDefinition, manages applyingFixIndex state, adds "Apply fix" button with tooltip and disabled state during application, updates warnings list or closes dialog on success, shows toast notifications.
Test Updates
packages/project-builder-lib/src/parser/collect-definition-issues.unit.test.ts
Uses optional chaining (fix\?.apply\?.) when invoking fix.apply to safely handle undefined apply methods.
Project Configuration
examples/blog-with-auth/baseplate/project-definition.json
Updates cliVersion to "0.6.2"; removes default empty string from AuthVerification.userId field options.

Sequence Diagram

sequenceDiagram
    participant User
    participant DefinitionWarningDialog as Warning Dialog
    participant FixSetter as createIssueFixSetter
    participant SaveDef as saveDefinition
    participant Definition as ProjectDefinition

    User->>DefinitionWarningDialog: Click "Apply fix" button
    DefinitionWarningDialog->>FixSetter: createIssueFixSetter(issue, container)
    FixSetter-->>DefinitionWarningDialog: returns setter function
    DefinitionWarningDialog->>SaveDef: Apply setter via saveDefinition
    SaveDef->>Definition: Mutate draft (e.g., align field type)
    Definition-->>SaveDef: Updated definition
    SaveDef->>DefinitionWarningDialog: Fix applied, definition saved
    DefinitionWarningDialog->>DefinitionWarningDialog: Remove issue from warnings or close dialog
    DefinitionWarningDialog->>User: Show success toast
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • PR #779 — Introduces the global definition-issue/fix system foundation that this PR builds upon, extending DefinitionIssueFix and adding createIssueFixSetter to support the auto-fix infrastructure.
  • PR #801 — Adds global issue-checking utilities that this PR leverages; this PR extends that work by implementing concrete auto-fix support tied to relation-type-mismatch checks and definition-issue utilities.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding auto-fix suggestions for definition issues in the warning dialog, with relation field type mismatch as the initial implementation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kingston/eng-1073-suggest-auto-fixes-for-issues
📝 Coding Plan for PR comments
  • Generate coding plan

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (3)
packages/project-builder-lib/src/parser/definition-issue-checkers/relation-type-mismatch-checker.ts (2)

30-36: Redundant assignments in enum branch.

Lines 31-32 assign type and options directly to draftField, but lines 33-36 immediately overwrite them with Object.assign. The initial assignments are unnecessary.

♻️ Proposed fix to remove redundant assignments
       if (foreignField.type === 'enum') {
-        draftField.type = 'enum';
-        draftField.options = { ...foreignField.options };
         Object.assign(draftField, {
           type: 'enum',
           options: { ...foreignField.options },
         });
       } else {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/project-builder-lib/src/parser/definition-issue-checkers/relation-type-mismatch-checker.ts`
around lines 30 - 36, The enum branch in relation-type-mismatch-checker is doing
duplicate assignments to draftField: first setting draftField.type and
draftField.options, then immediately calling Object.assign(draftField, { type:
'enum', options: { ...foreignField.options } }), which is redundant; remove the
initial direct assignments (draftField.type = 'enum' and draftField.options = {
...foreignField.options }) and keep the single Object.assign call (or vice
versa) so draftField is only updated once with the enum type and copied options
from foreignField.

37-42: Options reset to {} discards field-specific configurations from the foreign field.

For enum fields, options are correctly copied from the foreign field (preserving enumRef). For other types (uuid, dateTime, date), resetting options to {} discards any user-configured values like genUuid: true or defaultToNow: true that may exist in the foreign field. While schema defaults apply during the initial defSchema.parse() call before fixes run, resetting options afterwards loses field-specific configurations that users may have explicitly set.

Consider copying applicable options from the foreign field consistently (as done for enum), or document this intentional behavior to clarify that non-default options are not preserved during type conversion.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/project-builder-lib/src/parser/definition-issue-checkers/relation-type-mismatch-checker.ts`
around lines 37 - 42, The code in relation-type-mismatch-checker.ts currently
replaces non-enum field options with {} (Object.assign(draftField, { type:
foreignField.type, options: {}, })), which discards user-configured options
(e.g., genUuid, defaultToNow); modify the fix so it preserves applicable options
from the foreign field instead of clearing them—for example, set options to a
shallow copy of foreignField.options (or explicitly copy known applicable keys
like genUuid, defaultToNow) when assigning draftField.type, while still
preserving the existing enum branch that copies enumRef.
packages/project-builder-web/src/components/definition-warning-dialog/definition-warning-dialog.tsx (1)

50-72: Consider showing success feedback even when new warnings remain.

When a fix is successfully applied but newWarnings.length > 0, the dialog updates with the new warnings but no success feedback is given. This might confuse users about whether their fix was actually applied.

♻️ Proposed enhancement to show success toast when fix is applied
     saveDefinition(setter)
       .then(({ warnings: newWarnings }) => {
+        toast.success(`Applied fix: ${fixLabel}`);
         if (newWarnings.length > 0) {
           setDialogOptions({ warnings: newWarnings });
         } else {
           setDialogOptions(undefined);
-          toast.success(`Applied fix: ${fixLabel}`);
         }
       })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/project-builder-web/src/components/definition-warning-dialog/definition-warning-dialog.tsx`
around lines 50 - 72, In handleApplyFix, when saveDefinition resolves and
returns newWarnings, always show a success toast for the applied fix even if
newWarnings.length > 0; update the .then callback for saveDefinition (inside
handleApplyFix) to call toast.success(`Applied fix: ${fixLabel}`) before or
alongside setDialogOptions({ warnings: newWarnings }) so users get success
feedback while the dialog refreshes with remaining warnings.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@packages/project-builder-lib/src/parser/definition-issue-checkers/relation-type-mismatch-checker.ts`:
- Around line 30-36: The enum branch in relation-type-mismatch-checker is doing
duplicate assignments to draftField: first setting draftField.type and
draftField.options, then immediately calling Object.assign(draftField, { type:
'enum', options: { ...foreignField.options } }), which is redundant; remove the
initial direct assignments (draftField.type = 'enum' and draftField.options = {
...foreignField.options }) and keep the single Object.assign call (or vice
versa) so draftField is only updated once with the enum type and copied options
from foreignField.
- Around line 37-42: The code in relation-type-mismatch-checker.ts currently
replaces non-enum field options with {} (Object.assign(draftField, { type:
foreignField.type, options: {}, })), which discards user-configured options
(e.g., genUuid, defaultToNow); modify the fix so it preserves applicable options
from the foreign field instead of clearing them—for example, set options to a
shallow copy of foreignField.options (or explicitly copy known applicable keys
like genUuid, defaultToNow) when assigning draftField.type, while still
preserving the existing enum branch that copies enumRef.

In
`@packages/project-builder-web/src/components/definition-warning-dialog/definition-warning-dialog.tsx`:
- Around line 50-72: In handleApplyFix, when saveDefinition resolves and returns
newWarnings, always show a success toast for the applied fix even if
newWarnings.length > 0; update the .then callback for saveDefinition (inside
handleApplyFix) to call toast.success(`Applied fix: ${fixLabel}`) before or
alongside setDialogOptions({ warnings: newWarnings }) so users get success
feedback while the dialog refreshes with remaining warnings.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 39d8b5ef-f781-49ea-adc7-68e1bfdb711d

📥 Commits

Reviewing files that changed from the base of the PR and between 51339e7 and 08003c2.

📒 Files selected for processing (12)
  • .changeset/suggest-auto-fixes-for-issues.md
  • .claude/settings.json
  • .vscode/tasks.json
  • examples/blog-with-auth/baseplate/project-definition.json
  • packages/project-builder-lib/src/parser/collect-definition-issues.unit.test.ts
  • packages/project-builder-lib/src/parser/definition-issue-checkers/relation-type-mismatch-checker.ts
  • packages/project-builder-lib/src/parser/definition-issue-checkers/relation-type-mismatch-checker.unit.test.ts
  • packages/project-builder-lib/src/parser/definition-issue-utils.ts
  • packages/project-builder-lib/src/parser/definition-issue-utils.unit.test.ts
  • packages/project-builder-lib/src/parser/index.ts
  • packages/project-builder-lib/src/schema/creator/definition-issue-types.ts
  • packages/project-builder-web/src/components/definition-warning-dialog/definition-warning-dialog.tsx

@kingston kingston merged commit d5e0b23 into main Mar 12, 2026
14 checks passed
@kingston kingston deleted the kingston/eng-1073-suggest-auto-fixes-for-issues branch March 12, 2026 15:32
@github-actions github-actions Bot mentioned this pull request Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant