feat(F-551): PFAD:-Präfix gegen Slash-Command-Blockade @implements: [F-551]
onboarding.py: PFAD_PREFIX + extract_path_with_prefix (streift PFAD:-Präfix, rückwärtskompatibel); adapter.py: ::setfakt path + _handle_fakt_store_path_input streifen Präfix ab vor Validierung, PFAD:-Beispiel in Aufforderungstexten/Dialog/Beschreibung; Tests: TestExtractPathWithPrefix (6); Analysen/F551_Architektur_dot45.md
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
# F-551 — PFAD:-Präfix gegen Slash-Command-Blockade (FAKT-Pfad-Eingabe)
|
||||
|
||||
**Autor:** dot45 (External Worker)
|
||||
**Feature:** [F-551]
|
||||
**Datum:** 22.09.2026
|
||||
**Status:** Implementiert
|
||||
|
||||
## Problem
|
||||
|
||||
Wenn der Nutzer im Rocket.Chat-Plugin einen absoluten Pfad als freie Nachricht
|
||||
eingibt (z.B. `/data/Wissensdatenbank`), fängt `rocket.cat` den führenden
|
||||
Schrägstrich `'/'` als **Slash-Command** ab. Die Nachricht kommt nie beim
|
||||
Archivar-Plugin an — es erscheint `'Es gibt keinen Befehl /data/Wissensdatenbank'`.
|
||||
Dadurch bricht der FAKT-Speicherort-Dialog ab (Onboarding Schritt 3 und die
|
||||
`::setfakt`-Pfad-Eingabe im laufenden Betrieb).
|
||||
|
||||
## Lösung (Andreas' Vorgabe)
|
||||
|
||||
Der Nutzer schreibt den Pfad mit einem **`PFAD:`-Präfix**:
|
||||
|
||||
```
|
||||
PFAD: /data/Wissensdatenbank
|
||||
```
|
||||
|
||||
Die Nachricht beginnt dann mit `P`, nicht mit `/` — `rocket.cat` greift nicht.
|
||||
Das Plugin erkennt das Präfix, streift es ab und validiert nur den Pfad danach.
|
||||
|
||||
## Betroffene Pfad-Eingabe-Wege
|
||||
|
||||
Es gibt **drei** Wege, über die ein Nutzer einen FAKT-Speicherort-Pfad eingibt:
|
||||
|
||||
| Weg | Stelle | Präfix-Toleranz |
|
||||
|---|---|---|
|
||||
| `::setfakt path <pfad>` (direktes Argument) | `plugin/adapter.py` ~Z.5550 | ja (Präfix abgestreift) |
|
||||
| Onboarding / `::setfakt`-Dialog Option 2/3 | `plugin/adapter.py` ~Z.8300–8316 | ja (Aufforderungstext mit PFAD:-Beispiel) |
|
||||
| Pfad-Eingabe-Sub-Phase (gemeinsamer Handler) | `plugin/adapter.py` `_handle_fakt_store_path_input` ~Z.8345 | ja (Präfix abgestreift vor Validierung) |
|
||||
|
||||
Der `::setfakt`-Dialog und das Onboarding nutzen **denselben** `fakt_store`-Flow
|
||||
(`_handle_fakt_store_path_input`), daher deckt eine Änderung dort BEIDE Wege ab —
|
||||
sowohl die FAKT-Speicherung im laufenden Betrieb als auch das Onboarding.
|
||||
|
||||
## Implementierung
|
||||
|
||||
### `plugin/archivar/onboarding.py`
|
||||
|
||||
Neue Konstante und Helfer-Funktion:
|
||||
|
||||
```python
|
||||
PFAD_PREFIX = "PFAD:"
|
||||
|
||||
def extract_path_with_prefix(raw_input: str) -> Dict[str, Any]:
|
||||
# Erkennt 'PFAD: <pfad>' (case-insensitiv, mit/ohne Leerzeichen nach ':')
|
||||
# → liefert {"had_prefix": bool, "path": <pfad ohne Präfix>}
|
||||
# Rückwärtskompatibel: ohne Präfix bleibt die Eingabe unverändert
|
||||
```
|
||||
|
||||
### `plugin/adapter.py`
|
||||
|
||||
- `::setfakt path <pfad>`: `extract_path_with_prefix(path_arg)` vor der Validierung.
|
||||
- `_handle_fakt_store_path_input`: `extract_path_with_prefix(single_line)` vor
|
||||
`validate_fact_store_path(...)`. Gilt für Onboarding UND `::setfakt`-Dialog.
|
||||
- Aufforderungstexte (Onboarding Option 2/3, Fehler-Meldung, `::setfakt`-Dialog,
|
||||
`::setfakt path`-Fehler, `::setfakt`-Registrierungsbeschreibung): überall
|
||||
`PFAD: /data/Wissensdatenbank` als Beispiel, damit der Nutzer das Präfix kennt.
|
||||
|
||||
## Rückwärtskompatibilität
|
||||
|
||||
`extract_path_with_prefix` liefert bei Eingaben **ohne** `PFAD:`-Präfix den Pfad
|
||||
unverändert (`had_prefix=False`). Alle bestehenden Eingaben funktionieren also
|
||||
weiterhin — das Präfix ist eine optionale, zusätzliche Möglichkeit.
|
||||
|
||||
## Tests
|
||||
|
||||
`plugin/archivar/tests/test_fact_store_onboarding.py` — neue Klasse
|
||||
`TestExtractPathWithPrefix`:
|
||||
|
||||
- Ohne Präfix bleibt die Eingabe unverändert (Rückwärtskompatibel).
|
||||
- `PFAD: /pfad` → Pfad ohne Präfix.
|
||||
- `PFAD:/pfad` (ohne Leerzeichen) wird toleriert.
|
||||
- `pfad:` (kleingeschrieben) wird case-insensitiv erkannt.
|
||||
- Präfix-Eingabe liefert einen Pfad, den `validate_fact_store_path` akzeptiert.
|
||||
- Leere Eingabe → `had_prefix=False`, Pfad unverändert.
|
||||
|
||||
## Risiken
|
||||
|
||||
- **Keine** für bestehende Eingaben (rein additive Präfix-Erkennung).
|
||||
- Falls ein echter Pfad zufällig mit `PFAD:` beginnt (praktisch unmöglich bei
|
||||
absoluten Pfaden), wird das Präfix fälschlich abgestreift — harmlos, da der
|
||||
Pfad danach normal validiert wird.
|
||||
- `::setfakt path PFAD: /pfad` (Präfix im Argument) wird ebenfalls unterstützt.
|
||||
@@ -15,6 +15,7 @@ Sicherheitsanforderungen:
|
||||
|
||||
# @implements: [F-012] — Auto-Onboarding
|
||||
# @implements: [F-065] — P-065 Onboarding ACTIVE-Guard aufspalten
|
||||
# @implements: [F-551] — PFAD:-Präfix gegen Slash-Command-Blockade (Pfad-Eingabe)
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -53,6 +54,42 @@ BLOCKED_PREFIXES = [
|
||||
"/proc",
|
||||
]
|
||||
|
||||
# F-551: Präfix vor der Pfad-Eingabe (umgeht rocket.cat Slash-Command-Blockade)
|
||||
PFAD_PREFIX = "PFAD:"
|
||||
|
||||
|
||||
def extract_path_with_prefix(raw_input: str) -> Dict[str, Any]:
|
||||
"""F-551: Extrahiere einen Pfad aus einer Nutzer-Eingabe mit PFAD:-Präfix.
|
||||
|
||||
rocket.cat fängt Nachrichten, die mit '/' beginnen, als Slash-Command ab
|
||||
(z.B. '/data/Wissensdatenbank' → 'Es gibt keinen Befehl /data/...').
|
||||
Andreas' Vorgabe: Der Nutzer schreibt 'PFAD: <absoluter Pfad>'. Diese
|
||||
Funktion erkennt das Präfix (auch mit Leerzeichen danach) und liefert den
|
||||
Pfad danach zurück — das Präfix wird abgestreift, BEVOR die Validierung
|
||||
läuft.
|
||||
|
||||
Rückwärtskompatibel: Wenn kein 'PFAD:'-Präfix vorhanden ist, wird die
|
||||
Eingabe unverändert als Pfad behandelt (altes Verhalten).
|
||||
|
||||
Args:
|
||||
raw_input: Die rohe Nutzer-Nachricht oder das ::setfakt path-Argument.
|
||||
|
||||
Returns:
|
||||
Dict mit:
|
||||
- had_prefix (bool): True wenn ein 'PFAD:'-Präfix erkannt wurde
|
||||
- path (str): Der extrahierte Pfad (ohne Präfix, gestrippt)
|
||||
"""
|
||||
if not raw_input or not raw_input.strip():
|
||||
return {"had_prefix": False, "path": raw_input}
|
||||
|
||||
stripped = raw_input.strip()
|
||||
# Toleriere 'PFAD:' und 'PFAD:' mit Leerzeichen danach
|
||||
if stripped.upper().startswith(PFAD_PREFIX):
|
||||
path = stripped[len(PFAD_PREFIX):].strip()
|
||||
return {"had_prefix": True, "path": path}
|
||||
|
||||
return {"had_prefix": False, "path": stripped}
|
||||
|
||||
|
||||
def validate_fact_store_path(raw_path: str) -> Dict[str, Any]:
|
||||
"""Validiere einen FAKT-Speicherort-Pfad.
|
||||
|
||||
@@ -3,7 +3,7 @@ Tests für FAKT-Speicherort-Dialog beim Onboarding (Thema 3).
|
||||
|
||||
Prüft:
|
||||
- room_map.py: fact_store_strategy, fact_store_created_at Felder + Migration
|
||||
- onboarding.py: Pfad-Validierung, 4-Optionen-Dialog
|
||||
- onboarding.py: Pfad-Validierung + F-551 PFAD:-Präfix-Extraktion
|
||||
- doc_store.py: set_base_dir()
|
||||
- adapter_integration.py: strategy-aware Instanziierung
|
||||
"""
|
||||
@@ -284,6 +284,59 @@ class TestFactStorePathValidation:
|
||||
assert result["valid"] is True
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════════
|
||||
# F-551: PFAD:-Präfix-Extraktion (Slash-Command-Blockade umgehen)
|
||||
# ═══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
class TestExtractPathWithPrefix:
|
||||
"""F-551: extract_path_with_prefix — PFAD:-Präfix wird vor Validierung abgestreift."""
|
||||
|
||||
def test_plain_path_no_prefix(self):
|
||||
"""Eingabe ohne Präfix bleibt unverändert (Rückwärtskompatibel)."""
|
||||
from plugin.archivar.onboarding import extract_path_with_prefix
|
||||
result = extract_path_with_prefix("/data/Wissensdatenbank")
|
||||
assert result["had_prefix"] is False
|
||||
assert result["path"] == "/data/Wissensdatenbank"
|
||||
|
||||
def test_prefix_stripped(self):
|
||||
"""'PFAD: /data/Wissensdatenbank' → Pfad ohne Präfix."""
|
||||
from plugin.archivar.onboarding import extract_path_with_prefix
|
||||
result = extract_path_with_prefix("PFAD: /data/Wissensdatenbank")
|
||||
assert result["had_prefix"] is True
|
||||
assert result["path"] == "/data/Wissensdatenbank"
|
||||
|
||||
def test_prefix_no_space_after_colon(self):
|
||||
"""'PFAD:/data/Wissensdatenbank' (ohne Leerzeichen) wird toleriert."""
|
||||
from plugin.archivar.onboarding import extract_path_with_prefix
|
||||
result = extract_path_with_prefix("PFAD:/data/Wissensdatenbank")
|
||||
assert result["had_prefix"] is True
|
||||
assert result["path"] == "/data/Wissensdatenbank"
|
||||
|
||||
def test_prefix_lowercase_insensitive(self):
|
||||
"""'pfad: /data/...' wird case-insensitiv erkannt."""
|
||||
from plugin.archivar.onboarding import extract_path_with_prefix
|
||||
result = extract_path_with_prefix("pfad: /data/Wissensdatenbank")
|
||||
assert result["had_prefix"] is True
|
||||
assert result["path"] == "/data/Wissensdatenbank"
|
||||
|
||||
def test_prefix_then_validate_ok(self):
|
||||
"""Präfix-Eingabe liefert einen Pfad, den validate_fact_store_path akzeptiert."""
|
||||
from plugin.archivar.onboarding import (
|
||||
extract_path_with_prefix,
|
||||
validate_fact_store_path,
|
||||
)
|
||||
extracted = extract_path_with_prefix("PFAD: /tmp/fakt_test")
|
||||
validation = validate_fact_store_path(extracted["path"])
|
||||
assert validation["valid"] is True
|
||||
|
||||
def test_empty_input(self):
|
||||
"""Leere Eingabe liefert had_prefix=False und path unverändert."""
|
||||
from plugin.archivar.onboarding import extract_path_with_prefix
|
||||
result = extract_path_with_prefix("")
|
||||
assert result["had_prefix"] is False
|
||||
assert result["path"] == ""
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════════
|
||||
# doc_store.py: set_base_dir()
|
||||
# ═══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
Reference in New Issue
Block a user