{"record":{"id":"19b0182ef9e7cee3","repo":"jackwener/OpenCLI","slug":"unexpected-jimeng-probe-json-stringify-probe","errorCode":null,"errorMessage":"Unexpected Jimeng probe: ${JSON.stringify(probe)}","messagePattern":"Unexpected Jimeng probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/jimeng/auth.js","lineNumber":31,"sourceCode":"    if (r.status === 401 || r.status === 403) return { kind: 'auth', detail: 'Jimeng passport HTTP ' + r.status };\n    if (!r.ok) return { kind: 'http', httpStatus: r.status };\n    const d = await r.json();\n    const u = d && d.data;\n    if (!u || !u.user_id || u.is_visitor_account) return { kind: 'auth', detail: 'Jimeng passport returned a visitor account (anonymous)' };\n    return { ok: true, user_id: String(u.user_id_str || u.user_id), screen_name: String(u.screen_name || u.name || '') };\n  } catch (e) {\n    return { kind: 'exception', detail: String(e && e.message || e) };\n  }\n})()`;\n\nasync function verifyJimengIdentity(page) {\n  await page.goto('https://jimeng.jianying.com/ai-tool/generate?type=image&workspace=0');\n  await page.wait(2);\n  const probe = await page.evaluate(WHOAMI_PROBE);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('jimeng.jianying.com', probe.detail);\n  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from Jimeng passport`);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`Jimeng whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Jimeng probe: ${JSON.stringify(probe)}`);\n  return { user_id: probe.user_id, screen_name: probe.screen_name };\n}\n\nregisterSiteAuthCommands({\n  site: 'jimeng',\n  domain: 'jimeng.jianying.com',\n  loginUrl: 'https://jimeng.jianying.com/',\n  columns: ['user_id', 'screen_name'],\n  verify: verifyJimengIdentity,\n  poll: async (page) => {\n    const probe = await page.evaluate(WHOAMI_PROBE);\n    if (!probe?.ok) throw new AuthRequiredError('jimeng.jianying.com', 'Waiting for Jimeng login');\n    return { user_id: probe.user_id, screen_name: probe.screen_name };\n  },\n});\n","sourceCodeStart":13,"sourceCodeEnd":47,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/jimeng/auth.js#L13-L47","documentation":"Final sanity check in verifyJimengIdentity: when the probe result is neither an auth/http/exception kind nor ok, the code throws CommandExecutionError with the JSON-serialized probe. This captures any unrecognized probe outcome so unknown protocol changes surface loudly instead of silently returning bad identity data.","triggerScenarios":"WHOAMI_PROBE returns an object without ok:true and without one of the known kinds — e.g. Jimeng changed the probe's response contract, the probe returned null/undefined, or a partially failing result with new fields.","commonSituations":"Jimeng front-end/API updated so the probe's assumptions broke; probe returns undefined because evaluate serialization failed (non-serializable return); a new intermediate result kind introduced by a code change.","solutions":["Read the JSON in the message to see the actual probe shape returned","Compare with WHOAMI_PROBE's expected contract and update the probe for Jimeng's current response format","Ensure the probe returns only serializable values from page.evaluate","Check for Jimeng A/B tests or regional variants that return a different whoami response","Update the CLI to a version matching the current Jimeng page behavior"],"exampleFix":"// before\nif (!probe?.ok) throw new CommandExecutionError(`Unexpected Jimeng probe: ${JSON.stringify(probe)}`);\n// after\nif (!probe?.ok) {\n  if (probe?.pending) return null; // tolerate newly-seen intermediate state\n  throw new CommandExecutionError(`Unexpected Jimeng probe: ${JSON.stringify(probe)}`);\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isUsableProbe(probe) {\n  return probe != null && typeof probe === 'object' && probe.ok === true &&\n    typeof probe.user_id === 'string' && typeof probe.screen_name === 'string';\n}","tryCatchPattern":"try {\n  const identity = await verifyJimengIdentity(page);\n} catch (err) {\n  if (/Unexpected Jimeng probe/.test(err.message)) {\n    const raw = err.message.slice('Unexpected Jimeng probe: '.length);\n    console.error('Probe contract mismatch:', JSON.parse(raw)); // diagnose and update WHOAMI_PROBE\n  }\n  throw err;\n}","preventionTips":["Validate probe shape (ok, user_id, screen_name) before trusting it","Update WHOAMI_PROBE whenever Jimeng changes its whoami response","Ensure page.evaluate return values are serializable","Watch for Jimeng A/B/regional response variants"],"tags":["invariant","contract-violation","jimeng","browser-automation"],"backgroundTag":"unexpected-response-shape","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}