mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
[codex] Deduplicate skill load warnings (#26698)
Skill reloads can get noisy when the watcher keeps triggering `skills/list` and the same invalid `SKILL.md` error comes back each time. This keeps the first warning visible, then suppresses repeats while the same `(path, message)` is still active. If the error clears and later comes back, or if the message changes, it will show again. Validation: - `just fmt` - `just test -p codex-tui skill_load_warning_state`
This commit is contained in:
1 parent
2f108f9fd9
commit
cbac22dabe
6 files changed
+199
No files matched your search
@@ -4,6 +4,45 @@
|
||||
//! catalog state into one-time TUI prompts or warning cells without owning the main event loop.
|
||||
|
||||
use super::*;
|
||||
use std::collections::HashSet;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
struct SkillLoadWarningKey {
|
||||
path: PathBuf,
|
||||
message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub(super) struct SkillLoadWarningState {
|
||||
active: HashSet<SkillLoadWarningKey>,
|
||||
}
|
||||
|
||||
impl SkillLoadWarningState {
|
||||
pub(super) fn clear(&mut self) {
|
||||
self.active.clear();
|
||||
}
|
||||
|
||||
pub(super) fn newly_active_errors(&mut self, errors: &[SkillErrorInfo]) -> Vec<SkillErrorInfo> {
|
||||
let previous = std::mem::take(&mut self.active);
|
||||
let mut current = HashSet::new();
|
||||
let mut newly_active = Vec::new();
|
||||
|
||||
for error in errors {
|
||||
let key = SkillLoadWarningKey {
|
||||
path: error.path.clone(),
|
||||
message: error.message.clone(),
|
||||
};
|
||||
let was_active = previous.contains(&key);
|
||||
if current.insert(key) && !was_active {
|
||||
newly_active.push(error.clone());
|
||||
}
|
||||
}
|
||||
|
||||
self.active = current;
|
||||
newly_active
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn emit_skill_load_warnings(app_event_tx: &AppEventSender, errors: &[SkillErrorInfo]) {
|
||||
if errors.is_empty() {
|
||||
@@ -336,8 +375,10 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::test_support::PathBufExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
use ratatui::text::Line;
|
||||
use std::path::PathBuf;
|
||||
use tempfile::tempdir;
|
||||
use tokio::sync::mpsc::unbounded_channel;
|
||||
|
||||
#[test]
|
||||
fn normalize_harness_overrides_resolves_relative_add_dirs() -> Result<()> {
|
||||
@@ -357,4 +398,126 @@ mod tests {
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn skill_error(path: &str, message: &str) -> SkillErrorInfo {
|
||||
SkillErrorInfo {
|
||||
path: PathBuf::from(path),
|
||||
message: message.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn render_line_text(line: &Line<'static>) -> String {
|
||||
line.spans
|
||||
.iter()
|
||||
.map(|span| span.content.as_ref())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn render_skill_load_warning_cells(errors: &[SkillErrorInfo]) -> String {
|
||||
let (tx, mut rx) = unbounded_channel();
|
||||
let app_event_tx = AppEventSender::new(tx);
|
||||
|
||||
emit_skill_load_warnings(&app_event_tx, errors);
|
||||
|
||||
let mut rendered = Vec::new();
|
||||
while let Ok(AppEvent::InsertHistoryCell(cell)) = rx.try_recv() {
|
||||
rendered.extend(
|
||||
cell.display_lines(/*width*/ 120)
|
||||
.iter()
|
||||
.map(render_line_text),
|
||||
);
|
||||
}
|
||||
rendered.join("\n")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn skill_load_warning_state_suppresses_repeated_active_errors() {
|
||||
let mut state = SkillLoadWarningState::default();
|
||||
let error = skill_error("/repo/.codex/skills/abc/SKILL.md", "invalid description");
|
||||
|
||||
assert_eq!(
|
||||
state.newly_active_errors(std::slice::from_ref(&error)),
|
||||
vec![error.clone()]
|
||||
);
|
||||
assert_eq!(
|
||||
state.newly_active_errors(std::slice::from_ref(&error)),
|
||||
Vec::<SkillErrorInfo>::new()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn skill_load_warning_state_reemits_after_error_clears() {
|
||||
let mut state = SkillLoadWarningState::default();
|
||||
let error = skill_error("/repo/.codex/skills/abc/SKILL.md", "invalid description");
|
||||
|
||||
assert_eq!(
|
||||
state.newly_active_errors(std::slice::from_ref(&error)),
|
||||
vec![error.clone()]
|
||||
);
|
||||
assert_eq!(state.newly_active_errors(&[]), Vec::<SkillErrorInfo>::new());
|
||||
assert_eq!(
|
||||
state.newly_active_errors(std::slice::from_ref(&error)),
|
||||
vec![error]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn skill_load_warning_state_displays_new_message_for_active_path() {
|
||||
let mut state = SkillLoadWarningState::default();
|
||||
let initial = skill_error("/repo/.codex/skills/abc/SKILL.md", "invalid description");
|
||||
let changed = skill_error("/repo/.codex/skills/abc/SKILL.md", "invalid frontmatter");
|
||||
|
||||
assert_eq!(
|
||||
state.newly_active_errors(std::slice::from_ref(&initial)),
|
||||
vec![initial]
|
||||
);
|
||||
assert_eq!(
|
||||
state.newly_active_errors(std::slice::from_ref(&changed)),
|
||||
vec![changed]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn skill_load_warning_state_clear_allows_active_error_again() {
|
||||
let mut state = SkillLoadWarningState::default();
|
||||
let error = skill_error("/repo/.codex/skills/abc/SKILL.md", "invalid description");
|
||||
|
||||
assert_eq!(
|
||||
state.newly_active_errors(std::slice::from_ref(&error)),
|
||||
vec![error.clone()]
|
||||
);
|
||||
assert_eq!(
|
||||
state.newly_active_errors(std::slice::from_ref(&error)),
|
||||
Vec::<SkillErrorInfo>::new()
|
||||
);
|
||||
|
||||
state.clear();
|
||||
|
||||
assert_eq!(
|
||||
state.newly_active_errors(std::slice::from_ref(&error)),
|
||||
vec![error]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn repeated_active_skill_load_warning_renders_once() {
|
||||
let mut state = SkillLoadWarningState::default();
|
||||
let error = skill_error("/repo/.codex/skills/abc/SKILL.md", "invalid description");
|
||||
|
||||
let first_errors = state.newly_active_errors(std::slice::from_ref(&error));
|
||||
let repeated_errors = state.newly_active_errors(std::slice::from_ref(&error));
|
||||
let rendered = [
|
||||
render_skill_load_warning_cells(&first_errors),
|
||||
render_skill_load_warning_cells(&repeated_errors),
|
||||
]
|
||||
.into_iter()
|
||||
.filter(|output| !output.is_empty())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
|
||||
insta::assert_snapshot!(rendered, @r"
|
||||
⚠ Skipped loading 1 skill(s) due to invalid SKILL.md files.
|
||||
⚠ /repo/.codex/skills/abc/SKILL.md: invalid description
|
||||
");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user