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
116 lines
3.8 KiB
Python
116 lines
3.8 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-only
|
|
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
|
|
|
|
"""Regression checks for Studio chat title generation context."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
REPO = Path(__file__).resolve().parents[2]
|
|
RUNTIME_TSX = REPO / "studio/frontend/src/features/chat/runtime-provider.tsx"
|
|
|
|
|
|
def _source_until(src: str, anchor: str, end_anchor: str) -> str:
|
|
start = src.find(anchor)
|
|
assert start != -1, f"anchor {anchor!r} not found"
|
|
end = src.find(end_anchor, start)
|
|
assert end != -1, f"end anchor {end_anchor!r} not found"
|
|
return src[start:end]
|
|
|
|
|
|
def _balanced_block(src: str, anchor: str) -> str:
|
|
# Brace-counting only; assumes no unbalanced braces in strings, regexes, or comments.
|
|
start = src.find(anchor)
|
|
assert start != -1, f"anchor {anchor!r} not found"
|
|
body_start = src.find("{", start)
|
|
assert body_start != -1, f"body opener after {anchor!r} not found"
|
|
|
|
depth = 0
|
|
for index in range(body_start, len(src)):
|
|
char = src[index]
|
|
if char == "{":
|
|
depth += 1
|
|
elif char == "}":
|
|
depth -= 1
|
|
if depth == 0:
|
|
return src[start : index + 1]
|
|
raise AssertionError(f"unbalanced block after {anchor!r}")
|
|
|
|
|
|
def test_title_model_prompt_targets_conversation_topic():
|
|
block = _source_until(
|
|
RUNTIME_TSX.read_text(),
|
|
"async function generateTitleWithModel",
|
|
"\nconst inflightTitleByKey",
|
|
)
|
|
|
|
assert "conversation topic" in block
|
|
assert "not the user's exact wording" in block
|
|
assert "Use the assistant reply as context when provided" in block
|
|
assert "Rules: 2-6 words" in block
|
|
|
|
|
|
def test_title_model_payload_includes_optional_assistant_reply():
|
|
block = _source_until(
|
|
RUNTIME_TSX.read_text(),
|
|
"async function generateTitleWithModel",
|
|
"\nconst inflightTitleByKey",
|
|
)
|
|
|
|
assert "assistantText?: string;" in block
|
|
assert 'const assistant = clip(payload.assistantText ?? "", 384);' in block
|
|
assert "const parts: string[] = [`User: ${user}`];" in block
|
|
assert "if (assistant)" in block
|
|
assert "parts.push(`Assistant: ${assistant}`);" in block
|
|
assert 'parts.join("\\n")' in block
|
|
|
|
|
|
def test_generate_title_passes_first_assistant_reply_after_first_user():
|
|
block = _balanced_block(
|
|
RUNTIME_TSX.read_text(),
|
|
"async generateTitle(remoteId",
|
|
)
|
|
|
|
assert 'const firstUserIndex = messages.findIndex((m) => m.role === "user");' in block
|
|
assert '.find((m, i) => m.role === "assistant" && i > firstUserIndex)' in block
|
|
assert "const assistantText = extractTextParts(firstAssistant);" in block
|
|
assert "generateTitleWithModel({" in block
|
|
assert "userText," in block
|
|
assert "assistantText," in block
|
|
|
|
|
|
def test_auto_title_disabled_uses_deterministic_user_text_fallback():
|
|
block = _balanced_block(
|
|
RUNTIME_TSX.read_text(),
|
|
"async generateTitle(remoteId",
|
|
)
|
|
auto_title_off = _balanced_block(block, "if (!autoTitle)")
|
|
|
|
assert "fallbackTitleFromUserText(userText)" in auto_title_off
|
|
assert "generateTitleWithModel" not in auto_title_off
|
|
|
|
|
|
def test_model_failure_still_falls_back_to_user_text():
|
|
block = _balanced_block(
|
|
RUNTIME_TSX.read_text(),
|
|
"async generateTitle(remoteId",
|
|
)
|
|
|
|
assert "})) || fallbackTitleFromUserText(userText);" in block
|
|
|
|
|
|
def test_title_normalizer_still_enforces_output_constraints():
|
|
block = _source_until(
|
|
RUNTIME_TSX.read_text(),
|
|
"async function generateTitleWithModel",
|
|
"\nconst inflightTitleByKey",
|
|
)
|
|
|
|
assert r'replace(/[^\x20-\x7E]+/g, " ")' in block
|
|
assert 'replace(/["\'`]+/g, "")' in block
|
|
assert 'replace(/[.!?:;,]+/g, " ")' in block
|
|
assert 'title.split(" ").filter(Boolean).slice(0, 6)' in block
|
|
assert "joined.length > 60" in block
|