tuitbot-core 0.1.47

Core library for Tuitbot autonomous X growth assistant
Documentation
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
//! Additional edge case tests for classification, scoring, and helper functions.
//! All deterministic — no DB required.

use crate::context::winning_dna::analysis::{
    classify_for_row, classify_reply_archetype, classify_tweet_format, compute_days_since,
    truncate_at_char_boundary,
};
use crate::context::winning_dna::scoring::{compute_engagement_score, compute_retrieval_weight};

// ============================================================================
// classify_reply_archetype edge cases
// ============================================================================

#[test]
fn classify_reply_why_question() {
    assert_eq!(
        classify_reply_archetype("Why do you think this approach works?"),
        "ask_question"
    );
}

#[test]
fn classify_reply_have_you_question() {
    assert_eq!(
        classify_reply_archetype("Have you tried using this pattern?"),
        "ask_question"
    );
}

#[test]
fn classify_reply_do_you_question() {
    assert_eq!(
        classify_reply_archetype("Do you think this scales well?"),
        "ask_question"
    );
}

#[test]
fn classify_reply_ends_with_question_mark() {
    assert_eq!(
        classify_reply_archetype("Is this the right approach to use here?"),
        "ask_question"
    );
}

#[test]
fn classify_reply_i_recently_experience() {
    assert_eq!(
        classify_reply_archetype("I recently deployed this in production and it worked"),
        "share_experience"
    );
}

#[test]
fn classify_reply_when_i_was_experience() {
    assert_eq!(
        classify_reply_archetype("When I was building my last project, this helped a lot"),
        "share_experience"
    );
}

#[test]
fn classify_reply_ive_experienced() {
    assert_eq!(
        classify_reply_archetype("I've experienced the same issue with my deployments"),
        "share_experience"
    );
}

#[test]
fn classify_reply_ive_found() {
    assert_eq!(
        classify_reply_archetype("I've found that testing early prevents most regressions"),
        "share_experience"
    );
}

#[test]
fn classify_reply_data_shows() {
    assert_eq!(
        classify_reply_archetype("Data shows that teams shipping daily have fewer bugs"),
        "add_data"
    );
}

#[test]
fn classify_reply_stats_show() {
    assert_eq!(
        classify_reply_archetype("Stats show a 40% improvement in deployment frequency"),
        "add_data"
    );
}

#[test]
fn classify_reply_study_shows() {
    assert_eq!(
        classify_reply_archetype("A recent study shows that TDD improves code quality"),
        "add_data"
    );
}

#[test]
fn classify_reply_percent_of() {
    assert_eq!(
        classify_reply_archetype("About 73% of teams use some form of CI now"),
        "add_data"
    );
}

#[test]
fn classify_reply_actually_i_think_disagree() {
    assert_eq!(
        classify_reply_archetype("Actually, I think there are better alternatives"),
        "respectful_disagree"
    );
}

#[test]
fn classify_reply_but_not_sure_disagree() {
    assert_eq!(
        classify_reply_archetype("But I'm not sure that holds in all cases"),
        "respectful_disagree"
    );
}

#[test]
fn classify_reply_however_id_argue() {
    assert_eq!(
        classify_reply_archetype("However, I'd argue that simplicity wins here"),
        "respectful_disagree"
    );
}

#[test]
fn classify_reply_empty_string_defaults() {
    assert_eq!(classify_reply_archetype(""), "agree_and_expand");
}

#[test]
fn classify_reply_generic_agreement() {
    assert_eq!(
        classify_reply_archetype("Great point, I think that applies to many teams"),
        "agree_and_expand"
    );
}

#[test]
fn classify_reply_case_insensitive_question() {
    assert_eq!(
        classify_reply_archetype("WHAT tools do you use for deployment?"),
        "ask_question"
    );
}

#[test]
fn classify_reply_case_insensitive_experience() {
    assert_eq!(
        classify_reply_archetype("IN MY EXPERIENCE, this approach works well"),
        "share_experience"
    );
}

// ============================================================================
// classify_tweet_format edge cases
// ============================================================================

#[test]
fn classify_tweet_everyone_says_pattern() {
    assert_eq!(
        classify_tweet_format("Everyone says you need a degree. They're wrong."),
        "most_people_think_x"
    );
}

#[test]
fn classify_tweet_contrarian_actually_but() {
    assert_eq!(
        classify_tweet_format("Actually, the common wisdom is wrong but there's a better way"),
        "contrarian_take"
    );
}

#[test]
fn classify_tweet_before_after() {
    assert_eq!(
        classify_tweet_format("Before: 200ms response time. After: 20ms."),
        "before_after"
    );
}

#[test]
fn classify_tweet_before_arrow() {
    assert_eq!(
        classify_tweet_format("Before → After transformation in our pipeline"),
        "before_after"
    );
}

#[test]
fn classify_tweet_tip_short() {
    assert_eq!(
        classify_tweet_format("Tip: always validate input before processing"),
        "tip"
    );
}

#[test]
fn classify_tweet_pro_tip_with_arrow() {
    assert_eq!(
        classify_tweet_format("Pro tip: use → for chaining operations"),
        "tip"
    );
}

#[test]
fn classify_tweet_tip_too_long_defaults() {
    let long_tip = format!("Tip: {}", "a".repeat(200));
    assert_eq!(classify_tweet_format(&long_tip), "storytelling");
}

#[test]
fn classify_tweet_empty_string() {
    assert_eq!(classify_tweet_format(""), "storytelling");
}

#[test]
fn classify_tweet_numbered_list_with_three_items() {
    assert_eq!(
        classify_tweet_format("1. Write tests 2. Run CI 3. Deploy"),
        "list"
    );
}

