|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | +import { test } from 'vitest'; |
| 3 | +import { AppError } from '@agent-device/kernel/errors'; |
| 4 | +import type { AgentDeviceClient } from '../agent-device-client.ts'; |
| 5 | +import { tryRunClientBackedCommand } from '../cli/commands/router.ts'; |
| 6 | + |
| 7 | +const REACHED_CLIENT = new Error('reached the client'); |
| 8 | + |
| 9 | +async function runInstallFromSource(source: string) { |
| 10 | + const client = { |
| 11 | + apps: { |
| 12 | + installFromSource: async () => { |
| 13 | + throw REACHED_CLIENT; |
| 14 | + }, |
| 15 | + }, |
| 16 | + } as unknown as AgentDeviceClient; |
| 17 | + return await tryRunClientBackedCommand({ |
| 18 | + command: 'install-from-source', |
| 19 | + positionals: [source], |
| 20 | + flags: { json: false, help: false, version: false }, |
| 21 | + client, |
| 22 | + }); |
| 23 | +} |
| 24 | + |
| 25 | +test('install-from-source refuses a local path with a typed error', async () => { |
| 26 | + await assert.rejects( |
| 27 | + () => runInstallFromSource('/abs/path/app.zip'), |
| 28 | + (error) => |
| 29 | + error instanceof AppError && |
| 30 | + error.code === 'INVALID_ARGS' && |
| 31 | + error.message === 'install-from-source <url> must be an http(s) URL: /abs/path/app.zip' && |
| 32 | + String(error.details?.hint).includes('install <app> <path>'), |
| 33 | + ); |
| 34 | +}); |
| 35 | + |
| 36 | +for (const source of [ |
| 37 | + 'http://', |
| 38 | + 'https://', |
| 39 | + 'http://exa mple.com/app.zip', |
| 40 | + 'ftp://example.com/app.zip', |
| 41 | + 'example.com/app.zip', |
| 42 | +]) { |
| 43 | + test(`install-from-source refuses ${JSON.stringify(source)} before any work`, async () => { |
| 44 | + await assert.rejects( |
| 45 | + () => runInstallFromSource(source), |
| 46 | + (error) => |
| 47 | + error instanceof AppError && |
| 48 | + error.code === 'INVALID_ARGS' && |
| 49 | + String(error.details?.hint).includes('install <app> <path>'), |
| 50 | + ); |
| 51 | + }); |
| 52 | +} |
| 53 | + |
| 54 | +test('install-from-source passes an http(s) URL to the client', async () => { |
| 55 | + await assert.rejects( |
| 56 | + () => runInstallFromSource('HTTPS://example.com/app.zip'), |
| 57 | + (error) => error === REACHED_CLIENT, |
| 58 | + ); |
| 59 | +}); |
0 commit comments