mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Unify Guardian context section collection (#42076)
## What changed - Add typed context sections for root-conversation evidence, trusted user answers, and conversation transcripts to `codex-guardian-context`. - Use the shared section registry when building core Guardian prompts and asynchronous Guardian V2 scoring context. - Preserve source-role labeling while delivering authorization evidence as user-role context, and fail closed when context collection fails. ## Testing - Cover shared section ordering and role preservation for synchronous and asynchronous targets. - Verify trusted user answers appear exactly once as user-role input in Guardian V2 approval flows. GitOrigin-RevId: 1d5d793ffbf166077411a66e85e039596907fb7e
This commit is contained in:
1 parent
d141438342
commit
2350823caa
15 files changed
+357
-108
No files matched your search
@@ -96,12 +96,14 @@ fn registered_transcript_preserves_shared_roles_and_node_repl_tool_attribution()
|
||||
target: ContextTarget::Async,
|
||||
history: &history,
|
||||
transcript: &config,
|
||||
root_conversation: &[],
|
||||
trusted_user_answers: &[],
|
||||
})
|
||||
.expect("transcript collection should succeed");
|
||||
|
||||
assert_eq!(
|
||||
sections,
|
||||
vec![ContextSection {
|
||||
vec![ContextSection::ConversationTranscript {
|
||||
items: vec![
|
||||
entry(
|
||||
ConversationTranscriptEntryKind::User,
|
||||
@@ -127,7 +129,7 @@ fn registered_transcript_preserves_shared_roles_and_node_repl_tool_attribution()
|
||||
);
|
||||
assert_eq!(
|
||||
sections,
|
||||
vec![ContextSection {
|
||||
vec![ContextSection::ConversationTranscript {
|
||||
items: collect_transcript(&history, &config),
|
||||
}]
|
||||
);
|
||||
@@ -166,11 +168,13 @@ fn excluded_tool_calls_still_attribute_included_results() {
|
||||
target: ContextTarget::Async,
|
||||
history: &history,
|
||||
transcript: &config,
|
||||
root_conversation: &[],
|
||||
trusted_user_answers: &[],
|
||||
})
|
||||
.expect("transcript collection should succeed");
|
||||
|
||||
assert_eq!(
|
||||
sections[0].items,
|
||||
transcript_items(§ions[0]),
|
||||
vec![entry(
|
||||
ConversationTranscriptEntryKind::ToolOutput("tool read_file result".to_string()),
|
||||
"file contents"
|
||||
@@ -255,6 +259,8 @@ fn outputs_with_call_ids_or_explicit_names_are_retained() {
|
||||
target,
|
||||
history: &history,
|
||||
transcript: &config,
|
||||
root_conversation: &[],
|
||||
trusted_user_answers: &[],
|
||||
})
|
||||
.expect("transcript collection should succeed");
|
||||
let mut expected = vec![
|
||||
@@ -271,7 +277,10 @@ fn outputs_with_call_ids_or_explicit_names_are_retained() {
|
||||
));
|
||||
}
|
||||
expected.push(generic("local shell output"));
|
||||
assert_eq!(sections, vec![ContextSection { items: expected }]);
|
||||
assert_eq!(
|
||||
sections,
|
||||
vec![ContextSection::ConversationTranscript { items: expected }]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -295,10 +304,12 @@ fn reused_registry_applies_current_history_sources_and_entry_limits() {
|
||||
target,
|
||||
history: &history,
|
||||
transcript: &config,
|
||||
root_conversation: &[],
|
||||
trusted_user_answers: &[],
|
||||
})
|
||||
.expect("transcript collection should succeed");
|
||||
assert_eq!(
|
||||
sections[0].items,
|
||||
transcript_items(§ions[0]),
|
||||
vec![ConversationTranscriptEntry {
|
||||
kind: ConversationTranscriptEntryKind::User,
|
||||
text: truncate_text(&text, message_tokens),
|
||||
@@ -325,6 +336,8 @@ fn reused_registry_applies_current_history_sources_and_entry_limits() {
|
||||
target: ContextTarget::Async,
|
||||
history: &history,
|
||||
transcript: &config,
|
||||
root_conversation: &[],
|
||||
trusted_user_answers: &[],
|
||||
})
|
||||
.expect("transcript collection should succeed");
|
||||
let mut expected = vec![ConversationTranscriptEntry {
|
||||
@@ -341,6 +354,13 @@ fn reused_registry_applies_current_history_sources_and_entry_limits() {
|
||||
original_bytes: text.len(),
|
||||
});
|
||||
}
|
||||
assert_eq!(sections[0].items, expected);
|
||||
assert_eq!(transcript_items(§ions[0]), expected);
|
||||
}
|
||||
}
|
||||
|
||||
fn transcript_items(section: &ContextSection) -> &[ConversationTranscriptEntry] {
|
||||
let ContextSection::ConversationTranscript { items } = section else {
|
||||
panic!("expected transcript section");
|
||||
};
|
||||
items
|
||||
}
|
||||
Reference in new issue
Block a user