Requirement 001 phase 6, S0: - Speech: the security class shows as "Sécurité" and is spoken as in maritime radio, "say-cure-ee-tay" three times. A hex run of 7 or more characters with a letter and a digit (commit, session, message ids) is spelled in the NATO alphabet; every other digit is spoken on its own in ICAO pronunciation (42305: four two tree zero fife). The spelling runs inside clip() before the length cut, so a phrase still fits SPEECH_LIMIT; the displayed text keeps its digits and hashes. - English: every orchestrator label, tooltip, message, error, script output, document and test string is English (Regeln -> Firewall, Hierarchie -> Hierarchy, Steuerung -> Controls, Ausführen -> Run, ...); the page declares lang="en" and formats dates as en-GB. Task filter ids are English. German stays only in the skill trigger phrases that quote the operator, and as identifiers: the view keys (view=) and the leitstand id. - tests/test_english.py scans every tracked text file for umlauts and German words, with an allowlist of the quoted trigger phrases. BREAKING CHANGE: the Stream search tokens art: and seit: are now kind: and since:; an old art: or seit: token counts as a plain word. Evidence: make test 657 OK, ruff and markdownlint clean (/tmp/s0-make-test-1.log); e2e 17 OK, none skipped (/tmp/s0-e2e-1.log); MEDUSA 86 files, 24 findings on reworded strings accepted after an independent skeptic (21 path:line, 0 rejected, no behaviour change in signing, approving, rules, denying, offices, events), rescan 0 open. 🎯 Fix: 93 % 💥 Break: 4 % 💸 Cost: 100 % ⏱️ Time: – 🛡️ Security: 100 % 🏆 Score: 89 🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
117 lines
4.5 KiB
Python
117 lines
4.5 KiB
Python
"""Exercise coach.py: preferences flip between like and dislike, the log feeds hours since."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
SCRIPT = REPO_ROOT / "skills" / "kvb-coach" / "scripts" / "coach.py"
|
|
HOOK = REPO_ROOT / "skills" / "kvb-coach" / "hooks" / "reminder.sh"
|
|
|
|
|
|
class TestCoach(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(self.tmp.cleanup)
|
|
self.profile = Path(self.tmp.name) / "state" / "coach.json"
|
|
|
|
def _run(self, *args: str) -> subprocess.CompletedProcess:
|
|
return subprocess.run(
|
|
[sys.executable, str(SCRIPT), "--profile", str(self.profile), *args],
|
|
check=False,
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
|
|
def _show(self, now: str) -> dict:
|
|
result = self._run("show", "--now", now, "--json")
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
return {row["area"]: row for row in json.loads(result.stdout)}
|
|
|
|
def test_a_dislike_replaces_a_like_and_forget_drops_it(self):
|
|
self._run("like", "body", "Running")
|
|
self._run("like", "body", "Running")
|
|
self._run("like", "body", "Yoga")
|
|
self._run("dislike", "body", "Running")
|
|
body = self._show("2026-11-03T18:00:00+00:00")["body"]
|
|
self.assertEqual(body["likes"], ["Yoga"])
|
|
self.assertEqual(body["dislikes"], ["Running"])
|
|
self._run("forget", "body", "Running")
|
|
self.assertEqual(self._show("2026-11-03T18:00:00+00:00")["body"]["dislikes"], [])
|
|
|
|
def test_the_latest_done_per_area_gives_the_hours_since(self):
|
|
self._run("done", "food", "Breakfast", "--at", "2026-11-03T08:00:00+00:00")
|
|
self._run("done", "food", "Lunch", "--at", "2026-11-03T12:30:00+00:00")
|
|
self._run("done", "sleep", "Night", "--at", "2026-11-02T23:00:00+00:00")
|
|
rows = self._show("2026-11-03T18:00:00+00:00")
|
|
self.assertEqual((rows["food"]["last"], rows["food"]["hours_ago"]), ("Lunch", 5.5))
|
|
self.assertEqual(rows["sleep"]["hours_ago"], 19.0)
|
|
self.assertIsNone(rows["psyche"]["last"])
|
|
|
|
def test_invalid_input_exits_2_and_keeps_the_profile(self):
|
|
self.assertEqual(self._run("like", "work", "x").returncode, 2)
|
|
self.assertEqual(self._run("done", "body", "x", "--at", "yesterday").returncode, 2)
|
|
self.assertFalse(self.profile.exists())
|
|
self.profile.parent.mkdir(parents=True)
|
|
self.profile.write_text("{broken", encoding="utf-8")
|
|
self.assertEqual(self._run("show").returncode, 2)
|
|
self.assertEqual(self.profile.read_text(encoding="utf-8"), "{broken")
|
|
|
|
|
|
class TestCoachHour(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(self.tmp.cleanup)
|
|
self.hours = Path(self.tmp.name) / "hours"
|
|
|
|
def _run(self, hour: str) -> str:
|
|
return subprocess.run(
|
|
["bash", str(HOOK)],
|
|
check=True,
|
|
capture_output=True,
|
|
text=True,
|
|
env={
|
|
"PATH": "/usr/bin:/bin",
|
|
"HOME": self.tmp.name,
|
|
"COACH_STAMP_DIR": str(self.hours),
|
|
"COACH_HOUR": hour,
|
|
},
|
|
).stdout
|
|
|
|
def test_first_prompt_of_each_hour_triggers_the_coach_once(self):
|
|
self.assertIn("kvb-coach", self._run("2026-11-03T14"))
|
|
self.assertEqual(self._run("2026-11-03T14"), "")
|
|
self.assertIn("kvb-coach", self._run("2026-11-03T15"))
|
|
self.assertEqual(sorted(p.name for p in self.hours.iterdir()), ["2026-11-03T15"])
|
|
|
|
def test_a_binary_planted_on_the_inherited_path_never_runs(self):
|
|
planted = Path(self.tmp.name) / "planted"
|
|
planted.mkdir()
|
|
marker = Path(self.tmp.name) / "ran"
|
|
for name in ("mkdir", "find", "cat", "date"):
|
|
fake = planted / name
|
|
fake.write_text(f"#!/bin/sh\n/usr/bin/touch '{marker}'\n", encoding="utf-8")
|
|
fake.chmod(0o755)
|
|
subprocess.run(
|
|
["bash", str(HOOK)],
|
|
check=True,
|
|
capture_output=True,
|
|
text=True,
|
|
env={
|
|
"PATH": f"{planted}:/usr/bin:/bin",
|
|
"HOME": self.tmp.name,
|
|
"COACH_STAMP_DIR": str(self.hours),
|
|
"COACH_HOUR": "2026-11-03T14",
|
|
},
|
|
)
|
|
self.assertFalse(marker.exists())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|