From ddfd6aac98890114d3a9ad8379472f4a3a88386d Mon Sep 17 00:00:00 2001 From: Erik Dubbelboer Date: Fri, 20 Nov 2026 03:57:32 +0100 Subject: [PATCH] List available game engines and guide developers through rejected updates Add `poki games engines` to list the exact engine names currently used by non-deleted games across teams. Point developers to the command from the `--engine` help, the annotations field reference, and the 403 error for an unknown engine. The API validates the engine in the existing PATCH request, so updates still take one request and dry runs stay offline. See: https://github.com/poki/mothership/pull/6297 --- src/api.ts | 3 +++ src/commands/games.ts | 14 +++++++++--- src/developer-permissions.ts | 1 + src/docs/command-groups/games.ts | 9 +++++++- src/docs/resources.ts | 6 +++-- test/resources.test.ts | 38 ++++++++++++++++++++++++++++++++ 6 files changed, 65 insertions(+), 6 deletions(-) diff --git a/src/api.ts b/src/api.ts index 6845455..7ad90ae 100644 --- a/src/api.ts +++ b/src/api.ts @@ -106,12 +106,15 @@ export function apiResponseError (status: number, body: unknown, headers: Header const retrySafe = method === 'GET' || request.retrySafe === true const transient = status === 408 || status === 429 || status >= 500 const redirect = status >= 300 && status < 400 + const unknownGameEngine = method === 'PATCH' && /^\/games\/[^/]+$/.test(request.path) && + status === 403 && firstErrorCode === 'forbidden' && firstErrorTitle === 'only admins can add new game engines; select an existing engine' return new CliError(code, message, status === 401 && !payloadValidationFailed ? 3 : status >= 500 ? 5 : 4, { status, ...(Object.keys(safeDetails).length === 0 ? {} : { details: safeDetails }), retryable: transient && retrySafe, requestId: headers.get('x-request-id') ?? headers.get('x-cloud-trace-context') ?? undefined, retryAfter: headers.get('retry-after') ?? undefined, + ...(unknownGameEngine ? { hint: 'Run `poki games engines` and use an exact name from the list in your update.' } : {}), ...(status === 403 && firstErrorCode === 'content-moderation-required' ? { hint: 'This operation requires content moderation to pass for an unapproved game. Inspect content_moderation_status with `poki games get GAME_ID`. Pending, fail, defer, and missing status block restricted operations. Wait for moderation or address the review feedback before retrying; ordinary version uploads remain available.' } : status === 400 && firstErrorCode === 'invalid-lobby-filter' && /^\/games\/[^/]+\/netlib\/lobbies$/.test(request.path) diff --git a/src/commands/games.ts b/src/commands/games.ts index 8a35769..cb99dae 100644 --- a/src/commands/games.ts +++ b/src/commands/games.ts @@ -1,9 +1,10 @@ import type { Argv } from 'yargs' import { ApiClient } from '../api' -import { gamesDocumentation } from '../docs/resources' +import { gameEngineInput, gamesDocumentation } from '../docs/resources' import { CliError, inputError } from '../errors' import { requireChanges } from '../input' +import { isRecord } from '../json' import { jsonApiDocument, unreadableFields, unreadableFieldsReport } from '../jsonapi' import { listCapabilities } from '../list-capabilities' import { getProjectGameId, projectConfigError } from '../project' @@ -130,7 +131,7 @@ function withGameFieldOptions (yargs: Argv): Argv { .option('archived', { describe: 'Archive the game; use --no-archived to restore it', type: 'boolean' }) .option('favorite', { describe: 'Favorite the game for the current user; use --no-favorite to remove it', type: 'boolean' }) .option('engine', { - describe: 'Developer-editable engine annotation: 2-32 lowercase letters, digits, or hyphens; the server preserves every other annotation', + describe: gameEngineInput, type: 'string' }) .option('privacy-policy-url', { @@ -178,6 +179,13 @@ export function registerGameCommands (yargs: Argv, api: ApiClient): Argv { const result = await listResources(api, '/games', argv, listCapabilities.games, [], argv.team === undefined ? [] : [['team_id', argv.team]]) renderList(result, argv, 'games') }) + .command('engines', 'List existing game engine names', engines => withRequestOptions(engines), async argv => { + const { body } = await api.request({ path: '/_annotations/engine', accept: 'application/json', timeoutMs: requestTimeout(argv) }) + if (!isRecord(body) || !Array.isArray(body.engine) || !body.engine.every(name => typeof name === 'string')) { + throw new CliError('INVALID_API_RESPONSE', 'Expected a list of engine names from the Poki API.', 5) + } + render({ data: body.engine, meta: { total: body.engine.length } }, argv) + }) .command('get [game-id]', 'Get one game; defaults to the configured project game', get => gameFlag(withOutputOptions(get)) .positional('game-id', { describe: 'Poki for Developers game ID; defaults to project game_id', type: 'string' }), async argv => { const gameID = selectedGame(argv) @@ -236,5 +244,5 @@ export function registerGameCommands (yargs: Argv, api: ApiClient): Argv { const body = jsonApiDocument('games', data, gameID) await renderMutation(api, argv, { method: 'PATCH', path, body, expected: { type: 'games', id: gameID }, behavior: { sideEffects: ['May create audit or notification activity.'] } }) }) - .demandCommand(1, 'Choose games list, games get, games readiness, or games update.'), () => {}) + .demandCommand(1, 'Choose games list, games engines, games get, games readiness, or games update.'), () => {}) } diff --git a/src/developer-permissions.ts b/src/developer-permissions.ts index 4058d04..4ab1e01 100644 --- a/src/developer-permissions.ts +++ b/src/developer-permissions.ts @@ -23,6 +23,7 @@ export const developerPermissionCatalog = [ { code: 'can_edit_owned_reviews', description: 'Update or close reviews for a game belonging to the current user or team.' }, { code: 'can_edit_owned_versions', description: 'Update, archive, or restore versions belonging to the current user or team.' }, { code: 'can_query_clickhouse', description: 'Run analytics queries; backend table and row scoping still applies.' }, + { code: 'can_read_distinct_engine_annotations', description: 'List the existing game engine names.' }, { code: 'can_read_owned_game_change_requests', description: 'List or read game-change requests for a game belonging to the current user or team.' }, { code: 'can_read_owned_game_events', description: 'List event definitions and funnels for a game belonging to the current user or team.' }, { code: 'can_read_owned_games', description: 'List or read games belonging to the current user or team.' }, diff --git a/src/docs/command-groups/games.ts b/src/docs/command-groups/games.ts index 0b226fe..af9a95b 100644 --- a/src/docs/command-groups/games.ts +++ b/src/docs/command-groups/games.ts @@ -1,4 +1,5 @@ import { listCapabilities } from '../../list-capabilities' +import { gameEngineInput } from '../resources' import type { CommandSpecBuilder } from './types' export function addGameCommandSpecs ({ add, apiAction, argument, categoryNameDiscovery, dataOption, example, formatOption, gameOption, group, listOptionsFor, mutationOptions, option, outputOptions, requestOptions }: CommandSpecBuilder): void { @@ -6,7 +7,7 @@ export function addGameCommandSpecs ({ add, apiAction, argument, categoryNameDis const gameFieldOptions = [ option('--archived', 'boolean', 'Archive the game; --no-archived restores it. Archiving is blocked during a requested or running Web Fit test.'), option('--favorite', 'boolean', 'Favorite for the current user only; --no-favorite removes it.'), - option('--engine', 'string', 'Developer-editable engine annotation: 2-32 lowercase letters, digits, or hyphens; the server preserves every other annotation.'), + option('--engine', 'string', gameEngineInput), option('--privacy-policy-url', 'string', 'Public privacy-policy URL with a supported network scheme and no whitespace.'), option('--suggested-description', 'string', 'Developer-suggested public game description, at most 65535 UTF-8 bytes.'), option('--suggested-category', 'string', `Suggested Poki content-category name; combined comma-separated value at most 65535 UTF-8 bytes; repeatable. ${categoryNameDiscovery}`, { repeatable: true }) @@ -14,6 +15,12 @@ export function addGameCommandSpecs ({ add, apiAction, argument, categoryNameDis const gameDataShapeBehavior = '--data is a flat attribute object, not a JSON:API envelope, and replaces all field flags. Run poki games fields for the editable field reference.' apiAction(['games', 'list'], 'List games for one team with bounded pagination.', { method: 'GET', path: '/games', contacts_api: true }, ['can_read_owned_games'], { options: [option('--team', 'string', 'Select an exact team ID; without it the API uses the authenticated user\'s first team.'), ...listOptionsFor(listCapabilities.games)], scope: '--team or the authenticated user\'s first team', behavior: ['This endpoint supports --team, sorting, and pagination. It does not support the generic --filter option or combine all of a user\'s teams.'], examples: [example('poki games list --team TEAM_ID --page 2 --page-size 50', 'Read one bounded page; meta.has_next reports whether more pages exist.'), example('poki games list --all --fields id,title,public_version --format csv', 'Select three developer-visible fields and export the complete list as CSV; a single page is refused unless it proves it is the last one.')] }) apiAction(['games', 'get'], 'Get one game; positional ID defaults to project game_id.', { method: 'GET', path: '/games/:gameID', contacts_api: true }, ['can_read_owned_games'], { arguments: [argument('game-id', 'Game ID; defaults to project game_id.', false)], options: [option('--game', 'string', 'Game ID; alternative to the positional game-id.'), ...outputOptions] }) + apiAction(['games', 'engines'], 'List existing game engine names for games update.', { method: 'GET', path: '/_annotations/engine', contacts_api: true }, ['can_read_distinct_engine_annotations'], { + options: requestOptions, + scope: 'All non-deleted games across teams.', + output: { shape: '{data: string[], meta: {total}}' }, + examples: [example('poki games engines --format json', 'Look up the exact name to pass to poki games update --engine.')] + }) add({ path: ['games', 'readiness'], summary: 'Report visible CLI and backend readiness for activation, Playtest requests, and Player Fit tests.', diff --git a/src/docs/resources.ts b/src/docs/resources.ts index 551332f..ff7f3e5 100644 --- a/src/docs/resources.ts +++ b/src/docs/resources.ts @@ -1,6 +1,8 @@ import { mediaKitAssetTypes } from '../media-kit' import { RESOURCE_API_TIME_ZONE } from '../timezones' +export const gameEngineInput = 'For a non-empty engine, select an exact name from poki games engines (2-32 lowercase letters, digits, or hyphens).' + export type RelationshipResourceApiType = 'games' | 'game_versions' | @@ -48,7 +50,7 @@ const supplementalDetails: Record', 'read-only', 'Traffic allocation entries containing track, version_id, and weight. versions activate supports games with at most one existing track and replaces the allocation with one public track.'), diff --git a/test/resources.test.ts b/test/resources.test.ts index 97e42c4..17d29f8 100644 --- a/test/resources.test.ts +++ b/test/resources.test.ts @@ -6,6 +6,44 @@ import test from 'node:test' import { apiHarness, authEnvironment, jsonApi, listen, requestBody, runCli, temporaryDirectory } from './helpers' +void test('games engines reads the live list and rejects malformed names', async t => { + let body: unknown + const { env } = await apiHarness(t, (req, res) => { + assert.equal(req.method, 'GET') + assert.equal(req.url, '/_annotations/engine') + assert.equal(req.headers.authorization, 'Bearer test-token') + assert.equal(req.headers.accept, 'application/json') + res.setHeader('Content-Type', 'application/json') + res.end(JSON.stringify(body)) + }, 'game-engines') + for (const engines of [['phaser-3', 'studio-engine'], []]) { + body = { engine: engines, internal: 'hidden' } + const result = await runCli(['games', 'engines', '--format', 'json'], { env }) + assert.equal(result.code, 0, result.stderr) + assert.deepEqual(JSON.parse(result.stdout), { data: engines, meta: { total: engines.length } }) + } + for (body of [{ engines: [] }, { engine: ['unity', null] }]) { + const result = await runCli(['games', 'engines', '--format', 'json'], { env }) + assert.equal(result.code, 5, result.stderr) + assert.equal(JSON.parse(result.stderr).error.code, 'INVALID_API_RESPONSE') + } +}) + +void test('games update points rejected engine names to the live list', async t => { + const title = 'only admins can add new game engines; select an existing engine' + const { env } = await apiHarness(t, (req, res) => { + assert.equal(req.method, 'PATCH') + assert.equal(req.url, '/games/g') + jsonApi(res, { errors: [{ status: '403', code: 'forbidden', title }] }, 403) + }, 'game-engine-update') + const result = await runCli(['games', 'update', 'g', '--engine', 'new-engine', '--format', 'json'], { env }) + assert.equal(result.code, 4, result.stderr) + const { error } = JSON.parse(result.stderr) + assert.equal(error.message, title) + assert.equal(error.retryable, false) + assert.match(error.hint, /poki games engines/) +}) + void test('resource lists default to operational summaries and support full and selected views', async t => { const { env } = await apiHarness(t, (req, res) => { jsonApi(res, {