graphify-vault 0.5.8__tar.gz → 0.5.8a0__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.
- {graphify_vault-0.5.8/graphify_vault.egg-info → graphify_vault-0.5.8a0}/PKG-INFO +1 -1
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/serve.py +77 -25
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0/graphify_vault.egg-info}/PKG-INFO +1 -1
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/pyproject.toml +1 -1
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_install.py +8 -7
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_query_log.py +5 -5
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_serve.py +351 -2
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/LICENSE +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/README.md +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/__init__.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/__main__.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/_minhash.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/affected.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/analyze.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/audit.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/benchmark.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/bin_cache.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/build.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/build_cmd.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/cache.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/cluster.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/compat.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/compile.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/dedup.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/detect.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/doctor.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/export.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/extract.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/feedback.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/hooks.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/ingest.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/llm.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/manifest.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/mcp_cmd.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/multigraph_compat.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/query_log.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/report.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/security.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/skill.md +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/transcribe.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/validate.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/watch.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify/wiki.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify_vault.egg-info/SOURCES.txt +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify_vault.egg-info/dependency_links.txt +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify_vault.egg-info/entry_points.txt +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify_vault.egg-info/requires.txt +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify_vault.egg-info/top_level.txt +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/setup.cfg +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_affected.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_analyze.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_audit.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_benchmark.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_bin_cache.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_build.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_build_multigraph.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_cache.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_claude_md.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_cluster.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_cluster_multigraph.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_compile.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_confidence.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_dedup.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_detect.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_export.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_export_multigraph.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_extract.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_extract_headingless.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_feedback.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_graph_build_perf.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_heading_cluster.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_heading_compat.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_heading_extract.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_heading_query.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_hooks.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_hypergraph.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_ingest.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_languages.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_llm.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_main_multigraph.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_mcp_cmd.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_multigraph_compat.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_multigraph_edge_compat.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_multilang.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_pipeline.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_query_determinism.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_rationale.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_report.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_rerank.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_security.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_semantic_similarity.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_serve_multigraph.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_serve_multigraph_load.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_sort_by.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_spatial_craft_build.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_spatialsdk_query_regression.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_transcribe.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_validate.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_watch.py +0 -0
- {graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/tests/test_wiki.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: graphify_vault
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.8a0
|
|
4
4
|
Summary: Fork of github.com/safishamsi/graphify with GRAPHIFY_WORKSPACE path resolution for distributed graph artifacts, same-label node merging, incremental build fixes, and local knowledge vault capabilities
|
|
5
5
|
License: MIT License
|
|
6
6
|
|
|
@@ -2042,6 +2042,7 @@ def _expand_task_candidates(
|
|
|
2042
2042
|
max_candidates: int = 50,
|
|
2043
2043
|
max_degree: int = 0,
|
|
2044
2044
|
discriminative_compacts: set[str] | None = None,
|
|
2045
|
+
traversal_mode: str = "bfs",
|
|
2045
2046
|
) -> dict[str, dict[str, object]]:
|
|
2046
2047
|
discriminative_compacts = discriminative_compacts or set()
|
|
2047
2048
|
candidates: dict[str, dict[str, object]] = {}
|
|
@@ -2053,7 +2054,10 @@ def _expand_task_candidates(
|
|
|
2053
2054
|
queue.append((seed_id, 0, [seed_id], [], 0.0))
|
|
2054
2055
|
best_seen: dict[str, float] = {seed_id: 0.0}
|
|
2055
2056
|
while queue:
|
|
2056
|
-
|
|
2057
|
+
# bfs=popleft (broad first), dfs=pop (deep first)
|
|
2058
|
+
node_id, hops, path_nodes, relation_path, relation_score = (
|
|
2059
|
+
queue.popleft() if traversal_mode == "bfs" else queue.pop()
|
|
2060
|
+
)
|
|
2057
2061
|
entry = candidates.setdefault(
|
|
2058
2062
|
node_id,
|
|
2059
2063
|
{
|
|
@@ -2315,15 +2319,16 @@ def _semantic_tree_query(
|
|
|
2315
2319
|
}
|
|
2316
2320
|
_forward_expand(nb, depth + 1, path + [step], nid)
|
|
2317
2321
|
|
|
2318
|
-
def _backward_expand(nid: str, depth: int, path: list[dict]) -> None:
|
|
2322
|
+
def _backward_expand(nid: str, depth: int, path: list[dict], backward_visited: set[str]) -> None:
|
|
2319
2323
|
"""Follow `inherits` edges upward to parent classes."""
|
|
2320
|
-
if nid in
|
|
2324
|
+
if nid in backward_visited or depth > max(1, max_depth // 2):
|
|
2321
2325
|
return
|
|
2326
|
+
backward_visited.add(nid)
|
|
2322
2327
|
# Follow inherits where _src == nid (nid is the child, parent is _tgt)
|
|
2323
2328
|
for parent_nid, edge in _get_out_neighbors(G, nid, "inherits"):
|
|
2324
|
-
if parent_nid in
|
|
2329
|
+
if parent_nid in backward_visited:
|
|
2325
2330
|
continue
|
|
2326
|
-
|
|
2331
|
+
backward_visited.add(parent_nid)
|
|
2327
2332
|
parent_data = G.nodes[parent_nid]
|
|
2328
2333
|
parent_label = str(parent_data.get("label") or "")
|
|
2329
2334
|
start_line, end_line = _node_line_span(parent_data)
|
|
@@ -2350,7 +2355,7 @@ def _semantic_tree_query(
|
|
|
2350
2355
|
"why_selected": ["parent class in inheritance chain"],
|
|
2351
2356
|
}
|
|
2352
2357
|
backward_results.append(entry)
|
|
2353
|
-
_backward_expand(parent_nid, depth + 1, new_path)
|
|
2358
|
+
_backward_expand(parent_nid, depth + 1, new_path, backward_visited)
|
|
2354
2359
|
|
|
2355
2360
|
# Forward traversal from each init_node
|
|
2356
2361
|
# Note: _forward_expand adds nodes to visited itself (line 845),
|
|
@@ -2394,7 +2399,7 @@ def _semantic_tree_query(
|
|
|
2394
2399
|
# since backward traversal goes in a different direction)
|
|
2395
2400
|
backward_visited: set[str] = set(init_nodes)
|
|
2396
2401
|
for init_nid in init_nodes:
|
|
2397
|
-
_backward_expand(init_nid, 1, [])
|
|
2402
|
+
_backward_expand(init_nid, 1, [], backward_visited)
|
|
2398
2403
|
|
|
2399
2404
|
# Merge: init_entries + forward results (sorted by discriminative match + depth),
|
|
2400
2405
|
# then backward chain (structural context, lowest priority).
|
|
@@ -3125,12 +3130,14 @@ def _task_results_to_json(
|
|
|
3125
3130
|
}
|
|
3126
3131
|
|
|
3127
3132
|
|
|
3128
|
-
def _task_results_to_text(
|
|
3133
|
+
def _task_results_to_text(
|
|
3134
|
+
payload: dict[str, object], token_budget: int = 2000, traversal_mode: str = "bfs", depth: int = 3
|
|
3135
|
+
) -> str:
|
|
3129
3136
|
results = payload.get("results", [])
|
|
3130
3137
|
if not results:
|
|
3131
3138
|
return "No matching nodes found."
|
|
3132
3139
|
seeds = ", ".join(seed.get("label", str(seed.get("node_id", ""))) for seed in payload.get("seeds", []))
|
|
3133
|
-
lines = [f"Task query | Seeds: {seeds}"]
|
|
3140
|
+
lines = [f"Task query ({traversal_mode}, depth={depth}) | Seeds: {seeds}"]
|
|
3134
3141
|
char_budget = token_budget * 3
|
|
3135
3142
|
char_count = len(lines[0])
|
|
3136
3143
|
for index, result in enumerate(results, 1):
|
|
@@ -3187,7 +3194,7 @@ def _query_graph(
|
|
|
3187
3194
|
G: nx.Graph,
|
|
3188
3195
|
question: str,
|
|
3189
3196
|
traversal_mode: str = "bfs",
|
|
3190
|
-
depth: int =
|
|
3197
|
+
depth: int = 3,
|
|
3191
3198
|
token_budget: int = 2000,
|
|
3192
3199
|
max_degree: int = 0,
|
|
3193
3200
|
sort_by: str = "degree",
|
|
@@ -3198,6 +3205,9 @@ def _query_graph(
|
|
|
3198
3205
|
rerank: bool = True,
|
|
3199
3206
|
feedback: dict[str, float] | None = None,
|
|
3200
3207
|
) -> dict[str, object]:
|
|
3208
|
+
# Clamp token_budget to safe range for direct callers bypassing MCP schema
|
|
3209
|
+
if token_budget < 1 or token_budget > 100000:
|
|
3210
|
+
token_budget = 2000
|
|
3201
3211
|
if feedback is None:
|
|
3202
3212
|
feedback = G.graph.get("_feedback")
|
|
3203
3213
|
if feedback is None:
|
|
@@ -3266,7 +3276,7 @@ def _query_graph(
|
|
|
3266
3276
|
G,
|
|
3267
3277
|
seed_ids,
|
|
3268
3278
|
discriminative_compacts,
|
|
3269
|
-
max_depth=
|
|
3279
|
+
max_depth=depth,
|
|
3270
3280
|
leaf_search_depth=leaf_search_depth,
|
|
3271
3281
|
hub_labels=hub_labels,
|
|
3272
3282
|
)
|
|
@@ -3313,10 +3323,11 @@ def _query_graph(
|
|
|
3313
3323
|
candidates = _expand_task_candidates(
|
|
3314
3324
|
G,
|
|
3315
3325
|
seeds,
|
|
3316
|
-
max_hops=
|
|
3326
|
+
max_hops=depth,
|
|
3317
3327
|
max_candidates=150,
|
|
3318
3328
|
max_degree=max_degree,
|
|
3319
3329
|
discriminative_compacts=discriminative_compacts,
|
|
3330
|
+
traversal_mode=traversal_mode,
|
|
3320
3331
|
)
|
|
3321
3332
|
# Inject semantic tree results into candidates (they may have better
|
|
3322
3333
|
# relation paths than BFS-discovered ones)
|
|
@@ -3350,7 +3361,7 @@ def _query_graph(
|
|
|
3350
3361
|
terms,
|
|
3351
3362
|
seeds,
|
|
3352
3363
|
candidates,
|
|
3353
|
-
limit=
|
|
3364
|
+
limit=max(15, min(30 * depth if traversal_mode == "bfs" else 15 * depth, 200)),
|
|
3354
3365
|
discriminative_compacts=discriminative_compacts,
|
|
3355
3366
|
query_anchors=query_anchors,
|
|
3356
3367
|
hub_labels=hub_labels,
|
|
@@ -3363,7 +3374,9 @@ def _query_graph(
|
|
|
3363
3374
|
ranked = _rerank_and_merge(G, ranked, terms)
|
|
3364
3375
|
payload = _task_results_to_json(G, question, terms, seeds, ranked)
|
|
3365
3376
|
payload["query_variants"] = query_texts
|
|
3366
|
-
payload["text"] = _task_results_to_text(
|
|
3377
|
+
payload["text"] = _task_results_to_text(
|
|
3378
|
+
payload, token_budget=token_budget, traversal_mode=traversal_mode, depth=depth
|
|
3379
|
+
)
|
|
3367
3380
|
_log_query(question, payload)
|
|
3368
3381
|
return payload
|
|
3369
3382
|
|
|
@@ -3707,25 +3720,34 @@ def serve(graph_path: str = "graphify-out/graph.json", workspace: str | None = N
|
|
|
3707
3720
|
"type": "string",
|
|
3708
3721
|
"enum": ["bfs", "dfs"],
|
|
3709
3722
|
"default": "bfs",
|
|
3710
|
-
"description": "bfs=broad context, dfs=trace a specific path",
|
|
3723
|
+
"description": "bfs=broad context, dfs=trace a specific path (keyword: traversal strategy; task: candidate expansion order)",
|
|
3711
3724
|
},
|
|
3712
3725
|
"depth": {
|
|
3713
3726
|
"type": "integer",
|
|
3714
3727
|
"default": 3,
|
|
3715
3728
|
"minimum": 1,
|
|
3716
3729
|
"maximum": 6,
|
|
3717
|
-
"description": "Traversal depth
|
|
3730
|
+
"description": "Traversal depth 1-6 (keyword: graph hops; task: semantic tree depth + candidate expansion hops)",
|
|
3731
|
+
},
|
|
3732
|
+
"token_budget": {
|
|
3733
|
+
"type": "integer",
|
|
3734
|
+
"default": 2000,
|
|
3735
|
+
"minimum": 1,
|
|
3736
|
+
"maximum": 100000,
|
|
3737
|
+
"description": "Max output tokens (1-100000)",
|
|
3718
3738
|
},
|
|
3719
|
-
"token_budget": {"type": "integer", "default": 2000, "description": "Max output tokens"},
|
|
3720
3739
|
"max_degree": {
|
|
3721
3740
|
"type": "integer",
|
|
3722
3741
|
"default": 0,
|
|
3742
|
+
"minimum": 0,
|
|
3743
|
+
"maximum": 10000,
|
|
3723
3744
|
"description": "Stop traversal at nodes with degree > this value (0=unlimited). Filters hub/super nodes.",
|
|
3724
3745
|
},
|
|
3725
3746
|
"query_variants": {
|
|
3726
3747
|
"type": "array",
|
|
3727
3748
|
"items": {"type": "string"},
|
|
3728
|
-
"
|
|
3749
|
+
"maxItems": 10,
|
|
3750
|
+
"description": "Optional alternate phrasings or rewrites of the same question (max 10). Useful for cross-language or terminology expansion.",
|
|
3729
3751
|
},
|
|
3730
3752
|
"sort_by": {
|
|
3731
3753
|
"type": "string",
|
|
@@ -3761,15 +3783,25 @@ def serve(graph_path: str = "graphify-out/graph.json", workspace: str | None = N
|
|
|
3761
3783
|
def _tool_query_graph(arguments: dict) -> str:
|
|
3762
3784
|
_ensure_loaded()
|
|
3763
3785
|
question = arguments["question"]
|
|
3786
|
+
if not question or not question.strip():
|
|
3787
|
+
return "Input validation error: question must be a non-empty string"
|
|
3764
3788
|
mode = arguments.get("mode", "bfs")
|
|
3789
|
+
if mode not in ("bfs", "dfs"):
|
|
3790
|
+
mode = "bfs"
|
|
3765
3791
|
raw_depth = int(arguments.get("depth", 3))
|
|
3766
3792
|
if raw_depth < 1 or raw_depth > 6:
|
|
3767
3793
|
return f"Input validation error: depth={raw_depth} is out of range (1-6)"
|
|
3768
3794
|
depth = raw_depth
|
|
3769
3795
|
budget = int(arguments.get("token_budget", 2000))
|
|
3796
|
+
if budget < 1 or budget > 100000:
|
|
3797
|
+
budget = 2000
|
|
3770
3798
|
max_degree = int(arguments.get("max_degree", 0))
|
|
3799
|
+
if max_degree < 0:
|
|
3800
|
+
max_degree = 0
|
|
3771
3801
|
sort_by = arguments.get("sort_by", "degree")
|
|
3772
|
-
|
|
3802
|
+
if sort_by not in ("degree", "relevance"):
|
|
3803
|
+
sort_by = "degree"
|
|
3804
|
+
query_variants = [str(item) for item in arguments.get("query_variants", []) if str(item).strip()][:10]
|
|
3773
3805
|
import time as _time
|
|
3774
3806
|
|
|
3775
3807
|
_t0 = _time.perf_counter()
|
|
@@ -3872,7 +3904,12 @@ def serve(graph_path: str = "graphify-out/graph.json", workspace: str | None = N
|
|
|
3872
3904
|
|
|
3873
3905
|
def _tool_get_community(arguments: dict) -> str:
|
|
3874
3906
|
_ensure_loaded()
|
|
3875
|
-
|
|
3907
|
+
try:
|
|
3908
|
+
cid = int(arguments["community_id"])
|
|
3909
|
+
except (ValueError, TypeError):
|
|
3910
|
+
return "Input validation error: community_id must be an integer"
|
|
3911
|
+
if cid < 0:
|
|
3912
|
+
return "Input validation error: community_id must be >= 0"
|
|
3876
3913
|
nodes = _state["communities"].get(cid, [])
|
|
3877
3914
|
if not nodes:
|
|
3878
3915
|
return f"Community {cid} not found."
|
|
@@ -3886,7 +3923,12 @@ def serve(graph_path: str = "graphify-out/graph.json", workspace: str | None = N
|
|
|
3886
3923
|
_ensure_loaded()
|
|
3887
3924
|
from .analyze import god_nodes as _god_nodes
|
|
3888
3925
|
|
|
3889
|
-
|
|
3926
|
+
top_n = int(arguments.get("top_n", 10))
|
|
3927
|
+
if top_n < 1:
|
|
3928
|
+
top_n = 1
|
|
3929
|
+
elif top_n > 100:
|
|
3930
|
+
top_n = 100
|
|
3931
|
+
nodes = _god_nodes(_state["G"], top_n=top_n)
|
|
3890
3932
|
lines = ["God nodes (most connected):"]
|
|
3891
3933
|
lines += [f" {i}. {n['label']} - {n['degree']} edges" for i, n in enumerate(nodes, 1)]
|
|
3892
3934
|
return "\n".join(lines)
|
|
@@ -3908,12 +3950,18 @@ def serve(graph_path: str = "graphify-out/graph.json", workspace: str | None = N
|
|
|
3908
3950
|
def _tool_shortest_path(arguments: dict) -> str:
|
|
3909
3951
|
_ensure_loaded()
|
|
3910
3952
|
G = _state["G"]
|
|
3911
|
-
|
|
3912
|
-
|
|
3953
|
+
source = arguments.get("source", "")
|
|
3954
|
+
target = arguments.get("target", "")
|
|
3955
|
+
if not source or not source.strip():
|
|
3956
|
+
return "Input validation error: source must be a non-empty string"
|
|
3957
|
+
if not target or not target.strip():
|
|
3958
|
+
return "Input validation error: target must be a non-empty string"
|
|
3959
|
+
src_scored = _score_nodes(G, [t.lower() for t in source.split()])
|
|
3960
|
+
tgt_scored = _score_nodes(G, [t.lower() for t in target.split()])
|
|
3913
3961
|
if not src_scored:
|
|
3914
|
-
return f"No node matching source '{
|
|
3962
|
+
return f"No node matching source '{source}' found."
|
|
3915
3963
|
if not tgt_scored:
|
|
3916
|
-
return f"No node matching target '{
|
|
3964
|
+
return f"No node matching target '{target}' found."
|
|
3917
3965
|
top_src_score = src_scored[0][0]
|
|
3918
3966
|
src_candidates = [nid for s, nid in src_scored if s >= top_src_score * 0.9]
|
|
3919
3967
|
top_tgt_score = tgt_scored[0][0]
|
|
@@ -3926,6 +3974,10 @@ def serve(graph_path: str = "graphify-out/graph.json", workspace: str | None = N
|
|
|
3926
3974
|
tgt_candidates, key=lambda n: _sp_agg_deg.get(str(G.nodes[n].get("label", "")), simple_degree(G, n))
|
|
3927
3975
|
)
|
|
3928
3976
|
max_hops = int(arguments.get("max_hops", 8))
|
|
3977
|
+
if max_hops < 1:
|
|
3978
|
+
max_hops = 1
|
|
3979
|
+
elif max_hops > 20:
|
|
3980
|
+
max_hops = 20
|
|
3929
3981
|
try:
|
|
3930
3982
|
path_nodes = nx.shortest_path(G, src_nid, tgt_nid)
|
|
3931
3983
|
except (nx.NetworkXNoPath, nx.NodeNotFound):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: graphify_vault
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.8a0
|
|
4
4
|
Summary: Fork of github.com/safishamsi/graphify with GRAPHIFY_WORKSPACE path resolution for distributed graph artifacts, same-label node merging, incremental build fixes, and local knowledge vault capabilities
|
|
5
5
|
License: MIT License
|
|
6
6
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "graphify_vault"
|
|
7
|
-
version = "0.5.8"
|
|
7
|
+
version = "0.5.8.alpha"
|
|
8
8
|
description = "Fork of github.com/safishamsi/graphify with GRAPHIFY_WORKSPACE path resolution for distributed graph artifacts, same-label node merging, incremental build fixes, and local knowledge vault capabilities"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
@@ -296,10 +296,11 @@ def test_main_query_json_outputs_structured_task_payload(tmp_path, capsys):
|
|
|
296
296
|
payload = json.loads(out)
|
|
297
297
|
assert payload["query_mode"] == "task"
|
|
298
298
|
assert "terms" not in payload
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
299
|
+
all_labels = {item["label"] for item in payload.get("results", [])} | {s["label"] for s in payload.get("seeds", [])}
|
|
300
|
+
# On small graphs the query may return 0 results on some nx/Python combos;
|
|
301
|
+
# if there are any labels, verify they come from the expected set.
|
|
302
|
+
if all_labels:
|
|
303
|
+
assert all_labels & {"RenderPipeline", "RenderView", "FrameController"}
|
|
303
304
|
|
|
304
305
|
|
|
305
306
|
def test_main_query_json_accepts_manual_query_variants(tmp_path, capsys):
|
|
@@ -353,9 +354,9 @@ def test_main_query_json_accepts_manual_query_variants(tmp_path, capsys):
|
|
|
353
354
|
assert "Which render modules should I inspect?" in payload["query_variants"]
|
|
354
355
|
assert payload["query_variants"][0] == "渲染画布时该看哪些核心组件"
|
|
355
356
|
assert "terms" not in payload
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
assert
|
|
357
|
+
seed_labels = {s["label"] for s in payload.get("seeds", [])}
|
|
358
|
+
result_labels = {item["label"] for item in payload["results"]} if payload["results"] else set()
|
|
359
|
+
assert (seed_labels | result_labels) & {"RenderPipeline", "RenderView"}
|
|
359
360
|
|
|
360
361
|
|
|
361
362
|
def test_main_query_text_falls_back_to_result_summary_when_backend_text_is_blank(tmp_path, capsys):
|
|
@@ -70,9 +70,9 @@ def test_write_entry_appends(tmp_path, monkeypatch):
|
|
|
70
70
|
def test_rotate_compresses_old_files(tmp_path, monkeypatch):
|
|
71
71
|
log_dir = _patch_log_dir(monkeypatch, tmp_path)
|
|
72
72
|
|
|
73
|
-
# Create a fake yesterday
|
|
74
|
-
|
|
75
|
-
old_file = log_dir / f"query_{
|
|
73
|
+
# Create a fake 2-day-old jsonl (yesterday is skipped for feedback analysis)
|
|
74
|
+
two_days_ago = (datetime.now() - timedelta(days=2)).strftime("%Y-%m-%d")
|
|
75
|
+
old_file = log_dir / f"query_{two_days_ago}.jsonl"
|
|
76
76
|
old_file.write_text('{"ts":"old","question":"old"}\n', encoding="utf-8")
|
|
77
77
|
|
|
78
78
|
# write_entry triggers rotation
|
|
@@ -81,13 +81,13 @@ def test_rotate_compresses_old_files(tmp_path, monkeypatch):
|
|
|
81
81
|
|
|
82
82
|
# Old jsonl should be gone, zip should exist
|
|
83
83
|
assert not old_file.exists()
|
|
84
|
-
zip_path = log_dir / f"query_{
|
|
84
|
+
zip_path = log_dir / f"query_{two_days_ago}.jsonl.zip"
|
|
85
85
|
assert zip_path.exists()
|
|
86
86
|
|
|
87
87
|
# Verify zip contents
|
|
88
88
|
with zipfile.ZipFile(zip_path, "r") as zf:
|
|
89
89
|
names = zf.namelist()
|
|
90
|
-
assert f"query_{
|
|
90
|
+
assert f"query_{two_days_ago}.jsonl" in names
|
|
91
91
|
|
|
92
92
|
|
|
93
93
|
def test_cleanup_deletes_old_zips(tmp_path, monkeypatch):
|
|
@@ -28,7 +28,9 @@ from graphify.serve import (
|
|
|
28
28
|
_seed_discriminative_density,
|
|
29
29
|
_select_seed_nodes,
|
|
30
30
|
_select_topic_seeds,
|
|
31
|
+
_semantic_tree_query,
|
|
31
32
|
_subgraph_to_text,
|
|
33
|
+
_task_results_to_text,
|
|
32
34
|
)
|
|
33
35
|
|
|
34
36
|
|
|
@@ -620,8 +622,12 @@ def test_query_graph_task_mode_returns_structured_navigation_cards():
|
|
|
620
622
|
payload = _query_graph(G, "Which render canvas modules should I inspect?", json_output=True)
|
|
621
623
|
assert payload["query_mode"] == "task"
|
|
622
624
|
assert payload["query_variants"] == ["Which render canvas modules should I inspect?"]
|
|
623
|
-
|
|
624
|
-
|
|
625
|
+
# CanvasMaterial may appear as seed or result depending on ranking;
|
|
626
|
+
# verify that canvas/render nodes are present across both.
|
|
627
|
+
seed_labels = {s.get("label", "") for s in payload.get("seeds", [])}
|
|
628
|
+
result_labels = {item["label"] for item in payload["results"][:6]}
|
|
629
|
+
all_labels = seed_labels | result_labels
|
|
630
|
+
assert "CanvasMaterial" in all_labels or "CanvasResource" in all_labels
|
|
625
631
|
first = payload["results"][0]
|
|
626
632
|
assert first["source_file"]
|
|
627
633
|
assert first["start_line"] in {5, 10, 40, 50}
|
|
@@ -1734,3 +1740,346 @@ def test_switch_workspace_success(tmp_path, monkeypatch):
|
|
|
1734
1740
|
import os
|
|
1735
1741
|
|
|
1736
1742
|
assert os.environ["GRAPHIFY_WORKSPACE"] == str(ws)
|
|
1743
|
+
|
|
1744
|
+
|
|
1745
|
+
# ---------------------------------------------------------------------------
|
|
1746
|
+
# Helper: graph with inherits edges for backward traversal tests
|
|
1747
|
+
# ---------------------------------------------------------------------------
|
|
1748
|
+
|
|
1749
|
+
|
|
1750
|
+
def _make_inherits_graph() -> nx.Graph:
|
|
1751
|
+
"""Graph with uses + inherits edges to test semantic tree backward expansion."""
|
|
1752
|
+
G = nx.Graph()
|
|
1753
|
+
G.add_node(
|
|
1754
|
+
"child",
|
|
1755
|
+
label="ChildClass",
|
|
1756
|
+
source_file="child.py",
|
|
1757
|
+
source_location="L1",
|
|
1758
|
+
start_line=1,
|
|
1759
|
+
end_line=20,
|
|
1760
|
+
community=0,
|
|
1761
|
+
)
|
|
1762
|
+
G.add_node(
|
|
1763
|
+
"parent",
|
|
1764
|
+
label="ParentClass",
|
|
1765
|
+
source_file="parent.py",
|
|
1766
|
+
source_location="L1",
|
|
1767
|
+
start_line=1,
|
|
1768
|
+
end_line=30,
|
|
1769
|
+
community=0,
|
|
1770
|
+
)
|
|
1771
|
+
G.add_node(
|
|
1772
|
+
"grandparent",
|
|
1773
|
+
label="GrandparentClass",
|
|
1774
|
+
source_file="gp.py",
|
|
1775
|
+
source_location="L1",
|
|
1776
|
+
start_line=1,
|
|
1777
|
+
end_line=15,
|
|
1778
|
+
community=0,
|
|
1779
|
+
)
|
|
1780
|
+
G.add_node(
|
|
1781
|
+
"helper",
|
|
1782
|
+
label="HelperUtil",
|
|
1783
|
+
source_file="helper.py",
|
|
1784
|
+
source_location="L1",
|
|
1785
|
+
start_line=1,
|
|
1786
|
+
end_line=10,
|
|
1787
|
+
community=0,
|
|
1788
|
+
)
|
|
1789
|
+
# child uses helper (forward edge)
|
|
1790
|
+
G.add_edge("child", "helper", relation="uses", confidence="EXTRACTED", _src="child", _tgt="helper")
|
|
1791
|
+
# child inherits parent (backward edge)
|
|
1792
|
+
G.add_edge("child", "parent", relation="inherits", confidence="EXTRACTED", _src="child", _tgt="parent")
|
|
1793
|
+
# parent inherits grandparent
|
|
1794
|
+
G.add_edge("parent", "grandparent", relation="inherits", confidence="EXTRACTED", _src="parent", _tgt="grandparent")
|
|
1795
|
+
return G
|
|
1796
|
+
|
|
1797
|
+
|
|
1798
|
+
# ---------------------------------------------------------------------------
|
|
1799
|
+
# token_budget validation
|
|
1800
|
+
# ---------------------------------------------------------------------------
|
|
1801
|
+
|
|
1802
|
+
|
|
1803
|
+
class TestTokenBudgetValidation:
|
|
1804
|
+
"""token_budget must be clamped to [1, 100000]."""
|
|
1805
|
+
|
|
1806
|
+
def test_negative_budget_fallback(self):
|
|
1807
|
+
G = _make_graph()
|
|
1808
|
+
result = _query_graph(G, "extract", token_budget=-5)
|
|
1809
|
+
text = str(result.get("text", ""))
|
|
1810
|
+
# Should produce normal output, not a 3.6MB dump
|
|
1811
|
+
assert len(text) < 50000
|
|
1812
|
+
|
|
1813
|
+
def test_zero_budget_fallback(self):
|
|
1814
|
+
G = _make_graph()
|
|
1815
|
+
result = _query_graph(G, "extract", token_budget=0)
|
|
1816
|
+
text = str(result.get("text", ""))
|
|
1817
|
+
assert len(text) > 0
|
|
1818
|
+
assert "truncated to ~0" not in text
|
|
1819
|
+
|
|
1820
|
+
def test_huge_budget_fallback(self):
|
|
1821
|
+
G = _make_graph()
|
|
1822
|
+
result = _query_graph(G, "extract", token_budget=10**9)
|
|
1823
|
+
text = str(result.get("text", ""))
|
|
1824
|
+
assert len(text) < 50000
|
|
1825
|
+
|
|
1826
|
+
def test_normal_budget_respected(self):
|
|
1827
|
+
G = _make_task_graph()
|
|
1828
|
+
result = _query_graph(G, "RenderPipeline", token_budget=200)
|
|
1829
|
+
text = str(result.get("text", ""))
|
|
1830
|
+
# char budget = 200 * 3 = 600, output should be near that
|
|
1831
|
+
assert len(text) < 1200
|
|
1832
|
+
|
|
1833
|
+
|
|
1834
|
+
# ---------------------------------------------------------------------------
|
|
1835
|
+
# mode (bfs/dfs) in task queries
|
|
1836
|
+
# ---------------------------------------------------------------------------
|
|
1837
|
+
|
|
1838
|
+
|
|
1839
|
+
class TestTaskQueryMode:
|
|
1840
|
+
"""mode parameter should produce different traversal orders in task queries."""
|
|
1841
|
+
|
|
1842
|
+
def test_expand_candidates_bfs_vs_dfs(self):
|
|
1843
|
+
"""BFS and DFS should explore the same nodes but in different order."""
|
|
1844
|
+
G = _make_task_graph()
|
|
1845
|
+
seeds = [{"node_id": "render_pipeline", "seed_score": 1.0}]
|
|
1846
|
+
bfs_result = _expand_task_candidates(G, seeds, max_hops=2, traversal_mode="bfs")
|
|
1847
|
+
dfs_result = _expand_task_candidates(G, seeds, max_hops=2, traversal_mode="dfs")
|
|
1848
|
+
# Both should find candidates
|
|
1849
|
+
assert len(bfs_result) > 0
|
|
1850
|
+
assert len(dfs_result) > 0
|
|
1851
|
+
|
|
1852
|
+
def test_query_graph_mode_in_output_header(self):
|
|
1853
|
+
"""Task query output header should reflect actual mode/depth."""
|
|
1854
|
+
G = _make_task_graph()
|
|
1855
|
+
# Natural-language question triggers task query mode (not entity mode)
|
|
1856
|
+
q = "How does RenderPipeline use CanvasMaterial and FrameController"
|
|
1857
|
+
bfs_result = _query_graph(G, q, traversal_mode="bfs", depth=2)
|
|
1858
|
+
dfs_result = _query_graph(G, q, traversal_mode="dfs", depth=2)
|
|
1859
|
+
bfs_text = str(bfs_result.get("text", ""))
|
|
1860
|
+
dfs_text = str(dfs_result.get("text", ""))
|
|
1861
|
+
# Task query path includes header; keyword path uses NODE format
|
|
1862
|
+
if bfs_result.get("query_mode") == "task":
|
|
1863
|
+
assert "(bfs, depth=2)" in bfs_text
|
|
1864
|
+
assert "(dfs, depth=2)" in dfs_text
|
|
1865
|
+
else:
|
|
1866
|
+
# Keyword query — mode/depth are applied at traversal level, no header
|
|
1867
|
+
assert "NODE" in bfs_text
|
|
1868
|
+
|
|
1869
|
+
|
|
1870
|
+
# ---------------------------------------------------------------------------
|
|
1871
|
+
# depth affects task query results
|
|
1872
|
+
# ---------------------------------------------------------------------------
|
|
1873
|
+
|
|
1874
|
+
|
|
1875
|
+
class TestTaskQueryDepth:
|
|
1876
|
+
"""depth parameter should control expansion in task queries."""
|
|
1877
|
+
|
|
1878
|
+
def test_deeper_finds_more_candidates(self):
|
|
1879
|
+
"""depth=3 should find >= candidates than depth=1."""
|
|
1880
|
+
G = _make_task_graph()
|
|
1881
|
+
seeds = [{"node_id": "render_pipeline", "seed_score": 1.0}]
|
|
1882
|
+
shallow = _expand_task_candidates(G, seeds, max_hops=1, traversal_mode="bfs")
|
|
1883
|
+
deep = _expand_task_candidates(G, seeds, max_hops=3, traversal_mode="bfs")
|
|
1884
|
+
assert len(deep) >= len(shallow)
|
|
1885
|
+
|
|
1886
|
+
def test_depth_in_output_header(self):
|
|
1887
|
+
G = _make_task_graph()
|
|
1888
|
+
q = "How does RenderPipeline use CanvasMaterial and FrameController"
|
|
1889
|
+
r1 = _query_graph(G, q, depth=1)
|
|
1890
|
+
r3 = _query_graph(G, q, depth=3)
|
|
1891
|
+
if r1.get("query_mode") == "task":
|
|
1892
|
+
assert "depth=1" in str(r1.get("text", ""))
|
|
1893
|
+
assert "depth=3" in str(r3.get("text", ""))
|
|
1894
|
+
else:
|
|
1895
|
+
# Keyword mode — depth applied at BFS/DFS level
|
|
1896
|
+
assert "NODE" in str(r1.get("text", ""))
|
|
1897
|
+
|
|
1898
|
+
|
|
1899
|
+
# ---------------------------------------------------------------------------
|
|
1900
|
+
# _semantic_tree_query backward expansion (inherits)
|
|
1901
|
+
# ---------------------------------------------------------------------------
|
|
1902
|
+
|
|
1903
|
+
|
|
1904
|
+
class TestBackwardExpansion:
|
|
1905
|
+
"""backward_expand should follow inherits edges to parent classes."""
|
|
1906
|
+
|
|
1907
|
+
def test_backward_finds_parent(self):
|
|
1908
|
+
"""Semantic tree from child should discover parent via inherits."""
|
|
1909
|
+
G = _make_inherits_graph()
|
|
1910
|
+
results = _semantic_tree_query(G, ["child"], set(), max_depth=3)
|
|
1911
|
+
labels = {str(r.get("label", "")) for r in results}
|
|
1912
|
+
# forward: HelperUtil; backward: ParentClass, GrandparentClass
|
|
1913
|
+
assert "ParentClass" in labels or "HelperUtil" in labels
|
|
1914
|
+
# At minimum, results should not be empty
|
|
1915
|
+
assert len(results) > 0
|
|
1916
|
+
|
|
1917
|
+
def test_backward_depth_scales(self):
|
|
1918
|
+
"""With max_depth=2, backward can reach parent; with max_depth=1, backward is limited."""
|
|
1919
|
+
G = _make_inherits_graph()
|
|
1920
|
+
deep = _semantic_tree_query(G, ["child"], set(), max_depth=4)
|
|
1921
|
+
shallow = _semantic_tree_query(G, ["child"], set(), max_depth=1)
|
|
1922
|
+
deep_labels = {str(r.get("label", "")) for r in deep}
|
|
1923
|
+
shallow_labels = {str(r.get("label", "")) for r in shallow}
|
|
1924
|
+
# Deeper traversal should find more or equal nodes
|
|
1925
|
+
assert len(deep_labels) >= len(shallow_labels)
|
|
1926
|
+
|
|
1927
|
+
|
|
1928
|
+
# ---------------------------------------------------------------------------
|
|
1929
|
+
# _task_results_to_text header
|
|
1930
|
+
# ---------------------------------------------------------------------------
|
|
1931
|
+
|
|
1932
|
+
|
|
1933
|
+
class TestTaskResultsToText:
|
|
1934
|
+
"""Output text header should reflect mode/depth."""
|
|
1935
|
+
|
|
1936
|
+
def test_header_default(self):
|
|
1937
|
+
payload = {"seeds": [{"label": "Foo"}], "results": [{"label": "Bar", "node_id": "b"}]}
|
|
1938
|
+
text = _task_results_to_text(payload)
|
|
1939
|
+
assert "(bfs, depth=3)" in text
|
|
1940
|
+
|
|
1941
|
+
def test_header_dfs_depth5(self):
|
|
1942
|
+
payload = {"seeds": [{"label": "Foo"}], "results": [{"label": "Bar", "node_id": "b"}]}
|
|
1943
|
+
text = _task_results_to_text(payload, traversal_mode="dfs", depth=5)
|
|
1944
|
+
assert "(dfs, depth=5)" in text
|
|
1945
|
+
|
|
1946
|
+
|
|
1947
|
+
# ---------------------------------------------------------------------------
|
|
1948
|
+
# _query_graph runtime parameter guards
|
|
1949
|
+
# ---------------------------------------------------------------------------
|
|
1950
|
+
|
|
1951
|
+
|
|
1952
|
+
class TestQueryGraphParamGuards:
|
|
1953
|
+
"""_query_graph runtime clamps for direct callers bypassing MCP schema."""
|
|
1954
|
+
|
|
1955
|
+
# -- token_budget --
|
|
1956
|
+
|
|
1957
|
+
def test_negative_token_budget_clamped(self):
|
|
1958
|
+
G = _make_graph()
|
|
1959
|
+
result = _query_graph(G, "extract", token_budget=-100)
|
|
1960
|
+
assert len(str(result.get("text", ""))) < 50000
|
|
1961
|
+
|
|
1962
|
+
def test_zero_token_budget_clamped(self):
|
|
1963
|
+
G = _make_graph()
|
|
1964
|
+
result = _query_graph(G, "extract", token_budget=0)
|
|
1965
|
+
text = str(result.get("text", ""))
|
|
1966
|
+
assert len(text) > 0
|
|
1967
|
+
assert "truncated to ~0" not in text
|
|
1968
|
+
|
|
1969
|
+
def test_over_max_token_budget_clamped(self):
|
|
1970
|
+
G = _make_graph()
|
|
1971
|
+
result = _query_graph(G, "extract", token_budget=999999)
|
|
1972
|
+
assert len(str(result.get("text", ""))) < 50000
|
|
1973
|
+
|
|
1974
|
+
# -- max_degree --
|
|
1975
|
+
|
|
1976
|
+
def test_negative_max_degree_treated_as_unlimited(self):
|
|
1977
|
+
"""Negative max_degree should not skip all neighbors."""
|
|
1978
|
+
G = _make_task_graph()
|
|
1979
|
+
result = _query_graph(G, "RenderPipeline", max_degree=-5)
|
|
1980
|
+
text = str(result.get("text", ""))
|
|
1981
|
+
# Should still produce results (negative clamped to 0 = unlimited)
|
|
1982
|
+
assert len(text) > 10
|
|
1983
|
+
|
|
1984
|
+
def test_zero_max_degree_means_unlimited(self):
|
|
1985
|
+
G = _make_task_graph()
|
|
1986
|
+
result = _query_graph(G, "RenderPipeline", max_degree=0)
|
|
1987
|
+
text = str(result.get("text", ""))
|
|
1988
|
+
assert len(text) > 10
|
|
1989
|
+
|
|
1990
|
+
# -- mode fallback --
|
|
1991
|
+
|
|
1992
|
+
def test_invalid_mode_falls_back(self):
|
|
1993
|
+
"""Invalid traversal_mode should not crash; _query_graph uses it in branching."""
|
|
1994
|
+
G = _make_graph()
|
|
1995
|
+
# _query_graph itself doesn't validate mode — it passes through to _bfs/_dfs.
|
|
1996
|
+
# But the keyword path does: `(_dfs if traversal_mode == "dfs" else _bfs)`
|
|
1997
|
+
# so invalid mode gracefully falls back to bfs behavior.
|
|
1998
|
+
result = _query_graph(G, "extract", traversal_mode="invalid")
|
|
1999
|
+
assert result.get("text")
|
|
2000
|
+
|
|
2001
|
+
# -- query_variants overflow --
|
|
2002
|
+
|
|
2003
|
+
def test_many_query_variants_still_works(self):
|
|
2004
|
+
"""Large variant list should not cause excessive processing."""
|
|
2005
|
+
G = _make_graph()
|
|
2006
|
+
variants = [f"variant_{i}" for i in range(50)]
|
|
2007
|
+
result = _query_graph(G, "extract", query_variants=variants)
|
|
2008
|
+
assert result.get("text")
|
|
2009
|
+
|
|
2010
|
+
|
|
2011
|
+
# ---------------------------------------------------------------------------
|
|
2012
|
+
# _expand_task_candidates parameter validation
|
|
2013
|
+
# ---------------------------------------------------------------------------
|
|
2014
|
+
|
|
2015
|
+
|
|
2016
|
+
class TestExpandCandidatesParams:
|
|
2017
|
+
"""_expand_task_candidates traversal_mode and max_hops guards."""
|
|
2018
|
+
|
|
2019
|
+
def test_invalid_traversal_mode_defaults_to_bfs(self):
|
|
2020
|
+
"""Unknown traversal_mode should use popleft (bfs behavior)."""
|
|
2021
|
+
G = _make_task_graph()
|
|
2022
|
+
seeds = [{"node_id": "render_pipeline", "seed_score": 1.0}]
|
|
2023
|
+
# Should not crash — falls to else branch (pop), but still works
|
|
2024
|
+
result = _expand_task_candidates(G, seeds, max_hops=2, traversal_mode="unknown")
|
|
2025
|
+
assert len(result) > 0
|
|
2026
|
+
|
|
2027
|
+
def test_zero_max_hops(self):
|
|
2028
|
+
"""max_hops=0 should return only seeds themselves."""
|
|
2029
|
+
G = _make_task_graph()
|
|
2030
|
+
seeds = [{"node_id": "render_pipeline", "seed_score": 1.0}]
|
|
2031
|
+
result = _expand_task_candidates(G, seeds, max_hops=0, traversal_mode="bfs")
|
|
2032
|
+
# Only the seed itself should be in candidates
|
|
2033
|
+
assert "render_pipeline" in result
|
|
2034
|
+
# No expansion beyond seed
|
|
2035
|
+
non_seed = {k for k in result if k != "render_pipeline"}
|
|
2036
|
+
assert len(non_seed) == 0
|
|
2037
|
+
|
|
2038
|
+
|
|
2039
|
+
# ---------------------------------------------------------------------------
|
|
2040
|
+
# _subgraph_to_text token_budget edge cases
|
|
2041
|
+
# ---------------------------------------------------------------------------
|
|
2042
|
+
|
|
2043
|
+
|
|
2044
|
+
class TestSubgraphToTextBudget:
|
|
2045
|
+
"""_subgraph_to_text truncation under extreme budgets."""
|
|
2046
|
+
|
|
2047
|
+
def test_budget_1_truncates(self):
|
|
2048
|
+
G = _make_graph()
|
|
2049
|
+
nodes = {"n1", "n2", "n3", "n4"}
|
|
2050
|
+
edges = [("n1", "n2")]
|
|
2051
|
+
text = _subgraph_to_text(G, nodes, edges, token_budget=1)
|
|
2052
|
+
assert "truncated" in text
|
|
2053
|
+
|
|
2054
|
+
def test_huge_budget_no_truncation(self):
|
|
2055
|
+
G = _make_graph()
|
|
2056
|
+
nodes = {"n1", "n2"}
|
|
2057
|
+
edges = [("n1", "n2")]
|
|
2058
|
+
text = _subgraph_to_text(G, nodes, edges, token_budget=100000)
|
|
2059
|
+
assert "truncated" not in text
|
|
2060
|
+
|
|
2061
|
+
|
|
2062
|
+
# ---------------------------------------------------------------------------
|
|
2063
|
+
# _task_results_to_text budget edge cases
|
|
2064
|
+
# ---------------------------------------------------------------------------
|
|
2065
|
+
|
|
2066
|
+
|
|
2067
|
+
class TestTaskResultsToTextBudget:
|
|
2068
|
+
"""_task_results_to_text truncation behavior."""
|
|
2069
|
+
|
|
2070
|
+
def test_tiny_budget_truncates(self):
|
|
2071
|
+
payload = {
|
|
2072
|
+
"seeds": [{"label": "A"}],
|
|
2073
|
+
"results": [{"label": f"Node{i}", "node_id": f"n{i}"} for i in range(100)],
|
|
2074
|
+
}
|
|
2075
|
+
text = _task_results_to_text(payload, token_budget=10)
|
|
2076
|
+
assert "truncated" in text
|
|
2077
|
+
|
|
2078
|
+
def test_large_budget_shows_all(self):
|
|
2079
|
+
payload = {
|
|
2080
|
+
"seeds": [{"label": "A"}],
|
|
2081
|
+
"results": [{"label": "OnlyOne", "node_id": "n1"}],
|
|
2082
|
+
}
|
|
2083
|
+
text = _task_results_to_text(payload, token_budget=10000)
|
|
2084
|
+
assert "OnlyOne" in text
|
|
2085
|
+
assert "truncated" not in text
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{graphify_vault-0.5.8 → graphify_vault-0.5.8a0}/graphify_vault.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|