Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions contextual_orchestrator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,16 @@ def _auto_discover_seed_agents(
return expanded


def main() -> None:
def main(argv: list[str] | None = None) -> None:
"""Parse CLI options and run bootstrap, prompt completion, or the HTTP server."""
if len(sys.argv) > 1 and sys.argv[1] == "register-credential":
_register_credential_command(sys.argv[2:])
arguments = list(sys.argv[1:] if argv is None else argv)
if arguments and arguments[0] == "register-credential":
_register_credential_command(arguments[1:])
return
if len(sys.argv) > 1 and sys.argv[1] == "discover-models":
_discover_models_command(sys.argv[2:])
if arguments and arguments[0] == "discover-models":
_discover_models_command(arguments[1:])
return
if len(sys.argv) > 1 and sys.argv[1] == "check-fast-mlsirm":
if arguments and arguments[0] == "check-fast-mlsirm":
_check_fast_mlsirm_command()
return

Expand Down Expand Up @@ -373,7 +374,7 @@ def main() -> None:
help="Seconds to cache identical requests (default 0 = disabled).")
parser.add_argument("--eval", nargs="+", metavar="PROMPT",
help="Measure orchestration vs a single-worker baseline on these prompts and print the report.")
args = parser.parse_args()
args = parser.parse_args(arguments)

client = ModelClient(
ca_bundle=args.provider_ca_bundle,
Expand Down
10 changes: 10 additions & 0 deletions tests/test_cli_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ def test_key_only_split_tokens_select_split_mode() -> None:
set_backend(None)


def test_main_accepts_explicit_argv_without_mutating_process_arguments() -> None:
original_argv = sys.argv[:]
with patch("contextual_orchestrator.__main__.serve") as serve:
main(["--serve", "--auth-token", "argv-token"])

assert sys.argv == original_argv
security = serve.call_args.kwargs["security"]
assert security.auth_token == "argv-token"


def test_invalid_local_provider_options_fail_at_parser_boundary() -> None:
invalid_options = (
(["--local-concurrency", "0"], "positive integer"),
Expand Down
Loading