๐Ÿ— KeyzHub
19Keys ยท community archive
12374 bytes raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
from aave_compress.filters import FILLER_PATTERNS, imperative_ize, strip_fillers


def test_removes_hedge_adverbs():
    assert strip_fillers("I really just want the error logs") == (
        "I want the error logs"
    )
    assert strip_fillers("It basically literally works") == "It works"


def test_removes_padding_phrases():
    assert strip_fillers("I want to know if the server is down") == (
        "the server is down"
    )
    assert strip_fillers("I was wondering if the cache expired") == (
        "the cache expired"
    )


def test_politeness_please_stripped_frame_survives():
    # "please" is still stripped by the politeness reduction, but since
    # round 3 the bare "can/could you VERB" frame no longer imperativizes
    # without a mandatory hedge word ("maybe"/"possibly"/"perhaps") โ€” the
    # frame survives, minus the "please".
    assert strip_fillers("Can you please restart the worker?") == (
        "Can you restart the worker?"
    )
    assert strip_fillers("could you please check the logs") == (
        "could you check the logs"
    )


def test_sentence_initial_openers():
    assert strip_fillers("Hey, so the deploy failed again.") == (
        "the deploy failed again."
    )
    assert strip_fillers("Okay so what changed?") == "what changed?"
    # "so far" is content โ€” sentence-initial "so" must survive here
    assert strip_fillers("So far the tests pass") == "So far the tests pass"


def test_discourse_like_only_when_comma_delimited():
    assert strip_fillers("It looks, like, broken") == "It looks, broken"
    # bare "like" is a verb/preposition โ€” never removed
    assert strip_fillers("I like this design") == "I like this design"
    assert strip_fillers("It behaves like a cache miss") == (
        "It behaves like a cache miss"
    )


def test_negations_survive():
    out = strip_fillers("I don't really want that")
    assert "don't" in out
    assert "want that" in out
    assert "really" not in out
    assert out == "I don't want that"


def test_code_backtick_span_untouched():
    text = "Please just run `pip install --just-testing` and honestly report back"
    out = strip_fillers(text)
    assert "`pip install --just-testing`" in out
    assert out == "Please run `pip install --just-testing` and report back"
    fenced = "So basically run this:\n```\nreally = just = 1\n```\nokay?"
    assert "really = just = 1" in strip_fillers(fenced)


def test_content_words_preserved():
    # "kind of" after a wh-word/determiner is content, not hedging
    text = "What kind of database index should I use?"
    assert strip_fillers(text) == text
    # but hedging "kind of" goes
    assert strip_fillers("It kind of works now") == "It works now"
    # question words and technical terms untouched
    text2 = "Why does the WebSocket handshake fail on nginx?"
    assert strip_fillers(text2) == text2


# --- imperative_ize: softened requests -> bare imperatives ---


def test_softened_request_exact_triggering_example():
    # the exact complaint that triggered the imperative pass: after the
    # existing filler rules remove the opener, the leftover "you could
    # maybe" frame must also go, leaving a bare imperative.
    assert strip_fillers(
        "Hey, so I really just want to know if you could maybe look at why "
        "the API is constantly and persistently timing out under load."
    ) == (
        "look at why the API is constantly and persistently timing out "
        "under load."
    )


def test_softened_request_frames_become_imperatives():
    # "could you maybe VERB...?" โ€” question mark becomes a period and the
    # sentence's capital moves onto the verb
    assert strip_fillers("Could you maybe restart the worker?") == (
        "Restart the worker."
    )
    # "would you (maybe|possibly|perhaps) VERB..."
    assert strip_fillers("Would you maybe review the PR today?") == (
        "Review the PR today."
    )
    # "can you (maybe|possibly|perhaps) VERB..."
    assert strip_fillers("Can you possibly deploy the fix tonight?") == (
        "Deploy the fix tonight."
    )
    # "is there any way you could VERB..." โ€” hedge still OPTIONAL here
    assert strip_fillers("Is there any way you could bump the rate limit?") == (
        "Bump the rate limit."
    )
    # "you might want to VERB..." โ€” hedge still OPTIONAL here
    assert strip_fillers("You might want to clear the cache first.") == (
        "Clear the cache first."
    )


def test_bare_modal_frames_require_hedge():
    # ROUND 3: without a hedge word ("maybe"/"possibly"/"perhaps") the
    # bare-modal frames never fire โ€” plain requests staying untouched is
    # an accepted, intentional false-negative cost of never inverting
    # warnings and rhetorical questions.
    for text in [
        "you could look at the logs",
        "Can you check the logs?",
        "Could you restart the worker?",
        "Would you review the PR today?",
    ]:
        assert imperative_ize(text) == text
        assert strip_fillers(text) == text
    # ...while the hedged versions still convert
    assert imperative_ize("you could maybe look at the logs") == (
        "look at the logs"
    )
    assert strip_fillers("you could maybe look at the logs") == (
        "look at the logs"
    )
    assert strip_fillers("Could you perhaps restart the worker?") == (
        "Restart the worker."
    )
    # "just" satisfies the requirement for "can you" ONLY. (Tested through
    # imperative_ize directly: strip_fillers removes "just" as a filler
    # adverb before the imperative pass ever sees it.)
    assert imperative_ize("Can you just check the logs?") == "Check the logs."
    assert imperative_ize("Could you just check the logs?") == (
        "Could you just check the logs?"
    )


def test_softened_request_after_comma_keeps_case():
    # question-order frames also fire clause-initially after a comma; the
    # rest of the sentence keeps its original case
    assert strip_fillers("The build is green, can you maybe ship it?") == (
        "The build is green, ship it."
    )


