quilltap 4.13.0 → 4.14.0-dev.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -488,10 +488,10 @@ The CLI includes theme management commands:
488
488
  ```bash
489
489
  quilltap themes list # List all installed themes
490
490
  quilltap themes install my.qtap-theme # Install a .qtap-theme bundle
491
- quilltap themes validate my.qtap-theme # Validate a bundle
491
+ quilltap themes validate my.qtap-theme # Validate a bundle (or a bundle directory)
492
492
  quilltap themes uninstall my-theme # Uninstall a bundle theme
493
493
  quilltap themes export earl-grey # Export any theme as a bundle
494
- quilltap themes create sunset # Scaffold a new theme
494
+ quilltap themes create sunset # Write a blank theme bundle to ./sunset/
495
495
  quilltap themes search "dark" # Search registries
496
496
  quilltap themes update # Check for theme updates
497
497
  quilltap themes registry list # List configured registries
@@ -504,6 +504,10 @@ quilltap themes registry keygen [--output <dir>] # Generate an Ed25519 keypa
504
504
  quilltap themes registry sign <dir> --key <private> # Sign a registry directory
505
505
  ```
506
506
 
507
+ Bundles are checked by the same theme engine the app uses, so `validate` reports exactly what an install would: schema errors in `theme.json` and `tokens.json`, and warnings from the hook lint with the file and line. Only version 2 bundles are accepted — `validate`, `install`, `update` and `export` all refuse one made for an earlier Quilltap. Archives containing symbolic links or paths that leave the bundle are refused.
508
+
509
+ `create <name>` writes a blank version 2 bundle — `theme.json` and an empty `tokens.json`, both naming their published schema — to `./<id>/`, the id derived from the name as the Atelier derives one (`"Brass Parlour"` → `brass-parlour`). It is the same pair of files a new draft in the Atelier starts from, and it refuses a directory that already exists. From there, pack the folder as a `.qtap-theme` and open it in the Atelier with **Open a theme file**; the Atelier is where a theme is made.
510
+
507
511
  ## Shell Completion
508
512
 
509
513
  Tab-completion for bash, zsh, and fish. Pick the block that matches your shell.
