|
| 1 | +import assert from 'node:assert/strict' |
| 2 | +import test from 'node:test' |
| 3 | +import { |
| 4 | + formatToolTitleWithDetail, |
| 5 | + getEventSkillName, |
| 6 | + getReadSkillTarget, |
| 7 | + getSandboxToolPath, |
| 8 | + sandboxFileListItems, |
| 9 | + skillFileListItems, |
| 10 | + skillScriptTitleCommand, |
| 11 | +} from './skillToolDisplay.ts' |
| 12 | + |
| 13 | +test('formatToolTitleWithDetail quotes a skill or path detail', () => { |
| 14 | + assert.equal(formatToolTitleWithDetail('读取技能', 'pdf-processing'), '读取技能:「pdf-processing」') |
| 15 | + assert.equal(formatToolTitleWithDetail('读取技能', ' '), '读取技能') |
| 16 | +}) |
| 17 | + |
| 18 | +test('getReadSkillTarget prefers skill/file from tool_data over arguments', () => { |
| 19 | + assert.equal( |
| 20 | + getReadSkillTarget({ |
| 21 | + arguments: { skill_name: 'old', file_path: 'SKILL.md' }, |
| 22 | + tool_data: { skill_name: 'pdf-processing', file_path: 'scripts/run.py' }, |
| 23 | + }), |
| 24 | + 'pdf-processing/scripts/run.py', |
| 25 | + ) |
| 26 | + assert.equal( |
| 27 | + getReadSkillTarget({ arguments: { skill_name: 'brandkit' } }), |
| 28 | + 'brandkit', |
| 29 | + ) |
| 30 | +}) |
| 31 | + |
| 32 | +test('getEventSkillName parses JSON-encoded arguments', () => { |
| 33 | + assert.equal( |
| 34 | + getEventSkillName({ arguments: '{"skill_name":"smart-charts"}' }), |
| 35 | + 'smart-charts', |
| 36 | + ) |
| 37 | +}) |
| 38 | + |
| 39 | +test('skillScriptTitleCommand drops a duplicated skill prefix', () => { |
| 40 | + assert.equal( |
| 41 | + skillScriptTitleCommand('pdf-processing', 'pdf-processing/scripts/run.py --fast'), |
| 42 | + 'scripts/run.py --fast', |
| 43 | + ) |
| 44 | + assert.equal(skillScriptTitleCommand('pdf-processing', 'ls'), 'ls') |
| 45 | +}) |
| 46 | + |
| 47 | +test('skillFileListItems skips SKILL.md and marks scripts', () => { |
| 48 | + const items = skillFileListItems({ |
| 49 | + files: ['SKILL.md', 'scripts/run.py', 'docs/guide.md', ''], |
| 50 | + }) |
| 51 | + assert.deepEqual( |
| 52 | + items.map((item) => ({ path: item.path, isScript: item.isScript })), |
| 53 | + [ |
| 54 | + { path: 'scripts/run.py', isScript: true }, |
| 55 | + { path: 'docs/guide.md', isScript: false }, |
| 56 | + ], |
| 57 | + ) |
| 58 | +}) |
| 59 | + |
| 60 | +test('sandboxFileListItems uses paths relative to the artifact root', () => { |
| 61 | + const items = sandboxFileListItems({ |
| 62 | + root: '/workspace/output', |
| 63 | + path: '/workspace/output', |
| 64 | + entries: [ |
| 65 | + { name: 'report.html', path: '/workspace/output/report.html', size: 12, modified_at: '2026-08-28T01:02:03Z' }, |
| 66 | + { name: 'chart.png', path: '/workspace/output/charts/chart.png', size: 2048 }, |
| 67 | + ], |
| 68 | + }) |
| 69 | + assert.equal(items[0].name, 'report.html') |
| 70 | + assert.equal(items[1].name, 'charts/chart.png') |
| 71 | + assert.equal(items[0].size, 12) |
| 72 | +}) |
| 73 | + |
| 74 | +test('getSandboxToolPath reads the listed directory', () => { |
| 75 | + assert.equal( |
| 76 | + getSandboxToolPath({ tool_data: { path: '/workspace/output/charts' } }), |
| 77 | + '/workspace/output/charts', |
| 78 | + ) |
| 79 | +}) |
0 commit comments