skillhub/cli/test/unit/integrations/removal-inventory.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

53 lines
3.1 KiB
TypeScript

import { expect, test } from 'bun:test'
import { mkdtemp, rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { commitRemovalInventory } from '../../../src/integrations/removal-inventory'
import type { RemovalBaseline } from '../../../src/integrations/native-contract'
import { InventoryStore } from '../../../src/stores/inventory-store'
test('removal commits exactly one target, journals before writing and preserves unrelated records', async () => {
const home = await mkdtemp(join(tmpdir(), 'skillhub-removal-inventory-'))
try {
const store = new InventoryStore(home)
const root = join(home, 'skills')
const target = { agent: 'dsh', rootDir: root, installDir: join(root, 'writer'), installedAt: '2026-10-14' }
const retained = { ...target, agent: 'other', rootDir: join(home, 'other'), installDir: join(home, 'other/writer') }
const item = { registry: 'https://registry.example', namespace: 'demo', slug: 'writer', version: '1.0.0',
fingerprint: 'fingerprint', targets: [target, retained] }
const other = { ...item, slug: 'reader', targets: [{ ...target, installDir: join(root, 'reader') }] }
const initial = { items: [item, other] }
const baseline: Extract<RemovalBaseline, { status: 'ready' }> = { status: 'ready', kind: 'remove-stale-record',
inventoryItem: item, target: { scope: 'user', root, path: target.installDir } }
await store.writeAtomic(initial)
let calls = 0
await commitRemovalInventory(store, baseline, async (before, after) => {
calls++
expect(await store.read()).toEqual(before)
expect(before).toEqual(initial)
expect(after.items).toEqual([{ ...item, targets: [retained] }, other])
})
expect(calls).toBe(1)
expect((await store.read()).items).toEqual([{ ...item, targets: [retained] }, other])
await expect(commitRemovalInventory(store, baseline, async () => {})).rejects.toThrow('inventory changed')
await store.writeAtomic(initial)
await expect(commitRemovalInventory(store, baseline, async () => { throw new Error('journal failed') })).rejects.toThrow('journal failed')
expect(await store.read()).toEqual(initial)
const occupied = { items: [...initial.items, { ...item, registry: 'https://other.example', targets: [target] }] }
await store.writeAtomic(occupied)
await expect(commitRemovalInventory(store, baseline, async () => { throw new Error('must not journal') })).rejects.toThrow('ownership changed')
expect(await store.read()).toEqual(occupied)
const changed = { items: [{ ...item, version: '2.0.0' }, other] }
await store.writeAtomic(changed)
await expect(commitRemovalInventory(store, baseline, async () => {})).rejects.toThrow('inventory changed')
expect(await store.read()).toEqual(changed)
const single = { ...item, targets: [target] }
await store.writeAtomic({ items: [single, other] })
await commitRemovalInventory(store, { ...baseline, inventoryItem: single }, async () => {})
expect((await store.read()).items).toEqual([other])
} finally { await rm(home, { recursive: true, force: true }) }
})