@@ -0,0 +1,241 @@
1
+ /**
2
+ * `quilltap themes` against the bundled theme engine.
3
+ *
4
+ * The CLI validates, installs and exports through the same engine the app
5
+ * uses (theme-engine.generated.js): version 2 bundles only, one extraction
6
+ * routine that refuses symbolic links and escaping paths, and theme ids that
7
+ * cannot name a directory outside the themes folder.
8
+ *
9
+ * @jest-environment node
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ const fs = require('fs');
15
+ const fsp = require('fs/promises');
16
+ const os = require('os');
17
+ const path = require('path');
18
+ const { execFileSync } = require('child_process');
19
+
20
+ const engine = require('../theme-engine.generated');
21
+ const { themesCommand } = require('../theme-commands');
22
+
23
+ const REPO_ROOT = path.resolve(__dirname, '../../../..');
24
+ const BUNDLED_THEMES = path.join(REPO_ROOT, 'themes/bundled');
25
+ const V1_FIXTURE = path.join(REPO_ROOT, '__tests__/fixtures/themes/v1-sample');
26
+
27
+ const MANIFEST = {
28
+ format: 'qtap-theme',
29
+ formatVersion: 2,
30
+ id: 'cli-test-theme',
31
+ name: 'CLI Test Theme',
32
+ author: 'Test Author',
33
+ version: '1.0.0',
34
+ supportsDarkMode: true,
35
+ tokensPath: 'tokens.json',
36
+ };
37
+ const TOKENS = { primitives: {}, tokens: { '--theme-primary': { value: '#3b82f6', dark: '#60a5fa' } }, choices: {} };
38
+
39
+ let tempDir;
40
+ let dataDir;
41
+
42
+ function zip(dir, out, args = ['-r', '-q']) {
43
+ execFileSync('zip', [...args, out, '.'], { cwd: dir, stdio: 'pipe' });
44
+ }
45
+
46
+ async function writeBundleDir(dir, manifest = MANIFEST) {
47
+ await fsp.mkdir(dir, { recursive: true });
48
+ await fsp.writeFile(path.join(dir, 'theme.json'), JSON.stringify(manifest, null, 2));
49
+ await fsp.writeFile(path.join(dir, 'tokens.json'), JSON.stringify(TOKENS, null, 2));
50
+ return dir;
51
+ }
52
+
53
+ async function makeBundle(name = 'theme', manifest = MANIFEST) {
54
+ const dir = await writeBundleDir(path.join(tempDir, `${name}-src`), manifest);
55
+ const out = path.join(tempDir, `${name}.qtap-theme`);
56
+ zip(dir, out);
57
+ return out;
58
+ }
59
+
60
+ /** Run a themes subcommand; returns its exit code and printed output. */
61
+ async function run(args) {
62
+ const lines = [];
63
+ const log = jest.spyOn(console, 'log').mockImplementation((...a) => lines.push(a.join(' ')));
64
+ const err = jest.spyOn(console, 'error').mockImplementation((...a) => lines.push(a.join(' ')));
65
+ const exit = jest.spyOn(process, 'exit').mockImplementation((code) => {
66
+ throw Object.assign(new Error('exit'), { exitCode: code });
67
+ });
68
+ let code = 0;
69
+ try {
70
+ await themesCommand([...args, '--data-dir', dataDir]);
71
+ } catch (e) {
72
+ if (e.exitCode === undefined) throw e;
73
+ code = e.exitCode;
74
+ } finally {
75
+ log.mockRestore();
76
+ err.mockRestore();
77
+ exit.mockRestore();
78
+ }
79
+ // Strip colour codes so assertions read the words.
80
+ return { code, output: lines.join('\n').replace(/\x1b\[[0-9;]*m/g, '') };
81
+ }
82
+
83
+ function themesDir() {
84
+ return path.join(dataDir, 'themes');
85
+ }
86
+
87
+ beforeEach(async () => {
88
+ tempDir = await fsp.mkdtemp(path.join(os.tmpdir(), 'qtap-cli-themes-'));
89
+ dataDir = path.join(tempDir, 'instance');
90
+ await fsp.mkdir(dataDir, { recursive: true });
91
+ });
92
+
93
+ afterEach(async () => {
94
+ await fsp.rm(tempDir, { recursive: true, force: true });
95
+ });
96
+
97
+ describe('the bundled theme engine', () => {
98
+ const bundled = fs.readdirSync(BUNDLED_THEMES).filter(d => fs.existsSync(path.join(BUNDLED_THEMES, d, 'theme.json')));
99
+
100
+ it.each(bundled)('validates the bundled theme %s with no warnings', async (dir) => {
101
+ const result = await engine.validateThemeDirectory(path.join(BUNDLED_THEMES, dir));
102
+ expect(result.errors).toEqual([]);
103
+ expect(result.warnings).toEqual([]);
104
+ expect(result.valid).toBe(true);
105
+ });
106
+
107
+ it('refuses a symbolic link inside an archive', async () => {
108
+ const dir = await writeBundleDir(path.join(tempDir, 'linked'));
109
+ await fsp.symlink('/etc/hosts', path.join(dir, 'hosts.txt'));
110
+ const out = path.join(tempDir, 'linked.qtap-theme');
111
+ zip(dir, out, ['-r', '-q', '--symlinks']);
112
+
113
+ const result = await engine.validateThemeBundle(out);
114
+ expect(result.valid).toBe(false);
115
+ expect(result.errors).toContain('Symbolic links are not allowed in theme bundles: hosts.txt');
116
+
117
+ const installed = await run(['install', out]);
118
+ expect(installed.code).toBe(1);
119
+ expect(fs.existsSync(path.join(themesDir(), 'cli-test-theme'))).toBe(false);
120
+ });
121
+
122
+ it('refuses an archive entry that climbs out of the bundle', async () => {
123
+ // A stored entry named "../escape.txt": built by hand, since zip will not.
124
+ const dir = await writeBundleDir(path.join(tempDir, 'escaping', 'inner'));
125
+ await fsp.writeFile(path.join(tempDir, 'escaping', 'escape.txt'), 'out');
126
+ const out = path.join(tempDir, 'escaping.qtap-theme');
127
+ execFileSync('zip', ['-q', out, 'theme.json', 'tokens.json', '../escape.txt'], { cwd: dir, stdio: 'pipe' });
128
+
129
+ const result = await engine.validateThemeBundle(out);
130
+ expect(result.valid).toBe(false);
131
+ expect(fs.existsSync(path.join(os.tmpdir(), 'escape.txt'))).toBe(false);
132
+ });
133
+ });
134
+
135
+ describe('quilltap themes validate', () => {
136
+ it('accepts a valid .qtap-theme file', async () => {
137
+ const { code, output } = await run(['validate', await makeBundle()]);
138
+ expect(code).toBe(0);
139
+ expect(output).toContain('Valid version 2 theme bundle');
140
+ expect(output).toContain('cli-test-theme');
141
+ });
142
+
143
+ it('accepts a bundle directory', async () => {
144
+ const dir = await writeBundleDir(path.join(tempDir, 'as-dir'));
145
+ const { code, output } = await run(['validate', dir]);
146
+ expect(code).toBe(0);
147
+ expect(output).toContain('Valid version 2 theme bundle');
148
+ });
149
+
150
+ it('refuses a version 1 bundle with the earlier-theme message', async () => {
151
+ const { code, output } = await run(['validate', V1_FIXTURE]);
152
+ expect(code).toBe(1);
153
+ expect(output).toContain(engine.earlierThemeMessage('Version 1 Sample'));
154
+ expect(output).toContain('Only version 2 theme bundles are accepted.');
155
+ });
156
+
157
+ it('reports a missing path', async () => {
158
+ const { code, output } = await run(['validate', path.join(tempDir, 'nope.qtap-theme')]);
159
+ expect(code).toBe(1);
160
+ expect(output).toContain('Bundle file not found or not readable');
161
+ });
162
+ });
163
+
164
+ describe('quilltap themes install / uninstall / export', () => {
165
+ it('installs a valid bundle and records it in the index', async () => {
166
+ const { code } = await run(['install', await makeBundle()]);
167
+ expect(code).toBe(0);
168
+ expect(fs.existsSync(path.join(themesDir(), 'cli-test-theme', 'theme.json'))).toBe(true);
169
+ const index = JSON.parse(await fsp.readFile(path.join(themesDir(), 'themes-index.json'), 'utf-8'));
170
+ expect(index.themes.map(t => t.id)).toEqual(['cli-test-theme']);
171
+ });
172
+
173
+ it('refuses a version 1 bundle at install before anything is written', async () => {
174
+ const out = path.join(tempDir, 'v1.qtap-theme');
175
+ zip(V1_FIXTURE, out);
176
+ const { code, output } = await run(['install', out]);
177
+ expect(code).toBe(1);
178
+ expect(output).toContain(engine.earlierThemeMessage('Version 1 Sample'));
179
+ expect(fs.existsSync(path.join(themesDir(), 'v1-sample'))).toBe(false);
180
+ expect(fs.existsSync(path.join(themesDir(), 'themes-index.json'))).toBe(false);
181
+ });
182
+
183
+ it('exports an installed theme to a bundle that validates', async () => {
184
+ await run(['install', await makeBundle()]);
185
+ const out = path.join(tempDir, 'exported.qtap-theme');
186
+ const { code } = await run(['export', 'cli-test-theme', '--output', out]);
187
+ expect(code).toBe(0);
188
+ const result = await engine.validateThemeBundle(out);
189
+ expect(result.valid).toBe(true);
190
+ expect(result.manifest.id).toBe('cli-test-theme');
191
+ });
192
+
193
+ it('refuses to export a version 1 theme found among the installed themes', async () => {
194
+ await fsp.cp(V1_FIXTURE, path.join(themesDir(), 'v1-sample'), { recursive: true });
195
+ const out = path.join(tempDir, 'v1-out.qtap-theme');
196
+ const { code, output } = await run(['export', 'v1-sample', '--output', out]);
197
+ expect(code).toBe(1);
198
+ expect(output).toContain(engine.earlierThemeMessage('Version 1 Sample'));
199
+ expect(fs.existsSync(out)).toBe(false);
200
+ });
201
+
202
+ it('will not uninstall or export a theme id that names a path', async () => {
203
+ const outside = path.join(dataDir, 'precious');
204
+ await fsp.mkdir(outside, { recursive: true });
205
+ await fsp.writeFile(path.join(outside, 'theme.json'), JSON.stringify(MANIFEST));
206
+
207
+ const uninstalled = await run(['uninstall', '../precious']);
208
+ expect(uninstalled.code).toBe(1);
209
+ expect(fs.existsSync(outside)).toBe(true);
210
+
211
+ const exported = await run(['export', '../precious', '--output', path.join(tempDir, 'x.qtap-theme')]);
212
+ expect(exported.code).toBe(1);
213
+ });
214
+ });
215
+
216
+ describe('icon overrides', () => {
217
+ async function iconBundle(icons) {
218
+ const dir = await writeBundleDir(path.join(tempDir, 'icons'), { ...MANIFEST, icons });
219
+ await fsp.mkdir(path.join(dir, 'icons'), { recursive: true });
220
+ await fsp.writeFile(path.join(dir, 'icons/chat.svg'), '<svg xmlns="http://www.w3.org/2000/svg"/>');
221
+ await fsp.writeFile(path.join(dir, 'icons/chat.png'), 'not really');
222
+ return engine.validateThemeDirectory(dir);
223
+ }
224
+
225
+ it('accepts an .svg override of an app icon', async () => {
226
+ const result = await iconBundle({ chat: 'icons/chat.svg' });
227
+ expect(result.errors).toEqual([]);
228
+ expect(result.valid).toBe(true);
229
+ });
230
+
231
+ it.each([
232
+ ['an asset that is not .svg or .webp', { chat: 'icons/chat.png' }, 'must be .svg or .webp'],
233
+ ['a climbing path', { chat: '../../../etc/passwd.svg' }, 'Must be a path inside the bundle'],
234
+ ['an absolute path', { chat: '/etc/passwd.svg' }, 'Must be a path inside the bundle'],
235
+ ['a name that is no app icon', { 'not-an-icon-zz': 'icons/chat.svg' }, 'not an app icon'],
236
+ ])('refuses %s', async (_label, icons, message) => {
237
+ const result = await iconBundle(icons);
238
+ expect(result.valid).toBe(false);
239
+ expect(result.errors.join(' ')).toContain(message);
240
+ });
241
+ });