File size: 2,548 Bytes
dabfdaa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | //! Checks array element kinds when a sort comparator mutates its receiver.
use codex_code_mode_runtime::ExecuteRequest;
use codex_code_mode_runtime::FunctionCallOutputContentItem;
use codex_code_mode_runtime::InProcessCodeModeSession;
use codex_code_mode_runtime::NoopCodeModeSessionDelegate;
use codex_code_mode_runtime::RuntimeResponse;
use pretty_assertions::assert_eq;
use std::sync::Arc;
#[tokio::test]
async fn array_sort_preserves_element_kinds_after_comparator_mutation() {
// Native syntax is process-wide, so keep this in its own integration target.
// Request Turbolev so initialization must also disable its Maglev frontend.
v8::V8::set_flags_from_string("--allow-natives-syntax --turbolev");
let service = InProcessCodeModeSession::new();
let started = service
.execute(
ExecuteRequest {
tool_call_id: "call_1".to_string(),
enabled_tools: Vec::new(),
source: r#"
function sortTopTier(values) {
return values.sort(() => {
values.fill(0);
return 0;
});
}
function sortMaglev(values) {
return values.sort(() => {
values.fill(0);
return 0;
});
}
function prepare(sort) {
%PrepareFunctionForOptimization(sort);
for (let i = 0; i < 100; ++i) {
sort([1, 2]);
sort([{}, {}]);
}
}
function check(sort) {
sort([1, 2]);
const object = {};
const values = [object, {}];
sort(values);
if (%HasSmiElements(values) && values[0] === object) {
throw new Error("sort stored an object in an integer-elements array");
}
}
prepare(sortTopTier);
%OptimizeFunctionOnNextCall(sortTopTier);
check(sortTopTier);
prepare(sortMaglev);
%OptimizeMaglevOnNextCall(sortMaglev);
check(sortMaglev);
text(JSON.stringify([3, 1, 2].sort((a, b) => a - b)));
"#
.to_string(),
yield_time_ms: None,
max_output_tokens: None,
},
Arc::new(NoopCodeModeSessionDelegate),
)
.await
.expect("start code-mode cell");
let cell_id = started.cell_id.clone();
let response = started
.initial_response()
.await
.expect("execute code-mode cell");
assert_eq!(
response,
RuntimeResponse::Result {
code_mode_host_duration: None,
cell_id,
content_items: vec![FunctionCallOutputContentItem::InputText {
text: "[1,2,3]".to_string(),
}],
error_text: None,
}
);
}
|