skillhub/plugins/dsh/test/catalog-error.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

65 lines
3.7 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { expect, test } from 'bun:test';
import { catalogErrorMessage } from '../src/client/catalog-error.js';
test.each([
['ANONYMOUS_DENIED', '不允许匿名读取'],
['RATE_LIMITED', '限流'],
['REGISTRY_UNAVAILABLE', '服务暂时不可用'],
['NETWORK_ERROR', '网络'],
['INVALID_SOURCE', '地址无效'],
['NOT_FOUND', '未找到'],
['CANCELLED', '已取消'],
['INVALID_RESPONSE', '数据格式'],
['RESPONSE_TOO_LARGE', '读取限制'],
])('catalog explains %s without displaying upstream diagnostics', (reason, expected) => {
const message = catalogErrorMessage({ code: 'skillhub/registry-error', details: { reason, body: 'private diagnostic' } });
expect(message).toContain(expected);
expect(message).not.toContain('private diagnostic');
});
test('unknown or malformed errors use safe fallback messages', () => {
for (const details of [undefined, null, 'private diagnostic', { reason: 'private diagnostic' }, { reason: {} }]) {
expect(catalogErrorMessage({ code: 'skillhub/registry-error', details }))
.toBe('无法读取 SkillHub,请检查来源地址或稍后重试。');
}
expect(catalogErrorMessage({ code: 'private diagnostic' })).toBe('请求失败,请稍后重试。');
expect(catalogErrorMessage({ code: 'skillhub/context-stale' })).toContain('来源已变化');
expect(catalogErrorMessage({ code: 'skillhub/source-not-configured' })).toContain('设置 SkillHub 地址');
});
test('local favorites errors explain recovery without exposing file paths or upstream diagnostics', () => {
const cases = [
['INVALID_STORE', '本地收藏文件无法读取,原有内容已保留。'],
['LIMIT_REACHED', '本机收藏已达上限,请先取消部分收藏。'],
['INVALID_INPUT', '此技能暂时无法收藏,请刷新后重试。'],
['UNAVAILABLE', '本地收藏暂时不可用,请重试。'],
] as const;
for (const [reason, expected] of cases) {
expect(catalogErrorMessage({ code: 'skillhub/favorites-error', details: { reason, message: '/private/favorites.json' } })).toBe(expected);
}
expect(catalogErrorMessage({ code: 'skillhub/favorites-error', details: { reason: 'FUTURE' } })).toBe('本地收藏暂时不可用,请重试。');
});
test('rate limit hints only interpolate a validated wait duration', () => {
expect(catalogErrorMessage({ code: 'skillhub/registry-error', details: { reason: 'RATE_LIMITED', retryAfterSeconds: 30 } }))
.toContain('至少 30 秒后手动重试');
for (const retryAfterSeconds of [-1, 0, 1.5, Infinity, 'private diagnostic']) {
expect(catalogErrorMessage({ code: 'skillhub/registry-error', details: { reason: 'RATE_LIMITED', retryAfterSeconds } }))
.toBe('SkillHub 来源暂时限流,请稍后重试。');
}
});
test('authentication failures retain their classification across all browser readers', async () => {
const { catalogError } = await import('../src/client/catalog-error.js');
const expired = catalogError({ code: 'skillhub/registry-error', details: { reason: 'AUTH_REQUIRED' } });
expect(expired.name).toBe('AccountExpired');
expect(expired.message).toContain('重新登录');
expect(catalogError({ code: 'skillhub/registry-error', details: { reason: 'ACCESS_DENIED' } }).name).toBe('Error');
expect(catalogError({ code: 'other', details: { reason: 'AUTH_REQUIRED' } }).name).toBe('Error');
});
test('a changed upload target is a definite rejection that can be confirmed again', async () => {
const { catalogError } = await import('../src/client/catalog-error.js');
expect(catalogError({ code: 'skillhub/registry-error', details: { reason: 'TARGET_CHANGED' } }).name).toBe('UploadTargetChanged');
expect(catalogError({ code: 'skillhub/registry-error', details: { reason: 'WRITE_UNKNOWN' } }).name).toBe('Error');
});