Skip to content

fix(workflows): reject falsy non-mapping step.yml in step add - #4321

Open
Noor-ul-ain001 wants to merge 3 commits into
github:mainfrom
Noor-ul-ain001:fix/step-add-falsy-yaml-shape
Open

fix(workflows): reject falsy non-mapping step.yml in step add#4321
Noor-ul-ain001 wants to merge 3 commits into
github:mainfrom
Noor-ul-ain001:fix/step-add-falsy-yaml-shape

Conversation

@Noor-ul-ain001

Copy link
Copy Markdown
Contributor

Summary

  • workflow_step_add (src/specify_cli/workflows/_commands.py) parses a fetched step.yml with _yaml.safe_load(step_yml_content.decode("utf-8")) or {}.
  • That or {} coerces a falsy non-mapping top-level document ([], false, 0, '') to {} before the if not isinstance(meta, dict): ... shape check runs. The command then proceeds with meta = {}, derives step_meta = meta.get("step", {}){} and type_key = "", and reports the unrelated "step.yml missing 'step.type_key' field" instead of the real problem: "step.yml must be a YAML mapping".
  • A truthy non-mapping document (e.g. a bare string) already hits the correct isinstance check and reports the right error — this was an inconsistency between falsy and truthy malformed inputs.
  • Same falsy-or-coerce shape as the catalog-config bugs already fixed this cycle in workflows/catalog.py (WorkflowCatalog/StepCatalog), presets/__init__.py (PresetCatalog._load_catalog_config), and integrations (fix(integrations): report a falsy non-mapping integration descriptor as a shape error #4187).

Test plan

  • Added test_add_rejects_falsy_non_mapping_step_yml to TestWorkflowStepAddCLI, parametrized over [], false, 0, '', mocking the HTTP fetch so step.yml's body is the falsy document.
  • Verified all 4 new parametrized cases fail without the fix (stashed only the source change, confirmed the misleading "missing 'step.type_key'" message) and pass with it.
  • Ran TestWorkflowStepAddCLI in full — 24 passed; the 1 remaining failure (test_add_rejects_symlinked_steps_base_dir) is a pre-existing Windows symlink-elevation failure unrelated to this change (reproduces on an unmodified checkout).

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01FW9fAYsCBCAgdKWovtSyqt

@Noor-ul-ain001
Noor-ul-ain001 requested a review from mnriem as a code owner August 25, 2026 15:07
`workflow_step_add` parses a fetched `step.yml` with
`_yaml.safe_load(...) or {}`, which coerces a FALSY non-mapping
top-level document (`[]`, `false`, `0`, `''`) to `{}` before the
`isinstance(meta, dict)` shape check runs. The command then proceeds
with `meta = {}`, derives `step_meta = {}` and `type_key = ""`, and
reports the unrelated "step.yml missing 'step.type_key' field"
instead of the real problem: "step.yml must be a YAML mapping". A
TRUTHY non-mapping document (a bare string) already reported the
correct error — this was an inconsistency.

Same falsy-or-coerce shape as the catalog-config bugs fixed elsewhere
in workflows/catalog.py, presets/__init__.py, and integrations
(github#4187) this cycle.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FW9fAYsCBCAgdKWovtSyqt

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Explicit YAML null documents remain coerced to an empty mapping and receive the wrong error.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes workflow step validation so falsy non-mapping YAML values report a mapping-shape error.

Changes:

  • Removes broad falsy-to-dictionary coercion.
  • Adds regression coverage for lists, booleans, numbers, and empty strings.
File summaries
File Description
src/specify_cli/workflows/_commands.py Refines step.yml shape validation.
tests/test_workflows.py Tests falsy non-mapping documents.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/specify_cli/workflows/_commands.py Outdated
An explicit null document (null/~/NULL) parses to the same None as a
genuinely empty document, so it was silently coerced to {} and
misreported as the unrelated "missing step.type_key" error instead of
the mapping-shape error, per Copilot review on PR github#4321. Use
yaml.compose to tell the two apart, matching the sibling loaders
(yamlio.py, integrations/catalog.py, overlays/layer_sources.py).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0147sii7uC56YzAu2Ep9qH94

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Explicit empty documents such as --- are incorrectly classified as non-mappings.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread src/specify_cli/workflows/_commands.py Outdated

@mnriem mnriem left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address Copilot feedback

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants