@kabmo-labs/kabmo 0.19.0 → 0.21.1
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 +32 -5
- package/dist/client/index.html +3 -3
- package/dist/client/index.js +340 -340
- package/dist/client/static/js/{index-sxdw908m.css → index-0721wrkf.css} +1 -1
- package/dist/client/static/js/{index-fcee4c13.js → index-thwqf24c.js} +685 -685
- package/dist/client/static/{manifest-42r8wcmg.webmanifest → manifest-q6h8k9e0.webmanifest} +1 -1
- package/index.html +1 -1
- package/package.json +1 -1
- package/public/manifest.webmanifest +1 -1
- package/src/client/components/common/checkbox/style.test.ts +11 -8
- package/src/client/components/common/panel-mark/index.test.tsx +124 -0
- package/src/client/components/common/panel-mark/index.tsx +9 -1
- package/src/client/components/settings/categories/panel-plugins/GitFreshness.test.tsx +46 -0
- package/src/client/components/settings/categories/panel-plugins/GitFreshness.tsx +1 -1
- package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +7 -9
- package/src/client/components/settings/categories/panel-plugins/PluginCard.test.tsx +149 -0
- package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +33 -6
- package/src/client/components/settings/categories/panel-plugins/PluginMark.test.ts +15 -0
- package/src/client/components/settings/categories/panel-plugins/PluginMark.tsx +6 -2
- package/src/client/components/settings/categories/panel-plugins/Section.tsx +7 -1
- package/src/client/components/settings/categories/panel-plugins/Toolbar.tsx +35 -2
- package/src/client/glass-sticky.test.ts +46 -0
- package/src/client/glass.css +27 -17
- package/src/client/glass.test.ts +21 -61
- package/src/client/hooks/ui/stuck-header.test.ts +28 -3
- package/src/client/hooks/ui/stuck-header.ts +36 -5
- package/src/client/hooks/workspace/panel-registry.ts +8 -4
- package/src/server/lib/lifecycle/tls.test.ts +6 -1
- package/src/server/lib/panels/git-update.server.test.ts +20 -0
- package/src/server/lib/panels/git-update.server.ts +20 -4
- package/src/server/lib/panels/sync.server.ts +9 -1
- package/src/server/lib/panels/update.server.test.ts +193 -0
- package/src/server/lib/panels/update.server.ts +210 -0
- package/src/server/lib/plugins/server-half.server.ts +42 -0
- package/src/server/lib/terminal/attach-replay.test.ts +26 -8
- package/src/server/routes/panels/install-route.test.ts +238 -0
- package/src/server/routes/panels/install.ts +36 -64
- package/src/server/routes/panels/panel-routes.test-util.ts +6 -1
- package/src/server/routes/panels/routes.test.ts +1 -118
- package/src/shared/lib/icons/icon-paint-css.test.ts +104 -25
- package/src/shared/lib/icons/icon-paint-css.ts +60 -50
- package/src/shared/lib/icons/icon-paint-panel.ts +16 -7
- package/src/shared/lib/icons/icon-paint-weight.ts +123 -0
- package/src/shared/lib/icons/icon-tone.ts +166 -0
- package/src/shared/lib/icons/tint-hues.generated.ts +50 -3
- package/src/shared/lib/icons/tint.test.ts +75 -15
- package/src/shared/lib/icons/tint.ts +40 -11
- package/src/shared/lib/panels/update.test.ts +107 -0
- package/src/shared/lib/panels/update.ts +73 -0
- package/src/shared/lib/theme/color.ts +50 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The install route's mutation verbs: forget, auto-update, check, update,
|
|
8
|
+
* update_all and force_sync.
|
|
9
|
+
*
|
|
10
|
+
* Split from `routes.test.ts` (which keeps the plugin FILE routes) because the
|
|
11
|
+
* two answer different questions and each now has enough cases to deserve its
|
|
12
|
+
* own budget: the file routes are a security boundary, while these are the
|
|
13
|
+
* pane's buttons.
|
|
14
|
+
*
|
|
15
|
+
* What is pinned here is what a second implementation would get wrong:
|
|
16
|
+
*
|
|
17
|
+
* - **`update` dispatches on the SOURCE.** A bundled install takes the store's
|
|
18
|
+
* copy; a local directory is refused by naming why nothing publishes it, and
|
|
19
|
+
* a missing plugin is refused too. A silent no-op would read as success.
|
|
20
|
+
* - **the store copy goes through the sync's EDIT GATE.** A hand-edited tree is
|
|
21
|
+
* refused and the differing file is named — the override stays the blocked
|
|
22
|
+
* notice's own button — so Update never becomes a one-click force-sync.
|
|
23
|
+
* - **`update_all` never aborts on one refusal.** The plugin with local changes
|
|
24
|
+
* is reported by name while the untouched one still updates, and the response
|
|
25
|
+
* is a 200 because something DID happen.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { describe, expect, test } from 'bun:test';
|
|
29
|
+
import fs from 'node:fs';
|
|
30
|
+
import { join } from 'node:path';
|
|
31
|
+
|
|
32
|
+
import { action as installAction } from '@/server/routes/panels/install';
|
|
33
|
+
import { discoverPanelPlugins, getMarketplacePluginsDir, invalidatePanelScan } from '@/server/lib/panels/registry.server';
|
|
34
|
+
import { writeBaseline } from '@/server/lib/panels/baseline.server';
|
|
35
|
+
import { hashTrackedFiles } from '@/server/lib/panels/local-edits.server';
|
|
36
|
+
import { dirs, MANIFEST, post, usePanelRouteFixtures, writePlugin } from '@/server/routes/panels/panel-routes.test-util';
|
|
37
|
+
|
|
38
|
+
usePanelRouteFixtures();
|
|
39
|
+
|
|
40
|
+
describe('the install route', () => {
|
|
41
|
+
test('forget drops a dangling catalog entry and reports the scan without it', async () => {
|
|
42
|
+
// The reported state: the catalog names a directory that is not there, so
|
|
43
|
+
// the scan rejects it and the pane has a dead-end row.
|
|
44
|
+
writePlugin('other', getMarketplacePluginsDir());
|
|
45
|
+
fs.mkdirSync(dirs.root, { recursive: true });
|
|
46
|
+
fs.writeFileSync(
|
|
47
|
+
join(dirs.root, 'marketplace.json'),
|
|
48
|
+
JSON.stringify({
|
|
49
|
+
name: 'Kabmo',
|
|
50
|
+
plugins: [
|
|
51
|
+
{ name: 'ghost', source: 'plugins/ghost' },
|
|
52
|
+
{ name: 'other', source: 'plugins/other' },
|
|
53
|
+
],
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
56
|
+
invalidatePanelScan();
|
|
57
|
+
expect((await discoverPanelPlugins()).errors.map((error) => error.source)).toEqual(['plugins/ghost']);
|
|
58
|
+
|
|
59
|
+
const response = await post(installAction, { type: 'forget', source: 'plugins/ghost' });
|
|
60
|
+
expect(response.status).toBe(200);
|
|
61
|
+
const body = (await response.json()) as { ok: boolean; errors: unknown[] };
|
|
62
|
+
expect(body.ok).toBe(true);
|
|
63
|
+
// The whole payload comes back, so the pane clears the row without a second
|
|
64
|
+
// read that could race the write.
|
|
65
|
+
expect(body.errors).toEqual([]);
|
|
66
|
+
|
|
67
|
+
const catalog = JSON.parse(fs.readFileSync(join(dirs.root, 'marketplace.json'), 'utf8')) as {
|
|
68
|
+
name: string;
|
|
69
|
+
plugins: Array<{ source: string }>;
|
|
70
|
+
};
|
|
71
|
+
expect(catalog.plugins.map((entry) => entry.source)).toEqual(['plugins/other']);
|
|
72
|
+
expect(catalog.name).toBe('Kabmo');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('forget refuses a source that is missing or escapes the marketplace', async () => {
|
|
76
|
+
expect((await post(installAction, { type: 'forget' })).status).toBe(400);
|
|
77
|
+
expect((await post(installAction, { type: 'forget', source: '../../etc' })).status).toBe(400);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('forget leaves the directory alone when one is there', async () => {
|
|
81
|
+
// The repair for a MISSING directory must not become a delete: only the
|
|
82
|
+
// remove action may touch files.
|
|
83
|
+
const dir = writePlugin('demo', getMarketplacePluginsDir());
|
|
84
|
+
fs.mkdirSync(dirs.root, { recursive: true });
|
|
85
|
+
fs.writeFileSync(
|
|
86
|
+
join(dirs.root, 'marketplace.json'),
|
|
87
|
+
JSON.stringify({ plugins: [{ name: 'demo', source: 'plugins/demo' }] }),
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
expect((await post(installAction, { type: 'forget', source: 'plugins/demo' })).status).toBe(200);
|
|
91
|
+
expect(fs.existsSync(dir)).toBe(true);
|
|
92
|
+
// The plugin still loads — the directory is what makes it exist.
|
|
93
|
+
invalidatePanelScan();
|
|
94
|
+
expect((await discoverPanelPlugins()).plugins.map((plugin) => plugin.pluginId)).toEqual(['demo']);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('set_auto_update flips the flag and answers with the payload', async () => {
|
|
98
|
+
const on = await post(installAction, { type: 'set_auto_update', enabled: true });
|
|
99
|
+
expect(on.status).toBe(200);
|
|
100
|
+
const body = (await on.json()) as { ok: boolean; autoUpdate: boolean };
|
|
101
|
+
expect(body.ok).toBe(true);
|
|
102
|
+
expect(body.autoUpdate).toBe(true);
|
|
103
|
+
|
|
104
|
+
const off = await post(installAction, { type: 'set_auto_update', enabled: false });
|
|
105
|
+
expect(((await off.json()) as { autoUpdate: boolean }).autoUpdate).toBe(false);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('check_updates answers even with nothing to probe', async () => {
|
|
109
|
+
// The button is disabled with no git plugins, but the route must not throw
|
|
110
|
+
// for a stale client that asks anyway.
|
|
111
|
+
writePlugin('demo', getMarketplacePluginsDir());
|
|
112
|
+
invalidatePanelScan();
|
|
113
|
+
|
|
114
|
+
const response = await post(installAction, { type: 'check_updates' });
|
|
115
|
+
expect(response.status).toBe(200);
|
|
116
|
+
const body = (await response.json()) as { ok: boolean; gitStatus: Record<string, unknown> };
|
|
117
|
+
expect(body.ok).toBe(true);
|
|
118
|
+
expect(body.gitStatus).toEqual({});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('update refuses a plugin that is not installed', async () => {
|
|
122
|
+
const response = await post(installAction, { type: 'update', pluginId: 'ghost' });
|
|
123
|
+
expect(response.status).toBe(400);
|
|
124
|
+
expect(((await response.json()) as { error: string }).error).toContain('No installed plugin');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('update refuses a local directory by naming why nothing publishes it', async () => {
|
|
128
|
+
// A hand-copied plugin has no remote and the store does not ship it. The
|
|
129
|
+
// refusal is the answer: a silent no-op would read as a successful update.
|
|
130
|
+
writePlugin('demo', getMarketplacePluginsDir());
|
|
131
|
+
invalidatePanelScan();
|
|
132
|
+
|
|
133
|
+
const response = await post(installAction, { type: 'update', pluginId: 'demo' });
|
|
134
|
+
expect(response.status).toBe(400);
|
|
135
|
+
expect(((await response.json()) as { error: string }).error).toContain('local directory');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('update requires a plugin id', async () => {
|
|
139
|
+
expect((await post(installAction, { type: 'update' })).status).toBe(400);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test('update applies the store copy of a BUNDLED install', async () => {
|
|
143
|
+
// The button a bundled card renders: the store ships 1.1.0 while the install
|
|
144
|
+
// sits at 1.0.0, and the whole payload comes back with the new version.
|
|
145
|
+
writePlugin('demo', getMarketplacePluginsDir());
|
|
146
|
+
writePlugin('demo', join(dirs.bundled, 'plugins'), { ...MANIFEST, version: '1.1.0' });
|
|
147
|
+
invalidatePanelScan();
|
|
148
|
+
|
|
149
|
+
const response = await post(installAction, { type: 'update', pluginId: 'demo' });
|
|
150
|
+
expect(response.status).toBe(200);
|
|
151
|
+
const body = (await response.json()) as {
|
|
152
|
+
ok: boolean;
|
|
153
|
+
updated: boolean;
|
|
154
|
+
plugins: Array<{ pluginId: string; version: string }>;
|
|
155
|
+
};
|
|
156
|
+
expect(body.ok).toBe(true);
|
|
157
|
+
expect(body.updated).toBe(true);
|
|
158
|
+
const installed = body.plugins.find((plugin) => plugin.pluginId === 'demo');
|
|
159
|
+
expect(installed?.version).toBe('1.1.0');
|
|
160
|
+
|
|
161
|
+
const manifest = JSON.parse(
|
|
162
|
+
fs.readFileSync(join(getMarketplacePluginsDir(), 'demo', 'kabmo.json'), 'utf8'),
|
|
163
|
+
) as { version: string };
|
|
164
|
+
expect(manifest.version).toBe('1.1.0');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('update refuses a bundled install whose files the user edited', async () => {
|
|
168
|
+
// The edit gate is the sync's, not the button's: an update must not become
|
|
169
|
+
// the force-sync escape hatch by being reachable in one click. The baseline
|
|
170
|
+
// is what PROVES Kabmo wrote the directory, so it is written here — an
|
|
171
|
+
// install with no baseline predates the gate and is meant to run.
|
|
172
|
+
writePlugin('demo', getMarketplacePluginsDir());
|
|
173
|
+
writePlugin('demo', join(dirs.bundled, 'plugins'), { ...MANIFEST, version: '1.1.0' });
|
|
174
|
+
await writeBaseline('demo', await hashTrackedFiles(join(getMarketplacePluginsDir(), 'demo')));
|
|
175
|
+
fs.writeFileSync(join(getMarketplacePluginsDir(), 'demo', 'README.md'), '# edited by hand');
|
|
176
|
+
invalidatePanelScan();
|
|
177
|
+
|
|
178
|
+
const response = await post(installAction, { type: 'update', pluginId: 'demo' });
|
|
179
|
+
expect(response.status).toBe(400);
|
|
180
|
+
const body = (await response.json()) as { error: string; syncBlocked: Record<string, unknown> };
|
|
181
|
+
expect(body.error).toContain('local changes');
|
|
182
|
+
expect(Object.keys(body.syncBlocked)).toEqual(['demo']);
|
|
183
|
+
// Nothing was replaced: the user's file still says what they wrote.
|
|
184
|
+
expect(fs.readFileSync(join(getMarketplacePluginsDir(), 'demo', 'README.md'), 'utf8')).toBe('# edited by hand');
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('update_all answers even when nothing is installed', async () => {
|
|
188
|
+
const response = await post(installAction, { type: 'update_all' });
|
|
189
|
+
expect(response.status).toBe(200);
|
|
190
|
+
expect(((await response.json()) as { ok: boolean }).ok).toBe(true);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('update_all updates the store copy and reports a refused plugin', async () => {
|
|
194
|
+
// One pass over every installed plugin: the plugin with an edited file is
|
|
195
|
+
// refused BY NAME while the untouched one still updates — a refusal must
|
|
196
|
+
// never abort the others.
|
|
197
|
+
writePlugin('demo', getMarketplacePluginsDir());
|
|
198
|
+
writePlugin('demo', join(dirs.bundled, 'plugins'), { ...MANIFEST, version: '1.1.0' });
|
|
199
|
+
writePlugin('other', getMarketplacePluginsDir(), { ...MANIFEST, id: 'other', name: 'Other' });
|
|
200
|
+
writePlugin('other', join(dirs.bundled, 'plugins'), { ...MANIFEST, id: 'other', name: 'Other', version: '1.1.0' });
|
|
201
|
+
await writeBaseline('other', await hashTrackedFiles(join(getMarketplacePluginsDir(), 'other')));
|
|
202
|
+
fs.writeFileSync(join(getMarketplacePluginsDir(), 'other', 'README.md'), '# edited by hand');
|
|
203
|
+
invalidatePanelScan();
|
|
204
|
+
|
|
205
|
+
const response = await post(installAction, { type: 'update_all' });
|
|
206
|
+
expect(response.status).toBe(200);
|
|
207
|
+
const body = (await response.json()) as {
|
|
208
|
+
ok: boolean;
|
|
209
|
+
error?: string;
|
|
210
|
+
plugins: Array<{ pluginId: string; version: string }>;
|
|
211
|
+
};
|
|
212
|
+
expect(body.ok).toBe(true);
|
|
213
|
+
expect(body.plugins.find((plugin) => plugin.pluginId === 'demo')?.version).toBe('1.1.0');
|
|
214
|
+
expect(body.plugins.find((plugin) => plugin.pluginId === 'other')?.version).toBe('1.0.0');
|
|
215
|
+
expect(body.error).toContain('other');
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test('force_sync refuses a plugin that is not a bundled install', async () => {
|
|
219
|
+
writePlugin('demo', getMarketplacePluginsDir());
|
|
220
|
+
invalidatePanelScan();
|
|
221
|
+
|
|
222
|
+
const response = await post(installAction, { type: 'force_sync', pluginId: 'demo' });
|
|
223
|
+
expect(response.status).toBe(400);
|
|
224
|
+
expect(((await response.json()) as { error: string }).error).toContain('No bundled plugin');
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test('force_sync requires a plugin id', async () => {
|
|
228
|
+
expect((await post(installAction, { type: 'force_sync' })).status).toBe(400);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test('the payload carries an empty syncBlocked by default', async () => {
|
|
232
|
+
writePlugin('demo', getMarketplacePluginsDir());
|
|
233
|
+
invalidatePanelScan();
|
|
234
|
+
// The field is always present, so the pane's notice has one shape to read
|
|
235
|
+
// rather than two (absent versus empty).
|
|
236
|
+
expect((await discoverPanelPlugins()).syncBlocked).toEqual({});
|
|
237
|
+
});
|
|
238
|
+
});
|
|
@@ -19,53 +19,27 @@
|
|
|
19
19
|
*
|
|
20
20
|
* `enable`/`disable` only flip a flag: the plugin's files stay on disk, which is
|
|
21
21
|
* what makes disabling reversible and different from `remove`.
|
|
22
|
+
*
|
|
23
|
+
* `update` and `update_all` are the pane's Update buttons. Both go through
|
|
24
|
+
* `update.server.ts`, which dispatches on the install's SOURCE — a git clone is
|
|
25
|
+
* fetched and reset to its remote, a bundled install takes the store's copy
|
|
26
|
+
* under the sync's own edit gate — so one button means one thing to the reader
|
|
27
|
+
* whatever the plugin's origin.
|
|
22
28
|
*/
|
|
23
29
|
|
|
24
30
|
import { json, type ActionFunctionArgs } from '@/server/lib/remix-compat';
|
|
25
31
|
import { methodNotAllowed } from '@/server/lib/route-adapter';
|
|
26
32
|
import { discoverPanelPlugins, invalidatePanelScan } from '@/server/lib/panels/registry.server';
|
|
27
33
|
import { installPanelPluginFromBundled, installPanelPluginFromGit, removePanelPlugin } from '@/server/lib/panels/install.server';
|
|
28
|
-
import { probeGitUpdate
|
|
34
|
+
import { probeGitUpdate } from '@/server/lib/panels/git-update.server';
|
|
35
|
+
import { updateAllPanelPlugins, updatePanelPlugin } from '@/server/lib/panels/update.server';
|
|
29
36
|
import { forceSyncBundledPlugin } from '@/server/lib/panels/sync.server';
|
|
30
37
|
import { writeGitStatus } from '@/server/lib/panels/git-status.server';
|
|
31
38
|
import { forgetCatalogEntry } from '@/server/lib/panels/catalog.server';
|
|
32
39
|
import { setPluginAutoUpdate, setPluginEnabled } from '@/server/lib/panels/state.server';
|
|
33
|
-
import {
|
|
40
|
+
import { syncPluginServer } from '@/server/lib/plugins/server-half.server';
|
|
34
41
|
import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
|
|
35
42
|
|
|
36
|
-
/**
|
|
37
|
-
* Bring a plugin's SERVER half in line with its on-disk state, now.
|
|
38
|
-
*
|
|
39
|
-
* The server half is otherwise loaded once at boot (`loadPluginServers` in the
|
|
40
|
-
* entry), so installing or switching a plugin on used to leave its routes, RPC
|
|
41
|
-
* methods and realtime topic unregistered until the process restarted — a panel
|
|
42
|
-
* that installed cleanly and then answered "no plugin is loaded", or a Stats
|
|
43
|
-
* panel stuck on "No sample yet." with nothing on screen to explain it.
|
|
44
|
-
*
|
|
45
|
-
* Never throws: a plugin whose server half cannot load is a plugin whose PANEL
|
|
46
|
-
* still works, and the failure is recorded through `notePluginLoadFailure` —
|
|
47
|
-
* the same list `GET /api/plugins/state` serves to the pane — so the reader
|
|
48
|
-
* sees WHY. Folding it into a 400 here would hide a successful install behind
|
|
49
|
-
* an unrelated fault.
|
|
50
|
-
*/
|
|
51
|
-
async function syncPluginServer(pluginId: string, enabled: boolean): Promise<void> {
|
|
52
|
-
try {
|
|
53
|
-
if (enabled) {
|
|
54
|
-
await loadPluginServer(pluginId);
|
|
55
|
-
// A later success clears an earlier failure, or the pane would keep
|
|
56
|
-
// reporting a fault the user has already fixed.
|
|
57
|
-
notePluginLoadFailure(pluginId, null);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
await disposePlugin(pluginId);
|
|
61
|
-
notePluginLoadFailure(pluginId, null);
|
|
62
|
-
} catch (error) {
|
|
63
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
64
|
-
notePluginLoadFailure(pluginId, reason);
|
|
65
|
-
console.error(`[plugins] ${pluginId}: server half ${enabled ? 'load' : 'unload'} failed — ${reason}`);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
43
|
export async function action({ request }: ActionFunctionArgs) {
|
|
70
44
|
if (request.method !== 'POST') return methodNotAllowed({ request, params: {} });
|
|
71
45
|
|
|
@@ -152,45 +126,43 @@ export async function action({ request }: ActionFunctionArgs) {
|
|
|
152
126
|
return json({ ok: true, ...(await discoverPanelPlugins()) });
|
|
153
127
|
}
|
|
154
128
|
|
|
155
|
-
if (type === '
|
|
129
|
+
if (type === 'update') {
|
|
156
130
|
const pluginId = typeof body.pluginId === 'string' ? body.pluginId.trim() : '';
|
|
157
131
|
if (!pluginId) return json({ error: 'A plugin id is required.' }, { status: 400 });
|
|
158
132
|
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
//
|
|
162
|
-
//
|
|
163
|
-
await
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
// refusal is about what an update WOULD do. Its server half goes back up
|
|
168
|
-
// either way, or a failed update would leave a working plugin inert.
|
|
169
|
-
await syncPluginServer(pluginId, true);
|
|
170
|
-
return json({ error: result.error, ...(await discoverPanelPlugins()) }, { status: 400 });
|
|
171
|
-
}
|
|
172
|
-
await syncPluginServer(pluginId, true);
|
|
173
|
-
// The freshness this update just achieved is written rather than probed
|
|
174
|
-
// again: the commit is known, and a second round trip could only disagree
|
|
175
|
-
// with the reset that already happened.
|
|
176
|
-
writeGitStatus(pluginId, {
|
|
177
|
-
current: result.commit ?? null,
|
|
178
|
-
latest: result.commit ?? null,
|
|
179
|
-
updateAvailable: false,
|
|
180
|
-
checkedAt: Date.now(),
|
|
181
|
-
});
|
|
182
|
-
// The statuses and the rebuilt bundle both travel on the scan payload, and
|
|
183
|
-
// the server-half reload above may have scanned in between — so the cache is
|
|
184
|
-
// dropped once more here, right before the read that answers the caller, and
|
|
185
|
-
// the topic is republished for the same reason `check_updates` does it: a
|
|
186
|
-
// stale topic snapshot wins over the response on the client.
|
|
133
|
+
// One button for both sources: a git clone is fetched and reset, a bundled
|
|
134
|
+
// install takes the store's copy under the sync's own edit gate. The
|
|
135
|
+
// unload/reload around the files and the freshness write live in
|
|
136
|
+
// `updatePanelPlugin`, so this branch only translates the outcome.
|
|
137
|
+
const result = await updatePanelPlugin(pluginId);
|
|
138
|
+
// The scan holds what either update moved — files, versions, the refusal
|
|
139
|
+
// record — and a stale topic snapshot WINS over the response on the client,
|
|
140
|
+
// so the topic is republished rather than only answered.
|
|
187
141
|
invalidatePanelScan();
|
|
188
142
|
emitRealtimeSignal('panels-changed');
|
|
189
143
|
const payload = await discoverPanelPlugins();
|
|
144
|
+
if (result.error) return json({ error: result.error, ...payload }, { status: 400 });
|
|
190
145
|
if (result.warning) return json({ ok: true, error: result.warning, ...payload });
|
|
191
146
|
return json({ ok: true, updated: result.updated, ...payload });
|
|
192
147
|
}
|
|
193
148
|
|
|
149
|
+
if (type === 'update_all') {
|
|
150
|
+
const result = await updateAllPanelPlugins();
|
|
151
|
+
invalidatePanelScan();
|
|
152
|
+
emitRealtimeSignal('panels-changed');
|
|
153
|
+
const payload = await discoverPanelPlugins();
|
|
154
|
+
// A refusal is answered 200 where the pass ALSO updated something: one
|
|
155
|
+
// plugin with local edits must not hide the others' success. The reasons
|
|
156
|
+
// travel in `error` (the pane's warning banner) and, for a blocked bundled
|
|
157
|
+
// copy, in `syncBlocked` beside it.
|
|
158
|
+
const notes = [
|
|
159
|
+
...result.refused.map((entry) => entry.error),
|
|
160
|
+
...result.warnings.map((entry) => `${entry.pluginId}: ${entry.warning}`),
|
|
161
|
+
];
|
|
162
|
+
if (notes.length > 0) return json({ ok: true, error: notes.join(' · '), ...payload });
|
|
163
|
+
return json({ ok: true, ...payload });
|
|
164
|
+
}
|
|
165
|
+
|
|
194
166
|
if (type === 'force_sync') {
|
|
195
167
|
// The escape hatch for a blocked bundled sync: the user has seen which files
|
|
196
168
|
// differ and asked for the store's copy anyway. Answered with the whole
|
|
@@ -101,7 +101,10 @@ export { getMarketplacePluginsDir };
|
|
|
101
101
|
* - the loaded plugins are DISPOSED, because the loader's registry is
|
|
102
102
|
* process-wide and a plugin from one test would still answer in the next;
|
|
103
103
|
* - the load-failure list is cleared, because it is global too and a leftover
|
|
104
|
-
* entry makes a later "no errors" assertion pass or fail for the wrong reason
|
|
104
|
+
* entry makes a later "no errors" assertion pass or fail for the wrong reason;
|
|
105
|
+
* - the freshness cache is cleared, because it is a `globalThis` map that any
|
|
106
|
+
* other suite's git probe writes to — a leftover status made this suite's
|
|
107
|
+
* "nothing to probe" assertion read a plugin it never installed.
|
|
105
108
|
*/
|
|
106
109
|
export function usePanelRouteFixtures(): void {
|
|
107
110
|
beforeEach(async () => {
|
|
@@ -110,12 +113,14 @@ export function usePanelRouteFixtures(): void {
|
|
|
110
113
|
process.env.KABMO_MARKETPLACE_DIR = dirs.root;
|
|
111
114
|
process.env.KABMO_BUNDLED_MARKETPLACE_DIR = dirs.bundled;
|
|
112
115
|
await isolateDb();
|
|
116
|
+
globalThis.__kabmoPanelGitStatus?.clear();
|
|
113
117
|
invalidatePanelScan();
|
|
114
118
|
});
|
|
115
119
|
|
|
116
120
|
afterEach(async () => {
|
|
117
121
|
await disposeAllPlugins();
|
|
118
122
|
globalThis.__kabmoPluginLoadErrors = undefined;
|
|
123
|
+
globalThis.__kabmoPanelGitStatus?.clear();
|
|
119
124
|
await releaseDb();
|
|
120
125
|
delete process.env.KABMO_MARKETPLACE_DIR;
|
|
121
126
|
delete process.env.KABMO_BUNDLED_MARKETPLACE_DIR;
|
|
@@ -33,10 +33,9 @@ import { join } from 'node:path';
|
|
|
33
33
|
import { loader as bundleLoader } from '@/server/routes/panels/bundle';
|
|
34
34
|
import { loader as iconLoader } from '@/server/routes/panels/icon';
|
|
35
35
|
import { loader as readmeLoader } from '@/server/routes/panels/readme';
|
|
36
|
-
import { action as installAction } from '@/server/routes/panels/install';
|
|
37
36
|
import { discoverPanelPlugins, getMarketplacePluginsDir, invalidatePanelScan } from '@/server/lib/panels/registry.server';
|
|
38
37
|
import { setPluginEnabled } from '@/server/lib/panels/state.server';
|
|
39
|
-
import { call, dirs,
|
|
38
|
+
import { call, dirs, usePanelRouteFixtures, writePlugin } from '@/server/routes/panels/panel-routes.test-util';
|
|
40
39
|
|
|
41
40
|
usePanelRouteFixtures();
|
|
42
41
|
|
|
@@ -134,122 +133,6 @@ describe('the README route', () => {
|
|
|
134
133
|
});
|
|
135
134
|
});
|
|
136
135
|
|
|
137
|
-
describe('the install route', () => {
|
|
138
|
-
test('forget drops a dangling catalog entry and reports the scan without it', async () => {
|
|
139
|
-
// The reported state: the catalog names a directory that is not there, so
|
|
140
|
-
// the scan rejects it and the pane has a dead-end row.
|
|
141
|
-
writePlugin('other', getMarketplacePluginsDir());
|
|
142
|
-
fs.mkdirSync(dirs.root, { recursive: true });
|
|
143
|
-
fs.writeFileSync(
|
|
144
|
-
join(dirs.root, 'marketplace.json'),
|
|
145
|
-
JSON.stringify({
|
|
146
|
-
name: 'Kabmo',
|
|
147
|
-
plugins: [
|
|
148
|
-
{ name: 'ghost', source: 'plugins/ghost' },
|
|
149
|
-
{ name: 'other', source: 'plugins/other' },
|
|
150
|
-
],
|
|
151
|
-
}),
|
|
152
|
-
);
|
|
153
|
-
invalidatePanelScan();
|
|
154
|
-
expect((await discoverPanelPlugins()).errors.map((error) => error.source)).toEqual(['plugins/ghost']);
|
|
155
|
-
|
|
156
|
-
const response = await post(installAction, { type: 'forget', source: 'plugins/ghost' });
|
|
157
|
-
expect(response.status).toBe(200);
|
|
158
|
-
const body = (await response.json()) as { ok: boolean; errors: unknown[] };
|
|
159
|
-
expect(body.ok).toBe(true);
|
|
160
|
-
// The whole payload comes back, so the pane clears the row without a second
|
|
161
|
-
// read that could race the write.
|
|
162
|
-
expect(body.errors).toEqual([]);
|
|
163
|
-
|
|
164
|
-
const catalog = JSON.parse(fs.readFileSync(join(dirs.root, 'marketplace.json'), 'utf8')) as {
|
|
165
|
-
name: string;
|
|
166
|
-
plugins: Array<{ source: string }>;
|
|
167
|
-
};
|
|
168
|
-
expect(catalog.plugins.map((entry) => entry.source)).toEqual(['plugins/other']);
|
|
169
|
-
expect(catalog.name).toBe('Kabmo');
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
test('forget refuses a source that is missing or escapes the marketplace', async () => {
|
|
173
|
-
expect((await post(installAction, { type: 'forget' })).status).toBe(400);
|
|
174
|
-
expect((await post(installAction, { type: 'forget', source: '../../etc' })).status).toBe(400);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
test('forget leaves the directory alone when one is there', async () => {
|
|
178
|
-
// The repair for a MISSING directory must not become a delete: only the
|
|
179
|
-
// remove action may touch files.
|
|
180
|
-
const dir = writePlugin('demo', getMarketplacePluginsDir());
|
|
181
|
-
fs.mkdirSync(dirs.root, { recursive: true });
|
|
182
|
-
fs.writeFileSync(
|
|
183
|
-
join(dirs.root, 'marketplace.json'),
|
|
184
|
-
JSON.stringify({ plugins: [{ name: 'demo', source: 'plugins/demo' }] }),
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
expect((await post(installAction, { type: 'forget', source: 'plugins/demo' })).status).toBe(200);
|
|
188
|
-
expect(fs.existsSync(dir)).toBe(true);
|
|
189
|
-
// The plugin still loads — the directory is what makes it exist.
|
|
190
|
-
invalidatePanelScan();
|
|
191
|
-
expect((await discoverPanelPlugins()).plugins.map((plugin) => plugin.pluginId)).toEqual(['demo']);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
test('set_auto_update flips the flag and answers with the payload', async () => {
|
|
195
|
-
const on = await post(installAction, { type: 'set_auto_update', enabled: true });
|
|
196
|
-
expect(on.status).toBe(200);
|
|
197
|
-
const body = (await on.json()) as { ok: boolean; autoUpdate: boolean };
|
|
198
|
-
expect(body.ok).toBe(true);
|
|
199
|
-
expect(body.autoUpdate).toBe(true);
|
|
200
|
-
|
|
201
|
-
const off = await post(installAction, { type: 'set_auto_update', enabled: false });
|
|
202
|
-
expect(((await off.json()) as { autoUpdate: boolean }).autoUpdate).toBe(false);
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
test('check_updates answers even with nothing to probe', async () => {
|
|
206
|
-
// The button is disabled with no git plugins, but the route must not throw
|
|
207
|
-
// for a stale client that asks anyway.
|
|
208
|
-
writePlugin('demo', getMarketplacePluginsDir());
|
|
209
|
-
invalidatePanelScan();
|
|
210
|
-
|
|
211
|
-
const response = await post(installAction, { type: 'check_updates' });
|
|
212
|
-
expect(response.status).toBe(200);
|
|
213
|
-
const body = (await response.json()) as { ok: boolean; gitStatus: Record<string, unknown> };
|
|
214
|
-
expect(body.ok).toBe(true);
|
|
215
|
-
expect(body.gitStatus).toEqual({});
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
test('update_git refuses a plugin that is not a clone', async () => {
|
|
219
|
-
writePlugin('demo', getMarketplacePluginsDir());
|
|
220
|
-
invalidatePanelScan();
|
|
221
|
-
|
|
222
|
-
const response = await post(installAction, { type: 'update_git', pluginId: 'demo' });
|
|
223
|
-
expect(response.status).toBe(400);
|
|
224
|
-
expect(((await response.json()) as { error: string }).error).toContain('not a git clone');
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
test('update_git requires a plugin id', async () => {
|
|
228
|
-
expect((await post(installAction, { type: 'update_git' })).status).toBe(400);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
test('force_sync refuses a plugin that is not a bundled install', async () => {
|
|
232
|
-
writePlugin('demo', getMarketplacePluginsDir());
|
|
233
|
-
invalidatePanelScan();
|
|
234
|
-
|
|
235
|
-
const response = await post(installAction, { type: 'force_sync', pluginId: 'demo' });
|
|
236
|
-
expect(response.status).toBe(400);
|
|
237
|
-
expect(((await response.json()) as { error: string }).error).toContain('No bundled plugin');
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
test('force_sync requires a plugin id', async () => {
|
|
241
|
-
expect((await post(installAction, { type: 'force_sync' })).status).toBe(400);
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
test('the payload carries an empty syncBlocked by default', async () => {
|
|
245
|
-
writePlugin('demo', getMarketplacePluginsDir());
|
|
246
|
-
invalidatePanelScan();
|
|
247
|
-
// The field is always present, so the pane's notice has one shape to read
|
|
248
|
-
// rather than two (absent versus empty).
|
|
249
|
-
expect((await discoverPanelPlugins()).syncBlocked).toEqual({});
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
|
|
253
136
|
describe('the bundled store is reachable', () => {
|
|
254
137
|
test('an uninstalled store plugin serves its icon and README', async () => {
|
|
255
138
|
// The store card has to draw the mark and open the details BEFORE the plugin
|