-
Notifications
You must be signed in to change notification settings - Fork 5
π§ͺ Add unit tests for idstack-gen-skills #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
savvides
wants to merge
1
commit into
main
Choose a base branch
from
test-gen-skills-3265346482908859913
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| #!/usr/bin/env bash | ||
| # Unit tests for bin/idstack-gen-skills. | ||
| # Run from the repo root (or sourced by smoke-test.sh). | ||
|
|
||
| set -e | ||
|
|
||
| PASS=0 | ||
| FAIL=0 | ||
| TOTAL=0 | ||
|
|
||
| REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" | ||
| GEN_SKILLS="$REPO_ROOT/bin/idstack-gen-skills" | ||
|
|
||
| assert() { | ||
| TOTAL=$((TOTAL + 1)) | ||
| if eval "$2" >/dev/null 2>&1; then | ||
| PASS=$((PASS + 1)) | ||
| echo " PASS: $1" | ||
| else | ||
| FAIL=$((FAIL + 1)) | ||
| echo " FAIL: $1" | ||
| fi | ||
| } | ||
|
|
||
| if [ ! -x "$GEN_SKILLS" ]; then | ||
| echo "test-gen-skills: $GEN_SKILLS missing or not executable" | ||
| exit 1 | ||
| fi | ||
|
|
||
| WORK=$(mktemp -d) | ||
| trap 'rm -rf "$WORK"' EXIT | ||
|
|
||
| seed_workspace() { | ||
| # Clean existing items before seeding to avoid permission issues or stale files | ||
| rm -rf "$WORK"/* "$WORK"/.??* 2>/dev/null || true | ||
| mkdir -p "$WORK/bin" "$WORK/templates/assets" "$WORK/skills/test-skill" | ||
| cp "$GEN_SKILLS" "$WORK/bin/" | ||
|
|
||
| echo "PREAMBLE CONTENT" > "$WORK/templates/preamble.md" | ||
| echo "SCHEMA CONTENT" > "$WORK/templates/manifest-schema.md" | ||
| touch "$WORK/templates/report.html.tmpl" | ||
| touch "$WORK/templates/index.html.tmpl" | ||
| touch "$WORK/templates/assets/idstack.css" | ||
| echo "AGENT CONTEXT" > "$WORK/templates/agent-context.md" | ||
|
|
||
| cat > "$WORK/skills/test-skill/SKILL.md.tmpl" <<'INNER_EOF' | ||
| --- | ||
| name: test-skill | ||
| allowed-tools: | ||
| - tool1 | ||
| - tool2 | ||
| description: test | ||
| --- | ||
| {{PREAMBLE}} | ||
| some content | ||
| {{MANIFEST_SCHEMA}} | ||
| INNER_EOF | ||
| } | ||
|
|
||
| echo "test-gen-skills" | ||
| echo "" | ||
|
|
||
| # --- Test 1: Missing templates fail --- | ||
| seed_workspace | ||
| rm "$WORK/templates/preamble.md" | ||
| set +e | ||
| "$WORK/bin/idstack-gen-skills" --target claude >/dev/null 2>&1 | ||
| EC=$? | ||
| set -e | ||
| assert "missing template exits 1" "[ $EC -eq 1 ]" | ||
|
|
||
| # --- Test 2: claude target generation --- | ||
| seed_workspace | ||
| "$WORK/bin/idstack-gen-skills" --target claude >/dev/null 2>&1 | ||
| assert "claude target creates SKILL.md" "[ -f \"$WORK/skills/test-skill/SKILL.md\" ]" | ||
| assert "claude target substitutes PREAMBLE" "grep -q 'PREAMBLE CONTENT' \"$WORK/skills/test-skill/SKILL.md\"" | ||
| assert "claude target substitutes MANIFEST_SCHEMA" "grep -q 'SCHEMA CONTENT' \"$WORK/skills/test-skill/SKILL.md\"" | ||
| assert "claude target preserves allowed-tools" "grep -q 'allowed-tools:' \"$WORK/skills/test-skill/SKILL.md\"" | ||
| assert "claude target injects auto-generated header" "grep -q 'AUTO-GENERATED' \"$WORK/skills/test-skill/SKILL.md\"" | ||
| assert "codex target NOT created" "[ ! -f \"$WORK/dist/codex/skills/idstack-test-skill/SKILL.md\" ]" | ||
| assert "AGENTS.md NOT created" "[ ! -f \"$WORK/AGENTS.md\" ]" | ||
|
|
||
| # --- Test 3: codex target generation --- | ||
| seed_workspace | ||
| "$WORK/bin/idstack-gen-skills" --target codex >/dev/null 2>&1 | ||
| assert "codex target creates SKILL.md" "[ -f \"$WORK/dist/codex/skills/idstack-test-skill/SKILL.md\" ]" | ||
| assert "codex target substitutes PREAMBLE" "grep -q 'PREAMBLE CONTENT' \"$WORK/dist/codex/skills/idstack-test-skill/SKILL.md\"" | ||
| assert "codex target strips allowed-tools" "! grep -q 'allowed-tools:' \"$WORK/dist/codex/skills/idstack-test-skill/SKILL.md\"" | ||
| assert "AGENTS.md is created" "[ -f \"$WORK/AGENTS.md\" ]" | ||
| assert "claude target NOT created" "[ ! -f \"$WORK/skills/test-skill/SKILL.md\" ]" | ||
|
|
||
| # --- Test 4: all target generation --- | ||
| seed_workspace | ||
| "$WORK/bin/idstack-gen-skills" >/dev/null 2>&1 | ||
| assert "all target creates claude SKILL.md" "[ -f \"$WORK/skills/test-skill/SKILL.md\" ]" | ||
| assert "all target creates codex SKILL.md" "[ -f \"$WORK/dist/codex/skills/idstack-test-skill/SKILL.md\" ]" | ||
| assert "all target creates AGENTS.md" "[ -f \"$WORK/AGENTS.md\" ]" | ||
|
|
||
| # --- Test 5: --dry-run behavior --- | ||
| seed_workspace | ||
| "$WORK/bin/idstack-gen-skills" --target claude >/dev/null 2>&1 | ||
| assert "dry-run passes when fresh" "$WORK/bin/idstack-gen-skills --dry-run --target claude >/dev/null 2>&1" | ||
| echo "stale" >> "$WORK/skills/test-skill/SKILL.md" | ||
| set +e | ||
| "$WORK/bin/idstack-gen-skills" --dry-run --target claude >/dev/null 2>&1 | ||
| EC=$? | ||
| set -e | ||
| assert "dry-run exits 1 when stale" "[ $EC -eq 1 ]" | ||
|
|
||
| # --- Test 6: Invalid target --- | ||
| seed_workspace | ||
| set +e | ||
| "$WORK/bin/idstack-gen-skills" --target bogus >/dev/null 2>&1 | ||
| EC=$? | ||
| set -e | ||
| assert "invalid target exits 2" "[ $EC -eq 2 ]" | ||
|
|
||
| echo "" | ||
| echo "test-gen-skills: $PASS/$TOTAL passed, $FAIL failed" | ||
| [ "$FAIL" -eq 0 ] && exit 0 || exit 1 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
rm -rf "$WORK"/*poses two significant issues:$WORKis ever empty or unset, this command expands torm -rf /*, which will attempt to delete the entire root filesystem..??*only matches dotfiles with at least two characters after the dot (e.g.,.ab), leaving single-character dotfiles (like.a) untouched.π‘ Recommendation
Simply delete and recreate the entire
$WORKdirectory. This is completely safe from therm -rf /*expansion risk, automatically cleans up all files (including all dotfiles), and is much simpler.