openpay/ (+3 crates, ~8400 LOC, 162 tests)
op-iso8583/ ISO 8583 messages for direct acquirer / card-network
connectivity. MTIs, primary+secondary bitmaps, full
DE catalogue, BCD/ASCII/EBCDIC/LLVAR/LLLVAR codecs,
five dialects (Visa Base I, Mastercard MDS, Amex GNS,
Discover, JCB), network-management messages
(sign-on/echo/cutover), DE 55 EMV TLV.
op-mobile-wallets/ Apple Pay (ECDH-P256 + AES-256-GCM), Google Pay ECv2
(ECDH + HKDF + AES-256-CTR + HMAC), Samsung Pay. PAN
never leaves the decryption boundary as a String;
lands in VaultRef. No-PAN-leakage assertions per
wallet.
op-routing/ Least-cost routing + MCC-aware routing + intelligent
retry / soft-decline recovery. 231-MCC catalogue.
Real ISO 8583 DE-39 soft/hard decline taxonomies.
smart-byte/smart-byte-rs/ (+3 crates, ~7100 LOC, 96 tests)
smart-byte-vc/ W3C Verifiable Credentials 2.0: VCDM, presentations,
Data Integrity proofs (eddsa-jcs-2022), VC-JWT,
SD-JWT (selective disclosure), Bitstring Status
List 2021. Cargo-bridge maps VCs to Smart Byte
envelopes with SAID stability.
smart-byte-did/ W3C DID resolution: did:key (Ed25519/P-256/secp256k1),
did:web (HTTPS), did:peer (numalgo 2+4), did:jwk,
did:ion (feature-gated stub). DID URL dereferencer.
smart-byte-pq/ Post-quantum signatures: ML-DSA-44/65/87 (FIPS 204),
SLH-DSA across 12 parameter sets (FIPS 205), FN-DSA
(draft FIPS 206, feature-gated). Hybrid Ed25519 +
ML-DSA pattern for the transition. Secret-key
zeroize-on-drop.
eoc/eoc-rs/ (+3 crates, ~6450 LOC, 76 tests)
eoc-vendor-api/ NeuralBackend implementations: Anthropic, OpenAI,
Google, Mistral, Cohere, Groq, Together, Fireworks.
SSE streaming. Prompt-caching where supported.
Joule estimates per published energy coefficient
(12-model curated table).
eoc-embeddings/ 21 embedding models behind one Embedder trait:
OpenAI v3 (3), Cohere v3 (3), Voyage (5), Mistral,
Jina, plus local ONNX (BGE x3, nomic, mxbai, GTE,
E5) behind 'local' feature. Matryoshka-style
dimension projection. Per-content-hash cache.
eoc-route-learned/ RouteLLM-style matrix-factorisation router +
multinomial-logreg classifier + LinUCB / Thompson
bandits for online learning. LearnedCascade wraps
the rule-based cascade with a confidence-threshold
skip policy. Synthetic-eval accuracy: MF 0.935,
LogReg 0.980.
Quality:
- cargo check across all three workspaces: clean
- cargo clippy --all-targets -- -D warnings on every new crate: clean
- 334 new tests total; all passing
- #![forbid(unsafe_code)] across every new crate
- No unwrap/expect outside #[cfg(test)]
Rust 1.95.0 edition 2024 (inherited via root rust-toolchain.toml).
149 lines
4.5 KiB
Rust
149 lines
4.5 KiB
Rust
//! End-to-end HTTP behaviour tests using `wiremock`.
|
|
//!
|
|
//! Covers the OpenAI-compatible path (which exercises four of the eight
|
|
//! backends: OpenAI, Mistral, Groq, Together, Fireworks). Each backend
|
|
//! shares the same retry / error-classification code in
|
|
//! `openai_compat::execute`, so testing the common path here gives full
|
|
//! coverage with one fixture set.
|
|
|
|
use std::time::Duration;
|
|
|
|
use eoc_core::{JouleSource, Query, Stage};
|
|
use eoc_neural::NeuralBackend;
|
|
use eoc_vendor_api::{
|
|
config::{RetryPolicy, VendorConfig},
|
|
error::VendorError,
|
|
openai::OpenAiBackend,
|
|
openai_compat,
|
|
};
|
|
use serde_json::json;
|
|
use wiremock::matchers::{header, method, path};
|
|
use wiremock::{Mock, MockServer, ResponseTemplate};
|
|
|
|
fn small_config() -> VendorConfig {
|
|
VendorConfig::new()
|
|
.with_timeout(Duration::from_secs(2))
|
|
.with_retry_policy(RetryPolicy {
|
|
max_retries: 2,
|
|
initial_backoff: Duration::from_millis(1),
|
|
backoff_factor: 1.0,
|
|
})
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn openai_happy_path_200() {
|
|
let server = MockServer::start().await;
|
|
let body = json!({
|
|
"choices": [{
|
|
"message": {"role": "assistant", "content": "hi there"},
|
|
"finish_reason": "stop"
|
|
}],
|
|
"usage": {"prompt_tokens": 5, "completion_tokens": 2}
|
|
});
|
|
Mock::given(method("POST"))
|
|
.and(path("/"))
|
|
.and(header("Authorization", "Bearer sk-test"))
|
|
.respond_with(ResponseTemplate::new(200).set_body_json(body))
|
|
.mount(&server)
|
|
.await;
|
|
|
|
let backend = OpenAiBackend::new("sk-test", "gpt-4o")
|
|
.without_stream()
|
|
.with_config(small_config().with_endpoint(server.uri()));
|
|
|
|
let q = Query::new("hello");
|
|
let r = backend.infer(&q).await;
|
|
assert_eq!(r.payload, "hi there");
|
|
assert_eq!(r.stage, Stage::Neural);
|
|
assert_eq!(r.joule_cost.source, JouleSource::Estimated);
|
|
// gpt-4o: 5*0.10 + 2*0.40 = 0.5 + 0.8 = 1.3 J = 1_300_000 µJ.
|
|
assert_eq!(r.joule_cost.microjoules, 1_300_000);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn openai_429_then_200_via_retry() {
|
|
let server = MockServer::start().await;
|
|
// First call: 429. Second call: 200.
|
|
Mock::given(method("POST"))
|
|
.and(path("/"))
|
|
.respond_with(ResponseTemplate::new(429))
|
|
.up_to_n_times(1)
|
|
.mount(&server)
|
|
.await;
|
|
Mock::given(method("POST"))
|
|
.and(path("/"))
|
|
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
|
|
"choices": [{
|
|
"message": {"role": "assistant", "content": "ok"},
|
|
"finish_reason": "stop"
|
|
}],
|
|
"usage": {"prompt_tokens": 1, "completion_tokens": 1}
|
|
})))
|
|
.mount(&server)
|
|
.await;
|
|
|
|
let backend = OpenAiBackend::new("sk-test", "gpt-4o")
|
|
.without_stream()
|
|
.with_config(small_config().with_endpoint(server.uri()));
|
|
|
|
let r = backend.infer(&Query::new("hi")).await;
|
|
assert_eq!(r.payload, "ok");
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn openai_401_no_retry() {
|
|
let server = MockServer::start().await;
|
|
// 401 must NOT be retried. We expect exactly one inbound call.
|
|
Mock::given(method("POST"))
|
|
.and(path("/"))
|
|
.respond_with(ResponseTemplate::new(401))
|
|
.expect(1)
|
|
.mount(&server)
|
|
.await;
|
|
|
|
let cfg = small_config().with_endpoint(server.uri());
|
|
let client = reqwest::Client::new();
|
|
let result = openai_compat::execute(
|
|
&client,
|
|
&format!("{}/", server.uri()),
|
|
&eoc_vendor_api::auth::Auth::Bearer("sk-bad".to_string()),
|
|
"gpt-4o",
|
|
&Query::new("hi"),
|
|
false,
|
|
&cfg,
|
|
)
|
|
.await;
|
|
|
|
match result {
|
|
Err(VendorError::InvalidApiKey) => {}
|
|
other => panic!("expected InvalidApiKey, got {other:?}"),
|
|
}
|
|
// wiremock's `.expect(1)` verifies count on drop.
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn openai_429_exhausts_retries() {
|
|
let server = MockServer::start().await;
|
|
Mock::given(method("POST"))
|
|
.and(path("/"))
|
|
.respond_with(ResponseTemplate::new(429))
|
|
.mount(&server)
|
|
.await;
|
|
|
|
let cfg = small_config().with_endpoint(server.uri());
|
|
let client = reqwest::Client::new();
|
|
let result = openai_compat::execute(
|
|
&client,
|
|
&format!("{}/", server.uri()),
|
|
&eoc_vendor_api::auth::Auth::Bearer("sk-test".to_string()),
|
|
"gpt-4o",
|
|
&Query::new("hi"),
|
|
false,
|
|
&cfg,
|
|
)
|
|
.await;
|
|
match result {
|
|
Err(VendorError::RateLimited { .. }) => {}
|
|
other => panic!("expected RateLimited, got {other:?}"),
|
|
}
|
|
}
|