mirror of
https://github.com/hansjone/dsh-ops-cron.git
synced 2026-10-09 08:23:15 +08:00
Stamp and reclaim chat-created cron jobs for the current user.
Tool creates often left ownerEmpNo unassigned so the sidebar hid them while runs still fired; infer identity from session/cwd, claim legacy orphans on list, and keep cron rows visible without leaking run sessions into the workspace list. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
d298c77f3f
commit
a0dc070372
7 changed files with 254 additions and 25 deletions
|
|
@ -4,7 +4,7 @@ import { tmpdir } from 'node:os'
|
|||
import { join } from 'node:path'
|
||||
import { test } from 'node:test'
|
||||
import { createHostService } from '../lib/host.js'
|
||||
import { callerWorkingDirectory, cronToolDefinitions, registerCronGuidance, registerCronTools, resolveCreateCwd, resolveCreateModel, scheduleFromArgs } from '../lib/tools.js'
|
||||
import { callerWorkingDirectory, cronToolDefinitions, registerCronGuidance, registerCronTools, resolveCreateCwd, resolveCreateModel, resolveToolIdentity, scheduleFromArgs } from '../lib/tools.js'
|
||||
|
||||
async function makeService(t) {
|
||||
const dir = await mkdtemp(join(tmpdir(), 'dsh-cron-tools-'))
|
||||
|
|
@ -241,6 +241,25 @@ test('registerCronGuidance registers the scheduled-tasks skill only', () => {
|
|||
assert.equal(skills.length, 0)
|
||||
})
|
||||
|
||||
test('cron_create stamps ownerEmpNo from user-workspaces cwd', async (t) => {
|
||||
const service = await makeService(t)
|
||||
const tools = byName(cronToolDefinitions(service))
|
||||
const exec = { agent: { session: { header: { cwd: '/tmp/user-workspaces/alice/app' } } } }
|
||||
assert.equal(resolveToolIdentity(exec, service)?.empNo, 'alice')
|
||||
const created = await tools.cron_create.execute({
|
||||
name: 'owned',
|
||||
prompt: 'ping',
|
||||
after_minutes: 5,
|
||||
timezone: 'Asia/Shanghai',
|
||||
}, exec)
|
||||
assert.equal(created.job.ownerEmpNo, 'alice')
|
||||
assert.equal(created.job.cwd, '/tmp/user-workspaces/alice/app')
|
||||
|
||||
const listed = await tools.cron_list.execute({}, exec)
|
||||
assert.equal(listed.count, 1)
|
||||
assert.equal(listed.jobs[0].id, created.job.id)
|
||||
})
|
||||
|
||||
test('registerCronTools registers each definition and disposer unregisters', () => {
|
||||
const registered = []
|
||||
const ctx = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue