Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: E2E Test Pipeline

on:
pull_request:
branches: [ main, dev ]
paths:
- 'nexus-explorer/**'
- 'nexus-db/**'
- 'scripts/e2e-test.sh'
- 'Cargo.toml'
- 'Cargo.lock'
push:
branches: [ main ]
paths:
- 'nexus-explorer/**'
- 'nexus-db/**'
- 'scripts/e2e-test.sh'
- 'Cargo.toml'
- 'Cargo.lock'

jobs:
e2e-tests:
name: E2E Test Suite
runs-on: macos-latest
steps:
- uses: actions/checkout@v4

- name: Setup Rust
uses: dtolnay/rust-toolchain@stable

- name: Cache cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-

- name: Run E2E Test Suite
run: |
chmod +x scripts/e2e-test.sh
bash scripts/e2e-test.sh
133 changes: 127 additions & 6 deletions nexus-explorer/src/commands/nql.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use crate::AppState;
use nexus_db::embedded::transaction::{Edge, Node, ReadTransaction};
use serde::{Deserialize, Serialize};

#[derive(Deserialize)]
Expand All @@ -13,13 +15,132 @@ pub struct NqlResult {
pub data: Option<serde_json::Value>,
}

#[derive(Serialize, Clone)]
struct QNode {
id: u128,
label: String,
}

#[derive(Serialize, Clone)]
struct QEdge {
id: u128,
label: String,
from: u128,
to: u128,
}

#[derive(Serialize)]
struct QResult {
nodes: Vec<QNode>,
edges: Vec<QEdge>,
count: usize,
}

