mirror of
https://github.com/codewhale-hq/Codewhale.git
synced 2026-11-10 17:10:18 -10:00
fix(config): check the dialect table only in tests; restore the wire dialect doc
Review follow-up for this PR. The embedded dialect JSON was re-parsed and re-generated at runtime by ensure_asset() on every lookup, which put the parser in the library build although build.rs already validates the same file at compile time. The parser module is now test-only and the check is the embedded_asset_matches_the_generated_table test. provider_responses_profile was inserted between provider_wire_dialect and its doc comment; the doc is back on its function. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
736510f3b3
commit
c48cdfe3c3
2 files changed
+24
-32
No files matched your search
@@ -6,13 +6,12 @@
|
||||
//! resolver before selection. Replay API scope strings and account identity
|
||||
//! stay with the caller. All four profiles share one usage policy.
|
||||
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::ProviderKind;
|
||||
use crate::provider::WireFormat;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "responses_dialect_data.rs"]
|
||||
mod data;
|
||||
|
||||
@@ -317,12 +316,10 @@ include!(concat!(env!("OUT_DIR"), "/responses_dialects.rs"));
|
||||
|
||||
#[must_use]
|
||||
pub fn builtin_profiles() -> &'static [ResponsesDialectProfile] {
|
||||
ensure_asset();
|
||||
BUILTIN_PROFILES
|
||||
}
|
||||
|
||||
pub fn profile(id: &str) -> Option<&'static ResponsesDialectProfile> {
|
||||
ensure_asset();
|
||||
find_profile(id)
|
||||
}
|
||||
|
||||
@@ -330,7 +327,6 @@ pub fn profile(id: &str) -> Option<&'static ResponsesDialectProfile> {
|
||||
/// stay on the versioned Responses path. Matching strips a trailing slash and
|
||||
/// lowercases; it does not trim surrounding whitespace.
|
||||
pub fn bound_responses_path(provider: ProviderKind, base_url: &str) -> ResponsesPathPolicy {
|
||||
ensure_asset();
|
||||
let normalized = base_url.trim_end_matches('/').to_ascii_lowercase();
|
||||
for binding in BUILTIN_BINDINGS {
|
||||
if binding.provider_kind != provider {
|
||||
@@ -352,7 +348,6 @@ pub fn bound_responses_path(provider: ProviderKind, base_url: &str) -> Responses
|
||||
pub fn accept_custom_responses_profile(
|
||||
profile: &str,
|
||||
) -> Result<&'static ResponsesDialectProfile, ResponsesProfileError> {
|
||||
ensure_asset();
|
||||
let Some(found) = find_profile(profile) else {
|
||||
return Err(ResponsesProfileError::UnknownProfile {
|
||||
profile: profile.to_string(),
|
||||
@@ -371,7 +366,6 @@ pub fn accept_custom_responses_profile(
|
||||
pub fn select_responses_profile(
|
||||
query: ResponsesProfileQuery<'_>,
|
||||
) -> Result<Option<&'static ResponsesDialectProfile>, ResponsesProfileError> {
|
||||
ensure_asset();
|
||||
if query.protocol != WireFormat::Responses {
|
||||
return match query.explicit_profile {
|
||||
Some(profile) => Err(ResponsesProfileError::NotResponses {
|
||||
@@ -425,27 +419,6 @@ pub fn select_responses_profile(
|
||||
))
|
||||
}
|
||||
|
||||
fn ensure_asset() {
|
||||
static OK: OnceLock<()> = OnceLock::new();
|
||||
OK.get_or_init(|| {
|
||||
let parsed = data::parse(include_str!("../assets/responses_dialects.json"))
|
||||
.expect("responses dialect asset");
|
||||
let generated = data::codegen(&parsed);
|
||||
assert_eq!(parsed.profiles.len(), BUILTIN_PROFILES.len());
|
||||
assert_eq!(parsed.bindings.len(), BUILTIN_BINDINGS.len());
|
||||
for profile in &parsed.profiles {
|
||||
assert!(
|
||||
BUILTIN_PROFILES
|
||||
.iter()
|
||||
.any(|item| item.id.as_str() == profile.id),
|
||||
"missing generated profile {}",
|
||||
profile.id
|
||||
);
|
||||
assert!(generated.contains(&profile.id));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn find_profile(id: &str) -> Option<&'static ResponsesDialectProfile> {
|
||||
BUILTIN_PROFILES
|
||||
.iter()
|
||||
@@ -494,6 +467,25 @@ fn normalize_base_url(url: &str) -> String {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn embedded_asset_matches_the_generated_table() {
|
||||
let parsed = data::parse(include_str!("../assets/responses_dialects.json"))
|
||||
.expect("responses dialect asset");
|
||||
let generated = data::codegen(&parsed);
|
||||
assert_eq!(parsed.profiles.len(), BUILTIN_PROFILES.len());
|
||||
assert_eq!(parsed.bindings.len(), BUILTIN_BINDINGS.len());
|
||||
for profile in &parsed.profiles {
|
||||
assert!(
|
||||
BUILTIN_PROFILES
|
||||
.iter()
|
||||
.any(|item| item.id.as_str() == profile.id),
|
||||
"missing generated profile {}",
|
||||
profile.id
|
||||
);
|
||||
assert!(generated.contains(&profile.id));
|
||||
}
|
||||
}
|
||||
|
||||
const DEEPSEEK_URLS: &[&str] = &[
|
||||
"https://api.deepseek.com",
|
||||
"https://api.deepseek.com/v1",
|
||||
|
||||
@@ -4932,17 +4932,17 @@ impl Config {
|
||||
/// Single source for the client wire resolver and the capability reporter
|
||||
/// so the two cannot drift. `None` means "no preference" — the provider's
|
||||
/// static policy applies.
|
||||
pub fn provider_responses_profile(&self, identity: &ProviderIdentity) -> Option<&str> {
|
||||
pub fn provider_wire_dialect(&self, identity: &ProviderIdentity) -> Option<&str> {
|
||||
self.provider_config_for(identity)?
|
||||
.responses_profile
|
||||
.wire
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
}
|
||||
|
||||
pub fn provider_wire_dialect(&self, identity: &ProviderIdentity) -> Option<&str> {
|
||||
pub fn provider_responses_profile(&self, identity: &ProviderIdentity) -> Option<&str> {
|
||||
self.provider_config_for(identity)?
|
||||
.wire
|
||||
.responses_profile
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
|
||||
Reference in new issue
Block a user