omena-lsp-server 0.3.0

Rust LSP server boundary scaffold for Omena CSS Modules
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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
#![allow(clippy::expect_used)]

use super::*;

#[test]
fn resolves_graph_aware_sass_diagnostics_from_opened_style_documents() {
    let mut state = LspShellState::default();
    for (uri, text) in [
        (
            "file:///workspace-a/src/App.module.scss",
            "@use \"./tokens\" as tokens;\n.button { color: tokens.$brand; padding: $missing; }",
        ),
        ("file:///workspace-a/src/_tokens.scss", "$brand: red;"),
    ] {
        handle_lsp_message(
            &mut state,
            json!({
                "jsonrpc": "2.0",
                "method": "textDocument/didOpen",
                "params": {
                    "textDocument": {
                        "uri": uri,
                        "languageId": "scss",
                        "version": 1,
                        "text": text,
                    },
                },
            }),
        );
    }

    let diagnostics_response = handle_lsp_message(
        &mut state,
        json!({
            "jsonrpc": "2.0",
            "id": 1,
            "method": STYLE_DIAGNOSTICS_REQUEST,
            "params": {
                "textDocument": {
                    "uri": "file:///workspace-a/src/App.module.scss",
                },
            },
        }),
    );
    let diagnostics = diagnostics_response
        .as_ref()
        .and_then(|value| value.pointer("/result"))
        .and_then(Value::as_array)
        .expect("style diagnostics response contains an array");
    let missing_sass_messages = diagnostics
        .iter()
        .filter(|diagnostic| diagnostic.pointer("/code") == Some(&json!("missingSassSymbol")))
        .map(|diagnostic| {
            diagnostic
                .pointer("/message")
                .and_then(Value::as_str)
                .expect("missing Sass symbol diagnostic has a message")
        })
        .collect::<Vec<_>>();

    assert_eq!(
        missing_sass_messages,
        vec!["Sass variable '$missing' not found in the visible Sass module graph."]
    );
    assert!(
        diagnostics.iter().any(|diagnostic| {
            diagnostic.pointer("/code") == Some(&json!("missingSassSymbol"))
                && diagnostic.pointer("/data/provenance/1")
                    == Some(&json!("omena-query.graph-aware-sass-diagnostics"))
        }),
        "Rust LSP style diagnostics should consume graph-aware omena-query Sass diagnostics"
    );
}

#[test]
fn style_diagnostics_surface_sass_module_identity_conflicts_from_lsp() {
    let mut state = LspShellState::default();
    for (uri, text) in [
        (
            "file:///workspace-a/src/App.module.scss",
            "@use \"./theme\" as theme;",
        ),
        (
            "file:///workspace-a/src/_theme.scss",
            "@forward \"./tokens\" with ($brand: red); @forward \"./tokens\" with ($brand: blue);",
        ),
        (
            "file:///workspace-a/src/_tokens.scss",
            "$brand: blue !default;",
        ),
    ] {
        handle_lsp_message(
            &mut state,
            json!({
                "jsonrpc": "2.0",
                "method": "textDocument/didOpen",
                "params": {
                    "textDocument": {
                        "uri": uri,
                        "languageId": "scss",
                        "version": 1,
                        "text": text,
                    },
                },
            }),
        );
    }

    let diagnostics_response = handle_lsp_message(
        &mut state,
        json!({
            "jsonrpc": "2.0",
            "id": 1,
            "method": STYLE_DIAGNOSTICS_REQUEST,
            "params": {
                "textDocument": {
                    "uri": "file:///workspace-a/src/App.module.scss",
                },
            },
        }),
    );
    let diagnostics = diagnostics_response
        .as_ref()
        .and_then(|value| value.pointer("/result"))
        .and_then(Value::as_array)
        .expect("style diagnostics response contains an array");
    let conflict = diagnostics
        .iter()
        .find(|diagnostic| {
            diagnostic.pointer("/code") == Some(&json!("sassModuleConfigurationConflict"))
        })
        .expect("LSP style diagnostics should surface Sass module identity conflicts");

    assert_eq!(
        conflict.pointer("/data/provenance/2"),
        Some(&json!("omena-query.style-diagnostics"))
    );
    assert!(
        conflict
            .pointer("/message")
            .and_then(Value::as_str)
            .is_some_and(|message| {
                message.contains("_tokens.scss")
                    && message.contains("brand=3:red")
                    && message.contains("brand=4:blue")
            }),
        "diagnostic should describe the conflicting configured module instance: {conflict:?}"
    );
}

