Files
adnify/tests/unit/shared/utils/remoteDownloadPath.test.ts
adnaan c55bb66781 fix(agent): bound tall tool result lists; shrink approval buttons
The symbol list (find_symbol / get_document_symbols) rendered every match into
an unbounded div, and LintCheckCard expanded every error with no ceiling, so a
50-symbol result or a file with hundreds of lint errors produced an arbitrarily
tall card. The diagnostics / references previews were already bounded (char cap
plus ExpandablePreviewContainer); these two branches had slipped through.

- Wrap the symbol list in the existing ExpandablePreviewContainer
  (max-h 220px, expand to 440px), matching every other preview: fade + expand
  affordance on overflow
- Cap LintCheckCard's expanded error details at max-h 260px with a scroll area;
  the collapse header already existed, only the expanded body was unbounded

Also tightens the tool approval action bar, which was oversized for a control
that lives inside a card: height 32->26px, icons 14->12px, tighter padding and
rounding. Reject/Stop drop to quiet muted-text buttons (color on hover only);
only Allow keeps the accent fill, so the primary action reads at a glance.

Fixes a Windows-only failure in remoteDownloadPath.test.ts: the expectations
used path.join on a POSIX root, which yields a drive-letter-less path, while
the implementation resolves to an absolute path (current drive). Resolve the
expected values the same way so they match on both platforms.
2026-08-24 23:16:32 +08:00

46 lines
1.9 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import path from 'path'
import {
assertSafeRemoteName,
buildDirectoryDownloadTarget,
buildDirectoryUploadRemoteTarget,
isSftpSymbolicLinkMode,
remoteDirectoryBasename,
safeJoinUnderDownloadRoot,
} from '@/shared/utils/remoteDownloadPath'
describe('remoteDownloadPath', () => {
it('builds a destination folder from the remote basename', () => {
// buildDirectoryDownloadTarget resolves the parent to an absolute path, so the
// expectation must resolve too — otherwise on Windows `path.join` yields a
// drive-letter-less `\tmp\...` while `resolve` prepends the current drive.
expect(buildDirectoryDownloadTarget('/tmp/downloads', '/home/ubuntu/project')).toBe(
path.join(path.resolve('/tmp/downloads'), 'project'),
)
expect(remoteDirectoryBasename('/')).toBe('remote-download')
expect(remoteDirectoryBasename('/var/log/')).toBe('log')
})
it('builds a remote upload target from the local basename', () => {
expect(buildDirectoryUploadRemoteTarget('/var/www', '/tmp/my-app')).toBe('/var/www/my-app')
expect(buildDirectoryUploadRemoteTarget('.', '/tmp/my-app')).toBe('my-app')
expect(buildDirectoryUploadRemoteTarget('/', '/tmp/my-app')).toBe('/my-app')
})
it('rejects unsafe remote names and path escapes', () => {
expect(() => assertSafeRemoteName('..')).toThrow(/Unsafe/)
expect(() => assertSafeRemoteName('a/b')).toThrow(/Unsafe/)
expect(() => assertSafeRemoteName(' padded ')).toThrow(/Unsafe/)
expect(() => safeJoinUnderDownloadRoot('/tmp/out', '..')).toThrow()
expect(safeJoinUnderDownloadRoot('/tmp/out', 'src', 'main.ts')).toBe(
path.join(path.resolve('/tmp/out'), 'src', 'main.ts'),
)
})
it('detects SFTP symlink mode bits', () => {
expect(isSftpSymbolicLinkMode(0o120777)).toBe(true)
expect(isSftpSymbolicLinkMode(0o040755)).toBe(false)
expect(isSftpSymbolicLinkMode(0o100644)).toBe(false)
})
})