Skip to content

feat(server-picker): probe ObjectOS discovery and confirm the server before connecting - #165

Merged
os-zhuang merged 6 commits into
mainfrom
claude/issue-154-server-probe-confirm
Nov 2, 2026
Merged

os-zhuang merged 6 commits into
mainfrom
claude/issue-154-server-probe-confirm

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Fixes #154

Clause-②: no
Metadata-protocol: none

维护者速读

  • 改了什么: 服务器选择页不再只探 /api/v1/health,而是读平台的三个匿名接口,判断"这是不是 ObjectOS 服务器、是哪一台",然后进入新的确认页(Logo 或品牌色首字母、产品名、完整地址、HTTPS 锁、登录方式、平台版本);用户点「连接并登录」才保存服务器。
  • 为什么改: 旧探测对任何能回 200 的网站都放行,用户填错地址也会被"连上";现在填错的地址会明确说「这不是 ObjectOS 服务器」,证书错误、超时、无法访问(含 VPN 提示)各有独立文案。
  • 风险与回滚: 只动服务器选择流程;已保存服务器的用户不受影响。证书错误的识别依赖 iOS/Android 原生错误文字,若某机型的文字没被识别,会退化为"无法连接"的提示,不会误连。回滚即 revert 本 PR。
  • 先看: lib/server-probe.ts(probeServer 判定顺序与 xhrFetch)、app/server-config.tsx(runProbe / handleConfirm,保存只在确认后)、components/shell/ServerConfirm.tsx。
  • 两分钟验证: npx jest --ci __tests__/lib/server-probe.test.ts __tests__/components ,预期 4 个文件全过,含 TLS、404、超时、重定向、部分失败各用例。
  • 需要你做的: 在真机上各连一次:自己的私有服务器(应出确认页,信息正确)、证书无效的服务器(应提示「证书无效」)、一个非 ObjectOS 的 https 网站(应提示「这不是 ObjectOS 服务器」)。

What changes

  • lib/server-probe.ts (new, pure, injected fetch). probeServer(input, { fetch, allowInsecure, timeoutMs }) normalizes the typed address (normalizeServerUrl, so the https rule and pasted Console links behave as before), then:
    • GET /.well-known/objectstack decides "is this ObjectOS": it must be the { success: true, data } envelope with data.name, data.version and a data.routes object. A 4xx or any other body is not-objectos; a 5xx is server-error.
    • Discovery's redirect is adopted with serverUrlAfterRedirect (apex to www, http to https). A redirect onto plain http to a public host is refused as insecure-http.
    • GET /api/v1/runtime/config (branding.productName, branding.logoUrl, branding.brandColor) and GET /api/v1/auth/config (data.emailPassword, data.socialProviders, data.features.sso, data.features.ssoEnforced) run in parallel and are best-effort: when either fails, the result is still ok, with no branding (initial on the default colour) or no sign-in row.
    • The result is a discriminated union: ok, empty, invalid, insecure-http, unreachable, tls, timeout, not-objectos, server-error. Each failure maps 1:1 to its own copy key.
    • All requests are anonymous: credentials: "omit", no cookie, no credential.
  • xhrFetch (same module). React Native's fetch (whatwg-fetch 3.6.20 over XHR) rejects every transport failure with the same TypeError: Network request failed, so a certificate error cannot be told from an unreachable host. RN's XMLHttpRequest keeps the native error text in responseText on failure (Libraries/Network/XMLHttpRequest.js, __didCompleteResponse). xhrFetch rejects with that text, and the probe classifies the iOS NSURLErrorDomain and Android javax.net.ssl / java.security.cert wordings as tls.
  • Confirm step (screen 7), components/shell/ServerConfirm.tsx. It shows the logo (falling back to the initial on the brand colour when there is no logo or it fails to load), the product name, the full URL, a lock row only for https, the sign-in methods, and the platform name and version. Actions: 连接并登录 / 不是这台服务器. Android back counts as "not this server".
  • Address step (screen 5), app/server-config.tsx. The screen runs the probe and only then shows the confirm step. The server is saved only in handleConfirm. A probe that finishes after the address was edited is ignored. New copy: "在哪里找到地址?" steps and the VPN hint.
  • lib/server-url.ts. resolveServerUrl and validateServerUrl are deleted, along with their tests; the persistence functions stay. stores/server-store.ts is unchanged: the save was already only in connect, which is now called only from the confirm step.
  • Locales en / zh / ar: new serverConfig.* and serverConfirm.* copy, written as "ObjectOS". serverConfig.help is replaced by serverConfig.where.step3.
  • docs/HYBRID-SHELL.md: new "Server selection" section covering the probe contract, the outcomes and the transport. "makes no API calls of its own" now says "no authenticated API calls; only the anonymous probe".

