#[path = "support/stel_surface_env.rs"]
mod stel_surface_env;
use std::collections::BTreeSet;
use symforge::protocol::surface_probe::{
SurfaceProfile, enforce_compact_surface, list_tools_for_profile, surface_profile_from_env,
};
use symforge::stel::{COMPACT_TOOL_NAMES, compact_surface_tools};
fn production_compact_names() -> BTreeSet<String> {
compact_surface_tools()
.into_iter()
.map(|tool| tool.name.to_string())
.collect()
}
fn advertised_names(profile: SurfaceProfile) -> BTreeSet<String> {
list_tools_for_profile(profile)
.into_iter()
.map(|tool| tool.name.to_string())
.collect()
}
#[tokio::test]
async fn unset_surface_resolves_compact_and_advertises_three_tools() {
let _serialize = stel_surface_env::COMPACT_ENV_LOCK.lock().await;
let _surface = stel_surface_env::clear_symforge_surface();
let profile = surface_profile_from_env();
assert_eq!(
profile,
SurfaceProfile::Compact,
"unset SYMFORGE_SURFACE must resolve to the compact-3 default"
);
let names = production_compact_names();
let expected: BTreeSet<String> = COMPACT_TOOL_NAMES.iter().map(|n| n.to_string()).collect();
assert_eq!(
names, expected,
"production compact tools/list must advertise exactly the compact-3 surface"
);
assert_eq!(
names.len(),
3,
"compact default must expose exactly 3 tools"
);
}
#[tokio::test]
async fn surface_full_resolves_full_and_advertises_legacy_surface() {
let _serialize = stel_surface_env::COMPACT_ENV_LOCK.lock().await;
let _surface = stel_surface_env::set_symforge_surface("full");
let profile = surface_profile_from_env();
assert_eq!(
profile,
SurfaceProfile::Full,
"SYMFORGE_SURFACE=full must restore the legacy surface profile"
);
let names = advertised_names(profile);
assert!(
names.len() >= 30,
"full opt-out must advertise the legacy (32-tool) surface; got {} tools",
names.len()
);
assert!(
!names.contains("symforge"),
"legacy full surface must not advertise the compact `symforge` facade"
);
assert!(
names.contains("get_symbol"),
"legacy full surface must advertise the legacy read tools"
);
}
#[tokio::test]
async fn compact_default_rejects_legacy_tool_call_at_dispatch() {
let _serialize = stel_surface_env::COMPACT_ENV_LOCK.lock().await;
let _surface = stel_surface_env::clear_symforge_surface();
assert_eq!(
surface_profile_from_env(),
SurfaceProfile::Compact,
"unset SYMFORGE_SURFACE must resolve to the compact default"
);
let rejected = enforce_compact_surface("search_text");
let err = rejected.expect_err(
"compact default must REJECT a legacy `tools/call` at dispatch, not just hide it from \
tools/list",
);
assert!(
err.message.contains("compact surface"),
"rejection must name the compact-surface policy; got: {}",
err.message
);
assert!(
err.message.contains("SYMFORGE_SURFACE=full"),
"rejection must point at the documented opt-out; got: {}",
err.message
);
for name in COMPACT_TOOL_NAMES {
assert!(
enforce_compact_surface(name).is_ok(),
"advertised compact tool `{name}` must be allowed on the compact surface"
);
}
}
#[tokio::test]
async fn full_surface_allows_legacy_tool_call_at_dispatch() {
let _serialize = stel_surface_env::COMPACT_ENV_LOCK.lock().await;
let _surface = stel_surface_env::set_symforge_surface("full");
assert_eq!(
surface_profile_from_env(),
SurfaceProfile::Full,
"SYMFORGE_SURFACE=full must resolve to the full surface"
);
assert!(
enforce_compact_surface("search_text").is_ok(),
"full surface must allow legacy `tools/call` (the documented opt-out)"
);
for name in COMPACT_TOOL_NAMES {
assert!(
enforce_compact_surface(name).is_ok(),
"tool `{name}` must not be dispatch-gated on the full surface"
);
}
}