🐛 fix(vscode): 调用树不统计测试代码

This commit is contained in:
cruldra committed 2026-10-11 22:57:15 +11:00
1 parent eff84a4df3
commit 066681d601
3 files changed
+80 -2

No files matched your search

@@ -10,6 +10,10 @@ function range(line: number, character = 0): CallRange {
return { line, character, endLine: line, endCharacter: character + 3 }
}
function symbolIn(path: string, name: string): CallSymbol {
return { ...symbol(name), path }
}
describe('顺着调用者往上收集调用边', () => {
it('有环就停,不再问已经走过的那个', async () => {
const target = symbol('mask_phone')
@@ -85,6 +89,73 @@ describe('顺着调用者往上收集调用边', () => {
])
})
it('业务代码的调用者里有测试函数:测试函数不当调用者,也不再往上问', async () => {
const target = symbolIn('app/sync.py', 'sync_users')
const job = symbolIn('app/jobs.py', 'run_jobs')
const inTestsDir = symbolIn('tests/test_sync.py', 'test_sync_runs')
const byFileName = symbolIn('test_x.py', 'test_x')
const asked: string[] = []
const outgoingAsked: string[] = []
const edges = await collectCallEdges(target, async (node) => {
asked.push(node.name)
if (node.name === 'sync_users') {
return [
{ from: inTestsDir, ranges: [range(3)] },
{ from: byFileName, ranges: [range(5)] },
{ from: job, ranges: [range(7)] },
]
}
return []
}, async (node) => {
outgoingAsked.push(node.name)
return []
})
expect(asked).toEqual(['sync_users', 'run_jobs'])
expect(outgoingAsked).toEqual(['run_jobs'])
expect(edges).toEqual([{ caller: job, callee: target, at: range(7) }])
})
it('往下问到的被调用方在测试文件里,这条边不收', async () => {
const target = symbolIn('app/sync.py', 'sync_users')
const job = symbolIn('app/jobs.py', 'run_jobs')
const fixture = symbolIn('tests/conftest.py', 'make_user')
const side = symbolIn('app/log.py', 'log_event')
const edges = await collectCallEdges(target, async (node) => {
if (node.name === 'sync_users')
return [{ from: job, ranges: [range(4)] }]
return []
}, async () => [
{ to: target, ranges: [range(4)] },
{ to: fixture, ranges: [range(6)] },
{ to: side, ranges: [range(8)] },
])
expect(edges).toEqual([
{ caller: job, callee: target, at: range(4) },
{ caller: job, callee: side, at: range(8) },
])
})
it('当前块本身在测试文件里:测试函数照样当调用者,往下问到的测试代码也收', async () => {
const target = symbolIn('tests/conftest.py', 'make_user')
const caller = symbolIn('tests/test_sync.py', 'test_sync_runs')
const helper = symbolIn('tests/helpers.py', 'fake_db')
const asked: string[] = []
const edges = await collectCallEdges(target, async (node) => {
asked.push(node.name)
if (node.name === 'make_user')
return [{ from: caller, ranges: [range(2)] }]
return []
}, async () => [
{ to: target, ranges: [range(2)] },
{ to: helper, ranges: [range(5)] },
])
expect(asked).toEqual(['make_user', 'test_sync_runs'])
expect(edges).toEqual([
{ caller, callee: target, at: range(2) },
{ caller, callee: helper, at: range(5) },
])
})
it('取消之后不再问下一个人', async () => {
const target = symbol('mask_phone')
const caller = symbol('get_profile')