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
11 changes: 10 additions & 1 deletion test/integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,23 @@ check "creates .idstack/ and timeline.jsonl" \
check "appends valid JSON with ts field" \
"python3 -c \"import json; d=json.loads(open('.idstack/timeline.jsonl').readline()); assert 'ts' in d and d['skill']=='test'\""

check "preserves caller-supplied ts field" \
"$IDSTACK_DIR/bin/idstack-timeline-log '{\"skill\":\"test\",\"ts\":\"2020-01-01T00:00:00Z\"}' && grep -q '\"ts\": \"2020-01-01T00:00:00Z\"' .idstack/timeline.jsonl"

check "handles invalid JSON gracefully" \
"$IDSTACK_DIR/bin/idstack-timeline-log '{\"skill\":\"bad\",}' && grep -q '\"raw\": \"{\\\\\\\"skill\\\\\\\":\\\\\\\"bad\\\\\\\",}\"' .idstack/timeline.jsonl"

check "fallback to bash works when python3 is missing" \
"mkdir -p mockbin && for cmd in bash sed date mkdir env tr wc grep echo cat ls rm pwd dirname chmod; do ln -s \$(which \$cmd) mockbin/\$cmd 2>/dev/null || true; done && PATH=\"\$PWD/mockbin\" $IDSTACK_DIR/bin/idstack-timeline-log '{\"skill\":\"no_py\"}' && grep -q '\"skill\":\"no_py\",\"ts\":' .idstack/timeline.jsonl"
Comment on lines +45 to +46

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current approach to mocking a missing python3 is fragile and complex. It attempts to recreate a restricted PATH by symlinking 14 different commands. This has several issues:

  1. It relies on which, which is non-standard and may not be available in minimal CI environments.
  2. If idstack-timeline-log uses any other command not in this list (e.g., sleep, uname, awk), the test will fail.
  3. It can create circular symlinks if any of the commands are shell builtins.

A much simpler and more robust approach is to prepend a mock python3 executable that exits with an error to the existing PATH. This simulates python3 being missing/broken while keeping all other system commands available.

Suggested change
check "fallback to bash works when python3 is missing" \
"mkdir -p mockbin && for cmd in bash sed date mkdir env tr wc grep echo cat ls rm pwd dirname chmod; do ln -s \$(which \$cmd) mockbin/\$cmd 2>/dev/null || true; done && PATH=\"\$PWD/mockbin\" $IDSTACK_DIR/bin/idstack-timeline-log '{\"skill\":\"no_py\"}' && grep -q '\"skill\":\"no_py\",\"ts\":' .idstack/timeline.jsonl"
check "fallback to bash works when python3 is missing" \
"mkdir -p mockbin && printf '#!/bin/sh\nexit 127\n' > mockbin/python3 && chmod +x mockbin/python3 && PATH=\"\$PWD/mockbin:\$PATH\" $IDSTACK_DIR/bin/idstack-timeline-log '{\"skill\":\"no_py\"}' && grep -q '\"skill\":\"no_py\",\"ts\":' .idstack/timeline.jsonl"


check "handles empty arg without error" \
"$IDSTACK_DIR/bin/idstack-timeline-log ''"

check "handles no arg without error" \
"$IDSTACK_DIR/bin/idstack-timeline-log"

check "multiple appends create multiple lines" \
"$IDSTACK_DIR/bin/idstack-timeline-log '{\"skill\":\"second\",\"event\":\"completed\"}' && [ \$(wc -l < .idstack/timeline.jsonl | tr -d ' ') -eq 2 ]"
"$IDSTACK_DIR/bin/idstack-timeline-log '{\"skill\":\"second\",\"event\":\"completed\"}' && [ \$(wc -l < .idstack/timeline.jsonl | tr -d ' ') -gt 1 ]"
Comment on lines 54 to +55

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

Changing the assertion from -eq 2 to -gt 1 weakens the test because it no longer verifies that exactly two lines are created by the multiple appends. Instead, it passes as long as there is more than one line, which is already true due to the state left by previous tests in the same file.

To ensure test isolation and keep the strict check, we should clean/truncate the timeline file before running this test.

Suggested change
check "multiple appends create multiple lines" \
"$IDSTACK_DIR/bin/idstack-timeline-log '{\"skill\":\"second\",\"event\":\"completed\"}' && [ \$(wc -l < .idstack/timeline.jsonl | tr -d ' ') -eq 2 ]"
"$IDSTACK_DIR/bin/idstack-timeline-log '{\"skill\":\"second\",\"event\":\"completed\"}' && [ \$(wc -l < .idstack/timeline.jsonl | tr -d ' ') -gt 1 ]"
check "multiple appends create multiple lines" \
"rm -f .idstack/timeline.jsonl && $IDSTACK_DIR/bin/idstack-timeline-log '{\"skill\":\"first\"}' && $IDSTACK_DIR/bin/idstack-timeline-log '{\"skill\":\"second\",\"event\":\"completed\"}' && [ \$(wc -l < .idstack/timeline.jsonl | tr -d ' ') -eq 2 ]"


echo ""

Expand Down