Files
DeepTutor/web/tests/capability-access.test.ts
Bingxi Zhao (Frank) d5c6d6ba54 refactor: reuse single LLM gate in turn runtime; drop unwired guard
The turn path (chat/partners/mastery via turn_runtime) already enforces
LLM-grant access at its single enforcement point and surfaces a clear
terminal "no model assigned" rejection — so require_llm_access was never
wired to any endpoint and only duplicated that logic. Drop it (and its
guard-only tests) and have turn_runtime reuse has_capability_access, giving
the gate one source of truth shared with the frontend lock.

Frontend fixes kept from the original PR plus two corrections:
- capabilityForPath now matches on a path-segment boundary, so a sibling
  route like /booket can't be swallowed by the /book prefix (+ regression).
- fix the misleading Knowledge sidebar comment — Knowledge needs no
  per-user grant and is never gated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 14:56:14 +08:00

40 lines
1.8 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { capabilityForPath } from "../lib/capability-routes";
// ── capabilityForPath ──────────────────────────────────────────────────
test("capabilityForPath maps LLM features to llm", () => {
assert.equal(capabilityForPath("/chat"), "llm");
assert.equal(capabilityForPath("/partners"), "llm");
assert.equal(capabilityForPath("/co-writer"), "llm");
assert.equal(capabilityForPath("/book"), "llm");
assert.equal(capabilityForPath("/learning"), "llm"); // Mastery Path
assert.equal(capabilityForPath("/playground"), "llm");
});
test("capabilityForPath matches nested routes by prefix", () => {
assert.equal(capabilityForPath("/chat/abc-123"), "llm");
assert.equal(capabilityForPath("/partners/partner-1"), "llm");
assert.equal(capabilityForPath("/learning/book-1"), "llm");
});
test("capabilityForPath matches on a segment boundary, not a bare prefix", () => {
// A sibling route must never be swallowed by a shorter gated prefix.
assert.equal(capabilityForPath("/booket"), null);
assert.equal(capabilityForPath("/chatter"), null);
assert.equal(capabilityForPath("/playgrounds-xyz"), null);
// The gated route itself and its children still match.
assert.equal(capabilityForPath("/book"), "llm");
assert.equal(capabilityForPath("/book/123"), "llm");
});
test("capabilityForPath returns null for ungated routes", () => {
// Knowledge is ungated: embedding is shared admin infra, not per-user.
assert.equal(capabilityForPath("/knowledge"), null);
assert.equal(capabilityForPath("/memory"), null);
assert.equal(capabilityForPath("/space"), null);
assert.equal(capabilityForPath("/settings"), null);
});