feat(orchestrator): draw agents and chairs as a matrix organigram
The agents hierarchy gains a matrix org chart: agents as columns, chairs as rows, so one agent with several chairs shows every one of them; a Home tile can pin it. Tests run once on unify/skills-20261114 after the merge (operator order 2026-11-14). 🎯 Fix: 82 % 💥 Break: 8 % 💸 Tokens: 90 % ⏱️ Velocity: 90 % 🛡️ Security: 100 % 🏆 Score: 93 🚦 Gate: ⛔ fix 82 % < 90, break 8 % > 5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
48f26b678a
commit
2b4c3baaa0
8 files changed
+641
-68
No files matched your search
@@ -0,0 +1,160 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
sys.path[:0] = [str(HERE.parent), str(HERE)]
|
||||
|
||||
import test_orchestrator_e2e as base
|
||||
from hub_case import HubCase
|
||||
from hub_support import iso
|
||||
|
||||
OUT = Path(os.environ.get("E2E_OUT", "/tmp/organigram-shots"))
|
||||
CHART = """(async () => {@HELPERS@
|
||||
await screenShown(8000);
|
||||
const canvas = await until(() => {
|
||||
const found = document.querySelector("#main .organigram");
|
||||
return found && found.querySelectorAll(".org-links path.org-dashed").length >= 3 ? found : null;
|
||||
}, 8000);
|
||||
if (!canvas) {
|
||||
return {error: text(document.getElementById("main"))};
|
||||
}
|
||||
await sleep(300);
|
||||
canvas.closest(".org-chart").scrollIntoView({block: "start"});
|
||||
const scroll = canvas.closest(".org-scroll");
|
||||
const rect = (node) => node.getBoundingClientRect();
|
||||
const chair = rect(document.querySelector('#main .org-box[data-office="chair"]'));
|
||||
const staff = all("#main .org-staff .org-box").map((node) => [node, rect(node)]);
|
||||
const units = all("#main .org-units > .org-unit");
|
||||
const side = (box) => (box.right <= chair.left ? "left" : box.left >= chair.right ? "right" : "under");
|
||||
const icons = all("#main svg.bi").map((svg) => svg.parentElement).filter((owner) => !text(owner) && !(owner.getAttribute("title") && owner.getAttribute("aria-label")));
|
||||
return {
|
||||
title: text(document.getElementById("org-title")),
|
||||
offices: all("#main .org-chart .org-row[data-office]").map((row) => [row.dataset.office, row.dataset.position, text(row.querySelector(".org-holder"))]),
|
||||
staff: staff.map(([node, box]) => [node.dataset.office, side(box)]),
|
||||
staffBelowChair: staff.every(([, box]) => box.top > chair.bottom),
|
||||
unitsBelowStaff: units.every((unit) => staff.every(([, box]) => rect(unit).top > box.bottom)),
|
||||
units: units.map((unit) => [unit.dataset.node, all(".org-positions .org-box", unit).map((node) => node.dataset.office)]),
|
||||
dashed: all("#main .org-links path.org-dashed").map((path) => [path.dataset.from, path.dataset.to, getComputedStyle(path).strokeDasharray !== "none"]),
|
||||
solid: all("#main .org-links path.org-solid").length,
|
||||
also: all("#main .org-dotted").map((node) => [node.closest(".org-box").dataset.office, text(node)]),
|
||||
toggles: all("#main .org-toggle").map(name),
|
||||
scroll: {inner: scroll.scrollWidth > scroll.clientWidth + 1, overflow: getComputedStyle(scroll).overflowX},
|
||||
chairSeen: chair.left >= rect(scroll).left - 1 && chair.right <= rect(scroll).right + 1,
|
||||
wide: document.documentElement.scrollWidth > window.innerWidth + 1,
|
||||
unlabelled: icons.map((owner) => owner.outerHTML.slice(0, 120)),
|
||||
};
|
||||
})()""".replace("@HELPERS@", base.HELPERS)
|
||||
FOLD = """(async () => {@HELPERS@
|
||||
const toggle = all("#main .org-toggle").find((button) => name(button) === "Collapse: identity");
|
||||
toggle.click();
|
||||
await sleep(300);
|
||||
return {label: name(toggle), dashed: all("#main .org-links path.org-dashed").map((path) => `${path.dataset.from} > ${path.dataset.to}`), seen: all("#main .org-box[data-office]").filter((node) => node.offsetParent !== null).map((node) => node.dataset.office)};
|
||||
})()""".replace("@HELPERS@", base.HELPERS)
|
||||
UNFOLD = """(async () => {@HELPERS@
|
||||
const toggle = all("#main .org-toggle").find((button) => name(button) === "Expand: identity");
|
||||
toggle.click();
|
||||
await sleep(300);
|
||||
return {label: name(toggle), dashed: all("#main .org-links path.org-dashed").map((path) => `${path.dataset.from} > ${path.dataset.to}`)};
|
||||
})()""".replace("@HELPERS@", base.HELPERS)
|
||||
UNITS = """(async () => {@HELPERS@
|
||||
const unit = document.querySelector('#main .org-unit[data-node="group:work"]');
|
||||
const scroll = unit.closest(".org-scroll");
|
||||
const before = scroll.scrollLeft;
|
||||
unit.scrollIntoView({block: "start", inline: "start"});
|
||||
await sleep(300);
|
||||
const box = unit.querySelector(".org-unit-box").getBoundingClientRect();
|
||||
const frame = scroll.getBoundingClientRect();
|
||||
return {moved: scroll.scrollLeft > before, seen: box.left >= frame.left - 1 && box.right <= frame.right + 1, wide: document.documentElement.scrollWidth > window.innerWidth + 1, page: window.scrollX};
|
||||
})()""".replace("@HELPERS@", base.HELPERS)
|
||||
OFFICES = [
|
||||
["chair", "chair", "Skills"],
|
||||
["cluster/web", "staff", "Main"],
|
||||
["stack-architecture", "staff", "Production"],
|
||||
["identity/ldap", "line", "Experiment"],
|
||||
["identity/oidc", "line", "Stage"],
|
||||
["network/dns", "line", "Stage"],
|
||||
["work/s2", "line", "Stage"],
|
||||
["work/s3", "line", "Experiment"],
|
||||
]
|
||||
DASHED = [["identity/oidc", "identity/ldap", True], ["identity/oidc", "work/s3", True], ["stack-architecture", "network/dns", True]]
|
||||
|
||||
|
||||
@unittest.skipUnless(shutil.which(os.environ.get("CHROMIUM", "chromium")), "no Chromium")
|
||||
class TestOrganigramE2E(HubCase):
|
||||
drive = base.TestOrchestratorE2E.drive
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
OUT.mkdir(parents=True, exist_ok=True)
|
||||
now = time.time()
|
||||
|
||||
def held(office: str, session: str, name: str, work: str) -> dict:
|
||||
return {"office": office, "session": session, "runtime": "claude", "name": name, "since": iso(now - 7200), "beat": now - 30, "work": work}
|
||||
|
||||
self.write_council({
|
||||
"chair/claim.json": held("chair", "s1", "Skills session", "allocate"),
|
||||
"identity/oidc/claim.json": held("identity/oidc", "s2", "Stage", "oidc line"),
|
||||
"network/dns/claim.json": held("network/dns", "s2", "Stage", "work/dns"),
|
||||
"work/s2/claim.json": held("work/s2", "s2", "Stage", "x"),
|
||||
"identity/ldap/claim.json": held("identity/ldap", "s3", "Experiment", "work/ldap"),
|
||||
"work/s3/claim.json": held("work/s3", "s3", "Experiment", "x"),
|
||||
"cluster/web/claim.json": held("cluster/web", "s4", "Main", "web cluster"),
|
||||
"stack-architecture/claim.json": held("stack-architecture", "s5", "Production", "stack"),
|
||||
"rasci.json": {
|
||||
"work/ldap": {"title": "LDAP sync", "status": "running", "worker": "Experiment", "roles": {"Experiment": "R", "Stage": "A"}},
|
||||
"work/dns": {"title": "DNS zones", "status": "running", "worker": "Stage", "roles": {"Stage": "R", "Production": "C"}},
|
||||
"work/s3": {"title": "Presidency", "status": "queued", "worker": "Experiment", "roles": {"Experiment": "R", "Stage": "C", "Operator": "A"}},
|
||||
"work/web": {"title": "Web cluster", "status": "running", "worker": "Main", "roles": {"Main": "RA", "Skills session": "C"}},
|
||||
"work/old": {"title": "Old", "status": "done", "worker": "Production", "roles": {"Production": "R", "Main": "A"}},
|
||||
},
|
||||
})
|
||||
self.base = f"http://{self.host}/"
|
||||
|
||||
def test_chromium_draws_the_organigram_with_staff_beside_the_chair_and_dashed_superiors_at_three_widths(self):
|
||||
steps = []
|
||||
for width, height in base.WIDTHS:
|
||||
steps.append({"width": width, "height": height, "url": f"{self.base}?{width}#agents/hierarchy", "wait": 1200, "probe": CHART, "shot": str(OUT / f"chromium-{width}-organigram.png")})
|
||||
if width == 1366:
|
||||
steps.append({"width": width, "height": height, "url": None, "wait": 0, "probe": FOLD, "shot": str(OUT / f"chromium-{width}-organigram-folded.png")})
|
||||
steps.append({"width": width, "height": height, "url": None, "wait": 0, "probe": UNFOLD, "shot": None})
|
||||
if width == 390:
|
||||
steps.append({"width": width, "height": height, "url": None, "wait": 0, "probe": UNITS, "shot": str(OUT / f"chromium-{width}-organigram-units.png")})
|
||||
data = self.drive(steps, None)
|
||||
(OUT / "chromium-organigram.json").write_text(json.dumps(data, indent=1), encoding="utf-8")
|
||||
self.assertEqual(data["errors"], [])
|
||||
results = iter(data["results"])
|
||||
for width, _ in base.WIDTHS:
|
||||
chart = next(results)
|
||||
with self.subTest(width=width):
|
||||
self.assertNotIn("error", chart, chart)
|
||||
self.assertTrue(chart["title"].startswith("Organigram"), chart["title"])
|
||||
self.assertEqual(chart["offices"], OFFICES)
|
||||
self.assertEqual(chart["staff"], [["cluster/web", "right"], ["stack-architecture", "left"]])
|
||||
self.assertTrue(chart["staffBelowChair"] and chart["unitsBelowStaff"], chart)
|
||||
self.assertEqual(chart["units"], [["dimension:identity", ["identity/ldap", "identity/oidc"]], ["dimension:network", ["network/dns"]], ["group:work", ["work/s2", "work/s3"]]])
|
||||
self.assertEqual(chart["dashed"], DASHED)
|
||||
self.assertEqual(chart["solid"], 16)
|
||||
self.assertEqual(chart["also"], [["identity/ldap", "Also under identity/oidc (A)"], ["network/dns", "Also under stack-architecture (C)"], ["work/s3", "Also under identity/oidc (C)"]])
|
||||
self.assertEqual(chart["toggles"], ["Collapse: Operator", "Collapse: Chair", "Collapse: identity", "Collapse: network", "Collapse: Presidents"])
|
||||
self.assertEqual((chart["unlabelled"], chart["wide"], chart["scroll"]["overflow"], chart["chairSeen"]), ([], False, "auto", True))
|
||||
if width == 390:
|
||||
self.assertTrue(chart["scroll"]["inner"], "the organigram does not scroll inside its container")
|
||||
if width == 1366:
|
||||
folded, unfolded = next(results), next(results)
|
||||
self.assertEqual((folded["label"], folded["dashed"]), ("Expand: identity", ["stack-architecture > network/dns"]))
|
||||
self.assertNotIn("identity/oidc", folded["seen"])
|
||||
self.assertEqual((unfolded["label"], len(unfolded["dashed"])), ("Collapse: identity", 3))
|
||||
if width == 390:
|
||||
moved = next(results)
|
||||
self.assertEqual((moved["moved"], moved["seen"], moved["wide"], moved["page"]), (True, True, False, 0), moved)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,127 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import shutil
|
||||
import subprocess
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ORGANIGRAM = Path(__file__).resolve().parent.parent / "orchestrator" / "templates" / "organigram.js"
|
||||
PROBE = """
|
||||
const O = require(process.argv[1]);
|
||||
const claim = (office, kind, agent, fields) => {
|
||||
const [dimension, line] = kind === "line" ? office.split("/") : ["", ""];
|
||||
return {office, kind, dimension, line, agent, session: agent ? `s-${agent}` : "s9", work: "-", beat: null, ...fields};
|
||||
};
|
||||
const claims = [
|
||||
claim("work/s3", "work", "Experiment"),
|
||||
claim("stack-architecture", "other", "Production"),
|
||||
claim("identity/oidc", "line", "Stage"),
|
||||
claim("chair", "chair", "Skills"),
|
||||
claim("cluster/web", "cluster", "Main"),
|
||||
claim("network/dns", "line", "Stage"),
|
||||
claim("identity/ldap", "line", "Experiment", {work: "work/ldap"}),
|
||||
claim("work/s2", "work", "Stage"),
|
||||
claim("work/s9", "work", ""),
|
||||
];
|
||||
const task = (name, roles, fields) => ({task: name, ended: false, worker: "-", roles, ...fields});
|
||||
const tasks = [
|
||||
task("work/ldap", {Experiment: "R", Stage: "A"}),
|
||||
task("work/dns", {Stage: "R", Production: "C", Experiment: "I"}),
|
||||
task("work/web", {Main: "RA", Skills: "C"}),
|
||||
task("work/old", {Production: "R", Main: "A"}, {ended: true}),
|
||||
task("work/s3", {Experiment: "R", Stage: "C", Operator: "A"}),
|
||||
task("work/ldap2", {Experiment: "R", Stage: "AC"}),
|
||||
task("work/worker", {Main: "C"}, {worker: "Production"}),
|
||||
task("work/support", {Stage: "R", Main: "S", Production: "I"}),
|
||||
task("queue/gate-1", {}),
|
||||
];
|
||||
const chart = O.chart(claims);
|
||||
const box = (left, top, width, height) => ({left, top, right: left + width, bottom: top + height});
|
||||
const unit = (left) => ({box: box(left, 300, 200, 40), positions: [box(left + 30, 360, 200, 60), box(left + 30, 440, 200, 60)]});
|
||||
console.log(JSON.stringify({
|
||||
positions: Object.fromEntries(claims.map((entry) => [entry.office, O.position(entry)])),
|
||||
unknown: O.position(claim("odd", "mystery", "X")),
|
||||
chart: {
|
||||
chair: chart.chair && chart.chair.office,
|
||||
staff: chart.staff.map((entry) => entry.office),
|
||||
units: chart.units.map((entry) => [entry.id, entry.kind, entry.label, entry.positions.map((position) => position.office)]),
|
||||
},
|
||||
vacant: O.chart(claims.filter((entry) => entry.kind !== "chair")).chair,
|
||||
edges: O.dotted(claims, tasks),
|
||||
quiet: O.dotted(claims, tasks.map((entry) => ({...entry, ended: true}))),
|
||||
solid: O.solid({root: box(400, 0, 200, 50), chair: box(400, 90, 200, 80), staff: [box(560, 200, 200, 60), box(240, 200, 200, 60)], units: [unit(100), unit(700)]}),
|
||||
lonely: O.solid({root: box(400, 0, 200, 50), chair: box(400, 90, 200, 80), staff: [], units: []}),
|
||||
below: O.dashed(box(0, 0, 100, 40), box(300, 200, 100, 40)),
|
||||
column: O.dashed(box(0, 0, 100, 40), box(0, 200, 100, 40)),
|
||||
beside: O.dashed(box(300, 0, 100, 40), box(0, 20, 100, 40)),
|
||||
}));
|
||||
"""
|
||||
|
||||
|
||||
@unittest.skipUnless(shutil.which("node"), "no node")
|
||||
class TestOrganigram(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
done = subprocess.run(["node", "-e", PROBE, str(ORGANIGRAM)], capture_output=True, text=True, timeout=60, check=True)
|
||||
cls.data = json.loads(done.stdout)
|
||||
|
||||
def test_domain_chairs_and_presidents_stand_in_line_and_organizers_and_single_offices_are_staff(self):
|
||||
self.assertEqual(self.data["positions"], {
|
||||
"work/s3": "line", "stack-architecture": "staff", "identity/oidc": "line", "chair": "chair", "cluster/web": "staff",
|
||||
"network/dns": "line", "identity/ldap": "line", "work/s2": "line", "work/s9": "line",
|
||||
})
|
||||
self.assertEqual(self.data["unknown"], "staff")
|
||||
|
||||
def test_the_chart_puts_the_dimensions_by_name_then_the_presidents_under_the_chair_and_the_staff_beside_it(self):
|
||||
self.assertEqual(self.data["chart"], {
|
||||
"chair": "chair",
|
||||
"staff": ["cluster/web", "stack-architecture"],
|
||||
"units": [
|
||||
["dimension:identity", "dimension", "identity", ["identity/ldap", "identity/oidc"]],
|
||||
["dimension:network", "dimension", "network", ["network/dns"]],
|
||||
["group:work", "work", "Presidents", ["work/s2", "work/s3", "work/s9"]],
|
||||
],
|
||||
})
|
||||
self.assertIsNone(self.data["vacant"])
|
||||
|
||||
def test_an_office_holder_named_a_or_c_on_an_open_task_becomes_a_dashed_superior(self):
|
||||
self.assertEqual(self.data["edges"], [
|
||||
{"from": "cluster/web", "to": "stack-architecture", "letters": "C", "tasks": ["work/worker"]},
|
||||
{"from": "identity/oidc", "to": "identity/ldap", "letters": "AC", "tasks": ["work/ldap", "work/ldap2"]},
|
||||
{"from": "identity/oidc", "to": "work/s3", "letters": "C", "tasks": ["work/s3"]},
|
||||
{"from": "stack-architecture", "to": "identity/oidc", "letters": "C", "tasks": ["work/dns"]},
|
||||
])
|
||||
|
||||
def test_ended_tasks_the_chair_s_own_line_and_parties_without_an_office_draw_no_dashed_line(self):
|
||||
self.assertEqual(self.data["quiet"], [])
|
||||
drawn = {(edge["from"], edge["to"]) for edge in self.data["edges"]}
|
||||
self.assertFalse({edge for edge in drawn if edge[0] == "chair" or "Operator" in edge})
|
||||
self.assertNotIn(("cluster/web", "identity/oidc"), drawn)
|
||||
|
||||
def test_the_solid_lines_join_root_chair_staff_rail_and_combs(self):
|
||||
self.assertEqual(self.data["solid"], [
|
||||
"M 500 50 V 70 H 500 V 90",
|
||||
"M 500 170 L 500 282",
|
||||
"M 500 230 L 560 230",
|
||||
"M 500 230 L 440 230",
|
||||
"M 200 282 L 800 282",
|
||||
"M 200 282 L 200 300",
|
||||
"M 800 282 L 800 300",
|
||||
"M 118 340 L 118 470",
|
||||
"M 118 390 L 130 390",
|
||||
"M 118 470 L 130 470",
|
||||
"M 718 340 L 718 470",
|
||||
"M 718 390 L 730 390",
|
||||
"M 718 470 L 730 470",
|
||||
])
|
||||
self.assertEqual(self.data["lonely"], ["M 500 50 V 70 H 500 V 90"])
|
||||
|
||||
def test_a_dashed_line_leaves_the_facing_edges_and_rounds_a_shared_column_on_the_right(self):
|
||||
self.assertEqual(self.data["below"], "M 50 40 C 50 120 350 120 350 200")
|
||||
self.assertEqual(self.data["column"], "M 100 20 C 136 20 136 220 100 220")
|
||||
self.assertEqual(self.data["beside"], "M 300 20 C 200 20 200 40 100 40")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user