fix: harden monorepo workspace detection and workflow generation#83
fix: harden monorepo workspace detection and workflow generation#83WolfieLeader wants to merge 7 commits intoTanStack:mainfrom
Conversation
🦋 Changeset detectedLatest commit: f9010aa The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
📝 WalkthroughWalkthroughThis PR fixes monorepo workspace detection across Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 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. Comment Tip CodeRabbit can suggest fixes for GitHub Check annotations.Configure the |
commit: |
|
Let's go all green🫡 |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
.changeset/fix-monorepo-workspace-detection.md (1)
1-5: Consider documenting the API signature changes in the changeset.The changeset describes the monorepo detection fixes well, but doesn't mention that
scanForIntentsandscanLibrarychanged from async to sync. If these are part of the public API, callers usingawaitwill still work (awaiting a non-Promise returns the value), but this behavioral change might be worth documenting for clarity.If these functions are internal-only, the current changeset is sufficient.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.changeset/fix-monorepo-workspace-detection.md around lines 1 - 5, Update the changeset to document that the functions scanForIntents and scanLibrary changed from async to synchronous signatures; explicitly state the new return types and note potential caller impact (e.g., awaiting a non-Promise is benign but callers should remove unnecessary async/await), and reference the exported symbols scanForIntents and scanLibrary so consumers can find and adapt their usage.packages/intent/src/utils.ts (1)
186-191: Consider edge cases in URL normalization.The function handles common cases well, but consider these edge cases:
- URLs ending with
.git.gitwould become.gitafter one replacement- SSH URLs like
git@github.com:org/repo.gitare not normalized toorg/repo- Non-GitHub URLs (GitLab, Bitbucket) retain their full path after
https://removalIf these edge cases are acceptable for the current use case (deriving repo identifiers), the implementation is fine. Otherwise, consider more robust URL parsing.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/intent/src/utils.ts` around lines 186 - 191, normalizeRepoUrl currently only strips a single leading git+ prefix, a single trailing ".git", and only matches "https://github.com/"; to handle the edge cases update normalizeRepoUrl to (1) remove repeated ".git" suffixes (e.g. trim all trailing ".git" occurrences), (2) convert SSH style URLs like "git@github.com:org/repo.git" into "org/repo" by detecting the "git@" pattern and replacing the "user@host:" prefix with host path, and (3) optionally generalize host stripping to remove "https?://<host>/" for non-GitHub hosts (or keep existing behavior if only GitHub is desired); update the function normalizeRepoUrl accordingly and add unit tests for inputs like "git+https://github.com/org/repo.git.git", "git@github.com:org/repo.git", and a non-GitHub https URL to validate the chosen behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In @.changeset/fix-monorepo-workspace-detection.md:
- Around line 1-5: Update the changeset to document that the functions
scanForIntents and scanLibrary changed from async to synchronous signatures;
explicitly state the new return types and note potential caller impact (e.g.,
awaiting a non-Promise is benign but callers should remove unnecessary
async/await), and reference the exported symbols scanForIntents and scanLibrary
so consumers can find and adapt their usage.
In `@packages/intent/src/utils.ts`:
- Around line 186-191: normalizeRepoUrl currently only strips a single leading
git+ prefix, a single trailing ".git", and only matches "https://github.com/";
to handle the edge cases update normalizeRepoUrl to (1) remove repeated ".git"
suffixes (e.g. trim all trailing ".git" occurrences), (2) convert SSH style URLs
like "git@github.com:org/repo.git" into "org/repo" by detecting the "git@"
pattern and replacing the "user@host:" prefix with host path, and (3) optionally
generalize host stripping to remove "https?://<host>/" for non-GitHub hosts (or
keep existing behavior if only GitHub is desired); update the function
normalizeRepoUrl accordingly and add unit tests for inputs like
"git+https://github.com/org/repo.git.git", "git@github.com:org/repo.git", and a
non-GitHub https URL to validate the chosen behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 639760bb-837c-4af4-9248-1033735b3f73
📒 Files selected for processing (14)
.changeset/fix-monorepo-workspace-detection.mdpackages/intent/meta/templates/workflows/validate-skills.ymlpackages/intent/src/cli.tspackages/intent/src/intent-library.tspackages/intent/src/library-scanner.tspackages/intent/src/scanner.tspackages/intent/src/setup.tspackages/intent/src/staleness.tspackages/intent/src/utils.tspackages/intent/tests/cli.test.tspackages/intent/tests/library-scanner.test.tspackages/intent/tests/scanner.test.tspackages/intent/tests/setup.test.tspackages/intent/tests/staleness.test.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/intent/tests/setup.test.ts (1)
255-282: Harden test teardown to avoid leaked temp dirs/mocks on assertion failures.Several tests clean up only at the end of the test body. If an assertion throws early, teardown is skipped, which can pollute subsequent tests:
- Lines 255–282:
rmSync(monoRoot, ...)at end, unguarded- Lines 343–384:
rmSync(monoRoot, ...)at end, unguarded- Lines 451–524:
logSpy.mockRestore()at end, unguarded- Lines 526–570:
logSpy.mockRestore()at end, unguardedWrap each test body in a
try/finallyblock to ensure cleanup always executes:♻️ Suggested pattern (try/finally guarded teardown)
it('treats workspace roots without package skills as monorepos', () => { const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {}) + try { - writeFileSync( - join(metaDir, 'templates', 'workflows', 'validate-skills.yml'), - 'for dir in {{WORKSPACE_SKILL_GLOBS}}; do\n echo "$dir"\ndone\n', - ) - // ... test setup/assertions ... - logSpy.mockRestore() + writeFileSync( + join(metaDir, 'templates', 'workflows', 'validate-skills.yml'), + 'for dir in {{WORKSPACE_SKILL_GLOBS}}; do\n echo "$dir"\ndone\n', + ) + // ... test setup/assertions ... + } finally { + logSpy.mockRestore() + } })it('skips !skills/_artifacts in pnpm monorepo packages (pnpm-workspace.yaml)', () => { const monoRoot = mkdtempSync(join(tmpdir(), 'pnpm-mono-')) + try { - const pkgDir = join(monoRoot, 'packages', 'my-lib') - mkdirSync(pkgDir, { recursive: true }) - // ... test setup/assertions ... - rmSync(monoRoot, { recursive: true, force: true }) + const pkgDir = join(monoRoot, 'packages', 'my-lib') + mkdirSync(pkgDir, { recursive: true }) + // ... test setup/assertions ... + } finally { + rmSync(monoRoot, { recursive: true, force: true }) + } })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/intent/tests/setup.test.ts` around lines 255 - 282, The tests leak temp dirs and spies when assertions throw because teardown calls (rmSync on monoRoot and logSpy.mockRestore()) are at the end of the test bodies; wrap the relevant test bodies that create monoRoot (where mkdtempSync is used) and those that set logSpy in a try/finally and move rmSync(monoRoot, { recursive: true, force: true }) and logSpy.mockRestore() into the finally block so cleanup always runs; specifically update the test cases that reference monoRoot/mkdtempSync and the tests that reference logSpy to use try { ... assertions ... } finally { rmSync(...)/logSpy.mockRestore() } to guarantee teardown even on failures.
🤖 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/intent/tests/setup.test.ts`:
- Around line 255-282: The tests leak temp dirs and spies when assertions throw
because teardown calls (rmSync on monoRoot and logSpy.mockRestore()) are at the
end of the test bodies; wrap the relevant test bodies that create monoRoot
(where mkdtempSync is used) and those that set logSpy in a try/finally and move
rmSync(monoRoot, { recursive: true, force: true }) and logSpy.mockRestore() into
the finally block so cleanup always runs; specifically update the test cases
that reference monoRoot/mkdtempSync and the tests that reference logSpy to use
try { ... assertions ... } finally { rmSync(...)/logSpy.mockRestore() } to
guarantee teardown even on failures.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 932e2c26-2f99-466c-8782-fae8c2e371ff
📒 Files selected for processing (1)
packages/intent/tests/setup.test.ts
🎯 Changes
Fixes #71.
This PR fixes the monorepo regressions reported against
@tanstack/intentand tightens workspace handling across setup, validation, and generated CI workflows.setup-github-actionsso monorepo roots are detected from actual workspace config, not just current skill-bearing packages.validate packages/<pkg>/skillsso packaging warnings are evaluated against the target package instead of the workspace root.!skills/_artifactswarnings for pnpm workspace packages.packages/*.✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit
Release Notes
Bug Fixes
New Features