Skip to content

fix(presets): set-priority repairs corrupted boolean priority#3269

Open
jawwad-ali wants to merge 1 commit into
github:mainfrom
jawwad-ali:fix/preset-set-priority-bool
Open

fix(presets): set-priority repairs corrupted boolean priority#3269
jawwad-ali wants to merge 1 commit into
github:mainfrom
jawwad-ali:fix/preset-set-priority-bool

Conversation

@jawwad-ali

Copy link
Copy Markdown
Contributor

Description

preset set-priority carries the same bool-is-int trap as extension set-priority. The skip-if-unchanged guard, whose comment promises corrupted values are repaired:

# This ensures corrupted values (e.g., "high") get repaired even when setting to default (10)
if isinstance(raw_priority, int) and raw_priority == priority:
    console.print(f"...already has priority {priority}")
    raise typer.Exit(0)

matches a corrupted boolean priority, because isinstance(True, int) is True and True == 1 (False == 0). Running preset set-priority <pack> 1 on a pack whose priority is corrupted to True reports "already has priority 1" and exits without repairing it. normalize_priority() already excludes bools; this call site didn't.

Fix

Exclude bools from the skip guard, mirroring normalize_priority (and the matching extension-side fix):

if (
    isinstance(raw_priority, int)
    and not isinstance(raw_priority, bool)
    and raw_priority == priority
):

Testing

  • New test_set_priority_repairs_corrupted_bool: injects priority: True, runs preset set-priority test-pack 1, asserts it reports priority changed (not already has priority) and the reloaded value is 1 with not isinstance(..., bool). Fails before ("already has priority 1", verified by source-stash), passes after.
  • TestPresetSetPriority passes (5 tests); uvx ruff check clean. The same-value test (priority 5) stays green.

AI Disclosure

  • I did use AI assistance (describe below)

Found and fixed with Claude Code (Claude Opus 4.8) under my direction. AI flagged the same bool-is-int trap on the preset side; I confirmed it on an independent code path, proved fail-before via source-stash, and reviewed the diff before submitting.

Same bool-is-int trap as the extension set-priority command: the skip
guard 'isinstance(raw_priority, int) and raw_priority == priority' treats
a stored boolean as a match (isinstance(True, int) is True, True == 1),
so a corrupted boolean priority reports 'already has priority N' and is
never rewritten to a real int — contradicting the adjacent comment.
Exclude bools explicitly, mirroring normalize_priority's bool guard.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants