wake-alarm/scripts/free_days_interop/check.sh
Krzysztof kuhy Rudnicki 758b2976b8 Gate the free-day rules against the Python package, and fix two picker paths
showDatePicker asserts that initialDate satisfies selectableDayPredicate,
so with today already free the picker asserted in debug and, in release,
pre-selected a disabled day. The cursor now starts on the first non-free
day. And the reason dialog had no Cancel: a barrier tap marked the day
anyway. Both covered by widget tests; the first fails without the fix.

The cross-language check that proved the Dart port was a one-off probe,
deleted after it ran. It is now scripts/free_days_interop/check.sh, a
pre-commit hook on both inputs: Dart writes one pool through every policy
branch, Python replays the same edits into a scratch pool, and every
semantic reading has to agree. The Python package is the oracle -- Dart's
own count compared to what Python reads from Dart's file cannot see a
drift in what Dart writes. Proved by dropping the sticky consumed flag
from release: remaining dart=33 python=32.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019pBgaXSJKyY3DarYpDatDF
2026-09-11 13:53:56 +02:00

59 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# ============================================================================
# Cross-language gate for the free-day pool.
#
# phone_app/lib/services/free_day_pool.dart reimplements the rules that
# ~/utils/freedays (Python) owns. Two implementations of one policy drift,
# and a Dart-only test cannot see it: it is self-consistent with the port.
# This writes a pool through the Dart rules and reads it back through the
# Python ones, and fails on any disagreement about what is free, what is
# spent and how many days are left.
#
# Requires the freedays venv that install.sh in ~/utils/freedays creates.
#
# Usage: scripts/free_days_interop/check.sh
# ============================================================================
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
readonly SCRIPT_DIR REPO_DIR
readonly FREEDAYS_PYTHON="${FREEDAYS_PYTHON:-$HOME/.local/share/freedays/venv/bin/python}"
TEMP_DIR=""
cleanup() {
if [[ -n "$TEMP_DIR" && -d "$TEMP_DIR" ]]; then
rm -rf "$TEMP_DIR"
fi
}
trap cleanup EXIT
validate_requirements() {
if [[ ! -x "$FREEDAYS_PYTHON" ]]; then
echo "Error: no freedays venv at $FREEDAYS_PYTHON (run ~/utils/freedays/install.sh)" >&2
exit 1
fi
command -v flutter >/dev/null || { echo "Error: flutter not on PATH" >&2; exit 1; }
}
main() {
validate_requirements
TEMP_DIR="$(mktemp -d)"
local pool="$TEMP_DIR/free_days.json"
echo "== free-day interop: Dart writes =="
(
cd "$REPO_DIR/phone_app"
FREE_DAYS_INTEROP_OUT="$pool" flutter test test/free_day_interop_writer_test.dart \
| tail -1
)
[[ -s "$pool" ]] || { echo "Error: Dart wrote no fixture" >&2; exit 1; }
echo "== free-day interop: Python reads =="
"$FREEDAYS_PYTHON" "$SCRIPT_DIR/verify.py" "$pool"
}
main "$@"