#[test]
fn style_diagnostics_resolve_sass_symbols_through_tsconfig_path_alias() -> TestResult {
    let workspace_path = std::env::temp_dir().join(format!(
        "omena-lsp-sass-diagnostics-tsconfig-alias-{}-{}",
        std::process::id(),
        current_time_millis()
    ));
    let app_style_path = workspace_path.join("src").join("App.module.scss");
    let tokens_style_path = workspace_path
        .join("src")
        .join("styles")
        .join("_tokens.scss");
    fs::create_dir_all(fixture_parent(
        app_style_path.as_path(),
        "app style fixture path has parent directory",
    )?)?;
    fs::create_dir_all(fixture_parent(
        tokens_style_path.as_path(),
        "tokens style fixture path has parent directory",
    )?)?;
    fs::write(
        workspace_path.join("tsconfig.json"),
        r#"{"compilerOptions":{"baseUrl":".","paths":{"$styles/*":["src/styles/*"]}}}"#,
    )?;

    let workspace_uri = path_to_file_uri(workspace_path.as_path());
    let app_style_uri = path_to_file_uri(app_style_path.as_path());
    let tokens_style_uri = path_to_file_uri(tokens_style_path.as_path());

    let mut state = LspShellState::default();
    handle_lsp_message(
        &mut state,
        json!({
            "jsonrpc": "2.0",
            "id": 1,
            "method": "initialize",
            "params": {
                "workspaceFolders": [
                    {
                        "uri": workspace_uri,
                        "name": "workspace-a",
                    },
                ],
            },
        }),
    );
    for (uri, text) in [
        (
            app_style_uri.as_str(),
            "@import \"$styles/_tokens.scss\";\n.button { color: $brand; padding: $missing; }",
        ),
        (tokens_style_uri.as_str(), "$brand: red;"),
    ] {
        handle_lsp_message(
            &mut state,
            json!({
                "jsonrpc": "2.0",
                "method": "textDocument/didOpen",
                "params": {
                    "textDocument": {
                        "uri": uri,
                        "languageId": "scss",
                        "version": 1,
                        "text": text,
                    },
                },
            }),
        );
    }

    let diagnostics_response = handle_lsp_message(
        &mut state,
        json!({
            "jsonrpc": "2.0",
            "id": 2,
            "method": STYLE_DIAGNOSTICS_REQUEST,
            "params": {
                "textDocument": {
                    "uri": app_style_uri,
                },
            },
        }),
    );
    let diagnostics = diagnostics_response
        .as_ref()
        .and_then(|value| value.pointer("/result"))
        .and_then(Value::as_array)
        .expect("style diagnostics response contains an array");
    let missing_sass_messages = diagnostics
        .iter()
        .filter(|diagnostic| diagnostic.pointer("/code") == Some(&json!("missingSassSymbol")))
        .filter_map(|diagnostic| diagnostic.pointer("/message").and_then(Value::as_str))
        .collect::<Vec<_>>();

    assert_eq!(
        missing_sass_messages,
        vec!["Sass variable '$missing' not found in the visible Sass module graph."],
        "tsconfig path aliases should make imported Sass symbols visible without hiding unresolved controls"
    );

    let _ = fs::remove_dir_all(workspace_path.as_path());
    Ok(())
}

