Compare commits
291
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
399dcc05b3 | ||
|
|
ef89707bb1 | ||
|
|
c88fc1c7c7 | ||
|
|
7a9dd69d30 | ||
|
|
3f23bb4396 | ||
|
|
af2ff17342 | ||
|
|
fc19ca54b7 | ||
|
|
613901847a | ||
|
|
ecf0109331 | ||
|
|
9710c11476 | ||
|
|
5e3ac8fb1b | ||
|
|
f81a950916 | ||
|
|
7fbfd9c105 | ||
|
|
792c2d9fbc | ||
|
|
bb26d5f289 | ||
|
|
7b42b9ce56 | ||
|
|
0a33b9d653 | ||
|
|
fc0121228e | ||
|
|
924097b246 | ||
|
|
1997276def | ||
|
|
5d9c677cf7 | ||
|
|
1e3a490c12 | ||
|
|
d4ea14ca5c | ||
|
|
62c1a95ead | ||
|
|
e67462ab53 | ||
|
|
e5dc54d0ec | ||
|
|
a5c3990d12 | ||
|
|
8dbdb7ad75 | ||
|
|
a205224a26 | ||
|
|
a96cc9be1f | ||
|
|
8db19622b2 | ||
|
|
53f480980f | ||
|
|
1335572f0a | ||
|
|
cf90030463 | ||
|
|
88f5524aa2 | ||
|
|
e745acf88a | ||
|
|
32bb64918c | ||
|
|
1b9868ddd0 | ||
|
|
6aeac42a46 | ||
|
|
68e7edb8c9 | ||
|
|
a3b5b43777 | ||
|
|
5fae61cdf1 | ||
|
|
1f43234b80 | ||
|
|
ca00f8a803 | ||
|
|
0be7b4fdc8 | ||
|
|
18f10e966b | ||
|
|
e897364a73 | ||
|
|
5fa68fcf43 | ||
|
|
b1368bbc7e | ||
|
|
9432f68c8b | ||
|
|
4c921ed1ba | ||
|
|
f8800ca1f8 | ||
|
|
dddc8aaf55 | ||
|
|
f6e9df2f68 | ||
|
|
47f65dad89 | ||
|
|
f5dae71050 | ||
|
|
b0bda625e0 | ||
|
|
19ba5f0394 | ||
|
|
439a6cd77b | ||
|
|
a5515d1d9f | ||
|
|
7b90633456 | ||
|
|
7838f45ed4 | ||
|
|
2453d717cf | ||
|
|
e772f51982 | ||
|
|
49445ded77 | ||
|
|
b9e60bdb0a | ||
|
|
bcf3856b6f | ||
|
|
d225f922fb | ||
|
|
dfb338fc37 | ||
|
|
26251badda | ||
|
|
5e25e14994 | ||
|
|
94ccea185c | ||
|
|
d21b842d86 | ||
|
|
f79249dfba | ||
|
|
f8c8d374d1 | ||
|
|
ec4961ae50 | ||
|
|
a113b7bd62 | ||
|
|
b5bdba2f38 | ||
|
|
20c337651f | ||
|
|
1c08d8db90 | ||
|
|
245647f12b | ||
|
|
3479ae8d39 | ||
|
|
e23e6f9a54 | ||
|
|
52d095e3c6 | ||
|
|
939915b1fa | ||
|
|
3aa2a434b4 | ||
|
|
944995dc3c | ||
|
|
8de412cf36 | ||
|
|
aeb173c684 | ||
|
|
025ed59480 | ||
|
|
a82d29abd7 | ||
|
|
d365850321 | ||
|
|
3a2d3e8ef8 | ||
|
|
871a3b7aac | ||
|
|
f3207e8bf9 | ||
|
|
772c71c49f | ||
|
|
c56eae2959 | ||
|
|
8c85db8968 | ||
|
|
02e2251bb2 | ||
|
|
e5d0f2714b | ||
|
|
ee1d8b3179 | ||
|
|
29feb4b94b | ||
|
|
4e667759c4 | ||
|
|
ff3875b55d | ||
|
|
76e1c444cc | ||
|
|
4f32d4e13c | ||
|
|
4f628b1f52 | ||
|
|
2100f0022f | ||
|
|
52038dc5ae | ||
|
|
0d331666d6 | ||
|
|
6a5a3c33dc | ||
|
|
1668b9e0d2 | ||
|
|
ec64dbded0 | ||
|
|
dad852a8a0 | ||
|
|
30c6b665f1 | ||
|
|
d034d6e571 | ||
|
|
25ea1f3511 | ||
|
|
842fe47e9e | ||
|
|
168e588387 | ||
|
|
7eb55bd378 | ||
|
|
f31331c83b | ||
|
|
6a22601af7 | ||
|
|
ce9951b93a | ||
|
|
99a45401c7 | ||
|
|
dd76bd2fa7 | ||
|
|
dee176c0f7 | ||
|
|
75a24f98b6 | ||
|
|
327785e5ec | ||
|
|
7ba5d321f6 | ||
|
|
f126dd7397 | ||
|
|
510d3470f9 | ||
|
|
d78830aa52 | ||
|
|
a72d1f68ed | ||
|
|
60f1c5a6b2 | ||
|
|
11ba7b3180 | ||
|
|
7f8e185d7c | ||
|
|
42483c4b61 | ||
|
|
deea6ad06d | ||
|
|
fba608fdbd | ||
|
|
f59490b113 | ||
|
|
6cca57f229 | ||
|
|
ea3edde697 | ||
|
|
14e3ab574c | ||
|
|
4b2eec5703 | ||
|
|
3871d37fdb | ||
|
|
09b005557c | ||
|
|
ef5574d18b | ||
|
|
31dafb0ce0 | ||
|
|
9e7e7ce5a1 | ||
|
|
9aaa8beb99 | ||
|
|
2e29e67664 | ||
|
|
f26b44db08 | ||
|
|
b43172a60c | ||
|
|
2be6fb3066 | ||
|
|
867ced8c81 | ||
|
|
fd71ef53c5 | ||
|
|
e3b64f9255 | ||
|
|
c7e5a4f086 | ||
|
|
f65822c4b2 | ||
|
|
32d4dc2c82 | ||
|
|
218e4f5e99 | ||
|
|
56a5ff99fe | ||
|
|
af4b28b0d7 | ||
|
|
4ee5b4b473 | ||
|
|
a70a7ed9eb | ||
|
|
de2cb2693a | ||
|
|
880adff12c | ||
|
|
d6f7412e9d | ||
|
|
1ab767a317 | ||
|
|
ac8f86eb00 | ||
|
|
47bd9ef211 | ||
|
|
b801fa533a | ||
|
|
8879192097 | ||
|
|
f76ee96ac4 | ||
|
|
23f5a0c53a | ||
|
|
502b814a65 | ||
|
|
c19a806298 | ||
|
|
67eeb75e7b | ||
|
|
fe1fbefee7 | ||
|
|
de04339494 | ||
|
|
998ce75fb6 | ||
|
|
4b392cb4c4 | ||
|
|
8d2109b87e | ||
|
|
b741b01cdf | ||
|
|
8a757c9bb4 | ||
|
|
d714bd7090 | ||
|
|
d64b069053 | ||
|
|
5490b2423e | ||
|
|
ffc9490a32 | ||
|
|
dc6625d33a | ||
|
|
dc8db159f9 | ||
|
|
86e7444603 | ||
|
|
2365806d18 | ||
|
|
7d348f243a | ||
|
|
ddd04623f7 | ||
|
|
9ad1477b1e | ||
|
|
70ab3ddf94 | ||
|
|
4f7529c315 | ||
|
|
bb21072386 | ||
|
|
ead1354e4d | ||
|
|
ae85df0dad | ||
|
|
6e7e349e63 | ||
|
|
f9ba9a87d7 | ||
|
|
e4efec6f0c | ||
|
|
99f355b2fc | ||
|
|
c79d4d47a3 | ||
|
|
8efed2dd2b | ||
|
|
12af6ec1f7 | ||
|
|
f3d1ae1c8c | ||
|
|
5af545e38d | ||
|
|
9da3967dd9 | ||
|
|
c8d94a8203 | ||
|
|
43d78a731a | ||
|
|
a3926704cc | ||
|
|
ea53d4f15b | ||
|
|
ea16e07c46 | ||
|
|
4f47c85208 | ||
|
|
603728a3fb | ||
|
|
018d857746 | ||
|
|
a7ac2b4a3e | ||
|
|
d347809e6e | ||
|
|
a5ffcc22e3 | ||
|
|
f18691560d | ||
|
|
c84a9069ef | ||
|
|
f967916550 | ||
|
|
3fa7c7734b | ||
|
|
cceeb40b16 | ||
|
|
2926ecd4b4 | ||
|
|
ff3c4003cb | ||
|
|
def596a99e | ||
|
|
14f78c0b57 | ||
|
|
7cea238e71 | ||
|
|
4f2f1827ab | ||
|
|
e454e4074b | ||
|
|
c518ac8c73 | ||
|
|
977f624123 | ||
|
|
23f3d4b3b0 | ||
|
|
8d46c4abb7 | ||
|
|
f714fe513d | ||
|
|
087c69ac8d | ||
|
|
bb7dde1963 | ||
|
|
446380e3a9 | ||
|
|
e07f248cc8 | ||
|
|
90ac6e0825 | ||
|
|
4e3c953acf | ||
|
|
ede183d026 | ||
|
|
481c9dca65 | ||
|
|
4025106234 | ||
|
|
a3134f997f | ||
|
|
3607fe445e | ||
|
|
61d549a9d5 | ||
|
|
2b84bc53e9 | ||
|
|
282dab43eb | ||
|
|
cc9df4004c | ||
|
|
b5d70ac1cd | ||
|
|
9118c16fe3 | ||
|
|
fe67849e57 | ||
|
|
21b303ba7c | ||
|
|
9375f25629 | ||
|
|
905654cc84 | ||
|
|
219fa3c615 | ||
|
|
c4e055ce51 | ||
|
|
10eca353ab | ||
|
|
88fc50afb8 | ||
|
|
19c68d73a7 | ||
|
|
41c41a860e | ||
|
|
4bf59b45b7 | ||
|
|
fc99d9e0d7 | ||
|
|
90f1239fba | ||
|
|
b2fe1cb1e0 | ||
|
|
065a879190 | ||
|
|
89882b4863 | ||
|
|
18a08daa91 | ||
|
|
aa59773d22 | ||
|
|
a4777f26b6 | ||
|
|
92faa9741b | ||
|
|
bf0a53e64c | ||
|
|
7be4a02e31 | ||
|
|
ad9c25a5a2 | ||
|
|
a83a127e31 | ||
|
|
4b9114fd8d | ||
|
|
e049a71458 | ||
|
|
0c944f2382 | ||
|
|
75525b67e4 | ||
|
|
85768dc489 | ||
|
|
1a221a40d3 | ||
|
|
0821deb877 | ||
|
|
31ada14111 | ||
|
|
20139394f3 | ||
|
|
eb139cf872 | ||
|
|
ae82fd2233 |
@@ -68,7 +68,7 @@ jobs:
|
|||||||
SHA: ${{ github.sha }}
|
SHA: ${{ github.sha }}
|
||||||
REF_NAME: ${{ github.ref_name }}
|
REF_NAME: ${{ github.ref_name }}
|
||||||
DEBIAN_FRONTEND: noninteractive
|
DEBIAN_FRONTEND: noninteractive
|
||||||
GO_VERSION: '1.25.0'
|
GO_VERSION: '1.26.0'
|
||||||
npm_config_store_dir: /cache/pnpm-store
|
npm_config_store_dir: /cache/pnpm-store
|
||||||
# The Go half wants the NDK; the Gradle half wants a platform.
|
# The Go half wants the NDK; the Gradle half wants a platform.
|
||||||
ANDROID_HOME: /cache/android-sdk
|
ANDROID_HOME: /cache/android-sdk
|
||||||
@@ -139,6 +139,23 @@ jobs:
|
|||||||
echo "skip=true" >> "$GITHUB_OUTPUT"
|
echo "skip=true" >> "$GITHUB_OUTPUT"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Nor is a prerelease, and this trigger is `v*`, which matches
|
||||||
|
# `v0.4.0-beta.1`. Two reasons it is worst here. The APK goes
|
||||||
|
# to the *generic* registry, which is readable without
|
||||||
|
# credentials so Obtainium can poll a plain URL — a beta would
|
||||||
|
# be offered to every device on it. And the versionCode maths
|
||||||
|
# below splits on dots and would read "1" out of "0-beta",
|
||||||
|
# producing a code that is wrong rather than a build that
|
||||||
|
# fails: Android orders releases by that integer and refuses
|
||||||
|
# anything not greater than what is installed.
|
||||||
|
case "$v" in
|
||||||
|
*-*)
|
||||||
|
echo "v$v is a prerelease; not publishing an APK for it"
|
||||||
|
echo "skip=true" >> "$GITHUB_OUTPUT"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
echo "skip=false" >> "$GITHUB_OUTPUT"
|
echo "skip=false" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
# Android orders releases by an integer and refuses anything
|
# Android orders releases by an integer and refuses anything
|
||||||
|
|||||||
@@ -72,6 +72,22 @@ jobs:
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# A prerelease is not a shipment either, and this trigger is
|
||||||
|
# `v*` — which matches `v0.4.0-beta.1`. Nothing produces one
|
||||||
|
# today; the guard is here because the thing that would is
|
||||||
|
# semantic-release's `prerelease: true` channel, a one-line
|
||||||
|
# change in .releaserc.yml whose blast radius is four public
|
||||||
|
# package channels. Same argument as release.yml's
|
||||||
|
# `chore(release):` guard: cheap, against something a future
|
||||||
|
# edit turns on somewhere else entirely.
|
||||||
|
case "$v" in
|
||||||
|
*-*)
|
||||||
|
echo "$v is a prerelease; not packaging it for pacman"
|
||||||
|
echo "skip=true" >> "$GITHUB_OUTPUT"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
echo "skip=false" >> "$GITHUB_OUTPUT"
|
echo "skip=false" >> "$GITHUB_OUTPUT"
|
||||||
echo "tag=$v" >> "$GITHUB_OUTPUT"
|
echo "tag=$v" >> "$GITHUB_OUTPUT"
|
||||||
echo "building $v"
|
echo "building $v"
|
||||||
|
|||||||
+23
-6
@@ -36,7 +36,7 @@ concurrency:
|
|||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
env:
|
env:
|
||||||
GO_VERSION: '1.25.0'
|
GO_VERSION: '1.26.0'
|
||||||
# Shared by all three Playwright consumers (@playwright/cli, e2e/'s
|
# Shared by all three Playwright consumers (@playwright/cli, e2e/'s
|
||||||
# @playwright/test, frontend/'s Vitest provider). See the browsers
|
# @playwright/test, frontend/'s Vitest provider). See the browsers
|
||||||
# step in job 2 for why that is not the whole story.
|
# step in job 2 for why that is not the whole story.
|
||||||
@@ -53,7 +53,7 @@ jobs:
|
|||||||
check:
|
check:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
# Not golang:1.25 — this job runs `make ui-test`, which is Vitest
|
# Not golang:1.26 — this job runs `make ui-test`, which is Vitest
|
||||||
# *browser* mode and needs a Chromium and its system libraries
|
# *browser* mode and needs a Chromium and its system libraries
|
||||||
# anyway, so the "fast job needs no browser" split does not hold.
|
# anyway, so the "fast job needs no browser" split does not hold.
|
||||||
# Not the Playwright image either: e2e/ pins @playwright/test
|
# Not the Playwright image either: e2e/ pins @playwright/test
|
||||||
@@ -107,15 +107,32 @@ jobs:
|
|||||||
# Conventional Commits. `.releaserc.yml` has always derived the
|
# Conventional Commits. `.releaserc.yml` has always derived the
|
||||||
# version from the commit type; until now nothing checked that the
|
# version from the commit type; until now nothing checked that the
|
||||||
# type was one it recognises, so a malformed subject silently meant
|
# type was one it recognises, so a malformed subject silently meant
|
||||||
# "no release". BEFORE is the push's previous tip and is absent or
|
# "no release".
|
||||||
# all-zeros for a new branch, in which case only the tip is linted.
|
#
|
||||||
|
# **On a `pull_request` there is no `before`.** Gitea leaves
|
||||||
|
# `github.event.before` empty for one, so this step fell through to
|
||||||
|
# bare `make commit-check`, which lints `git log -1` — the tip
|
||||||
|
# alone. Every other commit the branch would bring was first
|
||||||
|
# examined by *main's* post-merge run, which is a green PR that
|
||||||
|
# stops being true after the merge, and which happened twice (#254).
|
||||||
|
# The PR's base is the stand-in: the range below already excludes
|
||||||
|
# what the base shares with the branch, because base advances on
|
||||||
|
# main and those commits stay reachable from it.
|
||||||
|
#
|
||||||
|
# Both are handed to the shell rather than chosen in an expression:
|
||||||
|
# `github.event.issue.number` in unclaim.yml is this repo's proof
|
||||||
|
# that payload fields resolve, and the shell then falls back to
|
||||||
|
# today's behaviour for a dispatch run or a missing field instead of
|
||||||
|
# depending on how `&&`/`||` treat an absent context.
|
||||||
- name: Commit messages
|
- name: Commit messages
|
||||||
working-directory: /src
|
working-directory: /src
|
||||||
env:
|
env:
|
||||||
BEFORE: ${{ github.event.before }}
|
PR_BASE: ${{ github.event.pull_request.base.sha }}
|
||||||
|
PUSH_BEFORE: ${{ github.event.before }}
|
||||||
run: |
|
run: |
|
||||||
set -eu
|
set -eu
|
||||||
if [ -n "${BEFORE:-}" ] && [ "${BEFORE#0000000}" = "$BEFORE" ] \
|
BEFORE="${PR_BASE:-${PUSH_BEFORE:-}}"
|
||||||
|
if [ -n "$BEFORE" ] && [ "${BEFORE#0000000}" = "$BEFORE" ] \
|
||||||
&& git cat-file -e "$BEFORE^{commit}" 2>/dev/null; then
|
&& git cat-file -e "$BEFORE^{commit}" 2>/dev/null; then
|
||||||
make commit-check RANGE="$BEFORE..$SHA"
|
make commit-check RANGE="$BEFORE..$SHA"
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ jobs:
|
|||||||
SHA: ${{ github.sha }}
|
SHA: ${{ github.sha }}
|
||||||
REF_NAME: ${{ github.ref_name }}
|
REF_NAME: ${{ github.ref_name }}
|
||||||
DEBIAN_FRONTEND: noninteractive
|
DEBIAN_FRONTEND: noninteractive
|
||||||
GO_VERSION: '1.25.0'
|
GO_VERSION: '1.26.0'
|
||||||
npm_config_store_dir: /cache/pnpm-store
|
npm_config_store_dir: /cache/pnpm-store
|
||||||
steps:
|
steps:
|
||||||
# The same set ci.yml's check job installs: the app is cgo, and
|
# The same set ci.yml's check job installs: the app is cgo, and
|
||||||
@@ -95,6 +95,19 @@ jobs:
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Nor is a prerelease, and this trigger is `v*`, which matches
|
||||||
|
# `v0.4.0-beta.1`. The mildest of the four — assets attach to
|
||||||
|
# the prerelease's own Gitea release and no package manager
|
||||||
|
# reads them — but four workflows sharing one trigger should
|
||||||
|
# share one answer about what a shipment is.
|
||||||
|
case "$v" in
|
||||||
|
*-*)
|
||||||
|
echo "$v is a prerelease; not attaching desktop assets"
|
||||||
|
echo "skip=true" >> "$GITHUB_OUTPUT"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
echo "skip=false" >> "$GITHUB_OUTPUT"
|
echo "skip=false" >> "$GITHUB_OUTPUT"
|
||||||
echo "tag=$v" >> "$GITHUB_OUTPUT"
|
echo "tag=$v" >> "$GITHUB_OUTPUT"
|
||||||
echo "version=${v#v}" >> "$GITHUB_OUTPUT"
|
echo "version=${v#v}" >> "$GITHUB_OUTPUT"
|
||||||
|
|||||||
@@ -56,6 +56,18 @@ jobs:
|
|||||||
echo "skip=true" >> "$GITHUB_OUTPUT"
|
echo "skip=true" >> "$GITHUB_OUTPUT"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Nor is a prerelease, and this trigger is `v*`, which matches
|
||||||
|
# `v0.4.0-beta.1`. It matters most here of the four: the tap
|
||||||
|
# is public, and `brew upgrade` would offer a beta to everyone
|
||||||
|
# on it.
|
||||||
|
case "$VERSION" in
|
||||||
|
*-*)
|
||||||
|
echo "$TAG is a prerelease; not syncing it to a public tap"
|
||||||
|
echo "skip=true" >> "$GITHUB_OUTPUT"
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
echo "skip=false" >> "$GITHUB_OUTPUT"
|
echo "skip=false" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
TARBALL="${SOURCE_TARBALL_BASE}/${TAG}.tar.gz"
|
TARBALL="${SOURCE_TARBALL_BASE}/${TAG}.tar.gz"
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ jobs:
|
|||||||
# claim with a test behind it now (cmd/indexbuild/deps_test.go),
|
# claim with a test behind it now (cmd/indexbuild/deps_test.go),
|
||||||
# because the v3 migration quietly broke it and this job was where
|
# because the v3 migration quietly broke it and this job was where
|
||||||
# that surfaced.
|
# that surfaced.
|
||||||
image: golang:1.25
|
image: golang:1.26
|
||||||
# This host path must exist on the runner and be listed verbatim in
|
# This host path must exist on the runner and be listed verbatim in
|
||||||
# act_runner's container.valid_volumes. It holds explore-staging/
|
# act_runner's container.valid_volumes. It holds explore-staging/
|
||||||
# (counts.bin + state.json) and yj.db — the checkpoint that makes
|
# (counts.bin + state.json) and yj.db — the checkpoint that makes
|
||||||
@@ -148,6 +148,49 @@ jobs:
|
|||||||
sha256sum /tmp/core-index.db.zst | tee /tmp/core-index.db.zst.sha256
|
sha256sum /tmp/core-index.db.zst | tee /tmp/core-index.db.zst.sha256
|
||||||
ls -lh /tmp/core-index.db.zst
|
ls -lh /tmp/core-index.db.zst
|
||||||
|
|
||||||
|
# Nothing is published until it has been imported by the code that
|
||||||
|
# imports it on a user's machine. The exporter and the importer are
|
||||||
|
# two descriptions of one storage format, and every other tier tests
|
||||||
|
# the importer against a *fixture* rather than against the file being
|
||||||
|
# shipped — a second description free to be wrong in the same
|
||||||
|
# direction as the code reading it.
|
||||||
|
#
|
||||||
|
# That is how #258 reached everyone: the importer positioned its batch
|
||||||
|
# walk with a Go `string` cursor against this file's 16-byte `mbid`
|
||||||
|
# column, and SQLite neither coerces between TEXT and BLOB nor
|
||||||
|
# complains about the comparison — so the walk merged no rows and
|
||||||
|
# never advanced, and no install could finish its first index build.
|
||||||
|
# The fixture guarding that walk writes the old text encoding, and the
|
||||||
|
# only compact fixture is one row, below the batch size, so the bound
|
||||||
|
# query never ran. Both were green throughout.
|
||||||
|
#
|
||||||
|
# Running it here is also what keeps the failure cheap: the previous
|
||||||
|
# artifact stays published while this runs, so a failure costs one
|
||||||
|
# stale catalog rather than an empty one for every install.
|
||||||
|
#
|
||||||
|
# `-tags indexbuild` because this container has no GTK and the default
|
||||||
|
# tag set links the app through Wails. The `--- PASS` grep is not
|
||||||
|
# decoration — the test skips without the path, and a skip is
|
||||||
|
# indistinguishable from a pass in a summary line.
|
||||||
|
- name: Import the exported artifact as a client does
|
||||||
|
if: steps.maintain.outputs.complete == 'true' && steps.maintain.outputs.changed == 'true'
|
||||||
|
working-directory: /src
|
||||||
|
env:
|
||||||
|
YJ_CORE_INDEX_ARTIFACT: /tmp/core-index.db.zst
|
||||||
|
run: |
|
||||||
|
set -eu
|
||||||
|
log=/tmp/import-check.log
|
||||||
|
if ! go test -tags indexbuild -count=1 -timeout 30m -v \
|
||||||
|
-run TestImportPublishedArtifact ./backend/explore/ > "$log" 2>&1;
|
||||||
|
then
|
||||||
|
tail -60 "$log"
|
||||||
|
echo "::error::The artifact does not import; not publishing it."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
cat "$log"
|
||||||
|
grep -qF -- 'PASS: TestImportPublishedArtifact' "$log"
|
||||||
|
echo "::notice::The artifact imports as a client would merge it."
|
||||||
|
|
||||||
- name: Publish to the Gitea package registry
|
- name: Publish to the Gitea package registry
|
||||||
if: steps.maintain.outputs.complete == 'true' && steps.maintain.outputs.changed == 'true'
|
if: steps.maintain.outputs.complete == 'true' && steps.maintain.outputs.changed == 'true'
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -1,11 +1,36 @@
|
|||||||
name: Release
|
name: Release
|
||||||
|
|
||||||
# The sixth workflow, and the one that decides whether the other three
|
# The sixth workflow, and the one that decides whether the other three
|
||||||
# run at all. On every push to main it reads the Conventional Commits
|
# run at all. It reads the Conventional Commits since the last tag, and
|
||||||
# since the last tag, and if any of them is releasable it writes the
|
# if any of them is releasable it writes the changelog, pushes the tag,
|
||||||
# changelog, pushes the tag, and creates the Gitea release whose body is
|
# and creates the Gitea release whose body is that changelog section.
|
||||||
# that changelog section. The publishing workflows are keyed on `v*`, so
|
# The publishing workflows are keyed on `v*`, so the tag push is what
|
||||||
# the tag push is what starts them.
|
# starts them.
|
||||||
|
#
|
||||||
|
# **It is triggered by hand, and there is deliberately no `push`
|
||||||
|
# trigger.** There was one, on `main`, which made the trigger "a PR was
|
||||||
|
# merged" and nothing else: eight releases in twenty-two hours
|
||||||
|
# (v0.0.1 -> v0.3.1) for one session's work, each fanning out to four
|
||||||
|
# publishers on a runner with capacity 1, so ~40 packaging jobs shipped
|
||||||
|
# three issues and ordinary PR CI queued behind them. A version per
|
||||||
|
# merged PR is a version per unit of *work*, not per *shipment*, and
|
||||||
|
# pacman, Homebrew and Obtainium see every one.
|
||||||
|
#
|
||||||
|
# Nothing else had to change to batch them: semantic-release already
|
||||||
|
# reads every commit since the last tag, so five fixes and two feats
|
||||||
|
# become one minor release with all seven in the notes. Release
|
||||||
|
# frequency was only ever how often this file fired.
|
||||||
|
#
|
||||||
|
# This is the rule `index-artifact.yml` states and is the other instance
|
||||||
|
# of: **a job that mutates state which cannot be rebuilt in ten minutes
|
||||||
|
# is triggered deliberately, not by a push.** A release here is a tag,
|
||||||
|
# a Gitea release, an Arch package, a Homebrew formula, a signed APK and
|
||||||
|
# desktop assets — and an Android version going backwards costs the user
|
||||||
|
# their library (docs/android-release.md).
|
||||||
|
#
|
||||||
|
# A schedule was considered and rejected: a cron batches without anyone
|
||||||
|
# having to remember, but it puts the decision back on a timer, which is
|
||||||
|
# the thing being removed.
|
||||||
#
|
#
|
||||||
# **Why the tag is pushed with PACKAGE_TOKEN and not the Actions token.**
|
# **Why the tag is pushed with PACKAGE_TOKEN and not the Actions token.**
|
||||||
# Gitea, like GitHub, does not start a workflow from a ref pushed by a
|
# Gitea, like GitHub, does not start a workflow from a ref pushed by a
|
||||||
@@ -19,9 +44,12 @@ name: Release
|
|||||||
# instead.
|
# instead.
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
|
||||||
branches: [main]
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
dry_run:
|
||||||
|
description: "Report what would be released and stop"
|
||||||
|
required: false
|
||||||
|
default: "false"
|
||||||
|
|
||||||
# Cutting a tag is not a thing to cancel halfway: a superseded run must
|
# Cutting a tag is not a thing to cancel halfway: a superseded run must
|
||||||
# finish, not be killed between `git push --tags` and the release POST.
|
# finish, not be killed between `git push --tags` and the release POST.
|
||||||
@@ -163,14 +191,32 @@ jobs:
|
|||||||
# been right, the tag would have been right, every job would have
|
# been right, the tag would have been right, every job would have
|
||||||
# been green, and the release body would have been empty. Check the
|
# been green, and the release body would have been empty. Check the
|
||||||
# notes, not the exit code, before moving any of these.
|
# notes, not the exit code, before moving any of these.
|
||||||
|
# The point of a manual trigger is deliberateness, and deliberate
|
||||||
|
# means being able to look before pulling the lever. `--dry-run`
|
||||||
|
# reports the version and the notes and writes nothing: no tag, no
|
||||||
|
# release, no publishers. `make release-dry` is the same answer
|
||||||
|
# locally; this is it from the runner, against the same commit and
|
||||||
|
# the same tag history, which is what actually decides.
|
||||||
- name: Run semantic-release
|
- name: Run semantic-release
|
||||||
if: steps.guard.outputs.skip == 'false'
|
if: steps.guard.outputs.skip == 'false'
|
||||||
working-directory: /src
|
working-directory: /src
|
||||||
|
env:
|
||||||
|
DRY_RUN: ${{ inputs.dry_run }}
|
||||||
run: |
|
run: |
|
||||||
set -eu
|
set -eu
|
||||||
git config user.name "yellowjacket-ci"
|
git config user.name "yellowjacket-ci"
|
||||||
git config user.email "yj@yellowjacket.app"
|
git config user.email "yj@yellowjacket.app"
|
||||||
|
|
||||||
|
# Anything but a literal "true" releases for real. A typo in a
|
||||||
|
# dispatch box must not silently turn a shipment into a no-op
|
||||||
|
# that reports success — the failure worth avoiding is the one
|
||||||
|
# where nothing happens and the run is green.
|
||||||
|
dry=""
|
||||||
|
if [ "${DRY_RUN:-false}" = "true" ]; then
|
||||||
|
echo "DRY RUN — no tag will be pushed and no release created"
|
||||||
|
dry="--dry-run"
|
||||||
|
fi
|
||||||
|
|
||||||
npx --yes \
|
npx --yes \
|
||||||
-p semantic-release@25 \
|
-p semantic-release@25 \
|
||||||
-p @semantic-release/commit-analyzer@13 \
|
-p @semantic-release/commit-analyzer@13 \
|
||||||
@@ -178,5 +224,5 @@ jobs:
|
|||||||
-p @semantic-release/changelog@7 \
|
-p @semantic-release/changelog@7 \
|
||||||
-p @semantic-release/exec@7 \
|
-p @semantic-release/exec@7 \
|
||||||
-p conventional-changelog-conventionalcommits@9 \
|
-p conventional-changelog-conventionalcommits@9 \
|
||||||
semantic-release \
|
semantic-release $dry \
|
||||||
--repository-url "https://x-access-token:${PACKAGE_TOKEN}@${SERVER_URL#https://}/${REPO}.git"
|
--repository-url "https://x-access-token:${PACKAGE_TOKEN}@${SERVER_URL#https://}/${REPO}.git"
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
name: Unclaim
|
||||||
|
|
||||||
|
# A `Closes #N` footer in a commit body closes the issue on merge — and
|
||||||
|
# leaves `Status/In Progress` on it, because Gitea's auto-close touches
|
||||||
|
# state and nothing else. So #100 was closed and simultaneously marked
|
||||||
|
# as being actively worked on, and `scripts/issue.sh close` (which does
|
||||||
|
# drop the label) is exactly the thing the footer exists to avoid
|
||||||
|
# calling.
|
||||||
|
#
|
||||||
|
# **This hooks the close, not the merge.** Stripping the label in the
|
||||||
|
# PR would work and would be a per-PR habit; habits are what the footer
|
||||||
|
# removed. `issues: [closed]` covers every path an issue can close by —
|
||||||
|
# the footer on merge, `issue.sh close`, someone clicking Close in the
|
||||||
|
# web UI — and asks nothing of anyone at any of them.
|
||||||
|
#
|
||||||
|
# **Reopening deliberately does not restore it.** Reopening says the
|
||||||
|
# work was not finished, not that somebody is at a keyboard doing it
|
||||||
|
# now; the claim gets re-made by whoever picks it up.
|
||||||
|
#
|
||||||
|
# **This is not instant, and should not be described as it.** The
|
||||||
|
# runner has capacity 1 and is shared with an index build that can hold
|
||||||
|
# it for three hours, so a label tweak can queue behind one. Stale for
|
||||||
|
# an afternoon beats stale forever, which is what it was.
|
||||||
|
#
|
||||||
|
# The audit that answers "is this still firing" stays in CLAUDE.md and
|
||||||
|
# is one command:
|
||||||
|
#
|
||||||
|
# ./scripts/issue.sh list --state closed --label "Status/In Progress"
|
||||||
|
#
|
||||||
|
# A workflow that silently stops working is the failure mode this whole
|
||||||
|
# area has already produced once.
|
||||||
|
|
||||||
|
on:
|
||||||
|
issues:
|
||||||
|
types: [closed]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
unclaim:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ubuntu:24.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Drop the claim label
|
||||||
|
# **Inside a container the act runner selects `sh`, not bash**, so
|
||||||
|
# `set -o pipefail` fails the job on its second line with "Illegal
|
||||||
|
# option" and the step never reaches the API. `homebrew-formula.yml`
|
||||||
|
# carries the same `set -euo pipefail` without trouble because it
|
||||||
|
# runs with **no container**, on the host image where bash is the
|
||||||
|
# default — so "another workflow does it" is not evidence here.
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
# The automatic Actions token, as release.yml uses for the
|
||||||
|
# floor tag. It needs no more than write access to this repo.
|
||||||
|
TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
|
API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
|
||||||
|
ISSUE: ${{ github.event.issue.number }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# `ca-certificates` is named because `--no-install-recommends`
|
||||||
|
# skips it, and `ubuntu:24.04` ships no CA bundle of its own —
|
||||||
|
# so curl comes up unable to verify TLS against our own Gitea
|
||||||
|
# and fails with "error setting certificate file" (exit 77).
|
||||||
|
# Every other containerised workflow here spells it out for the
|
||||||
|
# same reason; this one did not, and cost a release cycle.
|
||||||
|
apt-get update -qq
|
||||||
|
apt-get install -y -qq --no-install-recommends \
|
||||||
|
ca-certificates curl jq >/dev/null
|
||||||
|
|
||||||
|
label_id=$(
|
||||||
|
curl -sSf -H "Authorization: token $TOKEN" "$API/labels?limit=100" |
|
||||||
|
jq -r '.[] | select(.name == "Status/In Progress") | .id'
|
||||||
|
)
|
||||||
|
|
||||||
|
# The label not existing is a repo somebody reorganised, not a
|
||||||
|
# failure of this run — say so and stop, rather than failing a
|
||||||
|
# job on every close from then on.
|
||||||
|
if [ -z "$label_id" ]; then
|
||||||
|
echo "unclaim: no 'Status/In Progress' label in this repo; nothing to do"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# DELETE is idempotent here: an issue that never carried the
|
||||||
|
# label answers the same as one that did, which is what makes
|
||||||
|
# this safe to run on *every* close rather than only the ones
|
||||||
|
# that were claimed.
|
||||||
|
# The body is captured, not discarded, so a refusal is
|
||||||
|
# diagnosable from this log alone. Whether the automatic
|
||||||
|
# token carries issue-write scope is still unproven, and
|
||||||
|
# "DELETE returned 403" without Gitea's own sentence costs
|
||||||
|
# another merge to find out which of the two it is.
|
||||||
|
body=$(mktemp)
|
||||||
|
code=$(
|
||||||
|
curl -sS -o "$body" -w '%{http_code}' -X DELETE \
|
||||||
|
-H "Authorization: token $TOKEN" \
|
||||||
|
"$API/issues/$ISSUE/labels/$label_id"
|
||||||
|
)
|
||||||
|
|
||||||
|
case "$code" in
|
||||||
|
204) echo "unclaim: #$ISSUE is closed and unclaimed" ;;
|
||||||
|
*)
|
||||||
|
echo "unclaim: DELETE returned $code for #$ISSUE" >&2
|
||||||
|
cat "$body" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
@@ -88,3 +88,10 @@ build/android/overlay.json
|
|||||||
# Written by @semantic-release/changelog purely to carry the release notes
|
# Written by @semantic-release/changelog purely to carry the release notes
|
||||||
# into scripts/gitea-release.sh; the release page is the changelog.
|
# into scripts/gitea-release.sh; the release page is the changelog.
|
||||||
.release-notes.md
|
.release-notes.md
|
||||||
|
|
||||||
|
# Agent session log and loop state: local scratch, not repo memory
|
||||||
|
# (that is CLAUDE.md and .planning/). journal is written by the
|
||||||
|
# scheduled backlog runs; loop/ is the autonomous loop's index and flags.
|
||||||
|
.pi/journal.md
|
||||||
|
.pi/schedule-prompts.json
|
||||||
|
.pi/loop/
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
---
|
||||||
|
name: diffreview
|
||||||
|
package: yj-loop
|
||||||
|
description: Scope-tight review of a loop PR's diff for correctness within the plan's stated scope. The understood-diff half of the critique fan-out.
|
||||||
|
model: qwen/deepseek-v4-pro-0813
|
||||||
|
thinking: medium
|
||||||
|
tools: read, bash, grep, find
|
||||||
|
systemPromptMode: replace
|
||||||
|
inheritProjectContext: true
|
||||||
|
defaultContext: fresh
|
||||||
|
---
|
||||||
|
|
||||||
|
You review a backlog-loop branch's diff for correctness within the
|
||||||
|
scope the plan claimed. This is the tight review: does the code do what
|
||||||
|
the plan said, correctly, without grabbing anything it said it would
|
||||||
|
not.
|
||||||
|
|
||||||
|
Read the issue, the plan comment, and the diff itself. Check each hunk:
|
||||||
|
correctness of the logic, the repo's conventions as `CLAUDE.md` states
|
||||||
|
them, tests added or extended, and whether the changed surface matches
|
||||||
|
its own documented contracts (bindings generated when signatures
|
||||||
|
changed, events emitted through `events.Emit`, lint grammar). Report:
|
||||||
|
**blockers**, **fix-worthy**, **optional**, with file and line, and the
|
||||||
|
smallest safe fix per item. Do not modify files. Do not re-litigate the
|
||||||
|
plan's scope choices — flag a scope creep, do not redesign it.
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
name: escalate
|
||||||
|
package: yj-loop
|
||||||
|
description: The loop's ceiling — re-runs a leg the two lower tiers failed, seeded with their written failure summaries. Fresh session, never parallel, once a day.
|
||||||
|
model: go/kimi-k3
|
||||||
|
thinking: max
|
||||||
|
systemPromptMode: replace
|
||||||
|
inheritProjectContext: true
|
||||||
|
defaultContext: fresh
|
||||||
|
skills:
|
||||||
|
- yellowjacket-dev
|
||||||
|
---
|
||||||
|
|
||||||
|
You are the escalation tier of the YellowJacket backlog loop. Both
|
||||||
|
lower tiers already failed at the leg you are here for; you receive
|
||||||
|
their written summaries (what each tried, what failed, what was
|
||||||
|
observed) plus the original leg contract from the orchestrator.
|
||||||
|
|
||||||
|
Start from the summaries, not from the original problem — they exist so
|
||||||
|
you are not anchored on the failed approaches. Read `CLAUDE.md` and
|
||||||
|
`.planning/NOTES.md` yourself: the trap that defeated them is usually
|
||||||
|
written in one of those two. `yellowjacket-dev` tells you how to run
|
||||||
|
the harness tiers.
|
||||||
|
|
||||||
|
You may delegate mechanical subtasks, never the leg. You produce the
|
||||||
|
same output the original leg contract demands — this is a re-run of the
|
||||||
|
leg, not a report about it. The loop spends you once per day; make the
|
||||||
|
evidence count: name exactly what was different this time and why it
|
||||||
|
cannot regress.
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
---
|
||||||
|
name: inspect
|
||||||
|
package: yj-loop
|
||||||
|
description: Mechanical gatherer for the backlog loop — dumps tracker, PR, CI and branch state verbatim into a digest. No judgement, no writes beyond the digest.
|
||||||
|
model: go/mimo-v2.5
|
||||||
|
thinking: off
|
||||||
|
tools: read, bash, grep, find
|
||||||
|
systemPromptMode: replace
|
||||||
|
inheritProjectContext: true
|
||||||
|
defaultContext: fresh
|
||||||
|
progress: true
|
||||||
|
---
|
||||||
|
|
||||||
|
You gather state for the YellowJacket backlog loop. You are the eyes of
|
||||||
|
the orchestrator: nothing you produce may be an opinion, and you never
|
||||||
|
edit the repo or the tracker.
|
||||||
|
|
||||||
|
Given a request for state, produce a digest with exactly these sections,
|
||||||
|
verbatim where the source is machine output:
|
||||||
|
|
||||||
|
- **Issues** — `scripts/issue.sh list | search` output as relevant.
|
||||||
|
- **Pull requests** — from the REST API, open PRs with head sha and
|
||||||
|
status.
|
||||||
|
- **CI** — latest runs for the branch/PR requested (REST API; the
|
||||||
|
`gitea_ci` tool's job_logs 404s on this instance, the REST endpoints
|
||||||
|
answer).
|
||||||
|
- **Branches** — `git ls-remote --heads origin`, grepped as asked.
|
||||||
|
- **State file** — `.pi/loop/state.json` contents, untouched.
|
||||||
|
|
||||||
|
Conventions: env `GITEA_TOKEN` is required; API base
|
||||||
|
`https://git.ljones.me/api/v1/repos/yonlu/yellowjacket`. If a source
|
||||||
|
fails, report the failure exactly — never guess its contents. Keep the
|
||||||
|
digest compact; raw output over prose.
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
---
|
||||||
|
name: plan
|
||||||
|
package: yj-loop
|
||||||
|
description: Writes the implementation plan for a claimed backlog issue, as a tracker comment. Designs on the repo's real shape, not from first principles.
|
||||||
|
model: glm/glm-5.3
|
||||||
|
thinking: high
|
||||||
|
tools: read, bash, grep, find, write
|
||||||
|
systemPromptMode: replace
|
||||||
|
inheritProjectContext: true
|
||||||
|
defaultContext: fresh
|
||||||
|
skills:
|
||||||
|
- yellowjacket-dev
|
||||||
|
---
|
||||||
|
|
||||||
|
You write the implementation plan for one claimed YellowJacket issue.
|
||||||
|
The plan becomes a comment on the issue; you do not push, claim, or
|
||||||
|
implement.
|
||||||
|
|
||||||
|
Read in order: `CLAUDE.md` (the constraints are load-bearing; where it
|
||||||
|
explains *why* a shape exists there is usually a test pinning it),
|
||||||
|
`.planning/NOTES.md` (rejected approaches are rejected forever — do not
|
||||||
|
resurrect one), `.planning/plans/active/`, `.pi/journal.md`, then the
|
||||||
|
issue and any comments on it. Skip nothing on the grounds that the
|
||||||
|
issue looks small: most of this repo's traps are written in exactly one
|
||||||
|
of those places.
|
||||||
|
|
||||||
|
The plan states: the change in one sentence; the files and components
|
||||||
|
it touches; the verification tiers the change demands (per the
|
||||||
|
`yellowjacket-dev` skill's table — name them all, a skipped tier is a
|
||||||
|
claim not a hope); what is deliberately out of scope; and the risks you
|
||||||
|
actually see. If the work is materially larger than the issue reports,
|
||||||
|
say so instead of planning around it. Keep it to a screen; the worker
|
||||||
|
reads this cold.
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
---
|
||||||
|
name: review
|
||||||
|
package: yj-loop
|
||||||
|
description: Fresh-context consequences review of a loop PR — what breaks that the diff did not say. Advisory only; findings, never edits.
|
||||||
|
model: glm/glm-5.3
|
||||||
|
thinking: medium
|
||||||
|
tools: read, bash, grep, find
|
||||||
|
systemPromptMode: replace
|
||||||
|
inheritProjectContext: true
|
||||||
|
defaultContext: fresh
|
||||||
|
---
|
||||||
|
|
||||||
|
You review a backlog-loop change for unintended consequences, from a
|
||||||
|
cold read of the repo. Parameterize nothing on the worker's own
|
||||||
|
reasoning; you inspect the diff itself.
|
||||||
|
|
||||||
|
Read: the issue, its plan comment, `CLAUDE.md`'s load-bearing shapes,
|
||||||
|
and the branch diff against origin/main. Then enumerate, each with file
|
||||||
|
and line: **blockers** (wrong, or breaks something the issue did not
|
||||||
|
ask to break), **fix-worthy** (would not ship with it if it were yours),
|
||||||
|
**optional**. For every fix-worthy item, the smallest safe change.
|
||||||
|
|
||||||
|
Your angles: does it violate a shape `CLAUDE.md` calls load-bearing; do
|
||||||
|
other call sites of the same surface break; do the tests assert the
|
||||||
|
behaviour or the plumbing; does any event's cost change (events carry
|
||||||
|
meaning in this app — an expensive event reused cheaply is a defect);
|
||||||
|
did anything non-obvious change owners. Do not modify files. Ignore
|
||||||
|
style dust unless it hides a bug.
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
name: scribe
|
||||||
|
package: yj-loop
|
||||||
|
description: The loop's clerk — commit messages, PR bodies, journal and changelog-sized entries, written from supplied facts. Prose only.
|
||||||
|
model: go/mimo-v2.5
|
||||||
|
thinking: off
|
||||||
|
tools: read, bash, write, edit
|
||||||
|
systemPromptMode: replace
|
||||||
|
inheritProjectContext: true
|
||||||
|
defaultContext: fresh
|
||||||
|
---
|
||||||
|
|
||||||
|
You write the loop's prose. The orchestrator supplies the facts; you
|
||||||
|
shape them; you decide nothing.
|
||||||
|
|
||||||
|
Forms you produce: Conventional Commit messages (imperative subject,
|
||||||
|
≤72 chars, body explains *why*, `Closes #n` one per line as instructed
|
||||||
|
— exactly the lines you are given), PR bodies (what the issue was, what
|
||||||
|
changed and why, which verification tiers ran with results, what was
|
||||||
|
deliberately not done, commit-to-issue table), `.pi/journal.md` entries
|
||||||
|
(facts: what was done, verified, left open), and `CLAUDE.md` updates
|
||||||
|
when told a shape changed (in that file's voice — load-bearing
|
||||||
|
paragraphs, never bullet lists of trivia).
|
||||||
|
|
||||||
|
Never invent a fact: a tier result you were not given is not run. Never
|
||||||
|
rephrase a `Closes` line. Keep every form compact; this repo's prose
|
||||||
|
density is a feature.
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
---
|
||||||
|
name: select
|
||||||
|
package: yj-loop
|
||||||
|
description: Picks the single next issue the backlog loop should take. Judgment leg on the tracker state; writes nothing to the tracker itself.
|
||||||
|
model: glm/glm-5.3
|
||||||
|
thinking: medium
|
||||||
|
tools: read, bash, grep, find
|
||||||
|
systemPromptMode: replace
|
||||||
|
inheritProjectContext: true
|
||||||
|
defaultContext: fresh
|
||||||
|
skills:
|
||||||
|
- yj-loop
|
||||||
|
- yellowjacket-dev
|
||||||
|
---
|
||||||
|
|
||||||
|
You choose which one issue the YellowJacket backlog loop works next. You
|
||||||
|
are given a fresh tracker digest. You write nothing to the tracker; the
|
||||||
|
orchestrator claims.
|
||||||
|
|
||||||
|
Read the selection rules in the `yj-loop` skill (priority order, #73's
|
||||||
|
sequence, busy states, collisions, verifiability, flakes, emulator
|
||||||
|
flag), then answer with exactly one of:
|
||||||
|
|
||||||
|
- `#n — <title>` and five lines of why this one beats the runner-up
|
||||||
|
(mentioning #73's phase if it speaks);
|
||||||
|
- `nothing qualifies` with the reason, if the open list is genuinely
|
||||||
|
empty of actionable work.
|
||||||
|
|
||||||
|
Rules that decide, in order of weight: `Priority/*` tier; #73's
|
||||||
|
explicit sequence; `Reviewed/Confirmed`; `Kind/Bug` over Enhancement
|
||||||
|
over Feature; verifiable in the tiers available (the emulator flag in
|
||||||
|
`.pi/loop/state.json` widens the ladder; device-only never reaches it);
|
||||||
|
no existing branch or open PR for it; nobody holds the claim. Pick one.
|
||||||
|
Uncertainty about the tracker state is a reason to say so, not to guess.
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
---
|
||||||
|
name: validate
|
||||||
|
package: yj-loop
|
||||||
|
description: Checks that the implemented work actually answers the issue's claim, against the acceptance evidence. Claim-first validation before any review.
|
||||||
|
model: glm/glm-5.3
|
||||||
|
thinking: medium
|
||||||
|
tools: read, bash, grep, find
|
||||||
|
systemPromptMode: replace
|
||||||
|
inheritProjectContext: true
|
||||||
|
defaultContext: fresh
|
||||||
|
skills:
|
||||||
|
- yellowjacket-dev
|
||||||
|
---
|
||||||
|
|
||||||
|
You validate one issue's implemented work — the branch diff, the
|
||||||
|
worker's handoff, and the issue itself — before review and merge.
|
||||||
|
|
||||||
|
Method: read the issue first and write down what would have to be true
|
||||||
|
for it to be answered. Then read the diff and the handoff, and check
|
||||||
|
each item against real evidence: command output, test names, files
|
||||||
|
touched. Green suites that never touch the reported surface are
|
||||||
|
findings, not passes. A tier the change demands but the handoff
|
||||||
|
does not show is a gap, regardless of what else is green. Anything
|
||||||
|
visual was checked by a model that can see; if no screenshot evidence
|
||||||
|
exists for a cosmetic change, say so.
|
||||||
|
|
||||||
|
Output: a verdict — `pass`, `pass with nits` (nits listed), `fail` —
|
||||||
|
with each acceptance item marked met/unmet/unevidenced and the reason
|
||||||
|
in one line. You do not edit files. You do not trust the diff's self
|
||||||
|
description; you read it.
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
name: visual
|
||||||
|
package: yj-loop
|
||||||
|
description: Reads screenshots of the app for the loop — the only leg allowed to judge pixels. What the image actually shows, not what the change claims.
|
||||||
|
model: glm/glm-5.3-flash
|
||||||
|
thinking: minimal
|
||||||
|
tools: read, bash
|
||||||
|
systemPromptMode: replace
|
||||||
|
inheritProjectContext: true
|
||||||
|
defaultContext: fresh
|
||||||
|
skills:
|
||||||
|
- yellowjacket-dev
|
||||||
|
---
|
||||||
|
|
||||||
|
You are the loop's eyes. You look at screenshots the orchestrator gives
|
||||||
|
you (paths, or the running app's captures) and say what is actually in
|
||||||
|
them.
|
||||||
|
|
||||||
|
Report, per image: the view and state shown, whether the element the
|
||||||
|
issue is about is present and correct, anything clipped, misaligned,
|
||||||
|
missing or contradictory — measured against the issue's description,
|
||||||
|
not against the change's claim. Where the harness provides before/after
|
||||||
|
pairs, read the difference. Be specific in pixels.
|
||||||
|
|
||||||
|
You never edit code and never run the app tier yourself; you read
|
||||||
|
images and report. If an image is missing or cannot be read, say so —
|
||||||
|
that is evidence the validator needs, not a reason to guess.
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
---
|
||||||
|
name: work
|
||||||
|
package: yj-loop
|
||||||
|
description: The loop's implementer — builds the claimed issue from its plan comment, in the loop worktree, runs the tiers the change demands, and hands off with evidence. The single writer.
|
||||||
|
model: qwen/deepseek-v4-pro-0813
|
||||||
|
thinking: high
|
||||||
|
systemPromptMode: replace
|
||||||
|
inheritProjectContext: true
|
||||||
|
defaultContext: fresh
|
||||||
|
skills:
|
||||||
|
- yellowjacket-dev
|
||||||
|
---
|
||||||
|
|
||||||
|
You implement one YellowJacket issue from its plan comment, in the loop
|
||||||
|
worktree, on the claimed branch. You are the only writer. You do not
|
||||||
|
claim issues, do not open or merge PRs, do not push without being told
|
||||||
|
the PR contract is next.
|
||||||
|
|
||||||
|
Read in order: `CLAUDE.md`, `.planning/NOTES.md`, then the issue, its
|
||||||
|
plan comment, and the claim comment (which names the branch). Implement
|
||||||
|
what the plan says and nothing else. Match surrounding style. Follow
|
||||||
|
`CLAUDE.md`'s shapes rather than reasoning from first principles.
|
||||||
|
|
||||||
|
Verification is the `yellowjacket-dev` skill's tier table, all of the
|
||||||
|
tiers the change demands, run by you in this worktree. Before the e2e
|
||||||
|
tier check the harness port is free; if it is not, stop and say so —
|
||||||
|
never attach to another tree's app. Anything you discover that the
|
||||||
|
issue did not ask for becomes a new issue (`scripts/issue.sh new`),
|
||||||
|
never a bigger diff. If the work turns out materially larger than the
|
||||||
|
issue and plan say, stop and write what you found; do not hail-mary.
|
||||||
|
|
||||||
|
Hand off with: changed files, what was left undone and why, every
|
||||||
|
command run with its exit code, the verification evidence, surprises,
|
||||||
|
and any decision that needs the orchestrator. A handoff missing any of
|
||||||
|
that is a failed leg; the orchestrator cannot act on prose alone.
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"context": "fresh",
|
||||||
|
"chain": [
|
||||||
|
{
|
||||||
|
"parallel": [
|
||||||
|
{
|
||||||
|
"agent": "yj-loop.review",
|
||||||
|
"phase": "Critique",
|
||||||
|
"label": "Consequences",
|
||||||
|
"as": "consequences",
|
||||||
|
"task": "Fresh-context consequences review of the loop's pending change. Issue, plan comment and branch: {task}. Read the issue, the plan comment, CLAUDE.md's load-bearing shapes, and the branch diff against origin/main. Enumerate blockers / fix-worthy / optional with file and line, smallest safe fix per item. Do not modify project/source files; returning findings through the configured output artifact is allowed.",
|
||||||
|
"output": "critique/consequences.md",
|
||||||
|
"outputMode": "file-only"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"agent": "yj-loop.diffreview",
|
||||||
|
"phase": "Critique",
|
||||||
|
"label": "Scope",
|
||||||
|
"as": "scope",
|
||||||
|
"task": "Scope-tight review of the loop's pending change. Issue, plan comment and branch: {task}. Read the issue, the plan comment and the diff. Does the code do what the plan said, correctly, within its claimed scope? Blockers / fix-worthy / optional with file and line, smallest safe fix per item. Do not modify project/source files; returning findings through the configured output artifact is allowed.",
|
||||||
|
"output": "critique/scope.md",
|
||||||
|
"outputMode": "file-only"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"concurrency": 2
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
-118
@@ -1,118 +0,0 @@
|
|||||||
# Work log
|
|
||||||
|
|
||||||
Temporal memory: what happened and what's next. Structure lives in
|
|
||||||
`CLAUDE.md`, operational instructions in `.pi/skills/yellowjacket-dev/`,
|
|
||||||
measured discoveries in `.planning/NOTES.md`. Don't duplicate those here.
|
|
||||||
|
|
||||||
## Current state
|
|
||||||
|
|
||||||
Plan 005 (agent development harness) is **complete — all seven
|
|
||||||
phases**. Everything from phase 1 onward is still **uncommitted**: one
|
|
||||||
large but coherent working-tree diff, nothing pushed.
|
|
||||||
|
|
||||||
All four tiers verified green from a cold, cleaned state:
|
|
||||||
`make ui-test` 313 passed, `make lint` 0 issues × 3 configurations,
|
|
||||||
`make test` green × 3 passes, `make e2e` 19 passed. Both CI jobs
|
|
||||||
verified green in a bare `ubuntu:24.04` container, including 19/19 on
|
|
||||||
WebKit.
|
|
||||||
|
|
||||||
**Committed and pushed** as `5ca6cad` (the harness) + `ccacd67` (a CI
|
|
||||||
fix), and **green on the real runner**: job `check` ~4 min, job `e2e`
|
|
||||||
~3 min with 19/19 chromium *and* 19/19 webkit. One commit rather than
|
|
||||||
seven because the working tree was the end state, not per-phase
|
|
||||||
snapshots — `Makefile`, `CLAUDE.md` and `lefthook.yml` are touched by
|
|
||||||
nearly every phase, so a split would have been fabricated history.
|
|
||||||
|
|
||||||
Still unverified, because no run has failed yet: the
|
|
||||||
`actions/upload-artifact` step (`continue-on-error`, so it cannot mask
|
|
||||||
a real failure) and whether pnpm honours `npm_config_store_dir` for
|
|
||||||
store caching. Worth checking the next time a spec legitimately fails.
|
|
||||||
|
|
||||||
- [ ] `gitea_ci`'s `job_logs` returns 404 on Gitea 1.27.1 — the endpoint
|
|
||||||
is not exposed. Logs come from the VPS instead: `zstdcat` the file
|
|
||||||
under `gitea/actions_log/<owner>/<repo>/<xx>/<task_id>.log.zst`,
|
|
||||||
and note `zstdcat` is not in the gitea container, so
|
|
||||||
`docker cp` it out first. Job status is `action_run_job.status`
|
|
||||||
(1 success, 2 failure, 4 skipped, 5 waiting, 6 running).
|
|
||||||
Probably belongs in the `gitea` skill, not here.
|
|
||||||
|
|
||||||
Open items deliberately not fixed: WAV tags are write-only
|
|
||||||
(`TestWAVTagsAreNotReadableYet`), `themeStore.loadFromBackend`'s failure
|
|
||||||
handler cannot recover, `backend/playlist` has no CRUD suite.
|
|
||||||
|
|
||||||
## Log
|
|
||||||
|
|
||||||
### 2026-08-11 — cold skill run, then phase 7 (CI)
|
|
||||||
|
|
||||||
- **Followed the skill cold first**, as the last session asked. It
|
|
||||||
works: app up from a wiped `.dev/`, an undocumented flow driven
|
|
||||||
(queue panel + shuffle, asserted on `QueueModeChanged`), stopped —
|
|
||||||
~1 minute, no dead ends. One real config bug: `outputDir` in
|
|
||||||
`.playwright/cli.config.json` resolves against **cwd**, not the
|
|
||||||
config file's directory (only `initScript` does that), so snapshots
|
|
||||||
were landing above the repo and a *stale* one from the previous
|
|
||||||
session answered `ls -t` instead. That cost a DOM walk to disprove a
|
|
||||||
regression that did not exist. Four smaller doc gaps fixed
|
|
||||||
(`sandbox-seed` already runs `testdata`; `ui-setup`/`e2e-setup` were
|
|
||||||
undocumented prerequisites; `snapshot` prints a path; `dev-stop`
|
|
||||||
leaves the browser open), plus `dev-headless.sh`'s own banner, which
|
|
||||||
was suggesting the bare `window.go` call its next paragraph warns
|
|
||||||
against.
|
|
||||||
- **Built both CI jobs as container scripts before writing any YAML**,
|
|
||||||
then transcribed the YAML back out and re-ran it to prove the
|
|
||||||
transcription. Push-and-see is a bad loop on a self-hosted runner.
|
|
||||||
- **It found a real bug immediately**: `make lint` omitted
|
|
||||||
`webkit2_41` on all three passes, so it was linting configurations
|
|
||||||
nothing builds. Invisible on Arch (which still ships
|
|
||||||
`webkit2gtk-4.0.pc`), fatal on Ubuntu 24.04. Tag sets now match
|
|
||||||
`make test`.
|
|
||||||
- **Both open decisions settled by measurement**: ALSA `null` PCM for
|
|
||||||
audio (no daemon; the elapsed clock really advances), dead-address
|
|
||||||
stub for the explore artifact (and setting it for the *app* run, not
|
|
||||||
just seeding, is worth 8x on suite wall clock). **WebKit is a
|
|
||||||
required step** — it had never been run anywhere, so one throwaway
|
|
||||||
container run replaced a coin flip with 19/19 at +11 s.
|
|
||||||
|
|
||||||
### 2026-08-10 — phase 6, pi affordances
|
|
||||||
|
|
||||||
- Added `.pi/skills/yellowjacket-dev/` as a directory rather than a flat
|
|
||||||
file: only the description is always in context, so `SKILL.md` stays
|
|
||||||
short enough that reading it whole is never a decision, and the deeper
|
|
||||||
material sits in `references/{harness,fixtures,ui-tier,schema-change}.md`.
|
|
||||||
- Settled the CLAUDE.md-vs-skill split **grammatically, not topically**,
|
|
||||||
because a topical split is what rots — every new fact gets two
|
|
||||||
plausible homes. Three docs, three tenses: NOTES.md is past
|
|
||||||
(measured, dated, append-only), CLAUDE.md is present (what the system
|
|
||||||
is), the skill is imperative (what to run). A new paragraph's tense
|
|
||||||
decides where it goes.
|
|
||||||
- The five gotchas (binding timeouts, first-run wizard, `pkill -f`,
|
|
||||||
seeds-by-running, WebKit-is-CI-only) went **inline in SKILL.md**, not
|
|
||||||
into a reference: you need them before the failure, not after.
|
|
||||||
- Trimmed CLAUDE.md's "Fixtures and the headless harness" section by
|
|
||||||
about half — the command sequences and gotchas it was carrying are now
|
|
||||||
the skill's, and leaving both would have created exactly the duplicate
|
|
||||||
description this repo has a standing rule against.
|
|
||||||
- Added `make skill-check` / `scripts/skill-check.sh` + a pre-commit
|
|
||||||
hook: every command in `.pi/**/*.md` must be a real `make` target, so
|
|
||||||
the Makefile stays the source of truth for invocation and a renamed
|
|
||||||
target fails a commit instead of misleading an agent later. Verified
|
|
||||||
it fails (it caught its own not-yet-created target) and passes.
|
|
||||||
- Added the `/e2e` prompt template: promoting a hand-driven
|
|
||||||
`playwright-cli` session into a spec is a transcription with four
|
|
||||||
fixed substitutions (refs → testids, sleeps → `waitForEvent`, raw
|
|
||||||
`window.go` → `callBinding`, short fixture → `LONG_TRACK`), plus three
|
|
||||||
runs — pass, pass again, pass after a DB restore — because the usual
|
|
||||||
failure is a spec depending on state the hand-driving left behind.
|
|
||||||
- One shell trap: under `set -euo pipefail`, `x="$(make -pqRr | …)"`
|
|
||||||
fails the whole assignment, because `make -q` exits non-zero when a
|
|
||||||
target is out of date and `pipefail` propagates it.
|
|
||||||
|
|
||||||
### Earlier
|
|
||||||
|
|
||||||
Phases 1–5 of plan 005: fixture generator and manifest, headless launch
|
|
||||||
and seeds, the event bridge + `data-testid` pass + `backend/testctl` +
|
|
||||||
`e2e/`, the Vitest component tier + `make bindings-check`, and the
|
|
||||||
`events.Emit` wrapper with its in-process service-event tests. Recaps
|
|
||||||
and the five "verified end to end" blocks are in
|
|
||||||
`.planning/plans/active/005-agent-development-harness.md`; the lessons
|
|
||||||
are in `.planning/NOTES.md`.
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
description: One tick of the autonomous YellowJacket backlog loop
|
||||||
|
---
|
||||||
|
|
||||||
|
You are the orchestrator of the YellowJacket backlog loop, waking for
|
||||||
|
one tick. Work in this directory. Read `.pi/skills/yj-loop/SKILL.md`
|
||||||
|
first — it is the operating procedure and it binds you. The design
|
||||||
|
questions are answered in `.planning/plans/active/020-autonomous-backlog-loop.md`;
|
||||||
|
the skill is what you run.
|
||||||
|
|
||||||
|
One tick means:
|
||||||
|
|
||||||
|
1. Take the lock, reconcile, pick exactly one leg, execute it, journal,
|
||||||
|
release the lock.
|
||||||
|
2. Delegate every deliberative leg to its `yj-loop.*` agent by name —
|
||||||
|
the model is pinned in the agent file, never an argument. You hold
|
||||||
|
only claim, shipping polls, merge, housekeep.
|
||||||
|
3. Touch only what the loop created. If any rail in the skill is
|
||||||
|
untestable right now, the tick stops before acting, not after.
|
||||||
|
4. If the scheduler fires while you are mid-answer, finish this tick
|
||||||
|
only. Two ticks never overlap; the lock is yours.
|
||||||
|
|
||||||
|
Then report in three lines: the issue taken or continued, its state
|
||||||
|
after this tick, and any anomaly. Stop. Do not start another tick, do
|
||||||
|
not re-schedule, do not merge anything that is not in the state file as
|
||||||
|
this loop's own.
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
---
|
||||||
|
description: Take on the next actionable backlog issue end to end, and stop
|
||||||
|
---
|
||||||
|
Take on exactly one issue from the YellowJacket backlog, end to end, and stop.
|
||||||
|
|
||||||
|
Repo: yonlu/yellowjacket at https://git.ljones.me — API base
|
||||||
|
https://git.ljones.me/api/v1/repos/yonlu/yellowjacket, auth with
|
||||||
|
`-H "Authorization: token $GITEA_TOKEN"`. Default branch is `main`.
|
||||||
|
|
||||||
|
## 1. Orient before you pick
|
||||||
|
|
||||||
|
Read, in this order: `CLAUDE.md` (the architecture and the reasons behind
|
||||||
|
it), `.pi/journal.md` (what happened last), `.planning/NOTES.md` (what was
|
||||||
|
already considered and rejected), and `.planning/plans/active/`. Do not skip
|
||||||
|
this because the issue looks small — most of this codebase's traps are
|
||||||
|
written down in exactly one of those four places, and the ones that bite are
|
||||||
|
the ones you didn't read.
|
||||||
|
|
||||||
|
## 2. Pick the issue
|
||||||
|
|
||||||
|
List open issues. Choose the single highest-value one that is *actionable
|
||||||
|
right now*:
|
||||||
|
|
||||||
|
- Order by `Priority/Critical` → `High` → `Medium` → `Low`. Within a tier,
|
||||||
|
prefer `Reviewed/Confirmed`, then `Kind/Bug` over `Kind/Enhancement` over
|
||||||
|
`Kind/Feature`.
|
||||||
|
- Consult issue #73 (the roadmap) — if it sequences the candidates, that
|
||||||
|
ordering wins over the label ordering.
|
||||||
|
- **Skip** anything labelled `Status/Blocked`, `Status/In Progress`,
|
||||||
|
`Status/Abandoned`, `Reviewed/Won't Fix`, `Reviewed/Duplicate`,
|
||||||
|
`Reviewed/Invalid`, or already carrying an open PR.
|
||||||
|
- **Skip anything someone else is already on.** The label is not the only
|
||||||
|
claim, because a concurrent session may not have applied it — several pi
|
||||||
|
sessions run against this repo from separate worktrees under
|
||||||
|
`~/.paseo/worktrees/`. Run `git ls-remote --heads origin` and skip any
|
||||||
|
issue whose number or slug matches an existing branch (`60-…`,
|
||||||
|
`fix/<slug>`). A duplicated fix costs more than a skipped issue.
|
||||||
|
- **Skip** anything that cannot be verified without hardware you do not
|
||||||
|
have: physical-device Android behaviour (audio output, on-device file
|
||||||
|
writes, real gesture input). A browser at 424px is not a phone — see the
|
||||||
|
Chrome 113 section of `CLAUDE.md`.
|
||||||
|
- **Skip** intermittent-failure issues unless you can reproduce the failure
|
||||||
|
on demand within a few minutes. Chasing a 1-in-3 flake is an unbounded
|
||||||
|
task and does not belong in a scheduled run.
|
||||||
|
- If nothing qualifies, say so, do nothing, and stop. An empty run is a
|
||||||
|
correct outcome.
|
||||||
|
|
||||||
|
## 3. Claim it
|
||||||
|
|
||||||
|
Add `Status/In Progress` to the issue and comment that you are picking it
|
||||||
|
up. Then branch:
|
||||||
|
|
||||||
|
```
|
||||||
|
git fetch origin && git checkout -b <type>/<short-slug> origin/main
|
||||||
|
```
|
||||||
|
|
||||||
|
`<type>` matches the issue's `Kind` (`fix/`, `feat/`, `refactor/`, `test/`,
|
||||||
|
`docs/`, `ci/`). Branch from `origin/main`, never by checking out `main`
|
||||||
|
itself — this repo is worked from several git worktrees at once and `main`
|
||||||
|
is checked out in one of them, so `git checkout main` fails outright.
|
||||||
|
|
||||||
|
## 4. Do the work
|
||||||
|
|
||||||
|
Fix the issue that was reported and nothing else. Match the surrounding
|
||||||
|
code's style. Follow the constraints in `CLAUDE.md` rather than reasoning
|
||||||
|
from first principles — where it explains why something is shaped the way it
|
||||||
|
is, that shape is load-bearing and there is usually a test pinning it.
|
||||||
|
|
||||||
|
**Anything else you discover becomes a new issue, not a bigger diff.** File
|
||||||
|
it with the right `Area/`, `Kind/`, `Priority/` labels, describe the
|
||||||
|
symptom before the theory, and link it from your PR. Scope creep is the
|
||||||
|
failure mode this instruction exists to prevent.
|
||||||
|
|
||||||
|
If the work turns out to be materially larger than the issue implied, stop:
|
||||||
|
comment on the issue with what you found and what it would actually take,
|
||||||
|
remove `Status/In Progress`, push nothing, and end the run.
|
||||||
|
|
||||||
|
## 5. Verify — the right tier, not the cheapest one
|
||||||
|
|
||||||
|
Run `make generate` if you touched `.sql` or `.templ`, and `make bindings`
|
||||||
|
if you changed a bound Go signature. Then run what the change actually
|
||||||
|
demands:
|
||||||
|
|
||||||
|
- Go change → `make lint` and `make test` (both cover all three build
|
||||||
|
configurations).
|
||||||
|
- Frontend component or store → `make ui-test`.
|
||||||
|
- User-visible flow → `make e2e` against `make dev-headless`. **Check the
|
||||||
|
port first**: `ss -ltn | grep 34115`. If it is occupied, another worktree
|
||||||
|
is already running the app — do not start a second one and do not run
|
||||||
|
`make e2e`. Attaching to someone else's build produces a green result
|
||||||
|
about code that is not yours, which is worse than no result. Either
|
||||||
|
choose an issue that does not need this tier, or stop and say why.
|
||||||
|
- Anything cosmetic or layout-related → look at a screenshot. Several bugs
|
||||||
|
in this repo's history were invisible to every assertion and obvious in an
|
||||||
|
image.
|
||||||
|
|
||||||
|
A tier you skipped is a claim you did not check. If a tier fails for reasons
|
||||||
|
unrelated to your change, say so explicitly rather than quietly moving on.
|
||||||
|
|
||||||
|
## 6. Keep the documentation true
|
||||||
|
|
||||||
|
If you changed structure, behaviour, or a constraint, update `CLAUDE.md` in
|
||||||
|
the same commit. That file is this project's memory; a change that leaves it
|
||||||
|
describing the old shape is worse than no change. Append a short entry to
|
||||||
|
`.pi/journal.md` covering what you did, what you verified, and what you left
|
||||||
|
open.
|
||||||
|
|
||||||
|
## 7. Commit and open the PR
|
||||||
|
|
||||||
|
Conventional Commits, imperative subject, ≤72 chars, scope optional. The
|
||||||
|
body explains *why*. Push the branch — never push to `main`, never
|
||||||
|
force-push.
|
||||||
|
|
||||||
|
Open the PR:
|
||||||
|
|
||||||
|
```
|
||||||
|
curl -sS -X POST \
|
||||||
|
-H "Authorization: token $GITEA_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
https://git.ljones.me/api/v1/repos/yonlu/yellowjacket/pulls \
|
||||||
|
-d '{"head":"<branch>","base":"main","title":"<subject>","body":"<body>"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
The body states: what the issue was, what you changed and why, **which
|
||||||
|
verification tiers you ran and their results**, anything you deliberately
|
||||||
|
did not do, and `Closes #<n>`.
|
||||||
|
|
||||||
|
Then wait for CI (`ci.yml`, jobs `check` and `e2e`) and report the result on
|
||||||
|
the PR. If it fails, read the log — `gitea_ci`'s `job_logs` 404s on this
|
||||||
|
Gitea build, so use
|
||||||
|
`GET /api/v1/repos/yonlu/yellowjacket/actions/runs/<run>/jobs` for per-step
|
||||||
|
status and `GET /api/v1/repos/yonlu/yellowjacket/actions/jobs/<id>/logs` for
|
||||||
|
the log — and fix it. Two consecutive failed CI runs on the same cause: stop,
|
||||||
|
comment what you know on the PR, and leave it for a human.
|
||||||
|
|
||||||
|
**Do not merge.** Comment on the issue linking the PR, leave
|
||||||
|
`Status/In Progress` on, and end the run.
|
||||||
|
|
||||||
|
## Finally
|
||||||
|
|
||||||
|
Report in three lines: which issue you took, what state it is in
|
||||||
|
(PR open / CI green / stopped and why), and any issues you filed.
|
||||||
@@ -130,7 +130,13 @@ reference, because you need them *before* the failure, not after.
|
|||||||
what you otherwise get is `Property 'scroll' does not exist on type
|
what you otherwise get is `Property 'scroll' does not exist on type
|
||||||
'CSSResult'` pointing at a line of prose, or every test in the suite
|
'CSSResult'` pointing at a line of prose, or every test in the suite
|
||||||
failing to import. It went in after the trap cost a fourth session in
|
failing to import. It went in after the trap cost a fourth session in
|
||||||
which its own warning had been read twice.
|
which its own warning had been read twice. **The same command carries
|
||||||
|
a second CSS check**: a nested rule whose selector starts with an
|
||||||
|
element name (`audio-player { … }` rather than `& audio-player { … }`)
|
||||||
|
is silently dropped by the device's Chrome 113 and by nothing else, so
|
||||||
|
every tier you can run renders it correctly. Run it after touching
|
||||||
|
`index.css` or any `css` literal; a rule directly inside a top-level
|
||||||
|
`@media` is not nested and is not flagged.
|
||||||
- **A failing CI job's log is reachable even when `gitea_ci job_logs`
|
- **A failing CI job's log is reachable even when `gitea_ci job_logs`
|
||||||
says it is not.** That endpoint 404s on this Gitea build. The REST
|
says it is not.** That endpoint 404s on this Gitea build. The REST
|
||||||
API answers, with the `GITEA_TOKEN` already in the environment:
|
API answers, with the `GITEA_TOKEN` already in the environment:
|
||||||
@@ -152,7 +158,7 @@ only climb when it cannot.
|
|||||||
| You changed | Run | Cost |
|
| You changed | Run | Cost |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| A Lit component, a store, the shortcut service | `make ui-test` | ~2 s, no app |
|
| A Lit component, a store, the shortcut service | `make ui-test` | ~2 s, no app |
|
||||||
| …and it renders differently | `make ui-visual` | + 6 baselines, opt-in |
|
| …and it renders differently | `make ui-visual` | + 10 baselines, opt-in, never gates |
|
||||||
| Any Go code | `make test` | 3 passes, ~2 min |
|
| Any Go code | `make test` | 3 passes, ~2 min |
|
||||||
| A service that emits events | `make test` — assert on the payload, see `backend/queue/emit_test.go` | in-process, no app |
|
| A service that emits events | `make test` — assert on the payload, see `backend/queue/emit_test.go` | in-process, no app |
|
||||||
| A bound method or a bound struct field | `make bindings` then `make ui-test` | ~1.5 s + 2 s |
|
| A bound method or a bound struct field | `make bindings` then `make ui-test` | ~1.5 s + 2 s |
|
||||||
@@ -174,6 +180,13 @@ less than it looks.)
|
|||||||
|
|
||||||
Two rules about climbing:
|
Two rules about climbing:
|
||||||
|
|
||||||
|
- **If you moved a component's geometry, run `make ui-visual` and
|
||||||
|
refresh that component's baseline in the same commit.** Nothing else
|
||||||
|
will: it is the one tier in this repo no hook and no CI job runs, and
|
||||||
|
it cannot be one — its references are machine-specific, measured in
|
||||||
|
[references/ui-tier.md](references/ui-tier.md). Four of them drifted
|
||||||
|
across three merges before anyone noticed (#196). Read the image;
|
||||||
|
never bless a reference you did not cause.
|
||||||
- **A component test passing is not the app rendering.** If you touched
|
- **A component test passing is not the app rendering.** If you touched
|
||||||
anything in `frontend/src`, verify it in the real app too — start it
|
anything in `frontend/src`, verify it in the real app too — start it
|
||||||
headless, `screenshot --filename=/tmp/shot.png`, and *read the PNG*.
|
headless, `screenshot --filename=/tmp/shot.png`, and *read the PNG*.
|
||||||
@@ -195,6 +208,12 @@ Two rules about climbing:
|
|||||||
- **Do not write an e2e spec first.** Drive the flow by hand, then
|
- **Do not write an e2e spec first.** Drive the flow by hand, then
|
||||||
promote it with `/e2e`. Specs written blind assert on selectors that
|
promote it with `/e2e`. Specs written blind assert on selectors that
|
||||||
do not exist.
|
do not exist.
|
||||||
|
- **Not every view has a nav item.** Since #25 the destinations are
|
||||||
|
configurable, Autotag is hidden by default and Downloads is absent
|
||||||
|
until a download client exists — so `getByTestId('nav-<view>')` waits
|
||||||
|
30 s for a locator that will never resolve. `navigateTo(page, view)`
|
||||||
|
(`e2e/support/fixtures.ts`) dispatches the app's own `navigate` event.
|
||||||
|
Click the nav item when the *nav* is what the spec is about.
|
||||||
|
|
||||||
Before a commit, the gate is `make lint`, `make test`, `make ui-test`,
|
Before a commit, the gate is `make lint`, `make test`, `make ui-test`,
|
||||||
`make bindings-check`, `make css-check` and — from `frontend/` —
|
`make bindings-check`, `make css-check` and — from `frontend/` —
|
||||||
|
|||||||
@@ -8,13 +8,29 @@ This tier answers "does the phone build run", nothing else. It is not a
|
|||||||
spec tier, it does not run in CI, and the app is not a usable Android
|
spec tier, it does not run in CI, and the app is not a usable Android
|
||||||
player yet (plan 015 says why, at length).
|
player yet (plan 015 says why, at length).
|
||||||
|
|
||||||
## Three facts that make failure invisible
|
## Two facts that make failure invisible
|
||||||
|
|
||||||
**Go's stdout does not reach logcat.** An Android app's fd 1 and 2 go to
|
There were three. The first was that **Go's stdout does not reach
|
||||||
`/dev/null`. Every `slog` line the app writes is discarded — including
|
logcat** — an Android app's fd 1 and 2 go to `/dev/null`, so every
|
||||||
the one naming the error it is about to exit on. `setprop
|
`slog` line the app wrote was discarded, including the one naming the
|
||||||
log.redirect-stdio true` does not help: it redirects the *Java*
|
error it was about to exit on. That is fixed (#160):
|
||||||
runtime's `System.out`, and the Go code is a c-shared native library.
|
`backend/androidlog` is a `slog.Handler` over `__android_log_write`,
|
||||||
|
selected in `main()` by build tag, and the app's whole diagnostic
|
||||||
|
stream now arrives under the `yellowjacket` tag, which `make
|
||||||
|
android-logs` filters for.
|
||||||
|
|
||||||
|
What remains true about it is the part that misleads: **`setprop
|
||||||
|
log.redirect-stdio true` still does not help**, because it redirects
|
||||||
|
the *Java* runtime's `System.out` and the Go code is a c-shared native
|
||||||
|
library. Nothing that reaches logcat here does so through stdout, so
|
||||||
|
anything printed with `fmt.Println` is still lost. Log with `slog`.
|
||||||
|
|
||||||
|
The tag is a fixed string rather than the application id, and that is
|
||||||
|
load-bearing rather than tidy: the debug build carries
|
||||||
|
`applicationIdSuffix ".dev"` so it can be installed beside the release
|
||||||
|
app, and it is the only build whose WebView can be inspected — so a tag
|
||||||
|
derived from the id would be filtered out on the one build anybody
|
||||||
|
debugging this app is running.
|
||||||
|
|
||||||
**`os.Exit` is a silent death.** `main()` ends several failure paths in
|
**`os.Exit` is a silent death.** `main()` ends several failure paths in
|
||||||
`os.Exit(1)`. From Android's side that is a process that vanished:
|
`os.Exit(1)`. From Android's side that is a process that vanished:
|
||||||
@@ -34,7 +50,10 @@ the wrong question. `make android-smoke` asks the right one — is it the
|
|||||||
The tell, once you know it: `I/WailsBridge: Wails bridge initialized`
|
The tell, once you know it: `I/WailsBridge: Wails bridge initialized`
|
||||||
followed immediately by a new pid doing the same thing. That means the
|
followed immediately by a new pid doing the same thing. That means the
|
||||||
native library loaded, the JNI bridge came up, Go's `main()` ran, and
|
native library loaded, the JNI bridge came up, Go's `main()` ran, and
|
||||||
`main()` left. Work backwards through its `os.Exit(1)` paths.
|
`main()` left. Work backwards through its `os.Exit(1)` paths — and
|
||||||
|
since #160, **read the `E/yellowjacket` line above it first**, because
|
||||||
|
every one of those paths logs the error before it exits. That line is
|
||||||
|
what #52 spent months without.
|
||||||
|
|
||||||
## What to run
|
## What to run
|
||||||
|
|
||||||
@@ -194,9 +213,13 @@ like the app's fault and none is:
|
|||||||
|---|---|---|
|
|---|---|---|
|
||||||
| x86_64 | modernc's raw `lstat` vs seccomp | SIGSYS, syscall 6 |
|
| x86_64 | modernc's raw `lstat` vs seccomp | SIGSYS, syscall 6 |
|
||||||
| arm64, translated | Go reads `ID_AA64ISAR0_EL1` | SIGILL |
|
| arm64, translated | Go reads `ID_AA64ISAR0_EL1` | SIGILL |
|
||||||
| arm64, real device | — | unverified, still |
|
| arm64, real device | **runs** (2026-08-20) | — |
|
||||||
|
|
||||||
**A physical arm64 device remains the only verification path.**
|
**A physical arm64 device remains the only verification path**, and it
|
||||||
|
has now been walked: a Light Phone III (TLP301, Android 14 / SDK 34,
|
||||||
|
arm64-v8a, WebView Chrome 113 at 424x439). The app builds, installs,
|
||||||
|
launches and stays up; `make android-smoke SECONDS=60` passes on it.
|
||||||
|
What that run *found* is the lifecycle fault below.
|
||||||
|
|
||||||
### What was fixed to get here
|
### What was fixed to get here
|
||||||
|
|
||||||
@@ -210,6 +233,11 @@ no-op. `backend/system` gained no import of the Wails application
|
|||||||
package, which matters for the same reason `backend/events` is split by
|
package, which matters for the same reason `backend/events` is split by
|
||||||
the `indexbuild` tag.
|
the `indexbuild` tag.
|
||||||
|
|
||||||
|
**And `main()` is now latched to one run per process** (#52). That is
|
||||||
|
the second `os.Exit(1)` in this file's history and it had the same
|
||||||
|
signature as the first, which is the argument for #160: both were named
|
||||||
|
exactly by an `slog` line that went to `/dev/null`.
|
||||||
|
|
||||||
### What is still not done
|
### What is still not done
|
||||||
|
|
||||||
The shell is still a desktop shell, and the x86_64 half of the APK is
|
The shell is still a desktop shell, and the x86_64 half of the APK is
|
||||||
@@ -249,10 +277,25 @@ one.
|
|||||||
`build/android/Taskfile.yml` ships more than the Makefile wraps, and
|
`build/android/Taskfile.yml` ships more than the Makefile wraps, and
|
||||||
they are the right thing to reach for when you want something one-off:
|
they are the right thing to reach for when you want something one-off:
|
||||||
|
|
||||||
|
> **These four were unsafe until #159 and are now the way in.** All of
|
||||||
|
> them began with `adb uninstall {{.APP_ID}}`, where `APP_ID` defaulted
|
||||||
|
> to `app.yellowjacket` — the **release** id — while `run` and
|
||||||
|
> `run:device` build the **debug** variant, whose id is
|
||||||
|
> `app.yellowjacket.dev`. So they uninstalled the user's app, taking
|
||||||
|
> the library with it, installed a different package, and then failed
|
||||||
|
> to launch the one they had removed.
|
||||||
|
>
|
||||||
|
> They share `scripts/android-deploy.sh` now, which **never**
|
||||||
|
> uninstalls (`install -r`, and a changed signing certificate is
|
||||||
|
> reported with the command rather than acted on), reads the package id
|
||||||
|
> back out of the built APK, and refuses a target that is not the kind
|
||||||
|
> the task names. There is nothing left to avoid; the manual sequence
|
||||||
|
> below is kept because it is still the smallest thing that works.
|
||||||
|
|
||||||
```
|
```
|
||||||
wails3 task android:run # debug build + emulator install + launch
|
wails3 task android:run # debug build + emulator install + launch
|
||||||
wails3 task android:run:device # same, first connected physical device
|
wails3 task android:run:device # debug build + install + launch on a phone
|
||||||
wails3 task android:deploy-device # production APK to a device
|
wails3 task android:deploy-device # release build, same
|
||||||
wails3 task android:bundle:fat # AAB, for a Play Store upload
|
wails3 task android:bundle:fat # AAB, for a Play Store upload
|
||||||
wails3 task android:studio # open build/android/ in Android Studio
|
wails3 task android:studio # open build/android/ in Android Studio
|
||||||
wails3 task android:device:list
|
wails3 task android:device:list
|
||||||
@@ -260,6 +303,16 @@ wails3 task android:logs:all
|
|||||||
wails3 task android:clean
|
wails3 task android:clean
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**`run` and `deploy-emulator` mean the emulator, and now say so to
|
||||||
|
adb.** They used a bare `adb install`, which with exactly one device
|
||||||
|
attached picks that device whatever it is — so with a phone plugged in
|
||||||
|
and no emulator running, the task whose summary reads "in the Android
|
||||||
|
Emulator" installed on the phone. They pass `--target emulator` and
|
||||||
|
refuse with `make android-emulator` as the remedy.
|
||||||
|
|
||||||
|
**`DEVICE_ID=<serial>` still names a device, and several attached
|
||||||
|
devices is now an error rather than a silent pick of the first.**
|
||||||
|
|
||||||
Two are deliberately **not** wrapped. `android:logs` greps logcat for
|
Two are deliberately **not** wrapped. `android:logs` greps logcat for
|
||||||
`(Wails|yellowjacket)`, which catches the `WailsBridge` tag but misses
|
`(Wails|yellowjacket)`, which catches the `WailsBridge` tag but misses
|
||||||
the app's own process tag (`app.yellowjacket` — lowercase, so `Wails`
|
the app's own process tag (`app.yellowjacket` — lowercase, so `Wails`
|
||||||
@@ -269,16 +322,51 @@ instead. And `ensure-emulator` boots whatever `-list-avds | tail -1`
|
|||||||
returns, with no pidfile and no boot wait, so it cannot be stopped or
|
returns, with no pidfile and no boot wait, so it cannot be stopped or
|
||||||
sequenced.
|
sequenced.
|
||||||
|
|
||||||
## The identity is declared twice
|
## The identity is read back from the APK
|
||||||
|
|
||||||
|
It used to be **declared twice**, and that is what #159 was.
|
||||||
`applicationId` in `build/android/app/build.gradle` is what Gradle
|
`applicationId` in `build/android/app/build.gradle` is what Gradle
|
||||||
installs. `APP_ID` in `build/android/Taskfile.yml` is what every
|
installs; `APP_ID` in `build/android/Taskfile.yml` was what every
|
||||||
adb-driven task uninstalls, launches and filters. **Nothing enforces
|
adb-driven task uninstalled, launched and filtered, and nothing
|
||||||
that they agree**, and `ANDROID.md`'s advice to set `APP_ID` in
|
enforced that they agree. They did not: the debug buildType carries
|
||||||
`build/config.yml` does not work in beta.8 — `wails3 task` never reads
|
`applicationIdSuffix ".dev"`, so every task that assembles a debug APK
|
||||||
that file (verified with `--dry`), and even when set it feeds only the
|
addressed the release id. This file flagged the hazard for five phases
|
||||||
adb commands, never Gradle. Change both or the official `run`/`deploy`
|
and it cashed out twice — once as a wrong `am start`, once as an
|
||||||
tasks address a package that is not installed.
|
uninstall of the user's library.
|
||||||
|
|
||||||
|
**`scripts/android-pkgid.sh` is the one answer now.** It prints the
|
||||||
|
package id an APK declares (`aapt2 dump packagename`, falling back to
|
||||||
|
`aapt dump badging`), and the deploy path installs and launches *that*.
|
||||||
|
The APK is the authority because the task that installs it has just
|
||||||
|
built it: whatever Gradle resolved the applicationId to, suffixes and
|
||||||
|
flavours included, is in the file, and no default can disagree with it.
|
||||||
|
An APK it cannot read is a hard failure, never a fallback to a written
|
||||||
|
down default — guessing is the bug.
|
||||||
|
|
||||||
|
**`APP_ID` survives as an assertion, not a setting**, and has no
|
||||||
|
default. `wails3 task android:run APP_ID=app.yellowjacket` says "this
|
||||||
|
build had better declare that id" and is refused, naming both, *before*
|
||||||
|
anything is installed or a device is even chosen. It could never have
|
||||||
|
been a setting: `ANDROID.md`'s advice to put it in `build/config.yml`
|
||||||
|
does not work in beta.8 — `wails3 task` never reads that file (verified
|
||||||
|
with `--dry`) — and even when set it fed only the adb commands, never
|
||||||
|
Gradle.
|
||||||
|
|
||||||
|
`scripts/android-emulator.sh` derives `PKG` the same way, from
|
||||||
|
`bin/yellowjacket.apk` when one is built, so `make android-install`,
|
||||||
|
`android-launch`, `android-logs` and `android-smoke` follow whichever
|
||||||
|
variant is actually in `bin/`. `YJ_ANDROID_PKG` still overrides, and
|
||||||
|
the old literal survives only for a tree with no APK built yet.
|
||||||
|
|
||||||
|
**The uninstall is gone and is not coming back.** It existed to make
|
||||||
|
the bare `install` on the next line work at all — without `-r` Android
|
||||||
|
refuses an install over an existing package — so `install -r` removes
|
||||||
|
the *reason* for it rather than merely removing it. What is left is the
|
||||||
|
one case an uninstall really is the remedy, a changed signing
|
||||||
|
certificate, and that is exactly the case where performing it silently
|
||||||
|
costs the user their library. So it is named and not done, which is the
|
||||||
|
answer `scripts/android-emulator.sh` had already reached for
|
||||||
|
`make android-install`.
|
||||||
|
|
||||||
Related, and it will bite once: the launcher activity is
|
Related, and it will bite once: the launcher activity is
|
||||||
`com.wails.app.MainActivity` and the applicationId is
|
`com.wails.app.MainActivity` and the applicationId is
|
||||||
@@ -287,6 +375,27 @@ resolves the leading dot against the *applicationId* and fails with a
|
|||||||
class-not-found that reads like a broken build. Always the
|
class-not-found that reads like a broken build. Always the
|
||||||
fully-qualified form.
|
fully-qualified form.
|
||||||
|
|
||||||
|
**`wails3 task android:run:device` is the way to put a debug build on a
|
||||||
|
real device**, since #159. What #52 used, before it was safe, was the
|
||||||
|
longer form, and it is still the smallest thing that works if you want
|
||||||
|
no script between you and adb:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
wails3 task android:build ARCH=arm64 && wails3 task android:assemble:apk
|
||||||
|
adb install -r bin/yellowjacket.apk # -r, never uninstall
|
||||||
|
adb shell am start -n app.yellowjacket.dev/com.wails.app.MainActivity
|
||||||
|
```
|
||||||
|
|
||||||
|
The id in that last line is the one thing to keep an eye on by hand —
|
||||||
|
`./scripts/android-pkgid.sh bin/yellowjacket.apk` is what the tasks ask,
|
||||||
|
and it is a good habit before any `am start` written out in full.
|
||||||
|
|
||||||
|
`YJ_ANDROID_PKG=app.yellowjacket.dev` still overrides what
|
||||||
|
`scripts/android-emulator.sh` — and therefore `make android-smoke`,
|
||||||
|
`android-logs`, `android-launch` — addresses, but it is rarely needed
|
||||||
|
now: that default is read from `bin/yellowjacket.apk`, so it already
|
||||||
|
follows whichever variant was built last.
|
||||||
|
|
||||||
## What only a device can answer
|
## What only a device can answer
|
||||||
|
|
||||||
The emulator cannot run this app (three separate reasons, none of them
|
The emulator cannot run this app (three separate reasons, none of them
|
||||||
@@ -311,6 +420,91 @@ system bars, the back gesture, focus and audio interruptions,
|
|||||||
permission dialogs, the keyboard — not about what the app draws. The
|
permission dialogs, the keyboard — not about what the app draws. The
|
||||||
drawing is what the other five tiers already cover.
|
drawing is what the other five tiers already cover.
|
||||||
|
|
||||||
|
**The third such fault was the activity lifecycle** (#52), and it is
|
||||||
|
the one to re-check after touching `main()`, `WailsBridge` or
|
||||||
|
`MainActivity`. Android destroys and recreates an activity **without
|
||||||
|
restarting the process**, and Wails' `nativeInit` — which
|
||||||
|
`MainActivity.onCreate` calls — runs `go mainFunc()` every time. So
|
||||||
|
Go's `main()` ran again on a live app, `app.Run()` refused (`a.starting`
|
||||||
|
is still true behind Android's `select{}`), and the `os.Exit(1)` under
|
||||||
|
it took the healthy first app down with it.
|
||||||
|
|
||||||
|
### The lifecycle check, and how to trigger it on demand
|
||||||
|
|
||||||
|
This is the regression guard for #52 on this tier, because no other
|
||||||
|
tier runs `main()` on Android at all. The Go-side guard
|
||||||
|
(`TestMainClaimsBeforeItDoesAnything`) catches work creeping above the
|
||||||
|
latch; only the device catches the latch not working.
|
||||||
|
|
||||||
|
**Trigger a relaunch with a configuration change the manifest does not
|
||||||
|
declare.** `AndroidManifest.xml` lists
|
||||||
|
`orientation|screenSize|keyboardHidden|uiMode`, so those are handled
|
||||||
|
in-place and are *not* triggers. `fontScale` is not listed, and it is a
|
||||||
|
one-liner:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
adb shell settings put system font_scale 1.15 # restore the old value after
|
||||||
|
```
|
||||||
|
|
||||||
|
That is the same in-process destroy/recreate that "Don't keep
|
||||||
|
activities", a locale change and a memory trim produce, but on demand.
|
||||||
|
|
||||||
|
**"Don't keep activities" is the report's own lever and did not work on
|
||||||
|
this device**: `settings put global always_finish_activities 1` reads
|
||||||
|
back as `1`, `am set-always-finish-activities` does not exist on this
|
||||||
|
build, and the activity was never finished on backgrounding. Do not
|
||||||
|
spend an afternoon on it; use the config change.
|
||||||
|
|
||||||
|
**The assertion is the pid, and the tell is two bridge inits in one.**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
adb logcat -d | grep -E "Wails bridge initialized|has died|finishDrawing of relaunch"
|
||||||
|
```
|
||||||
|
|
||||||
|
Healthy is one pid appearing twice — the process surviving the
|
||||||
|
recreation:
|
||||||
|
|
||||||
|
```
|
||||||
|
I/WailsBridge(28420): Wails bridge initialized
|
||||||
|
I/WailsBridge(28420): Wails bridge initialized <- same pid, recreated
|
||||||
|
```
|
||||||
|
|
||||||
|
Broken is that pair followed within a second by:
|
||||||
|
|
||||||
|
```
|
||||||
|
I/WindowManager: finishDrawing of relaunch: Window{...MainActivity} 603ms
|
||||||
|
I/ActivityManager: Process app.yellowjacket.dev (pid 22956) has died: fg TOP
|
||||||
|
W/ActivityTaskManager: Force removing ActivityRecord{...}: app died, no saved state
|
||||||
|
```
|
||||||
|
|
||||||
|
Two things about reading that. **`has died: fg TOP` is not a memory
|
||||||
|
kill** — the system does not reclaim the foreground process, so this is
|
||||||
|
the app leaving of its own accord. And there is **no crash record
|
||||||
|
anywhere**: `logcat -b crash` is empty, no `AndroidRuntime`, no
|
||||||
|
`libc: Fatal signal`, no tombstone. That is the `os.Exit` signature,
|
||||||
|
and it is why "the system killed it" is the wrong first hypothesis.
|
||||||
|
|
||||||
|
**Surviving is only half of it — check the recreated WebView is still
|
||||||
|
wired to the running app.** A plausible-looking fix (making
|
||||||
|
`WailsBridge.initialized` static, so the second `nativeInit` is skipped)
|
||||||
|
keeps the process alive and silently breaks this, because `nativeInit`
|
||||||
|
is also what re-points the JNI reference at the new bridge. Go would go
|
||||||
|
on executing JavaScript against the destroyed activity's WebView: the
|
||||||
|
app opens, renders, and never receives another backend event.
|
||||||
|
|
||||||
|
Ask the page, after a relaunch and a resume:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make android-inspect
|
||||||
|
make android-eval EXPR='(()=>{window.__probe=[];const o=window._wails.dispatchWailsEvent.bind(window._wails);window._wails.dispatchWailsEvent=(e)=>{window.__probe.push(e&&e.name);return o(e)};return "ok"})()'
|
||||||
|
# background and foreground the app, then:
|
||||||
|
make android-eval EXPR='JSON.stringify(window.__probe)'
|
||||||
|
```
|
||||||
|
|
||||||
|
A healthy build answers with events from the live services —
|
||||||
|
`["IndexStatusChanged","JobsChanged","JobsChanged","android:storageAccess"]`.
|
||||||
|
`[]` means the bridge reference is stale.
|
||||||
|
|
||||||
## Asking the device, not just looking at it
|
## Asking the device, not just looking at it
|
||||||
|
|
||||||
A real phone can be inspected, and that turns this tier from "reported
|
A real phone can be inspected, and that turns this tier from "reported
|
||||||
@@ -340,6 +534,130 @@ Four things about it, each of which costs an hour if met cold:
|
|||||||
script. Plug in over USB for anything longer than a couple of probes.
|
script. Plug in over USB for anything longer than a couple of probes.
|
||||||
- **The socket name carries the pid**, which changes on every launch, so
|
- **The socket name carries the pid**, which changes on every launch, so
|
||||||
it is resolved rather than remembered.
|
it is resolved rather than remembered.
|
||||||
|
- **A reinstall resets the runtime permissions**, and the grant dialog
|
||||||
|
is a separate activity that takes focus — so the app is up, `am start`
|
||||||
|
reports "delivered to currently running top-most instance", and
|
||||||
|
`pidof` is empty because it never got to the foreground.
|
||||||
|
`dumpsys window | grep mCurrentFocus` naming
|
||||||
|
`GrantPermissionsActivity` is the tell. `adb shell pm grant
|
||||||
|
app.yellowjacket.dev android.permission.READ_MEDIA_AUDIO` (and
|
||||||
|
`POST_NOTIFICATIONS`) ahead of the launch skips it.
|
||||||
|
|
||||||
|
### Getting the app into a state worth measuring
|
||||||
|
|
||||||
|
A fresh install is **not** a neutral starting point, and three things
|
||||||
|
about it will each cost you a measurement.
|
||||||
|
|
||||||
|
**It downloads the real catalog.** `YJ_CORE_INDEX_URL` is stubbed in
|
||||||
|
`dev-headless.sh` and in CI and is *real* here, so the app spends its
|
||||||
|
first minutes fetching ~0.6 GB and `job-band` is **103px of a 439px
|
||||||
|
screen** while it does. Every vertical number taken in that state is
|
||||||
|
wrong -- one #51 measurement had the album art at 0px and it was
|
||||||
|
entirely this.
|
||||||
|
|
||||||
|
`__yj.call("explore.Service.StopIndexBuild", [])` stops it and returns
|
||||||
|
cleanly. **It then starts again within seconds.** So stop it
|
||||||
|
*immediately before* the measurement rather than once at the beginning,
|
||||||
|
and check `jobs.Service.GetJobs` afterwards -- an empty array is the
|
||||||
|
only proof. `jobs.Service.ClearFinishedJobs` tidies the finished rows
|
||||||
|
that otherwise keep the band open.
|
||||||
|
|
||||||
|
**A library added over the bridge does not dismiss the first-run
|
||||||
|
wizard.** `library.Library.AddLibrary` works and scans, but the wizard
|
||||||
|
checks for an existing library once, on mount, and its "Get Started"
|
||||||
|
button gates on a directory chosen *in the wizard* -- so it stays up
|
||||||
|
with a correctly disabled button over everything you are trying to
|
||||||
|
measure. Nothing is broken; reload the page and it is gone. This reads
|
||||||
|
exactly like a tap being swallowed, which is the expensive part.
|
||||||
|
|
||||||
|
**Scoped storage decides where the music can be.** `/sdcard/Music/...`
|
||||||
|
plus `pm grant <pkg> android.permission.READ_MEDIA_AUDIO` works and
|
||||||
|
`AddLibrary` takes the plain path; a push into
|
||||||
|
`/sdcard/Android/data/<pkg>/files/` looks like it worked and then is not
|
||||||
|
there. Some builds additionally want
|
||||||
|
`appops set <pkg> MANAGE_EXTERNAL_STORAGE allow`, and until they have it
|
||||||
|
the app opens the *system* "All files access" screen on launch -- so
|
||||||
|
`dumpsys window | grep mCurrentFocus` naming `com.android.settings` is
|
||||||
|
that, not a crash.
|
||||||
|
|
||||||
|
### A note on quoting `make android-eval`
|
||||||
|
|
||||||
|
`EXPR='...'` is a single-quoted shell word, so anything with a quote or
|
||||||
|
an apostrophe in it -- a file path like `Blazo, 49'ers - ...`, or a
|
||||||
|
snippet containing a string literal -- breaks in a way that reads as a
|
||||||
|
JavaScript error. Put the expression in a file and pass it positionally:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
node ./scripts/android-eval.mjs "$(cat /tmp/probe.js)"
|
||||||
|
```
|
||||||
|
|
||||||
|
That is the same script `make android-eval` wraps, so nothing is lost.
|
||||||
|
Two things worth knowing about it: it does **not** await a promise, so
|
||||||
|
an async call has to park its result (`window.__r = ...`) and be read
|
||||||
|
back in a second eval; and the shim from the section below is lost on
|
||||||
|
every reload and every app restart, along with the devtools socket,
|
||||||
|
whose name carries the pid.
|
||||||
|
|
||||||
|
### Calling a binding on the device
|
||||||
|
|
||||||
|
**The runtime call does not go over HTTP on Android**, and this is worth
|
||||||
|
knowing before an hour is spent on it. The WebView cannot deliver a
|
||||||
|
`fetch()` POST body to `shouldInterceptRequest`, so v3 routes runtime
|
||||||
|
calls through the `addJavascriptInterface` bridge instead: the
|
||||||
|
@wailsio/runtime installs a `customTransport` that calls
|
||||||
|
`window.wails.invokeAsync(id, payload)` and receives the answer on
|
||||||
|
`window._wailsAndroidCallback`. Two consequences:
|
||||||
|
|
||||||
|
- **`.playwright/init-events.js` does not transfer to the device.** Its
|
||||||
|
outbound half hooks `fetch`, which sees nothing here, and its
|
||||||
|
`call()` posts to `/wails/runtime`, which answers
|
||||||
|
`Invalid runtime call: missing object value` — the interceptor got the
|
||||||
|
URL with no body. Its *inbound* half is still right, because
|
||||||
|
`dispatchWailsEvent` is the entry point in every mode.
|
||||||
|
- **Hooking `fetch` from an eval is too late anyway**, on any platform:
|
||||||
|
the bundle captured its reference at module scope, so a wrapper
|
||||||
|
installed afterwards records nothing. That is why the harness is an
|
||||||
|
`initScript` and not a step in a spec.
|
||||||
|
|
||||||
|
What works is to borrow the bridge, chaining the runtime's own callback
|
||||||
|
so its pending calls still resolve:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const pending = new Map();
|
||||||
|
const prev = window._wailsAndroidCallback;
|
||||||
|
window._wailsAndroidCallback = (id, response, error) => {
|
||||||
|
if (!pending.has(id)) return prev && prev(id, response, error);
|
||||||
|
const p = pending.get(id); pending.delete(id);
|
||||||
|
const env = JSON.parse(response || "{}");
|
||||||
|
return env.ok ? p.resolve(env.data ?? env.text) : p.reject(new Error(env.error));
|
||||||
|
};
|
||||||
|
window.__yj = { call(name, args) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const id = "yj" + Math.random().toString(36).slice(2);
|
||||||
|
pending.set(id, { resolve, reject });
|
||||||
|
window.wails.invokeAsync(id, JSON.stringify({
|
||||||
|
object: 0, method: 0, windowName: "",
|
||||||
|
args: { "call-id": id, methodName: "yellowjacket/backend/" + name, args: args || [] },
|
||||||
|
clientId: window._wails.clientId,
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
} };
|
||||||
|
```
|
||||||
|
|
||||||
|
That turns the device into a tier that can be *driven* rather than only
|
||||||
|
looked at — `__yj.call("player.Player.LoadFile", [path])` and
|
||||||
|
`__yj.call("library.Library.AddLibrary", ["/sdcard/Music/..."])` are how
|
||||||
|
#53 was measured. Names are the Go ones (`GetTracks`, not
|
||||||
|
`GetAllTracks`); an unknown one comes back as a plain
|
||||||
|
`unknown bound method name`, so a wrong guess is loud.
|
||||||
|
|
||||||
|
**Getting audio onto the phone**: `adb push` into
|
||||||
|
`/sdcard/Android/data/<pkg>/files/` looks like it works and then the
|
||||||
|
files are not there — scoped storage. `/sdcard/Music/...` plus
|
||||||
|
`pm grant … READ_MEDIA_AUDIO` does work, and `AddLibrary` takes the
|
||||||
|
plain path. The generated fixtures are **~2 seconds** each, which is
|
||||||
|
fine for a scan and useless for watching a seek bar, so synthesise a
|
||||||
|
long one: `ffmpeg -f lavfi -i sine=frequency=440:duration=240`.
|
||||||
|
|
||||||
**And the reason to bother: the phone is an engine, not a screen.** The
|
**And the reason to bother: the phone is an engine, not a screen.** The
|
||||||
first device here renders in **Chrome 113** at 424x439 CSS px. Every
|
first device here renders in **Chrome 113** at 424x439 CSS px. Every
|
||||||
|
|||||||
@@ -42,11 +42,16 @@ strings and identical specs produce different bytes on different builds.
|
|||||||
playback and then clicks pause races the track ending and fails
|
playback and then clicks pause races the track ending and fails
|
||||||
against a correct UI. Use `LONG_TRACK` (90 s, `edge-lengths`) exported
|
against a correct UI. Use `LONG_TRACK` (90 s, `edge-lengths`) exported
|
||||||
from `e2e/support/fixtures.ts`.
|
from `e2e/support/fixtures.ts`.
|
||||||
- **WAV tracks scan in untitled.** `backend/tagwriter` writes WAV tags
|
- **WAV tracks scan like every other format.** #104 added
|
||||||
into a RIFF `id3 ` chunk and `dhowden/tag` has no RIFF parser, so
|
`backend/riff`, so the scan reads the `id3 ` chunk `backend/tagwriter`
|
||||||
there is no "Field Recordings" artist in the Artists view. This is a
|
writes and both WAVs come in fully tagged: "Field Recordings" is an
|
||||||
known open bug pinned by `TestWAVTagsAreNotReadableYet`; do not
|
ordinary artist in the Artists view, with a "Test Tones" album and a
|
||||||
"fix" a spec by asserting the broken behaviour elsewhere.
|
cover. They are therefore not an example of an untitled or albumless
|
||||||
|
track — the only two tracks with no album are
|
||||||
|
`unsorted/no-tags-at-all.mp3` and `unsorted/title-only.mp3`. Prose
|
||||||
|
written before #104 says the opposite and names
|
||||||
|
`TestWAVTagsAreNotReadableYet`, a test that change deleted; that is
|
||||||
|
dated history rather than a description of the app.
|
||||||
|
|
||||||
## Seeds
|
## Seeds
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,21 @@ behind `YJ_TESTCTL=1`, which `scripts/dev-headless.sh` sets and
|
|||||||
staging the work that would produce it — job progress, download
|
staging the work that would produce it — job progress, download
|
||||||
progress, scan progress. It calls `events.Deliver`, which *errors*
|
progress, scan progress. It calls `events.Deliver`, which *errors*
|
||||||
when the event reaches nobody, so a `200` means it really arrived.
|
when the event reaches nobody, so a `200` means it really arrived.
|
||||||
|
- **State you stage, you own** (#168). Nothing resets those stores, so
|
||||||
|
clear yours in `test.afterEach` with the same event that staged it
|
||||||
|
(`emit('JobsChanged', [])`) — the store replaces its list from every
|
||||||
|
snapshot, so `testctl` needs no special case. **Measured: this does
|
||||||
|
not currently cross a spec boundary**, because every test gets a fresh
|
||||||
|
page and `JobStore.init()` refetches `GetJobs()` from a backend
|
||||||
|
registry that `/__test/emit` never writes to. Stated anyway, because
|
||||||
|
it costs one line and the leak needs only one spec that keeps a page
|
||||||
|
alive — but do not cite #168 for a symptom you have not reproduced.
|
||||||
|
- **Measure against the thing next to you, not an absolute
|
||||||
|
coordinate.** An absolute number in a shell measurement is also a
|
||||||
|
claim about everything above it — `contentTop === 0` quietly asserts
|
||||||
|
"and no background job is running", which is not what that spec was
|
||||||
|
about or could arrange, while `contentTop === jobBandBottom` is true
|
||||||
|
either way. This is the half of #168 that stands on its own.
|
||||||
- **`restore` is slow** (~40 s in the suite) because it copies every
|
- **`restore` is slow** (~40 s in the suite) because it copies every
|
||||||
table. Prefer snapshotting once and restoring only when a spec
|
table. Prefer snapshotting once and restoring only when a spec
|
||||||
genuinely mutates state.
|
genuinely mutates state.
|
||||||
|
|||||||
@@ -78,9 +78,58 @@ synchronously.
|
|||||||
Microtasks and not a timer, deliberately: a timer hangs forever under
|
Microtasks and not a timer, deliberately: a timer hangs forever under
|
||||||
the suites that install fake ones.
|
the suites that install fake ones.
|
||||||
|
|
||||||
Visual baselines are font-hinting and compositing sensitive, which is
|
## The visual tier does not gate, and that is measured (#196)
|
||||||
why they are opt-in: they only mean anything on the machine that
|
|
||||||
recorded them.
|
`make ui-visual` is the same suite with nine `toMatchScreenshot`
|
||||||
|
baselines switched on. **Nothing runs it but a person**, deliberately,
|
||||||
|
and the reason is a number rather than a preference: the committed
|
||||||
|
baselines were recorded on Arch, and replayed in a bare `ubuntu:24.04`
|
||||||
|
container — CI's `check` image — three of them fail for reasons that
|
||||||
|
have nothing to do with any component.
|
||||||
|
|
||||||
|
| baseline | Arch | ubuntu:24.04 |
|
||||||
|
|---|---|---|
|
||||||
|
| `page-header` filtered-by-search | passes | ratio 0.03 differ, against a 0.02 allowance |
|
||||||
|
| `track-info` | passes | ratio 0.03 differ |
|
||||||
|
| `seek-bar` | 1152×18 | 1152×17 |
|
||||||
|
|
||||||
|
The two references that were genuinely stale did not even agree about
|
||||||
|
their *new* size — `now-playing` renders 1152×65 on Arch and 1152×64 in
|
||||||
|
the container. So moving CI's `check` job from `make ui-test` to
|
||||||
|
`make ui-visual` is not a one-line change: it needs a second,
|
||||||
|
container-recorded baseline set, which every local run would then fail
|
||||||
|
against. That is the same trap the other way round, and a pre-push hook
|
||||||
|
is the same fault again — one machine's baselines against everybody
|
||||||
|
else's renderer.
|
||||||
|
|
||||||
|
So the tier stays local and opt-in, and the rule that replaces the gate
|
||||||
|
is:
|
||||||
|
|
||||||
|
- **A change that moves a component's geometry refreshes that
|
||||||
|
component's reference in the same commit, having read the image.**
|
||||||
|
Look at the PNG; the dimensions in the failure message are the cheap
|
||||||
|
half of the answer.
|
||||||
|
- **Never refresh a reference you did not cause.** #196 exists because
|
||||||
|
four of them drifted across three unrelated merges, and every red run
|
||||||
|
made the next person likelier to stop running the tier than to read
|
||||||
|
it.
|
||||||
|
- **State the world the shot is taken in.** The stores are singletons,
|
||||||
|
so a visual case that sets nothing photographs whatever the previous
|
||||||
|
case left behind — which is how the sidebar's baseline came to have
|
||||||
|
Tracks lit and `now-playing`'s to be playing from a dynamic mix.
|
||||||
|
- **Record one file with `make ui-visual-update UI_ARGS=<path>`**, and
|
||||||
|
check `git status` before committing either way. That filter is only
|
||||||
|
honoured since #204: the recipe was a bare `--update`, and vitest
|
||||||
|
takes the following positional as the flag's value, so the path was
|
||||||
|
swallowed and *every* baseline was re-recorded — blessing any stale
|
||||||
|
one in silence.
|
||||||
|
|
||||||
|
What the tier is worth, for the record: it is a *layout* check, blind to
|
||||||
|
colour (the component tier has no `:root`, so it renders the fallbacks —
|
||||||
|
`make ui-visual` passed unchanged through a whole palette rewrite,
|
||||||
|
twice), and it has caught one thing nothing else could — swapping
|
||||||
|
`library-status-indicator`'s `<button>` for a `<span>` lost the UA
|
||||||
|
stylesheet's `box-sizing` and grew the badge 36→38px.
|
||||||
|
|
||||||
## Bindings
|
## Bindings
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,306 @@
|
|||||||
|
---
|
||||||
|
name: yj-loop
|
||||||
|
description: Operating the autonomous backlog loop — the crank that works the YellowJacket tracker one issue at a time (tick mechanics, the state machine in Gitea, which agent and model take each leg, the escalation ladder, merge authority and the rails that stop it doing damage). Use whenever a scheduled tick fires, and when piloting or debugging the loop.
|
||||||
|
---
|
||||||
|
|
||||||
|
# The YellowJacket backlog loop
|
||||||
|
|
||||||
|
Design and arguments: `.planning/plans/active/020-autonomous-backlog-loop.md`.
|
||||||
|
This skill is the **operating procedure**; the plan is the reasoning.
|
||||||
|
`yellowjacket-dev` is the harness doctrine (tiers, seeds, traps); this
|
||||||
|
skill is the loop doctrine (who acts, on what model, with what authority).
|
||||||
|
Read the plan first, once. Then this file every tick.
|
||||||
|
|
||||||
|
## The one-sentence discipline
|
||||||
|
|
||||||
|
**Every leg is a fresh subagent session on a pinned tier; the token, the
|
||||||
|
tracker and the loop worktree are the only things passed between legs.
|
||||||
|
Never switch a model mid-session, never let two writers exist at once,
|
||||||
|
never keep state in a conversation.**
|
||||||
|
|
||||||
|
## Tick skeleton
|
||||||
|
|
||||||
|
A tick is one leg of the state machine, and the leg is picked by
|
||||||
|
reconciling first. Execute in this order:
|
||||||
|
|
||||||
|
1. **Lock.** `/tmp/yj-loop.lock` holds `pid + start-iso`. If a live
|
||||||
|
process owns it and is younger than 2 h: exit immediately, report
|
||||||
|
"tick skipped (lock held)". If the PID is dead, take the lock.
|
||||||
|
Remove it before every exit.
|
||||||
|
2. **Reconcile.** Fresh reads, never cached: open issues
|
||||||
|
(`scripts/issue.sh list`), PRs and CI via the REST API, branches via
|
||||||
|
`git ls-remote --heads origin`, `.pi/loop/state.json`. GITEA_TOKEN
|
||||||
|
refusing = the tick reports and exits; the identity rails below are
|
||||||
|
not optional.
|
||||||
|
3. **Pick the leg.** See the state machine below; the leg follows the
|
||||||
|
issue's lifecycle (claim→plan→…→merge→…→housekeep). Exactly one leg.
|
||||||
|
4. **Execute** — the leg table below says who acts and what they must
|
||||||
|
return.
|
||||||
|
5. **Journal** — one line per tick in the state file (issue, leg, result,
|
||||||
|
tick cost if leg reports it).
|
||||||
|
6. **Report** — three lines: issue taken or continued, its state now,
|
||||||
|
anomalies. Then stop. A tick that reports is a tick that can leave a
|
||||||
|
conversation behind.
|
||||||
|
|
||||||
|
## The state machine
|
||||||
|
|
||||||
|
The tracker is the truth. The state file (`.pi/loop/state.json`,
|
||||||
|
gitignored) is an index plus flags (`emulator`, `drain`); the tracker
|
||||||
|
wins every disagreement.
|
||||||
|
|
||||||
|
| Stage | Where it lives | Leg → actor |
|
||||||
|
|---|---|---|
|
||||||
|
| selected | nothing written until claim is possible | select |
|
||||||
|
| in flight | `Status/In Progress`, assignee, comment with branch+approach | claim (orchestrator, `scripts/issue.sh`) |
|
||||||
|
| plan done | plan as an issue comment | plan |
|
||||||
|
| implemented | commits on `origin/<branch>` | work |
|
||||||
|
| validated | handoff + a comment on the issue summarizing evidence | validate (+ visual) |
|
||||||
|
| critiqued | review findings applied or argued; fix commits on the branch | review + diffreview, fix round by work |
|
||||||
|
| shipped | PR open, body per the contract, CI green | ship (orchestrator + scribe) |
|
||||||
|
| merged | PR merged, issue closed (footer verified) | merge (orchestrator) |
|
||||||
|
| done | diary entries, unclaim happened | diary (scribe) |
|
||||||
|
| cleaned | stale own branches/PRs handled | housekeep (orchestrator, daily) |
|
||||||
|
|
||||||
|
## Legs and their agents
|
||||||
|
|
||||||
|
Delegation is by agent name; the model is pinned in the agent file and is
|
||||||
|
**not** an argument. Every leg prompt names: the issue, the evidence so
|
||||||
|
far (plan comment, handoffs), what the leg must produce, and its stop
|
||||||
|
rules. Never "go fix it" — the leg contract is in this file.
|
||||||
|
|
||||||
|
| Leg | Agent | Model (tier) | Produces |
|
||||||
|
|---|---|---|---|
|
||||||
|
| gather/mechanical dump | `yj-loop.inspect` | go/mimo-v2.5 (T0) | tracker/PR/CI/branch digest, verbatim |
|
||||||
|
| select next issue | `yj-loop.select` | glm/glm-5.3 (T2) | one issue + reasons, or "nothing qualifies" |
|
||||||
|
| plan | `yj-loop.plan` | glm/glm-5.3 (T2) | a plan comment on the issue |
|
||||||
|
| implement | `yj-loop.work` | qwen/deepseek-v4-pro-0813 (T1) | commits + a handoff (see contract below) |
|
||||||
|
| validate | `yj-loop.validate` | glm/glm-5.3 (T2) | pass/fail with evidence per acceptance item |
|
||||||
|
| visual evidence | `yj-loop.visual` | glm/glm-5.3-flash (T2) | what the screenshot actually shows |
|
||||||
|
| consequences review | `yj-loop.review` | glm/glm-5.3 (T2) | blockers / fix-worthy / optional findings |
|
||||||
|
| understood-diff review | `yj-loop.diffreview` | qwen/deepseek-v4-pro-0813 (T1) | same shape, scope-tight |
|
||||||
|
| escalation | `yj-loop.escalate` | go/kimi-k3 (T3) | same leg re-run, seeded with failure summary |
|
||||||
|
| prose (PR body, commit msgs, journal) | `yj-loop.scribe` | go/mimo-v2.5 (T0) | text only, from supplied facts |
|
||||||
|
|
||||||
|
**Model fallback on quota exhaustion.** The pinned models are the
|
||||||
|
intent, not a guarantee. The qwen token plan is a weekly pool and has
|
||||||
|
run dry mid-tick (`429 … 1-week quota exhausted`). When a leg's launch
|
||||||
|
fails with a 429, re-run it with a per-run `model` override one rung
|
||||||
|
down and journal the substitution — never spend the T3 escalation
|
||||||
|
model on a quota substitution. The qwen-pinned legs (`work`,
|
||||||
|
`diffreview`) fall back `qwen/deepseek-v4-pro-0813` → `go/deepseek-v4-pro`
|
||||||
|
→ `go/glm-5.3-flash`. Do **not** use the `deepseek/...` provider: it has
|
||||||
|
no models, only catalog overrides, and fails silently (empty artifact,
|
||||||
|
no session) — the model lives on the `go` gateway.
|
||||||
|
|
||||||
|
**Launch legs in the foreground.** The async subagent runner has died
|
||||||
|
without persisting a child session (nothing to resume) and emits
|
||||||
|
spurious "needs attention" nudges on runs that are already complete.
|
||||||
|
Foreground `subagent` calls are the reliable mode here. A worker that
|
||||||
|
dies mid-leg leaves uncommitted work: inspect the tree, then relaunch
|
||||||
|
to *complete* — never to re-implement.
|
||||||
|
|
||||||
|
Orchestrator-only legs: **claim** (`issue.sh claim --branch` — atomic,
|
||||||
|
refuses if held), **ship's PR/CI polling** (REST API below — `gitea_ci`
|
||||||
|
job_logs 404s on this Gitea; the REST endpoints are the way), **merge**
|
||||||
|
(API below), **housekeep**.
|
||||||
|
|
||||||
|
## Selection rules (`select`)
|
||||||
|
|
||||||
|
The rules from `.pi/prompts/next-issue.md` stay — priority order, #73's
|
||||||
|
sequence overriding labels where it speaks, skipping `Status/*` states
|
||||||
|
that mean busy, branch-collision check, verifiability, flakes. The
|
||||||
|
emulator flag **adds** emulator-verifiable Android issues; it never
|
||||||
|
reaches device-only ones. A "nothing qualifies" answer is a correct
|
||||||
|
tick, not a failure — report it and stop.
|
||||||
|
|
||||||
|
## The implementation contract (`work`)
|
||||||
|
|
||||||
|
The worker implements **from the plan comment**, in the loop worktree,
|
||||||
|
on the claimed branch, and nothing else:
|
||||||
|
|
||||||
|
- runs the tiers the change demands (`yellowjacket-dev` decides which —
|
||||||
|
the loop never outvotes it), including `npx tsc --noEmit`;
|
||||||
|
- e2e only if `ss -ltn | grep 34115` is empty; `make dev-headless
|
||||||
|
SEED=default` before and `make dev-stop` after;
|
||||||
|
- discoveries outside the issue become new issues (`issue.sh new`), never
|
||||||
|
bigger diffs; a materially-larger-than-implied issue stops the leg with
|
||||||
|
a comment and a label removal, not a hail-mary;
|
||||||
|
- handoff must state: changed files, what was left undone, commands run
|
||||||
|
with exit codes, verification evidence, surprises, decisions needing
|
||||||
|
approval. A handoff without that list is a failed leg.
|
||||||
|
|
||||||
|
## Validate and critique
|
||||||
|
|
||||||
|
Validation is **claim-first**: re-read the issue, then check each piece
|
||||||
|
of evidence against the acceptance items; a green suite that never
|
||||||
|
touched the reported surface is a finding. Screenshots go to `visual`,
|
||||||
|
never to a text-only tier.
|
||||||
|
|
||||||
|
Critique is the standing fan-out (`subagent` parallel: `yj-loop.review`
|
||||||
|
consequences + `yj-loop.diffreview` scope-tight, both fresh). The
|
||||||
|
orchestrator synthesizes: blockers and fix-worthy findings go back to
|
||||||
|
`work` as one bounded fix round (maximum three rounds total; then the
|
||||||
|
issue gets a `⟦loop⟧` comment stating what will not be fixed and why,
|
||||||
|
and the ship leg proceeds unless a finding is a blocker). Reviewers do
|
||||||
|
not edit files.
|
||||||
|
|
||||||
|
## Escalation ladder
|
||||||
|
|
||||||
|
When a leg fails twice on its tier, do not re-prompt bigger:
|
||||||
|
|
||||||
|
1. The failing session writes its summary: what it tried, what failed,
|
||||||
|
what it observed.
|
||||||
|
2. A **new** session on the next tier up is seeded with that summary and
|
||||||
|
the original leg contract.
|
||||||
|
3. T3 is the ceiling: fresh session, never parallel, **once per day**.
|
||||||
|
A day's escalation is spent — the issue waits until tomorrow.
|
||||||
|
|
||||||
|
Routing down is free; routing up is the budget.
|
||||||
|
|
||||||
|
## Ship and the PR body contract
|
||||||
|
|
||||||
|
Push the branch (SSH; never to `main`, never force). The PR body —
|
||||||
|
written by `scribe` from the validator's and reviewers' output — states:
|
||||||
|
what the issue was, what changed and why, **which verification tiers ran
|
||||||
|
and their results**, what was deliberately not done, the commit-to-issue
|
||||||
|
table, and `Closes #n`. `Closes` also sits one-per-line in a commit body
|
||||||
|
**inside the branch** — both, regardless of merge strategy, because the
|
||||||
|
pairing was measured.
|
||||||
|
|
||||||
|
Poll CI until `check` and `e2e` finish. On failure: read the log via
|
||||||
|
`GET /api/v1/repos/yonlu/yellowjacket/actions/runs/<run>/jobs` (per-step)
|
||||||
|
and `…/actions/jobs/<id>/logs` (full). Fix on the branch. **Two
|
||||||
|
consecutive identical failures = stop**: comment what is known on the
|
||||||
|
PR and the issue, leave both, report. Do not burn ticks on a red wall.
|
||||||
|
|
||||||
|
## Merge authority
|
||||||
|
|
||||||
|
Merge when, and only when, **all** hold:
|
||||||
|
|
||||||
|
- the PR was opened by this loop (it is in the state file's index);
|
||||||
|
- the protection contexts `CI / check` and `CI / e2e` are green on the
|
||||||
|
PR's head, read from the API, not from the PR page's badge;
|
||||||
|
- the PR reports mergeable;
|
||||||
|
- the critique leg ran and no open blocker stands;
|
||||||
|
- the branch is **not behind `origin/main`** — the protection's
|
||||||
|
`block_on_outdated_branch: true` refuses it anyway; never
|
||||||
|
`force_manually_merged` around it.
|
||||||
|
|
||||||
|
**Refresh before every merge.** In the loop worktree: `git fetch origin`
|
||||||
|
in the same breath, then `git merge origin/main` on the PR branch,
|
||||||
|
push. The fetch must be immediate — a cached `origin/main` merges
|
||||||
|
against the wrong base, CI goes green on it, and the merge comes back
|
||||||
|
405 "behind base", one whole CI cycle wasted (measured on the adoption
|
||||||
|
wave). A textual conflict
|
||||||
|
stops the leg there — as diff text, not as a failed merge click: hunks
|
||||||
|
the loop authored are resolved by the loop; anything else is left with
|
||||||
|
`⟦loop⟧` comment for a human, never forced. After any refresh push,
|
||||||
|
re-poll the PR's own required contexts on the **new head** before
|
||||||
|
merging.
|
||||||
|
|
||||||
|
**Merges happen one at a time**, each re-reading state — the previous
|
||||||
|
merge moved `main`, and the next PR's mergeability is recomputed at
|
||||||
|
its own turn.
|
||||||
|
|
||||||
|
```
|
||||||
|
curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
https://git.ljones.me/api/v1/repos/yonlu/yellowjacket/pulls/<n>/merge \
|
||||||
|
-d '{"Do":"merge","merge_message_field":"default","force_manually_merged":false}'
|
||||||
|
```
|
||||||
|
|
||||||
|
**Afterwards watch the `push` run on `main`** — the CI the merge
|
||||||
|
started. A red main after a loop merge is a **halt**: comment what is
|
||||||
|
known on the offending PR, mark the state file, stop taking new issues.
|
||||||
|
That run is the only thing between a clean textual merge of
|
||||||
|
independently-written PRs and a self-contradicting main; no
|
||||||
|
mergeability check sees it. Only a green main lets the tick proceed (to
|
||||||
|
footer verification, below).
|
||||||
|
|
||||||
|
Footer verification: `scripts/issue.sh list --state open` and check
|
||||||
|
the footer took. Close stragglers with `issue.sh close`, naming the
|
||||||
|
merge commit. `unclaim.yml` handles the label; it is not instant;
|
||||||
|
reopening does not restore it. Merging fans out to nothing (releases
|
||||||
|
are the manual `release.yml`, which the loop never runs) — the
|
||||||
|
criticism stands before the merge because nothing stands after it.
|
||||||
|
|
||||||
|
## Rails — the loop's absolute rules
|
||||||
|
|
||||||
|
1. **Touch only its own.** Issues it claimed, branches it made, PRs it
|
||||||
|
opened. `issue.sh claim` enforces the front gate; never work around a
|
||||||
|
refusal.
|
||||||
|
2. **One writer, one issue.** The loop worktree is the only dirty tree.
|
||||||
|
3. **Never merge a PR it did not open.** Any merge that violates this is
|
||||||
|
a hard stop.
|
||||||
|
4. **Human work is holy.** Human branches, PRs, assignees: leave exactly
|
||||||
|
as found. Cleanup never names them.
|
||||||
|
5. **The token is identity.** If GITEA_TOKEN misbehaves, the tick stops.
|
||||||
|
6. **New findings are new issues**, never scope creep. The tracker
|
||||||
|
vocabulary (`Kind/`, `Area/`, `Priority/`) stays intact in one
|
||||||
|
taxonomy; use `scripts/issue.sh new` with correct labels.
|
||||||
|
7. **Conventional Commits**, enforced by `scripts/commit-check.sh`; the
|
||||||
|
type list and `.releaserc.yml`'s must agree — a loop commit is a
|
||||||
|
release grammar token even after months of no manual releases.
|
||||||
|
8. **Tiers over vibes.** `yellowjacket-dev`'s tier table decides what a
|
||||||
|
change must pass; a skipped tier is stated, never silent.
|
||||||
|
9. **Two strikes on CI, three rounds of critique, one kimi a day.** The
|
||||||
|
loop's patience is finite on purpose.
|
||||||
|
10. **Every leg writes its evidence.** A leg that leaves nothing behind
|
||||||
|
is indistinguishable from a leg that did not run — which is how the
|
||||||
|
next tick re-does it.
|
||||||
|
11. **The loop may not re-schedule itself** (the scheduler refuses it
|
||||||
|
anyway — treat as an invariant, not a limitation).
|
||||||
|
12. **Drain means drain.** `drain: true` = finish in flight, take
|
||||||
|
nothing new, then stop.
|
||||||
|
|
||||||
|
## Emulator mode
|
||||||
|
|
||||||
|
Flag `emulator: true` in the state file **and** an already-booted
|
||||||
|
emulator (`adb devices` answers) opts in: `make android` (build), `make
|
||||||
|
android-install`, `make android-smoke` (crash check — the same pid
|
||||||
|
surviving is the only signal that means started), `make
|
||||||
|
android-screenshot` and `make android-eval` as evidence for `visual`.
|
||||||
|
The loop never boots or stops an emulator; that is the user's machine.
|
||||||
|
Device-only issues stay open under either setting. One-time setup the
|
||||||
|
user performs: `make android-setup` (~3.5 GB, creates the `yj-test`
|
||||||
|
AVD), then `make android-emulator` per session.
|
||||||
|
|
||||||
|
## ON / OFF / drain
|
||||||
|
|
||||||
|
- **Worktree:** `git worktree add ~/.paseo/worktrees/loop/jumpy-hound
|
||||||
|
origin/main` (from any clone; branch from origin/main in the loop
|
||||||
|
tree, never `git checkout main`). **Provision it once before the
|
||||||
|
first push:** `make build-frontend` and `make testdata` — the pre-push
|
||||||
|
`go-test` hook needs `frontend/dist` (the `//go:embed` in `main.go`)
|
||||||
|
and the fixture library, and refuses the push without them.
|
||||||
|
- **Session:** pi in that worktree, `/name loop`. Add the job via
|
||||||
|
`/schedule-prompt` (name `yj-loop`, cron
|
||||||
|
`0 0 10-18 * * 1-5`, prompt: "Read `.pi/skills/yj-loop/SKILL.md` and
|
||||||
|
run exactly one tick. Stop.") — session-bound by default.
|
||||||
|
- **OFF:** toggle the job, or close the session. **ON:** `pi --resume
|
||||||
|
loop` in the worktree, job enabled. Courses of the tick appear in
|
||||||
|
that session's transcript.
|
||||||
|
- **Tune in:** the same resume. Talk to it only between; a tick is
|
||||||
|
atomic.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
- `issue.sh: GITEA_TOKEN is not set` or a 401 — the token is the whole
|
||||||
|
identity (rails 5). Stop, do not fall back to anything.
|
||||||
|
- `gitea_ci`'s job log 404s — the REST endpoints above answer; this is
|
||||||
|
a Gitea build, not a fault.
|
||||||
|
- A spec fails that the tier doc says can fail from stale backend state
|
||||||
|
— restart the app tier before believing it (`yellowjacket-dev`).
|
||||||
|
- A tick that "did nothing" — reconcile again; the tracker usually says
|
||||||
|
which leg it really is.
|
||||||
|
- The job did not fire — the scheduler fires only while a session is
|
||||||
|
open in its directory (documented); "the loop is off" is the correct
|
||||||
|
reading, not a bug.
|
||||||
|
- `error: object file … is empty` / `unpack-objects failed` / `bad
|
||||||
|
object refs/heads/…` during a fetch or checkout — the shared object
|
||||||
|
store was corrupted (a killed fetch leaves 0-byte object files, and a
|
||||||
|
local ref can end up pointing at the dead sha1). **Halt and report**;
|
||||||
|
do not retry, the churn only deepens it. Human repair: delete the
|
||||||
|
0-byte objects, `git fetch origin --prune`, delete any ref that
|
||||||
|
still dangles (`git update-ref -d refs/heads/<b>`), re-checkout the
|
||||||
|
worktree at `origin/main`, then `git fsck --full`.
|
||||||
+1647
File diff suppressed because it is too large
Load Diff
@@ -13,7 +13,7 @@ reviews. Nothing was changed.
|
|||||||
|
|
||||||
Findings below are numbered `H-n` (hands-on) and cross-reference the
|
Findings below are numbered `H-n` (hands-on) and cross-reference the
|
||||||
static reports where they overlap. The reconciliation plan built from
|
static reports where they overlap. The reconciliation plan built from
|
||||||
all four files is `.planning/plans/pending/007-ui-reconciliation.md`.
|
all four files is `.planning/plans/completed/007-ui-reconciliation.md`.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,244 @@
|
|||||||
|
# 020 — The autonomous backlog loop
|
||||||
|
|
||||||
|
**Issue:** #236 (`Kind/Enhancement`, `Priority/Low`)
|
||||||
|
**Status:** active — phase 0, supervised pilot
|
||||||
|
**Relates:** #73 (the roadmap the loop follows), plan 005 (the harness the
|
||||||
|
loop drives). Cost and model-tier doctrine is the `pi-session-reference`
|
||||||
|
card handed to the session that designed this; the loop's copies of it
|
||||||
|
are deliberate one-paragraph summaries, not the authority.
|
||||||
|
|
||||||
|
A pi coding-agent configuration that, toggled on, works the Gitea tracker
|
||||||
|
one issue at a time — triage, claim, plan, implement, validate, critique,
|
||||||
|
PR, CI, merge, verify-close, diary — and then does it again. The tracker is
|
||||||
|
the state machine: whoever reads Gitea sees exactly where the loop is,
|
||||||
|
which is the property this document's rails exist to protect.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## The shape: a crank, not a resident brain
|
||||||
|
|
||||||
|
Half the design is that **nothing lives in a conversation**. Each tick is a
|
||||||
|
fresh, bounded unit of work; every transition writes evidence to Gitea
|
||||||
|
(label, comment, branch, PR) or to the loop's own state file; a tick that
|
||||||
|
dies mid-leg loses nothing, because the next tick resumes from what Gitea
|
||||||
|
says.
|
||||||
|
|
||||||
|
The other half is that **no leg trusts the one before it**. The worker
|
||||||
|
implements from the plan, not from the issue alone; the validator checks
|
||||||
|
the *claim*, not the green CI row; the merger merges only after reading the
|
||||||
|
protection contexts itself; the diary leg is what makes the next issue's
|
||||||
|
triage cheaper.
|
||||||
|
|
||||||
|
One issue in flight at a time. That is a pacing decision, not a
|
||||||
|
concurrency limit of the tooling — CI has a capacity-1 runner and the e2e
|
||||||
|
tier owns one headless port on this machine, so two writers would serialize
|
||||||
|
on infrastructure they cannot see and appear to be doing fine.
|
||||||
|
|
||||||
|
## The state machine
|
||||||
|
|
||||||
|
| Leg | Writes | Actor / model |
|
||||||
|
|---|---|---|
|
||||||
|
| reconcile | — | orchestrator + `inspect` (mimo-v2.5) |
|
||||||
|
| select | nothing on the tracker; decision logged in the tick transcript | `select` (glm-5.3) |
|
||||||
|
| claim | assignee + `Status/In Progress` + comment naming branch & approach | `scripts/issue.sh claim` |
|
||||||
|
| plan | plan as an issue comment | `plan` (glm-5.3) |
|
||||||
|
| implement | commits on the issue branch, in the loop worktree | `work` (qwen/deepseek-v4-pro-0813) |
|
||||||
|
| validate | verification evidence in the handoff | `validate` (glm-5.3), `visual` (glm-5.3-flash) for screenshots |
|
||||||
|
| critique | review findings; fix commits | `review` (glm-5.3) + `diffreview` (qwen) + fix round by `work` |
|
||||||
|
| ship | push, PR with body contract, CI read + fixes | orchestrator + `scribe` (mimo-v2.5) |
|
||||||
|
| merge | the merge; post-merge issue verification | orchestrator |
|
||||||
|
| diary | `.pi/journal.md`, `CLAUDE.md` if structural | `scribe` |
|
||||||
|
| housekeep | stale-branch/PR cleanup, state-file prune | orchestrator |
|
||||||
|
|
||||||
|
### Legs that are the orchestrator's alone
|
||||||
|
|
||||||
|
The orchestrator (the loop session) delegates every deliberative leg and
|
||||||
|
keeps three for itself because they are script-shaped and must not be
|
||||||
|
re-implemented by a model: claim (`issue.sh claim`, which refuses when
|
||||||
|
someone else holds the issue — the backstop), merge (API calls below), and
|
||||||
|
housekeep (branch deletion). If a tick does nothing else, it reconciles.
|
||||||
|
|
||||||
|
## Model routing
|
||||||
|
|
||||||
|
The routing authority is the card's four tiers, reproduced here as the
|
||||||
|
loop's assignment, not as an argument:
|
||||||
|
|
||||||
|
- **T0 `go/mimo-v2.5`** — mechanical gathering, commit/PR/journal prose,
|
||||||
|
any fan-out. Effectively free; wrong only where wrongness costs a
|
||||||
|
debugging session, so nothing above takes its word for a *fact*.
|
||||||
|
- **T1 `qwen/deepseek-v4-pro-0813`** — implement-from-a-written-plan,
|
||||||
|
understood-diff review, the orchestrator itself. The default session
|
||||||
|
model; half price 10:00–20:00 EDT, which the cron is shaped around.
|
||||||
|
- **T2 `glm/glm-5.3`** — repo-scale reasoning: selection, planning,
|
||||||
|
consequences review, validation judgement. Weekly credits with no
|
||||||
|
rollover: the loop draws them every week by construction, which is the
|
||||||
|
correct posture. **`glm-5.3-flash`** for anything multimodal
|
||||||
|
(screenshots, UI inspection).
|
||||||
|
- **T3 `go/kimi-k3`** — escalation only: two lower tiers already failed,
|
||||||
|
or the issue is a named gnarly one. A fresh session seeded with the
|
||||||
|
failing tier's own summary, never a mid-session switch, never parallel,
|
||||||
|
at most once per day.
|
||||||
|
|
||||||
|
The invariant behind all four, from the card: **routing down is cheap,
|
||||||
|
routing up is expensive.** An implementation that stalls is escalated by
|
||||||
|
having the T1 session write *what it tried, what failed, what it observed*
|
||||||
|
and handing that to a new session one tier up. Escalating a session in
|
||||||
|
place is forbidden in both directions.
|
||||||
|
|
||||||
|
Fan-out is allowed on T0 and T1 only (the Go plan's $12/5 h constraint
|
||||||
|
makes T3 fan-out self-defeating). Critique is the one standing fan-out:
|
||||||
|
two reviewers, two angles, one synthesis.
|
||||||
|
|
||||||
|
## Scheduling
|
||||||
|
|
||||||
|
`0 0 10-18 * * 1-5` (local = EDT): hourly on weekdays inside Qwen's
|
||||||
|
half-price window, clear of the card's ⚠ 2–6am band (DeepSeek peaks, GLM
|
||||||
|
loses its off-peak discount — the window the old `yj-backlog` cron sat in,
|
||||||
|
which this replaces as the loop supersedes it).
|
||||||
|
|
||||||
|
- A tick takes a lock (`/tmp/yj-loop.lock`, PID + timestamp). An overrun
|
||||||
|
tick makes the next fire exit immediately; serialization survives
|
||||||
|
whatever the scheduler does with overlapping fires.
|
||||||
|
- ~9 ticks/day; an issue is 2–5 ticks; **one to two issues per day** is
|
||||||
|
the natural rate. That also paces the bills without a budget flag.
|
||||||
|
- The port check is part of reconcile: if `34115` is occupied, the tick
|
||||||
|
refuses any leg that needs the headless app and defers to the next
|
||||||
|
tick, without complaint. A human's interactive tier always wins.
|
||||||
|
|
||||||
|
## Runtime and ON/OFF
|
||||||
|
|
||||||
|
The scheduler (`pi-schedule-prompt`) fires only while a pi session is open
|
||||||
|
in the job's directory — that limitation is the switch:
|
||||||
|
|
||||||
|
- **Worktree:** `git worktree add` a dedicated clone at
|
||||||
|
`~/.paseo/worktrees/loop/jumpy-hound`. Loop edits happen only there; a
|
||||||
|
dirty tree there is the loop's business and nobody else's. **Provision
|
||||||
|
it once before its first push:** `make build-frontend` + `make testdata`
|
||||||
|
— the pre-push `go-test` hook needs both and refuses without them.
|
||||||
|
- **Session:** pi in that worktree, `/name loop`. The job is bound to that
|
||||||
|
session, so another pi elsewhere in the same directory does not
|
||||||
|
double-fire it.
|
||||||
|
- **ON:** resume the loop session (`pi --resume loop`) and enable the job.
|
||||||
|
**OFF:** toggle the job off in `/schedule-prompt`, or close the session.
|
||||||
|
**Drain** (stop taking new work, finish in flight): set `drain: true` in
|
||||||
|
the state file.
|
||||||
|
- **Tune in:** the same `pi --resume loop` — the chat transcript *is* the
|
||||||
|
loop's log, each tick's reasoning inline, each leg reporting in.
|
||||||
|
|
||||||
|
## Identity, claims, and what the loop may touch
|
||||||
|
|
||||||
|
The loop operates **as the owner** via `GITEA_TOKEN` (scopes: `read:user`,
|
||||||
|
`write:issue`, `write:pull`, `write:repository`); pushes ride SSH and need
|
||||||
|
no token. Every tracker comment the loop writes is prefixed `⟦loop⟧`, so
|
||||||
|
the collaborator reads it as the pump and not as a person.
|
||||||
|
|
||||||
|
It may only ever touch work it created: issues it claimed, branches it
|
||||||
|
made, PRs it opened. Two mechanisms make that enforced rather than
|
||||||
|
intentional: `issue.sh claim` refuses an issue somebody else holds, and
|
||||||
|
reconcile checks `git ls-remote --heads origin` so a branch name collision
|
||||||
|
from a concurrent session is caught before the first edit.
|
||||||
|
|
||||||
|
## Merge lifecycle
|
||||||
|
|
||||||
|
- **Only PRs the loop opened.** A collaborator's PR is never merged, never
|
||||||
|
commented on for pressure, never touched.
|
||||||
|
- **Every branch is refreshed against main before its merge**, in the
|
||||||
|
loop worktree — the refresh is where a textual conflict surfaces, as
|
||||||
|
diff text: hunks the loop authored are resolved there, anything else
|
||||||
|
is left to a human with a `⟦loop⟧` comment. The protection's
|
||||||
|
`block_on_outdated_branch` makes the refresh mandatory for adopted
|
||||||
|
(pre-loop) branches: behind `main`, a PR cannot merge at all.
|
||||||
|
Required contexts are re-polled on the refreshed head.
|
||||||
|
- **Merges are one at a time**, each re-reading state — the previous
|
||||||
|
merge moved `main`, and the next PR's mergeability is recomputed at
|
||||||
|
its own turn.
|
||||||
|
- **Post-merge, the `push` run on `main` is watched.** A red main after
|
||||||
|
a loop merge halts the loop. That run is the only guard against the
|
||||||
|
class no mergeability check sees: two PRs touching the same file,
|
||||||
|
merging cleanly, contradicting each other.
|
||||||
|
- The gate is the protection rule itself, read from the API: contexts
|
||||||
|
`CI / check*` and `CI / e2e*` green, PR mergeable. (Required approvals
|
||||||
|
is 0 today; if a second person changes protection rules, the merge
|
||||||
|
endpoint refuses and the tick stops and reports — human business.)
|
||||||
|
- `Closes #n` goes **in a commit body inside the branch, one line per
|
||||||
|
issue, and in the PR body**. Both, because a squash route and a merge
|
||||||
|
route parse different texts, and this pairing was measured: a comma
|
||||||
|
list partially matched, five of ten issues.
|
||||||
|
- After merging: verify against `issue.sh list --state open` that the
|
||||||
|
issue actually closed; close any straggler naming the merge commit.
|
||||||
|
`unclaim.yml` strips `Status/In Progress` automatically; it is not
|
||||||
|
instant, and a re-open does not restore it — the verification is
|
||||||
|
against the open list, not against the label.
|
||||||
|
- Merging to `main` fans out to nothing: releases are the manual
|
||||||
|
`release.yml`, which this loop never runs. The blast radius of a
|
||||||
|
merge is the main branch's CI, and the critique leg is what stands
|
||||||
|
before it.
|
||||||
|
|
||||||
|
## Verification contract
|
||||||
|
|
||||||
|
The tier table is `yellowjacket-dev`'s; the loop re-states nothing above
|
||||||
|
it except the *division of duty*: the worker runs the tiers the change
|
||||||
|
demands, and the validator re-reads the issue and checks that the tier
|
||||||
|
evidence actually answers the claim — a green suite that never touched
|
||||||
|
the reported surface is a finding, not a pass. Cosmetics are read by a
|
||||||
|
model that can see (`visual`, the multimodal tier); a change that moves
|
||||||
|
geometry refreshes its `ui-visual` baseline in the same commit.
|
||||||
|
`tsc --noEmit` is part of the gate and nothing else runs it. The e2e app
|
||||||
|
is seeded (`SEED=default`) and stopped after.
|
||||||
|
|
||||||
|
## Android / emulator mode
|
||||||
|
|
||||||
|
The loop is **device-free by default**: issues whose verification is
|
||||||
|
physical-device behaviour stay open for humans (the repo's own tags say
|
||||||
|
which those are). One step of the ladder exists for the rest:
|
||||||
|
|
||||||
|
- `{"emulator": true}` in `.pi/loop/state.json` **plus an already-booted
|
||||||
|
emulator** (`adb devices` answers) opts the loop into building the APK
|
||||||
|
and using `android-smoke` (crash verification), and `android-screenshot`
|
||||||
|
/ `android-eval` as rendering evidence for `visual`.
|
||||||
|
- The loop **never boots or stops an emulator** — that is the user's
|
||||||
|
machine and their gesture. Boot it with `make android-emulator`
|
||||||
|
(one-time `make android-setup`, ~3.5 GB, creates the AVD), and
|
||||||
|
`make android-emulator-stop` when done.
|
||||||
|
- Real-device-only issues are skipped under either setting.
|
||||||
|
|
||||||
|
## Budgets and pacing
|
||||||
|
|
||||||
|
Expected spend: dominated by the T1 implementation leg inside the
|
||||||
|
half-price window (pennies to tens of cents) and T2 on weekly credits;
|
||||||
|
T3 bounded at one fresh call per day. The card's numbers ($12 per rolling
|
||||||
|
5 h, $30/week as burst headroom not allowance, GLM reset weekly) are the
|
||||||
|
sanity cells; the loop's own weekly check compares against them rather
|
||||||
|
than against the month.
|
||||||
|
|
||||||
|
## Cleanup (housekeep leg, once per day)
|
||||||
|
|
||||||
|
- Loop-owned branches whose commits are in `origin/main`: deleted, local
|
||||||
|
and remote.
|
||||||
|
- Loop-owned PRs open >7 days or red on a second identical CI cause:
|
||||||
|
commented with what is known (`⟦loop⟧`), and left — never silently
|
||||||
|
deleted.
|
||||||
|
- Anything not the loop's (assignee, branch, PR): left exactly as found.
|
||||||
|
|
||||||
|
## Pilot phases
|
||||||
|
|
||||||
|
- **P0 — supervised.** One tick, user watching the transcript: reconcile,
|
||||||
|
select, claim, plan. No merge.
|
||||||
|
- **P1 — observed.** Two ticks ending in the loop's first merge, watched
|
||||||
|
through CI → merge → verify-close.
|
||||||
|
- **P2 — unattended.** The schedule left on. Weekly check against the
|
||||||
|
card's two-minute ritual.
|
||||||
|
- **Hard stops** (any of these halts the loop and leaves a comment, never
|
||||||
|
a silent retry): a tick dies twice with no explanation; a merge happens
|
||||||
|
for a PR the loop did not open; spend outside the cells above by 2×.
|
||||||
|
|
||||||
|
## Not now, on purpose
|
||||||
|
|
||||||
|
- **Parallel worktrees** — blocked on e2e's exclusive port; viable only
|
||||||
|
with per-worktree headless ports or CI-only e2e. The shape (
|
||||||
|
supervisor + per-issue worktrees) is the target, not the first cut.
|
||||||
|
- **Weekend batch refactors** — DeepSeek off-peak is real but is a
|
||||||
|
scheduling knob on top of a working pump.
|
||||||
|
- **More chain files** — the critique fan-out is a chain; the rest stay
|
||||||
|
orchestrator-legs until two weeks of unattended runs say which legs
|
||||||
|
are actually fixed-shape.
|
||||||
@@ -0,0 +1,263 @@
|
|||||||
|
# 021 — Listening accounting: smart plays, skips, and a real history
|
||||||
|
|
||||||
|
**Issue:** none yet — open one before the first edit (tracker is the
|
||||||
|
source of truth; `./scripts/issue.sh search "skip play count"` comes
|
||||||
|
back empty as of this writing).
|
||||||
|
|
||||||
|
**Status:** plan — not started.
|
||||||
|
|
||||||
|
**Relates:** play-count rendering (`frontend/src/components/track-list/columns.ts`),
|
||||||
|
smart playlists (`backend/smartplaylist/`), the event contract
|
||||||
|
(`TrackPlayCountChanged`), and any future Wrapped / "minutes listened"
|
||||||
|
surface.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## What exists now
|
||||||
|
|
||||||
|
Three facts, all load-bearing.
|
||||||
|
|
||||||
|
**A "play" is recorded only on a natural finish.** `recordPlay`
|
||||||
|
(`backend/queue/playhistory.go:9`) is called from exactly one place —
|
||||||
|
`OnPlaybackFinished` (`backend/queue/handlers.go:14`), and only when
|
||||||
|
`srcErr == nil`. A track the user skips past at 90% is *not* a play;
|
||||||
|
neither is one they pause at 60% and abandon. `play_count` /
|
||||||
|
`last_played` on `audio_files` reflect "finished to the end," nothing
|
||||||
|
more.
|
||||||
|
|
||||||
|
**There is no skip concept at all.** Skipping is indistinguishable
|
||||||
|
from a natural finish, a pause, or a shutdown. Nothing records "the
|
||||||
|
user rejected this track," so no downstream feature (smart playlists,
|
||||||
|
shuffle, the revisit shelf, a future skip-rate heuristic) can ask
|
||||||
|
about it.
|
||||||
|
|
||||||
|
**`play_history` is a write-only log.** It holds
|
||||||
|
`(audio_file_id, played_at)` and nothing reads it — no sqlc query
|
||||||
|
touches it, no `PlayHistory` read path exists. Its only recorded
|
||||||
|
purpose is the timestamps a future "minutes listened over time"
|
||||||
|
feature would need. It is classified `Authored, Cascade` in
|
||||||
|
`backend/datamap/datamap.go:272` ("Listening history").
|
||||||
|
|
||||||
|
So the gaps are: (1) skips are invisible, and (2) "played" is
|
||||||
|
under-counted — the opposite of the usual over-counting fear. The
|
||||||
|
scrobble intuition (count a play once `min(50%, 4:00)` has been
|
||||||
|
*heard*, independent of how it ends) is the fix for both.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## What we're building
|
||||||
|
|
||||||
|
A single classification of every track *exit*, plus one row per exit in
|
||||||
|
a listening log, plus the existing denormalized `play_count` /
|
||||||
|
`last_played` updated to match the new meaning. Three exit kinds:
|
||||||
|
|
||||||
|
| kind | condition |
|
||||||
|
|---|---|
|
||||||
|
| `complete` | reached natural end, **or** abandoned with `remaining <= tail` |
|
||||||
|
| `play` | heard `>= playThreshold`, abandoned before the tail |
|
||||||
|
| `skip` | user moved to a *different* track before `playThreshold` |
|
||||||
|
|
||||||
|
Not counted, not any kind: decode failure, pause/stop/shutdown before
|
||||||
|
the threshold, and tracks shorter than `minTrackLength`.
|
||||||
|
|
||||||
|
### The thresholds — named judgements, one file
|
||||||
|
|
||||||
|
Follow the `PreviousRestartThreshold` precedent (`backend/queue/queue.go:28`,
|
||||||
|
a bare `const` with a comment). A new `backend/queue/listen.go` (or a
|
||||||
|
tiny `backend/listencount` package) declares:
|
||||||
|
|
||||||
|
```go
|
||||||
|
const (
|
||||||
|
// A track this short is deliberated jingle / interstitial and is
|
||||||
|
// never counted, either way.
|
||||||
|
minTrackLength = 30 * time.Second
|
||||||
|
// The scrobble rule: half the track, or four minutes, whichever
|
||||||
|
// comes first (Last.fm / ListenBrainz).
|
||||||
|
playThresholdMax = 4 * time.Minute
|
||||||
|
// "Finished enough": within 15s of the end, or the last 10%,
|
||||||
|
// whichever is larger. A 10:00 ambient track gets a 60s fade
|
||||||
|
// window; a 2:00 pop song gets 15s.
|
||||||
|
tailWindowFloor = 15 * time.Second
|
||||||
|
tailWindowFraction = 0.10
|
||||||
|
)
|
||||||
|
|
||||||
|
func playThreshold(d time.Duration) time.Duration {
|
||||||
|
return min(d/2, playThresholdMax)
|
||||||
|
}
|
||||||
|
func tailWindow(d time.Duration) time.Duration {
|
||||||
|
return max(d/10, tailWindowFloor)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Classification is a pure function of `(reason, position, duration)` and
|
||||||
|
*therefore unit-testable without a player*:
|
||||||
|
|
||||||
|
```go
|
||||||
|
func classify(reason ExitReason, pos, dur time.Duration) Kind
|
||||||
|
```
|
||||||
|
|
||||||
|
`ExitReason` is `finished | skipped | failed | abandoned`. `skipped`
|
||||||
|
means the queue moved to a different track by user action (Next,
|
||||||
|
Previous past the restart threshold, PlayIndex, queue replacement,
|
||||||
|
select-from-a-list). `failed` is the decode-error path. `abandoned` is
|
||||||
|
pause/stop/unload/shutdown — and in v1 is a no-op (see open question 3).
|
||||||
|
|
||||||
|
**"Heard" is approximated by the position at exit.** We read
|
||||||
|
`player.CurrentPositionSeconds()` at the moment of the transition, not
|
||||||
|
an accumulated listen-time ledger. A user who seeks to 80% and listens
|
||||||
|
5 seconds reads as "heard 80%." That is deliberately accepted for v1:
|
||||||
|
it is how most players actually behave, it is drastically simpler, and
|
||||||
|
the failure mode ("counted a track you skimmed as played") is mild and
|
||||||
|
exactly what the scrobble threshold already forgives. Written down
|
||||||
|
because "position is not listen time" is the one assumption that will
|
||||||
|
look like a bug if it is not.
|
||||||
|
|
||||||
|
**Fires once per listen.** Leaving a track already leaves it; the
|
||||||
|
`chainID` guard in `player.onPlaybackFinished` (`backend/player/player.go:633`)
|
||||||
|
already swallows a stale finish callback, and a transition advances
|
||||||
|
`currentIndex` past the finished track. The classifier needs the same
|
||||||
|
guard so a Next-then-stale-finish cannot produce two rows. Key it on the
|
||||||
|
`(audioFileID, chainID)` the transition was about.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Schema — resolved: fresh design, no migration
|
||||||
|
|
||||||
|
The A/B migration agonizing is moot. This app has two users and both
|
||||||
|
are devs, and play counts are explicitly not worth preserving yet — so
|
||||||
|
the schema is written as if listening accounting had been designed in
|
||||||
|
from the start, and the existing two databases rebuild what they need
|
||||||
|
(see below). There is no migration step and none is re-introduced.
|
||||||
|
|
||||||
|
**`play_history` is renamed to `listening_events`** and grows the three
|
||||||
|
kinds, plus the raw position/duration the classification was made from:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
CREATE TABLE IF NOT EXISTS listening_events (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
audio_file_id INTEGER NOT NULL,
|
||||||
|
kind TEXT NOT NULL DEFAULT 'complete'
|
||||||
|
CHECK (kind IN ('complete','play','skip')),
|
||||||
|
position_seconds INTEGER NOT NULL DEFAULT 0,
|
||||||
|
duration_seconds INTEGER NOT NULL DEFAULT 0,
|
||||||
|
occurred_at DATETIME NOT NULL DEFAULT (datetime('now')),
|
||||||
|
FOREIGN KEY(audio_file_id) REFERENCES audio_files(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_listening_events_audio_file_id
|
||||||
|
ON listening_events(audio_file_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_listening_events_occurred_at
|
||||||
|
ON listening_events(occurred_at);
|
||||||
|
```
|
||||||
|
|
||||||
|
`position_seconds`/`duration_seconds` are kept raw so a future re-tune
|
||||||
|
of the threshold does not force the events to be re-recorded. `kind`
|
||||||
|
stays the write-time classification; the raw reading is evidence, not
|
||||||
|
a second copy of the rule.
|
||||||
|
|
||||||
|
**The counters are denormalized onto `audio_files`** — `skip_count` /
|
||||||
|
`last_skipped` join the existing `play_count` / `last_played`, because
|
||||||
|
that is where the hot read path already lives and a log join per track
|
||||||
|
row is not acceptable. This does grow the MIXED-KIND wart (see the
|
||||||
|
survey below for the structural answer), but it is the *continuation* of
|
||||||
|
the existing design, not a new leak: play counts sat on `audio_files`
|
||||||
|
from before this feature existed.
|
||||||
|
|
||||||
|
**What happens to the two real databases on next launch.**
|
||||||
|
`listening_events` is a new table, created verbatim. `audio_files`
|
||||||
|
gains two columns, which `retireStaleTables` treats as a stale Owned
|
||||||
|
table and rebuilds by rescan — dropping `play_count` / `last_played` /
|
||||||
|
`tag_status` with it, which is the accepted cost stated in the issue.
|
||||||
|
`play_history` is gone from the schema and the datamap, so
|
||||||
|
`obsoleteTables` drops it; its (natural-finish-only) timestamp rows go
|
||||||
|
with it. Nothing here is wrong on a fresh install, and on the two dev
|
||||||
|
machines the answer is the documented "delete and rescan."
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Wiring: where the classifier is called
|
||||||
|
|
||||||
|
The risk is not the classifier — it is that **every track-replacement
|
||||||
|
path must classify the outgoing track**, and there are many: `Next`,
|
||||||
|
`Previous` (past the 3s restart threshold), `PlayIndex`, `playFromStart`,
|
||||||
|
`SetQueue` / clear-and-play, remove-current, and select-from-a-list.
|
||||||
|
Miss one and that path silently never records a skip.
|
||||||
|
|
||||||
|
So the classification is centralized in one queue method —
|
||||||
|
|
||||||
|
```go
|
||||||
|
// leaveCurrent(reason) classifies the track at currentIndex as it is
|
||||||
|
// about to be replaced, and records exactly one listening event.
|
||||||
|
// Must be called without q.mu held (it writes to SQLite).
|
||||||
|
func (q *Queue) leaveCurrent(reason ExitReason)
|
||||||
|
```
|
||||||
|
|
||||||
|
— which reads position/duration from the player, calls `classify`, and
|
||||||
|
emits the play/skip row + `TrackPlayCountChanged` when `kind != skip`.
|
||||||
|
`OnPlaybackFinished(nil)` routes through `leaveCurrent(finished)`, the
|
||||||
|
navigation methods route through `leaveCurrent(skipped)` before they
|
||||||
|
advance, and `recordPlay` becomes the "did a play happen" half of it.
|
||||||
|
|
||||||
|
Because "one path forgot to call it" is the failure mode, a **source
|
||||||
|
sweep** pins it, on the pattern of `TestNoDirectRuntimeEmits`
|
||||||
|
(`backend/events/noemit_test.go`) and `TestCatalogCoversSchema`: a test
|
||||||
|
walks `backend/queue` for assignments to `currentIndex` (and the
|
||||||
|
`SetQueue` / remove paths) and fails if a mutation site does not sit
|
||||||
|
adjacent to a `leaveCurrent` call. The sweep is the enforcement; the
|
||||||
|
central method is the convenience.
|
||||||
|
|
||||||
|
`recordPlay` keeps its existing contract *when a play happens* —
|
||||||
|
`TrackPlayCountChanged` with `{audioFileId, filePath, playCount,
|
||||||
|
lastPlayed}` — so the frontend patch path and
|
||||||
|
`playhistory_test.go` keep passing. A skip emits no per-track event in
|
||||||
|
v1 (open question 4).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phases
|
||||||
|
|
||||||
|
1. **The classifier.** `listen.go`: the constants, `playThreshold`,
|
||||||
|
`tailWindow`, `classify`. Table-driven unit tests covering every
|
||||||
|
cell of the tristate, the <30s exemption, the tail window on both a
|
||||||
|
10:00 and a 2:00 track, and the clip at the 4:00 cap. No I/O.
|
||||||
|
2. **Schema.** *Done in this session.* `listening_events` replaces
|
||||||
|
`play_history`; `skip_count` / `last_skipped` added to
|
||||||
|
`audio_files`; datamap entry and `TestAuthoredCascadesAreDeliberate`
|
||||||
|
allow-list renamed; `recordPlay` writes `listening_events
|
||||||
|
('complete')`. `make generate` run; database / datamap / queue
|
||||||
|
tests green.
|
||||||
|
3. **Wiring.** `leaveCurrent`, the navigation/finish/error call sites,
|
||||||
|
the `fires once per listen` guard, and the source sweep. Extend
|
||||||
|
`playhistory_test.go` for skip/complete classification through the
|
||||||
|
queue rather than the pure function.
|
||||||
|
4. **Smart-playlist field.** `skip_count` (and optionally
|
||||||
|
`days_since_skipped`) in `smartplaylist.go` field/numeric maps and
|
||||||
|
the editor's field list, via subquery. A frontend event for skip —
|
||||||
|
if a UI wants a skip column — follows separately.
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
- **Go:** the classifier is pure and exhaustively unit-tested; the
|
||||||
|
queue wiring is tested in-process with `events.WithSink`
|
||||||
|
(`backend/queue/emit_test.go` is the model), asserting a Next at 90%
|
||||||
|
emits a *play*, a Next at 10% emits a *skip and no play*, a natural
|
||||||
|
finish emits a *complete*.
|
||||||
|
- **Database:** schema + datamap tests fail-loud on any new or
|
||||||
|
reclassified table; `database_test.go`'s listening-events round-trip
|
||||||
|
asserts the new table and the four denormalized counter columns.
|
||||||
|
- **e2e:** `e2e/specs/play-count.spec.ts` already awaits
|
||||||
|
`TrackPlayCountChanged`; add the skip case (advance early, assert no
|
||||||
|
`TrackPlayCountChanged` and a `skip` row via the `__/test/sql`
|
||||||
|
endpoint if convenient, or via the playlist effect).
|
||||||
|
- No visual/component tier needed unless a skip column ships (phase 4).
|
||||||
|
|
||||||
|
## Open questions / decisions needed
|
||||||
|
|
||||||
|
1. **Migration mechanism.** Resolved — fresh design, no migration (see the schema section). Play counts are not worth preserving, both users are devs, and `audio_files` / `play_history` rebuild-or-drop on next launch.
|
||||||
|
2. **"Position is not listen time."** Accept the approximation for v1,
|
||||||
|
or track accumulated listen seconds (a real ledger on the player) now?
|
||||||
|
3. **Abandon on shutdown.** A track paused at 70% and then app-killed:
|
||||||
|
count a `play` (scrobble says heard) or leave it unrecorded? v1
|
||||||
|
proposes *unrecorded* — same as today — to keep the write path off
|
||||||
|
the shutdown critical path.
|
||||||
|
4. **Skip event to the frontend.** Emit now (parallel to
|
||||||
|
`TrackPlayCountChanged`) or only when a surface consumes it?
|
||||||
+2
@@ -1,5 +1,7 @@
|
|||||||
# 012 — What we ask the network for, and what we already had
|
# 012 — What we ask the network for, and what we already had
|
||||||
|
|
||||||
|
> **Completed.** Findings 1, 2 and 4 shipped. Finding 3 — the bound-but-uncalled methods — is now **#86**.
|
||||||
|
|
||||||
**Status:** all four findings fixed. Lint (3 configs), Go tests (3
|
**Status:** all four findings fixed. Lint (3 configs), Go tests (3
|
||||||
configs), `tsc` and 752 Vitest tests pass; **not driven against the
|
configs), `tsc` and 752 Vitest tests pass; **not driven against the
|
||||||
real app**, so the numbers below are read off the code, not measured.
|
real app**, so the numbers below are read off the code, not measured.
|
||||||
+2
@@ -1,5 +1,7 @@
|
|||||||
# 015 — Android release pipeline
|
# 015 — Android release pipeline
|
||||||
|
|
||||||
|
> **Completed.** The pipeline ships a signed APK from CI on every `v*` tag; `docs/android-release.md` is its operating document.
|
||||||
|
|
||||||
Ship an Android APK from CI on every version tag, published to the Gitea
|
Ship an Android APK from CI on every version tag, published to the Gitea
|
||||||
generic package registry so Obtainium can poll a plain URL.
|
generic package registry so Obtainium can poll a plain URL.
|
||||||
|
|
||||||
+2
@@ -1,5 +1,7 @@
|
|||||||
# 015 — Multi-artist credits, navigable
|
# 015 — Multi-artist credits, navigable
|
||||||
|
|
||||||
|
> **Completed.** Phases 1, 2 and 4 shipped. Running the ingest against the real dump and publishing an artifact that carries credits is **#88**; Phase 3 (`file_artists`) is **#89**, blocked on it.
|
||||||
|
|
||||||
## The problem
|
## The problem
|
||||||
|
|
||||||
A track credited to more than one artist has exactly one navigable
|
A track credited to more than one artist has exactly one navigable
|
||||||
+2
@@ -1,5 +1,7 @@
|
|||||||
# 016 — What Android parity would actually take
|
# 016 — What Android parity would actually take
|
||||||
|
|
||||||
|
> **Completed.** Sections A, B1, B2 and B4 shipped. B3, writing tags on the device, is now **#87**; the device-found UI faults are #51–#72, sequenced by #73.
|
||||||
|
|
||||||
> **Status: all of section A is done.** A1–A3 landed with "let the app
|
> **Status: all of section A is done.** A1–A3 landed with "let the app
|
||||||
> reach the user's music"; A4 (MediaSession, transport notification,
|
> reach the user's music"; A4 (MediaSession, transport notification,
|
||||||
> audio focus) landed with "survive the screen locking". The direction
|
> audio focus) landed with "survive the screen locking". The direction
|
||||||
@@ -0,0 +1,327 @@
|
|||||||
|
# 018 — Supported sizes, and what the queue panel is
|
||||||
|
|
||||||
|
**Issue:** #24 (`Area/Shell-Nav`, `Priority/High`, `Reviewed/Confirmed`)
|
||||||
|
**Unblocks:** #55 (queue as a screen) — a real Gitea dependency
|
||||||
|
**Relates:** #69 (page-header overflow), #12 (mini-player), #51 (small-screen umbrella)
|
||||||
|
**Status:** complete — #24 shipped as PR #132, and the matrix's last
|
||||||
|
unkept promise closed with #69.
|
||||||
|
|
||||||
|
#73 puts this first in Phase 2 and hangs the rest of the phase off it,
|
||||||
|
so the decision has to be written down and arguable before any CSS
|
||||||
|
moves. This document is the decision. Everything below the matrix is
|
||||||
|
either a measurement or an argument for one of the four choices #24
|
||||||
|
asks for.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## What is actually wrong, measured
|
||||||
|
|
||||||
|
Against the running app (`make dev-headless SEED=default`, Chromium),
|
||||||
|
Playlists, sweeping the viewport with the queue open and closed. The
|
||||||
|
number that matters is how much of the page header survives.
|
||||||
|
|
||||||
|
| viewport | sidebar | queue | main panel | header needs | actions clipped |
|
||||||
|
|---|---|---|---|---|---|
|
||||||
|
| 1280×800 | 200 | open 321 | 759 | 759 | — |
|
||||||
|
| 1000×700 | 200 | open 321 | 479 | 747 | New Playlist, New Smart Playlist |
|
||||||
|
| **900×600** | 200 | open 321 | **379** | 747 | **all three** |
|
||||||
|
| 800×600 | 56 | open 321 | 423 | 747 | all three |
|
||||||
|
| 700×600 | 56 | open 321 | 323 | 747 | all three |
|
||||||
|
| 390×780 | — | open 321 | **69** | 747 | all three |
|
||||||
|
| 320×600 | — | open 321 | **0** | 747 | all three |
|
||||||
|
| 900×600 | 200 | closed | 700 | 747 | New Smart Playlist |
|
||||||
|
| **800×600** | 56 | closed | 744 | 747 | **New Smart Playlist (158/162px)** |
|
||||||
|
| 320×600 | — | closed | 320 | 747 | all three |
|
||||||
|
|
||||||
|
Five things in that table are not in the issue.
|
||||||
|
|
||||||
|
**The header clips at the supported minimum with the queue closed.**
|
||||||
|
At 800×600 — the size `backend/config/window.go` enforces and the only
|
||||||
|
size this app *promises* — "New Smart Playlist" loses 4px of its 162.
|
||||||
|
#24 reads as a queue-panel bug; the queue makes it dramatic, but the
|
||||||
|
header overflows on its own at the minimum window.
|
||||||
|
|
||||||
|
**900×600 is worse than 800×600, because the sidebar expands at 900.**
|
||||||
|
`AUTO_COLLAPSE_VIEWPORT` collapses the sidebar to icons *below* 900, so
|
||||||
|
at 899px the main panel is 843px and at 900px it is 700px. The worst
|
||||||
|
desktop case is therefore not the minimum window; it is the pixel
|
||||||
|
immediately above the collapse. Anything that tests "the minimum" and
|
||||||
|
stops has not tested the worst case, which is what
|
||||||
|
`layout-overflow.spec.ts` does today.
|
||||||
|
|
||||||
|
**At phone widths the queue is not a drawer, it is an amputation.**
|
||||||
|
`queue-panel`'s host is `flex-shrink: 0; width: 0`, going to
|
||||||
|
`width: var(--queue-width, 320px)` under `[open]` — it is *in the flow*
|
||||||
|
of `.content-area`, so it takes its width from the main panel rather
|
||||||
|
than covering it. At 390px that leaves 69px of the page; at 320px it
|
||||||
|
leaves **0px**, and the app is not degraded but gone. This is the
|
||||||
|
measurement #55 needs and did not have.
|
||||||
|
|
||||||
|
**Only Playlists overflows.** Sweeping all ten primary views at 900×600
|
||||||
|
and at 390×780, every other header reports `scrollWidth ==
|
||||||
|
clientWidth`, and Albums at 390px renders title, count and sort
|
||||||
|
legibly (checked on a screenshot, not just the number). #69 is
|
||||||
|
therefore one view's action set — three text buttons totalling 390px —
|
||||||
|
and not a systemic header failure, though the *rule* still belongs in
|
||||||
|
`page-header`.
|
||||||
|
|
||||||
|
**Both reasons in `MinWidth`'s comment are stale.** It says the floor is
|
||||||
|
800×600 because "below ~780 the header's subtitle wraps" and "below
|
||||||
|
~600 tall the eleven sidebar items no longer fit". The subtitle is
|
||||||
|
`display: none` below 900 (index.css), and the sidebar host is
|
||||||
|
`overflow-y: auto` — at 600×460 its `scrollHeight` is 434 against a
|
||||||
|
332px client, and Settings is reachable after scrolling. Neither
|
||||||
|
mechanism can happen any more. That does not mean the floor should
|
||||||
|
move; it means its stated reason no longer supports it, which is worse
|
||||||
|
than either answer.
|
||||||
|
|
||||||
|
*(Care needed: my first probe for the sidebar scroller searched
|
||||||
|
`shadowRoot.querySelectorAll('*')` and reported "items are
|
||||||
|
unreachable", because the scroller is the **host** and a host is not in
|
||||||
|
its own shadow root. The claim in CLAUDE.md is correct.)*
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Decision 1 — the supported size matrix
|
||||||
|
|
||||||
|
Three bands. Two of them already exist and are already argued; what is
|
||||||
|
new is that they are written down as a *promise*, and that the queue is
|
||||||
|
part of it.
|
||||||
|
|
||||||
|
| band | width | navigation | queue | promise |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| **Phone** | < 600 | `bottom-nav` + drawer | overlay, full width | reflows; nothing needs sideways scrolling; fits 320px |
|
||||||
|
| **Compact** | 600 – 899 | icon sidebar | overlay + scrim | nothing is clipped or unreachable at any width in the band |
|
||||||
|
| **Desktop** | ≥ 900 | labelled sidebar | inline where it fits (see decision 2), else overlay | as Compact |
|
||||||
|
|
||||||
|
And one promise across all three: **no action is ever unreachable.**
|
||||||
|
That is the sentence #69 asks for and it is the one the matrix exists
|
||||||
|
to make checkable.
|
||||||
|
|
||||||
|
**400% zoom** keeps the meaning it already has: WCAG 1.4.10 names 320px
|
||||||
|
as the reflow target, the phone band covers it, and
|
||||||
|
`layout-overflow.spec.ts` already asserts a 320px viewport needs no
|
||||||
|
sideways scrolling. What changes is that the *queue* must be part of
|
||||||
|
that assertion — it is not today, and with the queue open at 320px the
|
||||||
|
main panel is 0px wide, which no current test can see.
|
||||||
|
|
||||||
|
**The window minimum stays 800×600**, and its comment gets the real
|
||||||
|
reason. The old mechanisms are gone, but the floor is still where the
|
||||||
|
Compact band's chrome stops being comfortable, and lowering it would
|
||||||
|
mean promising the desktop layout at sizes where only the phone layout
|
||||||
|
works. The interesting consequence is decision 4.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Decision 2 — the queue is an overlay when it cannot afford to be a column
|
||||||
|
|
||||||
|
**The rule.** The queue panel renders inline — in the flow, as today —
|
||||||
|
only while
|
||||||
|
|
||||||
|
```
|
||||||
|
viewport − sidebar − queueWidth ≥ 480
|
||||||
|
```
|
||||||
|
|
||||||
|
and as an overlay with a scrim otherwise.
|
||||||
|
|
||||||
|
**Why it cannot be a media query**, which is the load-bearing half:
|
||||||
|
the queue's width is *user state*. It is drag-resizable between 200 and
|
||||||
|
500px and persisted (`--queue-width`, `MIN_WIDTH`/`MAX_WIDTH` in
|
||||||
|
`queue-panel.ts`). A breakpoint at a fixed viewport width silently
|
||||||
|
assumes the default 320, and is wrong by 180px for a user who has
|
||||||
|
dragged the panel wide — in the direction that hurts, since a wider
|
||||||
|
queue is exactly when the content can least afford it. So the mode is
|
||||||
|
computed from the measured widths and published as an attribute, the
|
||||||
|
way `data-active-view` already is, and the CSS keys off that.
|
||||||
|
|
||||||
|
**Why 480, honestly.** There is no cliff to derive it from. The track
|
||||||
|
list rescales its columns continuously — at main widths from 900 down
|
||||||
|
to 544 its `--grid-cols` shrink from 213px to 124px with
|
||||||
|
`rowOverflow=0` throughout — and the album grid steps 3 columns to 2
|
||||||
|
somewhere between 564 and 644 without breaking. So this is a judgement,
|
||||||
|
anchored on two things: it keeps the *default* window (1100 wide, main
|
||||||
|
= 580) inline, because the inline queue is a desktop affordance people
|
||||||
|
choose and turning it into an overlay for the common case would be a
|
||||||
|
regression in feel; and it puts every case measured as broken —
|
||||||
|
900×600 at main=379, and every phone width — on the overlay side.
|
||||||
|
1024×768 lands at main=504 and stays inline.
|
||||||
|
|
||||||
|
**The scrim is the other half of the issue's complaint** ("make the
|
||||||
|
queue obviously an overlay *over* the content so it reads as something
|
||||||
|
to close"). An overlay queue gets a scrim, closes on scrim click and on
|
||||||
|
Escape, and returns focus to `#queue-button`.
|
||||||
|
|
||||||
|
**What must not change**: #55's Direction is explicit — one component,
|
||||||
|
two mount points, do not fork it. The overlay is a *presentation* of
|
||||||
|
the same `queue-panel`, so the roving tab stop, Alt+Arrow reorder, drag
|
||||||
|
reorder, selection semantics and the `virtualizer.requestUpdate()` on
|
||||||
|
selection and current-track change all come along untouched. This
|
||||||
|
decision deliberately stops short of #55's detail-view mount, but it is
|
||||||
|
the shape that makes it possible, and it unblocks it.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Decision 3 — #69 is its own PR, and here is the finding that decides it
|
||||||
|
|
||||||
|
`page-header` **cannot collapse its own actions**, and that is not an
|
||||||
|
effort estimate but a fact about the API. Actions arrive through
|
||||||
|
`<slot name="actions">` as arbitrary light-DOM markup — Playlists slots
|
||||||
|
a `<div class="header-actions">` of three `<button>`s with click
|
||||||
|
handlers, drag handlers and a conditional class. A component cannot
|
||||||
|
move another component's light-DOM children into a dropdown and keep
|
||||||
|
their behaviour; there is nothing generic to render as a menu item.
|
||||||
|
|
||||||
|
So the overflow rule needs an *actions API* — hosts declaring
|
||||||
|
`{icon, label, handler, priority}` data that `page-header` can render
|
||||||
|
either as buttons or as menu items — which is a change to all three
|
||||||
|
hosts that slot actions, not a rule added in one place. That is a
|
||||||
|
different piece of work from this one, it is independently verifiable,
|
||||||
|
and the desktop half of #69's symptom is removed by decision 2 anyway
|
||||||
|
(the queue stops eating the header's width).
|
||||||
|
|
||||||
|
It therefore stays #69, gets the finding above recorded on it, and
|
||||||
|
follows immediately after this. What *this* plan owes it is the
|
||||||
|
promise in the matrix — no action unreachable at any supported size —
|
||||||
|
and the measurement that the only offender today is Playlists.
|
||||||
|
|
||||||
|
**And the promise is not kept yet, which is the honest version of a
|
||||||
|
claim this document made in its first draft.** "Decision 2 removes the
|
||||||
|
desktop half of #69's symptom" was too strong. Measured after phase 2,
|
||||||
|
at 900×600 on Playlists:
|
||||||
|
|
||||||
|
| | before | after |
|
||||||
|
|---|---|---|
|
||||||
|
| queue open | main 379px, **all three** actions clipped | main 700px, **one** clipped |
|
||||||
|
| queue closed | main 700px, one clipped | unchanged |
|
||||||
|
|
||||||
|
So the queue's *contribution* is gone — open and closed are now
|
||||||
|
identical, which is the whole of what this decision owed — and the
|
||||||
|
residual "New Smart Playlist: 114/162px" is the header overflowing on
|
||||||
|
its own, at a size the queue never touched. #69 is still a live defect
|
||||||
|
at a supported size, and the matrix's promise is what will close it.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Decision 4 — a very small window becomes the phone layout, not the mini-player
|
||||||
|
|
||||||
|
#24 asks whether a very small window should switch to the mini-player
|
||||||
|
(#12) "or simply refuse to go there". Both options in the question are
|
||||||
|
worse than the one the codebase already has.
|
||||||
|
|
||||||
|
**#12 is a second window, not a mode.** Its findings say so: v3
|
||||||
|
supports multiple windows, `AlwaysOnTop` is a window *option*, and the
|
||||||
|
frontend would need an entry branch mounting only the mini-player root
|
||||||
|
for a second window loading the same bundle. Turning the main window
|
||||||
|
into a mini-player at some width conflates the two: it would throw away
|
||||||
|
the user's navigation state on a resize, and it puts the MPRIS question
|
||||||
|
(#12's own open question — media controls are process-level and must
|
||||||
|
not be per-window) on a code path that a drag can trigger by accident.
|
||||||
|
|
||||||
|
**And "refuses" is unnecessary, because the reflow already exists.**
|
||||||
|
The phone band is real, tested, and reached by width alone — a desktop
|
||||||
|
window narrowed below 600px already gets `bottom-nav` and the phone
|
||||||
|
shell. That is a better answer than refusing: it is strictly more
|
||||||
|
usable than a hard minimum, it costs nothing new, and it is the same
|
||||||
|
code Android runs, so it stays exercised.
|
||||||
|
|
||||||
|
So: the main window reflows and never becomes a mini-player; #12 stays
|
||||||
|
a separate always-on-top window and is not blocked by, or coupled to,
|
||||||
|
this decision. The window minimum stays 800×600 for the reason in
|
||||||
|
decision 1 — but the phone band is what happens below it, not a
|
||||||
|
refusal, which is why the minimum is a comfort floor rather than a
|
||||||
|
correctness one.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phases
|
||||||
|
|
||||||
|
1. **This document**, linked from #24, with the matrix reported on the
|
||||||
|
issue and #55 told whether it is unblocked. *(no code)* — **done**
|
||||||
|
2. **The queue's overlay mode** — computed mode attribute, scrim,
|
||||||
|
Escape and scrim-click close, focus return. The inline path is
|
||||||
|
unchanged above the threshold. — **done**
|
||||||
|
3. **The window minimum's comment** — replace both stale reasons with
|
||||||
|
the measured ones. No value change. — **done**
|
||||||
|
4. **Verification**, below. Including the specs that must change
|
||||||
|
because they assert the old behaviour. — **done**
|
||||||
|
|
||||||
|
#69 follows as its own branch; #55 became unblocked at phase 2.
|
||||||
|
|
||||||
|
## What landed, measured
|
||||||
|
|
||||||
|
Main panel width with the queue open, before and after:
|
||||||
|
|
||||||
|
| viewport | before | after | mode |
|
||||||
|
|---|---|---|---|
|
||||||
|
| 1280×800 | 759 | 759 | inline |
|
||||||
|
| 1100×720 (default window) | 579 | 579 | inline |
|
||||||
|
| 1024×768 | 503 | 503 | inline |
|
||||||
|
| 900×600 | **379** | **700** | overlay |
|
||||||
|
| 800×600 | 423 | 744 | overlay |
|
||||||
|
| 390×780 | **69** | **390** | overlay |
|
||||||
|
| 320×600 | **0** | **320** | overlay |
|
||||||
|
|
||||||
|
The scrim is perceptible but subtle on a dark ramp, which is worth
|
||||||
|
knowing before someone "fixes" it: sampled from the screenshots at
|
||||||
|
900×600, the main panel's background goes 33,37,41 → 18,20,23 and a
|
||||||
|
row's text 242 → 133. It covers the **content area only** — not the
|
||||||
|
sidebar or the transport — on purpose: the queue is not modal, and
|
||||||
|
leaving the navigation live means the scrim reads as "this is over the
|
||||||
|
content" (which is what #24 asked for) without pretending the rest of
|
||||||
|
the app is unavailable.
|
||||||
|
|
||||||
|
## What #69 did with the promise, and one thing this plan got wrong
|
||||||
|
|
||||||
|
#69 landed on its own branch as decision 3 said it would, and the
|
||||||
|
matrix's *no action is ever unreachable at any supported size* is now
|
||||||
|
kept rather than promised. Measured on Playlists, actions clipped:
|
||||||
|
|
||||||
|
| viewport | before #24 | after #24 | after #69 |
|
||||||
|
|---|---|---|---|
|
||||||
|
| 900×600, queue open | all three | one (114/162px) | none |
|
||||||
|
| 900×600, queue closed | one | one | none |
|
||||||
|
| 800×600, queue closed | one (158/162px) | one | none |
|
||||||
|
| 390×780 | all three | all three | none |
|
||||||
|
| 320×600 | all three | all three | none |
|
||||||
|
|
||||||
|
The shape was the one decision 3 predicted — an actions API first, an
|
||||||
|
overflow rule second — and all three hosts that slot actions migrated.
|
||||||
|
|
||||||
|
**What this document got wrong is smaller and worth keeping.** Decision
|
||||||
|
1 says the header's minimum is a *comfort* floor and that only the
|
||||||
|
queue and the actions compete for the header's width. They are not the
|
||||||
|
only two: every child of that flex row was `flex-shrink: 0`, so
|
||||||
|
whatever came last lost, and the actions come last. At 320px the sort
|
||||||
|
control alone is 172px of the header — so with every action already
|
||||||
|
collapsed into the menu, the *menu button* was 76px off the right edge.
|
||||||
|
The promise was still broken with nothing left to collapse.
|
||||||
|
|
||||||
|
That is why #69 also had to decide what gives way: the title (which the
|
||||||
|
navigation also states) and, below 600px, the word "Sort:" (which the
|
||||||
|
direction arrow implies). Neither is an action, which is the rule the
|
||||||
|
matrix actually encodes — **an action is a capability and everything
|
||||||
|
else on that row is a label.**
|
||||||
|
|
||||||
|
## Verification, and what each tier cannot see
|
||||||
|
|
||||||
|
- `make ui-test` — the queue panel's mode logic is component-tier
|
||||||
|
work and belongs there. It **cannot** see the shell: the threshold is
|
||||||
|
computed from the sidebar and viewport, which do not exist in that
|
||||||
|
tier.
|
||||||
|
- `make e2e` — `layout-overflow.spec.ts` gains the queue-open case at
|
||||||
|
every band (it has none today, which is why main=0px at 320px has
|
||||||
|
never failed anything) and **gains 900×600**, since the minimum is
|
||||||
|
not the worst case. `queue-toggle-state.spec.ts` and
|
||||||
|
`phone-shell.spec.ts` both touch the panel and must be re-read before
|
||||||
|
editing.
|
||||||
|
- **Screenshots at every band, read by a human.** This is not optional
|
||||||
|
here: `layout-overflow.spec.ts` asserts the *shell* needs no sideways
|
||||||
|
scrolling and passes on a build whose album header clips its own
|
||||||
|
buttons (measured this session at 390px; filed on #66). Clipping
|
||||||
|
*inside* a component is invisible to it, and clipping is this issue.
|
||||||
|
- `make ui-visual` **cannot help at all** — the component tier renders
|
||||||
|
the token fallbacks, because the theme only reaches `:root` in the
|
||||||
|
real app.
|
||||||
|
- Accessible names via `page.getByRole(...)`, never a shadow-root
|
||||||
|
query. A drawer with a scrim is exactly the shape that grows a
|
||||||
|
nameless control, and this repo has shipped one three times.
|
||||||
@@ -0,0 +1,408 @@
|
|||||||
|
# 019 — The Android touch model
|
||||||
|
|
||||||
|
**Issue:** #63 (`Area/Library-UI`, `Kind/Feature`, `Priority/High`)
|
||||||
|
**Depends on:** #60 (bottom-sheet menus) — closed, merged as PR #176
|
||||||
|
**Relates:** #67 (inline links into the menu), #71 ("More" nav), #54
|
||||||
|
(native feel), #5/#8 (selection, drag to queue — the desktop semantics
|
||||||
|
being diverged from)
|
||||||
|
**Status:** shipped (phases 1-4). Its one deliberate remainder is #200.
|
||||||
|
|
||||||
|
#73 puts #60 first in Phase 4 because it is "the presentation every
|
||||||
|
other item needs", and this is the next one. The Direction on #63 asks
|
||||||
|
for the interaction model to be designed as one piece before any of it
|
||||||
|
is built, because it *reassigns an existing gesture* rather than adding
|
||||||
|
one — `utils/long-press.ts` currently owns the 500ms hold, and every
|
||||||
|
context menu in the app is downstream of it.
|
||||||
|
|
||||||
|
This document is that design. Everything below is a measurement, or an
|
||||||
|
argument for one of the choices #63 leaves open.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## The mapping
|
||||||
|
|
||||||
|
| gesture | pointer is a finger | pointer is a mouse |
|
||||||
|
|---|---|---|
|
||||||
|
| single tap / click | **play the row** | select the row |
|
||||||
|
| double | — | play the row |
|
||||||
|
| long press (500ms) | **enter selection mode** | — |
|
||||||
|
| right-click | — | context menu |
|
||||||
|
| swipe right | **add to queue** | — |
|
||||||
|
| drag | reorder / drag to playlist | reorder / drag to playlist |
|
||||||
|
|
||||||
|
Three of those are #63's report unchanged. Two are decisions it left
|
||||||
|
open, and one is a deliberate divergence.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Decision 1 — the predicate is the pointer, not the platform
|
||||||
|
|
||||||
|
#63 says "the row component needs a platform-aware interaction layer
|
||||||
|
rather than shared handlers". It needs an interaction layer; it should
|
||||||
|
not be platform-aware.
|
||||||
|
|
||||||
|
**The question a row has to answer is not "am I on Android" or "is the
|
||||||
|
viewport under 600px" but "what made this event".** `pointerType ===
|
||||||
|
'touch'`, read off the event that is being handled, which is already
|
||||||
|
how `long-press.ts` decides (`if (e.pointerType !== 'touch') return`)
|
||||||
|
and is the only such test in the frontend today.
|
||||||
|
|
||||||
|
This is #64's rule — the predicate is named after the capability, not
|
||||||
|
the platform — and it carries #64's warning with it. Keyed on a width:
|
||||||
|
|
||||||
|
- an Android **tablet** at 600px or more gets click-selects /
|
||||||
|
double-click-plays on a touchscreen, which is the exact inversion
|
||||||
|
this issue exists to fix, on the platform it exists for;
|
||||||
|
- a **touchscreen laptop** cannot be described at all, because both
|
||||||
|
pointers are live in the same session on the same row;
|
||||||
|
- and a narrow desktop window gets phone semantics with a mouse.
|
||||||
|
|
||||||
|
Per event, all three are right for free, and there is no second
|
||||||
|
declaration of what a phone does — the thing CLAUDE.md declines to add
|
||||||
|
every time it comes up.
|
||||||
|
|
||||||
|
**Measured, so this is not an assumption about the WebView.** On the
|
||||||
|
reference device (TLP301, Android 14, WebView Chrome 113, 424x439),
|
||||||
|
driving a real tap with `adb shell input tap`:
|
||||||
|
|
||||||
|
```
|
||||||
|
[["down","touch",78,94],["touchstart","touchstart",0,0],["up","touch",78,94]]
|
||||||
|
```
|
||||||
|
|
||||||
|
`PointerEvent` exists, `pointerType` is `"touch"`, `maxTouchPoints` is
|
||||||
|
5, and `(pointer: coarse)` / `(hover: none)` both match.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Decision 2 — there is no double-tap, and the number is why
|
||||||
|
|
||||||
|
#63 asks for *single tap → play* **and** *double tap → context menu*.
|
||||||
|
Those two cannot both be honoured. The first tap of a double tap is
|
||||||
|
indistinguishable from a single tap until the interval expires, so
|
||||||
|
"tap plays" necessarily becomes "tap waits to find out whether you
|
||||||
|
meant something else, then plays". The app already owns that constant:
|
||||||
|
`utils/explore-link.ts` holds a navigation for `DOUBLE_CLICK_GRACE_MS
|
||||||
|
= 250` for precisely this reason.
|
||||||
|
|
||||||
|
**What it would be added to, measured on the device.** Six runs, from
|
||||||
|
the play command to the backend's `TrackChanged`:
|
||||||
|
|
||||||
|
```
|
||||||
|
155, 123, 85, 56, 91 ms median ~100
|
||||||
|
```
|
||||||
|
|
||||||
|
So the app's primary interaction is ~100ms, and a double-tap
|
||||||
|
discriminator makes it ~350 — **3.5x, of which 250ms is spent
|
||||||
|
deliberately doing nothing** — paid on every track anyone ever plays,
|
||||||
|
in order to reach a menu.
|
||||||
|
|
||||||
|
It is also against the platform's convention, which counts for more
|
||||||
|
than usual here because this is the phone build and nothing else:
|
||||||
|
long-press is *how you select* on Android (Gmail, Files, Photos),
|
||||||
|
double-tap is zoom or nothing, and a list's menu is either the
|
||||||
|
long-press sheet or a per-row overflow.
|
||||||
|
|
||||||
|
**So the menu and the selection action bar become the same surface**,
|
||||||
|
which is the convention and removes a concept rather than adding one.
|
||||||
|
Long-press selects the row it was made on and raises the action bar;
|
||||||
|
the bar's actions *are* the context menu's actions, contextualised to
|
||||||
|
whatever is selected — one row or forty. #60's bottom sheet stays
|
||||||
|
behind it as the overflow, so `contextMenuStyles`, `MenuKeyboard` and
|
||||||
|
`menu-surface` are reused rather than reimplemented.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Decision 3 — tap-to-play and selection mode ship together
|
||||||
|
|
||||||
|
The obvious phase order is "tap plays first, it is the smallest
|
||||||
|
change". It is wrong, and the reason is a capability that exists today
|
||||||
|
and is easy to miss.
|
||||||
|
|
||||||
|
**A touch user can already multi-select**: tap selects (the desktop
|
||||||
|
semantics, which a finger currently gets), and the long-press menu then
|
||||||
|
acts on the selection. Move tap to play without shipping selection mode
|
||||||
|
in the same change and there is a window — a release, if it lands — in
|
||||||
|
which selecting forty tracks to add to a playlist is impossible on a
|
||||||
|
phone. That is a regression dressed as an increment.
|
||||||
|
|
||||||
|
So phase 1 is both, or neither.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## What the code looks like now
|
||||||
|
|
||||||
|
| surface | how it binds | selection |
|
||||||
|
|---|---|---|
|
||||||
|
| `track-list` | delegated on the virtualizer: `click`, `dblclick`, `contextmenu`, `dragstart` | `SelectionController` |
|
||||||
|
| `queue-panel` | delegated, same shape | `SelectionController` |
|
||||||
|
| `playlist-details` | per row | `SelectionController` |
|
||||||
|
| `smart-playlist-details` | per row | `SelectionController` |
|
||||||
|
|
||||||
|
All four already share `SelectionController`, and all four resolve a
|
||||||
|
row from an event by `data-index` / `data-file-path` on the row. So the
|
||||||
|
gesture layer has one shape to talk to, and "selection mode" is a flag
|
||||||
|
on the controller they already have rather than a fifth concept.
|
||||||
|
|
||||||
|
`utils/long-press.ts` is one document-capture listener that synthesises
|
||||||
|
a `contextmenu` — the seam that needed no component to opt in. **This
|
||||||
|
plan keeps that shape and changes what the gesture means**, which is
|
||||||
|
why it is a rewrite of that file rather than a second listener set: two
|
||||||
|
document listeners both claiming the 500ms hold is the fault the file's
|
||||||
|
own header warns about.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Two measurements that decide the implementation
|
||||||
|
|
||||||
|
**`touch-action` is `auto` on both the virtualizer and the rows.** With
|
||||||
|
`auto` the browser owns panning on both axes, so a horizontal drag can
|
||||||
|
be claimed as a scroll and our gesture ends in `pointercancel`
|
||||||
|
mid-swipe. A row that wants a horizontal swipe has to declare
|
||||||
|
`touch-action: pan-y`: the browser keeps the vertical pan (which is the
|
||||||
|
virtualizer's scroll, and must stay native or the list stutters) and
|
||||||
|
hands us the horizontal axis. This is the single most likely way for
|
||||||
|
swipe-to-queue to "work in Chromium and not on the phone".
|
||||||
|
|
||||||
|
**The row is 424x52 on the device**, so a swipe threshold in px is a
|
||||||
|
fraction of a row height, not of a screen.
|
||||||
|
|
||||||
|
**And the third one was found by building phase 1 and then running it**
|
||||||
|
— it is not something any browser tier can report. Chrome 113's Android
|
||||||
|
WebView **fires its own `contextmenu` on a long press**. `long-press.ts`
|
||||||
|
stood down when a trusted one arrived, which was right while both paths
|
||||||
|
ended in the same place; once a hold can mean selection mode they end
|
||||||
|
in different places, and standing down means the gesture silently does
|
||||||
|
the *old* thing. Measured, before the fix:
|
||||||
|
|
||||||
|
```
|
||||||
|
{"log":["contextmenu isTrusted=true"],
|
||||||
|
"state":{"bar":null,"menuActive":true,"selected":1}}
|
||||||
|
```
|
||||||
|
|
||||||
|
`yj-long-press` was never announced at all, the context menu opened,
|
||||||
|
and all 26 tests in the component tier passed — dispatched pointer
|
||||||
|
events do not make a browser synthesise a `contextmenu`.
|
||||||
|
|
||||||
|
So the browser's event is a **trigger, not a competitor**: the gesture
|
||||||
|
is announced from it, and only a component that claims it suppresses
|
||||||
|
the native menu. Unclaimed, it propagates untouched. That is the same
|
||||||
|
"browser wins" outcome, reached by asking instead of assuming — and
|
||||||
|
verified both ways on the device, a track row entering selection mode
|
||||||
|
and an album card still opening its menu.
|
||||||
|
|
||||||
|
The tier could not *find* it and can *hold* it: a test cannot dispatch
|
||||||
|
a trusted event, but this module has always told its own apart by
|
||||||
|
identity rather than `isTrusted`, so an untrusted one from a test takes
|
||||||
|
exactly the browser's path.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## A tier note: this one can be driven, not only measured
|
||||||
|
|
||||||
|
`adb shell input tap|swipe` reaches the WebView as real pointer events,
|
||||||
|
which the log above is evidence of. So for the first time the Android
|
||||||
|
tier can *perform* the thing under test rather than describe the page
|
||||||
|
afterwards — a long press is `input swipe X Y X Y 600`, a swipe right
|
||||||
|
is `input swipe X Y X+N Y 120`.
|
||||||
|
|
||||||
|
Device CSS pixels from device pixels, on this phone:
|
||||||
|
`css = (device - 59) / 2.564` vertically, `css = device / 2.564`
|
||||||
|
horizontally (measured from the tap above: 200,300 arrived as 78,94).
|
||||||
|
|
||||||
|
This does not make the device a spec tier — it does not run in CI and
|
||||||
|
`make ui-test` still has to carry the assertions. It makes "does the
|
||||||
|
gesture actually fire on Chrome 113" answerable in seconds.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phases
|
||||||
|
|
||||||
|
**Phase 1 — the seam, tap-to-play, selection mode.** `utils/
|
||||||
|
touch-gestures.ts` replacing `long-press.ts`: pointer-typed
|
||||||
|
recognition of tap / long-press / horizontal swipe, dispatched as
|
||||||
|
composed custom events so a delegated listener in any shadow root
|
||||||
|
still works. `SelectionController` gains a mode. `track-list` acts on
|
||||||
|
tap and enters the mode on long press. The action bar.
|
||||||
|
|
||||||
|
**Phase 2 — swipe right to queue**, with the `touch-action: pan-y`
|
||||||
|
finding above and a reveal-and-snap affordance. **Shipped**; what the
|
||||||
|
device said about it is the section below.
|
||||||
|
|
||||||
|
**Phase 3 — the other three surfaces**, which is mostly wiring, since
|
||||||
|
they already share the controller. **Shipped**, and it was not entirely
|
||||||
|
wiring — see below.
|
||||||
|
|
||||||
|
**Phase 4 — what this leaves behind.** The inline `explore-link`s in a
|
||||||
|
row are a single-click target inside a row whose single tap now plays;
|
||||||
|
that conflict is #67's, and this plan should not pre-empt its answer
|
||||||
|
beyond making tap-to-play win on touch. **Shipped.**
|
||||||
|
|
||||||
|
## Phase 3 was not symmetric, in two places
|
||||||
|
|
||||||
|
**A tap on a queue row plays that position**, not the list. Copying
|
||||||
|
`track-list`'s tap — which sets the queue to the list the row is in —
|
||||||
|
would rebuild the queue *from* the queue, discarding its source, its
|
||||||
|
shuffle order and everything a user had inserted by hand. It reads as a
|
||||||
|
no-op and is not one.
|
||||||
|
|
||||||
|
**The queue panel has no swipe, deliberately.** A right swipe means
|
||||||
|
*add to the queue* everywhere else it exists, and a queue row is
|
||||||
|
already in the queue; the only thing it could mean there is *remove*,
|
||||||
|
which is the same gesture with the opposite effect one screen away —
|
||||||
|
the fault `utils/icon-language.ts` exists to have fixed for glyphs.
|
||||||
|
Removing a queue row is on the row itself (the ×), on its bottom sheet
|
||||||
|
since #60, and on the selection bar this phase gave it. The assertion
|
||||||
|
is that its rows do **not** carry `data-swipe`, so a swipe there cannot
|
||||||
|
silently become a second meaning for the app's one horizontal gesture.
|
||||||
|
|
||||||
|
And the affordance became `utils/swipe-to-queue.ts` rather than being
|
||||||
|
copied twice. Three lists want it; three copies of "how far is far
|
||||||
|
enough" is three chances for them to disagree, which is what
|
||||||
|
`utils/library-status.ts` and `utils/ownership.ts` each exist to have
|
||||||
|
stopped happening. The shared stylesheet is keyed on `[data-swipe]`
|
||||||
|
rather than on a class name, because the three lists call their rows
|
||||||
|
two different things and the `touch-action` half of the device fix has
|
||||||
|
to reach all of them.
|
||||||
|
|
||||||
|
## Phase 4 was already true, which is why it is asserted
|
||||||
|
|
||||||
|
A claimed tap has its click swallowed at document capture, so an
|
||||||
|
`explore-link` inside the row never sees one and tap-to-play wins with
|
||||||
|
no rule of its own. Nothing in the suite would have failed if that
|
||||||
|
stopped covering the link, and the symptom — tapping a track's *title*
|
||||||
|
navigating to its album instead of playing it — is one a phone user
|
||||||
|
meets constantly and a mouse user never does.
|
||||||
|
|
||||||
|
**Its test was vacuous when written**, in the way this file keeps
|
||||||
|
finding: the tap helper dispatched `pointerdown` and `pointerup` and no
|
||||||
|
`click`, so there was nothing to swallow and the assertion held on any
|
||||||
|
build. It sends the trailing click now, which also strengthened phase
|
||||||
|
1's "a tap plays and does not also select". The fixture needed an MBID
|
||||||
|
for the same reason — without one the link asks the backend for a local
|
||||||
|
album first and gives up when nothing answers, so "it did not navigate"
|
||||||
|
was true of a working build and a broken one alike.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## What phase 2 measured, which was not what phase 2 predicted
|
||||||
|
|
||||||
|
The `touch-action` finding above is **half** of the answer, and
|
||||||
|
shipping only that half would have been the exact failure it warns
|
||||||
|
about. Driving a real finger with `adb shell input swipe` across a
|
||||||
|
track row, three values, all three on the device:
|
||||||
|
|
||||||
|
```
|
||||||
|
touch-action: auto pointerdown, 1 move, pointercancel
|
||||||
|
touch-action: pan-y pointerdown, 2 moves, pointercancel
|
||||||
|
touch-action: none pointerdown, 2 moves, pointercancel
|
||||||
|
```
|
||||||
|
|
||||||
|
`touchmove` kept firing in all three. So **Chrome 113's WebView
|
||||||
|
cancels the pointer stream ~16px into any drag whatever `touch-action`
|
||||||
|
says**, and a swipe recognised from `pointermove` — which is what the
|
||||||
|
rest of this module is built on — is a swipe that dies 16px in.
|
||||||
|
|
||||||
|
The other half is a **non-passive `touchmove` calling
|
||||||
|
`preventDefault()`**: with it, the same swipe ran to 12 moves and a
|
||||||
|
`pointerup` at full travel. And both halves are required, which was
|
||||||
|
measured rather than assumed — with the `preventDefault` in place and
|
||||||
|
`touch-action` back at `auto`, the gesture died after **one** move.
|
||||||
|
The reading is that `auto` lets the browser commit to a horizontal pan
|
||||||
|
on the first move past slop, before any threshold of ours can have
|
||||||
|
been crossed, while `pan-y` leaves it undecided long enough for the
|
||||||
|
second move to claim it.
|
||||||
|
|
||||||
|
`none` is the one value to avoid: the list stopped scrolling at all.
|
||||||
|
With the shipped pair, a vertical drag still scrolls the virtualizer
|
||||||
|
81px on the same run that a horizontal one survives.
|
||||||
|
|
||||||
|
**`draggable="true"` is not a competitor**, which is the other thing
|
||||||
|
the device was asked. No `dragstart` fires from a touch drag on this
|
||||||
|
WebView at all, so the drag-to-playlist attribute on every row needs no
|
||||||
|
pointer-type gate.
|
||||||
|
|
||||||
|
### And it found a phase 1 defect that no tier can see
|
||||||
|
|
||||||
|
The native `contextmenu` arrives in **either** order, and phase 1 only
|
||||||
|
handled one of them. `nativeSeen` covers the browser's menu arriving
|
||||||
|
*during* the hold. The reverse — our 500ms timer firing first, a
|
||||||
|
component claiming it, and Chrome delivering its own `contextmenu`
|
||||||
|
50–70ms *later* — was suppressed by nothing, so the context menu
|
||||||
|
opened on top of the selection bar. Measured over four holds:
|
||||||
|
|
||||||
|
```
|
||||||
|
hold 1 yj-long-press, then contextmenu isTrusted=true menu open
|
||||||
|
hold 2 yj-long-press clean
|
||||||
|
hold 3 yj-long-press, then contextmenu isTrusted=true menu open
|
||||||
|
hold 4 yj-long-press clean
|
||||||
|
```
|
||||||
|
|
||||||
|
Two in four, on the one surface #63 exists to have changed, and
|
||||||
|
invisible to both browser tiers because neither synthesises a
|
||||||
|
`contextmenu` from a dispatched press. A press that has produced its
|
||||||
|
outcome now suppresses a late one whichever branch it took; six holds
|
||||||
|
on the fixed build, six clean.
|
||||||
|
|
||||||
|
### The rules phase 2 settled
|
||||||
|
|
||||||
|
- **A swipe is not a selection.** It queues the row it was made on,
|
||||||
|
unless that row is one of several *explicitly* selected — the same
|
||||||
|
rule the context menu answers with, because a bar reading "40
|
||||||
|
selected" beside a gesture that quietly queues one of them is two
|
||||||
|
answers to one question. It never changes the selection, which is
|
||||||
|
where it differs from a right-click.
|
||||||
|
- **Rightward only.** Nothing is bound to a leftward swipe and
|
||||||
|
claiming one would take a gesture away to do nothing with it.
|
||||||
|
- **The commit threshold is a fraction of the row** (0.3, floor 72px),
|
||||||
|
because the row is 424x52 on this device and a bare pixel count is a
|
||||||
|
fraction of a row height on one screen and a third of the width on
|
||||||
|
the next.
|
||||||
|
- **The affordance is not only a colour** (WCAG 1.4.1, the rule the
|
||||||
|
playing-row marker exists for): the pane carries the queue icon and
|
||||||
|
words, the words change at the threshold ("Add to queue" → "Release
|
||||||
|
to add" → "Added"), and the outcome is announced in a live region.
|
||||||
|
- **The row does not move; its cells do.** `.track-row` is
|
||||||
|
`contain: strict` with `overflow: hidden`, so a pane held at the
|
||||||
|
row's original position while the row translates is a pane at a
|
||||||
|
negative offset inside a clipping box and is simply not painted.
|
||||||
|
Sliding the cells needs no wrapper element in a row that is already
|
||||||
|
a grid.
|
||||||
|
- **The travel is written to the row's own style, not rendered.** One
|
||||||
|
render at the start, one at the threshold, one at the end; a
|
||||||
|
virtualizer re-rendering every visible row per frame of one finger's
|
||||||
|
travel is the thing `perf.m1` is about.
|
||||||
|
|
||||||
|
## Open questions
|
||||||
|
|
||||||
|
1. **Does selection mode have an escape other than the bar's own
|
||||||
|
close?** *Settled: Escape, here; back, not here.*
|
||||||
|
|
||||||
|
Escape leaves the mode, from `selection-bar` rather than from each
|
||||||
|
of the four hosts — that element exists only while the mode does, so
|
||||||
|
it is the one place a dismissal can be attached and detached with
|
||||||
|
the thing it dismisses. It is the same documented exception the
|
||||||
|
overlaid queue's Escape is: **a dismissal, not a shortcut**, so it
|
||||||
|
is not a panel-scoped binding.
|
||||||
|
|
||||||
|
The back gesture is the half that is *not* done, and deliberately.
|
||||||
|
The obvious version — `selection-bar` pushing a history entry — is
|
||||||
|
precisely the fault `navStack` was deleted for: the shell owns the
|
||||||
|
stack (#6/#55) and is the only thing that calls `pushState`, so that
|
||||||
|
two stacks cannot disagree about what one press means. Four lists
|
||||||
|
each reaching for `history` is four stacks. It is also wrong on its
|
||||||
|
own terms, since a mode is per-component and a user who enters one,
|
||||||
|
navigates away and returns has an entry for a mode that no longer
|
||||||
|
exists. #55 settled the shape for a *place*; a mode is not one,
|
||||||
|
which is why it could not simply inherit that answer.
|
||||||
|
|
||||||
|
What it wants is one shell-owned register of dismissible surfaces,
|
||||||
|
which would retro-fit the queue overlay, the dialogs and this alike
|
||||||
|
rather than adding a fourth private answer. **#200.**
|
||||||
|
|
||||||
|
2. **Does a tap on a row's favourite icon still toggle it in normal
|
||||||
|
mode?** *Settled in phase 1: yes.* A control inside the row keeps
|
||||||
|
its own tap — the gesture is simply not claimed there, so the click
|
||||||
|
behind it falls through untouched. It is the same rule the shortcut
|
||||||
|
service has for a focused control that owns a key, and it is what
|
||||||
|
keeps the 44px favourite target (#56) from becoming a 44px play
|
||||||
|
target. The queue row's × is the second instance of it.
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
# Autotag (v1.3) — MusicBrainz Autotagger
|
# Autotag (v1.3) — MusicBrainz Autotagger
|
||||||
|
|
||||||
|
> **Historical record.** Phases 008–010 shipped, and the scoring engine was subsequently overhauled (`recommend.go`, `rank.go`, `mixedbag.go`), which makes the 011/012 sections below stale in their details. What is actually left is **#90** (auto-accept and entry points) and **#91** (settings, and a way back from the dismissed file-write warning).
|
||||||
|
|
||||||
The MusicBrainz autotagger, collectively **v1.3**. Builds on the explore-browser API client + cache foundation. Five sequential phases (008–012), each depending on the prior one.
|
The MusicBrainz autotagger, collectively **v1.3**. Builds on the explore-browser API client + cache foundation. Five sequential phases (008–012), each depending on the prior one.
|
||||||
|
|
||||||
| Phase | Title | Status |
|
| Phase | Title | Status |
|
||||||
@@ -1,195 +0,0 @@
|
|||||||
# 010 — Owned albums, offline
|
|
||||||
|
|
||||||
**Status:** not started — and **much smaller than when it was written**
|
|
||||||
**Branch:** none yet
|
|
||||||
**Created:** 2026-08-13
|
|
||||||
**Depends on:** nothing
|
|
||||||
**Related:** the `AlbumReleasesFailed` fix that prompted it, and the
|
|
||||||
tag-derived completeness that landed after it (same session)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## What already shipped, and what it leaves
|
|
||||||
|
|
||||||
The common case is solved without this plan. `GetAlbumCompleteness`
|
|
||||||
reads the "5/12" denominator off the files' own tags — persisted to
|
|
||||||
`release_group_recordings.total_tracks`, having been extracted at every
|
|
||||||
scan since forever and discarded — and an album that is **MBID-matched
|
|
||||||
and complete** now opens with **no catalog call at all**. Identity from
|
|
||||||
the MBID, tracklist from the tags; those were the two things the browse
|
|
||||||
was being spent on.
|
|
||||||
|
|
||||||
So the set this plan still has to serve is not "albums you own a track
|
|
||||||
of". It is:
|
|
||||||
|
|
||||||
- albums that are genuinely **incomplete** (the catalog is the only way
|
|
||||||
to say *which* tracks are missing — tags give the count, not the
|
|
||||||
names), and
|
|
||||||
- albums whose tags **never declared a total**, where completeness is
|
|
||||||
unknowable locally and the catalog is the only source.
|
|
||||||
|
|
||||||
On a well-tagged library that is a small minority, which changes the
|
|
||||||
economics below considerably: the run is shorter, and the rate limiter
|
|
||||||
contention that dominates this design is proportionally less severe.
|
|
||||||
Re-measure before building — the answer may now be "the prefetch is
|
|
||||||
enough".
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## The problem
|
|
||||||
|
|
||||||
Opening an album detail page for an album **you already own** hits
|
|
||||||
MusicBrainz. Every time it is not in the response cache, which for most
|
|
||||||
of a library is every time, because nothing warms that cache except a
|
|
||||||
capped prefetch on the artist page.
|
|
||||||
|
|
||||||
The user's framing: *this is a classic example of an album we should
|
|
||||||
have had locally.*
|
|
||||||
|
|
||||||
## Why we do not have it, despite the discography backfill
|
|
||||||
|
|
||||||
`BackfillLibraryDiscographies` / `EnsureArtistDiscography`
|
|
||||||
(`backend/explore/searchindex.go:301`, `:397`) do less than the name
|
|
||||||
suggests. Per artist, `indexOneArtist` fetches:
|
|
||||||
|
|
||||||
- `fetchTopReleaseGroups` — capped at `indexMaxRGs` (50)
|
|
||||||
- `fetchTopRecordings` — capped at `indexMaxRecs` (200)
|
|
||||||
|
|
||||||
and writes them as **flat `explore_index` rows**. There is no release
|
|
||||||
group → tracklist relation anywhere in the index, and no release-level
|
|
||||||
rows at all. `explore_index` recordings carry `caa_release_mbid` and
|
|
||||||
`release_name`, which name the release used for cover art — not a
|
|
||||||
tracklist.
|
|
||||||
|
|
||||||
So "we have full discographies for library artists" means *we know
|
|
||||||
which albums the artist made, offline*. It has never meant we know
|
|
||||||
what is on any of them.
|
|
||||||
|
|
||||||
The only store of release-level catalog data in the app is `http_cache`
|
|
||||||
under `mb:browse:releases:<rg>` (90-day TTL, `musicbrainz.go:27`),
|
|
||||||
populated **only** by a live `BrowseReleases` with
|
|
||||||
`Includes: ["recordings", "media"]` at `MaxLimit` — the most expensive
|
|
||||||
call the app makes to MusicBrainz. It is warmed by exactly one thing:
|
|
||||||
`PrefetchReleases` (`explore.go:746`), capped at 8, called only when an
|
|
||||||
artist page renders.
|
|
||||||
|
|
||||||
An album opened from the library grid therefore always browses live.
|
|
||||||
|
|
||||||
## What to build
|
|
||||||
|
|
||||||
**A post-scan backfill that warms the release cache for release groups
|
|
||||||
that are owned but not known-complete** — bounded, resumable, and
|
|
||||||
shaped exactly like `BackfillLibraryDiscographies`, which is the proven
|
|
||||||
pattern for this in the codebase.
|
|
||||||
|
|
||||||
The scoping rule is the user's and it is the right one: not "every
|
|
||||||
album by every artist in the library" (50 release groups per artist,
|
|
||||||
mostly never opened) but albums with owned tracks — narrowed further,
|
|
||||||
now, to the ones a local answer cannot already cover. The query gains
|
|
||||||
one clause: skip release groups whose `GetAlbumCompleteness` reports
|
|
||||||
`complete`.
|
|
||||||
|
|
||||||
Sketch:
|
|
||||||
|
|
||||||
1. A query for release groups with ≥1 owned track and no warm release
|
|
||||||
cache entry. `release_groups.mbid` is the key; the owned-track join
|
|
||||||
is `audio_files → recordings → release_group_recordings`, the same
|
|
||||||
shape `unenrichedLibraryArtistMBIDs` already uses one table over.
|
|
||||||
2. Order by owned-track count descending, so the albums the user has
|
|
||||||
most of are warmed first — same reasoning as the discography
|
|
||||||
backfill's ordering, same benefit if a run is cut short.
|
|
||||||
3. Run through `releasesSF`, so it never double-fetches a release group
|
|
||||||
an interactive open is already handling.
|
|
||||||
4. Bound a run (`discogBackfillMaxPerRun` has a value to copy) and make
|
|
||||||
it resumable: the resume marker is the response cache itself —
|
|
||||||
`BrowseReleasesCached` already answers "is this one done", so unlike
|
|
||||||
the discography path this needs **no new flag column**.
|
|
||||||
5. Trigger it where `BackfillLibraryDiscographies` is triggered, and
|
|
||||||
register it with `jobs` so it has progress, pause and cancel like
|
|
||||||
every other long-running operation.
|
|
||||||
|
|
||||||
### The rate limiter is the whole design constraint
|
|
||||||
|
|
||||||
> **Update (2026-08-13): the priority half is built, and the sentence
|
|
||||||
> below is wrong on a detail.** `e.mb` runs on `mbSearchLimiter`
|
|
||||||
> (`NewRateLimiterBurst(3, 1)`); the 1 req/s `NewRateLimiter()` cited
|
|
||||||
> here is the *artist image* limiter. Both are shared and both were
|
|
||||||
> FIFO. `RateLimiter.WithBackgroundLane` + `WithBackgroundPriority(ctx)`
|
|
||||||
> now make a marked caller yield to interactive work and pace at 1/s,
|
|
||||||
> and `jobs.KindCatalogEnrich` + `startBackfillJob` give the existing
|
|
||||||
> backfills progress and cancel. **"Do not start until the priority
|
|
||||||
> question has an answer" is satisfied** — mark this backfill's context
|
|
||||||
> and register it the way `BackfillLibraryDiscographies` now is.
|
|
||||||
> `PrefetchReleases`' cap of 8 is still unrevisited.
|
|
||||||
|
|
||||||
One shared `NewRateLimiter()` at 1 req/s (`explore.go:84`) serves this,
|
|
||||||
`PrefetchReleases`, and every interactive browse. A backfill over a
|
|
||||||
few thousand owned albums is *hours* of wall clock at that rate — which
|
|
||||||
is fine for a background job, and not fine if it starves the album page
|
|
||||||
the user is looking at right now.
|
|
||||||
|
|
||||||
That is the real work in this plan, and it is not the query:
|
|
||||||
|
|
||||||
- Interactive browses need to **jump the queue**. Today they cannot;
|
|
||||||
there is one limiter and it is FIFO.
|
|
||||||
- `PrefetchReleases`' cap of 8 was sized when nothing else competed for
|
|
||||||
the limiter. Revisit it in the same change.
|
|
||||||
- The 60 s fallback the `AlbumReleasesFailed` fix installed is sized
|
|
||||||
for today's contention. If a backfill can queue behind it, that
|
|
||||||
number is wrong again — which is an argument for priority, not for a
|
|
||||||
bigger number.
|
|
||||||
|
|
||||||
Do not start the query until the priority question has an answer.
|
|
||||||
|
|
||||||
## The alternative that was considered and rejected
|
|
||||||
|
|
||||||
**Project release-group tracklists in the dump build and ship them in
|
|
||||||
the artifact.** The data is there: `canonical_musicbrainz_data.csv`
|
|
||||||
carries `release_mbid` *and* `recording_mbid`
|
|
||||||
(`dumpcatalog.go:520`), and `release_to_rg` already maps release →
|
|
||||||
release group. It is derivable from bytes the index build already
|
|
||||||
streams, with no new API surface at all, and it would work offline on
|
|
||||||
first launch with no per-user backfill.
|
|
||||||
|
|
||||||
It is rejected **for this plan** because the artifact is built
|
|
||||||
centrally and is byte-identical for every user, so "albums the user
|
|
||||||
owns a track of" cannot be a filter on it. Shipping tracklists for the
|
|
||||||
whole catalog means per-recording rows against a ~900 MB artifact
|
|
||||||
budget (~426 B/row measured), and gating on a popularity floor means it
|
|
||||||
is absent for exactly the obscure albums a local backfill would have
|
|
||||||
covered.
|
|
||||||
|
|
||||||
Worse than absent, in fact — and this is the argument that actually
|
|
||||||
kills it. The floor is not one number over artists; it is a **per
|
|
||||||
artist track budget** (`dumpcatalog.go:58-89`): 50 tracks for a tier-A
|
|
||||||
artist, 25 for tier B, 12 for tier C. A projected tracklist would
|
|
||||||
therefore be *whichever* of an album's tracks survived that budget,
|
|
||||||
with nothing marking the rest as absent — so the album page would count
|
|
||||||
owned against a truncated denominator and render "Play 7 of 9" for a
|
|
||||||
twelve-track album. That is a confident lie, where the honest states
|
|
||||||
this plan's alternative produces (complete / incomplete / unknown) are
|
|
||||||
at worst silent.
|
|
||||||
|
|
||||||
Note that `markLibraryArtists` (`dumpcatalog.go:246`) already grants
|
|
||||||
every library artist full coverage — 500 tracks, 100 release groups —
|
|
||||||
by reading the local library, so the per-user tailoring this option
|
|
||||||
supposedly cannot have does exist in code. It is a no-op in the CI
|
|
||||||
build (empty library), and reaching it means a **local** dump build:
|
|
||||||
the ~205 GB, half-a-day download the entire artifact design exists to
|
|
||||||
avoid. Whoever finds that function next should read this paragraph
|
|
||||||
before getting excited about it.
|
|
||||||
|
|
||||||
Worth revisiting if the artifact ever gains per-user tailoring, or if a
|
|
||||||
measurement shows the row count is smaller than feared. Note it also
|
|
||||||
yields the *canonical* tracklist rather than MusicBrainz's full version
|
|
||||||
list, so the versions dropdown would still browse live when opened.
|
|
||||||
|
|
||||||
## Done when
|
|
||||||
|
|
||||||
- Opening an owned album that has never been opened before renders its
|
|
||||||
catalog tracklist with no network call, after one backfill run.
|
|
||||||
- An interactive browse issued while the backfill is running is not
|
|
||||||
delayed by it.
|
|
||||||
- The backfill appears in the jobs indicator, and can be paused and
|
|
||||||
cancelled there.
|
|
||||||
- A second run after a completed one does approximately nothing.
|
|
||||||
+14
-3
@@ -1,8 +1,19 @@
|
|||||||
# semantic-release configuration.
|
# semantic-release configuration.
|
||||||
#
|
#
|
||||||
# Runs on pushes to main from .gitea/workflows/release.yml: determine the
|
# Run by hand from .gitea/workflows/release.yml, which has no push
|
||||||
# version from the Conventional Commits since the last tag, write the
|
# trigger: determine the version from the Conventional Commits since the
|
||||||
# changelog, commit it, push the tag, and create the Gitea release.
|
# last tag, write the changelog, push the tag, and create the Gitea
|
||||||
|
# release. A release is a shipment rather than a merge, and the commits
|
||||||
|
# accumulate until someone says so -- this file needs to know nothing
|
||||||
|
# about that, because reading everything since the last tag is what it
|
||||||
|
# already did.
|
||||||
|
#
|
||||||
|
# `branches` is main and only main. A `prerelease: true` channel is the
|
||||||
|
# obvious next edit here and is the one to think twice about: all four
|
||||||
|
# publishing workflows trigger on `v*`, which matches `v0.4.0-beta.1`.
|
||||||
|
# They carry a prerelease guard now, so the failure is a clean skip
|
||||||
|
# rather than a beta in a public tap -- but they are four separate files
|
||||||
|
# and this is the line that would turn them on.
|
||||||
#
|
#
|
||||||
# **There is no `@semantic-release/github` plugin here and there must not
|
# **There is no `@semantic-release/github` plugin here and there must not
|
||||||
# be.** Gitea's API is `/api/v1` and is not GitHub's surface. The Gitea
|
# be.** Gitea's API is `/api/v1` and is not GitHub's surface. The Gitea
|
||||||
|
|||||||
+10
-5
@@ -5,15 +5,20 @@ The changelog is the releases page:
|
|||||||
<https://git.ljones.me/yonlu/yellowjacket/releases>
|
<https://git.ljones.me/yonlu/yellowjacket/releases>
|
||||||
|
|
||||||
Every release there is generated from the Conventional Commits it
|
Every release there is generated from the Conventional Commits it
|
||||||
contains, by `.gitea/workflows/release.yml` on merge to `main`. Each one
|
contains, by `.gitea/workflows/release.yml`. Each one carries its notes
|
||||||
carries its notes as its body, grouped by change type, with a link to the
|
as its body, grouped by change type, with a link to the commit behind
|
||||||
commit behind every line.
|
every line.
|
||||||
|
|
||||||
|
That workflow is **run by hand**, so a release holds everything merged
|
||||||
|
since the last one rather than one PR's worth. It used to fire on every
|
||||||
|
push to `main`, which made a version per merged PR (issue #115).
|
||||||
|
|
||||||
**This file is not generated and is not a copy of that.** `main` is a
|
**This file is not generated and is not a copy of that.** `main` is a
|
||||||
protected branch, so nothing pushes a changelog commit back to it — and a
|
protected branch, so nothing pushes a changelog commit back to it — and a
|
||||||
file that claimed to be a changelog while silently never updating would
|
file that claimed to be a changelog while silently never updating would
|
||||||
be worse than no file at all. `make release-dry` prints what the next
|
be worse than no file at all. `make release-dry` prints what a release
|
||||||
merge would release.
|
run would cut right now, and the workflow's own `dry_run` input answers
|
||||||
|
the same question from CI.
|
||||||
|
|
||||||
History before `v0.0.1` is in `git log`. The versions before it were cut
|
History before `v0.0.1` is in `git log`. The versions before it were cut
|
||||||
by hand and are not on the releases page; the entries this file used to
|
by hand and are not on the releases page; the entries this file used to
|
||||||
|
|||||||
+173
@@ -0,0 +1,173 @@
|
|||||||
|
# Contributing to YellowJacket
|
||||||
|
|
||||||
|
This is the contributor's half of the [README](README.md): how to build it, how
|
||||||
|
to check a change, and how a change gets in. [`CLAUDE.md`](CLAUDE.md) is the
|
||||||
|
deep reference — the architecture, and the reasons behind the shape of it —
|
||||||
|
and is worth reading before a change of any size, because most of this
|
||||||
|
codebase's traps are written down there and nowhere else.
|
||||||
|
|
||||||
|
## Building from source
|
||||||
|
|
||||||
|
YellowJacket is [Go](https://go.dev/) with a [Lit](https://lit.dev/)/TypeScript
|
||||||
|
frontend, bridged by [Wails v3](https://wails.io/).
|
||||||
|
|
||||||
|
| Tool | Version |
|
||||||
|
|------|---------|
|
||||||
|
| Go | 1.26+ |
|
||||||
|
| Node.js | 22+ |
|
||||||
|
| pnpm | 10+ |
|
||||||
|
| Wails CLI | v3 — vendored, no install needed (`go tool wails3`) |
|
||||||
|
|
||||||
|
The Wails v3 CLI resolves from the `tool` block in `go.mod`, so there is nothing
|
||||||
|
to install globally; `make setup` fetches it with the rest of the tooling.
|
||||||
|
|
||||||
|
On Linux, install the system libraries Wails needs. v3 builds against GTK4 +
|
||||||
|
WebKitGTK 6.0 by default:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt-get install libasound2-dev libgtk-4-dev libwebkitgtk-6.0-dev # Debian/Ubuntu
|
||||||
|
sudo pacman -S alsa-lib gtk4 webkitgtk-6.0 # Arch
|
||||||
|
```
|
||||||
|
|
||||||
|
A machine without `webkitgtk-6.0` can still build with `-tags gtk3` against the
|
||||||
|
older WebKit2GTK 4.1 stack, but that is an escape hatch, not what CI or a
|
||||||
|
release builds. macOS and Windows need no extra system packages. Run
|
||||||
|
`go tool wails3 doctor` to check your environment.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make setup # install tooling, frontend packages and the git hooks
|
||||||
|
make dev # run with hot-reload
|
||||||
|
make build-dev # debug build with symbols
|
||||||
|
make build-prod # production build (stripped and trimmed)
|
||||||
|
make android # the arm64 APK, into bin/
|
||||||
|
```
|
||||||
|
|
||||||
|
The `Makefile` is the front door and carries a one-line description against
|
||||||
|
each target; `Taskfile.yml` and `build/<platform>/Taskfile.yml` are the build
|
||||||
|
implementation behind it and are not called directly.
|
||||||
|
|
||||||
|
## Generated code
|
||||||
|
|
||||||
|
Two generators run from `go generate ./...`, which `make generate` wraps:
|
||||||
|
**sqlc** turns `backend/database/sql/queries/` into Go in
|
||||||
|
`backend/database/sql/sqlcgen/`, and **templ** turns `.templ` files into
|
||||||
|
`*_templ.go` beside them. Never edit either output by hand — run
|
||||||
|
`make generate` after touching a `.sql` or a `.templ` file.
|
||||||
|
|
||||||
|
The TypeScript bindings in `frontend/bindings/` are generated by `wails3`
|
||||||
|
rather than by `go generate`, so they are a separate step: `make bindings`
|
||||||
|
regenerates them and `make bindings-check` fails if they are stale.
|
||||||
|
`frontend/src/events.ts` is generated too, from `backend/events/events.go`.
|
||||||
|
|
||||||
|
A pre-commit hook checks that all of this is fresh, so the usual way to meet it
|
||||||
|
is a failing commit rather than a bug.
|
||||||
|
|
||||||
|
## Checking a change
|
||||||
|
|
||||||
|
Run the tier the change actually demands, not the cheapest one.
|
||||||
|
|
||||||
|
| Change | Command |
|
||||||
|
|---|---|
|
||||||
|
| Go | `make lint` and `make test` — both cover all three build configurations |
|
||||||
|
| A frontend component or store | `make ui-test` (Vitest in a real Chromium, no backend) |
|
||||||
|
| A user-visible flow | `make e2e`, against a running `make dev-headless` |
|
||||||
|
| CSS | `make css-check` — see the Chrome 113 note below |
|
||||||
|
| Anything cosmetic | look at a screenshot; several bugs here were invisible to every assertion and obvious in an image |
|
||||||
|
|
||||||
|
`make test` needs the fixture library, which is generated rather than
|
||||||
|
committed — it runs `make testdata` itself (about a second).
|
||||||
|
|
||||||
|
The end-to-end tier drives the real app with no display at all: `make
|
||||||
|
dev-headless` starts it in the background on `:34115` (add `SEED=<name>` for a
|
||||||
|
seeded library, built by `make sandbox-seed NAME=<name>`), `make dev-logs` tails
|
||||||
|
it and `make dev-stop` stops it. **Check the port before starting one** — if
|
||||||
|
`:34115` is already answering, someone else's app is there, and a green result
|
||||||
|
about their build is worse than no result.
|
||||||
|
|
||||||
|
Two smaller checks exist because the failure they catch is silent:
|
||||||
|
`make bindings-check` (stale generated bindings) and `make css-check`, which is
|
||||||
|
two passes — one fails on a `css` literal ended early by a backtick inside a
|
||||||
|
comment, the other on a nested CSS rule that begins with a bare element
|
||||||
|
selector. Chrome 113 is what the reference Android device renders with, and it
|
||||||
|
drops such a rule without a word.
|
||||||
|
|
||||||
|
`make vulncheck` runs govulncheck over the module.
|
||||||
|
|
||||||
|
## The issue tracker is the source of truth
|
||||||
|
|
||||||
|
Work is described by issues before it is described by branches, and the tracker
|
||||||
|
is shared with people who cannot see your terminal.
|
||||||
|
|
||||||
|
- **Search before starting**, closed issues included: `./scripts/issue.sh search
|
||||||
|
<terms>`. "That was fixed three weeks ago" is the cheapest possible answer.
|
||||||
|
- **Claim before the first edit**, not before the commit:
|
||||||
|
`./scripts/issue.sh claim <n>` sets the assignee, applies `Status/In Progress`
|
||||||
|
and comments with the branch, so the work is visibly taken *while it is being
|
||||||
|
done*. It refuses if somebody else holds it — talk to them rather than working
|
||||||
|
around it.
|
||||||
|
- **If no issue covers the work, open one first** (`./scripts/issue.sh new`).
|
||||||
|
- **Findings get filed.** A bug tripped over on the way to something else is an
|
||||||
|
issue with a reproduction, not a wider diff and not a sentence in a chat log.
|
||||||
|
- **#73 is the roadmap** and states the order the backlog should be worked in.
|
||||||
|
|
||||||
|
`scripts/issue.sh` is the whole interface (`list`, `mine`, `search`, `show`,
|
||||||
|
`new`, `claim`, `unclaim`, `comment`, `close`, `label`, `depends`, `labels`) and
|
||||||
|
wants a `GITEA_TOKEN` with `write:issue`. The labels are a taxonomy rather than
|
||||||
|
tags: `Kind/*`, `Area/*`, `Priority/*`, `Platform/*`, plus `Reviewed/*` and
|
||||||
|
`Status/*`, of which the last two are exclusive scopes.
|
||||||
|
|
||||||
|
## Commits and pull requests
|
||||||
|
|
||||||
|
`main` is protected, so a branch and a PR are the only way in. Branch from
|
||||||
|
`origin/main`, and name the branch after the issue (`fix/140-…`, `feat/25-…`).
|
||||||
|
|
||||||
|
Commit subjects are [Conventional Commits](https://www.conventionalcommits.org/)
|
||||||
|
— `type(scope): subject`, imperative, ≤72 characters — and are enforced by a
|
||||||
|
`commit-msg` hook and by CI (`make commit-check`). This is load-bearing rather
|
||||||
|
than decorative: semantic-release reads the **type** to decide the next version,
|
||||||
|
so a CI-only change is `ci:` and never `fix(ci):`, which would ship a patch
|
||||||
|
release. `make release-dry` prints what a release would cut right now.
|
||||||
|
|
||||||
|
**The closing keyword goes in the commit body**, one issue per line, because
|
||||||
|
Gitea parses commit messages that reach `main` and does not parse the PR body:
|
||||||
|
|
||||||
|
```
|
||||||
|
docs: rewrite the README as a landing page
|
||||||
|
|
||||||
|
<why>
|
||||||
|
|
||||||
|
Closes #50
|
||||||
|
```
|
||||||
|
|
||||||
|
A PR body carries a commit-to-issue table, the verification you actually ran
|
||||||
|
(with results), and a `Closes` list for whoever reads it.
|
||||||
|
|
||||||
|
## Style
|
||||||
|
|
||||||
|
- **Go** — golangci-lint v2, strict: `err113` (static errors), `nlreturn`,
|
||||||
|
`wsl_v5`, `godot`, `sloglint`, `perfsprint`, and imports grouped stdlib →
|
||||||
|
third-party → `yellowjacket/…` by gci.
|
||||||
|
- **TypeScript** — strict mode, no implicit `any`, no unused locals or
|
||||||
|
parameters.
|
||||||
|
- Match the surrounding code. Where `CLAUDE.md` explains why something is shaped
|
||||||
|
the way it is, that shape is load-bearing and there is usually a test pinning
|
||||||
|
it.
|
||||||
|
|
||||||
|
Hooks do most of the enforcing (`lefthook.yml`, installed by `make setup`):
|
||||||
|
pre-commit runs vet, lint, the codegen checks, the frontend typecheck and the
|
||||||
|
two CSS checks in parallel; pre-push runs the Go suite and the UI tier,
|
||||||
|
deliberately one after the other rather than together.
|
||||||
|
|
||||||
|
## Where the rest of the documentation is
|
||||||
|
|
||||||
|
- [`CLAUDE.md`](CLAUDE.md) — architecture and constraints, in depth.
|
||||||
|
- [`docs/PROFILING.md`](docs/PROFILING.md) — Go pprof and frontend profiling.
|
||||||
|
- [`docs/android-release.md`](docs/android-release.md) — the APK, its signing
|
||||||
|
key, and what the release workflow checks.
|
||||||
|
- [`docs/index-cache.md`](docs/index-cache.md) — the search-index build cache
|
||||||
|
and why it has a snapshot.
|
||||||
|
- [`packaging/arch/README.md`](packaging/arch/README.md),
|
||||||
|
[`packaging/homebrew/README.md`](packaging/homebrew/README.md) — the two
|
||||||
|
package channels.
|
||||||
|
- `.planning/` — design documents and measured history, not a queue. The queue
|
||||||
|
is the tracker.
|
||||||
@@ -160,8 +160,11 @@ ui-watch: ## Same suite, in watch mode
|
|||||||
ui-visual: ## Run the suite including screenshot comparisons
|
ui-visual: ## Run the suite including screenshot comparisons
|
||||||
@cd frontend && YJ_VISUAL=1 npx vitest run $(UI_ARGS)
|
@cd frontend && YJ_VISUAL=1 npx vitest run $(UI_ARGS)
|
||||||
|
|
||||||
ui-visual-update: ## Re-record the screenshot baselines
|
# `--update=true`, never a bare `--update`: vitest takes the following
|
||||||
@cd frontend && YJ_VISUAL=1 npx vitest run --update $(UI_ARGS)
|
# positional as the flag's value, so `--update <path>` swallows the path
|
||||||
|
# and re-records every baseline in the repo instead of the one named.
|
||||||
|
ui-visual-update: ## Re-record the screenshot baselines (UI_ARGS=<path> to filter)
|
||||||
|
@cd frontend && YJ_VISUAL=1 npx vitest run --update=true $(UI_ARGS)
|
||||||
|
|
||||||
ui-setup: ## Install the Vitest browser provider's own Chromium (once)
|
ui-setup: ## Install the Vitest browser provider's own Chromium (once)
|
||||||
@cd frontend && pnpm install && npx playwright install chromium
|
@cd frontend && pnpm install && npx playwright install chromium
|
||||||
@@ -172,19 +175,24 @@ ui-setup: ## Install the Vitest browser provider's own Chromium (once)
|
|||||||
bindings-check: ## Fail if the generated bindings are stale
|
bindings-check: ## Fail if the generated bindings are stale
|
||||||
@./scripts/bindings-check.sh
|
@./scripts/bindings-check.sh
|
||||||
|
|
||||||
|
# Two CSS traps that report a long way from their cause, or not at all.
|
||||||
# A backtick inside a comment in a css`` literal ends the literal, and
|
# A backtick inside a comment in a css`` literal ends the literal, and
|
||||||
# what you get back is a type error about CSSResult, or every test in
|
# what you get back is a type error about CSSResult, or every test in
|
||||||
# the suite failing to import. Four sessions, three plans. Instant.
|
# the suite failing to import. Four sessions, three plans. And a nested
|
||||||
|
# rule starting with an element name is dropped by the device's
|
||||||
|
# Chrome 113 in silence -- no tier here runs an engine that can see it.
|
||||||
|
# Instant.
|
||||||
.PHONY: css-check
|
.PHONY: css-check
|
||||||
css-check: ## Fail if a css`` literal was ended early by a backtick in a comment
|
css-check: ## Fail on a css`` literal ended early by a backtick, or a nested rule needing an &
|
||||||
@cd frontend && node scripts/check-css-literals.mjs
|
@cd frontend && node scripts/check-css-literals.mjs
|
||||||
|
@cd frontend && node scripts/check-css-nesting.mjs
|
||||||
|
|
||||||
# .pi/ and CLAUDE.md document commands, and a doc that documents a
|
# .pi/ and CLAUDE.md document commands, and a doc that documents a
|
||||||
# command wrongly is worse than no doc: an agent runs it confidently.
|
# command wrongly is worse than no doc: an agent runs it confidently.
|
||||||
# Every command in them is a make target on purpose, so this is
|
# Every command in them is a make target on purpose, so this is
|
||||||
# checkable. It also asserts AGENTS.md is a symlink to CLAUDE.md, so the
|
# checkable. It also asserts AGENTS.md is a symlink to CLAUDE.md, so the
|
||||||
# two harnesses cannot drift onto two descriptions of one project.
|
# two harnesses cannot drift onto two descriptions of one project.
|
||||||
skill-check: ## Fail if the agent docs name a missing make target, or AGENTS.md is not a symlink
|
skill-check: ## Fail if the docs name a missing make target, or AGENTS.md is not a symlink
|
||||||
@./scripts/skill-check.sh
|
@./scripts/skill-check.sh
|
||||||
|
|
||||||
# Conventional Commits, which CLAUDE.md claimed CI enforced for a long
|
# Conventional Commits, which CLAUDE.md claimed CI enforced for a long
|
||||||
@@ -192,15 +200,21 @@ skill-check: ## Fail if the agent docs name a missing make target, or AGENTS.md
|
|||||||
commit-check: ## Fail if a commit subject is not a Conventional Commit
|
commit-check: ## Fail if a commit subject is not a Conventional Commit
|
||||||
@./scripts/commit-check.sh $(if $(RANGE),--range $(RANGE))
|
@./scripts/commit-check.sh $(if $(RANGE),--range $(RANGE))
|
||||||
|
|
||||||
# What a merge to main would release, without releasing it. Reads the
|
# What running the release workflow now would ship, without shipping it.
|
||||||
# same .releaserc.yml CI does, so "why did that not cut a version" is
|
# Reads the same .releaserc.yml CI does, so "why did that not cut a
|
||||||
# answerable locally instead of by pushing and watching. Needs no
|
# version" is answerable locally instead of by pushing and watching.
|
||||||
# credentials: --dry-run neither tags nor publishes.
|
# Needs no credentials: --dry-run neither tags nor publishes.
|
||||||
|
#
|
||||||
|
# release.yml is dispatch-only, so this answers the question that
|
||||||
|
# actually gets asked now -- what has accumulated since the last tag --
|
||||||
|
# rather than what one merge would have done. The workflow's own
|
||||||
|
# `dry_run` input is the same answer from the runner, against whatever
|
||||||
|
# main points at rather than the working tree.
|
||||||
#
|
#
|
||||||
# The pins must stay identical to release.yml's, which is where the note
|
# The pins must stay identical to release.yml's, which is where the note
|
||||||
# on holding the conventionalcommits preset at 9 lives -- at 10 the
|
# on holding the conventionalcommits preset at 9 lives -- at 10 the
|
||||||
# release notes come out empty with everything green.
|
# release notes come out empty with everything green.
|
||||||
release-dry: ## Print the version a merge to main would release
|
release-dry: ## Print the version a release run would cut right now
|
||||||
@npx --yes \
|
@npx --yes \
|
||||||
-p semantic-release@25 \
|
-p semantic-release@25 \
|
||||||
-p @semantic-release/commit-analyzer@13 \
|
-p @semantic-release/commit-analyzer@13 \
|
||||||
|
|||||||
@@ -2,109 +2,139 @@
|
|||||||
|
|
||||||
*Music how it was meant to bee.*
|
*Music how it was meant to bee.*
|
||||||
|
|
||||||
YellowJacket is a fast, cross-platform desktop music player for your local
|
YellowJacket plays the music you already own. Point it at your folders and it
|
||||||
collection. It plays your files, keeps your library tidy, and helps you discover
|
scans them, reads the tags and the cover art, and gives you a library you can
|
||||||
and organize your music — all in a clean, responsive interface. No accounts, no
|
browse, search, queue and tidy up — on your own machine, with no account, no
|
||||||
streaming, no telemetry: just your music on your machine.
|
streaming service and no telemetry.
|
||||||
|
|
||||||
Runs on **Linux**, **macOS**, and **Windows**.
|
It plays **MP3**, **FLAC**, **OGG Vorbis** and **WAV**, on **Linux** and
|
||||||
|
**Android**, and builds from source on **macOS**.
|
||||||
|
|
||||||
## Features
|

|
||||||
|
|
||||||
### Play your music
|
## What it does
|
||||||
- Plays **MP3, FLAC, OGG Vorbis, and WAV**
|
|
||||||
- Play, pause, seek, and volume control with a mute toggle
|
|
||||||
- Gapless, glitch-free seeking backed by a read-ahead buffer
|
|
||||||
- A queue you can add to, reorder, and shuffle, with play-next support
|
|
||||||
- Shuffle and repeat (off / all / one)
|
|
||||||
- Picks up right where you left off — remembers your track, position, and volume between sessions
|
|
||||||
- Media-key and MPRIS support on Linux, so your desktop's playback controls just work
|
|
||||||
|
|
||||||
### Keep your library organized
|
**Plays your files.** Play, pause, seek and volume with a mute toggle; a
|
||||||
- Point it at your music folders and it scans them automatically
|
read-ahead buffer so seeking is instant rather than gappy; a queue you can add
|
||||||
- Reads tags and embedded cover art, and de-duplicates artwork so it isn't stored twice
|
to, reorder and shuffle, with play-next; shuffle and repeat (off / all / one).
|
||||||
- Incremental sync — only new or changed files get reprocessed, and deleted files are cleaned up
|
It remembers the track, the position and the queue between sessions, and it
|
||||||
- Browse by **album**, **artist**, or **genre**, or search across everything
|
answers your desktop's media keys — MPRIS on Linux, a media notification and
|
||||||
- Mark favorites and see what you've been listening to with play history
|
lock-screen controls on Android.
|
||||||
- Edit track tags directly when something's off
|
|
||||||
|
|
||||||
### Playlists
|
**Keeps the library tidy.** It scans the folders you give it and rescans only
|
||||||
- Create playlists, drag tracks in, and reorder them
|
what changed, so a big library costs its full scan once. It de-duplicates
|
||||||
- **Smart playlists** that build themselves from rules (by genre, rating, play count, and more)
|
embedded cover art rather than storing the same image a hundred times, notices
|
||||||
- Pin a default playlist and spot duplicate tracks at a glance
|
files that have gone away, and spots duplicate tracks. Browse by album, artist
|
||||||
|
or genre, search across everything, mark favourites, and see what you have been
|
||||||
|
playing.
|
||||||
|
|
||||||
### Discover and clean up (powered by MusicBrainz)
|
**Playlists, and playlists that write themselves.** Drag tracks in and reorder
|
||||||
- **Explore** — browse artists, releases, and genres from the MusicBrainz catalog, not just what's already in your library
|
them, or describe what you want — genre, play count, how long since you played
|
||||||
- **Auto-tag** — match your files against MusicBrainz to fill in correct artist, album, and track metadata, with a review step before anything is written
|
it — and let a smart playlist keep itself up to date.
|
||||||
- **Lyrics search** — find a track by a line you remember
|
|
||||||
|
**Explore and auto-tag, from the MusicBrainz catalog.** Explore browses artists,
|
||||||
|
releases and genres from the catalog rather than only from what you own, so an
|
||||||
|
album page can tell you that you have nine of its twelve tracks. Auto-tag
|
||||||
|
matches your files against MusicBrainz and fills in the metadata that is
|
||||||
|
missing, with a review step before anything is written to disk. Lyrics search
|
||||||
|
finds a track from a line you remember.
|
||||||
|
|
||||||
|
Explore needs its catalog, which is a one-off ~0.6 GB download from
|
||||||
|
**Settings → Search Index**. It asks first on a metered connection, and
|
||||||
|
everything else in the app works without it.
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
Download the latest build for your platform from the
|
Every download comes from the
|
||||||
[releases page](https://git.ljones.me/yonlu/yellowjacket/releases).
|
[releases page](https://git.ljones.me/yonlu/yellowjacket/releases).
|
||||||
|
|
||||||
| Platform | Download |
|
### Linux
|
||||||
|----------|----------|
|
|
||||||
| Linux | `yellowjacket-linux-amd64` |
|
|
||||||
| macOS | `yellowjacket-darwin-universal.app.zip` (Apple Silicon + Intel) |
|
|
||||||
| Windows | `yellowjacket-windows-amd64.exe` |
|
|
||||||
|
|
||||||
Prefer to build it yourself? See [Building from source](#building-from-source).
|
Download `yellowjacket-<version>-linux-amd64.tar.gz` from the latest release and
|
||||||
|
unpack it. It holds the binary, a `.desktop` entry and an icon.
|
||||||
|
|
||||||
## Getting started
|
On **Arch**, install it from the package registry instead and get updates with
|
||||||
|
the rest of your system — the one-time key import and `pacman.conf` block are in
|
||||||
|
[`packaging/arch/README.md`](packaging/arch/README.md):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo pacman -Sy yellowjacket
|
||||||
|
```
|
||||||
|
|
||||||
|
### Android
|
||||||
|
|
||||||
|
Install the APK from the release page, or from the URL below, which always
|
||||||
|
points at the newest build:
|
||||||
|
|
||||||
|
```
|
||||||
|
https://git.ljones.me/api/packages/yonlu/generic/yellowjacket-android/latest/yellowjacket.apk
|
||||||
|
```
|
||||||
|
|
||||||
|
That URL needs no credentials, so [Obtainium](https://obtainium.imranr.dev/) can
|
||||||
|
poll it directly and keep the app up to date. The build is `arm64-v8a` only, and
|
||||||
|
[`docs/android-release.md`](docs/android-release.md) says why.
|
||||||
|
|
||||||
|
### macOS
|
||||||
|
|
||||||
|
Homebrew builds it from source on your own Mac — there is no prebuilt `.app`,
|
||||||
|
because a signed macOS bundle needs a macOS machine to produce it and the
|
||||||
|
release runner is a Linux container.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
brew install shadow-puppet/yellowjacket/yellowjacket
|
||||||
|
```
|
||||||
|
|
||||||
|
See [`packaging/homebrew/README.md`](packaging/homebrew/README.md).
|
||||||
|
|
||||||
|
### Windows
|
||||||
|
|
||||||
|
Not published. It cross-compiles cleanly, but no Windows build of this app has
|
||||||
|
ever been *run*, and nothing here can exercise one — so shipping it would be a
|
||||||
|
promise that cannot be kept. You can still build it yourself: see
|
||||||
|
[`CONTRIBUTING.md`](CONTRIBUTING.md).
|
||||||
|
|
||||||
|
### Coming from a 1.x install?
|
||||||
|
|
||||||
|
Versions restarted at **0.0.1** when releases became automatic, which every
|
||||||
|
package manager reads as a downgrade. It costs one reinstall, once — the details
|
||||||
|
are with each channel: [Homebrew](packaging/homebrew/README.md#upgrading-from-1x-needs-a-reinstall-once),
|
||||||
|
[Android](docs/android-release.md#the-1x-installs-cannot-be-upgraded-to-00x).
|
||||||
|
|
||||||
|
## First run
|
||||||
|
|
||||||
1. Launch YellowJacket.
|
1. Launch YellowJacket.
|
||||||
2. Open **Settings** and add the folder(s) where your music lives.
|
2. Add the folder your music lives in — the first-run wizard asks, and
|
||||||
3. Let the initial scan finish — you'll see progress as it works.
|
**Settings → Libraries** is where you add more later.
|
||||||
4. Browse by album, artist, or genre, queue something up, and press play.
|
3. Watch the scan finish. It reports progress, and you can browse while it runs.
|
||||||
|
4. Queue something and press play.
|
||||||
|
|
||||||
Your library and settings are stored locally:
|
Your library and settings stay on your machine:
|
||||||
|
|
||||||
| | Linux / macOS | Windows |
|
| | Linux / macOS | Windows |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| Config | `~/.config/yellowjacket/` | `%LOCALAPPDATA%\yellowjacket\config` |
|
| Config | `~/.config/yellowjacket/` | `%LOCALAPPDATA%\yellowjacket\config` |
|
||||||
| Library data | `~/.local/share/yellowjacket/` | `%LOCALAPPDATA%\yellowjacket\data` |
|
| Library data | `~/.local/share/yellowjacket/` | `%LOCALAPPDATA%\yellowjacket\data` |
|
||||||
|
|
||||||
## Building from source
|
Setting `YJ_HOME` moves both, which is how you keep a second library separate.
|
||||||
|
|
||||||
YellowJacket is built with [Go](https://go.dev/) and a
|
## More screenshots
|
||||||
[Lit](https://lit.dev/)/TypeScript frontend, bridged by the
|
|
||||||
[Wails](https://wails.io/) framework.
|
|
||||||
|
|
||||||
**Prerequisites**
|
An album page knows what you own, and says so:
|
||||||
|
|
||||||
| Tool | Version |
|

|
||||||
|------|---------|
|
|
||||||
| Go | 1.25+ |
|
|
||||||
| Node.js | 22+ |
|
|
||||||
| pnpm | 10+ |
|
|
||||||
| Wails CLI | v3 — vendored, no install needed (`go tool wails3`) |
|
|
||||||
|
|
||||||
The Wails v3 CLI resolves from the `tool` block in `go.mod`, so there is nothing
|
The home page suggests somewhere to start rather than opening on a wall of
|
||||||
to install globally; `make setup` fetches it with the rest of the tooling.
|
everything:
|
||||||
|
|
||||||
On Linux, install the system libraries Wails needs. v3 builds against GTK4 +
|

|
||||||
WebKitGTK 6.0 by default:
|
|
||||||
|
|
||||||
```bash
|
## Contributing, and the rest of the documentation
|
||||||
sudo apt-get install libasound2-dev libgtk-4-dev libwebkitgtk-6.0-dev # Debian/Ubuntu
|
|
||||||
sudo pacman -S alsa-lib gtk4 webkitgtk-6.0 # Arch
|
|
||||||
```
|
|
||||||
|
|
||||||
A machine without `webkitgtk-6.0` can still build with `-tags gtk3` against the
|
- [`CONTRIBUTING.md`](CONTRIBUTING.md) — build it from source, run the tests,
|
||||||
older WebKit2GTK 4.1 stack, but that is an escape hatch, not what CI or a
|
and how a change gets in.
|
||||||
release builds.
|
- [`CLAUDE.md`](CLAUDE.md) — the deep reference: the architecture and the reasons
|
||||||
|
behind the shape of it.
|
||||||
macOS and Windows need no extra system packages. Run `go tool wails3 doctor` to
|
- [The issue tracker](https://git.ljones.me/yonlu/yellowjacket/issues) is what
|
||||||
check your environment.
|
is wanted and what is being worked on; **#73** is the roadmap.
|
||||||
|
- [Releases](https://git.ljones.me/yonlu/yellowjacket/releases) double as the
|
||||||
**Build**
|
changelog — every one is generated from the commits it contains.
|
||||||
|
|
||||||
```bash
|
|
||||||
make setup # install tooling and git hooks
|
|
||||||
make dev # run with hot-reload
|
|
||||||
make build-prod # produce a release binary
|
|
||||||
```
|
|
||||||
|
|
||||||
More detail for contributors lives in
|
|
||||||
[`docs/dev/overview.md`](./docs/dev/overview.md) and [`CLAUDE.md`](./CLAUDE.md).
|
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
//go:build android
|
||||||
|
|
||||||
|
// The write itself, and nothing else. Everything decidable off a phone
|
||||||
|
// is in androidlog.go; see the package comment for why.
|
||||||
|
|
||||||
|
package androidlog
|
||||||
|
|
||||||
|
/*
|
||||||
|
#cgo LDFLAGS: -llog
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <android/log.h>
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log/slog"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The priorities in androidlog.go are android/log.h's own values, and
|
||||||
|
// these are what says so. A constant expression that would be negative
|
||||||
|
// does not compile as a uint, so a renumbered header fails the build
|
||||||
|
// here rather than logging everything at the wrong severity -- which is
|
||||||
|
// the failure that would otherwise be invisible, since logcat would
|
||||||
|
// happily print whatever number it was handed.
|
||||||
|
const (
|
||||||
|
_ = uint(C.ANDROID_LOG_VERBOSE - PrioVerbose)
|
||||||
|
_ = uint(PrioVerbose - C.ANDROID_LOG_VERBOSE)
|
||||||
|
_ = uint(C.ANDROID_LOG_DEBUG - PrioDebug)
|
||||||
|
_ = uint(PrioDebug - C.ANDROID_LOG_DEBUG)
|
||||||
|
_ = uint(C.ANDROID_LOG_INFO - PrioInfo)
|
||||||
|
_ = uint(PrioInfo - C.ANDROID_LOG_INFO)
|
||||||
|
_ = uint(C.ANDROID_LOG_WARN - PrioWarn)
|
||||||
|
_ = uint(PrioWarn - C.ANDROID_LOG_WARN)
|
||||||
|
_ = uint(C.ANDROID_LOG_ERROR - PrioError)
|
||||||
|
_ = uint(PrioError - C.ANDROID_LOG_ERROR)
|
||||||
|
_ = uint(C.ANDROID_LOG_FATAL - PrioFatal)
|
||||||
|
_ = uint(PrioFatal - C.ANDROID_LOG_FATAL)
|
||||||
|
)
|
||||||
|
|
||||||
|
// New returns the handler main() installs on Android.
|
||||||
|
func New(opts *slog.HandlerOptions) slog.Handler {
|
||||||
|
return NewHandler(opts, write)
|
||||||
|
}
|
||||||
|
|
||||||
|
// write hands one line to liblog.
|
||||||
|
func write(prio int, tag, msg string) {
|
||||||
|
cTag := C.CString(tag)
|
||||||
|
defer C.free(unsafe.Pointer(cTag))
|
||||||
|
|
||||||
|
cMsg := C.CString(msg)
|
||||||
|
defer C.free(unsafe.Pointer(cMsg))
|
||||||
|
|
||||||
|
C.__android_log_write(C.int(prio), cTag, cMsg)
|
||||||
|
}
|
||||||
@@ -0,0 +1,250 @@
|
|||||||
|
// Package androidlog routes slog to logcat.
|
||||||
|
//
|
||||||
|
// **An Android app's fd 1 and 2 go to /dev/null**, so every line this
|
||||||
|
// app writes with slog is discarded on that platform -- including the
|
||||||
|
// one naming the error it is about to os.Exit on. #52 is what that
|
||||||
|
// cost: a process that vanished with no tombstone, no AndroidRuntime
|
||||||
|
// stack and nothing in `logcat -b crash`, at Priority/Critical for
|
||||||
|
// months, whose entire diagnosis was one slog.Error main.go was
|
||||||
|
// already writing.
|
||||||
|
//
|
||||||
|
// The platform's own sink is __android_log_write, which is a handful
|
||||||
|
// of cgo -- and cgo compiled by nothing `make lint` or `make test`
|
||||||
|
// runs, since the only toolchain that builds the android tag is a
|
||||||
|
// cross-compiler and the only thing that runs it is a phone. So the
|
||||||
|
// split here is the one backend/mediacontrols/androidpayload.go makes,
|
||||||
|
// pushed as far as it will go: **everything except the write itself is
|
||||||
|
// in this file, untagged**. The priority mapping, the formatting, the
|
||||||
|
// chunking and the handler's own attr and group bookkeeping are
|
||||||
|
// ordinary Go that `go test` exercises on any platform; android.go is
|
||||||
|
// fifteen lines that hand a string to liblog.
|
||||||
|
package androidlog
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"log/slog"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Tag is what logcat labels these lines with.
|
||||||
|
//
|
||||||
|
// It is a constant of ours rather than the application id, because the
|
||||||
|
// debug build carries `applicationIdSuffix ".dev"` so that it can be
|
||||||
|
// installed beside the release app -- so a tag derived from the package
|
||||||
|
// name is a *different* tag on the one build that can be inspected, and
|
||||||
|
// the filter that is supposed to show these lines would hide them on
|
||||||
|
// exactly the build used to look for them.
|
||||||
|
const Tag = "yellowjacket"
|
||||||
|
|
||||||
|
// Android's priorities, from android/log.h. These are the values
|
||||||
|
// __android_log_write takes; android.go asserts at compile time that
|
||||||
|
// they still match the header, so a renumbered platform is a build
|
||||||
|
// failure here rather than a warning silently logged as an error.
|
||||||
|
const (
|
||||||
|
PrioVerbose = 2
|
||||||
|
PrioDebug = 3
|
||||||
|
PrioInfo = 4
|
||||||
|
PrioWarn = 5
|
||||||
|
PrioError = 6
|
||||||
|
PrioFatal = 7
|
||||||
|
)
|
||||||
|
|
||||||
|
// maxPayload is how much of one line liblog will carry.
|
||||||
|
//
|
||||||
|
// The kernel logger's entry is 4068 bytes for the tag, the message and
|
||||||
|
// their two NULs together, and what does not fit is **dropped without
|
||||||
|
// comment** -- so a long line would be truncated in the middle of the
|
||||||
|
// thing worth reading. 3500 leaves room for the tag and for the "(N/M)"
|
||||||
|
// a continuation carries.
|
||||||
|
const maxPayload = 3500
|
||||||
|
|
||||||
|
// WriteFunc is the platform sink: one already-formatted line, at one
|
||||||
|
// priority, under one tag.
|
||||||
|
//
|
||||||
|
// It is a parameter rather than a package-level function so that the
|
||||||
|
// handler can be driven by a test on a machine with no liblog at all.
|
||||||
|
type WriteFunc func(prio int, tag, msg string)
|
||||||
|
|
||||||
|
// Priority maps a slog level onto an Android one.
|
||||||
|
//
|
||||||
|
// slog's levels are open -- a caller may define its own at any int --
|
||||||
|
// so this is a banding rather than a lookup: anything below Info is
|
||||||
|
// debug, anything at or above Error is error. A custom level between
|
||||||
|
// two of the standard ones lands in the band beneath it, which is what
|
||||||
|
// slog's own level naming does.
|
||||||
|
func Priority(level slog.Level) int {
|
||||||
|
switch {
|
||||||
|
case level < slog.LevelDebug:
|
||||||
|
return PrioVerbose
|
||||||
|
case level < slog.LevelInfo:
|
||||||
|
return PrioDebug
|
||||||
|
case level < slog.LevelWarn:
|
||||||
|
return PrioInfo
|
||||||
|
case level < slog.LevelError:
|
||||||
|
return PrioWarn
|
||||||
|
default:
|
||||||
|
return PrioError
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handler formats records with slog's own TextHandler and hands each
|
||||||
|
// line to a WriteFunc.
|
||||||
|
//
|
||||||
|
// It delegates the formatting rather than doing it, because WithAttrs
|
||||||
|
// and WithGroup are the half of slog.Handler that is easy to get subtly
|
||||||
|
// wrong -- and a logger whose groups are wrong is a logger nobody reads.
|
||||||
|
// What it does own is what logcat needs and TextHandler does not know
|
||||||
|
// about: the priority, and the fact that a line has a maximum length.
|
||||||
|
type Handler struct {
|
||||||
|
write WriteFunc
|
||||||
|
|
||||||
|
// mu guards buf, which the delegate writes into. slog.Handler is
|
||||||
|
// documented as safe for concurrent use.
|
||||||
|
mu *sync.Mutex
|
||||||
|
buf *bytes.Buffer
|
||||||
|
delegate slog.Handler
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewHandler builds a handler over an arbitrary sink.
|
||||||
|
//
|
||||||
|
// The time and the level are dropped from the formatted line: logcat
|
||||||
|
// stamps every entry with both, and repeating them costs a quarter of
|
||||||
|
// the width of a phone-sized terminal to say the same thing twice.
|
||||||
|
func NewHandler(opts *slog.HandlerOptions, write WriteFunc) *Handler {
|
||||||
|
buf := &bytes.Buffer{}
|
||||||
|
|
||||||
|
inner := &slog.HandlerOptions{}
|
||||||
|
if opts != nil {
|
||||||
|
*inner = *opts
|
||||||
|
}
|
||||||
|
|
||||||
|
user := inner.ReplaceAttr
|
||||||
|
inner.ReplaceAttr = func(groups []string, a slog.Attr) slog.Attr {
|
||||||
|
if len(groups) == 0 && isBuiltin(a) {
|
||||||
|
return slog.Attr{}
|
||||||
|
}
|
||||||
|
|
||||||
|
if user != nil {
|
||||||
|
return user(groups, a)
|
||||||
|
}
|
||||||
|
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Handler{
|
||||||
|
write: write,
|
||||||
|
mu: &sync.Mutex{},
|
||||||
|
buf: buf,
|
||||||
|
delegate: slog.NewTextHandler(buf, inner),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// isBuiltin reports whether an attr is slog's own time or level,
|
||||||
|
// rather than a caller's attribute that happens to share the name.
|
||||||
|
//
|
||||||
|
// ReplaceAttr cannot tell those apart by key. It is called with an
|
||||||
|
// empty group path for the built-ins *and* for every top-level
|
||||||
|
// attribute, so a key comparison alone silently eats a caller's own
|
||||||
|
// "level" or "time" -- which is not hypothetical: the probe that
|
||||||
|
// verified this package on the device logged one, and the attribute
|
||||||
|
// vanished. The kinds are what separate them, because slog builds the
|
||||||
|
// built-ins as slog.Any(LevelKey, r.Level) and slog.Time(TimeKey, ...)
|
||||||
|
// and an attribute value of type slog.Level is not something a caller
|
||||||
|
// passes by accident.
|
||||||
|
func isBuiltin(a slog.Attr) bool {
|
||||||
|
switch a.Key {
|
||||||
|
case slog.TimeKey:
|
||||||
|
return a.Value.Kind() == slog.KindTime
|
||||||
|
case slog.LevelKey:
|
||||||
|
_, ok := a.Value.Any().(slog.Level)
|
||||||
|
|
||||||
|
return ok
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enabled reports whether the level is worth formatting.
|
||||||
|
func (h *Handler) Enabled(ctx context.Context, level slog.Level) bool {
|
||||||
|
return h.delegate.Enabled(ctx, level)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle formats one record and writes it out, in as many entries as
|
||||||
|
// its length demands.
|
||||||
|
func (h *Handler) Handle(ctx context.Context, rec slog.Record) error {
|
||||||
|
h.mu.Lock()
|
||||||
|
defer h.mu.Unlock()
|
||||||
|
|
||||||
|
h.buf.Reset()
|
||||||
|
|
||||||
|
if err := h.delegate.Handle(ctx, rec); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
prio := Priority(rec.Level)
|
||||||
|
for _, line := range Chunk(strings.TrimRight(h.buf.String(), "\n")) {
|
||||||
|
h.write(prio, Tag, line)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithAttrs returns a handler carrying the given attributes.
|
||||||
|
func (h *Handler) WithAttrs(attrs []slog.Attr) slog.Handler {
|
||||||
|
return h.derive(h.delegate.WithAttrs(attrs))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithGroup returns a handler that qualifies subsequent attributes.
|
||||||
|
func (h *Handler) WithGroup(name string) slog.Handler {
|
||||||
|
return h.derive(h.delegate.WithGroup(name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// derive shares the buffer and its mutex with the parent.
|
||||||
|
//
|
||||||
|
// They must be shared rather than copied: the delegate returned by
|
||||||
|
// WithAttrs writes into the *same* buffer this one does, so a second
|
||||||
|
// mutex would guard nothing and two loggers derived from one would
|
||||||
|
// interleave their bytes into a single line.
|
||||||
|
func (h *Handler) derive(delegate slog.Handler) *Handler {
|
||||||
|
return &Handler{
|
||||||
|
write: h.write,
|
||||||
|
mu: h.mu,
|
||||||
|
buf: h.buf,
|
||||||
|
delegate: delegate,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chunk splits a formatted record into entries liblog will carry
|
||||||
|
// whole.
|
||||||
|
//
|
||||||
|
// A record short enough to fit is returned as it is, which is nearly
|
||||||
|
// every record; the numbering only appears where something was going
|
||||||
|
// to be silently truncated anyway. It splits on bytes rather than runes
|
||||||
|
// because the limit is a byte count -- a multi-byte rune straddling the
|
||||||
|
// boundary is a mojibake character in a log line, against a lost one.
|
||||||
|
func Chunk(msg string) []string {
|
||||||
|
if len(msg) <= maxPayload {
|
||||||
|
return []string{msg}
|
||||||
|
}
|
||||||
|
|
||||||
|
var parts []string
|
||||||
|
|
||||||
|
for rest := msg; rest != ""; {
|
||||||
|
n := min(maxPayload, len(rest))
|
||||||
|
parts = append(parts, rest[:n])
|
||||||
|
rest = rest[n:]
|
||||||
|
}
|
||||||
|
|
||||||
|
numbered := make([]string, 0, len(parts))
|
||||||
|
for i, p := range parts {
|
||||||
|
numbered = append(
|
||||||
|
numbered,
|
||||||
|
"("+strconv.Itoa(i+1)+"/"+strconv.Itoa(len(parts))+") "+p,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return numbered
|
||||||
|
}
|
||||||
@@ -0,0 +1,355 @@
|
|||||||
|
package androidlog_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log/slog"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"yellowjacket/backend/androidlog"
|
||||||
|
)
|
||||||
|
|
||||||
|
// entry is one call to the sink.
|
||||||
|
type entry struct {
|
||||||
|
prio int
|
||||||
|
tag string
|
||||||
|
msg string
|
||||||
|
}
|
||||||
|
|
||||||
|
// recorder is the platform write, on a machine with no platform.
|
||||||
|
type recorder struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
entries []entry
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *recorder) write(prio int, tag, msg string) {
|
||||||
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
|
|
||||||
|
r.entries = append(r.entries, entry{prio: prio, tag: tag, msg: msg})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *recorder) only(t *testing.T) entry {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
r.mu.Lock()
|
||||||
|
defer r.mu.Unlock()
|
||||||
|
|
||||||
|
if len(r.entries) != 1 {
|
||||||
|
t.Fatalf("want exactly one entry, got %d: %v", len(r.entries), r.entries)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.entries[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
func newLogger(r *recorder, level slog.Level) *slog.Logger {
|
||||||
|
return slog.New(androidlog.NewHandler(
|
||||||
|
&slog.HandlerOptions{Level: level},
|
||||||
|
r.write,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestPriorityMapsEveryLevel pins the level banding.
|
||||||
|
//
|
||||||
|
// This is the one thing in #160 that a wrong answer hides rather than
|
||||||
|
// breaks: logcat prints whatever priority it is handed, so an Error
|
||||||
|
// filed as Info is a line that is present, correct and invisible to
|
||||||
|
// every filter anyone would use to look for it.
|
||||||
|
func TestPriorityMapsEveryLevel(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
level slog.Level
|
||||||
|
want int
|
||||||
|
}{
|
||||||
|
{"below debug is verbose", slog.LevelDebug - 1, androidlog.PrioVerbose},
|
||||||
|
{"debug", slog.LevelDebug, androidlog.PrioDebug},
|
||||||
|
{"info", slog.LevelInfo, androidlog.PrioInfo},
|
||||||
|
{"warn", slog.LevelWarn, androidlog.PrioWarn},
|
||||||
|
{"error", slog.LevelError, androidlog.PrioError},
|
||||||
|
|
||||||
|
// slog's levels are open, so a caller may sit between two of
|
||||||
|
// the named ones. Each lands in the band beneath it, which is
|
||||||
|
// what slog's own level naming does ("INFO+2").
|
||||||
|
{"between info and warn", slog.LevelInfo + 2, androidlog.PrioInfo},
|
||||||
|
{"between warn and error", slog.LevelWarn + 1, androidlog.PrioWarn},
|
||||||
|
{"above error", slog.LevelError + 4, androidlog.PrioError},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
if got := androidlog.Priority(tt.level); got != tt.want {
|
||||||
|
t.Errorf("Priority(%v) = %d, want %d", tt.level, got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestPrioritiesAreTheHeadersValues pins the constants themselves.
|
||||||
|
//
|
||||||
|
// android.go asserts these against android/log.h at compile time, but
|
||||||
|
// only a cross-compiler ever builds that file. This is the assertion
|
||||||
|
// that runs in CI, and the numbers are written out longhand on purpose
|
||||||
|
// -- comparing a constant to itself would pass on any renumbering.
|
||||||
|
func TestPrioritiesAreTheHeadersValues(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
for _, tt := range []struct {
|
||||||
|
name string
|
||||||
|
got int
|
||||||
|
want int
|
||||||
|
}{
|
||||||
|
{"verbose", androidlog.PrioVerbose, 2},
|
||||||
|
{"debug", androidlog.PrioDebug, 3},
|
||||||
|
{"info", androidlog.PrioInfo, 4},
|
||||||
|
{"warn", androidlog.PrioWarn, 5},
|
||||||
|
{"error", androidlog.PrioError, 6},
|
||||||
|
{"fatal", androidlog.PrioFatal, 7},
|
||||||
|
} {
|
||||||
|
if tt.got != tt.want {
|
||||||
|
t.Errorf("%s priority = %d, want %d", tt.name, tt.got, tt.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestRecordReachesTheSink is the whole point of the package: a line
|
||||||
|
// written with slog arrives, under the app's tag, at the right
|
||||||
|
// priority.
|
||||||
|
func TestRecordReachesTheSink(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
rec := &recorder{}
|
||||||
|
newLogger(rec, slog.LevelInfo).Error("application error", "err", "boom")
|
||||||
|
|
||||||
|
got := rec.only(t)
|
||||||
|
|
||||||
|
if got.prio != androidlog.PrioError {
|
||||||
|
t.Errorf("priority = %d, want %d", got.prio, androidlog.PrioError)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got.tag != androidlog.Tag {
|
||||||
|
t.Errorf("tag = %q, want %q", got.tag, androidlog.Tag)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(got.msg, "application error") {
|
||||||
|
t.Errorf("message %q does not carry the message", got.msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(got.msg, `err=boom`) {
|
||||||
|
t.Errorf("message %q does not carry the attribute", got.msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestTheTagIsNotTheApplicationID guards the trap the tag exists to
|
||||||
|
// avoid.
|
||||||
|
//
|
||||||
|
// The debug build carries `applicationIdSuffix ".dev"`, so it is
|
||||||
|
// installed as app.yellowjacket.dev -- and it is the *only* build whose
|
||||||
|
// WebView can be inspected, so it is the build anyone debugging this
|
||||||
|
// app is running. A tag derived from the application id therefore
|
||||||
|
// differs between the build being looked at and the build the filter
|
||||||
|
// was written for, which is the failure this whole issue is about
|
||||||
|
// wearing a different hat.
|
||||||
|
func TestTheTagIsNotTheApplicationID(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
if strings.Contains(androidlog.Tag, ".") {
|
||||||
|
t.Errorf(
|
||||||
|
"tag %q looks like an application id; it must be stable "+
|
||||||
|
"across the debug suffix",
|
||||||
|
androidlog.Tag,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logcat's tag field is 23 bytes. A longer one is truncated, and a
|
||||||
|
// truncated tag matches no filter.
|
||||||
|
if len(androidlog.Tag) > 23 {
|
||||||
|
t.Errorf("tag %q is %d bytes, over logcat's 23", androidlog.Tag, len(androidlog.Tag))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestTimeAndLevelAreDropped checks the formatting decision.
|
||||||
|
//
|
||||||
|
// logcat stamps every entry with a timestamp and a priority letter, so
|
||||||
|
// carrying slog's own is the same information twice on a 424px screen.
|
||||||
|
func TestTimeAndLevelAreDropped(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
rec := &recorder{}
|
||||||
|
newLogger(rec, slog.LevelInfo).Warn("scan finished", "files", 1577)
|
||||||
|
|
||||||
|
got := rec.only(t).msg
|
||||||
|
|
||||||
|
if strings.Contains(got, "time=") {
|
||||||
|
t.Errorf("message %q still carries a timestamp", got)
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.Contains(got, "level=") {
|
||||||
|
t.Errorf("message %q still carries a level", got)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(got, "files=1577") {
|
||||||
|
t.Errorf("message %q lost its attributes with them", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestACallersOwnLevelAttrSurvives is a regression, and it was found on
|
||||||
|
// the phone rather than here.
|
||||||
|
//
|
||||||
|
// Dropping slog's built-in time and level by key alone also drops a
|
||||||
|
// caller's attribute of the same name, because ReplaceAttr sees an
|
||||||
|
// empty group path for both. The probe that verified this package on
|
||||||
|
// the device wrote slog.Info("...", "level", "info") and logcat showed
|
||||||
|
// the message with no attributes at all.
|
||||||
|
func TestACallersOwnLevelAttrSurvives(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
rec := &recorder{}
|
||||||
|
newLogger(rec, slog.LevelInfo).Info("probe", "level", "info", "time", "soon")
|
||||||
|
|
||||||
|
got := rec.only(t).msg
|
||||||
|
|
||||||
|
for _, want := range []string{"level=info", "time=soon"} {
|
||||||
|
if !strings.Contains(got, want) {
|
||||||
|
t.Errorf("message %q lost the caller's %q", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// And slog's own are still gone: the built-in level renders as a
|
||||||
|
// bare word like INFO, never as the caller's value.
|
||||||
|
if strings.Contains(got, "level=INFO") {
|
||||||
|
t.Errorf("message %q carries slog's own level", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestLevelIsHonoured checks that Enabled reaches the delegate.
|
||||||
|
func TestLevelIsHonoured(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
rec := &recorder{}
|
||||||
|
log := newLogger(rec, slog.LevelWarn)
|
||||||
|
|
||||||
|
log.Info("not this one")
|
||||||
|
log.Warn("this one")
|
||||||
|
|
||||||
|
if got := rec.only(t).msg; !strings.Contains(got, "this one") {
|
||||||
|
t.Errorf("wrong record survived: %q", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestGroupsAndAttrsSurvive covers the half of slog.Handler this
|
||||||
|
// delegates rather than implements -- the reason it delegates at all.
|
||||||
|
func TestGroupsAndAttrsSurvive(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
rec := &recorder{}
|
||||||
|
log := newLogger(rec, slog.LevelInfo).
|
||||||
|
With("component", "player").
|
||||||
|
WithGroup("track")
|
||||||
|
|
||||||
|
log.Info("loaded", "path", "/sdcard/Music/a.flac")
|
||||||
|
|
||||||
|
got := rec.only(t).msg
|
||||||
|
|
||||||
|
for _, want := range []string{
|
||||||
|
"component=player",
|
||||||
|
"track.path=/sdcard/Music/a.flac",
|
||||||
|
} {
|
||||||
|
if !strings.Contains(got, want) {
|
||||||
|
t.Errorf("message %q is missing %q", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestDerivedHandlersDoNotInterleave is why derive shares the buffer's
|
||||||
|
// mutex rather than taking a new one.
|
||||||
|
//
|
||||||
|
// Two loggers derived from one write into the same buffer, so a second
|
||||||
|
// mutex would guard nothing and a concurrent pair would splice each
|
||||||
|
// other's bytes into a single line -- which reads as corrupted logs
|
||||||
|
// under load and as nothing at all in a test that logs once.
|
||||||
|
func TestDerivedHandlersDoNotInterleave(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
rec := &recorder{}
|
||||||
|
base := newLogger(rec, slog.LevelInfo)
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
|
for i := range 8 {
|
||||||
|
wg.Add(1)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
|
log := base.With("worker", i).WithGroup("g")
|
||||||
|
for range 50 {
|
||||||
|
log.Info("tick", "n", i)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
rec.mu.Lock()
|
||||||
|
defer rec.mu.Unlock()
|
||||||
|
|
||||||
|
if len(rec.entries) != 8*50 {
|
||||||
|
t.Fatalf("got %d entries, want %d", len(rec.entries), 8*50)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, e := range rec.entries {
|
||||||
|
if strings.Count(e.msg, "msg=tick") != 1 {
|
||||||
|
t.Fatalf("interleaved line: %q", e.msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestChunkLeavesShortLinesAlone is the common case: no numbering
|
||||||
|
// appears on a record that was never going to be truncated.
|
||||||
|
func TestChunkLeavesShortLinesAlone(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
got := androidlog.Chunk("msg=short")
|
||||||
|
|
||||||
|
if len(got) != 1 || got[0] != "msg=short" {
|
||||||
|
t.Errorf("Chunk(short) = %q, want the input unchanged", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestChunkSplitsWhatWouldBeTruncated covers the case liblog drops
|
||||||
|
// silently.
|
||||||
|
func TestChunkSplitsWhatWouldBeTruncated(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
const n = 9000
|
||||||
|
|
||||||
|
long := strings.Repeat("x", n)
|
||||||
|
parts := androidlog.Chunk(long)
|
||||||
|
|
||||||
|
if len(parts) < 2 {
|
||||||
|
t.Fatalf("a %d-byte line was not split", n)
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload strings.Builder
|
||||||
|
|
||||||
|
for i, p := range parts {
|
||||||
|
if len(p) > 4000 {
|
||||||
|
t.Errorf("part %d is %d bytes, over liblog's entry", i, len(p))
|
||||||
|
}
|
||||||
|
|
||||||
|
_, rest, found := strings.Cut(p, ") ")
|
||||||
|
if !found {
|
||||||
|
t.Fatalf("part %d carries no (n/m) marker: %q", i, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
payload.WriteString(rest)
|
||||||
|
}
|
||||||
|
|
||||||
|
if payload.String() != long {
|
||||||
|
t.Errorf("the parts do not reassemble into the input")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -499,6 +499,10 @@ func (yj *YellowJacketApp) OnStartup(ctx context.Context) {
|
|||||||
PostRemove: yj.explore.InvalidateLibrarySync,
|
PostRemove: yj.explore.InvalidateLibrarySync,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// A deleted playlist must not leave the queue's "Playing from"
|
||||||
|
// label pointing at it.
|
||||||
|
yj.playlist.SetOnPlaylistDeleted(yj.queue.DropSourceForPlaylist)
|
||||||
|
|
||||||
// Register playback finished handler to drive queue auto-advance.
|
// Register playback finished handler to drive queue auto-advance.
|
||||||
yj.player.SetPlaybackFinishedHandler(yj.queue.OnPlaybackFinished)
|
yj.player.SetPlaybackFinishedHandler(yj.queue.OnPlaybackFinished)
|
||||||
|
|
||||||
@@ -775,6 +779,8 @@ func (yj *YellowJacketApp) startJanitor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
yj.janitor.Register(maintenance.ExpiredHTTPCacheJob(yj.database))
|
yj.janitor.Register(maintenance.ExpiredHTTPCacheJob(yj.database))
|
||||||
|
yj.janitor.Register(maintenance.StaleArtistMetadataJob(yj.database))
|
||||||
|
yj.janitor.Register(maintenance.StaleSearchClicksJob(yj.database))
|
||||||
yj.janitor.Register(maintenance.OrphanedCoverFilesJob(
|
yj.janitor.Register(maintenance.OrphanedCoverFilesJob(
|
||||||
yj.database, coversDir, library.CoverArtFileSet,
|
yj.database, coversDir, library.CoverArtFileSet,
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
|
|
||||||
"yellowjacket/backend/database/sql/sqlcgen"
|
"yellowjacket/backend/database/sql/sqlcgen"
|
||||||
|
"yellowjacket/backend/tagtotals"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TagChanges mirrors tagwriter.TagChanges — redefined here so the
|
// TagChanges mirrors tagwriter.TagChanges — redefined here so the
|
||||||
@@ -28,6 +29,8 @@ const (
|
|||||||
FieldYear = "year"
|
FieldYear = "year"
|
||||||
FieldTrackNumber = "track_number"
|
FieldTrackNumber = "track_number"
|
||||||
FieldDiscNumber = "disc_number"
|
FieldDiscNumber = "disc_number"
|
||||||
|
FieldTotalTracks = "total_tracks"
|
||||||
|
FieldTotalDiscs = "total_discs"
|
||||||
FieldCoverArt = "cover_art"
|
FieldCoverArt = "cover_art"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -418,5 +421,32 @@ func buildChanges(
|
|||||||
changes[FieldDiscNumber] = track.DiscNumber
|
changes[FieldDiscNumber] = track.DiscNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The totals are what says "2 of 10" rather than a bare tick, and
|
||||||
|
// dropping them here is what made autotagging an album *erase* the
|
||||||
|
// evidence: the release becomes MBID-matched while the field
|
||||||
|
// GetAlbumCompleteness reads stays absent.
|
||||||
|
//
|
||||||
|
// They are written unconditionally where the candidate has a
|
||||||
|
// tracklist, not only when they differ from the local value, because
|
||||||
|
// the common case is a file that declares no total at all -- which
|
||||||
|
// compares equal to nothing and would be skipped by a diff guard.
|
||||||
|
if tracks, discs := tagtotals.For(
|
||||||
|
candidatePositions(cand), track.DiscNumber,
|
||||||
|
); tracks > 0 {
|
||||||
|
changes[FieldTotalTracks] = tracks
|
||||||
|
changes[FieldTotalDiscs] = discs
|
||||||
|
}
|
||||||
|
|
||||||
return changes
|
return changes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// candidatePositions is the candidate's tracklist as bare positions.
|
||||||
|
func candidatePositions(cand Candidate) []tagtotals.Position {
|
||||||
|
out := make([]tagtotals.Position, 0, len(cand.Tracks))
|
||||||
|
|
||||||
|
for _, t := range cand.Tracks {
|
||||||
|
out = append(out, tagtotals.Position{Disc: t.DiscNumber, Track: t.Position})
|
||||||
|
}
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package autotag
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
// Autotagging an album used to *erase* the evidence that says "2 of 10":
|
||||||
|
// the release became MBID-matched while the totals the files declared
|
||||||
|
// went unwritten, so the album page showed a plain tick. These pin the
|
||||||
|
// two halves of the fix that are easy to get wrong silently.
|
||||||
|
func TestBuildChanges_Totals(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
twoDiscs := Candidate{
|
||||||
|
Tracks: []CandidateTrack{
|
||||||
|
{DiscNumber: 1, Position: 1},
|
||||||
|
{DiscNumber: 1, Position: 2},
|
||||||
|
{DiscNumber: 2, Position: 1},
|
||||||
|
{DiscNumber: 2, Position: 2},
|
||||||
|
{DiscNumber: 2, Position: 3},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
cand Candidate
|
||||||
|
local LocalTrack
|
||||||
|
track CandidateTrack
|
||||||
|
wantTracks any
|
||||||
|
wantDiscs any
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
// The common case, and the one a diff guard would skip: the
|
||||||
|
// file declares no total at all, so the total "has not
|
||||||
|
// changed" and would never be written.
|
||||||
|
name: "a file with no total gets one",
|
||||||
|
cand: Candidate{Tracks: []CandidateTrack{
|
||||||
|
{Position: 1}, {Position: 2}, {Position: 3},
|
||||||
|
}},
|
||||||
|
local: LocalTrack{TrackNumber: 1},
|
||||||
|
track: CandidateTrack{Position: 1},
|
||||||
|
wantTracks: 3,
|
||||||
|
wantDiscs: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// 5 here would be the release's track count. Summed once
|
||||||
|
// per disc by GetAlbumCompleteness that claims a ten-track
|
||||||
|
// expectation for a five-track album, which no library can
|
||||||
|
// ever satisfy.
|
||||||
|
name: "a multi-disc release totals the track's own disc",
|
||||||
|
cand: twoDiscs,
|
||||||
|
local: LocalTrack{},
|
||||||
|
track: CandidateTrack{DiscNumber: 2, Position: 1},
|
||||||
|
wantTracks: 3,
|
||||||
|
wantDiscs: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "the other disc gets its own total",
|
||||||
|
cand: twoDiscs,
|
||||||
|
local: LocalTrack{},
|
||||||
|
track: CandidateTrack{DiscNumber: 1, Position: 1},
|
||||||
|
wantTracks: 2,
|
||||||
|
wantDiscs: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// A candidate with no tracklist knows nothing, and writing
|
||||||
|
// a zero would claim it did.
|
||||||
|
name: "a candidate with no tracklist writes no total",
|
||||||
|
cand: Candidate{},
|
||||||
|
local: LocalTrack{},
|
||||||
|
track: CandidateTrack{Position: 1},
|
||||||
|
wantTracks: nil,
|
||||||
|
wantDiscs: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range tests {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
changes := buildChanges(tc.local, tc.cand, tc.track)
|
||||||
|
|
||||||
|
if got := changes[FieldTotalTracks]; got != tc.wantTracks {
|
||||||
|
t.Errorf("%s: got %v, want %v", FieldTotalTracks, got, tc.wantTracks)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got := changes[FieldTotalDiscs]; got != tc.wantDiscs {
|
||||||
|
t.Errorf("%s: got %v, want %v", FieldTotalDiscs, got, tc.wantDiscs)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,34 @@ const (
|
|||||||
RecommendationStrong Recommendation = "strong"
|
RecommendationStrong Recommendation = "strong"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ConfidentTier is the tier at which this package considers a match
|
||||||
|
// good enough to act on without being asked to look.
|
||||||
|
//
|
||||||
|
// It exists as a name rather than as `== RecommendationStrong` at
|
||||||
|
// each call site because two features read it and they must not
|
||||||
|
// disagree about what "high confidence" means: the album page tells
|
||||||
|
// the user unprompted that the autotagger has a match (#28), and
|
||||||
|
// strict auto-accept will rewrite the files without asking (#90).
|
||||||
|
// A page that says "we are sure" about something the auto-accept
|
||||||
|
// pass would decline is the app contradicting itself.
|
||||||
|
//
|
||||||
|
// What the two do *not* share is everything else. Surfacing a match
|
||||||
|
// is a suggestion with a confirm dialog behind it; auto-accept is an
|
||||||
|
// irreversible on-disk rewrite, and #90 gates it on further
|
||||||
|
// conditions this tier cannot express — exact track count, every
|
||||||
|
// title matching, lengths within a couple of seconds, no cover
|
||||||
|
// replacement, no MBID conflict. So this is the floor both stand on,
|
||||||
|
// not the whole of either test.
|
||||||
|
const ConfidentTier = RecommendationStrong
|
||||||
|
|
||||||
|
// Confident reports whether a tier clears ConfidentTier.
|
||||||
|
//
|
||||||
|
// A comparison rather than an equality, so adding a tier above
|
||||||
|
// "strong" later does not silently stop qualifying.
|
||||||
|
func Confident(r Recommendation) bool {
|
||||||
|
return recommendationRank(r) >= recommendationRank(ConfidentTier)
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Absolute score tiers.
|
// Absolute score tiers.
|
||||||
strongScoreThresh = 0.90
|
strongScoreThresh = 0.90
|
||||||
|
|||||||
@@ -168,3 +168,34 @@ func TestRecommend_LocalCandidatesWithoutRGMBIDCompareByTitle(t *testing.T) {
|
|||||||
t.Errorf("different-title rival: Recommend = %q, want medium", got)
|
t.Errorf("different-title rival: Recommend = %q, want medium", got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The tier both features stand on is one name, checked here rather
|
||||||
|
// than assumed at two call sites.
|
||||||
|
//
|
||||||
|
// #28 renders "we have a match for this album" on the album page and
|
||||||
|
// #90 will rewrite files without asking; a page that claims confidence
|
||||||
|
// the auto-accept pass would decline is the app contradicting itself.
|
||||||
|
// What they do not share is everything else — auto-accept adds gates
|
||||||
|
// this tier cannot express — so this pins the floor, not the whole of
|
||||||
|
// either test.
|
||||||
|
func TestConfidentIsTheOneSharedFloor(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
if ConfidentTier != RecommendationStrong {
|
||||||
|
t.Errorf("ConfidentTier = %q, want strong", ConfidentTier)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range []struct {
|
||||||
|
rec Recommendation
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{RecommendationNone, false},
|
||||||
|
{RecommendationLow, false},
|
||||||
|
{RecommendationMedium, false},
|
||||||
|
{RecommendationStrong, true},
|
||||||
|
} {
|
||||||
|
if got := Confident(tc.rec); got != tc.want {
|
||||||
|
t.Errorf("Confident(%q) = %v, want %v", tc.rec, got, tc.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,145 @@
|
|||||||
|
package autotagservice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"yellowjacket/backend/autotag"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AlbumMatchView is "the autotagger already has a confident match for
|
||||||
|
// the album you are looking at".
|
||||||
|
//
|
||||||
|
// It is deliberately not a score. The album page renders a suggestion,
|
||||||
|
// and a suggestion has to be actionable: which release, what it is
|
||||||
|
// called, and whether acting on it here would do the whole album or
|
||||||
|
// only part of it.
|
||||||
|
type AlbumMatchView struct {
|
||||||
|
// GroupKey is the tagging group the actions operate on.
|
||||||
|
GroupKey string `json:"groupKey"`
|
||||||
|
|
||||||
|
// Recommendation is the tier, as a string, for a caller that
|
||||||
|
// wants to render the strength rather than trust the filter.
|
||||||
|
Recommendation string `json:"recommendation"`
|
||||||
|
|
||||||
|
// Score is the top candidate's raw score, 0..1.
|
||||||
|
Score float64 `json:"score"`
|
||||||
|
|
||||||
|
// ReleaseMBID is the release Apply would write.
|
||||||
|
ReleaseMBID string `json:"releaseMbid"`
|
||||||
|
|
||||||
|
// Title and ArtistCredit name that release, so the banner can say
|
||||||
|
// what it is offering rather than "a match".
|
||||||
|
Title string `json:"title"`
|
||||||
|
ArtistCredit string `json:"artistCredit"`
|
||||||
|
|
||||||
|
// TrackCount is the group's local track count.
|
||||||
|
TrackCount int64 `json:"trackCount"`
|
||||||
|
|
||||||
|
// GroupCount is how many tagging groups this album spans.
|
||||||
|
//
|
||||||
|
// More than one means a multi-disc album (one group per disc), and
|
||||||
|
// it is the reason this is a field rather than an implementation
|
||||||
|
// detail: applying "the album" from a single button would retag
|
||||||
|
// one disc of three and leave the folder holding a mix of old and
|
||||||
|
// new tags. The caller offers review instead.
|
||||||
|
GroupCount int `json:"groupCount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MatchForAlbum answers "does the autotagger have something confident
|
||||||
|
// to say about this album", for the album detail page.
|
||||||
|
//
|
||||||
|
// Three things about it are load-bearing.
|
||||||
|
//
|
||||||
|
// **It costs no MusicBrainz request.** Everything it needs is already
|
||||||
|
// on disk: `tagging_items` carries the top score and release from the
|
||||||
|
// background prefetch, and `tagging_candidates` durably holds the
|
||||||
|
// scored list. The rate limiters here are shared with every page the
|
||||||
|
// user can open, so a lookup that fires on page load must not join
|
||||||
|
// that queue — which also means this returns nothing for a folder
|
||||||
|
// nobody has scored yet, rather than scoring it now. That is the
|
||||||
|
// right trade: the prefetch will get to it, and a page that silently
|
||||||
|
// spends a minute of somebody's MusicBrainz budget to draw a banner
|
||||||
|
// is worse than a page that says nothing.
|
||||||
|
//
|
||||||
|
// **The tier is computed, not read.** `tagging_items.score` is the raw
|
||||||
|
// number and `Recommend` is what turns it into a claim — capping it
|
||||||
|
// for an ambiguous runner-up, an incomplete alignment or a folder too
|
||||||
|
// small to corroborate itself. Filtering on the raw score would
|
||||||
|
// promise confidence the scorer had explicitly withheld.
|
||||||
|
//
|
||||||
|
// **Nothing is said about an album the user has already answered
|
||||||
|
// for.** Only a `pending` group qualifies: `confirmed` covers both a
|
||||||
|
// finished apply and an explicit "leave as is", and `skipped` is the
|
||||||
|
// user saying not now. Re-offering either is nagging, and "leave as
|
||||||
|
// is" would be actively wrong to argue with.
|
||||||
|
func (s *Service) MatchForAlbum(albumID int64) (*AlbumMatchView, error) {
|
||||||
|
if albumID <= 0 {
|
||||||
|
return nil, nil //nolint:nilnil // "no album" is not an error.
|
||||||
|
}
|
||||||
|
|
||||||
|
rows, err := s.db.Queries.GetTaggingItemsForAlbum(
|
||||||
|
s.ctx, sql.NullInt64{Int64: albumID, Valid: true},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("tagging items for album: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
pending := rows[:0:0]
|
||||||
|
|
||||||
|
for _, row := range rows {
|
||||||
|
if row.Status == "pending" {
|
||||||
|
pending = append(pending, row)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(pending) == 0 {
|
||||||
|
return nil, nil //nolint:nilnil // nothing to say is not an error.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rows arrive best-score-first, so the first pending one is the
|
||||||
|
// group worth describing. On a multi-disc album that is one disc
|
||||||
|
// of several and GroupCount says so.
|
||||||
|
best := pending[0]
|
||||||
|
|
||||||
|
cands := s.lookupCachedCandidates(best.GroupKey)
|
||||||
|
if len(cands) == 0 {
|
||||||
|
return nil, nil //nolint:nilnil // not scored yet; see the doc comment.
|
||||||
|
}
|
||||||
|
|
||||||
|
locals, err := s.scorer.LocalTracksForGroup(s.ctx, best.GroupKey)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("local tracks for group: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
group := autotag.Group{
|
||||||
|
AlbumName: best.AlbumName,
|
||||||
|
AlbumArtist: best.AlbumArtist,
|
||||||
|
Tracks: locals,
|
||||||
|
Synthetic: best.Synthetic != 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
rec := autotag.Recommend(group, cands)
|
||||||
|
if !autotag.Confident(rec) {
|
||||||
|
return nil, nil //nolint:nilnil // not confident enough to interrupt.
|
||||||
|
}
|
||||||
|
|
||||||
|
top := cands[0]
|
||||||
|
|
||||||
|
// The release the banner names must be the release Apply would
|
||||||
|
// write. Apply with an empty MBID takes the top cached candidate,
|
||||||
|
// which is what this reads — but it is passed explicitly anyway,
|
||||||
|
// so a rescore between the page rendering and the user clicking
|
||||||
|
// cannot swap the album out from under a button they have already
|
||||||
|
// read.
|
||||||
|
return &AlbumMatchView{
|
||||||
|
GroupKey: best.GroupKey,
|
||||||
|
Recommendation: string(rec),
|
||||||
|
Score: top.Score,
|
||||||
|
ReleaseMBID: top.ReleaseMBID,
|
||||||
|
Title: top.Title,
|
||||||
|
ArtistCredit: top.ArtistCredit,
|
||||||
|
TrackCount: best.TrackCount,
|
||||||
|
GroupCount: len(pending),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,320 @@
|
|||||||
|
package autotagservice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"yellowjacket/backend/autotag"
|
||||||
|
"yellowjacket/backend/database"
|
||||||
|
)
|
||||||
|
|
||||||
|
// seedAlbumGroup writes one album's files, its tagging item and the
|
||||||
|
// durable candidate blob the prefetch would have left behind.
|
||||||
|
//
|
||||||
|
// The candidate list is what a real one looks like in the two ways
|
||||||
|
// that decide the tier: a per-track alignment for every local track,
|
||||||
|
// and a runner-up far enough away not to count as ambiguity.
|
||||||
|
func seedAlbumGroup(
|
||||||
|
t *testing.T,
|
||||||
|
db *database.DB,
|
||||||
|
groupKey string,
|
||||||
|
tracks int,
|
||||||
|
status string,
|
||||||
|
score float64,
|
||||||
|
) int64 {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
for i := 1; i <= tracks; i++ {
|
||||||
|
database.InsertTestTrack(t, db, database.TestTrack{
|
||||||
|
FilePath: filePathFor(groupKey, i),
|
||||||
|
Title: titleFor(i),
|
||||||
|
Artist: "Tideline",
|
||||||
|
Album: "Glass Harbour",
|
||||||
|
AlbumArtist: "Tideline",
|
||||||
|
TrackNumber: int64(i),
|
||||||
|
LengthMs: 200000,
|
||||||
|
LibraryID: 0,
|
||||||
|
GroupKey: groupKey,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := db.ExecContext(`
|
||||||
|
INSERT INTO tagging_items
|
||||||
|
(group_key, library_id, track_count, album_name, album_artist,
|
||||||
|
disc_number, status, score, best_match_release_mbid)
|
||||||
|
VALUES (?, 0, ?, 'Glass Harbour', 'Tideline', 0, ?, ?, 'rel-1')
|
||||||
|
`, groupKey, tracks, status, score); err != nil {
|
||||||
|
t.Fatalf("insert tagging item: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var albumID int64
|
||||||
|
if err := db.QueryRowWriter(
|
||||||
|
`SELECT album_id FROM audio_files WHERE group_key = ? LIMIT 1`, groupKey,
|
||||||
|
).Scan(&albumID); err != nil {
|
||||||
|
t.Fatalf("read album id: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return albumID
|
||||||
|
}
|
||||||
|
|
||||||
|
func filePathFor(groupKey string, n int) string {
|
||||||
|
return "/music/" + groupKey + "/0" + string(rune('0'+n)) + ".mp3"
|
||||||
|
}
|
||||||
|
|
||||||
|
func titleFor(n int) string {
|
||||||
|
return "Track " + string(rune('0'+n))
|
||||||
|
}
|
||||||
|
|
||||||
|
// storeCandidates writes the durable blob GetCandidates would have
|
||||||
|
// cached, with `top` as the winning score.
|
||||||
|
func storeCandidates(
|
||||||
|
t *testing.T, db *database.DB, groupKey string, tracks int, top float64,
|
||||||
|
) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
aligns := make([]autotag.TrackAlignment, 0, tracks)
|
||||||
|
for i := range tracks {
|
||||||
|
aligns = append(aligns, autotag.TrackAlignment{
|
||||||
|
Status: autotag.AlignmentMatched,
|
||||||
|
LocalIndex: i,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
cands := []autotag.Candidate{
|
||||||
|
{
|
||||||
|
ReleaseMBID: "rel-1",
|
||||||
|
ReleaseGroupMBID: "rg-1",
|
||||||
|
Title: "Glass Harbour",
|
||||||
|
ArtistCredit: "Tideline",
|
||||||
|
TrackCount: tracks,
|
||||||
|
Alignments: aligns,
|
||||||
|
Score: top,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ReleaseMBID: "rel-2",
|
||||||
|
ReleaseGroupMBID: "rg-2",
|
||||||
|
Title: "Something Else",
|
||||||
|
ArtistCredit: "Another Band",
|
||||||
|
TrackCount: tracks,
|
||||||
|
Score: 0.40,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
blob, err := json.Marshal(cands)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("marshal candidates: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := db.ExecContext(
|
||||||
|
`INSERT INTO tagging_candidates (group_key, candidates) VALUES (?, ?)`,
|
||||||
|
groupKey, string(blob),
|
||||||
|
); err != nil {
|
||||||
|
t.Fatalf("insert candidates: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A confident match is what the album page exists to surface.
|
||||||
|
func TestMatchForAlbumSurfacesAConfidentMatch(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
db := database.NewTestDB(t)
|
||||||
|
svc := newTestService(t, db)
|
||||||
|
|
||||||
|
albumID := seedAlbumGroup(t, db, "grp-1", 8, "pending", 0.95)
|
||||||
|
storeCandidates(t, db, "grp-1", 8, 0.95)
|
||||||
|
|
||||||
|
got, err := svc.MatchForAlbum(albumID)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("MatchForAlbum: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got == nil {
|
||||||
|
t.Fatal("no match returned for a strong candidate")
|
||||||
|
}
|
||||||
|
|
||||||
|
if got.Recommendation != string(autotag.RecommendationStrong) {
|
||||||
|
t.Errorf("recommendation = %q, want strong", got.Recommendation)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The release named is the release Apply would write — the page
|
||||||
|
// must not offer one album and tag another.
|
||||||
|
if got.ReleaseMBID != "rel-1" || got.Title != "Glass Harbour" {
|
||||||
|
t.Errorf("named %q/%q, want rel-1/Glass Harbour", got.ReleaseMBID, got.Title)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got.GroupCount != 1 {
|
||||||
|
t.Errorf("groupCount = %d, want 1", got.GroupCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The tier is computed from the candidates, not read off the raw
|
||||||
|
// score — a high number the scorer would have capped must not reach
|
||||||
|
// the page as confidence it withheld.
|
||||||
|
func TestMatchForAlbumDoesNotTrustTheStoredScore(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
db := database.NewTestDB(t)
|
||||||
|
svc := newTestService(t, db)
|
||||||
|
|
||||||
|
// Two tracks: below the evidence floor, so `Recommend` caps this
|
||||||
|
// at medium however well it scores.
|
||||||
|
albumID := seedAlbumGroup(t, db, "grp-2", 2, "pending", 0.99)
|
||||||
|
storeCandidates(t, db, "grp-2", 2, 0.99)
|
||||||
|
|
||||||
|
got, err := svc.MatchForAlbum(albumID)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("MatchForAlbum: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got != nil {
|
||||||
|
t.Errorf("surfaced %+v for a two-track folder, want nothing", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A weak match is not worth interrupting for.
|
||||||
|
func TestMatchForAlbumStaysQuietBelowTheTier(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
db := database.NewTestDB(t)
|
||||||
|
svc := newTestService(t, db)
|
||||||
|
|
||||||
|
albumID := seedAlbumGroup(t, db, "grp-3", 8, "pending", 0.60)
|
||||||
|
storeCandidates(t, db, "grp-3", 8, 0.60)
|
||||||
|
|
||||||
|
got, err := svc.MatchForAlbum(albumID)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("MatchForAlbum: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got != nil {
|
||||||
|
t.Errorf("surfaced %+v for a 0.60 match, want nothing", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// An album the user has already answered for is not re-offered.
|
||||||
|
//
|
||||||
|
// `confirmed` covers both a finished apply and an explicit "leave as
|
||||||
|
// is", and arguing with the second would be actively wrong.
|
||||||
|
func TestMatchForAlbumRespectsAnAnswerAlreadyGiven(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
for _, status := range []string{"confirmed", "skipped", "matched"} {
|
||||||
|
t.Run(status, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
db := database.NewTestDB(t)
|
||||||
|
svc := newTestService(t, db)
|
||||||
|
|
||||||
|
albumID := seedAlbumGroup(t, db, "grp-"+status, 8, status, 0.95)
|
||||||
|
storeCandidates(t, db, "grp-"+status, 8, 0.95)
|
||||||
|
|
||||||
|
got, err := svc.MatchForAlbum(albumID)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("MatchForAlbum: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got != nil {
|
||||||
|
t.Errorf("surfaced %+v for a %s group, want nothing", got, status)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A folder nobody has scored yet says nothing, rather than scoring it
|
||||||
|
// now: the MusicBrainz limiter is shared with every page the user can
|
||||||
|
// open, and this runs on page load.
|
||||||
|
func TestMatchForAlbumMakesNoNetworkCallForAnUnscoredFolder(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
db := database.NewTestDB(t)
|
||||||
|
svc := newTestService(t, db)
|
||||||
|
|
||||||
|
// No storeCandidates: the prefetch has not reached this folder.
|
||||||
|
albumID := seedAlbumGroup(t, db, "grp-4", 8, "pending", 0.95)
|
||||||
|
|
||||||
|
got, err := svc.MatchForAlbum(albumID)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("MatchForAlbum: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got != nil {
|
||||||
|
t.Errorf("surfaced %+v with no cached candidates, want nothing", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A multi-disc album is several groups, and the count is what stops
|
||||||
|
// the page offering one button that would retag one disc of two.
|
||||||
|
func TestMatchForAlbumCountsEveryGroupOfTheAlbum(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
db := database.NewTestDB(t)
|
||||||
|
svc := newTestService(t, db)
|
||||||
|
|
||||||
|
albumID := seedAlbumGroup(t, db, "grp-d1", 8, "pending", 0.95)
|
||||||
|
storeCandidates(t, db, "grp-d1", 8, 0.95)
|
||||||
|
|
||||||
|
// Disc two: same album row, its own folder and tagging group.
|
||||||
|
for i := 1; i <= 6; i++ {
|
||||||
|
database.InsertTestTrack(t, db, database.TestTrack{
|
||||||
|
FilePath: filePathFor("grp-d2", i),
|
||||||
|
Title: titleFor(i),
|
||||||
|
Artist: "Tideline",
|
||||||
|
Album: "Glass Harbour",
|
||||||
|
AlbumArtist: "Tideline",
|
||||||
|
TrackNumber: int64(i),
|
||||||
|
DiscNumber: 2,
|
||||||
|
LengthMs: 200000,
|
||||||
|
LibraryID: 0,
|
||||||
|
GroupKey: "grp-d2",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := db.ExecContext(`
|
||||||
|
INSERT INTO tagging_items
|
||||||
|
(group_key, library_id, track_count, album_name, album_artist,
|
||||||
|
disc_number, status, score)
|
||||||
|
VALUES ('grp-d2', 0, 6, 'Glass Harbour', 'Tideline', 2, 'pending', 0.93)
|
||||||
|
`); err != nil {
|
||||||
|
t.Fatalf("insert disc two: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
storeCandidates(t, db, "grp-d2", 6, 0.93)
|
||||||
|
|
||||||
|
got, err := svc.MatchForAlbum(albumID)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("MatchForAlbum: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got == nil {
|
||||||
|
t.Fatal("no match returned")
|
||||||
|
}
|
||||||
|
|
||||||
|
if got.GroupCount != 2 {
|
||||||
|
t.Errorf("groupCount = %d, want 2", got.GroupCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Best-first: the 0.95 disc is the one described.
|
||||||
|
if got.GroupKey != "grp-d1" {
|
||||||
|
t.Errorf("described %q, want the higher-scoring grp-d1", got.GroupKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// An album with no local files at all — a pure catalog page — is not
|
||||||
|
// a question this can answer.
|
||||||
|
func TestMatchForAlbumSaysNothingWithoutAnAlbum(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
db := database.NewTestDB(t)
|
||||||
|
svc := newTestService(t, db)
|
||||||
|
|
||||||
|
for _, id := range []int64{0, -1, 4242} {
|
||||||
|
got, err := svc.MatchForAlbum(id)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("MatchForAlbum(%d): %v", id, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got != nil {
|
||||||
|
t.Errorf("MatchForAlbum(%d) = %+v, want nil", id, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package autotagservice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"yellowjacket/backend/autotag"
|
||||||
|
"yellowjacket/backend/tagwriter"
|
||||||
|
)
|
||||||
|
|
||||||
|
// twAdapter passes the diff map through unchanged, so autotag's field
|
||||||
|
// constants and tagwriter's are the same keys written down twice --
|
||||||
|
// deliberately, to keep autotag out of the write pipeline's import
|
||||||
|
// graph. A key that drifts does not fail to compile and does not fail
|
||||||
|
// to write: the writer simply finds no entry under the name it looks
|
||||||
|
// for, and the field is silently dropped. That is what this pins, and
|
||||||
|
// this package is the one place that imports both.
|
||||||
|
func TestAutotagAndTagwriterAgreeOnFieldNames(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
pairs := map[string][2]string{
|
||||||
|
"title": {autotag.FieldTitle, tagwriter.FieldTitle},
|
||||||
|
"artist": {autotag.FieldArtist, tagwriter.FieldArtist},
|
||||||
|
"album": {autotag.FieldAlbum, tagwriter.FieldAlbum},
|
||||||
|
"album artist": {autotag.FieldAlbumArtist, tagwriter.FieldAlbumArtist},
|
||||||
|
"year": {autotag.FieldYear, tagwriter.FieldYear},
|
||||||
|
"track number": {autotag.FieldTrackNumber, tagwriter.FieldTrackNumber},
|
||||||
|
"disc number": {autotag.FieldDiscNumber, tagwriter.FieldDiscNumber},
|
||||||
|
"total tracks": {autotag.FieldTotalTracks, tagwriter.FieldTotalTracks},
|
||||||
|
"total discs": {autotag.FieldTotalDiscs, tagwriter.FieldTotalDiscs},
|
||||||
|
"cover art": {autotag.FieldCoverArt, tagwriter.FieldCoverArt},
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, pair := range pairs {
|
||||||
|
if pair[0] != pair[1] {
|
||||||
|
t.Errorf("%s: autotag says %q, tagwriter says %q", name, pair[0], pair[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+158
-1
@@ -303,6 +303,24 @@ func (c *Config) GetLibraryDirectory() string {
|
|||||||
return string(c.Library.DirectoryPath)
|
return string(c.Library.DirectoryPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A rejected setter puts the old value back, and that is not tidiness
|
||||||
|
// (#231). Save validates the *whole* config, so a value left behind by
|
||||||
|
// a failed write does not merely fail its own call: it fails every
|
||||||
|
// later save, of every unrelated setting, silently and for the rest of
|
||||||
|
// the session. Nothing reaches disk, so a restart clears it -- which
|
||||||
|
// is exactly what makes the fault hard to see and impossible to report.
|
||||||
|
//
|
||||||
|
// The setters below that assign and then validate therefore snapshot
|
||||||
|
// the field first and restore it on the error path. SetLibraryDirectory
|
||||||
|
// is the other safe shape and the better one where the value can be
|
||||||
|
// built on its own: it validates a candidate *before* assigning
|
||||||
|
// anything, so there is nothing to undo.
|
||||||
|
//
|
||||||
|
// Not every setter needs either. A bool, an int64 and the shortcut
|
||||||
|
// bindings pass through no validation that can reject them, and
|
||||||
|
// SetViewVisible refuses an unknown, non-hideable or launch-page view
|
||||||
|
// up front, so GeneralConfig.Validate never sees one it would fail on.
|
||||||
|
|
||||||
// SetLibraryDirectory validates and saves a new library directory,
|
// SetLibraryDirectory validates and saves a new library directory,
|
||||||
// then emits the LibraryConfigChanged event so listeners (e.g. the
|
// then emits the LibraryConfigChanged event so listeners (e.g. the
|
||||||
// Library scanner) can react.
|
// Library scanner) can react.
|
||||||
@@ -360,11 +378,14 @@ func (c *Config) SetScanConcurrency(mode string) error {
|
|||||||
c.Library.ApplyDefaults()
|
c.Library.ApplyDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
previous := c.Library.ScanConcurrency
|
||||||
c.Library.ScanConcurrency = library.ScanConcurrency(
|
c.Library.ScanConcurrency = library.ScanConcurrency(
|
||||||
mode,
|
mode,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err := c.Library.Validate(); err != nil {
|
if err := c.Library.Validate(); err != nil {
|
||||||
|
c.Library.ScanConcurrency = previous
|
||||||
|
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"invalid scan concurrency mode: %w", err,
|
"invalid scan concurrency mode: %w", err,
|
||||||
)
|
)
|
||||||
@@ -455,9 +476,12 @@ func (c *Config) SetThemeAccentColor(
|
|||||||
c.Theme.ApplyDefaults()
|
c.Theme.ApplyDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
previous := c.Theme.AccentColor
|
||||||
c.Theme.AccentColor = color
|
c.Theme.AccentColor = color
|
||||||
|
|
||||||
if err := c.Theme.Validate(); err != nil {
|
if err := c.Theme.Validate(); err != nil {
|
||||||
|
c.Theme.AccentColor = previous
|
||||||
|
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"invalid theme accent color: %w", err,
|
"invalid theme accent color: %w", err,
|
||||||
)
|
)
|
||||||
@@ -488,9 +512,12 @@ func (c *Config) SetThemeBackgroundShade(
|
|||||||
c.Theme.ApplyDefaults()
|
c.Theme.ApplyDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
previous := c.Theme.BackgroundShade
|
||||||
c.Theme.BackgroundShade = theme.BackgroundShade(shade)
|
c.Theme.BackgroundShade = theme.BackgroundShade(shade)
|
||||||
|
|
||||||
if err := c.Theme.Validate(); err != nil {
|
if err := c.Theme.Validate(); err != nil {
|
||||||
|
c.Theme.BackgroundShade = previous
|
||||||
|
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"invalid theme background shade: %w", err,
|
"invalid theme background shade: %w", err,
|
||||||
)
|
)
|
||||||
@@ -544,9 +571,12 @@ func (c *Config) SetDefaultPage(page string) error {
|
|||||||
c.General.ApplyDefaults()
|
c.General.ApplyDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
c.General.DefaultPage = DefaultPage(page)
|
previous := c.General.DefaultPage
|
||||||
|
c.General.DefaultPage = View(page)
|
||||||
|
|
||||||
if err := c.General.Validate(); err != nil {
|
if err := c.General.Validate(); err != nil {
|
||||||
|
c.General.DefaultPage = previous
|
||||||
|
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"invalid default page: %w", err,
|
"invalid default page: %w", err,
|
||||||
)
|
)
|
||||||
@@ -591,9 +621,12 @@ func (c *Config) SetQueueFallback(mode string) error {
|
|||||||
c.General.ApplyDefaults()
|
c.General.ApplyDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
previous := c.General.QueueFallback
|
||||||
c.General.QueueFallback = QueueFallback(mode)
|
c.General.QueueFallback = QueueFallback(mode)
|
||||||
|
|
||||||
if err := c.General.Validate(); err != nil {
|
if err := c.General.Validate(); err != nil {
|
||||||
|
c.General.QueueFallback = previous
|
||||||
|
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"invalid queue fallback: %w", err,
|
"invalid queue fallback: %w", err,
|
||||||
)
|
)
|
||||||
@@ -666,6 +699,124 @@ func (c *Config) SetAllowMeteredCatalogDownload(allow bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPopupVolume reports whether the bottom bar's volume control is a
|
||||||
|
// click-to-open popup rather than an inline slider (#42).
|
||||||
|
func (c *Config) GetPopupVolume() bool {
|
||||||
|
if c.General == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.General.PopupVolume
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPopupVolume saves the volume control's presentation.
|
||||||
|
//
|
||||||
|
// Nothing to validate: both values are legal at every width, and the
|
||||||
|
// frontend additionally stands the inline slider down below the phone
|
||||||
|
// breakpoint whatever this says, because that is about room rather than
|
||||||
|
// about preference.
|
||||||
|
func (c *Config) SetPopupVolume(popup bool) error {
|
||||||
|
if c.General == nil {
|
||||||
|
c.General = &GeneralConfig{}
|
||||||
|
c.General.ApplyDefaults()
|
||||||
|
}
|
||||||
|
|
||||||
|
c.General.PopupVolume = popup
|
||||||
|
|
||||||
|
if err := c.Save(); err != nil {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"could not save config: %w", err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
events.Emit(
|
||||||
|
c.ctx,
|
||||||
|
events.GeneralConfigChanged,
|
||||||
|
map[string]any{
|
||||||
|
"PopupVolume": popup,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
c.logger.Info("volume control presentation updated", "popup", popup)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetViewVisibility reports which primary views the sidebar should
|
||||||
|
// show, answered for every known view rather than only the ones the
|
||||||
|
// config mentions -- so the frontend filters on a value and never has
|
||||||
|
// to hold a second copy of the defaults.
|
||||||
|
func (c *Config) GetViewVisibility() map[string]bool {
|
||||||
|
if c.General == nil {
|
||||||
|
general := &GeneralConfig{}
|
||||||
|
general.ApplyDefaults()
|
||||||
|
|
||||||
|
return general.ResolvedViewVisibility()
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.General.ResolvedViewVisibility()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetViewVisible shows or hides one primary view.
|
||||||
|
//
|
||||||
|
// Two refusals, both about a state the user cannot get out of from the
|
||||||
|
// UI they would be left with: Settings is never hideable, and the
|
||||||
|
// launch page is never hideable while it is the launch page (change it
|
||||||
|
// first). Hiding a view does not make it unreachable -- `navigate`
|
||||||
|
// still resolves it, which detail views depend on -- it only takes the
|
||||||
|
// nav item away.
|
||||||
|
func (c *Config) SetViewVisible(view string, visible bool) error {
|
||||||
|
spec, known := LookupView(view)
|
||||||
|
if !known {
|
||||||
|
return fmt.Errorf("%w: %q", errUnknownView, view)
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.General == nil {
|
||||||
|
c.General = &GeneralConfig{}
|
||||||
|
c.General.ApplyDefaults()
|
||||||
|
}
|
||||||
|
|
||||||
|
if !visible {
|
||||||
|
if !spec.Hideable {
|
||||||
|
return fmt.Errorf("%w: %q", errViewNotHideable, view)
|
||||||
|
}
|
||||||
|
|
||||||
|
if spec.ID == c.General.DefaultPage {
|
||||||
|
return fmt.Errorf("%w: %q", errViewIsLaunchPage, view)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.General.ViewVisibility == nil {
|
||||||
|
c.General.ViewVisibility = make(map[string]bool, len(Views))
|
||||||
|
}
|
||||||
|
|
||||||
|
c.General.ViewVisibility[view] = visible
|
||||||
|
|
||||||
|
if err := c.General.Validate(); err != nil {
|
||||||
|
return fmt.Errorf("invalid view visibility: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.Save(); err != nil {
|
||||||
|
return fmt.Errorf("could not save config: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
events.Emit(
|
||||||
|
c.ctx,
|
||||||
|
events.GeneralConfigChanged,
|
||||||
|
map[string]any{
|
||||||
|
"ViewVisibility": c.General.ResolvedViewVisibility(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
c.logger.Info(
|
||||||
|
"view visibility updated",
|
||||||
|
"view", view,
|
||||||
|
"visible", visible,
|
||||||
|
)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetTrackListColumns returns the configured track-list columns.
|
// GetTrackListColumns returns the configured track-list columns.
|
||||||
func (c *Config) GetTrackListColumns() []tracklist.Column {
|
func (c *Config) GetTrackListColumns() []tracklist.Column {
|
||||||
if c.TrackList == nil {
|
if c.TrackList == nil {
|
||||||
@@ -683,9 +834,12 @@ func (c *Config) SetTrackListColumns(
|
|||||||
c.TrackList = &tracklist.Config{}
|
c.TrackList = &tracklist.Config{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
previous := c.TrackList.Columns
|
||||||
c.TrackList.Columns = columns
|
c.TrackList.Columns = columns
|
||||||
|
|
||||||
if err := c.TrackList.Validate(); err != nil {
|
if err := c.TrackList.Validate(); err != nil {
|
||||||
|
c.TrackList.Columns = previous
|
||||||
|
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"invalid track-list columns: %w", err,
|
"invalid track-list columns: %w", err,
|
||||||
)
|
)
|
||||||
@@ -783,9 +937,12 @@ func (c *Config) SetFavoritesIconStyle(
|
|||||||
c.Favorites.ApplyDefaults()
|
c.Favorites.ApplyDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
previous := c.Favorites.IconStyle
|
||||||
c.Favorites.IconStyle = favorites.IconStyle(style)
|
c.Favorites.IconStyle = favorites.IconStyle(style)
|
||||||
|
|
||||||
if err := c.Favorites.Validate(); err != nil {
|
if err := c.Favorites.Validate(); err != nil {
|
||||||
|
c.Favorites.IconStyle = previous
|
||||||
|
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
"invalid favorites icon style: %w", err,
|
"invalid favorites icon style: %w", err,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -188,3 +188,43 @@ func TestEmit_FavoritesChangeCarriesFullConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestEmit_PopupVolumeRoundTripsAndDefaultsToInline pins both halves of
|
||||||
|
// #42's storage decision.
|
||||||
|
//
|
||||||
|
// The **default** is the load-bearing one: inline is what a fresh
|
||||||
|
// install and an existing `config.toml` with no such key must both
|
||||||
|
// produce, which is why the field names the popup rather than the
|
||||||
|
// inline slider. A flag spelled the other way round would default to
|
||||||
|
// false, hand every existing install the popup this issue exists to
|
||||||
|
// stop being the only option, and need a migration to say otherwise.
|
||||||
|
func TestEmit_PopupVolumeRoundTripsAndDefaultsToInline(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
conf, rec := setupRecordedConfig(t)
|
||||||
|
|
||||||
|
if conf.GetPopupVolume() {
|
||||||
|
t.Error("a config with no PopupVolume key wants the popup, want inline")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := conf.SetPopupVolume(true); err != nil {
|
||||||
|
t.Fatalf("SetPopupVolume: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !conf.GetPopupVolume() {
|
||||||
|
t.Error("GetPopupVolume = false after setting it true")
|
||||||
|
}
|
||||||
|
|
||||||
|
data := payloadMap(t, rec, events.GeneralConfigChanged)
|
||||||
|
if data["PopupVolume"] != true {
|
||||||
|
t.Errorf("PopupVolume = %v, want true", data["PopupVolume"])
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := conf.SetPopupVolume(false); err != nil {
|
||||||
|
t.Fatalf("SetPopupVolume(false): %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if conf.GetPopupVolume() {
|
||||||
|
t.Error("GetPopupVolume = true after setting it false")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+96
-26
@@ -5,27 +5,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultPage identifies which view the app opens to on launch.
|
|
||||||
type DefaultPage string
|
|
||||||
|
|
||||||
// Valid DefaultPage values, matching the frontend's top-level route ids.
|
|
||||||
const (
|
|
||||||
DefaultPageHome DefaultPage = "home"
|
|
||||||
DefaultPageTracks DefaultPage = "tracks"
|
|
||||||
DefaultPageAlbums DefaultPage = "albums"
|
|
||||||
DefaultPageArtists DefaultPage = "artists"
|
|
||||||
DefaultPageGenres DefaultPage = "genres"
|
|
||||||
DefaultPagePlaylists DefaultPage = "playlists"
|
|
||||||
DefaultPageExplore DefaultPage = "explore"
|
|
||||||
DefaultPageDownloads DefaultPage = "downloads"
|
|
||||||
DefaultPageAutotag DefaultPage = "autotag"
|
|
||||||
DefaultPageJobs DefaultPage = "jobs"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DefaultDefaultPage is the launch page for a fresh install.
|
// DefaultDefaultPage is the launch page for a fresh install.
|
||||||
const DefaultDefaultPage = DefaultPageHome
|
const DefaultDefaultPage = ViewHome
|
||||||
|
|
||||||
var errUnknownDefaultPage = errors.New("unknown default page")
|
var (
|
||||||
|
errUnknownDefaultPage = errors.New("unknown default page")
|
||||||
|
errViewCannotLaunch = errors.New("view cannot be the launch page")
|
||||||
|
)
|
||||||
|
|
||||||
// QueueFallback identifies what plays, if anything, once the queue
|
// QueueFallback identifies what plays, if anything, once the queue
|
||||||
// runs out with nothing left to auto-advance to.
|
// runs out with nothing left to auto-advance to.
|
||||||
@@ -46,18 +32,52 @@ var errUnknownQueueFallback = errors.New("unknown queue fallback")
|
|||||||
// GeneralConfig holds general application preferences that don't
|
// GeneralConfig holds general application preferences that don't
|
||||||
// belong to a more specific subsystem.
|
// belong to a more specific subsystem.
|
||||||
type GeneralConfig struct {
|
type GeneralConfig struct {
|
||||||
DefaultPage DefaultPage `toml:"DefaultPage"`
|
DefaultPage View `toml:"DefaultPage"`
|
||||||
QueueFallback QueueFallback `toml:"QueueFallback"`
|
QueueFallback QueueFallback `toml:"QueueFallback"`
|
||||||
|
// ViewVisibility says which sidebar destinations are shown, keyed by
|
||||||
|
// view id.
|
||||||
|
//
|
||||||
|
// **An absent key means that view's own default** (`Views`), and that
|
||||||
|
// is the whole reason this is a map rather than a `HiddenViews
|
||||||
|
// []string` or a struct of booleans. A list's zero value is "hide
|
||||||
|
// nothing", which cannot express Autotag being off by default without
|
||||||
|
// a migration; a struct field for a view that later stops existing is
|
||||||
|
// stored garbage somebody has to deprecate. Here a view added later
|
||||||
|
// gets its own default rather than being invisible or forcibly
|
||||||
|
// visible, an unknown key is dropped on load, and no install needs
|
||||||
|
// migrating in either direction. Same polarity rule as
|
||||||
|
// AllowMeteredCatalogDownload: the zero value is the intended answer.
|
||||||
|
ViewVisibility map[string]bool `toml:"ViewVisibility"`
|
||||||
// AllowMeteredCatalogDownload permits the ~0.6 GB Explore catalog to
|
// AllowMeteredCatalogDownload permits the ~0.6 GB Explore catalog to
|
||||||
// be fetched on a connection the platform calls cellular. It defaults
|
// be fetched on a connection the platform calls cellular. It defaults
|
||||||
// to false, which is the whole point: the zero value is the safe one,
|
// to false, which is the whole point: the zero value is the safe one,
|
||||||
// so an existing config with no such key refuses by default rather
|
// so an existing config with no such key refuses by default rather
|
||||||
// than needing a migration to become careful.
|
// than needing a migration to become careful.
|
||||||
AllowMeteredCatalogDownload bool `toml:"AllowMeteredCatalogDownload"`
|
AllowMeteredCatalogDownload bool `toml:"AllowMeteredCatalogDownload"`
|
||||||
|
// PopupVolume draws the bottom bar's volume as a click-to-open popup
|
||||||
|
// instead of a slider that is always there (#42).
|
||||||
|
//
|
||||||
|
// The polarity is the rule this file already states twice: **the
|
||||||
|
// zero value is the intended answer**. Inline is the new default, so
|
||||||
|
// the flag has to name the *other* choice — an `InlineVolume bool`
|
||||||
|
// would default to false and give every existing install the popup
|
||||||
|
// this issue exists to stop being the only option, and would need a
|
||||||
|
// migration to say otherwise.
|
||||||
|
PopupVolume bool `toml:"PopupVolume"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyDefaults fills zero-value fields with sensible defaults.
|
// ApplyDefaults fills zero-value fields with sensible defaults.
|
||||||
|
//
|
||||||
|
// A launch page naming a *retired* view is treated as a zero value
|
||||||
|
// rather than as an error, because the alternative is an app that will
|
||||||
|
// not start for anyone who had that page selected when it was removed.
|
||||||
|
// An unknown-but-not-retired name still fails Validate: that is a typo,
|
||||||
|
// and telling someone about it is the useful answer.
|
||||||
func (c *GeneralConfig) ApplyDefaults() {
|
func (c *GeneralConfig) ApplyDefaults() {
|
||||||
|
if _, retired := RetiredViews[c.DefaultPage]; retired {
|
||||||
|
c.DefaultPage = ""
|
||||||
|
}
|
||||||
|
|
||||||
if c.DefaultPage == "" {
|
if c.DefaultPage == "" {
|
||||||
c.DefaultPage = DefaultDefaultPage
|
c.DefaultPage = DefaultDefaultPage
|
||||||
}
|
}
|
||||||
@@ -71,15 +91,17 @@ func (c *GeneralConfig) ApplyDefaults() {
|
|||||||
func (c *GeneralConfig) Validate() error {
|
func (c *GeneralConfig) Validate() error {
|
||||||
c.ApplyDefaults()
|
c.ApplyDefaults()
|
||||||
|
|
||||||
switch c.DefaultPage {
|
spec, known := LookupView(string(c.DefaultPage))
|
||||||
case DefaultPageHome, DefaultPageTracks, DefaultPageAlbums, DefaultPageArtists,
|
if !known {
|
||||||
DefaultPageGenres, DefaultPagePlaylists, DefaultPageExplore, DefaultPageDownloads,
|
|
||||||
DefaultPageAutotag, DefaultPageJobs:
|
|
||||||
// Valid.
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("%w: %q", errUnknownDefaultPage, c.DefaultPage)
|
return fmt.Errorf("%w: %q", errUnknownDefaultPage, c.DefaultPage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !spec.CanLaunch {
|
||||||
|
return fmt.Errorf("%w: %q", errViewCannotLaunch, c.DefaultPage)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.normalizeViewVisibility()
|
||||||
|
|
||||||
switch c.QueueFallback {
|
switch c.QueueFallback {
|
||||||
case QueueFallbackStop, QueueFallbackFavorites, QueueFallbackDynamicMix:
|
case QueueFallbackStop, QueueFallbackFavorites, QueueFallbackDynamicMix:
|
||||||
// Valid.
|
// Valid.
|
||||||
@@ -89,3 +111,51 @@ func (c *GeneralConfig) Validate() error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// normalizeViewVisibility drops what the stored map may not say, and
|
||||||
|
// repairs the one invariant the shell depends on.
|
||||||
|
//
|
||||||
|
// Three things are dropped or forced, and all three are reachable only
|
||||||
|
// from a hand-edited config or from a version that knew different
|
||||||
|
// views: an unknown id (a view removed since, e.g. when #27 folds Jobs
|
||||||
|
// into Settings) says nothing to anybody; a view that is not Hideable
|
||||||
|
// cannot be false; and **the launch page is always visible**, because
|
||||||
|
// otherwise an install lands on a page with no nav item pointing at it.
|
||||||
|
//
|
||||||
|
// That last one is a *repair* here and an *error* at the setter
|
||||||
|
// (SetViewVisible), deliberately. On load there is nobody to tell and
|
||||||
|
// the honest reading of "my launch page is Autotag" is that this user
|
||||||
|
// wants Autotag, so it is un-hidden rather than the launch page being
|
||||||
|
// silently reset to something they did not choose. At the setter the
|
||||||
|
// user is right there and can act, so it refuses and says why.
|
||||||
|
func (c *GeneralConfig) normalizeViewVisibility() {
|
||||||
|
for id := range c.ViewVisibility {
|
||||||
|
spec, known := LookupView(id)
|
||||||
|
if !known || !spec.Hideable {
|
||||||
|
delete(c.ViewVisibility, id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if visible, ok := c.ViewVisibility[string(c.DefaultPage)]; ok && !visible {
|
||||||
|
c.ViewVisibility[string(c.DefaultPage)] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResolvedViewVisibility answers for every known view, so no caller has
|
||||||
|
// to know the defaults -- the frontend included, which is why the
|
||||||
|
// binding returns this rather than the stored map.
|
||||||
|
func (c *GeneralConfig) ResolvedViewVisibility() map[string]bool {
|
||||||
|
resolved := make(map[string]bool, len(Views))
|
||||||
|
|
||||||
|
for _, v := range Views {
|
||||||
|
visible := v.VisibleByDefault
|
||||||
|
|
||||||
|
if stored, ok := c.ViewVisibility[string(v.ID)]; ok && v.Hideable {
|
||||||
|
visible = stored
|
||||||
|
}
|
||||||
|
|
||||||
|
resolved[string(v.ID)] = visible
|
||||||
|
}
|
||||||
|
|
||||||
|
return resolved
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,262 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log/slog"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"yellowjacket/backend/library"
|
||||||
|
"yellowjacket/backend/tracklist"
|
||||||
|
)
|
||||||
|
|
||||||
|
// newSavableConfig builds a loaded, valid config in a temp directory,
|
||||||
|
// so Save() writes rather than refusing with errSaveBeforeLoad.
|
||||||
|
//
|
||||||
|
// The library directory is real and set, because Config.Validate only
|
||||||
|
// validates the Library section when DirectoryPath is non-empty -- an
|
||||||
|
// empty one would hide a poisoned ScanConcurrency from the whole-config
|
||||||
|
// save that is the symptom under test.
|
||||||
|
func newSavableConfig(t *testing.T) *Config {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
c := &Config{
|
||||||
|
logger: slog.Default(),
|
||||||
|
filePath: filepath.Join(t.TempDir(), "config.toml"),
|
||||||
|
Library: &library.Config{
|
||||||
|
DirectoryPath: library.Directory(t.TempDir()),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
c.applyDefaults()
|
||||||
|
|
||||||
|
if err := c.Load(); err != nil {
|
||||||
|
t.Fatalf("Load() error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.Save(); err != nil {
|
||||||
|
t.Fatalf("Save() on a fresh config error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestSetterRejectionDoesNotPoisonTheConfig is the whole of #231.
|
||||||
|
//
|
||||||
|
// Every setter here assigns to the in-memory config and then validates.
|
||||||
|
// When the validation rejects the argument, the rejected value has to go
|
||||||
|
// back -- not because the caller sees it (it gets an error either way),
|
||||||
|
// but because Config.Save() validates the *whole* config. A value left
|
||||||
|
// behind by a failed setter therefore fails every later save, of every
|
||||||
|
// unrelated setting, silently and for the rest of the session.
|
||||||
|
//
|
||||||
|
// So each case asserts three things in order: the setter reports the
|
||||||
|
// error, the getter still reports the old value, and an unrelated save
|
||||||
|
// still works. The third is the one the user feels.
|
||||||
|
func TestSetterRejectionDoesNotPoisonTheConfig(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
// reject calls the setter with an argument its own Validate
|
||||||
|
// refuses.
|
||||||
|
reject func(*Config) error
|
||||||
|
// read reports the value the setter writes, so the rollback is
|
||||||
|
// asserted on the config rather than only on the save.
|
||||||
|
read func(*Config) string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "scan concurrency",
|
||||||
|
reject: func(c *Config) error {
|
||||||
|
return c.SetScanConcurrency("telepathy")
|
||||||
|
},
|
||||||
|
read: (*Config).GetScanConcurrency,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "theme accent colour",
|
||||||
|
reject: func(c *Config) error {
|
||||||
|
return c.SetThemeAccentColor("not-a-hex")
|
||||||
|
},
|
||||||
|
read: (*Config).GetThemeAccentColor,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "theme background shade",
|
||||||
|
reject: func(c *Config) error {
|
||||||
|
return c.SetThemeBackgroundShade("chartreuse")
|
||||||
|
},
|
||||||
|
read: (*Config).GetThemeBackgroundShade,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "default page",
|
||||||
|
reject: func(c *Config) error {
|
||||||
|
return c.SetDefaultPage("nowhere")
|
||||||
|
},
|
||||||
|
read: (*Config).GetDefaultPage,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "queue fallback",
|
||||||
|
reject: func(c *Config) error {
|
||||||
|
return c.SetQueueFallback("improvise")
|
||||||
|
},
|
||||||
|
read: (*Config).GetQueueFallback,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "favorites icon style",
|
||||||
|
reject: func(c *Config) error {
|
||||||
|
return c.SetFavoritesIconStyle("asterisk")
|
||||||
|
},
|
||||||
|
read: (*Config).GetFavoritesIconStyle,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "track-list columns",
|
||||||
|
reject: func(c *Config) error {
|
||||||
|
// titleArtist is a drawing definition, not a
|
||||||
|
// configurable column (#197), so it is exactly what
|
||||||
|
// the frontend used to be able to send.
|
||||||
|
return c.SetTrackListColumns([]tracklist.Column{
|
||||||
|
{ID: "titleArtist"},
|
||||||
|
})
|
||||||
|
},
|
||||||
|
read: func(c *Config) string {
|
||||||
|
return columnIDs(c.GetTrackListColumns())
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "track-list columns, duplicated",
|
||||||
|
reject: func(c *Config) error {
|
||||||
|
// The route #197 closed was one invalid id; a
|
||||||
|
// duplicate is the one still reachable from a client
|
||||||
|
// that assembles the list itself.
|
||||||
|
return c.SetTrackListColumns([]tracklist.Column{
|
||||||
|
{ID: tracklist.ColTrackName},
|
||||||
|
{ID: tracklist.ColTrackName},
|
||||||
|
})
|
||||||
|
},
|
||||||
|
read: func(c *Config) string {
|
||||||
|
return columnIDs(c.GetTrackListColumns())
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
c := newSavableConfig(t)
|
||||||
|
before := tc.read(c)
|
||||||
|
|
||||||
|
if err := tc.reject(c); err == nil {
|
||||||
|
t.Fatal("setter accepted an invalid value, want an error")
|
||||||
|
}
|
||||||
|
|
||||||
|
if after := tc.read(c); after != before {
|
||||||
|
t.Errorf(
|
||||||
|
"value after a rejected write = %q, want the previous %q",
|
||||||
|
after, before,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The symptom: an unrelated setting can no longer be saved.
|
||||||
|
if err := c.SetPopupVolume(true); err != nil {
|
||||||
|
t.Errorf("an unrelated setter failed after a rejected write: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.Save(); err != nil {
|
||||||
|
t.Errorf("Save() failed after a rejected write: %v", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestRejectedSetterLeavesNothingOnDisk pairs with the sweep above: the
|
||||||
|
// rollback must not be undone by what the file already holds, so a
|
||||||
|
// config reloaded from disk after a rejected write agrees with memory.
|
||||||
|
func TestRejectedSetterLeavesNothingOnDisk(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
c := newSavableConfig(t)
|
||||||
|
|
||||||
|
if err := c.SetThemeAccentColor("#123456"); err != nil {
|
||||||
|
t.Fatalf("SetThemeAccentColor() error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.SetThemeAccentColor("not-a-hex"); err == nil {
|
||||||
|
t.Fatal("SetThemeAccentColor accepted a non-colour, want an error")
|
||||||
|
}
|
||||||
|
|
||||||
|
reloaded := &Config{logger: slog.Default(), filePath: c.filePath}
|
||||||
|
reloaded.applyDefaults()
|
||||||
|
|
||||||
|
if err := reloaded.Load(); err != nil {
|
||||||
|
t.Fatalf("Load() error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got := reloaded.GetThemeAccentColor(); got != "#123456" {
|
||||||
|
t.Errorf("accent colour on disk = %q, want %q", got, "#123456")
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.GetThemeAccentColor() != reloaded.GetThemeAccentColor() {
|
||||||
|
t.Errorf(
|
||||||
|
"in-memory accent %q disagrees with disk %q after a rejected write",
|
||||||
|
c.GetThemeAccentColor(), reloaded.GetThemeAccentColor(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestSetLibraryDirectoryValidatesBeforeAssigning pins the precedent the
|
||||||
|
// seven rolled-back setters follow: this one has always built and
|
||||||
|
// validated a candidate before assigning, so a bad path never reaches
|
||||||
|
// the config at all.
|
||||||
|
func TestSetLibraryDirectoryValidatesBeforeAssigning(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
c := newSavableConfig(t)
|
||||||
|
before := c.GetLibraryDirectory()
|
||||||
|
|
||||||
|
if err := c.SetLibraryDirectory(filepath.Join(t.TempDir(), "no-such-dir")); err == nil {
|
||||||
|
t.Fatal("SetLibraryDirectory accepted a missing directory, want an error")
|
||||||
|
}
|
||||||
|
|
||||||
|
if after := c.GetLibraryDirectory(); after != before {
|
||||||
|
t.Errorf("library directory = %q, want the previous %q", after, before)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.Save(); err != nil {
|
||||||
|
t.Errorf("Save() failed after a rejected library directory: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestSetViewVisibleRefusesBeforeAssigning covers the other setter left
|
||||||
|
// out of the rollback pass: it guards its own argument up front, so
|
||||||
|
// GeneralConfig.Validate never sees a view it would reject.
|
||||||
|
func TestSetViewVisibleRefusesBeforeAssigning(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
c := newSavableConfig(t)
|
||||||
|
|
||||||
|
if err := c.SetViewVisible("no-such-view", false); err == nil {
|
||||||
|
t.Fatal("SetViewVisible accepted an unknown view, want an error")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.SetViewVisible(c.GetDefaultPage(), false); err == nil {
|
||||||
|
t.Fatal("SetViewVisible hid the launch page, want an error")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := c.Save(); err != nil {
|
||||||
|
t.Errorf("Save() failed after a refused view visibility change: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// columnIDs renders a column list for comparison in the table above.
|
||||||
|
func columnIDs(cols []tracklist.Column) string {
|
||||||
|
ids := make([]byte, 0, len(cols)*8)
|
||||||
|
|
||||||
|
for i, col := range cols {
|
||||||
|
if i > 0 {
|
||||||
|
ids = append(ids, ',')
|
||||||
|
}
|
||||||
|
|
||||||
|
ids = append(ids, col.ID...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(ids)
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
var (
|
||||||
|
errUnknownView = errors.New("unknown view")
|
||||||
|
errViewNotHideable = errors.New("view cannot be hidden")
|
||||||
|
errViewIsLaunchPage = errors.New("view is the launch page")
|
||||||
|
)
|
||||||
|
|
||||||
|
// View identifies one of the shell's primary destinations -- the
|
||||||
|
// things the sidebar lists and `index.ts` knows as `VIEW_TAGS`.
|
||||||
|
type View string
|
||||||
|
|
||||||
|
// The primary views, in no particular order: the sidebar owns the order
|
||||||
|
// it draws them in, because that is presentation.
|
||||||
|
const (
|
||||||
|
ViewHome View = "home"
|
||||||
|
ViewPlaylists View = "playlists"
|
||||||
|
ViewArtists View = "artists"
|
||||||
|
ViewGenres View = "genres"
|
||||||
|
ViewAlbums View = "albums"
|
||||||
|
ViewTracks View = "tracks"
|
||||||
|
ViewExplore View = "explore"
|
||||||
|
ViewDownloads View = "downloads"
|
||||||
|
ViewAutotag View = "autotag"
|
||||||
|
ViewSettings View = "settings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RetiredViews are destinations that used to exist and no longer do.
|
||||||
|
//
|
||||||
|
// A *visibility* entry for a removed view needs no such list: it is a
|
||||||
|
// key in a map, and an unknown key is dropped on load. A `DefaultPage`
|
||||||
|
// is a **value**, and an unknown one fails validation -- which on the
|
||||||
|
// load path means the app refuses to start rather than a setting being
|
||||||
|
// ignored. So the one shape that cannot be retired for free is named
|
||||||
|
// here and reset to the default instead.
|
||||||
|
//
|
||||||
|
// `jobs` was folded into Settings by #27: library scans under
|
||||||
|
// Libraries, index work under Search Index, downloads under the
|
||||||
|
// download clients, and the autotag apply into the Autotag view.
|
||||||
|
var RetiredViews = map[View]struct{}{
|
||||||
|
"jobs": {},
|
||||||
|
}
|
||||||
|
|
||||||
|
// ViewSpec is what the backend knows about a destination. The label and
|
||||||
|
// the icon are deliberately absent: those are presentation, they live
|
||||||
|
// beside the rest of the app's icon vocabulary in
|
||||||
|
// `frontend/src/utils/icon-language.ts`, and a Go copy of them would be
|
||||||
|
// a second thing to keep in step for nothing.
|
||||||
|
type ViewSpec struct {
|
||||||
|
// ID is the view name the frontend navigates by.
|
||||||
|
ID View
|
||||||
|
// VisibleByDefault is what an install gets when the config says
|
||||||
|
// nothing about this view -- which is every install until somebody
|
||||||
|
// changes it, and every view added after this one shipped.
|
||||||
|
VisibleByDefault bool
|
||||||
|
// Hideable is false for Settings alone. It is a property of the
|
||||||
|
// view rather than a check in the setter because `config.toml` is
|
||||||
|
// hand-editable, and an app that can be locked out of its own
|
||||||
|
// Settings by a typo is a support problem nobody can debug
|
||||||
|
// remotely.
|
||||||
|
Hideable bool
|
||||||
|
// CanLaunch reports whether the view may be the launch page.
|
||||||
|
// Settings is the only one that may not, which is the shape the
|
||||||
|
// DefaultPage enum already had.
|
||||||
|
CanLaunch bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// Views is the one list of primary destinations, in the order Settings
|
||||||
|
// offers them.
|
||||||
|
//
|
||||||
|
// It is the single source for three things that used to be written down
|
||||||
|
// separately: which views exist, which of them may be the launch page
|
||||||
|
// (`DefaultPage`'s validation reads it), and what an unconfigured
|
||||||
|
// install shows.
|
||||||
|
//
|
||||||
|
// Autotag is the one view hidden by default: it rewrites tags on disk,
|
||||||
|
// which is not what most libraries want on day one, and #25 asks for it
|
||||||
|
// to be turned on deliberately.
|
||||||
|
var Views = []ViewSpec{
|
||||||
|
{ID: ViewHome, VisibleByDefault: true, Hideable: true, CanLaunch: true},
|
||||||
|
{ID: ViewPlaylists, VisibleByDefault: true, Hideable: true, CanLaunch: true},
|
||||||
|
{ID: ViewArtists, VisibleByDefault: true, Hideable: true, CanLaunch: true},
|
||||||
|
{ID: ViewGenres, VisibleByDefault: true, Hideable: true, CanLaunch: true},
|
||||||
|
{ID: ViewAlbums, VisibleByDefault: true, Hideable: true, CanLaunch: true},
|
||||||
|
{ID: ViewTracks, VisibleByDefault: true, Hideable: true, CanLaunch: true},
|
||||||
|
{ID: ViewExplore, VisibleByDefault: true, Hideable: true, CanLaunch: true},
|
||||||
|
{ID: ViewDownloads, VisibleByDefault: true, Hideable: true, CanLaunch: true},
|
||||||
|
{ID: ViewAutotag, VisibleByDefault: false, Hideable: true, CanLaunch: true},
|
||||||
|
{ID: ViewSettings, VisibleByDefault: true, Hideable: false, CanLaunch: false},
|
||||||
|
}
|
||||||
|
|
||||||
|
// LookupView returns the spec for a view id.
|
||||||
|
func LookupView(id string) (ViewSpec, bool) {
|
||||||
|
for _, v := range Views {
|
||||||
|
if string(v.ID) == id {
|
||||||
|
return v, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ViewSpec{}, false
|
||||||
|
}
|
||||||
@@ -0,0 +1,307 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"log/slog"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// newViewTestConfig builds a Config backed by a temp file, which is all
|
||||||
|
// SetViewVisible needs: it saves and emits, and the emit is a no-op
|
||||||
|
// without a running app.
|
||||||
|
func newViewTestConfig(t *testing.T) *Config {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
c := &Config{
|
||||||
|
logger: slog.Default(),
|
||||||
|
filePath: filepath.Join(t.TempDir(), "config.toml"),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load a file that is not there: that is what marks the config
|
||||||
|
// loaded, without which Save refuses on the *second* write.
|
||||||
|
if err := c.Load(); err != nil {
|
||||||
|
t.Fatalf("Load() error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// A view the config says nothing about takes its own default, which is
|
||||||
|
// what makes this need no migration in either direction: an existing
|
||||||
|
// install gets Autotag hidden without a key, and a view added later
|
||||||
|
// gets its own answer rather than the list's.
|
||||||
|
func TestViewVisibilityDefaults(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
general := &GeneralConfig{}
|
||||||
|
general.ApplyDefaults()
|
||||||
|
|
||||||
|
resolved := general.ResolvedViewVisibility()
|
||||||
|
|
||||||
|
if len(resolved) != len(Views) {
|
||||||
|
t.Fatalf("resolved %d views, want %d", len(resolved), len(Views))
|
||||||
|
}
|
||||||
|
|
||||||
|
if resolved[string(ViewAutotag)] {
|
||||||
|
t.Error("autotag should be hidden by default")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range Views {
|
||||||
|
if v.ID == ViewAutotag {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !resolved[string(v.ID)] {
|
||||||
|
t.Errorf("%s should be visible by default", v.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A stored answer wins over the default, in both directions -- turning
|
||||||
|
// Autotag on is the whole user-facing point.
|
||||||
|
func TestViewVisibilityStoredWins(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
general := &GeneralConfig{
|
||||||
|
ViewVisibility: map[string]bool{
|
||||||
|
string(ViewAutotag): true,
|
||||||
|
string(ViewExplore): false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
general.ApplyDefaults()
|
||||||
|
|
||||||
|
resolved := general.ResolvedViewVisibility()
|
||||||
|
|
||||||
|
if !resolved[string(ViewAutotag)] {
|
||||||
|
t.Error("autotag was switched on and should be visible")
|
||||||
|
}
|
||||||
|
|
||||||
|
if resolved[string(ViewExplore)] {
|
||||||
|
t.Error("explore was switched off and should be hidden")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A key for a view that no longer exists is discarded rather than
|
||||||
|
// migrated. This is the property the #25-before-#27 ordering rests on:
|
||||||
|
// when Jobs folds into Settings, `jobs = true` in somebody's config is
|
||||||
|
// a key nothing asks about, not a cleanup task.
|
||||||
|
func TestValidateDropsUnknownAndUnhideableViews(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
general := &GeneralConfig{
|
||||||
|
ViewVisibility: map[string]bool{
|
||||||
|
"a-view-that-was-removed": true,
|
||||||
|
string(ViewSettings): false,
|
||||||
|
string(ViewAutotag): true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := general.Validate(); err != nil {
|
||||||
|
t.Fatalf("Validate() error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := general.ViewVisibility["a-view-that-was-removed"]; ok {
|
||||||
|
t.Error("an unknown view id should be dropped on load")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := general.ViewVisibility[string(ViewSettings)]; ok {
|
||||||
|
t.Error("settings is not hideable and should not be stored")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !general.ResolvedViewVisibility()[string(ViewSettings)] {
|
||||||
|
t.Error("settings must resolve visible whatever the file said")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// On load there is nobody to tell, so a launch page hidden by a
|
||||||
|
// hand-edited file is un-hidden rather than the launch page being
|
||||||
|
// reset to something the user did not choose.
|
||||||
|
func TestValidateRevealsAHiddenLaunchPage(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
general := &GeneralConfig{
|
||||||
|
DefaultPage: ViewAutotag,
|
||||||
|
ViewVisibility: map[string]bool{
|
||||||
|
string(ViewAutotag): false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := general.Validate(); err != nil {
|
||||||
|
t.Fatalf("Validate() error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !general.ResolvedViewVisibility()[string(ViewAutotag)] {
|
||||||
|
t.Error("the launch page must be visible")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A launch page naming a view that no longer exists resets to the
|
||||||
|
// default instead of failing validation, which on the load path would
|
||||||
|
// mean the app refusing to start for whoever had it selected.
|
||||||
|
//
|
||||||
|
// This is the one shape #25's storage decision does *not* make free: a
|
||||||
|
// visibility entry is a key and an unknown key is dropped, but a launch
|
||||||
|
// page is a value.
|
||||||
|
func TestARetiredLaunchPageFallsBackToTheDefault(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
general := &GeneralConfig{DefaultPage: "jobs"}
|
||||||
|
|
||||||
|
if err := general.Validate(); err != nil {
|
||||||
|
t.Fatalf("Validate() error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if general.DefaultPage != DefaultDefaultPage {
|
||||||
|
t.Errorf("DefaultPage = %q, want %q", general.DefaultPage, DefaultDefaultPage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A name that is merely wrong is still an error: that is a typo, and
|
||||||
|
// saying so is more useful than ignoring it.
|
||||||
|
func TestAnUnknownLaunchPageIsStillAnError(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
general := &GeneralConfig{DefaultPage: "nonsense"}
|
||||||
|
|
||||||
|
if err := general.Validate(); !errors.Is(err, errUnknownDefaultPage) {
|
||||||
|
t.Fatalf("Validate() error = %v, want errUnknownDefaultPage", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A retired view is not a view, so nothing offers it and nothing
|
||||||
|
// resolves it -- the visibility map included.
|
||||||
|
func TestARetiredViewIsGone(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
for id := range RetiredViews {
|
||||||
|
if _, ok := LookupView(string(id)); ok {
|
||||||
|
t.Errorf("%s is retired but still in Views", id)
|
||||||
|
}
|
||||||
|
|
||||||
|
general := &GeneralConfig{}
|
||||||
|
general.ApplyDefaults()
|
||||||
|
|
||||||
|
if _, ok := general.ResolvedViewVisibility()[string(id)]; ok {
|
||||||
|
t.Errorf("%s is retired but still resolves a visibility", id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Settings may not be the launch page, which is the shape the old
|
||||||
|
// DefaultPage enum had and is now read off the same table.
|
||||||
|
func TestValidateRejectsAnUnlaunchablePage(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
general := &GeneralConfig{DefaultPage: ViewSettings}
|
||||||
|
|
||||||
|
err := general.Validate()
|
||||||
|
if !errors.Is(err, errViewCannotLaunch) {
|
||||||
|
t.Fatalf("Validate() error = %v, want errViewCannotLaunch", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// At the setter the user is present and can act, so the two states
|
||||||
|
// they could not get out of are refused rather than repaired.
|
||||||
|
func TestSetViewVisibleRefusals(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
view string
|
||||||
|
visible bool
|
||||||
|
want error
|
||||||
|
}{
|
||||||
|
{"settings is never hideable", string(ViewSettings), false, errViewNotHideable},
|
||||||
|
{"the launch page is not hideable", string(ViewHome), false, errViewIsLaunchPage},
|
||||||
|
{"an unknown view is not a setting", "nonsense", false, errUnknownView},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
c := newViewTestConfig(t)
|
||||||
|
|
||||||
|
err := c.SetViewVisible(tt.view, tt.visible)
|
||||||
|
if !errors.Is(err, tt.want) {
|
||||||
|
t.Fatalf("SetViewVisible() error = %v, want %v", err, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Showing a view is never refused, including Settings and the launch
|
||||||
|
// page -- there is no state to be stuck in.
|
||||||
|
func TestSetViewVisibleShowsAnything(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
c := newViewTestConfig(t)
|
||||||
|
|
||||||
|
for _, v := range Views {
|
||||||
|
if err := c.SetViewVisible(string(v.ID), true); err != nil {
|
||||||
|
t.Fatalf("SetViewVisible(%q, true) error: %v", v.ID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !c.GetViewVisibility()[string(ViewAutotag)] {
|
||||||
|
t.Error("autotag was switched on and should be visible")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The stored map survives a save/load round trip, which is what a
|
||||||
|
// map-valued TOML key is worth checking for.
|
||||||
|
func TestViewVisibilityRoundTrips(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
path := filepath.Join(t.TempDir(), "config.toml")
|
||||||
|
|
||||||
|
original := &Config{logger: slog.Default(), filePath: path}
|
||||||
|
if err := original.Load(); err != nil {
|
||||||
|
t.Fatalf("Load() error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := original.SetViewVisible(string(ViewAutotag), true); err != nil {
|
||||||
|
t.Fatalf("SetViewVisible() error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := original.SetViewVisible(string(ViewExplore), false); err != nil {
|
||||||
|
t.Fatalf("SetViewVisible() error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
loaded := &Config{logger: slog.Default(), filePath: path}
|
||||||
|
if err := loaded.Load(); err != nil {
|
||||||
|
t.Fatalf("Load() error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
resolved := loaded.GetViewVisibility()
|
||||||
|
|
||||||
|
if !resolved[string(ViewAutotag)] {
|
||||||
|
t.Error("autotag should have loaded as visible")
|
||||||
|
}
|
||||||
|
|
||||||
|
if resolved[string(ViewExplore)] {
|
||||||
|
t.Error("explore should have loaded as hidden")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Every view the shell can launch into is a view the sidebar can show,
|
||||||
|
// or an install could land on a page with no nav item and no setting
|
||||||
|
// pointing at it.
|
||||||
|
func TestEveryLaunchableViewIsAView(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
for _, v := range Views {
|
||||||
|
if !v.CanLaunch {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !v.Hideable {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := LookupView(string(v.ID)); !ok {
|
||||||
|
t.Errorf("%s is launchable but not a known view", v.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,13 +13,31 @@ const (
|
|||||||
// enforces this at runtime; it is also the floor below which a
|
// enforces this at runtime; it is also the floor below which a
|
||||||
// reported size is treated as bogus and not persisted.
|
// reported size is treated as bogus and not persisted.
|
||||||
//
|
//
|
||||||
// 800x600 is where the shell was measured to still work, rather
|
// **Both reasons this comment used to give have expired**, and the
|
||||||
// than a round number: below ~780 the header's subtitle wraps and
|
// value is right for a third one. It said the floor was 800x600
|
||||||
// pushes the title out of the 4em top bar, and below ~600 tall the
|
// because "below ~780 the header's subtitle wraps and pushes the
|
||||||
// eleven sidebar items no longer fit at once. The previous
|
// title out of the 4em top bar" and "below ~600 tall the eleven
|
||||||
// 512x384 was aspirational — at 700x480 the sidebar overflowed
|
// sidebar items no longer fit at once". Neither mechanism can
|
||||||
// behind the player bar with no scroll and Settings and Jobs could
|
// happen now: the subtitle is display:none from 899px down
|
||||||
// not be reached at all.
|
// (index.css), and the sidebar host is overflow-y:auto — measured
|
||||||
|
// at 600x460, its scrollHeight is 434 against a 332px client and
|
||||||
|
// Settings is reachable after scrolling. A floor defended by two
|
||||||
|
// mechanisms that no longer exist is a number nobody can argue
|
||||||
|
// with, which is worse than either answer.
|
||||||
|
//
|
||||||
|
// It stays 800x600 because that is where the *desktop* chrome
|
||||||
|
// stops being comfortable — the Compact band of plan 018's size
|
||||||
|
// matrix (#24) — and not because the app breaks below it. It does
|
||||||
|
// not: under 600px wide the phone layout takes over (bottom-nav,
|
||||||
|
// no sidebar) and the shell fits 320px exactly, which is what
|
||||||
|
// makes this a comfort floor rather than a correctness one, and
|
||||||
|
// why a very small window reflows instead of becoming a
|
||||||
|
// mini-player (#12 is a second always-on-top window, not a mode of
|
||||||
|
// this one).
|
||||||
|
//
|
||||||
|
// The previous 512x384 was aspirational — at 700x480 the sidebar
|
||||||
|
// overflowed behind the player bar with no scroll and Settings and
|
||||||
|
// Jobs could not be reached at all.
|
||||||
MinWidth = 800
|
MinWidth = 800
|
||||||
// MinHeight is the smallest allowed window height in pixels.
|
// MinHeight is the smallest allowed window height in pixels.
|
||||||
MinHeight = 600
|
MinHeight = 600
|
||||||
|
|||||||
@@ -662,19 +662,19 @@ func TestSmartPlaylistColumns(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Migration 10 — play history tracking
|
// Listening events tracking
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
func TestPlayHistoryTable(t *testing.T) {
|
func TestListeningEventsTable(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
db := NewTestDB(t)
|
db := NewTestDB(t)
|
||||||
|
|
||||||
// Verify play_history table exists.
|
// Verify listening_events table exists.
|
||||||
var tableCount int64
|
var tableCount int64
|
||||||
|
|
||||||
tblRows, err := db.QueryContext(
|
tblRows, err := db.QueryContext(
|
||||||
"SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='play_history'",
|
"SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='listening_events'",
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("query sqlite_master: %v", err)
|
t.Fatalf("query sqlite_master: %v", err)
|
||||||
@@ -695,12 +695,14 @@ func TestPlayHistoryTable(t *testing.T) {
|
|||||||
_ = tblRows.Close()
|
_ = tblRows.Close()
|
||||||
|
|
||||||
if tableCount != 1 {
|
if tableCount != 1 {
|
||||||
t.Errorf("play_history table count = %d, want 1", tableCount)
|
t.Errorf("listening_events table count = %d, want 1", tableCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify audio_files has play_count and last_played columns.
|
// Verify audio_files has the denormalized listening counters.
|
||||||
hasPlayCount := false
|
hasPlayCount := false
|
||||||
hasLastPlayed := false
|
hasLastPlayed := false
|
||||||
|
hasSkipCount := false
|
||||||
|
hasLastSkipped := false
|
||||||
|
|
||||||
colRows, err := db.QueryContext("PRAGMA table_info(audio_files)")
|
colRows, err := db.QueryContext("PRAGMA table_info(audio_files)")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -732,6 +734,14 @@ func TestPlayHistoryTable(t *testing.T) {
|
|||||||
if name == "last_played" {
|
if name == "last_played" {
|
||||||
hasLastPlayed = true
|
hasLastPlayed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if name == "skip_count" {
|
||||||
|
hasSkipCount = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if name == "last_skipped" {
|
||||||
|
hasLastSkipped = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = colRows.Close()
|
_ = colRows.Close()
|
||||||
@@ -744,6 +754,14 @@ func TestPlayHistoryTable(t *testing.T) {
|
|||||||
t.Error("audio_files missing last_played column")
|
t.Error("audio_files missing last_played column")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !hasSkipCount {
|
||||||
|
t.Error("audio_files missing skip_count column")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !hasLastSkipped {
|
||||||
|
t.Error("audio_files missing last_skipped column")
|
||||||
|
}
|
||||||
|
|
||||||
// Verify track_metadata VIEW includes play_count and last_played.
|
// Verify track_metadata VIEW includes play_count and last_played.
|
||||||
viewCols := map[string]bool{}
|
viewCols := map[string]bool{}
|
||||||
|
|
||||||
@@ -783,7 +801,7 @@ func TestPlayHistoryTable(t *testing.T) {
|
|||||||
t.Error("track_metadata VIEW missing last_played column")
|
t.Error("track_metadata VIEW missing last_played column")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Round-trip: insert a play_history row and verify play_count update.
|
// Round-trip: insert a listening_events row and verify play_count update.
|
||||||
// First, set up test data. The test DB already has library id=0.
|
// First, set up test data. The test DB already has library id=0.
|
||||||
InsertTestTrack(t, db, TestTrack{
|
InsertTestTrack(t, db, TestTrack{
|
||||||
FilePath: "/test/play_history.mp3",
|
FilePath: "/test/play_history.mp3",
|
||||||
@@ -821,12 +839,12 @@ func TestPlayHistoryTable(t *testing.T) {
|
|||||||
t.Errorf("initial play_count = %d, want 0", playCount)
|
t.Errorf("initial play_count = %d, want 0", playCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert a play_history row and update play_count.
|
// Insert a listening_events row (kind defaults to 'complete').
|
||||||
_, err = db.ExecContext(
|
_, err = db.ExecContext(
|
||||||
"INSERT INTO play_history (audio_file_id) VALUES (1)",
|
"INSERT INTO listening_events (audio_file_id, kind) VALUES (1, 'complete')",
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("insert play_history: %v", err)
|
t.Fatalf("insert listening_events: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = db.ExecContext(
|
_, err = db.ExecContext(
|
||||||
|
|||||||
@@ -151,16 +151,28 @@ func (d *DB) SetLyrics(audioFileID int64, lyrics, source, recordingMBID string)
|
|||||||
return d.upsertLyricsIndex(audioFileID, lyrics)
|
return d.upsertLyricsIndex(audioFileID, lyrics)
|
||||||
}
|
}
|
||||||
|
|
||||||
// upsertLyricsIndex refreshes a single file's entry in the contentless
|
// DeleteLyricsIndex removes one file's entry from the contentless
|
||||||
// lyrics_index. contentless_delete=1 makes the DELETE valid; an empty
|
// lyrics_index. It is called wherever a file row is deleted — the
|
||||||
// lyrics string leaves the row deleted.
|
// `lyrics` table cascades with its file, but the FTS entry does not and
|
||||||
func (d *DB) upsertLyricsIndex(audioFileID int64, lyrics string) error {
|
// would otherwise accumulate for the life of the install (#249).
|
||||||
|
func (d *DB) DeleteLyricsIndex(audioFileID int64) error {
|
||||||
if _, err := d.db.ExecContext(d.Ctx,
|
if _, err := d.db.ExecContext(d.Ctx,
|
||||||
"DELETE FROM lyrics_index WHERE rowid = ?", audioFileID,
|
"DELETE FROM lyrics_index WHERE rowid = ?", audioFileID,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return fmt.Errorf("could not delete lyrics_index row: %w", err)
|
return fmt.Errorf("could not delete lyrics_index row: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// upsertLyricsIndex refreshes a single file's entry in the contentless
|
||||||
|
// lyrics_index. contentless_delete=1 makes the DELETE valid; an empty
|
||||||
|
// lyrics string leaves the row deleted.
|
||||||
|
func (d *DB) upsertLyricsIndex(audioFileID int64, lyrics string) error {
|
||||||
|
if err := d.DeleteLyricsIndex(audioFileID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if strings.TrimSpace(lyrics) == "" {
|
if strings.TrimSpace(lyrics) == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,177 @@
|
|||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Preserving a playlist entry across the loss of its track is two
|
||||||
|
// statements, not one, and the split is not tidiness -- it is what
|
||||||
|
// makes the important half work in the situation that needs it most.
|
||||||
|
//
|
||||||
|
// `playlist_tracks.audio_file_id` is ON DELETE SET NULL, so an entry
|
||||||
|
// outlives its file as an id-less row that says nothing about what the
|
||||||
|
// user put in the playlist. The phantom_* columns carry the answer
|
||||||
|
// across and ResolvePhantomTracksAfterScan re-links them afterwards --
|
||||||
|
// but only if something fills them *before* the rows go.
|
||||||
|
//
|
||||||
|
// The two halves are not equally important and are not equally
|
||||||
|
// available:
|
||||||
|
//
|
||||||
|
// - **phantom_file_path is the one that matters.**
|
||||||
|
// ResolvePhantomTracksAfterScan matches it against
|
||||||
|
// `audio_files.file_path`, so without it an entry can never be
|
||||||
|
// re-linked and the playlist is empty for good. It comes straight
|
||||||
|
// off `audio_files`, whose `file_path` is the table's natural key
|
||||||
|
// and has been present in every shape it has ever had -- including
|
||||||
|
// the pre-013 stub of `(id, file_path, recording_id)`.
|
||||||
|
// - The rest is *display* for a phantom entry before a rescan
|
||||||
|
// re-links it, and it comes from the `track_metadata` view, which
|
||||||
|
// is the one definition of a track row and not worth restating.
|
||||||
|
//
|
||||||
|
// Reading the view is what cannot be relied on here, and that is the
|
||||||
|
// whole reason for the split. This runs *before* applySchema, which is
|
||||||
|
// precisely the moment the schema is inconsistent: the view is whatever
|
||||||
|
// the last launch's schema declared, while `audio_files` is whatever
|
||||||
|
// the launch before that left behind. A view over columns the table no
|
||||||
|
// longer has is not merely empty -- `pragma_table_info` on it *errors*,
|
||||||
|
// and so does selecting from it. `cmd/indexbuild`'s fixture is exactly
|
||||||
|
// that shape and is what caught this.
|
||||||
|
//
|
||||||
|
// COALESCE keeps an existing phantom value in both halves: an entry
|
||||||
|
// already phantom is one whose file went missing in an earlier pass,
|
||||||
|
// and its recorded metadata is the only copy left. Overwriting that
|
||||||
|
// from a NULL join erases the rows this exists to protect.
|
||||||
|
const (
|
||||||
|
preservePhantomPathSQL = `
|
||||||
|
UPDATE playlist_tracks
|
||||||
|
SET phantom_file_path = COALESCE(phantom_file_path, (
|
||||||
|
SELECT af.file_path FROM audio_files af
|
||||||
|
WHERE af.id = playlist_tracks.audio_file_id
|
||||||
|
))
|
||||||
|
WHERE audio_file_id IS NOT NULL
|
||||||
|
`
|
||||||
|
|
||||||
|
preservePhantomDisplaySQL = `
|
||||||
|
UPDATE playlist_tracks
|
||||||
|
SET
|
||||||
|
phantom_title = COALESCE(phantom_title, (
|
||||||
|
SELECT tm.title FROM track_metadata tm
|
||||||
|
WHERE tm.id = playlist_tracks.audio_file_id
|
||||||
|
)),
|
||||||
|
phantom_artist = COALESCE(phantom_artist, (
|
||||||
|
SELECT tm.artist_name FROM track_metadata tm
|
||||||
|
WHERE tm.id = playlist_tracks.audio_file_id
|
||||||
|
)),
|
||||||
|
phantom_album = COALESCE(phantom_album, (
|
||||||
|
SELECT tm.album FROM track_metadata tm
|
||||||
|
WHERE tm.id = playlist_tracks.audio_file_id
|
||||||
|
)),
|
||||||
|
phantom_duration_ms = COALESCE(phantom_duration_ms, (
|
||||||
|
SELECT af.length_milliseconds FROM audio_files af
|
||||||
|
WHERE af.id = playlist_tracks.audio_file_id
|
||||||
|
)),
|
||||||
|
phantom_genre = COALESCE(phantom_genre, (
|
||||||
|
SELECT tm.genre FROM track_metadata tm
|
||||||
|
WHERE tm.id = playlist_tracks.audio_file_id
|
||||||
|
)),
|
||||||
|
phantom_cover_art_path = COALESCE(phantom_cover_art_path, (
|
||||||
|
SELECT tm.cover_art_path FROM track_metadata tm
|
||||||
|
WHERE tm.id = playlist_tracks.audio_file_id
|
||||||
|
))
|
||||||
|
WHERE audio_file_id IS NOT NULL
|
||||||
|
`
|
||||||
|
)
|
||||||
|
|
||||||
|
// PreservePlaylistPhantoms records every linked playlist entry's track
|
||||||
|
// metadata on the entry itself, so the entry survives the rows being
|
||||||
|
// deleted underneath it.
|
||||||
|
//
|
||||||
|
// Every path that empties `audio_files` must call this (or the scoped
|
||||||
|
// variant below) first, inside the same transaction as the delete.
|
||||||
|
// These paths have drifted before: the full rescan in backend/library
|
||||||
|
// did this and the stale-shape retire in this package did not, so the
|
||||||
|
// *documented* repair ("delete and rescan") preserved playlists while
|
||||||
|
// the automatic one that exists to spare the user that work silently
|
||||||
|
// emptied them (#183). The incremental scan's orphan cleanup and
|
||||||
|
// RemoveFromLibrary drifted the same way and are #246.
|
||||||
|
//
|
||||||
|
// The display half is skipped, with a warning, when `track_metadata`
|
||||||
|
// cannot answer -- see the note above. Skipping it costs a phantom
|
||||||
|
// entry its title until a rescan re-links it; skipping the path half
|
||||||
|
// would cost the entry outright, so that one is an error.
|
||||||
|
func PreservePlaylistPhantoms(
|
||||||
|
ctx context.Context, tx *sql.Tx, logger *slog.Logger,
|
||||||
|
) error {
|
||||||
|
return preservePlaylistPhantoms(ctx, tx, nil, logger)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PreservePlaylistPhantomsForFiles is PreservePlaylistPhantoms scoped to
|
||||||
|
// the given audio file ids, for the two removal paths that delete a
|
||||||
|
// known subset of the table rather than all of it: the incremental
|
||||||
|
// scan's orphan cleanup and RemoveFromLibrary. A bulk pass there would
|
||||||
|
// rewrite every linked playlist row on every scan for nothing.
|
||||||
|
func PreservePlaylistPhantomsForFiles(
|
||||||
|
ctx context.Context, tx *sql.Tx, ids []int64, logger *slog.Logger,
|
||||||
|
) error {
|
||||||
|
return preservePlaylistPhantoms(ctx, tx, ids, logger)
|
||||||
|
}
|
||||||
|
|
||||||
|
func preservePlaylistPhantoms(
|
||||||
|
ctx context.Context, tx *sql.Tx, ids []int64, logger *slog.Logger,
|
||||||
|
) error {
|
||||||
|
clause, args, skip := phantomIDFilter(ids)
|
||||||
|
if skip {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := tx.ExecContext(
|
||||||
|
ctx, preservePhantomPathSQL+clause, args...,
|
||||||
|
); err != nil {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"could not preserve playlist track file paths: %w", err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := tx.ExecContext(
|
||||||
|
ctx, preservePhantomDisplaySQL+clause, args...,
|
||||||
|
); err != nil {
|
||||||
|
// A failed statement does not roll back a SQLite transaction,
|
||||||
|
// so the path half above stands and the entries remain
|
||||||
|
// re-linkable.
|
||||||
|
logger.Warn(
|
||||||
|
"could not record display metadata for playlist entries; "+
|
||||||
|
"they will be re-linked by the next scan but read as "+
|
||||||
|
"unknown until then",
|
||||||
|
"err", err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// phantomIDFilter builds the extra WHERE terms and arguments that scope
|
||||||
|
// a preservation pass to a set of audio file ids. A nil ids returns the
|
||||||
|
// empty clause (a bulk run over every linked entry); an empty slice
|
||||||
|
// reports skip, since there is nothing to preserve.
|
||||||
|
func phantomIDFilter(ids []int64) (clause string, args []any, skip bool) {
|
||||||
|
switch {
|
||||||
|
case ids == nil:
|
||||||
|
return "", nil, false
|
||||||
|
case len(ids) == 0:
|
||||||
|
return "", nil, true
|
||||||
|
}
|
||||||
|
|
||||||
|
clause = " AND audio_file_id IN (" +
|
||||||
|
strings.Repeat("?,", len(ids)-1) + "?)"
|
||||||
|
|
||||||
|
args = make([]any, len(ids))
|
||||||
|
for i, id := range ids {
|
||||||
|
args[i] = id
|
||||||
|
}
|
||||||
|
|
||||||
|
return clause, args, false
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestPreservePlaylistPhantomsForFilesScopesToTheRequestedIDs is the
|
||||||
|
// scoping half of the scoped variant: a run over one file's id must
|
||||||
|
// fill that file's playlist entries and leave every other entry alone,
|
||||||
|
// because the incremental scan calls this once per orphan batch and a
|
||||||
|
// pass that rewrote the whole table would touch every playlist row on
|
||||||
|
// every scan.
|
||||||
|
func TestPreservePlaylistPhantomsForFilesScopesToTheRequestedIDs(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
db := openRaw(t, t.TempDir())
|
||||||
|
|
||||||
|
if _, err := db.ExecContext(ctx, "PRAGMA foreign_keys = ON"); err != nil {
|
||||||
|
t.Fatalf("pragma: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := applySchema(ctx, db); err != nil {
|
||||||
|
t.Fatalf("applySchema: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := db.ExecContext(ctx, `
|
||||||
|
INSERT INTO playlists (id, name) VALUES (1, 'keepme');
|
||||||
|
INSERT INTO libraries (id, name, path) VALUES (0, 'test', '/music');
|
||||||
|
INSERT INTO artists (id, name) VALUES (3, 'Aurora Fields');
|
||||||
|
INSERT INTO cover_art (id, file_path, mime_type)
|
||||||
|
VALUES (9, 'covers/7.jpg', 'image/jpeg');
|
||||||
|
INSERT INTO albums (id, name, artist_id, cover_art_id)
|
||||||
|
VALUES (4, 'Tideline', 3, 9);
|
||||||
|
INSERT INTO audio_files
|
||||||
|
(id, file_path, file_type_id, length_milliseconds,
|
||||||
|
title, artist_credit, artist_id, album_id)
|
||||||
|
VALUES
|
||||||
|
(7, '/music/a.flac', 1, 1000,
|
||||||
|
'Slack Water', 'Aurora Fields', 3, 4),
|
||||||
|
(8, '/music/b.flac', 1, 2000,
|
||||||
|
'Second Tide', 'Aurora Fields', 3, 4);
|
||||||
|
INSERT INTO playlist_tracks (playlist_id, audio_file_id, position)
|
||||||
|
VALUES (1, 7, 0), (1, 8, 1);
|
||||||
|
`); err != nil {
|
||||||
|
t.Fatalf("seed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tx, err := db.BeginTx(ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("begin: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func() { _ = tx.Rollback() }()
|
||||||
|
|
||||||
|
if err := PreservePlaylistPhantomsForFiles(
|
||||||
|
ctx, tx, []int64{7}, testLogger(),
|
||||||
|
); err != nil {
|
||||||
|
t.Fatalf("preserve: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := tx.Commit(); err != nil {
|
||||||
|
t.Fatalf("commit: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var filled, untouched sql.NullString
|
||||||
|
|
||||||
|
if err := db.QueryRowContext(ctx,
|
||||||
|
"SELECT phantom_file_path FROM playlist_tracks WHERE audio_file_id = 7",
|
||||||
|
).Scan(&filled); err != nil {
|
||||||
|
t.Fatalf("read the requested entry: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if filled.String != "/music/a.flac" {
|
||||||
|
t.Errorf(
|
||||||
|
"requested entry phantom_file_path = %q, want %q",
|
||||||
|
filled.String, "/music/a.flac",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := db.QueryRowContext(ctx,
|
||||||
|
"SELECT phantom_file_path FROM playlist_tracks WHERE audio_file_id = 8",
|
||||||
|
).Scan(&untouched); err != nil {
|
||||||
|
t.Fatalf("read the untouched entry: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if untouched.Valid {
|
||||||
|
t.Errorf(
|
||||||
|
"untouched entry got phantom_file_path = %q, want NULL "+
|
||||||
|
"(a scoped run must not rewrite the whole table)",
|
||||||
|
untouched.String,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,7 +40,8 @@ WHERE id = ? AND (mbid IS NULL OR mbid = '');
|
|||||||
-- name: GetAlbumsWithPendingReleaseMBID :many
|
-- name: GetAlbumsWithPendingReleaseMBID :many
|
||||||
SELECT id, pending_release_mbid FROM albums
|
SELECT id, pending_release_mbid FROM albums
|
||||||
WHERE pending_release_mbid IS NOT NULL AND pending_release_mbid != ''
|
WHERE pending_release_mbid IS NOT NULL AND pending_release_mbid != ''
|
||||||
AND (mbid IS NULL OR mbid = '');
|
AND (mbid IS NULL OR mbid = '')
|
||||||
|
LIMIT ?;
|
||||||
|
|
||||||
-- name: DeleteAlbum :exec
|
-- name: DeleteAlbum :exec
|
||||||
DELETE FROM albums WHERE id = ?;
|
DELETE FROM albums WHERE id = ?;
|
||||||
@@ -135,3 +136,49 @@ SELECT
|
|||||||
) AS INTEGER) AS known
|
) AS INTEGER) AS known
|
||||||
FROM audio_files a
|
FROM audio_files a
|
||||||
WHERE a.album_id = sqlc.arg(album_id);
|
WHERE a.album_id = sqlc.arg(album_id);
|
||||||
|
|
||||||
|
-- name: GetAlbumsCompleteness :many
|
||||||
|
-- The same question as GetAlbumCompleteness, asked of a screenful of
|
||||||
|
-- albums at once.
|
||||||
|
--
|
||||||
|
-- A card grid cannot afford one query per card, and the answer it wants
|
||||||
|
-- is the one thing a badge cannot guess: an album held 9 tracks of 12
|
||||||
|
-- must show the count, never a bare tick. So this is one query for the
|
||||||
|
-- whole grid, asked only of the cards that have a local album id.
|
||||||
|
--
|
||||||
|
-- It is two grouping levels rather than the single-album form's
|
||||||
|
-- correlated subqueries, because a correlated subquery in the FROM
|
||||||
|
-- clause is not something SQLite will reliably do -- and because the
|
||||||
|
-- slice may only be spelled once, or sqlc expands it twice with
|
||||||
|
-- independently numbered placeholders.
|
||||||
|
--
|
||||||
|
-- The per-disc level is where the meaning is, and it is the same
|
||||||
|
-- meaning as the single-album query. `owned` counts DISTINCT track
|
||||||
|
-- numbers within a disc (this app detects duplicates, and counting two
|
||||||
|
-- files of track 3 twice would report a short album as complete), with
|
||||||
|
-- a file that declares no track number falling back to its own id
|
||||||
|
-- because three untagged files are three tracks and not one.
|
||||||
|
-- `expected` takes each disc's declared total and sums over discs,
|
||||||
|
-- since a total is declared per disc and a release total written on
|
||||||
|
-- every file of a two-disc album would double its expectation. A disc
|
||||||
|
-- whose files declared nothing contributes a NULL that SUM ignores,
|
||||||
|
-- and `known` is what says the album is therefore unanswerable.
|
||||||
|
WITH per_disc AS (
|
||||||
|
SELECT
|
||||||
|
album_id AS album_id,
|
||||||
|
COUNT(DISTINCT COALESCE(CAST(track_number AS TEXT), 'f' || id))
|
||||||
|
AS owned_on_disc,
|
||||||
|
MAX(total_tracks) AS disc_total,
|
||||||
|
SUM(CASE WHEN total_tracks IS NULL THEN 1 ELSE 0 END)
|
||||||
|
AS discs_without_a_total
|
||||||
|
FROM audio_files
|
||||||
|
WHERE album_id IN (sqlc.slice('album_ids'))
|
||||||
|
GROUP BY album_id, COALESCE(disc_number, 1)
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
CAST(album_id AS INTEGER) AS album_id,
|
||||||
|
CAST(SUM(owned_on_disc) AS INTEGER) AS owned,
|
||||||
|
CAST(COALESCE(SUM(disc_total), 0) AS INTEGER) AS expected,
|
||||||
|
CAST(SUM(discs_without_a_total) = 0 AS INTEGER) AS known
|
||||||
|
FROM per_disc
|
||||||
|
GROUP BY album_id;
|
||||||
|
|||||||
@@ -342,3 +342,35 @@ WHERE ti.status = 'pending'
|
|||||||
)
|
)
|
||||||
ORDER BY ti.group_key
|
ORDER BY ti.group_key
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
|
||||||
|
-- name: GetTaggingItemsForAlbum :many
|
||||||
|
-- Every tagging group holding a file of this album.
|
||||||
|
--
|
||||||
|
-- The join is `audio_files.group_key`, not a key derived from the
|
||||||
|
-- album's folder path: a group carved out of a mixed-bag folder by
|
||||||
|
-- SplitMixedFolder is keyed on its tags rather than on a directory,
|
||||||
|
-- so a path-derived key finds nothing for exactly the messiest
|
||||||
|
-- libraries this is meant to help.
|
||||||
|
--
|
||||||
|
-- Usually one row. A multi-disc album is one group per disc, which
|
||||||
|
-- the caller has to know about rather than average over -- applying
|
||||||
|
-- to "the album" would silently retag one disc of three.
|
||||||
|
SELECT
|
||||||
|
ti.group_key,
|
||||||
|
ti.status,
|
||||||
|
ti.score,
|
||||||
|
ti.best_match_release_mbid,
|
||||||
|
ti.track_count,
|
||||||
|
ti.album_name,
|
||||||
|
ti.album_artist,
|
||||||
|
ti.synthetic
|
||||||
|
FROM tagging_items ti
|
||||||
|
WHERE ti.group_key IN (
|
||||||
|
SELECT DISTINCT af.group_key
|
||||||
|
FROM audio_files af
|
||||||
|
WHERE af.album_id = sqlc.arg(album_id) AND af.group_key != ''
|
||||||
|
)
|
||||||
|
AND ti.cleared_at IS NULL
|
||||||
|
-- Best first, with an unscored group last rather than first: NULL
|
||||||
|
-- sorts low in SQLite and DESC would put it at the top.
|
||||||
|
ORDER BY ti.score IS NULL, ti.score DESC, ti.group_key;
|
||||||
|
|||||||
@@ -68,8 +68,14 @@ CREATE TABLE IF NOT EXISTS audio_files (
|
|||||||
-- compared against the on-disk mtime during a scan to detect files
|
-- compared against the on-disk mtime during a scan to detect files
|
||||||
-- another application retagged in place.
|
-- another application retagged in place.
|
||||||
modified_at INTEGER NOT NULL DEFAULT 0,
|
modified_at INTEGER NOT NULL DEFAULT 0,
|
||||||
|
-- Listening counts, denormalized from listening_events so the hot
|
||||||
|
-- read path (track list sort, shelves, smart playlists) never joins
|
||||||
|
-- a log table. Authored: a rescan cannot rebuild them. This is the
|
||||||
|
-- "MIXED KIND" half of audio_files the datamap notes.
|
||||||
play_count INTEGER NOT NULL DEFAULT 0,
|
play_count INTEGER NOT NULL DEFAULT 0,
|
||||||
last_played DATETIME,
|
last_played DATETIME,
|
||||||
|
skip_count INTEGER NOT NULL DEFAULT 0,
|
||||||
|
last_skipped DATETIME,
|
||||||
tag_status TEXT NOT NULL DEFAULT 'untagged'
|
tag_status TEXT NOT NULL DEFAULT 'untagged'
|
||||||
CHECK(tag_status IN (
|
CHECK(tag_status IN (
|
||||||
'untagged', 'auto_matched', 'user_confirmed', 'user_skipped_permanent'
|
'untagged', 'auto_matched', 'user_confirmed', 'user_skipped_permanent'
|
||||||
|
|||||||
@@ -45,8 +45,6 @@ CREATE INDEX IF NOT EXISTS idx_download_items_live
|
|||||||
CREATE INDEX IF NOT EXISTS idx_download_items_state
|
CREATE INDEX IF NOT EXISTS idx_download_items_state
|
||||||
ON download_items(state);
|
ON download_items(state);
|
||||||
|
|
||||||
-- idx_download_items_download is deliberately NOT declared here: on an
|
-- ListDownloadItemsForDownload filters on the parent download.
|
||||||
-- existing database this table already exists at schema-pass time with
|
CREATE INDEX IF NOT EXISTS idx_download_items_download
|
||||||
-- its old column still named request_id, so an inline CREATE INDEX on
|
ON download_items(download_id);
|
||||||
-- download_id would fail outright. See ensureDownloadIndexes in
|
|
||||||
-- backend/database/download_rename_migration.go.
|
|
||||||
|
|||||||
@@ -66,14 +66,11 @@ CREATE TABLE IF NOT EXISTS download_requests (
|
|||||||
FOREIGN KEY(parent_id) REFERENCES download_requests(id) ON DELETE CASCADE
|
FOREIGN KEY(parent_id) REFERENCES download_requests(id) ON DELETE CASCADE
|
||||||
);
|
);
|
||||||
|
|
||||||
-- idx_download_requests_{due,entity,parent} are deliberately NOT
|
CREATE INDEX IF NOT EXISTS idx_download_requests_due
|
||||||
-- declared here. This table name is reused from the old one-shot
|
ON download_requests(state, next_try_at);
|
||||||
-- attempt table (also called download_requests before the Want/Request
|
|
||||||
-- rename), so on an existing database this CREATE TABLE is a no-op
|
CREATE INDEX IF NOT EXISTS idx_download_requests_entity
|
||||||
-- against a table that, at schema-pass time, is still shaped like the
|
ON download_requests(entity, state);
|
||||||
-- OLD attempts table and lacks these columns entirely — an inline
|
|
||||||
-- CREATE INDEX here would fail outright rather than just no-op. See
|
CREATE INDEX IF NOT EXISTS idx_download_requests_parent
|
||||||
-- migrateDownloadRename/ensureDownloadIndexes in
|
ON download_requests(parent_id) WHERE parent_id IS NOT NULL;
|
||||||
-- backend/database/download_rename_migration.go, which create these
|
|
||||||
-- once the rename has actually happened (or immediately, on a fresh
|
|
||||||
-- database where the columns exist from the start).
|
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
-- One row per track *exit*, three ways a listen can end: it reached
|
||||||
|
-- the end, it was heard enough to count and then skipped past, or it
|
||||||
|
-- was abandoned for another track before anyone had really listened.
|
||||||
|
--
|
||||||
|
-- This is the source of truth for listening behaviour. The
|
||||||
|
-- denormalized `play_count` / `last_played` / `skip_count` /
|
||||||
|
-- `last_skipped` on audio_files are materialized from it, because the
|
||||||
|
-- hot read path (track-list sort, the shelves, smart playlists) must
|
||||||
|
-- not join a log that grows by one row per song forever.
|
||||||
|
--
|
||||||
|
-- `kind` is the classification, applied at write time:
|
||||||
|
--
|
||||||
|
-- complete the track reached its natural end, or was skipped in
|
||||||
|
-- its tail window (the last few seconds of a long fade).
|
||||||
|
-- play the scrobble threshold was heard — half the track or
|
||||||
|
-- four minutes, whichever is less — and the user moved on
|
||||||
|
-- before the end.
|
||||||
|
-- skip the user moved to a different track before that.
|
||||||
|
--
|
||||||
|
-- `position_seconds` / `duration_seconds` are the raw reading the
|
||||||
|
-- classification was made from, kept so a future re-tune of the
|
||||||
|
-- threshold does not need the events re-recorded. 0/0 on a row means
|
||||||
|
-- "not captured for this event" (e.g. a natural finish recorded before
|
||||||
|
-- these columns existed), not "a zero-second track".
|
||||||
|
CREATE TABLE IF NOT EXISTS listening_events (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
audio_file_id INTEGER NOT NULL,
|
||||||
|
kind TEXT NOT NULL DEFAULT 'complete'
|
||||||
|
CHECK (kind IN ('complete', 'play', 'skip')),
|
||||||
|
position_seconds INTEGER NOT NULL DEFAULT 0,
|
||||||
|
duration_seconds INTEGER NOT NULL DEFAULT 0,
|
||||||
|
occurred_at DATETIME NOT NULL DEFAULT (datetime('now')),
|
||||||
|
FOREIGN KEY(audio_file_id) REFERENCES audio_files(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_listening_events_audio_file_id
|
||||||
|
ON listening_events(audio_file_id);
|
||||||
|
|
||||||
|
-- "What did I listen to this month" walks this, rather than the
|
||||||
|
-- per-track index above.
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_listening_events_occurred_at
|
||||||
|
ON listening_events(occurred_at);
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
CREATE TABLE IF NOT EXISTS play_history (
|
|
||||||
id INTEGER PRIMARY KEY,
|
|
||||||
audio_file_id INTEGER NOT NULL,
|
|
||||||
played_at DATETIME NOT NULL DEFAULT (datetime('now')),
|
|
||||||
FOREIGN KEY(audio_file_id) REFERENCES audio_files(id) ON DELETE CASCADE
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_play_history_audio_file_id
|
|
||||||
ON play_history(audio_file_id);
|
|
||||||
@@ -1,18 +1,15 @@
|
|||||||
CREATE TABLE IF NOT EXISTS queue (
|
CREATE TABLE IF NOT EXISTS queue (
|
||||||
id INTEGER PRIMARY KEY CHECK(id = 1),
|
id INTEGER PRIMARY KEY CHECK(id = 1),
|
||||||
source_playlist_id INTEGER,
|
|
||||||
current_position INTEGER NOT NULL DEFAULT 0,
|
current_position INTEGER NOT NULL DEFAULT 0,
|
||||||
shuffle_mode BOOLEAN NOT NULL DEFAULT false,
|
shuffle_mode BOOLEAN NOT NULL DEFAULT false,
|
||||||
repeat_mode TEXT NOT NULL DEFAULT 'off',
|
repeat_mode TEXT NOT NULL DEFAULT 'off',
|
||||||
shuffle_order TEXT,
|
shuffle_order TEXT,
|
||||||
-- source_playlist_id above is unused dead weight (nothing has ever
|
-- What the queue was built from ("Playing from: X"): an album,
|
||||||
-- written it a nonzero value); source_type/source_id/source_label
|
-- playlist, smart playlist, genre or artist, identified by the id
|
||||||
-- below are its generalized replacement, covering albums, playlists,
|
-- that source_type's namespace gives it.
|
||||||
-- smart playlists, genres and artists rather than playlists alone.
|
|
||||||
source_type TEXT NOT NULL DEFAULT '',
|
source_type TEXT NOT NULL DEFAULT '',
|
||||||
source_id INTEGER NOT NULL DEFAULT 0,
|
source_id INTEGER NOT NULL DEFAULT 0,
|
||||||
source_label TEXT NOT NULL DEFAULT '',
|
source_label TEXT NOT NULL DEFAULT ''
|
||||||
FOREIGN KEY(source_playlist_id) REFERENCES playlists(id) ON DELETE SET NULL
|
|
||||||
);
|
);
|
||||||
|
|
||||||
-- Singleton row: there is exactly one playback queue.
|
-- Singleton row: there is exactly one playback queue.
|
||||||
|
|||||||
@@ -26,17 +26,10 @@ CREATE TABLE IF NOT EXISTS tagging_items (
|
|||||||
-- complete rip of their own directory. parent_group_key is the
|
-- complete rip of their own directory. parent_group_key is the
|
||||||
-- original folder group they were split from.
|
-- original folder group they were split from.
|
||||||
--
|
--
|
||||||
-- These two columns are declared LAST, after created_at, even
|
-- These columns are appended after created_at rather than grouped
|
||||||
-- though that reads oddly next to the rest of the table: sql/
|
-- with the rest of the row: sqlc's `SELECT *` scans (GetTaggingItem)
|
||||||
-- migrations/0001 brings a pre-existing tagging_items up to date
|
-- bind column order positionally, so new columns always go at the
|
||||||
-- with `ALTER TABLE ADD COLUMN`, which SQLite always appends at
|
-- end.
|
||||||
-- the end of the column list. A fresh install (this file) and an
|
|
||||||
-- upgraded database (this file + the migration) must end up with
|
|
||||||
-- IDENTICAL column order, because sqlc-generated `SELECT *` scans
|
|
||||||
-- (e.g. GetTaggingItem) bind columns positionally — see the
|
|
||||||
-- schema/migration column-order test in database_test.go. Put
|
|
||||||
-- new columns wherever reads best when adding a table for the
|
|
||||||
-- first time; append-only from the second migration on.
|
|
||||||
synthetic INTEGER NOT NULL DEFAULT 0,
|
synthetic INTEGER NOT NULL DEFAULT 0,
|
||||||
parent_group_key TEXT NOT NULL DEFAULT '',
|
parent_group_key TEXT NOT NULL DEFAULT '',
|
||||||
-- album_artist_conflict latches to 1 the first time two tracks
|
-- album_artist_conflict latches to 1 the first time two tracks
|
||||||
@@ -58,10 +51,3 @@ CREATE INDEX IF NOT EXISTS idx_tagging_items_library_status
|
|||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_tagging_items_status_pending
|
CREATE INDEX IF NOT EXISTS idx_tagging_items_status_pending
|
||||||
ON tagging_items(library_id) WHERE status = 'pending';
|
ON tagging_items(library_id) WHERE status = 'pending';
|
||||||
|
|
||||||
-- idx_tagging_items_parent_group_key is NOT declared here on
|
|
||||||
-- purpose: this file runs unconditionally, before migrations, even
|
|
||||||
-- against a database that hasn't run 0001 yet — an index predicate
|
|
||||||
-- referencing parent_group_key would fail on that table. It lives
|
|
||||||
-- solely in sql/migrations/0001_tagging_items_synthetic.sql, which
|
|
||||||
-- runs after the column exists either way (see database.go).
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ package sqlcgen
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const deleteAlbum = `-- name: DeleteAlbum :exec
|
const deleteAlbum = `-- name: DeleteAlbum :exec
|
||||||
@@ -234,10 +235,103 @@ func (q *Queries) GetAlbumsByArtistName(ctx context.Context, arg GetAlbumsByArti
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getAlbumsCompleteness = `-- name: GetAlbumsCompleteness :many
|
||||||
|
WITH per_disc AS (
|
||||||
|
SELECT
|
||||||
|
album_id AS album_id,
|
||||||
|
COUNT(DISTINCT COALESCE(CAST(track_number AS TEXT), 'f' || id))
|
||||||
|
AS owned_on_disc,
|
||||||
|
MAX(total_tracks) AS disc_total,
|
||||||
|
SUM(CASE WHEN total_tracks IS NULL THEN 1 ELSE 0 END)
|
||||||
|
AS discs_without_a_total
|
||||||
|
FROM audio_files
|
||||||
|
WHERE album_id IN (/*SLICE:album_ids*/?)
|
||||||
|
GROUP BY album_id, COALESCE(disc_number, 1)
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
CAST(album_id AS INTEGER) AS album_id,
|
||||||
|
CAST(SUM(owned_on_disc) AS INTEGER) AS owned,
|
||||||
|
CAST(COALESCE(SUM(disc_total), 0) AS INTEGER) AS expected,
|
||||||
|
CAST(SUM(discs_without_a_total) = 0 AS INTEGER) AS known
|
||||||
|
FROM per_disc
|
||||||
|
GROUP BY album_id
|
||||||
|
`
|
||||||
|
|
||||||
|
type GetAlbumsCompletenessRow struct {
|
||||||
|
AlbumID int64
|
||||||
|
Owned int64
|
||||||
|
Expected int64
|
||||||
|
Known int64
|
||||||
|
}
|
||||||
|
|
||||||
|
// The same question as GetAlbumCompleteness, asked of a screenful of
|
||||||
|
// albums at once.
|
||||||
|
//
|
||||||
|
// A card grid cannot afford one query per card, and the answer it wants
|
||||||
|
// is the one thing a badge cannot guess: an album held 9 tracks of 12
|
||||||
|
// must show the count, never a bare tick. So this is one query for the
|
||||||
|
// whole grid, asked only of the cards that have a local album id.
|
||||||
|
//
|
||||||
|
// It is two grouping levels rather than the single-album form's
|
||||||
|
// correlated subqueries, because a correlated subquery in the FROM
|
||||||
|
// clause is not something SQLite will reliably do -- and because the
|
||||||
|
// slice may only be spelled once, or sqlc expands it twice with
|
||||||
|
// independently numbered placeholders.
|
||||||
|
//
|
||||||
|
// The per-disc level is where the meaning is, and it is the same
|
||||||
|
// meaning as the single-album query. `owned` counts DISTINCT track
|
||||||
|
// numbers within a disc (this app detects duplicates, and counting two
|
||||||
|
// files of track 3 twice would report a short album as complete), with
|
||||||
|
// a file that declares no track number falling back to its own id
|
||||||
|
// because three untagged files are three tracks and not one.
|
||||||
|
// `expected` takes each disc's declared total and sums over discs,
|
||||||
|
// since a total is declared per disc and a release total written on
|
||||||
|
// every file of a two-disc album would double its expectation. A disc
|
||||||
|
// whose files declared nothing contributes a NULL that SUM ignores,
|
||||||
|
// and `known` is what says the album is therefore unanswerable.
|
||||||
|
func (q *Queries) GetAlbumsCompleteness(ctx context.Context, albumIds []sql.NullInt64) ([]GetAlbumsCompletenessRow, error) {
|
||||||
|
query := getAlbumsCompleteness
|
||||||
|
var queryParams []interface{}
|
||||||
|
if len(albumIds) > 0 {
|
||||||
|
for _, v := range albumIds {
|
||||||
|
queryParams = append(queryParams, v)
|
||||||
|
}
|
||||||
|
query = strings.Replace(query, "/*SLICE:album_ids*/?", strings.Repeat(",?", len(albumIds))[1:], 1)
|
||||||
|
} else {
|
||||||
|
query = strings.Replace(query, "/*SLICE:album_ids*/?", "NULL", 1)
|
||||||
|
}
|
||||||
|
rows, err := q.db.QueryContext(ctx, query, queryParams...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []GetAlbumsCompletenessRow
|
||||||
|
for rows.Next() {
|
||||||
|
var i GetAlbumsCompletenessRow
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.AlbumID,
|
||||||
|
&i.Owned,
|
||||||
|
&i.Expected,
|
||||||
|
&i.Known,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Close(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
const getAlbumsWithPendingReleaseMBID = `-- name: GetAlbumsWithPendingReleaseMBID :many
|
const getAlbumsWithPendingReleaseMBID = `-- name: GetAlbumsWithPendingReleaseMBID :many
|
||||||
SELECT id, pending_release_mbid FROM albums
|
SELECT id, pending_release_mbid FROM albums
|
||||||
WHERE pending_release_mbid IS NOT NULL AND pending_release_mbid != ''
|
WHERE pending_release_mbid IS NOT NULL AND pending_release_mbid != ''
|
||||||
AND (mbid IS NULL OR mbid = '')
|
AND (mbid IS NULL OR mbid = '')
|
||||||
|
LIMIT ?
|
||||||
`
|
`
|
||||||
|
|
||||||
type GetAlbumsWithPendingReleaseMBIDRow struct {
|
type GetAlbumsWithPendingReleaseMBIDRow struct {
|
||||||
@@ -245,8 +339,8 @@ type GetAlbumsWithPendingReleaseMBIDRow struct {
|
|||||||
PendingReleaseMbid sql.NullString
|
PendingReleaseMbid sql.NullString
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) GetAlbumsWithPendingReleaseMBID(ctx context.Context) ([]GetAlbumsWithPendingReleaseMBIDRow, error) {
|
func (q *Queries) GetAlbumsWithPendingReleaseMBID(ctx context.Context, limit int64) ([]GetAlbumsWithPendingReleaseMBIDRow, error) {
|
||||||
rows, err := q.db.QueryContext(ctx, getAlbumsWithPendingReleaseMBID)
|
rows, err := q.db.QueryContext(ctx, getAlbumsWithPendingReleaseMBID, limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ INSERT INTO audio_files (
|
|||||||
?, ?, ?, ?, ?, ?,
|
?, ?, ?, ?, ?, ?,
|
||||||
?, ?, ?, ?, ?
|
?, ?, ?, ?, ?
|
||||||
)
|
)
|
||||||
RETURNING id, file_path, library_id, file_type_id, length_milliseconds, sample_rate, bit_depth, channels, bitrate, file_size, title, artist_credit, artist_id, album_id, track_number, disc_number, total_tracks, year, composer, comment, recording_mbid, basename, group_key, modified_at, play_count, last_played, tag_status
|
RETURNING id, file_path, library_id, file_type_id, length_milliseconds, sample_rate, bit_depth, channels, bitrate, file_size, title, artist_credit, artist_id, album_id, track_number, disc_number, total_tracks, year, composer, comment, recording_mbid, basename, group_key, modified_at, play_count, last_played, skip_count, last_skipped, tag_status
|
||||||
`
|
`
|
||||||
|
|
||||||
type CreateAudioFileParams struct {
|
type CreateAudioFileParams struct {
|
||||||
@@ -135,6 +135,8 @@ func (q *Queries) CreateAudioFile(ctx context.Context, arg CreateAudioFileParams
|
|||||||
&i.ModifiedAt,
|
&i.ModifiedAt,
|
||||||
&i.PlayCount,
|
&i.PlayCount,
|
||||||
&i.LastPlayed,
|
&i.LastPlayed,
|
||||||
|
&i.SkipCount,
|
||||||
|
&i.LastSkipped,
|
||||||
&i.TagStatus,
|
&i.TagStatus,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
@@ -192,7 +194,7 @@ func (q *Queries) GetAllAudioFilePaths(ctx context.Context) ([]GetAllAudioFilePa
|
|||||||
|
|
||||||
const getAudioFile = `-- name: GetAudioFile :one
|
const getAudioFile = `-- name: GetAudioFile :one
|
||||||
|
|
||||||
SELECT id, file_path, library_id, file_type_id, length_milliseconds, sample_rate, bit_depth, channels, bitrate, file_size, title, artist_credit, artist_id, album_id, track_number, disc_number, total_tracks, year, composer, comment, recording_mbid, basename, group_key, modified_at, play_count, last_played, tag_status FROM audio_files WHERE id = ? LIMIT 1
|
SELECT id, file_path, library_id, file_type_id, length_milliseconds, sample_rate, bit_depth, channels, bitrate, file_size, title, artist_credit, artist_id, album_id, track_number, disc_number, total_tracks, year, composer, comment, recording_mbid, basename, group_key, modified_at, play_count, last_played, skip_count, last_skipped, tag_status FROM audio_files WHERE id = ? LIMIT 1
|
||||||
`
|
`
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
@@ -228,13 +230,15 @@ func (q *Queries) GetAudioFile(ctx context.Context, id int64) (AudioFile, error)
|
|||||||
&i.ModifiedAt,
|
&i.ModifiedAt,
|
||||||
&i.PlayCount,
|
&i.PlayCount,
|
||||||
&i.LastPlayed,
|
&i.LastPlayed,
|
||||||
|
&i.SkipCount,
|
||||||
|
&i.LastSkipped,
|
||||||
&i.TagStatus,
|
&i.TagStatus,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
const getAudioFileByPath = `-- name: GetAudioFileByPath :one
|
const getAudioFileByPath = `-- name: GetAudioFileByPath :one
|
||||||
SELECT id, file_path, library_id, file_type_id, length_milliseconds, sample_rate, bit_depth, channels, bitrate, file_size, title, artist_credit, artist_id, album_id, track_number, disc_number, total_tracks, year, composer, comment, recording_mbid, basename, group_key, modified_at, play_count, last_played, tag_status FROM audio_files WHERE file_path = ? LIMIT 1
|
SELECT id, file_path, library_id, file_type_id, length_milliseconds, sample_rate, bit_depth, channels, bitrate, file_size, title, artist_credit, artist_id, album_id, track_number, disc_number, total_tracks, year, composer, comment, recording_mbid, basename, group_key, modified_at, play_count, last_played, skip_count, last_skipped, tag_status FROM audio_files WHERE file_path = ? LIMIT 1
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetAudioFileByPath(ctx context.Context, filePath string) (AudioFile, error) {
|
func (q *Queries) GetAudioFileByPath(ctx context.Context, filePath string) (AudioFile, error) {
|
||||||
@@ -267,6 +271,8 @@ func (q *Queries) GetAudioFileByPath(ctx context.Context, filePath string) (Audi
|
|||||||
&i.ModifiedAt,
|
&i.ModifiedAt,
|
||||||
&i.PlayCount,
|
&i.PlayCount,
|
||||||
&i.LastPlayed,
|
&i.LastPlayed,
|
||||||
|
&i.SkipCount,
|
||||||
|
&i.LastSkipped,
|
||||||
&i.TagStatus,
|
&i.TagStatus,
|
||||||
)
|
)
|
||||||
return i, err
|
return i, err
|
||||||
@@ -334,7 +340,7 @@ func (q *Queries) GetAudioFilesByPaths(ctx context.Context, paths []string) ([]G
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getAudioFilesInLibrary = `-- name: GetAudioFilesInLibrary :many
|
const getAudioFilesInLibrary = `-- name: GetAudioFilesInLibrary :many
|
||||||
SELECT id, file_path, library_id, file_type_id, length_milliseconds, sample_rate, bit_depth, channels, bitrate, file_size, title, artist_credit, artist_id, album_id, track_number, disc_number, total_tracks, year, composer, comment, recording_mbid, basename, group_key, modified_at, play_count, last_played, tag_status FROM audio_files WHERE library_id = ?
|
SELECT id, file_path, library_id, file_type_id, length_milliseconds, sample_rate, bit_depth, channels, bitrate, file_size, title, artist_credit, artist_id, album_id, track_number, disc_number, total_tracks, year, composer, comment, recording_mbid, basename, group_key, modified_at, play_count, last_played, skip_count, last_skipped, tag_status FROM audio_files WHERE library_id = ?
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetAudioFilesInLibrary(ctx context.Context, libraryID int64) ([]AudioFile, error) {
|
func (q *Queries) GetAudioFilesInLibrary(ctx context.Context, libraryID int64) ([]AudioFile, error) {
|
||||||
@@ -373,6 +379,8 @@ func (q *Queries) GetAudioFilesInLibrary(ctx context.Context, libraryID int64) (
|
|||||||
&i.ModifiedAt,
|
&i.ModifiedAt,
|
||||||
&i.PlayCount,
|
&i.PlayCount,
|
||||||
&i.LastPlayed,
|
&i.LastPlayed,
|
||||||
|
&i.SkipCount,
|
||||||
|
&i.LastSkipped,
|
||||||
&i.TagStatus,
|
&i.TagStatus,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -94,6 +94,8 @@ type AudioFile struct {
|
|||||||
ModifiedAt int64
|
ModifiedAt int64
|
||||||
PlayCount int64
|
PlayCount int64
|
||||||
LastPlayed sql.NullTime
|
LastPlayed sql.NullTime
|
||||||
|
SkipCount int64
|
||||||
|
LastSkipped sql.NullTime
|
||||||
TagStatus string
|
TagStatus string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,6 +263,15 @@ type Library struct {
|
|||||||
AutotagWarningAcked int64
|
AutotagWarningAcked int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ListeningEvent struct {
|
||||||
|
ID int64
|
||||||
|
AudioFileID int64
|
||||||
|
Kind string
|
||||||
|
PositionSeconds int64
|
||||||
|
DurationSeconds int64
|
||||||
|
OccurredAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
type Lyric struct {
|
type Lyric struct {
|
||||||
AudioFileID int64
|
AudioFileID int64
|
||||||
Text string
|
Text string
|
||||||
@@ -273,12 +284,6 @@ type LyricsIndex struct {
|
|||||||
Lyrics string
|
Lyrics string
|
||||||
}
|
}
|
||||||
|
|
||||||
type PlayHistory struct {
|
|
||||||
ID int64
|
|
||||||
AudioFileID int64
|
|
||||||
PlayedAt time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
type PlayerState struct {
|
type PlayerState struct {
|
||||||
ID int64
|
ID int64
|
||||||
Volume int64
|
Volume int64
|
||||||
@@ -313,7 +318,6 @@ type PlaylistTrack struct {
|
|||||||
|
|
||||||
type Queue struct {
|
type Queue struct {
|
||||||
ID int64
|
ID int64
|
||||||
SourcePlaylistID sql.NullInt64
|
|
||||||
CurrentPosition int64
|
CurrentPosition int64
|
||||||
ShuffleMode bool
|
ShuffleMode bool
|
||||||
RepeatMode string
|
RepeatMode string
|
||||||
|
|||||||
@@ -231,6 +231,82 @@ func (q *Queries) GetTaggingItem(ctx context.Context, groupKey string) (TaggingI
|
|||||||
return i, err
|
return i, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getTaggingItemsForAlbum = `-- name: GetTaggingItemsForAlbum :many
|
||||||
|
SELECT
|
||||||
|
ti.group_key,
|
||||||
|
ti.status,
|
||||||
|
ti.score,
|
||||||
|
ti.best_match_release_mbid,
|
||||||
|
ti.track_count,
|
||||||
|
ti.album_name,
|
||||||
|
ti.album_artist,
|
||||||
|
ti.synthetic
|
||||||
|
FROM tagging_items ti
|
||||||
|
WHERE ti.group_key IN (
|
||||||
|
SELECT DISTINCT af.group_key
|
||||||
|
FROM audio_files af
|
||||||
|
WHERE af.album_id = ?1 AND af.group_key != ''
|
||||||
|
)
|
||||||
|
AND ti.cleared_at IS NULL
|
||||||
|
ORDER BY ti.score IS NULL, ti.score DESC, ti.group_key
|
||||||
|
`
|
||||||
|
|
||||||
|
type GetTaggingItemsForAlbumRow struct {
|
||||||
|
GroupKey string
|
||||||
|
Status string
|
||||||
|
Score sql.NullFloat64
|
||||||
|
BestMatchReleaseMbid sql.NullString
|
||||||
|
TrackCount int64
|
||||||
|
AlbumName string
|
||||||
|
AlbumArtist string
|
||||||
|
Synthetic int64
|
||||||
|
}
|
||||||
|
|
||||||
|
// Every tagging group holding a file of this album.
|
||||||
|
//
|
||||||
|
// The join is `audio_files.group_key`, not a key derived from the
|
||||||
|
// album's folder path: a group carved out of a mixed-bag folder by
|
||||||
|
// SplitMixedFolder is keyed on its tags rather than on a directory,
|
||||||
|
// so a path-derived key finds nothing for exactly the messiest
|
||||||
|
// libraries this is meant to help.
|
||||||
|
//
|
||||||
|
// Usually one row. A multi-disc album is one group per disc, which
|
||||||
|
// the caller has to know about rather than average over -- applying
|
||||||
|
// to "the album" would silently retag one disc of three.
|
||||||
|
// Best first, with an unscored group last rather than first: NULL
|
||||||
|
// sorts low in SQLite and DESC would put it at the top.
|
||||||
|
func (q *Queries) GetTaggingItemsForAlbum(ctx context.Context, albumID sql.NullInt64) ([]GetTaggingItemsForAlbumRow, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, getTaggingItemsForAlbum, albumID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []GetTaggingItemsForAlbumRow
|
||||||
|
for rows.Next() {
|
||||||
|
var i GetTaggingItemsForAlbumRow
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.GroupKey,
|
||||||
|
&i.Status,
|
||||||
|
&i.Score,
|
||||||
|
&i.BestMatchReleaseMbid,
|
||||||
|
&i.TrackCount,
|
||||||
|
&i.AlbumName,
|
||||||
|
&i.AlbumArtist,
|
||||||
|
&i.Synthetic,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Close(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
const listAudioFilesInTaggingGroup = `-- name: ListAudioFilesInTaggingGroup :many
|
const listAudioFilesInTaggingGroup = `-- name: ListAudioFilesInTaggingGroup :many
|
||||||
SELECT
|
SELECT
|
||||||
af.id,
|
af.id,
|
||||||
|
|||||||
@@ -245,6 +245,13 @@ func dropDeferred(
|
|||||||
ctx context.Context, db *sql.DB, logger *slog.Logger,
|
ctx context.Context, db *sql.DB, logger *slog.Logger,
|
||||||
drop map[string]string,
|
drop map[string]string,
|
||||||
) error {
|
) error {
|
||||||
|
// Asked before the transaction opens, because the answer is about
|
||||||
|
// which tables are live and that cannot change underneath us here.
|
||||||
|
preserve, err := shouldPreservePhantoms(ctx, db, drop)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
tx, err := db.BeginTx(ctx, nil)
|
tx, err := db.BeginTx(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not begin the retire transaction: %w", err)
|
return fmt.Errorf("could not begin the retire transaction: %w", err)
|
||||||
@@ -256,6 +263,22 @@ func dropDeferred(
|
|||||||
return fmt.Errorf("could not defer foreign keys: %w", err)
|
return fmt.Errorf("could not defer foreign keys: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Before any drop, so every entry still has a track to read. It is
|
||||||
|
// in this transaction rather than beside it because the preservation
|
||||||
|
// and the delete have to succeed or fail together: a commit that
|
||||||
|
// dropped the files without the phantoms is the bug, and a commit
|
||||||
|
// that wrote phantoms without dropping anything is a lie about rows
|
||||||
|
// that are still there.
|
||||||
|
if preserve {
|
||||||
|
logger.Info(
|
||||||
|
"preserving playlist entries across the retire of audio_files",
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := PreservePlaylistPhantoms(ctx, tx, logger); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Sorted, so a failure is reproducible. Map order is random, and a
|
// Sorted, so a failure is reproducible. Map order is random, and a
|
||||||
// bug that depends on which table happens to go first reproduces on
|
// bug that depends on which table happens to go first reproduces on
|
||||||
// one run in three and passes review on the other two -- which is
|
// one run in three and passes review on the other two -- which is
|
||||||
@@ -283,6 +306,38 @@ func dropDeferred(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// shouldPreservePhantoms reports whether this retire is about to take
|
||||||
|
// `audio_files` out from under the playlists.
|
||||||
|
//
|
||||||
|
// The `playlist_tracks` check is not defensive padding. This runs
|
||||||
|
// *before* applySchema, which is the moment the schema is by definition
|
||||||
|
// mid-repair, and the preservation reads a table it does not drop. A
|
||||||
|
// database old enough not to have it would otherwise fail here, and
|
||||||
|
// failing here means the app does not open at all -- while nothing is
|
||||||
|
// lost by skipping, since an absent `playlist_tracks` holds no
|
||||||
|
// playlists to save.
|
||||||
|
//
|
||||||
|
// It deliberately does *not* ask after `track_metadata`. Whether that
|
||||||
|
// view can answer is PreservePlaylistPhantoms's own business, because a
|
||||||
|
// view broken against an older `audio_files` is a state this function
|
||||||
|
// cannot detect without hitting the same error it is trying to avoid:
|
||||||
|
// pragma_table_info on such a view errors rather than reporting no
|
||||||
|
// columns.
|
||||||
|
func shouldPreservePhantoms(
|
||||||
|
ctx context.Context, db *sql.DB, drop map[string]string,
|
||||||
|
) (bool, error) {
|
||||||
|
if _, going := drop["audio_files"]; !going {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
cols, err := liveColumns(ctx, db, "playlist_tracks")
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return len(cols) > 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
// staleReason reports why a live table disagrees with its declaration,
|
// staleReason reports why a live table disagrees with its declaration,
|
||||||
// or "" when it agrees. A column the live table does not have is the
|
// or "" when it agrees. A column the live table does not have is the
|
||||||
// additive case; a column whose declared type changed is the one an
|
// additive case; a column whose declared type changed is the one an
|
||||||
|
|||||||
@@ -497,3 +497,180 @@ func TestParseCreateTablesReadsTheRealSchema(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestRetiringAudioFilesKeepsPlaylistContents is the symptom this
|
||||||
|
// repair exists for: a playlist survived the retire as a row count and
|
||||||
|
// nothing else.
|
||||||
|
//
|
||||||
|
// TestRetiringOwnedTablesDoesNotDangle already asserts the entry does
|
||||||
|
// not keep a stale id, which is the *dangerous* half. It is satisfied
|
||||||
|
// just as well by an entry that says nothing at all, which is the
|
||||||
|
// half that quietly emptied every playlist -- so this asserts what the
|
||||||
|
// entry still knows, and specifically phantom_file_path, because that
|
||||||
|
// is the column ResolvePhantomTracksAfterScan matches back against
|
||||||
|
// audio_files.file_path.
|
||||||
|
//
|
||||||
|
// Note the seed drops `comment`, not `artist_credit`: the mutation has
|
||||||
|
// to leave `track_metadata` standing, since a real launch reaches the
|
||||||
|
// retire with the view the previous launch created. A test that drops
|
||||||
|
// the view first is testing the skip path, not this one.
|
||||||
|
func TestRetiringAudioFilesKeepsPlaylistContents(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
db := openRaw(t, t.TempDir())
|
||||||
|
|
||||||
|
if _, err := db.ExecContext(ctx, "PRAGMA foreign_keys = ON"); err != nil {
|
||||||
|
t.Fatalf("pragma: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := applySchema(ctx, db); err != nil {
|
||||||
|
t.Fatalf("applySchema: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := db.ExecContext(ctx, `
|
||||||
|
INSERT INTO playlists (id, name) VALUES (1, 'keepme');
|
||||||
|
INSERT INTO libraries (id, name, path) VALUES (0, 'test', '/music');
|
||||||
|
INSERT INTO artists (id, name) VALUES (3, 'Aurora Fields');
|
||||||
|
INSERT INTO cover_art (id, file_path, mime_type)
|
||||||
|
VALUES (9, 'covers/7.jpg', 'image/jpeg');
|
||||||
|
INSERT INTO genres (id, name) VALUES (5, 'Ambient');
|
||||||
|
INSERT INTO albums (id, name, artist_id, cover_art_id)
|
||||||
|
VALUES (4, 'Tideline', 3, 9);
|
||||||
|
INSERT INTO audio_files
|
||||||
|
(id, file_path, file_type_id, length_milliseconds,
|
||||||
|
title, artist_credit, artist_id, album_id)
|
||||||
|
VALUES (7, '/music/a.flac', 1, 1000,
|
||||||
|
'Slack Water', 'Aurora Fields', 3, 4);
|
||||||
|
INSERT INTO file_genres (audio_file_id, genre_id) VALUES (7, 5);
|
||||||
|
INSERT INTO playlist_tracks (playlist_id, audio_file_id, position)
|
||||||
|
VALUES (1, 7, 0);
|
||||||
|
ALTER TABLE audio_files DROP COLUMN comment;
|
||||||
|
`); err != nil {
|
||||||
|
t.Fatalf("seed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := retireStaleTables(ctx, db, testLogger()); err != nil {
|
||||||
|
t.Fatalf("retire: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := applySchema(ctx, db); err != nil {
|
||||||
|
t.Fatalf("applySchema: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
path, title, artist, album, genre, cover sql.NullString
|
||||||
|
duration sql.NullInt64
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := db.QueryRowContext(ctx, `
|
||||||
|
SELECT phantom_file_path, phantom_title, phantom_artist,
|
||||||
|
phantom_album, phantom_duration_ms, phantom_genre,
|
||||||
|
phantom_cover_art_path
|
||||||
|
FROM playlist_tracks WHERE playlist_id = 1
|
||||||
|
`).Scan(&path, &title, &artist, &album, &duration, &genre, &cover); err != nil {
|
||||||
|
t.Fatalf("read the surviving entry: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The one that matters: without it the entry can never be re-linked
|
||||||
|
// by the rescan the retire itself provokes.
|
||||||
|
if path.String != "/music/a.flac" {
|
||||||
|
t.Fatalf(
|
||||||
|
"phantom_file_path is %q, want %q -- the playlist entry "+
|
||||||
|
"cannot be re-linked and the playlist is empty for good",
|
||||||
|
path.String, "/music/a.flac",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if title.String != "Slack Water" {
|
||||||
|
t.Errorf("phantom_title is %q, want %q", title.String, "Slack Water")
|
||||||
|
}
|
||||||
|
|
||||||
|
if artist.String != "Aurora Fields" {
|
||||||
|
t.Errorf("phantom_artist is %q, want %q", artist.String, "Aurora Fields")
|
||||||
|
}
|
||||||
|
|
||||||
|
if album.String != "Tideline" {
|
||||||
|
t.Errorf("phantom_album is %q, want %q", album.String, "Tideline")
|
||||||
|
}
|
||||||
|
|
||||||
|
if duration.Int64 != 1000 {
|
||||||
|
t.Errorf("phantom_duration_ms is %d, want 1000", duration.Int64)
|
||||||
|
}
|
||||||
|
|
||||||
|
if genre.String != "Ambient" {
|
||||||
|
t.Errorf("phantom_genre is %q, want %q", genre.String, "Ambient")
|
||||||
|
}
|
||||||
|
|
||||||
|
if cover.String != "covers/7.jpg" {
|
||||||
|
t.Errorf("phantom_cover_art_path is %q, want %q", cover.String, "covers/7.jpg")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestRetiringAudioFilesKeepsPathsWhenTheViewCannotAnswer is the case
|
||||||
|
// that broke cmd/indexbuild: this repair runs *before* applySchema, so
|
||||||
|
// `track_metadata` is whatever the last launch declared while
|
||||||
|
// `audio_files` is whatever the launch before that left behind, and a
|
||||||
|
// view over columns the table no longer has does not read as empty --
|
||||||
|
// it errors.
|
||||||
|
//
|
||||||
|
// The pre-013 stub shape below is the real one that fixture carries.
|
||||||
|
// What must survive is phantom_file_path, because `file_path` is the
|
||||||
|
// table's natural key and has been in every shape it ever had; the
|
||||||
|
// display columns are allowed to be absent, and the open must not fail.
|
||||||
|
func TestRetiringAudioFilesKeepsPathsWhenTheViewCannotAnswer(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
db := openRaw(t, t.TempDir())
|
||||||
|
|
||||||
|
if _, err := db.ExecContext(ctx, "PRAGMA foreign_keys = ON"); err != nil {
|
||||||
|
t.Fatalf("pragma: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := applySchema(ctx, db); err != nil {
|
||||||
|
t.Fatalf("applySchema: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The rows go in *after* the reshape: dropping audio_files with
|
||||||
|
// foreign keys on would fire the ON DELETE SET NULL and null the
|
||||||
|
// entry this test is about, which would pass for the wrong reason.
|
||||||
|
if _, err := db.ExecContext(ctx, `
|
||||||
|
DROP TABLE audio_files;
|
||||||
|
CREATE TABLE audio_files (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
file_path TEXT NOT NULL UNIQUE,
|
||||||
|
recording_id INTEGER
|
||||||
|
);
|
||||||
|
INSERT INTO playlists (id, name) VALUES (1, 'keepme');
|
||||||
|
INSERT INTO audio_files (id, file_path) VALUES (7, '/music/a.flac');
|
||||||
|
INSERT INTO playlist_tracks (playlist_id, audio_file_id, position)
|
||||||
|
VALUES (1, 7, 0);
|
||||||
|
`); err != nil {
|
||||||
|
t.Fatalf("seed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The symptom this guards: the repair must not turn a recoverable
|
||||||
|
// database into one the app refuses to open.
|
||||||
|
if err := retireStaleTables(ctx, db, testLogger()); err != nil {
|
||||||
|
t.Fatalf(
|
||||||
|
"the retire failed on a view it could not read, so the app "+
|
||||||
|
"would not open at all: %v", err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := applySchema(ctx, db); err != nil {
|
||||||
|
t.Fatalf("applySchema: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var path sql.NullString
|
||||||
|
if err := db.QueryRowContext(ctx,
|
||||||
|
"SELECT phantom_file_path FROM playlist_tracks WHERE playlist_id = 1",
|
||||||
|
).Scan(&path); err != nil {
|
||||||
|
t.Fatalf("read the surviving entry: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if path.String != "/music/a.flac" {
|
||||||
|
t.Fatalf(
|
||||||
|
"phantom_file_path is %q, want %q -- the display half being "+
|
||||||
|
"unavailable must not cost the entry its one re-link key",
|
||||||
|
path.String, "/music/a.flac",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -269,10 +269,11 @@ var tables = []Table{
|
|||||||
"from owned files plus the LRCLIB backfill.",
|
"from owned files plus the LRCLIB backfill.",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "play_history", Kind: Authored, Lifetime: Cascade,
|
Name: "listening_events", Kind: Authored, Lifetime: Cascade,
|
||||||
Note: "Listening history. Authored, but intentionally cascades " +
|
Note: "Listening history, one row per track exit (complete, play " +
|
||||||
"with its track — history for a file no longer in the library " +
|
"or skip). Authored, but intentionally cascades with its " +
|
||||||
"has nothing to point at.",
|
"track — history for a file no longer in the library has " +
|
||||||
|
"nothing to point at.",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "player_state", Kind: Authored, Lifetime: Retained,
|
Name: "player_state", Kind: Authored, Lifetime: Retained,
|
||||||
|
|||||||
@@ -212,13 +212,13 @@ func TestLifetimesMatchSchema(t *testing.T) {
|
|||||||
|
|
||||||
// Authored data is unrecoverable, so it must never be removed as a side
|
// Authored data is unrecoverable, so it must never be removed as a side
|
||||||
// effect of deleting owned data. Cascade is allowed only where the
|
// effect of deleting owned data. Cascade is allowed only where the
|
||||||
// catalog explains why (play_history, queue_tracks); this test pins the
|
// catalog explains why (listening_events, queue_tracks); this test pins the
|
||||||
// set so a new cascade onto authored data is a deliberate decision.
|
// set so a new cascade onto authored data is a deliberate decision.
|
||||||
func TestAuthoredCascadesAreDeliberate(t *testing.T) {
|
func TestAuthoredCascadesAreDeliberate(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
allowed := map[string]bool{
|
allowed := map[string]bool{
|
||||||
"play_history": true,
|
"listening_events": true,
|
||||||
"queue_tracks": true,
|
"queue_tracks": true,
|
||||||
|
|
||||||
// Download history is scoped to the library it imported into.
|
// Download history is scoped to the library it imported into.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -144,17 +145,36 @@ func (c *apiClient) checkStatus(resp *http.Response) error {
|
|||||||
case resp.StatusCode >= 400:
|
case resp.StatusCode >= 400:
|
||||||
snippet, _ := io.ReadAll(io.LimitReader(resp.Body, 512))
|
snippet, _ := io.ReadAll(io.LimitReader(resp.Body, 512))
|
||||||
|
|
||||||
return fmt.Errorf(
|
return fmt.Errorf("%w: %w", c.errUnreachable, &httpStatusError{
|
||||||
"%w: HTTP %d: %s",
|
code: resp.StatusCode,
|
||||||
c.errUnreachable,
|
body: strings.TrimSpace(string(snippet)),
|
||||||
resp.StatusCode,
|
})
|
||||||
strings.TrimSpace(string(snippet)),
|
|
||||||
)
|
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// httpStatusError is a non-2xx answer, kept typed so a caller can tell
|
||||||
|
// a missing endpoint from a daemon that is down.
|
||||||
|
type httpStatusError struct {
|
||||||
|
code int
|
||||||
|
body string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *httpStatusError) Error() string {
|
||||||
|
return fmt.Sprintf("HTTP %d: %s", e.code, e.body)
|
||||||
|
}
|
||||||
|
|
||||||
|
// statusCode returns the HTTP status an error carries, or 0.
|
||||||
|
func statusCode(err error) int {
|
||||||
|
var se *httpStatusError
|
||||||
|
if errors.As(err, &se) {
|
||||||
|
return se.code
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
// decodeJSON decodes a JSON string into out. Providers whose auth or
|
// decodeJSON decodes a JSON string into out. Providers whose auth or
|
||||||
// response handling does not fit apiClient still parse bodies the same
|
// response handling does not fit apiClient still parse bodies the same
|
||||||
// way, so the helper lives here rather than being repeated.
|
// way, so the helper lives here rather than being repeated.
|
||||||
|
|||||||
@@ -0,0 +1,248 @@
|
|||||||
|
package download
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Multi-disc rips, single-track results and coverage counted in tracks
|
||||||
|
// rather than files (#270).
|
||||||
|
|
||||||
|
func TestParsePathReadsTheDiscFromItsFolder(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
cases := []struct {
|
||||||
|
path string
|
||||||
|
disc int
|
||||||
|
track int
|
||||||
|
folder string
|
||||||
|
}{
|
||||||
|
{`\share\Pink Floyd - The Wall (1979)\CD2\03 Hey You.flac`, 2, 3, "The Wall"},
|
||||||
|
{`\share\The Wall\Disc 1\01 In The Flesh.flac`, 1, 1, "The Wall"},
|
||||||
|
{`\share\The Wall\[Disk-2]\01 Hey You.flac`, 2, 1, "The Wall"},
|
||||||
|
{`\share\The Wall\CD1 - Live\04 Mother.flac`, 1, 4, "The Wall"},
|
||||||
|
// The filename's own disc number is more specific than the folder.
|
||||||
|
{`\share\The Wall\CD1\2-05 Comfortably Numb.flac`, 2, 5, "The Wall"},
|
||||||
|
// Not a disc folder: a number is required.
|
||||||
|
{`\share\CDs\The Wall\01 In The Flesh.flac`, 0, 1, "The Wall"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.path, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
got := ParsePath(tc.path)
|
||||||
|
if got.Disc != tc.disc || got.Track != tc.track || got.Folder != tc.folder {
|
||||||
|
t.Errorf(
|
||||||
|
"ParsePath = disc %d track %d folder %q, want %d %d %q",
|
||||||
|
got.Disc, got.Track, got.Folder, tc.disc, tc.track, tc.folder,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAlbumDir(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
cases := map[string]string{
|
||||||
|
`\share\Album\CD1\01 A.flac`: "/share/Album",
|
||||||
|
`\share\Album\01 A.flac`: "/share/Album",
|
||||||
|
`CD1\01 A.flac`: "CD1",
|
||||||
|
`\share\CD Collection\01.mp3`: "/share/CD Collection",
|
||||||
|
}
|
||||||
|
|
||||||
|
for in, want := range cases {
|
||||||
|
if got := AlbumDir(in); got != want {
|
||||||
|
t.Errorf("AlbumDir(%q) = %q, want %q", in, got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// One album shared as CD1/CD2 is one candidate, named after the album.
|
||||||
|
func TestSlskdGroupsDiscFoldersIntoOneCandidate(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
stub := newSlskdStub(t)
|
||||||
|
stub.responses = []slskdResponse{{
|
||||||
|
Username: "peer",
|
||||||
|
Files: []slskdFile{
|
||||||
|
{Filename: `\m\The Wall\CD1\01 In The Flesh.flac`, Size: 1},
|
||||||
|
{Filename: `\m\The Wall\CD1\02 The Thin Ice.flac`, Size: 1},
|
||||||
|
{Filename: `\m\The Wall\CD2\01 Hey You.flac`, Size: 1},
|
||||||
|
{Filename: `\m\The Wall\CD2\02 Is There Anybody Out There.flac`, Size: 1},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
|
||||||
|
s, _ := newStubSlskd(t, stub)
|
||||||
|
|
||||||
|
got, err := s.Search(context.Background(), Download{Query: "the wall"})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Search: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(got) != 1 {
|
||||||
|
t.Fatalf("got %d candidates, want the two discs as one", len(got))
|
||||||
|
}
|
||||||
|
|
||||||
|
if got[0].Title != "The Wall" || len(got[0].Files) != 4 {
|
||||||
|
t.Errorf(
|
||||||
|
"candidate = %q with %d files, want \"The Wall\" with 4",
|
||||||
|
got[0].Title, len(got[0].Files),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A track search matches one file per folder, so a single-track request
|
||||||
|
// must accept a one-file folder that an album request rightly drops.
|
||||||
|
func TestSlskdKeepsASingleFileForATrackRequest(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
stub := newSlskdStub(t)
|
||||||
|
stub.responses = []slskdResponse{{
|
||||||
|
Username: "peer",
|
||||||
|
Files: []slskdFile{
|
||||||
|
{Filename: `\m\OK Computer\02 Paranoid Android.flac`, Size: 1},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
|
||||||
|
s, _ := newStubSlskd(t, stub)
|
||||||
|
|
||||||
|
track, err := s.Search(context.Background(), Download{
|
||||||
|
RecordingMBID: "rec-1", Artist: "Radiohead", Album: "Paranoid Android",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Search: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(track) != 1 {
|
||||||
|
t.Errorf("track request: got %d candidates, want 1", len(track))
|
||||||
|
}
|
||||||
|
|
||||||
|
album, err := s.Search(context.Background(), Download{
|
||||||
|
ReleaseMBID: "rel-1", Artist: "Radiohead", Album: "OK Computer",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Search: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(album) != 0 {
|
||||||
|
t.Errorf("album request: got %d candidates, want the one-file folder dropped", len(album))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Two discs with a file of the same name both reach staging, each under
|
||||||
|
// its disc folder, where the importer reads the disc number from.
|
||||||
|
func TestSlskdCollectKeepsDiscFolders(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
stub := newSlskdStub(t)
|
||||||
|
s, downloads := newStubSlskd(t, stub)
|
||||||
|
|
||||||
|
for _, disc := range []string{"CD1", "CD2"} {
|
||||||
|
dir := filepath.Join(downloads, disc)
|
||||||
|
if err := os.MkdirAll(dir, 0o750); err != nil {
|
||||||
|
t.Fatalf("mkdir: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.WriteFile(
|
||||||
|
filepath.Join(dir, "01 Intro.flac"), []byte(disc), 0o600,
|
||||||
|
); err != nil {
|
||||||
|
t.Fatalf("write: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dst := t.TempDir()
|
||||||
|
|
||||||
|
got, err := s.collect(Candidate{Files: []CandidateFile{
|
||||||
|
{Path: `\m\Album\CD1\01 Intro.flac`, IsAudio: true},
|
||||||
|
{Path: `\m\Album\CD2\01 Intro.flac`, IsAudio: true},
|
||||||
|
}}, dst, "", nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("collect: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(got.Files) != 2 {
|
||||||
|
t.Fatalf("collected %d files, want 2", len(got.Files))
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, disc := range []string{"CD1", "CD2"} {
|
||||||
|
data, err := os.ReadFile(filepath.Join(dst, disc, "01 Intro.flac"))
|
||||||
|
if err != nil || string(data) != disc {
|
||||||
|
t.Errorf("%s's file missing or overwritten: %q, %v", disc, data, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if hint := ParsePath(filepath.Join(dst, disc, "01 Intro.flac")); hint.Disc == 0 {
|
||||||
|
t.Errorf("staged %s file lost its disc number", disc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A two-disc release whose discs both number from 01 aligns completely
|
||||||
|
// once the disc comes from the folder; before, disc 2's 01 collided with
|
||||||
|
// disc 1's.
|
||||||
|
func TestMultiDiscCandidateAlignsEveryTrack(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
dl := Download{
|
||||||
|
ReleaseMBID: "the-wall",
|
||||||
|
Artist: "Pink Floyd",
|
||||||
|
Album: "The Wall",
|
||||||
|
Expected: []ExpectedTrack{
|
||||||
|
{DiscNumber: 1, Position: 1, Title: "In the Flesh?"},
|
||||||
|
{DiscNumber: 1, Position: 2, Title: "The Thin Ice"},
|
||||||
|
{DiscNumber: 2, Position: 1, Title: "Hey You"},
|
||||||
|
{DiscNumber: 2, Position: 2, Title: "Is There Anybody Out There?"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
c := Candidate{
|
||||||
|
Title: "The Wall",
|
||||||
|
Files: []CandidateFile{
|
||||||
|
{Path: `\m\Pink Floyd - The Wall\CD1\01 In the Flesh.flac`, Size: 1},
|
||||||
|
{Path: `\m\Pink Floyd - The Wall\CD1\02 The Thin Ice.flac`, Size: 1},
|
||||||
|
{Path: `\m\Pink Floyd - The Wall\CD2\01 Hey You.flac`, Size: 1},
|
||||||
|
{Path: `\m\Pink Floyd - The Wall\CD2\02 Is There Anybody Out There.flac`, Size: 1},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
got := Score(dl, c, 50, AutoDownloadPrefs{})
|
||||||
|
|
||||||
|
if got.Match.Completeness != 1 {
|
||||||
|
t.Errorf("completeness = %f, want 1", got.Match.Completeness)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got.Match.AlbumFit < 0.99 {
|
||||||
|
t.Errorf("album fit = %f, want the album's own name to match", got.Match.AlbumFit)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got.Match.Overall < minMatch {
|
||||||
|
t.Errorf("match = %f, want it to clear the auto-pick bar %f", got.Match.Overall, minMatch)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ten files against a ten-track album is not a complete album when only
|
||||||
|
// three of them are its tracks.
|
||||||
|
func TestCompletenessCountsTracksNotFiles(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
dl := okComputer()
|
||||||
|
|
||||||
|
c := Candidate{Title: "OK Computer", Files: []CandidateFile{
|
||||||
|
{Path: `\m\Radiohead - OK Computer\Airbag.flac`, Size: 1},
|
||||||
|
{Path: `\m\Radiohead - OK Computer\Paranoid Android.flac`, Size: 1},
|
||||||
|
{Path: `\m\Radiohead - OK Computer\Exit Music (For a Film).flac`, Size: 1},
|
||||||
|
{Path: `\m\Radiohead - OK Computer\Creep.flac`, Size: 1},
|
||||||
|
}}
|
||||||
|
|
||||||
|
got := Score(dl, c, 50, AutoDownloadPrefs{})
|
||||||
|
|
||||||
|
if got.Match.Completeness > 0.76 {
|
||||||
|
t.Errorf(
|
||||||
|
"completeness = %f with 3 of 4 tracks present, want at most 0.75",
|
||||||
|
got.Match.Completeness,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -47,7 +47,7 @@ func grabAll(
|
|||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
f.manager.grab(ctx, dl, candidate, nil)
|
f.manager.grab(ctx, dl, candidate, nil, false)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,9 +79,9 @@ func TestConcurrencyForPrefersOverrideThenKind(t *testing.T) {
|
|||||||
want int
|
want int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "slskd defaults to one",
|
name: "slskd defaults to a few peers",
|
||||||
cfg: Config{Kind: KindSlskd},
|
cfg: Config{Kind: KindSlskd},
|
||||||
want: 1,
|
want: 3,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "usenet defaults higher",
|
name: "usenet defaults higher",
|
||||||
@@ -92,9 +92,9 @@ func TestConcurrencyForPrefersOverrideThenKind(t *testing.T) {
|
|||||||
name: "explicit override wins",
|
name: "explicit override wins",
|
||||||
cfg: Config{
|
cfg: Config{
|
||||||
Kind: KindSlskd,
|
Kind: KindSlskd,
|
||||||
Settings: map[string]string{concurrencyKey: "3"},
|
Settings: map[string]string{concurrencyKey: "1"},
|
||||||
},
|
},
|
||||||
want: 3,
|
want: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "nonsense override falls back",
|
name: "nonsense override falls back",
|
||||||
@@ -102,7 +102,7 @@ func TestConcurrencyForPrefersOverrideThenKind(t *testing.T) {
|
|||||||
Kind: KindSlskd,
|
Kind: KindSlskd,
|
||||||
Settings: map[string]string{concurrencyKey: "not a number"},
|
Settings: map[string]string{concurrencyKey: "not a number"},
|
||||||
},
|
},
|
||||||
want: 1,
|
want: 3,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "zero override falls back",
|
name: "zero override falls back",
|
||||||
@@ -110,7 +110,7 @@ func TestConcurrencyForPrefersOverrideThenKind(t *testing.T) {
|
|||||||
Kind: KindSlskd,
|
Kind: KindSlskd,
|
||||||
Settings: map[string]string{concurrencyKey: "0"},
|
Settings: map[string]string{concurrencyKey: "0"},
|
||||||
},
|
},
|
||||||
want: 1,
|
want: 3,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "unknown kind falls back to the global default",
|
name: "unknown kind falls back to the global default",
|
||||||
@@ -126,9 +126,9 @@ func TestConcurrencyForPrefersOverrideThenKind(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The reason the per-provider cap exists: a Soulseek daemon capped at
|
// The reason the per-provider cap exists: a daemon capped at one
|
||||||
// one transfer must serialize, even when the global cap would allow
|
// transfer must serialize, even when the global cap would allow more and
|
||||||
// more and the user has queued several albums at once.
|
// the user has queued several albums at once.
|
||||||
func TestPerProviderCapSerializesTransfers(t *testing.T) {
|
func TestPerProviderCapSerializesTransfers(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
@@ -142,6 +142,7 @@ func TestPerProviderCapSerializesTransfers(t *testing.T) {
|
|||||||
ID: 1,
|
ID: 1,
|
||||||
Kind: KindSlskd,
|
Kind: KindSlskd,
|
||||||
Priority: 50,
|
Priority: 50,
|
||||||
|
Settings: map[string]string{concurrencyKey: "1"},
|
||||||
}, slow)
|
}, slow)
|
||||||
|
|
||||||
// Three requests against the same one-at-a-time provider.
|
// Three requests against the same one-at-a-time provider.
|
||||||
@@ -210,8 +211,8 @@ func TestSyncSemaphoresReplacesChangedLimits(t *testing.T) {
|
|||||||
f.manager.installProvider(Config{ID: 1, Kind: KindSlskd}, nil)
|
f.manager.installProvider(Config{ID: 1, Kind: KindSlskd}, nil)
|
||||||
|
|
||||||
first := f.manager.semaphoreFor(1)
|
first := f.manager.semaphoreFor(1)
|
||||||
if cap(first) != 1 {
|
if want := kindConcurrency[KindSlskd]; cap(first) != want {
|
||||||
t.Fatalf("slskd semaphore cap = %d, want 1", cap(first))
|
t.Fatalf("slskd semaphore cap = %d, want %d", cap(first), want)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Same limit: the semaphore is kept, so in-flight accounting is not
|
// Same limit: the semaphore is kept, so in-flight accounting is not
|
||||||
|
|||||||
@@ -0,0 +1,261 @@
|
|||||||
|
package download
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// A transfer that fails on one copy of an album is not a failed
|
||||||
|
// download while another acceptable copy exists. On Soulseek the usual
|
||||||
|
// failure is one peer being offline, with several others offering the
|
||||||
|
// same folder.
|
||||||
|
|
||||||
|
var errPeerOffline = errors.New("peer went offline")
|
||||||
|
|
||||||
|
func TestManagerFallsBackToTheNextCandidate(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
f := newManagerFixture(t)
|
||||||
|
|
||||||
|
// The failing source ranks first on priority, so the fallback is
|
||||||
|
// what reaches the one that works.
|
||||||
|
bad := fakeWithAlbum(1, "offline-peer", ".flac")
|
||||||
|
bad.GrabErr = errPeerOffline
|
||||||
|
good := fakeWithAlbum(2, "online-peer", ".flac")
|
||||||
|
|
||||||
|
f.manager.installProvider(Config{ID: 1, Priority: 90}, bad)
|
||||||
|
f.manager.installProvider(Config{ID: 2, Priority: 10}, good)
|
||||||
|
|
||||||
|
dl := fourTrackDownload()
|
||||||
|
|
||||||
|
if _, err := f.manager.Start(context.Background(), dl); err != nil {
|
||||||
|
t.Fatalf("Start: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
waitForDownloadState(t, f.store, dl.ID, StateComplete)
|
||||||
|
|
||||||
|
if bad.GrabCalls != 1 || good.GrabCalls != 1 {
|
||||||
|
t.Errorf(
|
||||||
|
"grabs: failing=%d working=%d, want 1 and 1",
|
||||||
|
bad.GrabCalls, good.GrabCalls,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The abandoned attempt's staging goes with it; only a request that
|
||||||
|
// fails outright keeps its staging for inspection.
|
||||||
|
waitFor(t, func() bool {
|
||||||
|
entries, err := os.ReadDir(f.staging.Root())
|
||||||
|
|
||||||
|
return err == nil && len(entries) == 0
|
||||||
|
}, "the failed attempt's staging was never released")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Falling back must not lower the bar. A second choice outside the
|
||||||
|
// user's guardrails is not a choice auto-pick may make, first or second.
|
||||||
|
func TestManagerFallbackRespectsTheGuardrails(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
f := newManagerFixture(t)
|
||||||
|
f.manager.SetPreferences(AutoDownloadPrefs{MaxSizeMB: 50})
|
||||||
|
|
||||||
|
bad := fakeWithAlbum(1, "offline-peer", ".flac")
|
||||||
|
bad.GrabErr = errPeerOffline
|
||||||
|
bad.Candidates[0].TotalSize = 40 << 20
|
||||||
|
|
||||||
|
huge := fakeWithAlbum(2, "oversized", ".flac")
|
||||||
|
huge.Candidates[0].TotalSize = 900 << 20
|
||||||
|
|
||||||
|
f.manager.installProvider(Config{ID: 1, Priority: 90}, bad)
|
||||||
|
f.manager.installProvider(Config{ID: 2, Priority: 10}, huge)
|
||||||
|
|
||||||
|
dl := fourTrackDownload()
|
||||||
|
|
||||||
|
if _, err := f.manager.Start(context.Background(), dl); err != nil {
|
||||||
|
t.Fatalf("Start: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
waitForDownloadState(t, f.store, dl.ID, StateFailed)
|
||||||
|
|
||||||
|
if huge.GrabCalls != 0 {
|
||||||
|
t.Errorf("fell back to a candidate over the size ceiling")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A copy the user picked by hand is the copy they asked for. Quietly
|
||||||
|
// substituting another is a decision they did not make.
|
||||||
|
func TestManagerPickDoesNotFallBack(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
f := newManagerFixture(t)
|
||||||
|
|
||||||
|
bad := fakeWithAlbum(1, "offline-peer", ".flac")
|
||||||
|
bad.GrabErr = errPeerOffline
|
||||||
|
good := fakeWithAlbum(2, "online-peer", ".flac")
|
||||||
|
|
||||||
|
f.manager.installProvider(Config{ID: 1, Priority: 90}, bad)
|
||||||
|
f.manager.installProvider(Config{ID: 2, Priority: 10}, good)
|
||||||
|
|
||||||
|
// A ceiling below both copies parks the result set for the user.
|
||||||
|
f.manager.SetPreferences(AutoDownloadPrefs{MaxSizeMB: 1})
|
||||||
|
|
||||||
|
bad.Candidates[0].TotalSize = 30 << 20
|
||||||
|
good.Candidates[0].TotalSize = 30 << 20
|
||||||
|
|
||||||
|
dl := fourTrackDownload()
|
||||||
|
|
||||||
|
if _, err := f.manager.Start(context.Background(), dl); err != nil {
|
||||||
|
t.Fatalf("Start: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := f.manager.Pick(
|
||||||
|
context.Background(), dl.ID, "offline-peer-cand",
|
||||||
|
); err != nil {
|
||||||
|
t.Fatalf("Pick: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
waitForDownloadState(t, f.store, dl.ID, StateFailed)
|
||||||
|
|
||||||
|
if good.GrabCalls != 0 {
|
||||||
|
t.Errorf("a hand-picked grab fell back to another candidate")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback is for surviving an offline peer or two, not for walking a
|
||||||
|
// forty-peer list for six hours.
|
||||||
|
func TestManagerFallbackIsBounded(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
f := newManagerFixture(t)
|
||||||
|
|
||||||
|
var providers []*FakeProvider
|
||||||
|
|
||||||
|
for i := int64(1); i <= maxGrabAttempts+2; i++ {
|
||||||
|
p := fakeWithAlbum(i, "peer-"+itoa(int(i)), ".flac")
|
||||||
|
p.GrabErr = errPeerOffline
|
||||||
|
|
||||||
|
f.manager.installProvider(Config{ID: i, Priority: 50}, p)
|
||||||
|
providers = append(providers, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
dl := fourTrackDownload()
|
||||||
|
|
||||||
|
if _, err := f.manager.Start(context.Background(), dl); err != nil {
|
||||||
|
t.Fatalf("Start: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
waitForDownloadState(t, f.store, dl.ID, StateFailed)
|
||||||
|
|
||||||
|
grabs := 0
|
||||||
|
for _, p := range providers {
|
||||||
|
grabs += p.GrabCalls
|
||||||
|
}
|
||||||
|
|
||||||
|
if grabs != maxGrabAttempts {
|
||||||
|
t.Errorf("grabs = %d, want %d", grabs, maxGrabAttempts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The veto judges the best candidate *inside* the guardrails, so the
|
||||||
|
// grab has to take that one — not the overall best, which may be the
|
||||||
|
// very copy the user said not to take unattended.
|
||||||
|
func TestManagerAutoPickTakesTheBestEligibleCandidate(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
f := newManagerFixture(t)
|
||||||
|
f.manager.SetPreferences(AutoDownloadPrefs{MaxSizeMB: 50})
|
||||||
|
|
||||||
|
huge := fakeWithAlbum(1, "oversized", ".flac")
|
||||||
|
huge.Candidates[0].TotalSize = 900 << 20
|
||||||
|
|
||||||
|
fits := fakeWithAlbum(2, "fits", ".flac")
|
||||||
|
fits.Candidates[0].TotalSize = 40 << 20
|
||||||
|
|
||||||
|
f.manager.installProvider(Config{ID: 1, Priority: 90}, huge)
|
||||||
|
f.manager.installProvider(Config{ID: 2, Priority: 10}, fits)
|
||||||
|
|
||||||
|
dl := fourTrackDownload()
|
||||||
|
|
||||||
|
ranked, err := f.manager.Start(context.Background(), dl)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Start: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ranked[0].ID != "oversized-cand" {
|
||||||
|
t.Fatalf("fixture: best overall is %s, want the oversized copy", ranked[0].ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
waitForDownloadState(t, f.store, dl.ID, StateComplete)
|
||||||
|
|
||||||
|
if huge.GrabCalls != 0 || fits.GrabCalls != 1 {
|
||||||
|
t.Errorf(
|
||||||
|
"grabs: oversized=%d fits=%d, want 0 and 1",
|
||||||
|
huge.GrabCalls, fits.GrabCalls,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// On Soulseek a failure is the peer's, so every folder that peer offered
|
||||||
|
// goes with it. Elsewhere a failure is the release's, and one indexer's
|
||||||
|
// other releases are still worth trying.
|
||||||
|
func TestRuledOutBy(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
failed := []Candidate{
|
||||||
|
{ID: "slskd:alice:Album", Kind: KindSlskd, ProviderID: 1, Origin: "alice"},
|
||||||
|
{ID: "tracker-1", Kind: KindProwlarr, ProviderID: 2, Origin: "indexer"},
|
||||||
|
}
|
||||||
|
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
c Candidate
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "the same candidate",
|
||||||
|
c: Candidate{ID: "tracker-1", Kind: KindProwlarr, ProviderID: 2, Origin: "indexer"},
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "another folder from a failed peer",
|
||||||
|
c: Candidate{
|
||||||
|
ID: "slskd:alice:Album (2)",
|
||||||
|
Kind: KindSlskd,
|
||||||
|
ProviderID: 1,
|
||||||
|
Origin: "alice",
|
||||||
|
},
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "another peer",
|
||||||
|
c: Candidate{ID: "slskd:bob:Album", Kind: KindSlskd, ProviderID: 1, Origin: "bob"},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "another release from the same indexer",
|
||||||
|
c: Candidate{ID: "tracker-2", Kind: KindProwlarr, ProviderID: 2, Origin: "indexer"},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "a peer of the same name on a different daemon",
|
||||||
|
c: Candidate{
|
||||||
|
ID: "slskd:alice:Album",
|
||||||
|
Kind: KindSlskd,
|
||||||
|
ProviderID: 3,
|
||||||
|
Origin: "alice",
|
||||||
|
},
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
if got := ruledOutBy(tc.c, failed); got != tc.want {
|
||||||
|
t.Errorf("ruledOutBy = %v, want %v", got, tc.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,190 @@
|
|||||||
|
package download
|
||||||
|
|
||||||
|
import (
|
||||||
|
"cmp"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"yellowjacket/backend/jobs"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Filling in an almost-complete album (#276).
|
||||||
|
//
|
||||||
|
// A grab that delivers nine of twelve tracks clears the completeness
|
||||||
|
// floor and is imported, and before this the other three were never
|
||||||
|
// looked for. On Soulseek that is the commonest way an album ends up
|
||||||
|
// almost right: one peer's folder is missing a track, or one file
|
||||||
|
// failed. So after an import, each missing track is searched for on
|
||||||
|
// its own and fetched from somewhere else, into the same album.
|
||||||
|
|
||||||
|
// maxFillInTracks bounds how many tracks are fetched one by one. An
|
||||||
|
// album missing more than a few is a different candidate's job, not a
|
||||||
|
// dozen single-track grabs.
|
||||||
|
const maxFillInTracks = 3
|
||||||
|
|
||||||
|
// fillIn fetches the tracks a successful import did not deliver. It
|
||||||
|
// never fails the download: the album is already imported, and a track
|
||||||
|
// it cannot find is logged and left.
|
||||||
|
func (m *Manager) fillIn(
|
||||||
|
ctx context.Context,
|
||||||
|
dl Download,
|
||||||
|
main Candidate,
|
||||||
|
imported ImportResult,
|
||||||
|
job *jobs.Handle,
|
||||||
|
) {
|
||||||
|
missing := missingTracks(dl, imported.Matched)
|
||||||
|
if len(missing) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, t := range missing {
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
paths, err := m.fillInTrack(ctx, dl, main, t, job)
|
||||||
|
if err != nil {
|
||||||
|
m.logger.Info(
|
||||||
|
"could not fill in a missing track",
|
||||||
|
"download", dl.ID,
|
||||||
|
"track", t.Title,
|
||||||
|
"error", err,
|
||||||
|
)
|
||||||
|
|
||||||
|
if job != nil {
|
||||||
|
job.Logf(jobs.LevelWarn, fmt.Sprintf(
|
||||||
|
"Could not find %q elsewhere: %v", t.Title, err,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if job != nil {
|
||||||
|
job.Logf(jobs.LevelInfo, fmt.Sprintf(
|
||||||
|
"Filled in %q from another source (%d file)", t.Title, len(paths),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// missingTracks is what an import left out, when filling it in is
|
||||||
|
// worth trying: an album with a tracklist, a few tracks short.
|
||||||
|
func missingTracks(dl Download, matched []ExpectedTrack) []ExpectedTrack {
|
||||||
|
// A recording request is one track; there is no album to complete.
|
||||||
|
if dl.RecordingMBID != "" || len(dl.Expected) < 2 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
have := make(map[trackKey]bool, len(matched))
|
||||||
|
for _, t := range matched {
|
||||||
|
have[keyOf(t)] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
var missing []ExpectedTrack
|
||||||
|
|
||||||
|
for _, t := range dl.Expected {
|
||||||
|
if !have[keyOf(t)] {
|
||||||
|
missing = append(missing, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A half-empty album was a poor copy, not a nearly complete one.
|
||||||
|
if len(missing) > maxFillInTracks || 2*len(missing) >= len(dl.Expected) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return missing
|
||||||
|
}
|
||||||
|
|
||||||
|
// fillInTrack searches for one track and grabs the first acceptable
|
||||||
|
// copy that is not from the source that already failed to supply it.
|
||||||
|
// One attempt: a fill-in that walks a candidate list per track would
|
||||||
|
// multiply a download's grabs by the number of gaps.
|
||||||
|
func (m *Manager) fillInTrack(
|
||||||
|
ctx context.Context,
|
||||||
|
dl Download,
|
||||||
|
main Candidate,
|
||||||
|
t ExpectedTrack,
|
||||||
|
job *jobs.Handle,
|
||||||
|
) ([]string, error) {
|
||||||
|
want := trackRequest(dl, t)
|
||||||
|
|
||||||
|
ranked, err := m.Search(ctx, want)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
prefs := m.preferences()
|
||||||
|
|
||||||
|
for _, c := range ranked {
|
||||||
|
if ruledOutBy(c, []Candidate{main}) || !autoAcceptable(want, c, prefs) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// The track is being put into an album this app placed; a
|
||||||
|
// delegate would put it in its own library instead.
|
||||||
|
if plan, err := m.planTransfer(want, c); err != nil || plan.delegated() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
narrowed, ok := narrowTo(c, t)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
out := m.attemptGrab(ctx, dl, narrowed, job, []ExpectedTrack{t})
|
||||||
|
|
||||||
|
if out.item.StagingDir != "" {
|
||||||
|
if err := m.staging.Release(out.item.StagingDir); err != nil {
|
||||||
|
m.logger.Warn("could not release staging dir", "error", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if out.err != nil {
|
||||||
|
return nil, out.err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := m.store.SetItemImported(
|
||||||
|
ctx, out.item.ID, out.imported.Paths,
|
||||||
|
); err != nil {
|
||||||
|
m.logger.Warn("could not record imported paths", "error", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return out.imported.Paths, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, ErrNoCandidates
|
||||||
|
}
|
||||||
|
|
||||||
|
// trackRequest is the search for one track of an album: the track's
|
||||||
|
// artist and title as the query, the album kept so a copy from that
|
||||||
|
// album outranks the same song off a compilation, and one expected
|
||||||
|
// track so a single file is a complete answer.
|
||||||
|
func trackRequest(dl Download, t ExpectedTrack) Download {
|
||||||
|
artist := cmp.Or(t.Artist, dl.Artist)
|
||||||
|
|
||||||
|
want := dl
|
||||||
|
want.Query = strings.TrimSpace(artist + " " + t.Title)
|
||||||
|
want.Expected = []ExpectedTrack{t}
|
||||||
|
|
||||||
|
return want
|
||||||
|
}
|
||||||
|
|
||||||
|
// narrowTo trims a candidate to the one file that aligns to t, so the
|
||||||
|
// grab fetches a track rather than whatever else the folder offered.
|
||||||
|
func narrowTo(c Candidate, t ExpectedTrack) (Candidate, bool) {
|
||||||
|
aligned, _ := matchFiles(c.Files, []ExpectedTrack{t})
|
||||||
|
|
||||||
|
for _, f := range aligned {
|
||||||
|
if f.IsAudio && f.MatchedTo == t.Position {
|
||||||
|
c.Files = []CandidateFile{f}
|
||||||
|
c.TotalSize = f.Size
|
||||||
|
|
||||||
|
return c, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Candidate{}, false
|
||||||
|
}
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
package download
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Filling in the tracks an almost-complete album is missing (#276).
|
||||||
|
|
||||||
|
func fiveTrackTitles() []string {
|
||||||
|
return append(allTitles(), "Let Down")
|
||||||
|
}
|
||||||
|
|
||||||
|
func fiveTrackDownload() Download {
|
||||||
|
dl := fourTrackDownload()
|
||||||
|
dl.Expected = append(dl.Expected, ExpectedTrack{Position: 5, Title: "Let Down"})
|
||||||
|
|
||||||
|
return dl
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMissingTracks(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
dl := fiveTrackDownload()
|
||||||
|
got := func(positions ...int) []ExpectedTrack {
|
||||||
|
out := make([]ExpectedTrack, 0, len(positions))
|
||||||
|
for _, p := range positions {
|
||||||
|
out = append(out, dl.Expected[p-1])
|
||||||
|
}
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
dl Download
|
||||||
|
matched []ExpectedTrack
|
||||||
|
want int
|
||||||
|
}{
|
||||||
|
{"complete", dl, got(1, 2, 3, 4, 5), 0},
|
||||||
|
{"one short", dl, got(1, 2, 3, 4), 1},
|
||||||
|
{"two short", dl, got(1, 2, 3), 2},
|
||||||
|
{"half gone is a poor copy", dl, got(1, 2), 0},
|
||||||
|
{"a recording is not an album", func() Download {
|
||||||
|
d := dl
|
||||||
|
d.RecordingMBID = "rec"
|
||||||
|
|
||||||
|
return d
|
||||||
|
}(), got(1, 2, 3, 4), 0},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
if n := len(missingTracks(tc.dl, tc.matched)); n != tc.want {
|
||||||
|
t.Errorf("%s: %d missing, want %d", tc.name, n, tc.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
big := fiveTrackDownload()
|
||||||
|
for i := 6; i <= 20; i++ {
|
||||||
|
big.Expected = append(big.Expected, ExpectedTrack{Position: i, Title: "T" + itoa(i)})
|
||||||
|
}
|
||||||
|
|
||||||
|
if n := len(missingTracks(big, big.Expected[:16])); n != 0 {
|
||||||
|
t.Errorf("four of twenty missing: %d filled in, want none past %d", n, maxFillInTracks)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A fill-in import takes only the file that is the missing track, and
|
||||||
|
// places it in the album with the album's tags; anything else the grab
|
||||||
|
// brought is left out.
|
||||||
|
func TestImportOnlyTakesTheMissingTrack(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
f := newImportFixture(t,
|
||||||
|
"05 - Let Down.flac",
|
||||||
|
"02 - Paranoid Android.flac",
|
||||||
|
)
|
||||||
|
|
||||||
|
dl := fiveTrackDownload()
|
||||||
|
|
||||||
|
got, err := f.importer.Import(
|
||||||
|
context.Background(), dl,
|
||||||
|
Result{Dir: f.dir, Files: f.files},
|
||||||
|
ImportOptions{LibraryRoot: f.root, WriteTags: true, Only: dl.Expected[4:]},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Import: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
want := filepath.Join(f.root, "Radiohead", "OK Computer", "05 Let Down.flac")
|
||||||
|
if len(got.Paths) != 1 || got.Paths[0] != want {
|
||||||
|
t.Errorf("imported %q, want only %s", got.Paths, want)
|
||||||
|
}
|
||||||
|
|
||||||
|
// A file that is not the missing track is not imported at all.
|
||||||
|
g := newImportFixture(t, "02 - Paranoid Android.flac")
|
||||||
|
|
||||||
|
if _, err := g.importer.Import(
|
||||||
|
context.Background(), dl,
|
||||||
|
Result{Dir: g.dir, Files: g.files},
|
||||||
|
ImportOptions{LibraryRoot: g.root, WriteTags: true, Only: dl.Expected[4:]},
|
||||||
|
); !errors.Is(err, ErrTooIncomplete) {
|
||||||
|
t.Errorf("Import = %v, want nothing matched", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The album comes from one source missing its fifth track; the fifth is
|
||||||
|
// then found on its own at another and lands in the same album.
|
||||||
|
func TestManagerFillsInAMissingTrack(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
f := newManagerFixture(t)
|
||||||
|
|
||||||
|
titles := fiveTrackTitles()
|
||||||
|
|
||||||
|
album := NewFakeProvider(1, "album", Caps{CanSearch: true, CanTransport: true})
|
||||||
|
ac := candidateFor("album-cand", titles, ".flac", 30_000_000)
|
||||||
|
ac.ProviderID = 1
|
||||||
|
album.Candidates = []Candidate{ac}
|
||||||
|
|
||||||
|
for i, tt := range titles[:4] {
|
||||||
|
album.Written[trackToken(i+1)+" - "+tt+".flac"] = []byte("audio-data")
|
||||||
|
}
|
||||||
|
|
||||||
|
single := NewFakeProvider(2, "single", Caps{CanSearch: true, CanTransport: true})
|
||||||
|
sc := Candidate{
|
||||||
|
ID: "single-cand",
|
||||||
|
Protocol: ProtocolDirect,
|
||||||
|
Title: "Radiohead - OK Computer",
|
||||||
|
Artist: "Radiohead",
|
||||||
|
Files: []CandidateFile{{
|
||||||
|
Path: "Radiohead - OK Computer/05 - Let Down.flac",
|
||||||
|
Size: 30_000_000,
|
||||||
|
}},
|
||||||
|
Health: 0.5,
|
||||||
|
ProviderID: 2,
|
||||||
|
}
|
||||||
|
single.Candidates = []Candidate{sc}
|
||||||
|
single.Written["05 - Let Down.flac"] = []byte("audio-data")
|
||||||
|
|
||||||
|
f.manager.installProvider(Config{ID: 1, Priority: 90}, album)
|
||||||
|
f.manager.installProvider(Config{ID: 2, Priority: 10}, single)
|
||||||
|
|
||||||
|
dl := fiveTrackDownload()
|
||||||
|
|
||||||
|
if _, err := f.manager.Start(context.Background(), dl); err != nil {
|
||||||
|
t.Fatalf("Start: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
waitForDownloadState(t, f.store, dl.ID, StateComplete)
|
||||||
|
|
||||||
|
if album.GrabCallCount() != 1 || single.GrabCallCount() != 1 {
|
||||||
|
t.Errorf(
|
||||||
|
"grabs: album=%d single=%d, want 1 and 1",
|
||||||
|
album.GrabCallCount(), single.GrabCallCount(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, tt := range titles {
|
||||||
|
p := filepath.Join(f.root, "Radiohead", "OK Computer", trackToken(i+1)+" "+tt+".flac")
|
||||||
|
if _, err := os.Stat(p); err != nil {
|
||||||
|
t.Errorf("track %d not in the library: %v", i+1, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"yellowjacket/backend/tagtotals"
|
||||||
"yellowjacket/backend/tagwriter"
|
"yellowjacket/backend/tagwriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -78,6 +79,12 @@ type ImportOptions struct {
|
|||||||
// them. Off for delegate providers, which have already imported
|
// them. Off for delegate providers, which have already imported
|
||||||
// and tagged the files themselves.
|
// and tagged the files themselves.
|
||||||
WriteTags bool
|
WriteTags bool
|
||||||
|
|
||||||
|
// Only, when set, imports just the files that align to these
|
||||||
|
// tracks of the download and skips the completeness check: it is a
|
||||||
|
// fill-in for tracks an earlier grab of the same album did not
|
||||||
|
// deliver (#276), tagged and placed as part of that album.
|
||||||
|
Only []ExpectedTrack
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultPathTemplate is the layout used when none is configured.
|
// DefaultPathTemplate is the layout used when none is configured.
|
||||||
@@ -117,6 +124,10 @@ type ImportResult struct {
|
|||||||
// Skipped counts non-audio files left in staging (logs, cue sheets,
|
// Skipped counts non-audio files left in staging (logs, cue sheets,
|
||||||
// scene .nfo files) — deliberately not imported.
|
// scene .nfo files) — deliberately not imported.
|
||||||
Skipped int
|
Skipped int
|
||||||
|
|
||||||
|
// Matched are the expected tracks an imported file was aligned to,
|
||||||
|
// which is how a caller learns what the grab did not deliver.
|
||||||
|
Matched []ExpectedTrack
|
||||||
}
|
}
|
||||||
|
|
||||||
// Import verifies, tags and moves a completed grab into the library.
|
// Import verifies, tags and moves a completed grab into the library.
|
||||||
@@ -139,14 +150,25 @@ func (i *Importer) Import(
|
|||||||
return ImportResult{}, ErrNoAudio
|
return ImportResult{}, ErrNoAudio
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(opts.Only) == 0 {
|
||||||
if err := checkCompleteness(len(audio), dl); err != nil {
|
if err := checkCompleteness(len(audio), dl); err != nil {
|
||||||
return ImportResult{}, err
|
return ImportResult{}, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Align staged files to the expected tracklist so tags and
|
// Align staged files to the expected tracklist so tags and
|
||||||
// filenames reflect the release, not the uploader's naming.
|
// filenames reflect the release, not the uploader's naming.
|
||||||
plan := i.planFiles(audio, dl)
|
plan := i.planFiles(audio, dl)
|
||||||
|
|
||||||
|
if len(opts.Only) > 0 {
|
||||||
|
plan = onlyTracks(plan, opts.Only)
|
||||||
|
if len(plan) == 0 {
|
||||||
|
return ImportResult{}, fmt.Errorf(
|
||||||
|
"%w: no file matched the missing track", ErrTooIncomplete,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
out := ImportResult{
|
out := ImportResult{
|
||||||
Paths: make([]string, 0, len(plan)),
|
Paths: make([]string, 0, len(plan)),
|
||||||
Skipped: skipped,
|
Skipped: skipped,
|
||||||
@@ -183,11 +205,49 @@ func (i *Importer) Import(
|
|||||||
}
|
}
|
||||||
|
|
||||||
out.Paths = append(out.Paths, dest)
|
out.Paths = append(out.Paths, dest)
|
||||||
|
|
||||||
|
if p.Matched {
|
||||||
|
out.Matched = append(out.Matched, p.Track)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// trackKey identifies an expected track within a release.
|
||||||
|
type trackKey struct{ disc, position int }
|
||||||
|
|
||||||
|
func keyOf(t ExpectedTrack) trackKey {
|
||||||
|
return trackKey{disc: t.DiscNumber, position: t.Position}
|
||||||
|
}
|
||||||
|
|
||||||
|
// onlyTracks keeps the planned files aligned to one of want. A fill-in
|
||||||
|
// grab can bring more than the one file it was after — a folder where
|
||||||
|
// the title also matched a live take — and anything else would land in
|
||||||
|
// the album as a duplicate or a stranger.
|
||||||
|
func onlyTracks(plan []plannedFile, want []ExpectedTrack) []plannedFile {
|
||||||
|
keys := make(map[trackKey]bool, len(want))
|
||||||
|
for _, t := range want {
|
||||||
|
keys[keyOf(t)] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
out := make([]plannedFile, 0, len(want))
|
||||||
|
seen := map[trackKey]bool{}
|
||||||
|
|
||||||
|
for _, p := range plan {
|
||||||
|
k := keyOf(p.Track)
|
||||||
|
if !p.Matched || !keys[k] || seen[k] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
seen[k] = true
|
||||||
|
|
||||||
|
out = append(out, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
// plannedFile pairs a staged file with the expected track it matched.
|
// plannedFile pairs a staged file with the expected track it matched.
|
||||||
type plannedFile struct {
|
type plannedFile struct {
|
||||||
Source string
|
Source string
|
||||||
@@ -275,6 +335,25 @@ func (i *Importer) tagFile(p plannedFile, dl Download) error {
|
|||||||
changes[tagwriter.FieldDiscNumber] = p.Track.DiscNumber
|
changes[tagwriter.FieldDiscNumber] = p.Track.DiscNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// An imported file should arrive knowing how much of the album it
|
||||||
|
// is one of, or the album reads as "in your library" from its first
|
||||||
|
// imported track onward.
|
||||||
|
//
|
||||||
|
// A *track* download is the case this must not touch: a
|
||||||
|
// RecordingMBID anchor resolves Expected to exactly that one track,
|
||||||
|
// so totalling it would write "1 of 1" onto a track off a
|
||||||
|
// twelve-track album -- a confident lie, and one that outranks the
|
||||||
|
// catalog's own total, which is the fallback that would otherwise
|
||||||
|
// have answered correctly.
|
||||||
|
if dl.RecordingMBID == "" {
|
||||||
|
if tracks, discs := tagtotals.For(
|
||||||
|
expectedPositions(dl.Expected), p.Track.DiscNumber,
|
||||||
|
); tracks > 0 {
|
||||||
|
changes[tagwriter.FieldTotalTracks] = tracks
|
||||||
|
changes[tagwriter.FieldTotalDiscs] = discs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := i.tags.WriteUntrackedFileTags(p.Source, changes); err != nil {
|
if err := i.tags.WriteUntrackedFileTags(p.Source, changes); err != nil {
|
||||||
return fmt.Errorf("write tags: %w", err)
|
return fmt.Errorf("write tags: %w", err)
|
||||||
}
|
}
|
||||||
@@ -282,6 +361,18 @@ func (i *Importer) tagFile(p plannedFile, dl Download) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// expectedPositions is the download's resolved tracklist as bare
|
||||||
|
// positions.
|
||||||
|
func expectedPositions(expected []ExpectedTrack) []tagtotals.Position {
|
||||||
|
out := make([]tagtotals.Position, 0, len(expected))
|
||||||
|
|
||||||
|
for _, t := range expected {
|
||||||
|
out = append(out, tagtotals.Position{Disc: t.DiscNumber, Track: t.Position})
|
||||||
|
}
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
// destinationFor computes a file's library path from the template.
|
// destinationFor computes a file's library path from the template.
|
||||||
func (i *Importer) destinationFor(
|
func (i *Importer) destinationFor(
|
||||||
p plannedFile,
|
p plannedFile,
|
||||||
|
|||||||
@@ -446,3 +446,77 @@ func keysOf(m map[string]tagwriter.TagChanges) []string {
|
|||||||
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// An imported album should arrive knowing its own size, or the album
|
||||||
|
// page reads "in your library" from its first imported track onward --
|
||||||
|
// which is the badge complaint this exists to answer.
|
||||||
|
func TestImportWritesTheAlbumTotals(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
f := newImportFixture(t,
|
||||||
|
"01 - Airbag.flac",
|
||||||
|
"02 - Paranoid Android.flac",
|
||||||
|
"03 - Subterranean Homesick Alien.flac",
|
||||||
|
"04 - Exit Music (For a Film).flac",
|
||||||
|
)
|
||||||
|
|
||||||
|
if _, err := f.importer.Import(
|
||||||
|
context.Background(),
|
||||||
|
fourTrackDownload(),
|
||||||
|
Result{Dir: f.dir, Files: f.files},
|
||||||
|
ImportOptions{LibraryRoot: f.root, WriteTags: true},
|
||||||
|
); err != nil {
|
||||||
|
t.Fatalf("Import: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
changes := f.tags.writes["01 - Airbag.flac"]
|
||||||
|
if changes == nil {
|
||||||
|
t.Fatal("no tag write recorded for the first track")
|
||||||
|
}
|
||||||
|
|
||||||
|
if got := changes[tagwriter.FieldTotalTracks]; got != 4 {
|
||||||
|
t.Errorf("%s: got %v, want 4", tagwriter.FieldTotalTracks, got)
|
||||||
|
}
|
||||||
|
|
||||||
|
if got := changes[tagwriter.FieldTotalDiscs]; got != 1 {
|
||||||
|
t.Errorf("%s: got %v, want 1", tagwriter.FieldTotalDiscs, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A RecordingMBID anchor resolves Expected to exactly the one track it
|
||||||
|
// asked for, so totalling it would tag a track off a twelve-track album
|
||||||
|
// as "1 of 1" -- worse than saying nothing, because a declared total
|
||||||
|
// outranks the catalog total that would have answered correctly.
|
||||||
|
func TestImportWritesNoTotalsForATrackDownload(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
f := newImportFixture(t, "01 - Airbag.flac")
|
||||||
|
|
||||||
|
dl := Download{
|
||||||
|
ID: "dl-track",
|
||||||
|
LibraryID: 1,
|
||||||
|
RecordingMBID: "mbid-recording",
|
||||||
|
Artist: "Radiohead",
|
||||||
|
Album: "OK Computer",
|
||||||
|
Expected: []ExpectedTrack{{Position: 1, Title: "Airbag"}},
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := f.importer.Import(
|
||||||
|
context.Background(),
|
||||||
|
dl,
|
||||||
|
Result{Dir: f.dir, Files: f.files},
|
||||||
|
ImportOptions{LibraryRoot: f.root, WriteTags: true},
|
||||||
|
); err != nil {
|
||||||
|
t.Fatalf("Import: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
changes := f.tags.writes["01 - Airbag.flac"]
|
||||||
|
if changes == nil {
|
||||||
|
t.Fatal("no tag write recorded")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := changes[tagwriter.FieldTotalTracks]; ok {
|
||||||
|
t.Errorf("%s written for a single-track download: %v",
|
||||||
|
tagwriter.FieldTotalTracks, changes[tagwriter.FieldTotalTracks])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package download
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
// keyedLock is a set of mutexes created on demand, one per key, that
|
||||||
|
// honour a context while waiting. An entry lives only while someone
|
||||||
|
// holds or waits on it, so a key per Soulseek peer or per folder name
|
||||||
|
// does not accumulate for the life of the process.
|
||||||
|
type keyedLock[K comparable] struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
held map[K]*keyedEntry
|
||||||
|
}
|
||||||
|
|
||||||
|
type keyedEntry struct {
|
||||||
|
ch chan struct{}
|
||||||
|
|
||||||
|
// refs counts holders and waiters; the entry is dropped at zero.
|
||||||
|
refs int
|
||||||
|
}
|
||||||
|
|
||||||
|
// acquire blocks until k is free or ctx ends, and returns the function
|
||||||
|
// that frees it.
|
||||||
|
func (l *keyedLock[K]) acquire(ctx context.Context, k K) (func(), error) {
|
||||||
|
l.mu.Lock()
|
||||||
|
|
||||||
|
if l.held == nil {
|
||||||
|
l.held = map[K]*keyedEntry{}
|
||||||
|
}
|
||||||
|
|
||||||
|
e, ok := l.held[k]
|
||||||
|
if !ok {
|
||||||
|
e = &keyedEntry{ch: make(chan struct{}, 1)}
|
||||||
|
l.held[k] = e
|
||||||
|
}
|
||||||
|
|
||||||
|
e.refs++
|
||||||
|
|
||||||
|
l.mu.Unlock()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case e.ch <- struct{}{}:
|
||||||
|
case <-ctx.Done():
|
||||||
|
l.drop(k, e)
|
||||||
|
|
||||||
|
return nil, ctx.Err()
|
||||||
|
}
|
||||||
|
|
||||||
|
var once sync.Once
|
||||||
|
|
||||||
|
return func() {
|
||||||
|
once.Do(func() {
|
||||||
|
<-e.ch
|
||||||
|
l.drop(k, e)
|
||||||
|
})
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *keyedLock[K]) drop(k K, e *keyedEntry) {
|
||||||
|
l.mu.Lock()
|
||||||
|
defer l.mu.Unlock()
|
||||||
|
|
||||||
|
e.refs--
|
||||||
|
if e.refs == 0 {
|
||||||
|
delete(l.held, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// size reports how many keys are held or awaited, for tests.
|
||||||
|
func (l *keyedLock[K]) size() int {
|
||||||
|
l.mu.Lock()
|
||||||
|
defer l.mu.Unlock()
|
||||||
|
|
||||||
|
return len(l.held)
|
||||||
|
}
|
||||||
+240
-57
@@ -59,13 +59,15 @@ const concurrencyKey = "maxConcurrent"
|
|||||||
// A single global cap is the wrong shape here: usenet and torrent
|
// A single global cap is the wrong shape here: usenet and torrent
|
||||||
// clients are built to run many transfers at once and are throttled by
|
// clients are built to run many transfers at once and are throttled by
|
||||||
// bandwidth, while Soulseek transfers come from one person's home
|
// bandwidth, while Soulseek transfers come from one person's home
|
||||||
// upload slot. Hitting the same peer with parallel requests gets you
|
// upload slot. Politeness there is per *peer* — asking one user for two
|
||||||
// queued behind everyone else at best and banned at worst, so slskd is
|
// folders at once gets you queued behind everyone else at best and
|
||||||
// capped at one — the polite number, and the one that actually
|
// banned at worst — and the manager holds that line separately, one
|
||||||
// completes fastest, because a Soulseek peer serves one file at a time
|
// grab per peer (peerLocks). Two different users do not compete for
|
||||||
// regardless of how many you ask for.
|
// anyone's slot, so the daemon-wide number only bounds how many peers
|
||||||
|
// are asked at once, and one slow peer no longer serialises every other
|
||||||
|
// Soulseek download behind it.
|
||||||
var kindConcurrency = map[Kind]int{
|
var kindConcurrency = map[Kind]int{
|
||||||
KindSlskd: 1,
|
KindSlskd: 3,
|
||||||
KindYtDlp: 2,
|
KindYtDlp: 2,
|
||||||
KindQBittorrent: 4,
|
KindQBittorrent: 4,
|
||||||
KindSABnzbd: 4,
|
KindSABnzbd: 4,
|
||||||
@@ -155,6 +157,11 @@ type Manager struct {
|
|||||||
semMu sync.Mutex
|
semMu sync.Mutex
|
||||||
provSem map[int64]chan struct{}
|
provSem map[int64]chan struct{}
|
||||||
|
|
||||||
|
// peerLocks holds one grab per Soulseek peer, taken before any
|
||||||
|
// slot: a grab waiting for a busy peer must not sit on a provider
|
||||||
|
// slot another peer could be using.
|
||||||
|
peerLocks keyedLock[peerKey]
|
||||||
|
|
||||||
// delegatePoll is how often delegating managers are asked for
|
// delegatePoll is how often delegating managers are asked for
|
||||||
// status. A field rather than the constant so tests can drive the
|
// status. A field rather than the constant so tests can drive the
|
||||||
// full delegate flow without sleeping through it.
|
// full delegate flow without sleeping through it.
|
||||||
@@ -577,12 +584,12 @@ func (m *Manager) Start(
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.AutoPickable(dl, ranked) {
|
if pick, ok := autoPick(dl, ranked, m.preferences()); ok {
|
||||||
if job != nil {
|
if job != nil {
|
||||||
job.Logf(jobs.LevelInfo, "Auto-selected best candidate")
|
job.Logf(jobs.LevelInfo, "Auto-selected best candidate")
|
||||||
}
|
}
|
||||||
|
|
||||||
go m.grab(context.WithoutCancel(ctx), dl, ranked[0], job)
|
go m.grab(context.WithoutCancel(ctx), dl, pick, job, true)
|
||||||
|
|
||||||
return ranked, nil
|
return ranked, nil
|
||||||
}
|
}
|
||||||
@@ -622,6 +629,13 @@ func (m *Manager) Attempt(
|
|||||||
return false, veto, nil
|
return false, veto, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pick, ok := autoPick(dl, ranked, m.preferences())
|
||||||
|
if !ok {
|
||||||
|
// Unreachable while autoPick and AutoPickVeto agree; kept so a
|
||||||
|
// future divergence refuses rather than grabbing blind.
|
||||||
|
return false, "no candidate clears the auto-download bar", nil
|
||||||
|
}
|
||||||
|
|
||||||
if err := m.store.CreateDownload(ctx, dl); err != nil {
|
if err := m.store.CreateDownload(ctx, dl); err != nil {
|
||||||
return false, "", err
|
return false, "", err
|
||||||
}
|
}
|
||||||
@@ -643,7 +657,7 @@ func (m *Manager) Attempt(
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
go m.grab(context.WithoutCancel(ctx), dl, ranked[0], job)
|
go m.grab(context.WithoutCancel(ctx), dl, pick, job, true)
|
||||||
|
|
||||||
return true, "", nil
|
return true, "", nil
|
||||||
}
|
}
|
||||||
@@ -678,7 +692,7 @@ func (m *Manager) Pick(
|
|||||||
|
|
||||||
job := m.startJob(dl)
|
job := m.startJob(dl)
|
||||||
|
|
||||||
go m.grab(context.WithoutCancel(ctx), dl, *chosen, job)
|
go m.grab(context.WithoutCancel(ctx), dl, *chosen, job, false)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -702,13 +716,20 @@ func (m *Manager) Cancel(ctx context.Context, downloadID string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// grab drives one candidate all the way to the library. It runs on its
|
// grab drives one request all the way to the library. It runs on its
|
||||||
// own goroutine and owns the job from here on.
|
// own goroutine and owns the job from here on.
|
||||||
|
//
|
||||||
|
// When fallback is set and a candidate's transfer fails, the next
|
||||||
|
// candidate that auto-pick would itself have accepted is tried in its
|
||||||
|
// place (see nextCandidate). It is set for the two unattended routes
|
||||||
|
// and not for a candidate the user picked by hand: they chose that copy,
|
||||||
|
// and quietly substituting another is a decision they did not make.
|
||||||
func (m *Manager) grab(
|
func (m *Manager) grab(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
dl Download,
|
dl Download,
|
||||||
c Candidate,
|
c Candidate,
|
||||||
job *jobs.Handle,
|
job *jobs.Handle,
|
||||||
|
fallback bool,
|
||||||
) {
|
) {
|
||||||
ctx, cancel := context.WithTimeout(ctx, grabTimeout)
|
ctx, cancel := context.WithTimeout(ctx, grabTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@@ -723,6 +744,101 @@ func (m *Manager) grab(
|
|||||||
m.actMu.Unlock()
|
m.actMu.Unlock()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
var failed []Candidate
|
||||||
|
|
||||||
|
for {
|
||||||
|
out := m.attemptGrab(ctx, dl, c, job, nil)
|
||||||
|
if out.err == nil {
|
||||||
|
m.fillIn(ctx, dl, c, out.imported, job)
|
||||||
|
m.finishGrab(ctx, dl, out.item, out.imported, job)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
failed = append(failed, c)
|
||||||
|
|
||||||
|
next, ok := m.nextCandidate(ctx, dl, failed, out, fallback)
|
||||||
|
if !ok {
|
||||||
|
m.failDownload(ctx, job, dl.ID, out.err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
m.logger.Info(
|
||||||
|
"download candidate failed; trying the next",
|
||||||
|
"download", dl.ID,
|
||||||
|
"failed", c.ID,
|
||||||
|
"next", next.ID,
|
||||||
|
"error", out.err,
|
||||||
|
)
|
||||||
|
|
||||||
|
if job != nil {
|
||||||
|
job.Logf(jobs.LevelWarn, fmt.Sprintf(
|
||||||
|
"%s failed (%v); trying %s instead",
|
||||||
|
describeCandidate(c), out.err, describeCandidate(next),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
// The failed attempt's staging holds at most a partial folder
|
||||||
|
// nobody is going to import, and the next attempt reserves its
|
||||||
|
// own. Only the final failure keeps its staging for inspection.
|
||||||
|
if out.item.StagingDir != "" {
|
||||||
|
if err := m.staging.Release(out.item.StagingDir); err != nil {
|
||||||
|
m.logger.Warn("could not release staging dir", "error", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c = next
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// maxGrabAttempts bounds how many candidates one request will try. A
|
||||||
|
// popular album can have dozens of peers; the point of falling back is
|
||||||
|
// to survive the ordinary one or two that are offline, not to walk the
|
||||||
|
// whole list for six hours.
|
||||||
|
const maxGrabAttempts = 3
|
||||||
|
|
||||||
|
// peerKey names one Soulseek user on one daemon. The same username on
|
||||||
|
// two daemons is two logins and two queues.
|
||||||
|
type peerKey struct {
|
||||||
|
provider int64
|
||||||
|
peer string
|
||||||
|
}
|
||||||
|
|
||||||
|
// peerKeyFor returns the peer a candidate is fetched from, when the
|
||||||
|
// source is one where asking a peer for two things at once is rude.
|
||||||
|
func peerKeyFor(c Candidate) (peerKey, bool) {
|
||||||
|
if c.Kind != KindSlskd || c.Origin == "" {
|
||||||
|
return peerKey{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
return peerKey{provider: c.ProviderID, peer: c.Origin}, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// grabOutcome is how one candidate's attempt ended.
|
||||||
|
type grabOutcome struct {
|
||||||
|
item DownloadItem
|
||||||
|
imported ImportResult
|
||||||
|
err error
|
||||||
|
|
||||||
|
// retryable reports whether another candidate might succeed where
|
||||||
|
// this one failed: the transfer failed, or delivered too little of
|
||||||
|
// the album. Anything else — no staging space, no library root, a
|
||||||
|
// tag write failing — would fail the next candidate identically.
|
||||||
|
retryable bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// attemptGrab takes one candidate through transfer and import. It
|
||||||
|
// records the item's own failure, but not the download's: whether the
|
||||||
|
// download has failed is the caller's decision, since another candidate
|
||||||
|
// may yet succeed.
|
||||||
|
func (m *Manager) attemptGrab(
|
||||||
|
ctx context.Context,
|
||||||
|
dl Download,
|
||||||
|
c Candidate,
|
||||||
|
job *jobs.Handle,
|
||||||
|
only []ExpectedTrack,
|
||||||
|
) grabOutcome {
|
||||||
// Who will move the bytes is decided before any slot is taken, so
|
// Who will move the bytes is decided before any slot is taken, so
|
||||||
// the transfer waits in its own provider's queue rather than in a
|
// the transfer waits in its own provider's queue rather than in a
|
||||||
// global one. A delegate takes no slot at all: the transfer is
|
// global one. A delegate takes no slot at all: the transfer is
|
||||||
@@ -731,21 +847,26 @@ func (m *Manager) grab(
|
|||||||
// work against our budget.
|
// work against our budget.
|
||||||
plan, err := m.planTransfer(dl, c)
|
plan, err := m.planTransfer(dl, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.failDownload(ctx, job, dl.ID, err)
|
return grabOutcome{err: err}
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !plan.delegated() {
|
if !plan.delegated() {
|
||||||
|
if key, ok := peerKeyFor(c); ok {
|
||||||
|
release, err := m.peerLocks.acquire(ctx, key)
|
||||||
|
if err != nil {
|
||||||
|
return grabOutcome{err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
defer release()
|
||||||
|
}
|
||||||
|
|
||||||
provSem := m.semaphoreFor(plan.transportID)
|
provSem := m.semaphoreFor(plan.transportID)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case provSem <- struct{}{}:
|
case provSem <- struct{}{}:
|
||||||
defer func() { <-provSem }()
|
defer func() { <-provSem }()
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
m.failDownload(ctx, job, dl.ID, ctx.Err())
|
return grabOutcome{err: ctx.Err()}
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
globalSem := m.globalSem()
|
globalSem := m.globalSem()
|
||||||
@@ -754,9 +875,7 @@ func (m *Manager) grab(
|
|||||||
case globalSem <- struct{}{}:
|
case globalSem <- struct{}{}:
|
||||||
defer func() { <-globalSem }()
|
defer func() { <-globalSem }()
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
m.failDownload(ctx, job, dl.ID, ctx.Err())
|
return grabOutcome{err: ctx.Err()}
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -771,24 +890,30 @@ func (m *Manager) grab(
|
|||||||
|
|
||||||
dir, err := m.staging.Reserve(item.ID)
|
dir, err := m.staging.Reserve(item.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.failDownload(ctx, job, dl.ID, err)
|
return grabOutcome{err: err}
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
item.StagingDir = dir
|
item.StagingDir = dir
|
||||||
|
|
||||||
if err := m.store.CreateItem(ctx, item); err != nil {
|
if err := m.store.CreateItem(ctx, item); err != nil {
|
||||||
m.failDownload(ctx, job, dl.ID, err)
|
return grabOutcome{item: item, err: err}
|
||||||
|
}
|
||||||
|
|
||||||
return
|
fail := func(err error, retryable bool) grabOutcome {
|
||||||
|
if serr := m.store.SetItemState(
|
||||||
|
ctx, item.ID, StateFailed, err.Error(),
|
||||||
|
); serr != nil {
|
||||||
|
m.logger.Warn("could not record item failure", "error", serr)
|
||||||
|
}
|
||||||
|
|
||||||
|
return grabOutcome{item: item, err: err, retryable: retryable}
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := m.transfer(ctx, dl, item, plan, job)
|
result, err := m.transfer(ctx, dl, item, plan, job)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.failItem(ctx, job, item, dl.ID, err)
|
// A delegate's failure is the external manager's verdict on the
|
||||||
|
// whole request, not on one copy of it.
|
||||||
return
|
return fail(err, !plan.delegated())
|
||||||
}
|
}
|
||||||
|
|
||||||
m.setStates(ctx, dl.ID, item.ID, StateImporting)
|
m.setStates(ctx, dl.ID, item.ID, StateImporting)
|
||||||
@@ -798,42 +923,117 @@ func (m *Manager) grab(
|
|||||||
job.SetStages(importStages(2))
|
job.SetStages(importStages(2))
|
||||||
}
|
}
|
||||||
|
|
||||||
var imported ImportResult
|
|
||||||
|
|
||||||
if result.Delegated {
|
if result.Delegated {
|
||||||
// The external manager already placed and tagged these files in
|
// The external manager already placed and tagged these files in
|
||||||
// its own library. Moving them out from under a system that is
|
// its own library. Moving them out from under a system that is
|
||||||
// still managing them would be worse than useless, so the files
|
// still managing them would be worse than useless, so the files
|
||||||
// are recorded where they are and the library scan picks them
|
// are recorded where they are and the library scan picks them
|
||||||
// up in place.
|
// up in place.
|
||||||
imported = ImportResult{Paths: result.Files}
|
|
||||||
|
|
||||||
if job != nil {
|
if job != nil {
|
||||||
job.Logf(jobs.LevelInfo, fmt.Sprintf(
|
job.Logf(jobs.LevelInfo, fmt.Sprintf(
|
||||||
"External manager imported %d files; recording them in place",
|
"External manager imported %d files; recording them in place",
|
||||||
len(result.Files),
|
len(result.Files),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
|
return grabOutcome{
|
||||||
|
item: item,
|
||||||
|
imported: ImportResult{Paths: result.Files},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
opts := m.importOptions()
|
opts := m.importOptions()
|
||||||
opts.WriteTags = true
|
opts.WriteTags = true
|
||||||
|
opts.Only = only
|
||||||
|
|
||||||
opts.LibraryRoot, err = m.library.LibraryPath(dl.LibraryID)
|
opts.LibraryRoot, err = m.library.LibraryPath(dl.LibraryID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.failItem(ctx, job, item, dl.ID,
|
return fail(fmt.Errorf("resolve library root: %w", err), false)
|
||||||
fmt.Errorf("resolve library root: %w", err))
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
imported, err = m.importer.Import(ctx, dl, result, opts)
|
imported, err := m.importer.Import(ctx, dl, result, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.failItem(ctx, job, item, dl.ID, err)
|
return fail(err, errors.Is(err, ErrTooIncomplete))
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return grabOutcome{item: item, imported: imported}
|
||||||
|
}
|
||||||
|
|
||||||
|
// nextCandidate picks the candidate to try after the ones in failed.
|
||||||
|
//
|
||||||
|
// It only ever offers a candidate auto-pick would have taken on its own
|
||||||
|
// (autoAcceptable), so falling back cannot lower the bar an unattended
|
||||||
|
// download is held to: the second choice has to clear the same gates
|
||||||
|
// the first did.
|
||||||
|
//
|
||||||
|
// On Soulseek a failure belongs to the *peer* — offline, refusing, or
|
||||||
|
// holding us in a queue — so every folder that peer offered is skipped
|
||||||
|
// with it. Elsewhere a failure belongs to the release, and only that
|
||||||
|
// candidate is.
|
||||||
|
func (m *Manager) nextCandidate(
|
||||||
|
ctx context.Context,
|
||||||
|
dl Download,
|
||||||
|
failed []Candidate,
|
||||||
|
out grabOutcome,
|
||||||
|
fallback bool,
|
||||||
|
) (Candidate, bool) {
|
||||||
|
if !fallback || !out.retryable || ctx.Err() != nil ||
|
||||||
|
len(failed) >= maxGrabAttempts {
|
||||||
|
return Candidate{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
m.resMu.RLock()
|
||||||
|
ranked := m.results[dl.ID]
|
||||||
|
m.resMu.RUnlock()
|
||||||
|
|
||||||
|
prefs := m.preferences()
|
||||||
|
|
||||||
|
for _, c := range ranked {
|
||||||
|
if ruledOutBy(c, failed) || !autoAcceptable(dl, c, prefs) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return c, true
|
||||||
|
}
|
||||||
|
|
||||||
|
return Candidate{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// ruledOutBy reports whether a failure among failed also rules out c.
|
||||||
|
func ruledOutBy(c Candidate, failed []Candidate) bool {
|
||||||
|
for _, f := range failed {
|
||||||
|
if c.ID == f.ID && c.ProviderID == f.ProviderID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Kind == KindSlskd && f.Kind == KindSlskd &&
|
||||||
|
c.ProviderID == f.ProviderID && c.Origin != "" &&
|
||||||
|
c.Origin == f.Origin {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// describeCandidate names a candidate for the job log.
|
||||||
|
func describeCandidate(c Candidate) string {
|
||||||
|
if c.Origin != "" {
|
||||||
|
return fmt.Sprintf("%q from %s", c.Title, c.Origin)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%q", c.Title)
|
||||||
|
}
|
||||||
|
|
||||||
|
// finishGrab records a successful import and retires what the request
|
||||||
|
// was holding.
|
||||||
|
func (m *Manager) finishGrab(
|
||||||
|
ctx context.Context,
|
||||||
|
dl Download,
|
||||||
|
item DownloadItem,
|
||||||
|
imported ImportResult,
|
||||||
|
job *jobs.Handle,
|
||||||
|
) {
|
||||||
if err := m.store.SetItemImported(
|
if err := m.store.SetItemImported(
|
||||||
ctx, item.ID, imported.Paths,
|
ctx, item.ID, imported.Paths,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
@@ -1177,23 +1377,6 @@ func (m *Manager) failDownload(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// failItem records an item-level failure and fails its download.
|
|
||||||
func (m *Manager) failItem(
|
|
||||||
ctx context.Context,
|
|
||||||
job *jobs.Handle,
|
|
||||||
item DownloadItem,
|
|
||||||
downloadID string,
|
|
||||||
err error,
|
|
||||||
) {
|
|
||||||
if serr := m.store.SetItemState(
|
|
||||||
ctx, item.ID, StateFailed, err.Error(),
|
|
||||||
); serr != nil {
|
|
||||||
m.logger.Warn("could not record item failure", "error", serr)
|
|
||||||
}
|
|
||||||
|
|
||||||
m.failDownload(ctx, job, downloadID, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// startJob registers the request in the background jobs panel.
|
// startJob registers the request in the background jobs panel.
|
||||||
func (m *Manager) startJob(dl Download) *jobs.Handle {
|
func (m *Manager) startJob(dl Download) *jobs.Handle {
|
||||||
if m.jobsReg == nil {
|
if m.jobsReg == nil {
|
||||||
|
|||||||
@@ -66,6 +66,14 @@ var (
|
|||||||
|
|
||||||
// separatorPattern splits "Artist - Album" style folder names.
|
// separatorPattern splits "Artist - Album" style folder names.
|
||||||
separatorPattern = regexp.MustCompile(`\s+[-–—]\s+`)
|
separatorPattern = regexp.MustCompile(`\s+[-–—]\s+`)
|
||||||
|
|
||||||
|
// discFolderPattern matches a directory that holds one disc of an
|
||||||
|
// album rather than the album: "CD1", "CD 2", "Disc 3", "Disk-1",
|
||||||
|
// "[Disc 2]", "CD1 - The Early Years". A number is required, so a
|
||||||
|
// folder merely called "CDs" is not one.
|
||||||
|
discFolderPattern = regexp.MustCompile(
|
||||||
|
`(?i)^\s*[\[(]?\s*(?:cd|disc|disk)\s*[-_.#]?\s*(\d{1,2})\b`,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
// FormatForPath returns the audio format implied by a path's extension,
|
// FormatForPath returns the audio format implied by a path's extension,
|
||||||
@@ -94,16 +102,63 @@ type TrackHint struct {
|
|||||||
Folder string
|
Folder string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// discFolder reports whether a directory name is one disc of an album,
|
||||||
|
// and which.
|
||||||
|
func discFolder(name string) (int, bool) {
|
||||||
|
m := discFolderPattern.FindStringSubmatch(name)
|
||||||
|
if m == nil {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
|
||||||
|
n, err := strconv.Atoi(m[1])
|
||||||
|
if err != nil || n == 0 {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
|
||||||
|
return n, true
|
||||||
|
}
|
||||||
|
|
||||||
|
// AlbumDir is the directory that holds a file's *album*: its parent,
|
||||||
|
// or its grandparent when the parent is a disc folder.
|
||||||
|
//
|
||||||
|
// Multi-disc rips are shared as `Album/CD1/…` and `Album/CD2/…`, and
|
||||||
|
// grouping candidates by the immediate parent split one album into two
|
||||||
|
// half-albums, each titled "CD1". Neither could clear the completeness
|
||||||
|
// or album-title bars, so a multi-disc release could not be auto-picked
|
||||||
|
// at all. A disc folder at the root has no album above it and is
|
||||||
|
// returned as it is.
|
||||||
|
func AlbumDir(p string) string {
|
||||||
|
dir := path.Dir(strings.ReplaceAll(p, `\`, "/"))
|
||||||
|
|
||||||
|
if _, ok := discFolder(path.Base(dir)); !ok {
|
||||||
|
return dir
|
||||||
|
}
|
||||||
|
|
||||||
|
parent := path.Dir(dir)
|
||||||
|
if parent == "." || parent == "/" || parent == "" {
|
||||||
|
return dir
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent
|
||||||
|
}
|
||||||
|
|
||||||
// ParsePath extracts what it can from one candidate file path.
|
// ParsePath extracts what it can from one candidate file path.
|
||||||
func ParsePath(p string) TrackHint {
|
func ParsePath(p string) TrackHint {
|
||||||
// Soulseek paths are Windows-style; normalize before splitting.
|
// Soulseek paths are Windows-style; normalize before splitting.
|
||||||
norm := strings.ReplaceAll(p, `\`, "/")
|
norm := strings.ReplaceAll(p, `\`, "/")
|
||||||
base := path.Base(norm)
|
base := path.Base(norm)
|
||||||
folder := path.Base(path.Dir(norm))
|
|
||||||
|
|
||||||
name := strings.TrimSuffix(base, path.Ext(base))
|
name := strings.TrimSuffix(base, path.Ext(base))
|
||||||
|
|
||||||
hint := TrackHint{Folder: cleanAlbumName(folder)}
|
// The album's name is the album directory's, not a disc folder's,
|
||||||
|
// and the disc folder is where a multi-disc rip says which disc a
|
||||||
|
// file is on. A disc number in the filename ("2-01 …") is more
|
||||||
|
// specific and overrides it below.
|
||||||
|
hint := TrackHint{Folder: cleanAlbumName(path.Base(AlbumDir(norm)))}
|
||||||
|
|
||||||
|
if disc, ok := discFolder(path.Base(path.Dir(norm))); ok {
|
||||||
|
hint.Disc = disc
|
||||||
|
}
|
||||||
|
|
||||||
if m := trackNumPattern.FindStringSubmatch(name); m != nil {
|
if m := trackNumPattern.FindStringSubmatch(name); m != nil {
|
||||||
if m[1] != "" {
|
if m[1] != "" {
|
||||||
@@ -203,21 +258,72 @@ func AnnotateFiles(files []CandidateFile) []CandidateFile {
|
|||||||
|
|
||||||
// matchFiles aligns a candidate's audio files to the expected tracklist
|
// matchFiles aligns a candidate's audio files to the expected tracklist
|
||||||
// and returns the per-file assignment plus the mean title similarity of
|
// and returns the per-file assignment plus the mean title similarity of
|
||||||
// the aligned pairs.
|
// the aligned pairs. alignFiles is the same alignment with the
|
||||||
|
// duration evidence as well.
|
||||||
|
func matchFiles(
|
||||||
|
files []CandidateFile,
|
||||||
|
expected []ExpectedTrack,
|
||||||
|
) ([]CandidateFile, float64) {
|
||||||
|
a := alignFiles(files, expected)
|
||||||
|
|
||||||
|
return a.files, a.titleFit
|
||||||
|
}
|
||||||
|
|
||||||
|
// alignment is what aligning a candidate to a tracklist found.
|
||||||
|
type alignment struct {
|
||||||
|
files []CandidateFile
|
||||||
|
|
||||||
|
// titleFit is the mean title similarity over aligned pairs.
|
||||||
|
titleFit float64
|
||||||
|
|
||||||
|
// durationFit is the mean duration agreement over aligned pairs
|
||||||
|
// where both sides state a length, and timedPairs is how many such
|
||||||
|
// pairs there were.
|
||||||
|
durationFit float64
|
||||||
|
timedPairs int
|
||||||
|
aligned int
|
||||||
|
}
|
||||||
|
|
||||||
|
// durationAgreement scores how well a file's length matches the
|
||||||
|
// expected track's, in 0..1. Rips of the same master differ by a
|
||||||
|
// second or two of silence; a different edit, a live take or a
|
||||||
|
// truncated file differs by tens of seconds.
|
||||||
|
func durationAgreement(got, want int64) float64 {
|
||||||
|
const (
|
||||||
|
exactMillis = 3_000
|
||||||
|
wrongMillis = 30_000
|
||||||
|
)
|
||||||
|
|
||||||
|
d := got - want
|
||||||
|
if d < 0 {
|
||||||
|
d = -d
|
||||||
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case d <= exactMillis:
|
||||||
|
return 1
|
||||||
|
case d >= wrongMillis:
|
||||||
|
return 0
|
||||||
|
default:
|
||||||
|
return 1 - float64(d-exactMillis)/float64(wrongMillis-exactMillis)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// alignFiles aligns a candidate's audio files to the expected tracklist.
|
||||||
//
|
//
|
||||||
// Alignment is greedy by score rather than optimal: candidate folders
|
// Alignment is greedy by score rather than optimal: candidate folders
|
||||||
// are small (a few dozen files at most) and the common cases — correct
|
// are small (a few dozen files at most) and the common cases — correct
|
||||||
// track numbers, or clean "NN Title" names — are unambiguous, so the
|
// track numbers, or clean "NN Title" names — are unambiguous, so the
|
||||||
// extra machinery of Hungarian assignment buys nothing here.
|
// extra machinery of Hungarian assignment buys nothing here.
|
||||||
func matchFiles(
|
func alignFiles(
|
||||||
files []CandidateFile,
|
files []CandidateFile,
|
||||||
expected []ExpectedTrack,
|
expected []ExpectedTrack,
|
||||||
) ([]CandidateFile, float64) {
|
) alignment {
|
||||||
annotated := make([]CandidateFile, len(files))
|
annotated := make([]CandidateFile, len(files))
|
||||||
copy(annotated, files)
|
copy(annotated, files)
|
||||||
|
|
||||||
if len(expected) == 0 {
|
if len(expected) == 0 {
|
||||||
return annotated, 0
|
return alignment{files: annotated}
|
||||||
}
|
}
|
||||||
|
|
||||||
hints := make([]TrackHint, len(annotated))
|
hints := make([]TrackHint, len(annotated))
|
||||||
@@ -230,8 +336,19 @@ func matchFiles(
|
|||||||
var (
|
var (
|
||||||
total float64
|
total float64
|
||||||
matched int
|
matched int
|
||||||
|
|
||||||
|
durTotal float64
|
||||||
|
timed int
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// timing adds a pair's duration evidence when both sides state one.
|
||||||
|
timing := func(f CandidateFile, e ExpectedTrack) {
|
||||||
|
if f.LengthMillis > 0 && e.LengthMillis > 0 {
|
||||||
|
durTotal += durationAgreement(f.LengthMillis, e.LengthMillis)
|
||||||
|
timed++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Pass 1: trust explicit track numbers when they are unique and in
|
// Pass 1: trust explicit track numbers when they are unique and in
|
||||||
// range. A folder that numbers its files correctly is the strong
|
// range. A folder that numbers its files correctly is the strong
|
||||||
// case, and title comparison only adds noise there.
|
// case, and title comparison only adds noise there.
|
||||||
@@ -250,6 +367,8 @@ func matchFiles(
|
|||||||
|
|
||||||
total += autotag.TitleSimilarity(hints[i].Title, expected[idx].Title)
|
total += autotag.TitleSimilarity(hints[i].Title, expected[idx].Title)
|
||||||
matched++
|
matched++
|
||||||
|
|
||||||
|
timing(annotated[i], expected[idx])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pass 2: title similarity for whatever is left.
|
// Pass 2: title similarity for whatever is left.
|
||||||
@@ -284,13 +403,26 @@ func matchFiles(
|
|||||||
|
|
||||||
total += bestSim
|
total += bestSim
|
||||||
matched++
|
matched++
|
||||||
|
|
||||||
|
timing(annotated[i], expected[bestIdx])
|
||||||
}
|
}
|
||||||
|
|
||||||
if matched == 0 {
|
if matched == 0 {
|
||||||
return annotated, 0
|
return alignment{files: annotated}
|
||||||
}
|
}
|
||||||
|
|
||||||
return annotated, total / float64(matched)
|
a := alignment{
|
||||||
|
files: annotated,
|
||||||
|
titleFit: total / float64(matched),
|
||||||
|
timedPairs: timed,
|
||||||
|
aligned: matched,
|
||||||
|
}
|
||||||
|
|
||||||
|
if timed > 0 {
|
||||||
|
a.durationFit = durTotal / float64(timed)
|
||||||
|
}
|
||||||
|
|
||||||
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
// indexForPosition finds the expected track at a disc/track position.
|
// indexForPosition finds the expected track at a disc/track position.
|
||||||
|
|||||||
@@ -0,0 +1,224 @@
|
|||||||
|
package download
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"path/filepath"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Soulseek politeness is per peer, not per daemon (#272).
|
||||||
|
|
||||||
|
func TestKeyedLockSerialisesOneKeyOnly(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
var l keyedLock[string]
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
releaseA, err := l.acquire(ctx, "a")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("acquire a: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Another key is free while "a" is held.
|
||||||
|
releaseB, err := l.acquire(ctx, "b")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("acquire b: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseB()
|
||||||
|
|
||||||
|
// The same key waits, and gives up with its context.
|
||||||
|
short, cancel := context.WithTimeout(ctx, 20*time.Millisecond)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
if _, err := l.acquire(short, "a"); !errors.Is(err, context.DeadlineExceeded) {
|
||||||
|
t.Fatalf("second acquire of a held key = %v, want the deadline", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseA()
|
||||||
|
releaseA() // Idempotent: a second call must not free someone else's hold.
|
||||||
|
|
||||||
|
if n := l.size(); n != 0 {
|
||||||
|
t.Errorf("%d keys left behind, want none once nobody holds or waits", n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// grabEach runs one grab per candidate and returns a function that waits
|
||||||
|
// for all of them; grabAll's reasons for waiting apply.
|
||||||
|
func grabEach(t *testing.T, f managerFixture, cands []Candidate) func() {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
|
for i, c := range cands {
|
||||||
|
dl := fourTrackDownload()
|
||||||
|
dl.ID = "dl-" + string(rune('a'+i))
|
||||||
|
|
||||||
|
if err := f.store.CreateDownload(ctx, dl); err != nil {
|
||||||
|
t.Fatalf("CreateDownload: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
wg.Add(1)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
|
||||||
|
f.manager.grab(ctx, dl, c, nil, false)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
return func() {
|
||||||
|
done := make(chan struct{})
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
wg.Wait()
|
||||||
|
close(done)
|
||||||
|
}()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
case <-time.After(5 * time.Second):
|
||||||
|
t.Error("transfers did not finish")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func slskdCandidates(p *FakeProvider, peers ...string) []Candidate {
|
||||||
|
out := make([]Candidate, 0, len(peers))
|
||||||
|
|
||||||
|
for i, peer := range peers {
|
||||||
|
c := p.Candidates[0]
|
||||||
|
c.ID = c.ID + "-" + itoa(i)
|
||||||
|
c.Kind = KindSlskd
|
||||||
|
c.ProviderID = 1
|
||||||
|
c.Origin = peer
|
||||||
|
out = append(out, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// Three albums from one user are asked for one at a time, even though
|
||||||
|
// the daemon would allow three transfers.
|
||||||
|
func TestOnePeerIsAskedForOneThingAtATime(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
f := newManagerFixture(t)
|
||||||
|
f.manager.SetMaxConcurrent(4)
|
||||||
|
|
||||||
|
p := fakeWithAlbum(1, "slskd", ".flac")
|
||||||
|
p.GrabGate = make(chan struct{})
|
||||||
|
|
||||||
|
f.manager.installProvider(Config{ID: 1, Kind: KindSlskd, Priority: 50}, p)
|
||||||
|
|
||||||
|
wait := grabEach(t, f, slskdCandidates(p, "alice", "alice", "alice"))
|
||||||
|
|
||||||
|
waitFor(t, func() bool { return p.GrabCallCount() >= 1 }, "no grab started")
|
||||||
|
time.Sleep(150 * time.Millisecond)
|
||||||
|
|
||||||
|
if got := p.MaxParallelGrabs(); got != 1 {
|
||||||
|
t.Errorf("%d simultaneous grabs from one peer, want 1", got)
|
||||||
|
}
|
||||||
|
|
||||||
|
close(p.GrabGate)
|
||||||
|
|
||||||
|
waitFor(t, func() bool { return p.GrabCallCount() == 3 }, "queued grabs never ran")
|
||||||
|
wait()
|
||||||
|
|
||||||
|
if n := f.manager.peerLocks.size(); n != 0 {
|
||||||
|
t.Errorf("%d peer locks left behind", n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Different users run at once, up to the daemon's cap — the point of
|
||||||
|
// the change: one slow peer no longer holds up every other.
|
||||||
|
func TestDifferentPeersRunTogether(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
f := newManagerFixture(t)
|
||||||
|
f.manager.SetMaxConcurrent(8)
|
||||||
|
|
||||||
|
p := fakeWithAlbum(1, "slskd", ".flac")
|
||||||
|
p.GrabGate = make(chan struct{})
|
||||||
|
|
||||||
|
f.manager.installProvider(Config{ID: 1, Kind: KindSlskd, Priority: 50}, p)
|
||||||
|
|
||||||
|
wait := grabEach(t, f, slskdCandidates(p, "alice", "bob", "carol", "dave"))
|
||||||
|
|
||||||
|
waitFor(
|
||||||
|
t,
|
||||||
|
func() bool { return p.MaxParallelGrabs() >= kindConcurrency[KindSlskd] },
|
||||||
|
"different peers were serialised",
|
||||||
|
)
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
|
||||||
|
if got := p.MaxParallelGrabs(); got != kindConcurrency[KindSlskd] {
|
||||||
|
t.Errorf("%d simultaneous grabs, want the daemon cap %d", got, kindConcurrency[KindSlskd])
|
||||||
|
}
|
||||||
|
|
||||||
|
close(p.GrabGate)
|
||||||
|
wait()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSlskdLocalFolders(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
s := &slskd{downloadsPath: "/dl"}
|
||||||
|
|
||||||
|
got := s.localFolders(Candidate{Files: []CandidateFile{
|
||||||
|
{Path: `\m\The Wall\CD2\01 Hey You.flac`},
|
||||||
|
{Path: `\m\The Wall\CD1\01 In The Flesh.flac`},
|
||||||
|
{Path: `\m\The Wall\CD1\02 The Thin Ice.flac`},
|
||||||
|
}})
|
||||||
|
|
||||||
|
want := []string{filepath.Join("/dl", "CD1"), filepath.Join("/dl", "CD2")}
|
||||||
|
if len(got) != len(want) || got[0] != want[0] || got[1] != want[1] {
|
||||||
|
t.Errorf("localFolders = %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Two peers' "Greatest Hits" land in one slskd directory, so the second
|
||||||
|
// grab does not enqueue until the first has collected its files.
|
||||||
|
func TestSlskdSameFolderNameWaits(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
stub := newSlskdStub(t)
|
||||||
|
s, downloads := newStubSlskd(t, stub)
|
||||||
|
|
||||||
|
c := Candidate{
|
||||||
|
Payload: map[string]string{"username": "bob"},
|
||||||
|
Files: []CandidateFile{
|
||||||
|
{Path: `\music\Greatest Hits\01 Intro.flac`, Size: 1, IsAudio: true},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
release, err := lockSlskdFolders(
|
||||||
|
context.Background(), []string{filepath.Join(downloads, "Greatest Hits")},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("lock: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
if _, err := s.Grab(ctx, c, t.TempDir(), nil); !errors.Is(err, context.DeadlineExceeded) {
|
||||||
|
t.Fatalf("Grab = %v, want it to wait on the held folder", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
release()
|
||||||
|
|
||||||
|
stub.mu.Lock()
|
||||||
|
posted := stub.posted
|
||||||
|
stub.mu.Unlock()
|
||||||
|
|
||||||
|
if posted {
|
||||||
|
t.Error("enqueued transfers into a folder another grab held")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -236,17 +236,18 @@ func Register(d Descriptor, c Constructor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// concurrencyField describes the per-provider transfer limit, with help
|
// concurrencyField describes the per-provider transfer limit, with help
|
||||||
// text explaining why the default is what it is — a user who raises
|
// text explaining what the number means where it means something
|
||||||
// slskd from 1 to 8 and gets themselves queued behind every other
|
// unusual: on slskd it counts peers, since each peer is only ever asked
|
||||||
// Soulseek user deserves to have been warned.
|
// for one folder at a time whatever it is set to.
|
||||||
func concurrencyField(k Kind) Field {
|
func concurrencyField(k Kind) Field {
|
||||||
help := "Maximum simultaneous transfers from this client."
|
help := "Maximum simultaneous transfers from this client."
|
||||||
|
|
||||||
if k == KindSlskd {
|
if k == KindSlskd {
|
||||||
help = "Maximum simultaneous transfers. Soulseek peers serve " +
|
help = "How many Soulseek users to download from at once. " +
|
||||||
"one file at a time and queue or ban clients that ask for " +
|
"Each user is only ever asked for one album at a time, " +
|
||||||
"more, so 1 is both the polite setting and usually the " +
|
"since peers queue or ban clients that ask for more; " +
|
||||||
"fastest."
|
"this bounds how many different users are asked in " +
|
||||||
|
"parallel."
|
||||||
}
|
}
|
||||||
|
|
||||||
return Field{
|
return Field{
|
||||||
|
|||||||
+1025
-84
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user