|
| 1 | +import { describe, it, expect, beforeEach, afterEach } from 'vitest'; |
| 2 | +import { z } from 'zod'; |
| 3 | +import { resolveSelectedWorkflows } from '../workflow-selection.ts'; |
| 4 | +import type { WorkflowGroup } from '../../core/plugin-types.ts'; |
| 5 | + |
| 6 | +function makeWorkflow(name: string): WorkflowGroup { |
| 7 | + return { |
| 8 | + directoryName: name, |
| 9 | + workflow: { |
| 10 | + name, |
| 11 | + description: `${name} workflow`, |
| 12 | + }, |
| 13 | + tools: [ |
| 14 | + { |
| 15 | + name: `${name}-tool`, |
| 16 | + description: `${name} tool`, |
| 17 | + schema: { enabled: z.boolean().optional() }, |
| 18 | + async handler() { |
| 19 | + return { content: [] }; |
| 20 | + }, |
| 21 | + }, |
| 22 | + ], |
| 23 | + }; |
| 24 | +} |
| 25 | + |
| 26 | +function makeWorkflowMap(names: string[]): Map<string, WorkflowGroup> { |
| 27 | + const map = new Map<string, WorkflowGroup>(); |
| 28 | + for (const name of names) { |
| 29 | + map.set(name, makeWorkflow(name)); |
| 30 | + } |
| 31 | + return map; |
| 32 | +} |
| 33 | + |
| 34 | +describe('resolveSelectedWorkflows', () => { |
| 35 | + let originalDebug: string | undefined; |
| 36 | + |
| 37 | + beforeEach(() => { |
| 38 | + originalDebug = process.env.XCODEBUILDMCP_DEBUG; |
| 39 | + }); |
| 40 | + |
| 41 | + afterEach(() => { |
| 42 | + if (typeof originalDebug === 'undefined') { |
| 43 | + delete process.env.XCODEBUILDMCP_DEBUG; |
| 44 | + } else { |
| 45 | + process.env.XCODEBUILDMCP_DEBUG = originalDebug; |
| 46 | + } |
| 47 | + }); |
| 48 | + |
| 49 | + it('adds doctor when debug is enabled and selection list is provided', () => { |
| 50 | + process.env.XCODEBUILDMCP_DEBUG = 'true'; |
| 51 | + const workflows = makeWorkflowMap(['session-management', 'doctor', 'simulator']); |
| 52 | + |
| 53 | + const result = resolveSelectedWorkflows(workflows, ['simulator']); |
| 54 | + |
| 55 | + expect(result.selectedNames).toEqual(['session-management', 'doctor', 'simulator']); |
| 56 | + expect(result.selectedWorkflows.map((workflow) => workflow.directoryName)).toEqual([ |
| 57 | + 'session-management', |
| 58 | + 'doctor', |
| 59 | + 'simulator', |
| 60 | + ]); |
| 61 | + }); |
| 62 | + |
| 63 | + it('does not add doctor when debug is disabled', () => { |
| 64 | + process.env.XCODEBUILDMCP_DEBUG = 'false'; |
| 65 | + const workflows = makeWorkflowMap(['session-management', 'doctor', 'simulator']); |
| 66 | + |
| 67 | + const result = resolveSelectedWorkflows(workflows, ['simulator']); |
| 68 | + |
| 69 | + expect(result.selectedNames).toEqual(['session-management', 'simulator']); |
| 70 | + expect(result.selectedWorkflows.map((workflow) => workflow.directoryName)).toEqual([ |
| 71 | + 'session-management', |
| 72 | + 'simulator', |
| 73 | + ]); |
| 74 | + }); |
| 75 | + |
| 76 | + it('returns all workflows when no selection list is provided', () => { |
| 77 | + process.env.XCODEBUILDMCP_DEBUG = 'true'; |
| 78 | + const workflows = makeWorkflowMap(['session-management', 'doctor', 'simulator']); |
| 79 | + |
| 80 | + const result = resolveSelectedWorkflows(workflows, []); |
| 81 | + |
| 82 | + expect(result.selectedNames).toBeNull(); |
| 83 | + expect(result.selectedWorkflows.map((workflow) => workflow.directoryName)).toEqual([ |
| 84 | + 'session-management', |
| 85 | + 'doctor', |
| 86 | + 'simulator', |
| 87 | + ]); |
| 88 | + }); |
| 89 | +}); |
0 commit comments