Skip to content

feat(profiles): add configuration profiles infrastructure#60

Merged
polaz merged 18 commits intomainfrom
feat/54-profiles-infrastructure
Jan 20, 2026
Merged

feat(profiles): add configuration profiles infrastructure#60
polaz merged 18 commits intomainfrom
feat/54-profiles-infrastructure

Conversation

@polaz
Copy link
Copy Markdown
Member

@polaz polaz commented Jan 20, 2026

Summary

Closes #54

Add support for named configuration profiles and presets that enable multi-GitLab workflows and role-based access patterns.

Key Changes

  • Profile/Preset separation for security:
    • Profile = full config with host/auth (user-defined only)
    • Preset = settings only, NO host/auth (built-in, safe for testing)
  • ProfileLoader class with caching and validation
  • applyProfile() function to map settings to environment variables
  • CLI integration: --profile <name> argument and GITLAB_PROFILE env var
  • Built-in presets: readonly, developer, admin
  • 67 unit tests covering all components

Security

Built-in presets NEVER contain host or auth to prevent accidental requests to wrong GitLab instances during testing.

Files

File Purpose
src/profiles/types.ts Zod schemas for Profile/Preset
src/profiles/loader.ts ProfileLoader class
src/profiles/applicator.ts Apply profile to env vars
src/profiles/index.ts Module exports
src/profiles/builtin/*.yaml Built-in presets
src/main.ts CLI --profile support

Test plan

  • Unit tests pass (67 new tests)
  • Full test suite passes (1900 tests)
  • Lint passes
  • Build passes

Add support for named configuration profiles and presets:
- Profile: full config with host/auth (user-defined in ~/.config/gitlab-mcp/profiles.yaml)
- Preset: settings only, NO host/auth (built-in safe for testing)

Features:
- ProfileLoader class with caching and validation
- applyProfile() to map profile settings to env vars
- --profile CLI argument and GITLAB_PROFILE env var support
- Built-in presets: readonly, developer, admin
- Zod schemas for type-safe validation
- 67 unit tests covering loader, applicator, types

Security: Built-in presets NEVER contain host/auth to prevent
accidental requests to wrong GitLab instances during testing.
Copilot AI review requested due to automatic review settings January 20, 2026 08:47
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 20, 2026

📊 Test Coverage Report

Overall Coverage: 87.67%

Coverage Details

Metric Percentage
Statements 87.67%
Branches 80.55%
Functions 73.2%
Lines 88.18%

Coverage Report: View detailed coverage report

This report was generated automatically from your PR changes.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 20, 2026

Codecov Report

❌ Patch coverage is 86.93182% with 46 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/main.ts 43.33% 15 Missing and 2 partials ⚠️
src/profiles/index.ts 0.00% 11 Missing ⚠️
src/profiles/applicator.ts 93.15% 1 Missing and 9 partials ⚠️
src/profiles/loader.ts 94.87% 4 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces configuration profiles infrastructure to enable multi-GitLab workflows and role-based access patterns. The implementation separates full profiles (with host/auth) from presets (settings only) for security purposes.

Changes:

  • Added Profile/Preset type system with Zod schemas for validation
  • Implemented ProfileLoader class for loading and caching profiles from YAML files
  • Created profile applicator to map settings to environment variables
  • Integrated CLI support with --profile argument and GITLAB_PROFILE env var
  • Added three built-in presets: readonly, developer, and admin
  • Included 67 comprehensive unit tests

Reviewed changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/profiles/types.ts Zod schemas and TypeScript types for Profile and Preset configurations
src/profiles/loader.ts ProfileLoader class with caching, validation, and YAML parsing
src/profiles/applicator.ts Functions to apply profile settings to environment variables
src/profiles/index.ts Module exports for the profiles subsystem
src/profiles/builtin/*.yaml Three built-in preset configurations (readonly, developer, admin)
src/main.ts CLI integration for --profile argument and profile loading
tests/unit/profiles/*.test.ts Comprehensive unit tests (67 tests total)
tests/unit/main.test.ts Updated tests to reflect new main() function structure
tests/unit/main.entry.test.ts Updated entry point tests with profile mocking
package.json Added yaml dependency
yarn.lock Lockfile update for yaml package

polaz added 2 commits January 20, 2026 10:54
- Add applyPreset() function for runtime built-in preset application
- Add .strict() to PresetSchema to reject unknown fields (security)
- Validate --profile CLI argument is not another flag
- Validate OAuth client_secret_env environment variable
- Validate cookie auth file path exists
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 18 changed files in this pull request and generated 1 comment.

- Add build:copy-assets script to copy YAML presets to dist
- Update getBuiltinDir() to use __dirname for npm package compatibility
- Add Node.js CommonJS globals to ESLint config
- Add 45+ tests for applyPreset, loadAndApplyProfile, loadAndApplyPreset
- Add validation tests for OAuth, cookie auth, and TLS paths
- Add profile handling tests for main.ts CLI integration

Closes #54
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 20 out of 21 changed files in this pull request and generated 2 comments.

…rning

- Replace Unix shell commands with Node.js one-liner for cross-platform compatibility
- Add warning when multiple --profile flags are provided
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 22 changed files in this pull request and generated 4 comments.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 22 changed files in this pull request and generated 3 comments.

Add environment variable mappings for:
- allowed_groups -> GITLAB_ALLOWED_GROUP_IDS
- allowed_tools -> GITLAB_ALLOWED_TOOLS (in applyProfile)
- default_namespace -> GITLAB_DEFAULT_NAMESPACE

These fields were defined in the Profile type but not applied
to environment variables when the profile was loaded.
@polaz polaz requested a review from Copilot January 20, 2026 10:44
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 22 changed files in this pull request and generated 5 comments.

- Improve denied_actions validation to check both tool and action parts
  are non-empty (fixes ':action', 'tool:', ':' edge cases)
- Fix getProfileNameFromEnv JSDoc comment accuracy
- Move multiple --profile warning outside loop with count
- Add tests for denied_actions edge cases
@polaz
Copy link
Copy Markdown
Member Author

polaz commented Jan 20, 2026

Fixed in cf7fa57:

  • JSDoc comment updated to accurately describe the function
  • denied_actions validation now checks both tool and action parts are non-empty
  • Multiple --profile warning moved outside loop with count

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 22 changed files in this pull request and generated 3 comments.

Add tests for:
- allowed_groups, allowed_tools, default_namespace env var mapping
- validation warnings logging path
- getProfileNameFromEnv standalone function

Coverage improved:
- applicator.ts: 94.44% -> 99.3%
- loader.ts: 95.56% -> 96.2%
- Overall profiles: 91.07% -> 93.53%
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 22 changed files in this pull request and generated 1 comment.

polaz added 2 commits January 20, 2026 16:18
Add tests for:
- Alphabetical sorting within same profile category
- Config cache hit when loading multiple profiles

Coverage improved:
- loader.ts: 96.2% -> 97.46%
- Overall profiles: 93.53% -> 94.15%
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 22 changed files in this pull request and generated 2 comments.

Warn users when denied_actions entries contain extra whitespace
around the colon (e.g., "tool : action"). The validation still
passes but logs a warning indicating the normalized form.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 22 changed files in this pull request and generated 1 comment.

Reduces code duplication between validateProfile and validatePreset
by extracting shared denied_actions validation logic into a private
helper method.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 22 changed files in this pull request and generated no new comments.

@polaz polaz merged commit 171b625 into main Jan 20, 2026
23 checks passed
@polaz polaz deleted the feat/54-profiles-infrastructure branch January 20, 2026 15:41
sw-release-bot bot pushed a commit that referenced this pull request Jan 20, 2026
## [6.13.0](v6.12.0...v6.13.0) (2026-01-20)

### Features

* **profiles:** add configuration profiles infrastructure ([#60](#60)) ([171b625](171b625)), closes [#54](#54) [#54](#54)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Profiles infrastructure - base support for named configuration profiles

2 participants