---
entity: caisson_node
workspace_id: ws_caisson_oss_backlog
workspace_slug: caisson-oss-backlog
node_id: nd_oss_b05_spec
node_type: SpecAndTests
status: verified
environment_version: node:22-ts:5.8
environment_lock_hash: 902c6c679663f6d8cd1f4a7a11f7c66b06f7ca39be1d1b5cf5cae8b9a5af2728
spec_hash: 4caadad9dd2dfe8668a4f8f326feb2a32a288b852b2bcc9ef3e8f52b57293d29
---

# SpecAndTests: Ready-Queue DAG Critical-Path Scheduler (`nd_oss_b05_spec`)

Frozen Vitest contract for src/dag/criticalPath.ts.

## Frozen Target Specification
```ts
// spec/target_statements/oss-b05-dag-scheduler.acceptance.test.ts
// Frozen SpecAndTests for nd_oss_b05_dag_scheduler:
// Implement src/dag/criticalPath.ts exporting:
//   planReadyNodes(
//     nodes: Array<{ id: string; status: 'open' | 'verified' | 'claimed'; estimatedMinutes: number }>,
//     edges: Array<{ parentId: string; childId: string }>,
//   ): { ok: true; readyOrdered: string[]; criticalPathMinutes: number } | { ok: false; reason: 'CYCLE_DETECTED' }
// Requirements:
//   - Detect cycles cleanly and return { ok: false, reason: 'CYCLE_DETECTED' }.
//   - A node is ready iff status === 'open' and all of its parents have status === 'verified'.
//   - Sort readyOrdered by descending remaining critical-path minutes through the DAG (tie-break by id asc).

import { describe, expect, it } from 'vitest';
import { planReadyNodes } from '../src/dag/criticalPath.js';

describe('OSS Backlog #5: Ready-Queue DAG Critical-Path Scheduler', () => {
  it('prioritizes open unblocked nodes on the longest remaining critical path', () => {
    const res = planReadyNodes(
      [
        { id: 'audit', status: 'verified', estimatedMinutes: 5 },
        { id: 'short_leaf', status: 'open', estimatedMinutes: 5 },
        { id: 'deep_a', status: 'open', estimatedMinutes: 10 },
        { id: 'deep_b', status: 'open', estimatedMinutes: 25 },
      ],
      [
        { parentId: 'audit', childId: 'short_leaf' },
        { parentId: 'audit', childId: 'deep_a' },
        { parentId: 'deep_a', childId: 'deep_b' },
      ],
    );
    expect(res).toEqual({ ok: true, readyOrdered: ['deep_a', 'short_leaf'], criticalPathMinutes: 35 });
  });

  it('rejects cyclic DAGs deterministically', () => {
    const res = planReadyNodes(
      [
        { id: 'a', status: 'open', estimatedMinutes: 5 },
        { id: 'b', status: 'open', estimatedMinutes: 5 },
      ],
      [
        { parentId: 'a', childId: 'b' },
        { parentId: 'b', childId: 'a' },
      ],
    );
    expect(res).toEqual({ ok: false, reason: 'CYCLE_DETECTED' });
  });
});
```

## Verified Solution
```ts
// spec/target_statements/oss-b05-dag-scheduler.acceptance.test.ts
// Frozen SpecAndTests for nd_oss_b05_dag_scheduler:
// Implement src/dag/criticalPath.ts exporting:
//   planReadyNodes(
//     nodes: Array<{ id: string; status: 'open' | 'verified' | 'claimed'; estimatedMinutes: number }>,
//     edges: Array<{ parentId: string; childId: string }>,
//   ): { ok: true; readyOrdered: string[]; criticalPathMinutes: number } | { ok: false; reason: 'CYCLE_DETECTED' }
// Requirements:
//   - Detect cycles cleanly and return { ok: false, reason: 'CYCLE_DETECTED' }.
//   - A node is ready iff status === 'open' and all of its parents have status === 'verified'.
//   - Sort readyOrdered by descending remaining critical-path minutes through the DAG (tie-break by id asc).

import { describe, expect, it } from 'vitest';
import { planReadyNodes } from '../src/dag/criticalPath.js';

describe('OSS Backlog #5: Ready-Queue DAG Critical-Path Scheduler', () => {
  it('prioritizes open unblocked nodes on the longest remaining critical path', () => {
    const res = planReadyNodes(
      [
        { id: 'audit', status: 'verified', estimatedMinutes: 5 },
        { id: 'short_leaf', status: 'open', estimatedMinutes: 5 },
        { id: 'deep_a', status: 'open', estimatedMinutes: 10 },
        { id: 'deep_b', status: 'open', estimatedMinutes: 25 },
      ],
      [
        { parentId: 'audit', childId: 'short_leaf' },
        { parentId: 'audit', childId: 'deep_a' },
        { parentId: 'deep_a', childId: 'deep_b' },
      ],
    );
    expect(res).toEqual({ ok: true, readyOrdered: ['deep_a', 'short_leaf'], criticalPathMinutes: 35 });
  });

  it('rejects cyclic DAGs deterministically', () => {
    const res = planReadyNodes(
      [
        { id: 'a', status: 'open', estimatedMinutes: 5 },
        { id: 'b', status: 'open', estimatedMinutes: 5 },
      ],
      [
        { parentId: 'a', childId: 'b' },
        { parentId: 'b', childId: 'a' },
      ],
    );
    expect(res).toEqual({ ok: false, reason: 'CYCLE_DETECTED' });
  });
});
```

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