---
entity: caisson_node
workspace_id: ws_ts_algo_foundry
workspace_slug: ts-algorithms-toolkit
node_id: nd_tsaf07_spec
node_type: SpecAndTests
status: verified
environment_version: node:22-ts:5.8
environment_lock_hash: 902c6c679663f6d8cd1f4a7a11f7c66b06f7ca39be1d1b5cf5cae8b9a5af2728
spec_hash: a69ac6318accb14fa577072b3fc28e77332eb7a2591559d77d98dd059c9b5b3d
---

# SpecAndTests: Iterative Tarjan Strongly Connected Components (`nd_tsaf07_spec`)

Frozen Vitest contract for src/graph/tarjanScc.ts.

## Frozen Target Specification
```ts
// spec/target_statements/tsaf07-tarjan-scc.acceptance.test.ts
// Frozen SpecAndTests for nd_tsaf07_tarjan_scc:
// Implement src/graph/tarjanScc.ts exporting:
//   stronglyConnectedComponents(adjacency: Record<string, string[]>): string[][]
// Requirements:
//   - Must be ITERATIVE (no recursive DFS — see dead end art_tsaf_deadend_recursive_dfs; must handle 20,000-node chain).
//   - Sort node IDs inside each SCC lexicographically, and sort components by their first node ID ascending.

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

describe('Algo Swarm #7: Iterative Tarjan Strongly Connected Components', () => {
  it('identifies exact SCCs and survives a 20,000-node deep chain without stack overflow', () => {
    const sccs = stronglyConnectedComponents({
      a: ['b'],
      b: ['c', 'a'],
      c: ['d'],
      d: ['c'],
      e: [],
    });
    expect(sccs).toEqual([['a', 'b'], ['c', 'd'], ['e']]);

    const chain: Record<string, string[]> = {};
    for (let i = 0; i < 20_000; i++) {
      chain[`n${i}`] = i < 19_999 ? [`n${i + 1}`] : [];
    }
    const chainSccs = stronglyConnectedComponents(chain);
    expect(chainSccs.length).toBe(20_000);
  });
});
```

## Verified Solution
```ts
// spec/target_statements/tsaf07-tarjan-scc.acceptance.test.ts
// Frozen SpecAndTests for nd_tsaf07_tarjan_scc:
// Implement src/graph/tarjanScc.ts exporting:
//   stronglyConnectedComponents(adjacency: Record<string, string[]>): string[][]
// Requirements:
//   - Must be ITERATIVE (no recursive DFS — see dead end art_tsaf_deadend_recursive_dfs; must handle 20,000-node chain).
//   - Sort node IDs inside each SCC lexicographically, and sort components by their first node ID ascending.

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

describe('Algo Swarm #7: Iterative Tarjan Strongly Connected Components', () => {
  it('identifies exact SCCs and survives a 20,000-node deep chain without stack overflow', () => {
    const sccs = stronglyConnectedComponents({
      a: ['b'],
      b: ['c', 'a'],
      c: ['d'],
      d: ['c'],
      e: [],
    });
    expect(sccs).toEqual([['a', 'b'], ['c', 'd'], ['e']]);

    const chain: Record<string, string[]> = {};
    for (let i = 0; i < 20_000; i++) {
      chain[`n${i}`] = i < 19_999 ? [`n${i + 1}`] : [];
    }
    const chainSccs = stronglyConnectedComponents(chain);
    expect(chainSccs.length).toBe(20_000);
  });
});
```

## 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`
