Files
anyllm-proxy/crates/rtk/tests/conformance.rs
whit3rabbitandClaude Opus 4.8 d155bfd148 feat: RTK tool-output compression and opt-in prompt optimizer
RTK (anyllm_rtk crate): command-aware filtering of tool-result text
(test/build/git/log output) via a catalog of 55 declarative filters ported
from OmniRoute (MIT). IO-free, deterministic, prompt-cache safe (cache_control
blocks preserved byte-for-byte). Wired into the Anthropic passthrough (stream +
non-stream) and OpenAI-translate paths, gated per-model via RTK_MODELS.
RTK_COMPRESS env / admin toggle, rtk_compress/rtk_models runtime config.

Optimizer (anyllm_optimize_* crates): opt-in Frozen-Frontier Extractive
Compression of long client-sent conversation history for OpenAI Chat
Completions, the Anthropic translate path, and the Anthropic passthrough path
(client history only, never proxy tool-loop turns). OPTIMIZER_MODE=off|shadow|
live env / admin toggle; live places a cache_control breakpoint at the frontier
over raw bytes. Optional LLMLingua-2 ONNX scorer behind the optimizer-onnx
feature (model fetched on demand, never bundled). New optimizer_* metrics
counters and GET/POST /admin/api/optimizer/model endpoints.

Both features expose runtime config + Settings UI controls and fail open on any
error. Adds workspace members, CI lint/test for the optimizer-onnx feature, and
gitignore rules for downloaded ONNX artifacts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-12 19:55:33 -05:00

63 lines
2.0 KiB
Rust

//! Conformance suite — port of OmniRoute's `verify.ts`.
//!
//! Runs every vendored built-in filter's embedded `tests[]` through
//! `apply_line_filter` and asserts the output matches `expected` byte-for-byte
//! (after trimming trailing newlines, exactly as `verify.ts::trimComparable`).
//! This is the ground truth that the Rust pipeline matches OmniRoute.
use anyllm_rtk::{apply_line_filter, filters};
/// Mirror `verify.ts::trimComparable`: strip trailing `\n` runs.
fn trim_comparable(s: &str) -> &str {
s.trim_end_matches('\n')
}
#[test]
fn every_filter_test_passes() {
let mut failures: Vec<String> = Vec::new();
let mut total = 0usize;
for filter in filters() {
for t in &filter.tests {
total += 1;
let actual = apply_line_filter(&t.input, filter, None);
if trim_comparable(&actual) != trim_comparable(&t.expected) {
failures.push(format!(
"\n[{}] {}\n expected: {:?}\n actual: {:?}",
filter.id,
t.name,
trim_comparable(&t.expected),
trim_comparable(&actual),
));
}
}
}
assert!(total > 0, "no inline tests found — filters not vendored?");
assert!(
failures.is_empty(),
"{} of {} filter conformance tests failed:{}",
failures.len(),
total,
failures.join("")
);
}
#[test]
fn compression_never_grows_output() {
// verify.ts invariant #5: compressed output is never larger than input.
for filter in filters() {
for t in &filter.tests {
let actual = apply_line_filter(&t.input, filter, None);
assert!(
actual.chars().count() <= t.input.chars().count(),
"filter {} test {} grew output ({} -> {} chars)",
filter.id,
t.name,
t.input.chars().count(),
actual.chars().count(),
);
}
}
}