Skip to content

openscience --port=5555 is silently ignored when server.port is set in the config #794

Closed

Description

What happens

src/cli/network.ts decides whether a port was passed on the command line with:

const portExplicitlySet = process.argv.includes("--port")
const port = portExplicitlySet ? args.port : (config?.server?.port ?? args.port)

includes is an exact string match, so it only recognises the space-separated spelling.

Why it is wrong

yargs parses both spellings into the same args.port, so the argument says the right thing while the flag that decides whether to trust it says no. With server.port set in openscience.json:

openscience serve --port 5555   ->  listens on 5555
openscience serve --port=5555   ->  listens on 1234 (from the config)

The = form is the more common one in scripts, CI, and documentation snippets, so the flag the user explicitly typed is silently discarded and the server binds somewhere they did not ask for.

There is no warning: the process starts successfully on the configured port, which reads as the flag having been understood.

Reproduction

process.argv = ["node", "openscience", "--port=5555"]
const resolved = await resolveNetworkOptions({ port: 5555, cors: [] })
resolved.port  // 1234, when the config has server.port = 1234

Suggested fix

Match both spellings:

const portExplicitlySet = process.argv.some((arg) => arg === "--port" || arg.startsWith("--port="))

src/cli/network.ts has no unit test today; the new test file covers both spellings, the config fallback, and the case where neither sets a port.

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