self-run: the task cut is its own function, tested at the boundary
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
85d336c9c2
commit
4981639f29
2 changed files with 12 additions and 9 deletions
|
|
@ -131,16 +131,10 @@ fn task_section(mind: &dyn MindPort, claims: &[PipelineRef]) -> String {
|
|||
_ => task.push_str(&format!("\n\nThe run claims `{}`, which could not be read as a follow-up: its task is unknown.", claim.id.0)),
|
||||
}
|
||||
}
|
||||
if task.len() > TASK_LIMIT {
|
||||
let mut end = TASK_LIMIT;
|
||||
while !task.is_char_boundary(end) {
|
||||
end -= 1;
|
||||
}
|
||||
task.truncate(end);
|
||||
task.push_str("\n[task truncated]");
|
||||
}
|
||||
task
|
||||
cut_at(task, TASK_LIMIT)
|
||||
}
|
||||
/// `text` cut at a character boundary to `limit` bytes, marked when cut.fn cut_at(mut text: String, limit: usize) -> String { if text.len() > limit { let mut end = limit; while !text.is_char_boundary(end) { end -= 1; } text.truncate(end); text.push_str("
|
||||
[task truncated]"); } text}
|
||||
|
||||
/// What the child is told once, at the context ceiling.
|
||||
pub const FLUSH_MESSAGE: &str = "The context ceiling is reached. Admit to the mind what it lacks, close your run, and end.";
|
||||
|
|
|
|||
|
|
@ -1385,3 +1385,12 @@ fn a_run_without_claims_gets_the_identity_lines_alone() {
|
|||
let ran = go(vec![Out(result_line())]);
|
||||
assert_eq!(ran.written()[0], start_message(&Slug("yggdrasil".into()), &run_ref("selfrun-a")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_cut_keeps_exactly_the_limit_whole_characters_and_marks_only_a_real_cut() {
|
||||
assert_eq!(cut_at("abcd".into(), 4), "abcd");
|
||||
assert_eq!(cut_at("abcde".into(), 4), "abcd\n[task truncated]");
|
||||
// "\u{e9}" is two bytes: a limit inside one keeps the characters before it.
|
||||
assert_eq!(cut_at("a\u{e9}\u{e9}".into(), 4), "a\u{e9}\n[task truncated]");
|
||||
assert_eq!(cut_at("a\u{e9}\u{e9}".into(), 5), "a\u{e9}\u{e9}");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue