rbtr-lang-yaml 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.
- rbtr_lang_yaml-2026.9.0.dev1/LICENSE +21 -0
- rbtr_lang_yaml-2026.9.0.dev1/PKG-INFO +59 -0
- rbtr_lang_yaml-2026.9.0.dev1/README.md +33 -0
- rbtr_lang_yaml-2026.9.0.dev1/pyproject.toml +57 -0
- rbtr_lang_yaml-2026.9.0.dev1/pyproject.toml.orig +61 -0
- rbtr_lang_yaml-2026.9.0.dev1/src/rbtr_lang_yaml/__init__.py +1 -0
- rbtr_lang_yaml-2026.9.0.dev1/src/rbtr_lang_yaml/plugin.py +32 -0
- rbtr_lang_yaml-2026.9.0.dev1/src/rbtr_lang_yaml/py.typed +0 -0
- rbtr_lang_yaml-2026.9.0.dev1/src/rbtr_lang_yaml/tests/__init__.py +0 -0
- rbtr_lang_yaml-2026.9.0.dev1/src/rbtr_lang_yaml/tests/__snapshots__/test_samples/test_edges_match_snapshot.json +3 -0
- rbtr_lang_yaml-2026.9.0.dev1/src/rbtr_lang_yaml/tests/__snapshots__/test_samples/test_extraction_matches_snapshot.json +154 -0
- rbtr_lang_yaml-2026.9.0.dev1/src/rbtr_lang_yaml/tests/cases_extraction.py +28 -0
- rbtr_lang_yaml-2026.9.0.dev1/src/rbtr_lang_yaml/tests/samples/yaml/api/openapi.yaml +5 -0
- rbtr_lang_yaml-2026.9.0.dev1/src/rbtr_lang_yaml/tests/samples/yaml/api/paths.yaml +6 -0
- rbtr_lang_yaml-2026.9.0.dev1/src/rbtr_lang_yaml/tests/samples/yaml/yaml.yaml +14 -0
- rbtr_lang_yaml-2026.9.0.dev1/src/rbtr_lang_yaml/tests/test_extraction.py +23 -0
- rbtr_lang_yaml-2026.9.0.dev1/src/rbtr_lang_yaml/tests/test_samples.py +68 -0
- rbtr_lang_yaml-2026.9.0.dev1/src/rbtr_lang_yaml/yaml.scm +23 -0
|
@@ -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,59 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rbtr-lang-yaml
|
|
3
|
+
Version: 2026.9.0.dev1
|
|
4
|
+
Summary: rbtr — YAML language plugin
|
|
5
|
+
Keywords: code-search,code-index,tree-sitter,static-analysis,semantic-search,developer-tools,yaml
|
|
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-yaml
|
|
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-yaml#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-yaml
|
|
28
|
+
|
|
29
|
+
YAML support for [rbtr]. Optional plugin — install with
|
|
30
|
+
`pip install rbtr[yaml]`.
|
|
31
|
+
|
|
32
|
+
[rbtr]: https://github.com/janrito/rbtr/tree/main/packages/rbtr#readme
|
|
33
|
+
|
|
34
|
+
## What it ingests
|
|
35
|
+
|
|
36
|
+
Top-level mapping keys become **config-key** chunks (YAML is data, not code).
|
|
37
|
+
Non-mapping YAML (a bare sequence or scalar) produces a single fallback chunk.
|
|
38
|
+
|
|
39
|
+
A `$ref` names another document, as OpenAPI splits a specification across
|
|
40
|
+
files, and becomes an **import**. So does a `uses` naming a path, which is how
|
|
41
|
+
a workflow reads an action kept in the same repository; a `uses` naming
|
|
42
|
+
anything else reads it from elsewhere and is left alone.
|
|
43
|
+
|
|
44
|
+
## Chunks produced
|
|
45
|
+
|
|
46
|
+
```yaml
|
|
47
|
+
name: CI # config_key "name"
|
|
48
|
+
on: [push] # config_key "on"
|
|
49
|
+
jobs: # config_key "jobs"
|
|
50
|
+
build: …
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Embedded / injected chunks
|
|
54
|
+
|
|
55
|
+
None. YAML does not embed other languages.
|
|
56
|
+
|
|
57
|
+
## Grammar & dependencies
|
|
58
|
+
|
|
59
|
+
Uses the `tree-sitter-yaml` grammar. No dependency on other language plugins.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# rbtr-lang-yaml
|
|
2
|
+
|
|
3
|
+
YAML support for [rbtr]. Optional plugin — install with
|
|
4
|
+
`pip install rbtr[yaml]`.
|
|
5
|
+
|
|
6
|
+
[rbtr]: https://github.com/janrito/rbtr/tree/main/packages/rbtr#readme
|
|
7
|
+
|
|
8
|
+
## What it ingests
|
|
9
|
+
|
|
10
|
+
Top-level mapping keys become **config-key** chunks (YAML is data, not code).
|
|
11
|
+
Non-mapping YAML (a bare sequence or scalar) produces a single fallback chunk.
|
|
12
|
+
|
|
13
|
+
A `$ref` names another document, as OpenAPI splits a specification across
|
|
14
|
+
files, and becomes an **import**. So does a `uses` naming a path, which is how
|
|
15
|
+
a workflow reads an action kept in the same repository; a `uses` naming
|
|
16
|
+
anything else reads it from elsewhere and is left alone.
|
|
17
|
+
|
|
18
|
+
## Chunks produced
|
|
19
|
+
|
|
20
|
+
```yaml
|
|
21
|
+
name: CI # config_key "name"
|
|
22
|
+
on: [push] # config_key "on"
|
|
23
|
+
jobs: # config_key "jobs"
|
|
24
|
+
build: …
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Embedded / injected chunks
|
|
28
|
+
|
|
29
|
+
None. YAML does not embed other languages.
|
|
30
|
+
|
|
31
|
+
## Grammar & dependencies
|
|
32
|
+
|
|
33
|
+
Uses the `tree-sitter-yaml` 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_yaml"
|
|
7
|
+
|
|
8
|
+
[tool.uv.sources.rbtr]
|
|
9
|
+
workspace = true
|
|
10
|
+
|
|
11
|
+
[project]
|
|
12
|
+
name = "rbtr-lang-yaml"
|
|
13
|
+
version = "2026.9.0-dev1"
|
|
14
|
+
description = "rbtr — YAML 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
|
+
"yaml",
|
|
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-yaml",
|
|
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-yaml#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
|
+
yaml = "rbtr_lang_yaml.plugin:yaml"
|
|
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_yaml"
|
|
7
|
+
# No source-exclude: the plugin's tests, samples, and snapshots ship with
|
|
8
|
+
# the wheel (they are the language's golden record), and yaml.scm ships as
|
|
9
|
+
# package data.
|
|
10
|
+
|
|
11
|
+
[project]
|
|
12
|
+
name = "rbtr-lang-yaml"
|
|
13
|
+
version = "2026.9.0-dev1"
|
|
14
|
+
description = "rbtr — YAML 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
|
+
"yaml",
|
|
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-yaml",
|
|
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-yaml#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
|
+
yaml = "rbtr_lang_yaml.plugin:yaml"
|
|
56
|
+
|
|
57
|
+
[tool.uv.sources]
|
|
58
|
+
rbtr = { workspace = true }
|
|
59
|
+
|
|
60
|
+
[dependency-groups]
|
|
61
|
+
dev = ["rbtr[test]"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""YAML language plugin package."""
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""YAML language plugin.
|
|
2
|
+
|
|
3
|
+
Extracts each top-level mapping key as a doc section, via a
|
|
4
|
+
tree-sitter query. Nested keys are part of their parent's
|
|
5
|
+
content, not separate chunks.
|
|
6
|
+
|
|
7
|
+
Extracted chunks::
|
|
8
|
+
|
|
9
|
+
name: CI → config_key "name", scope ""
|
|
10
|
+
on: [push] → config_key "on", scope ""
|
|
11
|
+
jobs: → config_key "jobs", scope ""
|
|
12
|
+
test:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from rbtr.languages.registration import LanguageRegistration, QueryExtraction, load_query
|
|
19
|
+
|
|
20
|
+
# Top-level keys only: pairs of the document's own block mapping.
|
|
21
|
+
# Nested pairs sit in a value's block mapping and do not match.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
yaml = LanguageRegistration(
|
|
25
|
+
id="yaml",
|
|
26
|
+
extensions=frozenset({".yaml", ".yml"}),
|
|
27
|
+
grammar_module="tree_sitter_yaml",
|
|
28
|
+
extraction=QueryExtraction(
|
|
29
|
+
query=load_query(__package__, "yaml"),
|
|
30
|
+
),
|
|
31
|
+
extraction_serial=5,
|
|
32
|
+
)
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"blob_sha": "sha1",
|
|
4
|
+
"file_path": "api/openapi.yaml",
|
|
5
|
+
"kind": "config_key",
|
|
6
|
+
"name": "openapi",
|
|
7
|
+
"scope": "",
|
|
8
|
+
"language": "yaml",
|
|
9
|
+
"file_language": "yaml",
|
|
10
|
+
"content": "# Refers into its bare sibling, which only resolves relative to this directory.\nopenapi: 3.1.0",
|
|
11
|
+
"line_start": 1,
|
|
12
|
+
"line_end": 2,
|
|
13
|
+
"metadata": {
|
|
14
|
+
"module": "",
|
|
15
|
+
"names": "",
|
|
16
|
+
"dots": "",
|
|
17
|
+
"language_hint": ""
|
|
18
|
+
},
|
|
19
|
+
"id": "6bf100cae9e931b4"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"blob_sha": "sha1",
|
|
23
|
+
"file_path": "api/openapi.yaml",
|
|
24
|
+
"kind": "config_key",
|
|
25
|
+
"name": "paths",
|
|
26
|
+
"scope": "",
|
|
27
|
+
"language": "yaml",
|
|
28
|
+
"file_language": "yaml",
|
|
29
|
+
"content": "paths:\n /greeting:\n $ref: \"paths.yaml\"\n",
|
|
30
|
+
"line_start": 3,
|
|
31
|
+
"line_end": 5,
|
|
32
|
+
"metadata": {
|
|
33
|
+
"module": "",
|
|
34
|
+
"names": "",
|
|
35
|
+
"dots": "",
|
|
36
|
+
"language_hint": ""
|
|
37
|
+
},
|
|
38
|
+
"id": "ffc37f267764c8bd"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"blob_sha": "sha1",
|
|
42
|
+
"file_path": "api/openapi.yaml",
|
|
43
|
+
"kind": "import",
|
|
44
|
+
"name": "$ref: \"paths.yaml\"",
|
|
45
|
+
"scope": "",
|
|
46
|
+
"language": "yaml",
|
|
47
|
+
"file_language": "yaml",
|
|
48
|
+
"content": "$ref: \"paths.yaml\"",
|
|
49
|
+
"line_start": 5,
|
|
50
|
+
"line_end": 5,
|
|
51
|
+
"metadata": {
|
|
52
|
+
"module": "paths.yaml",
|
|
53
|
+
"names": "",
|
|
54
|
+
"dots": "",
|
|
55
|
+
"language_hint": ""
|
|
56
|
+
},
|
|
57
|
+
"id": "41cb39ef48e43af8"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"blob_sha": "sha1",
|
|
61
|
+
"file_path": "api/paths.yaml",
|
|
62
|
+
"kind": "config_key",
|
|
63
|
+
"name": "get",
|
|
64
|
+
"scope": "",
|
|
65
|
+
"language": "yaml",
|
|
66
|
+
"file_language": "yaml",
|
|
67
|
+
"content": "# Referred to from api/openapi.yaml as a bare sibling.\nget:\n summary: A greeting\n responses:\n \"200\":\n description: OK\n",
|
|
68
|
+
"line_start": 1,
|
|
69
|
+
"line_end": 6,
|
|
70
|
+
"metadata": {
|
|
71
|
+
"module": "",
|
|
72
|
+
"names": "",
|
|
73
|
+
"dots": "",
|
|
74
|
+
"language_hint": ""
|
|
75
|
+
},
|
|
76
|
+
"id": "5df3fcb6f09459b7"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"blob_sha": "sha1",
|
|
80
|
+
"file_path": "yaml.yaml",
|
|
81
|
+
"kind": "comment",
|
|
82
|
+
"name": "",
|
|
83
|
+
"scope": "",
|
|
84
|
+
"language": "yaml",
|
|
85
|
+
"file_language": "yaml",
|
|
86
|
+
"content": "# Greeter CI workflow.",
|
|
87
|
+
"line_start": 1,
|
|
88
|
+
"line_end": 1,
|
|
89
|
+
"metadata": {
|
|
90
|
+
"module": "",
|
|
91
|
+
"names": "",
|
|
92
|
+
"dots": "",
|
|
93
|
+
"language_hint": ""
|
|
94
|
+
},
|
|
95
|
+
"id": "97943055c48aca06"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"blob_sha": "sha1",
|
|
99
|
+
"file_path": "yaml.yaml",
|
|
100
|
+
"kind": "config_key",
|
|
101
|
+
"name": "name",
|
|
102
|
+
"scope": "",
|
|
103
|
+
"language": "yaml",
|
|
104
|
+
"file_language": "yaml",
|
|
105
|
+
"content": "name: greeter",
|
|
106
|
+
"line_start": 3,
|
|
107
|
+
"line_end": 3,
|
|
108
|
+
"metadata": {
|
|
109
|
+
"module": "",
|
|
110
|
+
"names": "",
|
|
111
|
+
"dots": "",
|
|
112
|
+
"language_hint": ""
|
|
113
|
+
},
|
|
114
|
+
"id": "029d3b7d58437d49"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"blob_sha": "sha1",
|
|
118
|
+
"file_path": "yaml.yaml",
|
|
119
|
+
"kind": "config_key",
|
|
120
|
+
"name": "on",
|
|
121
|
+
"scope": "",
|
|
122
|
+
"language": "yaml",
|
|
123
|
+
"file_language": "yaml",
|
|
124
|
+
"content": "on:\n push:\n branches: [main]",
|
|
125
|
+
"line_start": 5,
|
|
126
|
+
"line_end": 7,
|
|
127
|
+
"metadata": {
|
|
128
|
+
"module": "",
|
|
129
|
+
"names": "",
|
|
130
|
+
"dots": "",
|
|
131
|
+
"language_hint": ""
|
|
132
|
+
},
|
|
133
|
+
"id": "94aa8e807730971c"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"blob_sha": "sha1",
|
|
137
|
+
"file_path": "yaml.yaml",
|
|
138
|
+
"kind": "config_key",
|
|
139
|
+
"name": "jobs",
|
|
140
|
+
"scope": "",
|
|
141
|
+
"language": "yaml",
|
|
142
|
+
"file_language": "yaml",
|
|
143
|
+
"content": "jobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v4\n - run: just check\n",
|
|
144
|
+
"line_start": 9,
|
|
145
|
+
"line_end": 14,
|
|
146
|
+
"metadata": {
|
|
147
|
+
"module": "",
|
|
148
|
+
"names": "",
|
|
149
|
+
"dots": "",
|
|
150
|
+
"language_hint": ""
|
|
151
|
+
},
|
|
152
|
+
"id": "77f31da28a7f1eeb"
|
|
153
|
+
}
|
|
154
|
+
]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""YAML extraction test cases (mapping 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_yaml_top_level_keys() -> SymbolCase:
|
|
12
|
+
"""YAML splits by top-level mapping keys."""
|
|
13
|
+
src = """\
|
|
14
|
+
name: CI
|
|
15
|
+
on: [push]
|
|
16
|
+
jobs:
|
|
17
|
+
test:
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
"""
|
|
20
|
+
return (
|
|
21
|
+
"yaml",
|
|
22
|
+
src,
|
|
23
|
+
[
|
|
24
|
+
("config_key", "name", ""),
|
|
25
|
+
("config_key", "on", ""),
|
|
26
|
+
("config_key", "jobs", ""),
|
|
27
|
+
],
|
|
28
|
+
)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""YAML 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}"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_yaml_no_mapping_fallback() -> None:
|
|
21
|
+
"""YAML without mapping falls back to single chunk."""
|
|
22
|
+
chunks = extract_file(FileEntry("input", "sha1", b"- item1\n- item2\n"), "yaml")
|
|
23
|
+
assert len(chunks) == 1
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""YAML sample extraction: the `samples/yaml/` 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" / "yaml"
|
|
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 "yaml"
|
|
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 YAML's config-key chunks."""
|
|
49
|
+
kinds = {c.kind for c in chunks}
|
|
50
|
+
assert {ChunkKind.CONFIG_KEY, ChunkKind.COMMENT} <= 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 "yaml")
|
|
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
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
; Comments (`#`).
|
|
2
|
+
(comment) @comment
|
|
3
|
+
|
|
4
|
+
(document
|
|
5
|
+
(block_node
|
|
6
|
+
(block_mapping
|
|
7
|
+
(block_mapping_pair
|
|
8
|
+
key: (_) @_section_name) @config_key)))
|
|
9
|
+
|
|
10
|
+
; A `$ref` names another document this repository may hold.
|
|
11
|
+
(block_mapping_pair
|
|
12
|
+
key: (flow_node) @_key
|
|
13
|
+
(#eq? @_key "$ref")
|
|
14
|
+
value: (flow_node) @_import_module) @import
|
|
15
|
+
|
|
16
|
+
; A `uses` naming a path reads a workflow or action from this repository;
|
|
17
|
+
; one naming anything else reads it from elsewhere, as an external link in
|
|
18
|
+
; prose does, and is left alone.
|
|
19
|
+
(block_mapping_pair
|
|
20
|
+
key: (flow_node) @_key
|
|
21
|
+
(#eq? @_key "uses")
|
|
22
|
+
value: (flow_node) @_import_module
|
|
23
|
+
(#match? @_import_module "^\\.{1,2}/")) @import
|