mere-kernel 0.0.3

Portable identity, authority, and mutation kernel for the Mere browser. Renamed from graphshell-core.
Documentation
// Copyright 2026 Mark Alan Boykin
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0

//! Test-fixture escape hatch over the `pub(crate)` graph mutators (write-path
//! migration, 2026-07-01).
//!
//! Production code routes every primitive durable mutation through
//! [`apply_graph_delta`](super::apply::apply_graph_delta) — the Phase 6.5
//! single-write-path boundary, enforced by `pub(crate)` visibility on the raw
//! mutators. Test fixtures building sample graphs would gain nothing from that
//! routing (they are not runtime paths and will never be event-logged), so this
//! extension trait re-exposes the raw mutators to them with call sites
//! unchanged: enable the kernel `fixtures` cargo feature in `dev-dependencies`
//! and `use kernel::graph::fixtures::GraphFixtures;` in the test module.
//!
//! The feature must never be enabled by a non-dev dependency — that would
//! reopen the boundary this module deliberately tunnels through for tests.

use euclid::default::Point2D;
use uuid::Uuid;

use super::edge_payload::EdgePayload;
use super::{
    Coupling, EdgeAssertion, EdgeKey, Field, Graph, Node, NodeFacetStore, NodeKey, RelationKey,
    RelationSelector,
};

/// Raw-mutator access for test fixtures. Every method delegates to the
/// `pub(crate)` inherent mutator of the same name.
pub trait GraphFixtures {
    #[cfg(not(target_arch = "wasm32"))]
    fn add_node(&mut self, url: String, position: Point2D<f32>) -> NodeKey;
    fn add_node_with_id(&mut self, id: Uuid, url: String, position: Point2D<f32>) -> NodeKey;
    fn remove_node(&mut self, key: NodeKey) -> bool;
    fn assert_relation(
        &mut self,
        from: NodeKey,
        to: NodeKey,
        assertion: EdgeAssertion,
    ) -> Option<RelationKey>;
    fn assert_semantic_predicate(
        &mut self,
        from: NodeKey,
        to: NodeKey,
        predicate: String,
    ) -> Option<RelationKey>;
    fn retract_relations(
        &mut self,
        from: NodeKey,
        to: NodeKey,
        selector: RelationSelector,
    ) -> usize;
    fn insert_node_tag(&mut self, key: NodeKey, tag: String) -> bool;
    fn remove_node_tag(&mut self, key: NodeKey, tag: &str) -> bool;
    fn set_node_title(&mut self, key: NodeKey, title: String) -> bool;
    fn set_node_body(&mut self, key: NodeKey, body: Option<String>) -> bool;
    fn set_node_mime_hint(&mut self, key: NodeKey, mime_hint: Option<String>) -> bool;
    fn set_node_image(
        &mut self,
        key: NodeKey,
        role: crate::types::ImageRole,
        image: crate::types::ImageRef,
    ) -> bool;
    fn add_field(&mut self, field: Field);
    fn add_coupling(&mut self, coupling: Coupling);
    fn get_node_mut(&mut self, key: NodeKey) -> Option<&mut Node>;
    fn get_edge_mut(&mut self, key: EdgeKey) -> Option<&mut EdgePayload>;
    fn get_relation_mut(&mut self, key: RelationKey) -> Option<&mut EdgePayload>;
    /// The facet store, unchecked: a test that must hold a graph checked open
    /// would refuse. Production installs through `install_facets`.
    fn facets_mut(&mut self) -> &mut NodeFacetStore;
}

impl GraphFixtures for Graph {
    #[cfg(not(target_arch = "wasm32"))]
    fn add_node(&mut self, url: String, position: Point2D<f32>) -> NodeKey {
        Graph::add_node(self, url, position)
    }
    fn add_node_with_id(&mut self, id: Uuid, url: String, position: Point2D<f32>) -> NodeKey {
        Graph::add_node_with_id(self, id, url, position)
    }
    fn remove_node(&mut self, key: NodeKey) -> bool {
        Graph::remove_node(self, key)
    }
    fn assert_relation(
        &mut self,
        from: NodeKey,
        to: NodeKey,
        assertion: EdgeAssertion,
    ) -> Option<RelationKey> {
        Graph::assert_relation(self, from, to, assertion)
    }
    fn assert_semantic_predicate(
        &mut self,
        from: NodeKey,
        to: NodeKey,
        predicate: String,
    ) -> Option<RelationKey> {
        Graph::assert_semantic_predicate(self, from, to, predicate)
    }
    fn retract_relations(
        &mut self,
        from: NodeKey,
        to: NodeKey,
        selector: RelationSelector,
    ) -> usize {
        Graph::retract_relations(self, from, to, selector)
    }
    fn insert_node_tag(&mut self, key: NodeKey, tag: String) -> bool {
        Graph::insert_node_tag(self, key, tag)
    }
    fn remove_node_tag(&mut self, key: NodeKey, tag: &str) -> bool {
        Graph::remove_node_tag(self, key, tag)
    }
    fn set_node_title(&mut self, key: NodeKey, title: String) -> bool {
        Graph::set_node_title(self, key, title)
    }
    fn set_node_body(&mut self, key: NodeKey, body: Option<String>) -> bool {
        Graph::set_node_body(self, key, body)
    }
    fn set_node_mime_hint(&mut self, key: NodeKey, mime_hint: Option<String>) -> bool {
        Graph::set_node_mime_hint(self, key, mime_hint)
    }
    fn set_node_image(
        &mut self,
        key: NodeKey,
        role: crate::types::ImageRole,
        image: crate::types::ImageRef,
    ) -> bool {
        Graph::set_node_image(self, key, role, image)
    }
    fn add_field(&mut self, field: Field) {
        Graph::add_field(self, field)
    }
    fn add_coupling(&mut self, coupling: Coupling) {
        Graph::add_coupling(self, coupling)
    }
    fn get_node_mut(&mut self, key: NodeKey) -> Option<&mut Node> {
        Graph::get_node_mut(self, key)
    }
    fn get_edge_mut(&mut self, key: EdgeKey) -> Option<&mut EdgePayload> {
        Graph::get_edge_mut(self, key)
    }
    fn get_relation_mut(&mut self, key: RelationKey) -> Option<&mut EdgePayload> {
        Graph::get_relation_mut(self, key)
    }
    fn facets_mut(&mut self) -> &mut NodeFacetStore {
        Graph::facets_mut(self)
    }
}