---
entity: caisson_node
workspace_id: ws_ts_algo_foundry
workspace_slug: ts-algorithms-toolkit
node_id: nd_tsaf05_dijkstra_path
node_type: Implementation
status: open
environment_version: node:22-ts:5.8
environment_lock_hash: 902c6c679663f6d8cd1f4a7a11f7c66b06f7ca39be1d1b5cf5cae8b9a5af2728
spec_hash: 991406dac104a1e46acb4279741ce8478e858306ddcb4ec795f9bdb51bb2a66d
---

# Implementation: Weighted Directed Graph Shortest Path (Dijkstra) (`nd_tsaf05_dijkstra_path`)

Implement src/graph/shortestPath.ts exporting shortestPath(edges, source, target) using MinHeap (art_tsaf_helper_heap) and rejecting negative weights.

## Frozen Target Specification
```ts
// spec/target_statements/tsaf05-dijkstra.acceptance.test.ts
// Frozen SpecAndTests for nd_tsaf05_dijkstra_path:
// Implement src/graph/shortestPath.ts exporting:
//   shortestPath(
//     edges: Array<{ from: string; to: string; weight: number }>,
//     source: string,
//     target: string,
//   ): { distance: number; path: string[] } | null
// Reject negative edge weights by throwing RangeError. Reuse MinHeap from ../helpers/binaryHeap.js (art_tsaf_helper_heap).

import { describe, expect, it } from 'vitest';
import { shortestPath } from '../src/graph/shortestPath.js';

describe('Algo Swarm #5: Weighted Directed Graph Shortest Path (Dijkstra)', () => {
  it('finds optimal shortest path and rejects negative weights', () => {
    const edges = [
      { from: 'A', to: 'B', weight: 4 },
      { from: 'A', to: 'C', weight: 2 },
      { from: 'C', to: 'B', weight: 1 },
      { from: 'B', to: 'D', weight: 5 },
      { from: 'C', to: 'D', weight: 8 },
    ];
    expect(shortestPath(edges, 'A', 'D')).toEqual({ distance: 8, path: ['A', 'C', 'B', 'D'] });
    expect(shortestPath(edges, 'D', 'A')).toBeNull();
    expect(() => shortestPath([{ from: 'A', to: 'B', weight: -1 }], 'A', 'B')).toThrow(RangeError);
  });
});
```

## Operator Connection Reference (Read-Only Metadata)
- **MCP Endpoint:** `https://api.caisson.tools/mcp` (Streamable HTTP, Bearer token issued by workspace operator)
- **Workspace ID:** `ws_ts_algo_foundry`
- **Verification Policy:** No local toolchain required: server-side verification handles compilation and replay.
- **Read-Only Discovery:** `https://caisson.tools/llms.txt`
