feat(schema): add dynamic action filtering with schema transformation pipeline#44
feat(schema): add dynamic action filtering with schema transformation pipeline#44
Conversation
… pipeline
- Add GITLAB_DENIED_ACTIONS config for filtering specific actions from CQRS tools
- Add GITLAB_ACTION_{TOOL}_{ACTION} for action description overrides
- Add GITLAB_PARAM_{TOOL}_{PARAM} for parameter description overrides
- Add GITLAB_SCHEMA_FORMAT config (flat|discriminated) for schema output format
- Create schema-utils.ts with transformation pipeline:
1. Filter denied actions (remove oneOf branches)
2. Apply description overrides (to oneOf or flat)
3. Conditional flatten based on config
- Migrate manage_milestone to discriminated union schema (pilot)
- Add runtime validation for denied actions in handlers
- Add comprehensive unit tests for config parsing and schema transformations
Closes #32
📊 Test Coverage ReportOverall Coverage: 86.44% Coverage Details
Coverage Report: View detailed coverage report
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
…n schema - Convert BrowseMilestonesSchema from flat z.object().refine() to z.discriminatedUnion() - Define separate schemas for each action: list, get, issues, merge_requests, burndown - Remove assertDefined calls - TypeScript narrowing handles type safety - Update integration tests with type narrowing for action-specific properties
There was a problem hiding this comment.
Pull request overview
This PR introduces a comprehensive schema transformation pipeline for CQRS tools, enabling fine-grained control over available actions and reducing AI context token usage. The implementation migrates manage_milestone to a discriminated union schema as a pilot, demonstrating benefits of TypeScript type narrowing and automatic parameter removal when actions are denied.
Changes:
- New configuration options for filtering and customizing CQRS tools (
GITLAB_DENIED_ACTIONS,GITLAB_ACTION_*,GITLAB_PARAM_*,GITLAB_SCHEMA_FORMAT) - Schema transformation pipeline in
schema-utils.tswith filtering, flattening, and override capabilities - Migration of
manage_milestonefrom flat schema to discriminated union with runtime validation
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/utils/schema-utils.ts | New utility implementing schema transformation pipeline (filter, flatten, apply overrides) |
| src/config.ts | Added parsing for denied actions, action/param description overrides, and helper functions |
| src/entities/milestones/schema.ts | Migrated manage_milestone from flat schema to discriminated union |
| src/entities/milestones/registry.ts | Added runtime validation for denied actions in both milestone tools |
| src/registry-manager.ts | Integrated schema transformation pipeline into tool registration |
| tests/unit/utils/schema-utils.test.ts | Comprehensive unit tests for all transformation functions (469 lines) |
| tests/unit/config.test.ts | Added tests for new config parsing functions (280+ new lines) |
| tests/unit/entities/milestones/registry.test.ts | Added runtime validation tests for denied actions |
| tests/integration/schemas/milestones.test.ts | Updated type narrowing checks for discriminated union |
| tests/unit/RegistryManager.test.ts | Updated mocks for new config functions and entities |
| README.md | Added comprehensive documentation for new features with examples |
…ated union schema - Convert BrowseLabelsSchema from flat z.object().refine() to z.discriminatedUnion() - Convert ManageLabelSchema from flat z.object().refine() to z.discriminatedUnion() - Add runtime validation for denied actions in handlers - Update integration tests with type narrowing for action-specific properties
- Convert BrowseVariablesSchema to z.discriminatedUnion with list/get actions - Convert ManageVariableSchema to z.discriminatedUnion with create/update/delete actions - Add runtime validation for denied actions via isActionDenied() - Update unit tests with proper type narrowing for action-specific properties - Update integration tests with type narrowing
- Convert BrowseWikiSchema to z.discriminatedUnion with list/get actions - Convert ManageWikiSchema to z.discriminatedUnion with create/update/delete actions - Add runtime validation for denied actions via isActionDenied() - Remove assertDefined calls since types are now properly narrowed - Update integration tests with proper type narrowing
- Convert BrowsePipelinesSchema to z.discriminatedUnion with 6 actions: list, get, jobs, triggers, job, logs - Convert ManagePipelineSchema to z.discriminatedUnion with create/retry/cancel actions - Convert ManagePipelineJobSchema to z.discriminatedUnion with play/retry/cancel actions - Add runtime validation for denied actions via isActionDenied() - Remove assertDefined calls since types are now properly narrowed
Migrate all entity schemas from z.object().refine() pattern to z.discriminatedUnion() for type-safe action handling and better AI client compatibility. Changes: - core: browse_commits, browse_events, browse_projects, browse_namespaces, manage_project schemas now use discriminatedUnion - files: browse_files, manage_files schemas migrated - mrs: browse_merge_requests, browse_mr_discussions, manage_merge_request, manage_mr_discussions schemas with action-specific field validation - snippets: browse_snippets, manage_snippet schemas migrated - webhooks: list_webhooks, manage_webhook schemas migrated - workitems: list_work_items, manage_work_item schemas migrated - integrations: manage_integration schema migrated Schema improvements: - Added .passthrough() to preserve unknown fields for validation - Added superRefine validation for action-specific fields - Updated tests for requiredId string coercion behavior - Fixed type narrowing in test assertions Closes #32
Summary
GITLAB_DENIED_ACTIONSconfig for filtering specific actions from CQRS toolsGITLAB_ACTION_{TOOL}_{ACTION}for action description overridesGITLAB_PARAM_{TOOL}_{PARAM}for parameter description overridesGITLAB_SCHEMA_FORMATconfig (flat|discriminated) for schema output formatschema-utils.tswith transformation pipelinemanage_milestoneto discriminated union schema (pilot)Schema Pipeline
When a tool is registered, the schema goes through a transformation pipeline:
GITLAB_DENIED_ACTIONSGITLAB_ACTION_*andGITLAB_PARAM_*overridesoneOfto flat schema whenGITLAB_SCHEMA_FORMAT=flat(default)Test plan
Closes #32