skillhub/plugins/dsh/test/installation-targets.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

54 lines
2.7 KiB
TypeScript

import { expect, test } from 'bun:test';
import { InstallationTargets } from '../src/host/installation-targets.js';
const context = { sessionId: 'session', cwd: '/project', sourceRevision: 'source', detailToken: 'detail' };
const target = { scope: 'project' as const, root: '/project/.dsh/skills', dshHome: '/home/test/.dsh' };
test('public target descriptors contain no paths and cannot mutate the stored binding', async () => {
const store = new InstallationTargets();
const input = { ...target };
const descriptor = store.issue(context, input);
expect(Object.keys(descriptor).sort()).toEqual(['scope', 'targetToken']);
input.root = '/elsewhere';
const resolved = await store.resolve(descriptor.targetToken, context, async () => target);
expect(resolved).toEqual(target);
resolved.root = '/mutated';
expect(await store.resolve(descriptor.targetToken, context, async () => target)).toEqual(target);
});
test('references reject other sessions, sources, projects and details before resolving paths', async () => {
const store = new InstallationTargets();
const { targetToken } = store.issue(context, target);
let calls = 0;
for (const field of ['sessionId', 'cwd', 'sourceRevision', 'detailToken']) {
await expect(store.resolve(targetToken, { ...context, [field]: 'changed' }, async () => {
calls++; return target;
})).rejects.toThrow();
}
expect(calls).toBe(0);
await expect(store.resolve('forged', context, async () => target)).rejects.toThrow();
});
test('canonical target, home and policy changes invalidate previously issued references', async () => {
const store = new InstallationTargets();
const { targetToken } = store.issue(context, target);
for (const changed of [{ ...target, root: '/redirected' }, { ...target, dshHome: '/another-home' }, { ...target, scope: 'user' as const }]) {
await expect(store.resolve(targetToken, context, async () => changed)).rejects.toThrow();
}
await expect(store.resolve(targetToken, context, async () => { throw new Error('policy denied'); })).rejects.toThrow('policy denied');
});
test('reload invalidation during asynchronous resolution cannot revive a target', async () => {
const store = new InstallationTargets();
const { targetToken } = store.issue(context, target);
await expect(store.resolve(targetToken, context, async () => {
store.clear(); return target;
})).rejects.toThrow();
});
test('bounded references evict the oldest target', async () => {
const store = new InstallationTargets();
const { targetToken } = store.issue(context, target);
for (let i = 0; i < 400; i++) store.issue(context, target);
await expect(store.resolve(targetToken, context, async () => target)).rejects.toThrow();
});