|
| 1 | +import { buildSession, RunPhase } from '../../../lib/wizard-session.js'; |
| 2 | +import { WizardReadiness } from '../../../lib/health-checks/readiness.js'; |
| 3 | +import { FLOWS, Flow, Screen } from '../flows.js'; |
| 4 | + |
| 5 | +function getEntry(flow: Flow, screen: Screen) { |
| 6 | + const entry = FLOWS[flow].find((candidate) => candidate.screen === screen); |
| 7 | + if (!entry) { |
| 8 | + throw new Error(`Missing flow entry for ${flow}:${screen}`); |
| 9 | + } |
| 10 | + return entry; |
| 11 | +} |
| 12 | + |
| 13 | +describe('FLOWS', () => { |
| 14 | + describe('Wizard setup predicate', () => { |
| 15 | + it('hides setup when there are no setup questions', () => { |
| 16 | + const session = buildSession({}); |
| 17 | + const entry = getEntry(Flow.Wizard, Screen.Setup); |
| 18 | + |
| 19 | + expect(entry.show?.(session)).toBe(false); |
| 20 | + expect(entry.isComplete?.(session)).toBe(true); |
| 21 | + }); |
| 22 | + |
| 23 | + it('shows setup when framework questions are missing answers', () => { |
| 24 | + const session = buildSession({}); |
| 25 | + const entry = getEntry(Flow.Wizard, Screen.Setup); |
| 26 | + |
| 27 | + session.frameworkConfig = { |
| 28 | + metadata: { |
| 29 | + setup: { |
| 30 | + questions: [{ key: 'packageManager' }, { key: 'srcDir' }], |
| 31 | + }, |
| 32 | + }, |
| 33 | + } as never; |
| 34 | + session.frameworkContext = { packageManager: 'pnpm' }; |
| 35 | + |
| 36 | + expect(entry.show?.(session)).toBe(true); |
| 37 | + expect(entry.isComplete?.(session)).toBe(false); |
| 38 | + }); |
| 39 | + |
| 40 | + it('marks setup complete once all required answers are present', () => { |
| 41 | + const session = buildSession({}); |
| 42 | + const entry = getEntry(Flow.Wizard, Screen.Setup); |
| 43 | + |
| 44 | + session.frameworkConfig = { |
| 45 | + metadata: { |
| 46 | + setup: { |
| 47 | + questions: [{ key: 'packageManager' }, { key: 'srcDir' }], |
| 48 | + }, |
| 49 | + }, |
| 50 | + } as never; |
| 51 | + session.frameworkContext = { |
| 52 | + packageManager: 'pnpm', |
| 53 | + srcDir: 'src', |
| 54 | + }; |
| 55 | + |
| 56 | + expect(entry.show?.(session)).toBe(false); |
| 57 | + expect(entry.isComplete?.(session)).toBe(true); |
| 58 | + }); |
| 59 | + }); |
| 60 | + |
| 61 | + describe('Wizard health-check predicate', () => { |
| 62 | + it('stays incomplete before readiness exists', () => { |
| 63 | + const session = buildSession({}); |
| 64 | + const entry = getEntry(Flow.Wizard, Screen.HealthCheck); |
| 65 | + |
| 66 | + expect(entry.isComplete?.(session)).toBe(false); |
| 67 | + }); |
| 68 | + |
| 69 | + it('stays incomplete for blocking readiness until outage is dismissed', () => { |
| 70 | + const session = buildSession({}); |
| 71 | + const entry = getEntry(Flow.Wizard, Screen.HealthCheck); |
| 72 | + |
| 73 | + session.readinessResult = { |
| 74 | + decision: WizardReadiness.No, |
| 75 | + health: {} as never, |
| 76 | + reasons: ['Anthropic: down'], |
| 77 | + }; |
| 78 | + |
| 79 | + expect(entry.isComplete?.(session)).toBe(false); |
| 80 | + |
| 81 | + session.outageDismissed = true; |
| 82 | + |
| 83 | + expect(entry.isComplete?.(session)).toBe(true); |
| 84 | + }); |
| 85 | + |
| 86 | + it('completes immediately for non-blocking readiness', () => { |
| 87 | + const session = buildSession({}); |
| 88 | + const entry = getEntry(Flow.Wizard, Screen.HealthCheck); |
| 89 | + |
| 90 | + session.readinessResult = { |
| 91 | + decision: WizardReadiness.YesWithWarnings, |
| 92 | + health: {} as never, |
| 93 | + reasons: [], |
| 94 | + }; |
| 95 | + |
| 96 | + expect(entry.isComplete?.(session)).toBe(true); |
| 97 | + }); |
| 98 | + }); |
| 99 | + |
| 100 | + describe('Wizard run predicate', () => { |
| 101 | + it('stays incomplete while run is idle or running', () => { |
| 102 | + const session = buildSession({}); |
| 103 | + const entry = getEntry(Flow.Wizard, Screen.Run); |
| 104 | + |
| 105 | + session.runPhase = RunPhase.Idle; |
| 106 | + expect(entry.isComplete?.(session)).toBe(false); |
| 107 | + |
| 108 | + session.runPhase = RunPhase.Running; |
| 109 | + expect(entry.isComplete?.(session)).toBe(false); |
| 110 | + }); |
| 111 | + |
| 112 | + it('completes when run finishes or errors', () => { |
| 113 | + const session = buildSession({}); |
| 114 | + const entry = getEntry(Flow.Wizard, Screen.Run); |
| 115 | + |
| 116 | + session.runPhase = RunPhase.Completed; |
| 117 | + expect(entry.isComplete?.(session)).toBe(true); |
| 118 | + |
| 119 | + session.runPhase = RunPhase.Error; |
| 120 | + expect(entry.isComplete?.(session)).toBe(true); |
| 121 | + }); |
| 122 | + }); |
| 123 | + |
| 124 | + describe('MCP flow predicates', () => { |
| 125 | + it('uses mcpComplete for McpAdd', () => { |
| 126 | + const session = buildSession({}); |
| 127 | + const entry = getEntry(Flow.McpAdd, Screen.McpAdd); |
| 128 | + |
| 129 | + expect(entry.isComplete?.(session)).toBe(false); |
| 130 | + |
| 131 | + session.mcpComplete = true; |
| 132 | + |
| 133 | + expect(entry.isComplete?.(session)).toBe(true); |
| 134 | + }); |
| 135 | + |
| 136 | + it('uses mcpComplete for McpRemove', () => { |
| 137 | + const session = buildSession({}); |
| 138 | + const entry = getEntry(Flow.McpRemove, Screen.McpRemove); |
| 139 | + |
| 140 | + expect(entry.isComplete?.(session)).toBe(false); |
| 141 | + |
| 142 | + session.mcpComplete = true; |
| 143 | + |
| 144 | + expect(entry.isComplete?.(session)).toBe(true); |
| 145 | + }); |
| 146 | + }); |
| 147 | +}); |
0 commit comments