Skip to content

🧪 Add tests for idstack-doctor#55

Open
savvides wants to merge 1 commit into
mainfrom
add-doctor-tests-9296994704396496624
Open

🧪 Add tests for idstack-doctor#55
savvides wants to merge 1 commit into
mainfrom
add-doctor-tests-9296994704396496624

Conversation

@savvides

@savvides savvides commented Jun 6, 2026

Copy link
Copy Markdown
Owner

🎯 What: Adds unit tests for the bin/idstack-doctor diagnostics script which was previously untested.
📊 Coverage: The tests fully isolate the environment by mocking the IDSTACK_DIR, the user's HOME directory, and the claude CLI binary. Test scenarios include happy paths, missing plugin/marketplace manifests, missing SKILL.md files, various claude plugin list output states, and legacy install conflicts.
Result: Better test coverage, allowing safer refactoring of installation diagnostics. Tests run smoothly in the existing smoke-test.sh framework.


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

Adds isolated mock-environment testing for the bin/idstack-doctor script,
covering missing manifests, skill files, claude CLI absence/states, and
legacy conflict scenarios. Integrates the new test suite into smoke-test.sh.

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 introduces unit tests for the idstack-doctor script by adding test/test-doctor.sh and integrating it into the smoke test suite. The feedback focuses on improving the robustness and isolation of the test script: specifically, guarding the EXIT trap against unset variables, refactoring the claude mock output generator to use printf instead of multiple echo statements, and replacing hardcoded /tmp paths with the isolated TEST_ROOT directory to prevent potential conflicts.

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.

Comment thread test/test-doctor.sh
Comment on lines +11 to +12
TEST_ROOT="$(mktemp -d)"
trap 'rm -rf "$TEST_ROOT"' EXIT

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

If mktemp -d fails or if the script exits prematurely before TEST_ROOT is fully assigned, running rm -rf "$TEST_ROOT" in the EXIT trap could potentially run on an empty or unset variable. It is safer to defensively guard the rm -rf command by ensuring TEST_ROOT is non-empty.

Suggested change
TEST_ROOT="$(mktemp -d)"
trap 'rm -rf "$TEST_ROOT"' EXIT
TEST_ROOT="$(mktemp -d)"
trap 'if [ -n "${TEST_ROOT:-}" ]; then rm -rf "$TEST_ROOT"; fi' EXIT

Comment thread test/test-doctor.sh
Comment on lines +54 to +64
mock_claude_output() {
cat > "$MOCK_BIN/claude" << 'EOF'
#!/bin/sh
if [ "$1 $2" = "plugin list" ]; then
EOF
echo " cat << 'INNER_EOF'" >> "$MOCK_BIN/claude"
echo "$1" >> "$MOCK_BIN/claude"
echo "INNER_EOF" >> "$MOCK_BIN/claude"
echo "fi" >> "$MOCK_BIN/claude"
chmod +x "$MOCK_BIN/claude"
}

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 current implementation of mock_claude_output uses multiple echo appends and is susceptible to issues if the input string contains backslashes or starts with characters that echo might interpret as options (like -e or -n). We can make this much more robust, concise, and readable by using a single printf statement with %s to safely output the raw string without shell expansion or interpretation.

Suggested change
mock_claude_output() {
cat > "$MOCK_BIN/claude" << 'EOF'
#!/bin/sh
if [ "$1 $2" = "plugin list" ]; then
EOF
echo " cat << 'INNER_EOF'" >> "$MOCK_BIN/claude"
echo "$1" >> "$MOCK_BIN/claude"
echo "INNER_EOF" >> "$MOCK_BIN/claude"
echo "fi" >> "$MOCK_BIN/claude"
chmod +x "$MOCK_BIN/claude"
}
mock_claude_output() {
printf "#!/bin/sh\nif [ \"\$1 \$2\" = \"plugin list\" ]; then\n cat << 'INNER_EOF'\n%s\nINNER_EOF\nfi\n" "$1" > "$MOCK_BIN/claude"
chmod +x "$MOCK_BIN/claude"
}

Comment thread test/test-doctor.sh
mock_claude_output "idstack@idstack
status: enabled"
mkdir -p "$HOME/.claude/skills"
ln -s "/tmp/dummy" "$HOME/.claude/skills/idstack"

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

Using a hardcoded /tmp/dummy path can lead to conflicts if multiple tests run concurrently or if other processes use that path. Since TEST_ROOT is already set up as a secure, isolated temporary directory, it is safer and cleaner to create the symlink target inside TEST_ROOT.

Suggested change
ln -s "/tmp/dummy" "$HOME/.claude/skills/idstack"
ln -s "$TEST_ROOT/dummy" "$HOME/.claude/skills/idstack"

Comment thread test/test-doctor.sh
status: enabled"
rm -rf "$HOME/.claude/skills/idstack"
mkdir -p "$HOME/.claude/skills"
ln -s "/tmp/dummy-idstack/some-skill" "$HOME/.claude/skills/needs-analysis"

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

Avoid using hardcoded /tmp paths to prevent potential conflicts and ensure complete test isolation. Use the secure TEST_ROOT directory instead.

Suggested change
ln -s "/tmp/dummy-idstack/some-skill" "$HOME/.claude/skills/needs-analysis"
ln -s "$TEST_ROOT/dummy-idstack/some-skill" "$HOME/.claude/skills/needs-analysis"

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