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 
d1dd29d
 
f676764
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
"""Task and scenario definitions for the Developer Control Room benchmark."""

from __future__ import annotations

from copy import deepcopy
from pathlib import Path


def repair_validator(
    description: str,
    path: str,
    required_groups: list[list[str]] | None = None,
    forbidden_terms: list[str] | None = None,
) -> dict:
    return {
        "description": description,
        "kind": "file_groups",
        "path": path,
        "required_groups": required_groups or [],
        "forbidden_terms": forbidden_terms or [],
    }


def review_validator(
    description: str,
    draft_id: str,
    required_groups: list[list[str]] | None = None,
    forbidden_terms: list[str] | None = None,
) -> dict:
    return {
        "description": description,
        "kind": "draft_groups",
        "draft_id": draft_id,
        "required_groups": required_groups or [],
        "forbidden_terms": forbidden_terms or [],
    }


def workflow_validator(
    description: str,
    artifact: str,
) -> dict:
    return {
        "description": description,
        "kind": "workflow_artifact",
        "artifact": artifact,
    }


def repair_scenario(
    scenario_id: str,
    developer_request: str,
    workspace_summary: str,
    known_files: list[str],
    editable_targets: list[str],
    known_assets: list[str],
    available_validators: list[str],
    files: dict[str, str],
    schema_registry: dict[str, str],
    repair_target: dict,
    validators: dict[str, dict],
    lineage: dict[str, str] | None = None,
) -> dict:
    return {
        "scenario_id": scenario_id,
        "developer_request": developer_request,
        "workspace_summary": workspace_summary,
        "known_files": known_files,
        "editable_targets": editable_targets,
        "known_assets": known_assets,
        "available_validators": available_validators,
        "files": files,
        "schema_registry": schema_registry,
        "lineage": lineage or {},
        "llm_draft": {},
        "repair_target": repair_target,
        "validators": validators,
    }


def review_scenario(
    scenario_id: str,
    developer_request: str,
    workspace_summary: str,
    known_files: list[str],
    known_assets: list[str],
    available_validators: list[str],
    files: dict[str, str],
    schema_registry: dict[str, str],
    llm_draft: dict[str, str],
    review_target: dict,
    validators: dict[str, dict],
) -> dict:
    return {
        "scenario_id": scenario_id,
        "developer_request": developer_request,
        "workspace_summary": workspace_summary,
        "known_files": known_files,
        "editable_targets": [],
        "known_assets": known_assets,
        "available_validators": available_validators,
        "files": files,
        "schema_registry": schema_registry,
        "lineage": {},
        "llm_draft": llm_draft,
        "review_target": review_target,
        "validators": validators,
    }


def workflow_artifact(
    path: str,
    required_groups: list[list[str]],
    weight: float,
    forbidden_terms: list[str] | None = None,
) -> dict:
    return {
        "path": path,
        "required_groups": required_groups,
        "forbidden_terms": forbidden_terms or [],
        "weight": weight,
    }


def workflow_scenario(
    scenario_id: str,
    developer_request: str,
    workspace_summary: str,
    known_files: list[str],
    editable_targets: list[str],
    known_assets: list[str],
    available_validators: list[str],
    files: dict[str, str],
    schema_registry: dict[str, str],
    workflow_target: dict,
    validators: dict[str, dict],
    lineage: dict[str, str] | None = None,
    llm_draft: dict[str, str] | None = None,
) -> dict:
    return {
        "scenario_id": scenario_id,
        "developer_request": developer_request,
        "workspace_summary": workspace_summary,
        "known_files": known_files,
        "editable_targets": editable_targets,
        "known_assets": known_assets,
        "available_validators": available_validators,
        "files": files,
        "schema_registry": schema_registry,
        "lineage": lineage or {},
        "llm_draft": llm_draft or {},
        "workflow_target": workflow_target,
        "validators": validators,
    }


def simulation_scenario(
    *,
    scenario_id: str,
    developer_request: str,
    workspace_summary: str,
    source_csv_path: str,
    source_csv_content: str,
    raw_table: str,
    staged_view: str,
    build_table: str,
    final_view: str,
    raw_asset: str,
    final_asset: str,
    date_column: str,
    raw_schema_columns: list[tuple[str, str]],
    required_output_columns: list[str],
    build_metric_groups: list[list[str]],
    report_terms: list[str],
    correct_load_sql: str,
    correct_build_sql: str,
    correct_report_sql: str,
    starter_files: dict[str, str] | None = None,
    expected_raw_preview: list[dict[str, object]] | None = None,
    expected_derived_preview: list[dict[str, object]] | None = None,
    expected_final_preview: list[dict[str, object]] | None = None,
) -> dict:
    starter_files = starter_files or {}
    template_text = "\n".join(
        [
            f"name: {final_view}_job",
            f"storage_path: mock_s3/staged/{Path(source_csv_path).name}",
            f"raw_table: {raw_table}",
            "load_sql: sql/load_raw.sql",
            "build_sql: sql/build_table.sql",
            "report_sql: sql/report_view.sql",
            f"final_view: {final_view}",
            "",
        ]
    )
    runtime_contract = "\n".join(
        [
            "# Runtime contract",
            "",
            f"- The runtime stages `{source_csv_path}` into a local mock S3 path.",
            "- `pipelines/report_job.yaml` must define:",
            "  - storage_path",
            "  - raw_table",
            "  - load_sql",
            "  - build_sql",
            "  - report_sql",
            "  - final_view",
            "- The runtime auto-loads the staged CSV into the `raw_table`.",
            f"- `sql/load_raw.sql` must create a staged view named `{staged_view}`.",
            f"- `sql/build_table.sql` must create a derived table named `{build_table}`.",
            f"- `sql/report_view.sql` must create a final view named `{final_view}`.",
            f"- The final view must expose columns: {', '.join(required_output_columns)}",
            "",
        ]
    )
    schema_json_columns = ",\n".join(
        f'    {{"name": "{name}", "type": "{type_name}"}}' for name, type_name in raw_schema_columns
    )
    schema_yaml_columns = "\n".join(f"  - {name}: {type_name}" for name, type_name in raw_schema_columns)

    files = {
        source_csv_path: source_csv_content,
        "docs/runtime_contract.md": runtime_contract,
        "templates/report_pipeline_template.yaml": template_text,
        f"schemas/{raw_table}.json": "{\n"
        f'  "name": "{raw_table}",\n'
        '  "columns": [\n'
        f"{schema_json_columns}\n"
        "  ]\n"
        "}\n",
    }
    files.update(starter_files)

    known_files = [
        source_csv_path,
        "docs/runtime_contract.md",
        "templates/report_pipeline_template.yaml",
        f"schemas/{raw_table}.json",
    ]
    for path in ["pipelines/report_job.yaml", "sql/load_raw.sql", "sql/build_table.sql", "sql/report_view.sql"]:
        if path in starter_files:
            known_files.append(path)

    scenario = workflow_scenario(
        scenario_id=scenario_id,
        developer_request=developer_request,
        workspace_summary=workspace_summary,
        known_files=known_files,
        editable_targets=[
            "pipelines/report_job.yaml",
            "sql/load_raw.sql",
            "sql/build_table.sql",
            "sql/report_view.sql",
        ],
        known_assets=[raw_asset, final_asset],
        available_validators=[
            "storage_stage_check",
            "duckdb_load_check",
            "report_view_check",
            "output_schema_check",
        ],
        files=files,
        schema_registry={
            raw_asset: f"asset: {raw_asset}\ncolumns:\n{schema_yaml_columns}\n",
            final_asset: (
                f"asset: {final_asset}\nrequired_columns:\n"
                + "".join(f"  - {column}\n" for column in required_output_columns)
            ),
        },
        workflow_target={
            "required_artifacts": ["pipeline_yaml", "load_sql", "build_sql", "report_sql"],
            "artifacts": {
                "pipeline_yaml": workflow_artifact(
                    "pipelines/report_job.yaml",
                    required_groups=[
                        [f"storage_path: mock_s3/staged/{Path(source_csv_path).name}"],
                        [f"raw_table: {raw_table}"],
                        ["load_sql: sql/load_raw.sql"],
                        ["build_sql: sql/build_table.sql"],
                        ["report_sql: sql/report_view.sql"],
                        [f"final_view: {final_view}"],
                    ],
                    weight=1.0,
                ),
                "load_sql": workflow_artifact(
                    "sql/load_raw.sql",
                    required_groups=[
                        ["create", staged_view],
                        [raw_table],
                        [f"cast({date_column} as date)", f"try_cast({date_column} as date)", date_column],
                    ],
                    weight=1.0,
                ),
                "build_sql": workflow_artifact(
                    "sql/build_table.sql",
                    required_groups=[
                        ["create", build_table],
                        [staged_view],
                        *build_metric_groups,
                    ],
                    weight=1.2,
                ),
                "report_sql": workflow_artifact(
                    "sql/report_view.sql",
                    required_groups=[
                        ["create", final_view],
                        [build_table],
                        *[[column] for column in required_output_columns],
                    ],
                    weight=1.2,
                ),
            },
            "validator_targets": [
                "storage_stage_check",
                "duckdb_load_check",
                "report_view_check",
                "output_schema_check",
            ],
            "solve_validator_targets": [
                "storage_stage_check",
                "duckdb_load_check",
                "report_view_check",
                "output_schema_check",
            ],
            "summary_groups": [
                [Path(source_csv_path).name],
                [final_view],
                *[[term] for term in report_terms],
            ],
            "investigation_targets": [
                ("read_file", "docs/runtime_contract.md"),
                ("read_file", source_csv_path),
                ("inspect_schema", raw_asset),
            ],
        },
        validators={
            "storage_stage_check": {
                "description": "Checks that the CSV could be staged into mock storage.",
                "kind": "runtime_check",
                "check_key": "storage_stage_check",
            },
            "duckdb_load_check": {
                "description": "Checks that the staged CSV loads into DuckDB.",
                "kind": "runtime_check",
                "check_key": "duckdb_load_check",
            },
            "report_view_check": {
                "description": "Checks that the final report view compiles.",
                "kind": "runtime_check",
                "check_key": "report_view_check",
            },
            "output_schema_check": {
                "description": "Checks that the final report view exposes the expected schema.",
                "kind": "runtime_check",
                "check_key": "output_schema_check",
            },
        },
        llm_draft={},
    )
    scenario["simulation_target"] = {
        "source_csv": source_csv_path,
        "pipeline_path": "pipelines/report_job.yaml",
        "load_sql_path": "sql/load_raw.sql",
        "build_sql_path": "sql/build_table.sql",
        "report_sql_path": "sql/report_view.sql",
        "required_output_columns": required_output_columns,
        "expected_raw_table": {
            "name": raw_table,
            "preview_rows": expected_raw_preview or [],
        },
        "expected_derived_table": {
            "name": build_table,
            "preview_rows": expected_derived_preview or [],
        },
        "expected_final_view": {
            "name": final_view,
            "preview_rows": expected_final_preview or [],
        },
    }
    scenario["llm_draft"]["simulation_target"] = deepcopy(scenario["simulation_target"])
    scenario["llm_draft"]["reference_solution"] = {
        "pipeline_yaml": template_text,
        "load_sql": correct_load_sql,
        "build_sql": correct_build_sql,
        "report_sql": correct_report_sql,
    }
    return scenario


TASK_DEFINITIONS: dict[str, dict] = {
    "repair_data_transform": {
        "id": "repair_data_transform",
        "name": "Task 1: Repair Data Transform",
        "difficulty": "easy",
        "max_steps": 8,
        "score_range": [0.0, 1.0],
        "description": (
            "Repair transform logic or dependency wiring while keeping downstream "
            "warehouse contracts stable."
        ),
        "available_actions": [
            "search_workspace",
            "read_file",
            "inspect_schema",
            "run_validator",
            "edit_file",
            "submit_repair",
        ],
        "submission_action": "submit_repair",
        "grader_family": "repair",
        "scenario_ids": ["PR-001", "PR-004"],
    },
    "repair_pipeline_execution": {
        "id": "repair_pipeline_execution",
        "name": "Task 2: Repair Pipeline Execution",
        "difficulty": "easy",
        "max_steps": 8,
        "score_range": [0.0, 1.0],
        "description": (
            "Recover ingestion or orchestration failures caused by storage layout, "
            "runner, or deploy-configuration drift."
        ),
        "available_actions": [
            "search_workspace",
            "read_file",
            "inspect_schema",
            "run_validator",
            "edit_file",
            "submit_repair",
        ],
        "submission_action": "submit_repair",
        "grader_family": "repair",
        "scenario_ids": ["PR-002", "PR-003", "PR-005", "PR-006", "PR-007", "PR-008"],
    },
    "review_ai_patch_safety": {
        "id": "review_ai_patch_safety",
        "name": "Task 3: Review AI Patch Safety",
        "difficulty": "medium",
        "max_steps": 8,
        "score_range": [0.0, 1.0],
        "description": (
            "Review AI-generated changes for governance, privacy, and operational "
            "safety risks before they reach production."
        ),
        "available_actions": [
            "search_workspace",
            "read_file",
            "inspect_schema",
            "inspect_llm_draft",
            "run_validator",
            "submit_review",
        ],
        "submission_action": "submit_review",
        "grader_family": "review",
        "scenario_ids": ["LR-001", "LR-004"],
    },
    "review_ai_patch_correctness": {
        "id": "review_ai_patch_correctness",
        "name": "Task 4: Review AI Patch Correctness",
        "difficulty": "medium",
        "max_steps": 8,
        "score_range": [0.0, 1.0],
        "description": (
            "Review AI-generated changes for semantic correctness and compatibility "
            "with published warehouse contracts."
        ),
        "available_actions": [
            "search_workspace",
            "read_file",
            "inspect_schema",
            "inspect_llm_draft",
            "run_validator",
            "submit_review",
        ],
        "submission_action": "submit_review",
        "grader_family": "review",
        "scenario_ids": ["LR-002", "LR-003"],
    },
    "synthesize_reporting_asset": {
        "id": "synthesize_reporting_asset",
        "name": "Task 5: Synthesize Reporting Asset",
        "difficulty": "hard",
        "max_steps": 12,
        "score_range": [0.0, 1.0],
        "description": (
            "Create reporting-facing assets such as views, contracts, and alerts "
            "that are ready for production use."
        ),
        "available_actions": [
            "search_workspace",
            "read_file",
            "inspect_schema",
            "inspect_lineage",
            "inspect_llm_draft",
            "edit_file",
            "run_validator",
            "submit_workspace",
        ],
        "submission_action": "submit_workspace",
        "grader_family": "workflow",
        "scenario_ids": ["WS-002", "WS-004"],
    },
    "synthesize_data_product": {
        "id": "synthesize_data_product",
        "name": "Task 6: Synthesize Data Product",
        "difficulty": "hard",
        "max_steps": 14,
        "score_range": [0.0, 1.0],
        "description": (
            "Create production-grade data products with pipeline metadata, SQL, "
            "checks, contracts, and governance-safe outputs."
        ),
        "available_actions": [
            "search_workspace",
            "read_file",
            "inspect_schema",
            "inspect_lineage",
            "inspect_llm_draft",
            "edit_file",
            "run_validator",
            "submit_workspace",
        ],
        "submission_action": "submit_workspace",
        "grader_family": "workflow",
        "scenario_ids": ["WS-001", "WS-003"],
    },
    "simulate_csv_report_workflow": {
        "id": "simulate_csv_report_workflow",
        "name": "Task 7: Simulate CSV Report Workflow",
        "difficulty": "hard",
        "max_steps": 12,
        "score_range": [0.0, 1.0],
        "description": (
            "Generate and repair a small CSV-to-report data workflow that stages "
            "source data, loads it into DuckDB, and publishes a final report view."
        ),
        "available_actions": [
            "search_workspace",
            "read_file",
            "inspect_schema",
            "edit_file",
            "run_validator",
            "submit_workspace",
        ],
        "submission_action": "submit_workspace",
        "grader_family": "simulation",
        "scenario_ids": ["SIM-001", "SIM-002", "SIM-003", "SIM-004", "SIM-005", "SIM-006", "SIM-007"],
    },
    "simulate_csv_report_curriculum_generate": {
        "id": "simulate_csv_report_curriculum_generate",
        "name": "Task 8: Easy CSV Workflow Generation",
        "difficulty": "easy",
        "max_steps": 8,
        "score_range": [0.0, 1.0],
        "description": "Create a tiny CSV-to-report workflow with a very small daily aggregation.",
        "available_actions": [
            "search_workspace",
            "read_file",
            "inspect_schema",
            "edit_file",
            "run_validator",
            "submit_workspace",
        ],
        "submission_action": "submit_workspace",
        "grader_family": "simulation",
        "scenario_ids": ["SIM-E001"],
    },
    "simulate_csv_report_curriculum_repair": {
        "id": "simulate_csv_report_curriculum_repair",
        "name": "Task 9: Easy CSV Workflow Repair",
        "difficulty": "easy",
        "max_steps": 8,
        "score_range": [0.0, 1.0],
        "description": "Repair a tiny CSV workflow where one final-view bug prevents success.",
        "available_actions": [
            "search_workspace",
            "read_file",
            "inspect_schema",
            "edit_file",
            "run_validator",
            "submit_workspace",
        ],
        "submission_action": "submit_workspace",
        "grader_family": "simulation",
        "scenario_ids": ["SIM-E002"],
    },
}