#[test]
fn style_diagnostics_keep_relative_import_symbols_visible() {
    let mut state = LspShellState::default();
    for (uri, text) in [
        (
            "file:///workspace-a/src/App.module.scss",
            "@import \"./tokens\";\n.button { color: $brand; padding: $missing; }",
        ),
        ("file:///workspace-a/src/_tokens.scss", "$brand: red;"),
    ] {
        handle_lsp_message(
            &mut state,
            json!({
                "jsonrpc": "2.0",
                "method": "textDocument/didOpen",
                "params": {
                    "textDocument": {
                        "uri": uri,
                        "languageId": "scss",
                        "version": 1,
                        "text": text,
                    },
                },
            }),
        );
    }

    let diagnostics_response = handle_lsp_message(
        &mut state,
        json!({
            "jsonrpc": "2.0",
            "id": 1,
            "method": STYLE_DIAGNOSTICS_REQUEST,
            "params": {
                "textDocument": {
                    "uri": "file:///workspace-a/src/App.module.scss",
                },
            },
        }),
    );
    let diagnostics = diagnostics_response
        .as_ref()
        .and_then(|value| value.pointer("/result"))
        .and_then(Value::as_array)
        .expect("style diagnostics response contains an array");
    let missing_sass_messages = diagnostics
        .iter()
        .filter(|diagnostic| diagnostic.pointer("/code") == Some(&json!("missingSassSymbol")))
        .filter_map(|diagnostic| diagnostic.pointer("/message").and_then(Value::as_str))
        .collect::<Vec<_>>();

    assert_eq!(
        missing_sass_messages,
        vec!["Sass variable '$missing' not found in the visible Sass module graph."],
        "relative Sass imports should keep imported symbols visible without hiding unresolved controls"
    );
}

#[test]
fn style_diagnostics_surface_streaming_ifds_cross_file_reachability_from_lsp() {
    let mut state = LspShellState::default();
    for (uri, text) in [
        (
            "file:///workspace-a/src/Button.module.scss",
            "@use \"./tokens\" as tokens;\n.root { color: tokens.$brand; }",
        ),
        ("file:///workspace-a/src/_tokens.scss", "$brand: red;"),
    ] {
        handle_lsp_message(
            &mut state,
            json!({
                "jsonrpc": "2.0",
                "method": "textDocument/didOpen",
                "params": {
                    "textDocument": {
                        "uri": uri,
                        "languageId": "scss",
                        "version": 1,
                        "text": text,
                    },
                },
            }),
        );
    }

    let importer_response = handle_lsp_message(
        &mut state,
        json!({
            "jsonrpc": "2.0",
            "id": 1,
            "method": STYLE_DIAGNOSTICS_REQUEST,
            "params": {
                "textDocument": {
                    "uri": "file:///workspace-a/src/Button.module.scss",
                },
            },
        }),
    );
    let importer_diagnostics = importer_response
        .as_ref()
        .and_then(|value| value.pointer("/result"))
        .and_then(Value::as_array)
        .expect("style diagnostics response contains an array");
    let streaming = importer_diagnostics
        .iter()
        .find(|diagnostic| {
            diagnostic.pointer("/code") == Some(&json!("crossFileStreamingReachability"))
        })
        .expect("LSP style diagnostics should surface streaming-IFDS reachability");
    assert_eq!(
        streaming.pointer("/data/provenance/1"),
        Some(&json!(
            "omena-streaming-ifds.cross-file-reachability-report"
        )),
    );
    assert!(
        streaming
            .pointer("/message")
            .and_then(Value::as_str)
            .is_some_and(|message| message
                == "cross-file dataflow reaches 1 module(s) via resolved edges; paths are omitted from diagnostics"),
        "streaming diagnostic should summarize reachability without publishing paths: {streaming:?}"
    );

    let leaf_response = handle_lsp_message(
        &mut state,
        json!({
            "jsonrpc": "2.0",
            "id": 2,
            "method": STYLE_DIAGNOSTICS_REQUEST,
            "params": {
                "textDocument": {
                    "uri": "file:///workspace-a/src/_tokens.scss",
                },
            },
        }),
    );
    let leaf_diagnostics = leaf_response
        .as_ref()
        .and_then(|value| value.pointer("/result"))
        .and_then(Value::as_array)
        .expect("leaf style diagnostics response contains an array");
    assert!(
        leaf_diagnostics.iter().all(|diagnostic| {
            diagnostic.pointer("/code") != Some(&json!("crossFileStreamingReachability"))
        }),
        "leaf module should not surface cross-file streaming reachability: {leaf_diagnostics:?}"
    );
}

