# tests/core/analyzers/board.analyzer.test.ts

> 103 lines of code and 0 definitions.

Tree: Coordination tree
Language: typescript
Canonical: https://banes-lab.com/anatomy/coordination#file-coordination-tests-core-analyzers-board-analyzer-test-ts
Source text: https://banes-lab.com/assets/sources/source.aeaf136547cbbd2d951b89b31a873b43723dc4087da108175cd385b534e2a864.generated.txt

## Source

```typescript
import {
    ACTIVE_STATE,
    activeAgents,
    activeSeats,
    boardRecords,
    delimitersIn,
    enclosingRecord,
    itemSpanFlags,
    seatState,
    unresolvedAddressing,
} from "../../../tools/core/analyzers/board.analyzer.ts";
import { describe, it } from "node:test";
import assert from "node:assert/strict";

const BOARD = [
    "# Board",
    "Agent A — ACTIVE",
    "  Owns: tools/core",
    "  Status: drafting",
    "┌─── AGENT A-1 · judgement ───",
    "To B — read the draft.",
    "  Hidden: not a field",
    "└─── END AGENT A-1",
    "└─── END AGENT A",
    "Agent B — INACTIVE",
    "  Owns: config",
    "Gate converge — open",
].join("\n");

describe("delimitersIn and enclosingRecord", () => {
    it("reads every open and close marker with its agent key and line", () => {
        assert.deepEqual(delimitersIn(BOARD), [
            { agent: "A-1", line: 5, open: true },
            { agent: "A-1", line: 8, open: false },
            { agent: "A", line: 9, open: false },
        ]);
    });

    it("resolves a line to the narrowest span that holds it", () => {
        const source = [
            "┌─── AGENT A",
            "┌─── AGENT A-1",
            "inside the item",
            "└─── END AGENT A-1",
            "└─── END AGENT A",
        ].join("\n");
        const holder = enclosingRecord(source);
        assert.equal(holder(3), "A-1");
        assert.equal(holder(5), "A");
        assert.equal(holder(9), null);
    });
});

describe("itemSpanFlags", () => {
    it("flags the lines inside an item's fence and nothing else", () => {
        const flags = itemSpanFlags(BOARD);
        assert.deepEqual(
            flags.map((flag, index) => (flag ? index : -1)).filter((index) => index !== -1),
            [5, 6],
        );
    });
});

describe("boardRecords", () => {
    it("reads agent and gate records with their state and indented fields, skipping item bodies", () => {
        const records = boardRecords(BOARD);
        assert.deepEqual(
            records.map((record) => [record.kind, record.label, record.state, record.line]),
            [
                ["agent", "Agent A", "ACTIVE", 2],
                ["agent", "Agent B", "INACTIVE", 10],
                ["gate", "Gate converge", "open", 12],
            ],
        );
        assert.deepEqual(
            [...(records[0]?.fields ?? new Map())],
            [
                ["Owns", "tools/core"],
                ["Status", "drafting"],
            ],
        );
    });
});

describe("seatState, activeSeats and activeAgents", () => {
    it("reads a seat's state from its board marker when no index allocates letters", () => {
        assert.equal(seatState("")("A", ACTIVE_STATE), ACTIVE_STATE);
        assert.deepEqual(activeSeats(BOARD, ""), ["A"]);
        assert.equal(activeAgents(BOARD, ""), 1);
    });

    it("reads a seat's state from the index when the index allocates letters, and the index wins", () => {
        const index = "| A | governance | INACTIVE |\n| B | document | ACTIVE |";
        assert.equal(seatState(index)("C", ACTIVE_STATE), "");
        assert.deepEqual(activeSeats(BOARD, index), ["B"]);
    });
});

describe("unresolvedAddressing", () => {
    it("reports a broadcast item whose opener addresses named agents instead of everyone", () => {
        const source = [
            "meta to:*",
            "To B — only one reader",
            "meta to:*",
            "To ALL — everyone",
            "no meta",
            "To C",
        ].join("\n");
        assert.deepEqual(unresolvedAddressing(source), [{ line: 1, opener: "To B — only one reader" }]);
    });
});
```
