skillhub/plugins/dsh/test/host-package-cache.test.ts
XiaoSeS 3a3ae6d9b8
Some checks failed
Security / Dependency Review (push) Waiting to run
Security / CodeQL (java-kotlin) (push) Waiting to run
Security / CodeQL (javascript-typescript) (push) Waiting to run
Security / CodeQL (python) (push) Waiting to run
Deploy Docs / build (push) Has been cancelled
Deploy Docs / Deploy (push) Has been cancelled
fix(dsh): admit newer hosts without a version ceiling (#1099)
Admit DSH hosts from 0.2.0-rc.2 without an upper version ceiling while retaining capability, ownership, permission and inventory protections.

Separate tested versions from admission, cover DSH 0.2.2-rc.3, and fix clean CI smoke dependency resolution. Prepare the DSH-only 0.6.4 patch; no CLI or application release.

Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
2026-11-16 15:02:04 +08:00

76 lines
4.1 KiB
TypeScript

import { expect, test } from 'bun:test';
import { Context } from '@deepseek-ai/cordis';
import { PluginPackages } from '@deepseek-ai/dsh-app-boot';
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { pathToFileURL } from 'node:url';
import { assertRuntimeCompatibility, runtimePackageBaseline, clientPackageBaseline } from '../src/host/runtime-compatibility.js';
test('official package service caches metadata while disk verification rejects replacement', async () => {
const root = await mkdtemp(join(tmpdir(), 'skillhub-official-package-cache-'));
const ctx = new Context();
const fiber = ctx.plugin(PluginPackages);
try {
await fiber;
const parent = pathToFileURL(join(root, 'plugin.js')).href;
for (const [name, version] of Object.entries({ ...runtimePackageBaseline, ...Object.fromEntries(clientPackageBaseline.map(name => [name, '0.2.0-rc.2'])) })) {
const directory = join(root, 'node_modules', name);
await mkdir(directory, { recursive: true });
await writeFile(join(directory, 'package.json'), JSON.stringify({ name, version }));
}
const services = {
packageOf: (name: string, parentURL: string) => ctx.pluginPackages.packageOf(name, parentURL),
clientPath: (name: string) => join(root, 'node_modules', name, 'lib/client.js'),
hasAgentLookup: () => true,
};
const check = () => assertRuntimeCompatibility(services, parent, (_file, name) => ({ name, version: '0.2.0-rc.2' }));
expect(check).not.toThrow();
for (const [name, version] of Object.entries({ ...runtimePackageBaseline, ...Object.fromEntries(clientPackageBaseline.map(name => [name, '0.2.0-rc.2'])) })) {
const original = ctx.pluginPackages.packageOf(name, parent)!;
const path = join(root, 'node_modules', name, 'package.json');
await writeFile(path, JSON.stringify({ name, version: '0.0.0-test-mismatch' }));
expect(ctx.pluginPackages.packageOf(name, parent)).toBe(original);
expect(original.version).toBe(version);
expect(check).toThrow('local writes are disabled');
await rm(path);
expect(check).toThrow('local writes are disabled');
await writeFile(path, JSON.stringify({ name, version }));
expect(check).not.toThrow();
}
} finally {
await fiber.dispose();
await rm(root, { recursive: true, force: true });
}
});
test('official Host lookup rejects a supported plugin peer masking a different nested Host Cordis', async () => {
const root = await mkdtemp(join(tmpdir(), 'skillhub-split-host-graph-'));
const ctx = new Context();
const fiber = ctx.plugin(PluginPackages);
try {
await fiber;
const parent = pathToFileURL(join(root, 'plugin.js')).href;
for (const [name, version] of Object.entries({ ...runtimePackageBaseline, ...Object.fromEntries(clientPackageBaseline.map(name => [name, '0.2.0-rc.2'])) })) {
const directory = join(root, 'node_modules', name);
await mkdir(directory, { recursive: true });
await writeFile(join(directory, 'package.json'), JSON.stringify({ name, version }));
}
const nested = join(root, 'node_modules/@deepseek-ai/dsh/node_modules/@deepseek-ai/cordis');
await mkdir(nested, { recursive: true });
await writeFile(join(nested, 'package.json'), JSON.stringify({ name: '@deepseek-ai/cordis', version: '4.0.5' }));
const services = {
packageOf: (name: string, parentURL: string) => ctx.pluginPackages.packageOf(name, parentURL),
clientPath: (name: string) => join(root, 'node_modules', name, 'lib/client.js'),
hasAgentLookup: () => true,
};
expect(ctx.pluginPackages.packageOf('@deepseek-ai/cordis', parent)?.version).toBe('4.0.4');
const hostURL = pathToFileURL(join(root, 'node_modules/@deepseek-ai/dsh/package.json')).href;
expect(ctx.pluginPackages.packageOf('@deepseek-ai/cordis', hostURL)?.version).toBe('4.0.5');
expect(() => assertRuntimeCompatibility(services, parent,
(_file, name) => ({ name, version: '0.2.0-rc.2' }))).toThrow('local writes are disabled');
} finally {
await fiber.dispose();
await rm(root, { recursive: true, force: true });
}
});