Skip to content

🧹 Refactor: Extract duplicated version classification logic into shared helper#44

Open
savvides wants to merge 1 commit into
mainfrom
fix/extract-version-classifier-11982650350858743443
Open

🧹 Refactor: Extract duplicated version classification logic into shared helper#44
savvides wants to merge 1 commit into
mainfrom
fix/extract-version-classifier-11982650350858743443

Conversation

@savvides

@savvides savvides commented Jun 6, 2026

Copy link
Copy Markdown
Owner

🎯 What: Extracted the duplicate version classification case statement from setup, bin/idstack-doctor, and test/test-version-classifier.sh into a new, shared helper script located at bin/idstack-version-classifier.
💡 Why: Reduces duplicate logic across multiple standalone scripts. By centralizing the complex bash globs for version strings into a single script, any future additions or changes to version parsing will only need to be updated in one place.
Verification: Validated that both test/test-version-classifier.sh and the full suite (test/smoke-test.sh and test/integration-test.sh) pass perfectly with no regressions. Code review confirmed the safety and correctness of executing a shared helper rather than repeating the case statement.
Result: Improved codebase maintainability by establishing a single source of truth for version legacy checking without breaking existing functionality or setup requirements.


PR created automatically by Jules for task 11982650350858743443 started by @savvides

- Extracted the duplicate version classification case statement from `setup` and `bin/idstack-doctor` into a new `bin/idstack-version-classifier` script.
- Updated `setup` and `bin/idstack-doctor` to execute the new helper.
- Updated `test/test-version-classifier.sh` to test the new helper directly rather than duplicating the logic inline.
- Verified all tests pass correctly.

Co-authored-by: savvides <1580637+savvides@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the version classification logic by extracting it into a new shared helper script, bin/idstack-version-classifier, which is now used by setup, bin/idstack-doctor, and the test suite. The feedback suggests addressing an edge case where the version 2.0 is not correctly classified as legacy, and recommends invoking the helper script with bash rather than executing it directly to prevent potential permission issues.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.


case "${1:-}" in
2.0.[1-9]*|2.[1-9]*|[3-9]*|[1-9][0-9]*) echo "skip" ;;
0.*|1.*|2.0.0.*|2.0.0) echo "legacy" ;;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The version 2.0 is a legacy version (pre-v2.0.1.0) but it currently does not match any of the patterns, resulting in an unknown classification. This means a legacy installation with version 2.0 in its VERSION file will not be detected or cleaned up during setup.

Adding 2.0 to the legacy pattern ensures it is correctly classified.

Please also consider adding check "2.0" legacy to the test cases in test/test-version-classifier.sh to prevent regressions.

  0.*|1.*|2.0.0.*|2.0.0|2.0) echo "legacy" ;;

Comment thread bin/idstack-doctor
esac
# Uses shared classifier to identify pre-v2.0.1.0 versions. Mirrors setup.
# Covered by test/test-version-classifier.sh.
class=$("$IDSTACK_DIR/bin/idstack-version-classifier" "$v")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Executing the helper script directly relies on the file having the executable permission bit set (chmod +x). In some environments (e.g., Windows/WSL, or when files are transferred/cloned with certain git configurations), the executable bit can be lost, leading to a "Permission denied" error.

Invoking the script with bash is more robust and avoids permission issues.

    class=$(bash "$IDSTACK_DIR/bin/idstack-version-classifier" "$v")

Comment thread setup
esac
# Uses shared classifier to identify pre-v2.0.1.0 versions. Covered by
# test/test-version-classifier.sh.
class=$("$IDSTACK_DIR/bin/idstack-version-classifier" "$legacy_version")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Executing the helper script directly relies on the file having the executable permission bit set. Since setup runs with set -e (line 2), any execution failure (such as "Permission denied" if the executable bit is missing) will cause the entire setup process to crash and exit immediately.

Invoking the script with bash is more robust and prevents potential installation failures.

    class=$(bash "$IDSTACK_DIR/bin/idstack-version-classifier" "$legacy_version")

local expected="$2"
local got
got="$(classify_version "$version")"
got="$("$IDSTACK_DIR/bin/idstack-version-classifier" "$version")"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For consistency and robustness, invoke the helper script using bash here as well.

Suggested change
got="$("$IDSTACK_DIR/bin/idstack-version-classifier" "$version")"
got="$(bash "$IDSTACK_DIR/bin/idstack-version-classifier" "$version")"

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.

1 participant