#[tauri::command]
pub fn nql_execute(_db_name: String, _query: String) -> Result<NqlResult, String> {
// NQL execution requires the full graph engine.
// Return a stub indicating this for now.
pub fn nql_execute(
state: tauri::State<AppState>,
db_name: String,
query: String,
) -> Result<NqlResult, String> {
let dbs = state.databases.lock().map_err(|e| e.to_string())?;
let db = dbs
.get(&db_name)
.ok_or_else(|| format!("Database '{}' not found", db_name))?;

let tx = db.read_transaction().map_err(|e| e.to_string())?;
let all_nodes = tx.scan_nodes().map_err(|e| e.to_string())?;
let all_edges = tx.scan_edges().map_err(|e| e.to_string())?;

let q = query.trim().to_lowercase();

let result = if q.starts_with("match") || q.starts_with("search") {
do_match(&q, &all_nodes, &all_edges)?
} else if q.starts_with("get") || q.starts_with("find") {
do_get(&q, &all_nodes, &all_edges)?
} else if q.starts_with("count") {
do_count(&q, &all_nodes, &all_edges)?
} else {
QResult {
nodes: all_nodes.iter().map(|n| QNode { id: n.id, label: n.label.clone() }).collect(),
edges: all_edges.iter().map(|e| QEdge { id: e.id, label: e.label.clone(), from: e.from, to: e.to }).collect(),
count: all_nodes.len(),
}
};

Ok(NqlResult {
success: false,
message: "NQL execution requires the full graph engine. Use Node/Edge CRUD operations in embedded mode.".to_string(),
data: None,
success: true,
message: format!("Query returned {} nodes and {} edges", result.nodes.len(), result.edges.len()),
data: Some(serde_json::to_value(&result).map_err(|e| e.to_string())?),
})
}

fn do_match(q: &str, nodes: &[Node], edges: &[Edge]) -> Result<QResult, String> {
let label = pick_label(q);
let matched: Vec<QNode> = nodes.iter()
.filter(|n| label.as_ref().map_or(true, |l| n.label.contains(l)))
.map(|n| QNode { id: n.id, label: n.label.clone() })
.collect();
let matched_edges: Vec<QEdge> = if q.contains(")-[") || q.contains("]->") {
let el = pick_edge_label(q);
edges.iter()
.filter(|e| {
let nm = matched.iter().any(|n| n.id == e.from || n.id == e.to);
el.as_ref().map_or(nm, |x| e.label.contains(x) && nm)
})
.map(|e| QEdge { id: e.id, label: e.label.clone(), from: e.from, to: e.to })
.collect()
} else { vec![] };
Ok(QResult { nodes: matched.clone(), edges: matched_edges, count: matched.len() })
}

fn do_get(q: &str, nodes: &[Node], edges: &[Edge]) -> Result<QResult, String> {
let term = pick_search(q);
let matched: Vec<QNode> = nodes.iter()
.filter(|n| term.as_ref().map_or(true, |s| n.label.to_lowercase().contains(s)))
.map(|n| QNode { id: n.id, label: n.label.clone() })
.collect();
let matched_edges: Vec<QEdge> = edges.iter()
.filter(|e| matched.iter().any(|n| n.id == e.from || n.id == e.to))
.map(|e| QEdge { id: e.id, label: e.label.clone(), from: e.from, to: e.to })
.collect();
Ok(QResult { nodes: matched.clone(), edges: matched_edges, count: matched.len() })
}

fn do_count(q: &str, nodes: &[Node], edges: &[Edge]) -> Result<QResult, String> {
let label = pick_label(q);
let count = if q.contains("edge") || q.contains("relationship") {
edges.len()
} else {
nodes.iter().filter(|n| label.as_ref().map_or(true, |l| n.label.contains(l))).count()
};
Ok(QResult { nodes: vec![], edges: vec![], count })
}

fn pick_label(q: &str) -> Option<String> {
let pos = q.find(':')?;
let rest = &q[pos + 1..];
let end = rest.find(|c: char| !c.is_alphanumeric() && c != '_').unwrap_or(rest.len());
if end > 0 { Some(rest[..end].to_string()) } else { None }
}

fn pick_edge_label(q: &str) -> Option<String> {
let start = q.find(")-[")?;
let rest = &q[start + 3..];
let colon = rest.find(':')?;
let after = &rest[colon + 1..];
let end = after.find(']')?;
if end > 0 { Some(after[..end].to_string()) } else { None }
}

fn pick_search(q: &str) -> Option<String> {
for pat in &["contains \"", "contains '", "= \"", "= '"] {
if let Some(s) = q.find(pat) {
let rest = &q[s + pat.len()..];
let delim = if pat.contains('"') { '"' } else { '\'' };
if let Some(e) = rest.find(delim) {
return Some(rest[..e].to_lowercase());
}
}
}
None
}
26 changes: 10 additions & 16 deletions nexus-explorer/src/frontend/src/components/graph/GraphView.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
import { Component, onMount, onCleanup, createEffect } from "solid-js";
import ForceGraph from "force-graph";
import type { ForceGraphInstance } from "force-graph";
import { nodes, edges, activeDb } from "../../stores/app";
import "./GraphView.css";

const GraphView: Component = () => {
let containerRef: HTMLDivElement | undefined;
let graph: InstanceType<typeof ForceGraph> | undefined;
let graph: ForceGraphInstance | undefined;

onMount(() => {
if (!containerRef) return;
graph = new ForceGraph(containerRef)
graph = ForceGraph(containerRef)
.backgroundColor("#0f172a")
.nodeLabel("label")
.nodeAutoColorBy("label")
.nodeRelSize(6)
.linkLabel("label")
.linkWidth(2)
.nodeCanvasObject((node: any, ctx: CanvasRenderingContext2D, globalScale: number) => {
const label = node.label;
const fontSize = 12 / globalScale;
ctx.font = `${fontSize}px Sans-Serif`;
ctx.fillStyle = node.color || "#3b82f6";
ctx.beginPath();
ctx.arc(node.x, node.y, 8, 0, 2 * Math.PI, false);
ctx.fill();
ctx.fillStyle = "#f1f5f9";
ctx.fillText(label, node.x + 12, node.y + 4);
.linkWidth(1.5)
.linkDirectionalParticles(1)
.linkDirectionalParticleWidth(2)
.onEngineStop(() => {
graph?.zoomToFit(400, 40);
});
});

onCleanup(() => {
if (graph) {
graph._destructor?.();
}
graph = undefined;
});

createEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions nexus-explorer/src/frontend/src/types/force-graph.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare module 'force-graph' {
interface ForceGraphInstance {
export interface ForceGraphInstance {
backgroundColor(color: string): ForceGraphInstance;
nodeLabel(label: string | ((node: any) => string)): ForceGraphInstance;
nodeAutoColorBy(field: string | null): ForceGraphInstance;
Expand All @@ -17,6 +17,6 @@ declare module 'force-graph' {
_destructor?(): void;
}

const ForceGraph: new (element: HTMLElement) => ForceGraphInstance;
const ForceGraph: (element: HTMLElement) => ForceGraphInstance;
export default ForceGraph;
}
Loading
Loading