Publish curated projectbrain source from 88fab8df1542019289e947f092c2b387e0825c60

This commit is contained in:
Public Source Publisher committed 2026-10-04 15:47:50 +00:00
1 parent 48e72d07e0
commit eca2891b07
45 files changed
+2697 -328

No files matched your search

@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import type { RuntimeJob, RuntimeRunner } from "@/shared/api/portfolioTypes";
import { getActivityOperationSections, latestCompletedRuntimeJobByRunner, prioritizeRuntimeJobs, runtimeJobGroups, runtimeJobLabel, runtimeQueueExplanation, runtimeRunnerCapacity } from "@/shared/lib/activityRuntimePresentation";
import { getActivityOperationSections, latestCompletedRuntimeJobByRunner, oldestRunnableRuntimeJob, prioritizeRuntimeJobs, runtimeCompatibleIdleRunnerCount, runtimeJobAgeMinutes, runtimeJobDetail, runtimeJobGroups, runtimeJobLabel, runtimeJobTimingLabel, runtimeQueueExplanation, runtimeRunnerCapacity, runtimeRunnerCapacityPresentation } from "@/shared/lib/activityRuntimePresentation";
const job = (queueState: RuntimeJob["queueState"], input: Partial<RuntimeJob> = {}): RuntimeJob => ({
id: 1,
@@ -22,11 +22,83 @@ describe("activity runtime presentation", () => {
expect(prioritizeRuntimeJobs([job("completed", { id: 9 }), job("dependency-blocked", { id: 8 }), job("runnable", { id: 7 }), job("running", { id: 6 })]).map((item) => item.id)).toEqual([6, 7, 8, 9]);
});
it("orders queued work by actual waiting age rather than newest id", () => {
const ordered = prioritizeRuntimeJobs([
job("runnable", { id: 9, createdAt: "2026-09-01T12:09:00Z" }),
job("runnable", { id: 7, createdAt: "2026-09-01T12:03:00Z" }),
job("runnable", { id: 8, createdAt: "2026-09-01T12:06:00Z" }),
]);
expect(ordered.map((item) => item.id)).toEqual([7, 8, 9]);
});
it("uses oldest creation time, ascending id ties, and unknown timestamps last for queued jobs", () => {
const ordered = prioritizeRuntimeJobs([
job("runnable", { id: 9, createdAt: "2026-09-01T12:03:00Z" }),
job("runnable", { id: 4, createdAt: "2026-09-01T12:03:00Z" }),
job("runnable", { id: 7, createdAt: "2026-09-01T12:06:00Z" }),
job("runnable", { id: 2, createdAt: "not-a-timestamp" }),
]);
expect(ordered.map((item) => item.id)).toEqual([4, 9, 7, 2]);
});
it("does not present dependency-blocked work as the oldest runnable job", () => {
const blocked = job("dependency-blocked", { id: 5, status: "requested", createdAt: "2026-09-01T12:00:00Z" });
expect(runtimeJobLabel(blocked)).toBe("Wacht op eerdere job");
expect(runtimeJobDetail(blocked)).toBe("Start zodra de vereiste eerdere job is afgerond");
expect(oldestRunnableRuntimeJob([
blocked,
job("dependency-blocked", { id: 4, createdAt: "2026-09-01T11:00:00Z" }),
])).toBeUndefined();
});
it("selects the oldest visible runnable job while ignoring dependency-blocked jobs", () => {
const selected = oldestRunnableRuntimeJob([
job("dependency-blocked", { id: 1, createdAt: "2026-09-01T11:00:00Z" }),
job("runnable", { id: 9, createdAt: "2026-09-01T12:09:00Z" }),
job("runnable", { id: 4, createdAt: "2026-09-01T12:03:00Z" }),
]);
expect(selected?.id).toBe(4);
});
it("reports waiting age and compatible idle runner capacity", () => {
const queued = job("runnable", { labels: ["linux-validation"], createdAt: "2026-09-01T12:00:00Z" });
const runners: RuntimeRunner[] = [
{ id: 1, name: "validation", status: "online", busy: false, disabled: false, labels: ["linux-validation"] },
{ id: 2, name: "security", status: "online", busy: false, disabled: false, labels: ["security"] },
{ id: 3, name: "busy-validation", status: "online", busy: true, disabled: false, labels: ["linux-validation"] },
];
const now = Date.parse("2026-09-01T12:07:30Z");
expect(runtimeJobAgeMinutes(queued, now)).toBe(7);
expect(runtimeJobTimingLabel(queued, now)).toBe("Wacht 7 min");
expect(runtimeCompatibleIdleRunnerCount(queued, runners)).toBe(1);
expect(runtimeCompatibleIdleRunnerCount(job("runnable", { labels: ["missing"] }), runners)).toBe(0);
});
it("never presents a queued job as completed", () => {
expect(runtimeJobLabel(job("runnable"))).toBe("Wacht op runner");
expect(runtimeQueueExplanation(38, 0, 0)).toContain("nog geen afgeronde jobs");
});
it("keeps capacity unknown when runner discovery is incomplete", () => {
const display = runtimeRunnerCapacityPresentation(runtimeRunnerCapacity([]), false);
expect(display).toEqual({ value: "?", label: "runnercapaciteit onbekend" });
const explanation = runtimeQueueExplanation(2, 0, 0, false);
expect(explanation).toContain("capaciteit is onbekend");
expect(explanation).not.toContain("alle online runners zijn momenteel bezig");
});
it("does not describe a known-empty runner inventory as busy capacity", () => {
const explanation = runtimeQueueExplanation(2, 0, 0, true, 0);
expect(explanation).toContain("geen online runners beschikbaar");
expect(explanation).not.toContain("alle online runners zijn momenteel bezig");
});
it("describes positive online capacity with no idle runners as busy", () => {
expect(runtimeQueueExplanation(2, 0, 0, true, 3)).toContain("alle online runners zijn momenteel bezig");
});
it("explains persistent queueing when free runners exist", () => {
expect(runtimeQueueExplanation(2, 0, 1)).toContain("1 vrije runner");
expect(runtimeQueueExplanation(2, 0, 2)).toContain("joblabels");