Skip to content

fix(migrations): traverse nested template choices#1152

Merged
chhoumann merged 2 commits intomasterfrom
codex/fix-file-exists-migration-traversal
Mar 14, 2026
Merged

fix(migrations): traverse nested template choices#1152
chhoumann merged 2 commits intomasterfrom
codex/fix-file-exists-migration-traversal

Conversation

@chhoumann
Copy link
Owner

@chhoumann chhoumann commented Mar 14, 2026

Handle nested Template choices during \ by reusing the shared choice traversal helper.

The previous migration only normalized top-level Template choices, Multi children, and direct legacy macro commands. That missed Template choices embedded inside Macro choice command lists and inside Conditional then/else branches, which left legacy file-exists settings behind and degraded runtime behavior to prompt mode.

This switches the migration to use , which already traverses Multi choices, Macro choice commands, legacy macros, and Conditional branches in one place. The tests now cover nested Macro-choice templates, legacy macros, and Conditional branches.

This came from follow-up review comments on #1151 after the original PR was merged.


Open with Devin

Summary by CodeRabbit

  • Tests

    • Expanded coverage for normalization of file-existence choices in nested macro and conditional scenarios; adds cases for malformed persisted data and asserts obsolete file-existence fields are removed.
  • Refactor

    • Streamlined migration logic to a single traversal-driven normalization pass for template choices, improving efficiency and consistency.

@vercel
Copy link

vercel bot commented Mar 14, 2026

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

Project Deployment Actions Updated (UTC)
quickadd Ready Ready Preview Mar 14, 2026 3:24pm

@coderabbitai
Copy link

coderabbitai bot commented Mar 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d6538326-9c38-48ae-8876-1e6b10c43540

📥 Commits

Reviewing files that changed from the base of the PR and between 6999b34 and 9ee2acf.

📒 Files selected for processing (2)
  • src/migrations/consolidateFileExistsBehavior.test.ts
  • src/migrations/consolidateFileExistsBehavior.ts

📝 Walkthrough

Walkthrough

Refactors the consolidateFileExistsBehavior migration to use a traversal-based normalization (walkAllChoices) and expands tests to cover nested template choices in macro commands, conditionals, legacy macros, and malformed persisted collections; tests also assert removal of obsolete file-exists fields.

Changes

Cohort / File(s) Summary
Test Expansion
src/migrations/consolidateFileExistsBehavior.test.ts
Adds multiple tests for normalizing template choices nested inside Macro commands, legacy macro structures, conditional branches (then/else), and malformed persisted choice/macro collections; asserts obsolete fields (fileExistsMode, setFileExistsBehavior) are removed.
Migration Refactor
src/migrations/consolidateFileExistsBehavior.ts
Replaces per-item recursive normalization with a deep-clone + unified walkAllChoices traversal that normalizes template choices; removes local recursive helpers and direct use of several prior helper predicates.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

released

Poem

🐰 I hopped through code and found a maze,
Nested choices tucked in macro bays,
I nudged the paths to walk, not climb,
Cleaned the crumbs and saved some time,
A tiny rabbit cheers refactor days! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(migrations): traverse nested template choices' directly matches the main change: implementing traversal of nested template choices in the migration to handle previously unprocessed nested structures.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 codex/fix-file-exists-migration-traversal
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@chhoumann chhoumann marked this pull request as ready for review March 14, 2026 15:18
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 14, 2026

Deploying quickadd with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9ee2acf
Status: ✅  Deploy successful!
Preview URL: https://4aa22f76.quickadd.pages.dev
Branch Preview URL: https://codex-fix-file-exists-migrat.quickadd.pages.dev

View logs

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/migrations/consolidateFileExistsBehavior.ts (1)

15-18: Harden migration input before deep-cloning settings arrays.

If persisted settings are malformed (e.g., choices missing/non-array), this can throw before traversal. Consider normalizing both collections with Array.isArray(...) before cloning.

