Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 92c110b

Browse files
committed
Phase 9: include create readiness helpers
1 parent b208beb commit 92c110b

File tree

2 files changed

+64
-5
lines changed

2 files changed

+64
-5
lines changed

packages/cli/src/commands/__tests__/init.runtime.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Command } from 'clipanion';
22
import type { ReporterOptions } from '@wpkernel/core/reporter';
33
import type { InitWorkflowOptions } from '../init/workflow';
4+
import type { ReadinessRegistry } from '../../dx';
45
import { WPKernelError } from '@wpkernel/core/error';
56
import { createCommandReporterHarness } from '@wpkernel/test-utils/cli';
67
import { makeWorkspaceMock } from '../../../tests/workspace.test-support';
@@ -100,6 +101,60 @@ describe('init command runtime helpers', () => {
100101
expect(() => runtime.readiness.plan([])).not.toThrow();
101102
});
102103

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+
103158
it('formats wpk errors consistently for init workflow consumers', () => {
104159
const error = new WPKernelError('ValidationError', {
105160
message: 'Failed to write files.',

packages/cli/src/commands/init/command-runtime.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,20 @@ export interface InitCommandReadinessRuntime {
7272
) => Promise<ReadinessRunResult>;
7373
}
7474

75-
function helperIncludesScope(
76-
helper: ReadinessHelperDescriptor,
77-
scope: string
75+
const INIT_COMMAND_DEFAULT_SCOPES: ReadonlySet<string> = new Set([
76+
'init',
77+
'create',
78+
]);
79+
80+
function helperMatchesInitCommandDefaultScopes(
81+
helper: ReadinessHelperDescriptor
7882
): boolean {
7983
const scopes = helper.metadata.scopes;
8084
if (!scopes || scopes.length === 0) {
8185
return true;
8286
}
8387

84-
return scopes.includes(scope);
88+
return scopes.some((scope) => INIT_COMMAND_DEFAULT_SCOPES.has(scope));
8589
}
8690

8791
export function createInitCommandRuntime(
@@ -137,7 +141,7 @@ export function createInitCommandRuntime(
137141

138142
const helperDescriptors = readinessRegistry.describe();
139143
const defaultKeys = helperDescriptors
140-
.filter((helper) => helperIncludesScope(helper, 'init'))
144+
.filter(helperMatchesInitCommandDefaultScopes)
141145
.map((helper) => helper.key);
142146

143147
const readinessRuntime: InitCommandReadinessRuntime = {

0 commit comments

Comments
 (0)