mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 05:57:09 +01:00
getOrgProjects() includes the caller (403f47cd), so `[...own, ...org]`
listed every own project twice. OrangeCat's actor-status spent half its
25-project cap on duplicates (orangecat appeared twice), and
loki_fleet_status reported double the project count. /control already
deduped on its own. One pure helper, mergeVisibleProjects, own rows first.
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { mergeVisibleProjects } from "../../src/lib/visible-projects";
|
|
|
|
/**
|
|
* Own + org projects, each once. getOrgProjects() includes the caller, so the
|
|
* naive spread doubled every own project (actor-status, fleet/status).
|
|
*
|
|
* Run: npx tsx scripts/test/visible-projects.ts
|
|
*/
|
|
console.log("visible projects:");
|
|
|
|
const own = [
|
|
{ id: "a", name: "orangecat", mine: true },
|
|
{ id: "b", name: "loki", mine: true },
|
|
];
|
|
const org = [
|
|
{ id: "a", name: "orangecat", mine: false },
|
|
{ id: "c", name: "peer-site", mine: false },
|
|
{ id: "b", name: "loki", mine: false },
|
|
];
|
|
|
|
const merged = mergeVisibleProjects(own, org);
|
|
assert.deepEqual(
|
|
merged.map((p) => p.id),
|
|
["a", "b", "c"],
|
|
);
|
|
console.log(" ✓ each project appears once, own first, order kept");
|
|
|
|
assert.ok(merged.filter((p) => p.id !== "c").every((p) => p.mine));
|
|
console.log(" ✓ the own row wins over the org copy of it");
|
|
|
|
assert.deepEqual(
|
|
mergeVisibleProjects([], org).map((p) => p.id),
|
|
["a", "c", "b"],
|
|
);
|
|
assert.deepEqual(
|
|
mergeVisibleProjects(own, []).map((p) => p.id),
|
|
["a", "b"],
|
|
);
|
|
console.log(" ✓ either list may be empty");
|