Repository navigation
Make target_type optional on SchemaRelationship and add node completeness check - #890
Conversation
…de_completeness (closes #888) ## Part 1: Optional target_type - `SchemaRelationship.target_type`: `String` → `Option<String>` - None = untyped relationship accepting any target node type - Serializes with `skip_serializing_if = "Option::is_none"` so existing schemas are backward-compatible - `compute_edge_table_name`: `{source}_{name}` when None, `{source}_{name}_{target}` when Some - `node_service.rs`: skip type check in `create_relationship` when target_type is None - `schema_table_manager.rs`: skip `validate_type_name` when target_type is None (both occurrences) - `relationship_cache.rs`: untyped relationships stored under "*" sentinel; `get_inbound_relationships` merges wildcard entries into every lookup - `schema_node.rs`: `get_relationships_to` includes untyped (None) relationships - `node_service.rs`: updated `get_inbound_relationships` and `get_relationship_graph` for Option<String> - `relationships.rs`: `RelationshipEdge.target_type` → `Option<String>` (skipped when None in JSON) - `surreal_store.rs`: fixed SurrealDB deserialization bug — `get_all_schemas` and `get_schema_node` now use raw JSON path (→ `SchemaNode::from_node` via serde_json) instead of SurrealDB native struct deserializer which cannot handle absent Option<String> fields in nested JSON blobs ## Part 2: check_node_completeness - `node_service.rs`: added `check_node_completeness(&self, node_id) → CompletenessResult` - Reads node's schema, checks each `required: true` relationship has at least one edge - Read-only introspection — does NOT block node creation or updates - `relationships.rs`: added `handle_check_node_completeness` MCP handler - `tools.rs`: added `check_node_completeness` tool (Tier 2 / Discoverable, category: Relationships) ## Tests - 10+ new unit/integration tests across schema.rs, relationships_handler_test.rs, relationship_cache_test.rs, and schema_table_manager_test.rs - All 1200+ existing tests continue to pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Code Review SummaryThis PR addresses a real architectural gap: untyped relationships were impossible to express, and the Overall this is a net improvement and all acceptance criteria from issue #888 are satisfied. A few issues warrant attention before merge. FindingsSuggested Improvements[Improvement] File: The struct serializes with {
"nodeId": "invoice-001",
"isComplete": false,
"missingRelationships": ["billed_to"]
}But the actual output will be: {
"node_id": "invoice-001",
"is_complete": false,
"missing_relationships": ["billed_to"]
}The test Fix: add [Improvement] N+1 query pattern in File: The loop fires a separate SurrealDB query for each relationship where SELECT relationship_type, count() AS cnt
FROM relationship
WHERE in = $source
AND relationship_type IN $rel_types
GROUP BY relationship_typeThis is not a blocker for greenfield, but worth capturing as a follow-up issue given the function will be called per-node in workflow loops. [Improvement] File:
Two options:
Option 1 is minimal and sufficient for now. The test at NitpicksNit: Doc comment on File: /// If not specified, computed as: `{source_type}_{name}_{target_type}`
This is now incomplete. Should read: /// If not specified, computed as: `{source_type}_{name}_{target_type}` when `target_type` is set,
/// or `{source_type}_{name}` when `target_type` is `None`.
Nit: This mirrors the existing pattern in Nit: Test name The name implies camelCase serialization validation, but the assertions check snake_case keys. Once the Acceptance Criteria Verification
The one open issue is the wire format mismatch on |
malibio
left a comment
There was a problem hiding this comment.
Requesting one change before merge: the CompletenessResult struct is missing #[serde(rename_all = "camelCase")], which breaks the MCP wire contract — the output will be snake_case while all other MCP tools emit camelCase and the handler's own doc comment shows camelCase. The test named test_completeness_result_complete_camel_case also needs its assertions updated to match once the attribute is added. See the detailed comment for full review findings.
- Add `#[serde(rename_all = "camelCase")]` to `CompletenessResult` — fixes wire contract bug where MCP output was snake_case while all other MCP tools emit camelCase and the handler's own doc comment showed camelCase - Update test assertions in relationships_handler_test.rs to use camelCase keys (`nodeId`, `isComplete`, `missingRelationships`) — test name `test_completeness_result_complete_camel_case` now accurately describes what it tests - Update `edge_table` doc comment in schema.rs to document both cases: three-part name when `target_type` is set, two-part when `None` - Update `get_all_inbound_relationships` doc comment in relationship_cache.rs to document that the returned map may contain the `"*"` sentinel key for untyped relationships, so callers are aware without needing a separate API Skipped (noted for follow-up): - N+1 query in check_node_completeness: acknowledged trade-off for greenfield with modest required-relationship counts; captured as potential future optimization - `serde_json::to_value(...).unwrap()` panic path: consistent with existing codebase pattern across handlers; low-priority cleanup across the file Addresses reviewer recommendations from PR #890 review. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Review Recommendations AddressedAll reviewer recommendations have been processed. ✅ Addressed (4 items)🔴 Critical — Wire format bug fixed Test assertions updated Doc fix — Doc fix — ⏭️ Skipped (2 items)N+1 query in
All 144 Rust tests pass. Quality checks clean. |
…ness check (#890) * Fix: Make target_type optional on SchemaRelationship and add check_node_completeness (closes #888) ## Part 1: Optional target_type - `SchemaRelationship.target_type`: `String` → `Option<String>` - None = untyped relationship accepting any target node type - Serializes with `skip_serializing_if = "Option::is_none"` so existing schemas are backward-compatible - `compute_edge_table_name`: `{source}_{name}` when None, `{source}_{name}_{target}` when Some - `node_service.rs`: skip type check in `create_relationship` when target_type is None - `schema_table_manager.rs`: skip `validate_type_name` when target_type is None (both occurrences) - `relationship_cache.rs`: untyped relationships stored under "*" sentinel; `get_inbound_relationships` merges wildcard entries into every lookup - `schema_node.rs`: `get_relationships_to` includes untyped (None) relationships - `node_service.rs`: updated `get_inbound_relationships` and `get_relationship_graph` for Option<String> - `relationships.rs`: `RelationshipEdge.target_type` → `Option<String>` (skipped when None in JSON) - `surreal_store.rs`: fixed SurrealDB deserialization bug — `get_all_schemas` and `get_schema_node` now use raw JSON path (→ `SchemaNode::from_node` via serde_json) instead of SurrealDB native struct deserializer which cannot handle absent Option<String> fields in nested JSON blobs ## Part 2: check_node_completeness - `node_service.rs`: added `check_node_completeness(&self, node_id) → CompletenessResult` - Reads node's schema, checks each `required: true` relationship has at least one edge - Read-only introspection — does NOT block node creation or updates - `relationships.rs`: added `handle_check_node_completeness` MCP handler - `tools.rs`: added `check_node_completeness` tool (Tier 2 / Discoverable, category: Relationships) ## Tests - 10+ new unit/integration tests across schema.rs, relationships_handler_test.rs, relationship_cache_test.rs, and schema_table_manager_test.rs - All 1200+ existing tests continue to pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * Address review: Fix CompletenessResult wire format and update docs - Add `#[serde(rename_all = "camelCase")]` to `CompletenessResult` — fixes wire contract bug where MCP output was snake_case while all other MCP tools emit camelCase and the handler's own doc comment showed camelCase - Update test assertions in relationships_handler_test.rs to use camelCase keys (`nodeId`, `isComplete`, `missingRelationships`) — test name `test_completeness_result_complete_camel_case` now accurately describes what it tests - Update `edge_table` doc comment in schema.rs to document both cases: three-part name when `target_type` is set, two-part when `None` - Update `get_all_inbound_relationships` doc comment in relationship_cache.rs to document that the returned map may contain the `"*"` sentinel key for untyped relationships, so callers are aware without needing a separate API Skipped (noted for follow-up): - N+1 query in check_node_completeness: acknowledged trade-off for greenfield with modest required-relationship counts; captured as potential future optimization - `serde_json::to_value(...).unwrap()` panic path: consistent with existing codebase pattern across handlers; low-priority cleanup across the file Addresses reviewer recommendations from PR #890 review. Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Closes #888