def test_capability_assessment_never_fires():
    # "you could be right" is an assessment, not a request โ€” even though
    # "be" looks like a bare verb it must survive untouched
    assert strip_fillers("You could be right.") == "You could be right."
    assert imperative_ize("you could be right") == "you could be right"


def test_warning_you_could_never_fires():
    # "you could VERB" is ALSO the standard English WARNING construction โ€”
    # imperativizing it would invert the meaning into an instruction to
    # cause the harm. Negative-outcome verbs, conditional tails ("if ..."),
    # and trailing consequence idioms ("over this", "for that") must all
    # leave the sentence completely untouched, frame and all.
    warnings = [
        "You could break prod if you deploy without testing.",
        "You could lose your job over this.",
        "You could get in trouble for that.",
        "You could regret this later.",
        "You could screw this up if you rush it.",
    ]
    for text in warnings:
        assert strip_fillers(text) == text
        assert imperative_ize(text) == text


def test_rhetorical_guilt_questions_never_fire():
    # Round-2 adversarial finds: rhetorical/guilt questions with no
    # conditional tail and the harm verb buried one clause deeper than the
    # denylist inspects ("afford to LOSE"). Fixed structurally: the
    # bare-modal frames now require a hedge word, and the "would you be
    # able to" / "do you think you could" frames were removed outright.
    rhetorical = [
        "Can you afford to lose this account?",
        "Could you live with yourself after that?",
        "Would you be able to sleep at night after that?",
        "Would you be able to live with the fallout?",
        "Would you be able to forgive yourself?",
        "Do you think you could handle the consequences?",
        "Do you think you could live with the consequences?",
    ]
    for text in rhetorical:
        assert imperative_ize(text) == text
        assert strip_fillers(text) == text


def test_hypothetical_if_you_could_never_fires():
    # the "if you could" frame is REMOVED (round 2): hypothetical-musing
    # questions imperativized into grammatically broken fragments
    # ("Go back in time, what would you change.").
    text = "If you could go back in time, what would you change?"
    assert imperative_ize(text) == text
    assert strip_fillers(text) == text
    # the old positive case for this frame is now an accepted false
    # negative โ€” it stays untouched instead of converting
    text2 = "If you could rotate the key, that would help."
    assert imperative_ize(text2) == text2
    assert strip_fillers(text2) == text2


def test_could_use_idiom_never_fires():
    # "you could use some sleep" = "you need/deserve sleep", not a request.
    # The whole could+use pattern is blocked in both word orders instead of
    # trying to disambiguate it from the task-suggestion sense.
    text = "You could use some more sleep."
    assert strip_fillers(text) == text
    assert imperative_ize(text) == text
    # "honestly" is a filler adverb and is (correctly) stripped by the
    # filler pass โ€” but the "You could use" frame itself must survive
    # unconverted (never "Use a raise").
    idiom = "You could use a raise, honestly."
    assert imperative_ize(idiom) == idiom
    assert strip_fillers(idiom) == "You could use a raise."


def test_non_verb_after_frame_never_fires():
    # "rather" is not an action verb โ€” a real question, not a request
    text = "Would you rather use tabs or spaces?"
    assert strip_fillers(text) == text


def test_hedged_capacity_questions_never_fire():
    # Round-4 finding: requiring a hedge word (round 3) does not close the
    # gap on its own โ€” inserting "maybe" into a rhetorical capacity/guilt
    # question still reads as valid-ish English and the frame still fired,
    # inverting meaning ("Afford to lose this account.", "Live with
    # yourself after that."). Fixed with two guards: a capacity-verb
    # denylist (afford/handle/manage/cope/stand/bear/stomach/survive/
    # live/dare) for the checked word itself, plus a scan of the whole
    # rest of the clause for any _WARNING_VERB_BLOCK word โ€” so the harm
    # verb is caught even when it sits one infinitival clause past the
    # word the frame first matches.
    hedged_rhetorical = [
        "Can you maybe afford to lose this account?",
        "Could you maybe live with yourself after that?",
        "Can you maybe afford to screw this up?",
        "Could you maybe handle losing the account?",
        "Could you maybe cope with failing this audit?",
        "Can you maybe manage without the extra headcount?",
    ]
    for text in hedged_rhetorical:
        assert imperative_ize(text) == text, text
        assert strip_fillers(text) == text, text


def test_must_still_work_case_survives_round4_guards():
    # The original feature request must still work after all four rounds
    # of guards โ€” none of the round-4 additions should touch it (the verb
    # is "look", not in any denylist, and the rest of the clause contains
    # no warning-block word).
    text = (
        "Hey, so I really just want to know if you could maybe look at "
        "why the API is constantly and persistently timing out under load."
    )
    assert (
        strip_fillers(text)
        == "look at why the API is constantly and persistently timing out under load."
    )


def test_imperative_code_span_protected():
    # a frame INSIDE a backtick span must pass through byte-for-byte
    fenced = "Paste this reply:\n```\ncould you check the logs\n```\ndone"
    assert "could you check the logs" in strip_fillers(fenced)
    inline = "Reply with `can you hold on` verbatim"
    assert strip_fillers(inline) == inline
    # ...while a hedged frame OUTSIDE the span still converts
    out = strip_fillers("Could you maybe run `pytest -q` for me")
    assert out == "Run `pytest -q` for me"


def test_filler_patterns_table_is_auditable():
    # every entry is (compiled regex, str-or-callable replacement)
    assert FILLER_PATTERNS
    for pattern, replacement in FILLER_PATTERNS:
        assert hasattr(pattern, "sub")
        assert isinstance(replacement, str) or callable(replacement)