Compare commits
20
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d5103ac90 | ||
|
|
3a6fe26d0c | ||
|
|
45277e02da | ||
|
|
87dda96e7e | ||
|
|
55855db55b | ||
|
|
8a4a5aef33 | ||
|
|
d33c2cf268 | ||
|
|
7bd0a652cb | ||
|
|
449f404464 | ||
|
|
0e5d76901d | ||
|
|
773f3b550f | ||
|
|
4664e71493 | ||
|
|
e7adb3e88b | ||
|
|
2e2960c159 | ||
|
|
627f813859 | ||
|
|
e750e0e687 | ||
|
|
63210afc7b | ||
|
|
7ec491d383 | ||
|
|
4f1277aa45 | ||
|
|
3908d5a3a6 |
No files matched your search
+1
-1
@@ -4,7 +4,7 @@ dist-newstyle
|
|||||||
|
|
||||||
.worktrees/
|
.worktrees/
|
||||||
|
|
||||||
docs/superpowers
|
docs/superpowers/plans
|
||||||
|
|
||||||
*.hp
|
*.hp
|
||||||
*.eventlog
|
*.eventlog
|
||||||
|
|||||||
@@ -5,6 +5,11 @@
|
|||||||
A sidecar for Home Assistant that runs automations using arrowized functional
|
A sidecar for Home Assistant that runs automations using arrowized functional
|
||||||
reactive programming (AFRP). Haskell, built with cabal.
|
reactive programming (AFRP). Haskell, built with cabal.
|
||||||
|
|
||||||
|
## Working style
|
||||||
|
|
||||||
|
- When doing any non-trivial work, always work in a worktree on a feature branch
|
||||||
|
- Feature branches should be named as the topic of the change
|
||||||
|
|
||||||
## Code style
|
## Code style
|
||||||
|
|
||||||
- Vertical modules: split by feature/concept, not by layer.
|
- Vertical modules: split by feature/concept, not by layer.
|
||||||
@@ -25,3 +30,8 @@ reactive programming (AFRP). Haskell, built with cabal.
|
|||||||
|
|
||||||
- hspec for unit tests, hedgehog for property tests.
|
- hspec for unit tests, hedgehog for property tests.
|
||||||
- Run with `nix develop -c cabal test`.
|
- Run with `nix develop -c cabal test`.
|
||||||
|
|
||||||
|
## Reviewing
|
||||||
|
|
||||||
|
Reviews are recorded in git notes under `refs/notes/review`; read the latest
|
||||||
|
note before reviewing. See [[REVIEW.md]].
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
# Code Review Guidelines
|
||||||
|
|
||||||
|
|
||||||
|
- Each MR should be focused, changing only one concept at a time
|
||||||
|
- Keep MRs small - aim for under 500 lines of diff. There can be some wiggle room for cases that are hard to split
|
||||||
|
- When reviewing code, check for test coverage and suggest tests if missing
|
||||||
|
- Go through tests and think hard to see if any unit tests or group of unit tests can be replaced with a property test
|
||||||
|
- When suggesting a property test, consider cases that the property needs to falsify and whether it needs its own generator
|
||||||
|
- Business logic stays pure
|
||||||
|
|
||||||
|
## Comments
|
||||||
|
|
||||||
|
- Less is more
|
||||||
|
- If there's comments for a function, verify they're proper haddock style
|
||||||
|
- If there's comments for a function, they must only be about the contract and use instructions
|
||||||
|
- If there's comments for implementation, they should only be for exceptional cases, cases where the reader would question why something is implemented like that
|
||||||
|
- Comment style should follow minimalistic writing style
|
||||||
|
|
||||||
|
## Recording reviews
|
||||||
|
|
||||||
|
Reviews are stored as git notes under `refs/notes/review`, one note per
|
||||||
|
reviewed commit. The note header carries `branch`, `round`, `verdict`
|
||||||
|
(`approve` or `request-changes`), `previous` (sha of the last reviewed tip),
|
||||||
|
and a findings list with stable IDs (`F1`, `F2`, ...) whose `status` is
|
||||||
|
`open`, `resolved`, or `wontfix`. The body is free markdown prose.
|
||||||
|
|
||||||
|
Protocol:
|
||||||
|
|
||||||
|
1. Fetch prior results:
|
||||||
|
`git fetch origin "refs/notes/review:refs/notes/review"`
|
||||||
|
Ignore the failure on the first-ever review (origin has no notes ref yet);
|
||||||
|
if the fetch is rejected as non-fast-forward, your local notes are ahead —
|
||||||
|
push instead.
|
||||||
|
2. Read the latest verdict and open findings for the branch:
|
||||||
|
`scripts/review-note latest [branch]`
|
||||||
|
3. Review the branch tip per this document.
|
||||||
|
4. Write the note (header + markdown) to a file and attach it to the tip:
|
||||||
|
`scripts/review-note write <file>`. Use `--force` only to replace a note
|
||||||
|
on the same commit deliberately.
|
||||||
|
5. Publish: `scripts/review-note push` (plain `git push` does not push
|
||||||
|
notes).
|
||||||
|
|
||||||
|
On a re-review after fixes: new tip, new note, `round`+1, `previous` set to
|
||||||
|
the last reviewed sha, open findings carried forward by ID, resolved ones
|
||||||
|
marked `resolved`.
|
||||||
|
|
||||||
|
On a branch rename: update the note's `branch:` header to the new name and
|
||||||
|
mention the old name in the body, so `latest <new-name>` chains and history
|
||||||
|
stays findable.
|
||||||
+6
-6
@@ -2,9 +2,9 @@
|
|||||||
, cereal, cereal-conduit, cereal-text, conduit, containers
|
, cereal, cereal-conduit, cereal-text, conduit, containers
|
||||||
, data-default, directory, ekg-core, exceptions, filepath, hedgehog
|
, data-default, directory, ekg-core, exceptions, filepath, hedgehog
|
||||||
, hspec, hspec-hedgehog, http-media, http-types, katip, lens
|
, hspec, hspec-hedgehog, http-media, http-types, katip, lens
|
||||||
, lens-aeson, lib, libsystemd-journal, network, process, retry
|
, lens-aeson, lib, libsystemd-journal, lucid2, network, process
|
||||||
, servant, servant-server, stm, temporary, text, time, unliftio
|
, retry, servant, servant-server, stm, temporary, text, time
|
||||||
, unordered-containers, uuid, wai, warp, websockets
|
, unliftio, unordered-containers, uuid, wai, warp, websockets
|
||||||
}:
|
}:
|
||||||
mkDerivation {
|
mkDerivation {
|
||||||
pname = "home-assistant-controller";
|
pname = "home-assistant-controller";
|
||||||
@@ -16,9 +16,9 @@ mkDerivation {
|
|||||||
aeson annotated-exception async base bytestring cereal
|
aeson annotated-exception async base bytestring cereal
|
||||||
cereal-conduit cereal-text conduit containers data-default
|
cereal-conduit cereal-text conduit containers data-default
|
||||||
directory ekg-core exceptions filepath http-media http-types katip
|
directory ekg-core exceptions filepath http-media http-types katip
|
||||||
lens lens-aeson libsystemd-journal network process retry servant
|
lens lens-aeson libsystemd-journal lucid2 network process retry
|
||||||
servant-server stm text time unliftio unordered-containers uuid wai
|
servant servant-server stm text time unliftio unordered-containers
|
||||||
warp websockets
|
uuid wai warp websockets
|
||||||
];
|
];
|
||||||
executableHaskellDepends = [ base ];
|
executableHaskellDepends = [ base ];
|
||||||
testHaskellDepends = [
|
testHaskellDepends = [
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
# Review notes protocol
|
||||||
|
|
||||||
|
Date: 2026-10-02
|
||||||
|
Status: approved
|
||||||
|
|
||||||
|
## Purpose
|
||||||
|
|
||||||
|
Record code-review results as git notes under `refs/notes/review` so that the
|
||||||
|
next reviewer — human or AI — can read the current verdict, see open findings
|
||||||
|
with stable IDs, and continue from where the last review stopped. This
|
||||||
|
replaces a CI reviewer: reviews happen locally, results travel with the
|
||||||
|
commits they judged.
|
||||||
|
|
||||||
|
## Storage model
|
||||||
|
|
||||||
|
- One note per reviewed commit, in the `review` notes ref.
|
||||||
|
- The tip of a reviewed branch always carries the latest verdict.
|
||||||
|
- Re-reviewing after fixes writes a **new** note on the **new** tip commit.
|
||||||
|
Old notes stay attached to old commits as history.
|
||||||
|
- Each note links to the previously reviewed commit via `previous`, forming a
|
||||||
|
walkable chain of review rounds per branch.
|
||||||
|
- Merging to main needs no special handling: the `approve` note on the final
|
||||||
|
tip is the record.
|
||||||
|
|
||||||
|
## Note format
|
||||||
|
|
||||||
|
Line-based header, then a blank line, then free markdown body:
|
||||||
|
|
||||||
|
branch: <branch name>
|
||||||
|
round: <integer, starting at 1>
|
||||||
|
verdict: approve | request-changes
|
||||||
|
previous: none | <sha of previously reviewed tip>
|
||||||
|
findings:
|
||||||
|
- id: F<N>
|
||||||
|
severity: blocker | major | minor
|
||||||
|
file: <path>:<line>
|
||||||
|
title: <one line>
|
||||||
|
status: open | resolved | wontfix
|
||||||
|
## Details
|
||||||
|
|
||||||
|
<markdown prose>
|
||||||
|
|
||||||
|
Rules:
|
||||||
|
|
||||||
|
- Finding IDs are unique within a note and carry forward across rounds: a
|
||||||
|
finding resolved since the last note keeps its ID and moves to
|
||||||
|
`status: resolved`; an unfixed finding keeps its ID and `status: open`.
|
||||||
|
New findings get fresh IDs that do not collide with carried-forward ones.
|
||||||
|
- The body is free markdown; the `## Details` heading in the example is
|
||||||
|
illustrative, not required.
|
||||||
|
- Headers are plain `key: value` lines so the helper script can parse them
|
||||||
|
with sed/awk.
|
||||||
|
|
||||||
|
## Helper script: `scripts/review-note`
|
||||||
|
|
||||||
|
Bash, git plumbing only. Subcommands:
|
||||||
|
|
||||||
|
- `review-note show [commit]` — print the note for a commit (default: current
|
||||||
|
tip). Exit 1 with a message on stderr if there is no note.
|
||||||
|
- `review-note write <file>` — attach the note in `<file>` to the current tip
|
||||||
|
commit. Refuses to replace an existing note unless `--force` is given; a
|
||||||
|
proper re-review targets a new commit, so overwriting is always deliberate.
|
||||||
|
Validates that `branch`, `round`, and `verdict` are present and that
|
||||||
|
`verdict` uses the vocabulary above. No other validation.
|
||||||
|
- `review-note latest [branch]` — print the note with the highest `round` for
|
||||||
|
a branch (default: current branch), scanning the notes ref and matching
|
||||||
|
notes on their `branch:` header. Exit 1 if there is no note for the branch.
|
||||||
|
(A `previous`-chain walk cannot bootstrap from an unreviewed tip, so the
|
||||||
|
scan uses the `branch:` header as the index instead.)
|
||||||
|
- `review-note push` — `git push origin refs/notes/review`. Plain `git push`
|
||||||
|
ignores notes, so this is the only way results travel.
|
||||||
|
|
||||||
|
`push` pushes without force; if the remote rejects, report the failure and let
|
||||||
|
the user decide.
|
||||||
|
|
||||||
|
## Lifecycle
|
||||||
|
|
||||||
|
1. Reviewer reads `review-note latest <branch>` (exit 1 means first review).
|
||||||
|
2. Reviewer reviews the branch tip per `REVIEW.md`.
|
||||||
|
3. Reviewer writes the note with `review-note write` and runs
|
||||||
|
`review-note push`.
|
||||||
|
4. If the verdict is `request-changes`, the author pushes fixes as new
|
||||||
|
commits. The next review round starts at the new tip with `round`+1,
|
||||||
|
`previous` set to the last reviewed tip, and carried-forward findings.
|
||||||
|
5. When the verdict is `approve` and the branch merges, the notes remain on
|
||||||
|
the branch commits as the review record.
|
||||||
|
|
||||||
|
## Documentation integration
|
||||||
|
|
||||||
|
- `REVIEW.md` gains a "Recording reviews" section describing the protocol and
|
||||||
|
the four script commands. This is the single source of truth for the
|
||||||
|
protocol.
|
||||||
|
- `AGENTS.md` "Reviewing" section gains one line pointing at the section, so
|
||||||
|
any AI session picks up the flow automatically.
|
||||||
|
|
||||||
|
## Seeding the experiment
|
||||||
|
|
||||||
|
The failing review of `home_assistant_controller_cleanup` (commit `ba6e0e8`)
|
||||||
|
becomes note round 1, with these findings:
|
||||||
|
|
||||||
|
- F1 (blocker, src/AFRP.hs:273): hlint's `\_ -> x` → `const x` rewrites break
|
||||||
|
the rank-2 `Mealy` type; library does not compile.
|
||||||
|
- F2 (blocker, test/AFRPLawsSpec.hs:98): seven law tests reduced to
|
||||||
|
tautologies by hlint rewrites; see :103, :212, :221, :228, :235, :256.
|
||||||
|
- F3 (minor, test/AFRPLawsSpec.hs:241): the interchange and composition laws
|
||||||
|
were reshaped to `<$>` forms; fold them into the same hlint suppression.
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
The script is verified by round-trip checks in a throwaway temp clone: write,
|
||||||
|
show, latest (two rounds, branch filtering), force-overwrite refusal and
|
||||||
|
acceptance, and push. No Haskell or cabal changes, so no
|
||||||
|
cabal2nix regeneration.
|
||||||
@@ -52,7 +52,7 @@ extra-doc-files: CHANGELOG.md
|
|||||||
-- extra-source-files:
|
-- extra-source-files:
|
||||||
|
|
||||||
common warnings
|
common warnings
|
||||||
ghc-options: -Wall
|
ghc-options: -Wall -Werror
|
||||||
|
|
||||||
library
|
library
|
||||||
-- Import common warning flags.
|
-- Import common warning flags.
|
||||||
@@ -132,6 +132,8 @@ library
|
|||||||
, wai
|
, wai
|
||||||
, retry
|
, retry
|
||||||
, libsystemd-journal
|
, libsystemd-journal
|
||||||
|
, lucid2
|
||||||
|
, http-api-data
|
||||||
|
|
||||||
-- Directories containing source files.
|
-- Directories containing source files.
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
@@ -179,6 +181,7 @@ test-suite home-assistant-controller-test
|
|||||||
, ConnectionSpec
|
, ConnectionSpec
|
||||||
, FlagsSpec
|
, FlagsSpec
|
||||||
, GraphingSpec
|
, GraphingSpec
|
||||||
|
, HttpServerSpec
|
||||||
, KitchenSpec
|
, KitchenSpec
|
||||||
, LivingroomSpec
|
, LivingroomSpec
|
||||||
, MetricsSpec
|
, MetricsSpec
|
||||||
@@ -222,4 +225,5 @@ test-suite home-assistant-controller-test
|
|||||||
unordered-containers,
|
unordered-containers,
|
||||||
process,
|
process,
|
||||||
directory,
|
directory,
|
||||||
temporary
|
temporary,
|
||||||
|
lucid2
|
||||||
Executable
+95
@@ -0,0 +1,95 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# review-note: manage code-review notes under refs/notes/review.
|
||||||
|
# The protocol lives in REVIEW.md.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
NOTES_REF=refs/notes/review
|
||||||
|
REMOTE=origin
|
||||||
|
|
||||||
|
die() { echo "review-note: $*" >&2; exit 1; }
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat >&2 <<'EOF'
|
||||||
|
usage:
|
||||||
|
review-note show [commit]
|
||||||
|
review-note write <file> [--force]
|
||||||
|
review-note latest [branch]
|
||||||
|
review-note push
|
||||||
|
EOF
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
validate() {
|
||||||
|
local file="$1"
|
||||||
|
grep -q '^branch: .\+' "$file" || die "missing or empty 'branch:' header"
|
||||||
|
grep -Eq '^round: [0-9]+$' "$file" || die "missing or invalid 'round:' header"
|
||||||
|
grep -Eq '^verdict: (approve|request-changes)$' "$file" \
|
||||||
|
|| die "verdict must be 'approve' or 'request-changes'"
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_show() {
|
||||||
|
local commit="${1:-HEAD}"
|
||||||
|
git notes --ref="$NOTES_REF" show "$commit" 2>/dev/null \
|
||||||
|
|| die "no review note for $commit"
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_write() {
|
||||||
|
local force="" file=""
|
||||||
|
local arg
|
||||||
|
for arg in "$@"; do
|
||||||
|
case "$arg" in
|
||||||
|
--force) force=1 ;;
|
||||||
|
*) file="$arg" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
[ -n "$file" ] || usage
|
||||||
|
[ -f "$file" ] || die "no such file: $file"
|
||||||
|
local tip
|
||||||
|
tip=$(git rev-parse HEAD)
|
||||||
|
if [ -z "$force" ] && git notes --ref="$NOTES_REF" show "$tip" >/dev/null 2>&1; then
|
||||||
|
die "tip $tip already has a review note; pass --force to replace"
|
||||||
|
fi
|
||||||
|
validate "$file"
|
||||||
|
if [ -n "$force" ]; then
|
||||||
|
git notes --ref="$NOTES_REF" add -f -F "$file" "$tip"
|
||||||
|
else
|
||||||
|
git notes --ref="$NOTES_REF" add -F "$file" "$tip"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_latest() {
|
||||||
|
local branch="${1:-$(git branch --show-current)}"
|
||||||
|
local blob obj note br rnd best="" best_round=-1
|
||||||
|
while read -r blob obj; do
|
||||||
|
note=$(git notes --ref="$NOTES_REF" show "$obj") || continue
|
||||||
|
br=$(sed -n '/^$/q; s/^branch: //p' <<<"$note")
|
||||||
|
[ "$br" = "$branch" ] || continue
|
||||||
|
rnd=$(sed -n '/^$/q; s/^round: //p' <<<"$note")
|
||||||
|
[[ "$rnd" =~ ^[0-9]+$ ]] || continue
|
||||||
|
if [ "$rnd" -gt "$best_round" ]; then
|
||||||
|
best_round=$rnd
|
||||||
|
best=$note
|
||||||
|
fi
|
||||||
|
done < <(git notes --ref="$NOTES_REF" list)
|
||||||
|
[ -n "$best" ] || die "no review notes for branch: $branch"
|
||||||
|
printf '%s\n' "$best"
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_push() {
|
||||||
|
git rev-parse -q --verify "$NOTES_REF" >/dev/null || die "no review notes to push"
|
||||||
|
git push "$REMOTE" "$NOTES_REF"
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
local cmd="${1:-}"
|
||||||
|
if [ $# -gt 0 ]; then shift; fi
|
||||||
|
case "$cmd" in
|
||||||
|
show) cmd_show "$@" ;;
|
||||||
|
write) cmd_write "$@" ;;
|
||||||
|
latest) cmd_latest "$@" ;;
|
||||||
|
push) cmd_push "$@" ;;
|
||||||
|
*) usage ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
||||||
Executable
+82
@@ -0,0 +1,82 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Round-trip checks for scripts/review-note, in a throwaway temp repo.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
root=$(cd "$(dirname "$0")/.." && pwd -P)
|
||||||
|
rn="$root/scripts/review-note"
|
||||||
|
fail() { echo "FAIL: $*" >&2; exit 1; }
|
||||||
|
tmp=$(mktemp -d)
|
||||||
|
trap 'rm -rf "$tmp"' EXIT
|
||||||
|
|
||||||
|
git init -q --bare "$tmp/remote.git"
|
||||||
|
git init -q -b main "$tmp/repo"
|
||||||
|
cd "$tmp/repo"
|
||||||
|
git config user.email test@example.com
|
||||||
|
git config user.name test
|
||||||
|
|
||||||
|
echo one > a.txt && git add a.txt && git commit -qm one
|
||||||
|
echo two > b.txt && git add b.txt && git commit -qm two
|
||||||
|
|
||||||
|
note="$tmp/note1"
|
||||||
|
cat > "$note" <<'EOF'
|
||||||
|
branch: main
|
||||||
|
round: 1
|
||||||
|
verdict: request-changes
|
||||||
|
previous: none
|
||||||
|
findings:
|
||||||
|
- id: F1
|
||||||
|
severity: blocker
|
||||||
|
file: a.txt:1
|
||||||
|
title: fix me
|
||||||
|
status: open
|
||||||
|
## Details
|
||||||
|
|
||||||
|
Fix it.
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if "$rn" show >/dev/null 2>&1; then fail "show should exit 1 without a note"; fi
|
||||||
|
|
||||||
|
sed '/^verdict:/d' "$note" > "$tmp/no-verdict"
|
||||||
|
if "$rn" write "$tmp/no-verdict" >/dev/null 2>&1; then fail "write should refuse a missing verdict"; fi
|
||||||
|
sed 's/^verdict: request-changes/verdict: maybe/' "$note" > "$tmp/bad-verdict"
|
||||||
|
if "$rn" write "$tmp/bad-verdict" >/dev/null 2>&1; then fail "write should refuse a bad verdict"; fi
|
||||||
|
|
||||||
|
"$rn" write "$note"
|
||||||
|
"$rn" show | grep -q '^verdict: request-changes$' || fail "show should print the note"
|
||||||
|
|
||||||
|
if "$rn" write "$note" >/dev/null 2>&1; then fail "write should refuse an existing note"; fi
|
||||||
|
|
||||||
|
sed 's/^verdict: request-changes/verdict: approve/' "$note" > "$tmp/note1b"
|
||||||
|
"$rn" write "$tmp/note1b" --force
|
||||||
|
"$rn" show | grep -q '^verdict: approve$' || fail "show should print the replaced note"
|
||||||
|
"$rn" show | diff -u "$tmp/note1b" - || fail "show should print the note verbatim"
|
||||||
|
|
||||||
|
# latest finds the note by branch, even from a newer unreviewed tip
|
||||||
|
echo three > c.txt && git add c.txt && git commit -qm three
|
||||||
|
"$rn" latest main | grep -q '^verdict: approve$' || fail "latest should find the round 1 note"
|
||||||
|
|
||||||
|
# a note for another branch must not leak into the result
|
||||||
|
sed -e 's/^branch: main/branch: other/' -e 's/^round: 1/round: 9/' "$tmp/note1b" > "$tmp/other"
|
||||||
|
"$rn" write "$tmp/other"
|
||||||
|
"$rn" latest main | grep -q '^verdict: approve$' || fail "latest should ignore other branches"
|
||||||
|
|
||||||
|
# round 2 on the new tip wins and carries previous (replaces the
|
||||||
|
# other-branch note on the same commit, so --force)
|
||||||
|
PREV=$(git rev-parse HEAD~1)
|
||||||
|
sed -e 's/^round: 1/round: 2/' -e "s/^previous: none/previous: $PREV/" "$tmp/note1b" > "$tmp/note2"
|
||||||
|
"$rn" write "$tmp/note2" --force
|
||||||
|
"$rn" latest main | grep -q '^round: 2$' || fail "latest should pick the highest round"
|
||||||
|
"$rn" latest main | grep -q "^previous: $PREV$" || fail "round 2 should carry previous"
|
||||||
|
|
||||||
|
if "$rn" latest nosuch >/dev/null 2>&1; then fail "latest should exit 1 for an unknown branch"; fi
|
||||||
|
|
||||||
|
# push publishes notes to origin; a fresh clone picks them up
|
||||||
|
git remote add origin "$tmp/remote.git"
|
||||||
|
git push -q origin main
|
||||||
|
"$rn" push
|
||||||
|
git clone -q "$tmp/remote.git" "$tmp/clone"
|
||||||
|
cd "$tmp/clone"
|
||||||
|
git fetch -q origin "refs/notes/review:refs/notes/review"
|
||||||
|
"$rn" latest main | grep -q '^round: 2$' || fail "clone should see the round 2 note"
|
||||||
|
|
||||||
|
echo "ok: show/write/latest/push"
|
||||||
+10
-6
@@ -1,5 +1,4 @@
|
|||||||
{-# LANGUAGE LambdaCase #-}
|
{-# LANGUAGE LambdaCase #-}
|
||||||
{-# LANGUAGE Arrows #-}
|
|
||||||
|
|
||||||
module AFRP
|
module AFRP
|
||||||
( Mealy(..)
|
( Mealy(..)
|
||||||
@@ -9,6 +8,7 @@ module AFRP
|
|||||||
, withEntities
|
, withEntities
|
||||||
, Event(..)
|
, Event(..)
|
||||||
, hold
|
, hold
|
||||||
|
, holdKnown
|
||||||
, events
|
, events
|
||||||
-- , switch
|
-- , switch
|
||||||
, preMapAccum
|
, preMapAccum
|
||||||
@@ -129,7 +129,7 @@ instance Monad m => Applicative (Auto m a) where
|
|||||||
pure a = Fun (\_req -> const a)
|
pure a = Fun (\_req -> const a)
|
||||||
fa <*> fb =
|
fa <*> fb =
|
||||||
case (fa,fb) of
|
case (fa,fb) of
|
||||||
(Fun af, Fun bf) -> Fun $ \req -> (af req <*> bf req)
|
(Fun af, Fun bf) -> Fun $ \req -> af req <*> bf req
|
||||||
(Stateful codec s af, Fun bf) -> Stateful codec s
|
(Stateful codec s af, Fun bf) -> Stateful codec s
|
||||||
(\s' req x -> do
|
(\s' req x -> do
|
||||||
let a = bf req x
|
let a = bf req x
|
||||||
@@ -179,7 +179,7 @@ instance (Monad m, Monoid b) => Monoid (Auto m a b) where
|
|||||||
|
|
||||||
|
|
||||||
instance Monad m => Category (Auto m) where
|
instance Monad m => Category (Auto m) where
|
||||||
id = Fun $ \_ -> id
|
id = Fun $ const id
|
||||||
af . ag =
|
af . ag =
|
||||||
case (af, ag) of
|
case (af, ag) of
|
||||||
(Fun f, Fun g) -> Fun (\req -> f req . g req)
|
(Fun f, Fun g) -> Fun (\req -> f req . g req)
|
||||||
@@ -272,8 +272,6 @@ instance Semigroup b => Semigroup (Mealy eff a b) where
|
|||||||
|
|
||||||
instance Monoid b => Monoid (Mealy eff a b) where
|
instance Monoid b => Monoid (Mealy eff a b) where
|
||||||
mempty = Mealy mempty $ \_nt -> mempty
|
mempty = Mealy mempty $ \_nt -> mempty
|
||||||
-- where
|
|
||||||
-- m = Mealy mempty $ \_ _ _ -> pure (Pair mempty m)
|
|
||||||
|
|
||||||
eff :: (Request -> a -> eff b) -> Mealy eff a b
|
eff :: (Request -> a -> eff b) -> Mealy eff a b
|
||||||
eff f = Mealy mempty $ \nt -> do
|
eff f = Mealy mempty $ \nt -> do
|
||||||
@@ -288,7 +286,8 @@ withEntities :: S.Set T.Text -> Mealy eff a b -> Mealy eff a b
|
|||||||
withEntities es (Mealy _ f) = Mealy es f
|
withEntities es (Mealy _ f) = Mealy es f
|
||||||
|
|
||||||
instance Category (Mealy eff) where
|
instance Category (Mealy eff) where
|
||||||
id = Mealy mempty (\_ -> id)
|
{- HLINT ignore "Use const" -}
|
||||||
|
id = Mealy mempty $ \_nt -> id
|
||||||
(Mealy ast f) . (Mealy bst g) = Mealy (ast <> bst) $ \nt -> do
|
(Mealy ast f) . (Mealy bst g) = Mealy (ast <> bst) $ \nt -> do
|
||||||
f nt . g nt
|
f nt . g nt
|
||||||
|
|
||||||
@@ -328,6 +327,11 @@ hold def = mapAccum step def id
|
|||||||
Tick -> prev
|
Tick -> prev
|
||||||
Event new -> new
|
Event new -> new
|
||||||
|
|
||||||
|
|
||||||
|
-- A variant of 'hold' which makes it explicit whether we have a previous value
|
||||||
|
holdKnown :: (Serialize a, Eq a) => Mealy m (Event a) (Maybe a)
|
||||||
|
holdKnown = arr (fmap Just) >>> hold Nothing
|
||||||
|
|
||||||
snapshot :: (Serialize a, Eq a) => a -> Mealy m (Event (), a) a
|
snapshot :: (Serialize a, Eq a) => a -> Mealy m (Event (), a) a
|
||||||
snapshot def = mapAccum step def id
|
snapshot def = mapAccum step def id
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ data BedroomControls
|
|||||||
|
|
||||||
bedroomButton :: HASS (Event Value) (Event BedroomControls)
|
bedroomButton :: HASS (Event Value) (Event BedroomControls)
|
||||||
bedroomButton = (masseButton &&& enishenButton &&& centralButton)
|
bedroomButton = (masseButton &&& enishenButton &&& centralButton)
|
||||||
>>> arr (\(a,(b,c)) -> a `lMerge` b `lMerge` c)
|
>>> arr (\(a,(b,c)) -> a <> b <> c)
|
||||||
where
|
where
|
||||||
masseButton = fmap Masse <$> ikeaQuickButton "event.bedroom_quick_remote_masse_action"
|
masseButton = fmap Masse <$> ikeaQuickButton "event.bedroom_quick_remote_masse_action"
|
||||||
enishenButton = fmap Enishen <$> ikeaQuickButton "event.bedroom_quick_jemina_action"
|
enishenButton = fmap Enishen <$> ikeaQuickButton "event.bedroom_quick_jemina_action"
|
||||||
|
|||||||
@@ -1,15 +1,25 @@
|
|||||||
{-# LANGUAGE Arrows #-}
|
{-# LANGUAGE Arrows #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE DerivingVia #-}
|
||||||
module HomeAssistant.Controller.Children where
|
module HomeAssistant.Controller.Children where
|
||||||
import HomeAssistant.Controller (HASS, callService, Target (AreaId), light, LightCommand(..), ikeaQuickButton, IkeaGesture (..), IkeaButton (..), traceEvent, activateScene, LightAttributes (..), Brightness (..))
|
import HomeAssistant.Controller (HASS, callService, light, LightCommand(..), ikeaQuickButton, IkeaGesture (..), IkeaButton (..), traceEvent, activateScene, LightAttributes (..), Brightness (..), entityRead, entityChangeEvent)
|
||||||
import AFRP (Event (..))
|
import AFRP (Event (..))
|
||||||
import qualified AFRP
|
import qualified AFRP
|
||||||
import Control.Arrow (Arrow(..), (>>>), returnA)
|
import Control.Arrow (Arrow(..), (>>>), returnA)
|
||||||
import Data.Time (Day, TimeOfDay (..), localDay, LocalTime (..))
|
import Data.Time (Day, TimeOfDay (..), localDay, LocalTime (..))
|
||||||
import Data.Time.Calendar.OrdinalDate (WeekOfYear, mondayStartWeek)
|
import Data.Time.Calendar.OrdinalDate (WeekOfYear, mondayStartWeek)
|
||||||
import Data.Functor.Contravariant (Predicate (..), (>$<))
|
import Data.Functor.Contravariant (Predicate (..), (>$<))
|
||||||
import Data.Aeson (Value)
|
import Data.Aeson (Value, object, (.=))
|
||||||
import Data.Default (Default(..))
|
import Data.Default (Default(..))
|
||||||
|
import Data.Serialize (Serialize)
|
||||||
|
import Data.Serialize.Text ()
|
||||||
|
import GHC.Generics (Generic)
|
||||||
|
import HomeAssistant.Controller.Service (Service(..), Target(..))
|
||||||
|
import Data.Aeson.Types (ToJSON (..))
|
||||||
|
import Data.Aeson.Lens (key, _String)
|
||||||
|
import Control.Lens ((^?), to)
|
||||||
|
import Data.Text (Text)
|
||||||
|
import Control.Monad (join)
|
||||||
|
|
||||||
-- Let's see building some reasonable interface for utctime
|
-- Let's see building some reasonable interface for utctime
|
||||||
dow :: Day -> (WeekOfYear, Int)
|
dow :: Day -> (WeekOfYear, Int)
|
||||||
@@ -94,3 +104,62 @@ childrenBedroomButtonController = proc x -> do
|
|||||||
Event (OnButton LongClick) -> callService (activateScene "scene.lasten_kirkas") -< ()
|
Event (OnButton LongClick) -> callService (activateScene "scene.lasten_kirkas") -< ()
|
||||||
Event (OffButton _) -> callService (light [AreaId "lasten_makuuhuone"] Off) -< ()
|
Event (OffButton _) -> callService (light [AreaId "lasten_makuuhuone"] Off) -< ()
|
||||||
_ -> returnA -< ()
|
_ -> returnA -< ()
|
||||||
|
|
||||||
|
newtype PM25 = PM25 Float
|
||||||
|
deriving (Serialize, Eq, Ord) via Float
|
||||||
|
deriving Show
|
||||||
|
|
||||||
|
data PM25Level = PM25High | PM25Low
|
||||||
|
deriving (Eq, Generic, Show)
|
||||||
|
|
||||||
|
instance Serialize PM25Level
|
||||||
|
|
||||||
|
pm25 :: HASS (Event Value) PM25
|
||||||
|
pm25 = fmap PM25 (entityRead "sensor.children_temp_pm25" >>> AFRP.hold 0)
|
||||||
|
|
||||||
|
pm25Level :: HASS PM25 PM25Level
|
||||||
|
pm25Level = (tagHigh &&& tagLow) >>> arr (uncurry AFRP.lMerge) >>> AFRP.hold PM25Low
|
||||||
|
where
|
||||||
|
-- Band between 8 and 12 to avoid oscillation near the ~10 mark
|
||||||
|
tagHigh = arr (> PM25 12) >>> AFRP.edge >>> arr (AFRP.tag PM25High)
|
||||||
|
tagLow = arr (< PM25 8) >>> AFRP.edge >>> arr (AFRP.tag PM25Low)
|
||||||
|
|
||||||
|
data HumidifierAction
|
||||||
|
= Idle
|
||||||
|
| Humidifying
|
||||||
|
| Other Text
|
||||||
|
deriving (Show, Eq, Generic)
|
||||||
|
instance Serialize HumidifierAction
|
||||||
|
|
||||||
|
-- what is the humidifer doing right now?
|
||||||
|
humidifierOperatingState :: HASS (Event Value) (Event (Maybe HumidifierAction))
|
||||||
|
humidifierOperatingState = entityChangeEvent "humidifier.lapset_ilmankostutin"
|
||||||
|
>>> arr (fmap entityAction)
|
||||||
|
where
|
||||||
|
entityAction v = v ^? key "event" . key "variables" . key "trigger" . key "to_state" . key "attributes" . key "action" . _String . to humidifierAction
|
||||||
|
humidifierAction = \case
|
||||||
|
"idle" -> Idle
|
||||||
|
"humidifying" -> Humidifying
|
||||||
|
other -> Other other
|
||||||
|
|
||||||
|
-- TODO: There's some other percentages elsewhere that could be replaced with this
|
||||||
|
newtype Percentage = Percentage Int
|
||||||
|
instance ToJSON Percentage where
|
||||||
|
toJSON (Percentage p) = object ["percentage" .= p]
|
||||||
|
|
||||||
|
childrenAirFilterController :: HASS (Event Value) ()
|
||||||
|
childrenAirFilterController = proc ev -> do
|
||||||
|
level <- pm25 >>> pm25Level >>> AFRP.changes >>> traceEvent -< ev
|
||||||
|
humidifier <- humidifierOperatingState >>> AFRP.holdKnown >>> arr join -< ev
|
||||||
|
case level of
|
||||||
|
Event PM25High ->
|
||||||
|
AFRP.whenA (== Just Idle) (callService (fanOnTo (Percentage 80))) -< humidifier
|
||||||
|
Event PM25Low -> callService (fanOnTo (Percentage 20)) -< ()
|
||||||
|
_ -> returnA -< ()
|
||||||
|
where
|
||||||
|
fanOnTo percentage = Service
|
||||||
|
{ serviceDomain = "fan"
|
||||||
|
, serviceName = "set_percentage"
|
||||||
|
, serviceTarget = [EntityId "fan.children_fan"]
|
||||||
|
, serviceData = Just $ toJSON percentage
|
||||||
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
{-# LANGUAGE Arrows #-}
|
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
module HomeAssistant.Controller.Ruuvi
|
module HomeAssistant.Controller.Ruuvi
|
||||||
( Ruuvi(..)
|
( Ruuvi(..)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import Data.Void (Void)
|
|||||||
import GHC.Stack (HasCallStack)
|
import GHC.Stack (HasCallStack)
|
||||||
import HomeAssistant.Controller (HASS, HASSEff (..))
|
import HomeAssistant.Controller (HASS, HASSEff (..))
|
||||||
import HomeAssistant.Controller.Bedroom (bedroomButtonController, bedroomDrawerController, bedroomPresenceController, humidifierController)
|
import HomeAssistant.Controller.Bedroom (bedroomButtonController, bedroomDrawerController, bedroomPresenceController, humidifierController)
|
||||||
import HomeAssistant.Controller.Children (childrenBedroomButtonController, schoolLightController)
|
import HomeAssistant.Controller.Children (childrenBedroomButtonController, schoolLightController, childrenAirFilterController)
|
||||||
import HomeAssistant.Controller.Hallway (hallwayLightsController)
|
import HomeAssistant.Controller.Hallway (hallwayLightsController)
|
||||||
import HomeAssistant.Controller.Kitchen (kitchenMotionController)
|
import HomeAssistant.Controller.Kitchen (kitchenMotionController)
|
||||||
import HomeAssistant.Controller.Livingroom (livingroomPlantLights, livingroomPresenceController)
|
import HomeAssistant.Controller.Livingroom (livingroomPlantLights, livingroomPresenceController)
|
||||||
@@ -69,7 +69,8 @@ controllers =
|
|||||||
Controller "livingroom-presence" livingroomPresenceController,
|
Controller "livingroom-presence" livingroomPresenceController,
|
||||||
Controller "hallway-motion-controller" hallwayLightsController,
|
Controller "hallway-motion-controller" hallwayLightsController,
|
||||||
Controller "children-button" childrenBedroomButtonController,
|
Controller "children-button" childrenBedroomButtonController,
|
||||||
Controller "livingroom-plants" livingroomPlantLights
|
Controller "livingroom-plants" livingroomPlantLights,
|
||||||
|
Controller "children-filter" childrenAirFilterController
|
||||||
]
|
]
|
||||||
|
|
||||||
-- | Steps the machine for every inbound message; service calls go to the
|
-- | Steps the machine for every inbound message; service calls go to the
|
||||||
|
|||||||
@@ -36,10 +36,9 @@ import Data.UUID (toText)
|
|||||||
import AFRP (Request(..), Event(..))
|
import AFRP (Request(..), Event(..))
|
||||||
import Control.Monad.IO.Class (liftIO, MonadIO)
|
import Control.Monad.IO.Class (liftIO, MonadIO)
|
||||||
import HomeAssistant.Runtime.RateLimit (RateLimited, RateLimiter, runRateLimited)
|
import HomeAssistant.Runtime.RateLimit (RateLimited, RateLimiter, runRateLimited)
|
||||||
import Control.Monad.Catch (MonadCatch)
|
|
||||||
import GHC.Stack (HasCallStack)
|
import GHC.Stack (HasCallStack)
|
||||||
import UnliftIO (MonadUnliftIO, race, withRunInIO)
|
import UnliftIO (MonadUnliftIO, race, withRunInIO)
|
||||||
import Control.Monad.Catch (onException)
|
import Control.Monad.Catch (MonadCatch, onException)
|
||||||
|
|
||||||
-- | Connect, authenticate, subscribe, then receive and broadcast forever.
|
-- | Connect, authenticate, subscribe, then receive and broadcast forever.
|
||||||
-- Restarting this action reconnects. All setup sends happen before the
|
-- Restarting this action reconnects. All setup sends happen before the
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ loadFlags rootPath allNames = do
|
|||||||
let path = rootPath </> "handlers.json"
|
let path = rootPath </> "handlers.json"
|
||||||
fileMap <- readFlagsFile path
|
fileMap <- readFlagsFile path
|
||||||
let defaults = M.fromList [(n, True) | n <- allNames]
|
let defaults = M.fromList [(n, True) | n <- allNames]
|
||||||
initial = M.unionWith (\fileVal -> const fileVal) fileMap defaults
|
initial = M.unionWith const fileMap defaults
|
||||||
tv <- liftIO $ newTVarIO initial
|
tv <- liftIO $ newTVarIO initial
|
||||||
lock <- liftIO $ newMVar ()
|
lock <- liftIO $ newMVar ()
|
||||||
pure Flags
|
pure Flags
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ module HomeAssistant.Runtime.Graphing
|
|||||||
, readProcessBytes
|
, readProcessBytes
|
||||||
, Graph(..)
|
, Graph(..)
|
||||||
, renderGraph
|
, renderGraph
|
||||||
|
, rangeSuffix
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Exception (evaluate)
|
import Control.Exception (evaluate)
|
||||||
@@ -190,10 +191,10 @@ cfName = \case
|
|||||||
|
|
||||||
defArgs :: FilePath -> Series -> [String]
|
defArgs :: FilePath -> Series -> [String]
|
||||||
defArgs rrdPath series =
|
defArgs rrdPath series =
|
||||||
[ "DEF:" ++ rawF ++ "=" ++ rrdPath ++ ":"
|
( "DEF:" ++ rawF ++ "=" ++ rrdPath ++ ":"
|
||||||
++ srcDs source ++ ":" ++ cfName (srcCF source)
|
++ srcDs source ++ ":" ++ cfName (srcCF source)
|
||||||
]
|
)
|
||||||
++ transformArgs
|
: transformArgs
|
||||||
where
|
where
|
||||||
source = serSource series
|
source = serSource series
|
||||||
alias = serAlias series
|
alias = serAlias series
|
||||||
|
|||||||
+173
-18
@@ -7,71 +7,225 @@ import Control.Monad.IO.Class (liftIO, MonadIO)
|
|||||||
import qualified Data.ByteString as BS
|
import qualified Data.ByteString as BS
|
||||||
import Data.Void (Void)
|
import Data.Void (Void)
|
||||||
import Network.Wai.Handler.Warp (run)
|
import Network.Wai.Handler.Warp (run)
|
||||||
import Servant.API ((:>), Capture, Get, QueryParam, (:-), MimeRender (..), Accept (..), NamedRoutes, JSON, ReqBody, Put)
|
import Servant.API ((:>), Capture, Get, QueryParam, (:-), MimeRender (..), Accept (..), NamedRoutes, JSON, ReqBody, Put, Post, FormUrlEncoded, Header)
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString (ByteString)
|
||||||
import GHC.Generics (Generic)
|
import GHC.Generics (Generic)
|
||||||
import Servant (Handler, err404)
|
import Servant (Handler, err404, fieldLink, toUrlPiece)
|
||||||
import Control.Monad.Catch (throwM, catch, MonadCatch, MonadThrow, SomeException)
|
import Control.Monad.Catch (throwM, catch, MonadCatch, MonadThrow, SomeException)
|
||||||
import Servant.Server (err500, ServerT)
|
import Servant.Server (err500, ServerT)
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
import Data.Map.Strict (Map)
|
import Data.Map.Strict (Map)
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import HomeAssistant.Runtime.Flags (Flags, allFlags, setEnabled, validNames)
|
import HomeAssistant.Runtime.Flags (Flags, allFlags, setEnabled, validNames, isEnabled)
|
||||||
import Control.Exception.Annotated (checkpoint, Annotation (Annotation))
|
import Control.Exception.Annotated (checkpoint, Annotation (Annotation))
|
||||||
import Servant.Server.Generic (genericServeT)
|
import Servant.Server.Generic (genericServeT)
|
||||||
import Network.Wai (Application)
|
import Network.Wai (Application)
|
||||||
import Network.HTTP.Media ((//))
|
import Network.HTTP.Media ((//))
|
||||||
import HomeAssistant.Runtime.Graphing (Graph, Range (..), lookupGraph, graphs, renderGraph)
|
import HomeAssistant.Runtime.Graphing (Graph (..), Range (..), lookupGraph, graphs, renderGraph, rangeSuffix)
|
||||||
import Katip (KatipContextT, Katip, runKatipContextT, LogEnv, KatipContext, ls, Severity (..), logFM)
|
import Katip (KatipContextT, Katip, runKatipContextT, LogEnv, KatipContext, ls, Severity (..), logFM, katipAddContext, sl)
|
||||||
|
import Data.Aeson (ToJSON (toJSON), FromJSON, object, (.=))
|
||||||
|
import Lucid (ToHtml, toHtml, renderBS, toHtmlRaw, HtmlT, Attributes)
|
||||||
|
import qualified Lucid.Html5 as H5
|
||||||
|
import qualified Data.Map.Strict as M
|
||||||
|
import Data.Foldable (for_)
|
||||||
|
import qualified Data.Text as T
|
||||||
|
import Web.FormUrlEncoded (FromForm, fromForm, parseUnique)
|
||||||
|
import Lucid.Base (makeAttributes)
|
||||||
|
import Data.Aeson.Key (fromText)
|
||||||
|
|
||||||
data ImagePng
|
data ImagePng
|
||||||
|
|
||||||
instance MimeRender ImagePng ByteString where
|
instance MimeRender ImagePng GraphPng where
|
||||||
mimeRender _ = BS.fromStrict
|
mimeRender _ (GraphPng bs) = BS.fromStrict bs
|
||||||
|
|
||||||
instance Accept ImagePng where
|
instance Accept ImagePng where
|
||||||
contentType _ = "image" // "png"
|
contentType _ = "image" // "png"
|
||||||
|
|
||||||
|
-- `servant-lucid` package would provide this and the instance for the original lucid(1) package
|
||||||
|
-- but we have lucid2
|
||||||
|
data HTML
|
||||||
|
|
||||||
|
instance Accept HTML where
|
||||||
|
contentType _ = "text" // "html"
|
||||||
|
|
||||||
|
instance ToHtml a => MimeRender HTML a where
|
||||||
|
mimeRender _ = renderBS . toHtml
|
||||||
|
|
||||||
|
newtype StatsPage = StatsPage (forall m. Monad m => HtmlT m ())
|
||||||
|
|
||||||
|
instance ToHtml StatsPage where
|
||||||
|
toHtml (StatsPage inner) = inner
|
||||||
|
toHtmlRaw = toHtml
|
||||||
|
|
||||||
|
page_ :: Monad m => HtmlT m () -> HtmlT m ()
|
||||||
|
page_ inner = H5.doctypehtml_ $ do
|
||||||
|
H5.head_ $ do
|
||||||
|
H5.script_
|
||||||
|
[ H5.src_ "https://cdn.jsdelivr.net/npm/htmx.org@2.0.11/dist/htmx.min.js"
|
||||||
|
, H5.integrity_ "sha384-2OatzQy1H+Zd/IIrjr1TcuDGqLXeHhbooAyJY1KdQMKnr4LZ22k31GBLdYKHmVjg"
|
||||||
|
, H5.crossorigin_ "anonymous"
|
||||||
|
]
|
||||||
|
("" :: Text)
|
||||||
|
H5.style_ css
|
||||||
|
H5.body_ inner
|
||||||
|
|
||||||
|
css :: Text
|
||||||
|
css = T.unlines
|
||||||
|
[ "body { font-family: system-ui, sans-serif; margin: 1rem auto; max-width: 40rem; padding: 0 1rem; }"
|
||||||
|
, "table { border-collapse: collapse; }"
|
||||||
|
, "th, td { padding: 0.4rem 0.75rem; border-bottom: 1px solid #ddd; text-align: left; }"
|
||||||
|
, "input[type=submit] { padding: 0.25rem 0.75rem; cursor: pointer; }"
|
||||||
|
, "img { max-width: 100%; }"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
type HxRequest = Header "HX-Request" Bool
|
||||||
|
|
||||||
data API mode = API
|
data API mode = API
|
||||||
{ getMetrics :: mode :- "metrics" :> Capture "graph" Graph :> QueryParam "range" Range :> Get '[ImagePng] ByteString
|
{ getMetrics :: mode :- "metrics" :> Capture "graph" Graph :> QueryParam "range" Range :> Get '[ImagePng] GraphPng
|
||||||
, getFlags :: mode :- "flags" :> Get '[JSON] (Map Text Bool)
|
, getStats :: mode :- "stats" :> HxRequest :> QueryParam "range" Range :> Get '[HTML] StatsPage
|
||||||
, putFlag :: mode :- "flags" :> Capture "name" Text :> ReqBody '[JSON] Bool :> Put '[JSON] (Map Text Bool)
|
, getFlags :: mode :- "flags" :> Get '[JSON, HTML] FlagsResponse
|
||||||
|
, putFlag :: mode :- "flags" :> Capture "name" Text :> ReqBody '[JSON, FormUrlEncoded] FlagValue :> Put '[HTML, JSON] FlagResponse
|
||||||
|
, postFlag :: mode :- "flags" :> Capture "name" Text :> ReqBody '[JSON, FormUrlEncoded] FlagValue :> Post '[JSON, HTML] FlagResponse
|
||||||
}
|
}
|
||||||
deriving Generic
|
deriving Generic
|
||||||
|
|
||||||
|
newtype GraphPng = GraphPng ByteString
|
||||||
|
|
||||||
getFlagsHandler :: Flags -> LoggingHandler (Map Text Bool)
|
newtype FlagValue = FlagValue Bool
|
||||||
getFlagsHandler flags = allFlags flags
|
deriving FromJSON via Bool
|
||||||
|
|
||||||
putFlagHandler :: Flags -> Text -> Bool -> LoggingHandler (Map Text Bool)
|
instance FromForm FlagValue where
|
||||||
putFlagHandler flags name val
|
fromForm f = FlagValue <$> parseUnique "flag-value" f
|
||||||
|
|
||||||
|
newtype FlagsResponse = FlagsResponse (Map Text Bool)
|
||||||
|
deriving (ToJSON) via (Map Text Bool)
|
||||||
|
|
||||||
|
data FlagResponse = FlagResponse Text Bool
|
||||||
|
|
||||||
|
instance ToHtml FlagResponse where
|
||||||
|
toHtml (FlagResponse name value) = flagRow name value
|
||||||
|
toHtmlRaw = toHtml
|
||||||
|
|
||||||
|
instance ToJSON FlagResponse where
|
||||||
|
toJSON (FlagResponse k v) = object [fromText k .= v]
|
||||||
|
|
||||||
|
flagsPage :: Monad m => FlagsResponse -> HtmlT m ()
|
||||||
|
flagsPage (FlagsResponse f) = page_ $
|
||||||
|
H5.table_ $ do
|
||||||
|
H5.tr_ $ do
|
||||||
|
H5.th_ "Name"
|
||||||
|
H5.th_ "Value"
|
||||||
|
H5.th_ ""
|
||||||
|
for_ (M.toList f) $ uncurry flagRow
|
||||||
|
|
||||||
|
flagRow :: Monad m => Text -> Bool -> HtmlT m ()
|
||||||
|
flagRow name value = H5.tr_ [H5.id_ (rowId name)] $ do
|
||||||
|
H5.td_ (toHtml name)
|
||||||
|
H5.td_ (toHtml (if value then "on" else "off" :: Text))
|
||||||
|
H5.td_ (toggle name value)
|
||||||
|
where
|
||||||
|
toggle :: Monad m => Text -> Bool -> HtmlT m ()
|
||||||
|
toggle key current = H5.form_ [H5.method_ "post", H5.action_ (postFlagsLink key)] $ do
|
||||||
|
H5.input_ [H5.name_ "flag-value", H5.type_ "hidden", H5.value_ (T.pack (show (not current)))]
|
||||||
|
H5.input_
|
||||||
|
[ H5.type_ "submit"
|
||||||
|
, H5.value_ (if current then "Disable" else "Enable")
|
||||||
|
, hxTrigger "click"
|
||||||
|
, hxTarget ("#" <> rowId key)
|
||||||
|
, hxPut (postFlagsLink key)
|
||||||
|
, hxSwap "outerHTML"
|
||||||
|
]
|
||||||
|
postFlagsLink k = "/" <> toUrlPiece (fieldLink putFlag k)
|
||||||
|
|
||||||
|
rowId :: Text -> Text
|
||||||
|
rowId = ("status-" <>)
|
||||||
|
|
||||||
|
hxTrigger :: Text -> Attributes
|
||||||
|
hxTrigger = makeAttributes "hx-trigger"
|
||||||
|
|
||||||
|
hxTarget :: Text -> Attributes
|
||||||
|
hxTarget = makeAttributes "hx-target"
|
||||||
|
|
||||||
|
hxPut :: Text -> Attributes
|
||||||
|
hxPut = makeAttributes "hx-put"
|
||||||
|
|
||||||
|
hxGet :: Text -> Attributes
|
||||||
|
hxGet = makeAttributes "hx-get"
|
||||||
|
|
||||||
|
hxPushUrl :: Text -> Attributes
|
||||||
|
hxPushUrl = makeAttributes "hx-push-url"
|
||||||
|
|
||||||
|
hxSwap :: Text -> Attributes
|
||||||
|
hxSwap = makeAttributes "hx-swap"
|
||||||
|
|
||||||
|
instance ToHtml FlagsResponse where
|
||||||
|
toHtml = flagsPage
|
||||||
|
toHtmlRaw = toHtml
|
||||||
|
|
||||||
|
getFlagsHandler :: Flags -> LoggingHandler FlagsResponse
|
||||||
|
getFlagsHandler = fmap FlagsResponse . allFlags
|
||||||
|
|
||||||
|
putFlagHandler :: Flags -> Text -> FlagValue -> LoggingHandler FlagResponse
|
||||||
|
putFlagHandler flags name (FlagValue val)
|
||||||
| name `S.notMember` validNames flags = throwM err404
|
| name `S.notMember` validNames flags = throwM err404
|
||||||
| otherwise = do
|
| otherwise = checkpoint (Annotation (name, val)) $ katipAddContext (sl "flag" (name, val)) $ do
|
||||||
setEnabled flags name val `catch` \e -> do
|
setEnabled flags name val `catch` \e -> do
|
||||||
logFM ErrorS (ls ("failed to persist handler flag: " <> show (e :: SomeException)))
|
logFM ErrorS (ls ("failed to persist handler flag: " <> show (e :: SomeException)))
|
||||||
throwM err500
|
throwM err500
|
||||||
allFlags flags
|
FlagResponse name <$> isEnabled flags name
|
||||||
|
|
||||||
|
|
||||||
getMetricsHandler :: FilePath -> FilePath -> Graph -> Maybe Range -> LoggingHandler ByteString
|
getMetricsHandler :: FilePath -> FilePath -> Graph -> Maybe Range -> LoggingHandler GraphPng
|
||||||
getMetricsHandler rrdPath rrdtool graphMode mRange = checkpoint (Annotation (graphMode, mRange)) $ do
|
getMetricsHandler rrdPath rrdtool graphMode mRange = checkpoint (Annotation (graphMode, mRange)) $ do
|
||||||
case lookupGraph graphs graphMode of
|
case lookupGraph graphs graphMode of
|
||||||
Nothing -> throwM err404
|
Nothing -> throwM err404
|
||||||
Just spec -> do
|
Just spec -> do
|
||||||
let range = fromMaybe OneDay mRange
|
let range = fromMaybe OneDay mRange
|
||||||
g <- renderGraph rrdPath rrdtool spec range
|
g <- renderGraph rrdPath rrdtool spec range
|
||||||
either (\e -> logFM ErrorS (ls e) >> throwM err500) pure g
|
either (\e -> logFM ErrorS (ls e) >> throwM err500) (pure . GraphPng) g
|
||||||
|
|
||||||
-- server :: FilePath -> FilePath -> API AsServer
|
-- server :: FilePath -> FilePath -> API AsServer
|
||||||
server :: FilePath -> FilePath -> Flags -> ServerT (NamedRoutes API) LoggingHandler
|
server :: FilePath -> FilePath -> Flags -> ServerT (NamedRoutes API) LoggingHandler
|
||||||
server rrdPath rrdtool flags = API
|
server rrdPath rrdtool flags = API
|
||||||
{ getMetrics = getMetricsHandler rrdPath rrdtool
|
{ getMetrics = getMetricsHandler rrdPath rrdtool
|
||||||
|
, getStats = getStatsHandler
|
||||||
, getFlags = getFlagsHandler flags
|
, getFlags = getFlagsHandler flags
|
||||||
, putFlag = putFlagHandler flags
|
, putFlag = putFlagHandler flags
|
||||||
|
, postFlag = putFlagHandler flags -- This exists only for html forms
|
||||||
}
|
}
|
||||||
|
|
||||||
|
statsPage :: Maybe Bool -> Maybe Range -> StatsPage
|
||||||
|
statsPage hx r = StatsPage $
|
||||||
|
if hx == Just True
|
||||||
|
then statsContent r
|
||||||
|
else page_ (statsContent r)
|
||||||
|
|
||||||
|
statsContent :: Monad m => Maybe Range -> HtmlT m ()
|
||||||
|
statsContent r = H5.div_ [H5.id_ "stats"] $ do
|
||||||
|
H5.ul_ $ for_ [minBound..maxBound] $ \range ->
|
||||||
|
H5.li_ $ H5.a_ (link range) $ toHtml $ rangeSuffix range
|
||||||
|
H5.h2_ "Traffic"
|
||||||
|
H5.img_ [H5.src_ (src Traffic)]
|
||||||
|
H5.h2_ "Memory"
|
||||||
|
H5.img_ [H5.src_ (src Memory)]
|
||||||
|
H5.h2_ "Ratelimit"
|
||||||
|
H5.img_ [H5.src_ (src RateLimit)]
|
||||||
|
where
|
||||||
|
src m = "/" <> toUrlPiece (fieldLink getMetrics m r)
|
||||||
|
link range =
|
||||||
|
let url = "/" <> toUrlPiece (fieldLink getStats (Just range))
|
||||||
|
in [ H5.href_ url
|
||||||
|
, hxGet url
|
||||||
|
, hxTarget "#stats"
|
||||||
|
, hxSwap "outerHTML"
|
||||||
|
, hxPushUrl "true"
|
||||||
|
]
|
||||||
|
|
||||||
|
getStatsHandler :: Maybe Bool -> Maybe Range -> LoggingHandler StatsPage
|
||||||
|
getStatsHandler hx r = pure (statsPage hx r)
|
||||||
|
|
||||||
servantApp :: LogEnv -> FilePath -> FilePath -> Flags -> Application
|
servantApp :: LogEnv -> FilePath -> FilePath -> Flags -> Application
|
||||||
servantApp le rrdPath rrdtool flags = genericServeT (toHandler le) (server rrdPath rrdtool flags)
|
servantApp le rrdPath rrdtool flags = genericServeT (toHandler le) (server rrdPath rrdtool flags)
|
||||||
|
|
||||||
@@ -85,3 +239,4 @@ toHandler :: LogEnv -> (forall a. LoggingHandler a -> Handler a)
|
|||||||
toHandler le (LoggingHandler k) = runKatipContextT le () "http" k
|
toHandler le (LoggingHandler k) = runKatipContextT le () "http" k
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -12,6 +12,10 @@ import Support (fakeRequest)
|
|||||||
import Test.Hspec (Spec, describe, it)
|
import Test.Hspec (Spec, describe, it)
|
||||||
import Test.Hspec.Hedgehog (forAll, forAllWith, hedgehog, (===))
|
import Test.Hspec.Hedgehog (forAll, forAllWith, hedgehog, (===))
|
||||||
|
|
||||||
|
-- We are testing laws -> hlint warns about not using laws
|
||||||
|
{-# ANN module "Hlint: ignore" #-}
|
||||||
|
|
||||||
|
|
||||||
-- | Law tests for the Mealy instances. Two machines count as equal when
|
-- | Law tests for the Mealy instances. Two machines count as equal when
|
||||||
-- they emit equal outputs on every input sequence, so each law runs both
|
-- they emit equal outputs on every input sequence, so each law runs both
|
||||||
-- sides on generated inputs.
|
-- sides on generated inputs.
|
||||||
|
|||||||
+3
-2
@@ -19,6 +19,7 @@ import qualified Hedgehog.Gen as Gen
|
|||||||
import qualified Hedgehog.Range as Range
|
import qualified Hedgehog.Range as Range
|
||||||
import Test.Hspec
|
import Test.Hspec
|
||||||
import Test.Hspec.Hedgehog
|
import Test.Hspec.Hedgehog
|
||||||
|
import Data.Maybe (listToMaybe)
|
||||||
|
|
||||||
fakeRequest :: Request
|
fakeRequest :: Request
|
||||||
fakeRequest = Request (sec 0) utc nil "test"
|
fakeRequest = Request (sec 0) utc nil "test"
|
||||||
@@ -52,7 +53,7 @@ instance Functor St where
|
|||||||
fmap f (St g) = St $ \s -> let (a, s') = g s in (f a, s')
|
fmap f (St g) = St $ \s -> let (a, s') = g s in (f a, s')
|
||||||
|
|
||||||
instance Applicative St where
|
instance Applicative St where
|
||||||
pure a = St (\s -> (a, s))
|
pure a = St (a,)
|
||||||
St f <*> St x = St $ \s -> let (f', s') = f s; (a, s'') = x s' in (f' a, s'')
|
St f <*> St x = St $ \s -> let (f', s') = f s; (a, s'') = x s' in (f' a, s'')
|
||||||
|
|
||||||
instance Monad St where
|
instance Monad St where
|
||||||
@@ -165,7 +166,7 @@ lMergeSpec = describe "lMerge" $ do
|
|||||||
changesSpec :: Spec
|
changesSpec :: Spec
|
||||||
changesSpec = describe "changes" $ do
|
changesSpec = describe "changes" $ do
|
||||||
it "first output is always Tick" $
|
it "first output is always Tick" $
|
||||||
runPure changes "hello" !! 0 `shouldBe` Tick
|
listToMaybe (runPure changes "hello") `shouldBe` Just Tick
|
||||||
|
|
||||||
it "outputs Event only on value change" $
|
it "outputs Event only on value change" $
|
||||||
runPure changes "aaaabbbcca"
|
runPure changes "aaaabbbcca"
|
||||||
|
|||||||
+1
-2
@@ -6,7 +6,7 @@ import AFRP (Request (..), Event (..))
|
|||||||
import Control.Concurrent.STM
|
import Control.Concurrent.STM
|
||||||
( atomically
|
( atomically
|
||||||
, dupTChan
|
, dupTChan
|
||||||
, isEmptyTChan
|
|
||||||
, readTChan
|
, readTChan
|
||||||
, writeTChan
|
, writeTChan
|
||||||
)
|
)
|
||||||
@@ -18,7 +18,6 @@ import HomeAssistant.Controller (HASSEff (..), Service (..), Target(..))
|
|||||||
import HomeAssistant.Runtime.Bus
|
import HomeAssistant.Runtime.Bus
|
||||||
import HomeAssistant.Runtime.Flags (loadFlags, setEnabled)
|
import HomeAssistant.Runtime.Flags (loadFlags, setEnabled)
|
||||||
import HomeAssistant.Runtime.Metrics (registerAppMetrics)
|
import HomeAssistant.Runtime.Metrics (registerAppMetrics)
|
||||||
import Control.Monad.IO.Class (liftIO)
|
|
||||||
import Katip (Namespace (Namespace), runKatipContextT)
|
import Katip (Namespace (Namespace), runKatipContextT)
|
||||||
import Katip.Monadic (runNoLoggingT)
|
import Katip.Monadic (runNoLoggingT)
|
||||||
import Support (withTestLogEnv)
|
import Support (withTestLogEnv)
|
||||||
|
|||||||
@@ -80,7 +80,5 @@ req n = Request (UTCTime (toEnum 0) (fromIntegral (0 :: Int))) utc
|
|||||||
uuid = "00000000-0000-0000-0000-" <> pad n
|
uuid = "00000000-0000-0000-0000-" <> pad n
|
||||||
|
|
||||||
lightOn :: [Target] -> Service
|
lightOn :: [Target] -> Service
|
||||||
lightOn targets = Service "light" "turn_on" Nothing targets
|
lightOn = Service "light" "turn_on" Nothing
|
||||||
|
|
||||||
lightOff :: [Target] -> Service
|
|
||||||
lightOff targets = Service "light" "turn_off" Nothing targets
|
|
||||||
@@ -4,7 +4,6 @@ import Test.Hspec
|
|||||||
import Data.Default (def)
|
import Data.Default (def)
|
||||||
import HomeAssistant.Controller (Brightness(..), formatLightAttributes, LightAttributes(..))
|
import HomeAssistant.Controller (Brightness(..), formatLightAttributes, LightAttributes(..))
|
||||||
import Data.Aeson (object, (.=))
|
import Data.Aeson (object, (.=))
|
||||||
import HomeAssistant.Controller ()
|
|
||||||
|
|
||||||
|
|
||||||
spec :: Spec
|
spec :: Spec
|
||||||
|
|||||||
+1
-1
@@ -70,7 +70,7 @@ spec = describe "Flags" $ do
|
|||||||
n <- forAll $ Gen.int (Range.linear 1 50)
|
n <- forAll $ Gen.int (Range.linear 1 50)
|
||||||
liftIO $ withTempDirectory "/tmp" "flags-spec" $ \dir -> do
|
liftIO $ withTempDirectory "/tmp" "flags-spec" $ \dir -> do
|
||||||
flags <- runNoLoggingT (loadFlags dir ["x"])
|
flags <- runNoLoggingT (loadFlags dir ["x"])
|
||||||
mapConcurrently_ (\i -> setEnabled flags "x" (even i)) [1 .. n]
|
mapConcurrently_ (setEnabled flags "x" . even) [1 .. n]
|
||||||
m <- allFlags flags
|
m <- allFlags flags
|
||||||
decoded <- decodeFileStrict (dir <> "/handlers.json")
|
decoded <- decodeFileStrict (dir <> "/handlers.json")
|
||||||
(decoded :: Maybe (Map Text Bool)) `shouldBe` Just m
|
(decoded :: Maybe (Map Text Bool)) `shouldBe` Just m
|
||||||
@@ -7,6 +7,7 @@ import qualified Data.ByteString as BS
|
|||||||
import HomeAssistant.Runtime.Graphing
|
import HomeAssistant.Runtime.Graphing
|
||||||
( GraphSpec (..)
|
( GraphSpec (..)
|
||||||
, Range (..)
|
, Range (..)
|
||||||
|
, Graph(..)
|
||||||
, buildGraphArgs
|
, buildGraphArgs
|
||||||
, graphs
|
, graphs
|
||||||
, lookupGraph
|
, lookupGraph
|
||||||
@@ -21,7 +22,6 @@ import System.Exit (ExitCode (..))
|
|||||||
import System.Process (readProcessWithExitCode)
|
import System.Process (readProcessWithExitCode)
|
||||||
import Test.Hspec
|
import Test.Hspec
|
||||||
import Servant.API (FromHttpApiData(..), ToHttpApiData (..))
|
import Servant.API (FromHttpApiData(..), ToHttpApiData (..))
|
||||||
import HomeAssistant.Runtime.Graphing (Graph(..))
|
|
||||||
|
|
||||||
traffic :: GraphSpec
|
traffic :: GraphSpec
|
||||||
traffic = case lookupGraph graphs Traffic of
|
traffic = case lookupGraph graphs Traffic of
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
|
module HttpServerSpec (spec) where
|
||||||
|
|
||||||
|
import qualified Data.Map.Strict as M
|
||||||
|
import Data.Text (Text)
|
||||||
|
import qualified Data.Text as T
|
||||||
|
import Data.Text.Lazy.Encoding (decodeUtf8)
|
||||||
|
import qualified Data.Text.Lazy as TL
|
||||||
|
import Lucid (Html, renderBS, toHtml)
|
||||||
|
import Test.Hspec
|
||||||
|
|
||||||
|
import HomeAssistant.Runtime.Graphing (Range (..))
|
||||||
|
import HttpServer
|
||||||
|
|
||||||
|
render :: Html () -> String
|
||||||
|
render = TL.unpack . decodeUtf8 . renderBS
|
||||||
|
|
||||||
|
spec :: Spec
|
||||||
|
spec = describe "HttpServer" $ do
|
||||||
|
describe "flagRow" $ do
|
||||||
|
it "renders the whole row so htmx can outerHTML-swap it" $
|
||||||
|
render (flagRow "tea" True) `shouldContain` "<tr id=\"status-tea\">"
|
||||||
|
|
||||||
|
it "requests an outerHTML swap (htmx casing)" $
|
||||||
|
render (flagRow "tea" True) `shouldContain` "hx-swap=\"outerHTML\""
|
||||||
|
|
||||||
|
it "displays on with a Disable button when enabled" $ do
|
||||||
|
let html = render (flagRow "tea" True)
|
||||||
|
html `shouldContain` "<td>on</td>"
|
||||||
|
html `shouldContain` "value=\"Disable\""
|
||||||
|
|
||||||
|
it "displays off with an Enable button when disabled" $ do
|
||||||
|
let html = render (flagRow "tea" False)
|
||||||
|
html `shouldContain` "<td>off</td>"
|
||||||
|
html `shouldContain` "value=\"Enable\""
|
||||||
|
|
||||||
|
describe "flagsPage" $ do
|
||||||
|
let page = flagsPage (FlagsResponse (M.fromList [("tea" :: Text, True)]))
|
||||||
|
it "uses the shared page shell with a style block" $
|
||||||
|
render page `shouldContain` "<style"
|
||||||
|
|
||||||
|
it "has a header row" $ do
|
||||||
|
let html = render page
|
||||||
|
html `shouldContain` "<th>Name</th>"
|
||||||
|
html `shouldContain` "<th>Value</th>"
|
||||||
|
|
||||||
|
it "carries each row id exactly once" $
|
||||||
|
T.count "id=\"status-tea\"" (T.pack (render page)) `shouldBe` 1
|
||||||
|
|
||||||
|
describe "statsPage" $ do
|
||||||
|
it "uses the shared page shell with a style block (full page)" $
|
||||||
|
render (toHtml (statsPage Nothing Nothing)) `shouldContain` "<style"
|
||||||
|
|
||||||
|
it "serves a bare fragment for htmx requests" $ do
|
||||||
|
let html = render (toHtml (statsPage (Just True) (Just OneDay)))
|
||||||
|
html `shouldNotContain` "DOCTYPE"
|
||||||
|
html `shouldContain` "<div id=\"stats\">"
|
||||||
|
|
||||||
|
it "range links swap the stats fragment in place" $ do
|
||||||
|
let html = render (toHtml (statsPage Nothing (Just OneDay)))
|
||||||
|
html `shouldContain` "hx-get=\"/stats?range=24h\""
|
||||||
|
html `shouldContain` "hx-target=\"#stats\""
|
||||||
|
html `shouldContain` "hx-push-url=\"true\""
|
||||||
@@ -8,6 +8,7 @@ import qualified BusSpec
|
|||||||
import qualified ConnectionSpec
|
import qualified ConnectionSpec
|
||||||
import qualified FlagsSpec
|
import qualified FlagsSpec
|
||||||
import qualified GraphingSpec
|
import qualified GraphingSpec
|
||||||
|
import qualified HttpServerSpec
|
||||||
import qualified KitchenSpec
|
import qualified KitchenSpec
|
||||||
import qualified LivingroomSpec
|
import qualified LivingroomSpec
|
||||||
import qualified MetricsSpec
|
import qualified MetricsSpec
|
||||||
@@ -23,6 +24,7 @@ main = hspec $ do
|
|||||||
ConnectionSpec.spec
|
ConnectionSpec.spec
|
||||||
FlagsSpec.spec
|
FlagsSpec.spec
|
||||||
GraphingSpec.spec
|
GraphingSpec.spec
|
||||||
|
HttpServerSpec.spec
|
||||||
KitchenSpec.spec
|
KitchenSpec.spec
|
||||||
LivingroomSpec.spec
|
LivingroomSpec.spec
|
||||||
MetricsSpec.spec
|
MetricsSpec.spec
|
||||||
|
|||||||
+1
-1
@@ -147,7 +147,7 @@ spec = do
|
|||||||
parseInfoDs "step = 10\nrra[0].cf = \"AVERAGE\"\n" `shouldBe` []
|
parseInfoDs "step = 10\nrra[0].cf = \"AVERAGE\"\n" `shouldBe` []
|
||||||
|
|
||||||
describe "schemaMatches" $ do
|
describe "schemaMatches" $ do
|
||||||
let ds name ty = DsSpec (T.pack name) name ty
|
let ds name = DsSpec (T.pack name) name
|
||||||
it "is true for identical schemas regardless of order" $
|
it "is true for identical schemas regardless of order" $
|
||||||
schemaMatches [ds "b" Gauge, ds "a" Derive] [("a", Derive), ("b", Gauge)]
|
schemaMatches [ds "b" Gauge, ds "a" Derive] [("a", Derive), ("b", Gauge)]
|
||||||
`shouldBe` True
|
`shouldBe` True
|
||||||
|
|||||||
+2
-1
@@ -36,7 +36,7 @@ instance Functor Acc where
|
|||||||
fmap f (Acc g) = Acc $ \s -> let (a, s') = g s in (f a, s')
|
fmap f (Acc g) = Acc $ \s -> let (a, s') = g s in (f a, s')
|
||||||
|
|
||||||
instance Applicative Acc where
|
instance Applicative Acc where
|
||||||
pure a = Acc (\s -> (a, s))
|
pure a = Acc (a,)
|
||||||
Acc f <*> Acc x = Acc $ \s -> let (f', s') = f s; (a, s'') = x s' in (f' a, s'')
|
Acc f <*> Acc x = Acc $ \s -> let (f', s') = f s; (a, s'') = x s' in (f' a, s'')
|
||||||
|
|
||||||
instance Monad Acc where
|
instance Monad Acc where
|
||||||
@@ -52,6 +52,7 @@ withTestLogEnv = bracket (initLogEnv "test" "test") closeScribes
|
|||||||
-- | Interpret `HASSEff` in `Acc`: record `CallService`, drop tracing/debug.
|
-- | Interpret `HASSEff` in `Acc`: record `CallService`, drop tracing/debug.
|
||||||
interp :: HASSEff a -> Acc a
|
interp :: HASSEff a -> Acc a
|
||||||
interp (CallService _ svc) = Acc $ \s -> ((), s ++ [svc])
|
interp (CallService _ svc) = Acc $ \s -> ((), s ++ [svc])
|
||||||
|
interp (CallServices _ svc) = Acc $ \s -> ((), s ++ svc)
|
||||||
interp (Debug _) = pure ()
|
interp (Debug _) = pure ()
|
||||||
interp (Trace _ _) = pure ()
|
interp (Trace _ _) = pure ()
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user