Files
opencode-manager/frontend/src/lib/fileReferences.test.ts
T
Chris Scott 68b13c8e35 fix(files): resolve workspace paths and add sandboxed HTML preview (#367)
* fix(files): resolve workspace paths and add sandboxed HTML preview

Accept workspace-absolute paths in the file service and return repo-relative paths for file reads and directory listings. Serve raw content under a CSP sandbox and preview HTML files in a sandboxed iframe with a raw toggle.

Resolve file-click paths from the session directory and repo local path, detect absolute and html/htm file references while ignoring URLs, accept the legacy filePath input key and filediff metadata, fix the file browser navigating into an initially selected directory, and use focus-visible rings across shared UI primitives.

* fix(files): address review feedback on navigation and path fallback

Key initial directory navigation to the initial selection so viewport changes do not reset it, and open the mobile preview from a separate effect.

Fall back to the legacy filePath input when path is empty, and cover both with regression tests.
2026-09-28 22:27:18 -04:00

21 lines
832 B
TypeScript

import { describe, it, expect } from 'vitest'
import { detectFileReferences } from './fileReferences'
describe('detectFileReferences', () => {
it('keeps the leading slash of absolute paths and parses line numbers', () => {
const [reference] = detectFileReferences('{"path": "/Users/me/workspace/repos/app/src/a.ts:12"}')
expect(reference.filePath).toBe('/Users/me/workspace/repos/app/src/a.ts')
expect(reference.lineNumber).toBe(12)
})
it('detects relative html and htm paths', () => {
expect(detectFileReferences('{"path": "./out/report.html", "other": "docs/page.htm"}').map((ref) => ref.filePath))
.toEqual(['./out/report.html', 'docs/page.htm'])
})
it('ignores the path portion of URLs', () => {
expect(detectFileReferences('fetch https://example.com/assets/app.js')).toEqual([])
})
})