Skip to content

[BUG]: Flags.duration in @salesforce/sf-plugins-core ignores min/max bounds of 0, so --wait=-5 is accepted #3689

Open

Description

@trackoor

Before You Submit

  • I'm using the latest version of Salesforce CLI
  • I've searched the existing issues
  • I've run sf doctor to diagnose common issues

Related Issue

No response

Command

sf org resume scratch

Org Type

Not applicable

Did this work before?

No, this is a new bug

Last Working Version

No response

Summary

In @salesforce/sf-plugins-core (src/flags/duration.ts), validate() checks min and max with truthiness (if (min && max && ...), else if (min && ...), else if (max && ...)), so a bound of 0 is ignored. Commands that declare Flags.duration({ unit: 'minutes', min: 0 }), including sf org resume scratch, sf org resume sandbox, and sf apex run test, accept negative values such as --wait=-5 instead of failing flag validation. max: 0 is ignored the same way, and { min: 0, max: 10 } falls through to errors.DurationBoundsMax instead of errors.DurationBounds when input exceeds max.

Repository to Reproduce

No response

Steps to reproduce

No DX project or authenticated org is needed because the bug happens during flag parsing in @salesforce/sf-plugins-core.

  1. Run a CLI command whose --wait flag sets min: 0 with a negative duration:
npx @salesforce/cli@2.158.7 org resume scratch --use-most-recent --wait=-5

Compare with a duration flag that sets min: 1:

npx @salesforce/cli@2.158.7 apex run test --target-org test@example.com --poll-interval=-5
  1. Or run directly against @salesforce/sf-plugins-core@13.0.9 (repro.mjs with "type": "module"):
// npm i @salesforce/sf-plugins-core@13.0.9 @oclif/core@5.1.12
import { Flags } from '@salesforce/sf-plugins-core';
import { Parser } from '@oclif/core';

const run = async (cfg, arg) => {
  try {
    const out = await Parser.parse([arg], { flags: { wait: Flags.duration(cfg) } });
    return `accepted: ${out.flags.wait.toString()}`;
  } catch (err) {
    return `rejected: ${err.message.replace(/\s+/g, ' ').trim()}`;
  }
};

console.log('min: 1, --wait=-5          =>', await run({ unit: 'minutes', min: 1 }, '--wait=-5'));
console.log('min: 0, --wait=-5          =>', await run({ unit: 'minutes', min: 0 }, '--wait=-5'));
console.log('min: 0, max: 10, --wait=-5 =>', await run({ unit: 'minutes', min: 0, max: 10 }, '--wait=-5'));
console.log('min: 0, max: 10, --wait=15 =>', await run({ unit: 'minutes', min: 0, max: 10 }, '--wait=15'));
console.log('max: 0, --wait=5           =>', await run({ unit: 'minutes', max: 0 }, '--wait=5'));

Expected Result

  • sf org resume scratch --use-most-recent --wait=-5 fails flag parsing with DurationBoundsMinError (The value must be at least 0.).
  • In Flags.duration, min: 0 rejects negative values with errors.DurationBoundsMin (or errors.DurationBounds when max is also set), and max: 0 rejects positive values with errors.DurationBoundsMax (or errors.DurationBounds when min is also set).

Actual Result

  • sf org resume scratch --use-most-recent --wait=-5 accepts --wait=-5 (Duration.minutes(-5)) during this.parse() and proceeds into run(), failing later only with NoRecentJobIdError.
  • Output from node repro.mjs:
min: 1, --wait=-5          => rejected: Parsing --wait The value must be at least 1. See more help with --help
min: 0, --wait=-5          => accepted: -5 minutes
min: 0, max: 10, --wait=-5 => accepted: -5 minutes
min: 0, max: 10, --wait=15 => rejected: Parsing --wait The value must be no more than 10. See more help with --help
max: 0, --wait=5           => accepted: 5 minutes

Error Message

Error (NoRecentJobIdError): There are no recent job IDs (ScratchOrgInfo requests) in your cache. Maybe it completed or already resumed?

System Information

{
  "architecture": "linux-x64",
  "cliVersion": "@salesforce/cli/2.158.7",
  "nodeVersion": "node-v26.13.0",
  "osVersion": "Linux 6.1.0-54-cloud-amd64",
  "shell": "bash",
  "pluginVersions": [
    "@oclif/plugin-autocomplete 4.0.6 (core)",
    "@oclif/plugin-commands 5.0.9 (core)",
    "@oclif/plugin-help 7.0.6 (core)",
    "@oclif/plugin-not-found 4.0.7 (core)",
    "@oclif/plugin-plugins 7.0.13 (core)",
    "@oclif/plugin-search 2.0.10 (core)",
    "@oclif/plugin-update 5.0.10 (core)",
    "@oclif/plugin-version 3.0.7 (core)",
    "@oclif/plugin-warn-if-update-available 4.0.5 (core)",
    "@oclif/plugin-which 4.0.6 (core)",
    "@salesforce/cli 2.158.7 (core)",
    "agent 2.2.4 (core)",
    "apex 4.4.7 (core)",
    "api 2.0.28 (core)",
    "auth 6.0.5 (core)",
    "data 5.1.26 (core)",
    "deploy-retrieve 4.3.2 (core)",
    "info 4.0.24 (core)",
    "limits 4.0.6 (core)",
    "marketplace 2.0.25 (core)",
    "org 7.0.13 (core)",
    "packaging 3.0.17 (core)",
    "schema 4.0.16 (core)",
    "settings 3.0.23 (core)",
    "sobject 2.0.22 (core)",
    "telemetry 4.2.4 (core)",
    "templates 57.6.0 (core)",
    "trust 4.1.0 (core)",
    "user 6.0.11 (core)"
  ]
}

Additional Information

Verified on @salesforce/sf-plugins-core@13.0.9 (salesforcecli/sf-plugins-core main commit 4dceed5) with @oclif/core@5.1.12 and @salesforce/cli@2.158.7.

In salesforcecli/sf-plugins-core PR #470, defaultValue was updated to check typeof context.options.defaultValue === 'number' so defaultValue: 0 works, while validate() in src/flags/duration.ts still checks min and max with truthiness instead of typeof min === 'number' / typeof max === 'number'.

Screenshots or Log Files

No response

Credit: https://ucsbplse.github.io/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions