dsh-ops-cron/test/package.test.js
oliver 819feed310 Make origin session mirror opt-in per job.
Default mirrorToSession to false so cron summaries stay in run history unless the sidebar checkbox or mirror_to_session is enabled.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-08 21:00:20 +08:00

82 lines
3.7 KiB
JavaScript

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.match(tools, /agent_preset/)
assert.match(tools, /resolveCreateAgentPreset/)
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, /mirrorRunToSession/)
assert.match(host, /mirrorToSession/)
assert.match(host, /getAgents/)
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.match(host, /\/presets/)
assert.match(host, /composeCronAgent/)
assert.match(host, /listPresetChoices/)
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, /PresetField/)
assert.match(client, /agentPreset/)
assert.match(client, /mirrorToSession/)
assert.match(client, /inject = \['slots', 'locale', 'settingsScope'\]/)
const preset = await readFile(join(root, 'lib/preset.js'), 'utf8')
assert.match(preset, /resolveCreateAgentPreset/)
const delivery = await readFile(join(root, 'lib/delivery.js'), 'utf8')
assert.match(delivery, /resolveCreateDelivery/)
assert.match(delivery, /resolveCreateOrigin/)
assert.match(delivery, /mirrorRunToSession/)
assert.match(delivery, /deliverRunToIm/)
assert.match(client, /origin/)
const prd = await readFile(join(root, 'docs/PRD.md'), 'utf8')
assert.match(prd, /定时任务/)
assert.match(prd, /dsh-schedule/)
})