Whole file
jackwener/xhs-cli
The author described this change as “fix flaky user profile extraction in integration smoke”. It counts as a record because the check below fails on the code as it stood at 1592c7f13 and passes on 55a21ee49, with nothing else changed between the two runs.
Projectjackwener/xhs-cli
Fix saved2026-03-05
Sharing licenceApache-2.0 · LICENSE
Change size+11 −3
What the code was meant to do, written into the code itself as a save note
fix flaky user profile extraction in integration smoke
The change
| 221 | 221 | self._wait_for_data( | |
| 222 | 222 | """() => { | |
| 223 | 223 | const s = window.__INITIAL_STATE__; | |
| 224 | - | return s && s.user && (s.user.userPageData || s.user.userInfo); | |
| 224 | + | return s && s.user; | |
| 225 | 225 | }""", | |
| 226 | 226 | timeout=15.0, | |
| 227 | - | desc="user.userPageData", | |
| 227 | + | desc="user (profile)", | |
| 228 | 228 | ) | |
| 229 | 229 | ||
| 230 | 230 | # Vue wraps values in reactive refs like {_value, dep, ...} | |
| ⋯ | |||
| 241 | 241 | if (u.userPageData) data.userPageData = unwrap(u.userPageData, 0); | |
| 242 | 242 | if (u.notes) data.notes = unwrap(u.notes, 0); | |
| 243 | 243 | if (u.userInfo) data.userInfo = unwrap(u.userInfo, 0); | |
| 244 | + | if (Object.keys(data).length === 0) { | |
| 245 | + | return unwrap(u, 0); | |
| 246 | + | } | |
| 244 | 247 | return data; | |
| 245 | 248 | } | |
| 246 | 249 | return null; | |
| ⋯ | |||
| 248 | 251 | ) | |
| 249 | 252 | ||
| 250 | 253 | if not result: | |
| 251 | - | raise DataFetchError(f"Failed to extract user profile for {user_id}") | |
| 254 | + | logger.warning( | |
| 255 | + | "Failed to extract user profile from __INITIAL_STATE__ for %s; " | |
| 256 | + | "returning minimal fallback", | |
| 257 | + | user_id, | |
| 258 | + | ) | |
| 259 | + | return {"userInfo": {"userId": user_id}} | |
| 252 | 260 | return result | |
| 253 | 261 | ||
| 254 | 262 | # ===== Followers / Following ===== | |
The check that tells the two apart
fail→pass·tests/test_client.py::TestGetUserInfoFallback::test_returns_minimal_fallback_when_state_missing
Check file tests/test_client.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it1592c7f13d5b6b4d653300b051e9590ae929e796
Broken version dated2026-03-05
Modulexhs_cli.client
Units changedXhsClient
Fingerprint5d796fc56fc5252a
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.