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:
137
akode-rs/feedback/src/feedback_event_tests.rs
Normal file
137
akode-rs/feedback/src/feedback_event_tests.rs
Normal file
@@ -0,0 +1,137 @@
|
||||
//! Local feedback report contracts for titles, tags, and lossless comment bodies.
|
||||
|
||||
use crate::CodexFeedback;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
fn expected_report(
|
||||
level: &str,
|
||||
title: &str,
|
||||
reason: Option<&str>,
|
||||
tags: BTreeMap<String, String>,
|
||||
) -> serde_json::Value {
|
||||
let mut report = json!({
|
||||
"level": level,
|
||||
"message": title,
|
||||
"tags": tags,
|
||||
});
|
||||
if let Some(reason) = reason {
|
||||
report["exception"] = json!({ "values": [{ "type": title, "value": reason }] });
|
||||
}
|
||||
report
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_titles_preserve_comments() {
|
||||
let snapshot = CodexFeedback::new().snapshot(/*session_id*/ None);
|
||||
let tags = BTreeMap::from([
|
||||
(
|
||||
"feedback_title".to_string(),
|
||||
" \t\u{2003}Workflow feedback\nwith 🌍 context\r\n ".to_string(),
|
||||
),
|
||||
("entrypoint".to_string(), "task-picker".to_string()),
|
||||
]);
|
||||
let title = "Workflow feedback\nwith 🌍 context";
|
||||
for (reason, reason_tag) in [
|
||||
(
|
||||
Some(" The\n\nworkflow\twas\u{2003}useful 🌍. "),
|
||||
Some(" The workflow\twas\u{2003}useful 🌍. "),
|
||||
),
|
||||
(Some(""), Some("")),
|
||||
(None, None),
|
||||
] {
|
||||
let report =
|
||||
snapshot.feedback_report("other", reason, Some(&tags), /*session_source*/ None);
|
||||
let mut expected_tags = tags.clone();
|
||||
expected_tags.extend([
|
||||
("thread_id".to_string(), snapshot.thread_id.clone()),
|
||||
("classification".to_string(), "other".to_string()),
|
||||
(
|
||||
"cli_version".to_string(),
|
||||
env!("CARGO_PKG_VERSION").to_string(),
|
||||
),
|
||||
]);
|
||||
if let Some(reason_tag) = reason_tag {
|
||||
expected_tags.insert("reason".to_string(), reason_tag.to_string());
|
||||
}
|
||||
assert_eq!(
|
||||
report,
|
||||
expected_report("info", title, reason, expected_tags)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_or_blank_titles_preserve_session_titles() {
|
||||
let snapshot = CodexFeedback::new().snapshot(/*session_id*/ None);
|
||||
let reason = " Feedback\nwith 🌍 context. ";
|
||||
for custom_title in [None, Some(""), Some(" \t\n\u{2003} ")] {
|
||||
let tags = custom_title
|
||||
.map(|title| BTreeMap::from([("feedback_title".to_string(), title.to_string())]));
|
||||
let report = snapshot.feedback_report(
|
||||
"bug",
|
||||
Some(reason),
|
||||
tags.as_ref(),
|
||||
/*session_source*/ None,
|
||||
);
|
||||
let title = format!("[Bug]: Codex session {}", snapshot.thread_id);
|
||||
let mut expected_tags = tags.unwrap_or_default();
|
||||
expected_tags.extend([
|
||||
("thread_id".to_string(), snapshot.thread_id.clone()),
|
||||
("classification".to_string(), "bug".to_string()),
|
||||
(
|
||||
"cli_version".to_string(),
|
||||
env!("CARGO_PKG_VERSION").to_string(),
|
||||
),
|
||||
(
|
||||
"reason".to_string(),
|
||||
" Feedback with 🌍 context. ".to_string(),
|
||||
),
|
||||
]);
|
||||
assert_eq!(
|
||||
report,
|
||||
expected_report("error", &title, Some(reason), expected_tags)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reason_tag_previews_preserve_full_comments_in_the_exception() {
|
||||
let snapshot = CodexFeedback::new().snapshot(/*session_id*/ None);
|
||||
let title = format!("[Bug]: Codex session {}", snapshot.thread_id);
|
||||
for (reason, preview) in [
|
||||
("A short comment".to_string(), "A short comment".to_string()),
|
||||
(
|
||||
"First\r\n\r\nSecond\rThird\n".to_string(),
|
||||
"First Second Third ".to_string(),
|
||||
),
|
||||
("a".repeat(200), "a".repeat(200)),
|
||||
("a".repeat(201), "a".repeat(200)),
|
||||
(format!("{}extra", "界🌍".repeat(100)), "界🌍".repeat(100)),
|
||||
] {
|
||||
let report = snapshot.feedback_report(
|
||||
"bug",
|
||||
Some(&reason),
|
||||
/*tags*/ None,
|
||||
/*session_source*/ None,
|
||||
);
|
||||
assert_eq!(
|
||||
report,
|
||||
expected_report(
|
||||
"error",
|
||||
&title,
|
||||
Some(&reason),
|
||||
BTreeMap::from([
|
||||
("thread_id".to_string(), snapshot.thread_id.clone()),
|
||||
("classification".to_string(), "bug".to_string()),
|
||||
(
|
||||
"cli_version".to_string(),
|
||||
env!("CARGO_PKG_VERSION").to_string()
|
||||
),
|
||||
("reason".to_string(), preview),
|
||||
]),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user