Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion test/integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,38 @@ echo "## idstack-learnings-search"
# Add a second learning of different type
$IDSTACK_DIR/bin/idstack-learnings-log '{"skill":"review","type":"pattern","key":"test2","insight":"pattern insight","confidence":7}'

# Add more learnings to test keyword search
$IDSTACK_DIR/bin/idstack-learnings-log '{"skill":"export","type":"technical","key":"canvas_export","insight":"Canvas requires specific API tokens","confidence":9}'
$IDSTACK_DIR/bin/idstack-learnings-log '{"skill":"review","type":"pattern","key":"rubric_design","insight":"Rubrics should be simple","confidence":8}'

check "returns results with --limit" \
"[ \$($IDSTACK_DIR/bin/idstack-learnings-search --limit 1 | wc -l | tr -d ' ') -eq 1 ]"

check "returns all when limit exceeds count" \
"[ \$($IDSTACK_DIR/bin/idstack-learnings-search --limit 99 | wc -l | tr -d ' ') -eq 2 ]"
"[ \$($IDSTACK_DIR/bin/idstack-learnings-search --limit 99 | wc -l | tr -d ' ') -eq 4 ]"

check "filters by --type" \
"$IDSTACK_DIR/bin/idstack-learnings-search --limit 10 --type operational | python3 -c \"import json,sys; d=json.loads(sys.stdin.readline()); assert d['type']=='operational'\""

check "filters by --keyword (hit)" \
"$IDSTACK_DIR/bin/idstack-learnings-search --keyword canvas | grep -q 'canvas_export'"

check "filters by --keyword (case insensitive)" \
"$IDSTACK_DIR/bin/idstack-learnings-search --keyword RuBrIc | grep -q 'rubric_design'"

check "filters by --keyword (miss)" \
"[ -z \"\$($IDSTACK_DIR/bin/idstack-learnings-search --keyword nonexistent_string)\" ]"

# Setup fake home and global learnings
mkdir -p "$TEST_DIR/fake_home/.idstack/global"
echo '{"skill":"import","type":"technical","key":"global_canvas","insight":"Global canvas insight","confidence":5}' > "$TEST_DIR/fake_home/.idstack/global/learnings.jsonl"

check "cross-project includes global learnings" \
"HOME=\"$TEST_DIR/fake_home\" $IDSTACK_DIR/bin/idstack-learnings-search --cross-project --keyword global_canvas | grep -q '\"_source\": \"global\"'"
Comment on lines +96 to +97

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 grep to assert JSON structure (like checking for "_source": "global") is fragile because it is sensitive to whitespace, key ordering, and formatting changes (e.g., if the JSON serializer configuration changes to omit spaces around colons).

Since Python is already used in other test assertions in this file, it is more robust to parse the output as JSON and assert the field value directly.

Suggested change
check "cross-project includes global learnings" \
"HOME=\"$TEST_DIR/fake_home\" $IDSTACK_DIR/bin/idstack-learnings-search --cross-project --keyword global_canvas | grep -q '\"_source\": \"global\"'"
check "cross-project includes global learnings" \
"HOME=\"$TEST_DIR/fake_home\" $IDSTACK_DIR/bin/idstack-learnings-search --cross-project --keyword global_canvas | python3 -c \"import json,sys; d=json.loads(sys.stdin.readline()); assert d.get('_source')=='global'\""


check "without cross-project excludes global learnings" \
"[ -z \"\$(HOME=\"$TEST_DIR/fake_home\" $IDSTACK_DIR/bin/idstack-learnings-search --keyword global_canvas)\" ]"

check "no file returns empty" \
"rm -f .idstack/learnings.jsonl && [ -z \"\$($IDSTACK_DIR/bin/idstack-learnings-search --limit 3)\" ]"

Expand Down