Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/void/src/cli/platform-lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
PlatformCloudflareApiError,
PlatformRuntimeTokenEmailPermissionError,
verifyPlatformRuntimeTokenPermissions,
PlatformCloudflarePrerequisiteError,
} from './platform-cloudflare.ts';
import type { CloudflareAccount } from './platform-cloudflare.ts';
import { platformCredentialHelp } from './platform-credential-label.ts';
Expand Down Expand Up @@ -392,6 +393,18 @@ export async function runPlatformLifecycleCommand(commandArgs: PlatformArgs): Pr
) {
throw new Error('platform: The installation belongs to a different Cloudflare account.');
}
// Fail before the domain questions when Workers for Platforms is off. Planning
// repeats this read and reports permission denials together, so only the
// missing-product error stops here.
try {
await withPlatformProgress('Checking Workers for Platforms', () =>
client.listDispatchNamespaces(accountId),
);
} catch (error) {
if (error instanceof PlatformCloudflarePrerequisiteError) {
throw error;
}
}
const recorded = existing?.deployment;
if (
existing &&
Expand Down
1 change: 1 addition & 0 deletions packages/void/test/unit/platform-install-prompts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ beforeEach(() => {
{ id: 'account', name: 'Account' },
]);
vi.spyOn(PlatformCloudflareClient.prototype, 'listHyperdriveConfigs').mockResolvedValue([]);
vi.spyOn(PlatformCloudflareClient.prototype, 'listDispatchNamespaces').mockResolvedValue([]);
mocks.text.mockImplementation(async ({ defaultValue }) => defaultValue ?? '');
mocks.select.mockImplementation(async ({ message, options }) =>
message === 'How should Void set up Hyperdrive?' ||
Expand Down
36 changes: 36 additions & 0 deletions packages/void/test/unit/platform-setup-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { parsePlatformArgs } from '../../src/cli/platform-args.ts';
import {
PlatformCloudflareApiError,
PlatformCloudflareClient,
PlatformCloudflarePrerequisiteError,
verifyPlatformRuntimeTokenEmailPermissions,
} from '../../src/cli/platform-cloudflare.ts';
import { formatPlatformCredentialDenials } from '../../src/cli/platform-credential-label.ts';
Expand Down Expand Up @@ -179,6 +180,7 @@ beforeEach(() => {
{ id: 'account', name: 'Account' },
]);
vi.spyOn(PlatformCloudflareClient.prototype, 'listHyperdriveConfigs').mockResolvedValue([]);
vi.spyOn(PlatformCloudflareClient.prototype, 'listDispatchNamespaces').mockResolvedValue([]);
mocks.confirm.mockResolvedValue(true);
mocks.spinner.mockReturnValue(mocks.progress);
mocks.select.mockImplementation(async ({ message, options }) =>
Expand Down Expand Up @@ -393,6 +395,40 @@ function accessManagementPlan() {
return [...args, '--login-methods', 'cloudflare-access', '--access-protection'];
}

describe('early Workers for Platforms check', () => {
it('stops right after the account is chosen when Workers for Platforms is off', async () => {
const listNamespaces = vi.mocked(PlatformCloudflareClient.prototype.listDispatchNamespaces);
listNamespaces.mockRejectedValue(
new PlatformCloudflarePrerequisiteError(
'Cloudflare Workers for Platforms requires a paid subscription for this account (code 10121).',
new PlatformCloudflareApiError(
'denied',
403,
'/accounts/account/workers/dispatch/namespaces',
),
),
);

await expect(
runPlatformLifecycleCommand(
parsePlatformArgs(['install', '--name', 'test-setup', '--account', 'account']),
),
).rejects.toThrow('Workers for Platforms requires a paid subscription');

expect(listNamespaces).toHaveBeenCalledWith('account');
expect(mocks.progress.start).toHaveBeenLastCalledWith('Checking Workers for Platforms');
const [namespaceRead] = listNamespaces.mock.invocationCallOrder;
expect(mocks.progress.start.mock.invocationCallOrder.at(-1)).toBeLessThan(namespaceRead);
expect(mocks.progress.clear.mock.invocationCallOrder.at(-1)).toBeGreaterThan(namespaceRead);
expect(mocks.select).not.toHaveBeenCalledWith(
expect.objectContaining({ message: 'Where should your apps live?' }),
);
expect(mocks.plan).not.toHaveBeenCalled();
expect(listSavedPlatformInstallPlans()).toEqual([]);
expect(listInstallationManifests()).toEqual([]);
});
});

describe('platform credential onboarding', () => {
it('shows discovery progress around remote reads without covering authentication', async () => {
const steps = vi.spyOn(log, 'step').mockImplementation(() => {});
Expand Down