cybertrain 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +188 -15
- data/cybertrain/cli/templates.rb +1 -1
- data/cybertrain/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f99f1622d743b5ddb5c97dfa005c843edbd73f710e1845db610eb9fa7a218847
|
|
4
|
+
data.tar.gz: fd1084a610c66561e7d9a0711476dfcbd1a53967362012826be0c614c3fb380b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ac8d21b2ab8a2b151a0578dde0d4e251a6e6b3062f3ce449ea28a821524a390428d4c174e126a63ae222e8a8dc94a31121d89a848af80471db5a703b55c1ea78
|
|
7
|
+
data.tar.gz: b28353d7e9d165337e1fa26b1907e4370e4a169e13a7541b5246fa5f8be3f00e9bb80c0ab1795771e4c7b4f3bf248ef7bef4234ff465ac67a48ef3a10597db1a
|
data/README.md
CHANGED
|
@@ -34,7 +34,9 @@ with comments) built on it, exercised by CI on Linux and macOS.
|
|
|
34
34
|
`cybertrain generate authentication` adds email-and-password sign-in the way
|
|
35
35
|
Rails 8's generator does, and `cybertrain generate attachment` (or a
|
|
36
36
|
`cover:attachment` scaffold field) adds a file upload to a model. `Cybertrain::Mailer` sends plain-text e-mail over SMTP
|
|
37
|
-
(see "Sending e-mail")
|
|
37
|
+
(see "Sending e-mail"), and `Cybertrain::WebSocket.subscribe` keeps a connection to an outside
|
|
38
|
+
WebSocket feed open while the server runs (see "Consuming WebSocket feeds"). Not built: Action Mailer-style
|
|
39
|
+
mailer classes and templates, a WebSocket server (ActionCable),
|
|
38
40
|
an asset pipeline, i18n, and anything beyond a minimal `render json:` — see
|
|
39
41
|
"Differences from Rails" below.
|
|
40
42
|
|
|
@@ -42,7 +44,7 @@ an asset pipeline, i18n, and anything beyond a minimal `render json:` — see
|
|
|
42
44
|
|
|
43
45
|
[Open the playground in GitHub Codespaces](https://codespaces.new/saeki-mototsune/CyberTrain?quickstart=1)
|
|
44
46
|
to try cybertrain without installing anything: VS Code opens in your browser with
|
|
45
|
-
Spinel 2026.10.
|
|
47
|
+
Spinel 2026.10.27.7020, the `cybertrain` CLI and the blog from the walkthrough below
|
|
46
48
|
already created (`cybertrain new blog`, the article scaffold, the root route and
|
|
47
49
|
the first migration, built once so the server starts without compiling), its
|
|
48
50
|
development server running in a terminal and the app, showing the article list,
|
|
@@ -76,7 +78,7 @@ works there with no network.
|
|
|
76
78
|
|
|
77
79
|
## Requirements
|
|
78
80
|
|
|
79
|
-
- Spinel `2026.10.
|
|
81
|
+
- Spinel `2026.10.27.7020` (`Cybertrain::SPINEL_TAG`, the same release as
|
|
80
82
|
`SPINEL_TAG` in [.github/workflows/ci.yml](.github/workflows/ci.yml)), a
|
|
81
83
|
release of [saeki-mototsune/spinel](https://github.com/saeki-mototsune/spinel)
|
|
82
84
|
(`Cybertrain::SPINEL_REPOSITORY`), the fork of matz/spinel that carries
|
|
@@ -177,7 +179,7 @@ commands (`cybertrain help` prints them):
|
|
|
177
179
|
`dist/` (the binary, `public/`, `storage/`, `tmp/`).
|
|
178
180
|
- `cybertrain spin ARGS...` runs `spin` with the pinned Spinel from any
|
|
179
181
|
directory (`cybertrain spin test`, `cybertrain spin run gen -- --check`).
|
|
180
|
-
- `cybertrain setup [--force]` installs Spinel `2026.10.
|
|
182
|
+
- `cybertrain setup [--force]` installs Spinel `2026.10.27.7020` into
|
|
181
183
|
`~/.cybertrain` unless a `spinel` of that release is already on `PATH`;
|
|
182
184
|
`--force` rebuilds the copy under `~/.cybertrain`.
|
|
183
185
|
- `cybertrain doctor` checks the C toolchain, the SQLite headers and the
|
|
@@ -191,11 +193,11 @@ Every command that runs `spin` (`new`, `db`, `server`, `build`, `spin`) first ma
|
|
|
191
193
|
sure a Spinel of the release in `Cybertrain::SPINEL_TAG` is available. A
|
|
192
194
|
`spinel` on `PATH` (with a `spin`) whose `spinel --version` reports that
|
|
193
195
|
release is used as it is; otherwise the copy `cybertrain` keeps under
|
|
194
|
-
`~/.cybertrain/spinel/2026.10.
|
|
196
|
+
`~/.cybertrain/spinel/2026.10.27.7020/` is used; otherwise `cybertrain`
|
|
195
197
|
builds that copy from the release tag of `Cybertrain::SPINEL_REPOSITORY`
|
|
196
198
|
(`git clone`, `make deps`, `make -j`, `make install PREFIX=...`), once, in a
|
|
197
199
|
few minutes. The build log is
|
|
198
|
-
`~/.cybertrain/log/spinel-2026.10.
|
|
200
|
+
`~/.cybertrain/log/spinel-2026.10.27.7020-build.log` (its last lines are printed
|
|
199
201
|
if a step fails); if a tool the build needs is missing, `cybertrain` says
|
|
200
202
|
which and prints the install command for your platform before it starts. A
|
|
201
203
|
`spinel` of another release on `PATH` is never used or touched:
|
|
@@ -220,7 +222,7 @@ if they are not that release.
|
|
|
220
222
|
|
|
221
223
|
`cybertrain new` writes the application with its `spin.toml` pointing at
|
|
222
224
|
the release matching the CLI (`cybertrain = { git =
|
|
223
|
-
"https://github.com/saeki-mototsune/cybertrain", ref = "v0.3.
|
|
225
|
+
"https://github.com/saeki-mototsune/cybertrain", ref = "v0.3.1" }`), makes
|
|
224
226
|
sure Spinel is installed, then runs `spin lock` (spin fetches the framework
|
|
225
227
|
into its cache, `~/.cache/spin/packages/`, and pins the commit in
|
|
226
228
|
`spin.lock`) and `spin run gen`, much as `rails new` runs `bundle install`,
|
|
@@ -677,7 +679,7 @@ hand-written sign-in):
|
|
|
677
679
|
- `dummy_digest` is a digest of a random password, made once per process
|
|
678
680
|
at the current cost. Verify against it when the address is unknown, so
|
|
679
681
|
the response time does not tell which addresses have accounts:
|
|
680
|
-
`Password.verify_serialized(password, user.nil? ? Password.dummy_digest : user.password_digest)`.
|
|
682
|
+
`Cybertrain::Password.verify_serialized(password, user.nil? ? Cybertrain::Password.dummy_digest : user.password_digest)`.
|
|
681
683
|
- `session_key(digest)` is an HMAC of the password digest under
|
|
682
684
|
`secret_key_base`; keep it in the session at sign-in and check it with
|
|
683
685
|
`session_key_matches?(session[:password_key], user.password_digest)` on
|
|
@@ -884,8 +886,10 @@ inside a `DB.with` block (which is not a transaction) gets a second connection.
|
|
|
884
886
|
`development` (the default `CYBERTRAIN_ENV`, except in a binary from
|
|
885
887
|
`cybertrain build`) also polls `app/**/*.rb`, `config/**/*.rb`, `db/schema.rb`
|
|
886
888
|
and `gen/**/*.rb` every half second (views are excluded — the engine reloads
|
|
887
|
-
those itself — and so is `gen/views.rb`, empty in development). A change runs `spin run gen && spin build NAME` in the
|
|
888
|
-
background
|
|
889
|
+
those itself — and so is `gen/views.rb`, empty in development). A change runs `spin run gen && spin build NAME -- --incremental` in the
|
|
890
|
+
background (Spinel's incremental build, which recompiles only the C units the
|
|
891
|
+
edit changed; a Spinel release without `--incremental` rejects the flag, and the
|
|
892
|
+
loop then builds without it); success requests a restart (the same flag an external `kill -HUP`
|
|
889
893
|
sets): a monitor thread stops the listener and drains open requests, then the
|
|
890
894
|
main thread `execv`s the new binary on the same port and PID, invisible to a
|
|
891
895
|
client mid-session. A failed build keeps serving the old binary and banners the
|
|
@@ -1167,8 +1171,9 @@ Cybertrain::Job.enqueue("reminder", @order.id.to_s, run_at: Time.now + 600)
|
|
|
1167
1171
|
`SPINEL_WORKERS=1` (the default) a long query stalls every request for as
|
|
1168
1172
|
long. Batch big work (delete a thousand rows per run, enqueue one job per
|
|
1169
1173
|
item) rather than doing it in one go.
|
|
1170
|
-
- **Testing.** `Scheduler.run_due(now)` runs one tick and
|
|
1171
|
-
one job, with an epoch time you choose, so
|
|
1174
|
+
- **Testing.** `Cybertrain::Scheduler.run_due(now)` runs one tick and
|
|
1175
|
+
`Cybertrain::Job.work_one(now)` one job, with an epoch time you choose, so
|
|
1176
|
+
a test never sleeps.
|
|
1172
1177
|
|
|
1173
1178
|
There is no cron syntax, no priority or uniqueness for jobs and no mailer:
|
|
1174
1179
|
this covers "send later" and "run every N seconds" (`docs/design.md` D28).
|
|
@@ -1292,11 +1297,12 @@ configuration still polls, only shows that the process answers HTTP.
|
|
|
1292
1297
|
| `Net::HTTP`, Faraday | `Cybertrain::HttpClient` for webhooks and APIs: every wait bounded, non-public destinations refused by default, no redirects or keep-alive (see "Outbound HTTP"); Spinel's `Net::HTTP` blocks the whole server on a stalled peer |
|
|
1293
1298
|
| Action Mailer (`deliver_later`, mailer classes, views) | `Cybertrain::Mailer.deliver(to:, subject:, body:)` sends plain text over SMTP (STARTTLS, implicit TLS or plain to loopback; AUTH PLAIN; every wait bounded); no templates, HTML, attachments or queue (see "Sending e-mail") |
|
|
1294
1299
|
| Active Job, `perform_later`, `solid_queue`, recurring tasks | `Cybertrain::Job.handle(kind) { \|payload\| ... }` and `Job.enqueue(kind, payload, run_at:)` (a String payload in a `cybertrain_jobs` table, retried with backoff, then `failed`), `Cybertrain::Scheduler.every(seconds, name) { ... }`; one thread in the served process, `CYBERTRAIN_WORKER=0` elsewhere ([Background work](#background-work)) |
|
|
1300
|
+
| ActionCable client, faye-websocket, websocket-client-simple | `Cybertrain::WebSocket.subscribe(name, url).on_message { \|conn, data\| ... }` keeps a feed connected while the server runs (reconnects, pings, silence detection), `Cybertrain::WebSocket::Client` for one synchronous connection; outbound only, every wait bounded (see "Consuming WebSocket feeds") |
|
|
1295
1301
|
| `config.filter_parameters += [:passw, /\Apin\z/, ->(k, v) { ... }]` | `config.filter_parameters` is an Array of Strings matched by substring, case-insensitively (no Regexps or lambdas); it applies to the request log and the development error page ([Filtered parameters](#configuration-and-environment-variables)) |
|
|
1296
1302
|
|
|
1297
1303
|
| `get "up" => "rails/health#show"` (a route to a controller) | `GET /up` is built in and answered before the static files, the session and the router, so no `before_action` runs; it queries the database and the background worker's last tick, `200 ok` or `503` ([Operations](#operations-backups-vacuum-health-check)) |
|
|
1298
1304
|
| `bin/rails db:...` tasks for backups (none built in) | `./<app> db backup PATH` / `db backup DIR/ --keep N` (`VACUUM INTO`, mode 0600, renamed into place) and `./<app> db vacuum` |
|
|
1299
|
-
| ActionCable, asset pipeline, i18n | Not built (MVP non-goals, `docs/design.md` §2.3) |
|
|
1305
|
+
| ActionCable (the server), asset pipeline, i18n | Not built (MVP non-goals, `docs/design.md` §2.3) |
|
|
1300
1306
|
|
|
1301
1307
|
Not exhaustive — `docs/design.md` §8 ("捨てたもの") is the fuller record.
|
|
1302
1308
|
|
|
@@ -1632,6 +1638,135 @@ socket layer (`cybertrain/net/socket.rb`: bounded connect, buffered reads,
|
|
|
1632
1638
|
bounded writes) is separate from the HTTP layer so that other protocols can
|
|
1633
1639
|
use it. The design: [docs/design.md](docs/design.md) D24.
|
|
1634
1640
|
|
|
1641
|
+
## Consuming WebSocket feeds
|
|
1642
|
+
|
|
1643
|
+
An application that listens to an outside feed (market ticks, device
|
|
1644
|
+
telemetry, an event stream) while the server runs subscribes to it with
|
|
1645
|
+
`Cybertrain::WebSocket.subscribe`. Like the HTTP client it is not in
|
|
1646
|
+
`require "cybertrain"`; require it where the subscription is written, and the
|
|
1647
|
+
TLS layer too for `wss://`:
|
|
1648
|
+
|
|
1649
|
+
```ruby
|
|
1650
|
+
# config/app.rb (or a file bin/<app>.rb requires before Cybertrain::Main.run)
|
|
1651
|
+
require "json"
|
|
1652
|
+
require "cybertrain/websocket"
|
|
1653
|
+
require "cybertrain/net/tls" # only for wss://; links the system libssl
|
|
1654
|
+
|
|
1655
|
+
Cybertrain::WebSocket.subscribe("trades", ENV["FEED_URL"],
|
|
1656
|
+
headers: { "Authorization" => "Bearer #{ENV["FEED_TOKEN"]}" },
|
|
1657
|
+
stale_after: 30)
|
|
1658
|
+
.on_open { |conn| conn.send_text(JSON.generate({ "op" => "subscribe", "channel" => "trades" })) }
|
|
1659
|
+
.on_message { |conn, text| Cybertrain::DB.with { |c| c.execute("INSERT INTO trades(raw) VALUES (?)", [text]) } }
|
|
1660
|
+
```
|
|
1661
|
+
|
|
1662
|
+
Requiring `cybertrain/websocket` registers the feeds with
|
|
1663
|
+
`Cybertrain::Background`, which `Application#serve` starts after the
|
|
1664
|
+
scheduler and stops at shutdown, so there is nothing to call. Each
|
|
1665
|
+
subscription gets one thread. It connects, runs `on_open` (send your
|
|
1666
|
+
subscribe message there: it runs again after every reconnect), then hands
|
|
1667
|
+
each message to `on_message` with the `Connection` (`send_text`,
|
|
1668
|
+
`send_binary`, `close`, and `last_opcode`, `:text` or `:binary`). The
|
|
1669
|
+
blocks take their arguments and cannot use `self` (Spinel has no
|
|
1670
|
+
`instance_eval`).
|
|
1671
|
+
|
|
1672
|
+
- **When it runs.** The feeds start when the binary serves, like the
|
|
1673
|
+
scheduler ([Background work](#background-work)); `migrate`, `db ...`,
|
|
1674
|
+
`Main.command` commands and `Cybertrain::Test::Client` never start them.
|
|
1675
|
+
With `CYBERTRAIN_WORKER=0` (`config.worker = false`) they do not run in
|
|
1676
|
+
that process (they simply do not start; the only notice is the
|
|
1677
|
+
scheduler's "run elsewhere" line, and `WebSocket.start!` called directly
|
|
1678
|
+
logs its own): turn it off in all but one when
|
|
1679
|
+
several processes serve, or each one receives the whole feed.
|
|
1680
|
+
`subscribe` must be called before the server starts; there is no adding or
|
|
1681
|
+
removing a feed while it runs. A name is unique (`ArgumentError`), and a
|
|
1682
|
+
feed without `on_message` fails the boot before the port is bound
|
|
1683
|
+
(`error: WebSocket subscription "trades" has no on_message`, exit 1).
|
|
1684
|
+
- **Options.** `headers:` (extra handshake headers), `timeout:` (5 seconds
|
|
1685
|
+
per wait while connecting and per write), `max_message:` (1 MiB; a larger
|
|
1686
|
+
message closes the connection with 1009), `ping_interval:` (15) and
|
|
1687
|
+
`stale_after:` (45), and `allow_private:` (as `HttpClient`, below).
|
|
1688
|
+
- **Waiting and reconnecting.** After any failure the thread waits
|
|
1689
|
+
`min(60, 2 ** (attempt - 1))` seconds, with 20 % of jitter either way: 1, 2,
|
|
1690
|
+
4, ... 60. A connection that lasted 60 seconds starts again from 1. Every
|
|
1691
|
+
wait is bounded. `WebSocket.stop!` returns within about 2 seconds
|
|
1692
|
+
whatever the servers do: it waits at most 2 seconds for all the threads
|
|
1693
|
+
together, a connected feed sends a close (1000) and waits at most 1 second
|
|
1694
|
+
for the server's answer, and every feed's `connected?` is false once it
|
|
1695
|
+
returns (a thread still closing finishes on its own).
|
|
1696
|
+
- **Silence.** A feed can go quiet without ever closing the connection, so
|
|
1697
|
+
the thread pings after `ping_interval` seconds without any frame (and then
|
|
1698
|
+
once per interval), and when no frame at all, a pong included, has arrived
|
|
1699
|
+
for `stale_after` seconds it closes the connection and reconnects.
|
|
1700
|
+
`stale_after` must be more than `ping_interval`, which must be at least 1
|
|
1701
|
+
(`ArgumentError` from `subscribe`).
|
|
1702
|
+
- **Errors in your blocks.** An exception in `on_message` is logged and the
|
|
1703
|
+
connection stays. An exception in `on_open` is logged and the connection is
|
|
1704
|
+
closed and retried, since a feed that did not subscribe is of no use.
|
|
1705
|
+
- **What is logged.**
|
|
1706
|
+
|
|
1707
|
+
| When | Level | Line |
|
|
1708
|
+
| --- | --- | --- |
|
|
1709
|
+
| start | INFO | `WebSocket started: trades (wss://feed.example.com:443)` |
|
|
1710
|
+
| connected | INFO | `WebSocket "trades" connected to feed.example.com:443` |
|
|
1711
|
+
| disconnected | WARN | `WebSocket "trades" disconnected: Cybertrain::WebSocket::ClosedError: feed.example.com:443: closed by the server (1001) (retry in 2s)` |
|
|
1712
|
+
| silent | WARN | `WebSocket "trades" silent for 45s; reconnecting` |
|
|
1713
|
+
| a block raised | ERROR | `WebSocket "trades" on_message failed: KeyError: ...` (or `on_open`) |
|
|
1714
|
+
|
|
1715
|
+
The path and the query are never logged or put in an error message: they
|
|
1716
|
+
often carry a token.
|
|
1717
|
+
- **Errors.** All are `Cybertrain::WebSocket::Error`s, with host and port
|
|
1718
|
+
only in the message. Once the handshake is done, a lost connection or a
|
|
1719
|
+
close by the server is a `ClosedError` (`close_code`, `close_reason`; a
|
|
1720
|
+
reset or an end without a close frame is 1006); a write that times out or
|
|
1721
|
+
fails in TLS is still a `TimeoutError` or `TLSError`. While connecting it
|
|
1722
|
+
is `RefusedError`, `TimeoutError`, `TLSError`, `BlockedAddressError` (a non-public address,
|
|
1723
|
+
refused by default exactly as in [Outbound HTTP](#outbound-http), with
|
|
1724
|
+
the same `allow_private:` and `http_allow_private` setting) or
|
|
1725
|
+
`HandshakeError` (not a 101, a wrong `Sec-WebSocket-Accept`, or the
|
|
1726
|
+
server answering with an extension or subprotocol). `ProtocolError`
|
|
1727
|
+
(the server broke the framing; the client sends 1002) and
|
|
1728
|
+
`TooLargeError` can come at any time.
|
|
1729
|
+
- **Health.** `Cybertrain::WebSocket.feed_status("trades")` answers a
|
|
1730
|
+
`Status`: `connected?`, `last_message_at` (epoch seconds, 0 before the
|
|
1731
|
+
first message) and `reconnects`. It is not part of `GET /up`; use it in
|
|
1732
|
+
your own check. The three are read one after the other, not as one
|
|
1733
|
+
snapshot, and `connected?` turns true when the connection is made, before
|
|
1734
|
+
`on_open` has run.
|
|
1735
|
+
- **Keep `on_message` short.** The thread waits with `wait_readable` or
|
|
1736
|
+
`sleep`, so a stalled feed does not hold an OS worker while it waits. Two
|
|
1737
|
+
things do hold one: each connect attempt resolves the host name with a
|
|
1738
|
+
blocking `getaddrinfo` (see "Name resolution blocks" in [Outbound
|
|
1739
|
+
HTTP](#outbound-http); with `SPINEL_WORKERS=1` a dead resolver stalls
|
|
1740
|
+
every request for the resolver's timeout, once per attempt per feed, and
|
|
1741
|
+
an IP address in the URL avoids the lookup), and a SQLite call inside
|
|
1742
|
+
`on_message` until it returns, as in a scheduled task ([Background
|
|
1743
|
+
work](#background-work)): with `SPINEL_WORKERS=1` a long write stalls every
|
|
1744
|
+
request. For a busy feed insert one small row, or collect messages in
|
|
1745
|
+
memory and write them in batches from a `Scheduler.every` task.
|
|
1746
|
+
- **Not built.** Extensions (`permessage-deflate`) and subprotocols are not
|
|
1747
|
+
negotiated. There is no proxy, redirect or cookie support, no automatic
|
|
1748
|
+
saving of messages, and no WebSocket server (ActionCable). Text frames are
|
|
1749
|
+
not checked for valid UTF-8 (a departure from RFC 6455 section 8.1): the
|
|
1750
|
+
bytes are passed on as they came. The `Connection` is valid only during
|
|
1751
|
+
the callback; sending from a request or a task is not supported.
|
|
1752
|
+
|
|
1753
|
+
For one connection without the reconnect loop (a script, a one-shot read)
|
|
1754
|
+
use the synchronous client:
|
|
1755
|
+
|
|
1756
|
+
```ruby
|
|
1757
|
+
require "cybertrain/websocket"
|
|
1758
|
+
require "cybertrain/net/tls" # only for wss://
|
|
1759
|
+
|
|
1760
|
+
client = Cybertrain::WebSocket::Client.connect("wss://feed.example.com/v1", timeout: 5)
|
|
1761
|
+
client.send_text("hello")
|
|
1762
|
+
msg = client.receive(10) # waits at most 10 s; nil when nothing came
|
|
1763
|
+
msg.ws_opcode # :text or :binary
|
|
1764
|
+
msg.ws_data # the bytes
|
|
1765
|
+
client.close
|
|
1766
|
+
```
|
|
1767
|
+
|
|
1768
|
+
The design: [docs/design.md](docs/design.md) D33.
|
|
1769
|
+
|
|
1635
1770
|
## Sending e-mail
|
|
1636
1771
|
|
|
1637
1772
|
`Cybertrain::Mailer` sends plain-text e-mail through an SMTP server (your
|
|
@@ -1829,6 +1964,44 @@ to call twice) ends and joins the receiver's thread and closes its port, so
|
|
|
1829
1964
|
a receiver never takes a later test's connection. They need only Ruby's
|
|
1830
1965
|
socket library, not openssl.
|
|
1831
1966
|
|
|
1967
|
+
A feed is tested the same way with `Cybertrain::Test::WebSocketReceiver`, a
|
|
1968
|
+
scripted WebSocket server on `127.0.0.1`: each connection plays a list of
|
|
1969
|
+
`Cybertrain::Test::WsStep`s (`"accept"`, `"send_text"`, `"expect"`,
|
|
1970
|
+
`"silent"`, `"close"`, `"drop"`, `"echo_until_close"`, ...), and the frames
|
|
1971
|
+
the client sent come back unmasked from `ws_received`.
|
|
1972
|
+
|
|
1973
|
+
```ruby
|
|
1974
|
+
require "cybertrain/websocket"
|
|
1975
|
+
require "cybertrain/test/websocket_receiver"
|
|
1976
|
+
|
|
1977
|
+
TICKS = Array.new(0) { "" } # a constant: the blocks cannot see locals
|
|
1978
|
+
|
|
1979
|
+
# The blocks are written in a method, where their parameters are used,
|
|
1980
|
+
# not inside the test block.
|
|
1981
|
+
def subscribe_trades(url)
|
|
1982
|
+
Cybertrain::WebSocket.subscribe("trades", url, allow_private: true)
|
|
1983
|
+
.on_open { |conn| conn.send_text("subscribe") }
|
|
1984
|
+
.on_message { |conn, text| TICKS << text }
|
|
1985
|
+
end
|
|
1986
|
+
|
|
1987
|
+
test "a trade message is stored" do
|
|
1988
|
+
rx = Cybertrain::Test::WebSocketReceiver.new
|
|
1989
|
+
rx.ws_script([Cybertrain::Test::WsStep.new("accept"), Cybertrain::Test::WsStep.new("expect"),
|
|
1990
|
+
Cybertrain::Test::WsStep.new("send_text", "tick"), Cybertrain::Test::WsStep.new("echo_until_close")])
|
|
1991
|
+
rx.start
|
|
1992
|
+
subscribe_trades(rx.url("/trades"))
|
|
1993
|
+
Cybertrain::WebSocket.start! # Test::Client never starts feeds
|
|
1994
|
+
# ... poll TICKS for at most a few seconds ...
|
|
1995
|
+
Cybertrain::WebSocket.stop!
|
|
1996
|
+
assert_equal ["tick"], TICKS
|
|
1997
|
+
assert_equal "subscribe", rx.ws_received[0].rec_data
|
|
1998
|
+
rx.stop
|
|
1999
|
+
end
|
|
2000
|
+
```
|
|
2001
|
+
|
|
2002
|
+
`Cybertrain::WebSocket.random_source = -> { 0.5 }` makes the retry delays exact.
|
|
2003
|
+
`test/websocket_integration.rb` in this repository shows a complete test.
|
|
2004
|
+
|
|
1832
2005
|
### Continuous integration
|
|
1833
2006
|
|
|
1834
2007
|
`cybertrain new` writes `.github/workflows/ci.yml` for the app. It calls the
|
|
@@ -1893,8 +2066,8 @@ before the gem is pushed:
|
|
|
1893
2066
|
1. Bump `Cybertrain::VERSION` (`cybertrain/version.rb`) and `version` in
|
|
1894
2067
|
`spin.toml` together (CI checks they match); spin caches a git
|
|
1895
2068
|
dependency by that version.
|
|
1896
|
-
2. Merge to `main`, then tag and push: `git tag
|
|
1897
|
-
3. `gem build cybertrain.gemspec && gem push cybertrain-
|
|
2069
|
+
2. Merge to `main`, then tag and push: `git tag vX.Y.Z && git push origin vX.Y.Z`.
|
|
2070
|
+
3. `gem build cybertrain.gemspec && gem push cybertrain-X.Y.Z.gem`.
|
|
1898
2071
|
4. The tag also publishes the playground image
|
|
1899
2072
|
`ghcr.io/saeki-mototsune/cybertrain-playground:X.Y.Z` (and `latest`) through
|
|
1900
2073
|
[.github/workflows/playground-image.yml](.github/workflows/playground-image.yml);
|
data/cybertrain/cli/templates.rb
CHANGED
|
@@ -452,7 +452,7 @@ module Cybertrain
|
|
|
452
452
|
TEXT
|
|
453
453
|
end
|
|
454
454
|
|
|
455
|
-
# "saeki-mototsune/cybertrain/.github/actions/setup-cybertrain@v0.3.
|
|
455
|
+
# "saeki-mototsune/cybertrain/.github/actions/setup-cybertrain@v0.3.1":
|
|
456
456
|
# the composite action in this repository, at this CLI's release tag.
|
|
457
457
|
# `uses:` takes no expressions, so the pin is static; the action itself
|
|
458
458
|
# reads the framework commit out of spin.lock and installs the
|
data/cybertrain/version.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
module Cybertrain
|
|
2
|
-
VERSION = "0.3.
|
|
2
|
+
VERSION = "0.3.1"
|
|
3
3
|
|
|
4
4
|
# Where `cybertrain new` points an app's spin.toml by default: the git tag
|
|
5
5
|
# "v#{VERSION}" of this repository. Kept here because the gem (CRuby) and
|
|
@@ -8,7 +8,7 @@ module Cybertrain
|
|
|
8
8
|
|
|
9
9
|
# The Spinel release cybertrain is written and tested against: the tag of
|
|
10
10
|
# SPINEL_REPOSITORY that `cybertrain setup` builds, and CI's SPINEL_TAG.
|
|
11
|
-
SPINEL_TAG = "2026.10.
|
|
11
|
+
SPINEL_TAG = "2026.10.27.7020"
|
|
12
12
|
|
|
13
13
|
# Where that tag lives: the saeki-mototsune fork of matz/spinel, which
|
|
14
14
|
# carries the fixes cybertrain needs ahead of an upstream release.
|