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.

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

221221 self._wait_for_data(
222222 """() => {
223223 const s = window.__INITIAL_STATE__;
224- return s && s.user && (s.user.userPageData || s.user.userInfo);
224+ return s && s.user;
225225 }""",
226226 timeout=15.0,
227- desc="user.userPageData",
227+ desc="user (profile)",
228228 )
229229
230230 # Vue wraps values in reactive refs like {_value, dep, ...}
241241 if (u.userPageData) data.userPageData = unwrap(u.userPageData, 0);
242242 if (u.notes) data.notes = unwrap(u.notes, 0);
243243 if (u.userInfo) data.userInfo = unwrap(u.userInfo, 0);
244+ if (Object.keys(data).length === 0) {
245+ return unwrap(u, 0);
246+ }
244247 return data;
245248 }
246249 return null;
248251 )
249252
250253 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}}
252260 return result
253261
254262 # ===== Followers / Following =====

The check that tells the two apart

failpass·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.