`Node::send()` became `Result<OutboxStatus, String>` in the local-outbox work,
which broke `crates/onionwire-sdk` (E0308 at src/lib.rs:195) — and nothing
noticed, because the SDK is a separate cargo workspace that root CI never
compiles and android-release.yml only builds on a v*.*.* tag.
- `Wire::send()` now returns `WResult<SendState>` (`Sent` | `Queued`) instead
of swallowing the outcome as `()`. A queued send is local-only until the
retry worker gets a circuit through, so the Kotlin boundary must be able to
tell it apart from a delivered one.
- `ChatMessage` gains `delivery: Option<String>` ("sent" | "queued" |
"sending" | "failed: <reason>"), populated from the message's outbox row;
`None` for incoming messages. An outgoing row with no outbox row was accepted
on the first attempt, so it reads "sent".
- New `sdk` job in `.forgejo/workflows/ci.yml`: `cargo test --locked` +
`cargo clippy --locked --all-targets -- -D warnings` in `crates/onionwire-sdk`
in the same rust:1.91-bookworm container, with its own target volume (the SDK
resolves the root crate with rustls, so sharing the root job's target dir
would thrash feature-unified artifacts).
- Drift found while un-rotting it: the SDK `Cargo.lock` was stale (missing
`sha2`, added to the root crate by the zeroize work), so `--locked` failed;
and the SDK README still said "no outbox, no spool in v1" and "identity keys
in sqlite are plaintext", both untrue since the outbox and SQLCipher landed.
Tests: crates/onionwire-sdk 4 passed (2 new unit tests over the status
mapping), clippy clean; root `cargo test --locked` clean. The CI job body was
smoke-run locally in the same container image before being committed.
# Conflicts:
# crates/onionwire-sdk/src/lib.rs
96 lines
3.5 KiB
Rust
96 lines
3.5 KiB
Rust
//! Lifecycle: a node stops when told to, says so, and refuses further work
|
|
//! with an error instead of panicking.
|
|
//!
|
|
//! Needs a live Tor network to publish the onion service, so `cargo test` skips
|
|
//! it. Run it on a networked machine with:
|
|
//!
|
|
//! ```text
|
|
//! cargo test --test tor_lifecycle -- --ignored --nocapture
|
|
//! ```
|
|
//!
|
|
//! The offline half of this contract — the Arti-status projection, the WAL
|
|
//! checkpoint, and the SDK's typed error after shutdown — runs in the normal
|
|
//! suite (`tests/hs.rs`, `src/node.rs`, `crates/onionwire-sdk/src/lib.rs`).
|
|
|
|
use onionwire::hs::TorState;
|
|
use onionwire::node::{FlushOutcome, Node};
|
|
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
#[ignore = "needs live Tor network"]
|
|
async fn shutdown_stops_the_node_and_later_calls_are_typed_errors() {
|
|
let _ = tracing_subscriber::fmt()
|
|
.with_env_filter(
|
|
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into()),
|
|
)
|
|
.with_test_writer()
|
|
.try_init();
|
|
|
|
let root = tempfile::tempdir().expect("tempdir");
|
|
let home = root.path().join("alice");
|
|
unsafe {
|
|
std::env::set_var("ONIONWIRE_STORE_PASSPHRASE", "onionwire-test");
|
|
}
|
|
|
|
let node = Node::start(home.clone()).await.expect("start");
|
|
|
|
// `start` returns only after `wait_until_published`, so the node is
|
|
// reachable by the time a caller can call this — which must not read as
|
|
// `Stopped` or `Bootstrapping`. `DegradedReachable` is the honest answer
|
|
// when Arti says the service is degraded.
|
|
//
|
|
// This caught a real bug: `tor_state()` originally projected Arti's raw
|
|
// combined status, which is still `Bootstrapping` after a *successful*
|
|
// probe (that mismatch is what the 360s publish wait exists for), and which
|
|
// reads `Shutdown` on a service that has not started its reactor yet — so a
|
|
// live node reported `Stopped`. See `onion_reachable` in `src/node.rs`.
|
|
let started_state = node.tor_state();
|
|
assert!(
|
|
matches!(
|
|
started_state,
|
|
TorState::Published | TorState::DegradedReachable
|
|
),
|
|
"start returned Ok but tor_state() is {started_state:?}"
|
|
);
|
|
|
|
// A flush with nothing queued is a no-op that reports it, not an error.
|
|
let drained: FlushOutcome = node.flush().await.expect("flush on a live node");
|
|
assert_eq!(drained.remaining, 0, "empty outbox: {drained:?}");
|
|
|
|
node.shutdown().await.expect("shutdown");
|
|
|
|
assert_eq!(
|
|
node.tor_state(),
|
|
TorState::Stopped,
|
|
"tor_state must report Stopped after shutdown"
|
|
);
|
|
|
|
// Second shutdown: idempotent at the node level — no panic, no repeat work.
|
|
node.shutdown().await.expect("shutdown is idempotent");
|
|
|
|
let err = node
|
|
.flush()
|
|
.await
|
|
.expect_err("flush after shutdown must be an error");
|
|
assert!(err.contains("stopped"), "flush error was {err:?}");
|
|
|
|
let err = node
|
|
.send(&[0u8; 32], b"after shutdown")
|
|
.await
|
|
.expect_err("send after shutdown must be an error");
|
|
assert!(err.contains("stopped"), "send error was {err:?}");
|
|
|
|
// `RotateResult` is not `Debug`, so match on the error instead of
|
|
// `expect_err`.
|
|
let err = node
|
|
.rotate()
|
|
.await
|
|
.err()
|
|
.expect("rotate after shutdown must be an error");
|
|
assert!(err.contains("stopped"), "rotate error was {err:?}");
|
|
|
|
// The store file survives the checkpoint: stopping is not wiping.
|
|
assert!(
|
|
home.join("onionwire.db").exists(),
|
|
"shutdown must not delete the store"
|
|
);
|
|
}
|