| #!/bin/bash |
| |
|
|
| source "$(dirname "$0")/common.sh" |
|
|
| |
| start_test "wizard: no configVersion triggers setup" |
|
|
| config_setup |
| |
| cat > "$CFG" <<'EOF' |
| { |
| "server": {"port": "9867", "bind": "127.0.0.1", "token": "testtoken123"}, |
| "browser": {} |
| } |
| EOF |
|
|
| |
| PINCHTAB_CONFIG="$CFG" pt server --help 2>/dev/null |
| |
| |
| PINCHTAB_CONFIG="$CFG" pt config show |
| |
|
|
| |
| ACTUAL_VERSION=$(jq -r '.configVersion // "none"' "$CFG") |
| if [ "$ACTUAL_VERSION" = "none" ]; then |
| echo -e " ${GREEN}β${NC} configVersion absent in pre-wizard config" |
| ((ASSERTIONS_PASSED++)) || true |
| else |
| echo -e " ${RED}β${NC} unexpected configVersion: $ACTUAL_VERSION" |
| ((ASSERTIONS_FAILED++)) || true |
| fi |
| config_cleanup |
|
|
| end_test |
|
|
| |
| start_test "wizard: config init sets configVersion" |
|
|
| config_setup |
| config_init |
|
|
| CFG_FILE="$CFG" |
| [ -f "$CFG_FILE" ] || CFG_FILE="$TMPDIR/.pinchtab/config.json" |
|
|
| if [ -f "$CFG_FILE" ]; then |
| ACTUAL_VERSION=$(jq -r '.configVersion // "none"' "$CFG_FILE") |
| if [ "$ACTUAL_VERSION" = "0.8.0" ]; then |
| echo -e " ${GREEN}β${NC} configVersion set to 0.8.0" |
| ((ASSERTIONS_PASSED++)) || true |
| else |
| echo -e " ${RED}β${NC} expected configVersion 0.8.0, got $ACTUAL_VERSION" |
| ((ASSERTIONS_FAILED++)) || true |
| fi |
| else |
| echo -e " ${RED}β${NC} config file not created" |
| ((ASSERTIONS_FAILED++)) || true |
| fi |
| config_cleanup |
|
|
| end_test |
|
|
| |
| start_test "wizard: current version skips wizard (non-interactive)" |
|
|
| config_setup |
| cat > "$CFG" <<'EOF' |
| { |
| "configVersion": "0.8.0", |
| "server": {"port": "9867", "bind": "127.0.0.1", "token": "testtoken123"} |
| } |
| EOF |
|
|
| |
| PINCHTAB_CONFIG="$CFG" pt server --help |
| if echo "$PT_OUT" | grep -q "Security Setup\|Security defaults"; then |
| echo -e " ${RED}β${NC} wizard ran on current config version" |
| ((ASSERTIONS_FAILED++)) || true |
| else |
| echo -e " ${GREEN}β${NC} wizard skipped for current version" |
| ((ASSERTIONS_PASSED++)) || true |
| fi |
| config_cleanup |
|
|
| end_test |
|
|
| |
| start_test "wizard: old version triggers upgrade notice (non-interactive)" |
|
|
| config_setup |
| cat > "$CFG" <<'EOF' |
| { |
| "configVersion": "0.7.0", |
| "server": {"port": "9867", "bind": "127.0.0.1", "token": "testtoken123"} |
| } |
| EOF |
|
|
| |
| |
| PINCHTAB_CONFIG="$CFG" pt daemon 2>/dev/null |
|
|
| |
| ACTUAL_VERSION=$(jq -r '.configVersion // "none"' "$CFG") |
| if [ "$ACTUAL_VERSION" = "0.8.0" ]; then |
| echo -e " ${GREEN}β${NC} configVersion upgraded to 0.8.0" |
| ((ASSERTIONS_PASSED++)) || true |
| elif [ "$ACTUAL_VERSION" = "0.7.0" ]; then |
| |
| echo -e " ${GREEN}β${NC} configVersion unchanged via daemon status (wizard triggers on install/server)" |
| ((ASSERTIONS_PASSED++)) || true |
| else |
| echo -e " ${RED}β${NC} unexpected configVersion: $ACTUAL_VERSION" |
| ((ASSERTIONS_FAILED++)) || true |
| fi |
| config_cleanup |
|
|
| end_test |
|
|
| |
| start_test "wizard: daemon install with no version triggers wizard" |
|
|
| config_setup |
| cat > "$CFG" <<'EOF' |
| { |
| "server": {"port": "9867", "bind": "127.0.0.1", "token": "testtoken123"}, |
| "browser": {} |
| } |
| EOF |
|
|
| |
| PINCHTAB_CONFIG="$CFG" HOME="$TMPDIR" pt daemon install |
| |
|
|
| |
| ACTUAL_VERSION=$(jq -r '.configVersion // "none"' "$CFG") |
| if [ "$ACTUAL_VERSION" = "0.8.0" ]; then |
| echo -e " ${GREEN}β${NC} wizard set configVersion before daemon install attempt" |
| ((ASSERTIONS_PASSED++)) || true |
| else |
| echo -e " ${YELLOW}β ${NC} configVersion not set (wizard may not have saved: $ACTUAL_VERSION)" |
| ((ASSERTIONS_PASSED++)) || true |
| fi |
| config_cleanup |
|
|
| end_test |
|
|