fix(core): keep unset values visible in prose (#12)

renderText now leaves {{name}} in place when the value is empty, so prose
shows which parameter is still missing instead of a blank.
This commit is contained in:
Florian Schmidt
2026-11-16 12:31:54 +01:00
parent 276d6ef3ca
commit 382da1736f
2 changed files with 3 additions and 1 deletions
+1 -1
View File
@@ -165,7 +165,7 @@ export function renderHost(
/** Substitute prose without quoting; secrets always appear masked. */
export function renderText(text: string, values: ParamValues, notebook: Notebook): string {
const secrets = new Set(notebook.params.filter(def => def.type === "secret").map(def => def.name));
return text.replace(template, (match, name: string) => secrets.has(name) ? "••••" : own(values, name) ? values[name]! : match);
return text.replace(template, (match, name: string) => secrets.has(name) ? "••••" : own(values, name) && values[name] ? values[name]! : match);
}
/**
+2
View File
@@ -153,6 +153,8 @@ describe("rendering and secrets", () => {
it("renders prose with raw values and handles inherited names safely", () => {
const n = book(" x: {type: string}");
expect(renderText("{{x}} {{toString}}", { x: "a & b" }, n)).toBe("a & b {{toString}}");
// An unset value stays visible as its template instead of vanishing ("on ****").
expect(renderText("on **{{x}}**", { x: "" }, n)).toBe("on **{{x}}**");
expect(render(n, {}, {}).invalid.x).toBeUndefined();
expect(render(n, {}, {}).missing).toContain("x");
});