tldr-core 0.4.0

Core analysis engine for TLDR code analysis tool
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
//! field_access_info-extension-v1 — M1 RED integration tests for
//! Ruby/Elixir/OCaml `Module.function(...)` taint shapes.
//!
//! Each Module.function test runs through TWO dispatch paths:
//!
//! 1. `analyze_with_ssa(...)` (regular) — exercises both AST and regex banks.
//!    PASSES at HEAD pre-M2/M3/M4 because the regex banks
//!    (`RUBY_PATTERNS`/`ELIXIR_PATTERNS`/`OCAML_PATTERNS`) still catch the
//!    Module.function shape via substring patterns. This is the additive
//!    coverage proof that the rewrite does not regress today's behavior.
//!
//! 2. `analyze_ast_only(...)` (AST-only) — activates an
//!    `AstOnlyTestModeGuard` (defined in
//!    `tldr_core::security::taint`) that transiently empties the regex
//!    `.sources` / `.sinks` banks for the duration of the call. This isolates
//!    the AST detection path. FAILS at HEAD pre-M2/M3/M4 because the
//!    `RUBY_AST_*` / `ELIXIR_AST_*` / `OCAML_AST_*` retain entries for these
//!    shapes use the raw-substring `("", "Module.fn")` form which is skipped
//!    by both the structural (`field_access_info`) and the W2-pre call-shape
//!    paths in `member_patterns_match` (`taint.rs:2989-3009`).
//!
//! This dual-path setup is the gating RED for M2/M3/M4: when each language's
//! structured-shape rewrite (`("Module", "fn")`) lands in
//! `RUBY_AST_*`/`ELIXIR_AST_*`/`OCAML_AST_*`, the corresponding fixtures
//! transition FAIL→PASS under `analyze_ast_only`. After M5 deletes the regex
//! banks, the regular `analyze_with_ssa` path collapses to the same behavior
//! as `analyze_ast_only`.
//!
//! The 3 string-literal regression-guard tests (`*_string_literal_*_zero_findings`)
//! must PASS on BOTH paths — they assert that fixtures where `IO.popen` /
//! `System.cmd` / `Sys.command` appear ONLY inside string-literal text never
//! trigger a finding. They are the closes-#24 generalization to Ruby/Elixir/
//! OCaml and must stay GREEN through M5.
//!
//! Test count: 6 Ruby Module.function + 7 Elixir Module.function + 5 OCaml
//! Module.function (1 of which uses the bare-call `read_line` source path,
//! not a Module.function rewrite) + 3 string-literal regression guards = 21
//! tests in this file. Per-language baseline augmentation (3 tests) is in
//! `rr_baseline_per_language_test.rs`.

use tldr_core::{Language, TaintInfo, TaintSinkType, TaintSourceType};

#[path = "common/integ_helpers.rs"]
mod common;

use common::{analyze_ast_only, analyze_with_ssa};

// ---------------------------------------------------------------------------
// Local helpers — small, file-private. These mirror the assertion shape used
// by `rr_baseline_per_language_test.rs` (filter sinks by type, assert
// non-empty), with `result` / `path` arguments so callers can pass either
// `analyze` or `analyze_ast_only` outputs through the same predicate.
// ---------------------------------------------------------------------------

fn assert_has_source_of_type(result: &TaintInfo, expected: TaintSourceType, path: &str) {
    let lines: Vec<u32> = result
        .sources
        .iter()
        .filter(|s| s.source_type == expected)
        .map(|s| s.line)
        .collect();
    assert!(
        !lines.is_empty(),
        "[{path}] expected at least one {:?} source; got sources={:?}",
        expected,
        result.sources
    );
}

fn assert_has_sink_of_type(result: &TaintInfo, expected: TaintSinkType, path: &str) {
    let lines: Vec<u32> = result
        .sinks
        .iter()
        .filter(|s| s.sink_type == expected)
        .map(|s| s.line)
        .collect();
    assert!(
        !lines.is_empty(),
        "[{path}] expected at least one {:?} sink; got sinks={:?}",
        expected,
        result.sinks
    );
}

fn assert_has_source_or_sink(result: &TaintInfo, source: TaintSourceType, sink: TaintSinkType, path: &str) {
    assert_has_source_of_type(result, source, path);
    assert_has_sink_of_type(result, sink, path);
}

// ===========================================================================
// Ruby (6 Module.function fixtures)
// ===========================================================================

