mooncak397 Claude Opus 5.5 commited on
Commit
295c71d
·
1 Parent(s): 6b6ccde

entry: strip invisible characters (zero-width, BOM, word joiner, Hangul filler, NUL); invisible-only input is EMPTY (B4)

Browse files
Files changed (2) hide show
  1. app/graph.py +2 -1
  2. tests/test_graph.py +6 -0
app/graph.py CHANGED
@@ -16,6 +16,7 @@ from app.texts import BUSY, EMPTY, FORM_INTRO, OFF_TOPIC, TOO_LONG
16
 
17
  log = logging.getLogger(__name__)
18
  MAX_CHARS = 1000
 
19
 
20
  CLASSIFY_PROMPT = """Classify the user's latest message for an assistant that answers questions about a job candidate.
21
  route:
@@ -95,7 +96,7 @@ def build_graph(model):
95
  return None, (BUSY if busy else idk)[lang]
96
 
97
  def entry(state: State):
98
- text = state["messages"][-1].text.strip()
99
  lang = _guess_lang(text, state.get("lang") or "en") # no model call to detect it
100
  out = {"route": "entry", "lang": lang, "show_form": False, "tool_calls": [], "reply": "", "fixed": False}
101
  if not text:
 
16
 
17
  log = logging.getLogger(__name__)
18
  MAX_CHARS = 1000
19
+ INVISIBLE = re.compile("[\u200b-\u200d\u2060\ufeff\u3164\x00]") # zero-width, word joiner, BOM, Hangul filler, NUL
20
 
21
  CLASSIFY_PROMPT = """Classify the user's latest message for an assistant that answers questions about a job candidate.
22
  route:
 
96
  return None, (BUSY if busy else idk)[lang]
97
 
98
  def entry(state: State):
99
+ text = INVISIBLE.sub("", state["messages"][-1].text).strip() # invisible-only input counts as empty
100
  lang = _guess_lang(text, state.get("lang") or "en") # no model call to detect it
101
  out = {"route": "entry", "lang": lang, "show_form": False, "tool_calls": [], "reply": "", "fixed": False}
102
  if not text:
tests/test_graph.py CHANGED
@@ -119,6 +119,12 @@ def test_entry_fixed_texts_cost_no_call(q, lang, text):
119
  assert m.calls == []
120
 
121
 
 
 
 
 
 
 
122
  def test_too_long_uses_the_language_of_the_text():
123
  de = "Bitte sagen Sie mir, was er bei der DATEV macht und wie das Team arbeitet. " * 20
124
  assert answer(FakeModel(), de) == TOO_LONG["de"]
 
119
  assert m.calls == []
120
 
121
 
122
+ @pytest.mark.parametrize("q", ["\u200b", "\ufeff", "\u2060\u2060", "\u200b \u200b", "\x00", "\xa0\t\n", "\u3164", "\u200d"])
123
+ def test_invisible_only_input_is_empty(q):
124
+ m = FakeModel()
125
+ assert answer(m, q) == EMPTY["en"] and m.calls == []
126
+
127
+
128
  def test_too_long_uses_the_language_of_the_text():
129
  de = "Bitte sagen Sie mir, was er bei der DATEV macht und wie das Team arbeitet. " * 20
130
  assert answer(FakeModel(), de) == TOO_LONG["de"]