1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Run: node desktop/assistant/test_presets.js
// Presets.js is a QML library, so its .pragma line is stripped before node
// evaluates it.
const fs = require("fs");
const assert = require("assert");
const src = fs.readFileSync(__dirname + "/Presets.js", "utf8")
.replace(/^\.pragma library$/m, "");
const P = new Function(src + "\nreturn { DEFAULTS, list, offered, prompt };")();
const files = (...kinds) => kinds.map((kind, i) => ({ path: `/f${i}`, name: `f${i}`, kind }));
const labels = staged => P.offered(P.DEFAULTS, staged).map(p => p.label);
assert.deepStrictEqual(labels(files("pdf")), ["Summarize", "Key points", "Explain simply", "Extract text"]);
assert.deepStrictEqual(labels(files("image", "pdf")), ["Extract text", "Compare"]);
assert.deepStrictEqual(labels(files("code", "code")), ["Explain", "Review", "Compare"]);
assert.deepStrictEqual(labels(files("code")), ["Explain", "Review"]);
assert.deepStrictEqual(labels(files("text")), ["Summarize", "Explain simply"]);
assert.deepStrictEqual(labels(files("image")), ["Describe", "Extract text", "What is this?"]);
assert.deepStrictEqual(labels(files("video")), []);
assert.deepStrictEqual(labels([]), []);
// Every prompt asks for the document's language.
for (const p of P.DEFAULTS)
assert.ok(P.prompt(p).endsWith(" Answer in the language of the document."), p.label);
// A saved list is used when valid; anything else reads as the defaults.
const mine = [{ label: "Mine", prompt: "Do it.", kinds: ["pdf"] }];
assert.strictEqual(P.list(mine), mine);
for (const bad of [null, undefined, {}, "x", [{ label: "No kinds", prompt: "p" }],
[{ label: 3, prompt: "p", kinds: [] }], [null]])
assert.strictEqual(P.list(bad), P.DEFAULTS, JSON.stringify(bad));
console.log("ok");
|