Files
gsfdc/demo-dify/dify/packages/openapi-content-mapper/test/navigation.test.mjs
T
wuzilongandCursor 6519682885 chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-18 13:59:25 +08:00

50 lines
1.9 KiB
JavaScript

/* oxlint-disable vitest/no-import-node-test, antfu/no-import-dist -- Native integration with the built mapper and editor navigation adapter. */
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { compileRuntime, transformSpec } from '../dist/tooling/transform.js'
import { backendLocations } from '../vscode/locations.cjs'
/* oxlint-enable vitest/no-import-node-test, antfu/no-import-dist */
test('backend links survive Markdown-sensitive filenames without entering runtime modules', () => {
const spec = JSON.stringify({
openapi: '3.1.0',
info: { title: 'navigation', version: '1' },
paths: {
'/pets': {
get: {
'x-source-location': { file: './back end(1)*/handler.py', line: 12 },
responses: { 204: { description: 'OK' } },
},
},
},
})
const result = transformSpec(spec, '/project/spec.openapi')
assert.equal(result.diagnostics, undefined)
assert.deepEqual(backendLocations([{ value: result.text }]), [
{
uri: 'file:///project/back%20end%281%29%2A/handler.py',
line: 12,
},
])
assert.doesNotMatch(
compileRuntime(spec, '/project/spec.openapi')(['pets']),
/handler.py|x-source-location|Open backend/,
)
})
test('navigation ignores missing, malformed, unrelated and non-file links and deduplicates origins', () => {
const link = '[Open backend implementation](file:///project/backend.py#L9)'
assert.deepEqual(
backendLocations([
{ value: `${link}\n${link}` },
'[Unrelated](file:///project/other.py#L9)',
'[Open backend implementation](https://example.com/backend.py#L9)',
'[Open backend implementation](file:///project/backend.py#L0)',
'[Open backend implementation](file:///project/backend.py#L99999999999999999)',
'[Open backend implementation](file:///project/backend.py?query=x#L9)',
'ordinary hover without metadata',
]),
[{ uri: 'file:///project/backend.py', line: 9 }],
)
})