ALL_TASKS = TASK_DEFINITIONS


SCENARIOS: dict[str, list[dict]] = {
    "pipeline_repair": [
        repair_scenario(
            scenario_id="PR-001",
            developer_request=(
                "The nightly `orders_daily` build started failing after an upstream "
                "change. Repair the workspace so the job compiles again, but keep "
                "the published contract stable for downstream dashboards."
            ),
            workspace_summary=(
                "This repo keeps transform logic in `transforms/`, job configs in "
                "`pipelines/`, and published contracts in `schemas/`. Validators "
                "`sql_compile` and `contract_guard` are available."
            ),
            known_files=[
                "pipelines/orders_daily.yaml",
                "transforms/orders_daily.sql",
                "schemas/orders_daily.json",
                "docs/pipeline_conventions.md",
            ],
            editable_targets=["transforms/orders_daily.sql"],
            known_assets=["raw.orders_events", "dim.customers", "orders_daily"],
            available_validators=["sql_compile", "contract_guard"],
            files={
                "pipelines/orders_daily.yaml": """name: orders_daily
schedule: "0 2 * * *"
owner: analytics-platform
sources:
  - raw.orders_events
  - dim.customers
target: orders_daily
contract: schemas/orders_daily.json
""",
                "transforms/orders_daily.sql": """with base as (
    select
        o.order_id,
        o.customer_id,
        o.event_ts as order_ts,
        date(o.event_ts) as order_date,
        o.amount_cents / 100.0 as total_amount
    from raw.orders_events o
    where o.status = 'completed'
)
select * from base;
""",
                "schemas/orders_daily.json": """{
  "name": "orders_daily",
  "columns": [
    {"name": "order_id", "type": "string"},
    {"name": "customer_id", "type": "string"},
    {"name": "order_ts", "type": "timestamp"},
    {"name": "order_date", "type": "date"},
    {"name": "total_amount", "type": "float"}
  ]
}
""",
                "docs/pipeline_conventions.md": """# Pipeline conventions

- Keep published column names stable when upstream systems rename fields.
- Prefer aliasing upstream renames inside SQL rather than changing the contract.
- `sql_compile` fails on unresolved columns.
""",
            },
            schema_registry={
                "raw.orders_events": """asset: raw.orders_events
columns:
  - order_id: string
  - customer_id: string
  - event_time: timestamp
  - amount_cents: bigint
  - status: string
notes:
  - Column `event_ts` was renamed to `event_time` in the latest ingestion deploy.
""",
                "dim.customers": """asset: dim.customers
columns:
  - customer_id: string
  - segment: string
""",
                "orders_daily": """asset: orders_daily
published_columns:
  - order_id
  - customer_id
  - order_ts
  - order_date
  - total_amount
""",
            },
            repair_target={
                "path": "transforms/orders_daily.sql",
                "required_groups": [["event_time"], ["as order_ts"], ["order_date"]],
                "forbidden_terms": ["event_ts"],
                "root_cause_groups": [["schema", "column"], ["event_ts"], ["event_time", "rename"]],
                "summary_groups": [["order_ts", "contract"], ["event_time"], ["orders_daily"]],
                "fix_path": "transforms/orders_daily.sql",
                "investigation_targets": [
                    ("read_file", "transforms/orders_daily.sql"),
                    ("inspect_schema", "raw.orders_events"),
                    ("run_validator", "sql_compile"),
                ],
            },
            validators={
                "sql_compile": repair_validator(
                    "Checks unresolved columns in the SQL transform.",
                    "transforms/orders_daily.sql",
                    required_groups=[["event_time"], ["as order_ts"]],
                    forbidden_terms=["event_ts"],
                ),
                "contract_guard": repair_validator(
                    "Confirms the output contract still publishes `order_ts`.",
                    "transforms/orders_daily.sql",
                    required_groups=[["as order_ts"], ["order_date"]],
                ),
            },
        ),
        repair_scenario(
            scenario_id="PR-002",
            developer_request=(
                "The `customer_events_ingest` job started failing after the data lake "
                "team changed the ADLS folder convention. Repair the config without "
                "renaming the target dataset."
            ),
            workspace_summary=(
                "Landing-zone jobs read from ADLS paths declared in `pipelines/`. "
                "Validators `path_resolver` and `target_guard` are available."
            ),
            known_files=[
                "pipelines/customer_events_ingest.yaml",
                "schemas/customer_events_raw.json",
                "docs/storage_layout.md",
            ],
            editable_targets=["pipelines/customer_events_ingest.yaml"],
            known_assets=["landing.customer_events", "customer_events_raw"],
            available_validators=["path_resolver", "target_guard"],
            files={
                "pipelines/customer_events_ingest.yaml": """name: customer_events_ingest
schedule: "0 * * * *"
owner: ingestion-platform
source_path: "abfss://bronze@datalake.dfs.core.windows.net/customer-events/date={{ ds }}/"
format: parquet
target: customer_events_raw
""",
                "schemas/customer_events_raw.json": """{
  "name": "customer_events_raw",
  "columns": [
    {"name": "event_id", "type": "string"},
    {"name": "customer_id", "type": "string"},
    {"name": "event_type", "type": "string"},
    {"name": "event_ts", "type": "timestamp"}
  ]
}
""",
                "docs/storage_layout.md": """# Storage layout

- Customer events now land under `customer-events/v2/`.
- Daily partitions use `dt={{ ds }}` instead of `date={{ ds }}`.
- Downstream dataset names must stay unchanged across ingestion path migrations.
""",
            },
            schema_registry={
                "landing.customer_events": """asset: landing.customer_events
location:
  abfss://bronze@datalake.dfs.core.windows.net/customer-events/v2/dt={{ ds }}/
format: parquet
""",
                "customer_events_raw": """asset: customer_events_raw
published_columns:
  - event_id
  - customer_id
  - event_type
  - event_ts
""",
            },
            repair_target={
                "path": "pipelines/customer_events_ingest.yaml",
                "required_groups": [["customer-events/v2"], ["dt={{ ds }}", "dt={ds}"], ["target: customer_events_raw"]],
                "forbidden_terms": ["date={{ ds }}"],
                "root_cause_groups": [["path", "folder", "partition"], ["date"], ["dt"]],
                "summary_groups": [["customer-events/v2"], ["customer_events_raw"]],
                "fix_path": "pipelines/customer_events_ingest.yaml",
                "investigation_targets": [
                    ("read_file", "pipelines/customer_events_ingest.yaml"),
                    ("read_file", "docs/storage_layout.md"),
                    ("run_validator", "path_resolver"),
                ],
            },
            validators={
                "path_resolver": repair_validator(
                    "Checks that the ADLS path uses the new folder and partition layout.",
                    "pipelines/customer_events_ingest.yaml",
                    required_groups=[["customer-events/v2"], ["dt={{ ds }}", "dt={ds}"]],
                    forbidden_terms=["date={{ ds }}"],
                ),
                "target_guard": repair_validator(
                    "Confirms the target dataset stays stable during the repair.",
                    "pipelines/customer_events_ingest.yaml",
                    required_groups=[["target: customer_events_raw"]],
                ),
            },
        ),
        repair_scenario(
            scenario_id="PR-003",
            developer_request=(
                "The Jenkins release job for `orders_daily` started failing after a CI "
                "cleanup. Fix the job definition so it invokes the packaged runner again."
            ),
            workspace_summary=(
                "CI jobs are declared in `ci/jenkins/`. Validators `jenkins_lint` and "
                "`runner_guard` are available."
            ),
            known_files=[
                "ci/jenkins/orders_daily.groovy",
                "docs/ci_conventions.md",
                "scripts/run_orders_daily.sh",
            ],
            editable_targets=["ci/jenkins/orders_daily.groovy"],
            known_assets=["ci.orders_daily", "artifact.orders_daily"],
            available_validators=["jenkins_lint", "runner_guard"],
            files={
                "ci/jenkins/orders_daily.groovy": """pipeline {
  agent any
  stages {
    stage('Run') {
      steps {
        sh './scripts/run-orders-daily.sh'
      }
    }
  }
}
""",
                "docs/ci_conventions.md": """# CI conventions

- Release jobs call the packaged runner script under `./scripts/`.
- Script names use underscores, not hyphens.
- Jobs should execute `./scripts/run_orders_daily.sh` for the orders_daily release.
""",
                "scripts/run_orders_daily.sh": """#!/usr/bin/env bash
set -euo pipefail
echo "running orders daily"
""",
            },
            schema_registry={
                "ci.orders_daily": """asset: ci.orders_daily
expected_runner:
  ./scripts/run_orders_daily.sh
""",
                "artifact.orders_daily": """asset: artifact.orders_daily
package:
  orders_daily.tar.gz
""",
            },
            repair_target={
                "path": "ci/jenkins/orders_daily.groovy",
                "required_groups": [["./scripts/run_orders_daily.sh"]],
                "forbidden_terms": ["run-orders-daily.sh"],
                "root_cause_groups": [["jenkins", "ci"], ["script", "runner"], ["hyphen", "path", "name"]],
                "summary_groups": [["run_orders_daily.sh"], ["jenkins", "runner"]],
                "fix_path": "ci/jenkins/orders_daily.groovy",
                "investigation_targets": [
                    ("read_file", "ci/jenkins/orders_daily.groovy"),
                    ("read_file", "docs/ci_conventions.md"),
                    ("run_validator", "jenkins_lint"),
                ],
            },
            validators={
                "jenkins_lint": repair_validator(
                    "Checks that the Jenkins job points at an existing runner script.",
                    "ci/jenkins/orders_daily.groovy",
                    required_groups=[["./scripts/run_orders_daily.sh"]],
                    forbidden_terms=["run-orders-daily.sh"],
                ),
                "runner_guard": repair_validator(
                    "Confirms the repair still uses the packaged runner convention.",
                    "ci/jenkins/orders_daily.groovy",
                    required_groups=[["sh"], ["./scripts/run_orders_daily.sh"]],
                ),
            },
        ),
        repair_scenario(
            scenario_id="PR-004",
            developer_request=(
                "The `revenue_dashboard_refresh` job is stale because its upstream "
                "dependency was renamed incorrectly during a rollout. Repair the "
                "dependency wiring so the dashboard refreshes again."
            ),
            workspace_summary=(
                "Downstream jobs declare upstreams in pipeline YAML. Validators "
                "`dependency_guard` and `freshness_guard` are available."
            ),
            known_files=[
                "pipelines/revenue_dashboard_refresh.yaml",
                "pipelines/orders_daily.yaml",
                "docs/lineage_notes.md",
            ],
            editable_targets=["pipelines/revenue_dashboard_refresh.yaml"],
            known_assets=["orders_daily", "orders_daily_v2", "revenue_dashboard_refresh"],
            available_validators=["dependency_guard", "freshness_guard"],
            files={
                "pipelines/revenue_dashboard_refresh.yaml": """name: revenue_dashboard_refresh
schedule: "0 5 * * *"
owner: finance-analytics
sources:
  - orders_daily_v2
target: revenue_dashboard_refresh
""",
                "pipelines/orders_daily.yaml": """name: orders_daily
schedule: "0 2 * * *"
target: orders_daily
""",
                "docs/lineage_notes.md": """# Lineage notes

- The rollout created a temporary `orders_daily_v2` alias, but the canonical
  upstream for production dashboards remains `orders_daily`.
- Downstream jobs should depend on canonical dataset names after the rollback.
""",
            },
            schema_registry={
                "orders_daily": """asset: orders_daily
freshness_sla: 3h
status: healthy
""",
                "orders_daily_v2": """asset: orders_daily_v2
status: deprecated_alias
""",
                "revenue_dashboard_refresh": """asset: revenue_dashboard_refresh
depends_on:
  - orders_daily
""",
            },
            repair_target={
                "path": "pipelines/revenue_dashboard_refresh.yaml",
                "required_groups": [["orders_daily"], ["target: revenue_dashboard_refresh"]],
                "forbidden_terms": ["orders_daily_v2"],
                "root_cause_groups": [["upstream", "dependency", "stale"], ["orders_daily_v2"], ["orders_daily", "canonical"]],
                "summary_groups": [["orders_daily"], ["revenue_dashboard_refresh"], ["deprecated", "alias"]],
                "fix_path": "pipelines/revenue_dashboard_refresh.yaml",
                "investigation_targets": [
                    ("read_file", "pipelines/revenue_dashboard_refresh.yaml"),
                    ("read_file", "docs/lineage_notes.md"),
                    ("run_validator", "dependency_guard"),
                ],
            },
            validators={
                "dependency_guard": repair_validator(
                    "Checks that the pipeline points at the canonical upstream dataset.",
                    "pipelines/revenue_dashboard_refresh.yaml",
                    required_groups=[["orders_daily"]],
                    forbidden_terms=["orders_daily_v2"],
                ),
                "freshness_guard": repair_validator(
                    "Confirms the dashboard target remains unchanged after the dependency fix.",
                    "pipelines/revenue_dashboard_refresh.yaml",
                    required_groups=[["target: revenue_dashboard_refresh"]],
                ),
            },
        ),
        repair_scenario(
            scenario_id="PR-005",
            developer_request=(
                "The reporting release deploy started failing after a config cleanup. "
                "Repair the deploy definition so it passes the expected warehouse "
                "role to the packaged release runner again."
            ),
            workspace_summary=(
                "Release definitions live under `deploy/`. Validators `deploy_lint` "
                "and `role_guard` are available."
            ),
            known_files=[
                "deploy/reporting_release.yaml",
                "docs/deploy_runbook.md",
                "scripts/release_reporting_asset.sh",
            ],
            editable_targets=["deploy/reporting_release.yaml"],
            known_assets=["deploy.reporting_release", "warehouse.reporting_release"],
            available_validators=["deploy_lint", "role_guard"],
            files={
                "deploy/reporting_release.yaml": """job: reporting_release
runner_image: reporting-release:latest
script: ./scripts/release_reporting_asset.sh
env:
  WAREHOUSE_ROLE: analytics_writer
  ALERT_ROUTE: finance-reporting
""",
                "docs/deploy_runbook.md": """# Reporting release runbook

- Reporting releases execute `./scripts/release_reporting_asset.sh`.
- Production deploys must pass `TARGET_WAREHOUSE_ROLE`.
- The reporting release role remains `analytics_writer`.
""",
                "scripts/release_reporting_asset.sh": """#!/usr/bin/env bash
set -euo pipefail
echo "releasing reporting asset"
""",
            },
            schema_registry={
                "deploy.reporting_release": """asset: deploy.reporting_release
expected_script:
  ./scripts/release_reporting_asset.sh
required_env:
  TARGET_WAREHOUSE_ROLE
""",
                "warehouse.reporting_release": """asset: warehouse.reporting_release
role: analytics_writer
""",
            },
            repair_target={
                "path": "deploy/reporting_release.yaml",
                "required_groups": [
                    ["TARGET_WAREHOUSE_ROLE"],
                    ["analytics_writer"],
                    ["./scripts/release_reporting_asset.sh"],
                ],
                "forbidden_terms": ["\nenv:\n  WAREHOUSE_ROLE:"],
                "root_cause_groups": [
                    ["deploy", "release"],
                    ["env", "environment", "variable"],
                    ["target_warehouse_role", "warehouse_role"],
                ],
                "summary_groups": [["TARGET_WAREHOUSE_ROLE"], ["analytics_writer"], ["release"]],
                "fix_path": "deploy/reporting_release.yaml",
                "investigation_targets": [
                    ("read_file", "deploy/reporting_release.yaml"),
                    ("read_file", "docs/deploy_runbook.md"),
                    ("read_file", "scripts/release_reporting_asset.sh"),
                    ("run_validator", "deploy_lint"),
                ],
            },
            validators={
                "deploy_lint": repair_validator(
                    "Checks that the release job uses the correct release script and env key.",
                    "deploy/reporting_release.yaml",
                    required_groups=[["./scripts/release_reporting_asset.sh"], ["TARGET_WAREHOUSE_ROLE"]],
                    forbidden_terms=["\nenv:\n  WAREHOUSE_ROLE:"],
                ),
                "role_guard": repair_validator(
                    "Confirms the release config still deploys with the analytics_writer role.",
                    "deploy/reporting_release.yaml",
                    required_groups=[["TARGET_WAREHOUSE_ROLE"], ["analytics_writer"]],
                ),
            },
        ),
        repair_scenario(
            scenario_id="PR-006",
            developer_request=(
                "The `customer_profile_import` batch started failing during load. The "
                "CSV still lands successfully, but the warehouse insert now errors "
                "because the incoming identifier shape no longer matches the target "
                "table contract. Repair the load mapping."
            ),
            workspace_summary=(
                "Batch loads stage CSVs in `samples/` and warehouse load SQL lives in "
                "`transforms/`. Validators `type_alignment_guard` and "
                "`load_contract_guard` are available."
            ),
            known_files=[
                "transforms/customer_profile_import.sql",
                "samples/customer_profile_import.csv",
                "schemas/customer_profile_dim.json",
                "docs/load_contracts.md",
            ],
            editable_targets=["transforms/customer_profile_import.sql"],
            known_assets=["customer_profile_stage", "customer_profile_dim"],
            available_validators=["type_alignment_guard", "load_contract_guard"],
            files={
                "transforms/customer_profile_import.sql": """insert into customer_profile_dim (
    customer_code,
    loyalty_tier,
    state_code
)
select
    cast(s.customer_code as integer) as customer_code,
    s.loyalty_tier,
    s.state_code
from customer_profile_stage s;
""",
                "samples/customer_profile_import.csv": """customer_code,loyalty_tier,state_code
000123,GOLD,CA
000124,SILVER,WA
""",
                "schemas/customer_profile_dim.json": """{
  "name": "customer_profile_dim",
  "columns": [
    {"name": "customer_code", "type": "string"},
    {"name": "loyalty_tier", "type": "string"},
    {"name": "state_code", "type": "string"}
  ]
}
""",
                "docs/load_contracts.md": """# Load contracts

- `customer_code` remains a string identifier because leading zeroes are significant.
- Batch imports may receive numeric-looking identifiers in CSV files, but warehouse
  inserts must preserve the original string representation.
""",
            },
            schema_registry={
                "customer_profile_stage": """asset: customer_profile_stage
columns:
  - customer_code: string
  - loyalty_tier: string
  - state_code: string
""",
                "customer_profile_dim": """asset: customer_profile_dim
published_columns:
  - customer_code:string
  - loyalty_tier:string
  - state_code:string
""",
            },
            repair_target={
                "path": "transforms/customer_profile_import.sql",
                "required_groups": [
                    ["insert into customer_profile_dim"],
                    ["customer_code"],
                    ["s.customer_code"],
                ],
                "forbidden_terms": ["cast(s.customer_code as integer)", "::integer", "as integer) as customer_code"],
                "root_cause_groups": [
                    ["customer_code"],
                    ["string", "varchar", "text"],
                    ["cast", "integer", "type mismatch"],
                ],
                "summary_groups": [["customer_code"], ["string", "leading zero"], ["load", "mapping"]],
                "fix_path": "transforms/customer_profile_import.sql",
                "investigation_targets": [
                    ("read_file", "transforms/customer_profile_import.sql"),
                    ("read_file", "samples/customer_profile_import.csv"),
                    ("read_file", "docs/load_contracts.md"),
                    ("read_file", "schemas/customer_profile_dim.json"),
                ],
            },
            validators={
                "type_alignment_guard": repair_validator(
                    "Checks that the load no longer casts customer_code to integer.",
                    "transforms/customer_profile_import.sql",
                    required_groups=[["s.customer_code"]],
                    forbidden_terms=["cast(s.customer_code as integer)", "::integer"],
                ),
                "load_contract_guard": repair_validator(
                    "Checks that the warehouse insert still targets the published string contract.",
                    "transforms/customer_profile_import.sql",
                    required_groups=[["customer_profile_dim"], ["customer_code"], ["loyalty_tier"], ["state_code"]],
                ),
            },
        ),
        repair_scenario(
            scenario_id="PR-007",
            developer_request=(
                "The `orders_archive_load` job is failing because the new CSV extract "
                "only ships 6 columns, while the archive table now has 12 columns. "
                "Repair the load configuration so the archive ingest succeeds again."
            ),
            workspace_summary=(
                "Archive loads map source columns in YAML and rely on default values "
                "for warehouse-only metadata fields. Validators `column_mapping_guard` "
                "and `archive_defaults_guard` are available."
            ),
            known_files=[
                "pipelines/orders_archive_load.yaml",
                "samples/orders_archive_extract.csv",
                "schemas/orders_archive.json",
                "docs/archive_load_guide.md",
            ],
            editable_targets=["pipelines/orders_archive_load.yaml"],
            known_assets=["orders_archive_stage", "orders_archive"],
            available_validators=["column_mapping_guard", "archive_defaults_guard"],
            files={
                "pipelines/orders_archive_load.yaml": """job: orders_archive_load
target_table: orders_archive
source_columns:
  - order_id
  - customer_id
  - order_ts
  - order_status
  - gross_amount_usd
  - currency_code
defaults: {}
""",
                "samples/orders_archive_extract.csv": """order_id,customer_id,order_ts,order_status,gross_amount_usd,currency_code
o-1001,c-11,2026-04-01T02:00:00Z,completed,129.0,USD
""",
                "schemas/orders_archive.json": """{
  "name": "orders_archive",
  "columns": [
    {"name": "order_id", "type": "string"},
    {"name": "customer_id", "type": "string"},
    {"name": "order_ts", "type": "timestamp"},
    {"name": "order_status", "type": "string"},
    {"name": "gross_amount_usd", "type": "float"},
    {"name": "currency_code", "type": "string"},
    {"name": "ingest_source", "type": "string"},
    {"name": "ingest_batch_id", "type": "string"},
    {"name": "created_at", "type": "timestamp"},
    {"name": "updated_at", "type": "timestamp"},
    {"name": "archive_status", "type": "string"},
    {"name": "notes", "type": "string"}
  ]
}
""",
                "docs/archive_load_guide.md": """# Archive load guide

- The extract only supplies 6 business columns.
- Warehouse-only fields must be populated through deterministic defaults:
  - ingest_source: csv_archive
  - ingest_batch_id: current_batch_id
  - created_at: current_timestamp
  - updated_at: current_timestamp
  - archive_status: active
  - notes: ''
""",
            },
            schema_registry={
                "orders_archive_stage": """asset: orders_archive_stage
extract_columns:
  - order_id
  - customer_id
  - order_ts
  - order_status
  - gross_amount_usd
  - currency_code
""",
                "orders_archive": """asset: orders_archive
required_columns: 12
warehouse_default_columns:
  - ingest_source
  - ingest_batch_id
  - created_at
  - updated_at
  - archive_status
  - notes
""",
            },
            repair_target={
                "path": "pipelines/orders_archive_load.yaml",
                "required_groups": [
                    ["order_id"],
                    ["customer_id"],
                    ["order_ts"],
                    ["order_status"],
                    ["gross_amount_usd"],
                    ["currency_code"],
                    ["ingest_source: csv_archive"],
                    ["ingest_batch_id: current_batch_id"],
                    ["created_at: current_timestamp"],
                    ["updated_at: current_timestamp"],
                    ["archive_status: active"],
                    ["notes: ''", "notes: \"\""],
                ],
                "forbidden_terms": ["defaults: {}"],
                "root_cause_groups": [
                    ["6", "six"],
                    ["12", "twelve"],
                    ["columns", "mapping"],
                ],
                "summary_groups": [["defaults"], ["12", "columns"], ["archive"], ["metadata"]],
                "fix_path": "pipelines/orders_archive_load.yaml",
                "investigation_targets": [
                    ("read_file", "pipelines/orders_archive_load.yaml"),
                    ("read_file", "schemas/orders_archive.json"),
                    ("read_file", "docs/archive_load_guide.md"),
                    ("read_file", "samples/orders_archive_extract.csv"),
                ],
            },
            validators={
                "column_mapping_guard": repair_validator(
                    "Checks that the archive load maps the 6 source columns and 6 deterministic defaults.",
                    "pipelines/orders_archive_load.yaml",
                    required_groups=[
                        ["order_id"],
                        ["customer_id"],
                        ["order_ts"],
                        ["order_status"],
                        ["gross_amount_usd"],
                        ["currency_code"],
                        ["ingest_source: csv_archive"],
                        ["ingest_batch_id: current_batch_id"],
                    ],
                    forbidden_terms=["defaults: {}"],
                ),
                "archive_defaults_guard": repair_validator(
                    "Checks that archive-only metadata fields are populated with stable defaults.",
                    "pipelines/orders_archive_load.yaml",
                    required_groups=[
                        ["created_at: current_timestamp"],
                        ["updated_at: current_timestamp"],
                        ["archive_status: active"],
                        ["notes: ''", "notes: \"\""],
                    ],
                ),
            },
        ),
        repair_scenario(
            scenario_id="PR-008",
            developer_request=(
                "The `dim_customer_merge` load started failing with a primary key "
                "violation after duplicate rows appeared in the incoming batch. "
                "Repair the merge strategy so the load is safe again."
            ),
            workspace_summary=(
                "Dimension merges are implemented in SQL and should deduplicate the "
                "incoming batch before writing to the warehouse table. Validators "
                "`pk_uniqueness_guard` and `merge_strategy_guard` are available."
            ),
            known_files=[
                "transforms/dim_customer_merge.sql",
                "samples/dim_customer_delta.csv",
                "schemas/dim_customer.json",
                "docs/merge_strategy.md",
            ],
            editable_targets=["transforms/dim_customer_merge.sql"],
            known_assets=["dim_customer_delta", "dim_customer"],
            available_validators=["pk_uniqueness_guard", "merge_strategy_guard"],
            files={
                "transforms/dim_customer_merge.sql": """insert into dim_customer (
    customer_id,
    customer_name,
    state_code,
    updated_at
)
select
    d.customer_id,
    d.customer_name,
    d.state_code,
    d.updated_at
from dim_customer_delta d;
""",
                "samples/dim_customer_delta.csv": """customer_id,customer_name,state_code,updated_at
c-1,Ada Smith,CA,2026-04-01T10:00:00Z
c-1,Ada Smith,CA,2026-04-01T10:05:00Z
""",
                "schemas/dim_customer.json": """{
  "name": "dim_customer",
  "primary_key": ["customer_id"],
  "columns": [
    {"name": "customer_id", "type": "string"},
    {"name": "customer_name", "type": "string"},
    {"name": "state_code", "type": "string"},
    {"name": "updated_at", "type": "timestamp"}
  ]
}
""",
                "docs/merge_strategy.md": """# Merge strategy

- Incoming dimension batches may contain duplicate customer_id rows.
- Deduplicate the stage with `row_number()` and keep the latest `updated_at`.
- Use `merge` or `insert ... where not exists` semantics; never blindly insert the full batch.
""",
            },
            schema_registry={
                "dim_customer_delta": """asset: dim_customer_delta
possible_duplicates:
  primary_key: customer_id
""",
                "dim_customer": """asset: dim_customer
primary_key:
  - customer_id
""",
            },
            repair_target={
                "path": "transforms/dim_customer_merge.sql",
                "required_groups": [
                    ["row_number()"],
                    ["partition by customer_id"],
                    ["order by d.updated_at desc", "order by updated_at desc"],
                    ["where rn = 1", "where deduped.rn = 1"],
                ],
                "forbidden_terms": [],
                "root_cause_groups": [
                    ["primary key", "pk"],
                    ["duplicate", "duplicates"],
                    ["deduplicate", "row_number", "merge"],
                ],
                "summary_groups": [["primary key"], ["deduplicate", "latest"], ["merge", "load"]],
                "fix_path": "transforms/dim_customer_merge.sql",
                "investigation_targets": [
                    ("read_file", "transforms/dim_customer_merge.sql"),
                    ("read_file", "samples/dim_customer_delta.csv"),
                    ("read_file", "schemas/dim_customer.json"),
                    ("read_file", "docs/merge_strategy.md"),
                ],
            },
            validators={
                "pk_uniqueness_guard": repair_validator(
                    "Checks that the merge SQL deduplicates customer_id rows before writing.",
                    "transforms/dim_customer_merge.sql",
                    required_groups=[
                        ["row_number()"],
                        ["partition by customer_id"],
                        ["where rn = 1", "where deduped.rn = 1"],
                    ],
                ),
                "merge_strategy_guard": repair_validator(
                    "Checks that the merge keeps the latest updated_at row instead of blindly inserting duplicates.",
                    "transforms/dim_customer_merge.sql",
                    required_groups=[
                        ["order by d.updated_at desc", "order by updated_at desc"],
                        ["insert into dim_customer", "merge into dim_customer"],
                    ],
                ),
            },
        ),
    ],
    "llm_patch_review": [
        review_scenario(
            scenario_id="LR-001",
            developer_request=(
                "Review the AI-generated patch for `payments_enriched` and decide if "
                "it is safe to merge into production analytics."
            ),
            workspace_summary=(
                "Company policy forbids exposing direct identifiers in analytics "
                "outputs. The patch file in `drafts/` contains the assistant's "
                "proposed change."
            ),
            known_files=[
                "transforms/payments_enriched.sql",
                "schemas/payments_enriched.json",
                "policies/data_governance.md",
                "drafts/payments_enriched.patch",
            ],
            known_assets=["payments_raw", "customer_dim", "payments_enriched"],
            available_validators=["privacy_guard", "contract_guard"],
            files={
                "transforms/payments_enriched.sql": """select
    p.payment_id,
    p.customer_id,
    p.amount_usd,
    p.payment_status,
    p.processed_at
from payments_raw p;
""",
                "schemas/payments_enriched.json": """{
  "name": "payments_enriched",
  "columns": [
    {"name": "payment_id", "type": "string"},
    {"name": "customer_id", "type": "string"},
    {"name": "amount_usd", "type": "float"},
    {"name": "payment_status", "type": "string"},
    {"name": "processed_at", "type": "timestamp"}
  ]
}
""",
                "policies/data_governance.md": """# Data governance

- Analytics outputs must not expose `customer_email`, `phone`, or `full_name`.
- Direct identifiers are only allowed in operational systems, not shared marts.
- Schema changes to published datasets require explicit approval.
""",
                "drafts/payments_enriched.patch": """diff --git a/transforms/payments_enriched.sql b/transforms/payments_enriched.sql
@@
 select
     p.payment_id,
     p.customer_id,
+    c.customer_email,
     p.amount_usd,
     p.payment_status,
     p.processed_at
 from payments_raw p
+left join customer_dim c on p.customer_id = c.customer_id;

diff --git a/schemas/payments_enriched.json b/schemas/payments_enriched.json
@@
   {"name": "customer_id", "type": "string"},
+  {"name": "customer_email", "type": "string"},
   {"name": "amount_usd", "type": "float"},
""",
            },
            schema_registry={
                "payments_raw": """asset: payments_raw
columns:
  - payment_id: string
  - customer_id: string
  - amount_usd: float
  - payment_status: string
  - processed_at: timestamp
""",
                "customer_dim": """asset: customer_dim
columns:
  - customer_id: string
  - customer_email: string
  - phone: string
""",
                "payments_enriched": """asset: payments_enriched
published_columns:
  - payment_id
  - customer_id
  - amount_usd
  - payment_status
  - processed_at
""",
            },
            llm_draft={
                "primary": """AI draft summary:
- Adds `customer_email` to the SELECT list.
- Joins `customer_dim`.
- Extends the published schema with `customer_email`.
""",
            },
            review_target={
                "correct_verdict": "reject",
                "correct_issue_type": "pii_exposure",
                "summary_groups": [["customer_email"], ["policy", "direct identifier"], ["schema", "contract"]],
                "investigation_targets": [
                    ("inspect_llm_draft", "primary"),
                    ("read_file", "policies/data_governance.md"),
                    ("run_validator", "privacy_guard"),
                ],
                "validator_targets": ["privacy_guard"],
            },
            validators={
                "privacy_guard": review_validator(
                    "Checks whether the proposed patch leaks direct identifiers.",
                    "primary",
                    forbidden_terms=["customer_email", "phone", "full_name"],
                ),
                "contract_guard": review_validator(
                    "Checks whether the patch changes the published contract.",
                    "primary",
                    forbidden_terms=["published schema", "customer_email"],
                ),
            },
        ),
        review_scenario(
            scenario_id="LR-002",
            developer_request=(
                "Review the assistant patch for `merchant_settlement_rollup`. The SQL "
                "looks plausible, but finance thinks the join is wrong."
            ),
            workspace_summary=(
                "The AI patch sits in `drafts/` and the correct join key is documented "
                "in the settlement conventions file."
            ),
            known_files=[
                "transforms/merchant_settlement_rollup.sql",
                "docs/settlement_conventions.md",
                "drafts/merchant_settlement_rollup.patch",
            ],
            known_assets=["settlements_raw", "merchant_dim", "merchant_settlement_rollup"],
            available_validators=["logic_guard", "join_key_guard"],
            files={
                "transforms/merchant_settlement_rollup.sql": """select
    s.settlement_id,
    s.merchant_id,
    s.net_amount_usd,
    s.settlement_date
from settlements_raw s;
""",
                "docs/settlement_conventions.md": """# Settlement conventions

- Merchant enrichment joins on `merchant_id`.
- Never join merchant dimensions using settlement or payment identifiers.
- Published rollups must stay at one row per settlement_id.
""",
                "drafts/merchant_settlement_rollup.patch": """diff --git a/transforms/merchant_settlement_rollup.sql b/transforms/merchant_settlement_rollup.sql
@@
 select
     s.settlement_id,
     s.merchant_id,
     m.region as merchant_region,
     s.net_amount_usd,
     s.settlement_date
 from settlements_raw s
+left join merchant_dim m on s.settlement_id = m.merchant_id;
""",
            },
            schema_registry={
                "settlements_raw": """asset: settlements_raw
columns:
  - settlement_id: string
  - merchant_id: string
  - net_amount_usd: float
  - settlement_date: date
""",
                "merchant_dim": """asset: merchant_dim
columns:
  - merchant_id: string
  - region: string
""",
                "merchant_settlement_rollup": """asset: merchant_settlement_rollup
grain:
  one_row_per: settlement_id
""",
            },
            llm_draft={
                "primary": """AI draft summary:
- Enriches settlements with merchant region.
- Joins `merchant_dim` using `settlement_id = merchant_id`.
- Does not change the published grain intentionally.
""",
            },
            review_target={
                "correct_verdict": "reject",
                "correct_issue_type": "technical_incorrectness",
                "summary_groups": [
                    ["join"],
                    ["settlement_id", "merchant_id"],
                    ["wrong", "incorrect"],
                    ["grain", "one row per settlement_id"],
                ],
                "investigation_targets": [
                    ("inspect_llm_draft", "primary"),
                    ("read_file", "drafts/merchant_settlement_rollup.patch"),
                    ("read_file", "docs/settlement_conventions.md"),
                    ("run_validator", "logic_guard"),
                ],
                "validator_targets": ["logic_guard", "join_key_guard"],
            },
            validators={
                "logic_guard": review_validator(
                    "Checks that the draft avoids the incorrect settlement-to-merchant join.",
                    "primary",
                    forbidden_terms=["settlement_id = merchant_id"],
                ),
                "join_key_guard": review_validator(
                    "Checks that the draft references the documented merchant join key.",
                    "primary",
                    required_groups=[["merchant_id"]],
                    forbidden_terms=["settlement_id = merchant_id"],
                ),
            },
        ),
        review_scenario(
            scenario_id="LR-003",
            developer_request=(
                "Review the patch for `subscription_mrr_daily`. The assistant claims it "
                "fixes a reporting bug, but product analytics is worried about contract "
                "compatibility."
            ),
            workspace_summary=(
                "Published contracts for finance datasets are strict. Review the patch "
                "and decide if the proposed schema change is acceptable."
            ),
            known_files=[
                "schemas/subscription_mrr_daily.json",
                "policies/published_contracts.md",
                "drafts/subscription_mrr_daily.patch",
            ],
            known_assets=["subscription_mrr_daily"],
            available_validators=["contract_guard", "consumer_guard"],
            files={
                "schemas/subscription_mrr_daily.json": """{
  "name": "subscription_mrr_daily",
  "columns": [
    {"name": "account_id", "type": "string"},
    {"name": "snapshot_date", "type": "date"},
    {"name": "mrr_usd", "type": "float"}
  ]
}
""",
                "policies/published_contracts.md": """# Published contracts

- Finance marts require approval before adding or renaming published columns.
- Backward-incompatible contract changes must not be merged through assistant patches.
""",
                "drafts/subscription_mrr_daily.patch": """diff --git a/schemas/subscription_mrr_daily.json b/schemas/subscription_mrr_daily.json
@@
   {"name": "account_id", "type": "string"},
   {"name": "snapshot_date", "type": "date"},
-  {"name": "mrr_usd", "type": "float"}
+  {"name": "monthly_recurring_revenue_usd", "type": "float"}
""",
            },
            schema_registry={
                "subscription_mrr_daily": """asset: subscription_mrr_daily
published_columns:
  - account_id
  - snapshot_date
  - mrr_usd
""",
            },
            llm_draft={
                "primary": """AI draft summary:
- Renames `mrr_usd` to `monthly_recurring_revenue_usd` for clarity.
- Describes the change as non-breaking because the meaning is unchanged.
""",
            },
            review_target={
                "correct_verdict": "reject",
                "correct_issue_type": "contract_breakage",
                "summary_groups": [["published", "contract"], ["mrr_usd"], ["rename", "breaking"], ["consumer", "downstream"]],
                "investigation_targets": [
                    ("inspect_llm_draft", "primary"),
                    ("read_file", "policies/published_contracts.md"),
                    ("run_validator", "contract_guard"),
                ],
                "validator_targets": ["contract_guard"],
            },
            validators={
                "contract_guard": review_validator(
                    "Checks that the draft keeps the published finance contract stable.",
                    "primary",
                    forbidden_terms=["monthly_recurring_revenue_usd", "rename"],
                ),
                "consumer_guard": review_validator(
                    "Checks that downstream consumers still receive `mrr_usd`.",
                    "primary",
                    forbidden_terms=["monthly_recurring_revenue_usd"],
                ),
            },
        ),
        review_scenario(
            scenario_id="LR-004",
            developer_request=(
                "Review the assistant response for warehouse recovery. Decide whether "
                "the recommendation is safe to execute in production."
            ),
            workspace_summary=(
                "The assistant produced an ops recommendation instead of a code patch. "
                "Use the platform recovery policy as the source of truth."
            ),
            known_files=[
                "policies/recovery_playbook.md",
                "drafts/warehouse_recovery_response.md",
            ],
            known_assets=["warehouse.recovery"],
            available_validators=["safety_guard", "playbook_guard"],
            files={
                "policies/recovery_playbook.md": """# Recovery playbook

- Never drop production marts as a first response to pipeline incidents.
- Do not disable contract or governance checks to speed up recovery.
- Preferred order: identify failing upstream, patch safely, re-run validators, then backfill.
""",
                "drafts/warehouse_recovery_response.md": """The quickest fix is to drop and recreate `finance.daily_margin_mart`,
disable contract checks temporarily, and backfill after the model retrains.
This avoids waiting on upstream teams and gets dashboards green faster.
""",
            },
            schema_registry={
                "warehouse.recovery": """asset: warehouse.recovery
policy_owner: platform-sre
""",
            },
            llm_draft={
                "primary": """AI response summary:
- Recommends dropping a production mart.
- Suggests disabling contract checks temporarily.
- Prioritizes speed over safe rollback and validation.
""",
            },
            review_target={
                "correct_verdict": "reject",
                "correct_issue_type": "unsafe_operation",
                "summary_groups": [["drop", "recreate"], ["disable", "checks"], ["unsafe", "policy"]],
                "investigation_targets": [
                    ("inspect_llm_draft", "primary"),
                    ("read_file", "drafts/warehouse_recovery_response.md"),
                    ("read_file", "policies/recovery_playbook.md"),
                    ("run_validator", "safety_guard"),
                ],
                "validator_targets": ["safety_guard", "playbook_guard"],
            },
            validators={
                "safety_guard": review_validator(
                    "Checks that the recommendation avoids destructive recovery advice.",
                    "primary",
                    forbidden_terms=["drop", "disable contract checks"],
                ),
                "playbook_guard": review_validator(
                    "Checks alignment with the platform recovery playbook.",
                    "primary",
                    forbidden_terms=["drop", "disable"],
                ),
            },
        ),
    ],
    "workflow_shipping": [
        workflow_scenario(
            scenario_id="WS-001",
            developer_request=(
                "Add a daily `merchant_risk_features` workflow for the risk-model "
                "team. Use `transactions_silver`, `chargebacks_silver`, and "
                "`merchant_dim`; compute a 30-day lookback; exclude test merchants; "
                "do not expose PII; add freshness and not-null checks; and preserve "
                "the downstream `risk_model_scoring` contract."
            ),
            workspace_summary=(
                "This repo contains examples for feature pipelines plus a draft from "
                "an internal coding assistant. The target workflow does not exist yet. "
                "Use the templates and downstream contract as the source of truth."
            ),
            known_files=[
                "templates/pipeline_template.yaml",
                "templates/feature_template.sql",
                "templates/checks_template.yaml",
                "pipelines/order_features.yaml",
                "sql/order_features.sql",
                "checks/order_features.yaml",
                "schemas/order_features.json",
                "pipelines/risk_model_scoring.yaml",
                "schemas/risk_model_scoring.json",
                "docs/platform_standards.md",
                "drafts/merchant_risk_features.stub",
            ],
            editable_targets=[
                "pipelines/merchant_risk_features.yaml",
                "sql/merchant_risk_features.sql",
                "checks/merchant_risk_features.yaml",
                "schemas/merchant_risk_features.json",
            ],
            known_assets=[
                "transactions_silver",
                "chargebacks_silver",
                "merchant_dim",
                "merchant_risk_features",
                "risk_model_scoring",
            ],
            available_validators=[
                "workflow_lint",
                "quality_checks",
                "contract_check",
                "governance_check",
            ],
            files={
                "templates/pipeline_template.yaml": """name: <pipeline_name>
schedule: "0 1 * * *"
owner: risk-platform
sources:
  - <source_asset>
target: <target_asset>
checks_file: checks/<pipeline_name>.yaml
downstreams:
  - <consumer>
""",
                "templates/feature_template.sql": """with source as (
    select *
    from <source_asset>
)
select *
from source;
""",
                "templates/checks_template.yaml": """checks:
  - type: freshness
    column: snapshot_date
  - type: not_null
    column: id
""",
                "pipelines/order_features.yaml": """name: order_features
schedule: "0 1 * * *"
owner: risk-platform
sources:
  - orders_silver
  - merchant_dim
target: order_features
checks_file: checks/order_features.yaml
downstreams:
  - risk_model_scoring
""",
                "sql/order_features.sql": """with recent_orders as (
    select
        o.merchant_id,
        count(*) as order_count_30d,
        current_date as snapshot_date
    from orders_silver o
    join merchant_dim m on o.merchant_id = m.merchant_id
    where m.is_test = false
      and o.created_at >= current_date - interval '30 day'
    group by 1, 3
)
select *
from recent_orders;
""",
                "checks/order_features.yaml": """checks:
  - type: freshness
    column: snapshot_date
  - type: not_null
    column: merchant_id
""",
                "schemas/order_features.json": """{
  "name": "order_features",
  "columns": [
    {"name": "merchant_id", "type": "string"},
    {"name": "order_count_30d", "type": "integer"},
    {"name": "snapshot_date", "type": "date"}
  ]
}
""",
                "pipelines/risk_model_scoring.yaml": """name: risk_model_scoring
sources:
  - merchant_risk_features
target: risk_model_scoring
""",
                "schemas/risk_model_scoring.json": """{
  "name": "risk_model_scoring",
  "required_inputs": [
    "merchant_id",
    "txn_count_30d",
    "chargeback_rate_30d",
    "snapshot_date"
  ]
}
""",
                "docs/platform_standards.md": """# Platform standards

- New feature pipelines run daily at `0 1 * * *`.
- Exclude test merchants using `merchant_dim.is_test = false`.
- Never select direct identifiers such as `email`, `phone`, or `full_name`.
- Every feature pipeline must ship freshness and not_null checks.
- Declare downstream consumers in the pipeline YAML.
""",
                "drafts/merchant_risk_features.stub": """# AI assistant stub
-- WARNING: draft may be unsafe
select
    t.merchant_id,
    m.email as merchant_email,
    count(*) as txn_count_30d,
    current_date as snapshot_date
from transactions_silver t
join merchant_dim m on t.merchant_id = m.merchant_id
group by 1, 2, 4;
""",
            },
            schema_registry={
                "transactions_silver": """asset: transactions_silver
columns:
  - merchant_id: string
  - transaction_id: string
  - amount_usd: float
  - processed_at: timestamp
""",
                "chargebacks_silver": """asset: chargebacks_silver
columns:
  - merchant_id: string
  - chargeback_id: string
  - processed_at: timestamp
""",
                "merchant_dim": """asset: merchant_dim
columns:
  - merchant_id: string
  - is_test: boolean
  - email: string
  - owner_name: string
""",
                "merchant_risk_features": """asset: merchant_risk_features
required_columns:
  - merchant_id
  - txn_count_30d
  - chargeback_rate_30d
  - snapshot_date
""",
                "risk_model_scoring": """asset: risk_model_scoring
requires:
  - merchant_id
  - txn_count_30d
  - chargeback_rate_30d
  - snapshot_date
""",
            },
            workflow_target={
                "required_artifacts": ["pipeline", "sql", "checks", "schema"],
                "artifacts": {
                    "pipeline": workflow_artifact(
                        "pipelines/merchant_risk_features.yaml",
                        [
                            ["merchant_risk_features"],
                            ["0 1 * * *", "daily"],
                            ["transactions_silver"],
                            ["chargebacks_silver"],
                            ["merchant_dim"],
                            ["risk_model_scoring"],
                        ],
                        0.25,
                    ),
                    "sql": workflow_artifact(
                        "sql/merchant_risk_features.sql",
                        [
                            ["transactions_silver"],
                            ["chargebacks_silver"],
                            ["merchant_dim"],
                            ["30 day", "30-day", "interval '30 day'"],
                            ["is_test = false", "is_test=false"],
                            ["txn_count_30d"],
                            ["chargeback_rate_30d"],
                            ["snapshot_date"],
                        ],
                        0.4,
                        forbidden_terms=["email", "phone", "full_name"],
                    ),
                    "checks": workflow_artifact(
                        "checks/merchant_risk_features.yaml",
                        [["freshness"], ["not_null"], ["merchant_id"], ["snapshot_date"]],
                        0.15,
                    ),
                    "schema": workflow_artifact(
                        "schemas/merchant_risk_features.json",
                        [["merchant_id"], ["txn_count_30d"], ["chargeback_rate_30d"], ["snapshot_date"]],
                        0.2,
                        forbidden_terms=["email", "phone", "full_name"],
                    ),
                },
                "investigation_targets": [
                    ("read_file", "templates/pipeline_template.yaml"),
                    ("read_file", "sql/order_features.sql"),
                    ("inspect_schema", "transactions_silver"),
                    ("inspect_lineage", "risk_model_scoring"),
                ],
                "summary_groups": [["merchant_risk_features"], ["risk_model_scoring"], ["checks", "validators"]],
                "solve_validator_targets": ["workflow_lint", "governance_check"],
                "validator_targets": [
                    "workflow_lint",
                    "quality_checks",
                    "contract_check",
                    "governance_check",
                    "workflow_sources_check",
                    "workflow_schema_shape_check",
                    "workflow_checks_shape_check",
                    "workflow_delivery_check",
                ],
                "forbidden_terms": ["email", "phone", "full_name"],
            },
            validators={
                "workflow_lint": workflow_validator(
                    "Checks pipeline metadata and lineage wiring.",
                    "pipeline",
                ),
                "quality_checks": workflow_validator(
                    "Checks freshness and not-null coverage.",
                    "checks",
                ),
                "contract_check": workflow_validator(
                    "Checks the schema contract expected by downstream scoring.",
                    "schema",
                ),
                "governance_check": workflow_validator(
                    "Checks for PII leakage and missing test-merchant filters.",
                    "sql",
                ),
                "workflow_sources_check": workflow_validator(
                    "Checks that the workflow covers the intended upstream source set.",
                    "pipeline",
                ),
                "workflow_schema_shape_check": workflow_validator(
                    "Checks that the feature schema stays aligned with downstream scoring expectations.",
                    "schema",
                ),
                "workflow_checks_shape_check": workflow_validator(
                    "Checks that the workflow publishes the expected validation checks.",
                    "checks",
                ),
                "workflow_delivery_check": workflow_validator(
                    "Checks that the workflow artifact bundle is ready for downstream delivery.",
                    "pipeline",
                ),
            },
            lineage={
                "risk_model_scoring": """risk_model_scoring
  <- merchant_risk_features
     <- transactions_silver
     <- chargebacks_silver
     <- merchant_dim
""",
            },
            llm_draft={
                "primary": """AI draft summary:
- Mentions `merchant_email`, which violates governance.
- Omits chargeback rate.
- Does not exclude test merchants.
- Does not define checks or pipeline metadata.
""",
            },
        ),
        workflow_scenario(
            scenario_id="WS-002",
            developer_request=(
                "Create a reporting view called `finance_weekly_net_revenue` for the "
                "finance analysts. Base it on `invoice_line_items` and "
                "`credit_memos_daily`, publish a weekly grain by account, and define "
                "the view contract. This task only needs the SQL and schema artifacts."
            ),
            workspace_summary=(
                "Reporting views live under `sql/views/` and publish contracts under "
                "`schemas/views/`. There is no pipeline YAML for analyst-facing views."
            ),
            known_files=[
                "sql/views/finance_daily_revenue.sql",
                "schemas/views/finance_daily_revenue.json",
                "docs/reporting_view_standards.md",
                "docs/finance_reporting_glossary.md",
            ],
            editable_targets=[
                "sql/views/finance_weekly_net_revenue.sql",
                "schemas/views/finance_weekly_net_revenue.json",
            ],
            known_assets=[
                "invoice_line_items",
                "credit_memos_daily",
                "finance_weekly_net_revenue",
            ],
            available_validators=[
                "view_sql_check",
                "view_contract_check",
                "view_usage_check",
                "view_reference_check",
                "view_schema_naming_check",
                "view_rollup_check",
                "view_source_shape_check",
                "view_semantics_check",
                "view_contract_shape_check",
            ],
            files={
                "sql/views/finance_daily_revenue.sql": """select
    i.account_id,
    date(i.invoice_ts) as revenue_date,
    sum(i.net_revenue_usd) as net_revenue_usd
from invoice_line_items i
group by 1, 2;
""",
                "schemas/views/finance_daily_revenue.json": """{
  "name": "finance_daily_revenue",
  "columns": [
    {"name": "account_id", "type": "string"},
    {"name": "revenue_date", "type": "date"},
    {"name": "net_revenue_usd", "type": "float"}
  ]
}
""",
                "docs/reporting_view_standards.md": """# Reporting view standards

- Analyst-facing views do not need pipeline YAML.
- Weekly finance views should group by `date_trunc('week', ...)`.
- Publish one schema contract per view.
- Keep direct identifiers out of finance reporting views.
""",
                "docs/finance_reporting_glossary.md": """# Finance reporting glossary

- Weekly reporting views should preserve a stable account-level rollup.
- Reporting contracts should stay aligned with finance naming conventions.
""",
            },
            schema_registry={
                "invoice_line_items": """asset: invoice_line_items
columns:
  - account_id: string
  - invoice_ts: timestamp
  - net_revenue_usd: float
""",
                "credit_memos_daily": """asset: credit_memos_daily
columns:
  - account_id: string
  - credit_memo_date: date
  - credit_amount_usd: float
""",
                "finance_weekly_net_revenue": """asset: finance_weekly_net_revenue
required_columns:
  - account_id
  - revenue_week
  - net_revenue_usd
""",
            },
            workflow_target={
                "required_artifacts": ["sql", "schema"],
                "artifacts": {
                    "sql": workflow_artifact(
                        "sql/views/finance_weekly_net_revenue.sql",
                        [
                            ["invoice_line_items"],
                            ["credit_memos_daily"],
                            ["date_trunc('week'", "date_trunc(\"week\""],
                            ["account_id"],
                            ["net_revenue_usd"],
                        ],
                        0.7,
                        forbidden_terms=["email", "phone", "full_name"],
                    ),
                    "schema": workflow_artifact(
                        "schemas/views/finance_weekly_net_revenue.json",
                        [["account_id"], ["revenue_week"], ["net_revenue_usd"]],
                        0.3,
                        forbidden_terms=["email", "phone", "full_name"],
                    ),
                },
                "investigation_targets": [
                    ("read_file", "sql/views/finance_daily_revenue.sql"),
                    ("read_file", "schemas/views/finance_daily_revenue.json"),
                    ("read_file", "docs/reporting_view_standards.md"),
                    ("read_file", "docs/finance_reporting_glossary.md"),
                    ("inspect_schema", "invoice_line_items"),
                    ("inspect_schema", "credit_memos_daily"),
                    ("inspect_schema", "finance_weekly_net_revenue"),
                ],
                "summary_groups": [["finance_weekly_net_revenue"], ["weekly"], ["schema"]],
                "solve_validator_targets": ["view_sql_check", "view_contract_check"],
                "validator_targets": [
                    "view_sql_check",
                    "view_contract_check",
                    "view_usage_check",
                    "view_reference_check",
                    "view_schema_naming_check",
                    "view_rollup_check",
                    "view_source_shape_check",
                    "view_semantics_check",
                    "view_contract_shape_check",
                ],
                "forbidden_terms": ["email", "phone", "full_name"],
            },
            validators={
                "view_sql_check": workflow_validator(
                    "Checks that the weekly reporting view SQL joins the expected inputs and weekly grain.",
                    "sql",
                ),
                "view_contract_check": workflow_validator(
                    "Checks that the reporting view contract publishes the required columns.",
                    "schema",
                ),
                "view_usage_check": workflow_validator(
                    "Checks that the reporting SQL publishes a stable account-level view shape.",
                    "sql",
                ),
                "view_reference_check": workflow_validator(
                    "Checks that the weekly view references the expected finance source tables.",
                    "sql",
                ),
                "view_schema_naming_check": workflow_validator(
                    "Checks that the published reporting schema uses the expected view name and column contract.",
                    "schema",
                ),
                "view_rollup_check": workflow_validator(
                    "Checks that the weekly reporting SQL preserves the intended rollup output shape.",
                    "sql",
                ),
                "view_source_shape_check": workflow_validator(
                    "Checks that the weekly reporting view contract stays aligned with the finance source shape.",
                    "schema",
                ),
                "view_semantics_check": workflow_validator(
                    "Checks that the weekly reporting SQL preserves the intended finance semantics.",
                    "sql",
                ),
                "view_contract_shape_check": workflow_validator(
                    "Checks that the weekly reporting contract stays aligned with downstream reporting expectations.",
                    "schema",
                ),
            },
        ),
        workflow_scenario(
            scenario_id="WS-003",
            developer_request=(
                "Create a new `customer_margin_mart` workflow for finance. It should "
                "combine `orders_silver`, `refunds_silver`, and `customer_dim`, ship "
                "daily, exclude internal test accounts, write checks, and publish a "
                "contract for downstream BI dashboards."
            ),
            workspace_summary=(
                "Finance marts follow the same pipeline structure as other curated "
                "warehouse tables. Use the existing mart example and governance rules."
            ),
            known_files=[
                "templates/pipeline_template.yaml",
                "sql/order_features.sql",
                "checks/order_features.yaml",
                "schemas/order_features.json",
                "docs/platform_standards.md",
            ],
            editable_targets=[
                "pipelines/customer_margin_mart.yaml",
                "sql/customer_margin_mart.sql",
                "checks/customer_margin_mart.yaml",
                "schemas/customer_margin_mart.json",
            ],
            known_assets=[
                "orders_silver",
                "refunds_silver",
                "customer_dim",
                "customer_margin_mart",
            ],
            available_validators=[
                "mart_lint",
                "mart_checks",
                "mart_contract",
                "mart_governance",
                "mart_source_check",
                "mart_schema_shape_check",
                "mart_pipeline_metadata_check",
                "mart_publish_contract_check",
                "mart_consumer_shape_check",
            ],
            files={
                "templates/pipeline_template.yaml": """name: <pipeline_name>
schedule: "0 1 * * *"
owner: data-platform
sources:
  - <source_asset>
target: <target_asset>
checks_file: checks/<pipeline_name>.yaml
""",
                "sql/order_features.sql": """with recent_orders as (
    select
        o.merchant_id,
        count(*) as order_count_30d,
        current_date as snapshot_date
    from orders_silver o
    join merchant_dim m on o.merchant_id = m.merchant_id
    where m.is_test = false
      and o.created_at >= current_date - interval '30 day'
    group by 1, 3
)
select *
from recent_orders;
""",
                "checks/order_features.yaml": """checks:
  - type: freshness
    column: snapshot_date
  - type: not_null
    column: merchant_id
""",
                "schemas/order_features.json": """{
  "name": "order_features",
  "columns": [
    {"name": "merchant_id", "type": "string"},
    {"name": "order_count_30d", "type": "integer"},
    {"name": "snapshot_date", "type": "date"}
  ]
}
""",
                "docs/platform_standards.md": """# Platform standards

- Curated marts run daily at `0 1 * * *`.
- Exclude test or internal entities using the dimension table filter.
- Publish freshness and not_null checks for curated marts.
- Avoid direct identifiers such as `email`, `phone`, and `full_name`.
""",
            },
            schema_registry={
                "orders_silver": """asset: orders_silver
columns:
  - customer_id: string
  - order_id: string
  - created_at: timestamp
  - gross_amount_usd: float
""",
                "refunds_silver": """asset: refunds_silver
columns:
  - customer_id: string
  - refund_id: string
  - processed_at: timestamp
  - refund_amount_usd: float
""",
                "customer_dim": """asset: customer_dim
columns:
  - customer_id: string
  - is_test: boolean
  - email: string
""",
                "customer_margin_mart": """asset: customer_margin_mart
required_columns:
  - customer_id
  - gross_revenue_usd
  - refund_amount_usd
  - net_margin_usd
  - snapshot_date
""",
            },
            workflow_target={
                "required_artifacts": ["pipeline", "sql", "checks", "schema"],
                "artifacts": {
                    "pipeline": workflow_artifact(
                        "pipelines/customer_margin_mart.yaml",
                        [
                            ["customer_margin_mart"],
                            ["0 1 * * *", "daily"],
                            ["orders_silver"],
                            ["refunds_silver"],
                            ["customer_dim"],
                        ],
                        0.2,
                    ),
                    "sql": workflow_artifact(
                        "sql/customer_margin_mart.sql",
                        [
                            ["orders_silver"],
                            ["refunds_silver"],
                            ["customer_dim"],
                            ["is_test = false", "is_test=false"],
                            ["gross_revenue_usd"],
                            ["refund_amount_usd"],
                            ["net_margin_usd"],
                            ["snapshot_date"],
                        ],
                        0.45,
                        forbidden_terms=["email", "phone", "full_name"],
                    ),
                    "checks": workflow_artifact(
                        "checks/customer_margin_mart.yaml",
                        [["freshness"], ["not_null"], ["customer_id"], ["snapshot_date"]],
                        0.15,
                    ),
                    "schema": workflow_artifact(
                        "schemas/customer_margin_mart.json",
                        [
                            ["customer_id"],
                            ["gross_revenue_usd"],
                            ["refund_amount_usd"],
                            ["net_margin_usd"],
                            ["snapshot_date"],
                        ],
                        0.2,
                        forbidden_terms=["email", "phone", "full_name"],
                    ),
                },
                "investigation_targets": [
                    ("read_file", "templates/pipeline_template.yaml"),
                    ("read_file", "checks/order_features.yaml"),
                    ("read_file", "docs/platform_standards.md"),
                    ("read_file", "schemas/order_features.json"),
                    ("inspect_schema", "orders_silver"),
                    ("inspect_schema", "refunds_silver"),
                    ("inspect_schema", "customer_dim"),
                ],
                "summary_groups": [["customer_margin_mart"], ["daily"], ["checks", "contract"]],
                "solve_validator_targets": ["mart_lint", "mart_governance"],
                "validator_targets": [
                    "mart_lint",
                    "mart_checks",
                    "mart_contract",
                    "mart_governance",
                    "mart_source_check",
                    "mart_schema_shape_check",
                    "mart_pipeline_metadata_check",
                    "mart_publish_contract_check",
                    "mart_consumer_shape_check",
                    "mart_schedule_check",
                    "mart_delivery_shape_check",
                ],
                "forbidden_terms": ["email", "phone", "full_name"],
            },
            validators={
                "mart_lint": workflow_validator(
                    "Checks mart pipeline metadata and sources.",
                    "pipeline",
                ),
                "mart_checks": workflow_validator(
                    "Checks mart freshness and not-null coverage.",
                    "checks",
                ),
                "mart_contract": workflow_validator(
                    "Checks mart contract columns.",
                    "schema",
                ),
                "mart_governance": workflow_validator(
                    "Checks that mart SQL excludes direct identifiers and test accounts.",
                    "sql",
                ),
                "mart_source_check": workflow_validator(
                    "Checks that the mart pipeline and SQL cover the required upstream sources.",
                    "pipeline",
                ),
                "mart_schema_shape_check": workflow_validator(
                    "Checks that the mart schema publishes the expected finance BI columns.",
                    "schema",
                ),
                "mart_pipeline_metadata_check": workflow_validator(
                    "Checks that the mart pipeline metadata is production-ready for finance scheduling.",
                    "pipeline",
                ),
                "mart_publish_contract_check": workflow_validator(
                    "Checks that the mart contract remains publishable for downstream BI consumers.",
                    "schema",
                ),
                "mart_consumer_shape_check": workflow_validator(
                    "Checks that the mart output shape is suitable for downstream dashboard consumption.",
                    "schema",
                ),
                "mart_schedule_check": workflow_validator(
                    "Checks that the mart pipeline metadata stays aligned with the daily finance schedule.",
                    "pipeline",
                ),
                "mart_delivery_shape_check": workflow_validator(
                    "Checks that the mart contract shape is ready for downstream finance delivery.",
                    "schema",
                ),
            },
        ),
        workflow_scenario(
            scenario_id="WS-004",
            developer_request=(
                "Create a new `finance_margin_watch` reporting asset for the control "
                "room. It should publish a daily SQL view, a schema contract, and an "
                "alert config that fires when margin drops sharply."
            ),
            workspace_summary=(
                "Control-room reporting assets pair warehouse views with lightweight "
                "alert configs so finance on-call can react to anomalies."
            ),
            known_files=[
                "sql/views/finance_daily_revenue.sql",
                "docs/reporting_view_standards.md",
                "docs/alerting_playbook.md",
                "alerts/examples/revenue_watch.yaml",
            ],
            editable_targets=[
                "sql/views/finance_margin_watch.sql",
                "schemas/views/finance_margin_watch.json",
                "alerts/finance_margin_watch.yaml",
            ],
            known_assets=[
                "invoice_line_items",
                "credit_memos_daily",
                "finance_margin_watch",
            ],
            available_validators=[
                "view_sql_check",
                "view_contract_check",
                "alert_config_check",
                "alert_severity_check",
                "view_monitoring_shape_check",
                "alert_dataset_check",
            ],
            files={
                "sql/views/finance_daily_revenue.sql": """select
    account_id,
    date(invoice_ts) as revenue_date,
    sum(net_revenue_usd) as net_revenue_usd
from invoice_line_items
group by 1, 2;
""",
                "docs/reporting_view_standards.md": """# Reporting view standards

- Reporting views must publish stable business columns.
- Views for control-room monitoring should expose a single daily grain.
- Schema contracts should list the published fields in order.
""",
                "docs/alerting_playbook.md": """# Alerting playbook

- Alert configs declare `name`, `dataset`, `metric`, `threshold`, and `severity`.
- Margin watch alerts should trigger when `margin_delta_pct` falls below `-0.15`.
- Finance alerts use severity `high`.
""",
                "alerts/examples/revenue_watch.yaml": """name: finance_revenue_watch
dataset: finance_daily_revenue
metric: net_revenue_usd
threshold: -0.1
severity: medium
""",
            },
            schema_registry={
                "invoice_line_items": """asset: invoice_line_items
columns:
  - account_id: string
  - invoice_ts: timestamp
  - net_revenue_usd: float
  - margin_usd: float
""",
                "credit_memos_daily": """asset: credit_memos_daily
columns:
  - account_id: string
  - credit_memo_date: date
  - credit_amount_usd: float
""",
                "finance_margin_watch": """asset: finance_margin_watch
required_columns:
  - account_id
  - margin_date
  - margin_usd
  - margin_delta_pct
""",
            },
            workflow_target={
                "required_artifacts": ["sql", "schema", "alert_config"],
                "artifacts": {
                    "sql": workflow_artifact(
                        "sql/views/finance_margin_watch.sql",
                        [
                            ["invoice_line_items"],
                            ["credit_memos_daily"],
                            ["margin_date"],
                            ["margin_usd"],
                            ["margin_delta_pct"],
                        ],
                        0.45,
                        forbidden_terms=["email", "phone", "full_name"],
                    ),
                    "schema": workflow_artifact(
                        "schemas/views/finance_margin_watch.json",
                        [["account_id"], ["margin_date"], ["margin_usd"], ["margin_delta_pct"]],
                        0.2,
                        forbidden_terms=["email", "phone", "full_name"],
                    ),
                    "alert_config": workflow_artifact(
                        "alerts/finance_margin_watch.yaml",
                        [
                            ["finance_margin_watch"],
                            ["margin_delta_pct"],
                            ["-0.15"],
                            ["high"],
                        ],
                        0.35,
                    ),
                },
                "investigation_targets": [
                    ("read_file", "sql/views/finance_daily_revenue.sql"),
                    ("read_file", "docs/reporting_view_standards.md"),
                    ("read_file", "docs/alerting_playbook.md"),
                    ("read_file", "alerts/examples/revenue_watch.yaml"),
                    ("inspect_schema", "invoice_line_items"),
                ],
                "summary_groups": [["finance_margin_watch"], ["alert"], ["margin_delta_pct"]],
                "solve_validator_targets": ["view_sql_check", "view_contract_check"],
                "validator_targets": [
                    "view_sql_check",
                    "view_contract_check",
                    "alert_config_check",
                    "alert_severity_check",
                    "view_monitoring_shape_check",
                    "alert_dataset_check",
                    "alert_threshold_shape_check",
                    "view_alert_contract_check",
                ],
                "forbidden_terms": ["email", "phone", "full_name"],
            },
            validators={
                "view_sql_check": workflow_validator(
                    "Checks that the margin watch SQL publishes the expected daily fields.",
                    "sql",
                ),
                "view_contract_check": workflow_validator(
                    "Checks that the margin watch contract publishes the expected columns.",
                    "schema",
                ),
                "alert_config_check": workflow_validator(
                    "Checks that the alert config targets the correct dataset, metric, and threshold.",
                    "alert_config",
                ),
                "alert_severity_check": workflow_validator(
                    "Checks that the alert config preserves the intended severity and threshold semantics.",
                    "alert_config",
                ),
                "view_monitoring_shape_check": workflow_validator(
                    "Checks that the monitoring schema exposes the expected daily margin-watch columns.",
                    "schema",
                ),
                "alert_dataset_check": workflow_validator(
                    "Checks that the alert config stays aligned with the intended monitoring dataset shape.",
                    "alert_config",
                ),
                "alert_threshold_shape_check": workflow_validator(
                    "Checks that the alert threshold configuration preserves the intended monitoring shape.",
                    "alert_config",
                ),
                "view_alert_contract_check": workflow_validator(
                    "Checks that the reporting schema and alert contract remain aligned for monitoring delivery.",
                    "schema",
                ),
            },
        ),
    ],
    "simulation_workflow": [
        simulation_scenario(
            scenario_id="SIM-E001",
            developer_request=(
                "Create the simplest possible daily signup report from this CSV. "
                "Stage the file, load it into DuckDB, and publish a final daily report view."
            ),
            workspace_summary=(
                "This is the easiest curriculum workspace. Build a tiny pipeline that only counts signups per day. "
                "The same four workflow files exist, but the SQL should stay very small."
            ),
            source_csv_path="data/daily_signups.csv",
            source_csv_content="""signup_id,signup_date,channel
S001,2026-04-01,organic
S002,2026-04-01,paid
S003,2026-04-02,organic
S004,2026-04-02,referral
""",
            raw_table="raw_daily_signups",
            staged_view="staged_daily_signups",
            build_table="daily_signup_counts",
            final_view="daily_signup_report",
            raw_asset="raw.daily_signups_csv",
            final_asset="mart.daily_signup_report",
            date_column="signup_date",
            raw_schema_columns=[
                ("signup_id", "string"),
                ("signup_date", "date"),
                ("channel", "string"),
            ],
            required_output_columns=[
                "signup_date",
                "signup_count",
            ],
            build_metric_groups=[
                ["count(*) as signup_count", "count(*) signup_count"],
            ],
            report_terms=["daily_signup_report", "DuckDB", "signup_count"],
            correct_load_sql="""create or replace view staged_daily_signups as
select
  signup_id,
  cast(signup_date as date) as signup_date,
  channel
from raw_daily_signups;
""",
            correct_build_sql="""create or replace table daily_signup_counts as
select
  signup_date,
  count(*) as signup_count
from staged_daily_signups
group by 1;
""",
            correct_report_sql="""create or replace view daily_signup_report as
select
  signup_date,
  signup_count
from daily_signup_counts;
""",
            expected_raw_preview=[
                {"signup_id": "S001", "signup_date": "2026-04-01", "channel": "organic"},
                {"signup_id": "S002", "signup_date": "2026-04-01", "channel": "paid"},
            ],
            expected_derived_preview=[
                {"signup_date": "2026-04-01", "signup_count": 2},
            ],
            expected_final_preview=[
                {"signup_date": "2026-04-02", "signup_count": 2},
            ],
        ),
        simulation_scenario(
            scenario_id="SIM-E002",
            developer_request=(
                "Repair this tiny signup report workflow. The pipeline is almost correct, but the final report view "
                "does not match the expected contract."
            ),
            workspace_summary=(
                "This is the easiest repair curriculum workspace. Almost everything is correct already; "
                "Fixer only needs to repair the final view so the runtime and schema checks pass."
            ),
            source_csv_path="data/daily_signups.csv",
            source_csv_content="""signup_id,signup_date,channel
S001,2026-04-01,organic
S002,2026-04-01,paid
S003,2026-04-02,organic
S004,2026-04-02,referral
""",
            raw_table="raw_daily_signups",
            staged_view="staged_daily_signups",
            build_table="daily_signup_counts",
            final_view="daily_signup_report",
            raw_asset="raw.daily_signups_csv",
            final_asset="mart.daily_signup_report",
            date_column="signup_date",
            raw_schema_columns=[
                ("signup_id", "string"),
                ("signup_date", "date"),
                ("channel", "string"),
            ],
            required_output_columns=[
                "signup_date",
                "signup_count",
            ],
            build_metric_groups=[
                ["count(*) as signup_count", "count(*) signup_count"],
            ],
            report_terms=["daily_signup_report", "DuckDB", "signup_count"],
            correct_load_sql="""create or replace view staged_daily_signups as
select
  signup_id,
  cast(signup_date as date) as signup_date,
  channel
from raw_daily_signups;
""",
            correct_build_sql="""create or replace table daily_signup_counts as
select
  signup_date,
  count(*) as signup_count
from staged_daily_signups
group by 1;
""",
            correct_report_sql="""create or replace view daily_signup_report as
select
  signup_date,
  signup_count
from daily_signup_counts;
""",
            starter_files={
                "pipelines/report_job.yaml": """name: daily_signup_report_job
storage_path: mock_s3/staged/daily_signups.csv
raw_table: raw_daily_signups
load_sql: sql/load_raw.sql
build_sql: sql/build_table.sql
report_sql: sql/report_view.sql
final_view: daily_signup_report
""",
                "sql/load_raw.sql": """create or replace view staged_daily_signups as
select
  signup_id,
  cast(signup_date as date) as signup_date,
  channel
from raw_daily_signups;
""",
                "sql/build_table.sql": """create or replace table daily_signup_counts as
select
  signup_date,
  count(*) as signup_count
from staged_daily_signups
group by 1;
""",
                "sql/report_view.sql": """create or replace view daily_signup_report as
select
  signup_date,
  signup_count as signups
from daily_signup_counts;
""",
            },
            expected_raw_preview=[
                {"signup_id": "S001", "signup_date": "2026-04-01", "channel": "organic"},
                {"signup_id": "S002", "signup_date": "2026-04-01", "channel": "paid"},
            ],
            expected_derived_preview=[
                {"signup_date": "2026-04-01", "signup_count": 2},
            ],
            expected_final_preview=[
                {"signup_date": "2026-04-02", "signup_count": 2},
            ],
        ),
        simulation_scenario(
            scenario_id="SIM-001",
            developer_request=(
                "Create a customer daily report from this sales-order CSV. The workflow "
                "should stage the raw data, load it into the warehouse, and publish a queryable report view."
            ),
            workspace_summary=(
                "This experimental workspace simulates a tiny data platform. Generate the "
                "pipeline YAML and SQL needed to stage the CSV into mock S3, load it into "
                "DuckDB, build a customer summary table, and publish the final report view. "
                "Builder starts with an empty workspace; Fixer repairs after runtime failures."
            ),
            source_csv_path="data/sales_orders.csv",
            source_csv_content="""order_id,customer_id,order_date,product_category,quantity,unit_price
1001,C001,2026-04-01,books,2,15.00
1002,C001,2026-04-01,games,1,25.00
1003,C002,2026-04-02,books,3,12.50
1004,C003,2026-04-02,gadgets,1,99.99
1005,C002,2026-04-03,games,2,30.00
""",
            raw_table="raw_sales_orders",
            staged_view="staged_sales_orders",
            build_table="customer_summary",
            final_view="customer_daily_report",
            raw_asset="raw.sales_orders_csv",
            final_asset="mart.customer_daily_report",
            date_column="order_date",
            raw_schema_columns=[
                ("order_id", "string"),
                ("customer_id", "string"),
                ("order_date", "date"),
                ("product_category", "string"),
                ("quantity", "integer"),
                ("unit_price", "float"),
            ],
            required_output_columns=[
                "customer_id",
                "order_date",
                "order_count",
                "gross_revenue_usd",
            ],
            build_metric_groups=[
                ["quantity * unit_price", "unit_price * quantity"],
                ["order_count"],
                ["gross_revenue_usd"],
            ],
            report_terms=["customer_daily_report", "DuckDB", "warehouse"],
            correct_load_sql="""create or replace view staged_sales_orders as
select
  order_id,
  customer_id,
  cast(order_date as date) as order_date,
  quantity,
  unit_price
from raw_sales_orders;
""",
            correct_build_sql="""create or replace table customer_summary as
select
  customer_id,
  order_date,
  count(*) as order_count,
  sum(quantity * unit_price) as gross_revenue_usd
from staged_sales_orders
group by 1, 2;
""",
            correct_report_sql="""create or replace view customer_daily_report as
select
  customer_id,
  order_date,
  order_count,
  gross_revenue_usd
from customer_summary;
""",
            expected_raw_preview=[
                {"order_id": "1001", "customer_id": "C001", "order_date": "2026-04-01"},
                {"order_id": "1002", "customer_id": "C001", "order_date": "2026-04-01"},
            ],
            expected_derived_preview=[
                {"customer_id": "C001", "order_date": "2026-04-01", "order_count": 2},
            ],
            expected_final_preview=[
                {"customer_id": "C001", "order_date": "2026-04-01", "gross_revenue_usd": 55.0},
            ],
        ),
        simulation_scenario(
            scenario_id="SIM-002",
            developer_request=(
                "Generate a plan-tier daily subscription report from this events CSV. "
                "The pipeline should stage the file, load it into the warehouse, and publish a final daily report."
            ),
            workspace_summary=(
                "Build a small DuckDB workflow that turns subscription events into a daily "
                "subscription report grouped by plan tier and date."
            ),
            source_csv_path="data/subscription_events.csv",
            source_csv_content="""event_id,account_id,event_date,plan_tier,event_type
E001,A100,2026-04-01,pro,started
E002,A101,2026-04-01,basic,started
E003,A100,2026-04-02,pro,cancelled
E004,A102,2026-04-02,pro,started
E005,A103,2026-04-02,basic,started
E006,A101,2026-04-03,basic,cancelled
""",
            raw_table="raw_subscription_events",
            staged_view="staged_subscription_events",
            build_table="subscription_daily_metrics",
            final_view="subscription_daily_report",
            raw_asset="raw.subscription_events_csv",
            final_asset="mart.subscription_daily_report",
            date_column="event_date",
            raw_schema_columns=[
                ("event_id", "string"),
                ("account_id", "string"),
                ("event_date", "date"),
                ("plan_tier", "string"),
                ("event_type", "string"),
            ],
            required_output_columns=[
                "plan_tier",
                "event_date",
                "new_subscriptions",
                "cancelled_subscriptions",
                "net_subscriptions",
            ],
            build_metric_groups=[
                ["event_type = 'started'", "event_type='started'"],
                ["event_type = 'cancelled'", "event_type='cancelled'"],
                ["net_subscriptions"],
            ],
            report_terms=["subscription_daily_report", "DuckDB", "plan_tier"],
            correct_load_sql="""create or replace view staged_subscription_events as
select
  event_id,
  account_id,
  cast(event_date as date) as event_date,
  plan_tier,
  lower(event_type) as event_type
from raw_subscription_events;
""",
            correct_build_sql="""create or replace table subscription_daily_metrics as
select
  plan_tier,
  event_date,
  sum(case when event_type = 'started' then 1 else 0 end) as new_subscriptions,
  sum(case when event_type = 'cancelled' then 1 else 0 end) as cancelled_subscriptions,
  sum(case when event_type = 'started' then 1 else 0 end) - sum(case when event_type = 'cancelled' then 1 else 0 end) as net_subscriptions
from staged_subscription_events
group by 1, 2;
""",
            correct_report_sql="""create or replace view subscription_daily_report as
select
  plan_tier,
  event_date,
  new_subscriptions,
  cancelled_subscriptions,
  net_subscriptions
from subscription_daily_metrics;
""",
            expected_raw_preview=[
                {"event_id": "E001", "plan_tier": "pro", "event_type": "started"},
                {"event_id": "E002", "plan_tier": "basic", "event_type": "started"},
            ],
            expected_derived_preview=[
                {"plan_tier": "basic", "event_date": "2026-04-01", "new_subscriptions": 1},
            ],
            expected_final_preview=[
                {"plan_tier": "pro", "event_date": "2026-04-02", "net_subscriptions": 0},
            ],
        ),
        simulation_scenario(
            scenario_id="SIM-003",
            developer_request=(
                "Create a warehouse-level inventory movement report from this CSV. "
                "Stage the file, load it into DuckDB, and publish a daily inventory view."
            ),
            workspace_summary=(
                "Generate a pipeline that turns inventory movement events into a daily "
                "warehouse inventory report with received, shipped, and net units."
            ),
            source_csv_path="data/inventory_movements.csv",
            source_csv_content="""movement_id,warehouse_id,movement_date,sku,movement_type,units
M001,W1,2026-04-01,SKU1,inbound,20
M002,W1,2026-04-01,SKU2,outbound,5
M003,W2,2026-04-01,SKU9,inbound,12
M004,W1,2026-04-02,SKU1,outbound,4
M005,W2,2026-04-02,SKU9,outbound,2
M006,W2,2026-04-02,SKU8,inbound,8
""",
            raw_table="raw_inventory_movements",
            staged_view="staged_inventory_movements",
            build_table="inventory_daily_balance",
            final_view="inventory_daily_report",
            raw_asset="raw.inventory_movements_csv",
            final_asset="mart.inventory_daily_report",
            date_column="movement_date",
            raw_schema_columns=[
                ("movement_id", "string"),
                ("warehouse_id", "string"),
                ("movement_date", "date"),
                ("sku", "string"),
                ("movement_type", "string"),
                ("units", "integer"),
            ],
            required_output_columns=[
                "warehouse_id",
                "movement_date",
                "received_units",
                "shipped_units",
                "net_units",
            ],
            build_metric_groups=[
                ["movement_type = 'inbound'", "movement_type='inbound'"],
                ["movement_type = 'outbound'", "movement_type='outbound'"],
                ["net_units"],
            ],
            report_terms=["inventory_daily_report", "DuckDB", "warehouse_id"],
            correct_load_sql="""create or replace view staged_inventory_movements as
select
  movement_id,
  warehouse_id,
  cast(movement_date as date) as movement_date,
  sku,
  lower(movement_type) as movement_type,
  units
from raw_inventory_movements;
""",
            correct_build_sql="""create or replace table inventory_daily_balance as
select
  warehouse_id,
  movement_date,
  sum(case when movement_type = 'inbound' then units else 0 end) as received_units,
  sum(case when movement_type = 'outbound' then units else 0 end) as shipped_units,
  sum(case when movement_type = 'inbound' then units else 0 end) - sum(case when movement_type = 'outbound' then units else 0 end) as net_units
from staged_inventory_movements
group by 1, 2;
""",
            correct_report_sql="""create or replace view inventory_daily_report as
select
  warehouse_id,
  movement_date,
  received_units,
  shipped_units,
  net_units
from inventory_daily_balance;
""",
            expected_raw_preview=[
                {"movement_id": "M001", "warehouse_id": "W1", "movement_type": "inbound"},
                {"movement_id": "M002", "warehouse_id": "W1", "movement_type": "outbound"},
            ],
            expected_derived_preview=[
                {"warehouse_id": "W1", "movement_date": "2026-04-01", "received_units": 20},
            ],
            expected_final_preview=[
                {"warehouse_id": "W2", "movement_date": "2026-04-02", "net_units": 6},
            ],
        ),
        simulation_scenario(
            scenario_id="SIM-004",
            developer_request=(
                "Repair the builder's broken customer-order pipeline so the staged CSV loads, "
                "the summary table builds correctly, and the final report contract stays intact."
            ),
            workspace_summary=(
                "Builder already generated a first pass of the customer report pipeline, but the "
                "runtime fails. Read the existing draft files, diagnose the SQL bug, and repair the workflow."
            ),
            source_csv_path="data/sales_orders.csv",
            source_csv_content="""order_id,customer_id,order_date,product_category,quantity,unit_price
2001,C010,2026-04-05,books,1,18.00
2002,C011,2026-04-05,gadgets,2,45.00
2003,C010,2026-04-06,games,1,35.00
2004,C012,2026-04-06,books,4,10.00
""",
            raw_table="raw_sales_orders",
            staged_view="staged_sales_orders",
            build_table="customer_summary",
            final_view="customer_daily_report",
            raw_asset="raw.sales_orders_csv",
            final_asset="mart.customer_daily_report",
            date_column="order_date",
            raw_schema_columns=[
                ("order_id", "string"),
                ("customer_id", "string"),
                ("order_date", "date"),
                ("product_category", "string"),
                ("quantity", "integer"),
                ("unit_price", "float"),
            ],
            required_output_columns=[
                "customer_id",
                "order_date",
                "order_count",
                "gross_revenue_usd",
            ],
            build_metric_groups=[
                ["quantity * unit_price", "unit_price * quantity"],
                ["gross_revenue_usd"],
            ],
            report_terms=["customer_daily_report", "DuckDB", "warehouse"],
            correct_load_sql="""create or replace view staged_sales_orders as
select
  order_id,
  customer_id,
  cast(order_date as date) as order_date,
  quantity,
  unit_price
from raw_sales_orders;
""",
            correct_build_sql="""create or replace table customer_summary as
select
  customer_id,
  order_date,
  count(*) as order_count,
  sum(quantity * unit_price) as gross_revenue_usd
from staged_sales_orders
group by 1, 2;
""",
            correct_report_sql="""create or replace view customer_daily_report as
select
  customer_id,
  order_date,
  order_count,
  gross_revenue_usd
from customer_summary;
""",
            starter_files={
                "pipelines/report_job.yaml": """name: customer_daily_report_job
storage_path: mock_s3/staged/sales_orders.csv
raw_table: raw_sales_orders
load_sql: sql/load_raw.sql
build_sql: sql/build_table.sql
report_sql: sql/report_view.sql
final_view: customer_daily_report
""",
                "sql/load_raw.sql": """create or replace view staged_sales_orders as
select
  order_id,
  customer_id,
  cast(order_date as date) as order_date,
  quantity,
  unit_price
from raw_sales_orders;
""",
                "sql/build_table.sql": """create or replace table customer_summary as
select
  customer_id,
  order_date,
  count(*) as order_count,
  sum(quantity * price) as gross_revenue_usd
from staged_sales_orders
group by 1, 2;
""",
                "sql/report_view.sql": """create or replace view customer_daily_report as
select
  customer_id,
  order_date,
  order_count,
  gross_revenue_usd
from customer_summary;
""",
            },
        ),
        simulation_scenario(
            scenario_id="SIM-005",
            developer_request=(
                "Fix this broken subscription reporting workflow. The builder used the right source CSV "
                "but the final pipeline no longer matches the expected report view contract."
            ),
            workspace_summary=(
                "A builder draft already exists for the subscription daily report. Repair the pipeline "
                "and SQL so the runtime publishes the intended final view and output columns."
            ),
            source_csv_path="data/subscription_events.csv",
            source_csv_content="""event_id,account_id,event_date,plan_tier,event_type
S001,A200,2026-04-07,pro,started
S002,A201,2026-04-07,basic,started
S003,A200,2026-04-08,pro,cancelled
S004,A202,2026-04-08,pro,started
""",
            raw_table="raw_subscription_events",
            staged_view="staged_subscription_events",
            build_table="subscription_daily_metrics",
            final_view="subscription_daily_report",
            raw_asset="raw.subscription_events_csv",
            final_asset="mart.subscription_daily_report",
            date_column="event_date",
            raw_schema_columns=[
                ("event_id", "string"),
                ("account_id", "string"),
                ("event_date", "date"),
                ("plan_tier", "string"),
                ("event_type", "string"),
            ],
            required_output_columns=[
                "plan_tier",
                "event_date",
                "new_subscriptions",
                "cancelled_subscriptions",
                "net_subscriptions",
            ],
            build_metric_groups=[
                ["event_type = 'started'", "event_type='started'"],
                ["event_type = 'cancelled'", "event_type='cancelled'"],
                ["net_subscriptions"],
            ],
            report_terms=["subscription_daily_report", "DuckDB", "plan_tier"],
            correct_load_sql="""create or replace view staged_subscription_events as
select
  event_id,
  account_id,
  cast(event_date as date) as event_date,
  plan_tier,
  lower(event_type) as event_type
from raw_subscription_events;
""",
            correct_build_sql="""create or replace table subscription_daily_metrics as
select
  plan_tier,
  event_date,
  sum(case when event_type = 'started' then 1 else 0 end) as new_subscriptions,
  sum(case when event_type = 'cancelled' then 1 else 0 end) as cancelled_subscriptions,
  sum(case when event_type = 'started' then 1 else 0 end) - sum(case when event_type = 'cancelled' then 1 else 0 end) as net_subscriptions
from staged_subscription_events
group by 1, 2;
""",
            correct_report_sql="""create or replace view subscription_daily_report as
select
  plan_tier,
  event_date,
  new_subscriptions,
  cancelled_subscriptions,
  net_subscriptions
from subscription_daily_metrics;
""",
            starter_files={
                "pipelines/report_job.yaml": """name: subscription_daily_report_job
storage_path: mock_s3/staged/subscription_events.csv
raw_table: raw_subscription_events
load_sql: sql/load_raw.sql
build_sql: sql/build_table.sql
report_sql: sql/report_view.sql
final_view: customer_daily_report
""",
                "sql/load_raw.sql": """create or replace view staged_subscription_events as
select
  event_id,
  account_id,
  cast(event_date as date) as event_date,
  plan_tier,
  lower(event_type) as event_type
from raw_subscription_events;
""",
                "sql/build_table.sql": """create or replace table subscription_daily_metrics as
select
  plan_tier,
  event_date,
  sum(case when event_type = 'started' then 1 else 0 end) as new_subscriptions,
  sum(case when event_type = 'cancelled' then 1 else 0 end) as cancelled_subscriptions,
  sum(case when event_type = 'started' then 1 else 0 end) - sum(case when event_type = 'cancelled' then 1 else 0 end) as net_subscriptions
from staged_subscription_events
group by 1, 2;
""",
                "sql/report_view.sql": """create or replace view customer_daily_report as
select
  plan_tier,
  event_date,
  new_subscriptions as started_subscriptions,
  cancelled_subscriptions,
  net_subscriptions
from subscription_daily_metrics;
""",
            },
        ),
        simulation_scenario(
            scenario_id="SIM-006",
            developer_request=(
                "Repair the inventory movement report. The current draft runs partway through, "
                "but the final report schema no longer matches the contract expected by downstream users."
            ),
            workspace_summary=(
                "You are in Fixer mode on an inventory reporting workflow. Read the broken draft "
                "and repair the output schema without changing the warehouse-level business meaning."
            ),
            source_csv_path="data/inventory_movements.csv",
            source_csv_content="""movement_id,warehouse_id,movement_date,sku,movement_type,units
I001,W5,2026-04-09,SKU1,inbound,15
I002,W5,2026-04-09,SKU2,outbound,3
I003,W6,2026-04-10,SKU8,inbound,10
I004,W6,2026-04-10,SKU8,outbound,4
""",
            raw_table="raw_inventory_movements",
            staged_view="staged_inventory_movements",
            build_table="inventory_daily_balance",
            final_view="inventory_daily_report",
            raw_asset="raw.inventory_movements_csv",
            final_asset="mart.inventory_daily_report",
            date_column="movement_date",
            raw_schema_columns=[
                ("movement_id", "string"),
                ("warehouse_id", "string"),
                ("movement_date", "date"),
                ("sku", "string"),
                ("movement_type", "string"),
                ("units", "integer"),
            ],
            required_output_columns=[
                "warehouse_id",
                "movement_date",
                "received_units",
                "shipped_units",
                "net_units",
            ],
            build_metric_groups=[
                ["movement_type = 'inbound'", "movement_type='inbound'"],
                ["movement_type = 'outbound'", "movement_type='outbound'"],
                ["net_units"],
            ],
            report_terms=["inventory_daily_report", "DuckDB", "warehouse_id"],
            correct_load_sql="""create or replace view staged_inventory_movements as
select
  movement_id,
  warehouse_id,
  cast(movement_date as date) as movement_date,
  sku,
  lower(movement_type) as movement_type,
  units
from raw_inventory_movements;
""",
            correct_build_sql="""create or replace table inventory_daily_balance as
select
  warehouse_id,
  movement_date,
  sum(case when movement_type = 'inbound' then units else 0 end) as received_units,
  sum(case when movement_type = 'outbound' then units else 0 end) as shipped_units,
  sum(case when movement_type = 'inbound' then units else 0 end) - sum(case when movement_type = 'outbound' then units else 0 end) as net_units
from staged_inventory_movements
group by 1, 2;
""",
            correct_report_sql="""create or replace view inventory_daily_report as
select
  warehouse_id,
  movement_date,
  received_units,
  shipped_units,
  net_units
from inventory_daily_balance;
""",
            starter_files={
                "pipelines/report_job.yaml": """name: inventory_daily_report_job
storage_path: mock_s3/staged/inventory_movements.csv
raw_table: raw_inventory_movements
load_sql: sql/load_raw.sql
build_sql: sql/build_table.sql
report_sql: sql/report_view.sql
final_view: inventory_daily_report
""",
                "sql/load_raw.sql": """create or replace view staged_inventory_movements as
select
  movement_id,
  warehouse_id,
  cast(movement_date as date) as movement_date,
  sku,
  lower(movement_type) as movement_type,
  units
from raw_inventory_movements;
""",
                "sql/build_table.sql": """create or replace table inventory_daily_balance as
select
  warehouse_id,
  movement_date,
  sum(case when movement_type = 'inbound' then units else 0 end) as received_units,
  sum(case when movement_type = 'outbound' then units else 0 end) as shipped_units,
  sum(case when movement_type = 'inbound' then units else 0 end) - sum(case when movement_type = 'outbound' then units else 0 end) as net_units
from staged_inventory_movements
group by 1, 2;
""",
                "sql/report_view.sql": """create or replace view inventory_daily_report as
select
  warehouse_id,
  movement_date,
  received_units as inbound_units,
  shipped_units as outbound_units,
  net_units
from inventory_daily_balance;
""",
            },
        ),
        simulation_scenario(
            scenario_id="SIM-007",
            developer_request=(
                "Builder already created an initial returns-report pipeline, but the runtime fails. "
                "Use the shared workspace to diagnose the failure and repair the pipeline so the final report view is queryable."
            ),
            workspace_summary=(
                "This shared Builder + Fixer workspace already contains a first-pass pipeline for a returns report. "
                "The builder draft stages the CSV and points the runtime at the right files, but one SQL artifact is broken. "
                "Fixer should use runtime feedback to repair the workflow and publish the expected report view."
            ),
            source_csv_path="data/returns_events.csv",
            source_csv_content="""return_id,customer_id,return_date,return_reason,refund_amount
R001,C300,2026-04-11,damaged,45.00
R002,C301,2026-04-11,wrong_item,30.00
R003,C300,2026-04-12,damaged,15.00
R004,C302,2026-04-12,late_delivery,22.50
R005,C301,2026-04-13,wrong_item,18.00
""",
            raw_table="raw_returns_events",
            staged_view="staged_returns_events",
            build_table="returns_daily_summary",
            final_view="returns_daily_report",
            raw_asset="raw.returns_events_csv",
            final_asset="mart.returns_daily_report",
            date_column="return_date",
            raw_schema_columns=[
                ("return_id", "string"),
                ("customer_id", "string"),
                ("return_date", "date"),
                ("return_reason", "string"),
                ("refund_amount", "float"),
            ],
            required_output_columns=[
                "return_reason",
                "return_date",
                "return_count",
                "refund_total_usd",
            ],
            build_metric_groups=[
                ["count(*) as return_count", "count(*) return_count"],
                ["sum(refund_amount) as refund_total_usd", "sum(refund_amount) refund_total_usd"],
            ],
            report_terms=["returns_daily_report", "DuckDB", "return_reason"],
            correct_load_sql="""create or replace view staged_returns_events as
select
  return_id,
  customer_id,
  cast(return_date as date) as return_date,
  return_reason,
  refund_amount
from raw_returns_events;
""",
            correct_build_sql="""create or replace table returns_daily_summary as
select
  return_reason,
  return_date,
  count(*) as return_count,
  sum(refund_amount) as refund_total_usd
from staged_returns_events
group by 1, 2;
""",
            correct_report_sql="""create or replace view returns_daily_report as
select
  return_reason,
  return_date,
  return_count,
  refund_total_usd
from returns_daily_summary;
""",
            starter_files={
                "pipelines/report_job.yaml": """name: returns_daily_report_job
storage_path: mock_s3/staged/returns_events.csv
raw_table: raw_returns_events
load_sql: sql/load_raw.sql
build_sql: sql/build_table.sql
report_sql: sql/report_view.sql
final_view: returns_daily_report
""",
                "sql/load_raw.sql": """create or replace view staged_returns_events as
select
  return_id,
  customer_id,
  cast(return_date as date) as return_date,
  return_reason,
  refund_amount
from raw_returns_events;
""",
                "sql/build_table.sql": """create or replace table returns_daily_summary as
select
  return_reason,
  returned_at,
  count(*) as return_count,
  sum(refund_amount) as refund_total_usd
from staged_returns_events
group by 1, 2;
""",
                "sql/report_view.sql": """create or replace view returns_daily_report as
select
  return_reason,
  return_date,
  return_count,
  refund_total_usd
from returns_daily_summary;
""",
            },
            expected_raw_preview=[
                {"return_id": "R001", "customer_id": "C300", "return_reason": "damaged"},
                {"return_id": "R002", "customer_id": "C301", "return_reason": "wrong_item"},
            ],
            expected_derived_preview=[
                {"return_reason": "damaged", "return_date": "2026-04-11", "return_count": 1},
            ],
            expected_final_preview=[
                {"return_reason": "wrong_item", "return_date": "2026-04-11", "refund_total_usd": 30.0},
            ],
        ),
    ],
}

