-
-
Notifications
You must be signed in to change notification settings - Fork 195
feat(session): Add namespaced session defaults profiles #215
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
cameroncooke
wants to merge
1
commit into
main
Choose a base branch
from
codex/feat-session-defaults-profiles
base: main
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
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
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,9 @@ | ||
| id: session_use_defaults_profile | ||
| module: mcp/tools/session-management/session_use_defaults_profile | ||
| names: | ||
| mcp: session_use_defaults_profile | ||
| cli: use-defaults-profile | ||
| description: Select the active session defaults profile for multi-target workflows. | ||
| annotations: | ||
| title: Use Session Defaults Profile | ||
| readOnlyHint: true | ||
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
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
97 changes: 97 additions & 0 deletions
97
src/mcp/tools/session-management/__tests__/session_use_defaults_profile.test.ts
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,97 @@ | ||
| import { describe, it, expect, beforeEach } from 'vitest'; | ||
| import path from 'node:path'; | ||
| import { parse as parseYaml } from 'yaml'; | ||
| import { __resetConfigStoreForTests, initConfigStore } from '../../../../utils/config-store.ts'; | ||
| import { createMockFileSystemExecutor } from '../../../../test-utils/mock-executors.ts'; | ||
| import { sessionStore } from '../../../../utils/session-store.ts'; | ||
| import { | ||
| handler, | ||
| schema, | ||
| sessionUseDefaultsProfileLogic, | ||
| } from '../session_use_defaults_profile.ts'; | ||
|
|
||
| describe('session-use-defaults-profile tool', () => { | ||
| beforeEach(() => { | ||
| __resetConfigStoreForTests(); | ||
| sessionStore.clear(); | ||
| }); | ||
|
|
||
| const cwd = '/repo'; | ||
| const configPath = path.join(cwd, '.xcodebuildmcp', 'config.yaml'); | ||
|
|
||
| it('exports handler and schema', () => { | ||
| expect(typeof handler).toBe('function'); | ||
| expect(schema).toBeDefined(); | ||
| expect(typeof schema).toBe('object'); | ||
| }); | ||
|
|
||
| it('activates a named profile', async () => { | ||
| const result = await sessionUseDefaultsProfileLogic({ profile: 'ios' }); | ||
| expect(result.isError).toBe(false); | ||
| expect(sessionStore.getActiveProfile()).toBe('ios'); | ||
| expect(sessionStore.listProfiles()).toContain('ios'); | ||
| }); | ||
|
|
||
| it('switches back to global profile', async () => { | ||
| sessionStore.setActiveProfile('watch'); | ||
| const result = await sessionUseDefaultsProfileLogic({ global: true }); | ||
| expect(result.isError).toBe(false); | ||
| expect(sessionStore.getActiveProfile()).toBeNull(); | ||
| }); | ||
|
|
||
| it('returns error when both global and profile are provided', async () => { | ||
| const result = await sessionUseDefaultsProfileLogic({ global: true, profile: 'ios' }); | ||
| expect(result.isError).toBe(true); | ||
| expect(result.content[0].text).toContain('either global=true or profile'); | ||
| }); | ||
|
|
||
| it('returns error when profile is missing and create=false', async () => { | ||
| const result = await sessionUseDefaultsProfileLogic({ profile: 'macos', create: false }); | ||
| expect(result.isError).toBe(true); | ||
| expect(result.content[0].text).toContain('does not exist'); | ||
| }); | ||
|
|
||
| it('returns status for empty args', async () => { | ||
| const result = await sessionUseDefaultsProfileLogic({}); | ||
| expect(result.isError).toBe(false); | ||
| expect(result.content[0].text).toContain('Active defaults profile: global'); | ||
| }); | ||
|
|
||
| it('persists active profile when persist=true', async () => { | ||
| const writes: { path: string; content: string }[] = []; | ||
| const fs = createMockFileSystemExecutor({ | ||
| existsSync: (targetPath: string) => targetPath === configPath, | ||
| readFile: async () => ['schemaVersion: 1', ''].join('\n'), | ||
| writeFile: async (targetPath: string, content: string) => { | ||
| writes.push({ path: targetPath, content }); | ||
| }, | ||
| }); | ||
| await initConfigStore({ cwd, fs }); | ||
|
|
||
| const result = await sessionUseDefaultsProfileLogic({ profile: 'ios', persist: true }); | ||
| expect(result.isError).toBe(false); | ||
| expect(result.content[0].text).toContain('Persisted active profile selection'); | ||
| expect(writes).toHaveLength(1); | ||
| const parsed = parseYaml(writes[0].content) as { activeSessionDefaultsProfile?: string }; | ||
| expect(parsed.activeSessionDefaultsProfile).toBe('ios'); | ||
| }); | ||
|
|
||
| it('removes active profile from config when persisting global selection', async () => { | ||
| const writes: { path: string; content: string }[] = []; | ||
| const yaml = ['schemaVersion: 1', 'activeSessionDefaultsProfile: "ios"', ''].join('\n'); | ||
| const fs = createMockFileSystemExecutor({ | ||
| existsSync: (targetPath: string) => targetPath === configPath, | ||
| readFile: async () => yaml, | ||
| writeFile: async (targetPath: string, content: string) => { | ||
| writes.push({ path: targetPath, content }); | ||
| }, | ||
| }); | ||
| await initConfigStore({ cwd, fs }); | ||
|
|
||
| const result = await sessionUseDefaultsProfileLogic({ global: true, persist: true }); | ||
| expect(result.isError).toBe(false); | ||
| expect(writes).toHaveLength(1); | ||
| const parsed = parseYaml(writes[0].content) as { activeSessionDefaultsProfile?: string }; | ||
| expect(parsed.activeSessionDefaultsProfile).toBeUndefined(); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
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.
State-modifying tool incorrectly annotated as read-only
High Severity
The
session_use_defaults_profilemanifest declaresreadOnlyHint: true, but the tool mutates session state viasessionStore.setActiveProfileand can write to the config file on disk whenpersist: true. The sibling toolssession_set_defaultsandsession_clear_defaultscorrectly usedestructiveHint: truefor the same reason. MCP clients rely onreadOnlyHintto decide whether a tool can be auto-approved without user confirmation, so this annotation could allow silent, unconfirmed state and filesystem changes.