/// Ruby: `cmd = STDIN.read; eval(cmd)` — Stdin source via `STDIN.read` Module
/// call -> CodeEval sink via bare `eval`. The `eval` sink is detected via
/// `RUBY_AST_SINKS` `call_names: ["eval"]` (already AST-native), so the
/// AST-only failure point is purely the `STDIN.read` source side.
#[test]
fn ruby_stdin_read_to_eval_via_compute_taint() {
    let src = "\
def handler
    cmd = STDIN.read
    eval(cmd)
end
";
    // (a) regular path: PASSES at HEAD via regex bank
    let regular = analyze_with_ssa(src, Language::Ruby, "handler", /* use_ssa */ false);
    assert_has_source_or_sink(&regular, TaintSourceType::Stdin, TaintSinkType::CodeEval, "regular");
    // (b) AST-only path: FAILS at HEAD pre-M2 (RED gate; M2 turns GREEN)
    let ast_only = analyze_ast_only(src, Language::Ruby, "handler");
    assert_has_source_of_type(&ast_only, TaintSourceType::Stdin, "ast_only");
    assert_has_sink_of_type(&ast_only, TaintSinkType::CodeEval, "ast_only");
}

/// Ruby: `cmd = STDIN.gets; system(cmd)` — Stdin source via `STDIN.gets`
/// Module call -> ShellExec sink via bare `system` call.
#[test]
fn ruby_stdin_gets_to_system_via_compute_taint() {
    let src = "\
def handler
    cmd = STDIN.gets
    system(cmd)
end
";
    let regular = analyze_with_ssa(src, Language::Ruby, "handler", false);
    assert_has_source_of_type(&regular, TaintSourceType::Stdin, "regular");
    assert_has_sink_of_type(&regular, TaintSinkType::ShellExec, "regular");
    let ast_only = analyze_ast_only(src, Language::Ruby, "handler");
    assert_has_source_of_type(&ast_only, TaintSourceType::Stdin, "ast_only");
    assert_has_sink_of_type(&ast_only, TaintSinkType::ShellExec, "ast_only");
}

/// Ruby: `cmd = STDIN.readline; IO.popen(cmd)` — Stdin source via
/// `STDIN.readline` Module call -> ShellExec sink via `IO.popen` Module
/// call. BOTH sides require structured Module.function matching — both fail
/// under AST-only at HEAD.
#[test]
fn ruby_stdin_readline_to_io_popen_via_compute_taint() {
    let src = "\
def handler
    cmd = STDIN.readline
    IO.popen(cmd)
end
";
    let regular = analyze_with_ssa(src, Language::Ruby, "handler", false);
    assert_has_source_of_type(&regular, TaintSourceType::Stdin, "regular");
    assert_has_sink_of_type(&regular, TaintSinkType::ShellExec, "regular");
    let ast_only = analyze_ast_only(src, Language::Ruby, "handler");
    assert_has_source_of_type(&ast_only, TaintSourceType::Stdin, "ast_only");
    assert_has_sink_of_type(&ast_only, TaintSinkType::ShellExec, "ast_only");
}

