fix: validate draft output modes before context
This commit is contained in:
@@ -549,16 +549,29 @@ def set_step_output_map(
|
||||
raise typer.BadParameter("provide --map, --bindings-file, or --clear")
|
||||
if selected_modes > 1:
|
||||
raise typer.BadParameter(
|
||||
"--bindings-file and --clear cannot be combined with --map"
|
||||
"--map, --bindings-file, and --clear are mutually exclusive"
|
||||
)
|
||||
if merge and (has_file or clear):
|
||||
raise typer.BadParameter(
|
||||
"--merge is supported only for compatibility map-only edits"
|
||||
)
|
||||
|
||||
context = load_cli_context(ctx)
|
||||
if merge:
|
||||
output_map = _parse_output_map_flags(mapping)
|
||||
bindings = None
|
||||
else:
|
||||
output_map = None
|
||||
bindings = (
|
||||
parse_step_output_bindings_file(bindings_file)
|
||||
if bindings_file is not None
|
||||
else []
|
||||
if clear
|
||||
else parse_step_output_binding_flags(mapping)
|
||||
)
|
||||
|
||||
context = load_cli_context(ctx)
|
||||
if merge:
|
||||
assert output_map is not None
|
||||
operation = context.handlers.set_step_output_map(
|
||||
workspace_id=workspace_id,
|
||||
revision=revision,
|
||||
@@ -567,13 +580,7 @@ def set_step_output_map(
|
||||
merge=True,
|
||||
)
|
||||
else:
|
||||
bindings = (
|
||||
parse_step_output_bindings_file(bindings_file)
|
||||
if bindings_file is not None
|
||||
else []
|
||||
if clear
|
||||
else parse_step_output_binding_flags(mapping)
|
||||
)
|
||||
assert bindings is not None
|
||||
operation = context.handlers.set_step_output_bindings(
|
||||
workspace_id=workspace_id,
|
||||
revision=revision,
|
||||
|
||||
@@ -2011,17 +2011,55 @@ def test_wf_draft_set_output_clear_sends_empty_binding_list(monkeypatch) -> None
|
||||
assert calls[0]["bindings"] == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("mode_args", "expected_error"),
|
||||
[
|
||||
(["--map", "report..title=state.title"], "path"),
|
||||
(["--bindings-file", "missing-bindings.json"], "cannot read"),
|
||||
],
|
||||
)
|
||||
def test_wf_draft_set_output_validates_selected_mode_before_context(
|
||||
monkeypatch, mode_args: list[str], expected_error: str
|
||||
) -> None:
|
||||
monkeypatch.setattr(
|
||||
"wf_cli.commands.drafts.load_cli_context",
|
||||
lambda _ctx: (_ for _ in ()).throw(AssertionError("context loaded")),
|
||||
)
|
||||
|
||||
result = runner.invoke(
|
||||
app,
|
||||
[
|
||||
"draft",
|
||||
"set-output",
|
||||
"report_ws",
|
||||
"--revision",
|
||||
"1",
|
||||
"--step",
|
||||
"render",
|
||||
*mode_args,
|
||||
],
|
||||
)
|
||||
|
||||
assert result.exit_code == 2
|
||||
assert "context loaded" not in result.output
|
||||
assert expected_error in " ".join(result.output.split()).lower()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("extra_args", "expected_error"),
|
||||
[
|
||||
([], "provide --map, --bindings-file, or --clear"),
|
||||
(
|
||||
["--bindings-file", "bindings.json", "--map", "value=state.value"],
|
||||
"cannot be combined with --map",
|
||||
"mutually exclusive",
|
||||
),
|
||||
(
|
||||
["--clear", "--map", "value=state.value"],
|
||||
"cannot be combined with --map",
|
||||
"mutually exclusive",
|
||||
),
|
||||
(
|
||||
["--bindings-file", "bindings.json", "--clear"],
|
||||
"mutually exclusive",
|
||||
),
|
||||
(
|
||||
["--merge", "--bindings-file", "bindings.json"],
|
||||
|
||||
Reference in New Issue
Block a user