Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/runvil-internal/runtime/benches/models_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ const SEED: RunSeed = RunSeed::from_bytes([1; 32]);
/// A scripted model whose every round gets the same terminal-text reply,
/// so a `models.loop` bench measures exactly one round per iteration.
fn bench_chat() -> ScriptedChat {
ScriptedChat::new(vec![ScriptedReply::Text {
ScriptedChat::repeating(ScriptedReply::Text {
model: "bench-model".to_owned(),
content: "bench reply".to_owned(),
finish_reason: Some("stop".to_owned()),
reasoning: None,
metrics: None,
}])
})
}

/// The model catalog the bench prompts resolve against; `context` sizes the
Expand Down
25 changes: 5 additions & 20 deletions crates/runvil-internal/runtime/src/execute/tests/adhoc_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ fn adhoc_tool_multiple_calls_in_one_response_all_run() {

#[test]
fn adhoc_tool_handler_error_surfaces_as_a_tool_failure() {
let gateway = ScriptedChat::new(vec![
calls(&[("call_1", "grab", "{\"value\":\"hi\"}")]),
text("unreachable"),
]);
let gateway = ScriptedChat::new(vec![calls(&[("call_1", "grab", "{\"value\":\"hi\"}")])]);
let trace = loop_scenario(grab_loop("error('handler exploded')"))
.chat(&gateway)
.run();
Expand Down Expand Up @@ -136,10 +133,7 @@ fn cancel_during_a_looping_adhoc_tool_handler_returns_promptly() {
// The round's answer hands the model's call to the looping handler in
// the next step. A cancel landing before that step starts ends the run
// the same way, and a hang fails through nextest's timeout.
let gateway = ScriptedChat::new(vec![
calls(&[("call_1", "grab", "{\"value\":\"hi\"}")]),
text("unreachable"),
]);
let gateway = ScriptedChat::new(vec![calls(&[("call_1", "grab", "{\"value\":\"hi\"}")])]);
let trace = loop_scenario(grab_loop("while true do end"))
.chat(&gateway)
.cancel_when(|effect| matches!(effect, Effect::Chat { .. }))
Expand Down Expand Up @@ -172,10 +166,7 @@ fn a_loop_handler_writes_and_reads_the_store_and_the_model_gets_the_text() {

#[test]
fn a_handler_that_calls_jump_fails_the_run() {
let gateway = ScriptedChat::new(vec![
calls(&[("call_1", "grab", "{\"value\":\"hi\"}")]),
text("unreachable"),
]);
let gateway = ScriptedChat::new(vec![calls(&[("call_1", "grab", "{\"value\":\"hi\"}")])]);
let only = "tools.offer(tools.adhoc({ name = 'grab', description = 'Grab a value', parameters = { value = 'string' } }, function(args)
jump('../Other')
end))
Expand Down Expand Up @@ -218,10 +209,7 @@ fn a_saved_jump_reference_is_refused_in_a_handler_the_script_calls() {

#[test]
fn a_saved_jump_reference_is_refused_in_a_handler_the_model_calls() {
let gateway = ScriptedChat::new(vec![
calls(&[("call_1", "grab", "{\"value\":\"hi\"}")]),
text("unreachable"),
]);
let gateway = ScriptedChat::new(vec![calls(&[("call_1", "grab", "{\"value\":\"hi\"}")])]);
let only = format!(
"{SAVED_JUMP_GRAB}messages:user('Use the tool.')\n\
models.loop()\n\
Expand Down Expand Up @@ -287,10 +275,7 @@ fn jump_works_in_the_same_block_after_the_loop_returns() {

#[test]
fn a_handler_returning_a_table_raises_and_is_observed_as_a_failure() {
let gateway = ScriptedChat::new(vec![
calls(&[("call_1", "grab", "{\"value\":\"hi\"}")]),
text("unreachable"),
]);
let gateway = ScriptedChat::new(vec![calls(&[("call_1", "grab", "{\"value\":\"hi\"}")])]);
let trace = loop_scenario(grab_loop("return { args.value }"))
.chat(&gateway)
.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ fn a_handlers_loop_during_a_loop_raises_loop_running_as_a_lua_error() {

#[test]
fn an_overflow_compactors_loop_raises_loop_running() {
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let source = one_section(&with_run_loop(
"local ok, err = pcall(run_loop, string.rep('x', 100000), function()\n\
models.loop()\n\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ fn a_context_overflow_resumes_with_its_reason_for_the_compactor() {
end)
assert(not ok, 'the compactor raise ends the loop')
return seen";
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let source = one_section(&format!(
"messages:user(string.rep('x', 100000))
{compacting_loop}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn each_broken_rule_raises_its_error_and_restores_the_records() {
),
];
for (rule, body, refusal) in cases {
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let trace = loop_scenario(overflowing_with(body)).chat(&gateway).run();
assert_eq!(
trace.text(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn a_retry_that_overflows_again_restores_the_records_and_raises_context_exhausti

#[test]
fn a_retry_that_fails_another_way_keeps_the_compacted_records() {
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let source = one_section(
"messages:user(string.rep('x', 100000))
local ok, err = pcall(models.loop, compactors.clear)
Expand All @@ -165,7 +165,7 @@ fn a_retry_that_fails_another_way_keeps_the_compacted_records() {

#[test]
fn a_compactor_that_raises_after_editing_restores_the_records_and_raises_its_failure() {
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let source = one_section(
"messages:user(string.rep('x', 100000))
local function shrink_then(raise)
Expand Down Expand Up @@ -208,7 +208,7 @@ fn a_compactor_that_calls_a_tool_gets_its_result() {

#[test]
fn a_loop_inside_a_compactor_raises_loop_running() {
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let source = one_section(
"messages:user(string.rep('x', 100000))
local _, err = pcall(models.loop, function()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//! 12, an arm's `tasks.concurrency` limit gating its fanout within the
//! caller's ceiling, and its clamping to that ceiling.

use std::cell::RefCell;

use super::*;
use crate::execute::tests::scheduler::ceiling;

Expand Down Expand Up @@ -102,18 +104,24 @@ fn an_arms_concurrency_limit_gates_its_fanout_and_the_whole_run() {
.map(|i| i.to_string())
.collect::<Vec<_>>()
.join("|");
let gateway = ScriptedChat::new((1..=10).map(|i| text(&format!("r{i}"))).collect::<Vec<_>>());
// Each run gets a script of its own, so each seeded run must ask for
// all 10 of its replies. The serial runs answer with canned replies
// and leave theirs unused.
let scripts = RefCell::new(Vec::new());
assert_every_interleaving_reads(
|| {
let gateway =
ScriptedChat::new((1..=10).map(|i| text(&format!("r{i}"))).collect::<Vec<_>>());
scripts.borrow_mut().push(gateway.clone());
scheduler_scenario(TRACE_12)
.limits(ceiling(8))
.chat(&gateway)
},
&expected,
);
let rounds: usize = scripts.borrow().iter().map(ScriptedChat::call_count).sum();
assert_eq!(
gateway.call_count(),
30,
rounds, 30,
"every sub-task made its one round, once per seed"
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,10 @@ fn join_any_joins_the_task_it_returns_and_only_that_task() {
// The pass half: reading the returned task's file passes, and the
// text is exactly that arm's. Which arm the wait returns is the
// recorded nondeterminism, so each interleaving is one of the two
// legal texts.
let gateway = ScriptedChat::new(vec![text("ra"), text("rb")]);
let pass = || scheduler_scenario(TRACE_5_PASS).chat(&gateway);
// legal texts. Each run gets a script of its own, so each seeded run
// of both halves must ask for both of its replies.
let script = || ScriptedChat::new(vec![text("ra"), text("rb")]);
let pass = || scheduler_scenario(TRACE_5_PASS).chat(&script());
let legal = |result: &Result<String, Error>| {
matches!(ok_text(result), Some("written by a" | "written by b"))
};
Expand All @@ -409,7 +410,7 @@ fn join_any_joins_the_task_it_returns_and_only_that_task() {

// The fail half: reading the file of the task the wait did NOT
// return always ends the run as the fatal make_determinism_error violation.
assert_every_interleaving_conflicts(|| scheduler_scenario(TRACE_5_FAIL).chat(&gateway));
assert_every_interleaving_conflicts(|| scheduler_scenario(TRACE_5_FAIL).chat(&script()));
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ fn nested_lua_infer_emits_a_model_turn_observation() {

#[test]
fn canceled_nested_infer_does_not_report_model_turn_failed() {
let gateway = ScriptedChat::new(vec![text("too late")]);
let gateway = ScriptedChat::new(vec![]);
let source = PromptSource::new().preamble(
"
local writer = models.get('default')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn models_compact_refuses_while_a_loop_its_handler_or_a_compactor_runs() {

#[test]
fn models_compact_applies_the_structural_rules_but_not_the_size_rules() {
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let source = one_section(
"messages:user(string.rep('x', 100000))
models.compact(function() end, 'no shrink needed')
Expand Down Expand Up @@ -124,7 +124,7 @@ fn models_compact_applies_the_structural_rules_but_not_the_size_rules() {

#[test]
fn models_compact_checks_the_compactor_then_the_reason() {
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let source = one_section(
"messages:user('kept')
local function refusal(...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::*;
/// refusal is placed on the line of the `pcall`.
#[track_caller]
fn refusals(calls: &str) -> String {
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let source = one_section(&format!(
"local other = models.get('strong')
messages:user('hello')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn the_chat_agent_shape_cuts_a_multibyte_excerpt_on_a_character_boundary() {
fn the_chat_agent_shape_fails_an_overflowing_first_turn() {
// With one user turn there is nothing older to summarize, so the turn
// fails rather than summarizing the question it is answering.
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let source = one_section(&format!(
"{}
return #messages .. '|' .. #messages[1].content",
Expand All @@ -180,7 +180,7 @@ fn the_chat_agent_shape_fails_an_overflowing_first_turn() {

#[test]
fn the_chat_agent_shape_fails_an_overflowing_second_turn() {
let gateway = ScriptedChat::new(vec![text("a1"), text("unreachable")]);
let gateway = ScriptedChat::new(vec![text("a1")]);
let source = one_section(&format!(
"{}
return #messages .. '|' .. messages[1].content .. '|' .. messages[2].content .. '|' .. #messages[3].content",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::*;

#[test]
fn an_omitted_compactor_defaults_to_fail_with_typed_precheck_exhaustion() {
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let source = one_section(
"messages:user(string.rep('x', 100000))
models.loop()
Expand All @@ -38,7 +38,7 @@ fn an_omitted_compactor_defaults_to_fail_with_typed_precheck_exhaustion() {

#[test]
fn models_loop_raises_context_exhaustion_at_the_call_site() {
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let source = one_section(
"messages:user(string.rep('x', 100000))
local ok, err = pcall(models.loop)
Expand Down Expand Up @@ -80,7 +80,7 @@ fn an_explicit_compactors_fail_invocation_reports_the_provider_reason() {

#[test]
fn an_uncaught_compactors_fail_with_a_callers_reason_ends_the_run_as_context_exhausted() {
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let source = one_section(
"messages:user(string.rep('x', 100000))
models.loop(function() compactors.fail('manual') end)
Expand All @@ -106,7 +106,7 @@ fn an_uncaught_compactors_fail_with_a_callers_reason_ends_the_run_as_context_exh

#[test]
fn an_uncaught_direct_compactors_fail_ends_the_run_as_context_exhausted() {
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let source = one_section(
"compactors.fail('manual')
return 'unreachable'",
Expand All @@ -132,7 +132,7 @@ fn a_non_function_compactor_is_the_calls_error_in_the_engines_type_names() {
// a float "number", anything else its Lua type name. No round runs.
// Each value is passed to `models.loop` with and without a leading
// handle; both shapes reach the compactor check.
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let source = one_section(
"messages:user('hello')
local writer = models.get('default')
Expand Down Expand Up @@ -198,7 +198,7 @@ fn cancel_during_a_looping_compactor_returns_promptly() {
// overflows the precheck and enters the looping compactor in the same
// step. A cancel landing before that step starts ends the run the same
// way, and a hang fails through nextest's timeout.
let gateway = ScriptedChat::new(vec![text("first"), text("unreachable")]);
let gateway = ScriptedChat::new(vec![text("first")]);
let source = one_section(
"messages:user('hello')
models.loop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,7 @@ fn an_adhoc_tool_canceled_mid_handler_reports_no_failed_tool_call() {
// The cancel lands between steps once the first round is answered, so
// the step that hands the model's call to the looping handler runs
// with the flag already set.
let gateway = ScriptedChat::new(vec![
calls(&[("call_1", "grab", "{\"value\":\"hi\"}")]),
text("unreachable"),
]);
let gateway = ScriptedChat::new(vec![calls(&[("call_1", "grab", "{\"value\":\"hi\"}")])]);
let source = one_section(
"tools.offer(tools.adhoc({ name = 'grab', description = 'Grab a value', parameters = { value = 'string' } }, function(args)
while true do end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn the_default_compactor_is_whatever_compactors_fail_holds_at_the_call() {
fn a_light_userdata_compactor_is_named_userdata_as_lua_names_it() {
// A JSON null in a structured tool's result is a null light userdata,
// which Lua's `type()` calls `userdata`.
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let source = one_section(
"tools.offer('tools/structured')
local null = tools.call('tools/structured', {}).none
Expand Down Expand Up @@ -101,7 +101,7 @@ fn the_arity_error_still_raises_when_the_author_has_rebound_error() {
// no-op instead of raising. Had that sent a round, the run would wait
// on nothing but the held round, and the cancel ends it canceled;
// had it spun in the block, nextest's timeout ends the test.
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let source = one_section(
"error = function() end
messages:user('hello')
Expand Down Expand Up @@ -129,7 +129,7 @@ fn the_arity_error_still_raises_when_the_author_has_rebound_error() {

#[test]
fn an_empty_list_raises_before_any_round() {
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let source = one_section(
"local ok, err = pcall(models.loop)\n\
assert(not ok, 'an empty list raises')\n\
Expand All @@ -146,7 +146,7 @@ fn an_empty_list_raises_before_any_round() {
#[test]
fn an_uncaught_loop_arity_error_fails_the_run_naming_the_authors_prompt_line() {
// The loop block opens at prompt line 10, so its second line is 11.
let gateway = ScriptedChat::new(vec![text("unreachable")]);
let gateway = ScriptedChat::new(vec![]);
let source = one_section(
"messages:user('hello')
models.loop(nil, nil)
Expand Down
Loading
Loading