BUG-HUNT: [boundary] DetailLevelMapBuilder fails to find level names with leading/trailing whitespace #3167

Open
opened 2026-04-05 07:09:46 +00:00 by freemo · 1 comment
Owner

Bug Report: [boundary] — DetailLevelMapBuilder fails to find level names with leading/trailing whitespace

Severity Assessment

  • Impact: The insert_after method of DetailLevelMapBuilder will fail to find an existing level if the level name in the parent map has leading or trailing whitespace. This can lead to unexpected ValueError exceptions.
  • Likelihood: Low. Level names are not expected to have leading or trailing whitespace.
  • Priority: Low

Location

  • File: cleveragents-core/src/cleveragents/acms/uko/detail_level_maps.py
  • Function/Class: DetailLevelMapBuilder.insert_after
  • Lines: 148-152

Description

The insert_after method in DetailLevelMapBuilder strips whitespace from the after_level argument before checking if it exists in the known set of level names. However, the level names in the known set are not stripped of whitespace when they are added from the parent map. This can cause a mismatch and a ValueError if a level name in the parent map contains leading or trailing whitespace.

Evidence

        after_stripped = after_level.strip()
        known = set(self._parent.effective_levels().keys())
        known.update(new_name for _, new_name in self._insertions)
        if after_stripped not in known:
            raise ValueError(
                f"Level '{after_stripped}' not found in parent map "
                f"'{self._parent.domain}'"
            )

Expected Behavior

The insert_after method should be able to find level names even if they contain leading or trailing whitespace. The check should be done consistently, either by stripping whitespace from both the input and the known level names, or by not stripping it at all.

Actual Behavior

The method fails to find level names with leading/trailing whitespace, raising a ValueError.

Suggested Fix

Strip the whitespace from the level names when building the known set.

        known = {name.strip() for name in self._parent.effective_levels().keys()}

Category

boundary

Metadata

  • Branch: fix/detail-level-map-builder-whitespace
  • Commit Message: fix(acms): strip whitespace from known level names in DetailLevelMapBuilder.insert_after
  • Milestone: Backlog
  • Parent Epic: #3132

Subtasks

  • Strip whitespace from level names when building the known set in DetailLevelMapBuilder.insert_after
  • Add unit test covering insert_after with a parent map containing level names with leading/trailing whitespace
  • Verify coverage >= 97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.
  • All nox stages pass
  • Coverage >= 97%

Backlog note: This issue was discovered during autonomous operation
on milestone v3.7.0. It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.


Automated by CleverAgents Bot
Supervisor: Bug Hunting | Agent: ca-new-issue-creator

## Bug Report: [boundary] — DetailLevelMapBuilder fails to find level names with leading/trailing whitespace ### Severity Assessment - **Impact**: The `insert_after` method of `DetailLevelMapBuilder` will fail to find an existing level if the level name in the parent map has leading or trailing whitespace. This can lead to unexpected `ValueError` exceptions. - **Likelihood**: Low. Level names are not expected to have leading or trailing whitespace. - **Priority**: Low ### Location - **File**: `cleveragents-core/src/cleveragents/acms/uko/detail_level_maps.py` - **Function/Class**: `DetailLevelMapBuilder.insert_after` - **Lines**: 148-152 ### Description The `insert_after` method in `DetailLevelMapBuilder` strips whitespace from the `after_level` argument before checking if it exists in the `known` set of level names. However, the level names in the `known` set are not stripped of whitespace when they are added from the parent map. This can cause a mismatch and a `ValueError` if a level name in the parent map contains leading or trailing whitespace. ### Evidence ```python after_stripped = after_level.strip() known = set(self._parent.effective_levels().keys()) known.update(new_name for _, new_name in self._insertions) if after_stripped not in known: raise ValueError( f"Level '{after_stripped}' not found in parent map " f"'{self._parent.domain}'" ) ``` ### Expected Behavior The `insert_after` method should be able to find level names even if they contain leading or trailing whitespace. The check should be done consistently, either by stripping whitespace from both the input and the known level names, or by not stripping it at all. ### Actual Behavior The method fails to find level names with leading/trailing whitespace, raising a `ValueError`. ### Suggested Fix Strip the whitespace from the level names when building the `known` set. ```python known = {name.strip() for name in self._parent.effective_levels().keys()} ``` ### Category boundary ## Metadata - **Branch**: `fix/detail-level-map-builder-whitespace` - **Commit Message**: `fix(acms): strip whitespace from known level names in DetailLevelMapBuilder.insert_after` - **Milestone**: Backlog - **Parent Epic**: #3132 ## Subtasks - [ ] Strip whitespace from level names when building the `known` set in `DetailLevelMapBuilder.insert_after` - [ ] Add unit test covering `insert_after` with a parent map containing level names with leading/trailing whitespace - [ ] Verify coverage >= 97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. - All nox stages pass - Coverage >= 97% > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.7.0. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: ca-new-issue-creator
freemo added this to the v3.6.0 milestone 2026-04-05 07:22:45 +00:00
freemo modified the milestone from v3.6.0 to v3.8.0 2026-04-05 07:24:00 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Backlog — edge case with whitespace in level names; low likelihood of occurring in practice
  • Milestone: v3.8.0
  • MoSCoW: Could Have — this is a boundary condition bug with low likelihood. Level names are not expected to have leading/trailing whitespace in normal usage. Desirable fix but not blocking.
  • Parent Epic: #3132

Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: ca-project-owner

Issue triaged by project owner: - **State**: Verified - **Priority**: Backlog — edge case with whitespace in level names; low likelihood of occurring in practice - **Milestone**: v3.8.0 - **MoSCoW**: Could Have — this is a boundary condition bug with low likelihood. Level names are not expected to have leading/trailing whitespace in normal usage. Desirable fix but not blocking. - **Parent Epic**: #3132 --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#3167
No description provided.