Files
OmniRoute/tests/unit/sidebar-visibility.test.ts
Diego Rodrigues de Sa e Souza fd7e4c10e5 feat(compression): omniglyph engine (context-as-image, Fable 5 direct) — stack + single mode (#6556)
* feat(compression): dependência omniglyph (file:) + smoke de import

* feat(compression): engine omniglyph — contexto-como-imagem com gates fail-closed

* fix(compression): omniglyph adapter fail-open no transform (try/catch)

* feat(compression): registra omniglyph no registry e catálogo (single mode, stackPriority 90)

* feat(compression): modo único omniglyph (async), selecionar o modo é o enable

* feat(compression): plumbing supportsVision + providerTransport até os engines

* feat(compression): estimador de tokens image-aware — modo stacked mantém a saída do omniglyph

* docs(compression): corrige comentário do prefixo base64 no decode PNG (64 chars)

* feat(compression): registra omniglyph nas listas de modo/engine (db, combo, deriveDefaultPlan, mcp)

* feat(dashboard): dedicated OmniGlyph engine screen (context-as-image)

Adds a per-engine detail page at /dashboard/context/omniglyph, alongside the
other compression engines in the sidebar. Four sections: the economics (measured
savings), a REAL before→after (dense text vs the rendered PNG page, not a mockup),
the fail-closed gate flow, and the enable control wired to /api/settings/compression
(preview engine, off by default). Sidebar entry + i18n label across all locales.

* chore(compression): consume published omniglyph@^1.0.0 from the npm registry

Replaces the local file: dependency used during the preview phase — npm ci
now resolves omniglyph from the registry with integrity, unblocking CI.

* fix(compression): satisfy v3.8.47 quality gates for the omniglyph engine

- dependency-allowlist: approve omniglyph (own package, published from
  diegosouzapw/OmniGlyph; supply-chain review done by the maintainer)
- ladder maps (#6533 guard): rank omniglyph 80 (stackPriority 90, runs after
  every text engine) with expectedReductionFactor 0.35 (measured 0.23-0.33)
- drop the two explicit any casts in omniglyph tests (no-explicit-any is
  error-level in tests since #6218)

* chore(compression): rebaseline strategySelector for the omniglyph mode dispatch

+18 lines of cohesive dispatch/type wiring at the existing mode chokepoints
(sync no-op + async single-mode branch + providerTransport on the options
types) — not extractable without hiding the dispatch boundary, mirroring the
prior compression rebaselines. Also drops an unused eslint-disable directive
in image-aware-tokens.test.ts (warning-level red under --max-warnings 0).

* chore(quality): register inherited base tests in stryker tap.testFiles

masked-200-exhaustion-fallback-6427 and headroom-codex-quota-snapshot-6379
arrived via the base merge without their stryker registration —
check:mutation-test-coverage --strict requires covering tests to be listed.

* refactor(compression): keep omniglyph wiring under the complexity gate

- extract the async single-mode resolution to engines/omniglyphSingleMode.ts
  (runCompressionAsync was at complexity 17 after the mode branch; back <=15)
- split OmniglyphContextPageClient into section components (was 161 lines in
  one function; every function now under the 80-line cap)
- complexity baseline 2052->2053: the +1 is inherited base drift (the ratchet
  does not run on fast-path merges — same pattern as the v3.8.44/46
  rebaselines); this PR's own code is measured complexity-net-zero

* chore(quality): register 3 more inherited base tests in stryker tap.testFiles

route-guard-middleware-local-only, combo-diagnostics-trace and
idempotency-fusion-collision arrived via the latest base merge without their
stryker registration (fast-path merges skip check:mutation-test-coverage).

* chore(quality): cognitive-complexity baseline 883->884 (inherited base drift)

check:cognitive-complexity measures 884 identically on the pristine
origin/release/v3.8.47 tip and on this HEAD — the PR itself is
cognitive-net-zero (single-mode resolution extracted to its own module,
page client split into section components). Same inherited-drift pattern
as the v3.8.4x release rebaselines.

---------

Co-authored-by: diegosouzapw <diegosouzapw@devbox.local>
2026-07-08 07:56:44 -03:00

183 lines
6.1 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import { join } from "node:path";
const sidebarVisibility = await import("../../src/shared/constants/sidebarVisibility.ts");
const repoRoot = join(import.meta.dirname, "../..");
function sectionItems(sectionId: string) {
const section = sidebarVisibility.SIDEBAR_SECTIONS.find(
(candidate) => candidate.id === sectionId
);
assert.ok(section, `expected ${sectionId} sidebar section to exist`);
return sidebarVisibility.getSectionItems(section);
}
test("system sidebar items: monitoring has activity at top then logs/audit/system groups", () => {
const items = sectionItems("monitoring");
assert.deepEqual(
items.map((item) => item.id),
[
"activity",
"logs",
"logs-proxy",
"logs-console",
"audit",
"audit-mcp",
"audit-a2a",
"health",
"runtime",
]
);
});
test("primary sidebar items place limits after cache", () => {
const items = sectionItems("omni-proxy");
assert.deepEqual(
items.map((item) => item.id),
[
"endpoints",
"api-manager",
"providers",
"embedded-services",
"combos",
"combos-live",
"quota",
"costs-quota-share",
"context-settings",
"context-combos",
"context-caveman",
"context-rtk",
"context-headroom",
"context-session-dedup",
"context-ccr",
"context-llmlingua",
"context-lite",
"context-aggressive",
"context-ultra",
"context-omniglyph",
"compression-studio",
"cli-code",
"cli-agents",
"acp-agents",
"cloud-agents",
"agent-bridge",
"traffic-inspector",
"discovery",
"api-endpoints",
"webhooks",
"proxy",
]
);
});
test("context sidebar section sits between primary and cli", () => {
const sectionIds = sidebarVisibility.SIDEBAR_SECTIONS.map((section) => section.id);
assert.deepEqual(sectionIds.slice(0, 4), ["home", "omni-proxy", "analytics", "costs"]);
const items = sectionItems("omni-proxy");
assert.deepEqual(
items
.filter((item) => item.id.startsWith("context-"))
.map((item) => ({ id: item.id, href: item.href })),
[
{ id: "context-settings", href: "/dashboard/context/settings" },
{ id: "context-combos", href: "/dashboard/context/combos" },
{ id: "context-caveman", href: "/dashboard/context/caveman" },
{ id: "context-rtk", href: "/dashboard/context/rtk" },
{ id: "context-headroom", href: "/dashboard/context/headroom" },
{ id: "context-session-dedup", href: "/dashboard/context/session-dedup" },
{ id: "context-ccr", href: "/dashboard/context/ccr" },
{ id: "context-llmlingua", href: "/dashboard/context/llmlingua" },
{ id: "context-lite", href: "/dashboard/context/lite" },
{ id: "context-aggressive", href: "/dashboard/context/aggressive" },
{ id: "context-ultra", href: "/dashboard/context/ultra" },
{ id: "context-omniglyph", href: "/dashboard/context/omniglyph" },
]
);
});
test("sidebar visibility drops stale entries from saved settings", () => {
const allSidebarItemIds = sidebarVisibility.SIDEBAR_SECTIONS.flatMap((section) =>
sidebarVisibility.getSectionItems(section).map((item) => item.id)
);
assert.equal(
(sidebarVisibility.HIDEABLE_SIDEBAR_ITEM_IDS as readonly string[]).includes("auto-combo"),
false
);
assert.equal((allSidebarItemIds as string[]).includes("auto-combo"), false);
assert.equal(
(sidebarVisibility.HIDEABLE_SIDEBAR_ITEM_IDS as readonly string[]).includes("settings"),
false
);
assert.equal((allSidebarItemIds as string[]).includes("settings"), false);
assert.deepEqual(sidebarVisibility.normalizeHiddenSidebarItems(["auto-combo" as any, "logs"]), [
"logs",
]);
});
test("help sidebar exposes changelog after docs and issues", () => {
const items = sectionItems("help");
assert.deepEqual(
items.map((item) => ({
id: item.id,
href: item.href,
i18nKey: item.i18nKey,
})),
[
{ id: "docs", href: "/docs", i18nKey: "docs" },
{
id: "issues",
href: "https://github.com/diegosouzapw/OmniRoute/issues",
i18nKey: "issues",
},
{ id: "changelog", href: "/dashboard/changelog", i18nKey: "changelog" },
]
);
assert.equal(sidebarVisibility.HIDEABLE_SIDEBAR_ITEM_IDS.includes("changelog"), true);
});
test("plugins (marketplace) has a discoverable sidebar entry (#3656 follow-up)", async () => {
const items = sectionItems("agentic-features");
const plugins = items.find((item) => item.id === "plugins");
assert.ok(plugins, "expected a plugins item in the agentic-features section");
assert.equal(plugins.href, "/dashboard/plugins");
assert.equal(sidebarVisibility.HIDEABLE_SIDEBAR_ITEM_IDS.includes("plugins"), true);
// It must be a real page (plugin manager + marketplace tab), not a legacy redirect stub.
const pluginsPage = await readFile(
join(repoRoot, "src/app/(dashboard)/dashboard/plugins/page.tsx"),
"utf8"
);
assert.doesNotMatch(pluginsPage, /^\s*redirect\(/m);
assert.match(pluginsPage, /marketplace/i);
});
test("legacy dashboard routes redirect to their consolidated surfaces", async () => {
const autoComboPage = await readFile(
join(repoRoot, "src/app/(dashboard)/dashboard/auto-combo/page.tsx"),
"utf8"
);
const usagePage = await readFile(
join(repoRoot, "src/app/(dashboard)/dashboard/usage/page.tsx"),
"utf8"
);
const settingsPage = await readFile(
join(repoRoot, "src/app/(dashboard)/dashboard/settings/page.tsx"),
"utf8"
);
assert.match(autoComboPage, /redirect\("\/dashboard\/combos\?filter=intelligent"\)/);
assert.match(usagePage, /redirect\("\/dashboard\/logs"\)/);
assert.match(settingsPage, /redirect\(resolveSettingsRoute\(tab\)\)/);
assert.match(settingsPage, /\/dashboard\/settings\/general/);
const compressionPage = await readFile(
join(repoRoot, "src/app/(dashboard)/dashboard/compression/page.tsx"),
"utf8"
);
assert.match(compressionPage, /redirect\("\/dashboard\/context\/caveman"\)/);
});