Files
breeze/tests/law_mutation_test.sh
waozi f1cc5be451 Update Arcade and complete pending Breeze integrations
Pin the latest pushed Arcade source and bundle its complete painted library artwork. Keep games as optional downloads and verify the embedded catalog plus a private launch smoke test.

Include pending profile sync, Telegram settings, Android push reconnection and breathing-control fixes with their tests and translations. Preserve saved design studies, storing their media in Git LFS.
2026-11-03 18:17:04 -03:00

244 lines
10 KiB
Bash
Executable File

#!/bin/sh
# Every deliberately broken implementation must be rejected by the laws, so
# the laws are known not to be vacuous. The unmutated tree must pass.
set -eu
ziran=${1:?pass the ziran command}
root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
work=$(mktemp -d)
cleanup() {
result=$?
trap - EXIT HUP INT TERM
if [ "$result" -ne 0 ] && [ -f "$work/out.err" ]; then
cat "$work/out.err" >&2
fi
rm -rf "$work"
exit "$result"
}
trap cleanup EXIT HUP INT TERM
fresh() {
rm -rf "$work/src"
mkdir -p "$work/src/app" "$work/src/storage"
cp "$root"/src/app/sync_retry.zi "$root"/src/app/sync_retry_laws.zi \
"$work/src/app/"
cp "$root"/src/app/practice_lifecycle.zi \
"$root"/src/app/practice_lifecycle_laws.zi "$work/src/app/"
cp "$root"/src/app/sync_recovery_policy.zi \
"$root"/src/app/sync_recovery_policy_laws.zi "$work/src/app/"
cp "$root"/src/storage/habit_merge_model.zi \
"$root"/src/storage/habit_merge_laws.zi "$work/src/storage/"
cp "$root"/src/storage/sync_restore_model.zi \
"$root"/src/storage/sync_restore_laws.zi "$work/src/storage/"
mkdir -p "$work/src/core"
cp "$root"/src/core/types.zi "$work/src/core/"
cp "$root"/src/app/modal_rules.zi "$root"/src/app/modal_rules_laws.zi \
"$work/src/app/"
cp "$root"/src/storage/sync_result.zi "$root"/src/storage/storage_layout.zi \
"$root"/src/storage/storage_layout_laws.zi "$root"/src/storage/app_records.zi "$work/src/storage/"
cp "$root"/src/guide.zi "$root"/src/guide_pager.zi \
"$root"/src/guide_laws.zi "$work/src/"
}
# Guide laws read Kryon's geometry and styles.
check_guide() {
"$ziran" check --root "$work/src" \
--module-path "$root/build/packages/kryon/src/ui" \
--module-path "$root/build/packages/ziran/std" \
"$work/src/guide_laws.zi" > "$work/out.json" 2> "$work/out.err"
}
mutate_guide() {
expression=$1 law=$2
fresh
sed -i "$expression" "$work/src/guide.zi"
if cmp -s "$root/src/guide.zi" "$work/src/guide.zi"; then
echo "mutation did not change guide.zi: $expression" >&2
exit 1
fi
if check_guide; then
echo "guide laws accepted mutation: $expression" >&2
exit 1
fi
if ! grep -q "law $law is disproved" "$work/out.err"; then
echo "mutation $expression did not disprove $law" >&2
cat "$work/out.err" >&2
exit 1
fi
# This counterexample is expected. Do not report it as the cause if a
# later independent SQL fixture fails during cleanup.
: > "$work/out.err"
}
check() {
"$ziran" check --root "$work/src" "$work/src/$1" > "$work/out.json" \
2> "$work/out.err"
}
fresh
check app/sync_retry_laws.zi
check app/practice_lifecycle_laws.zi
check app/sync_recovery_policy_laws.zi
check app/modal_rules_laws.zi
check storage/habit_merge_laws.zi
check storage/sync_restore_laws.zi
check storage/storage_layout_laws.zi
check_guide
# file, module to check, sed expression, expected disproved law
mutate() {
file=$1 module=$2 expression=$3 law=$4
fresh
sed -i "$expression" "$work/src/$file"
if cmp -s "$root/src/$file" "$work/src/$file"; then
echo "mutation did not change $file: $expression" >&2
exit 1
fi
if check "$module"; then
echo "laws accepted mutation: $file: $expression" >&2
exit 1
fi
if ! grep -q "law $law is disproved" "$work/out.err"; then
echo "mutation $expression did not disprove $law" >&2
cat "$work/out.err" >&2
exit 1
fi
}
sync=app/sync_retry.zi
mutate $sync app/sync_retry_laws.zi \
'0,/RetryDecision.{0, 0, 0}/s//RetryDecision.{0, 0, 1}/' SuccessResets
mutate $sync app/sync_retry_laws.zi \
's/if attempt == 2 { return 15 }/if attempt == 2 { return 16 }/' \
ChallengeRetries
mutate $sync app/sync_retry_laws.zi \
's/ ||$//; /result == cast(s32) SyncResult.SYNC_REQUEST_FAILED$/d' \
RequestRetries
mutate $sync app/sync_retry_laws.zi \
's/if attempt > 4 { return 4 }/if attempt > 5 { return 5 }/' \
AttemptStaysBounded
mutate $sync app/sync_retry_laws.zi \
's/return RetryDecision.{attempt, 0, 1}/return RetryDecision.{attempt, 0, 0}/' \
InvalidUrlStops
mutate $sync app/sync_retry_laws.zi \
's/ || retry_after_sign_in(result)//' AuthenticationFailureRetries
lifecycle=app/practice_lifecycle.zi
mutate $lifecycle app/practice_lifecycle_laws.zi \
's/if auto_paused == 0 \&\& session_paused == 0 {/if auto_paused == 0 {/' \
UserPauseIsNeverResumed
mutate $lifecycle app/practice_lifecycle_laws.zi \
's/LifecycleDecision.{background_active, 0, 0, 0, auto_paused}/LifecycleDecision.{background_active, 0, 1, 0, 1}/' \
DesktopNeverPauses
mutate $lifecycle app/practice_lifecycle_laws.zi \
's/if play_in_background != 0 \&\& activity_paused != 0 {/if play_in_background != 0 \&\& activity_paused != 0 \&\& background_active != 0 {/' \
BackgroundPlayKeepsRunning
mutate $lifecycle app/practice_lifecycle_laws.zi \
's/if play_in_background != 0 \&\& activity_paused != 0 {/if activity_paused != 0 {/' \
BackgroundPlayOffPauses
mutate $lifecycle app/practice_lifecycle_laws.zi \
's/if run != background_active {/if run == background_active {/' \
ChangeMatchesState
mutate $lifecycle app/practice_lifecycle_laws.zi \
's/} else if auto_paused != 0 {/} else if auto_paused != 0 || session_paused != 0 {/' \
ResumeOnlyOwnPause
recovery=app/sync_recovery_policy.zi
mutate $recovery app/sync_recovery_policy_laws.zi \
's/if identity_current != 0 \&\& succeeded != 0 {/if succeeded != 0 {/' \
OnlyCurrentAccountApplies
mutate $recovery app/sync_recovery_policy_laws.zi \
's/if stage <= SocialStageFriends || identity_current == 0 {/if stage <= SocialStageRequests || identity_current == 0 {/' \
RequiredFailureKeepsKnownData
mutate $recovery app/sync_recovery_policy_laws.zi \
's/if stage <= SocialStageFriends || identity_current == 0 {/if stage <= SocialStageFriends {/' \
SwitchedAccountStopsRefresh
mutate $recovery app/sync_recovery_policy_laws.zi \
's/if stage == SocialStageStreak {/if stage != SocialStageStreak {/' \
StreakFailureDropsOnlyStreak
mutate $recovery app/sync_recovery_policy_laws.zi \
's/(next == SocialStageAverage \&\& has_average == 0)/(next == SocialStageAverage \&\& has_average != 0)/' \
FinishesAfterStreakUnlessWhm
merge=storage/habit_merge_model.zi
mutate $merge storage/habit_merge_laws.zi \
's/if mine > theirs {/if mine < theirs {/' MergeKeepsMine
mutate $merge storage/habit_merge_laws.zi \
's/return HabitDayValue(HabitDayValue(a\[day\], b\[day\]), c\[day\])/return HabitDayValue(a[day], b[day])/' \
MergeAssociates
mutate $merge storage/habit_merge_laws.zi \
's/ return theirs$/ return theirs + 1/' MergeInventsNothing
# The real SQL must fail the same statements when it loses progress.
fresh
mkdir -p "$work/sql/src/storage"
cp "$root"/src/storage/storage_habit_sync.zi "$root"/src/storage/habit_sync_sql.zi \
"$root"/src/storage/schema_sql.zi "$work/sql/src/storage/"
HABIT_MERGE_ROOT="$work/sql" python3 "$root/tests/habit_merge_sql_test.py" > /dev/null
sed -i 's/completed=MAX(completed,/completed=MIN(completed,/' \
"$work/sql/src/storage/storage_habit_sync.zi"
if HABIT_MERGE_ROOT="$work/sql" python3 "$root/tests/habit_merge_sql_test.py" \
> /dev/null 2>&1; then
echo "SQL merge test accepted a merge that loses progress" >&2
exit 1
fi
restore=storage/sync_restore_model.zi
mutate $restore storage/sync_restore_laws.zi \
's/ if present != 0 {/ if present == 0 {/' RestoreKeepsEveryLocalChange
mutate $restore storage/sync_restore_laws.zi \
's/^ return OutboxAfterClear(queued_before)/ return 1/' \
RestoreQueuesOnlyLocalData
# The real restore SQL must fail the same statements when it leaves data out.
mkdir -p "$work/restore/src/storage"
cp "$root"/src/storage/sync_outbox.zi "$root"/src/storage/schema_sql.zi \
"$work/restore/src/storage/"
SYNC_RESTORE_ROOT="$work/restore" python3 \
"$root/tests/sync_restore_sql_test.py" > /dev/null
sed -i "s/FROM elist_items WHERE user_id/FROM elist_items WHERE 0=1 AND user_id/" \
"$work/restore/src/storage/sync_outbox.zi"
if SYNC_RESTORE_ROOT="$work/restore" python3 \
"$root/tests/sync_restore_sql_test.py" > /dev/null 2>&1; then
echo "restore test accepted a restore that leaves local data unqueued" >&2
exit 1
fi
modal=app/modal_rules.zi
mutate $modal app/modal_rules_laws.zi \
's/return screen == ScreenStart$/return screen == ScreenSettings/' \
MeditationSetupOnlyOnStart
mutate $modal app/modal_rules_laws.zi \
's/^ return true$/ return false/' OtherDialogsAppearAnywhere
mutate $modal app/modal_rules_laws.zi \
's/screen == ScreenHabitEdit || (screen == ScreenHabits \&\& habit_edit_tab)/screen == ScreenHabitEdit || screen == ScreenHabits/' \
DeleteHabitNeedsEditor
mutate storage/sync_result.zi app/sync_retry_laws.zi \
's/SYNC_AUTH_FAILED :: 7/SYNC_AUTH_FAILED :: 8/' WireAuthFailed
mutate storage/storage_layout.zi storage/storage_layout_laws.zi \
's/^CurrentDirectoryName :: "inbe"/CurrentDirectoryName :: "breathing"/' \
CurrentDirectoryIsInbe
mutate storage/storage_layout.zi storage/storage_layout_laws.zi \
's/^PreviousDatabaseEntry :: .*/PreviousDatabaseEntry :: "inbe-data\/inbe.db"/' \
HistoricalEntryStaysImportable
mutate storage/storage_layout.zi storage/storage_layout_laws.zi \
's/^LumiPrivateCollection :: .*/LumiPrivateCollection :: "private.inbe.v1.cells"/' \
LumiCollectionIsIsolated
mutate storage/storage_layout.zi storage/storage_layout_laws.zi \
's/^LumiPrivateKeyContext :: .*/LumiPrivateKeyContext :: "breathing-private-record-key-v1"/' \
LumiKeyIsSeparate
mutate storage/storage_layout.zi storage/storage_layout_laws.zi \
's/^LumiPrivateKeyID :: .*/LumiPrivateKeyID :: "breathing-main-1"/' \
LumiKeyIsSeparate
# A tap on finished text that shows it again instead of going on.
mutate_guide 's/ if typed < characters {/ if typed <= characters {/' \
TapStepsWhenTyped
# Typing that outlasts the voice clip.
mutate_guide 's/if clip_ms > 0 { return clip_ms }/if clip_ms > 0 { return clip_ms + 100 }/' \
TypingFollowsClip
# Text that is all there before the voice ends.
mutate_guide 's/if typing_ms <= 0 || elapsed_ms >= typing_ms { return characters }/if typing_ms <= 0 || elapsed_ms + 1 >= typing_ms { return characters }/' \
TextEndsWithClip
# Lumi hovering away from her bubble.
mutate_guide 's/place.lumi.x = place.tip.x - cast(float32)need/place.lumi.x = place.tip.x - cast(float32)lumi_width/' \
LumiBesideBubble
echo "law mutation test passed"