SCENARIO_REGISTRY: dict[str, dict] = {
    scenario["scenario_id"]: scenario
    for scenario_group in SCENARIOS.values()
    for scenario in scenario_group
}


def _replace_text(value: str, mapping: dict[str, str]) -> str:
    rendered = value
    for old, new in mapping.items():
        rendered = rendered.replace(old, new)
    return rendered


def _replace_groups(groups: list[list[str]], mapping: dict[str, str]) -> list[list[str]]:
    return [[_replace_text(option, mapping) for option in group] for group in groups]


def _apply_variant_mapping(value: object, mapping: dict[str, str]) -> object:
    if isinstance(value, str):
        return _replace_text(value, mapping)
    if isinstance(value, list):
        return [_apply_variant_mapping(item, mapping) for item in value]
    if isinstance(value, dict):
        return {key: _apply_variant_mapping(item, mapping) for key, item in value.items()}
    return value


def _seed_variant_index(seed: int, count: int, salt: int) -> int:
    if count <= 0:
        return 0
    return abs(seed + salt) % count


def _apply_seeded_variant(scenario: dict, seed: int | None) -> dict:
    if seed is None:
        return scenario

    scenario_id = scenario.get("scenario_id", "")

    if scenario_id == "PR-005":
        variants = [
            {
                "env_key": "TARGET_WAREHOUSE_ROLE",
                "stale_key": "WAREHOUSE_ROLE",
                "role": "analytics_writer",
            },
            {
                "env_key": "TARGET_REPORTING_ROLE",
                "stale_key": "REPORTING_ROLE",
                "role": "reporting_writer",
            },
        ]
        variant = variants[_seed_variant_index(seed, len(variants), 5)]
        mapping = {
            "TARGET_WAREHOUSE_ROLE": variant["env_key"],
            "WAREHOUSE_ROLE": variant["stale_key"],
            "analytics_writer": variant["role"],
        }
        scenario = _apply_variant_mapping(scenario, mapping)
        scenario["developer_request"] = (
            f"{scenario['developer_request']} The packaged runner now expects `{variant['env_key']}` "
            f"with the `{variant['role']}` role."
        )
        return scenario

    if scenario_id == "PR-006":
        variants = [
            {"id_col": "customer_code"},
            {"id_col": "member_code"},
            {"id_col": "profile_code"},
        ]
        variant = variants[_seed_variant_index(seed, len(variants), 6)]
        mapping = {"customer_code": variant["id_col"]}
        scenario = _apply_variant_mapping(scenario, mapping)
        scenario["developer_request"] = (
            f"{scenario['developer_request']} The failing identifier column is `{variant['id_col']}`."
        )
        return scenario

    if scenario_id == "LR-003":
        variants = [
            {"metric": "mrr_usd", "replacement": "monthly_recurring_revenue_usd"},
            {"metric": "arr_usd", "replacement": "annual_recurring_revenue_usd"},
            {"metric": "net_revenue_usd", "replacement": "net_revenue_amount_usd"},
        ]
        variant = variants[_seed_variant_index(seed, len(variants), 3)]
        mapping = {
            "mrr_usd": variant["metric"],
            "monthly_recurring_revenue_usd": variant["replacement"],
        }
        scenario = _apply_variant_mapping(scenario, mapping)
        scenario["developer_request"] = (
            f"{scenario['developer_request']} The published metric under review is `{variant['metric']}`."
        )
        return scenario

    if scenario_id == "WS-004":
        variants = [
            {"metric": "margin_delta_pct", "threshold": "-0.15"},
            {"metric": "net_revenue_delta_pct", "threshold": "-0.12"},
        ]
        variant = variants[_seed_variant_index(seed, len(variants), 4)]
        mapping = {
            "margin_delta_pct": variant["metric"],
            "-0.15": variant["threshold"],
        }
        scenario = _apply_variant_mapping(scenario, mapping)
        scenario["developer_request"] = (
            f"{scenario['developer_request']} The alert should monitor `{variant['metric']}` "
            f"and fire below `{variant['threshold']}`."
        )
        return scenario

    return scenario


