Repository navigation
fix(cli): wire SQUAD_TEAM_ROOT into squad resolution for subprocess compatibility (#734) #763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| "@bradygaster/squad-cli": patch | ||
| --- | ||
|
|
||
| fix(cli): wire --team-root / SQUAD_TEAM_ROOT into squad resolution for nap, status, and cost commands (#734) | ||
|
|
||
| Commands that resolve .squad/ now respect the SQUAD_TEAM_ROOT env var (set by --team-root flag), | ||
| fixing subprocess invocations (e.g. Copilot CLI bang commands) where process.cwd() differs from | ||
| the interactive shell. Also improves the nap error message to show the searched directory. |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /** | ||
| * Nap subprocess / --team-root resolution tests (#734) | ||
| * | ||
| * Verifies that the nap command works correctly when invoked from a | ||
| * subprocess with a different working directory, as happens with | ||
| * Copilot CLI bang commands (!squad nap) on Windows. | ||
| * | ||
| * The fix: getSquadStartDir() respects SQUAD_TEAM_ROOT env var, | ||
| * falling back to process.cwd() when unset. | ||
| * | ||
| * @see packages/squad-cli/src/cli-entry.ts — getSquadStartDir() | ||
| * @see https://github.com/bradygaster/squad/issues/734 | ||
| */ | ||
|
|
||
| import { describe, it, expect, afterEach, beforeEach } from 'vitest'; | ||
| import { | ||
| mkdtempSync, | ||
| writeFileSync, | ||
| mkdirSync, | ||
| rmSync, | ||
| } from 'node:fs'; | ||
| import { join } from 'node:path'; | ||
| import { tmpdir } from 'node:os'; | ||
|
|
||
| import { runNap } from '../../packages/squad-cli/src/cli/core/nap.js'; | ||
|
|
||
| // ============================================================================ | ||
| // Helpers | ||
| // ============================================================================ | ||
|
|
||
| const tmpDirs: string[] = []; | ||
|
|
||
| function createTestSquadDir(): string { | ||
| const tmpDir = mkdtempSync(join(tmpdir(), 'squad-nap-subprocess-')); | ||
| tmpDirs.push(tmpDir); | ||
| const squadDir = join(tmpDir, '.squad'); | ||
| mkdirSync(join(squadDir, 'agents', 'edie'), { recursive: true }); | ||
| mkdirSync(join(squadDir, 'decisions', 'inbox'), { recursive: true }); | ||
| mkdirSync(join(squadDir, 'orchestration-log'), { recursive: true }); | ||
| writeFileSync(join(squadDir, 'team.md'), '# Team\n'); | ||
| writeFileSync(join(squadDir, 'routing.md'), '# Routing\n'); | ||
| writeFileSync(join(squadDir, 'decisions.md'), '# Decisions\n'); | ||
| writeFileSync( | ||
| join(squadDir, 'agents', 'edie', 'history.md'), | ||
| '## Core Context\n\nTest agent.\n', | ||
| ); | ||
| return squadDir; | ||
| } | ||
|
|
||
| // ============================================================================ | ||
| // Tests | ||
| // ============================================================================ | ||
|
|
||
| describe('nap: subprocess / --team-root resolution (#734)', () => { | ||
| const savedTeamRoot = process.env['SQUAD_TEAM_ROOT']; | ||
|
|
||
| beforeEach(() => { | ||
| delete process.env['SQUAD_TEAM_ROOT']; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| // Restore env | ||
| if (savedTeamRoot !== undefined) { | ||
| process.env['SQUAD_TEAM_ROOT'] = savedTeamRoot; | ||
| } else { | ||
| delete process.env['SQUAD_TEAM_ROOT']; | ||
| } | ||
| // Clean up temp dirs | ||
| for (const dir of tmpDirs) { | ||
| rmSync(dir, { recursive: true, force: true }); | ||
| } | ||
| tmpDirs.length = 0; | ||
| }); | ||
|
|
||
| it('runNap succeeds with explicit squadDir from a different working directory', async () => { | ||
| const squadDir = createTestSquadDir(); | ||
| const differentCwd = mkdtempSync(join(tmpdir(), 'squad-nap-other-cwd-')); | ||
| tmpDirs.push(differentCwd); | ||
| const previousCwd = process.cwd(); | ||
|
|
||
| try { | ||
| // This simulates the key scenario from #734: nap is called with a | ||
| // squadDir resolved from SQUAD_TEAM_ROOT while the current working | ||
| // directory points somewhere else. | ||
| process.chdir(differentCwd); | ||
|
|
||
| const result = await runNap({ squadDir, dryRun: true }); | ||
|
|
||
| expect(result).toBeDefined(); | ||
| expect(result.actions).toBeDefined(); | ||
| expect(result.before).toBeDefined(); | ||
| expect(result.after).toBeDefined(); | ||
| } finally { | ||
| process.chdir(previousCwd); | ||
| } | ||
| }); | ||
|
|
||
| it('runNap returns empty result when squadDir does not exist', async () => { | ||
| const nonExistent = join(tmpdir(), 'squad-nap-nonexistent-dir'); | ||
| const result = await runNap({ squadDir: nonExistent, dryRun: true }); | ||
|
|
||
| expect(result.actions).toHaveLength(0); | ||
| expect(result.before.totalFiles).toBe(0); | ||
| expect(result.after.totalFiles).toBe(0); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