refactor(ts#project): improve GritQL pattern scoping and idempotency#550
Open
nx-plugin-for-aws wants to merge 3 commits intomainfrom
Open
refactor(ts#project): improve GritQL pattern scoping and idempotency#550nx-plugin-for-aws wants to merge 3 commits intomainfrom
nx-plugin-for-aws wants to merge 3 commits intomainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #550 +/- ##
==========================================
+ Coverage 89.35% 89.48% +0.12%
==========================================
Files 94 94
Lines 3166 3157 -9
Branches 701 694 -7
==========================================
- Hits 2829 2825 -4
+ Misses 156 155 -1
+ Partials 181 177 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
added 3 commits
April 7, 2026 13:12
Add missing idempotency guards to GritQL patterns that could produce duplicate transformations if run multiple times, and consolidate match+apply pairs into single idempotent apply calls where it simplifies the code.
Use a JSX element pattern instead of a className string for the idempotency check, which GritQL can match correctly in JSX context.
The cognito-auth generator already prevents re-running via a top-level guard, so pattern-level idempotency in .grit files is unnecessary. The added where clauses also interfered with GritQL pattern evaluation in nested contains-rewrite expressions, breaking the e2e smoke tests.
2591b53 to
c9bbee2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reason for this change
Several GritQL AST transformation patterns across generators lacked idempotency guards, meaning they could produce duplicate code if run multiple times on the same file. Additionally, some generators used a
matchGritQL+applyGritQLtwo-step pattern where a single idempotentapplyGritQLcall with awhereclause would be simpler and more consistent with patterns used elsewhere in the codebase.Description of changes
Idempotency guards added to inline GritQL patterns:
connection/serve-local.ts— prevents duplicateruntimeConfig.apis.*lines via$stmts <: not containsts/strands-agent/react-connection/serve-local.ts— prevents duplicateruntimeConfig.agentRuntimes.*linests/nx-generator/generator.ts— prevents duplicate sidebar entries in docs configConsolidated
matchGritQL+applyGritQLinto single idempotentapplyGritQL:utils/shared-shadcn.ts— ESLint rule addition now uses$items <: not containsguard instead of a separatematchGritQLcheckutils/connection/open-api/react.ts— QueryClientProvider and API provider wrapping use$program <: not containsinstead of a separatematchGritQLchecktrpc/react/generator.ts— QueryClientProvider and tRPC provider wrapping (same pattern)ts/strands-agent/react-connection/generator.ts— QueryClientProvider and agent provider wrapping (same pattern)These consolidations follow the same pattern already used in
cognito-auth-wrapper.grit($program <: not contains), making the codebase more consistent.Note: The cognito-auth
.gritfiles (none-auth-menu.grit,cloudscape-auth-menu.grit,shadcn-auth-menu.grit,shadcn-state-declarations.grit) were intentionally left without pattern-level idempotency guards. The cognito-auth generator already prevents re-running at a higher level, and addingwhereguards to these patterns interfered with GritQL's evaluation of nestedcontains-rewrite expressions.Description of how you validated changes
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license