rbtr-lang-json 2026.9.0.dev1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alejandro Giacometti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,61 @@
1
+ Metadata-Version: 2.4
2
+ Name: rbtr-lang-json
3
+ Version: 2026.9.0.dev1
4
+ Summary: rbtr — JSON language plugin
5
+ Keywords: code-search,code-index,tree-sitter,static-analysis,semantic-search,developer-tools,json
6
+ Author: Alejandro Giacometti
7
+ Author-email: Alejandro Giacometti <alejandro.giacometti@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Topic :: Software Development :: Libraries
15
+ Classifier: Topic :: Text Processing :: Indexing
16
+ Classifier: Typing :: Typed
17
+ Requires-Dist: rbtr==2026.9.0.dev1
18
+ Requires-Dist: tree-sitter-json
19
+ Requires-Python: >=3.13
20
+ Project-URL: Homepage, https://github.com/janrito/rbtr
21
+ Project-URL: Repository, https://github.com/janrito/rbtr
22
+ Project-URL: Documentation, https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-json#readme
23
+ Project-URL: Issues, https://github.com/janrito/rbtr/issues
24
+ Project-URL: Changelog, https://github.com/janrito/rbtr/releases
25
+ Description-Content-Type: text/markdown
26
+
27
+ # rbtr-lang-json
28
+
29
+ JSON support for [rbtr]. Optional plugin — install with
30
+ `pip install rbtr[json]`.
31
+
32
+ [rbtr]: https://github.com/janrito/rbtr/tree/main/packages/rbtr#readme
33
+
34
+ ## What it ingests
35
+
36
+ Top-level keys of the root object become **config-key** chunks (JSON is data,
37
+ not code). Non-object JSON (arrays, scalars) produces no structural chunks and
38
+ falls through to plaintext.
39
+
40
+ A `$ref` or an `extends` names another file, so each becomes an **import**
41
+ and links the two documents. A `$ref`'s pointer — the part after the `#` —
42
+ names a key inside the file it reaches, so the edge lands on that key rather
43
+ than on the document as a whole.
44
+
45
+ ## Chunks produced
46
+
47
+ ```json
48
+ {
49
+ "name": "my-project", // config_key "name"
50
+ "version": "1.0.0", // config_key "version"
51
+ "dependencies": { … } // config_key "dependencies"
52
+ }
53
+ ```
54
+
55
+ ## Embedded / injected chunks
56
+
57
+ None. JSON does not embed other languages.
58
+
59
+ ## Grammar & dependencies
60
+
61
+ Uses the `tree-sitter-json` grammar. No dependency on other language plugins.
@@ -0,0 +1,35 @@
1
+ # rbtr-lang-json
2
+
3
+ JSON support for [rbtr]. Optional plugin — install with
4
+ `pip install rbtr[json]`.
5
+
6
+ [rbtr]: https://github.com/janrito/rbtr/tree/main/packages/rbtr#readme
7
+
8
+ ## What it ingests
9
+
10
+ Top-level keys of the root object become **config-key** chunks (JSON is data,
11
+ not code). Non-object JSON (arrays, scalars) produces no structural chunks and
12
+ falls through to plaintext.
13
+
14
+ A `$ref` or an `extends` names another file, so each becomes an **import**
15
+ and links the two documents. A `$ref`'s pointer — the part after the `#` —
16
+ names a key inside the file it reaches, so the edge lands on that key rather
17
+ than on the document as a whole.
18
+
19
+ ## Chunks produced
20
+
21
+ ```json
22
+ {
23
+ "name": "my-project", // config_key "name"
24
+ "version": "1.0.0", // config_key "version"
25
+ "dependencies": { … } // config_key "dependencies"
26
+ }
27
+ ```
28
+
29
+ ## Embedded / injected chunks
30
+
31
+ None. JSON does not embed other languages.
32
+
33
+ ## Grammar & dependencies
34
+
35
+ Uses the `tree-sitter-json` grammar. No dependency on other language plugins.
@@ -0,0 +1,57 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.11.26,<1"]
3
+ build-backend = "uv_build"
4
+
5
+ [tool.uv.build-backend]
6
+ module-name = "rbtr_lang_json"
7
+
8
+ [tool.uv.sources.rbtr]
9
+ workspace = true
10
+
11
+ [project]
12
+ name = "rbtr-lang-json"
13
+ version = "2026.9.0-dev1"
14
+ description = "rbtr — JSON language plugin"
15
+ readme = "README.md"
16
+ license = "MIT"
17
+ license-files = ["LICENSE"]
18
+ keywords = [
19
+ "code-search",
20
+ "code-index",
21
+ "tree-sitter",
22
+ "static-analysis",
23
+ "semantic-search",
24
+ "developer-tools",
25
+ "json",
26
+ ]
27
+ classifiers = [
28
+ "Development Status :: 4 - Beta",
29
+ "Intended Audience :: Developers",
30
+ "Programming Language :: Python :: 3 :: Only",
31
+ "Programming Language :: Python :: 3.13",
32
+ "Topic :: Software Development :: Libraries",
33
+ "Topic :: Text Processing :: Indexing",
34
+ "Typing :: Typed",
35
+ ]
36
+ requires-python = ">=3.13"
37
+ dependencies = [
38
+ "rbtr==2026.9.0-dev1",
39
+ "tree-sitter-json",
40
+ ]
41
+
42
+ [[project.authors]]
43
+ name = "Alejandro Giacometti"
44
+ email = "alejandro.giacometti@gmail.com"
45
+
46
+ [project.urls]
47
+ Homepage = "https://github.com/janrito/rbtr"
48
+ Repository = "https://github.com/janrito/rbtr"
49
+ Documentation = "https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-json#readme"
50
+ Issues = "https://github.com/janrito/rbtr/issues"
51
+ Changelog = "https://github.com/janrito/rbtr/releases"
52
+
53
+ [project.entry-points."rbtr.languages"]
54
+ json = "rbtr_lang_json.plugin:json"
55
+
56
+ [dependency-groups]
57
+ dev = ["rbtr[test]"]
@@ -0,0 +1,61 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.11.26,<1"]
3
+ build-backend = "uv_build"
4
+
5
+ [tool.uv.build-backend]
6
+ module-name = "rbtr_lang_json"
7
+ # No source-exclude: the plugin's tests, samples, and snapshots ship with
8
+ # the wheel (they are the language's golden record), and json.scm ships as
9
+ # package data.
10
+
11
+ [project]
12
+ name = "rbtr-lang-json"
13
+ version = "2026.9.0-dev1"
14
+ description = "rbtr — JSON language plugin"
15
+ readme = "README.md"
16
+ license = "MIT"
17
+ license-files = ["LICENSE"]
18
+ authors = [
19
+ { name = "Alejandro Giacometti", email = "alejandro.giacometti@gmail.com" },
20
+ ]
21
+ keywords = [
22
+ "code-search",
23
+ "code-index",
24
+ "tree-sitter",
25
+ "static-analysis",
26
+ "semantic-search",
27
+ "developer-tools",
28
+ "json",
29
+ ]
30
+ classifiers = [
31
+ "Development Status :: 4 - Beta",
32
+ "Intended Audience :: Developers",
33
+ "Programming Language :: Python :: 3 :: Only",
34
+ "Programming Language :: Python :: 3.13",
35
+ "Topic :: Software Development :: Libraries",
36
+ "Topic :: Text Processing :: Indexing",
37
+ "Typing :: Typed",
38
+ ]
39
+ requires-python = ">=3.13"
40
+ dependencies = [
41
+ "rbtr==2026.9.0-dev1",
42
+ "tree-sitter-json",
43
+ ]
44
+
45
+ [project.urls]
46
+ Homepage = "https://github.com/janrito/rbtr"
47
+ Repository = "https://github.com/janrito/rbtr"
48
+ Documentation = "https://github.com/janrito/rbtr/tree/main/packages/rbtr-lang-json#readme"
49
+ Issues = "https://github.com/janrito/rbtr/issues"
50
+ Changelog = "https://github.com/janrito/rbtr/releases"
51
+
52
+ [project.entry-points."rbtr.languages"]
53
+ # The value resolves to the language's `LanguageRegistration` (named by its
54
+ # id) — see the rbtr ARCHITECTURE "External plugins" note.
55
+ json = "rbtr_lang_json.plugin:json"
56
+
57
+ [tool.uv.sources]
58
+ rbtr = { workspace = true }
59
+
60
+ [dependency-groups]
61
+ dev = ["rbtr[test]"]
@@ -0,0 +1 @@
1
+ """JSON language plugin package."""
@@ -0,0 +1,9 @@
1
+ (pair
2
+ key: (string (string_content) @_section_name)) @config_key
3
+
4
+ ; A `$ref` names another schema document, and `extends` names a base
5
+ ; configuration: both are references to a file this repository may hold.
6
+ (pair
7
+ key: (string (string_content) @_key)
8
+ (#any-of? @_key "$ref" "extends")
9
+ value: (string (string_content) @_import_module)) @import
@@ -0,0 +1,58 @@
1
+ """JSON language plugin.
2
+
3
+ Splits JSON by top-level keys in the root object via a
4
+ tree-sitter query, one config-key chunk per key. Non-object JSON
5
+ (arrays, scalars) produces no structural chunks and falls through
6
+ to plaintext.
7
+
8
+ Extracted chunks::
9
+
10
+ { → config_key "name", scope ""
11
+ "name": "my-project", → config_key "version", scope ""
12
+ "version": "1.0.0", → config_key "dependencies", scope ""
13
+ "dependencies": { ... }
14
+ }
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ from typing import TYPE_CHECKING
20
+
21
+ from rbtr.domain.models import ImportMeta
22
+ from rbtr.languages.registration import (
23
+ ImportResolver,
24
+ LanguageRegistration,
25
+ QueryExtraction,
26
+ load_query,
27
+ )
28
+
29
+ if TYPE_CHECKING:
30
+ from tree_sitter import Node
31
+
32
+ json = LanguageRegistration(
33
+ id="json",
34
+ extensions=frozenset({".json"}),
35
+ grammar_module="tree_sitter_json",
36
+ extraction=QueryExtraction(
37
+ query=load_query(__package__, "json"),
38
+ ),
39
+ extraction_serial=3,
40
+ )
41
+
42
+
43
+ @json.import_extractor
44
+ def split_pointer_fragment(
45
+ resolver: ImportResolver, node: Node, captures: dict[str, list[Node]]
46
+ ) -> ImportMeta:
47
+ """Separate a JSON pointer from the document it points into.
48
+
49
+ `{"$ref": "defs.json#/Named"}` reaches `defs.json`, and the pointer
50
+ after the `#` names what it wants inside it, which is the same shape a
51
+ Markdown link to a heading has.
52
+ """
53
+ meta = resolver(node, captures)
54
+ if "#" in meta.module:
55
+ module, _, pointer = meta.module.partition("#")
56
+ meta.module = module
57
+ meta.names = pointer.lstrip("/").replace("/", ".")
58
+ return meta
@@ -0,0 +1,3 @@
1
+ [
2
+ "schema/greeting.json::\"$ref\": \"defs.json#/Name\" -> schema/defs.json::Name [imports]"
3
+ ]
@@ -0,0 +1,306 @@
1
+ [
2
+ {
3
+ "blob_sha": "sha1",
4
+ "file_path": "json.json",
5
+ "kind": "config_key",
6
+ "name": "name",
7
+ "scope": "",
8
+ "language": "json",
9
+ "file_language": "json",
10
+ "content": "\"name\": \"greeter\"",
11
+ "line_start": 2,
12
+ "line_end": 2,
13
+ "metadata": {
14
+ "module": "",
15
+ "names": "",
16
+ "dots": "",
17
+ "language_hint": ""
18
+ },
19
+ "id": "3b6dd850e3e3752a"
20
+ },
21
+ {
22
+ "blob_sha": "sha1",
23
+ "file_path": "json.json",
24
+ "kind": "config_key",
25
+ "name": "version",
26
+ "scope": "",
27
+ "language": "json",
28
+ "file_language": "json",
29
+ "content": "\"version\": \"1.0.0\"",
30
+ "line_start": 3,
31
+ "line_end": 3,
32
+ "metadata": {
33
+ "module": "",
34
+ "names": "",
35
+ "dots": "",
36
+ "language_hint": ""
37
+ },
38
+ "id": "a059576fe1473efe"
39
+ },
40
+ {
41
+ "blob_sha": "sha1",
42
+ "file_path": "json.json",
43
+ "kind": "config_key",
44
+ "name": "defaults",
45
+ "scope": "",
46
+ "language": "json",
47
+ "file_language": "json",
48
+ "content": "\"defaults\": {\n \"greeting\": \"Hello\",\n \"locale\": \"en\"\n }",
49
+ "line_start": 4,
50
+ "line_end": 7,
51
+ "metadata": {
52
+ "module": "",
53
+ "names": "",
54
+ "dots": "",
55
+ "language_hint": ""
56
+ },
57
+ "id": "cc300e28219ead37"
58
+ },
59
+ {
60
+ "blob_sha": "sha1",
61
+ "file_path": "json.json",
62
+ "kind": "config_key",
63
+ "name": "greeting",
64
+ "scope": "",
65
+ "language": "json",
66
+ "file_language": "json",
67
+ "content": "\"greeting\": \"Hello\"",
68
+ "line_start": 5,
69
+ "line_end": 5,
70
+ "metadata": {
71
+ "module": "",
72
+ "names": "",
73
+ "dots": "",
74
+ "language_hint": ""
75
+ },
76
+ "id": "4129601aeeaeb683"
77
+ },
78
+ {
79
+ "blob_sha": "sha1",
80
+ "file_path": "json.json",
81
+ "kind": "config_key",
82
+ "name": "locale",
83
+ "scope": "",
84
+ "language": "json",
85
+ "file_language": "json",
86
+ "content": "\"locale\": \"en\"",
87
+ "line_start": 6,
88
+ "line_end": 6,
89
+ "metadata": {
90
+ "module": "",
91
+ "names": "",
92
+ "dots": "",
93
+ "language_hint": ""
94
+ },
95
+ "id": "9681039edbb00040"
96
+ },
97
+ {
98
+ "blob_sha": "sha1",
99
+ "file_path": "json.json",
100
+ "kind": "config_key",
101
+ "name": "locales",
102
+ "scope": "",
103
+ "language": "json",
104
+ "file_language": "json",
105
+ "content": "\"locales\": [\"en\", \"fr\"]",
106
+ "line_start": 8,
107
+ "line_end": 8,
108
+ "metadata": {
109
+ "module": "",
110
+ "names": "",
111
+ "dots": "",
112
+ "language_hint": ""
113
+ },
114
+ "id": "832e35f22ae9a561"
115
+ },
116
+ {
117
+ "blob_sha": "sha1",
118
+ "file_path": "schema/defs.json",
119
+ "kind": "config_key",
120
+ "name": "$comment",
121
+ "scope": "",
122
+ "language": "json",
123
+ "file_language": "json",
124
+ "content": "\"$comment\": \"Referred to from schema/greeting.json as a bare sibling.\"",
125
+ "line_start": 2,
126
+ "line_end": 2,
127
+ "metadata": {
128
+ "module": "",
129
+ "names": "",
130
+ "dots": "",
131
+ "language_hint": ""
132
+ },
133
+ "id": "2c00abd3f86ca52a"
134
+ },
135
+ {
136
+ "blob_sha": "sha1",
137
+ "file_path": "schema/defs.json",
138
+ "kind": "config_key",
139
+ "name": "Name",
140
+ "scope": "",
141
+ "language": "json",
142
+ "file_language": "json",
143
+ "content": "\"Name\": {\n \"type\": \"string\",\n \"minLength\": 1\n }",
144
+ "line_start": 3,
145
+ "line_end": 6,
146
+ "metadata": {
147
+ "module": "",
148
+ "names": "",
149
+ "dots": "",
150
+ "language_hint": ""
151
+ },
152
+ "id": "cf0a30f8c145364c"
153
+ },
154
+ {
155
+ "blob_sha": "sha1",
156
+ "file_path": "schema/defs.json",
157
+ "kind": "config_key",
158
+ "name": "type",
159
+ "scope": "",
160
+ "language": "json",
161
+ "file_language": "json",
162
+ "content": "\"type\": \"string\"",
163
+ "line_start": 4,
164
+ "line_end": 4,
165
+ "metadata": {
166
+ "module": "",
167
+ "names": "",
168
+ "dots": "",
169
+ "language_hint": ""
170
+ },
171
+ "id": "7150bcdc4307a6a6"
172
+ },
173
+ {
174
+ "blob_sha": "sha1",
175
+ "file_path": "schema/defs.json",
176
+ "kind": "config_key",
177
+ "name": "minLength",
178
+ "scope": "",
179
+ "language": "json",
180
+ "file_language": "json",
181
+ "content": "\"minLength\": 1",
182
+ "line_start": 5,
183
+ "line_end": 5,
184
+ "metadata": {
185
+ "module": "",
186
+ "names": "",
187
+ "dots": "",
188
+ "language_hint": ""
189
+ },
190
+ "id": "d449819b44b881c8"
191
+ },
192
+ {
193
+ "blob_sha": "sha1",
194
+ "file_path": "schema/greeting.json",
195
+ "kind": "config_key",
196
+ "name": "$comment",
197
+ "scope": "",
198
+ "language": "json",
199
+ "file_language": "json",
200
+ "content": "\"$comment\": \"Refers into its bare sibling, which only resolves relative to this directory.\"",
201
+ "line_start": 2,
202
+ "line_end": 2,
203
+ "metadata": {
204
+ "module": "",
205
+ "names": "",
206
+ "dots": "",
207
+ "language_hint": ""
208
+ },
209
+ "id": "2c00abd3f86ca52a"
210
+ },
211
+ {
212
+ "blob_sha": "sha1",
213
+ "file_path": "schema/greeting.json",
214
+ "kind": "config_key",
215
+ "name": "type",
216
+ "scope": "",
217
+ "language": "json",
218
+ "file_language": "json",
219
+ "content": "\"type\": \"object\"",
220
+ "line_start": 3,
221
+ "line_end": 3,
222
+ "metadata": {
223
+ "module": "",
224
+ "names": "",
225
+ "dots": "",
226
+ "language_hint": ""
227
+ },
228
+ "id": "5f2c0917d45381d5"
229
+ },
230
+ {
231
+ "blob_sha": "sha1",
232
+ "file_path": "schema/greeting.json",
233
+ "kind": "config_key",
234
+ "name": "properties",
235
+ "scope": "",
236
+ "language": "json",
237
+ "file_language": "json",
238
+ "content": "\"properties\": {\n \"recipient\": { \"$ref\": \"defs.json#/Name\" }\n }",
239
+ "line_start": 4,
240
+ "line_end": 6,
241
+ "metadata": {
242
+ "module": "",
243
+ "names": "",
244
+ "dots": "",
245
+ "language_hint": ""
246
+ },
247
+ "id": "d5f2c28098b8efb7"
248
+ },
249
+ {
250
+ "blob_sha": "sha1",
251
+ "file_path": "schema/greeting.json",
252
+ "kind": "config_key",
253
+ "name": "recipient",
254
+ "scope": "",
255
+ "language": "json",
256
+ "file_language": "json",
257
+ "content": "\"recipient\": { \"$ref\": \"defs.json#/Name\" }",
258
+ "line_start": 5,
259
+ "line_end": 5,
260
+ "metadata": {
261
+ "module": "",
262
+ "names": "",
263
+ "dots": "",
264
+ "language_hint": ""
265
+ },
266
+ "id": "e0a96b72685764db"
267
+ },
268
+ {
269
+ "blob_sha": "sha1",
270
+ "file_path": "schema/greeting.json",
271
+ "kind": "config_key",
272
+ "name": "$ref",
273
+ "scope": "",
274
+ "language": "json",
275
+ "file_language": "json",
276
+ "content": "\"$ref\": \"defs.json#/Name\"",
277
+ "line_start": 5,
278
+ "line_end": 5,
279
+ "metadata": {
280
+ "module": "",
281
+ "names": "",
282
+ "dots": "",
283
+ "language_hint": ""
284
+ },
285
+ "id": "88d44c7351662f14"
286
+ },
287
+ {
288
+ "blob_sha": "sha1",
289
+ "file_path": "schema/greeting.json",
290
+ "kind": "import",
291
+ "name": "\"$ref\": \"defs.json#/Name\"",
292
+ "scope": "",
293
+ "language": "json",
294
+ "file_language": "json",
295
+ "content": "\"$ref\": \"defs.json#/Name\"",
296
+ "line_start": 5,
297
+ "line_end": 5,
298
+ "metadata": {
299
+ "module": "defs.json",
300
+ "names": "Name",
301
+ "dots": "",
302
+ "language_hint": ""
303
+ },
304
+ "id": "56a8b4e1fe14fc24"
305
+ }
306
+ ]
@@ -0,0 +1,30 @@
1
+ """JSON extraction test cases (object keys -> config_key)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pytest_cases import case
6
+
7
+ type SymbolCase = tuple[str, str, list[tuple[str, str, str]]]
8
+
9
+
10
+ @case(tags=["symbol"])
11
+ def case_json_top_level_keys() -> SymbolCase:
12
+ """JSON splits by top-level keys."""
13
+ src = """\
14
+ {
15
+ "name": "my-project",
16
+ "version": "1.0.0",
17
+ "dependencies": {
18
+ "foo": "^1.0"
19
+ }
20
+ }
21
+ """
22
+ return (
23
+ "json",
24
+ src,
25
+ [
26
+ ("config_key", "name", ""),
27
+ ("config_key", "version", ""),
28
+ ("config_key", "dependencies", ""),
29
+ ],
30
+ )
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "greeter",
3
+ "version": "1.0.0",
4
+ "defaults": {
5
+ "greeting": "Hello",
6
+ "locale": "en"
7
+ },
8
+ "locales": ["en", "fr"]
9
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "$comment": "Referred to from schema/greeting.json as a bare sibling.",
3
+ "Name": {
4
+ "type": "string",
5
+ "minLength": 1
6
+ }
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "$comment": "Refers into its bare sibling, which only resolves relative to this directory.",
3
+ "type": "object",
4
+ "properties": {
5
+ "recipient": { "$ref": "defs.json#/Name" }
6
+ }
7
+ }
@@ -0,0 +1,17 @@
1
+ """JSON extraction tests (cases in `cases_extraction.py`)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pytest_cases import parametrize_with_cases
6
+
7
+ from rbtr.git import FileEntry
8
+ from rbtr.languages.extract import extract_file
9
+
10
+
11
+ @parametrize_with_cases("lang, source, expected", cases=".cases_extraction", has_tag="symbol")
12
+ def test_extracts_expected_symbols(lang: str, source: str, expected: list) -> None:
13
+ """Each expected (kind, name, scope) tuple appears in the output."""
14
+ chunks = extract_file(FileEntry("input", "sha1", source.encode()), lang)
15
+ symbols = [(c.kind, c.name, c.scope) for c in chunks]
16
+ for exp in expected:
17
+ assert exp in symbols, f"expected {exp} not found in {symbols}"
@@ -0,0 +1,68 @@
1
+ """JSON sample extraction: the `samples/json/` project through the real pipeline."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+ from typing import TYPE_CHECKING
7
+
8
+ import pytest
9
+ from tree_sitter import Parser
10
+
11
+ from rbtr.domain.models import Chunk, ChunkKind, Edge
12
+ from rbtr.git import FileEntry
13
+ from rbtr.languages.edges import build_resolution_map, infer_import_edges
14
+ from rbtr.languages.extract import extract_file
15
+ from rbtr.languages.manager import get_manager
16
+ from rbtr.testing import render_edges
17
+
18
+ if TYPE_CHECKING:
19
+ from syrupy.assertion import SnapshotAssertion
20
+
21
+
22
+ @pytest.fixture
23
+ def project() -> list[tuple[str, str]]:
24
+ root = Path(__file__).parent / "samples" / "json"
25
+ return [
26
+ (str(p.relative_to(root)), p.read_text()) for p in sorted(root.rglob("*")) if p.is_file()
27
+ ]
28
+
29
+
30
+ @pytest.fixture
31
+ def chunks(project: list[tuple[str, str]]) -> list[Chunk]:
32
+ manager = get_manager()
33
+ out: list[Chunk] = []
34
+ for path, text in project:
35
+ lang = manager.detect_language(path) or "json"
36
+ out.extend(extract_file(FileEntry(path, "sha1", text.encode()), lang))
37
+ return out
38
+
39
+
40
+ @pytest.fixture
41
+ def edges(project: list[tuple[str, str]], chunks: list[Chunk]) -> list[Edge]:
42
+ manager = get_manager()
43
+ repo_files = {path for path, _ in project}
44
+ return infer_import_edges(chunks, repo_files, build_resolution_map(manager))
45
+
46
+
47
+ def test_emits_expected_kinds(chunks: list[Chunk]) -> None:
48
+ """The sample exercises JSON's config-key chunks."""
49
+ kinds = {c.kind for c in chunks}
50
+ assert {ChunkKind.CONFIG_KEY} <= kinds
51
+
52
+
53
+ def test_parses_cleanly(project: list[tuple[str, str]]) -> None:
54
+ manager = get_manager()
55
+ for path, text in project:
56
+ grammar = manager.grammar(manager.detect_language(path) or "json")
57
+ assert grammar is not None
58
+ assert not Parser(grammar).parse(text.encode()).root_node.has_error, path
59
+
60
+
61
+ def test_extraction_matches_snapshot(chunks: list[Chunk], snapshot_json: SnapshotAssertion) -> None:
62
+ assert chunks == snapshot_json
63
+
64
+
65
+ def test_edges_match_snapshot(
66
+ chunks: list[Chunk], edges: list[Edge], snapshot_json: SnapshotAssertion
67
+ ) -> None:
68
+ assert render_edges(edges, chunks) == snapshot_json