mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-07-09 00:45:16 +00:00
fix(cli): filter unknown --inputs keys even on flow persistence restore
Review follow-up: the `id` (persistence-restore) branch of _resolve_flow_inputs returned the raw payload, so typo keys passed alongside `id` skipped the unknown-key warning/drop and reached kickoff — which can fail strict (extra="forbid") flow state models. The restore path now still warns on and drops unknown keys (keeping `id` and known state fields); it only skips the required-field prompt and pre-kickoff validation, which persistence hydrates. Regression test: test_id_restore_still_drops_unknown_keys. Also drop the duplicate module import in test_input_prompt.py (both `import` and `from ... import` of crewai_cli.input_prompt) flagged by the code-quality bot; monkeypatching now uses the string target form. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RBYGqJHC2TMC6fonFziuuh
This commit is contained in:
@@ -4,7 +4,6 @@ from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
import crewai_cli.input_prompt as input_prompt_module
|
||||
from crewai_cli.input_prompt import (
|
||||
closest_name,
|
||||
parse_inputs_json,
|
||||
@@ -51,7 +50,7 @@ def test_prompt_for_inputs_uses_describe_and_coerce(monkeypatch, capsys):
|
||||
seen.append(text)
|
||||
return "42"
|
||||
|
||||
monkeypatch.setattr(input_prompt_module.click, "prompt", fake_prompt)
|
||||
monkeypatch.setattr("crewai_cli.input_prompt.click.prompt", fake_prompt)
|
||||
|
||||
result = prompt_for_inputs(
|
||||
["count"],
|
||||
@@ -71,7 +70,7 @@ def test_prompt_for_inputs_uses_describe_and_coerce(monkeypatch, capsys):
|
||||
|
||||
def test_prompt_for_inputs_keeps_raw_string_without_coerce(monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
input_prompt_module.click, "prompt", lambda text, **kwargs: "AI"
|
||||
"crewai_cli.input_prompt.click.prompt", lambda text, **kwargs: "AI"
|
||||
)
|
||||
|
||||
result = prompt_for_inputs(
|
||||
|
||||
@@ -381,3 +381,22 @@ def test_id_only_input_skips_required_validation(tmp_path: Path) -> None:
|
||||
resolved = run_declarative_flow_module._resolve_flow_inputs(flow, {"id": "run-123"})
|
||||
|
||||
assert resolved == {"id": "run-123"}
|
||||
|
||||
|
||||
def test_id_restore_still_drops_unknown_keys(
|
||||
tmp_path: Path, capsys: pytest.CaptureFixture[str]
|
||||
) -> None:
|
||||
# A persistence restore (`id` present) still filters typo keys so they don't
|
||||
# reach kickoff and trip strict (extra="forbid") state models — it only
|
||||
# skips the required-field prompt/validation, not the unknown-key warning.
|
||||
path = _write(tmp_path, REQUIRED_FLOW_YAML)
|
||||
flow = run_declarative_flow_module.load_declarative_flow(str(path))
|
||||
|
||||
resolved = run_declarative_flow_module._resolve_flow_inputs(
|
||||
flow, {"id": "run-123", "prospect_emai": "typo"}
|
||||
)
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert resolved == {"id": "run-123"} # id kept, typo dropped
|
||||
assert "Ignoring unknown input 'prospect_emai'" in captured.err
|
||||
assert "Ignoring unknown input 'id'" not in captured.err
|
||||
|
||||
Reference in New Issue
Block a user