e93507a09c
Lockfile supply-chain audit / lockfile supply-chain audit (push) Has been cancelled
Windows Studio GGUF CI / GPU prebuilt resolves without Visual Studio (push) Has been cancelled
Windows Studio GGUF CI / setup.ps1 unit tests (VS 2026 / CMake guard) (push) Has been cancelled
Windows Studio GGUF CI / real-VS detection (VS 2022) (push) Has been cancelled
Windows Studio GGUF CI / real-VS detection (VS 2026) (push) Has been cancelled
Windows Studio GGUF CI / VC++ runtime detect + install round-trip (windows-2025-vs2026) (push) Has been cancelled
Windows Studio GGUF CI / VC++ runtime detect + install round-trip (windows-latest) (push) Has been cancelled
Windows Studio Update CI / Studio Updating Tests (push) Has been cancelled
Wheel CI / Wheel build + content sanity + import smoke (push) Has been cancelled
Lint CI / Source lint (Python + shell + YAML + JSON + safety nets) (push) Has been cancelled
MLX CI on Mac M1 / dispatch (push) Has been cancelled
Security audit / advisory audit (pip + npm + cargo) (push) Has been cancelled
Security audit / pip scan-packages :: extras (push) Has been cancelled
Security audit / pip scan-packages :: studio (push) Has been cancelled
Security audit / pip scan-packages :: hf-stack (push) Has been cancelled
Security audit / npm scan-packages (Studio frontend tarballs) (push) Has been cancelled
Security audit / workflow-trigger lint (pull_request_target / cache-poisoning) (push) Has been cancelled
Security audit / pytest tests/security (push) Has been cancelled
Security audit / npm provenance + new install-script diff (push) Has been cancelled
Studio API CI / Studio API & Auth Tests (push) Has been cancelled
Backend CI / (Python 3.10) (push) Has been cancelled
Backend CI / (Python 3.11) (push) Has been cancelled
Backend CI / (Python 3.12) (push) Has been cancelled
Backend CI / (Python 3.13) (push) Has been cancelled
Backend CI / Repo tests (CPU) (push) Has been cancelled
Frontend CI / Frontend build + bundle sanity (push) Has been cancelled
Studio GGUF CI / OpenAI, Anthropic API tests (push) Has been cancelled
Studio GGUF CI / Tool calling Tests (push) Has been cancelled
Studio GGUF CI / JSON, images (push) Has been cancelled
Mac Studio GGUF CI / OpenAI, Anthropic API tests (push) Has been cancelled
Mac Studio GGUF CI / Tool calling Tests (push) Has been cancelled
Mac Studio GGUF CI / JSON, images (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-14) (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-15) (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-26) (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-15-intel) (push) Has been cancelled
Mac Studio API CI / Studio API & Auth Tests (push) Has been cancelled
Mac Studio Install Matrix CI / Install + load (macos-26-intel) (push) Has been cancelled
Mac Studio UI CI / Chat UI Tests (push) Has been cancelled
Studio Tauri CI / Tauri Linux debug build (no codesign) (push) Has been cancelled
Mac Studio Update CI / Studio Updating Tests (push) Has been cancelled
Studio UI CI / Chat UI Tests (push) Has been cancelled
Windows Studio API CI / Studio API & Auth Tests (push) Has been cancelled
Windows Studio UI CI / Chat UI Tests (push) Has been cancelled
Studio Update CI / Studio Updating Tests (push) Has been cancelled
Core / Core (HF=default + TRL=default) (push) Has been cancelled
Core / Core (HF=4.57.6 + TRL<1) (push) Has been cancelled
Core / Core (HF=latest + TRL=latest) (push) Has been cancelled
Core / llama.cpp build + smoke (push) Has been cancelled
Windows Studio GGUF CI / OpenAI, Anthropic API tests (push) Has been cancelled
Windows Studio GGUF CI / Tool calling Tests (push) Has been cancelled
Windows Studio GGUF CI / JSON, images (push) Has been cancelled
Windows Studio GGUF CI / Studio install + inference without Visual Studio (push) Has been cancelled
Studio export capability / capability (macos-latest) (push) Has been cancelled
Studio export capability / capability (ubuntu-latest) (push) Has been cancelled
Studio export capability / capability (windows-latest) (push) Has been cancelled
Cross-platform parity / parity (macos-latest) (push) Has been cancelled
Cross-platform parity / parity (windows-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Studio load-orchestrator CI / test (push) Has been cancelled
223 lines
6.8 KiB
Python
223 lines
6.8 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-only
|
|
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
|
|
|
|
import os
|
|
import sys
|
|
|
|
_backend = os.path.join(os.path.dirname(__file__), "..")
|
|
sys.path.insert(0, _backend)
|
|
|
|
from models.inference import LoadRequest
|
|
|
|
|
|
def _base_load_request(**overrides):
|
|
data = {
|
|
"model_path": "unsloth/test-model-GGUF",
|
|
"hf_token": None,
|
|
"max_seq_length": 4096,
|
|
"load_in_4bit": True,
|
|
"is_lora": False,
|
|
"gguf_variant": "Q4_K_M",
|
|
}
|
|
data.update(overrides)
|
|
return LoadRequest.model_validate(data)
|
|
|
|
|
|
def test_blank_chat_template_override_normalizes_to_none():
|
|
req = _base_load_request(chat_template_override = " \n\t")
|
|
|
|
assert req.chat_template_override is None
|
|
|
|
|
|
def test_nonblank_chat_template_override_is_preserved_verbatim():
|
|
template = " {{ messages }} "
|
|
req = _base_load_request(chat_template_override = template)
|
|
|
|
assert req.chat_template_override == template
|
|
|
|
|
|
# ---------- ChatCompletionRequest tool_call_id walkback ----------
|
|
|
|
from models.inference import ChatCompletionRequest
|
|
|
|
|
|
def _req(messages, **overrides):
|
|
payload = {"model": "x", "messages": messages, **overrides}
|
|
return ChatCompletionRequest.model_validate(payload)
|
|
|
|
|
|
def test_tool_message_inherits_id_from_prior_assistant_tool_call():
|
|
req = _req(
|
|
[
|
|
{"role": "user", "content": "what is 2+2"},
|
|
{
|
|
"role": "assistant",
|
|
"content": None,
|
|
"tool_calls": [
|
|
{
|
|
"id": "call_real123",
|
|
"type": "function",
|
|
"function": {"name": "calc", "arguments": "{}"},
|
|
}
|
|
],
|
|
},
|
|
{"role": "tool", "name": "calc", "content": "4"}, # no tool_call_id
|
|
]
|
|
)
|
|
assert req.messages[-1].tool_call_id == "call_real123"
|
|
|
|
|
|
def test_tool_message_with_explicit_id_unchanged():
|
|
req = _req(
|
|
[
|
|
{
|
|
"role": "assistant",
|
|
"content": None,
|
|
"tool_calls": [
|
|
{
|
|
"id": "call_a",
|
|
"type": "function",
|
|
"function": {"name": "search", "arguments": "{}"},
|
|
}
|
|
],
|
|
},
|
|
{"role": "tool", "tool_call_id": "call_user_supplied", "content": "ok"},
|
|
]
|
|
)
|
|
assert req.messages[-1].tool_call_id == "call_user_supplied"
|
|
|
|
|
|
def test_walkback_prefers_function_name_match():
|
|
req = _req(
|
|
[
|
|
{
|
|
"role": "assistant",
|
|
"content": None,
|
|
"tool_calls": [
|
|
{
|
|
"id": "call_x",
|
|
"type": "function",
|
|
"function": {"name": "search", "arguments": "{}"},
|
|
},
|
|
{
|
|
"id": "call_y",
|
|
"type": "function",
|
|
"function": {"name": "calc", "arguments": "{}"},
|
|
},
|
|
],
|
|
},
|
|
{"role": "tool", "name": "calc", "content": "4"},
|
|
]
|
|
)
|
|
assert req.messages[-1].tool_call_id == "call_y"
|
|
|
|
|
|
def test_walkback_takes_first_unconsumed_when_no_name():
|
|
req = _req(
|
|
[
|
|
{
|
|
"role": "assistant",
|
|
"content": None,
|
|
"tool_calls": [
|
|
{
|
|
"id": "call_a",
|
|
"type": "function",
|
|
"function": {"name": "calc", "arguments": "{}"},
|
|
},
|
|
{
|
|
"id": "call_b",
|
|
"type": "function",
|
|
"function": {"name": "search", "arguments": "{}"},
|
|
},
|
|
],
|
|
},
|
|
{"role": "tool", "content": "first result"},
|
|
{"role": "tool", "content": "second result"},
|
|
]
|
|
)
|
|
assert req.messages[-2].tool_call_id == "call_a"
|
|
assert req.messages[-1].tool_call_id == "call_b"
|
|
|
|
|
|
def test_walkback_falls_back_to_synth_when_no_assistant_turn():
|
|
req = _req(
|
|
[
|
|
{"role": "user", "content": "hi"},
|
|
{"role": "tool", "content": "orphan"},
|
|
]
|
|
)
|
|
tcid = req.messages[-1].tool_call_id
|
|
assert tcid is not None and tcid.startswith("call_") and len(tcid) > 5
|
|
|
|
|
|
def test_walkback_does_not_cross_user_turn():
|
|
req = _req(
|
|
[
|
|
{
|
|
"role": "assistant",
|
|
"content": None,
|
|
"tool_calls": [
|
|
{
|
|
"id": "old_call",
|
|
"type": "function",
|
|
"function": {"name": "calc", "arguments": "{}"},
|
|
}
|
|
],
|
|
},
|
|
{"role": "tool", "tool_call_id": "old_call", "content": "4"},
|
|
{"role": "user", "content": "next turn"},
|
|
{"role": "tool", "content": "no parent in this turn"},
|
|
]
|
|
)
|
|
last = req.messages[-1].tool_call_id
|
|
# Walkback must NOT pick old_call across a user turn; falls back to synth.
|
|
assert last is not None
|
|
assert last != "old_call"
|
|
assert last.startswith("call_")
|
|
|
|
|
|
def test_walkback_skips_explicitly_consumed_tool_call_id():
|
|
"""An explicit-id tool result reserves its assistant slot so a
|
|
follow-up missing-id result picks the OTHER tool call."""
|
|
req = _req(
|
|
[
|
|
{
|
|
"role": "assistant",
|
|
"content": None,
|
|
"tool_calls": [
|
|
{
|
|
"id": "call_a",
|
|
"type": "function",
|
|
"function": {"name": "calc", "arguments": "{}"},
|
|
},
|
|
{
|
|
"id": "call_b",
|
|
"type": "function",
|
|
"function": {"name": "search", "arguments": "{}"},
|
|
},
|
|
],
|
|
},
|
|
{"role": "tool", "tool_call_id": "call_a", "content": "4"},
|
|
{"role": "tool", "content": "second result"},
|
|
]
|
|
)
|
|
assert [m.tool_call_id for m in req.messages if m.role == "tool"] == ["call_a", "call_b"]
|
|
|
|
|
|
def test_walkback_handles_malformed_function_string():
|
|
"""A tool_call with ``function`` as a string (provider quirk) must not
|
|
raise; resolution falls back to id selection."""
|
|
req = _req(
|
|
[
|
|
{
|
|
"role": "assistant",
|
|
"content": None,
|
|
"tool_calls": [
|
|
{"id": "call_a", "type": "function", "function": "calc"},
|
|
],
|
|
},
|
|
{"role": "tool", "name": "calc", "content": "4"},
|
|
]
|
|
)
|
|
assert req.messages[-1].tool_call_id == "call_a"
|