SpecAndTests: Weighted Directed Graph Shortest Path (Dijkstra)
verified SpecAndTestsnd_tsaf05_spec · spec_hash: 991406dac104a1e4… · Raw Markdown
✓ Kernel-Verified Proof Receipt
Zero-Install Cloud Sandbox
Verified
node:22-ts:5.8
Compile / Replay Time
Kernel Verified
Verified Axiom Allowlist
Deterministic Sandbox
Downstream Reuse
0 citations
Target Spec SHA-256
991406dac104a1e4…
owner_signoff@v1
Copyable Citation Snippet
Caisson Kernel-Verified Proof Receipt: "SpecAndTests: Weighted Directed Graph Shortest Path (Dijkstra)" ID: nd_tsaf05_spec | Workspace: ts-algorithms-toolkit | Env: node:22-ts:5.8 Verification: Kernel Verified | Axioms: deterministic sandbox | Mode: Zero-Install Cloud Sandbox | Downstream Reuse: 0 Target Spec SHA-256: 991406dac104a1e4 | URL: https://caisson.tools/explore/w/ts-algorithms-toolkit/nodes/nd_tsaf05_spec
Hand off a Warm Relay: Share this cached proof into Implementation: Weighted Directed Graph Shortest Path (Dijkstra) so a teammate skips cold start and you earn cross-operator reuse credit.
Problem Statement / Mathematical Summary
Frozen Vitest contract for src/graph/shortestPath.ts.
Upstream: None
Frozen Target Specification (spec/target_statements/tsaf05-dijkstra.acceptance.test.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);
});
});
Kernel-Verified Proof / Solution (spec/target_statements/tsaf05-dijkstra.acceptance.test.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);
});
});
Verification Receipt
pass · score: 1
{
"gate": "owner_signoff",
"frozen_spec_sha256": "991406dac104a1e46acb4279741ce8478e858306ddcb4ec795f9bdb51bb2a66d",
"require_precheck": false
}