mirror of
https://github.com/iflytek/skillhub.git
synced 2026-12-01 00:27:21 +00:00
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
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>
61 lines
3.8 KiB
TypeScript
61 lines
3.8 KiB
TypeScript
import { expect, test } from 'bun:test'
|
|
import { realpath, mkdtemp, mkdir, readFile, rm, symlink, unlink, writeFile } from 'node:fs/promises'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { inspectRemovalBaseline } from '../../../src/integrations/removal-baseline'
|
|
import { snapshotSkillDirectory } from '../../../src/services/skill-fingerprint'
|
|
import type { Inventory, InventoryItem } from '../../../src/stores/inventory-store'
|
|
|
|
test('removal inspects one exact target while retaining all other targets in its baseline', async () => {
|
|
const root = await realpath(await mkdtemp(join(tmpdir(), 'skillhub-removal-baseline-')))
|
|
try {
|
|
const target = { scope: 'project' as const, root: join(root, 'project/skills') }
|
|
const path = join(target.root, 'writer')
|
|
await mkdir(join(path, '.skillhub'), { recursive: true })
|
|
await writeFile(join(path, 'SKILL.md'), 'original')
|
|
const snapshot = await snapshotSkillDirectory(path)
|
|
const selected = { registry: 'https://registry.example', namespace: 'demo', slug: 'writer', version: '1.0.0' }
|
|
const entry = { agent: 'dsh', rootDir: target.root, installDir: path, installedAt: '2026-10-14T00:00:00Z' }
|
|
const item: InventoryItem = { ...selected, fingerprint: snapshot.fingerprint,
|
|
targets: [entry, { ...entry, agent: 'other-agent', rootDir: join(root, 'other'), installDir: join(root, 'other/writer') }] }
|
|
await writeFile(join(path, '.skillhub/metadata.json'), JSON.stringify({ ...selected, ...snapshot, agent: 'dsh', installedAt: entry.installedAt }))
|
|
let inventory: Inventory = { items: [structuredClone(item)] }
|
|
const store = { read: async () => structuredClone(inventory) }
|
|
const check = () => inspectRemovalBaseline(store, selected, target)
|
|
const ready = await check()
|
|
expect(ready.status).toBe('ready')
|
|
if (ready.status !== 'ready') throw new Error('Expected valid removal')
|
|
expect(ready.kind).toBe('uninstall')
|
|
expect(ready.inventoryItem.targets).toHaveLength(2)
|
|
expect(ready.target.path).toBe(path)
|
|
expect(await readFile(join(path, 'SKILL.md'), 'utf8')).toBe('original')
|
|
inventory.items[0]!.targets[0]!.installedBy = ['direct', 'suite:demo']
|
|
expect(await check()).toEqual({ status: 'blocked', reason: 'shared-target' })
|
|
inventory = { items: [structuredClone(item)] }
|
|
await writeFile(join(path, 'SKILL.md'), 'local changes')
|
|
expect(await check()).toEqual({ status: 'blocked', reason: 'local-changes' })
|
|
await rm(path, { recursive: true })
|
|
expect(await check()).toMatchObject({ status: 'ready', kind: 'remove-stale-record', target: { path } })
|
|
inventory.items.push({ ...structuredClone(item), registry: 'https://foreign.example' })
|
|
expect(await check()).toEqual({ status: 'blocked', reason: 'shared-target' })
|
|
inventory = { items: [structuredClone(item)] }
|
|
let reads = 0
|
|
expect(await inspectRemovalBaseline({ read: async () => {
|
|
reads++; return { items: [reads === 1 ? structuredClone(item) : { ...structuredClone(item), version: '2.0.0' }] }
|
|
} }, selected, target)).toEqual({ status: 'blocked', reason: 'record-changed' })
|
|
reads = 0
|
|
expect(await inspectRemovalBaseline({ read: async () => {
|
|
reads++
|
|
if (reads === 2) await mkdir(path)
|
|
return structuredClone(inventory)
|
|
} }, selected, target)).toEqual({ status: 'blocked', reason: 'record-changed' })
|
|
await rm(path, { recursive: true })
|
|
await mkdir(join(root, 'outside'))
|
|
await symlink(join(root, 'outside'), path)
|
|
expect(await check()).toMatchObject({ status: 'blocked', reason: 'target-alias' })
|
|
await unlink(path)
|
|
await rm(target.root, { recursive: true })
|
|
await writeFile(target.root, 'not a directory')
|
|
expect(await check()).toEqual({ status: 'blocked', reason: 'target-unavailable' })
|
|
} finally { await rm(root, { recursive: true, force: true }) }
|
|
})
|