Визуализатор: справочник ответственных, каноническая длительность, поддержка обеих схем
Модель читает khbuild_responsible (колонки responsible, responsible2/3 = ключ «роль - Имя»); если справочника нет (архив khnata) - прежние responsible_role/responsible_name и khnata_roles. Длительность: 5d - календарные дни, 5wd - рабочие, суффикс ? игнорируется при расчёте и выводится в Ганте и ARIS. Тесты на обе схемы и откат на прежний справочник. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,8 +3,8 @@ import { renderPage } from "./html.js";
|
||||
import { renderAris } from "./aris.js";
|
||||
import { clampPx, placeLabels, renderGantt, stageOrder, summarizeGroup } from "./gantt.js";
|
||||
import { buildApi } from "./http-api.js";
|
||||
import { mapRow, type ProcessModel } from "./model.js";
|
||||
import { computeSchedule, parseConstraint, parseDuration } from "./schedule.js";
|
||||
import { buildModel, describeResponsible, loadModel, mapRow, type ProcessModel } from "./model.js";
|
||||
import { computeSchedule, parseConstraint, parseDuration, parseDurationInfo } from "./schedule.js";
|
||||
|
||||
const row = (o: Record<string, unknown>) => mapRow({ id: "X", ...o });
|
||||
|
||||
@@ -35,6 +35,109 @@ describe("parseDuration", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("каноническая длительность", () => {
|
||||
it("5d - календарные дни, 5wd - рабочие (5 рабочих = 7 календарных), ? - оценка, при расчёте игнорируется", () => {
|
||||
expect(parseDurationInfo("5d")).toEqual({ amount: 5, unit: "d", uncertain: false, days: 5 });
|
||||
expect(parseDurationInfo("30d?")).toMatchObject({ days: 30, uncertain: true });
|
||||
expect(parseDurationInfo("5wd")).toMatchObject({ unit: "wd", days: 7, uncertain: false });
|
||||
expect(parseDurationInfo("10wd")).toMatchObject({ days: 14 });
|
||||
expect(parseDurationInfo("2wd?")).toMatchObject({ days: 3, uncertain: true });
|
||||
expect(parseDurationInfo("0d")).toMatchObject({ days: 0 });
|
||||
expect(parseDurationInfo("1.5d")).toMatchObject({ amount: 1.5 });
|
||||
expect(parseDuration("30d?")).toBe(30);
|
||||
expect(parseDuration("10wd")).toBe(14);
|
||||
});
|
||||
it("прежние текстовые значения архива по-прежнему читаются", () => {
|
||||
expect(parseDurationInfo("4 недели")).toMatchObject({ days: 28 });
|
||||
expect(parseDurationInfo("~3 месяца")).toMatchObject({ days: 90, uncertain: true });
|
||||
expect(parseDurationInfo("TBD")).toBeNull();
|
||||
});
|
||||
it("вопросик не влияет на расписание, но выводится в Ганте и ARIS", () => {
|
||||
const rows = [row({ id: "A", stage: "S", action_name: "Работа", duration: "28d?", date_constraint: "день 0 → день 28" }), row({ id: "B", stage: "S", action_name: "Ещё", duration: "28d", date_constraint: "день 0 → день 28" })];
|
||||
const sch = computeSchedule(rows);
|
||||
expect(sch.timings.get("A")).toMatchObject({ start: 0, end: 28 });
|
||||
expect(sch.warnings).toEqual([]);
|
||||
const m: ProcessModel = { ...model, rows };
|
||||
expect(renderGantt(m, sch, {})).toContain("A · 28d?");
|
||||
expect(renderGantt(m, sch, {})).toContain("B · 28d<");
|
||||
expect(renderAris(m, sch, {})).toContain(">28d?<");
|
||||
});
|
||||
it("рабочие дни в расписании переводятся в календарные", () => {
|
||||
const sch = computeSchedule([row({ id: "A", duration: "10wd" }), row({ id: "B", depends_on: "A", duration: "5d" })]);
|
||||
expect(sch.timings.get("A")).toMatchObject({ start: 0, end: 14 });
|
||||
expect(sch.timings.get("B")).toMatchObject({ start: 14, end: 19 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("справочник ответственных", () => {
|
||||
const raw = {
|
||||
process: [
|
||||
{ id: "CP-0", responsible: "architect - RIOS", responsible2: "arch_permit_lead - Андрей", data_out1: "Plan" },
|
||||
{ id: "S-1", responsible: "pm - PM" },
|
||||
{ id: "S-2" },
|
||||
],
|
||||
refs: [
|
||||
{ id: "architect - RIOS", role: "architect", person: "RIOS", comment: null },
|
||||
{ id: "arch_permit_lead - Андрей", role: "arch_permit_lead", person: "Андрей", comment: "уточнить" },
|
||||
{ id: "specs_client_mgr - Austin", role: "specs_client_mgr", person: "Austin", comment: null },
|
||||
{ id: "specs_client_mgr - Маша", role: "specs_client_mgr", person: "Маша", comment: "делит с Austin" },
|
||||
{ id: "pm - PM", role: "pm", person: "PM", comment: null },
|
||||
],
|
||||
legacyRoles: false,
|
||||
systems: [],
|
||||
data: [{ id: "Plan", data_description: "План", responsible: "architect - RIOS", comment: null }],
|
||||
};
|
||||
it("колонки responsible, responsible2, responsible3 дают список ключей, роль берётся у первого", () => {
|
||||
const m = buildModel("khbuild", raw);
|
||||
expect(m.rows[0]).toMatchObject({ responsible: ["architect - RIOS", "arch_permit_lead - Андрей"], role: "architect", responsibleName: "RIOS; Андрей" });
|
||||
expect(m.rows[1]).toMatchObject({ responsible: ["pm - PM"], role: "pm" });
|
||||
expect(m.rows[2]).toMatchObject({ responsible: [], role: null });
|
||||
expect(describeResponsible(m.rows[0]!, m)).toBe("architect - RIOS; arch_permit_lead - Андрей");
|
||||
expect(describeResponsible(m.rows[2]!, m)).toBe("не указан");
|
||||
});
|
||||
it("роли производны от справочника: имена одной роли собираются, комментарий берётся первый непустой", () => {
|
||||
const m = buildModel("khbuild", raw);
|
||||
const sc = m.roles.find((r) => r.id === "specs_client_mgr")!;
|
||||
expect(sc.person).toBe("Austin, Маша");
|
||||
expect(sc.comment).toBe("делит с Austin");
|
||||
expect(m.roles.map((r) => r.id)).toEqual(["architect", "arch_permit_lead", "specs_client_mgr", "pm"]);
|
||||
});
|
||||
it("ответственный за объект данных берётся из справочника", () => {
|
||||
expect(buildModel("khbuild", raw).data[0]).toMatchObject({ id: "Plan", role: "architect" });
|
||||
});
|
||||
it("прежняя схема (архив khnata): responsible_role / responsible_name и справочник ролей", () => {
|
||||
const m = buildModel("khnata", {
|
||||
process: [{ id: "S1001", responsible_role: "seller", responsible_name: "Arthur" }],
|
||||
refs: [{ id: "seller", role_person: "Arthur", comment: null }],
|
||||
legacyRoles: true,
|
||||
systems: [],
|
||||
data: [{ id: "D", responsible_role: "seller" }],
|
||||
});
|
||||
expect(m.rows[0]).toMatchObject({ responsible: [], role: "seller", responsibleName: "Arthur" });
|
||||
expect(describeResponsible(m.rows[0]!, m)).toBe("Arthur / Arthur");
|
||||
expect(m.roles).toEqual([{ id: "seller", person: "Arthur", comment: null }]);
|
||||
expect(m.data[0]).toMatchObject({ role: "seller" });
|
||||
});
|
||||
it("loadModel: нет таблицы responsible (42P01) - читается прежний справочник ролей; другие ошибки пробрасываются", async () => {
|
||||
const calls: string[] = [];
|
||||
const db = {
|
||||
query: async (sql: string) => {
|
||||
calls.push(sql);
|
||||
if (sql.includes("_responsible")) throw Object.assign(new Error("relation does not exist"), { code: "42P01" });
|
||||
if (sql.includes("_roles")) return { rows: [{ id: "seller", role_person: "Arthur", comment: null }] };
|
||||
if (sql.includes("_process")) return { rows: [{ id: "S1", responsible_role: "seller" }] };
|
||||
return { rows: [] };
|
||||
},
|
||||
};
|
||||
const m = await loadModel(db as never, "khnata");
|
||||
expect(m.rows[0]?.role).toBe("seller");
|
||||
expect(calls.some((c) => c.includes("khnata_responsible"))).toBe(true);
|
||||
expect(calls.some((c) => c.includes("khnata_roles"))).toBe(true);
|
||||
const bad = { query: async (sql: string) => { if (sql.includes("_responsible")) throw Object.assign(new Error("permission denied"), { code: "42501" }); return { rows: [] }; } };
|
||||
await expect(loadModel(bad as never, "khbuild")).rejects.toThrow("permission denied");
|
||||
});
|
||||
});
|
||||
|
||||
describe("computeSchedule", () => {
|
||||
it("берёт срок из ограничения, остальное выводит по зависимостям", () => {
|
||||
const rows = [
|
||||
@@ -72,6 +175,10 @@ describe("computeSchedule", () => {
|
||||
|
||||
const model: ProcessModel = {
|
||||
set: "khbuild",
|
||||
responsible: [
|
||||
{ id: "architect - RIOS", role: "architect", person: "RIOS", comment: null },
|
||||
{ id: "pm - PM", role: "pm", person: "PM", comment: "кто именно?" },
|
||||
],
|
||||
roles: [
|
||||
{ id: "architect", person: "RIOS", comment: null },
|
||||
{ id: "pm", person: "PM", comment: "кто именно?" },
|
||||
|
||||
Reference in New Issue
Block a user