feat: add CLI wrapper script for the reddit-post sidecar
Implements run.sh with argument parsing (--username, --password, --subreddit, --title, --body, optional --headed), environment variable mapping to Task 2's env contract, Playwright invocation with proper exit-code capture via set +e, and result file output to stdout. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
f794a5ae83
commit
a95440751f
Executable
+63
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
USERNAME=""
|
||||
PASSWORD=""
|
||||
SUBREDDIT=""
|
||||
TITLE=""
|
||||
BODY=""
|
||||
HEADLESS_FLAG="true"
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--username=*) USERNAME="${arg#*=}" ;;
|
||||
--password=*) PASSWORD="${arg#*=}" ;;
|
||||
--subreddit=*) SUBREDDIT="${arg#*=}" ;;
|
||||
--title=*) TITLE="${arg#*=}" ;;
|
||||
--body=*) BODY="${arg#*=}" ;;
|
||||
--headed) HEADLESS_FLAG="false" ;;
|
||||
*)
|
||||
echo "{\"success\": false, \"error\": \"Unknown argument: $arg\"}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
MISSING=""
|
||||
[ -z "$USERNAME" ] && MISSING="$MISSING --username"
|
||||
[ -z "$PASSWORD" ] && MISSING="$MISSING --password"
|
||||
[ -z "$SUBREDDIT" ] && MISSING="$MISSING --subreddit"
|
||||
[ -z "$TITLE" ] && MISSING="$MISSING --title"
|
||||
[ -z "$BODY" ] && MISSING="$MISSING --body"
|
||||
|
||||
if [ -n "$MISSING" ]; then
|
||||
echo "{\"success\": false, \"error\": \"Missing required argument(s):$MISSING\"}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export REDDIT_USERNAME="$USERNAME"
|
||||
export REDDIT_PASSWORD="$PASSWORD"
|
||||
export SUBREDDIT="$SUBREDDIT"
|
||||
export POST_TITLE="$TITLE"
|
||||
export POST_BODY="$BODY"
|
||||
export HEADLESS="$HEADLESS_FLAG"
|
||||
|
||||
set +e
|
||||
npx playwright test tests/reddit-post.spec.js
|
||||
PLAYWRIGHT_EXIT_CODE=$?
|
||||
set -e
|
||||
|
||||
RESULT_FILE="test-results/result.json"
|
||||
|
||||
if [ -f "$RESULT_FILE" ]; then
|
||||
cat "$RESULT_FILE"
|
||||
echo
|
||||
else
|
||||
echo "{\"success\": false, \"error\": \"Test did not produce a result file\"}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit "$PLAYWRIGHT_EXIT_CODE"
|
||||
Reference in New Issue
Block a user