ZhYQ1 commented on code in PR #432:
URL: https://github.com/apache/hugegraph-ai/pull/432#discussion_r4560042518


##########
ontogeny/tests/test_engine_functions.py:
##########
@@ -234,6 +234,86 @@ async def test_traverse_three_hops(self, env):
         assert [s_["type"] for s_ in out["steps"]] == ["material", "bom", 
"product"]
         assert out["final_ids"] == ["P-200"]
 
+    async def test_traverse_batches_fk_reads_per_hop(self, env, monkeypatch):
+        q, repo = env["query"], env["repo"]
+        batched: list[bool] = []
+        single: list[str] = []
+        orig_batch = repo.link_members_by_ids
+        orig_single = q._linked_ids
+
+        async def counting_batch(session, link_name, ids, *, from_source, 
**kw):
+            batched.append(from_source)
+            return await orig_batch(session, link_name, ids, 
from_source=from_source, **kw)
+
+        async def counting_single(session, link_name, obj_id, *, from_source):
+            single.append(obj_id)
+            return await orig_single(session, link_name, obj_id, 
from_source=from_source)
+
+        monkeypatch.setattr(repo, "link_members_by_ids", counting_batch)
+        monkeypatch.setattr(q, "_linked_ids", counting_single)
+
+        async with env["maker"]() as s:
+            out = await q.traverse(
+                s,
+                "equipment",
+                ["EQ-02", "EQ-07"],
+                SUPER,
+                [
+                    {"link": "step-equipment", "direction": "out"},
+                    {"link": "step-equipment", "direction": "in"},
+                ],
+            )
+        # one batched read per hop (source side, then target side), never per 
id
+        assert single == []
+        assert batched == [True, False]
+        assert sorted(out["steps"][1]["ids"]) == ["PS-7111", "PS-7112", 
"PS-7121", "PS-7131", "PS-7132"]
+        assert sorted(out["final_ids"]) == ["EQ-02", "EQ-07"]
+        pairs = {(e["source"]["id"], e["target"]["id"]) for e in out["edges"]}
+        assert ("EQ-02", "PS-7111") in pairs
+        assert ("EQ-07", "PS-7132") in pairs
+        assert ("EQ-02", "PS-7112") not in pairs
+
+    async def test_traverse_batches_join_table_reads_per_hop(self, join_env, 
monkeypatch):
+        import datetime as dt
+
+        q, repo = join_env["query"], join_env["repo"]
+        calls: list[tuple[str, list[str], bool]] = []
+        orig_batch = repo.link_members_by_ids
+
+        async def counting_batch(session, link_name, ids, *, from_source, 
**kw):
+            calls.append((link_name, list(ids), from_source))
+            return await orig_batch(session, link_name, ids, 
from_source=from_source, **kw)
+
+        monkeypatch.setattr(repo, "link_members_by_ids", counting_batch)
+
+        now = dt.datetime.now(dt.UTC)

Review Comment:
   Both fixed in a730220.
   
   **1. `equipment` / `step-equipment` does not exist in the fixture (line 
258)**
   
   product-manufacturing has no `equipment` object or `step-equipment` link, so 
the test died with `NotFoundError` before exercising any batching. Rewritten to 
walk `work-center` over `operation-work-center`, which the fixture does define:
   
   - start: `work-center` `["WC-01", "WC-02"]`, hop 1 `out`, hop 2 `in`
   - `steps[1].ids` now asserts the operation ids the seed holds: `OP-2001, 
OP-2002, OP-2301` (WC-01) and `OP-2003, OP-2101, OP-2102, OP-2201, OP-2302` 
(WC-02)
   - `final_ids == ["WC-01", "WC-02"]`
   - edge attribution: `("WC-01", "OP-2001")` and `("WC-02", "OP-2302")` 
present, `("WC-01", "OP-2003")` absent (OP-2003 belongs to WC-02)
   
   The batching assertions are unchanged: `single == []` and `batched == [True, 
False]`, i.e. one read per hop, source side then target side.
   
   **2. `dt.UTC` is 3.11+ (line 289)**
   
   Replaced with `dt.timezone.utc`, matching the existing usage at line 204. 
`ontogeny/pyproject.toml` declares `>=3.10`, so this was a real break for the 
3.10 job. I also scanned the touched files for other 3.11+ constructs 
(`TaskGroup`, `StrEnum`, `typing.Self`, `except*`) — none left.
   
   **Verification**
   
       ruff check server/ontogeny/engine/service.py 
server/ontogeny/stores/repo.py tests/test_engine_functions.py   -> All checks 
passed
       ruff format --check ...                                                  
                                    -> 3 files already formatted
       pytest tests/test_engine_functions.py -q -k "batch or link"              
                                    -> 5 passed
   
   Full file: 12 passed, 3 failed. The 3 failures are Windows-only and 
pre-existing — `TestSandbox::test_timeout_kills_runaway` (the 
fchmod/source-path case) and the two `TestFunctionSourceEndpoint` 
path-separator assertions. To confirm they are not mine, I exported the 
pre-change file (`git show HEAD:...`) and re-ran the same three tests: 
identical failures on one and the same lines.
   
   Note the diff is still just `tests/test_engine_functions.py` — no production 
code changed in this commit.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to