aKode fase 5: rinomina interna (crate akode-*, akode-rs/, akode-cli/, binario akode, AKODE_*, ~/.akode, snapshot)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
//! Verifies provider attribution follows the selected route, including cached reads.
|
||||
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
use tracing::field::Field;
|
||||
use tracing::field::Visit;
|
||||
use tracing::instrument::WithSubscriber;
|
||||
use tracing_subscriber::Layer;
|
||||
use tracing_subscriber::layer::Context;
|
||||
use tracing_subscriber::prelude::*;
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
struct ReadEvents(Arc<Mutex<Vec<Value>>>);
|
||||
|
||||
#[derive(Default)]
|
||||
struct Fields(serde_json::Map<String, Value>);
|
||||
|
||||
impl Visit for Fields {
|
||||
fn record_str(&mut self, field: &Field, value: &str) {
|
||||
self.0.insert(field.name().into(), json!(value));
|
||||
}
|
||||
|
||||
fn record_bool(&mut self, field: &Field, value: bool) {
|
||||
self.0.insert(field.name().into(), json!(value));
|
||||
}
|
||||
|
||||
fn record_debug(&mut self, field: &Field, value: &dyn std::fmt::Debug) {
|
||||
self.record_str(field, &format!("{value:?}"));
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: tracing::Subscriber> Layer<S> for ReadEvents {
|
||||
fn on_event(&self, event: &tracing::Event<'_>, _context: Context<'_, S>) {
|
||||
let mut fields = Fields::default();
|
||||
event.record(&mut fields);
|
||||
if fields.0.get("event.name") == Some(&json!("codex.skill_read.source_selected")) {
|
||||
self.0
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.push(Value::Object(fields.0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn source_events_cover_default_and_explicit_executor_reads() -> TestResult {
|
||||
let installed = installed_skill("matching", "work")?;
|
||||
let executor = provider(vec![installed.clone()]);
|
||||
let executor_reads = executor.read_requests.clone();
|
||||
let harness = MergeHarness::new(executor, default_config()).await?;
|
||||
harness
|
||||
.turn_store
|
||||
.insert(selected_plugins(&[None, Some("env-1:matching")], &[]));
|
||||
let tools = harness.tools(&harness.step_store).await;
|
||||
harness.render().await?;
|
||||
let events = ReadEvents::default();
|
||||
let subscriber = tracing_subscriber::registry().with(events.clone().with_filter(
|
||||
tracing_subscriber::filter::filter_fn(akode_otel::trace_export_filter),
|
||||
));
|
||||
// Prevent parallel tests with no subscriber from disabling this callsite globally.
|
||||
let _interest_cache_guard =
|
||||
tracing::Dispatch::new(tracing::subscriber::NoSubscriber::default());
|
||||
async {
|
||||
for selector in [
|
||||
Value::Null,
|
||||
json!({"kind": "executor", "environment_id": "env-1"}),
|
||||
] {
|
||||
call_tool(
|
||||
&tools,
|
||||
"read",
|
||||
json!({"package": installed.id.0, "source": selector}),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
assert!(
|
||||
call_tool(&tools, "read", json!({"package": "missing"}))
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
TestResult::Ok(())
|
||||
}
|
||||
.with_subscriber(subscriber)
|
||||
.await?;
|
||||
|
||||
let expected = [(); 2].map(|()| {
|
||||
json!({
|
||||
"message": "Selected skill read source",
|
||||
"event.name": "codex.skill_read.source_selected",
|
||||
"conversation.id": "thread",
|
||||
"turn_id": "turn-1",
|
||||
"call_id": "skill-test",
|
||||
"tool_namespace": "skills",
|
||||
"tool_name": "read",
|
||||
"skill_source": "executor",
|
||||
"skill_name": "deploy:work",
|
||||
"skill_plugin_id": "matching",
|
||||
"skill_resource_kind": "main_prompt",
|
||||
"is_continuation": false,
|
||||
})
|
||||
});
|
||||
assert_eq!(*events.0.lock().unwrap(), expected);
|
||||
assert_eq!(read_request_keys(&executor_reads).len(), 2);
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user