Tests

All runs below are on head 49de79b.

  • npx tsc --noEmit: exit 0
  • npx eslint . --ext .ts,.tsx: exit 0
  • npx jest --ci --coverage: exit 0. Test Suites 29/29, Tests 329/329; on 8c6f13a it was 26 suites and 283 tests. lib/ coverage is 84.73% of statements (threshold 80); server-probe.ts is at 95.2%.
  • New tests:
    • __tests__/lib/server-probe.test.ts: an ObjectOS server, a non-ObjectOS 200 HTML page, JSON that is not discovery, a 404, a 5xx, a timeout, five TLS wordings, five unreachable wordings, redirect adoption, a redirect to a login page, a redirect to plain http, typed http (public and local), empty and invalid input, a pasted Console link, the partial failures (branding missing gives the initial on the default colour, branding transport failure, auth config missing, a bad colour, relative logos), SSO-only mode, a disabled provider, and xhrFetch (no credentials, final URL, native error text, abort).
    • __tests__/components/ServerConfirm.test.tsx: the confirm screen's fields, the logo fallbacks, the lock row, the sign-in row, its two actions, and Android back.
    • __tests__/components/ServerConfigScreen.test.tsx: nothing is saved before confirm, "not this server" keeps the address, each failure kind shows its own message, and a stale probe is ignored.
  • Ablation, both runs on committed code, both mutations proven on disk by ablation-replace.mjs, both restored to the HEAD blob with an empty git diff HEAD:
    • A1 (save right after a successful probe, before confirm): ServerConfigScreen.test.tsx 2 failed / 10 passed.
    • A2 (TLS classification removed): server-probe.test.ts 5 failed / 30 passed. A first attempt was refused by the tool, because the replacement text was not distinguishable on disk; it did not run, and was redone with a distinct replacement.