/// Ruby: `cmd = File.read("path"); eval(cmd)` — FileRead source via
/// `File.read` Module call -> CodeEval sink via bare `eval`.
#[test]
fn ruby_file_read_to_eval_via_compute_taint() {
    let src = "\
def handler
    cmd = File.read(\"path\")
    eval(cmd)
end
";
    let regular = analyze_with_ssa(src, Language::Ruby, "handler", false);
    assert_has_source_of_type(&regular, TaintSourceType::FileRead, "regular");
    assert_has_sink_of_type(&regular, TaintSinkType::CodeEval, "regular");
    let ast_only = analyze_ast_only(src, Language::Ruby, "handler");
    assert_has_source_of_type(&ast_only, TaintSourceType::FileRead, "ast_only");
    assert_has_sink_of_type(&ast_only, TaintSinkType::CodeEval, "ast_only");
}

/// Ruby: `cmd = File.open("path"); system(cmd)` — FileRead source via
/// `File.open` Module call -> ShellExec sink via bare `system`.
#[test]
fn ruby_file_open_to_system_via_compute_taint() {
    let src = "\
def handler
    cmd = File.open(\"path\")
    system(cmd)
end
";
    let regular = analyze_with_ssa(src, Language::Ruby, "handler", false);
    assert_has_source_of_type(&regular, TaintSourceType::FileRead, "regular");
    assert_has_sink_of_type(&regular, TaintSinkType::ShellExec, "regular");
    let ast_only = analyze_ast_only(src, Language::Ruby, "handler");
    assert_has_source_of_type(&ast_only, TaintSourceType::FileRead, "ast_only");
    assert_has_sink_of_type(&ast_only, TaintSinkType::ShellExec, "ast_only");
}

/// Ruby: bare `gets` (UserInput, AST-native via `call_names: ["gets"]`) ->
/// `IO.popen(cmd)` ShellExec sink. The sink side requires structured
/// Module.function matching — fails under AST-only at HEAD pre-M2.
#[test]
fn ruby_io_popen_with_user_input_via_compute_taint() {
    let src = "\
def handler
    cmd = gets
    IO.popen(cmd)
end
";
    let regular = analyze_with_ssa(src, Language::Ruby, "handler", false);
    assert_has_source_of_type(&regular, TaintSourceType::UserInput, "regular");
    assert_has_sink_of_type(&regular, TaintSinkType::ShellExec, "regular");
    let ast_only = analyze_ast_only(src, Language::Ruby, "handler");
    // Source side already AST-native; the failure point at HEAD is the sink.
    assert_has_source_of_type(&ast_only, TaintSourceType::UserInput, "ast_only");
    assert_has_sink_of_type(&ast_only, TaintSinkType::ShellExec, "ast_only");
}

// ===========================================================================
// Elixir (7 Module.function fixtures)
// ===========================================================================

/// Elixir: `cmd = IO.gets("> "); System.cmd(cmd, [])` — UserInput via
/// `IO.gets` Module call -> ShellExec via `System.cmd` Module call. Both
/// sides require structured Module.function matching.
#[test]
fn elixir_io_gets_to_system_cmd_via_compute_taint() {
    let src = "\
def handler do
  cmd = IO.gets(\"> \")
  System.cmd(cmd, [])
end
";
    let regular = analyze_with_ssa(src, Language::Elixir, "handler", false);
    assert_has_source_of_type(&regular, TaintSourceType::UserInput, "regular");
    assert_has_sink_of_type(&regular, TaintSinkType::ShellExec, "regular");
    let ast_only = analyze_ast_only(src, Language::Elixir, "handler");
    assert_has_source_of_type(&ast_only, TaintSourceType::UserInput, "ast_only");
    assert_has_sink_of_type(&ast_only, TaintSinkType::ShellExec, "ast_only");
}

/// Elixir: `name = System.get_env("X"); Code.eval_string(name)` — EnvVar
/// via `System.get_env` -> CodeEval via `Code.eval_string`.
#[test]
fn elixir_system_get_env_to_code_eval_via_compute_taint() {
    let src = "\
def handler do
  name = System.get_env(\"X\")
  Code.eval_string(name)
end
";
    let regular = analyze_with_ssa(src, Language::Elixir, "handler", false);
    assert_has_source_of_type(&regular, TaintSourceType::EnvVar, "regular");
    assert_has_sink_of_type(&regular, TaintSinkType::CodeEval, "regular");
    let ast_only = analyze_ast_only(src, Language::Elixir, "handler");
    assert_has_source_of_type(&ast_only, TaintSourceType::EnvVar, "ast_only");
    assert_has_sink_of_type(&ast_only, TaintSinkType::CodeEval, "ast_only");
}

/// Elixir: `cmd = File.read("path"); System.cmd(cmd, [])` — FileRead via
/// `File.read` -> ShellExec via `System.cmd`.
#[test]
fn elixir_file_read_to_system_cmd_via_compute_taint() {
    let src = "\
def handler do
  cmd = File.read(\"path\")
  System.cmd(cmd, [])
end
";
    let regular = analyze_with_ssa(src, Language::Elixir, "handler", false);
    assert_has_source_of_type(&regular, TaintSourceType::FileRead, "regular");
    assert_has_sink_of_type(&regular, TaintSinkType::ShellExec, "regular");
    let ast_only = analyze_ast_only(src, Language::Elixir, "handler");
    assert_has_source_of_type(&ast_only, TaintSourceType::FileRead, "ast_only");
    assert_has_sink_of_type(&ast_only, TaintSinkType::ShellExec, "ast_only");
}

/// Elixir: `cmd = File.read!("path"); System.cmd(cmd, [])` — FileRead via
/// `File.read!` (bang-suffix variant; tree-sitter-elixir parses `read!` as a
/// single identifier node) -> ShellExec via `System.cmd`.
#[test]
fn elixir_file_read_bang_to_system_cmd_via_compute_taint() {
    let src = "\
def handler do
  cmd = File.read!(\"path\")
  System.cmd(cmd, [])
end
";
    let regular = analyze_with_ssa(src, Language::Elixir, "handler", false);
    assert_has_source_of_type(&regular, TaintSourceType::FileRead, "regular");
    assert_has_sink_of_type(&regular, TaintSinkType::ShellExec, "regular");
    let ast_only = analyze_ast_only(src, Language::Elixir, "handler");
    assert_has_source_of_type(&ast_only, TaintSourceType::FileRead, "ast_only");
    assert_has_sink_of_type(&ast_only, TaintSinkType::ShellExec, "ast_only");
}

/// Elixir: `cmd = IO.gets("> "); Code.eval_string(cmd)` — UserInput via
/// `IO.gets` -> CodeEval via `Code.eval_string`.
#[test]
fn elixir_user_input_to_code_eval_string_via_compute_taint() {
    let src = "\
def handler do
  cmd = IO.gets(\"> \")
  Code.eval_string(cmd)
end
";
    let regular = analyze_with_ssa(src, Language::Elixir, "handler", false);
    assert_has_source_of_type(&regular, TaintSourceType::UserInput, "regular");
    assert_has_sink_of_type(&regular, TaintSinkType::CodeEval, "regular");
    let ast_only = analyze_ast_only(src, Language::Elixir, "handler");
    assert_has_source_of_type(&ast_only, TaintSourceType::UserInput, "ast_only");
    assert_has_sink_of_type(&ast_only, TaintSinkType::CodeEval, "ast_only");
}

/// Elixir: `cmd = IO.gets("> "); Ecto.Adapters.SQL.query(repo, cmd, [])`
/// — UserInput via `IO.gets` -> SqlQuery via `Ecto.Adapters.SQL.query`
/// (multi-segment dotted receiver). Verifies that the W2-pre call-shape
/// `rfind('.')` split correctly produces `("Ecto.Adapters.SQL", "query")`.
#[test]
fn elixir_user_input_to_ecto_sql_query_via_compute_taint() {
    let src = "\
def handler(repo) do
  cmd = IO.gets(\"> \")
  Ecto.Adapters.SQL.query(repo, cmd, [])
end
";
    let regular = analyze_with_ssa(src, Language::Elixir, "handler", false);
    assert_has_source_of_type(&regular, TaintSourceType::UserInput, "regular");
    assert_has_sink_of_type(&regular, TaintSinkType::SqlQuery, "regular");
    let ast_only = analyze_ast_only(src, Language::Elixir, "handler");
    assert_has_source_of_type(&ast_only, TaintSourceType::UserInput, "ast_only");
    assert_has_sink_of_type(&ast_only, TaintSinkType::SqlQuery, "ast_only");
}

/// Elixir: `IO.gets("> ") |> System.cmd([])` — pipe operator desugars at
/// parse time to `System.cmd(IO.gets("> "), [])`. tree-sitter-elixir
/// represents the pipe as a `binary_operator` whose right side is a `call`,
/// so `walk_descendants` still visits the inner `System.cmd` call. Verifies
/// the pipe doesn't break detection.
#[test]
fn elixir_pipe_operator_io_gets_to_system_cmd_via_compute_taint() {
    let src = "\
def handler do
  IO.gets(\"> \") |> System.cmd([])
end
";
    let regular = analyze_with_ssa(src, Language::Elixir, "handler", false);
    assert_has_source_of_type(&regular, TaintSourceType::UserInput, "regular");
    assert_has_sink_of_type(&regular, TaintSinkType::ShellExec, "regular");
    let ast_only = analyze_ast_only(src, Language::Elixir, "handler");
    assert_has_source_of_type(&ast_only, TaintSourceType::UserInput, "ast_only");
    assert_has_sink_of_type(&ast_only, TaintSinkType::ShellExec, "ast_only");
}

// ===========================================================================
// OCaml (5 fixtures: 4 Module.function + 1 bare-call)
// ===========================================================================

/// OCaml: `let cmd = Sys.getenv "CMD" in Sys.command cmd` — EnvVar via
/// `Sys.getenv` Module call -> ShellExec via `Sys.command` Module call.
/// Both sides require structured matching.
#[test]
fn ocaml_sys_getenv_to_sys_command_via_compute_taint() {
    let src = "\
let handler () =
  let cmd = Sys.getenv \"CMD\" in
  ignore (Sys.command cmd)
";
    let regular = analyze_with_ssa(src, Language::Ocaml, "handler", false);
    assert_has_source_of_type(&regular, TaintSourceType::EnvVar, "regular");
    assert_has_sink_of_type(&regular, TaintSinkType::ShellExec, "regular");
    let ast_only = analyze_ast_only(src, Language::Ocaml, "handler");
    assert_has_source_of_type(&ast_only, TaintSourceType::EnvVar, "ast_only");
    assert_has_sink_of_type(&ast_only, TaintSinkType::ShellExec, "ast_only");
}

/// OCaml: `let cmd = In_channel.read_all path in Sys.command cmd` —
/// FileRead via `In_channel.read_all` Module call -> ShellExec via
/// `Sys.command` Module call.
#[test]
fn ocaml_in_channel_read_all_to_sys_command_via_compute_taint() {
    let src = "\
let handler path =
  let cmd = In_channel.read_all path in
  ignore (Sys.command cmd)
";
    let regular = analyze_with_ssa(src, Language::Ocaml, "handler", false);
    assert_has_source_of_type(&regular, TaintSourceType::FileRead, "regular");
    assert_has_sink_of_type(&regular, TaintSinkType::ShellExec, "regular");
    let ast_only = analyze_ast_only(src, Language::Ocaml, "handler");
    assert_has_source_of_type(&ast_only, TaintSourceType::FileRead, "ast_only");
    assert_has_sink_of_type(&ast_only, TaintSinkType::ShellExec, "ast_only");
}

/// OCaml: `let cmd = In_channel.input_all ic in Unix.execvp cmd [||]` —
/// FileRead via `In_channel.input_all` -> ShellExec via `Unix.execvp`.
#[test]
fn ocaml_in_channel_input_all_to_unix_execvp_via_compute_taint() {
    let src = "\
let handler ic =
  let cmd = In_channel.input_all ic in
  Unix.execvp cmd [||]
";
    let regular = analyze_with_ssa(src, Language::Ocaml, "handler", false);
    assert_has_source_of_type(&regular, TaintSourceType::FileRead, "regular");
    assert_has_sink_of_type(&regular, TaintSinkType::ShellExec, "regular");
    let ast_only = analyze_ast_only(src, Language::Ocaml, "handler");
    assert_has_source_of_type(&ast_only, TaintSourceType::FileRead, "ast_only");
    assert_has_sink_of_type(&ast_only, TaintSinkType::ShellExec, "ast_only");
}

/// OCaml: `let cmd = read_line () in Sys.command cmd` — UserInput via the
/// bare-call `read_line` (already AST-native via `OCAML_AST_SOURCES`
/// `call_names: ["read_line"]`) -> ShellExec via `Sys.command` Module call.
///
/// This test is NOT one of the 6 OCaml Module.function rewrites — the
/// `read_line` source side is AST-native at HEAD. Only the `Sys.command`
/// sink side requires M4 to land for `analyze_ast_only` to PASS. Listed in
/// dispatch-contract M1 because it pairs the bare-call source with a
/// Module.function sink.
#[test]
fn ocaml_read_line_to_sys_command_via_compute_taint() {
    let src = "\
let handler () =
  let cmd = read_line () in
  ignore (Sys.command cmd)
";
    let regular = analyze_with_ssa(src, Language::Ocaml, "handler", false);
    assert_has_source_of_type(&regular, TaintSourceType::UserInput, "regular");
    assert_has_sink_of_type(&regular, TaintSinkType::ShellExec, "regular");
    let ast_only = analyze_ast_only(src, Language::Ocaml, "handler");
    // Source side already AST-native; fails on sink side at HEAD pre-M4.
    assert_has_source_of_type(&ast_only, TaintSourceType::UserInput, "ast_only");
    assert_has_sink_of_type(&ast_only, TaintSinkType::ShellExec, "ast_only");
}

/// OCaml: `let cmd = read_line () in Sqlite3.exec db cmd` — UserInput via
/// bare-call `read_line` -> SqlQuery via `Sqlite3.exec` Module call.
#[test]
fn ocaml_user_input_to_sqlite3_exec_via_compute_taint() {
    let src = "\
let handler db =
  let cmd = read_line () in
  ignore (Sqlite3.exec db cmd)
";
    let regular = analyze_with_ssa(src, Language::Ocaml, "handler", false);
    assert_has_source_of_type(&regular, TaintSourceType::UserInput, "regular");
    assert_has_sink_of_type(&regular, TaintSinkType::SqlQuery, "regular");
    let ast_only = analyze_ast_only(src, Language::Ocaml, "handler");
    assert_has_source_of_type(&ast_only, TaintSourceType::UserInput, "ast_only");
    assert_has_sink_of_type(&ast_only, TaintSinkType::SqlQuery, "ast_only");
}

// ===========================================================================
// String-literal regression guards (3 fixtures — must PASS on BOTH paths)
// ===========================================================================
//
// These assert ZERO findings on fixtures where the dangerous Module.function
// name appears ONLY inside a string literal — never as a real call. They are
// the closes-#24 generalization to Ruby/Elixir/OCaml. Must stay GREEN
// through M5 (when the regex banks are deleted).

/// Ruby: `msg = "do not run IO.popen here"; puts msg` — `IO.popen`
/// substring in a string literal must not produce any source/sink.
#[test]
fn ruby_string_literal_io_popen_substring_zero_findings() {
    let src = "\
def handler
    msg = \"do not run IO.popen here\"
    puts msg
end
";
    let regular = analyze_with_ssa(src, Language::Ruby, "handler", false);
    assert!(
        regular.sources.is_empty(),
        "[regular] expected ZERO sources for string-literal IO.popen substring; got sources={:?}",
        regular.sources
    );
    assert!(
        !regular.sinks.iter().any(|s| matches!(s.sink_type, TaintSinkType::ShellExec)),
        "[regular] expected ZERO ShellExec sinks for string-literal IO.popen substring; got sinks={:?}",
        regular.sinks
    );
    let ast_only = analyze_ast_only(src, Language::Ruby, "handler");
    assert!(
        ast_only.sources.is_empty(),
        "[ast_only] expected ZERO sources for string-literal IO.popen substring; got sources={:?}",
        ast_only.sources
    );
    assert!(
        !ast_only.sinks.iter().any(|s| matches!(s.sink_type, TaintSinkType::ShellExec)),
        "[ast_only] expected ZERO ShellExec sinks for string-literal IO.popen substring; got sinks={:?}",
        ast_only.sinks
    );
}

/// Elixir: `msg = "System.cmd is dangerous"; IO.puts(msg)` — `System.cmd`
/// substring in a string literal must not produce any sink. (Note:
/// `IO.puts` itself is not a registered Elixir source — used here purely
/// to exercise the parser. The fixture's purpose is verifying the
/// `System.cmd` substring is NOT picked up.)
#[test]
fn elixir_string_literal_system_cmd_substring_zero_findings() {
    let src = "\
def handler do
  msg = \"System.cmd is dangerous\"
  IO.puts(msg)
end
";
    let regular = analyze_with_ssa(src, Language::Elixir, "handler", false);
    assert!(
        !regular.sinks.iter().any(|s| matches!(s.sink_type, TaintSinkType::ShellExec)),
        "[regular] expected ZERO ShellExec sinks for string-literal System.cmd substring; got sinks={:?}",
        regular.sinks
    );
    let ast_only = analyze_ast_only(src, Language::Elixir, "handler");
    assert!(
        !ast_only.sinks.iter().any(|s| matches!(s.sink_type, TaintSinkType::ShellExec)),
        "[ast_only] expected ZERO ShellExec sinks for string-literal System.cmd substring; got sinks={:?}",
        ast_only.sinks
    );
}

/// OCaml: `let msg = "Sys.command is dangerous" in print_endline msg` —
/// `Sys.command` substring in a string literal must not produce any sink.
#[test]
fn ocaml_string_literal_sys_command_substring_zero_findings() {
    let src = "\
let handler () =
  let msg = \"Sys.command is dangerous\" in
  print_endline msg
";
    let regular = analyze_with_ssa(src, Language::Ocaml, "handler", false);
    assert!(
        !regular.sinks.iter().any(|s| matches!(s.sink_type, TaintSinkType::ShellExec)),
        "[regular] expected ZERO ShellExec sinks for string-literal Sys.command substring; got sinks={:?}",
        regular.sinks
    );
    let ast_only = analyze_ast_only(src, Language::Ocaml, "handler");
    assert!(
        !ast_only.sinks.iter().any(|s| matches!(s.sink_type, TaintSinkType::ShellExec)),
        "[ast_only] expected ZERO ShellExec sinks for string-literal Sys.command substring; got sinks={:?}",
        ast_only.sinks
    );
}