From 5c1349ff8497e30791835afb2068db616e6957a7 Mon Sep 17 00:00:00 2001 From: Jasper Delahaije Date: Sat, 17 Oct 2026 09:56:54 +0200 Subject: [PATCH] Expand weight evidence probe across APK statistics selections --- docs/app-validation.md | 4 ++ docs/weight-source-investigation.md | 87 +++++++++++++++++++++++++++++ scripts/probe_weights.py | 27 ++++++++- scripts/weight_report.py | 4 +- tests/test_weight_probe.py | 48 +++++++++++++++- 5 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 docs/weight-source-investigation.md diff --git a/docs/app-validation.md b/docs/app-validation.md index 8e3edac..555fc47 100644 --- a/docs/app-validation.md +++ b/docs/app-validation.md @@ -275,3 +275,7 @@ The live timezone contract was corrected after this guide was originally written Changes now require `iana_time_zone` in addition to the catalog ID. See [remaining-validation.md](remaining-validation.md) before changing timezones; it also documents DND preservation and the separate DST observation script. + + +For the expanded four-range weight probe and independent-visit evidence boundaries, +see [weight-source-investigation.md](weight-source-investigation.md). diff --git a/docs/weight-source-investigation.md b/docs/weight-source-investigation.md new file mode 100644 index 0000000..c5948cc --- /dev/null +++ b/docs/weight-source-investigation.md @@ -0,0 +1,87 @@ +# Weight source investigation (#41) + +## What the APK establishes + +Source: NOTTY Smart Pet 1.1.30, SHA-256 +`3b6dc21037f2802e92233ecd9f685e76b03a79afa2d82dd52a5dfcd689a18e6a`. +Addresses refer to local ARM64 Blutter output; decoded files stay ignored. + +- `CatsController::getPetList` GETs `/pet/list` at `0xbf67cc`. + `cats_view.dart` reads the selected row's `today_weight` at `0xc9d8f4`. +- `PetCardController::getAllPetDetail` GETs `/pet/info/{pet_id}` + (`0xbf9590`, GET `0xbf95ac`); its response callback (`0xbf95f8`, field + callback `0xbf9690`) assigns recognized fields to observables. Its constructor + initializes `today_weight` and `yesterday_weight` (`0xd23158`, `0xd23198`). + Neither the presence of these fields nor their defaults proves a fresh weigh-in. +- Account toilet charts use `/pet/pet_wc_data_statistics` (`0xbf86dc`), with + `pet_id` and `type` parameters (`0xbf8780`, `0xbf87a4`). The `type` closure + (`0xbf9474`) reads controller field `0x63`. +- Device/pet charts use `/device/litter_box/pet_data_statistics/{box_id}` + (`0xbf986c`) with `pet_id` and `type` (`0xbf9914`, `0xbf9938`). +- The chart tab controller has four positions (`0xbf809c`). Its listener assigns + `index + 1` to the selection (`0xbfac08` → `0xbfac28`), establishing query + types 1–4. These are selector values, not an invented pagination range. +- Per-box detail uses `/device/litter_box/pet_data_detail/{box_id}` + (`0xbfa6f0`). No separate timestamped weight-history request was identified in + these inspected callers. The inspected native pet-card view does not establish + a weight-history chart. This is not proof that the backend has no such data. + +## Fresh live evidence + +The expanded probe completed 25 GET reads without failures: both pet profiles, +all four account toilet-chart selections for each account pet, box info/list/ +associations, and the selected box's detail/default chart/four chart selections +for each associated pet. Feeder and water endpoints were not called. + +Recognized weight fields appeared only in the profiles: `weight`, `today_weight` +and `yesterday_weight`, without a measurement timestamp. Chart responses contain +`duration` and `count`; detail responses contain today's/yesterday's toilet +counts and duration plus profile metadata, without recognized weight fields. +The comparable profile weight/unit/timestamp context was unchanged from the +prior capture. Toilet-event rows inspected in box info had no weight field. + +The owner recalls a visit sometime that morning but cannot identify the cat or +time. This is **not** an independently bracketed visit. Neither unchanged values +nor a later poll establishes measurement freshness, reference fallback behavior +or which cat was measured. No independent per-visit weight history is claimed. + +The API also supplies an external health-report SPA link. Only the public root +was requested, without its private URL fragment or credentials. The HTTPS root +was unreachable during this investigation, so that application's data requests +remain uninspected. A failed fetch is not evidence that it has no weight history. +Do not publish account health URLs or private fragments in an issue or report. + +## Repeatable read-only comparison + +`probe_weights.py` now includes all four APK chart selections. Captures retain +`capture_started_at`/`captured_at` and per-source `requested_at`/`received_at`. +These delimit collection intervals; they are **not measurement timestamps**. +Default reports omit names, IDs, weight values and captured timestamp values. +Existing captures remain readable and comparison joins by private stable IDs. + +Before the next independently observed normal visit: + +```sh +uv run python scripts/probe_weights.py \ + --session-file probe-output/fresh-login-20261017.private.json \ + --capture-raw probe-output/weight-before-next-visit.private.json \ + --output probe-output/weight-before-next-visit.report.json +``` + +After the visit and phone-app refresh: + +```sh +uv run python scripts/probe_weights.py \ + --session-file probe-output/fresh-login-20261017.private.json \ + --compare probe-output/weight-before-next-visit.private.json \ + --capture-raw probe-output/weight-after-next-visit.private.json \ + --output probe-output/weight-after-next-visit.report.json +``` + +Use new output filenames for each attempt. Record the independently identified +cat, approximate visit start/end and phone-app weight/unit separately and +privately. For a clean before/after window the first capture must finish before +the visit starts and the second must start afterward. A different numeric weight +still needs source/timestamp investigation; an unchanged weight cannot disprove +a measurement. NOTTY's own cat attribution may be wrong and is not corrected by +reassigning API identities in this integration. diff --git a/scripts/probe_weights.py b/scripts/probe_weights.py index a35cc14..75f967f 100755 --- a/scripts/probe_weights.py +++ b/scripts/probe_weights.py @@ -34,6 +34,7 @@ SAND_WORD = "sand" LIST_FIELDS = ("list", "data", "rows", "items") LITTER_PRODUCT_ID = 2 +STATISTICS_TYPES = (1, 2, 3, 4) def rows(value: JsonValue) -> list[JsonObject]: @@ -117,6 +118,7 @@ async def read(self, label: str, kind: str, identity: str, path: str, *, pet_id: Raises: NottyAuthError: If the saved session expires; collection stops without retry. """ + requested_at = datetime.now(UTC).isoformat() try: data = await self.api.request("GET", path) except probe_datapoints.load_api.NottyAuthError: @@ -127,7 +129,14 @@ async def read(self, label: str, kind: str, identity: str, path: str, *, pet_id: if pet_id is not None and not profile_identity_matches(data, pet_id): self.errors.append({"source": label, "error": "profile_identity_mismatch_or_missing"}) return None - self.sources.append({"label": label, "kind": kind, "identity": identity, "data": data}) + self.sources.append({ + "label": label, + "kind": kind, + "identity": identity, + "data": data, + "requested_at": requested_at, + "received_at": datetime.now(UTC).isoformat(), + }) return data async def box(self, device_id: str, label: str, pets: dict[str, str]) -> None: @@ -167,6 +176,13 @@ async def box(self, device_id: str, label: str, pets: dict[str, str]) -> None: f"{identity}:pet:{pet_id}:{kind}", f"/device/litter_box/{endpoint}/{device_id}?pet_id={pet_id}", ) + for selection in STATISTICS_TYPES: + await self.read( + f"{label}.{pet_label}.statistics_type{selection}", + "statistics", + f"{identity}:pet:{pet_id}:statistics:type:{selection}", + f"/device/litter_box/pet_data_statistics/{device_id}?pet_id={pet_id}&type={selection}", + ) async def collect(self, device_ids: list[str], pet_ids: list[str]) -> JsonObject: """Resolve selected targets from current account discovery before reading data. @@ -177,6 +193,7 @@ async def collect(self, device_ids: list[str], pet_ids: list[str]) -> JsonObject Raises: ValueError: If a requested target is outside current account discovery. """ + started_at = datetime.now(UTC).isoformat() pets = rows(await self.api.request("GET", "/pet/list")) account_pets = {numeric_id(pet.get("pet_id")): pet for pet in pets} selected_pets = {numeric_id(value) for value in pet_ids} if pet_ids else set(account_pets) @@ -194,12 +211,20 @@ async def collect(self, device_ids: list[str], pet_ids: list[str]) -> JsonObject await self.read( f"{label}.profile", "profile", f"pet:{pet_id}:profile", f"/pet/info/{pet_id}", pet_id=pet_id ) + for selection in STATISTICS_TYPES: + await self.read( + f"{label}.wc_statistics_type{selection}", + "wc_statistics", + f"pet:{pet_id}:wc_statistics:type:{selection}", + f"/pet/pet_wc_data_statistics?pet_id={pet_id}&type={selection}", + ) for index, device_id in enumerate(sorted(selected_boxes, key=int), 1): await self.box(device_id, f"box[{index}]", labels) if not selected_boxes or not selected_pets: self.errors.append({"source": "discovery", "error": "no_litter_boxes_or_pets"}) return { "schema_version": 1, + "capture_started_at": started_at, "captured_at": datetime.now(UTC).isoformat(), "sources": self.sources, "errors": self.errors, diff --git a/scripts/weight_report.py b/scripts/weight_report.py index a98257b..b476196 100644 --- a/scripts/weight_report.py +++ b/scripts/weight_report.py @@ -56,7 +56,7 @@ CAPTURE_VERSION = 1 FIELD_DATA = "data" SOURCE_PATTERN = re.compile( - r"(?:pet\[[1-9][0-9]*\]\.profile|box\[[1-9][0-9]*\]\.(?:info|pet_list|associations|pet\[[1-9][0-9]*\]\.(?:statistics|detail)))" + r"(?:pet\[[1-9][0-9]*\]\.(?:profile|wc_statistics_type[1-4])|box\[[1-9][0-9]*\]\.(?:info|pet_list|associations|pet\[[1-9][0-9]*\]\.(?:statistics(?:_type[1-4])?|detail)))" ) @@ -202,7 +202,7 @@ def capture_sources(capture: JsonObject) -> list[JsonObject]: not isinstance(label, str) or SOURCE_PATTERN.fullmatch(label) is None or not isinstance(kind, str) - or kind not in {PROFILE, "info", "pet_list", "associations", "statistics", "detail"} + or kind not in {PROFILE, "info", "pet_list", "associations", "statistics", "detail", "wc_statistics"} ): msg = "Unknown weight-probe source label or kind" raise ValueError(msg) diff --git a/tests/test_weight_probe.py b/tests/test_weight_probe.py index dafb5d1..1f4d356 100644 --- a/tests/test_weight_probe.py +++ b/tests/test_weight_probe.py @@ -19,9 +19,11 @@ FIELD_VALUE = "reported_value" SERIES_COUNT = 2 EXPECTED_DETAIL_PATH = "/device/litter_box/pet_data_detail/123?pet_id=7" -FORBIDDEN_PATH_PARTS = ("pet_id=8", "pet_id=99", "/456") +FORBIDDEN_PATH_PARTS = ("pet_id=99", "/456") PRIVATE_MARKER = "secret-token" ANALYSIS_TIME = "analysed_at" +UNBOUND_PET_QUERY = "pet_id=8" +PRIVATE_JOIN_KEY = "private-join-key" def capture() -> JsonObject: @@ -110,6 +112,12 @@ async def test_collector_calls_get_only_and_scopes_history_to_bound_account_pets paths = [call.args[1] for call in api.request.await_args_list] assert all(call.args[0] == GET for call in api.request.await_args_list) assert EXPECTED_DETAIL_PATH in paths + assert not any(path.startswith("/device/") and UNBOUND_PET_QUERY in path for path in paths) + assert all(f"/pet/pet_wc_data_statistics?pet_id=7&type={selection}" in paths for selection in (1, 2, 3, 4)) + assert all( + f"/device/litter_box/pet_data_statistics/123?pet_id=7&type={selection}" in paths for selection in (1, 2, 3, 4) + ) + assert all(source["requested_at"] <= source["received_at"] for source in result["sources"]) assert not any(part in path for path in paths for part in FORBIDDEN_PATH_PARTS) @@ -174,3 +182,41 @@ async def test_profile_for_a_different_pet_never_becomes_weight_evidence() -> No await collector.read("pet[1].profile", "profile", "pet:7:profile", "/pet/info/7", pet_id="7") assert not collector.sources assert collector.errors + + +@pytest.mark.parametrize( + "label", ["pet[1].wc_statistics_type1", "pet[1].wc_statistics_type4", "box[1].pet[1].statistics_type4"] +) +def test_extended_statistics_sources_are_safe_and_detect_weight_candidates(label: str) -> None: + """Report candidates from all APK-selected ranges without trusting them as measurements.""" + kind = "wc_statistics" if label.startswith("pet[") else "statistics" + value = { + "schema_version": 1, + "errors": [], + "sources": [ + { + "label": label, + "kind": kind, + "identity": "private-join-key", + "data": {"weight": [4.1], "date": "2026-01-01"}, + } + ], + } + result = weight_report.report(value) + expected = "unverified_measurement_candidate" + assert result["sources"][0]["fields"][0]["role"] == expected + assert PRIVATE_JOIN_KEY not in json.dumps(result) + + +@pytest.mark.parametrize( + "label", ["pet[1].wc_statistics_type0", "pet[1].wc_statistics_type5", "box[1].pet[1].statistics_type99"] +) +def test_unknown_statistics_ranges_are_not_echoed(label: str) -> None: + """Untrusted capture labels cannot add unsupported range identifiers to output.""" + value = { + "schema_version": 1, + "errors": [], + "sources": [{"label": label, "kind": "statistics", "identity": "join", "data": {}}], + } + with pytest.raises(ValueError, match="Unknown"): + weight_report.report(value)