#![cfg(feature = "server")]
use symforge::stel::{
AdmissionDecision, SessionLedger, StelStatusContext, StelStatusDetail, StelStatusRequest,
TrustEnvelopeInput, build_plan, evaluate_plan, format_stel_status, format_trust_envelope,
metrics_for_decision, plan_summary_line, summarize_calibration,
};
fn render_live_envelope(query: &str, session_tokens_served: i64) -> String {
let request = symforge::stel::StelRequest {
query: query.to_string(),
..Default::default()
};
let plan = build_plan(&request);
let decision = evaluate_plan(&request, &plan);
let plan_summary = plan_summary_line(&plan);
let metrics = metrics_for_decision(plan_summary, &decision, &plan, 420, session_tokens_served);
symforge::stel::envelope_for_decision(&metrics)
}
fn render_full_status() -> String {
let ledger = SessionLedger::new();
let ctx = StelStatusContext::from_server("compact", "symforge", true, 128, 512, &ledger, 4096);
format_stel_status(
&StelStatusRequest {
detail: Some(StelStatusDetail::Full),
},
&ctx,
)
}
#[test]
fn envelope_never_presents_a_gross_counter_as_net_savings() {
let envelope = render_live_envelope("who references cfg_if", 4096);
assert!(
envelope.contains("session_tokens_served:"),
"session running total must be named `session_tokens_served`:\n{envelope}"
);
assert!(
!envelope.contains("session_net_vs_manual"),
"the mislabeled `session_net_vs_manual` field must not survive:\n{envelope}"
);
assert!(
!envelope.contains("session_tokens_served: +"),
"a gross counter must not be printed with a `+net` savings sign:\n{envelope}"
);
}
#[test]
fn envelope_labels_every_token_figure_as_estimated_or_heuristic() {
let envelope = render_live_envelope("who references cfg_if", 4096);
assert!(
envelope.contains("(est. chars/4)"),
"served tokens must be labeled an estimate:\n{envelope}"
);
assert!(
envelope.contains("vs manual (heuristic)"),
"the vs-manual comparison must be labeled heuristic:\n{envelope}"
);
assert!(
envelope.contains("(heuristic)"),
"predicted tokens must be labeled heuristic:\n{envelope}"
);
assert!(
!envelope.contains(" saved vs manual"),
"no figure may claim a measured `saved vs manual`:\n{envelope}"
);
}
#[test]
fn envelope_calibration_is_deferred_not_pending() {
let envelope = render_live_envelope("who references cfg_if", 4096);
assert!(
envelope.contains("calibration: deferred"),
"calibration must read `deferred`:\n{envelope}"
);
assert!(
!envelope.contains("calibration: pending"),
"`pending` implies transient work; the seam is permanently deferred:\n{envelope}"
);
}
#[test]
fn rejected_decision_never_prints_a_positive_saving() {
let envelope = format_trust_envelope(&TrustEnvelopeInput {
plan_summary: "trace → find_references (exact)".to_string(),
decision: AdmissionDecision::Reject,
response_tokens: 100,
est_net_vs_manual: 213,
schema_tokens: 45,
invoke_tokens: 80,
predicted_tokens: 400,
predict_error_pct: 0.0,
session_tokens_served: 213,
calibration: "deferred",
ledger_line: None,
});
assert!(envelope.contains("decision: reject"));
assert!(
envelope.contains("n/a (rejected) vs manual"),
"a reject must show `n/a (rejected)`, not a positive saving:\n{envelope}"
);
assert!(!envelope.contains("213 fewer"));
}
#[test]
fn status_banner_uses_no_blanket_active_or_pending_literal() {
let status = render_full_status();
assert!(
!status.contains(": active"),
"no subsystem may report a blanket `active`:\n{status}"
);
assert!(
!status.contains(": pending"),
"no subsystem may report a blanket `pending`:\n{status}"
);
assert!(status.contains("l1_planner: wired"), "{status}");
assert!(status.contains("l4_ledger: in_memory"), "{status}");
}
#[test]
fn status_deferred_list_drops_shipped_ledger_persistence() {
let status = render_full_status();
assert!(
!status.contains("ledger_persistence"),
"`ledger_persistence` ships in serve mode; not deferred:\n{status}"
);
}
#[test]
fn calibration_summary_surface_is_observational_not_validated() {
let summary = summarize_calibration(&[]);
let section = symforge::stel::format_calibration_section(&summary);
assert!(
section.contains("(observational)"),
"calibration section must be labeled observational:\n{section}"
);
assert!(
!section.to_lowercase().contains("validated"),
"calibration must not claim a validated state:\n{section}"
);
assert!(
section.contains("deferred"),
"auto-tuning must read as deferred:\n{section}"
);
}