import assert from "node:assert/strict";
import test from "node:test";

import {isStalledWorkstream} from "../src/components/workplan-status.js";

test("stalled workstream predicate is safe to pass to Array.filter", () => {
  const realNow = Date.now;
  Date.now = () => new Date("2026-06-07T15:00:00Z").getTime();

  try {
    const rows = [
      {
        title: "stale active",
        status: "active",
        updated_at: "2026-05-20T12:00:00Z",
        done: 1,
        progress: 1,
        todo: 0,
        wait: 0,
      },
      {
        title: "fresh active",
        status: "active",
        updated_at: "2026-06-06T12:00:00Z",
        done: 1,
        progress: 1,
        todo: 0,
        wait: 0,
      },
      {
        title: "stale finished",
        status: "finished",
        updated_at: "2026-05-20T12:00:00Z",
        done: 2,
        progress: 0,
        todo: 0,
        wait: 0,
      },
    ];

    assert.deepEqual(rows.filter(isStalledWorkstream).map(w => w.title), ["stale active"]);
  } finally {
    Date.now = realNow;
  }
});
