diff --git a/src/endpoints_submission_cli/commands/submissions/create.py b/src/endpoints_submission_cli/commands/submissions/create.py index 9a9cf00..faedd82 100644 --- a/src/endpoints_submission_cli/commands/submissions/create.py +++ b/src/endpoints_submission_cli/commands/submissions/create.py @@ -97,6 +97,13 @@ default=False, help="Assemble folder, run checker, print layout — exit without submitting.", ) +@click.option( + "--test", + "is_test", + is_flag=True, + default=False, + help="Mark the submission as a test submission (not a real results entry).", +) def submissions_create( token: str | None, division: str, @@ -109,6 +116,7 @@ def submissions_create( target_availability_date: str | None, embargo_date: str | None, dry_run: bool, + is_test: bool, ) -> None: """Create a new submission from one or more registered runs. @@ -118,26 +126,12 @@ def submissions_create( 3. Run the Submission Checker — abort on errors. 4. POST /submissions → get submission_id. 5. Upload the submission bundle. - 6. Create a GitHub PR. - 7. PATCH submission with pr_url and pr_number. """ run_ids_list = list(run_ids) # Ask before any downloads — a declined prompt should cost nothing. if provisional and not dry_run: _confirm_provisional(assume_yes) resolved_token = _get_token(token) - """ - if not dry_run: - target_repo = github_ops.get_target_repo() - _console.print("[cyan]Checking GitHub prerequisites…[/cyan]") - try: - repo_ok, repo_warning = github_ops.check_prerequisites(target_repo) - except GitHubError as exc: - _console.print(f"[bold red]GitHub prerequisite check failed:[/bold red] {exc}") - sys.exit(1) - if not repo_ok: - _console.print(f"[yellow]Warning:[/yellow] {repo_warning}") - """ with tempfile.TemporaryDirectory() as tmp: tmp_path = Path(tmp) @@ -199,8 +193,10 @@ def submissions_create( "scenario": scenario, "availability": availability, "run_ids": run_ids_list, + "is_test": is_test, # Wire field is still early_publish — the API schema has not been renamed. "early_publish": provisional, + } if publication_cycle: payload["publication_cycle"] = publication_cycle @@ -234,31 +230,6 @@ def submissions_create( _console.print(f"[bold red]Rollback failed:[/bold red] {rb_exc}") sys.exit(1) - """ - # 6. Push submission branch and create GitHub PR - _console.print("[cyan]Creating GitHub PR…[/cyan]") - branch = f"submission-{submission_id}" - try: - github_ops.prepare_submission_branch( - submission_dir, branch, target_repo, # type: ignore[possibly-undefined] - tmp_path / "gh" - ) - pr_url, pr_number = github_ops.create_pr(submission_id, branch, target_repo) - except GitHubError as exc: - _console.print( - f"[bold red]PR creation failed:[/bold red] {exc}\n" - f"[yellow]Rolling back submission {submission_id}…[/yellow]" - ) - try: - subs_api.withdraw_submission(resolved_token, submission_id) - _console.print("[green]Rollback successful — submission withdrawn.[/green]") - except APIError as rb_exc: - _console.print( - f"[bold red]Rollback also failed:[/bold red] {rb_exc}\n" - f"Orphaned submission ID: {submission_id}" - ) - sys.exit(1) - """ # 7. PATCH with pr_url, pr_number, status try: subs_api.update_submission( diff --git a/src/endpoints_submission_cli/commands/submissions/create_local.py b/src/endpoints_submission_cli/commands/submissions/create_local.py index 6eed8e1..d7e348c 100644 --- a/src/endpoints_submission_cli/commands/submissions/create_local.py +++ b/src/endpoints_submission_cli/commands/submissions/create_local.py @@ -100,6 +100,13 @@ default=False, help="Run the Submission Checker and print layout — exit without calling the API.", ) +@click.option( + "--test", + "is_test", + is_flag=True, + default=False, + help="Mark the submission as a test submission (not a real results entry).", +) def submissions_create_local( token: str | None, submission_path: Path, @@ -112,6 +119,7 @@ def submissions_create_local( target_availability_date: str | None, embargo_date: str | None, dry_run: bool, + is_test: bool, ) -> None: """Create a submission from a pre-assembled local folder. @@ -222,6 +230,7 @@ def submissions_create_local( "scenario": scenario, "availability": availability, "run_ids": run_ids, + "is_test": is_test, # Wire field is still early_publish — the API schema has not been renamed. "early_publish": provisional, } diff --git a/tests/endpoints_submission_cli/commands/test_submissions_commands.py b/tests/endpoints_submission_cli/commands/test_submissions_commands.py index e167a5c..8282fb8 100644 --- a/tests/endpoints_submission_cli/commands/test_submissions_commands.py +++ b/tests/endpoints_submission_cli/commands/test_submissions_commands.py @@ -778,6 +778,8 @@ def test_create_success(self, tmp_path: Path) -> None: *_TOKEN_ARGS, ) mock_create.assert_called_once() + # Without --test, the submission is created as a non-test entry. + assert mock_create.call_args.args[1]["is_test"] is False # The bundle carries a cli_metadata.json marker identifying the build command. meta_path = fake_sub_dir / "cli_metadata.json" assert meta_path.is_file() @@ -785,6 +787,64 @@ def test_create_success(self, tmp_path: Path) -> None: assert meta["command"] == "create" assert "cli_version" in meta and "created_at" in meta + def test_create_test_flag_sets_is_test(self, tmp_path: Path) -> None: + import contextlib + + fake_archive = _make_fake_archive(tmp_path) + fake_sub_dir = tmp_path / "sub" + fake_sub_dir.mkdir() + fake_bundle = tmp_path / "bundle.tar.gz" + fake_bundle.write_bytes(b"bundle") + C = "endpoints_submission_cli" + + with contextlib.ExitStack() as stack: + stack.enter_context(patch(f"{C}._http.get_token", return_value=TOKEN)) + stack.enter_context( + patch(f"{C}.runs.api.download_run_archive", return_value=fake_archive) + ) + stack.enter_context( + patch( + f"{C}.commands.submissions.create.build_submission_folder", + return_value=fake_sub_dir, + ) + ) + stack.enter_context(patch(f"{C}.commands.submissions.create._run_submission_checker")) + mock_create = stack.enter_context( + patch(f"{C}.submissions.api.create_submission", return_value=SUBMISSION_OUT) + ) + stack.enter_context( + patch( + f"{C}.commands.submissions.create.create_bundle_archive", + return_value=fake_bundle, + ) + ) + stack.enter_context(patch(f"{C}.submissions.api.upload_submission_archive")) + stack.enter_context(patch(f"{C}.submissions.github.prepare_submission_branch")) + stack.enter_context( + patch(f"{C}.submissions.github.create_pr", return_value=(_PR_URL, _PR_NUMBER)) + ) + stack.enter_context(patch(f"{C}.submissions.api.update_submission")) + stack.enter_context( + patch(f"{C}.submissions.github.get_target_repo", return_value="org/repo") + ) + _run_app( + "submissions", + "create", + "--division", + "standardized", + "--scenario", + "cop", + "--availability", + "available", + "--run-ids", + RUN_ID, + "--test", + *_TOKEN_ARGS, + ) + + mock_create.assert_called_once() + assert mock_create.call_args.args[1]["is_test"] is True + def test_create_download_failure_exits_1(self) -> None: with patch("endpoints_submission_cli._http.get_token", return_value=TOKEN): with patch(