Skip to content

Fix app.py and scripts/export.py CLI: switch to argparse, add --port/--host/--base-dir, fix default host, validate --since #4

Description

@wpak-ai

Summary

A CLI audit found three bugs across app.py and scripts/export.py. All are now fixed and covered by regression tests.


Bugs fixed

Bug 1 — app.py: Default host was 0.0.0.0 (binds to all interfaces)

The server was binding to all network interfaces by default. The intended behaviour for a local-use tool is to bind to 127.0.0.1 (localhost only).

Fix: Changed hardcoded host="0.0.0.0" to host="127.0.0.1".


Bug 2 — app.py: Manual sys.argv loop; missing --port, --host, --base-dir; hardcoded startup message

app.py used a hand-rolled while loop over sys.argv that only recognised --exclude-rules/-e. As a result:

  • --help was silently ignored
  • Unknown arguments were silently discarded
  • Port and bind address could not be changed without editing the source
  • The workspace storage path could only be overridden via the WORKSPACE_PATH environment variable, not from the command line
  • The startup message was hardcoded to http://localhost:3000 regardless of actual host/port

Fix: Replaced the manual loop with argparse. Added:

  • --port (default 3000)
  • --host (default 127.0.0.1)
  • --base-dir (overrides workspace storage path; wired to set_workspace_path_override)

Startup message is now dynamic: http://{args.host}:{args.port}.


Bug 3 — scripts/export.py: Manual parse_args() with no --base-dir and no --since validation

The hand-rolled parse_args() had two problems:

  • --since accepted any arbitrary string without validation. Passing --since weekly would silently be treated as "all" with no error, masking typos.
  • No --base-dir flag to override the workspace storage path from the command line, forcing users to set WORKSPACE_PATH as an environment variable instead.

Fix: Replaced the manual loop with argparse. Added:

  • --base-dir (overrides WORKSPACE_PATH env var when set)
  • --since now uses choices=["all", "last"] — invalid values exit with a clear error message

Tests added

tests/test_cli_args.py — 34 unittest tests covering every flag combination for both app.py and scripts/export.py, including all defaults, overrides, short-form flags, invalid --since rejection, --help/-h exit codes, and source-level assertions.

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