#[test]
fn style_diagnostics_surface_less_module_streaming_reachability_from_lsp() {
    let mut state = LspShellState::default();
    for (uri, text) in [
        (
            "file:///workspace-a/src/Button.module.less",
            "@import \"./tokens.less\";\n.root { color: @brand; }",
        ),
        ("file:///workspace-a/src/tokens.less", "@brand: red;"),
    ] {
        handle_lsp_message(
            &mut state,
            json!({
                "jsonrpc": "2.0",
                "method": "textDocument/didOpen",
                "params": {
                    "textDocument": {
                        "uri": uri,
                        "languageId": "less",
                        "version": 1,
                        "text": text,
                    },
                },
            }),
        );
    }

    let importer_response = handle_lsp_message(
        &mut state,
        json!({
            "jsonrpc": "2.0",
            "id": 1,
            "method": STYLE_DIAGNOSTICS_REQUEST,
            "params": {
                "textDocument": {
                    "uri": "file:///workspace-a/src/Button.module.less",
                },
            },
        }),
    );
    let importer_diagnostics = importer_response
        .as_ref()
        .and_then(|value| value.pointer("/result"))
        .and_then(Value::as_array)
        .expect("Less style diagnostics response contains an array");
    let streaming = importer_diagnostics
        .iter()
        .find(|diagnostic| {
            diagnostic.pointer("/code") == Some(&json!("crossFileStreamingReachability"))
        })
        .expect("LSP Less diagnostics should surface streaming-IFDS reachability");
    assert_eq!(
        streaming.pointer("/data/provenance/1"),
        Some(&json!(
            "omena-streaming-ifds.cross-file-reachability-report"
        )),
    );
    assert!(
        streaming
            .pointer("/message")
            .and_then(Value::as_str)
            .is_some_and(|message| message
                == "cross-file dataflow reaches 1 module(s) via resolved edges; paths are omitted from diagnostics"),
        "Less streaming diagnostic should summarize Less import reachability: {streaming:?}"
    );

    let leaf_response = handle_lsp_message(
        &mut state,
        json!({
            "jsonrpc": "2.0",
            "id": 2,
            "method": STYLE_DIAGNOSTICS_REQUEST,
            "params": {
                "textDocument": {
                    "uri": "file:///workspace-a/src/tokens.less",
                },
            },
        }),
    );
    let leaf_diagnostics = leaf_response
        .as_ref()
        .and_then(|value| value.pointer("/result"))
        .and_then(Value::as_array)
        .expect("Less leaf diagnostics response contains an array");
    assert!(
        leaf_diagnostics.iter().all(|diagnostic| {
            diagnostic.pointer("/code") != Some(&json!("crossFileStreamingReachability"))
        }),
        "Less leaf module should not surface cross-file streaming reachability: {leaf_diagnostics:?}"
    );
}

