mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-29 14:03:21 +01:00
Compare commits
No commits in common. "66160cd6daf12414335d7b69d05cf49345e507cc" and "c4d5631054fd9c17aebf323c282e843afd5db4a7" have entirely different histories.
66160cd6da
...
c4d5631054
@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"title": "i3 bar: automation_tutor block renamed to tutor",
|
|
||||||
"objective": "The bar's tutor block reads ~/.local/share/tutor/ledger.json and a click runs ~/src/tutor/run.sh; the daily-limits renderers show the gear for earned_time 0.9.0's 'tutor' earner.",
|
|
||||||
"acceptance_criteria": [
|
|
||||||
"test_i3blocks_tutor.sh passes (counts, hidden at 4/4, unreadable ledger, click)",
|
|
||||||
"test_i3blocks_gaming_budget.sh passes",
|
|
||||||
"~/.config/i3blocks/tutor.sh prints 'tutor n/4' from the live ledger at the new path"
|
|
||||||
],
|
|
||||||
"out_of_scope": [
|
|
||||||
"What the block counts (rows vs minutes) -- unchanged",
|
|
||||||
"The tutor itself (kuhyx/tutor)"
|
|
||||||
],
|
|
||||||
"verifier": "bash linux_configuration/tests/test_i3blocks_tutor.sh; bash linux_configuration/tests/test_i3blocks_gaming_budget.sh"
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
{
|
|
||||||
"intent": "The i3 tutor block shows today's credited tutor minutes against the 60-minute daily cap; it used to count ledger rows against 4 and hid after 4 credited minutes since earned_time 0.8.0 made each row a minute count.",
|
|
||||||
"scope": [
|
|
||||||
"linux_configuration/i3blocks/tutor.sh, linux_configuration/tests/test_i3blocks_tutor.sh",
|
|
||||||
"Non-goal: no HMAC check (earned_time stays the authority)"
|
|
||||||
],
|
|
||||||
"changes": [
|
|
||||||
"Sum detail.minutes of today's credit rows (legacy rows without it count 15, as earned_time does); TARGET 4 -> 60",
|
|
||||||
"Test fixture takes day:kind[:minutes]; new cases for summing, legacy rows and the 60/60 hidden state"
|
|
||||||
],
|
|
||||||
"verification": [
|
|
||||||
{
|
|
||||||
"command": "bash linux_configuration/tests/test_i3blocks_tutor.sh",
|
|
||||||
"result": "pass",
|
|
||||||
"evidence": "tutor block: all checks passed"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"command": "bash linux_configuration/i3blocks/tutor.sh",
|
|
||||||
"result": "pass",
|
|
||||||
"evidence": "⚙ tutor 0/60 on the live ledger; same jq on 2026-10-11 gives 60, matching earned_time's 60 units that day"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"risks": [
|
|
||||||
"A ledger row with non-numeric minutes would make jq fail and show the orange 'ledger unreadable' state"
|
|
||||||
],
|
|
||||||
"rollback": [
|
|
||||||
"git revert the commit; the block goes back to counting rows / 4"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -1,36 +0,0 @@
|
|||||||
{
|
|
||||||
"intent": "The automation tutor is now just Tutor (own repo ~/src/tutor, data ~/.local/share/tutor, earned_time 0.9.0 earner 'tutor'); the i3 bar follows the rename.",
|
|
||||||
"scope": [
|
|
||||||
"linux_configuration/i3blocks/tutor.sh (was automation_tutor.sh), the [tutor] stanza in linux_configuration/i3blocks/config, linux_configuration/tests/test_i3blocks_tutor.sh",
|
|
||||||
"gaming_budget.sh and shutdown_countdown.sh icon maps: earner 'tutor' gets the same gear as 'automation'",
|
|
||||||
"Non-goal: no change to what the block counts (still today's credit rows / 4)"
|
|
||||||
],
|
|
||||||
"changes": [
|
|
||||||
"Ledger default ~/.local/share/tutor/ledger.json (override TUTOR_LEDGER); click runs ~/src/tutor/run.sh (override TUTOR_RUN)",
|
|
||||||
"Block and test renamed; ~/.config/i3blocks/tutor.sh symlink replaces automation_tutor.sh",
|
|
||||||
"tutor: \"⚙\" added beside automation in the two daily-limits renderers"
|
|
||||||
],
|
|
||||||
"verification": [
|
|
||||||
{
|
|
||||||
"command": "bash linux_configuration/tests/test_i3blocks_tutor.sh",
|
|
||||||
"result": "pass",
|
|
||||||
"evidence": "tutor block: all checks passed"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"command": "bash linux_configuration/tests/test_i3blocks_gaming_budget.sh",
|
|
||||||
"result": "pass",
|
|
||||||
"evidence": "All gaming_budget checks passed."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"command": "~/.config/i3blocks/tutor.sh",
|
|
||||||
"result": "pass",
|
|
||||||
"evidence": "⚙ tutor 0/4 (live ledger at the new path)"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"risks": [
|
|
||||||
"The i3blocks config is symlinked, so the [tutor] stanza is live on the next i3blocks reload; until then the old stanza points at a removed symlink"
|
|
||||||
],
|
|
||||||
"rollback": [
|
|
||||||
"git revert the commit and re-link ~/.config/i3blocks/automation_tutor.sh"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -1,24 +1,23 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Tutor status for i3blocks: today's credited tutor minutes.
|
# Automation tutor status for i3blocks: today's credited 15-minute blocks.
|
||||||
#
|
#
|
||||||
# A click runs ~/src/tutor/run.sh, which starts the tutor if it is down and
|
# A click runs plc-lab's run.sh, which starts the tutor if it is down and
|
||||||
# opens it in the browser -- nobody has to remember the port. Hidden once the
|
# opens it in the browser -- nobody has to remember the port. Hidden once all
|
||||||
# daily cap is in: nothing left to earn, nothing to click.
|
# four blocks are in: nothing left to earn, nothing to click.
|
||||||
#
|
#
|
||||||
# Sums detail.minutes of the ledger's credit rows dated today (legacy rows
|
# Counts the tutor ledger's credit rows dated today. It does not check their
|
||||||
# without it count 15, as earned_time does). It does not check their
|
|
||||||
# HMAC (that needs the key and Python); earned_time does, so this is a
|
# HMAC (that needs the key and Python); earned_time does, so this is a
|
||||||
# display, never the authority on what was paid.
|
# display, never the authority on what was paid.
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
readonly LEDGER="${TUTOR_LEDGER:-$HOME/.local/share/tutor/ledger.json}"
|
readonly LEDGER="${AUTOMATION_TUTOR_LEDGER:-$HOME/.local/share/automation_tutor/ledger.json}"
|
||||||
# i3blocks' PATH has no ~/src: absolute path.
|
# i3blocks' PATH has no ~/src: absolute path.
|
||||||
readonly RUN="${TUTOR_RUN:-$HOME/src/tutor/run.sh}"
|
readonly RUN="${AUTOMATION_TUTOR_RUN:-$HOME/src/plc-lab/run.sh}"
|
||||||
readonly TARGET=60 # earned_time daily cap, minutes
|
readonly TARGET=4
|
||||||
|
|
||||||
readonly YELLOW='#F1FA8C'
|
readonly YELLOW='#F1FA8C'
|
||||||
readonly ORANGE='#FFB86C'
|
readonly ORANGE='#FFB86C'
|
||||||
@ -38,19 +37,19 @@ if ! command -v jq >/dev/null 2>&1; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
printf -v today '%(%Y-%m-%d)T' -1
|
printf -v today '%(%Y-%m-%d)T' -1
|
||||||
done_minutes=0
|
done_blocks=0
|
||||||
# No ledger yet is a real zero: the tutor creates it on the first credit.
|
# No ledger yet is a real zero: the tutor creates it on the first block.
|
||||||
if [[ -e $LEDGER ]]; then
|
if [[ -e $LEDGER ]]; then
|
||||||
if ! done_minutes=$(jq --arg d "$today" \
|
if ! done_blocks=$(jq --arg d "$today" \
|
||||||
'[.entries[] | select(.kind == "credit" and .day == $d) | (.detail.minutes // 15)] | add // 0 | floor' \
|
'[.entries[] | select(.kind == "credit" and .day == $d)] | length' \
|
||||||
"$LEDGER" 2>/dev/null); then
|
"$LEDGER" 2>/dev/null); then
|
||||||
emit '⚙ tutor: ledger unreadable' '⚙ ?' "$ORANGE"
|
emit '⚙ tutor: ledger unreadable' '⚙ ?' "$ORANGE"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ((done_minutes >= TARGET)); then
|
if ((done_blocks >= TARGET)); then
|
||||||
emit '' '' "$YELLOW"
|
emit '' '' "$YELLOW"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
emit "⚙ tutor ${done_minutes}/${TARGET}" "⚙ ${done_minutes}/${TARGET}" "$YELLOW"
|
emit "⚙ tutor ${done_blocks}/${TARGET}" "⚙ ${done_blocks}/${TARGET}" "$YELLOW"
|
||||||
@ -63,8 +63,8 @@ interval=30
|
|||||||
command=~/.config/i3blocks/book_guard.sh
|
command=~/.config/i3blocks/book_guard.sh
|
||||||
interval=30
|
interval=30
|
||||||
|
|
||||||
[tutor]
|
[automation_tutor]
|
||||||
command=~/.config/i3blocks/tutor.sh
|
command=~/.config/i3blocks/automation_tutor.sh
|
||||||
interval=30
|
interval=30
|
||||||
|
|
||||||
[issue_dashboard]
|
[issue_dashboard]
|
||||||
|
|||||||
@ -54,7 +54,7 @@ render_limits() {
|
|||||||
def hm: . as $m
|
def hm: . as $m
|
||||||
| "\($m / 60 | floor)h\($m % 60 | tostring | if length < 2 then "0" + . else . end)";
|
| "\($m / 60 | floor)h\($m % 60 | tostring | if length < 2 then "0" + . else . end)";
|
||||||
def bonus_hm: if . < 60 then "\(.)m" else hm | sub("h00$"; "h") end;
|
def bonus_hm: if . < 60 then "\(.)m" else hm | sub("h00$"; "h") end;
|
||||||
{workout: "💪", leetcode: "🧩", reading: "📖", anki: "🗂", automation: "⚙", tutor: "⚙"} as $icon
|
{workout: "💪", leetcode: "🧩", reading: "📖", anki: "🗂", automation: "⚙"} as $icon
|
||||||
| .gaming as $g
|
| .gaming as $g
|
||||||
| ([.earners[] | select(.status != "done" and .gaming_minutes > 0)
|
| ([.earners[] | select(.status != "done" and .gaming_minutes > 0)
|
||||||
| "+\($icon[.name] // .label)\(if .status == "unknown" then "?" else "" end)\(.gaming_minutes | bonus_hm)"]
|
| "+\($icon[.name] // .label)\(if .status == "unknown" then "?" else "" end)\(.gaming_minutes | bonus_hm)"]
|
||||||
|
|||||||
@ -179,7 +179,7 @@ render_limits() {
|
|||||||
def bonus_hm: . as $m
|
def bonus_hm: . as $m
|
||||||
| if $m < 60 then "\($m)m"
|
| if $m < 60 then "\($m)m"
|
||||||
else "\($m / 60 | floor)h" + ($m % 60 | if . == 0 then "" else "\(.)" | if length < 2 then "0" + . else . end end) end;
|
else "\($m / 60 | floor)h" + ($m % 60 | if . == 0 then "" else "\(.)" | if length < 2 then "0" + . else . end end) end;
|
||||||
{workout: "💪", leetcode: "🧩", reading: "📖", anki: "🗂", automation: "⚙", tutor: "⚙"} as $icon
|
{workout: "💪", leetcode: "🧩", reading: "📖", anki: "🗂", automation: "⚙"} as $icon
|
||||||
| (.earners | map({(.name): .}) | add // {}) as $by
|
| (.earners | map({(.name): .}) | add // {}) as $by
|
||||||
| (.shutdown.applied // .shutdown.resolved) as $time
|
| (.shutdown.applied // .shutdown.resolved) as $time
|
||||||
| (.shutdown.ceiling) as $ceiling
|
| (.shutdown.ceiling) as $ceiling
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Behaviour tests for the i3blocks tutor block: today's credited
|
# Behaviour tests for the i3blocks automation_tutor block: today's credit
|
||||||
# minutes, the hidden 60/60 state, the unreadable-ledger warning and the click.
|
# count, the hidden 4/4 state, the unreadable-ledger warning and the click.
|
||||||
# The ledger is a fixture and run.sh is a stub, so nothing reads the real
|
# The ledger is a fixture and run.sh is a stub, so nothing reads the real
|
||||||
# ledger and no tutor or browser is ever started.
|
# ledger and no tutor or browser is ever started.
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
|
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
|
||||||
REPO_DIR=$(cd -- "$SCRIPT_DIR/.." && pwd)
|
REPO_DIR=$(cd -- "$SCRIPT_DIR/.." && pwd)
|
||||||
BLOCK="$REPO_DIR/i3blocks/tutor.sh"
|
BLOCK="$REPO_DIR/i3blocks/automation_tutor.sh"
|
||||||
TMP_DIR=$(mktemp -d)
|
TMP_DIR=$(mktemp -d)
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
@ -30,7 +30,7 @@ assert_eq() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf '{}' | jq -e . >/dev/null 2>&1 ||
|
printf '{}' | jq -e . >/dev/null 2>&1 ||
|
||||||
fail 'a working jq is required for the tutor block tests (pacman -S jq)'
|
fail 'a working jq is required for the automation_tutor tests (pacman -S jq)'
|
||||||
|
|
||||||
BIN_DIR="$TMP_DIR/bin"
|
BIN_DIR="$TMP_DIR/bin"
|
||||||
mkdir -p "$BIN_DIR"
|
mkdir -p "$BIN_DIR"
|
||||||
@ -45,21 +45,19 @@ LEDGER="$TMP_DIR/ledger.json"
|
|||||||
TODAY=$(date +%Y-%m-%d)
|
TODAY=$(date +%Y-%m-%d)
|
||||||
YESTERDAY=$(date -d yesterday +%Y-%m-%d)
|
YESTERDAY=$(date -d yesterday +%Y-%m-%d)
|
||||||
|
|
||||||
# ledger <day:kind[:minutes]>... (writes {"entries":[...]}; no minutes = legacy row)
|
# ledger <day:kind>... (writes {"entries":[...]})
|
||||||
ledger() {
|
ledger() {
|
||||||
local rows=()
|
local rows=()
|
||||||
local spec
|
local spec
|
||||||
for spec in "$@"; do
|
for spec in "$@"; do
|
||||||
local day kind minutes
|
rows+=("$(jq -n --arg day "${spec%%:*}" --arg kind "${spec##*:}" \
|
||||||
IFS=: read -r day kind minutes <<<"$spec"
|
'{day: $day, kind: $kind}')")
|
||||||
rows+=("$(jq -n --arg day "$day" --arg kind "$kind" --arg m "$minutes" \
|
|
||||||
'{day: $day, kind: $kind} + (if $m == "" then {} else {detail: {minutes: ($m | tonumber)}} end)')")
|
|
||||||
done
|
done
|
||||||
printf '%s\n' "${rows[@]}" | jq -s '{entries: .}' >"$LEDGER"
|
printf '%s\n' "${rows[@]}" | jq -s '{entries: .}' >"$LEDGER"
|
||||||
}
|
}
|
||||||
|
|
||||||
run_block() {
|
run_block() {
|
||||||
TUTOR_LEDGER="$LEDGER" TUTOR_RUN="$BIN_DIR/run.sh" \
|
AUTOMATION_TUTOR_LEDGER="$LEDGER" AUTOMATION_TUTOR_RUN="$BIN_DIR/run.sh" \
|
||||||
bash "$BLOCK"
|
bash "$BLOCK"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,29 +65,26 @@ line() {
|
|||||||
sed -n "${1}p" <<<"$2"
|
sed -n "${1}p" <<<"$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
printf 'Checking tutor block states...\n'
|
printf 'Checking automation_tutor block states...\n'
|
||||||
|
|
||||||
rm -f "$LEDGER"
|
rm -f "$LEDGER"
|
||||||
out=$(run_block)
|
out=$(run_block)
|
||||||
assert_eq '⚙ tutor 0/60' "$(line 1 "$out")" 'no ledger is 0/60'
|
assert_eq '⚙ tutor 0/4' "$(line 1 "$out")" 'no ledger is 0/4'
|
||||||
assert_eq '⚙ 0/60' "$(line 2 "$out")" 'no ledger short text'
|
assert_eq '⚙ 0/4' "$(line 2 "$out")" 'no ledger short text'
|
||||||
assert_eq '#F1FA8C' "$(line 3 "$out")" 'progress is yellow'
|
assert_eq '#F1FA8C' "$(line 3 "$out")" 'progress is yellow'
|
||||||
|
|
||||||
ledger "$TODAY:credit:3" "$TODAY:credit:1" "$YESTERDAY:credit:50"
|
ledger "$TODAY:credit" "$TODAY:credit" "$YESTERDAY:credit"
|
||||||
out=$(run_block)
|
out=$(run_block)
|
||||||
assert_eq '⚙ tutor 4/60' "$(line 1 "$out")" 'sums only today'
|
assert_eq '⚙ tutor 2/4' "$(line 1 "$out")" 'counts only today'
|
||||||
assert_eq '⚙ 4/60' "$(line 2 "$out")" 'short text'
|
assert_eq '⚙ 2/4' "$(line 2 "$out")" 'short text'
|
||||||
|
|
||||||
ledger "$TODAY:credit" "$TODAY:credit:2"
|
ledger "$TODAY:credit" "$TODAY:debit"
|
||||||
assert_eq '⚙ tutor 17/60' "$(line 1 "$(run_block)")" 'legacy row counts 15'
|
assert_eq '⚙ tutor 1/4' "$(line 1 "$(run_block)")" 'only credit rows count'
|
||||||
|
|
||||||
ledger "$TODAY:credit:5" "$TODAY:debit:9"
|
ledger "$TODAY:credit" "$TODAY:credit" "$TODAY:credit" "$TODAY:credit"
|
||||||
assert_eq '⚙ tutor 5/60' "$(line 1 "$(run_block)")" 'only credit rows count'
|
|
||||||
|
|
||||||
ledger "$TODAY:credit:59" "$TODAY:credit:1"
|
|
||||||
out=$(run_block)
|
out=$(run_block)
|
||||||
assert_eq '' "$(line 1 "$out")" '60/60 hides the block'
|
assert_eq '' "$(line 1 "$out")" '4/4 hides the block'
|
||||||
assert_eq '' "$(line 2 "$out")" '60/60 short text hidden'
|
assert_eq '' "$(line 2 "$out")" '4/4 short text hidden'
|
||||||
|
|
||||||
printf 'Checking failure states are never blank or green...\n'
|
printf 'Checking failure states are never blank or green...\n'
|
||||||
|
|
||||||
@ -108,4 +103,4 @@ for _ in 1 2 3 4 5 6 7 8 9 10; do
|
|||||||
done
|
done
|
||||||
assert_eq 'clicked' "$(cat "$TMP_DIR/clicks" 2>/dev/null)" 'click runs run.sh'
|
assert_eq 'clicked' "$(cat "$TMP_DIR/clicks" 2>/dev/null)" 'click runs run.sh'
|
||||||
|
|
||||||
printf 'tutor block: all checks passed\n'
|
printf 'automation_tutor block: all checks passed\n'
|
||||||
Loading…
Reference in New Issue
Block a user