Files
numolus/app/frontend/engine/__tests__/graph.spec.ts
T
wkhandClaude Opus 5.5 e14bada114 Add Rails backend: accounts via magic link, server documents, sharing
The app becomes a Rails 8 application; the Vue frontend moves to
app/frontend and is served through vite_rails.

- Without an account documents stay in the browser (IndexedDB). Sign-in
  is by magic link or the 6-digit code from the same mail; afterwards
  local documents can be uploaded into the account.
- Server documents (/d/<id>) with versioned saves and a single-editor
  lock per browser tab; others see them read-only and follow by polling.
- Sharing via link (works without an account) and via e-mail invitation,
  roles viewer/editor; the owner manages links and people.
- Store gains a read-only mode that blocks all content changes.
- Solid Queue, Cache and Cable share the one PostgreSQL database.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 20:09:06 +02:00

62 lines
2.3 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { DependencyGraph } from '../graph';
/**
* Helper: build a graph from "cell <- precedent, precedent" lines.
* Node names are arbitrary strings here (real code uses `keyOf`).
*/
function build(edges: Record<string, string[]>): DependencyGraph {
const g = new DependencyGraph();
for (const [cell, precs] of Object.entries(edges)) g.setPrecedents(cell, precs);
return g;
}
describe('DependencyGraph.affected', () => {
it('returns dirty cells plus their transitive dependents', () => {
// A -> B -> C ; A -> D
const g = build({ B: ['A'], C: ['B'], D: ['A'] });
expect([...g.affected(['A'])].sort()).toEqual(['A', 'B', 'C', 'D']);
expect([...g.affected(['B'])].sort()).toEqual(['B', 'C']);
});
});
describe('DependencyGraph.topoOrder', () => {
it('orders precedents before dependents', () => {
const g = build({ B: ['A'], C: ['A', 'B'], D: ['C'] });
const { order, circular } = g.topoOrder(g.affected(['A']));
expect(circular.size).toBe(0);
const pos = (n: string) => order.indexOf(n);
expect(pos('A')).toBeLessThan(pos('B'));
expect(pos('B')).toBeLessThan(pos('C'));
expect(pos('C')).toBeLessThan(pos('D'));
});
it('detects a direct self-reference', () => {
const g = build({ A: ['A'] });
const { circular } = g.topoOrder(g.affected(['A']));
expect([...circular]).toEqual(['A']);
});
it('detects a 2-cycle and flags both nodes', () => {
const g = build({ A: ['B'], B: ['A'] });
const { order, circular } = g.topoOrder(g.affected(['A']));
expect([...circular].sort()).toEqual(['A', 'B']);
expect(order).toEqual([]);
});
it('detects a longer cycle, leaves acyclic tail evaluable', () => {
// cycle A->B->C->A ; plus D reads C (D is not on the cycle)
const g = build({ A: ['C'], B: ['A'], C: ['B'], D: ['C'] });
const { order, circular } = g.topoOrder(g.affected(['A']));
expect([...circular].sort()).toEqual(['A', 'B', 'C']);
expect(order).toEqual(['D']);
});
it('rewiring precedents removes stale edges', () => {
const g = build({ B: ['A'] });
expect([...g.affected(['A'])].sort()).toEqual(['A', 'B']);
g.setPrecedents('B', []); // B no longer reads A
expect([...g.affected(['A'])].sort()).toEqual(['A']);
});
});