Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

3.1 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0

// The files panels' X hides the panel; retrieval and the composer's RAG tag stay.

import assert from "node:assert/strict";
import test from "node:test";

import { readSrc } from "./helpers/kit.ts";

const bar = readSrc("features/rag/components/thread-documents-bar.tsx");
const store = readSrc("features/chat/stores/chat-runtime-store.ts");
const thread = readSrc("components/assistant-ui/thread.tsx");

test("the panel X hides the panel instead of turning RAG off", () => {
  assert.doesNotMatch(bar, /onClose=\{\(\) => setRagEnabled\(false\)\}/);
  assert.equal(bar.match(/onClose=\{\(\) => setRagPanelHidden\(true\)\}/g)?.length, 3);
  assert.match(bar, /if \(ragPanelHidden\) \{\n\s*return kbDialog;\n\s*\}/);
});

test("a project chat with RAG off can hide its project sources panel (#13876)", () => {
  const off = bar.slice(bar.indexOf("if (!ragEnabled) {"), bar.indexOf("const busy = projectUnresolved;"));
  assert.match(off, /\{projectDocuments\.length > 0 && !ragPanelHidden \? \(/);
  assert.match(off, /onClose=\{\(\) => setRagPanelHidden\(true\)\}\n\s*closeLabel="Hide sources"/);
});

test("turning RAG on, picking a source or switching chats shows the panel again", () => {
  assert.match(store, /ragEnabled,\n\s*ragPanelHidden: false,/);
  assert.match(store, /ragSource,\n\s*ragPanelHidden: false,/);
  // Only a real chat switch: a remount in the same chat (the first send moves the composer) keeps it hidden.
  assert.match(
    bar,
    /if \(panelThreadItemId !== null && panelThreadItemId !== threadItemId\) \{\n\s*useChatRuntimeStore\.getState\(\)\.setRagPanelHidden\(false\);\n\s*\}\n\s*panelThreadItemId = threadItemId;/,
  );
  assert.match(thread, /if \(ragEnabled && ragPanelHidden\) \{\n\s*setRagPanelHidden\(false\);\n\s*return;/);
  // Compare's + menu too: the regular view stays mounted behind it.
  assert.match(
    readSrc("features/chat/shared-composer.tsx"),
    /if \(ragEnabled && ragPanelHidden\) \{\n\s*setRagPanelHidden\(false\);\n\s*return;/,
  );
});

test("header controls use the app's tooltip, not the browser's title", () => {
  const panel = bar.slice(bar.indexOf("function ChatFilesPanel("), bar.indexOf("const ATTACHMENT_TARGETS"));
  assert.doesNotMatch(panel, /\btitle=\{/);
  assert.match(panel, /<HeaderTip label=\{compact \? "Expand files" : "Collapse files"\}>/);
  assert.match(panel, /<HeaderTip label=\{closeLabel \?\? "Close"\}>/);
});

test("the RAG tag's menu offers Show files, with the count, while the panel is hidden", () => {
  const menu = readSrc("features/rag/components/knowledge-base-composer-button.tsx");
  assert.match(menu, /\{ragPanelHidden && hasFilesPanel \? \([\s\S]*?onSelect=\{\(\) => setRagPanelHidden\(false\)\}[\s\S]*?Show files[\s\S]*?\{ragPanelFileCount\}/);
  assert.match(bar, /setRagPanelFileCount\(fileCount\);\n\s*\}, \[fileCount\]\);/);
});

test("Compare, with no files panel of its own, does not offer Show files", () => {
  assert.match(readSrc("features/chat/shared-composer.tsx"), /<KnowledgeBaseComposerButton side="top" hasFilesPanel=\{false\} \/>/);
});