Rinomina: crate akode-*, cartelle akode-rs/ e akode-cli/, binario akode, ~/.akode, AKODE_* (A)
Riapplica la fase 5 di aKode (86e7c72e) sulla base ripulita:
- crate codex-* -> akode-*, codex-rs -> akode-rs, codex-cli -> akode-cli, binario e ausiliari akode;
- ~/.codex -> ~/.akode, CODEX_HOME -> AKODE_HOME, variabili CODEX_* -> AKODE_*, .codex/ -> .akode/ di progetto;
nessun fallback a ~/.codex o a CODEX_*;
- testi per l'utente "Codex" -> "aKode"; testi verso il modello e istruzioni di sistema invariati;
- snapshot insta rinominati (non ancora rigenerati).
I conflitti con la base ripulita sono stati risolti riapplicando la rinomina ai file senza le
funzioni di imeAI (script di mappa dei token per file).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
105
akode-rs/core/src/model_request_tests.rs
Normal file
105
akode-rs/core/src/model_request_tests.rs
Normal file
@@ -0,0 +1,105 @@
|
||||
//! Interceptors can transform incremental events and retain upstream cancellation.
|
||||
use super::*;
|
||||
use crate::client_common::ResponseStream;
|
||||
use akode_extension_api::ResponseEvent;
|
||||
use futures::StreamExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::time::Duration;
|
||||
use tokio::sync::mpsc;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
struct Append(&'static str);
|
||||
impl ModelResponseInterceptor for Append {
|
||||
fn intercept(self: Box<Self>, stream: ModelResponseStream) -> ModelResponseStream {
|
||||
Box::pin(stream.map(move |event| {
|
||||
event.map(|event| match event {
|
||||
ResponseEvent::OutputTextDelta(text) => {
|
||||
ResponseEvent::OutputTextDelta(format!("{text}{}", self.0))
|
||||
}
|
||||
other => other,
|
||||
})
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn interceptors_forward_before_completion_in_order_and_cancel_upstream() {
|
||||
let (tx_event, rx_event) = mpsc::channel(1);
|
||||
let consumer_dropped = CancellationToken::new();
|
||||
let upstream_cancelled = consumer_dropped.clone();
|
||||
let mut stream = intercept_stream(
|
||||
Box::pin(
|
||||
ResponseStream {
|
||||
rx_event,
|
||||
interrupt: None,
|
||||
consumer_dropped,
|
||||
}
|
||||
.map(|event| {
|
||||
event.map_err(|error| {
|
||||
akode_extension_api::ModelResponseError::Stream(error.to_string())
|
||||
})
|
||||
}),
|
||||
),
|
||||
vec![Box::new(Append("a")), Box::new(Append("b"))],
|
||||
);
|
||||
tx_event
|
||||
.send(Ok(ResponseEvent::OutputTextDelta("text".into())))
|
||||
.await
|
||||
.unwrap();
|
||||
// Upstream remains open and has not sent Completed.
|
||||
let event = tokio::time::timeout(Duration::from_secs(1), stream.next())
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let ResponseEvent::OutputTextDelta(text) = event else {
|
||||
panic!("expected text delta");
|
||||
};
|
||||
assert_eq!(text, "textab");
|
||||
drop(stream);
|
||||
tokio::time::timeout(Duration::from_secs(1), upstream_cancelled.cancelled())
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct MetadataContributor;
|
||||
impl ModelRequestContributor for MetadataContributor {
|
||||
fn request(&self, input: ModelRequestInput<'_>) -> Option<Box<dyn ModelResponseInterceptor>> {
|
||||
*input.client_metadata = Some(HashMap::from([
|
||||
("thread_id".into(), "replaced".into()),
|
||||
("guardian_credits_requested".into(), "true".into()),
|
||||
("parent_response_id".into(), "forged".into()),
|
||||
("existing".into(), "replaced".into()),
|
||||
("x-request-id".into(), "request".into()),
|
||||
]));
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn contributor_metadata_preserves_core_fields_and_existing_values() {
|
||||
let mut metadata = Some(HashMap::from([
|
||||
("thread_id".into(), "thread".into()),
|
||||
("existing".into(), "original".into()),
|
||||
]));
|
||||
let contributors: Vec<Arc<dyn ModelRequestContributor>> = vec![Arc::new(MetadataContributor)];
|
||||
assert!(
|
||||
prepare(
|
||||
&contributors,
|
||||
"thread",
|
||||
"model",
|
||||
ModelRequestKind::Generation,
|
||||
&mut metadata
|
||||
)
|
||||
.is_empty()
|
||||
);
|
||||
assert_eq!(
|
||||
metadata,
|
||||
Some(HashMap::from([
|
||||
("thread_id".into(), "thread".into()),
|
||||
("existing".into(), "original".into()),
|
||||
("x-request-id".into(), "request".into()),
|
||||
]))
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user