|
1 | 1 | import { spawnSync } from 'node:child_process' |
| 2 | +import { mkdtempSync, rmSync, writeFileSync } from 'node:fs' |
| 3 | +import { tmpdir } from 'node:os' |
2 | 4 | import { join } from 'node:path' |
3 | 5 | import { fileURLToPath } from 'node:url' |
4 | 6 | import { describe, expect, it } from 'vite-plus/test' |
@@ -106,3 +108,30 @@ d('install-r2.ps1 install location, PATH hint and download', () => { |
106 | 108 | expect(r.stdout).toMatch(/checksum mismatch/) |
107 | 109 | }) |
108 | 110 | }) |
| 111 | + |
| 112 | +// A v2 binary answers `install skills --help`; a v1 one exits 1 with "unknown command". |
| 113 | +// The fakes are shell scripts, so this runs where pwsh runs outside Windows. |
| 114 | +describe.skipIf(!hasPwsh || process.platform === 'win32')('install-r2.ps1 Write-SkillHint', () => { |
| 115 | + const hint = (bin: string) => pwsh(`Write-SkillHint '${bin}'`) |
| 116 | + |
| 117 | + it('prints the hint for a binary that has install skills, and stays quiet otherwise', () => { |
| 118 | + const dir = mkdtempSync(join(tmpdir(), 'difyctl-hint-')) |
| 119 | + try { |
| 120 | + const v2 = join(dir, 'v2') |
| 121 | + const v1 = join(dir, 'v1') |
| 122 | + writeFileSync(v2, '#!/bin/sh\n[ "$*" = "install skills --help" ]\n', { mode: 0o755 }) |
| 123 | + writeFileSync(v1, '#!/bin/sh\necho "unknown command: $*" >&2\nexit 1\n', { mode: 0o755 }) |
| 124 | + expect(hint(v2)).toMatchObject({ |
| 125 | + code: 0, |
| 126 | + stdout: expect.stringContaining('difyctl install skills <skills root>'), |
| 127 | + }) |
| 128 | + expect(hint(v1)).toMatchObject({ code: 0, stdout: '' }) |
| 129 | + } finally { |
| 130 | + rmSync(dir, { recursive: true, force: true }) |
| 131 | + } |
| 132 | + }) |
| 133 | + |
| 134 | + it('prints nothing when the binary cannot run', () => { |
| 135 | + expect(hint('/nonexistent/difyctl')).toMatchObject({ code: 0, stdout: '' }) |
| 136 | + }) |
| 137 | +}) |
0 commit comments