Repository navigation
Expand file tree
/
Copy pathtest_lua_functions.py
More file actions
80 lines (62 loc) · 1.83 KB
/
Copy pathtest_lua_functions.py
File metadata and controls
80 lines (62 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from pathlib import Path
from unittest.mock import MagicMock
from codebase_rag.graph_updater import GraphUpdater
from codebase_rag.parser_loader import load_parsers
def test_lua_function_discovery(temp_repo: Path, mock_ingestor: MagicMock) -> None:
"""Ensure Lua functions are discovered and function calls are tracked."""
project_path = temp_repo / "lua_functions_test"
project_path.mkdir()
(project_path / "mod.lua").write_text(
"""
local M = {}
local function local_add(a, b)
return a + b
end
function M.mul(a, b)
return a * b
end
function M.use(add_fn, x, y)
return add_fn(x, y) + M.mul(x, y)
end
return M
"""
)
(project_path / "main.lua").write_text(
"""
local mod = require('mod')
local function compute(x, y)
return mod.use(function(a,b) return a - b end, x, y)
end
local r = compute(4, 2)
"""
)
parsers, queries = load_parsers()
assert "lua" in parsers, "Lua parser should be available"
updater = GraphUpdater(
ingestor=mock_ingestor,
repo_path=project_path,
parsers=parsers,
queries=queries,
)
updater.run()
# Function nodes should be created for M.mul, M.use, compute, local_add
created_functions = [
c
for c in mock_ingestor.ensure_node_batch.call_args_list
if c[0][0] == "Function"
]
fn_qns = {c[0][1]["qualified_name"] for c in created_functions}
expected_suffixes = {
".mod.local_add",
".mod.M.mul",
".mod.M.use",
".main.compute",
}
assert any(qn.endswith(s) for s in expected_suffixes for qn in fn_qns), fn_qns
# Calls should include call to compute and inline anonymous function
call_rels = [
c
for c in mock_ingestor.ensure_relationship_batch.call_args_list
if c.args[1] == "CALLS"
]
assert len(call_rels) >= 1