import assert from 'node:assert/strict' import { readFile } from 'node:fs/promises' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' import { test } from 'node:test' const root = join(dirname(fileURLToPath(import.meta.url)), '..') test('installable bundle declares host apply, client half, unique id, and no @deepseek-ai runtime deps', async () => { const pkg = JSON.parse(await readFile(join(root, 'package.json'), 'utf8')) assert.equal(pkg.name, 'dsh-ops-cron') assert.equal(pkg.dsh.bundle.patch, './cordis.patch.yml') assert.equal(pkg.dsh.client.platform, 'web') assert.ok(pkg.exports['./client']) assert.equal(pkg.main, 'lib/index.js') assert.ok(!pkg.dependencies || !Object.keys(pkg.dependencies).some((id) => id.startsWith('@deepseek-ai/'))) const patch = await readFile(join(root, 'cordis.patch.yml'), 'utf8') assert.match(patch, /id:\s*dsh-ops-cron/) const index = await readFile(join(root, 'lib/index.js'), 'utf8') assert.match(index, /export function apply\(/) assert.match(index, /registerCronTools/) assert.match(index, /inject\(\['tools'\]/) assert.match(index, /getDshIm/) const tools = await readFile(join(root, 'lib/tools.js'), 'utf8') assert.match(tools, /name: 'cron_create'/) assert.match(tools, /name: 'cron_list'/) assert.match(tools, /crontab/) assert.match(tools, /scheduled-tasks/) assert.match(tools, /hour/) assert.match(tools, /Current local time/) assert.match(tools, /source: 'runtime'/) assert.match(tools, /resolveCreateDelivery/) assert.match(tools, /im_bot_id/) assert.match(tools, /resolveCreateCwd/) assert.match(tools, /after_minutes/) assert.match(tools, /Extra schedule fields are ignored/) assert.doesNotMatch(tools, /pass only one of expr, at, or hour/) assert.match(index, /makeCronSkill/) assert.doesNotMatch(index, /agent\/session-start/) assert.doesNotMatch(index, /system-reminder/) assert.doesNotMatch(tools, /from ['"]@deepseek-ai\//) const host = await readFile(join(root, 'lib/host.js'), 'utf8') assert.match(host, /agentDefaultModel/) assert.match(host, /deliverRunToIm/) assert.match(host, /PLUGIN_NAME = 'dsh-ops-cron'/) assert.match(host, /API_PREFIX = '\/dsh-ops-cron'/) assert.match(host, /resolveSessionPlacement/) assert.match(host, /\/models/) assert.doesNotMatch(host, /from ['"]@deepseek-ai\//) const client = await readFile(join(root, 'lib/client.js'), 'utf8') assert.match(client, /运维定时/) assert.match(client, /dsh-ops-cron/) assert.match(client, /settings\.plugin\.item/) assert.match(client, /deliveryKind/) assert.match(client, /imBotId/) assert.match(client, /imTargetId/) assert.match(client, /CwdField/) assert.match(client, /ModelField/) assert.match(client, /inject = \['slots', 'locale', 'settingsScope'\]/) const delivery = await readFile(join(root, 'lib/delivery.js'), 'utf8') assert.match(delivery, /resolveCreateDelivery/) assert.match(delivery, /deliverRunToIm/) const prd = await readFile(join(root, 'docs/PRD.md'), 'utf8') assert.match(prd, /定时任务/) assert.match(prd, /dsh-schedule/) })