@kabmo-labs/kabmo 0.19.0 → 0.21.0
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 +362 -362
- package/dist/client/static/js/{index-sxdw908m.css → index-0721wrkf.css} +1 -1
- package/dist/client/static/js/{index-fcee4c13.js → index-zg32n2sk.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 +8 -7
- package/src/shared/lib/icons/icon-paint-css.ts +2 -1
- package/src/shared/lib/icons/icon-paint-panel.ts +16 -7
- 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,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The dispatch the pane's Update buttons go through.
|
|
8
|
+
*
|
|
9
|
+
* `updatePanelPlugin` is the one entry point for both sources, so the cases that
|
|
10
|
+
* matter are the ones a per-source button would have got wrong: a git clone is
|
|
11
|
+
* fetched and reset AND its freshness is written (a stale status would leave the
|
|
12
|
+
* card offering the update it just applied), while a directory with no source is
|
|
13
|
+
* refused by name rather than silently succeeding.
|
|
14
|
+
*
|
|
15
|
+
* `updateAllPanelPlugins` probes before it fetches: only a clone that is actually
|
|
16
|
+
* behind is moved, so an up-to-date one costs a ref lookup and nothing else.
|
|
17
|
+
*
|
|
18
|
+
* Driven against REAL git repositories, like `git-update.server.test.ts`.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { afterEach, beforeEach, describe, expect, setDefaultTimeout, test } from 'bun:test';
|
|
22
|
+
import fs from 'node:fs';
|
|
23
|
+
import { tmpdir } from 'node:os';
|
|
24
|
+
import { join } from 'node:path';
|
|
25
|
+
|
|
26
|
+
import { installPanelPluginFromGit } from '@/server/lib/panels/install.server';
|
|
27
|
+
import { installPanelPluginFromBundled } from '@/server/lib/panels/install.server';
|
|
28
|
+
import { updateAllPanelPlugins, updatePanelPlugin } from '@/server/lib/panels/update.server';
|
|
29
|
+
import { readGitStatus } from '@/server/lib/panels/git-status.server';
|
|
30
|
+
import { invalidatePanelScan } from '@/server/lib/panels/registry.server';
|
|
31
|
+
import { removeDir } from '@/test-support/remove-dir';
|
|
32
|
+
import { isolateDb, releaseDb } from '@/test-support/isolated-db';
|
|
33
|
+
|
|
34
|
+
const hasGit = Boolean(Bun.which('git'));
|
|
35
|
+
|
|
36
|
+
/** Real git processes plus a plugin build; see the note in the sibling suite. */
|
|
37
|
+
setDefaultTimeout(30_000);
|
|
38
|
+
|
|
39
|
+
let work = '';
|
|
40
|
+
let root = '';
|
|
41
|
+
let store = '';
|
|
42
|
+
|
|
43
|
+
const VALID = { id: 'from-git', name: 'From Git', version: '1.0.0', app: 'dist/app.js' };
|
|
44
|
+
|
|
45
|
+
function git(dir: string, args: string[]): void {
|
|
46
|
+
Bun.spawnSync(['git', '-C', dir, ...args], { stdout: 'pipe', stderr: 'pipe' });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function makeRepo(): string {
|
|
50
|
+
const dir = fs.mkdtempSync(join(work, 'repo-'));
|
|
51
|
+
fs.writeFileSync(join(dir, 'kabmo.json'), JSON.stringify(VALID));
|
|
52
|
+
fs.mkdirSync(join(dir, 'dist'), { recursive: true });
|
|
53
|
+
fs.writeFileSync(join(dir, 'dist', 'app.js'), 'export default {};');
|
|
54
|
+
git(dir, ['init', '-q']);
|
|
55
|
+
git(dir, ['config', 'core.autocrlf', 'false']);
|
|
56
|
+
git(dir, ['config', 'core.eol', 'lf']);
|
|
57
|
+
git(dir, ['config', 'user.email', 'test@example.com']);
|
|
58
|
+
git(dir, ['config', 'user.name', 'Test']);
|
|
59
|
+
git(dir, ['add', '-A']);
|
|
60
|
+
git(dir, ['commit', '-q', '-m', 'init']);
|
|
61
|
+
return dir;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function advance(repo: string, version: string): void {
|
|
65
|
+
fs.writeFileSync(join(repo, 'kabmo.json'), JSON.stringify({ ...VALID, version }));
|
|
66
|
+
git(repo, ['add', '-A']);
|
|
67
|
+
git(repo, ['commit', '-q', '-m', `v${version}`]);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
beforeEach(async () => {
|
|
71
|
+
work = fs.mkdtempSync(join(tmpdir(), 'omp-panels-update-repos-'));
|
|
72
|
+
root = fs.mkdtempSync(join(tmpdir(), 'omp-panels-update-work-'));
|
|
73
|
+
store = fs.mkdtempSync(join(tmpdir(), 'omp-panels-update-store-'));
|
|
74
|
+
process.env.KABMO_MARKETPLACE_DIR = root;
|
|
75
|
+
process.env.KABMO_BUNDLED_MARKETPLACE_DIR = store;
|
|
76
|
+
// The baselines and the refusal records live in `app_settings`, so a suite
|
|
77
|
+
// without this reads — and writes — the developer's own database, and the
|
|
78
|
+
// edit gate then answers from another install's history.
|
|
79
|
+
await isolateDb();
|
|
80
|
+
globalThis.__kabmoPanelGitStatus?.clear();
|
|
81
|
+
invalidatePanelScan();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
afterEach(async () => {
|
|
85
|
+
delete process.env.KABMO_MARKETPLACE_DIR;
|
|
86
|
+
delete process.env.KABMO_BUNDLED_MARKETPLACE_DIR;
|
|
87
|
+
// The freshness cache is a `globalThis` map, so a status this suite wrote
|
|
88
|
+
// would outlive it and answer for a plugin another suite never probed.
|
|
89
|
+
globalThis.__kabmoPanelGitStatus?.clear();
|
|
90
|
+
await releaseDb();
|
|
91
|
+
invalidatePanelScan();
|
|
92
|
+
for (const dir of [work, root, store]) removeDir(dir);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
function installedVersion(pluginId: string): string {
|
|
96
|
+
const manifest = JSON.parse(fs.readFileSync(join(root, 'plugins', pluginId, 'kabmo.json'), 'utf8')) as {
|
|
97
|
+
version: string;
|
|
98
|
+
};
|
|
99
|
+
return manifest.version;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
describe('updatePanelPlugin on a git clone', () => {
|
|
103
|
+
test.skipIf(!hasGit)('moves the files and writes the freshness it just achieved', async () => {
|
|
104
|
+
const repo = makeRepo();
|
|
105
|
+
await installPanelPluginFromGit(repo);
|
|
106
|
+
advance(repo, '2.0.0');
|
|
107
|
+
|
|
108
|
+
const result = await updatePanelPlugin('from-git');
|
|
109
|
+
expect(result.updated).toBe(true);
|
|
110
|
+
expect(result.error).toBeUndefined();
|
|
111
|
+
expect(installedVersion('from-git')).toBe('2.0.0');
|
|
112
|
+
|
|
113
|
+
// The status must say CURRENT after the update: leaving the previous
|
|
114
|
+
// "behind" verdict would keep offering an update that already happened.
|
|
115
|
+
expect(readGitStatus('from-git')?.updateAvailable).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test.skipIf(!hasGit)('reports a dirty clone by name and touches nothing', async () => {
|
|
119
|
+
const repo = makeRepo();
|
|
120
|
+
await installPanelPluginFromGit(repo);
|
|
121
|
+
advance(repo, '2.0.0');
|
|
122
|
+
fs.writeFileSync(join(root, 'plugins', 'from-git', 'dist', 'app.js'), 'export default { edited: true };');
|
|
123
|
+
|
|
124
|
+
const result = await updatePanelPlugin('from-git');
|
|
125
|
+
expect(result.updated).toBe(false);
|
|
126
|
+
expect(result.error).toContain('uncommitted changes');
|
|
127
|
+
expect(installedVersion('from-git')).toBe('1.0.0');
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('updatePanelPlugin on a directory nothing publishes', () => {
|
|
132
|
+
test('refuses it by naming why', async () => {
|
|
133
|
+
const dir = join(root, 'plugins', 'plain');
|
|
134
|
+
fs.mkdirSync(join(dir, 'dist'), { recursive: true });
|
|
135
|
+
fs.writeFileSync(join(dir, 'kabmo.json'), JSON.stringify({ ...VALID, id: 'plain' }));
|
|
136
|
+
fs.writeFileSync(join(dir, 'dist', 'app.js'), 'export default {};');
|
|
137
|
+
|
|
138
|
+
const result = await updatePanelPlugin('plain');
|
|
139
|
+
expect(result.updated).toBe(false);
|
|
140
|
+
expect(result.error).toContain('local directory');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('refuses an id that is not installed at all', async () => {
|
|
144
|
+
expect((await updatePanelPlugin('ghost')).error).toContain('No installed plugin');
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe('updateAllPanelPlugins', () => {
|
|
149
|
+
test.skipIf(!hasGit)('updates a clone that is behind and leaves a current one alone', async () => {
|
|
150
|
+
const behind = makeRepo();
|
|
151
|
+
await installPanelPluginFromGit(behind);
|
|
152
|
+
advance(behind, '2.0.0');
|
|
153
|
+
|
|
154
|
+
// A second plugin whose remote never moved.
|
|
155
|
+
const current = fs.mkdtempSync(join(work, 'repo-'));
|
|
156
|
+
fs.writeFileSync(join(current, 'kabmo.json'), JSON.stringify({ ...VALID, id: 'current', name: 'Current' }));
|
|
157
|
+
fs.mkdirSync(join(current, 'dist'), { recursive: true });
|
|
158
|
+
fs.writeFileSync(join(current, 'dist', 'app.js'), 'export default {};');
|
|
159
|
+
git(current, ['init', '-q']);
|
|
160
|
+
git(current, ['config', 'core.autocrlf', 'false']);
|
|
161
|
+
git(current, ['config', 'user.email', 'test@example.com']);
|
|
162
|
+
git(current, ['config', 'user.name', 'Test']);
|
|
163
|
+
git(current, ['add', '-A']);
|
|
164
|
+
git(current, ['commit', '-q', '-m', 'init']);
|
|
165
|
+
await installPanelPluginFromGit(current);
|
|
166
|
+
|
|
167
|
+
invalidatePanelScan();
|
|
168
|
+
const outcome = await updateAllPanelPlugins();
|
|
169
|
+
|
|
170
|
+
expect(outcome.updated).toEqual(['from-git']);
|
|
171
|
+
expect(installedVersion('from-git')).toBe('2.0.0');
|
|
172
|
+
// The current clone was probed, found equal, and not fetched or reset.
|
|
173
|
+
expect(outcome.refused).toEqual([]);
|
|
174
|
+
expect(readGitStatus('current')?.updateAvailable).toBe(false);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('applies a store update for a bundled install', async () => {
|
|
178
|
+
// The store path of the same pass: installed 1.0.0, store ships 1.1.0.
|
|
179
|
+
const bundled = { ...VALID, id: 'demo', name: 'Demo' };
|
|
180
|
+
for (const dir of [join(root, 'plugins', 'demo'), join(store, 'plugins', 'demo')]) {
|
|
181
|
+
fs.mkdirSync(join(dir, 'dist'), { recursive: true });
|
|
182
|
+
fs.writeFileSync(join(dir, 'kabmo.json'), JSON.stringify(bundled));
|
|
183
|
+
fs.writeFileSync(join(dir, 'dist', 'app.js'), 'export default {};');
|
|
184
|
+
}
|
|
185
|
+
await installPanelPluginFromBundled('demo');
|
|
186
|
+
fs.writeFileSync(join(store, 'plugins', 'demo', 'kabmo.json'), JSON.stringify({ ...bundled, version: '1.1.0' }));
|
|
187
|
+
invalidatePanelScan();
|
|
188
|
+
|
|
189
|
+
const outcome = await updateAllPanelPlugins();
|
|
190
|
+
expect(outcome.updated).toContain('demo');
|
|
191
|
+
expect(installedVersion('demo')).toBe('1.1.0');
|
|
192
|
+
});
|
|
193
|
+
});
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Bringing one installed panel plugin — or all of them — up to whatever owns it.
|
|
8
|
+
*
|
|
9
|
+
* Two sources publish plugin updates and the pane offers ONE Update button, so
|
|
10
|
+
* the dispatch lives here rather than in the route: a git clone is fetched and
|
|
11
|
+
* reset to its remote's HEAD (`git-update.server.ts`), while a bundled install
|
|
12
|
+
* takes the store's copy (`sync.server.ts`) under the same edit gate the boot
|
|
13
|
+
* pass uses. A directory with neither source is refused by name — "nothing
|
|
14
|
+
* updates it" is a fact the reader needs, not a silent no-op.
|
|
15
|
+
*
|
|
16
|
+
* Every update unloads the plugin's SERVER half BEFORE the files move and
|
|
17
|
+
* reloads it afterwards, and only when it was loaded to begin with: the module
|
|
18
|
+
* is already imported and its registrations are live, so a half that kept
|
|
19
|
+
* running would answer from code the directory no longer holds — while loading
|
|
20
|
+
* one that was never running (a disabled plugin, or one with no server entry)
|
|
21
|
+
* would invent a half the user switched off.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { join } from 'path';
|
|
25
|
+
import { pathExists } from '@/server/lib/omp/core/paths';
|
|
26
|
+
import {
|
|
27
|
+
discoverPanelPlugins,
|
|
28
|
+
getBundledMarketplaceDir,
|
|
29
|
+
getMarketplacePluginsDir,
|
|
30
|
+
invalidatePanelScan,
|
|
31
|
+
} from '@/server/lib/panels/registry.server';
|
|
32
|
+
import { readGitOrigin } from '@/server/lib/panels/git-clone.server';
|
|
33
|
+
import { probeGitUpdate, updateGitPlugin } from '@/server/lib/panels/git-update.server';
|
|
34
|
+
import { writeGitStatus } from '@/server/lib/panels/git-status.server';
|
|
35
|
+
import { syncBundledPlugins } from '@/server/lib/panels/sync.server';
|
|
36
|
+
import { loadedPlugin } from '@/server/lib/plugins/loader.server';
|
|
37
|
+
import { syncPluginServer } from '@/server/lib/plugins/server-half.server';
|
|
38
|
+
|
|
39
|
+
/** What one plugin's update did. */
|
|
40
|
+
export interface PanelUpdateOutcome {
|
|
41
|
+
pluginId: string;
|
|
42
|
+
/** True when files actually moved. */
|
|
43
|
+
updated: boolean;
|
|
44
|
+
/** The version or commit it was at, for a bundled update. */
|
|
45
|
+
from?: string;
|
|
46
|
+
/** The version or commit it moved to. */
|
|
47
|
+
to?: string;
|
|
48
|
+
/** Why nothing moved — a refusal names its reason. */
|
|
49
|
+
error?: string;
|
|
50
|
+
/** A rebuild that failed after the files moved. */
|
|
51
|
+
warning?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** What an update-all pass did, per plugin. */
|
|
55
|
+
export interface PanelUpdateAllOutcome {
|
|
56
|
+
/** Plugins whose files moved. */
|
|
57
|
+
updated: string[];
|
|
58
|
+
/** Plugins left as they were, with the reason. */
|
|
59
|
+
refused: Array<{ pluginId: string; error: string }>;
|
|
60
|
+
/** Updates that moved files but left a message, e.g. a failed rebuild. */
|
|
61
|
+
warnings: Array<{ pluginId: string; warning: string }>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Where an install's updates come from, read off the directory itself. */
|
|
65
|
+
async function sourceOf(pluginId: string, dir: string): Promise<'git' | 'bundled' | 'local'> {
|
|
66
|
+
if (await readGitOrigin(dir)) return 'git';
|
|
67
|
+
const storeDir = join(getBundledMarketplaceDir(), 'plugins', pluginId);
|
|
68
|
+
return (await pathExists(storeDir)) ? 'bundled' : 'local';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Bring ONE installed plugin up to its source.
|
|
73
|
+
*
|
|
74
|
+
* Never throws for an expected refusal (a dirty clone, a hand-edited bundled
|
|
75
|
+
* copy, a plugin that is not there): the answer is a value the pane reports.
|
|
76
|
+
*/
|
|
77
|
+
export async function updatePanelPlugin(pluginId: string): Promise<PanelUpdateOutcome> {
|
|
78
|
+
const dir = join(getMarketplacePluginsDir(), pluginId);
|
|
79
|
+
if (!(await pathExists(dir))) {
|
|
80
|
+
return { pluginId, updated: false, error: `No installed plugin with id "${pluginId}".` };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const source = await sourceOf(pluginId, dir);
|
|
84
|
+
if (source === 'local') {
|
|
85
|
+
return {
|
|
86
|
+
pluginId,
|
|
87
|
+
updated: false,
|
|
88
|
+
error: `${pluginId} is a local directory — it has no remote and the store does not ship it, so nothing publishes an update for it.`,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Read BEFORE the unload: after it, the registry can no longer say whether
|
|
93
|
+
// this plugin's server half was running.
|
|
94
|
+
const wasLoaded = loadedPlugin(pluginId) !== undefined;
|
|
95
|
+
await syncPluginServer(pluginId, false);
|
|
96
|
+
try {
|
|
97
|
+
return source === 'git' ? await updateFromRemote(pluginId) : await updateFromStore(pluginId);
|
|
98
|
+
} finally {
|
|
99
|
+
if (wasLoaded) await syncPluginServer(pluginId, true);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Fetch the remote's HEAD, move the clone to it, rebuild. */
|
|
104
|
+
async function updateFromRemote(pluginId: string): Promise<PanelUpdateOutcome> {
|
|
105
|
+
const result = await updateGitPlugin(pluginId);
|
|
106
|
+
if (!result.ok) return { pluginId, updated: false, error: result.error };
|
|
107
|
+
|
|
108
|
+
// The freshness this update just achieved is WRITTEN rather than probed
|
|
109
|
+
// again: the commit is known, and a second round trip could only disagree
|
|
110
|
+
// with the reset that already happened.
|
|
111
|
+
writeGitStatus(pluginId, {
|
|
112
|
+
current: result.commit ?? null,
|
|
113
|
+
latest: result.commit ?? null,
|
|
114
|
+
updateAvailable: false,
|
|
115
|
+
checkedAt: Date.now(),
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
pluginId,
|
|
119
|
+
updated: result.updated,
|
|
120
|
+
...(result.commit ? { to: result.commit } : {}),
|
|
121
|
+
...(result.warning ? { warning: result.warning } : {}),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Apply the store's copy under the sync's own gate.
|
|
127
|
+
*
|
|
128
|
+
* The gate — not the caller — decides whether anything is applied: a tree the
|
|
129
|
+
* user edited is REFUSED here exactly as it is at boot, and the files that
|
|
130
|
+
* differ are named so the pane's blocked notice can offer the override. An
|
|
131
|
+
* update button that overwrote them would be the force-sync escape hatch
|
|
132
|
+
* without the warning.
|
|
133
|
+
*/
|
|
134
|
+
async function updateFromStore(pluginId: string): Promise<PanelUpdateOutcome> {
|
|
135
|
+
const synced = await syncBundledPlugins({ only: pluginId });
|
|
136
|
+
|
|
137
|
+
const failure = synced.failed.find((entry) => entry.pluginId === pluginId);
|
|
138
|
+
if (failure) return { pluginId, updated: false, error: failure.error };
|
|
139
|
+
|
|
140
|
+
const blocked = synced.blocked.find((entry) => entry.pluginId === pluginId);
|
|
141
|
+
if (blocked) return { pluginId, updated: false, error: blockedReason(pluginId, blocked.changed.length) };
|
|
142
|
+
|
|
143
|
+
const applied = synced.updated.find((entry) => entry.pluginId === pluginId);
|
|
144
|
+
if (!applied) return { pluginId, updated: false };
|
|
145
|
+
return {
|
|
146
|
+
pluginId,
|
|
147
|
+
updated: true,
|
|
148
|
+
from: applied.from,
|
|
149
|
+
to: applied.to,
|
|
150
|
+
...(applied.warning ? { warning: applied.warning } : {}),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Apply every update that is actually available, and report each one.
|
|
156
|
+
*
|
|
157
|
+
* Git clones are PROBED first and only the ones behind are fetched-and-reset:
|
|
158
|
+
* an update against a clone already at its remote's HEAD would be a network
|
|
159
|
+
* round trip that changes nothing.
|
|
160
|
+
*
|
|
161
|
+
* Bundled installs run one pass over the store — the same pass the boot runs —
|
|
162
|
+
* and only the plugins it actually moved are reloaded afterwards. Unloading
|
|
163
|
+
* every bundled server half BEFORE the pass would be the safer ordering for a
|
|
164
|
+
* plugin that is about to be replaced, but it also stops the panels of every
|
|
165
|
+
* bundled plugin on a pass that usually changes nothing; the pass replaces
|
|
166
|
+
* files rather than removing them, so the reload afterwards is what keeps the
|
|
167
|
+
* running code honest.
|
|
168
|
+
*/
|
|
169
|
+
export async function updateAllPanelPlugins(): Promise<PanelUpdateAllOutcome> {
|
|
170
|
+
const outcome: PanelUpdateAllOutcome = { updated: [], refused: [], warnings: [] };
|
|
171
|
+
const { plugins } = await discoverPanelPlugins();
|
|
172
|
+
|
|
173
|
+
const record = (result: PanelUpdateOutcome): void => {
|
|
174
|
+
if (result.updated) outcome.updated.push(result.pluginId);
|
|
175
|
+
if (result.error) outcome.refused.push({ pluginId: result.pluginId, error: result.error });
|
|
176
|
+
if (result.warning) outcome.warnings.push({ pluginId: result.pluginId, warning: result.warning });
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
for (const plugin of plugins) {
|
|
180
|
+
if (!plugin.gitOrigin) continue;
|
|
181
|
+
const status = await probeGitUpdate(plugin.pluginId);
|
|
182
|
+
writeGitStatus(plugin.pluginId, status);
|
|
183
|
+
if (!status.updateAvailable) continue;
|
|
184
|
+
record(await updatePanelPlugin(plugin.pluginId));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const synced = await syncBundledPlugins();
|
|
188
|
+
for (const entry of synced.updated) {
|
|
189
|
+
outcome.updated.push(entry.pluginId);
|
|
190
|
+
if (entry.warning) outcome.warnings.push({ pluginId: entry.pluginId, warning: entry.warning });
|
|
191
|
+
// Reload only a half that was RUNNING: loading one that was not would switch
|
|
192
|
+
// a disabled plugin's routes on behind the switch that says off.
|
|
193
|
+
if (loadedPlugin(entry.pluginId)) {
|
|
194
|
+
await syncPluginServer(entry.pluginId, false);
|
|
195
|
+
await syncPluginServer(entry.pluginId, true);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
for (const entry of synced.blocked) {
|
|
199
|
+
outcome.refused.push({ pluginId: entry.pluginId, error: blockedReason(entry.pluginId, entry.changed.length) });
|
|
200
|
+
}
|
|
201
|
+
for (const entry of synced.failed) outcome.refused.push(entry);
|
|
202
|
+
|
|
203
|
+
invalidatePanelScan();
|
|
204
|
+
return outcome;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** The one sentence a refused bundled update reports, so both callers agree. */
|
|
208
|
+
function blockedReason(pluginId: string, changed: number): string {
|
|
209
|
+
return `${pluginId} has local changes in ${changed} file${changed === 1 ? '' : 's'}, so its bundled update is paused. Nothing was replaced.`;
|
|
210
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Bringing one plugin's SERVER half in line with its on-disk state, now.
|
|
8
|
+
*
|
|
9
|
+
* The half is otherwise loaded once at boot (`loadPluginServers` in the entry),
|
|
10
|
+
* so every action that moves a plugin's files or its enablement — install,
|
|
11
|
+
* remove, enable, disable, update — has to load or unload it itself. Without
|
|
12
|
+
* this the plugin's routes, RPC methods and realtime topic stay registered
|
|
13
|
+
* against code the directory no longer holds: a panel that installed cleanly and
|
|
14
|
+
* then answered "no plugin is loaded", or a Stats panel stuck on "No sample
|
|
15
|
+
* yet." with nothing on screen to explain it.
|
|
16
|
+
*
|
|
17
|
+
* Never throws: a plugin whose server half cannot load is a plugin whose PANEL
|
|
18
|
+
* still works, and the failure is recorded through `notePluginLoadFailure` — the
|
|
19
|
+
* same list `GET /api/plugins/state` serves to the pane — so the reader sees
|
|
20
|
+
* WHY. Folding it into a 4xx at the call site would hide a successful install
|
|
21
|
+
* behind an unrelated fault.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { disposePlugin, loadPluginServer, notePluginLoadFailure } from '@/server/lib/plugins/loader.server';
|
|
25
|
+
|
|
26
|
+
export async function syncPluginServer(pluginId: string, enabled: boolean): Promise<void> {
|
|
27
|
+
try {
|
|
28
|
+
if (enabled) {
|
|
29
|
+
await loadPluginServer(pluginId);
|
|
30
|
+
// A later success clears an earlier failure, or the pane would keep
|
|
31
|
+
// reporting a fault the user has already fixed.
|
|
32
|
+
notePluginLoadFailure(pluginId, null);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
await disposePlugin(pluginId);
|
|
36
|
+
notePluginLoadFailure(pluginId, null);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
39
|
+
notePluginLoadFailure(pluginId, reason);
|
|
40
|
+
console.error(`[plugins] ${pluginId}: server half ${enabled ? 'load' : 'unload'} failed — ${reason}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -59,9 +59,21 @@ function join(parts: Uint8Array[]): Uint8Array {
|
|
|
59
59
|
return out;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* The numbered lines in `text`, in arrival order.
|
|
64
|
+
*
|
|
65
|
+
* A trailing line with no newline after it is NOT counted: it is a line still
|
|
66
|
+
* arriving, and its prefix is a number that happens to parse. The replay is
|
|
67
|
+
* captured mid-flood by construction, so it routinely ends inside a line —
|
|
68
|
+
* measured on the Linux gate, where the replay ended after the first two bytes
|
|
69
|
+
* of `5136` and this helper turned that fragment into the line `51`, failing
|
|
70
|
+
* `gap(replayed)` with `5135 -> 51 at 5134` on a terminal that was working. The
|
|
71
|
+
* same rule makes the live collectors safe for the same reason: a line counts
|
|
72
|
+
* once the shell has finished writing it.
|
|
73
|
+
*/
|
|
63
74
|
function numbers(text: string): number[] {
|
|
64
|
-
|
|
75
|
+
const complete = text.endsWith('\n') ? text : text.slice(0, text.lastIndexOf('\n') + 1);
|
|
76
|
+
return complete
|
|
65
77
|
.split('\n')
|
|
66
78
|
.map((line) => line.replace(/\r$/, '').trim())
|
|
67
79
|
.filter((line) => /^\d+$/.test(line))
|
|
@@ -122,11 +134,17 @@ test('a viewer attaching mid-stream sees the replay and live output exactly once
|
|
|
122
134
|
expect(replayed.length).toBeGreaterThan(0);
|
|
123
135
|
expect(gap(replayed)).toBeNull();
|
|
124
136
|
|
|
125
|
-
// …and its live stream
|
|
126
|
-
//
|
|
137
|
+
// …and the replay plus its live stream is ONE seamless rendering: no line
|
|
138
|
+
// twice, none skipped. Asserted on the CONCATENATION rather than by comparing
|
|
139
|
+
// `secondLines[0]` to the replay's last line, because the boundary is allowed
|
|
140
|
+
// to land inside a line — the replay is captured mid-flood, and measured on
|
|
141
|
+
// the Linux gate it ended two bytes into `5135`. A per-side comparison then
|
|
142
|
+
// reads that fragment as its own line and reports a gap on a working
|
|
143
|
+
// terminal; the concatenation is what the viewer actually renders, so a
|
|
144
|
+
// duplicate or a hole still fails here.
|
|
145
|
+
const combined = numbers(dec.decode(attachment.replay) + second.text());
|
|
127
146
|
expect(secondLines.length).toBeGreaterThan(0);
|
|
128
|
-
expect(
|
|
129
|
-
expect(
|
|
130
|
-
expect(
|
|
131
|
-
expect(secondLines.at(-1)).toBe(TOTAL);
|
|
147
|
+
expect(gap(combined)).toBeNull();
|
|
148
|
+
expect(new Set(combined).size).toBe(combined.length);
|
|
149
|
+
expect(combined.at(-1)).toBe(TOTAL);
|
|
132
150
|
}, 60_000);
|