def scenario_count(task_id: str) -> int:
    task = TASK_DEFINITIONS.get(task_id)
    if not task:
        raise ValueError(f"Unknown task_id '{task_id}'")
    return len(task.get("scenario_ids", []))


def get_task(task_id: str) -> dict:
    if task_id not in TASK_DEFINITIONS:
        raise ValueError(f"Unknown task_id '{task_id}'")
    task = deepcopy(TASK_DEFINITIONS[task_id])
    task["scenarios"] = scenario_count(task_id)
    return task


def get_scenario(task_id: str, index: int = 0, seed: int | None = None) -> dict:
    task = TASK_DEFINITIONS.get(task_id)
    if not task:
        raise ValueError(f"Unknown task_id '{task_id}'")
    scenario_ids = task.get("scenario_ids", [])
    if index < 0 or index >= len(scenario_ids):
        raise ValueError(
            f"Scenario index {index} out of range for task '{task_id}' "
            f"(available: 0-{len(scenario_ids) - 1})"
        )
    scenario_id = scenario_ids[index]
    scenario = deepcopy(SCENARIO_REGISTRY[scenario_id])
    return _apply_seeded_variant(scenario, seed)


def get_grader_family(task_id: str) -> str:
    task = TASK_DEFINITIONS.get(task_id)
    if task is None:
        raise ValueError(f"Unknown task_id '{task_id}'")
    return str(task.get("grader_family", ""))


def list_tasks() -> list[dict]:
    return [get_task(task_id) for task_id in TASK_DEFINITIONS]