Files
imeai-aKode/codex-rs/ext/skills/tests/skills_extension/source_telemetry_tests.rs
andrea.difonzo 6089fbde91 aKode fase 2b-2: rimosso login ChatGPT e tutti i sottosistemi solo-ChatGPT
- Login: resta solo chiave API (+ header, Bedrock). Rimossi OAuth/browser,
  device code, refresh/revoke su auth.openai.com, PAT, agent/workload identity,
  runtime agent instance, backend-client e openapi-models, workspace routing.
- Rimossi: generazione immagini (ext + skill imagegen), history notes, plugin
  remoti (catalogo, sync, share), cyber access program, daybreak, cloud config
  e requirements (config_server ora fail-closed), attestation, frozen cloud
  skills, EMA MCP auth, Codex Apps/connettori, ricerca ospitata, header/zstd/
  routing/cookie del backend Codex, fallback OPENAI_API_KEY del realtime.
- Messaggi d'errore senza link a chatgpt.com.
- Chiavi di config legacy accettate e ignorate; feature rimosse = Stage::Removed.
- Test: cancellati solo quelli del codice rimosso; test di sicurezza
  (sandbox estensioni, permessi, redazione, auth storage, requirements)
  adattati. Restano solo fallimenti d'ambiente (code-mode-host/V8, ~/.agents).
- Istruzioni di sistema invariate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 16:20:15 +01:00

105 lines
3.5 KiB
Rust

//! 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(codex_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(())
}