89 lines
4.1 KiB
TypeScript
89 lines
4.1 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { spawnSync } from 'node:child_process';
|
|
import { existsSync, readFileSync } from 'node:fs';
|
|
import { dirname, resolve } from 'node:path';
|
|
import { test } from 'vitest';
|
|
import { fileURLToPath } from 'node:url';
|
|
import semver from 'semver';
|
|
|
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
const pkg = JSON.parse(readFileSync(resolve(root, 'package.json'), 'utf8')) as {
|
|
name: string;
|
|
main: string;
|
|
scripts?: { prepare?: string };
|
|
exports: Record<string, { default?: string } | string>;
|
|
files: string[];
|
|
dsh: { bundle?: { patch?: string }; client?: { inject?: string[] } };
|
|
peerDependencies: Record<string, string>;
|
|
};
|
|
|
|
const HARNESS_PEER = '>=0.2.1-rc.1 <0.2.3';
|
|
|
|
test('Harness peer range accepts the 0.2.2 line and rejects the 0.2.0 series', () => {
|
|
const peers = Object.entries(pkg.peerDependencies).filter(([name]) => name.startsWith('@deepseek-ai/dsh-'));
|
|
assert.ok(peers.length >= 10);
|
|
for (const [name, range] of peers) {
|
|
assert.equal(range, HARNESS_PEER, name);
|
|
assert.equal(semver.satisfies('0.2.2-rc.2', range, { includePrerelease: true }), true, name);
|
|
assert.equal(semver.satisfies('0.2.1-rc.5', range, { includePrerelease: true }), true, name);
|
|
assert.equal(semver.satisfies('0.2.1', range, { includePrerelease: true }), true, name);
|
|
assert.equal(semver.satisfies('0.2.1-alpha.1', range, { includePrerelease: true }), false, name);
|
|
assert.equal(semver.satisfies('0.2.0-rc.2', range, { includePrerelease: true }), false, name);
|
|
assert.equal(semver.satisfies('0.2.0', range, { includePrerelease: true }), false, name);
|
|
assert.equal(semver.satisfies('0.1.7-rc.2', range, { includePrerelease: true }), false, name);
|
|
}
|
|
const manifest = JSON.parse(readFileSync(resolve(root, 'package.json'), 'utf8')) as { engines?: { dsh?: string } };
|
|
assert.equal(manifest.engines?.dsh, HARNESS_PEER);
|
|
});
|
|
|
|
test('declares dsh.bundle.patch so official add joins the profile layer stack', () => {
|
|
assert.equal(pkg.dsh.bundle?.patch, './cordis.patch.yml');
|
|
assert.equal(existsSync(resolve(root, 'cordis.patch.yml')), true);
|
|
const patch = readFileSync(resolve(root, 'cordis.patch.yml'), 'utf8');
|
|
assert.match(patch, /id: dsh-better-chat/);
|
|
assert.match(patch, /name: dsh-better-chat/);
|
|
assert.equal(pkg.files.includes('cordis.patch.yml'), true);
|
|
});
|
|
|
|
test('commits one merged client bundle and one host entry', () => {
|
|
assert.equal(pkg.scripts?.prepare, undefined);
|
|
assert.equal(pkg.name, 'dsh-better-chat');
|
|
assert.equal(pkg.main, 'lib/host.js');
|
|
const client = pkg.exports['./client'];
|
|
assert.equal(typeof client === 'object' && client !== null ? client.default : client, './lib/client.js');
|
|
assert.equal(existsSync(resolve(root, 'lib/host.js')), true);
|
|
assert.equal(existsSync(resolve(root, 'lib/client.js')), true);
|
|
|
|
const clientJs = readFileSync(resolve(root, 'lib/client.js'), 'utf8');
|
|
assert.match(clientJs, /window\.__ModuleLoader__\.load/);
|
|
assert.match(clientJs, /id:\s*"dsh-better-chat"/);
|
|
// reading view (merged from dsh-better-display)
|
|
assert.match(clientJs, /conversation\.view/);
|
|
assert.match(clientJs, /data-reader-glass/);
|
|
assert.match(clientJs, /foldIntensity/);
|
|
// chat enhancements (dsh-better-chat)
|
|
assert.match(clientJs, /data-approval-key/);
|
|
assert.match(clientJs, /data-better-chat-update/);
|
|
assert.match(clientJs, /Full access/);
|
|
});
|
|
|
|
test('compiled host entry loads in Node without a TypeScript loader', async () => {
|
|
// Dynamic import rather than a child process: the desktop sandbox forbids
|
|
// spawning children with piped stdio.
|
|
const plugin = await import(new URL('../lib/host.js', import.meta.url).href) as {
|
|
name?: string;
|
|
apply?: unknown;
|
|
};
|
|
assert.equal(plugin.name, 'dsh-better-chat');
|
|
assert.equal(typeof plugin.apply, 'function');
|
|
});
|
|
|
|
test('README documents the official install one-liner', () => {
|
|
for (const name of ['README.md', 'README.en.md']) {
|
|
const text = readFileSync(resolve(root, name), 'utf8');
|
|
assert.match(text, /dsh plugin --profile desktop add dsh-better-chat/);
|
|
assert.doesNotMatch(text, /activate-new-client/);
|
|
assert.doesNotMatch(text, /my-plugins/);
|
|
}
|
|
});
|