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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
import assert from "node:assert/strict";
import test from "node:test";
import { readSrcAsync, registerBundlerResolver } from "./helpers/kit.ts";
registerBundlerResolver();
const { COMPOSER_INPUT_SELECTOR, isTextEntryFocused } = await import(
"../src/features/settings/hooks/use-shortcut.ts"
);
function focus(el: { tagName?: string; isContentEditable?: boolean } | null) {
(globalThis as { document?: unknown }).document = {
activeElement: el
? { matches: (selector: string) => selector === el.tagName, ...el }
: null,
};
}
function field(tagName: string, ...selectors: string[]) {
return {
tagName,
matches: (selector: string) => selectors.includes(selector),
};
}
test("the gate holds for every text entry when no exception is named", () => {
for (const tagName of ["INPUT", "TEXTAREA"]) {
focus(field(tagName));
assert.equal(isTextEntryFocused(), true);
}
focus({ tagName: "DIV", isContentEditable: true });
assert.equal(isTextEntryFocused(), true);
focus(field("BUTTON"));
assert.equal(isTextEntryFocused(), false);
focus(null);
assert.equal(isTextEntryFocused(), false);
});
test("the composer exception frees the composer and nothing else", () => {
focus(field("TEXTAREA", COMPOSER_INPUT_SELECTOR));
assert.equal(isTextEntryFocused(), true, "the plain gate still holds it");
assert.equal(isTextEntryFocused(COMPOSER_INPUT_SELECTOR), false);
focus(field("TEXTAREA"));
assert.equal(isTextEntryFocused(COMPOSER_INPUT_SELECTOR), true);
focus(field("INPUT"));
assert.equal(isTextEntryFocused(COMPOSER_INPUT_SELECTOR), true);
focus({ tagName: "DIV", isContentEditable: true });
assert.equal(isTextEntryFocused(COMPOSER_INPUT_SELECTOR), true);
});
test("the decline chord takes the exception and the approve chord does not", async () => {
const controls = await readSrcAsync(
"components/assistant-ui/tool-confirmation-controls.tsx",
);
assert.match(
controls,
/useShortcut\(\n?\s*"declineToolRequest",[\s\S]{0,800}?textFieldException: COMPOSER_INPUT_SELECTOR,/,
);
const approve = controls.slice(
controls.indexOf('"approveToolRequest",'),
controls.indexOf('"declineToolRequest",'),
);
assert.ok(approve.includes("skipInTextFields: true"));
assert.ok(!approve.includes("textFieldException"));
});
test("the selector matches the class the composer actually carries", async () => {
const thread = await readSrcAsync("components/assistant-ui/thread.tsx");
assert.equal(COMPOSER_INPUT_SELECTOR, ".aui-composer-input");
// A selector naming a class nothing carries would silently gate everything.
assert.match(thread, /className="aui-composer-input /);
});