skillhub/plugins/dsh/test/core-registry-transport.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

67 lines
4.3 KiB
TypeScript

import { expect, test } from 'bun:test';
import { createHash, randomUUID } from 'node:crypto';
import { mkdir, mkdtemp, readFile, realpath, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { zipSync, strToU8 } from 'fflate';
import { registryFetch } from '../scripts/core-registry-transport.ts';
import type { NativeCore, NativeRuntime } from '../src/host/generated/native-contract.js';
test('DSH download redirects stop carrying credentials after leaving Registry API paths', async () => {
const observed: Array<string | null> = [];
const urls = ['https://registry.example/prefix/api/download', 'https://registry.example/storage/file', 'https://registry.example/prefix/api/final'];
const fetchImpl = Object.assign(async (input: string | URL | Request, init?: RequestInit) => {
const index = observed.length;
expect(String(input)).toBe(urls[index]);
observed.push(new Headers(init?.headers).get('Authorization'));
expect(init?.redirect).toBe('manual');
return index < 2 ? new Response(null, { status: 302, headers: { Location: urls[index + 1]! } }) : new Response('package');
}, { preconnect: fetch.preconnect });
const response = await registryFetch('https://registry.example/prefix', 'fixture-token', fetchImpl)(urls[0]!);
expect(await response.text()).toBe('package');
expect(observed).toEqual(['Bearer fixture-token', null, null]);
});
test('the packaged DSH adapter authenticates concurrent Host installations independently', async () => {
const content = '# Private fixture';
const fingerprint = 'sha256:' + createHash('sha256').update('SKILL.md:' + createHash('sha256').update(content).digest('hex') + '\n').digest('hex');
const archive = zipSync({ 'SKILL.md': strToU8(content) });
const tokens = new Set<string>();
const server = Bun.serve({ hostname: '127.0.0.1', port: 0, async fetch(request) {
const auth = request.headers.get('Authorization');
if (auth !== 'Bearer alice' && auth !== 'Bearer bob') return new Response(null, { status: 401 });
tokens.add(auth);
await new Promise(resolve => setTimeout(resolve, 5));
if (new URL(request.url).pathname.endsWith('/resolve')) return Response.json({ data: {
namespace: 'team', slug: 'fixture', version: '1.0', versionId: 7, fingerprint,
downloadUrl: '/api/cli/v1/skills/team/fixture/versions/1.0/download',
} });
return new Response(archive);
} });
const home = await realpath(await mkdtemp(join(tmpdir(), 'dsh-private-core-')));
try {
const core = await import(new URL('../lib/local-core.js', import.meta.url).href) as {
openNativeRuntime(options: Parameters<NativeCore['openNativeRuntime']>[0] & { getRegistryToken(registry: string): string | undefined }): Promise<NativeRuntime>;
};
await Promise.all(['alice', 'bob'].map(async name => {
const profile = join(home, name);
const root = join(profile, 'skills');
await mkdir(root, { recursive: true });
const registry = server.url.href.replace(/\/$/u, '');
const runtime = await core.openNativeRuntime({ stateDirectory: join(profile, 'operations'), inventoryHome: profile,
getRegistryToken: source => source === registry ? name : undefined });
const operation = await runtime.acceptInstall({ hostInstanceId: runtime.hostInstanceId, ownerId: name,
requestKey: randomUUID(), mode: 'new', parameters: { slug: 'fixture' } }, async () => ({
namespace: 'team', slug: 'fixture', version: '1.0', targetLabel: 'Fixture', targetPaths: [join(root, 'fixture')],
context: { sourceIdentity: registry, sourceLabel: 'Fixture', sourceRevision: randomUUID(), hostLabel: 'DSH', initiatedFrom: 'plaza' },
}));
expect(operation).toBeDefined();
const result = await runtime.executeInstall({ operationId: operation!.operationId, ownerId: name, registry,
namespace: 'team', slug: 'fixture', version: '1.0', versionId: 7, fingerprint, root, scope: 'user',
authorize: async () => {}, validateStaged: async () => {} });
expect(result.outcome).toBe('committed');
expect(await readFile(join(root, 'fixture', 'SKILL.md'), 'utf8')).toBe(content);
}));
expect(tokens).toEqual(new Set(['Bearer alice', 'Bearer bob']));
} finally { await server.stop(true); await rm(home, { recursive: true, force: true }); }
});