kbforge-sql 0.1.0__tar.gz → 0.1.2__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.
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: kbforge-sql
3
- Version: 0.1.0
3
+ Version: 0.1.2
4
4
  Summary: SQL source connector for kbforge
5
5
  Author-email: Qing <qingye779@gmail.com>
6
6
  License: MIT
7
7
  Requires-Python: >=3.12
8
- Requires-Dist: kbforge>=0.8.0
8
+ Requires-Dist: kbforge>=0.14.1
9
9
  Requires-Dist: pydantic>=2.0
10
10
  Requires-Dist: sqlalchemy>=2.0
11
11
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "kbforge-sql"
3
- version = "0.1.0"
3
+ version = "0.1.2"
4
4
  description = "SQL source connector for kbforge"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -9,7 +9,7 @@ license = { text = "MIT" }
9
9
  dependencies = [
10
10
  # 0.8.0: cursor slots keyed per config instance, so two `sql` sources never
11
11
  # share a manifest; `synthesize.OKF_OWNED` and `canonical.is_blank` exist.
12
- "kbforge>=0.8.0",
12
+ "kbforge>=0.14.1",
13
13
  "pydantic>=2.0",
14
14
  "sqlalchemy>=2.0",
15
15
  ]
@@ -12,7 +12,7 @@ from collections.abc import Mapping, Sequence
12
12
  from pydantic import BaseModel, ConfigDict, Field, ValidationError
13
13
 
14
14
  from kbforge.canonical import is_blank
15
- from kbforge.synthesize import OKF_OWNED
15
+ from kbforge.synthesize import OKF_OWNED, OKF_RESERVED
16
16
  from kbforge_sql.errors import SqlSourceError
17
17
 
18
18
  # Same shapes as kbforge-mcp's config: an ALL_CAPS env var name, and a `system`
@@ -128,7 +128,13 @@ def problems_for(config: dict) -> list[str]:
128
128
  problems.append(
129
129
  f"config 'exclude' names column(s) the source also uses: {sorted(clash)}"
130
130
  )
131
- if owned := sorted(set(cfg.facets) & OKF_OWNED):
131
+ # `tags` is exempted: unlike every other OKF-owned key, the emitter does not
132
+ # drop it. `assemble` (kbforge.synthesize) reads `structured["tags"]` and
133
+ # ships it as the concept's own tags, normalized by `_source_tags` (a
134
+ # string becomes one tag). A `tags` facet reaches the rendered concept, so
135
+ # rejecting it here would be a false positive -- exactly the failure mode
136
+ # this check exists to prevent for every OTHER owned key.
137
+ if owned := sorted(set(cfg.facets) & ((OKF_OWNED - {"tags"}) | OKF_RESERVED)):
132
138
  problems.append(
133
139
  f"config 'facets' must not use OKF-owned key(s) {owned}: the emitter "
134
140
  "drops them, so the facet would silently never appear"
@@ -105,6 +105,26 @@ def test_a_facet_named_like_an_okf_key_is_rejected():
105
105
  )
106
106
 
107
107
 
108
+ def test_a_facet_named_like_a_reserved_okf_key_is_rejected():
109
+ # The emitter drops `stale_after` like an owned key, so the config must
110
+ # refuse it for the same reason: the facet would silently never appear.
111
+ problems = problems_for(_cfg(facets=["family", "stale_after"]))
112
+ assert any(
113
+ p.startswith("config 'facets' must not use OKF-owned key(s) ['stale_after']")
114
+ for p in problems
115
+ ), problems
116
+
117
+
118
+ def test_a_tags_facet_is_allowed():
119
+ # `tags` is OKF-owned too, but unlike the other owned keys the emitter does
120
+ # not drop it: `assemble` reads `structured["tags"]` and ships it,
121
+ # normalized (kbforge.synthesize._source_tags). Rejecting it here would be
122
+ # a false positive -- a deployment exposing a `tags` column worked before
123
+ # `tags` joined OKF_OWNED and must keep working.
124
+ problems = problems_for(_cfg(facets=["tags"]))
125
+ assert not any("facets" in p for p in problems)
126
+
127
+
108
128
  def test_group_children_must_not_include_id_columns():
109
129
  problems = problems_for(_cfg(group={"children": ["product_id", "x"]}))
110
130
  assert (
@@ -42,6 +42,35 @@ def test_a_flat_source_yields_one_document_per_row(tmp_path, monkeypatch):
42
42
  assert_fetch_contract(list(docs.values()), complete=True)
43
43
 
44
44
 
45
+ def test_a_tags_facet_ships_as_the_concept_top_level_tags(tmp_path, monkeypatch):
46
+ """Important 1 (#40 review): `tags` is OKF-owned but not dropped -- unlike
47
+ every other owned key, `assemble` (kbforge.synthesize) reads
48
+ `structured["tags"]` and ships it, normalized. A single string column
49
+ value becomes the single tag `["MOTIX"]`, not a split-on-comma list."""
50
+ import yaml
51
+
52
+ from kbforge.models import ChangeSet
53
+ from kbforge.synthesize import StubSynthesizer, concept_path
54
+
55
+ make_db(tmp_path, monkeypatch)
56
+ cfg = flat_cfg(
57
+ query=(
58
+ "SELECT product_id, product_name, family AS tags, status, "
59
+ "description, last_refreshed FROM product"
60
+ ),
61
+ facets=["tags", "status"],
62
+ )
63
+ _, docs = _docs(cfg)
64
+ doc = docs["products:IMC300"]
65
+ assert doc.structured["tags"] == "MOTIX" # a SQL string, not a list
66
+
67
+ proposal = StubSynthesizer().synthesize([doc], ChangeSet(added=[doc.doc_id]))
68
+ rendered = proposal.files[concept_path(doc.doc_id)]
69
+ front = yaml.safe_load(rendered.split("---\n")[1])
70
+ assert front["tags"] == ["MOTIX"] # one string is one tag, not split on ","
71
+ assert "tags" not in {**proposal.concepts[concept_path(doc.doc_id)].facets}
72
+
73
+
45
74
  def test_a_null_text_column_leaves_no_lead(tmp_path, monkeypatch):
46
75
  make_db(tmp_path, monkeypatch)
47
76
  _, docs = _docs(flat_cfg())
File without changes
File without changes