Skip to content

Improve expand_foreach test coverage: foreach removal, edge cases, and Jinja filters #296

Description

@coderabbitai

Background

During review of PR #294, the following gaps in src/manifest/expand_tests.rs were identified. Addressing them is out of scope for that documentation-and-expansion PR.

Work Required

File to edit: src/manifest/expand_tests.rs

  1. In expand_foreach_expands_sequence_values (Test 1), after confirming targets.len() == 2, add an assertion for each expanded target that its object map does not contain the key "foreach".

  2. In expand_foreach_applies_when_expression (Test 2), after confirming the filtered count, add an assertion for each remaining target that its object map does not contain the key "foreach".

  3. In expand_foreach_applies_action_when_expression (Test 4), after confirming the filtered count, add an assertion for each remaining action that its object map does not contain the key "foreach".

  4. Add a test expand_foreach_empty_foreach_produces_no_entries that passes a target with foreach: [] and asserts the expanded targets slice is empty.

  5. Add a test expand_foreach_non_object_entry_is_passed_through that passes a targets array containing a bare string value (non-object) and asserts it survives unexpanded.

  6. Add a test expand_foreach_iteration_vars_do_not_overwrite_globals that passes a target whose vars map already contains a key "item" with a value, and asserts the iteration-injected item value (from foreach) takes precedence for each expanded entry (or whichever precedence rule expand_section implements — assert the actual observed behaviour).

  7. Add a test expand_foreach_jinja_filter_in_name that passes a target whose name uses a Jinja filter (e.g. {{ item | upper }}) with a foreach list of lowercase strings and asserts the expanded names are uppercased correctly.

Do not remove or modify any existing tests.

AI Agent Prompt

File to edit: src/manifest/expand_tests.rs

1. In `expand_foreach_expands_sequence_values` (Test 1), after confirming
   `targets.len() == 2`, add an assertion for each expanded target that its
   object map does not contain the key `foreach`.

2. In `expand_foreach_applies_when_expression` (Test 2), after confirming
   the filtered count, add an assertion for each remaining target that its
   object map does not contain the key `foreach`.

3. In `expand_foreach_applies_action_when_expression` (Test 4), after
   confirming the filtered count, add an assertion for each remaining action
   that its object map does not contain the key `foreach`.

4. Add a test `expand_foreach_empty_foreach_produces_no_entries` that
   passes a target with `foreach: []` and asserts the expanded `targets`
   slice is empty.

5. Add a test `expand_foreach_non_object_entry_is_passed_through` that
   passes a `targets` array containing a bare string value (non-object) and
   asserts it survives unexpanded.

6. Add a test `expand_foreach_iteration_vars_do_not_overwrite_globals` that
   passes a target whose `vars` map already contains a key `item` with a
   value, and asserts the iteration-injected `item` value (from `foreach`)
   takes precedence for each expanded entry (or whichever precedence rule
   `expand_section` implements — assert the actual observed behaviour).

7. Add a test `expand_foreach_jinja_filter_in_name` that passes a target
   whose `name` uses a Jinja filter (e.g. `{{ item | upper }}`) with a
   `foreach` list of lowercase strings and asserts the expanded names are
   uppercased correctly.

Do not remove or modify any existing tests.

Raised By

@leynos — identified during review of PR #294 (#294).

Rescope (2026-08-12)

The tests have since moved from src/manifest/expand_tests.rs into src/manifest/expand_test_cases/. Progress against the numbered items:

  • Items 1–3 (foreach-key-removal assertions): done!map.contains_key("foreach") assertions exist in expand_test_cases/action_condition_cases.rs:27 and condition_cases.rs:88, and the proptest foreach_key_is_removed_from_all_entries (property_cases.rs:97, merged via Add proptest property tests for expand_foreach (#295) #359) covers the invariant generally.
  • Item 6 (iteration vars vs entry vars): effectively covered by expand_foreach_when_item_overrides_entry_vars (condition_cases.rs:126).
  • Items 4, 5, and 7 (empty foreach, non-object passthrough, Jinja filter in name): outstanding — no such tests exist under src/manifest/. PR Extend expand_foreach test coverage (#296) #358 is in flight to cover these.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lowBacklog work, hygiene, or technical debt planned opportunistically, without a strict deadline.testingTest coverage, test infrastructure, and verification tooling work.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions