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.

Studio: pin what the trailing-placeholder window does with nested placeholders (#9091)

Daniel Hanc755c9e3ab37
diff --git a/studio/frontend/tests/trailing-template-placeholder.test.ts b/studio/frontend/tests/trailing-template-placeholder.test.ts
index 5b08de69a2d..d3ebf3c34db 100644
--- a/studio/frontend/tests/trailing-template-placeholder.test.ts
+++ b/studio/frontend/tests/trailing-template-placeholder.test.ts
@@ -202,3 +202,26 @@ test("a narrow window only ever strips less than the unbounded pattern", () => {
`only ${differed} inputs were stripped at all across the narrow windows`,
);
});
+
+test("an out-of-window opener strips the nested placeholder, not the outer one", () => {
+ // The window's guarantee is about what is REMOVED, not about leaving an oversized
+ // fragment whole. The outer `${` sits past the window so it is not an opener here, and
+ // the inner `${nested}` is a complete trailing placeholder, so stripping it is correct.
+ const input = `answer \${${"a".repeat(4196)}\${nested}`;
+ const bounded = stripTrailingTemplatePlaceholder(input);
+ const unbounded = stripUnbounded(input);
+
+ assert.equal(
+ bounded,
+ input.slice(0, input.length - "${nested}".length),
+ "the inner placeholder, and only it, should be removed",
+ );
+ // The unbounded `[^}]*` takes 4,208 characters of model text here; bounded takes 9.
+ assert.equal(input.length - unbounded.length, 4208);
+ assert.equal(input.length - bounded.length, 9);
+ assert.equal(
+ input.startsWith(bounded),
+ true,
+ "the result must stay a prefix of the input",
+ );
+});