Skip to content

Gate the Relationships trigger on the type having typed relationships - #2017

Merged
mstomar125 merged 3 commits into
mainfrom
issue-2007-relationships-gate
Aug 10, 2026
Merged

mstomar125 merged 3 commits into
mainfrom
issue-2007-relationships-gate

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

The Relationships entry point in GenericSchemaForm rendered unconditionally, so clicking it on a schema with no typed relationships opened the viewer only to show "no typed relationships" — noise on every type that has none. This gap was explicitly deferred in #1918's review; #1999 (project→task) now gives a real relationship to test the gate against. Closes #2007.

Change

Gate the button on whether the node's type actually has a typed relationship. The viewer's own load (loadNodeRelationshipsView) already resolves both sides — outbound declared on this schema and inbound declared by another schema targeting this type — into one group per relationship, so the gate runs that load once per node and shows the button iff it yields any group.

  • packages/desktop-app/src/lib/components/schema/generic-schema-form.svelte: {#if hasRelationships} around the trigger; a $effect runs loadNodeRelationshipsView(nodeId) once per node. Default hidden; fail open on a load error so a transient failure never hides a real feature.

Note: the check reuses the viewer's load rather than reading schema.relationships — the frontend SchemaNode type carries no relationships field (post-#2008 the wire carries declarations under properties.relationships), so the resolved view is the single source of truth for both directions.

Tests

New generic-schema-form-relationships-gate.test.ts — 3 cases: has-relationships → shown, none → hidden, load-error → fail-open shown.

Isolation note: the test spies on the real sharedNodeStore.getNode (restored per-test) rather than vi.mock-ing that module — under vitest's forks pool a module mock of the shared singleton leaks into other suites in the same fork (it broke navigation-service's ancestor walk). Full frontend suite green (192 files / 4450 tests); eslint + svelte-check clean; pre-push gate passed.

🤖 Generated with Claude Code

mstomar125 and others added 2 commits August 10, 2026 11:26
The Relationships entry point in GenericSchemaForm rendered unconditionally,
so clicking it on a schema with no typed relationships opened the viewer only
to say "no typed relationships" — noise on every type that has none.

Gate the button on whether the node's type actually has a relationship. The
viewer's own load (loadNodeRelationshipsView) already resolves both sides —
outbound declared on this schema and inbound declared by another schema
targeting this type — into one group per relationship, so run it once per node
and show the button iff it yields any group. Default hidden; fail open on a
load error so a transient failure never hides a real feature.

Now testable against a real relationship since #1999 added project -> task.

Closes #2007.

Co-Authored-By: Claude <[email protected]>
The visibility gate hid the Relationships button on a type reached only via a
derived inbound relationship with no edges yet — e.g. a task with no linked
project — because get_node_relationships dropped empty inbound groups while
emitting empty outbound ones. That asymmetry made the gate edge-level on the
inbound side but declaration-level on the outbound side, so a fresh unlinked
task failed the "shows the button" acceptance criterion.

Make the inbound branch symmetric with the outbound branch: emit the declared
group even with zero edges. This fixes the gate for the inbound side and also
lets the viewer add the first inbound edge from the target's side. Adds a
get_node_relationships test asserting both empty declared groups (in + out)
are present.

Severity: 🔴 addressed (AC2). Reviewer: pragmatic-code-review on PR #2017.

Co-Authored-By: Claude <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic Code Review — Initial Review

Independent review against #2007's ACs. The mechanism, $effect guarding, fail-open policy, and non-goal discipline are clean, and AC1/AC3 hold. But a real correctness gap surfaced:

🔴 AC2 not met (empty-inbound case). The gate reuses the viewer load (loadNodeRelationshipsView → get_node_relationships), which emits empty outbound declared groups but drops empty inbound ones (rel_ops.rs: if related.is_empty() { continue; }). Since #1999 declares project→task outbound on project only (task's side is a derived inbound), a task with no linked project — the ordinary case — gets its inbound group dropped → groups.length === 0 → button hidden. It only appears once a project already links the task. So the gate is declaration-level for outbound but edge-level for inbound.

🟡 Test blind spot. The three gate tests mock loadNodeRelationshipsView with synthetic groups, so they exercise the $effect→{#if} wiring but not real rel_ops semantics — which is why the suite stayed green despite the bug.

🟢 $effect guard correct (once per nodeId, stale-async-safe); fail-open-on-error is the right call; no CLAUDE.md violations.

Verdict: REQUEST CHANGES — AC2 is a genuine gap, not a nit.

@mstomar125

Copy link
Copy Markdown
Contributor Author

/address-review

🔴 AC2 (empty-inbound) — ADDRESSED. Fixed the root cause in the backend rather than papering over it in the gate: made get_node_relationships's inbound branch symmetric with the outbound branch — it now emits the declared group even with zero edges (rel_ops.rs). So a task reached only via the derived inbound project relationship surfaces the group with count 0 → groups.length > 0 → button shows, even with no project linked. Bonus: this also lets the viewer add the first inbound edge from the target side (previously impossible).

🟡 Test blind spot — ADDRESSED. Added test_get_node_relationships_emits_empty_declared_groups (node_service tests) asserting both empty declared groups (in + out) are present from the real command — the honest coverage the mocked frontend test lacked. The frontend gate test still validates the $effect→gate wiring given groups; together they cover the path end-to-end.

Validation: full cargo test -p nodespace-core green (incl. the new + all existing get_node_relationships tests); fmt + clippy clean; re-pushing through the full gate.

Re-Review Decision

Decision: RE-REVIEW NEEDED — a backend semantics change (empty inbound groups now emitted for every type with an inbound declaration) + a new test. Running /pragmatic-code-review again on the new commit once the gate passes.

The function doc still said inbound groups are returned only with an edge; both
sides now return declared groups even when empty. Doc-only.

Co-Authored-By: Claude <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic Code Review — Re-Review (delta 04bb4d0e..fdce08d1)

🔴 AC2 — RESOLVED. The inbound branch's empty-skip is removed; the group is pushed unconditionally after the source-type retain, symmetric with outbound. The empty group is well-formed (count 0, related [], direction "in", correct source_type/target_type/reverse_name), so a task reached only via the derived inbound project relationship now yields a group even with zero edges.

🟡 Test blind spot — RESOLVED. test_get_node_relationships_emits_empty_declared_groups drives the real command (no edge) and asserts both empty declared groups (in + out) are present — it would have failed under the old continue.

Regression check — clean. Read-mode modal filters rows.length > 0 so empty groups add no user-visible noise (edit-mode only); the source-type dedup runs before the push so multi-source separation is intact; no test asserted "no inbound group when empty."

🟡 (new, addressed) stale doc comment at rel_ops.rs:265 — fixed in a follow-up commit to state both sides always return declared groups.

Verdict: APPROVE.

/address-review (doc nit)

  • ✅ Addressed the stale function-doc comment. Doc-only, no logic change.
  • Re-Review Decision: NO RE-REVIEW NEEDED — comment-only edit.

@mstomar125
mstomar125 merged commit 5beb857 into main Aug 10, 2026
@mstomar125
mstomar125 deleted the issue-2007-relationships-gate branch August 10, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Relationships trigger shows even when a schema has no typed relationships defined

1 participant