-
Notifications
You must be signed in to change notification settings - Fork 5
π§ͺ Add tests for idstack-timeline-log #47
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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" | ||||||||||||
|
|
||||||||||||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing the assertion from To ensure test isolation and keep the strict check, we should clean/truncate the timeline file before running this test.
Suggested change
|
||||||||||||
|
|
||||||||||||
| echo "" | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
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.
The current approach to mocking a missing
python3is fragile and complex. It attempts to recreate a restrictedPATHby symlinking 14 different commands. This has several issues:which, which is non-standard and may not be available in minimal CI environments.idstack-timeline-loguses any other command not in this list (e.g.,sleep,uname,awk), the test will fail.A much simpler and more robust approach is to prepend a mock
python3executable that exits with an error to the existingPATH. This simulatespython3being missing/broken while keeping all other system commands available.