|
1 | 1 | import type { Command } from 'clipanion'; |
2 | 2 | import type { ReporterOptions } from '@wpkernel/core/reporter'; |
3 | 3 | import type { InitWorkflowOptions } from '../init/workflow'; |
| 4 | +import type { ReadinessRegistry } from '../../dx'; |
4 | 5 | import { WPKernelError } from '@wpkernel/core/error'; |
5 | 6 | import { createCommandReporterHarness } from '@wpkernel/test-utils/cli'; |
6 | 7 | import { makeWorkspaceMock } from '../../../tests/workspace.test-support'; |
@@ -100,6 +101,60 @@ describe('init command runtime helpers', () => { |
100 | 101 | expect(() => runtime.readiness.plan([])).not.toThrow(); |
101 | 102 | }); |
102 | 103 |
|
| 104 | + it('includes helpers scoped only to create when deriving default readiness keys', () => { |
| 105 | + const workspace = makeWorkspaceMock({ root: '/tmp/create-only' }); |
| 106 | + const reporters = createCommandReporterHarness(); |
| 107 | + const reporter = reporters.create(); |
| 108 | + |
| 109 | + const buildWorkspace = jest.fn(() => workspace); |
| 110 | + const buildReporter = jest.fn(() => reporter); |
| 111 | + const runWorkflow = jest.fn(); |
| 112 | + |
| 113 | + const describe = jest.fn(() => [ |
| 114 | + { |
| 115 | + key: 'init-only', |
| 116 | + metadata: { label: 'Init helper', scopes: ['init'] }, |
| 117 | + }, |
| 118 | + { |
| 119 | + key: 'create-only', |
| 120 | + metadata: { label: 'Create helper', scopes: ['create'] }, |
| 121 | + }, |
| 122 | + { |
| 123 | + key: 'generate-only', |
| 124 | + metadata: { label: 'Generate helper', scopes: ['generate'] }, |
| 125 | + }, |
| 126 | + { |
| 127 | + key: 'global-helper', |
| 128 | + metadata: { label: 'Global helper' }, |
| 129 | + }, |
| 130 | + ]); |
| 131 | + |
| 132 | + const plan = jest.fn((keys: readonly string[]) => ({ |
| 133 | + keys: [...keys], |
| 134 | + run: jest.fn(async () => ({ outcomes: [] })), |
| 135 | + })); |
| 136 | + |
| 137 | + const runtime = createInitCommandRuntime( |
| 138 | + { |
| 139 | + buildWorkspace, |
| 140 | + buildReporter, |
| 141 | + runWorkflow, |
| 142 | + buildReadinessRegistry: () => |
| 143 | + ({ describe, plan }) as unknown as ReadinessRegistry, |
| 144 | + }, |
| 145 | + { |
| 146 | + reporterNamespace: 'wpk.cli.test', |
| 147 | + workspaceRoot: workspace.root, |
| 148 | + } |
| 149 | + ); |
| 150 | + |
| 151 | + expect(runtime.readiness.defaultKeys).toEqual([ |
| 152 | + 'init-only', |
| 153 | + 'create-only', |
| 154 | + 'global-helper', |
| 155 | + ]); |
| 156 | + }); |
| 157 | + |
103 | 158 | it('formats wpk errors consistently for init workflow consumers', () => { |
104 | 159 | const error = new WPKernelError('ValidationError', { |
105 | 160 | message: 'Failed to write files.', |
|
0 commit comments