From a95440751fc2889fa3da4f34cd5b5ee13b4eb158 Mon Sep 17 00:00:00 2001 From: Doar Mihai Date: Sat, 18 Jul 2026 18:42:08 +0300 Subject: [PATCH] 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 --- sidecars/reddit-post/run.sh | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 sidecars/reddit-post/run.sh diff --git a/sidecars/reddit-post/run.sh b/sidecars/reddit-post/run.sh new file mode 100755 index 0000000..aebc038 --- /dev/null +++ b/sidecars/reddit-post/run.sh @@ -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"