🧪 Add tests for idstack-doctor#55
Conversation
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>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
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.
| TEST_ROOT="$(mktemp -d)" | ||
| trap 'rm -rf "$TEST_ROOT"' EXIT |
There was a problem hiding this comment.
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.
| 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 |
| 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" | ||
| } |
There was a problem hiding this comment.
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.
| 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" | |
| } |
| mock_claude_output "idstack@idstack | ||
| status: enabled" | ||
| mkdir -p "$HOME/.claude/skills" | ||
| ln -s "/tmp/dummy" "$HOME/.claude/skills/idstack" |
There was a problem hiding this comment.
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.
| ln -s "/tmp/dummy" "$HOME/.claude/skills/idstack" | |
| ln -s "$TEST_ROOT/dummy" "$HOME/.claude/skills/idstack" |
| 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" |
There was a problem hiding this comment.
Avoid using hardcoded /tmp paths to prevent potential conflicts and ensure complete test isolation. Use the secure TEST_ROOT directory instead.
| 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" |
🎯 What: Adds unit tests for the
bin/idstack-doctordiagnostics script which was previously untested.📊 Coverage: The tests fully isolate the environment by mocking the
IDSTACK_DIR, the user'sHOMEdirectory, and theclaudeCLI binary. Test scenarios include happy paths, missing plugin/marketplace manifests, missing SKILL.md files, variousclaude plugin listoutput states, and legacy install conflicts.✨ Result: Better test coverage, allowing safer refactoring of installation diagnostics. Tests run smoothly in the existing
smoke-test.shframework.PR created automatically by Jules for task 9296994704396496624 started by @savvides