// ============================================================================
// compute_engagement_score edge cases
// ============================================================================

#[test]
fn engagement_score_mid_range() {
    let score = compute_engagement_score(25.0, 100.0);
    assert!((score - 0.25).abs() < 0.001);
    assert!(score >= 0.0);
    assert!(score <= 1.0);
}

#[test]
fn engagement_score_very_small_max() {
    let score = compute_engagement_score(0.001, 0.001);
    assert!((score - 1.0).abs() < 0.001);
}

#[test]
fn engagement_score_zero_performance() {
    let score = compute_engagement_score(0.0, 50.0);
    assert!((score - 0.0).abs() < 0.001);
}

#[test]
fn engagement_score_negative_performance() {
    let score = compute_engagement_score(-10.0, 100.0);
    assert!((score - 0.0).abs() < 0.001);
}

// ============================================================================
// compute_retrieval_weight edge cases
// ============================================================================

#[test]
fn retrieval_weight_two_half_lives() {
    let w = compute_retrieval_weight(1.0, 28.0, 14.0);
    assert!((w - 0.25).abs() < 0.05, "got {w}");
}

#[test]
fn retrieval_weight_three_half_lives() {
    let w = compute_retrieval_weight(1.0, 42.0, 14.0);
    assert!((w - 0.125).abs() < 0.05, "got {w}");
}

#[test]
fn retrieval_weight_with_partial_engagement() {
    let w = compute_retrieval_weight(0.5, 14.0, 14.0);
    assert!((w - 0.25).abs() < 0.05, "got {w}");
}

#[test]
fn retrieval_weight_zero_engagement() {
    let w = compute_retrieval_weight(0.0, 14.0, 14.0);
    assert!((w - 0.0).abs() < 0.001);
}

#[test]
fn retrieval_weight_negative_days() {
    let w = compute_retrieval_weight(1.0, -5.0, 14.0);
    assert!(w > 1.0, "negative days should increase weight: got {w}");
}

#[test]
fn retrieval_weight_very_large_days() {
    let w = compute_retrieval_weight(1.0, 365.0, 14.0);
    assert!(
        w < 0.001,
        "very old content should have near-zero weight: got {w}"
    );
}

#[test]
fn retrieval_weight_very_small_half_life() {
    let w = compute_retrieval_weight(1.0, 1.0, 0.001);
    assert!(w < 0.001, "tiny half-life should decay quickly: got {w}");
}

// ============================================================================
// compute_days_since edge cases
// ============================================================================

#[test]
fn compute_days_since_iso_z_format() {
    let now = chrono::Utc::now();
    let one_week_ago = now - chrono::Duration::days(7);
    let posted = one_week_ago.format("%Y-%m-%dT%H:%M:%SZ").to_string();
    let days = compute_days_since(&posted, &now);
    assert!((days - 7.0).abs() < 0.2, "should be ~7 days, got {days}");
}

#[test]
fn compute_days_since_rfc3339_with_offset() {
    let now = chrono::Utc::now();
    let posted = (now - chrono::Duration::hours(48)).to_rfc3339();
    let days = compute_days_since(&posted, &now);
    assert!((days - 2.0).abs() < 0.1, "should be ~2 days, got {days}");
}

#[test]
fn compute_days_since_future_date() {
    let now = chrono::Utc::now();
    let future = (now + chrono::Duration::hours(24)).to_rfc3339();
    let days = compute_days_since(&future, &now);
    assert!(
        days < 0.0,
        "future date should give negative days: got {days}"
    );
}

#[test]
fn compute_days_since_empty_string() {
    let now = chrono::Utc::now();
    let days = compute_days_since("", &now);
    assert!(
        (days - 30.0).abs() < 0.1,
        "empty string should default to 30 days"
    );
}

#[test]
fn compute_days_since_partial_date() {
    let now = chrono::Utc::now();
    let days = compute_days_since("2026-01-01", &now);
    assert!(
        (days - 30.0).abs() < 0.1,
        "unparseable partial date should default to 30"
    );
}

// ============================================================================
// classify_for_row edge cases
// ============================================================================

#[test]
fn classify_for_row_reply_experience() {
    assert_eq!(
        classify_for_row("reply", "I've found this to be true in practice"),
        "share_experience"
    );
}

#[test]
fn classify_for_row_tweet_list() {
    assert_eq!(
        classify_for_row("tweet", "1. First item 2. Second item"),
        "list"
    );
}

#[test]
fn classify_for_row_empty_type() {
    let result = classify_for_row("", "Some content here");
    assert_eq!(result, "storytelling");
}

// ============================================================================
// truncate_at_char_boundary edge cases
// ============================================================================

#[test]
fn truncate_at_char_boundary_empty_string() {
    assert_eq!(truncate_at_char_boundary("", 10), "");
}

#[test]
fn truncate_at_char_boundary_zero_max() {
    assert_eq!(truncate_at_char_boundary("hello", 0), "");
}

#[test]
fn truncate_at_char_boundary_multibyte_char() {
    let s = "hello \u{1F600} world";
    let result = truncate_at_char_boundary(s, 7);
    assert!(result.len() <= 7);
    assert!(result.is_char_boundary(result.len()));
}

#[test]
fn truncate_at_char_boundary_unicode() {
    let s = "\u{00E9}\u{00E9}\u{00E9}\u{00E9}\u{00E9}";
    let result = truncate_at_char_boundary(s, 4);
    assert!(result.len() <= 4);
    assert!(result.is_char_boundary(result.len()));
}