dsh-multi-device-config-sync 0.0.0-stage → 1.6.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/LICENSE +21 -0
- package/README.md +105 -2
- package/assets/icon-256.png +0 -0
- package/client.js +1658 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +19 -0
- package/index.js +52 -0
- package/lib/backup.js +1087 -0
- package/lib/errors.js +67 -0
- package/lib/gist.js +343 -0
- package/lib/plugins.js +490 -0
- package/lib/routes.js +507 -0
- package/lib/store.js +73 -0
- package/lib/sync-install.js +231 -0
- package/lib/tool.js +191 -0
- package/locale/en.json +24 -0
- package/locale/zh.json +24 -0
- package/package.json +66 -4
- package/test/activation.test.mjs +141 -0
- package/test/client-decisions.test.mjs +55 -0
- package/test/client-registration.test.mjs +98 -0
- package/test/config-preview.test.mjs +454 -0
- package/test/first-run.test.mjs +104 -0
- package/test/harness.mjs +176 -0
- package/test/library.test.mjs +169 -0
- package/test/package.test.mjs +165 -0
- package/test/plugins.test.mjs +543 -0
- package/test/progress-client.test.mjs +225 -0
- package/test/progress-engine.test.mjs +235 -0
- package/test/progress-http.test.mjs +340 -0
- package/test/rename-compat.test.mjs +255 -0
- package/test/run.mjs +32 -0
- package/test/sync-install.test.mjs +338 -0
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two things a cross-machine restore has to get right besides the files.
|
|
3
|
+
*
|
|
4
|
+
* 1. A dependency spec that only resolves on the machine that wrote it must not
|
|
5
|
+
* travel. `link:E:/work/plugin` reaching another machine overwrites its own
|
|
6
|
+
* `^1.0.0` — the union merge lets the incoming side win — and every later
|
|
7
|
+
* `pnpm install` there fails on a path that does not exist.
|
|
8
|
+
* 2. A restore writes a manifest, not an installation. The plugins the manifest
|
|
9
|
+
* names have to be listed and installable, and a host that publishes no
|
|
10
|
+
* plugin manager has to be told apart from a host that says nothing is
|
|
11
|
+
* missing.
|
|
12
|
+
*
|
|
13
|
+
* The union guarantee is re-checked here as a regression: this plugin is only
|
|
14
|
+
* allowed to drop what it does not understand from an *export*, never to drop a
|
|
15
|
+
* local plugin during a restore.
|
|
16
|
+
*
|
|
17
|
+
* Everything is offline. The one host any check talks to is its own loopback
|
|
18
|
+
* stub, and the plugin manager is a local object.
|
|
19
|
+
*/
|
|
20
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
21
|
+
import { join } from 'node:path'
|
|
22
|
+
import { createReport, makeProfile, tempDir, useProfile, callRoute, serveHandler } from './harness.mjs'
|
|
23
|
+
|
|
24
|
+
const { check, finish } = createReport('plugins')
|
|
25
|
+
const backup = await import('../lib/backup.js')
|
|
26
|
+
const plugins = await import('../lib/plugins.js')
|
|
27
|
+
|
|
28
|
+
const workspace = tempDir('dpg-plugins-')
|
|
29
|
+
const home = join(workspace, 'home')
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The publisher's machine: one plugin is a local link into a checkout, another
|
|
33
|
+
* plugin is a plain registry range, and `dsh.profile.bundles` still names the
|
|
34
|
+
* linked plugin — the case the task requires to be left alone.
|
|
35
|
+
*/
|
|
36
|
+
const linkedCheckout = join(workspace, 'example-linked-plugin')
|
|
37
|
+
const linkedSpec = `link:${linkedCheckout.replaceAll('\\', '/')}`
|
|
38
|
+
mkdirSync(linkedCheckout, { recursive: true })
|
|
39
|
+
writeFileSync(join(linkedCheckout, 'package.json'), `${JSON.stringify({
|
|
40
|
+
name: 'example-linked-plugin',
|
|
41
|
+
version: '1.0.0',
|
|
42
|
+
}, null, 2)}\n`)
|
|
43
|
+
|
|
44
|
+
const linkedProfile = makeProfile(join(home, 'profiles', 'linked'), {
|
|
45
|
+
dependencies: { 'example-linked-plugin': linkedSpec, 'some-plugin': '^1.0.0' },
|
|
46
|
+
bundles: ['@deepseek-ai/dsh-base', 'example-linked-plugin'],
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
// ---- 1. what an upload must not carry ----------------------------------
|
|
50
|
+
useProfile(linkedProfile, home)
|
|
51
|
+
const exported = backup.exportBackupWithReport()
|
|
52
|
+
const manifestEntry = exported.backup.files.find(file => file.path === 'package.json')
|
|
53
|
+
const exportedDeps = manifestEntry.json.dependencies
|
|
54
|
+
|
|
55
|
+
check('a link: dependency is not in the exported document',
|
|
56
|
+
exportedDeps['example-linked-plugin'] === undefined, JSON.stringify(exportedDeps))
|
|
57
|
+
check('a normal semver dependency is untouched', exportedDeps['some-plugin'] === '^1.0.0', exportedDeps['some-plugin'])
|
|
58
|
+
check('nothing else in package.json changes',
|
|
59
|
+
manifestEntry.json.name === 'dsh-profile-test'
|
|
60
|
+
&& manifestEntry.json.private === true
|
|
61
|
+
&& JSON.stringify(manifestEntry.json.dsh.profile.bundles) === JSON.stringify(['@deepseek-ai/dsh-base', 'example-linked-plugin']),
|
|
62
|
+
JSON.stringify(manifestEntry.json))
|
|
63
|
+
check('the bundle list keeps the name whose dependency was dropped',
|
|
64
|
+
manifestEntry.json.dsh.profile.bundles.includes('example-linked-plugin'))
|
|
65
|
+
check('the drop is reported to the caller',
|
|
66
|
+
exported.dropped.length === 1 && exported.dropped[0].name === 'example-linked-plugin',
|
|
67
|
+
JSON.stringify(exported.dropped))
|
|
68
|
+
check('the report names the dropped spec', exported.dropped[0]?.spec === linkedSpec, exported.dropped[0]?.spec)
|
|
69
|
+
check('and the plugin it pointed at, read from its own package.json',
|
|
70
|
+
exported.dropped[0]?.package === 'example-linked-plugin' && exported.dropped[0]?.version === '1.0.0',
|
|
71
|
+
`${exported.dropped[0]?.package}@${exported.dropped[0]?.version}`)
|
|
72
|
+
check('the report carries an exclusion code, like every other exclusion',
|
|
73
|
+
exported.dropped[0]?.code === 'local-dependency', exported.dropped[0]?.code)
|
|
74
|
+
check('the document itself carries no extra top-level key',
|
|
75
|
+
Object.keys(exported.backup).sort().join() === 'createdAt,files,format,profile,version',
|
|
76
|
+
Object.keys(exported.backup).join())
|
|
77
|
+
check('the package.json entry carries no extra field',
|
|
78
|
+
Object.keys(manifestEntry).sort().join() === 'json,path', Object.keys(manifestEntry).join())
|
|
79
|
+
check('exportBackup still returns the document alone',
|
|
80
|
+
backup.exportBackup().format === backup.BACKUP_FORMAT && backup.exportBackup().dropped === undefined)
|
|
81
|
+
|
|
82
|
+
// An absolute path with no `link:` prefix is the other half of the same rule.
|
|
83
|
+
const absoluteProfile = makeProfile(join(home, 'profiles', 'absolute'), {
|
|
84
|
+
dependencies: {
|
|
85
|
+
'tarball-plugin': join(workspace, 'somewhere', 'tarball-plugin-1.0.0.tgz'),
|
|
86
|
+
'file-plugin': 'file:../file-plugin',
|
|
87
|
+
'workspace-plugin': 'workspace:*',
|
|
88
|
+
'registry-plugin': '1.2.3',
|
|
89
|
+
},
|
|
90
|
+
bundles: ['@deepseek-ai/dsh-base'],
|
|
91
|
+
})
|
|
92
|
+
useProfile(absoluteProfile, home)
|
|
93
|
+
const absolute = backup.exportBackupWithReport()
|
|
94
|
+
const absoluteDeps = absolute.backup.files.find(file => file.path === 'package.json').json.dependencies
|
|
95
|
+
check('an absolute-path spec is not in the exported document', absoluteDeps['tarball-plugin'] === undefined, JSON.stringify(absoluteDeps))
|
|
96
|
+
check('a file: spec is not either', absoluteDeps['file-plugin'] === undefined)
|
|
97
|
+
check('nor is a workspace: spec', absoluteDeps['workspace-plugin'] === undefined)
|
|
98
|
+
check('a registry spec beside them survives', absoluteDeps['registry-plugin'] === '1.2.3', absoluteDeps['registry-plugin'])
|
|
99
|
+
check('every drop is reported once', absolute.dropped.length === 3 && absolute.droppedEntries === 3,
|
|
100
|
+
`${absolute.dropped.length}/${absolute.droppedEntries}`)
|
|
101
|
+
check('a spec whose target is not there is still dropped, with no package claimed',
|
|
102
|
+
absolute.dropped.find(entry => entry.name === 'tarball-plugin')?.package === null,
|
|
103
|
+
JSON.stringify(absolute.dropped.find(entry => entry.name === 'tarball-plugin')))
|
|
104
|
+
check('the classifier agrees on the forms the task names', [
|
|
105
|
+
'link:../x', 'file:/a/b', 'portal:./x', 'workspace:*', 'E:/x', 'C:\\x', '/x', './x', '../x',
|
|
106
|
+
].every(spec => backup.isMachineLocalSpec(spec) === true))
|
|
107
|
+
check('and refuses a registry range, tag, or alias', [
|
|
108
|
+
'^1.0.0', '~2.1.0', 'latest', 'next', 'npm:@scope/name@1.0.0', 'github:someone/repo',
|
|
109
|
+
].every(spec => backup.isMachineLocalSpec(spec) === false))
|
|
110
|
+
|
|
111
|
+
// ---- 2. a restore still unions, never deletes ---------------------------
|
|
112
|
+
/**
|
|
113
|
+
* A document as another machine would publish it, naming `shared-plugin` and one
|
|
114
|
+
* plugin this machine has never seen. No machine-local spec is in it, because an
|
|
115
|
+
* upload cannot carry one — that is what section 1 proves.
|
|
116
|
+
*/
|
|
117
|
+
const incoming = {
|
|
118
|
+
format: backup.BACKUP_FORMAT,
|
|
119
|
+
version: backup.BACKUP_VERSION,
|
|
120
|
+
createdAt: '2026-01-01T00:00:00.000Z',
|
|
121
|
+
profile: 'other',
|
|
122
|
+
files: [{
|
|
123
|
+
path: 'package.json',
|
|
124
|
+
json: {
|
|
125
|
+
name: 'dsh-profile-test',
|
|
126
|
+
private: true,
|
|
127
|
+
dependencies: { 'shared-plugin': '^2.0.0', 'cloud-only-plugin': '3.0.0' },
|
|
128
|
+
dsh: { profile: { bundles: ['@deepseek-ai/dsh-base', 'cloud-only-plugin'] } },
|
|
129
|
+
},
|
|
130
|
+
}],
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// The target already has a plugin that exists nowhere else, declared as its own
|
|
134
|
+
// local link, plus a shared plugin pinned at its own spec.
|
|
135
|
+
const unionProfile = makeProfile(join(home, 'profiles', 'union'), {
|
|
136
|
+
dependencies: { 'local-only-plugin': 'link:../local-only-plugin', 'shared-plugin': '1.0.0' },
|
|
137
|
+
bundles: ['@deepseek-ai/dsh-base', 'local-only-plugin'],
|
|
138
|
+
})
|
|
139
|
+
useProfile(unionProfile, home)
|
|
140
|
+
check('the plan merges the manifest rather than replacing it', backup.planRestore(incoming).manifest !== null)
|
|
141
|
+
backup.applyRestore(incoming)
|
|
142
|
+
const merged = JSON.parse(readFileSync(join(unionProfile, 'package.json'), 'utf8'))
|
|
143
|
+
check('a local-only plugin survives a restore', merged.dependencies['local-only-plugin'] !== undefined,
|
|
144
|
+
JSON.stringify(merged.dependencies))
|
|
145
|
+
// Documented, not just asserted: the manifest merge spreads the current map first
|
|
146
|
+
// and the incoming one second, so when BOTH sides declare the same plugin the
|
|
147
|
+
// incoming spec wins. That is precisely the mechanism the export-side drop exists
|
|
148
|
+
// to make safe, and it is the behavior a reader of this file should know about.
|
|
149
|
+
check('the incoming spec wins for a plugin both sides declare',
|
|
150
|
+
merged.dependencies['shared-plugin'] === '^2.0.0', merged.dependencies['shared-plugin'])
|
|
151
|
+
check('a plugin only the cloud has is added', merged.dependencies['cloud-only-plugin'] === '3.0.0')
|
|
152
|
+
check('the bundle list is unioned, keeping the local-only name',
|
|
153
|
+
merged.dsh.profile.bundles.includes('local-only-plugin') && merged.dsh.profile.bundles.includes('cloud-only-plugin'),
|
|
154
|
+
JSON.stringify(merged.dsh.profile.bundles))
|
|
155
|
+
|
|
156
|
+
// The bug this change fixes, stated as a check: feed a target a document this
|
|
157
|
+
// plugin itself exported from the linked machine. The publisher's link: spec is
|
|
158
|
+
// not in it, so nothing here is overwritten with a path into another machine.
|
|
159
|
+
useProfile(linkedProfile, home)
|
|
160
|
+
const reexported = backup.exportBackup()
|
|
161
|
+
const freshProfile = makeProfile(join(home, 'profiles', 'fresh'), {
|
|
162
|
+
dependencies: { 'shared-plugin': '1.0.0' },
|
|
163
|
+
bundles: ['@deepseek-ai/dsh-base'],
|
|
164
|
+
})
|
|
165
|
+
useProfile(freshProfile, home)
|
|
166
|
+
backup.applyRestore(reexported)
|
|
167
|
+
const fresh = readFileSync(join(freshProfile, 'package.json'), 'utf8')
|
|
168
|
+
check('restoring a real upload carries no machine-local spec',
|
|
169
|
+
!fresh.includes('link:') && !fresh.includes(linkedCheckout.replaceAll('\\', '/')), fresh)
|
|
170
|
+
check('and the plugin the publisher dropped does not appear as a dependency',
|
|
171
|
+
JSON.parse(fresh).dependencies['example-linked-plugin'] === undefined, fresh)
|
|
172
|
+
check('while the rest of the publisher’s manifest does arrive',
|
|
173
|
+
JSON.parse(fresh).dependencies['some-plugin'] === '^1.0.0', fresh)
|
|
174
|
+
|
|
175
|
+
// ---- 3. the missing-plugin computation ---------------------------------
|
|
176
|
+
useProfile(linkedProfile, home)
|
|
177
|
+
check('declared plugins come from dependencies first, in manifest order',
|
|
178
|
+
plugins.declaredPlugins(linkedProfile)[0]?.name === 'example-linked-plugin'
|
|
179
|
+
&& plugins.declaredPlugins(linkedProfile)[0]?.kind === 'both',
|
|
180
|
+
JSON.stringify(plugins.declaredPlugins(linkedProfile)))
|
|
181
|
+
check('a name only the bundle list declares is still declared',
|
|
182
|
+
plugins.declaredPlugins(unionProfile).some(entry => entry.name === 'local-only-plugin'),
|
|
183
|
+
JSON.stringify(plugins.declaredPlugins(unionProfile).map(entry => entry.name)))
|
|
184
|
+
|
|
185
|
+
/** A plugin manager double; omitted rows stay omitted the way a host would. */
|
|
186
|
+
function stubManager({ plugins: rows = null, bundles = [], installBehavior = null } = {}) {
|
|
187
|
+
const installed = []
|
|
188
|
+
const state = { bundles: new Map(bundles.map(bundle => [bundle.name, bundle])) }
|
|
189
|
+
return {
|
|
190
|
+
installed,
|
|
191
|
+
state,
|
|
192
|
+
async listPlugins() {
|
|
193
|
+
// A host that publishes no loader list reports null, not an empty array:
|
|
194
|
+
// "I have no loader" and "the loader has nothing" are different answers.
|
|
195
|
+
return rows
|
|
196
|
+
},
|
|
197
|
+
async listBundles() {
|
|
198
|
+
return [...state.bundles.values()]
|
|
199
|
+
},
|
|
200
|
+
async installBundle(spec) {
|
|
201
|
+
installed.push(spec)
|
|
202
|
+
return installBehavior === null
|
|
203
|
+
? { changed: true, application: 'restart-required' }
|
|
204
|
+
: installBehavior(spec, state)
|
|
205
|
+
},
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** A host context offering only what the code under test asks for. */
|
|
210
|
+
function hostOf(pluginManager) {
|
|
211
|
+
return { get: (name) => (name === 'pluginManager' ? pluginManager : undefined), pluginManager }
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// A profile declaring one installable plugin and one local link, on a machine
|
|
215
|
+
// where the link target does not exist.
|
|
216
|
+
const mixedProfile = makeProfile(join(home, 'profiles', 'mixed'), {
|
|
217
|
+
dependencies: { 'some-plugin': '^1.0.0', 'example-linked-plugin': linkedSpec },
|
|
218
|
+
bundles: ['@deepseek-ai/dsh-base'],
|
|
219
|
+
})
|
|
220
|
+
useProfile(mixedProfile, home)
|
|
221
|
+
|
|
222
|
+
{
|
|
223
|
+
const manager = stubManager({
|
|
224
|
+
plugins: [{ moduleName: '@deepseek-ai/dsh-base' }],
|
|
225
|
+
bundles: [
|
|
226
|
+
{ name: '@deepseek-ai/dsh-base', availability: 'installed', installed: true, version: '1.0.0' },
|
|
227
|
+
// The manager reports the recorded spec as `source`, prefixed with the
|
|
228
|
+
// name; a link: target it cannot resolve is reported as `missing`.
|
|
229
|
+
{ name: 'example-linked-plugin', availability: 'missing', installed: true, source: `example-linked-plugin@${linkedSpec}` },
|
|
230
|
+
],
|
|
231
|
+
})
|
|
232
|
+
const inventory = await plugins.pluginInventory(hostOf(manager))
|
|
233
|
+
check('the inventory says it could check', inventory.available === true, JSON.stringify(inventory.reason))
|
|
234
|
+
check('it reports both inventory sources separately',
|
|
235
|
+
inventory.sources.plugins === true && inventory.sources.bundles === true, JSON.stringify(inventory.sources))
|
|
236
|
+
check('exactly the two declared plugins that are absent are missing',
|
|
237
|
+
JSON.stringify(inventory.missing.map(entry => entry.name)) === JSON.stringify(['some-plugin', 'example-linked-plugin']),
|
|
238
|
+
JSON.stringify(inventory.missing.map(entry => entry.name)))
|
|
239
|
+
check('the local link is missing but not installable here',
|
|
240
|
+
inventory.missing[1]?.resolvable === false && inventory.missing[1]?.note === 'local-path'
|
|
241
|
+
&& inventory.missing[1]?.installSpec === null,
|
|
242
|
+
JSON.stringify(inventory.missing[1]))
|
|
243
|
+
check('the registry dependency is installable, and its spec is reconstructed',
|
|
244
|
+
inventory.missing[0]?.resolvable === true && inventory.missing[0]?.installSpec === 'some-plugin@^1.0.0',
|
|
245
|
+
JSON.stringify(inventory.missing[0]))
|
|
246
|
+
check('the counts separate missing from installable',
|
|
247
|
+
inventory.counts.declared === 3 && inventory.counts.missing === 2
|
|
248
|
+
&& inventory.counts.installable === 1 && inventory.counts.unresolved === 1,
|
|
249
|
+
JSON.stringify(inventory.counts))
|
|
250
|
+
// `@deepseek-ai/dsh-base` is the one bundle this machine reports as installed.
|
|
251
|
+
check('the installed list names what is there',
|
|
252
|
+
JSON.stringify(inventory.installed) === JSON.stringify(['@deepseek-ai/dsh-base']),
|
|
253
|
+
JSON.stringify(inventory.installed))
|
|
254
|
+
|
|
255
|
+
// Running the install over a set with one impossible entry must touch only the
|
|
256
|
+
// possible one.
|
|
257
|
+
const ran = await plugins.installMissingPlugins(hostOf(manager))
|
|
258
|
+
check('the unresolvable plugin is skipped, never handed to the manager',
|
|
259
|
+
ran.outcomeCounts.skipped === 1 && !manager.installed.some(spec => spec.includes('link:')),
|
|
260
|
+
`${JSON.stringify(ran.outcomeCounts)} / ${JSON.stringify(manager.installed)}`)
|
|
261
|
+
check('a skipped result carries the reason instead of a message',
|
|
262
|
+
ran.results.find(result => result.outcome === 'skipped')?.message === 'local-path',
|
|
263
|
+
JSON.stringify(ran.results))
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
{
|
|
267
|
+
// A machine that answers "nothing is missing" installs nothing at all.
|
|
268
|
+
const presentProfile = makeProfile(join(home, 'profiles', 'present'), {
|
|
269
|
+
dependencies: { 'some-plugin': '^1.0.0' },
|
|
270
|
+
bundles: ['@deepseek-ai/dsh-base'],
|
|
271
|
+
})
|
|
272
|
+
useProfile(presentProfile, home)
|
|
273
|
+
const manager = stubManager({
|
|
274
|
+
plugins: [{ moduleName: '@deepseek-ai/dsh-base' }, { moduleName: 'some-plugin' }],
|
|
275
|
+
bundles: [
|
|
276
|
+
{ name: '@deepseek-ai/dsh-base', availability: 'installed', installed: true, version: '1.0.0' },
|
|
277
|
+
{ name: 'some-plugin', availability: 'installed', installed: true, version: '1.0.0' },
|
|
278
|
+
],
|
|
279
|
+
})
|
|
280
|
+
const ran = await plugins.installMissingPlugins(hostOf(manager))
|
|
281
|
+
check('a machine with nothing missing installs nothing',
|
|
282
|
+
manager.installed.length === 0 && ran.results.length === 0, JSON.stringify(manager.installed))
|
|
283
|
+
check('and reports zero of every outcome',
|
|
284
|
+
Object.values(ran.outcomeCounts).every(count => count === 0), JSON.stringify(ran.outcomeCounts))
|
|
285
|
+
check('and does not ask for a restart', ran.restart === false)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
{
|
|
289
|
+
// A plugin present on disk but composed by nothing: the third piece of
|
|
290
|
+
// evidence keeps it from being reported as missing. Its own profile, so no
|
|
291
|
+
// later check sees this machine as already having the package.
|
|
292
|
+
const onDiskProfile = makeProfile(join(home, 'profiles', 'on-disk'), {
|
|
293
|
+
dependencies: { 'some-plugin': '^1.0.0', 'example-linked-plugin': linkedSpec },
|
|
294
|
+
bundles: ['@deepseek-ai/dsh-base'],
|
|
295
|
+
})
|
|
296
|
+
useProfile(onDiskProfile, home)
|
|
297
|
+
mkdirSync(join(onDiskProfile, 'node_modules', 'some-plugin'), { recursive: true })
|
|
298
|
+
writeFileSync(join(onDiskProfile, 'node_modules', 'some-plugin', 'package.json'), '{"name":"some-plugin","version":"1.0.0"}\n')
|
|
299
|
+
const manager = stubManager({ plugins: [], bundles: [] })
|
|
300
|
+
const inventory = await plugins.pluginInventory(hostOf(manager))
|
|
301
|
+
check('a package installed on disk is not called missing',
|
|
302
|
+
!inventory.missing.some(entry => entry.name === 'some-plugin'),
|
|
303
|
+
JSON.stringify(inventory.missing.map(entry => entry.name)))
|
|
304
|
+
check('the link: dependency is still missing, since its target is absent',
|
|
305
|
+
inventory.missing.some(entry => entry.name === 'example-linked-plugin'),
|
|
306
|
+
JSON.stringify(inventory.missing.map(entry => entry.name)))
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
{
|
|
310
|
+
// A registry-spec plugin that is genuinely absent, then installed: the second
|
|
311
|
+
// run is a no-op because the manager now reports it present.
|
|
312
|
+
useProfile(mixedProfile, home)
|
|
313
|
+
const manager = stubManager({
|
|
314
|
+
plugins: [{ moduleName: '@deepseek-ai/dsh-base' }],
|
|
315
|
+
bundles: [{ name: 'some-plugin', availability: 'missing', installed: true, source: 'some-plugin@^1.0.0' }],
|
|
316
|
+
installBehavior: (spec, state) => {
|
|
317
|
+
state.bundles.set('some-plugin', { name: 'some-plugin', availability: 'installed', installed: true, version: '1.0.0' })
|
|
318
|
+
return { changed: true, application: 'restart-required', version: '1.0.0' }
|
|
319
|
+
},
|
|
320
|
+
})
|
|
321
|
+
const ran = await plugins.installMissingPlugins(hostOf(manager))
|
|
322
|
+
check('the install hands the manager the spec the manifest declares',
|
|
323
|
+
manager.installed.includes('some-plugin@^1.0.0'), JSON.stringify(manager.installed))
|
|
324
|
+
check('the outcome is "installed"',
|
|
325
|
+
ran.results.find(result => result.name === 'some-plugin')?.outcome === 'installed', JSON.stringify(ran.results))
|
|
326
|
+
check('and it asks for a restart', ran.restart === true)
|
|
327
|
+
check('the answer re-reads the inventory instead of assuming success',
|
|
328
|
+
!ran.missing.some(entry => entry.name === 'some-plugin'),
|
|
329
|
+
JSON.stringify(ran.missing.map(entry => entry.name)))
|
|
330
|
+
|
|
331
|
+
manager.installed.length = 0
|
|
332
|
+
const second = await plugins.installMissingPlugins(hostOf(manager))
|
|
333
|
+
check('a second run installs nothing', manager.installed.length === 0, JSON.stringify(manager.installed))
|
|
334
|
+
check('and reports nothing to do',
|
|
335
|
+
!second.results.some(result => result.name === 'some-plugin'), JSON.stringify(second.results.map(result => result.name)))
|
|
336
|
+
}
|
|
337
|
+
{
|
|
338
|
+
// The manager refusing because the package is already there. Its own profile,
|
|
339
|
+
// so the link: dependency mixedProfile declares does not enter the tally.
|
|
340
|
+
const presentProfile = makeProfile(join(home, 'profiles', 'refused'), {
|
|
341
|
+
dependencies: { 'some-plugin': '^1.0.0' },
|
|
342
|
+
bundles: ['@deepseek-ai/dsh-base'],
|
|
343
|
+
})
|
|
344
|
+
useProfile(presentProfile, home)
|
|
345
|
+
const manager = stubManager({
|
|
346
|
+
plugins: [{ moduleName: '@deepseek-ai/dsh-base' }],
|
|
347
|
+
bundles: [
|
|
348
|
+
{ name: '@deepseek-ai/dsh-base', availability: 'installed', installed: true, version: '1.0.0' },
|
|
349
|
+
{ name: 'some-plugin', availability: 'missing', installed: true, source: 'some-plugin@^1.0.0' },
|
|
350
|
+
],
|
|
351
|
+
installBehavior: () => ({ changed: false, application: 'failed', error: { code: 'already-installed' } }),
|
|
352
|
+
})
|
|
353
|
+
const ran = await plugins.installMissingPlugins(hostOf(manager))
|
|
354
|
+
check('only the genuinely missing plugin is attempted', manager.installed.length === 1, JSON.stringify(manager.installed))
|
|
355
|
+
check('a manager refusal of an installed package reads as already-present',
|
|
356
|
+
ran.outcomeCounts['already-present'] === 1 && ran.outcomeCounts.failed === 0, JSON.stringify(ran.outcomeCounts))
|
|
357
|
+
check('and it does not ask for a restart', ran.restart === false)
|
|
358
|
+
}
|
|
359
|
+
{
|
|
360
|
+
// A failure carries the manager's own diagnostic.
|
|
361
|
+
const failingProfile = makeProfile(join(home, 'profiles', 'failing'), {
|
|
362
|
+
dependencies: { 'some-plugin': '^1.0.0' },
|
|
363
|
+
bundles: ['@deepseek-ai/dsh-base'],
|
|
364
|
+
})
|
|
365
|
+
useProfile(failingProfile, home)
|
|
366
|
+
const manager = stubManager({
|
|
367
|
+
plugins: [{ moduleName: '@deepseek-ai/dsh-base' }],
|
|
368
|
+
bundles: [
|
|
369
|
+
{ name: '@deepseek-ai/dsh-base', availability: 'installed', installed: true, version: '1.0.0' },
|
|
370
|
+
{ name: 'some-plugin', availability: 'missing', installed: true, source: 'some-plugin@^1.0.0' },
|
|
371
|
+
],
|
|
372
|
+
installBehavior: () => ({ changed: false, application: 'failed', error: { code: 'operation-error', diagnostic: 'ERR_PNPM_FETCH_404' } }),
|
|
373
|
+
})
|
|
374
|
+
const ran = await plugins.installMissingPlugins(hostOf(manager))
|
|
375
|
+
check('a failed install keeps the diagnostic',
|
|
376
|
+
ran.results.find(result => result.outcome === 'failed')?.message === 'ERR_PNPM_FETCH_404', JSON.stringify(ran.results))
|
|
377
|
+
check('and is counted as failed, not as installed', ran.outcomeCounts.failed === 1, JSON.stringify(ran.outcomeCounts))
|
|
378
|
+
|
|
379
|
+
// A manager that throws is the same outcome with the thrown message.
|
|
380
|
+
const throwing = stubManager({
|
|
381
|
+
plugins: [{ moduleName: '@deepseek-ai/dsh-base' }],
|
|
382
|
+
bundles: [
|
|
383
|
+
{ name: '@deepseek-ai/dsh-base', availability: 'installed', installed: true, version: '1.0.0' },
|
|
384
|
+
{ name: 'some-plugin', availability: 'missing', installed: true, source: 'some-plugin@^1.0.0' },
|
|
385
|
+
],
|
|
386
|
+
installBehavior: () => { throw new Error('the lock is held') },
|
|
387
|
+
})
|
|
388
|
+
const strict = await plugins.installMissingPlugins(hostOf(throwing))
|
|
389
|
+
check('a manager that throws is reported, not propagated',
|
|
390
|
+
strict.results.some(result => result.outcome === 'failed' && result.message === 'the lock is held'),
|
|
391
|
+
JSON.stringify(strict.results))
|
|
392
|
+
}
|
|
393
|
+
{
|
|
394
|
+
// A bundle row with no `source` still has the manifest spec to fall back on.
|
|
395
|
+
useProfile(mixedProfile, home)
|
|
396
|
+
const bare = stubManager({ bundles: [{ name: 'some-plugin', availability: 'missing' }, { name: 'example-linked-plugin', availability: 'missing' }] })
|
|
397
|
+
const ran = await plugins.installMissingPlugins(hostOf(bare))
|
|
398
|
+
check('with no reported source the manifest spec is used',
|
|
399
|
+
ran.results.find(result => result.name === 'some-plugin')?.installSpec === 'some-plugin@^1.0.0',
|
|
400
|
+
JSON.stringify(ran.results))
|
|
401
|
+
check('and the local link is still refused, not installed by name',
|
|
402
|
+
!bare.installed.includes('example-linked-plugin'), JSON.stringify(bare.installed))
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// ---- 4. the service-absent cases ---------------------------------------
|
|
406
|
+
{
|
|
407
|
+
const inventory = await plugins.pluginInventory(hostOf(undefined))
|
|
408
|
+
check('without a plugin manager the answer says it could not check',
|
|
409
|
+
inventory.available === false && inventory.reason === 'no-plugin-manager', JSON.stringify(inventory))
|
|
410
|
+
check('and it carries no missing list to misread as an empty one', inventory.missing === undefined,
|
|
411
|
+
JSON.stringify(Object.keys(inventory)))
|
|
412
|
+
const ran = await plugins.installMissingPlugins(hostOf(undefined))
|
|
413
|
+
check('the install route degrades the same way',
|
|
414
|
+
ran.available === false && ran.results.length === 0 && ran.restart === false,
|
|
415
|
+
JSON.stringify(ran.outcomeCounts))
|
|
416
|
+
}
|
|
417
|
+
{
|
|
418
|
+
// A manager whose inventory throws answers no better than no manager — and a
|
|
419
|
+
// host whose service lookup itself throws is the same case again.
|
|
420
|
+
const broken = {
|
|
421
|
+
async listPlugins() { throw new Error('loader is gone') },
|
|
422
|
+
async listBundles() { throw new Error('loader is gone') },
|
|
423
|
+
async installBundle() { throw new Error('nope') },
|
|
424
|
+
}
|
|
425
|
+
const inventory = await plugins.pluginInventory({ get: () => broken, pluginManager: broken })
|
|
426
|
+
check('a manager that cannot list is reported as unable to check',
|
|
427
|
+
inventory.available === false && inventory.reason === 'plugin-manager-error', JSON.stringify(inventory))
|
|
428
|
+
const throwingHost = { get() { throw new Error('no service registry') } }
|
|
429
|
+
const degraded = await plugins.pluginInventory(throwingHost)
|
|
430
|
+
check('a context whose service lookup throws is "no plugin manager", not a crash',
|
|
431
|
+
degraded.available === false && degraded.reason === 'no-plugin-manager', JSON.stringify(degraded))
|
|
432
|
+
}
|
|
433
|
+
{
|
|
434
|
+
// `ctx.get` is the style the rest of this plugin uses; a host publishing the
|
|
435
|
+
// service that way only must still answer.
|
|
436
|
+
const manager = stubManager({ plugins: [], bundles: [{ name: 'some-plugin', availability: 'installed', installed: true }] })
|
|
437
|
+
const viaGet = await plugins.pluginInventory({ get: (name) => (name === 'pluginManager' ? manager : undefined) })
|
|
438
|
+
check('a manager found through ctx.get still answers', viaGet.available === true, JSON.stringify(viaGet.reason))
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// ---- 5. the routes over HTTP -------------------------------------------
|
|
442
|
+
{
|
|
443
|
+
useProfile(mixedProfile, home)
|
|
444
|
+
const manager = stubManager({
|
|
445
|
+
plugins: [{ moduleName: '@deepseek-ai/dsh-base' }],
|
|
446
|
+
bundles: [{ name: 'some-plugin', availability: 'missing', installed: true, source: 'some-plugin@^1.0.0' }],
|
|
447
|
+
installBehavior: (spec, state) => {
|
|
448
|
+
state.bundles.set('some-plugin', { name: 'some-plugin', availability: 'installed', installed: true, version: '1.0.0' })
|
|
449
|
+
return { changed: true, application: 'restart-required' }
|
|
450
|
+
},
|
|
451
|
+
})
|
|
452
|
+
const { registerRoutes, BASE_PATH } = await import('../lib/routes.js')
|
|
453
|
+
let handler = null
|
|
454
|
+
registerRoutes({
|
|
455
|
+
get: (name) => {
|
|
456
|
+
if (name === 'webServer') return { register: (route) => { handler = route.handler; return () => {} } }
|
|
457
|
+
if (name === 'pluginManager') return manager
|
|
458
|
+
return undefined
|
|
459
|
+
},
|
|
460
|
+
pluginManager: manager,
|
|
461
|
+
})
|
|
462
|
+
const served = await serveHandler(handler)
|
|
463
|
+
const call = (path, body) => callRoute(served.base, `${BASE_PATH}${path}`, body)
|
|
464
|
+
|
|
465
|
+
const inventory = await call('/api/plugins')
|
|
466
|
+
check('GET /api/plugins answers', inventory.status === 200 && inventory.payload.available === true,
|
|
467
|
+
`${inventory.status} ${JSON.stringify(inventory.payload).slice(0, 120)}`)
|
|
468
|
+
check('it lists the declared plugin this machine lacks',
|
|
469
|
+
inventory.payload.missing.some(entry => entry.name === 'some-plugin'),
|
|
470
|
+
JSON.stringify(inventory.payload.missing.map(entry => entry.name)))
|
|
471
|
+
|
|
472
|
+
const install = await call('/api/plugins/install', {})
|
|
473
|
+
check('POST /api/plugins/install answers', install.status === 200 && Array.isArray(install.payload.results),
|
|
474
|
+
`${install.status} ${JSON.stringify(install.payload).slice(0, 120)}`)
|
|
475
|
+
check('it installed the one it could', install.payload.outcomeCounts.installed === 1, JSON.stringify(install.payload.outcomeCounts))
|
|
476
|
+
check('it never called the manager for the machine-local dependency',
|
|
477
|
+
!manager.installed.some(spec => spec.includes('link:')), JSON.stringify(manager.installed))
|
|
478
|
+
check('the response says what happened to each spec',
|
|
479
|
+
install.payload.results.every(result => typeof result.name === 'string' && typeof result.outcome === 'string'))
|
|
480
|
+
|
|
481
|
+
const second = await call('/api/plugins/install', {})
|
|
482
|
+
check('a second run is safe and adds no duplicate spec',
|
|
483
|
+
second.status === 200 && new Set(manager.installed).size === manager.installed.length,
|
|
484
|
+
`${second.status} ${JSON.stringify(manager.installed)}`)
|
|
485
|
+
|
|
486
|
+
// A host with no plugin manager still answers, and says it could not check.
|
|
487
|
+
let bareHandler = null
|
|
488
|
+
registerRoutes({
|
|
489
|
+
get: (name) => (name === 'webServer' ? { register: (route) => { bareHandler = route.handler; return () => {} } } : undefined),
|
|
490
|
+
})
|
|
491
|
+
const bare = await serveHandler(bareHandler)
|
|
492
|
+
const bareInventory = await callRoute(bare.base, `${BASE_PATH}/api/plugins`)
|
|
493
|
+
check('a host without a plugin manager answers "cannot check"',
|
|
494
|
+
bareInventory.status === 200 && bareInventory.payload.available === false,
|
|
495
|
+
`${bareInventory.status} ${JSON.stringify(bareInventory.payload)}`)
|
|
496
|
+
const bareInstall = await callRoute(bare.base, `${BASE_PATH}/api/plugins/install`, {})
|
|
497
|
+
check('and its install route does nothing rather than failing',
|
|
498
|
+
bareInstall.status === 200 && bareInstall.payload.results.length === 0, String(bareInstall.status))
|
|
499
|
+
bare.close()
|
|
500
|
+
served.close()
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
// ---- 6. the token error is actionable ----------------------------------
|
|
504
|
+
{
|
|
505
|
+
const gist = await import('../lib/gist.js')
|
|
506
|
+
const saved = {
|
|
507
|
+
user: process.env.USERPROFILE,
|
|
508
|
+
home: process.env.HOME,
|
|
509
|
+
path: process.env.PATH,
|
|
510
|
+
host: process.env.DSH_GITHUB_TOKEN,
|
|
511
|
+
plain: process.env.GITHUB_TOKEN,
|
|
512
|
+
}
|
|
513
|
+
// All three token sources are emptied, and gh is hidden, so the message read
|
|
514
|
+
// here is the one a machine with no token at all really produces.
|
|
515
|
+
const nowhere = join(workspace, 'no-gh-here')
|
|
516
|
+
mkdirSync(nowhere, { recursive: true })
|
|
517
|
+
process.env.USERPROFILE = nowhere
|
|
518
|
+
process.env.HOME = nowhere
|
|
519
|
+
process.env.PATH = ''
|
|
520
|
+
delete process.env.DSH_GITHUB_TOKEN
|
|
521
|
+
delete process.env.GITHUB_TOKEN
|
|
522
|
+
let error = null
|
|
523
|
+
try {
|
|
524
|
+
await gist.resolveTokenSource(undefined)
|
|
525
|
+
} catch (caught) {
|
|
526
|
+
error = caught
|
|
527
|
+
}
|
|
528
|
+
const message = String(error?.message ?? '')
|
|
529
|
+
check('a missing token is an auth error', error?.code === 'auth', String(error?.code))
|
|
530
|
+
check('it names all three token sources',
|
|
531
|
+
message.includes('DSH_GITHUB_TOKEN') && message.includes('gh auth login') && message.includes('GitHub token field'),
|
|
532
|
+
message)
|
|
533
|
+
check('it names the scope the token needs', message.includes('`gist` scope'), message)
|
|
534
|
+
check('it gives a link that pre-selects the scope',
|
|
535
|
+
message.includes('https://github.com/settings/tokens/new?scopes=gist'), message)
|
|
536
|
+
for (const [key, value] of [['USERPROFILE', saved.user], ['HOME', saved.home], ['PATH', saved.path]]) {
|
|
537
|
+
if (value !== undefined) process.env[key] = value
|
|
538
|
+
}
|
|
539
|
+
if (saved.host !== undefined) process.env.DSH_GITHUB_TOKEN = saved.host
|
|
540
|
+
if (saved.plain !== undefined) process.env.GITHUB_TOKEN = saved.plain
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
process.exit(finish())
|