Files
infrastructure/openspec/specs/terminal-telegram-client/spec.md
T

132 lines
5.5 KiB
Markdown

# terminal-telegram-client Specification
## Purpose
Терминальный клиент Telegram на bigbox: где он установлен и как обновляется,
какие системные библиотеки ему нужны, как проверяется подлинность релиза и
как он ходит в Telegram через SOCKS5-туннель, потому что прямой MTProto с
этого хоста заблокирован.
## Requirements
### Requirement: Service Directory Layout
The terminal Telegram client MUST be installed under `/opt/tuigram` with the
binary at `/opt/tuigram/bin/tuigram` and MUST be reachable as `tuigram` from
`PATH` via the symlink `/usr/local/bin/tuigram`.
#### Scenario: Binary and symlink present
- GIVEN the change is applied
- WHEN running `ls -l /opt/tuigram/bin/tuigram /usr/local/bin/tuigram`
- THEN `/opt/tuigram/bin/tuigram` is an executable regular file
- AND `/usr/local/bin/tuigram` is a symlink pointing to it
#### Scenario: Version reported
- GIVEN the client is installed
- WHEN running `tuigram --version`
- THEN it prints the installed version (e.g. `tuigram 1.8.1`)
- AND exits with status 0
### Requirement: Runtime Libraries
The system MUST provide the C++ runtime the release binary links against, so
that the client starts without `error while loading shared libraries`.
#### Scenario: No missing shared objects
- GIVEN the client binary is installed
- WHEN running `ldd /opt/tuigram/bin/tuigram`
- THEN no line contains `not found`
- AND `libc++.so.1`, `libc++abi.so.1`, `libunwind.so.1` resolve to system paths
### Requirement: Verified Release Artifacts
Installation and update MUST use the upstream GitHub release asset for
`x86_64-unknown-linux-gnu` and MUST verify its SHA256 against the release's
`SHA256SUMS` before the binary is replaced.
#### Scenario: Checksum matches
- GIVEN the release tarball and `SHA256SUMS` were downloaded
- WHEN the installer compares the digest
- THEN a match installs the new binary atomically (`mv` over the old one)
- AND `VERSION` records the release tag
#### Scenario: Checksum mismatch or missing entry
- GIVEN the downloaded tarball has a different digest, or its name is absent
from `SHA256SUMS`
- WHEN the installer runs
- THEN it exits non-zero and leaves the existing binary untouched
### Requirement: Proxy Preset Before First Login
The client MUST default to the SOCKS5 tunnel that leaves the country
(`127.0.0.1:1082` → vps03) before the first login, because direct MTProto to
Telegram datacenters is blocked from this host and a tunnel that egresses from
the same network as the host does not bypass the block.
#### Scenario: Settings file carries the proxy
- GIVEN `~/.local/share/tuigram/settings.toml` does not exist yet
- WHEN the proxy preset is applied
- THEN the file contains `proxy = "socks5://127.0.0.1:1082"`
- AND an existing file is not overwritten without an explicit decision
#### Scenario: Proxy path is reachable
- GIVEN `telegram-tunnel-vps03.service` is active
- WHEN opening a TCP connection to `149.154.175.50:443` through
`127.0.0.1:1082`
- THEN the connection succeeds
- AND `tdlib.log` records an `auth_key_id` for the main datacenter, i.e. the
MTProto handshake actually completed through the tunnel
- AND the same connection attempted directly fails, confirming the proxy is
required rather than optional
#### Scenario: Egress differs from the host's own address
- GIVEN the tunnel is up
- WHEN querying `https://ifconfig.me` through `127.0.0.1:1082`
- THEN the reported address is `77.67.89.154` (vps03)
- AND it differs from the address seen without a proxy, which is the condition
that makes the tunnel useful at all
#### Scenario: One-off override
- GIVEN the preset points at `127.0.0.1:1082`
- WHEN the client is started as `TG_PROXY=socks5://host:port tuigram`
- THEN the environment value takes precedence over the saved setting
#### Scenario: MTProto proxy links are not a substitute
- GIVEN a working MTProto proxy reachable from the host
- WHEN it is supplied as a `t.me/proxy` link through `settings.toml` or
`TG_PROXY`
- THEN tuigram 1.8.1 MUST NOT be assumed to use it: the observed behaviour is a
direct connection attempt to the datacenter, so the SOCKS5 preset stays the
supported path
### Requirement: Operators' Documentation
`/opt/tuigram/README.md` MUST document the installed version, how to update
and roll back, the proxy setting, and where user data lives.
#### Scenario: Documented facts match reality
- GIVEN the README exists
- WHEN comparing it to the installed artifacts
- THEN the documented version equals `/opt/tuigram/VERSION`
- AND the documented data directory equals the path printed by `tuigram --help`
### Requirement: Dedicated Egress Tunnel
The host MUST run a dedicated SOCKS5 tunnel to vps03 for the terminal Telegram
client, independent of tunnels serving other tools.
#### Scenario: Unit is enabled and listening on localhost only
- GIVEN the host boots
- WHEN systemd starts `telegram-tunnel-vps03.service`
- THEN it listens on `127.0.0.1:1082` and not on wildcard addresses
- AND the unit is enabled in `multi-user.target.wants`
#### Scenario: Tunnel dies
- GIVEN the SSH process exits unexpectedly
- WHEN systemd detects the failure
- THEN the service restarts automatically (`Restart=always`, `RestartSec=10`)
#### Scenario: Existing tunnels are untouched
- GIVEN `telegram-tunnel.service` (vps01, `127.0.0.1:1080`) serves other tasks
- WHEN the vps03 tunnel is added or restarted
- THEN the vps01 tunnel keeps running and its port binding is unchanged