Skip to content

feat(chat): implement Chat::register_bot in the shared Rust core - #430

Merged
TarikGul merged 9 commits into
mainfrom
feat/chat-register-bot
Aug 18, 2026
Merged

feat(chat): implement Chat::register_bot in the shared Rust core#430
TarikGul merged 9 commits into
mainfrom
feat/chat-register-bot

Conversation

@decrypto21

@decrypto21 decrypto21 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • serve chat.registerBot from the shared core through a ChatPlatform::register_bot hook, reaching native storage via NativeChatCallbacks and the Swift ChatHostBridge
  • validate product-supplied chat ids, names and icons centrally on create_room and register_bot, and normalize post_message's room id to the same form
  • answer CallError::Unsupported from all nine CoinPayment methods rather than inheriting the trait default's HostFailure
  • pin the register_bot request bytes and status discriminants against the reference JS host's own codec
  • derive the Chat diagnosis method list from the generated service metadata, run the playground unit tests in CI, and render a generated-but-unmeasured method as a gap in the explorer compatibility matrix
  • record that a WASM/JS host cannot install a ChatPlatform, so executionKind: "Chat" there answers unsupported and its subscriptions end empty

register_bot reserves wire id 40 and is present in the generated dispatcher, the wire table and the published TS types, so the wire surface is unchanged by this PR — it converts a runtime unavailable into a real answer.

Chat coverage after this change

All six product-initiated Chat methods reach an implementation. The native adapter persists Text and Custom message content; the remaining five ChatMessageContent variants report a domain error, which a test pins so the ceiling is explicit rather than incidental. Worth naming: action_subscribe delivers ActionTriggered while Actions is one of the rejected variants, so a product can receive action triggers it cannot yet produce.

Field validation

create_room and register_bot bound their ids, names and icons, NFC-normalize them, and screen characters that let two distinct values render identically. Identifiers are screened harder than display names: a name keeps ZWJ and ZWNJ because emoji sequences and Persian need them, while an identifier rejects those plus variation selectors, soft hyphens, invisible operators and non-ASCII spaces. Icons are an allowlist — https, or an inline raster image — because a URL parser reaches a scheme through whitespace, tabs and NUL that a prefix comparison does not.

Contextual output escaping, storage limits, and every post_message field remain host-owned.

ChatHostBridge.registerBot is a required member

There is no protocol-extension default: a host either implements bot registration or fails to compile. A default that reported "unavailable" would land as an untyped Unknown{reason} — indistinguishable from a genuine failure, and the same additive-blind shape this change set exists to remove. StubChatHostBridge in the test target writes out every member, which is what makes the ios-swift job a gate.

Downstream needs one method. polkadot-app-ios-v2 has a live conformer on develop at polkadot-app/Modules/Products/TrUAPI/RustChatExecutionBridge.swift, implementing the four existing members. It needs a registerBot following the notImplemented(#function) pattern already in that file. The ios-swift job compiles only this repo's package, so CI here cannot see that break.

Validation

  • cargo test --workspace --all-features — 914 tests
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo +nightly fmt --check
  • cargo check --target wasm32-unknown-unknown -p truapi-server
  • ./scripts/codegen.sh with no tracked-file drift; make uniffi reproduces the committed bindings byte-for-byte
  • @parity/truapi 225 tests, @parity/truapi-host 49 tests; playground yarn test:unit, yarn lint, yarn build; explorer npm run lint

The Swift compile is covered by CI rather than locally: the TRUAPIProvider
product added in #276 resolves an unpublished @parity/ios-provider release
asset, so xcodebuild needs both TRUAPI_USE_LOCAL_BINARY=1 and
TRUAPI_PROVIDER_USE_LOCAL_BINARY=1 with both xcframeworks built first, which is
what the iOS package (swift compile) job does.

Each new assertion was mutation-checked against the defect it guards: removing the impl reproduces unavailable; swallowing a host rejection into a fabricated New fails; collapsing a field rejection into Unsupported fails; dropping post_message normalization orphans the room and fails; reordering bot_id/name fails the wire fixture; deleting a CoinPayment override restores HostFailure and fails; a spurious room-list republish fails rather than hanging.

Notes

Registering a bot does not republish the room list — list_rooms reports rooms, and a bot identity is not a room. A host that joins a bot to a room signals that through notify_chat_rooms_changed.

@decrypto21
decrypto21 requested a review from a team August 17, 2026 19:45
@TarikGul

Copy link
Copy Markdown
Member

Shared findings with @decrypto21 offline.

@decrypto21
decrypto21 force-pushed the feat/chat-register-bot branch from a59a6b2 to 356e9b9 Compare August 18, 2026 08:02
@TarikGul
TarikGul added this pull request to the merge queue Aug 18, 2026
Merged via the queue into main with commit 28e9e77 Aug 18, 2026
19 checks passed
@TarikGul
TarikGul deleted the feat/chat-register-bot branch August 18, 2026 20:32
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.

2 participants