mirror of
https://github.com/iflytek/skillhub.git
synced 2026-12-02 00:37:22 +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>
52 lines
3.3 KiB
TypeScript
52 lines
3.3 KiB
TypeScript
import { expect, test } from 'bun:test';
|
|
import { realpath, mkdtemp, mkdir, rm } from 'node:fs/promises';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
import SkillHubService from '@astron-team/skillhub-dsh';
|
|
import { RemovalPlans } from '../src/host/upgrade-plans.js';
|
|
import type { RemovalBaseline } from '../src/host/generated/native-contract.js';
|
|
|
|
test('uninstall preparation remains local and distinguishes removal from stale-record cleanup', async () => {
|
|
const cwd = await realpath(await mkdtemp(join(tmpdir(), 'skillhub-prepare-uninstall-')));
|
|
try {
|
|
await mkdir(join(cwd, '.git'));
|
|
const root = join(cwd, '.dsh/skills');
|
|
const scope = { sessionId: 'session', sourceRevision: 'source', cwd };
|
|
const identity = { registry: 'https://registry.example', namespace: 'demo', slug: 'writer', version: '1', fingerprint: 'fp' };
|
|
let baseline: RemovalBaseline = { status: 'ready', kind: 'uninstall', inventoryItem: { ...identity, targets: [] },
|
|
target: { scope: 'project', root, path: join(root, 'writer'), metadata: identity, files: { 'SKILL.md': 'hash' } } };
|
|
let mode = 'danger-full-access';
|
|
let pending = 0;
|
|
let state = 'present';
|
|
let inspected = 0;
|
|
const plans = new RemovalPlans();
|
|
const context = { lifetime: new AbortController(), removalPlans: plans, selectionScope: () => scope,
|
|
getContext: () => ({ registryUrl: identity.registry }),
|
|
readSource: () => { throw new Error('Uninstall must not query Registry'); },
|
|
readInstalledItem: async () => ({ item: { ...identity, state, scope: 'project' }, valid() {},
|
|
agent: { session: { id: 'session', header: { cwd } }, ctx: { get: () => ({ resolve: () => ({ mode }) }) } },
|
|
fs: { sandboxMode: 'workspace-write', resolve: async (path: string) => path,
|
|
processPath: (path: string) => path, processPathFromHostPath: (path: string) => path },
|
|
runtime: { getStatus: () => ({ pendingOperations: pending, hostInstanceId: 'host' }),
|
|
inspectRemoval: async () => { inspected++; return baseline; } } }),
|
|
};
|
|
const prepare = () => Reflect.apply(SkillHubService.prototype.prepareUninstall, context, ['source', 'item', new AbortController().signal]);
|
|
const ready = await prepare();
|
|
if (!ready.planId) throw new Error('Expected removal plan');
|
|
expect(ready).toMatchObject({ status: 'ready', kind: 'uninstall', currentVersion: '1', target: { scope: 'project', path: join(root, 'writer') } });
|
|
expect(plans.read(ready.planId, scope)).toEqual(baseline);
|
|
state = 'missing';
|
|
baseline = { status: 'ready', kind: 'remove-stale-record', inventoryItem: { ...identity, targets: [] },
|
|
target: { scope: 'project', root, path: join(root, 'writer') } };
|
|
expect(await prepare()).toMatchObject({ status: 'ready', kind: 'remove-stale-record' });
|
|
baseline = { status: 'blocked', reason: 'shared-target' };
|
|
expect(await prepare()).toMatchObject({ status: 'blocked', reason: 'shared-target', planId: null });
|
|
const before = inspected;
|
|
pending = 1;
|
|
expect(await prepare()).toMatchObject({ status: 'blocked', reason: 'recovery-required' });
|
|
expect(inspected).toBe(before);
|
|
pending = 0; mode = 'read-only';
|
|
await expect(prepare()).rejects.toThrow('read-only');
|
|
expect(inspected).toBe(before);
|
|
} finally { await rm(cwd, { recursive: true, force: true }); }
|
|
});
|