skillhub/plugins/dsh/test/client-slot-lifecycle.test.ts
dongmucat 6d436d664e
feat(dsh): connect accounts and manage namespace skills and members (#1114)
* feat(dsh): connect registry accounts and manage namespace skills and members

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(dsh): use the patched ZIP reader for skill packages

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(dsh): bind owned skill actions to the published version ID

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(auth): handle context-prefixed registry requests consistently

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(dsh): address account isolation and upload review findings

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(dsh): recover changed upload targets and clear private detail caches

Signed-off-by: dongmucat <1127093059@qq.com>

* refactor(dsh): keep registry authentication inside the plugin

Signed-off-by: dongmucat <1127093059@qq.com>

* test(dsh): canonicalize temporary profile roots across platforms

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(dsh): clear expired accounts during detail reads

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(auth): include DSH permissions in default personal tokens

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(web): refresh token form analytics manifest

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(dsh): organize account dialogs and preserve modal focus

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(ci): pin DSH browser checks to supported Ubuntu

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(dsh): unify workbench appearance and source navigation

Signed-off-by: dongmucat <1127093059@qq.com>

* test(dsh): wait for runtime readiness before availability install

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(dsh): align namespace pages with the account prototype

Signed-off-by: dongmucat <1127093059@qq.com>

* test(dsh): use monotonic clocks for fixture deadlines

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(dsh): expose namespace member management actions

Add a direct member-management entry, explain disabled role and state restrictions, and preserve keyboard focus after membership changes. Exercise add, role change and removal through the real account components.

Signed-off-by: dongmucat <1127093059@qq.com>

* feat(dsh): support drag and drop skill uploads

Use one validated file selection flow for dropping and browsing ZIPs. Show selected file details, protect in-flight uploads and confirmation revisions, and cover keyboard, busy and invalid-file behavior in Chromium.

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(dsh): right-align the catalog upload action

Signed-off-by: dongmucat <1127093059@qq.com>

* feat(dsh): persist Windows account credentials securely

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(dsh): remove saved accounts reliably on Windows Unicode paths

Signed-off-by: dongmucat <1127093059@qq.com>

* test(organizations): isolate committed portal fixtures

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(auth): preserve token lifecycle state during usage updates

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(skills): enforce caller-aware deletion across CLI endpoints

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(dsh): submit account writes once and refresh registry views

Signed-off-by: dongmucat <1127093059@qq.com>

* chore(db): reserve unpublished token migration after upstream V128

Signed-off-by: dongmucat <1127093059@qq.com>

---------

Signed-off-by: dongmucat <1127093059@qq.com>
2026-11-25 16:07:19 +08:00

146 lines
7.2 KiB
TypeScript

import { expect, test } from 'bun:test';
import { Context } from '@deepseek-ai/cordis';
import type { SidebarPanelIconOwnerProps } from '@deepseek-ai/dsh-client-ui-sidebar/client';
import { createElement, type ComponentType } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { readFile } from 'node:fs/promises';
import { createRequire } from 'node:module';
import { dirname, join } from 'node:path';
import { runInNewContext } from 'node:vm';
import * as clientPlugin from '../src/client/index.js';
// Exercise the published slot lifecycle without mounting a React DOM tree.
async function loadSlotRegistry() {
const require = createRequire(import.meta.url);
type Registry = Context['slots'] & { entriesOfSlot(name: string): { component: unknown }[] };
type Entry = { factory: (require: (id: string) => unknown) => { SlotRegistry: new (ctx: Context) => Registry } };
const entries: Entry[] = [];
const manifest = require.resolve('@deepseek-ai/dsh-client-ui-renderer/package.json');
runInNewContext(await readFile(join(dirname(manifest), 'lib/client.js'), 'utf8'), {
window: { __ModuleLoader__: { load: (entry: Entry) => entries.push(entry) } },
queueMicrotask,
});
expect(entries).toHaveLength(1);
return entries[0]!.factory(id => {
// DOM rendering is deliberately outside this service-lifecycle test.
if (id === 'react-dom' || id === 'react-dom/client') return {};
return require(id);
}).SlotRegistry;
}
test('official slot declaration loss preserves catalog and independently removes tool/config contributions', async () => {
const SlotRegistry = await loadSlotRegistry();
const ctx = new Context();
const renderer = ctx.plugin({ apply: (ctx: Context) => { new SlotRegistry(ctx); } });
await renderer;
const slots = ctx.slots as InstanceType<typeof SlotRegistry>;
const empty = () => null;
const root = slots.register({ name: 'root', children: {
main: { kind: 'keyed', scope: 'session-maybe' },
'sidebar.panellist': { kind: 'list', scope: 'root' },
'test.tools': { kind: 'single', scope: 'root' },
'test.config': { kind: 'single', scope: 'root' },
} } as never, empty);
const providers = [
ctx.provide('remote', { $mount: async () => async () => {} } as never),
ctx.provide('remote.skillhub', {} as never),
ctx.provide('sessions', { scope: () => undefined } as never),
ctx.provide('layout', { selectPanel: () => {} } as never),
];
providers.push(ctx.provide('uiSession', {} as never));
const plugin = ctx.plugin(clientPlugin);
const flush = async () => { await new Promise(resolve => setTimeout(resolve, 25)); };
try {
await plugin; await flush();
const catalog = slots.entriesOfSlot('main')[0]?.component;
expect(catalog).toBeDefined();
const sidebarEntries = slots.entriesOfSlot('sidebar.panellist');
expect(sidebarEntries).toHaveLength(1);
const SidebarIcon = sidebarEntries[0]!.component as ComponentType<SidebarPanelIconOwnerProps>;
for (const size of [16, 18]) {
const icon = renderToStaticMarkup(createElement(SidebarIcon, { size, active: false }));
expect(icon).toContain(`width="${size}"`);
expect(icon).toContain(`height="${size}"`);
}
expect(slots.entriesOfSlot('tool.call.toolview')).toHaveLength(0);
expect(slots.entriesOfSlot('plugins.bundle.config')).toHaveLength(0);
for (let cycle = 0; cycle < 2; cycle++) {
const tools = slots.register({ name: 'test.tools', children: {
'tool.call.toolview': { kind: 'keyed', scope: 'session' },
} } as never, empty);
expect(slots.entriesOfSlot('tool.call.toolview')).toHaveLength(10);
tools(); await flush();
expect(slots.entriesOfSlot('tool.call.toolview')).toHaveLength(0);
expect(slots.entriesOfSlot('main')[0]?.component).toBe(catalog);
const config = slots.register({ name: 'test.config', children: {
'plugins.bundle.config': { kind: 'keyed', scope: 'root' },
} } as never, empty);
expect(slots.entriesOfSlot('plugins.bundle.config')).toHaveLength(0);
const forms = ctx.provide('configForms', { get: () => ({}) } as never);
await flush();
expect(slots.entriesOfSlot('plugins.bundle.config')).toHaveLength(1);
await forms(); await flush();
expect(slots.entriesOfSlot('plugins.bundle.config')).toHaveLength(0);
expect(slots.entriesOfSlot('main')[0]?.component).toBe(catalog);
config();
}
await plugin.dispose();
expect(slots.entriesOfSlot('main')).toHaveLength(0);
expect(slots.entriesOfSlot('sidebar.panellist')).toHaveLength(0);
// Disposing the plugin must also cancel waits for declarations not yet present.
const toolsAfterDispose = slots.register({ name: 'test.tools', children: {
'tool.call.toolview': { kind: 'keyed', scope: 'session' },
} } as never, empty);
expect(slots.entriesOfSlot('tool.call.toolview')).toHaveLength(0);
toolsAfterDispose();
} finally {
await plugin.dispose();
for (const remove of providers.reverse()) await remove();
root(); await renderer.dispose();
}
});
test('session adapter loss removes scoped catalog contributions and restoration registers them once', async () => {
const SlotRegistry = await loadSlotRegistry();
const ctx = new Context();
const renderer = ctx.plugin({ apply: (ctx: Context) => { new SlotRegistry(ctx); } });
await renderer;
const slots = ctx.slots as InstanceType<typeof SlotRegistry>;
const root = slots.register({ name: 'root', children: {
main: { kind: 'keyed', scope: 'session-maybe' },
'sidebar.panellist': { kind: 'list', scope: 'root' },
} } as never, () => null);
const providers = [
ctx.provide('remote', { $mount: async () => async () => {} } as never),
ctx.provide('remote.skillhub', {} as never),
ctx.provide('sessions', { scope: () => undefined } as never),
ctx.provide('layout', { selectPanel: () => {} } as never),
];
const plugin = ctx.plugin(clientPlugin);
const flush = async () => { await new Promise(resolve => setTimeout(resolve, 25)); };
const source = { getSnapshot: () => ({ hooks: {}, keyedHooks: {}, props: {} }), subscribe: () => () => {} };
const adapter = { current: source, bindingSource: () => source };
let owner: ReturnType<Context['plugin']> | undefined;
try {
await plugin; await flush();
// sessions is available, but the session-maybe renderer cannot run without its UI adapter.
expect(slots.entriesOfSlot('main')).toHaveLength(0);
expect(slots.entriesOfSlot('sidebar.panellist')).toHaveLength(0);
for (let cycle = 0; cycle < 2; cycle++) {
owner = ctx.plugin({ inject: ['slots'], apply: (ctx: Context) => {
ctx.provide('uiSession', {} as never);
ctx.slots.installScope('session', adapter);
} });
await owner; await flush();
expect(slots.entriesOfSlot('main')).toHaveLength(1);
expect(slots.entriesOfSlot('sidebar.panellist')).toHaveLength(1);
await owner.dispose(); await flush();
expect(slots.entriesOfSlot('main')).toHaveLength(0);
expect(slots.entriesOfSlot('sidebar.panellist')).toHaveLength(0);
}
} finally {
await plugin.dispose(); await owner?.dispose();
for (const remove of providers.reverse()) await remove();
root(); await renderer.dispose();
}
});