Files
orca/src/shared/terminal-file-url-target.test.ts
Brennan Benson 624c8d4120 Make plain-text file:// links clickable in the terminal (#9467)
* Make plain-text file:// links clickable in the terminal

Printed file:// URIs (e.g. a report path echoed by a tool or agent) were
neither http links nor bare filesystem paths, so the terminal's URL and
local-path detectors both skipped them and the link was dead.

Orca already resolves and opens file:// URIs for OSC 8 hyperlinks. Reuse
that exact resolver for plain-text URIs so a printed file:// behaves the
same whether or not the emitter wrapped it in an escape sequence:

- Promote the (dependency-pure) file-url target resolver into src/shared
  so the OSC path and the new plain-text path share one implementation.
- Add a file:// detector that decodes the URI to a filesystem path and
  routes it through the existing file-link pipeline (existence probe +
  openDetectedFilePath), so line/col anchors, %20, Windows drive paths,
  html-in-browser, editor reveal, and SSH/runtime resolution all just work.

Lines without file:// are unchanged: the pass short-circuits to the prior
result, so only file://-bearing lines gain a link.

- Add unit + integration coverage for detection, decoding, and no-double-link.

* Harden plain-text file URI detection

* Split terminal file link detection modules
2026-07-19 15:21:06 -07:00

21 lines
645 B
TypeScript

import { describe, expect, it } from 'vitest'
import { resolveTerminalFileUrlTarget } from './terminal-file-url-target'
describe('resolveTerminalFileUrlTarget', () => {
it('resolves UNC file URLs with line and column anchors', () => {
expect(
resolveTerminalFileUrlTarget(new URL('file://Server/Share/Repo/src/app.ts#L12C3'), {
allowUncHost: true
})
).toEqual({
filePath: '//server/Share/Repo/src/app.ts',
line: 12,
column: 3
})
})
it('returns null for malformed file URL escapes', () => {
expect(resolveTerminalFileUrlTarget(new URL('file:///tmp/%E0%A4%A.txt'))).toBeNull()
})
})