Acceptance notes

  • Measured producer shapes vs the card's spelling (objectstack main @ d9885f5d). Every field the card names exists. Two are nested differently from how the card writes them:
    • The branding fields are branding.productName / branding.logoUrl / branding.brandColor in a bare, non-enveloped body (packages/cloud-connection/src/runtime-config-plugin.ts:1199, sent by sendRevalidated at :308-315).
    • ssoEnforced is data.features.ssoEnforced, next to data.features.sso (packages/plugins/plugin-auth/src/auth-manager.ts getPublicConfig, served enveloped at auth-plugin.ts:3103-3110).
    • Discovery is enveloped (packages/runtime/src/dispatcher-plugin.ts:1134-1155), with name: 'ObjectOS' and version from http-dispatcher.ts:2105-2113.
    • logoUrl may be relative (its doc comment, runtime-config-plugin.ts:760). A root-relative logo resolves against the server origin; any other relative form is dropped and the initial is shown instead.
  • Screen 5 steps do not point at Console › 个人设置 › 移动应用. That page does not exist on objectstack main @ d9885f5d: grep of ui/apps/console/src finds no mobile-app settings page, and Connect by QR code: objectos://connect?server=… links and the native scanner screen #156 says an objectstack card will add it. Copy that sends users to a page that does not exist would be a misleading-copy defect. So the steps say what is true today: open ObjectOS in a browser, copy the address bar (a pasted Console link is cut to the server part), and otherwise ask the administrator. Once that page ships, this is a one-string change per locale (serverConfig.where.step1 / step2).
  • Scan button not rendered. The scanner (Connect by QR code: objectos://connect?server=… links and the native scanner screen #156) cannot do anything yet. The seam is named in the app/server-config.tsx header ("Scan entry point"): the scanner adds its button beside the address field and passes the scanned address to runProbe.
  • server-error (5xx) is an outcome beyond the suggested union. The card does not cover a 5xx on discovery. Calling it "not ObjectOS" would be wrong, and calling it "unreachable" would hide a server that did answer.
  • Discovery envelope age is unmeasured. The objectstack checkout is shallow, so this PR does not establish when the { success, data } envelope landed on /.well-known/objectstack. A deployed server older than the envelope would read as "not ObjectOS". The probe stays strict to the contract as served on main.
  • features.sso is served and classified in packages/spec/src/kernel/public-auth-features.ts:188, but GetAuthConfigResponseSchema (packages/spec/src/api/auth-endpoints.zod.ts) does not declare it. That is a read-only observation, not filed. The probe reads the served body without parsing it through that schema.
  • SVG logos. RN Image cannot render SVG. The confirm screen falls back to the initial on onError. Not device-verified.

Verification

Device checks are not verified by this PR. They are listed under 需要你做的 above: a real private server, a server with a TLS error, and a non-ObjectOS https site.

Gate readings on 49de79b
TSC_EXIT=0
ESLINT_EXIT=0
JEST_EXIT=0
Test Suites: 29 passed, 29 total
Tests:       329 passed, 329 total
 lib                    |   84.73 |    72.69 |   89.87 |   85.23 |
  server-probe.ts       |    95.2 |    87.03 |   96.15 |   97.24 | 340,371-372
os-verify-lock: VERDICT command-exit 0
Ablation readings
A1  ok mutation landed: anchor 1 -> 0, blob 491eb9d71b85 -> c1fe448443df
    Tests: 2 failed, 10 passed, 12 total
    ok restored: blob == HEAD (491eb9d71b85) and `git diff HEAD` is empty
A2b ok mutation landed: anchor 1 -> 0, blob 789cd23b53ab -> 9647dccbbb6c
    Tests: 5 failed, 30 passed, 35 total
    ok restored: blob == HEAD (789cd23b53ab) and `git diff HEAD` is empty

Generated by Claude Code

…ving it

Replace the /api/v1/health probe with lib/server-probe.ts, which reads the
anonymous discovery, runtime-config and auth-config endpoints, and add the
confirm step: nothing is saved until the user confirms.

Claude-Session: https://claude.ai/code/session_01QSeKYnW1Xf6HDSWz1eGAqv
Co-authored-by: Claude <noreply@anthropic.com>
…d the save-on-confirm flow

Claude-Session: https://claude.ai/code/session_01QSeKYnW1Xf6HDSWz1eGAqv
Co-authored-by: Claude <noreply@anthropic.com>
…be-confirm

Conflicts: locales/{en,zh,ar}.json serverConfig.subtitle only; kept this
branch's rewritten subtitle, which already says ObjectOS.

Claude-Session: https://claude.ai/code/session_01QSeKYnW1Xf6HDSWz1eGAqv
Co-authored-by: Claude <noreply@anthropic.com>
…ll warm-up

The first render of the picker requires and babel-transforms react-native's
lazily exported components (Text, ScrollView, Image, ...). On a cold transform
cache that cost about 3.7-4.0 s locally, landed inside the first test, and
exceeded the 5 s timeout on CI. Render once in beforeAll under its own
timeout instead.

Claude-Session: https://claude.ai/code/session_01QSeKYnW1Xf6HDSWz1eGAqv
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:mobile#1 · os-justin · session_01QSeKYnW1Xf6HDSWz1eGAqv

Seat verdict: ACCEPT — Head-sha: a93d7cbfb7c77d2a3c16d9b3e0382bdc257aa681

维护者速读

  • 改了什么: 填服务器地址后,App 不再只探 /api/v1/health,而是读平台的三个匿名接口(发现、品牌、登录配置),判断「是不是 ObjectOS、是哪一台」。然后进入新确认页:Logo 或品牌色首字母、名称、完整地址、HTTPS 锁、登录方式、版本。用户点「连接并登录」才保存。
  • 为什么改: 旧探测对任何回 200 的网站都放行,填错地址也会「连上」。现在会明确提示「这不是 ObjectOS 服务器」,证书无效、超时、无法访问(含 VPN 提示)、服务器 5xx 各有独立文案。
  • 风险与回滚: 只动服务器选择流程,已保存服务器的用户不受影响。证书错误靠原生错误文字识别,没识别出的机型会退化成「无法连接」,不会误连。回滚就是 revert 本 PR。
  • 先看: lib/server-probe.ts(判定顺序与 xhrFetch)→ app/server-config.tsx 的 handleConfirm(唯一保存点)→ components/shell/ServerConfirm.tsx。
  • 两分钟验证: 运行 npx jest --ci __tests__/lib/server-probe.test.ts __tests__/components,各种探测结果都有用例。
  • 需要你做的: ① 真机各连一次:你的私有服务器(应出确认页且信息正确)、证书无效的服务器(应提示「证书无效」)、一个非 ObjectOS 的 https 网站(应提示「这不是 ObjectOS 服务器」)。本 PR 未上真机。② 审批并合并。合入 main 会触发 EAS,所以合并只归你。

席位意见: 范围与卡面一致。保存点只有确认后一处,有测试钉住,消融实测可证伪。有一处契约措辞请你知道:docs/HYBRID-SHELL.md 的「壳不自己调 API」改为「不发带凭据的 API 请求,只有匿名探测」。旧代码本就会匿名探 /api/v1/health,探测本身也是卡面要求的,所以席位接受。但车道章程(objectstack 里的 lanes/mobile.md)的「不调平台 API」这一句随之不准确,改不改由你定。建议合并。

席位核对

  1. Shape: draft → main. The first line is Fixes #154, and no other closing keyword sits next to an open card. Clause-②: no and Metadata-protocol: none are in the body and the changeset. .changeset/154-server-probe-confirm.md is "mobile": minor. The body's Tests section is pinned to 49de79b (329 tests). The current-head readings are row 3; the head moved only by a merge of main and a test-scaffold commit.
  2. Premise, measured:
  3. Gates, check-runs pinned to head a93d7cb: Code Quality success; Lint & Type Check success. mergeable_state is clean.
    • Head e3a7384 was red: ServerConfigScreen.test.tsx:61 exceeded the 5 s timeout (run 41445036323).
    • Measured root cause: React Native components are lazy getters, and their cold babel transform (~4.8 s) was paid inside the first test.
    • Fix: a beforeAll warm-up render under its own 30 s budget. No test was skipped or weakened, and the per-test timeout is unchanged.
    • Cold first-test time: 3701 / 3970 ms before, 40 / 43 ms after.
  4. Accepted deviations:
  5. Out of scope:
  6. Landing: path surface NOT governed (check-governed-merges --pr objectstack-ai/mobile#165: 0 of 13), +1503 / −210 ≤ 3000. Merging to main is a release action here (lane charter), so the maintainer merges. The seat marks the PR ready and requests review, with no auto-merge.

@objectstack-fleet objectstack-fleet Bot added the needs-user-decision Blocked on a maintainer decision — do not dispatch; decision cards only, never on a PR label Nov 2, 2026
@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 2, 2026 12:34
@os-zhuang
os-zhuang merged commit 83d4716 into main Nov 2, 2026
2 checks passed
os-justin pushed a commit that referenced this pull request Nov 2, 2026
Resolves the docs/HYBRID-SHELL.md Testing-list conflict with #165: both
entries kept (the server probe and picker tests, and the load state machine
test). #165's Server selection section, Session-and-auth wording and Layout
entries merged cleanly beside this branch's Load states and Safe area sections.

Claude-Session: https://claude.ai/code/session_01QSeKYnW1Xf6HDSWz1eGAqv
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet objectstack-fleet Bot removed the needs-user-decision Blocked on a maintainer decision — do not dispatch; decision cards only, never on a PR label Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Private servers: probe with the anonymous discovery endpoints and confirm the server's identity before connecting

2 participants