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
29 changes: 29 additions & 0 deletions test/integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,34 @@ check "regenerate fixes staleness" \
"$IDSTACK_DIR/bin/idstack-gen-skills && $IDSTACK_DIR/bin/idstack-gen-skills --dry-run"

echo ""
# --- idstack-learnings-promote ---
echo "## idstack-learnings-promote"

FAKE_HOME="$TEST_DIR/fake_home"
mkdir -p "$FAKE_HOME"

check "fails if no key provided" \
"! $IDSTACK_DIR/bin/idstack-learnings-promote"

check "fails if no local learnings found" \
"rm -f .idstack/learnings.jsonl && ! $IDSTACK_DIR/bin/idstack-learnings-promote my-key"

mkdir -p .idstack
echo '{"skill":"test-skill","key":"my-key","type":"pattern","insight":"hello"}' > .idstack/learnings.jsonl

check "fails if key not found" \
"! $IDSTACK_DIR/bin/idstack-learnings-promote wrong-key"

check "promotes learning with unknown project" \
"HOME=\"$FAKE_HOME\" $IDSTACK_DIR/bin/idstack-learnings-promote my-key && [ -f \"$FAKE_HOME/.idstack/global/learnings.jsonl\" ] && python3 -c \"import json; d=json.loads(open('$FAKE_HOME/.idstack/global/learnings.jsonl').readlines()[-1]); assert d['_source_project'] == 'unknown'\""

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

Passing the $FAKE_HOME path directly inside the Python code string can lead to syntax errors or failures if the path contains single quotes or other special characters (since it is enclosed in single quotes '...' in the Python snippet).

A more robust approach is to pass the file path as a command-line argument to Python and access it via sys.argv[1]. This keeps the Python code string static and avoids quoting/escaping issues.

Suggested change
"HOME=\"$FAKE_HOME\" $IDSTACK_DIR/bin/idstack-learnings-promote my-key && [ -f \"$FAKE_HOME/.idstack/global/learnings.jsonl\" ] && python3 -c \"import json; d=json.loads(open('$FAKE_HOME/.idstack/global/learnings.jsonl').readlines()[-1]); assert d['_source_project'] == 'unknown'\""
"HOME=\"$FAKE_HOME\" $IDSTACK_DIR/bin/idstack-learnings-promote my-key && [ -f \"$FAKE_HOME/.idstack/global/learnings.jsonl\" ] && python3 -c \"import sys, json; d=json.loads(open(sys.argv[1]).readlines()[-1]); assert d['_source_project'] == 'unknown'\" \"$FAKE_HOME/.idstack/global/learnings.jsonl\""


echo '{"project_name":"my-test-proj"}' > .idstack/project.json
echo '{"skill":"test-skill","key":"key2","type":"pattern","insight":"hello2"}' >> .idstack/learnings.jsonl

check "promotes learning with known project" \
"HOME=\"$FAKE_HOME\" $IDSTACK_DIR/bin/idstack-learnings-promote key2 && python3 -c \"import json; d=json.loads(open('$FAKE_HOME/.idstack/global/learnings.jsonl').readlines()[-1]); assert d['_source_project'] == 'my-test-proj'\""

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

Similarly to the previous test, passing the $FAKE_HOME path directly inside the Python code string can fail if the path contains single quotes. Passing it as an argument via sys.argv[1] is much more robust.

Suggested change
"HOME=\"$FAKE_HOME\" $IDSTACK_DIR/bin/idstack-learnings-promote key2 && python3 -c \"import json; d=json.loads(open('$FAKE_HOME/.idstack/global/learnings.jsonl').readlines()[-1]); assert d['_source_project'] == 'my-test-proj'\""
"HOME=\"$FAKE_HOME\" $IDSTACK_DIR/bin/idstack-learnings-promote key2 && python3 -c \"import sys, json; d=json.loads(open(sys.argv[1]).readlines()[-1]); assert d['_source_project'] == 'my-test-proj'\" \"$FAKE_HOME/.idstack/global/learnings.jsonl\""


echo ""

echo "Results: $PASS/$TOTAL passed, $FAIL failed"
[ "$FAIL" -eq 0 ] && exit 0 || exit 1