Suggested defensive patch
-		plugin.settings.choices = deepClone(plugin.settings.choices);
-		(plugin.settings as any).macros = deepClone(
-			(plugin.settings as any).macros || [],
-		);
+		const choices = Array.isArray(plugin.settings.choices)
+			? plugin.settings.choices
+			: [];
+		const macros = Array.isArray((plugin.settings as any).macros)
+			? (plugin.settings as any).macros
+			: [];
+
+		plugin.settings.choices = deepClone(choices);
+		(plugin.settings as any).macros = deepClone(macros);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/migrations/consolidateFileExistsBehavior.ts` around lines 15 - 18, The
migration currently deep-clones plugin.settings.choices and (plugin.settings as
any).macros without validating their types, which can throw if persisted data is
malformed; before calling deepClone, ensure both are normalized to arrays by
replacing non-array values with empty arrays (e.g., set plugin.settings.choices
= Array.isArray(plugin.settings.choices) ? deepClone(plugin.settings.choices) :
[]; and similarly for (plugin.settings as any).macros), preserving the existing
cast to (plugin.settings as any) for macros and using deepClone for the safe
copy.
src/migrations/consolidateFileExistsBehavior.test.ts (1)

87-92: Optional: assert legacy field cleanup on nested template nodes too.

You already assert normalized fileExistsBehavior; adding toBeUndefined() checks for nested setFileExistsBehavior and fileExistsMode would better lock in full normalization behavior.

Also applies to: 171-180

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

In `@src/migrations/consolidateFileExistsBehavior.test.ts` around lines 87 - 92,
Add assertions to ensure legacy fields are removed on nested template nodes by
checking that setFileExistsBehavior and fileExistsMode are undefined wherever
you already assert normalized fileExistsBehavior; for example augment the
existing expectation on plugin.settings.choices[0].macro.commands[0].choice to
also include toBeUndefined() checks for choice.setFileExistsBehavior and
choice.fileExistsMode, and do the same for the other nested node assertions
around the second test block (the nodes currently asserting normalized
fileExistsBehavior) so the test verifies both normalization and cleanup.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/migrations/consolidateFileExistsBehavior.test.ts`:
- Around line 87-92: Add assertions to ensure legacy fields are removed on
nested template nodes by checking that setFileExistsBehavior and fileExistsMode
are undefined wherever you already assert normalized fileExistsBehavior; for
example augment the existing expectation on
plugin.settings.choices[0].macro.commands[0].choice to also include
toBeUndefined() checks for choice.setFileExistsBehavior and
choice.fileExistsMode, and do the same for the other nested node assertions
around the second test block (the nodes currently asserting normalized
fileExistsBehavior) so the test verifies both normalization and cleanup.

In `@src/migrations/consolidateFileExistsBehavior.ts`:
- Around line 15-18: The migration currently deep-clones plugin.settings.choices
and (plugin.settings as any).macros without validating their types, which can
throw if persisted data is malformed; before calling deepClone, ensure both are
normalized to arrays by replacing non-array values with empty arrays (e.g., set
plugin.settings.choices = Array.isArray(plugin.settings.choices) ?
deepClone(plugin.settings.choices) : []; and similarly for (plugin.settings as
any).macros), preserving the existing cast to (plugin.settings as any) for
macros and using deepClone for the safe copy.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 85a9d2fd-2121-4c80-a1c4-19ca910be176

📥 Commits

Reviewing files that changed from the base of the PR and between 5ea1db0 and 6999b34.

📒 Files selected for processing (2)
  • src/migrations/consolidateFileExistsBehavior.test.ts
  • src/migrations/consolidateFileExistsBehavior.ts

@chhoumann chhoumann merged commit 08d2430 into master Mar 14, 2026
5 checks passed
@chhoumann chhoumann deleted the codex/fix-file-exists-migration-traversal branch March 14, 2026 15:27
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