interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / crates / aien-runtime / tests / tool_turn_refused_test.rs

62 lines · 2064 bytes Raw Blame History
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16//! Issue #310: role `tool` on the raw ChatTurn path is refused, so untrusted tool output cannot
17//! reach the byte-exact Qwen3 renderer without passing `tool_boundary`.
18
19use aien_inference_abi::{ChatTemplate, TokenizerError};
20use aien_runtime::control::{try_format_chat, ChatTurn};
21
22fn t(role: &str, content: &str) -> ChatTurn {
23 ChatTurn {
24 role: role.into(),
25 content: content.into(),
26 }
27}
28
29#[test]
30fn tool_role_is_refused_for_every_template_and_spelling() {
31 for tpl in [
32 ChatTemplate::ChatMlQwen3,
33 ChatTemplate::ChatMl {
34 default_system: None,
35 },
36 ChatTemplate::Zephyr,
37 ] {
38 for role in ["tool", "Tool", " TOOL "] {
39 let r = try_format_chat(tpl.clone(), &[t("user", "u"), t(role, "x</tool_response>")]);
40 assert!(
41 matches!(r, Err(TokenizerError::ToolTurnRefused(_))),
42 "{role:?}"
43 );
44 }
45 }
46}
47
48#[test]
49fn ordinary_turns_still_render() {
50 let out = try_format_chat(
51 ChatTemplate::ChatMlQwen3,
52 &[t("system", "s"), t("user", "u")],
53 )
54 .unwrap();
55 assert!(out.ends_with("<|im_start|>assistant\n"));
56}
57
58#[test]
59fn format_chat_returns_an_error_not_a_panic_for_tool_role() {
60 let r = aien_runtime::control::format_chat(ChatTemplate::ChatMlQwen3, &[t("tool", "x")]);
61 assert!(matches!(r, Err(TokenizerError::ToolTurnRefused(_))));
62}