Skip to content

actors search: --pricing-model and --sort-by use options: instead of choices:, so they are never validated #1322

Description

@l2ysho

Problem

src/commands/actors/search.ts declares two enum flags with an options: key:

'sort-by': Flags.string({
    description: 'Sort order for the results.',
    options: ['relevance', 'popularity', 'newest', 'lastUpdate'],
    default: 'relevance',
}),
'pricing-model': Flags.string({
    description: 'Filter by pricing model.',
    options: ['FREE', 'FLAT_PRICE_PER_MONTH', 'PRICE_PER_DATASET_ITEM', 'PAY_PER_EVENT'],
}),

The flag framework only reads choicessrc/lib/command-framework/flags.ts:115 is the sole consumer. options is silently ignored.

TypeScript doesn't catch it: stringFlag takes options: T & { choices?: Choices } with T inferred from the literal, so the excess property passes.

Impact

  1. No validation. --pricing-model BOGUS skips the APIFY_INVALID_CHOICE check at src/lib/command-framework/apify-command.ts:593 and goes straight to the API.
  2. Help and docs hide the allowed values. src/lib/command-framework/help/CommandHelp.ts:276 renders <option> and appends an <options: …> line only when choices is set.
  3. Flag types are string instead of the literal union, so nothing downstream is type-checked.

Current generated docs (docs/reference.md:717):

--pricing-model=<value>  Filter by pricing model.
--sort-by=<value>        Sort order for the results.

What a correct choices: flag renders (docs/reference.md:1314):

--format=<option>  The format of the returned output. By
                   default, it is set to 'json'.
                   <options: json|jsonl|csv|html|rss|xml|xlsx>

Reproduce

apify actors search "scraper" --pricing-model BOGUS

Expected: Invalid choice listing the four pricing models. Actual: the value is forwarded to GET /v2/store.

Fix

Rename options:choices: in both flags, then run pnpm run update-docs and commit the regenerated docs/.

Values match the API (store-get), so no list changes needed.

Follow-up (optional)

Make the framework reject the mistake instead of swallowing it — tighten StringFlagOptions so an unknown key fails to compile, or add options?: never as a cheap trap. Nothing today stops the next person from writing options: again.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working.t-buildersIssues owned by the Builders team.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions