test: verify dragged paths with an @ segment are preserved
Adds a fixture under a scoped-package-style subdir (`@types/index.d.ts`) so we exercise the realistic `node_modules/@types/...` drag case and lock in that `extractDraggedFilePaths` returns the raw path unchanged — the `@` inside the path must not collide with the mention prefix the caller prepends downstream.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { afterAll, beforeAll, describe, expect, test } from 'bun:test'
|
import { afterAll, beforeAll, describe, expect, test } from 'bun:test'
|
||||||
import { mkdtempSync, rmSync, writeFileSync } from 'fs'
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'fs'
|
||||||
import { tmpdir } from 'os'
|
import { tmpdir } from 'os'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { extractDraggedFilePaths } from './dragDropPaths.js'
|
import { extractDraggedFilePaths } from './dragDropPaths.js'
|
||||||
@@ -10,13 +10,19 @@ describe('extractDraggedFilePaths', () => {
|
|||||||
const packageJson = `${process.cwd()}/package.json`
|
const packageJson = `${process.cwd()}/package.json`
|
||||||
|
|
||||||
// Temp dir with a file whose name contains a space, for Finder-drag
|
// Temp dir with a file whose name contains a space, for Finder-drag
|
||||||
// backslash-escape tests.
|
// backslash-escape tests, and a scoped-package-style subdir so we can
|
||||||
|
// exercise paths that embed `@` (e.g. `node_modules/@types/...`).
|
||||||
let tmpDir: string
|
let tmpDir: string
|
||||||
let spacedFile: string
|
let spacedFile: string
|
||||||
|
let atSignFile: string
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
tmpDir = mkdtempSync(join(tmpdir(), 'dragdrop-test-'))
|
tmpDir = mkdtempSync(join(tmpdir(), 'dragdrop-test-'))
|
||||||
spacedFile = join(tmpDir, 'my file.txt')
|
spacedFile = join(tmpDir, 'my file.txt')
|
||||||
writeFileSync(spacedFile, 'test')
|
writeFileSync(spacedFile, 'test')
|
||||||
|
const scopedDir = join(tmpDir, '@types')
|
||||||
|
mkdirSync(scopedDir)
|
||||||
|
atSignFile = join(scopedDir, 'index.d.ts')
|
||||||
|
writeFileSync(atSignFile, 'test')
|
||||||
})
|
})
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
rmSync(tmpDir, { recursive: true, force: true })
|
rmSync(tmpDir, { recursive: true, force: true })
|
||||||
@@ -128,4 +134,12 @@ describe('extractDraggedFilePaths', () => {
|
|||||||
test('trims surrounding whitespace from the whole paste', () => {
|
test('trims surrounding whitespace from the whole paste', () => {
|
||||||
expect(extractDraggedFilePaths(` ${thisFile} `)).toEqual([thisFile])
|
expect(extractDraggedFilePaths(` ${thisFile} `)).toEqual([thisFile])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('resolves a path that embeds an `@` segment', () => {
|
||||||
|
// Realistic case: dragging something under `node_modules/@types/...`.
|
||||||
|
// The `@` inside the path must not be confused with the mention prefix
|
||||||
|
// that the caller prepends downstream — `extractDraggedFilePaths`
|
||||||
|
// returns raw paths and leaves mention formatting to PromptInput.
|
||||||
|
expect(extractDraggedFilePaths(atSignFile)).toEqual([atSignFile])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user