ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
use super::{ChannelOptions, ChannelShelf, Channels, Unchanneled, resolved};

use crate::drive::NodeSection;

/// A shelf as the derive emits one: one entry per declared upstream, in declaration order.
struct TwoUpstreams {
  ocr: Option<ChannelOptions>,
  frames: Option<ChannelOptions>,
}

impl ChannelShelf for TwoUpstreams {
  fn tuning(&self) -> impl Iterator<Item = Option<ChannelOptions>> {
    [self.ocr, self.frames].into_iter()
  }
}

/// **THE PRECEDENCE**, all three layers, in the one function that states it.
#[test]
fn config_beats_declared_beats_shipped() {
  let shipped = ChannelOptions::Bounded(32);
  assert_eq!(resolved(None, None, shipped), shipped);
  assert_eq!(
    resolved(None, Some(ChannelOptions::Bounded(4)), shipped),
    ChannelOptions::Bounded(4)
  );
  assert_eq!(
    resolved(
      Some(ChannelOptions::Bounded(64)),
      Some(ChannelOptions::Bounded(4)),
      shipped
    ),
    ChannelOptions::Bounded(64)
  );
}

/// **NO FROZEN AXIS**: the KIND resolves by the same rule the depth does, in both directions.
#[test]
fn the_kind_overrides_as_readily_as_the_depth() {
  let shipped = ChannelOptions::Bounded(32);
  // A document widens what an author shipped bounded.
  assert_eq!(
    resolved(
      Some(ChannelOptions::Unbounded),
      Some(ChannelOptions::Bounded(4)),
      shipped
    ),
    ChannelOptions::Unbounded
  );
  // And bounds back what an author shipped unbounded.
  assert_eq!(
    resolved(
      Some(ChannelOptions::Bounded(4)),
      Some(ChannelOptions::Unbounded),
      shipped
    ),
    ChannelOptions::Bounded(4)
  );
}

/// A table is read BY POSITION, and a position nobody spoke about answers nothing rather than a
/// value the layer under it would have to argue with.
#[test]
fn a_table_answers_by_position_and_says_nothing_about_the_rest() {
  let channels = Channels::new().tuned("captions", [Some(ChannelOptions::Bounded(4)), None]);

  assert_eq!(
    channels.spec("captions", 0),
    Some(ChannelOptions::Bounded(4))
  );
  assert_eq!(channels.spec("captions", 1), None);
  assert_eq!(channels.spec("captions", 2), None);
  assert_eq!(channels.spec("decode", 0), None);
  assert_eq!(channels.names().collect::<Vec<_>>(), ["captions"]);
}

/// A node's table is ONE STATEMENT: writing it twice replaces it rather than merging two halves
/// nobody could read back.
#[test]
fn a_second_table_for_one_node_replaces_the_first() {
  let channels = Channels::new()
    .tuned("captions", [Some(ChannelOptions::Bounded(4))])
    .tuned("captions", [Some(ChannelOptions::Unbounded)]);

  assert_eq!(
    channels.spec("captions", 0),
    Some(ChannelOptions::Unbounded)
  );
}

/// **THE BRIDGE**: a section's block reaches the config layer, and both kinds of absence reach it as
/// silence.
#[test]
fn the_spine_bridge_carries_a_block_and_reads_both_absences_as_silence() {
  let section = NodeSection::<()>::default().with_channels(TwoUpstreams {
    ocr: Some(ChannelOptions::Unbounded),
    frames: None,
  });

  let channels = Channels::new().mounted("captions", Some(&section));
  assert_eq!(
    channels.spec("captions", 0),
    Some(ChannelOptions::Unbounded)
  );
  assert_eq!(channels.spec("captions", 1), None);

  // A section that wrote no block at all.
  let bare = NodeSection::<(), TwoUpstreams>::default();
  assert_eq!(
    Channels::new()
      .mounted("captions", Some(&bare))
      .spec("captions", 0),
    None
  );

  // And a node this deployment did not name.
  assert_eq!(
    Channels::new()
      .mounted("captions", None::<&NodeSection<(), TwoUpstreams>>)
      .spec("captions", 0),
    None
  );
}

/// A node that declared no upstreams has a shelf with nothing in it — the rack's default, and what
/// makes a document writing one refusable by name.
#[test]
fn the_default_shelf_tunes_nothing() {
  assert_eq!(Unchanneled::default().tuning().count(), 0);
}