#[test]
fn style_diagnostics_surface_unified_cross_file_scc_from_lsp() {
    let mut state = LspShellState::default();
    for (uri, text) in [
        (
            "file:///workspace-a/src/a.module.scss",
            r#".a { composes: b from "./b.module.scss"; }"#,
        ),
        (
            "file:///workspace-a/src/b.module.scss",
            r#".b { composes: a from "./a.module.scss"; }"#,
        ),
    ] {
        handle_lsp_message(
            &mut state,
            json!({
                "jsonrpc": "2.0",
                "method": "textDocument/didOpen",
                "params": {
                    "textDocument": {
                        "uri": uri,
                        "languageId": "scss",
                        "version": 1,
                        "text": text,
                    },
                },
            }),
        );
    }

    let response = handle_lsp_message(
        &mut state,
        json!({
            "jsonrpc": "2.0",
            "id": 1,
            "method": STYLE_DIAGNOSTICS_REQUEST,
            "params": {
                "textDocument": {
                    "uri": "file:///workspace-a/src/a.module.scss",
                },
            },
        }),
    );
    let diagnostics = response
        .as_ref()
        .and_then(|value| value.pointer("/result"))
        .and_then(Value::as_array)
        .expect("style diagnostics response contains an array");
    let cycle = diagnostics
        .iter()
        .find(|diagnostic| diagnostic.pointer("/code") == Some(&json!("crossFileStyleCycle")))
        .expect("LSP style diagnostics should surface unified SCC cycles");

    assert_eq!(
        cycle.pointer("/data/crossFileScc/featureGate"),
        Some(&json!("cross-file-scc-v0"))
    );
    assert_eq!(
        cycle.pointer("/data/crossFileScc/connectivityBackend"),
        Some(&json!("exactTarjanScc"))
    );
    assert_eq!(
        cycle.pointer("/data/crossFileScc/polylogBoundScope"),
        Some(&json!("notClaimedExactTraversal"))
    );
    assert_eq!(
        cycle.pointer("/data/crossFileScc/theoremClaimed"),
        Some(&json!(false))
    );
}

#[test]
fn style_diagnostics_surface_replica_ensemble_inconsistency_from_lsp() {
    let mut state = LspShellState::default();
    for (uri, text) in [
        (
            "file:///workspace-a/src/App.module.scss",
            "@use \"./theme\";\n.button { color: red; }\n.button { color: green; }",
        ),
        (
            "file:///workspace-a/src/_theme.scss",
            ".button { color: red; }\n.button { color: blue; }",
        ),
    ] {
        handle_lsp_message(
            &mut state,
            json!({
                "jsonrpc": "2.0",
                "method": "textDocument/didOpen",
                "params": {
                    "textDocument": {
                        "uri": uri,
                        "languageId": "scss",
                        "version": 1,
                        "text": text,
                    },
                },
            }),
        );
    }

    let response = handle_lsp_message(
        &mut state,
        json!({
            "jsonrpc": "2.0",
            "id": 1,
            "method": STYLE_DIAGNOSTICS_REQUEST,
            "params": {
                "textDocument": {
                    "uri": "file:///workspace-a/src/App.module.scss",
                },
            },
        }),
    );
    let diagnostics = response
        .as_ref()
        .and_then(|value| value.pointer("/result"))
        .and_then(Value::as_array)
        .expect("style diagnostics response contains an array");
    let ensemble = diagnostics
        .iter()
        .find(|diagnostic| {
            diagnostic.pointer("/code") == Some(&json!("replicaEnsembleInconsistency"))
        })
        .expect("LSP style diagnostics should surface replica-ensemble inconsistency");
    assert_eq!(
        ensemble.pointer("/data/provenance/2"),
        Some(&json!("omena-ensemble.cross-file-inconsistency-report")),
    );
    assert!(
        ensemble
            .pointer("/message")
            .and_then(Value::as_str)
            .is_some_and(|message| message.contains("not a default product decision mechanism")),
        "ensemble diagnostic should keep hint-scope wording: {ensemble:?}"
    );

    let mut consistent_state = LspShellState::default();
    for (uri, text) in [
        (
            "file:///workspace-a/src/App.module.scss",
            "@use \"./theme\";\n.button { color: red; }\n.button { color: green; }",
        ),
        (
            "file:///workspace-a/src/_theme.scss",
            ".button { color: red; }\n.button { color: green; }",
        ),
    ] {
        handle_lsp_message(
            &mut consistent_state,
            json!({
                "jsonrpc": "2.0",
                "method": "textDocument/didOpen",
                "params": {
                    "textDocument": {
                        "uri": uri,
                        "languageId": "scss",
                        "version": 1,
                        "text": text,
                    },
                },
            }),
        );
    }

    let consistent_response = handle_lsp_message(
        &mut consistent_state,
        json!({
            "jsonrpc": "2.0",
            "id": 2,
            "method": STYLE_DIAGNOSTICS_REQUEST,
            "params": {
                "textDocument": {
                    "uri": "file:///workspace-a/src/App.module.scss",
                },
            },
        }),
    );
    let consistent_diagnostics = consistent_response
        .as_ref()
        .and_then(|value| value.pointer("/result"))
        .and_then(Value::as_array)
        .expect("consistent style diagnostics response contains an array");
    assert!(
        consistent_diagnostics.iter().all(|diagnostic| {
            diagnostic.pointer("/code") != Some(&json!("replicaEnsembleInconsistency"))
        }),
        "matching replica winners must not surface ensemble inconsistency: {consistent_diagnostics:?}"
    );
}

