Buckets:

download
raw
4.26 kB
from pathlib import Path
import pytest
from chunker import extract_boundary_ir as extract_boundary_ir_public
from chunker.boundary import extract_boundary_ir
from chunker.parser import list_languages
def test_extract_boundary_ir_python_repo_is_deterministic(tmp_path: Path):
source = tmp_path / "service.py"
source.write_text(
"def helper(name):\n"
" return name.upper()\n\n"
"def greet(name):\n"
" return helper(name)\n",
encoding="utf-8",
)
first = extract_boundary_ir(tmp_path, "python")
second = extract_boundary_ir(tmp_path, "python")
assert first == second
assert list(first) == [
"diagnostics",
"edges",
"files",
"metrics",
"nodes",
"run",
"schema_version",
"source",
]
assert first["schema_version"] == "2.0"
assert first["files"][0]["path"] == "service.py"
assert first["metrics"]["files_total"] == 1
assert first["metrics"]["nodes_total"] >= 2
assert first["run"]["created_at"] is None
assert any(node["identity"]["source"] == "definition_id" for node in first["nodes"])
def test_extract_boundary_ir_top_level_export_matches_boundary_module(tmp_path: Path):
source = tmp_path / "app.py"
source.write_text("def greet(name):\n return name\n", encoding="utf-8")
direct = extract_boundary_ir(tmp_path, "python")
public = extract_boundary_ir_public(tmp_path, "python")
assert public == direct
assert public["schema_version"] == "2.0"
def test_extract_boundary_ir_single_file_uses_file_source_kind(tmp_path: Path):
source = tmp_path / "service.py"
source.write_text(
"def helper(name):\n"
" return name.upper()\n\n"
"def greet(name):\n"
" return helper(name)\n",
encoding="utf-8",
)
ir = extract_boundary_ir(source, "python")
assert ir["source"]["kind"] == "file"
assert ir["source"]["path"] == str(source)
assert [item["path"] for item in ir["files"]] == ["service.py"]
assert all(node["path"] == "service.py" for node in ir["nodes"])
def test_extract_boundary_ir_records_unresolved_python_edge(tmp_path: Path):
source = tmp_path / "service.py"
source.write_text(
"import missing_lib\n\n"
"def use_missing():\n"
" return missing_lib.value\n",
encoding="utf-8",
)
ir = extract_boundary_ir(tmp_path, "python")
unresolved = [edge for edge in ir["edges"] if edge["resolution"] == "unresolved"]
assert unresolved
assert ir["metrics"]["unresolved_edges"] == len(unresolved)
assert all(edge["candidates"] == [] for edge in unresolved)
def test_extract_boundary_ir_javascript_resolved_call(tmp_path: Path):
(tmp_path / "helper.js").write_text(
"export function helper(name) { return name; }\n",
encoding="utf-8",
)
(tmp_path / "service.js").write_text(
"import { helper } from './helper.js';\n"
"export function greet(name) {\n"
" return helper(name);\n"
"}\n",
encoding="utf-8",
)
ir = extract_boundary_ir(tmp_path, "javascript")
assert any(edge["resolution"] == "resolved" for edge in ir["edges"])
assert ir["metrics"]["resolved_edges"] >= 1
def test_extract_boundary_ir_created_at_is_opt_in(tmp_path: Path):
source = tmp_path / "service.py"
source.write_text("def greet():\n return 'hi'\n", encoding="utf-8")
default_ir = extract_boundary_ir(tmp_path, "python")
pinned_ir = extract_boundary_ir(
tmp_path,
"python",
created_at="2026-04-30T00:00:00Z",
)
assert default_ir["run"]["created_at"] is None
assert pinned_ir["run"]["created_at"] == "2026-04-30T00:00:00Z"
def test_extract_boundary_ir_go_core_fields_when_grammar_available(tmp_path: Path):
if "go" not in list_languages():
pytest.skip("go grammar is not available")
(tmp_path / "main.go").write_text(
'package main\n\nfunc greet() string {\n\treturn "hi"\n}\n',
encoding="utf-8",
)
ir = extract_boundary_ir(tmp_path, "go")
assert ir["files"][0]["language"] == "go"
assert ir["nodes"]
assert ir["metrics"]["nodes_total"] == len(ir["nodes"])

Xet Storage Details

Size:
4.26 kB
·
Xet hash:
190ac2b0f69197606be345b43cab67dab8415492305b32177f12bd409cbdb6d9

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.