Files
Octop/tests/unit/gateway/test_slash_parse.py
jubaoliang 52bad9c4d0 feat(users): per-user resource policies (workspace root + token quota) and slash parser
Add a `user_policies` table (migration v14) backing per-user `workspace_root_dir`
(restricts local backend roots) and `token_quota` (lifetime token limit). Token
quota is enforced in the agent runtime via TokenQuotaMiddleware. Extract slash
command parsing into infra/gateway/slash/parser.py and expose policies on the
users API. Frontend adds admin policy UI, storage/chat/experts restyle, and a
shared TabLabel / PageLoading component.
2026-09-08 14:21:28 +08:00

44 lines
1017 B
Python

"""tests/unit/gateway/test_slash_parse.py"""
from __future__ import annotations
import pytest
from octop.infra.gateway.slash.parser import parse_slash
@pytest.mark.parametrize(
("text", "name", "args"),
[
("/help", "help", ""),
(" /help ", "help", ""),
("/HELP", "help", ""),
("/model openai:gpt-4o", "model", "openai:gpt-4o"),
("/new\nhello", "new", "hello"),
("/switch-thread t1", "switch-thread", "t1"),
],
)
def test_parses_commands(text: str, name: str, args: str) -> None:
cmd = parse_slash(text)
assert cmd is not None
assert (cmd.name, cmd.args) == (name, args)
@pytest.mark.parametrize(
"text",
[
"/root/ddd",
"/root/ddd is missing",
"/usr/bin/env python",
"/etc/hosts",
"/tmp/a.txt",
"//comment",
"/2fa",
"/ help",
"",
None,
],
)
def test_rejects_paths_and_non_commands(text: str | None) -> None:
assert parse_slash(text) is None