Repository navigation
365 lines (297 loc) · 13.9 KB
/
Copy pathci.yml
File metadata and controls
365 lines (297 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
name: CI
on:
push:
# `dev` is included so integration work is checked at the commit
# that introduces a problem rather than at the dev -> main merge,
# where unrelated failures pile up and have to be peeled apart.
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
# Default to least privilege (I1). Jobs that need more (e.g.,
# writing to the repo) must override at job scope. CI is read-only
# by construction: it tests, lints, and reports results.
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
test:
name: Test (${{ matrix.os }}, Rust ${{ matrix.rust }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- { os: ubuntu-latest, rust: stable }
- { os: macos-latest, rust: stable }
- { os: windows-latest, rust: stable }
- { os: ubuntu-latest, rust: "1.88" }
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.14"
- name: Install Rust
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable @ 2026-05-21
with:
toolchain: ${{ matrix.rust }}
- uses: Swatinem/rust-cache@eedcf2fb1c22f010a0eb66b92f378c110977f266 # v2
# `--workspace` matters: without it this only tested the root crate,
# so the broker/risk/rebalancer suites never ran here and a test that
# called the live Binance API sat undetected until the release gate
# tried to publish and hit a 451 from a restricted runner region.
# Curated feature list instead of --all-features (bq-oxtu): the opt-in
# `native-tls` broker backend drags in openssl-sys, which cannot build
# on machines without system OpenSSL headers. Everything else ships.
- name: Run tests (curated features)
run: cargo test --workspace --features "nanobook/serde,nanobook/persistence,nanobook/portfolio,nanobook/parallel,nanobook/itch,nanobook/scenarios,nanobook-broker/binance,nanobook-broker/strict-market-reject"
- name: Run tests (no default features)
run: cargo test --no-default-features
failure-injection:
name: Failure Injection Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install Rust
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable @ 2026-05-21
- uses: Swatinem/rust-cache@eedcf2fb1c22f010a0eb66b92f378c110977f266 # v2
- name: Run IBKR F6 reconnect drill test
run: cargo test -p nanobook-broker --test ibkr_f6_reconnect_drill
- name: Run Binance F1 idempotency test
run: cargo test -p nanobook-broker --test binance_f_bin1_idempotency --features binance
- name: Run Binance F2 reconnect drill test
run: cargo test -p nanobook-broker --test binance_f_bin2_reconnect_drill --features binance
python-test:
name: Python (${{ matrix.os }}, ${{ matrix.python }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# All Python versions on Linux; latest only on Mac/Windows
include:
- { os: ubuntu-latest, python: "3.11" }
- { os: ubuntu-latest, python: "3.12" }
- { os: ubuntu-latest, python: "3.13" }
- { os: ubuntu-latest, python: "3.14" }
- { os: macos-latest, python: "3.14" }
- { os: windows-latest, python: "3.14" }
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: ${{ matrix.python }}
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
- uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable @ 2026-05-21
- uses: Swatinem/rust-cache@eedcf2fb1c22f010a0eb66b92f378c110977f266 # v2
with:
key: python-${{ matrix.python }}
- name: Build and install Python extension
working-directory: python
run: uv sync --python ${{ matrix.python }} --group dev
# One line: Windows PowerShell does not treat a backslash as continuation.
- name: Run Python tests (property + unit)
working-directory: python
run: uv run --python ${{ matrix.python }} --group dev python -m pytest tests/ -v --ignore=tests/reference --cov=nanobook --cov-report=term --cov-fail-under=100
python-scenarios:
name: Python scenarios (${{ matrix.label }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- label: with-numpy
- label: no-numpy
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.14"
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
- uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable @ 2026-05-21
- uses: Swatinem/rust-cache@eedcf2fb1c22f010a0eb66b92f378c110977f266 # v2
with:
key: python-scenarios-${{ matrix.label }}
- name: Build and install Python extension
working-directory: python
run: uv sync --python 3.14 --group dev
- name: Drop numpy for stdlib-only matrix leg
if: matrix.label == 'no-numpy'
working-directory: python
run: uv pip uninstall numpy
- name: Run scenario tests (with numpy + parity)
if: matrix.label == 'with-numpy'
working-directory: python
run: |
uv run --python 3.14 --group dev python -m pytest \
tests/test_scenarios.py \
tests/test_scenarios_helpers.py \
tests/test_scenarios_stats.py \
tests/test_scenarios_normal.py \
tests/property/test_prop_scenarios.py \
tests/reference/test_ref_scenarios.py \
-v
- name: Run scenario tests (stdlib-only, no numpy)
if: matrix.label == 'no-numpy'
working-directory: python
run: |
uv run --python 3.14 --group dev python -m pytest \
tests/test_scenarios.py \
tests/test_scenarios_helpers.py \
tests/property/test_prop_scenarios.py \
-v
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.14"
- name: Install Rust
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable @ 2026-05-21
with:
components: clippy, rustfmt
- uses: Swatinem/rust-cache@eedcf2fb1c22f010a0eb66b92f378c110977f266 # v2
- name: Check formatting
run: cargo fmt --all -- --check
# `--workspace`, for the same reason the test job needs it: without it
# only the root crate is linted, and broker/risk/rebalancer accumulate
# unchecked. Bringing them in cleared 141 findings, most of them the
# dollar.cents digit-grouping convention that was never declared for
# those crates.
# Curated features, not --all-features: native-tls needs openssl-sys
# (bq-oxtu). Same list as the test job.
- name: Clippy
run: cargo clippy --workspace --all-targets --features "nanobook/serde,nanobook/persistence,nanobook/portfolio,nanobook/parallel,nanobook/itch,nanobook/scenarios,nanobook-broker/binance,nanobook-broker/strict-market-reject" -- -D warnings
# The `security` job moved to .github/workflows/audit.yml so it can run on
# a weekly schedule. Here it only fired on push/PR, so an advisory filed
# against an unchanged Cargo.lock waited for the next push to surface.
coverage:
name: Code coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install Rust
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable @ 2026-05-21
- uses: Swatinem/rust-cache@eedcf2fb1c22f010a0eb66b92f378c110977f266 # v2
with:
key: coverage
- name: Install cargo-llvm-cov
run: cargo install cargo-llvm-cov --version 0.8.5 --locked
- name: Generate coverage
run: cargo llvm-cov --workspace --features "nanobook/serde,nanobook/persistence,nanobook/portfolio,nanobook/parallel,nanobook/itch,nanobook/scenarios,nanobook-broker/binance,nanobook-broker/strict-market-reject" --lcov --output-path lcov.info
- name: Upload to Codecov
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
with:
files: lcov.info
fail_ci_if_error: false
bench:
name: Benchmark
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install Rust
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable @ 2026-05-21
- uses: Swatinem/rust-cache@eedcf2fb1c22f010a0eb66b92f378c110977f266 # v2
- name: Run benchmarks
run: cargo bench --workspace --features "nanobook/serde,nanobook/persistence,nanobook/portfolio,nanobook/parallel,nanobook/itch,nanobook/scenarios,nanobook-broker/binance,nanobook-broker/strict-market-reject"
itch-replay-smoke:
# Runs on a small committed fixture (a few seconds of real ITCH data),
# no network. To regenerate the fixture from the full NASDAQ file, see
# examples/itch-replay/README.md (download.sh + itch-slice).
name: ITCH Replay Smoke (committed fixture)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.14"
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
- name: Install Rust
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable @ 2026-05-21
- uses: Swatinem/rust-cache@eedcf2fb1c22f010a0eb66b92f378c110977f266 # v2
with:
key: itch-replay-smoke
- name: Decompress fixture
working-directory: examples/itch-replay
run: |
mkdir -p data
gunzip -c fixtures/smoke.itch.gz > data/smoke.itch
- name: Run replay on fixture
working-directory: examples/itch-replay
run: |
cargo run --release --example itch-replay --features itch -- \
--input data/smoke.itch \
--output-dir data/replay-smoke
- name: Install Python dependencies
working-directory: examples/itch-replay
run: |
uv venv
uv pip install -r requirements.txt
# report.py imports nanobook; build the local bindings.
uv pip install ../../python
- name: Generate report
working-directory: examples/itch-replay
run: uv run report.py --input data/replay-smoke/event-log.jsonl --output data/replay-smoke/report.html
- name: Verify summary matches expected
working-directory: examples/itch-replay
run: diff -u expected/summary.txt data/replay-smoke/summary.txt
- name: Verify invariants log is empty
working-directory: examples/itch-replay
run: |
if [ -s data/replay-smoke/invariants.log ]; then
echo "invariants.log should be empty but contains:"
cat data/replay-smoke/invariants.log
exit 1
fi
momentum-backtest-smoke:
name: Momentum Backtest Smoke (cached prices)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.14"
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
- name: Install Rust
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable @ 2026-05-21
- uses: Swatinem/rust-cache@eedcf2fb1c22f010a0eb66b92f378c110977f266 # v2
with:
key: momentum-backtest-smoke
# Price data is committed in the repo; no cache or download needed.
- name: Install Python dependencies
working-directory: examples/momentum-backtest
run: |
uv venv
uv pip install -r requirements.txt
# strategy.py imports nanobook; build the local bindings so the
# smoke test exercises the code under review, not a PyPI wheel.
uv pip install ../../python
- name: Run backtest with cached data (zero cost)
working-directory: examples/momentum-backtest
run: |
# Window must cover the 12-month momentum lookback before the
# first rebalance, or the signal is all-NaN and no rebalances run.
uv run python strategy.py \
--data-file data/sp100_ohlcv.csv \
--start-date 2019-01-01 \
--end-date 2020-12-31 \
--initial-cash 1000000 \
--commission-bps 0 \
--slippage-bps 0 \
--output results.json
- name: Generate report
working-directory: examples/momentum-backtest
run: uv run python report.py --results results.json --output report.html
- name: Verify results exist
working-directory: examples/momentum-backtest
run: |
if [ ! -f results.json ]; then
echo "results.json not found"
exit 1
fi
if [ ! -f report.html ]; then
echo "report.html not found"
exit 1
fi