mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-04 04:12:36 +00:00
The backend import package is now docsgpt, the name it will carry on PyPI; application was far too generic to install into anyone's site-packages. git mv plus a mechanical rewrite of every import, dotted string and path reference: 734 Python files, the compose files, Dockerfile, workflows, docs, setup scripts, devcontainer, k8s manifests, vscode config, pytest and coverage config, .gitignore. Behaviour is unchanged. Kept for one release: - A top-level application package whose meta-path finder resolves application.x.y to the already-imported docsgpt.x.y object, so old imports and entry points (celery -A application.app.celery, uvicorn application.asgi:asgi_app) keep working with a FutureWarning. - Celery registers every application.* task name as an alias of its docsgpt.* task on start-up, so messages queued by the previous release still run. The redbeat key prefix moves to redbeat:docsgpt:v2: so schedule entries the previous release wrote are left unread instead of firing twice. The backend image builds from the repository root (docker build -f docsgpt/Dockerfile .) so it can ship the alias package; a root .dockerignore allow-lists docsgpt/ and application/ and keeps caches, local data, .env files, the sample index files and the Dockerfile out. Compose and the image workflows point at the new context.
82 lines
2.3 KiB
Python
82 lines
2.3 KiB
Python
"""Tests for docsgpt.devices.normalizer."""
|
|
|
|
from docsgpt.devices.normalizer import normalize_command, normalize_segment
|
|
|
|
|
|
def test_normalize_git_checkout():
|
|
assert normalize_segment("git checkout main -- file.txt") == "git checkout *"
|
|
|
|
|
|
def test_normalize_npm_install():
|
|
assert normalize_segment("npm install foo bar") == "npm install *"
|
|
|
|
|
|
def test_normalize_ls_with_args():
|
|
assert normalize_segment("ls -la /tmp") == "ls *"
|
|
|
|
|
|
def test_normalize_cat_path():
|
|
assert normalize_segment("cat /etc/passwd") == "cat *"
|
|
|
|
|
|
def test_normalize_no_args():
|
|
assert normalize_segment("pwd") == "pwd"
|
|
|
|
|
|
def test_normalize_two_word_no_args():
|
|
# ``git status`` has no additional args; pattern is just ``git status``.
|
|
assert normalize_segment("git status") == "git status"
|
|
|
|
|
|
def test_normalize_empty():
|
|
assert normalize_segment("") == ""
|
|
|
|
|
|
def test_normalize_command_compound_joins_all_segments():
|
|
# All segments normalized and joined; not just the first.
|
|
assert normalize_command("ls -la && rm -rf /tmp") == "ls * && rm *"
|
|
|
|
|
|
def test_normalize_command_compound_distinguishes_tail():
|
|
# Sticky for ``ls /tmp && whoami`` must not match ``ls /tmp && rm /tmp/x``.
|
|
assert normalize_command("ls /tmp && whoami") == "ls * && whoami"
|
|
assert (
|
|
normalize_command("ls /tmp && rm /tmp/x")
|
|
!= normalize_command("ls /tmp && whoami")
|
|
)
|
|
|
|
|
|
def test_normalize_command_single_segment_unchanged():
|
|
# A non-compound command yields just its own pattern (no `` && ``).
|
|
assert normalize_command("ls -la /tmp") == "ls *"
|
|
|
|
|
|
def test_normalize_command_skips_empty_segments():
|
|
# Trailing/empty connector segments are dropped, not joined as blanks.
|
|
assert normalize_command("ls -la && ") == "ls *"
|
|
|
|
|
|
def test_normalize_command_none_when_empty():
|
|
assert normalize_command("") is None
|
|
|
|
|
|
def test_normalize_command_none_when_only_connectors():
|
|
assert normalize_command("&& ;") is None
|
|
|
|
|
|
def test_normalize_quoted_args():
|
|
assert normalize_segment('echo "hello world"') == "echo *"
|
|
|
|
|
|
def test_normalize_docker_run():
|
|
assert normalize_segment("docker run -it nginx") == "docker run *"
|
|
|
|
|
|
def test_normalize_kubectl_apply():
|
|
assert normalize_segment("kubectl apply -f deploy.yaml") == "kubectl apply *"
|
|
|
|
|
|
def test_normalize_known_two_word_minimal():
|
|
# Just ``npm`` with no subcmd.
|
|
assert normalize_segment("npm") == "npm"
|