mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-28 18:09:12 +01:00
Compare commits
2 Commits
c8272d9eea
...
aea8838515
| Author | SHA1 | Date | |
|---|---|---|---|
| aea8838515 | |||
| 2e5566e8a3 |
@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"intent": "A red CI baseline no longer blocks a commit or push that touches only dependency-pin files, so a pin bump can fix a red freshness gate.",
|
||||||
|
"scope": [
|
||||||
|
"meta/scripts/check_ci_green.sh: PIN_FILE_RE, changed_files, only_pin_files and the exemption branch",
|
||||||
|
"linux_configuration/tests/test_check_ci_green.bats (new)",
|
||||||
|
"Non-goal: any other bypass; everything else stays fail-closed on a red baseline"
|
||||||
|
],
|
||||||
|
"changes": [
|
||||||
|
"On a red baseline the hook exits 0 when every changed file is .fvmrc, pubspec.yaml/.lock, package.json, pnpm-lock.yaml, requirements*.txt or pyproject.toml, and prints an EXEMPTION FIRED line listing them",
|
||||||
|
"Scope is the push range (PRE_COMMIT_FROM_REF..TO_REF) when set, else the staged files; empty or unusable scope is not exempt"
|
||||||
|
],
|
||||||
|
"verification": [
|
||||||
|
{
|
||||||
|
"command": "bats linux_configuration/tests/test_check_ci_green.bats",
|
||||||
|
"result": "pass",
|
||||||
|
"evidence": "8/8 ok: green passes, red blocks code, empty scope, pin-only exempt, mixed blocked, lookalikes blocked, push range, bad range fails closed"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"command": "pre-commit run --files meta/scripts/check_ci_green.sh linux_configuration/tests/test_check_ci_green.bats",
|
||||||
|
"result": "pass",
|
||||||
|
"evidence": "no hook output beyond Passed/Skipped"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"risks": [
|
||||||
|
"A pin-only change can still break the build; the pre-push CI mirror and CI itself remain the guard",
|
||||||
|
"A poisoned pin file is exempt from the red-baseline check only, not from other hooks"
|
||||||
|
],
|
||||||
|
"rollback": [
|
||||||
|
"git revert the commit; the hook returns to blocking every commit on a red baseline",
|
||||||
|
"Validate by running bats linux_configuration/tests/test_check_ci_green.bats is gone and the hook still passes on green"
|
||||||
|
]
|
||||||
|
}
|
||||||
91
linux_configuration/tests/test_check_ci_green.bats
Executable file
91
linux_configuration/tests/test_check_ci_green.bats
Executable file
@ -0,0 +1,91 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
# Tests for meta/scripts/check_ci_green.sh with a stubbed `gh` and a scratch git
|
||||||
|
# repo, so no network and no real CI state is involved.
|
||||||
|
#
|
||||||
|
# bats linux_configuration/tests/test_check_ci_green.bats
|
||||||
|
|
||||||
|
bats_require_minimum_version 1.5.0
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
SCRIPT="$(cd -- "$(dirname -- "$BATS_TEST_FILENAME")/../.." && pwd)/meta/scripts/check_ci_green.sh"
|
||||||
|
unset CI_GREEN_SKIP GITHUB_ACTIONS PRE_COMMIT_FROM_REF PRE_COMMIT_TO_REF
|
||||||
|
mkdir -p "$BATS_TEST_TMPDIR/bin" "$BATS_TEST_TMPDIR/repo"
|
||||||
|
cat >"$BATS_TEST_TMPDIR/bin/gh" <<'STUB'
|
||||||
|
#!/bin/bash
|
||||||
|
[[ $1 == auth ]] && exit 0
|
||||||
|
echo "${FAKE_CONCLUSION:-failure}"
|
||||||
|
STUB
|
||||||
|
chmod +x "$BATS_TEST_TMPDIR/bin/gh"
|
||||||
|
export PATH="$BATS_TEST_TMPDIR/bin:$PATH"
|
||||||
|
cd "$BATS_TEST_TMPDIR/repo" || return 1
|
||||||
|
git init -q .
|
||||||
|
git config user.email t@example.com
|
||||||
|
git config user.name t
|
||||||
|
git commit -q --allow-empty -m base
|
||||||
|
}
|
||||||
|
|
||||||
|
stage() {
|
||||||
|
local f
|
||||||
|
for f in "$@"; do
|
||||||
|
mkdir -p "$(dirname "$f")"
|
||||||
|
echo x >"$f"
|
||||||
|
git add "$f"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "green baseline passes regardless of files" {
|
||||||
|
stage src/app.py
|
||||||
|
FAKE_CONCLUSION=success run "$SCRIPT"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "red baseline blocks a code change" {
|
||||||
|
stage src/app.py
|
||||||
|
run "$SCRIPT"
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
[[ $output == *"main is RED"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "red baseline blocks nothing staged (fail closed)" {
|
||||||
|
run "$SCRIPT"
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "red baseline allows a pin-only change and says so" {
|
||||||
|
stage meta/.fvmrc app/pubspec.yaml app/pubspec.lock web/package.json web/pnpm-lock.yaml requirements-test.txt pyproject.toml
|
||||||
|
run "$SCRIPT"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ $output == *"EXEMPTION FIRED"* ]]
|
||||||
|
[[ $output == *"meta/.fvmrc"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "red baseline blocks a pin mixed with code" {
|
||||||
|
stage meta/.fvmrc src/app.py
|
||||||
|
run "$SCRIPT"
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
[[ $output != *"EXEMPTION FIRED"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "lookalike names are not pins" {
|
||||||
|
stage notes/requirements.md my.fvmrc.bak
|
||||||
|
run "$SCRIPT"
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "push range of pins is exempt, range with code is not" {
|
||||||
|
local base
|
||||||
|
base="$(git rev-parse HEAD)"
|
||||||
|
stage meta/.fvmrc
|
||||||
|
git commit -q -m pin
|
||||||
|
PRE_COMMIT_FROM_REF="$base" PRE_COMMIT_TO_REF="$(git rev-parse HEAD)" run "$SCRIPT"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
stage src/app.py
|
||||||
|
git commit -q -m code
|
||||||
|
PRE_COMMIT_FROM_REF="$base" PRE_COMMIT_TO_REF="$(git rev-parse HEAD)" run "$SCRIPT"
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "unusable push range fails closed" {
|
||||||
|
PRE_COMMIT_FROM_REF=0000000 PRE_COMMIT_TO_REF=deadbeef run "$SCRIPT"
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
}
|
||||||
@ -18,6 +18,14 @@
|
|||||||
# failing is how a red baseline gets buried under changes that make it harder
|
# failing is how a red baseline gets buried under changes that make it harder
|
||||||
# to bisect.
|
# to bisect.
|
||||||
#
|
#
|
||||||
|
# Built-in exemption (no env var, nothing to forget): when the change under
|
||||||
|
# review touches ONLY dependency-pin / toolchain files (see PIN_FILE_RE), a red
|
||||||
|
# baseline does not block it, because such a bump is the usual fix for a red
|
||||||
|
# dependency-freshness gate and refusing it deadlocks the repo. The scope is the
|
||||||
|
# push range (PRE_COMMIT_FROM_REF..TO_REF) when set, else the staged files. An
|
||||||
|
# empty or undeterminable scope is NOT exempt (fail closed). A loud line says
|
||||||
|
# which files qualified.
|
||||||
|
#
|
||||||
# Bypass for a deliberate fix-forward commit. It must be given TWICE, because
|
# Bypass for a deliberate fix-forward commit. It must be given TWICE, because
|
||||||
# this hook runs at both stages: once at commit, and again inside the pre-push
|
# this hook runs at both stages: once at commit, and again inside the pre-push
|
||||||
# CI mirror's clean-worktree `pre-commit` run, which sees the same still-red
|
# CI mirror's clean-worktree `pre-commit` run, which sees the same still-red
|
||||||
@ -35,6 +43,8 @@ readonly SCRIPT_NAME="${0##*/}"
|
|||||||
# can legitimately be an old one.
|
# can legitimately be an old one.
|
||||||
readonly REQUIRED_WORKFLOWS=("Pre-commit checks" "Shell tests")
|
readonly REQUIRED_WORKFLOWS=("Pre-commit checks" "Shell tests")
|
||||||
readonly TIMEOUT_SECONDS=5
|
readonly TIMEOUT_SECONDS=5
|
||||||
|
# Files whose edits may land on a red baseline (matched on the full path).
|
||||||
|
readonly PIN_FILE_RE='(^|/)(\.fvmrc|pubspec\.yaml|pubspec\.lock|package\.json|pnpm-lock\.yaml|requirements[^/]*\.txt|pyproject\.toml)$'
|
||||||
|
|
||||||
warn_and_pass() {
|
warn_and_pass() {
|
||||||
printf '%s: %s\n' "$SCRIPT_NAME" "$1" >&2
|
printf '%s: %s\n' "$SCRIPT_NAME" "$1" >&2
|
||||||
@ -75,6 +85,31 @@ for workflow in "${REQUIRED_WORKFLOWS[@]}"; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
changed_files() {
|
||||||
|
if [[ -n ${PRE_COMMIT_FROM_REF:-} && -n ${PRE_COMMIT_TO_REF:-} ]]; then
|
||||||
|
git diff --name-only "$PRE_COMMIT_FROM_REF" "$PRE_COMMIT_TO_REF" 2>/dev/null || true
|
||||||
|
else
|
||||||
|
git diff --cached --name-only 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
only_pin_files() {
|
||||||
|
local files file
|
||||||
|
files="$(changed_files)"
|
||||||
|
[[ -n $files ]] || return 1
|
||||||
|
while IFS= read -r file; do
|
||||||
|
[[ $file =~ $PIN_FILE_RE ]] || return 1
|
||||||
|
done <<<"$files"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ ${#failed[@]} -gt 0 ]] && only_pin_files; then
|
||||||
|
printf '%s: EXEMPTION FIRED: main is RED (%s) but this change touches ONLY dependency-pin files:\n' \
|
||||||
|
"$SCRIPT_NAME" "${failed[*]}" >&2
|
||||||
|
changed_files | sed 's/^/ - /' >&2
|
||||||
|
printf '%s: allowing it so a pin bump can fix a red baseline.\n' "$SCRIPT_NAME" >&2
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ${#failed[@]} -gt 0 ]]; then
|
if [[ ${#failed[@]} -gt 0 ]]; then
|
||||||
printf '%s: main is RED on GitHub Actions:\n' "$SCRIPT_NAME" >&2
|
printf '%s: main is RED on GitHub Actions:\n' "$SCRIPT_NAME" >&2
|
||||||
printf ' - %s\n' "${failed[@]}" >&2
|
printf ' - %s\n' "${failed[@]}" >&2
|
||||||
|
|||||||
127
python_pkg/android_ui/TODO-android-ui-mcp-wrapper.md
Normal file
127
python_pkg/android_ui/TODO-android-ui-mcp-wrapper.md
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
# Task: replace blind coordinate tapping with element-targeted Android UI automation
|
||||||
|
|
||||||
|
> **STATUS 2026-08-10: BUILT.** The tool now exists at
|
||||||
|
> `~/src/testsAndMisc/python_pkg/android_ui/` (see its README). It covers `dump` /
|
||||||
|
> `find` / `tap` / `type` / `wait` / `focus` with verified typing, ambiguity as
|
||||||
|
> an error, keyboard detection, and partial-tree retries — all exercised
|
||||||
|
> against the physical Pixel 6a. What remains from the spec below is the
|
||||||
|
> optional MCP wrapper, `scroll_to()`, and rolling it out to `~/src/todo` and
|
||||||
|
> `~/src/dufs-cloud/app`. Everything after this line is the original brief, kept
|
||||||
|
> because it records WHY each guarantee exists.
|
||||||
|
|
||||||
|
## what
|
||||||
|
|
||||||
|
Every Flutter/Android app in these repos is currently driven by an agent the
|
||||||
|
same bad way: screenshot -> read pixel positions by eye -> `adb shell input tap
|
||||||
|
<x> <y>`. Replace that with a reusable tool that finds elements by _identity_
|
||||||
|
(text, content-desc, resource-id) and taps their real bounds, and that can
|
||||||
|
report what is on screen as structured text instead of an image.
|
||||||
|
|
||||||
|
## why this is not a nicety
|
||||||
|
|
||||||
|
Observed in one session (2026-08-10, workout_app Firebase verification):
|
||||||
|
|
||||||
|
- **Silent mis-taps.** A tap at `(540, 1705)` intended for the password field
|
||||||
|
landed with the field unfocused. The typed password went nowhere. Nothing
|
||||||
|
errored — the next screenshot just showed an empty box. A no-op and a hit are
|
||||||
|
indistinguishable without dumping the tree and diffing.
|
||||||
|
- **Layout shift invalidates every coordinate.** Opening the soft keyboard moved
|
||||||
|
the email field from y=1572 to y=1319. Coordinates captured one step earlier
|
||||||
|
were already wrong.
|
||||||
|
- **Screenshot scaling is a manual multiply.** The harness renders 1080x2400 at
|
||||||
|
900x2000, so every read coordinate needs `* 1.20`. One forgotten multiply is
|
||||||
|
an off-screen tap.
|
||||||
|
- **Screenshots are expensive.** A full-page PNG per step burns far more context
|
||||||
|
than the equivalent element list, and can't be grepped or asserted on.
|
||||||
|
|
||||||
|
`uiautomator dump` already solves this and is on every device — no new
|
||||||
|
dependency:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
adb shell uiautomator dump /sdcard/ui.xml
|
||||||
|
adb pull /sdcard/ui.xml
|
||||||
|
# -> <node text="Connect Firebase" class="android.widget.Button"
|
||||||
|
# bounds="[32,1808][1048,1878]" .../>
|
||||||
|
```
|
||||||
|
|
||||||
|
This is how the same session recovered: dumping the tree found both `EditText`
|
||||||
|
nodes by class and gave exact centers, and the retry worked first time.
|
||||||
|
|
||||||
|
## where
|
||||||
|
|
||||||
|
New shared tool, not a per-repo copy. Two options, pick one:
|
||||||
|
|
||||||
|
- `~/src/testsAndMisc/python_pkg/android_ui/` — a CLI (`android-ui find "Connect
|
||||||
|
Firebase"`, `android-ui tap "Connect Firebase"`, `android-ui dump`), matching
|
||||||
|
how `app_icons` is already shared across repos.
|
||||||
|
- An MCP server exposing the same as tools, which is what makes it available to
|
||||||
|
the agent without shelling out. Preferred if MCP is acceptable — the user
|
||||||
|
asked for "some tool ... (mcp?) which also translates to UI".
|
||||||
|
|
||||||
|
Consumers (every repo with an Android surface):
|
||||||
|
|
||||||
|
- `~/src/screen-locker/stronglift_replacement/workout_app`
|
||||||
|
- `~/src/todo`
|
||||||
|
- `~/src/dufs-cloud/app`
|
||||||
|
- any future Flutter app (this should be part of the app scaffold)
|
||||||
|
|
||||||
|
## must
|
||||||
|
|
||||||
|
- `find(query)` -> matching elements with class, text/content-desc, bounds,
|
||||||
|
center, and enabled/focused state. Match on text, content-desc, or
|
||||||
|
resource-id; substring and exact.
|
||||||
|
- `tap(query)` -> resolves the query, taps the center of the _current_ bounds
|
||||||
|
(re-dump before every tap; never reuse a stale coordinate), and **fails
|
||||||
|
loudly with a non-zero exit when the query matches zero or >1 elements**.
|
||||||
|
Ambiguity must be an error, not a silent first-match.
|
||||||
|
- `type(query, text)` -> focus the field, type, then **verify the field's text
|
||||||
|
actually changed** and fail if not. This is the specific bug that cost this
|
||||||
|
session a round trip.
|
||||||
|
- `dump()` -> flat, greppable text list of visible elements. This replaces the
|
||||||
|
screenshot for most steps.
|
||||||
|
- Waits: `wait_for(query, timeout)` that polls the tree, so no more blind
|
||||||
|
`sleep 14`.
|
||||||
|
- must not: require root, an emulator, a running Flutter debug connection, or
|
||||||
|
any change to app source. It must work against a plain release APK on a
|
||||||
|
physical device over adb.
|
||||||
|
- optional: `flutter drive` / integration_test as a second backend when a debug
|
||||||
|
build IS available — richer (widget keys, no dump latency), but it cannot
|
||||||
|
drive a release APK, so it can't be the only path.
|
||||||
|
- optional: screenshot fallback for genuinely visual checks (theming, icon
|
||||||
|
rendering) — where a picture is the point, not a workaround.
|
||||||
|
|
||||||
|
## done
|
||||||
|
|
||||||
|
A verification script that drives workout_app's "connect Firebase" flow
|
||||||
|
end-to-end with **zero hardcoded pixel coordinates** in it, and:
|
||||||
|
|
||||||
|
- passes on the current layout;
|
||||||
|
- still passes after the SYNC and OFFLINE BACKUP sections are reordered in
|
||||||
|
`settings_screen.dart` (the test that coordinate-based automation fails);
|
||||||
|
- exits non-zero, naming the query, when an element is missing.
|
||||||
|
|
||||||
|
## verify
|
||||||
|
|
||||||
|
On the physical Pixel 6a over adb, against an installed release APK — not an
|
||||||
|
emulator and not a debug-only Flutter driver session.
|
||||||
|
|
||||||
|
## read first
|
||||||
|
|
||||||
|
- This session's working recovery: `uiautomator dump` + the bounds-parsing
|
||||||
|
python in the screen-locker scratchpad (`ui.xml`, `ui2.xml`).
|
||||||
|
- `~/src/screen-locker/CLAUDE.md` — "You are NOT done until you install the new
|
||||||
|
version on the phone itself", which is why agent-driven UI is on the critical
|
||||||
|
path for every task in this repo.
|
||||||
|
- Note `uiautomator dump` returns an empty/partial tree while an animation is
|
||||||
|
in flight; retry-with-backoff belongs in the tool, not in each caller.
|
||||||
|
- **Observed 2026-08-10, must be handled:** while a Flutter `TextField` holds
|
||||||
|
focus, the dump returns ONLY the `EditText` nodes — the rest of the tree
|
||||||
|
(including the button you are about to tap) is missing, and it stays missing
|
||||||
|
across retries, so a naive retry loop never converges. Worse, `KEYCODE_BACK`
|
||||||
|
to dismiss the keyboard is treated by Flutter as a route pop: it navigated
|
||||||
|
out of Settings and discarded the typed credentials, twice. The tool must
|
||||||
|
unfocus without popping the route (tap dead space, or `dumpsys input_method`
|
||||||
|
to check `mInputShown` first) and must distinguish "tree is partial" from
|
||||||
|
"element is genuinely absent" rather than reporting a false negative.
|
||||||
|
|
||||||
|
REMOVE ME AFTER FINISH
|
||||||
Loading…
Reference in New Issue
Block a user