Skip to content

feat(api): a coded message type, and the link test speaks it - #53

Merged
fylorn merged 1 commit into
mainfrom
i18n/messages
Sep 20, 2026
Merged

fylorn merged 1 commit into
mainfrom
i18n/messages

Conversation

@fylorn

@fylorn fylorn commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Core sends the desktop app sentences to display. The app ships in Simplified
Chinese and English, so a sentence written here can only be right in one of
them — and this process serves the CLI and the server edition too, neither of
which has an interface language to consult.

tw_types::Msg is what goes over the wire instead: a stable code, the arguments
that fill the sentence, and the English text with those arguments already in it.
The app looks the code up in its own dictionary; a code it does not know (core
newer than the app, or a third-party client with no dictionary at all) falls
back to the English, which beats showing a bare identifier. The code is the
contract and the sentence is not
, so rewording costs nothing and only a change
of meaning takes a new code.

msg! builds one, binding the arguments before the format string so the
sentence and the argument map cannot drift apart:

msg!("l1.dns.no_records", host = host => "{host} resolved, but to no addresses.")

Why the link test went first

It is the surface that shows why the codes matter: it was comparing Chinese
sentences to make decisions.

if e == timed_out() { /* DNS timeout */ } else { /* DNS failure */ }

tcp_message asked the same question a second time. Both were one reworded
character away from reporting the wrong cause, with no test and no compile error
to catch it. They compare Msg::code now.

Also here

  • L1Result.error is a Msg, and the two Stage / SkipReason labels are
    English — they were already documented as CLI-only, so the app loses nothing.
  • Event::ProxyChanged gains failed: Option<L1Stage>, and its detail is a
    Msg. It used to ship "TCP 握手:{why}" as one string, so an app that wanted
    to phrase it differently had to take a sentence apart at a colon.
  • twcore speed prints English; its segment column widens from 18 to 28 to fit
    "TLS handshake to the proxy".
  • The tests that asserted on Chinese substrings assert on codes instead.

Not in this change

tw_control::fail still collapses a Msg to its text for HTTP error bodies, so
the 400 from /proxies/test loses the code. That is the control plane's own
error envelope and it changes with the rest of tw-control.

Verified

cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace (78 suites, 0 failures) and
./scripts/smoke.sh (51 passed, 0 failed) all green. The two new tests in
tw-types cover the argument map and that an empty one stays off the wire; the
four L1 tests that read error text now read codes.

🤖 Generated with Claude Code

Core sends the desktop app sentences to display. The app ships in
Simplified Chinese and English, so a sentence written here can only be
right in one of them — and this process serves the CLI and the server
edition too, neither of which has an interface language to consult.

`tw_types::Msg` is what goes over the wire instead: a stable code, the
arguments that fill the sentence, and the English text with those
arguments already in it. The app looks the code up in its own
dictionary; a code it does not know (core newer than the app, or a
third-party client with no dictionary at all) falls back to the English,
which beats showing a bare identifier. The code is the contract and the
sentence is not, so rewording costs nothing and only a change of meaning
takes a new code.

`msg!` builds one, binding the arguments before the format string so the
sentence and the argument map cannot drift apart:

    msg!("l1.dns.no_records", host = host => "{host} resolved, but to no addresses.")

The link test is the first surface converted, and the one that shows why
the codes matter: it was comparing Chinese sentences to make decisions.
`resolve` asked `if e == timed_out()` to tell a DNS timeout from a DNS
failure, and `tcp_message` asked the same question a second time — both
one reworded character away from reporting the wrong thing, with nothing
to catch it. They compare `Msg::code` now.

Also here:

- `L1Result.error` and the two L1 `Stage`/`SkipReason` labels are
  English; the labels were already documented as CLI-only, so the app
  loses nothing.
- `Event::ProxyChanged` gains `failed: Option<L1Stage>` and its `detail`
  becomes a `Msg`. It used to ship `"TCP 握手:{why}"` as one string, so
  an app wanting to say it differently had to parse a sentence apart at
  a colon.
- `twcore speed` prints English, and its segment column widens from 18
  to 28 for "TLS handshake to the proxy".
- The tests that asserted on Chinese substrings assert on codes.

Not in this change: `tw_control::fail` still collapses a `Msg` to its
text for HTTP error bodies, so the `/proxies/test` 400 path loses the
code. That is the control plane's own error envelope, and it changes
with the rest of `tw-control`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@fylorn
fylorn merged commit 86a7fac into main Sep 20, 2026
1 check passed
@fylorn
fylorn deleted the i18n/messages branch September 20, 2026 05:17
@fylorn fylorn mentioned this pull request Sep 20, 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.

1 participant