#[test]
fn style_diagnostics_surface_rg_flow_only_when_deep_analysis_is_enabled() {
    let mut state = LspShellState::default();
    handle_lsp_message(
        &mut state,
        json!({
            "jsonrpc": "2.0",
            "method": "textDocument/didOpen",
            "params": {
                "textDocument": {
                    "uri": "file:///workspace-a/src/RgFlow.module.scss",
                    "languageId": "scss",
                    "version": 1,
                    "text": ":root {\n  --seed: 1px;\n  --a: var(--seed);\n  --b: var(--seed);\n  --c: var(--seed);\n  --d: var(--seed);\n}\n",
                },
            },
        }),
    );

    let default_response = handle_lsp_message(
        &mut state,
        json!({
            "jsonrpc": "2.0",
            "id": 1,
            "method": STYLE_DIAGNOSTICS_REQUEST,
            "params": {
                "textDocument": {
                    "uri": "file:///workspace-a/src/RgFlow.module.scss",
                },
            },
        }),
    );
    let default_diagnostics = default_response
        .as_ref()
        .and_then(|value| value.pointer("/result"))
        .and_then(Value::as_array)
        .expect("default style diagnostics response contains an array");
    assert!(
        default_diagnostics
            .iter()
            .all(|diagnostic| diagnostic.pointer("/code") != Some(&json!("rgFlowRelevantOperator"))),
        "RG-flow must stay off by default: {default_diagnostics:?}"
    );

    handle_lsp_message(
        &mut state,
        json!({
            "jsonrpc": "2.0",
            "method": "workspace/didChangeConfiguration",
            "params": {
                "settings": {
                    "omena": {
                        "diagnostics": {
                            "deepAnalysis": true,
                        },
                    },
                },
            },
        }),
    );

    let deep_response = handle_lsp_message(
        &mut state,
        json!({
            "jsonrpc": "2.0",
            "id": 2,
            "method": STYLE_DIAGNOSTICS_REQUEST,
            "params": {
                "textDocument": {
                    "uri": "file:///workspace-a/src/RgFlow.module.scss",
                },
            },
        }),
    );
    let deep_diagnostics = deep_response
        .as_ref()
        .and_then(|value| value.pointer("/result"))
        .and_then(Value::as_array)
        .expect("deep-analysis style diagnostics response contains an array");
    let rg_flow = deep_diagnostics
        .iter()
        .find(|diagnostic| diagnostic.pointer("/code") == Some(&json!("rgFlowRelevantOperator")))
        .expect("opt-in deep analysis should surface RG-flow hint");
    assert_eq!(
        rg_flow.pointer("/data/provenance/3"),
        Some(&json!("omena-rg-flow.coupling-jacobian-spectrum")),
    );
    assert_eq!(
        rg_flow.pointer("/severity"),
        Some(&json!(4)),
        "RG-flow remains a hint-level opt-in diagnostic"
    );
}