skillhub/cli/test/unit/integrations/installed-projection.test.ts
XiaoSeS 3560679793
Some checks failed
Deploy Docs / build (push) Has been cancelled
Security / Dependency Review (push) Has been cancelled
Security / CodeQL (java-kotlin) (push) Has been cancelled
Security / CodeQL (javascript-typescript) (push) Has been cancelled
Security / CodeQL (python) (push) Has been cancelled
Deploy Docs / Deploy (push) Has been cancelled
feat(dsh): add native SkillHub plugin for DeepSeek Harness (#956)
Add the native SkillHub plugin for DeepSeek Harness with a scoped skill center, conversation search/install tools, exact-version installation and protected lifecycle management. Prepare the independently versioned 0.1.0 npm candidate with an empty default Registry and documented compatibility limits.

Keep formal specifications and executable regression tests; remove archived development screenshots and runtime reports from the final tree. Review fixes cover independent scopes, installed references, pre-staging recovery and idempotent discovery.

Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
2026-10-16 19:22:26 +08:00

60 lines
3.7 KiB
TypeScript

import { expect, test } from 'bun:test'
import { realpath, mkdtemp, mkdir, rm, symlink, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join, resolve } from 'node:path'
import { readInstalledProjection } from '../../../src/integrations/installed-projection'
import type { InventoryItem } from '../../../src/stores/inventory-store'
const registry = 'https://registry.example'
test('installed projection preserves both scopes and fixed versions without scanning other targets', async () => {
const root = await realpath(await mkdtemp(join(tmpdir(), 'skillhub-projection-')))
try {
const user = join(root, 'user')
const project = join(root, 'project')
const item: InventoryItem = { registry: registry + '/', namespace: 'demo', slug: 'writer', version: '1.2.0',
fingerprint: 'original', targets: [user, project].map(rootDir => ({ agent: 'dsh', rootDir,
installDir: join(rootDir, 'writer'), installedAt: '2026-10-14T00:00:00Z' })) }
for (const target of item.targets) {
await mkdir(join(target.installDir, '.skillhub'), { recursive: true })
await writeFile(join(target.installDir, '.skillhub/metadata.json'), JSON.stringify({ ...item,
agent: target.agent, installedAt: target.installedAt }))
// No hash claim: local content may differ; presence alone is shown by this projection.
await writeFile(join(target.installDir, 'SKILL.md'), 'locally edited')
}
const inventory = { read: async () => ({ items: [item,
{ ...item, registry: 'https://other.example' },
{ ...item, targets: [{ ...item.targets[0]!, rootDir: join(root, 'other-project'), installDir: '/not-read' }] },
{ ...item, targets: [{ ...item.targets[0]!, agent: 'other-agent' }] },
] }) }
const targets = [{ scope: 'user' as const, root: user }, { scope: 'project' as const, root: project }]
const result = await readInstalledProjection(inventory, registry, targets)
expect(result.complete).toBe(true)
expect(result.issues).toEqual([])
expect(result.items.map(value => [value.scope, value.version, value.state])).toEqual([
['user', '1.2.0', 'present'], ['project', '1.2.0', 'present'],
])
await rm(join(project, 'writer'), { recursive: true })
expect((await readInstalledProjection(inventory, registry, targets)).items[1]!.state).toBe('missing')
await symlink(join(user, 'writer'), join(project, 'writer'))
const linked = await readInstalledProjection(inventory, registry, targets)
expect(linked.complete).toBe(false)
expect(linked.items[1]!.state).toBe('mismatch')
await writeFile(join(user, 'writer/.skillhub/metadata.json'), '{')
expect((await readInstalledProjection(inventory, registry, targets)).items[0]!.state).toBe('metadata-invalid')
} finally { await rm(root, { recursive: true, force: true }) }
})
test('inventory failure is partial and escaping targets are reported without reading outside roots', async () => {
const failed = await readInstalledProjection({ read: async () => { throw new Error('permission denied') } }, registry, [])
expect(failed).toEqual({ items: [], complete: false, issues: ['inventory-unreadable'] })
const trusted = resolve('/trusted')
const item: InventoryItem = { registry, namespace: 'demo', slug: 'writer', version: '1', targets: [
{ agent: 'dsh', rootDir: trusted, installDir: resolve('/untrusted/secret'), installedAt: 'today' },
] }
const result = await readInstalledProjection({ read: async () => ({ items: [item, item] }) }, registry,
[{ scope: 'project', root: trusted }])
expect(result.complete).toBe(false)
expect(result.items).toHaveLength(1)
expect(result.items[0]!.state).toBe('mismatch')
expect(result.items[0]!.targetPath).toBe(join(trusted, 'writer'))
})