From 00e340d40ede71d681a5dd8ddab0f618a3b47526 Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Mon, 16 Nov 2026 05:28:51 +0100 Subject: [PATCH] Only allow media kit uploads for approved games --- src/api.ts | 9 +++++++++ src/docs/command-groups/media-kit.ts | 3 ++- test/media-kit.test.ts | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/api.ts b/src/api.ts index 2b3ce9a..6845455 100644 --- a/src/api.ts +++ b/src/api.ts @@ -93,6 +93,15 @@ export function apiResponseError (status: number, body: unknown, headers: Header hint: 'This request was rejected without starting a test. Run `poki limits get` for current capacity. Reduce the recording batch if it can fit, wait for quota to reset or be released, or contact your account manager if the limit is zero. Do not automatically retry or cancel work to regain quota.' }) } + if (status === 409 && request.method === 'POST' && /^\/games\/[^/]+\/marketing_assets\/[^/]+$/.test(request.path) && firstErrorTitle === 'game must be approved') { + return new CliError(code, message, 4, { + status, + details: safeDetails, + retryable: false, + requestId: headers.get('x-request-id') ?? undefined, + hint: 'Media Kit uploads become available once your game is approved. Inspect approved with `poki games get GAME_ID` and wait for approval before uploading again.' + }) + } const method = request.method ?? 'GET' const retrySafe = method === 'GET' || request.retrySafe === true const transient = status === 408 || status === 429 || status >= 500 diff --git a/src/docs/command-groups/media-kit.ts b/src/docs/command-groups/media-kit.ts index a019032..6249305 100644 --- a/src/docs/command-groups/media-kit.ts +++ b/src/docs/command-groups/media-kit.ts @@ -23,10 +23,11 @@ export function addMediaKitCommandSpecs ({ add, apiAction, argument, downloadReq }) apiAction(['media-kit', 'upload'], 'Upload one or more files of one current asset type.', { method: 'MULTIPLE', path: [`POST ${collection}/:type`, `GET ${collection} (--wait only)`], contacts_api: true }, [edit, read], { options: [gameOption, option('--type', 'enum', 'Current asset type; run poki media-kit types for requirements.', { values: [...mediaKitUploadTypes], required: true }), option('--file', 'path', 'Readable nonempty file; repeat once per file, up to 50.', { repeatable: true, required: true }), ...uploadMutationOptions, ...waitOptions('Poll once per interval for all newly accepted IDs to become ready.')], - permission_logic: 'Uploading requires can_edit_owned_marketing_assets; polling additionally requires can_read_owned_marketing_assets.', + permission_logic: 'Uploading requires an approved game and can_edit_owned_marketing_assets; polling additionally requires can_read_owned_marketing_assets.', missing_input: '--type and --file', side_effects: ['Creates assets and starts asynchronous storage uploads. Accepted files remain created when other files fail.'], behavior: [ + 'Uploads require games.approved=true, including for admins. The server rejects unapproved games with 409 Conflict before processing files. Existing assets can still be read, downloaded, and deleted. Dry-run does not check game approval.', 'Uses repeated multipart file fields and streams file-backed blobs. Dry-run validates local files and describes the request without contacting the API.', 'Normalized success always returns a collection, including single-file uploads; raw output preserves the original singular or collection response.', 'Partial acceptance raises MEDIA_KIT_UPLOAD_PARTIAL_FAILURE (exit 4), with details.accepted, accepted_ids, failed [{filename, error}], and recovery commands. It returns immediately even when polling was requested. Do not replay the batch.', diff --git a/test/media-kit.test.ts b/test/media-kit.test.ts index fb09614..224ca0c 100644 --- a/test/media-kit.test.ts +++ b/test/media-kit.test.ts @@ -396,6 +396,11 @@ void test('Media Kit API rejections retain normal permission and unavailable-ass const unavailable = await runCli(scoped('download-url', 'a'), { env }) assert.equal(unavailable.code, 4) assert.equal(errorOf(unavailable).code, 'CONFLICT') + const approval = apiResponseError(409, { errors: [{ status: '409', code: 'conflict', title: 'game must be approved' }] }, new Headers(), { method: 'POST', path: '/games/g/marketing_assets/image_screenshot' }) + assert.equal(approval.code, 'CONFLICT') + assert.equal(approval.exitCode, 4) + assert.equal(approval.retryable, false) + assert.match(approval.hint ?? '', /once your game is approved/) }) for (const interrupt of ['signal', 'handler'] as const) {