-
Notifications
You must be signed in to change notification settings - Fork 462
feat(init): default VS Code chat sessions to Squad #1485
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
Open
tamirdresher
wants to merge
2
commits into
dev
Choose a base branch
from
tamirdresher-microsoft-super-dollop
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,5 @@ | ||
| --- | ||
| "@bradygaster/squad-cli": minor | ||
| --- | ||
|
|
||
| `squad init` now defaults to writing `"chat.newSession.defaultMode": "Squad"` into `.vscode/settings.json`, so new VS Code chat sessions open in Squad mode automatically. The edit is JSONC-aware (preserves comments, trailing commas, and existing keys), idempotent, and skipped when the key already exists. Pass `--no-vscode-default` to opt out entirely. |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,205 @@ | ||
| /** | ||
| * Tests for VS Code default chat session mode injection (feat(init): #vscode-default). | ||
| * | ||
| * Verifies that `runInit()` writes `"chat.newSession.defaultMode": "Squad"` to | ||
| * `.vscode/settings.json` with JSONC-safe, idempotent, and opt-out semantics. | ||
| * | ||
| * Cases: | ||
| * 1. Missing .vscode/settings.json (and dir) → created with the key. | ||
| * 2. Existing file without the key → key added, existing settings preserved. | ||
| * 3. Existing key with a different value → left untouched. | ||
| * 4. File has comments and trailing commas → both preserved after edit. | ||
| * 5. --no-vscode-default passed → file not created or modified. | ||
| * 6. Idempotent rerun → second run produces no further diff. | ||
| * 7. isGlobal:true passed → .vscode/settings.json not created (global skips vscode). | ||
| * 8. Malformed file → init does not crash; warning shown; file unchanged. | ||
| */ | ||
|
|
||
| import { describe, it, expect, beforeEach, afterEach } from 'vitest'; | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
| import os from 'node:os'; | ||
| import { execFileSync } from 'node:child_process'; | ||
|
|
||
| import { runInit } from '../packages/squad-cli/src/cli/core/init.js'; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Helpers | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| function makeTempRepo(prefix = 'squad-vscode-test-'): string { | ||
| const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix)); | ||
| execFileSync('git', ['init', '--quiet', '-b', 'main'], { cwd: dir, stdio: 'pipe' }); | ||
| execFileSync('git', ['config', 'user.email', 'test@example.com'], { cwd: dir, stdio: 'pipe' }); | ||
| execFileSync('git', ['config', 'user.name', 'Squad Test'], { cwd: dir, stdio: 'pipe' }); | ||
| // Seed a commit so HEAD exists | ||
| fs.writeFileSync(path.join(dir, 'README.md'), '# test\n'); | ||
| execFileSync('git', ['add', 'README.md'], { cwd: dir, stdio: 'pipe' }); | ||
| execFileSync('git', ['commit', '-q', '-m', 'init'], { cwd: dir, stdio: 'pipe' }); | ||
| return dir; | ||
| } | ||
|
|
||
| function cleanDir(dir: string): void { | ||
| try { fs.rmSync(dir, { recursive: true, force: true }); } catch { /* ok */ } | ||
| } | ||
|
|
||
| function settingsPath(repoDir: string): string { | ||
| return path.join(repoDir, '.vscode', 'settings.json'); | ||
| } | ||
|
|
||
| const INIT_OPTS = { includeWorkflows: false }; | ||
| const KEY = 'chat.newSession.defaultMode'; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Tests | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| describe('runInit — VS Code default chat session mode', () => { | ||
| let tmpDir: string; | ||
| let homeTmpDir: string; | ||
|
|
||
| beforeEach(() => { | ||
| tmpDir = makeTempRepo(); | ||
| homeTmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'squad-vscode-home-')); | ||
| process.env.SQUAD_HOME_DIR_OVERRIDE = homeTmpDir; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| delete process.env.SQUAD_HOME_DIR_OVERRIDE; | ||
| cleanDir(tmpDir); | ||
| cleanDir(homeTmpDir); | ||
| }); | ||
|
|
||
| // ── Case 1: missing .vscode/settings.json ───────────────────────────── | ||
| it('creates .vscode/settings.json when the file does not exist', async () => { | ||
| await runInit(tmpDir, INIT_OPTS); | ||
|
|
||
| const sp = settingsPath(tmpDir); | ||
| expect(fs.existsSync(sp), '.vscode/settings.json should be created').toBe(true); | ||
|
|
||
| const content = fs.readFileSync(sp, 'utf-8'); | ||
| const parsed = JSON.parse(content); | ||
| expect(parsed[KEY]).toBe('Squad'); | ||
| }); | ||
|
|
||
| // ── Case 2: existing file without the key ───────────────────────────── | ||
| it('adds the key to an existing settings.json that lacks it', async () => { | ||
| const vsDir = path.join(tmpDir, '.vscode'); | ||
| fs.mkdirSync(vsDir, { recursive: true }); | ||
| fs.writeFileSync(path.join(vsDir, 'settings.json'), JSON.stringify({ | ||
| 'editor.tabSize': 2, | ||
| 'files.autoSave': 'off', | ||
| }, null, 2) + '\n', 'utf-8'); | ||
|
|
||
| await runInit(tmpDir, INIT_OPTS); | ||
|
|
||
| const sp = settingsPath(tmpDir); | ||
| const content = fs.readFileSync(sp, 'utf-8'); | ||
| const parsed = JSON.parse(content); | ||
|
|
||
| expect(parsed[KEY]).toBe('Squad'); | ||
| expect(parsed['editor.tabSize']).toBe(2); | ||
| expect(parsed['files.autoSave']).toBe('off'); | ||
| }); | ||
|
|
||
| // ── Case 3: key already set to a different value ─────────────────────── | ||
| it('does not overwrite an existing chat.newSession.defaultMode value', async () => { | ||
| const vsDir = path.join(tmpDir, '.vscode'); | ||
| fs.mkdirSync(vsDir, { recursive: true }); | ||
| fs.writeFileSync(path.join(vsDir, 'settings.json'), JSON.stringify({ | ||
| [KEY]: 'Custom', | ||
| }, null, 2) + '\n', 'utf-8'); | ||
|
|
||
| await runInit(tmpDir, INIT_OPTS); | ||
|
|
||
| const sp = settingsPath(tmpDir); | ||
| const content = fs.readFileSync(sp, 'utf-8'); | ||
| const parsed = JSON.parse(content); | ||
| expect(parsed[KEY]).toBe('Custom'); | ||
| }); | ||
|
|
||
| // ── Case 4: file has JSONC comments and trailing commas ──────────────── | ||
| it('preserves comments and trailing commas in settings.json', async () => { | ||
| const vsDir = path.join(tmpDir, '.vscode'); | ||
| fs.mkdirSync(vsDir, { recursive: true }); | ||
| const jsoncContent = `{ | ||
| // My VS Code settings | ||
| "editor.tabSize": 2, // two spaces | ||
| "editor.formatOnSave": true, | ||
| }\n`; | ||
| fs.writeFileSync(path.join(vsDir, 'settings.json'), jsoncContent, 'utf-8'); | ||
|
|
||
| await runInit(tmpDir, INIT_OPTS); | ||
|
|
||
| const sp = settingsPath(tmpDir); | ||
| const updatedContent = fs.readFileSync(sp, 'utf-8'); | ||
|
|
||
| // Comments must be preserved | ||
| expect(updatedContent).toContain('// My VS Code settings'); | ||
| expect(updatedContent).toContain('// two spaces'); | ||
|
|
||
| // The new key must be present | ||
| expect(updatedContent).toContain(`"${KEY}"`); | ||
| expect(updatedContent).toContain('"Squad"'); | ||
|
|
||
| // Original keys must still be present | ||
| expect(updatedContent).toContain('"editor.tabSize"'); | ||
| expect(updatedContent).toContain('"editor.formatOnSave"'); | ||
| }); | ||
|
|
||
| // ── Case 5: --no-vscode-default passed ──────────────────────────────── | ||
| it('does not create .vscode/settings.json when includeVscodeDefault is false', async () => { | ||
| await runInit(tmpDir, { ...INIT_OPTS, includeVscodeDefault: false }); | ||
|
|
||
| const sp = settingsPath(tmpDir); | ||
| expect(fs.existsSync(sp), '.vscode/settings.json must NOT be created').toBe(false); | ||
| }); | ||
|
|
||
| it('does not modify an existing settings.json when includeVscodeDefault is false', async () => { | ||
| const vsDir = path.join(tmpDir, '.vscode'); | ||
| fs.mkdirSync(vsDir, { recursive: true }); | ||
| const original = JSON.stringify({ 'editor.tabSize': 4 }, null, 2) + '\n'; | ||
| fs.writeFileSync(path.join(vsDir, 'settings.json'), original, 'utf-8'); | ||
|
|
||
| await runInit(tmpDir, { ...INIT_OPTS, includeVscodeDefault: false }); | ||
|
|
||
| const sp = settingsPath(tmpDir); | ||
| expect(fs.readFileSync(sp, 'utf-8')).toBe(original); | ||
| }); | ||
|
|
||
| // ── Case 6: idempotent rerun ─────────────────────────────────────────── | ||
| it('produces no further diff when run a second time', async () => { | ||
| await runInit(tmpDir, INIT_OPTS); | ||
|
|
||
| const sp = settingsPath(tmpDir); | ||
| const afterFirst = fs.readFileSync(sp, 'utf-8'); | ||
|
|
||
| await runInit(tmpDir, INIT_OPTS); | ||
|
|
||
| const afterSecond = fs.readFileSync(sp, 'utf-8'); | ||
| expect(afterSecond).toBe(afterFirst); | ||
| }); | ||
|
|
||
| // ── Case 7 (regression): isGlobal:true skips .vscode entirely ──────── | ||
| it('does not create .vscode/settings.json when isGlobal is true', async () => { | ||
| await runInit(tmpDir, { ...INIT_OPTS, isGlobal: true }); | ||
|
|
||
| const sp = settingsPath(tmpDir); | ||
| expect(fs.existsSync(sp), '.vscode/settings.json must NOT be created for global init').toBe(false); | ||
| }); | ||
|
|
||
| // ── Case 8: malformed / unparseable settings.json ───────────────────── | ||
| it('does not crash or corrupt a malformed settings.json', async () => { | ||
| const vsDir = path.join(tmpDir, '.vscode'); | ||
| fs.mkdirSync(vsDir, { recursive: true }); | ||
| const malformed = '{ this is not valid json at all !!! '; | ||
| fs.writeFileSync(path.join(vsDir, 'settings.json'), malformed, 'utf-8'); | ||
|
|
||
| // Should not throw | ||
| await expect(runInit(tmpDir, INIT_OPTS)).resolves.not.toThrow(); | ||
|
|
||
| // File content must be untouched | ||
| const sp = settingsPath(tmpDir); | ||
| expect(fs.readFileSync(sp, 'utf-8')).toBe(malformed); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.