mirror of
https://github.com/iflytek/skillhub.git
synced 2026-11-27 23:58:51 +00:00
* 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>
215 lines
13 KiB
TypeScript
215 lines
13 KiB
TypeScript
import { describe, expect, test } from 'bun:test';
|
|
import { Context } from '@deepseek-ai/cordis';
|
|
import SkillHubService from '@astron-team/skillhub-dsh';
|
|
import type { SkillHubConfig } from '../src/host/types.ts';
|
|
|
|
describe('optional detail modules', () => {
|
|
for (const mode of ['auto', 'show', 'hide'] as const) {
|
|
test.each([200, 403, 404, 503])(`${mode} gates optional requests with HTTP %s`, async status => {
|
|
const requests: string[] = [];
|
|
const server = Bun.serve({ hostname: '127.0.0.1', port: 0, fetch(request) {
|
|
const url = new URL(request.url);
|
|
requests.push(url.pathname + url.search);
|
|
if (url.pathname.endsWith('/versions') || url.pathname.endsWith('/reviews')) {
|
|
if (status !== 200) return new Response('private diagnostics', { status });
|
|
return Response.json({ data: { items: [], total: 0,
|
|
page: Number(url.searchParams.get('page')), size: Number(url.searchParams.get('size')) } });
|
|
}
|
|
if (url.pathname.endsWith('/resolve')) return Response.json({ data: {
|
|
namespace: 'team', slug: 'writer', version: '1', versionId: 7, fingerprint: 'f', downloadUrl: '/archive',
|
|
} });
|
|
if (url.pathname.endsWith('/file')) return new Response('# Writer');
|
|
return Response.json({ data: { id: 42, namespace: 'team', slug: 'writer', displayName: 'Writer', summary: '' } });
|
|
} });
|
|
const ctx = new Context();
|
|
let config: SkillHubConfig = { registryUrl: server.url.href,
|
|
detailTabs: { versions: mode, reviews: mode, securityAudit: mode } };
|
|
const fiber = ctx.plugin(ctx => { new SkillHubService(ctx, { get: () => config }); });
|
|
await fiber;
|
|
try {
|
|
const signal = new AbortController().signal;
|
|
const detail = await ctx.skillhub.getSkillDetail(ctx.skillhub.getContext().sourceRevision,
|
|
'team', 'writer', '1', signal);
|
|
const availability = mode === 'hide' ? 'hidden' : mode === 'show' ? 'unknown'
|
|
: status === 200 ? 'available' : status === 403 ? 'anonymous-denied' : 'unknown';
|
|
expect(detail.tabs).toEqual({ versions: availability, reviews: availability,
|
|
securityAudit: mode === 'hide' ? 'hidden' : 'anonymous-denied' });
|
|
expect(requests.filter(path => path.includes('size='))).toEqual(mode === 'auto' ? [
|
|
'/api/v1/skills/team/writer/versions?page=0&size=1',
|
|
'/api/v1/skills/42/reviews?page=0&size=1',
|
|
] : []);
|
|
for (const read of [() => ctx.skillhub.listVersions(detail.detailToken, 0, signal),
|
|
() => ctx.skillhub.listReviews(detail.detailToken, 0, signal)]) {
|
|
if (mode === 'hide') await expect(read()).rejects.toMatchObject({ code: 'skillhub/context-stale' });
|
|
else if (status === 200) expect(await read()).toMatchObject({ items: [], total: 0, size: 20 });
|
|
else await expect(read()).rejects.toMatchObject({ code: 'skillhub/registry-error', details: { status } });
|
|
}
|
|
expect(requests.filter(path => path.includes('size=20'))).toHaveLength(mode === 'hide' ? 0 : 2);
|
|
expect(requests.some(path => path.includes('security-audit'))).toBe(false);
|
|
// Configuration changes must gate even previously issued detail references before I/O.
|
|
config = { ...config, detailTabs: { versions: 'hide', reviews: 'hide', securityAudit: 'hide' } };
|
|
const count = requests.length;
|
|
await expect(ctx.skillhub.listVersions(detail.detailToken, 0, signal)).rejects.toMatchObject({ code: 'skillhub/context-stale' });
|
|
await expect(ctx.skillhub.listReviews(detail.detailToken, 0, signal)).rejects.toMatchObject({ code: 'skillhub/context-stale' });
|
|
expect(requests).toHaveLength(count);
|
|
} finally { await fiber.dispose(); await server.stop(true); }
|
|
});
|
|
}
|
|
|
|
test('a transient failed probe can become an available empty module on explicit detail retry', async () => {
|
|
let available = false;
|
|
let probes = 0;
|
|
const server = Bun.serve({ hostname: '127.0.0.1', port: 0, fetch(request) {
|
|
const url = new URL(request.url);
|
|
if (url.pathname.endsWith('/reviews')) {
|
|
probes++;
|
|
return available ? Response.json({ data: { items: [], total: 0, page: 0, size: 1 } })
|
|
: new Response('temporarily unavailable', { status: 503 });
|
|
}
|
|
if (url.pathname.endsWith('/resolve')) return Response.json({ data: {
|
|
namespace: 'team', slug: 'writer', version: '1', versionId: 7, fingerprint: 'f', downloadUrl: '/archive',
|
|
} });
|
|
if (url.pathname.endsWith('/file')) return new Response('# Writer');
|
|
return Response.json({ data: { id: 42, namespace: 'team', slug: 'writer', displayName: 'Writer', summary: '' } });
|
|
} });
|
|
const ctx = new Context();
|
|
const fiber = ctx.plugin(SkillHubService, { registryUrl: server.url.href,
|
|
detailTabs: { versions: 'hide', reviews: 'auto', securityAudit: 'hide' } });
|
|
await fiber;
|
|
try {
|
|
const read = () => ctx.skillhub.getSkillDetail(ctx.skillhub.getContext().sourceRevision,
|
|
'team', 'writer', '1', new AbortController().signal);
|
|
expect((await read()).tabs.reviews).toBe('unknown');
|
|
available = true;
|
|
expect((await read()).tabs.reviews).toBe('available');
|
|
expect((await read()).tabs.reviews).toBe('available');
|
|
expect(probes).toBe(2);
|
|
} finally { await fiber.dispose(); await server.stop(true); }
|
|
});
|
|
|
|
test.each([[403, 'anonymous-denied'], [404, 'unknown'], [503, 'unknown']] as const)(
|
|
'auto preserves the meaning of HTTP %s without declaring unsupported', async (status, expected) => {
|
|
let probes = 0;
|
|
const server = Bun.serve({ hostname: '127.0.0.1', port: 0, fetch(request) {
|
|
const path = new URL(request.url).pathname;
|
|
if (path.endsWith('/versions')) { probes++; return new Response('private', { status }); }
|
|
if (path.endsWith('/resolve')) return Response.json({ data: { namespace:'team',slug:'writer',version:'1',versionId:7,fingerprint:'f',downloadUrl:'/archive' } });
|
|
if (path.endsWith('/file')) return new Response('# Writer');
|
|
return Response.json({ data: { id:42,namespace:'team',slug:'writer',displayName:'Writer',summary:'' } });
|
|
} });
|
|
const ctx = new Context();
|
|
const fiber = ctx.plugin(SkillHubService, { registryUrl:server.url.href,
|
|
detailTabs:{ versions:'auto',reviews:'hide',securityAudit:'auto' } });
|
|
await fiber;
|
|
try {
|
|
for (let i = 0; i < 2; i++) {
|
|
const detail = await ctx.skillhub.getSkillDetail(ctx.skillhub.getContext().sourceRevision,
|
|
'team','writer','1',new AbortController().signal);
|
|
expect(detail.tabs.versions).toBe(expected);
|
|
}
|
|
expect(probes).toBe(status === 403 ? 1 : 2);
|
|
} finally { await fiber.dispose(); await server.stop(true); }
|
|
},
|
|
);
|
|
|
|
test('auto probes only first rows, shares cached capability and binds lazy reviews to skill ID', async () => {
|
|
const paths: string[] = [];
|
|
const server = Bun.serve({ hostname: '127.0.0.1', port: 0, fetch(request) {
|
|
const u = new URL(request.url); paths.push(u.pathname + u.search);
|
|
expect(request.headers.get('authorization')).toBeNull();
|
|
let data: unknown;
|
|
if (u.pathname.endsWith('/resolve')) data = {namespace:'team',slug:'writer',version:'1',versionId:7,fingerprint:'f',downloadUrl:'/archive'};
|
|
else if (u.pathname.endsWith('/file')) return new Response('# Writer');
|
|
else if (u.pathname.endsWith('/versions') || u.pathname.endsWith('/reviews')) data = {
|
|
items: [], total:0,page:Number(u.searchParams.get('page')),size:Number(u.searchParams.get('size')),
|
|
};
|
|
else data = {id:42,namespace:'team',slug:'writer',displayName:'Writer',summary:'Example',ownerId:'private',canManageLifecycle:true};
|
|
return Response.json({data});
|
|
}});
|
|
const ctx = new Context();
|
|
let config: SkillHubConfig = {registryUrl:server.url.href,detailTabs:{versions:'auto',reviews:'auto',securityAudit:'show'}};
|
|
const fiber = ctx.plugin(ctx => { new SkillHubService(ctx,{get:()=>config}); }); await fiber;
|
|
const signal = new AbortController().signal;
|
|
try {
|
|
const revision=ctx.skillhub.getContext().sourceRevision;
|
|
const detail=await ctx.skillhub.getSkillDetail(revision,'team','writer','1',signal);
|
|
expect(detail.tabs).toEqual({versions:'available',reviews:'available',securityAudit:'anonymous-denied'});
|
|
expect(detail).not.toHaveProperty('ownerId');
|
|
expect(paths.filter(path=>path.includes('size='))).toEqual([
|
|
'/api/v1/skills/team/writer/versions?page=0&size=1', '/api/v1/skills/42/reviews?page=0&size=1',
|
|
]);
|
|
await ctx.skillhub.getSkillDetail(revision,'team','writer','1',signal);
|
|
expect(paths.filter(path=>path.includes('size=1'))).toHaveLength(2);
|
|
await ctx.skillhub.listReviews(detail.detailToken,1,signal);
|
|
expect(paths.at(-1)).toBe('/api/v1/skills/42/reviews?page=1&size=20');
|
|
expect(paths.some(path=>path.includes('security-audit'))).toBe(false);
|
|
config={...config,detailTabs:{versions:'hide',reviews:'hide',securityAudit:'hide'}};
|
|
const before=paths.length;
|
|
const hidden=await ctx.skillhub.getSkillDetail(revision,'team','writer','1',signal);
|
|
expect(hidden.tabs).toEqual({versions:'hidden',reviews:'hidden',securityAudit:'hidden'});
|
|
expect(paths.slice(before).some(path=>path.includes('size='))).toBe(false);
|
|
await expect(ctx.skillhub.listReviews(detail.detailToken,0,signal)).rejects.toMatchObject({code:'skillhub/context-stale'});
|
|
config={...config,registryUrl:''};
|
|
await expect(ctx.skillhub.listVersions(detail.detailToken,0,signal)).rejects.toMatchObject({code:'skillhub/context-stale'});
|
|
} finally { await fiber.dispose(); await server.stop(true); }
|
|
});
|
|
});
|
|
|
|
describe('account expiry during detail reading', () => {
|
|
for (const endpoint of ['file', 'versions', 'reviews'] as const) {
|
|
test.each([401, 403, 503])(`${endpoint} handles HTTP %s without hiding account expiry`, async status => {
|
|
let fail = false;
|
|
const requests: { path: string; authorization: string | null }[] = [];
|
|
const server = Bun.serve({ hostname: '127.0.0.1', port: 0, fetch(request) {
|
|
const path = new URL(request.url).pathname;
|
|
requests.push({ path, authorization: request.headers.get('authorization') });
|
|
if (path.endsWith('/whoami')) return Response.json({ data: { handle: 'alice', displayName: 'Alice' } });
|
|
if (fail && path.endsWith('/' + endpoint)) return new Response('private diagnostics', { status });
|
|
if (path.endsWith('/resolve')) return Response.json({ data: {
|
|
namespace: 'team', slug: path.includes('/other/') ? 'other' : 'writer', version: '1',
|
|
versionId: 7, fingerprint: 'f', downloadUrl: '/archive',
|
|
} });
|
|
if (path.endsWith('/file')) return new Response('# Private documentation');
|
|
if (path.endsWith('/versions') || path.endsWith('/reviews')) {
|
|
return Response.json({ data: { items: [], total: 0, page: 0, size: 1 } });
|
|
}
|
|
return Response.json({ data: { id: path.endsWith('/other') ? 43 : 42,
|
|
namespace: 'team', slug: path.endsWith('/other') ? 'other' : 'writer', displayName: 'Private skill', summary: '' } });
|
|
} });
|
|
const ctx = new Context();
|
|
const fiber = ctx.plugin(SkillHubService, { registryUrl: server.url.href,
|
|
detailTabs: { versions: 'auto', reviews: 'auto', securityAudit: 'hide' } });
|
|
try {
|
|
await fiber;
|
|
const api = ctx.skillhub;
|
|
const signal = new AbortController().signal;
|
|
await api.connectAccount(api.getContext().sourceRevision, 'fixture-token', signal);
|
|
const revision = api.getContext().sourceRevision;
|
|
const previous = await api.getSkillDetail(revision, 'team', 'writer', '1', signal);
|
|
fail = true;
|
|
const read = api.getSkillDetail(revision, 'team', 'other', '1', signal);
|
|
if (status === 401) {
|
|
await expect(read).rejects.toMatchObject({ code: 'skillhub/registry-error',
|
|
details: { reason: 'AUTH_REQUIRED', status: 401 } });
|
|
const next = api.getContext().sourceRevision;
|
|
expect(next).not.toBe(revision);
|
|
expect(await api.accountIdentity(next, signal)).toBeNull();
|
|
const count = requests.length;
|
|
await expect(api.listVersions(previous.detailToken, 0, signal)).rejects.toMatchObject({ code: 'skillhub/context-stale' });
|
|
expect(requests).toHaveLength(count);
|
|
fail = false;
|
|
await api.getSkillDetail(next, 'team', 'other', '1', signal);
|
|
expect(requests.slice(count).every(request => request.authorization === null)).toBe(true);
|
|
} else {
|
|
const detail = await read;
|
|
if (endpoint === 'file') expect(detail.documentation).toMatchObject({ state: 'error' });
|
|
else expect(detail.tabs[endpoint]).toBe('unknown');
|
|
expect(api.getContext().sourceRevision).toBe(revision);
|
|
expect(await api.accountIdentity(revision, signal)).toEqual({ handle: 'alice', displayName: 'Alice' });
|
|
}
|
|
expect(requests.some(request => request.path.endsWith('/' + endpoint)
|
|
&& request.authorization === 'Bearer fixture-token')).toBe(true);
|
|
} finally { await fiber.dispose(); await server.stop(true); }
|
|
});
|
|
}
|
|
});
|