redact-secret 0.1.0-beta.15

Deterministic secret detection and redaction for runtime data and AI context: scans text locally before it reaches logs, storage, telemetry, tools, or model context. Side-effect free: no runtime network, filesystem, environment, telemetry, secret storage, or UI.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
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
//! Stripe, `PyPI`, Hugging Face, Docker, `DigitalOcean`, Supabase, npm,
//! Google, Grafana Cloud, and Pulumi access token detection.
//!
//! Mirrors the retired `src/detectors/additional-providers.ts` oracle. Every
//! one of these providers reduces to the same shape as [`super::gitlab`] or
//! [`super::anthropic`] — a documented literal prefix set, each prefix
//! followed by a fixed- or minimum-length run of a documented alphabet, an
//! optional post-hoc check, and the finding signals a match carries — so
//! they share one generic, table-driven [`Detector`] implementation instead
//! of one bespoke type each. [`super::cloudflare`] and [`super::linear`] are
//! this same detector: a [`PrefixShape`]'s alphabet, signals, and
//! [`pattern::PostCheck`] are each carried per shape, not per detector, so
//! Cloudflare's checksum-shaped tail and Linear's two differently-alphabet'd
//! prefixes are both expressible as data, matched in one left-to-right,
//! longest-prefix-wins pass. [`super::slack`] is the one exception: its
//! `xoxb-` bot prefix needs a `-`-separated section grammar no
//! [`PrefixShape`] can express, so it stays a bespoke `Detector`; its other
//! prefixes keep this same "prefix plus a minimum-length run" shape as an
//! interim guard, merged with the bot scan's results by position.

use crate::detectors::pattern::{self, Alphabet, PrefixShape};
use crate::error::DetectorFailure;
use crate::types::{ByteRange, Candidate, Confidence, Detector, DetectorContext, Specificity};

/// A detector defined purely by a table of [`PrefixShape`]s (each carrying
/// its own alphabet and finding signals) and a shared boundary alphabet.
pub(super) struct KnownFormatProviderDetector {
    id: &'static str,
    type_name: &'static str,
    shapes: &'static [PrefixShape<'static>],
    boundary: Alphabet,
}

impl KnownFormatProviderDetector {
    /// Constructs a detector from its table, for use by sibling detector
    /// modules ([`super::cloudflare`], [`super::linear`]) whose own reviewed
    /// contract is this same shape.
    pub(super) const fn new(
        id: &'static str,
        type_name: &'static str,
        shapes: &'static [PrefixShape<'static>],
        boundary: Alphabet,
    ) -> Self {
        Self {
            id,
            type_name,
            shapes,
            boundary,
        }
    }

    /// [`Detector::id`], usable in a `const`.
    pub(super) const fn detector_id(&self) -> &'static str {
        self.id
    }

    /// The shape table. Every candidate starts with one of its prefixes, so
    /// they are this detector's literals for the shared prefilter
    /// (`super::prefilter`, issue #983).
    pub(super) const fn shapes(&self) -> &'static [PrefixShape<'static>] {
        self.shapes
    }
}

impl Detector for KnownFormatProviderDetector {
    fn id(&self) -> &str {
        self.id
    }

    fn detect(
        &self,
        input: &str,
        _context: &DetectorContext,
    ) -> Result<Vec<Candidate>, DetectorFailure> {
        let mut candidates = Vec::new();
        for (start, end, signals) in
            pattern::scan_prefixed_shapes(input, self.shapes, self.boundary)
        {
            let Some(range) = ByteRange::new(start, end) else {
                continue;
            };
            candidates.push(
                Candidate::built_in(self.type_name, Confidence::High, range)
                    .with_specificity(Specificity::Provider)
                    .with_signals(signals.iter().copied()),
            );
        }
        Ok(candidates)
    }
}

/// A [`KnownFormatProviderDetector`] whose shapes each report their own
/// finding type, for one provider that documents several credential roles
/// with distinct prefixes (issue #860: Trigger.dev, `PostHog`, Helicone,
/// Composio). `types[i]` is the finding type of `shapes[i]`.
///
/// The scan is the same single left-to-right, longest-prefix-wins pass; a
/// match's type is that of the shape the scan selected at its start, which is
/// the longest prefix that matches there, so it is recovered without a second
/// pass. The same model as `github-token`'s one-detector, many-types table.
pub(super) struct TypedKnownFormatProviderDetector {
    id: &'static str,
    shapes: &'static [PrefixShape<'static>],
    types: &'static [&'static str],
    boundary: Alphabet,
}

impl TypedKnownFormatProviderDetector {
    /// Constructs a detector from parallel shape and finding-type tables.
    pub(super) const fn new(
        id: &'static str,
        shapes: &'static [PrefixShape<'static>],
        types: &'static [&'static str],
        boundary: Alphabet,
    ) -> Self {
        assert!(shapes.len() == types.len());
        Self {
            id,
            shapes,
            types,
            boundary,
        }
    }

    /// [`Detector::id`], usable in a `const`.
    pub(super) const fn detector_id(&self) -> &'static str {
        self.id
    }

    /// The shape table, as [`KnownFormatProviderDetector::shapes`].
    pub(super) const fn shapes(&self) -> &'static [PrefixShape<'static>] {
        self.shapes
    }

    /// The finding type of the shape the scan selected at `start`.
    fn type_at(&self, bytes: &[u8], start: usize) -> Option<&'static str> {
        self.shapes
            .iter()
            .zip(self.types)
            .filter(|(shape, _)| bytes[start..].starts_with(shape.prefix.as_bytes()))
            .max_by_key(|(shape, _)| shape.prefix.len())
            .map(|(_, type_name)| *type_name)
    }
}

impl Detector for TypedKnownFormatProviderDetector {
    fn id(&self) -> &str {
        self.id
    }

    fn detect(
        &self,
        input: &str,
        _context: &DetectorContext,
    ) -> Result<Vec<Candidate>, DetectorFailure> {
        let bytes = input.as_bytes();
        let mut candidates = Vec::new();
        for (start, end, signals) in
            pattern::scan_prefixed_shapes(input, self.shapes, self.boundary)
        {
            let (Some(range), Some(type_name)) =
                (ByteRange::new(start, end), self.type_at(bytes, start))
            else {
                continue;
            };
            candidates.push(
                Candidate::built_in(type_name, Confidence::High, range)
                    .with_specificity(Specificity::Provider)
                    .with_signals(signals.iter().copied()),
            );
        }
        Ok(candidates)
    }
}

/// Stripe secret, restricted, organization, and webhook-signing
/// credentials. The suffix alphabet is `[A-Za-z0-9]` — narrower than the
/// `[A-Za-z0-9_-]` boundary — so a trailing `_` or `-` still rejects a
/// truncated candidate. The publishable-key prefix (`pk_live_`,
/// `pk_test_`) is deliberately excluded: Stripe's own key-types table
/// (<https://docs.stripe.com/keys>, observed 2026-09-20) marks `pk_...` as
/// "Safe to expose" — the only key type it does — so treating it as a match
/// would be a false positive by the provider's own classification, not
/// merely a naming convention this project inferred.
///
/// Issue #513 completes the family with `sk_org_` and `whsec_`, each on a
/// narrower evidence bar than `sk_`/`rk_`'s: gitleaks' `stripe-access-token`
/// rule (`(?:sk|rk)_(?:test|live|prod)_[a-zA-Z0-9]{10,99}`) and trufflehog's
/// `stripe` detector (`[rs]k_live_[a-zA-Z0-9]{20,247}`) corroborate `sk_`
/// and `rk_`'s `live`/`test` segments, but neither tool has a rule for
/// `sk_org_` or `whsec_` — both are adopted on provider documentation alone
/// (T1, prefix only; the 20-byte floor below is this family's existing
/// support-policy choice, not independently evidenced for these two
/// prefixes):
///
/// - `sk_org_` — the same key-types table documents an "Organization API
///   key `sk_org_...`", "Safe to expose: No", same secret handling as an
///   account-level secret or restricted key
///   (<https://docs.stripe.com/keys>, observed 2026-09-20).
///   `docs.stripe.com/keys/organization-api-keys` (observed 2026-09-20)
///   states the prefix precisely — "Organization API keys are prefixed
///   `sk_org`" — and, as a direct evidenced negative, that there is **no**
///   `rk_org_` counterpart: "All organization API keys have the same
///   `sk_org` prefix, regardless of their permission levels. (There's no
///   `rk_org` prefix.)" That page also states organization keys "support
///   sandboxes and live mode", but shows no literal example. Issue #1030
///   (research #1012, verdict BLOCKED, no issuance evidence) records that
///   two independent implementations branch on `sk_org_live_` and
///   `sk_org_test_`, so the shape also claims those two mode-segment
///   prefixes with the same 20-byte `[A-Za-z0-9]` floor, at the same
///   docs-plus-independent-implementation support-policy evidence level and
///   never above it. The body length and alphabet after the mode segment are
///   unverified, and a mode segment shorter or longer than `live`/`test` is
///   not claimed. `sk_org_` + one opaque run stays as before. Longest prefix
///   wins, so `sk_org_live_` is never read as `sk_org_` plus a short run.
///   gitleaks' own environment enumeration additionally includes `prod`
///   (`sk_prod_`/`rk_prod_`), which no Stripe page documents for any key
///   type; adopting it is out of this issue's scope and is left unadded.
/// - `whsec_` — moved out of this table by issue #729 into its own
///   `stripe_webhook_signing_secret` grammar in [`super::stripe`], because
///   Stripe states webhook signing secrets are "per-webhook secrets",
///   separate from API keys (<https://docs.stripe.com/webhooks>, observed
///   2026-09-20). The 20-byte alnum floor recorded here for #513 no longer
///   applies to it.
const STRIPE_SIGNALS: [&str; 2] = ["stripe-documented-prefix", "opaque-suffix"];

pub(super) const STRIPE: KnownFormatProviderDetector = KnownFormatProviderDetector {
    id: "stripe-token",
    type_name: "stripe_credential",
    shapes: &[
        PrefixShape::at_least("sk_test_", 20, pattern::is_alnum, &STRIPE_SIGNALS),
        PrefixShape::at_least("sk_live_", 20, pattern::is_alnum, &STRIPE_SIGNALS),
        PrefixShape::at_least("rk_test_", 20, pattern::is_alnum, &STRIPE_SIGNALS),
        PrefixShape::at_least("rk_live_", 20, pattern::is_alnum, &STRIPE_SIGNALS),
        PrefixShape::at_least("sk_org_", 20, pattern::is_alnum, &STRIPE_SIGNALS),
        PrefixShape::at_least("sk_org_live_", 20, pattern::is_alnum, &STRIPE_SIGNALS),
        PrefixShape::at_least("sk_org_test_", 20, pattern::is_alnum, &STRIPE_SIGNALS),
    ],
    boundary: pattern::is_alnum_dash,
};

/// `PyPI`'s documented Macaroon serialization with its exact minimum
/// suffix. The prefix is matched case-sensitively (lowercase `pypi-`
/// only) and the 85-byte minimum favors precision: a shorter or
/// differently-cased example is an intentional false negative rather than
/// a loosened match.
const PYPI_SIGNALS: [&str; 2] = ["pypi-documented-prefix", "macaroon-minimum-length"];

pub(super) const PYPI: KnownFormatProviderDetector = KnownFormatProviderDetector {
    id: "pypi-token",
    type_name: "pypi_api_token",
    shapes: &[PrefixShape::at_least(
        "pypi-",
        85,
        pattern::is_alnum_dash,
        &PYPI_SIGNALS,
    )],
    boundary: pattern::is_alnum_dash,
};

/// Hugging Face user access tokens in the provider's `hf_` namespace: the
/// reviewed grammar (issue #372, following the frozen precision contract
/// from issue #367, `docs/contracts/precision/precision-contracts.json`) is
/// `hf_` plus an exact 34-byte body, matched to the union alphabet
/// `[A-Za-z0-9]`. gitleaks 8.30.1 and trufflehog 3.97.4 independently agree
/// on the 34-byte exact length, so a body one byte short is an intentional
/// false negative; they disagree on the body alphabet (gitleaks: letters
/// only; trufflehog: letters and digits), resolved as a support-policy
/// choice for the union rather than the letters-only intersection, so a
/// digit-bearing body is accepted even though it stays unscored (T0) in the
/// benchmark corpus pending independent review. Both tools agree the body
/// excludes `_`/`-`, an evidence-backed exclusion rather than merely a
/// length shortfall. A dash in place of the documented underscore prefix, or
/// any other undocumented prefix, is an intentional false negative.
///
/// Hugging Face organization API tokens in the `api_org_` namespace (issue
/// #485, re-tiering `docs/contracts/precision/precision-contracts.json`,
/// `families.huggingface-token.pending.organization-token` from T0 to T2):
/// the #367 audit deferred `api_org_` not for an evidence gap but as a scope
/// boundary ("adding a variant is a coverage change, not a precision fix"),
/// while the evidence itself already matched the `hf_` variant's own T2
/// bar. gitleaks 8.30.1 registers `api_org_` as its own
/// `huggingface-organization-api-token` rule (34-byte letters-only body) and
/// trufflehog 3.97.4 matches both `hf_` and `api_org_` under one
/// `(?:hf_|api_org_)[a-zA-Z0-9]{34}` rule — the identical dual-tool,
/// 34-byte-exact-length agreement, and the identical gitleaks/trufflehog
/// letters-only-vs-union alphabet conflict, that already ties `hf_`'s own
/// length and alphabet to "tool-agreement" and "support-policy" rather than
/// provider documentation. No Hugging Face page documents `api_org_`'s
/// grammar, but none documents `hf_`'s length or alphabet either — only its
/// bare prefix, as a placeholder. `api_org_` is therefore adopted as a
/// second [`PrefixShape`] over `hf_`'s identical body grammar, not new
/// matching logic, and the alphabet conflict is resolved identically (union
/// `[A-Za-z0-9]`, support-policy).
const HUGGING_FACE_SIGNALS: [&str; 2] = ["huggingface-documented-prefix", "base62-exact-length"];
const HUGGING_FACE_ORGANIZATION_SIGNALS: [&str; 2] = [
    "huggingface-organization-documented-prefix",
    "base62-exact-length",
];

pub(super) const HUGGING_FACE: KnownFormatProviderDetector = KnownFormatProviderDetector {
    id: "huggingface-token",
    type_name: "huggingface_token",
    shapes: &[
        PrefixShape::exact("hf_", 34, pattern::is_alnum, &HUGGING_FACE_SIGNALS),
        PrefixShape::exact(
            "api_org_",
            34,
            pattern::is_alnum,
            &HUGGING_FACE_ORGANIZATION_SIGNALS,
        ),
    ],
    boundary: pattern::is_alnum_dash,
};

/// Docker Hub personal (`dckr_pat_`) and organization (`dckr_oat_`) access
/// tokens, validated as separately-sized exact-length shapes (issue #370,
/// `decision-freeze-precision-contracts-seven-provider-families`, Docker row;
/// the second OAT width is issue #708):
///
/// ```text
/// dckr_pat_<27 bytes from [A-Za-z0-9_-]>        (36 bytes total)
/// dckr_oat_<27 or 32 bytes from [A-Za-z0-9_-]>  (36 or 41 bytes total)
/// ```
///
/// Docker's own Hub API reference shows an organization access token with a
/// 27-byte body. The 32-byte width comes from trufflehog only, so both
/// widths are accepted under `dckr_oat_` (#708). Every other length is an
/// intentional false negative rather than a fuzzy match: a 26- or 28-byte
/// suffix after `dckr_pat_`, anything other than 27 or 32 bytes after
/// `dckr_oat_`, or the 32-byte OAT width under the PAT prefix. This follows
/// the same exact-length precedent `npm-token` and `google-api-key` below
/// already set. Only the two
/// documented segment names are matched; an undocumented segment name is an
/// intentional false negative, and legacy Docker Hub passwords (which carry
/// no distinguishing prefix at all) are out of scope for this detector.
const DOCKER_SIGNALS: [&str; 2] = ["docker-documented-prefix", "exact-length-suffix"];

pub(super) const DOCKER: KnownFormatProviderDetector = KnownFormatProviderDetector {
    id: "docker-token",
    type_name: "docker_token",
    shapes: &[
        PrefixShape::exact(
            "dckr_pat_",
            DOCKER_PAT_SUFFIX_LEN,
            pattern::is_alnum_dash,
            &DOCKER_SIGNALS,
        ),
        PrefixShape::one_of(
            "dckr_oat_",
            &DOCKER_OAT_SUFFIX_LENS,
            pattern::is_alnum_dash,
            &DOCKER_SIGNALS,
        ),
    ],
    boundary: pattern::is_alnum_dash,
};

/// The exact suffix length after `dckr_pat_`.
pub(super) const DOCKER_PAT_SUFFIX_LEN: usize = 27;
/// The longer exact suffix length after `dckr_oat_` (trufflehog-corroborated).
pub(super) const DOCKER_OAT_SUFFIX_LEN: usize = 32;
/// Every exact suffix length accepted after `dckr_oat_`: the provider's own
/// 27-byte example width (issue #708) and the 32-byte width.
pub(super) const DOCKER_OAT_SUFFIX_LENS: [usize; 2] =
    [DOCKER_PAT_SUFFIX_LEN, DOCKER_OAT_SUFFIX_LEN];

/// `DigitalOcean` personal (`dop_v1_`), `OAuth` access (`doo_v1_`), and
/// `OAuth` refresh (`dor_v1_`) token families.
///
/// The reviewed contract (issue #369) is each documented prefix followed by
/// exactly 64 lowercase hexadecimal bytes. `DigitalOcean`'s API release
/// notes (2022-03-29) establish the three prefixes; gitleaks v8.30.1
/// (`digitalocean-pat`, `digitalocean-access-token`,
/// `digitalocean-refresh-token`) and trufflehog v3.97.4 (`digitaloceanv2`)
/// independently pin the body to `[a-f0-9]{64}`, and no reviewed source
/// shows any other length or alphabet. The earlier 20-byte `[A-Za-z0-9_-]`
/// minimum accepted a 63-byte twin of every paired positive; the exact run
/// rejects it, rejects a 65-byte or wider run outright (a token is never
/// carved out of a longer identifier), and rejects uppercase hex. gitleaks
/// alone matches `dor_v1_` case-insensitively; that is a tool convenience
/// with no provider evidence behind it, so all three prefixes stay
/// case-sensitive. Only the documented `v1` namespace is matched; a future
/// version bump (`dop_v2_` and siblings) is an intentional false negative
/// until that shape is confirmed and added.
const DIGITALOCEAN_SIGNALS: [&str; 2] =
    ["digitalocean-documented-prefix", "fixed-length-hex-suffix"];

pub(super) const DIGITALOCEAN: KnownFormatProviderDetector = KnownFormatProviderDetector {
    id: "digitalocean-token",
    type_name: "digitalocean_token",
    shapes: &[
        PrefixShape::exact("dop_v1_", 64, pattern::is_lower_hex, &DIGITALOCEAN_SIGNALS),
        PrefixShape::exact("doo_v1_", 64, pattern::is_lower_hex, &DIGITALOCEAN_SIGNALS),
        PrefixShape::exact("dor_v1_", 64, pattern::is_lower_hex, &DIGITALOCEAN_SIGNALS),
    ],
    boundary: pattern::is_alnum_dash,
};

/// Supabase elevated-access secret keys. The `sb_publishable_` prefix is
/// deliberately excluded — it names a public identifier, not a secret —
/// so classifying it would be a false positive; an undocumented prefix is
/// a false negative.
///
/// Issue #742: the body is the provider-documented layout, not an open
/// floor. Supabase's self-hosting key page
/// (<https://supabase.com/docs/guides/self-hosting/self-hosted-auth-keys>)
/// documents `sb_secret_<22-char-random>_<8-char-checksum>` and states that
/// hosted keys "use the same format as the platform"; the provider's
/// `docker/utils/add-new-auth-keys.sh` builds both segments from base64url
/// (`[A-Za-z0-9_-]`), and the Supabase CLI's local-dev keys measure the same
/// 22 + `_` + 8 (redact-secret-benchmarks#231, rows 4-6). So the body is
/// exactly [`SUPABASE_BODY_LEN`] bytes of `[A-Za-z0-9_-]` with a literal `_`
/// at [`SUPABASE_DELIMITER_OFFSET`]; because the alphabet itself contains
/// `_` and `-`, the delimiter is checked by position, never by splitting.
/// A 21- or 23-byte random part, a 7- or 9-byte checksum, or a `-` in the
/// delimiter position is rejected rather than truncated.
///
/// The checksum *value* is not validated. The provider script computes it
/// as the first 8 base64url characters of
/// `sha256("<project ref>|" + prefix + random)` with the fixed self-hosted
/// ref `supabase-self-hosted`; a hosted key's input (presumably the real
/// project ref, which does not appear in the key) is undocumented, so
/// validating against the self-hosted constant would reject every hosted
/// key, and there is no documented input to validate a hosted key against.
const SUPABASE_SIGNALS: [&str; 3] = [
    "supabase-secret-prefix",
    "elevated-access-key",
    "documented-random-checksum-layout",
];

/// The documented `<22-char-random>_<8-char-checksum>` body length.
const SUPABASE_BODY_LEN: usize = 22 + 1 + 8;

/// The body offset of the documented `_` between the random and checksum
/// segments.
const SUPABASE_DELIMITER_OFFSET: usize = 22;

const SUPABASE_PREFIX: &str = "sb_secret_";

/// `true` when the byte at the documented delimiter offset is `_`.
fn supabase_delimiter_ok(bytes: &[u8], start: usize, _end: usize) -> bool {
    bytes.get(start + SUPABASE_PREFIX.len() + SUPABASE_DELIMITER_OFFSET) == Some(&b'_')
}

pub(super) const SUPABASE: KnownFormatProviderDetector = KnownFormatProviderDetector {
    id: "supabase-token",
    type_name: "supabase_secret_key",
    shapes: &[PrefixShape::exact(
        SUPABASE_PREFIX,
        SUPABASE_BODY_LEN,
        pattern::is_alnum_dash,
        &SUPABASE_SIGNALS,
    )
    .with_post_check(supabase_delimiter_ok)],
    boundary: pattern::is_alnum_dash,
};

/// Supabase personal access tokens (PATs): a credential class that
/// authenticates the Management API and the tools built on it (the
/// Supabase CLI and MCP server), issued from a project's account settings
/// rather than from a project's own API-keys page.
/// `docs.supabase.com/guides/platform/personal-access-tokens` documents the
/// `sbp_` prefix (by example only, e.g. `sbp_fc...`) and the classic-vs-
/// scoped distinction, but not an exact body grammar.
///
/// `decision-freeze-precision-contracts-seven-provider-families` (Supabase
/// management-token row, issue #515) is explicit that this class must never borrow or lend
/// evidence to `SUPABASE` (`sb_secret_`/`sb_publishable_`, above) or to the
/// legacy JWT anon/service-role carve-out in [`super::jwt`]: a PAT
/// authenticates a Supabase *account*, a secret key authenticates one
/// *project's* data API, and a legacy JWT is a third, structurally
/// unrelated shape. The two-shape body grammar here (`sbp_`/`sbp_v0_`, each
/// followed by exactly 40 [`pattern::is_lower_alnum`] bytes) is instead
/// externally corroborated: it is the shape `TruffleHog`'s own shipped
/// detector (the `supabase` reference this project's benchmark evidence has
/// historically pinned, per issue #515) already matches for the classic
/// `sbp_` prefix. That reference detector's regex is anchored to
/// `[a-z0-9]{40}` and carries no `_` in its character class, so it cannot
/// match the versioned `sbp_v0_` prefix the same docs page's scoped-token
/// walkthrough names — an admitted gap this detector closes as a second
/// [`PrefixShape`] over the identical body grammar, not new matching logic,
/// the same "adopt the sibling prefix, keep the body shape" move
/// `HUGGING_FACE`'s `api_org_` shape already makes above. No `TruffleHog`
/// implementation code is used; only its published match shape is
/// consulted, per `AGENTS.md`.
const SUPABASE_PAT_SIGNALS: [&str; 2] =
    ["supabase-pat-documented-prefix", "tool-corroborated-length"];

pub(super) const SUPABASE_PAT: KnownFormatProviderDetector = KnownFormatProviderDetector {
    id: "supabase-management-token",
    type_name: "supabase_personal_access_token",
    shapes: &[
        PrefixShape::exact(
            "sbp_v0_",
            40,
            pattern::is_lower_alnum,
            &SUPABASE_PAT_SIGNALS,
        ),
        PrefixShape::exact("sbp_", 40, pattern::is_lower_alnum, &SUPABASE_PAT_SIGNALS),
    ],
    boundary: pattern::is_alnum_dash,
};

/// npm access tokens. Granular, automation, and legacy read-only tokens all
/// share the same `npm_`-prefixed shape: a fixed 36-byte base62
/// (`[A-Za-z0-9]`) body, the last six bytes of which encode a base62-encoded
/// CRC32 checksum. The suffix is matched as an exact length, not a minimum —
/// a prefix with the token truncated below 36 bytes, or with the `npm_`
/// prefix stripped entirely, is an intentional false negative; the fixed
/// prefix, alphabet, and length keep false-positive risk low.
const NPM_SIGNALS: [&str; 2] = ["npm-documented-prefix", "base62-exact-length"];

pub(super) const NPM: KnownFormatProviderDetector = KnownFormatProviderDetector {
    id: "npm-token",
    type_name: "npm_access_token",
    shapes: &[PrefixShape::exact(
        "npm_",
        36,
        pattern::is_alnum,
        &NPM_SIGNALS,
    )],
    boundary: pattern::is_alnum_dash,
};

/// Legacy Google Cloud / Gemini "standard" API keys: the `AIza` prefix
/// documented by Google Cloud's API-key authentication guide, followed by an
/// exact 35-byte suffix from `[A-Za-z0-9_-]`, for 39 bytes total. This is the
/// key *string* used to authenticate requests, not the administrative key
/// *ID* shown in Cloud console URLs — the ID cannot call any API and is out
/// of scope. Google began issuing a differently-shaped "Auth key" (service
/// account-bound, reported with an `AQ.` prefix) as the new default in 2026
/// and is retiring standalone `AIza` keys; that newer shape is an
/// intentional false negative until its grammar is confirmed from
/// authoritative Google documentation, not third-party reports. A suffix
/// shorter or longer than exactly 35 bytes, or an undocumented prefix, is
/// also an intentional false negative rather than a fuzzy match. The same
/// `AIza`-prefixed shape appears in public Firebase/browser configuration
/// as well as in service-scoped Cloud/Gemini use, and the shape carries no
/// API scope: an unrestricted key on a project with the Generative Language
/// API enabled can call Gemini whatever config object surrounds it. So this
/// detector always reports the shape at `Confidence::High`, and nothing
/// downstream exempts it by context. Issue #520 (B3a) once dropped a match
/// inside a recognized Firebase Web SDK client-config object at the
/// pipeline level; #749 reversed that, so a `firebaseConfig` `apiKey` is
/// reported like any other. The redact/warn action call is left to policy,
/// the same tradeoff npm and the other known-format providers above make.
const GOOGLE_SIGNALS: [&str; 2] = ["google-documented-prefix", "exact-length-suffix"];

pub(super) const GOOGLE: KnownFormatProviderDetector = KnownFormatProviderDetector {
    id: "google-api-key",
    type_name: "google_api_key",
    shapes: &[PrefixShape::exact(
        "AIza",
        35,
        pattern::is_alnum_dash,
        &GOOGLE_SIGNALS,
    )],
    boundary: pattern::is_alnum_dash,
};

/// Grafana Cloud access policy tokens (formerly "Grafana Cloud API tokens"
/// in older provider material). Grafana's own documentation describes the
/// `glc_` prefix only through example output, not a published grammar; two
/// independent external tools (gitleaks's `grafana-cloud-api-token` and
/// trufflehog's `grafana` detector, consulted only as behavioral references
/// per `AGENTS.md`) both converge on a `glc_`-prefixed base64 body, with
/// trufflehog additionally observing that the body itself decodes as
/// base64-encoded JSON. This detector matches the `glc_` prefix followed by
/// a run of the standard base64 body alphabet (`[A-Za-z0-9+/]`, no `=`
/// padding -- see [`pattern::is_base64_body`]) with a 32-byte minimum,
/// matching gitleaks's documented floor rather than trufflehog's narrower
/// `eyJ`-anchored variant, since requiring a specific decoded-JSON prefix
/// would encode an implementation detail of a single external tool rather
/// than an independently confirmed provider fact. An undocumented prefix,
/// or a body shorter than the minimum, is an intentional false negative.
const GRAFANA_CLOUD_SIGNALS: [&str; 2] =
    ["grafana-cloud-documented-prefix", "base64-opaque-suffix"];

pub(super) const GRAFANA_CLOUD: KnownFormatProviderDetector = KnownFormatProviderDetector {
    id: "grafana-cloud-access-policy-token",
    type_name: "grafana_cloud_access_policy_token",
    shapes: &[PrefixShape::at_least(
        "glc_",
        32,
        pattern::is_base64_body,
        &GRAFANA_CLOUD_SIGNALS,
    )],
    boundary: pattern::is_alnum_dash,
};

/// Pulumi Cloud access tokens (issue #522, B3c): personal, organization, and
/// team credentials, all three sharing one literal prefix and body shape --
/// Pulumi's own REST API reference documents no kind-specific prefix, so
/// (the same "one documented shape, several issuance contexts" reading
/// [`NPM`] above already applies) this is one [`PrefixShape`], not one per
/// token kind.
///
/// **Prefix: provider-documented.** Pulumi's Cloud REST API reference
/// (`pulumi.com/docs/reference/cloud-rest-api/access-tokens/`, observed
/// 2026-09-21) states, of the token-creation response: "The response
/// includes the token ID and the tokenValue (prefixed with 'pul-')." That
/// page, and its `personal-access-tokens` sibling (identical prose, observed
/// the same day), state no length or alphabet for the value that follows.
///
/// **Body: tool-corroborated, not provider-documented.** Two independently
/// maintained tools, consulted only as external behavioral references per
/// `AGENTS.md`, converge on the same shape:
///
/// ```text
/// gitleaks 8.30.1's pulumi-api-token rule:
///   \b(pul-[a-f0-9]{40})(?:[`'"\s;]|\\[nr]|$)
/// pleno-dlp's Pulumi detector (github.com/plenoai/pleno-dlp):
///   "pul- prefix + 40-hex"
/// ```
///
/// Both pin exactly 40 lowercase hexadecimal bytes after the prefix; neither
/// registers any other length or alphabet. A worked, explicitly
/// non-working example (Nelson Figueroa, "How to Tell What Kind of Pulumi
/// Access Token You Have", dev.to, observed 2026-09-21, itself citing
/// gitleaks/trufflehog) shows one 40-lowercase-hex-byte example each for the
/// personal, organization, and team kinds -- consistent with, but not
/// treated as independent of, that tool agreement. A body shorter or longer
/// than 40 bytes, in uppercase hex, or using any other undocumented
/// character is an intentional false negative rather than a fuzzy match,
/// the same exact-length precedent [`DIGITALOCEAN`] and [`NPM`] above
/// already set.
const PULUMI_SIGNALS: [&str; 2] = ["pulumi-documented-prefix", "tool-corroborated-length"];

pub(super) const PULUMI: KnownFormatProviderDetector = KnownFormatProviderDetector {
    id: "pulumi-access-token",
    type_name: "pulumi_access_token",
    shapes: &[PrefixShape::exact(
        "pul-",
        40,
        pattern::is_lower_hex,
        &PULUMI_SIGNALS,
    )],
    boundary: pattern::is_alnum_dash,
};

#[cfg(test)]
mod tests {
    use super::*;

    const BODY: &str = "SYNTHETICREVOKEDPROVIDERVALUE";
    /// Issue #372: Hugging Face's suffix is matched as an exact 34-byte
    /// length from `[A-Za-z0-9]` (no `_`/`-`), not a minimum, so it needs
    /// its own fixed-length, underscore-free synthetic body rather than
    /// [`BODY`].
    const HUGGING_FACE_BODY: &str = "SYNTHETICREVOKEDHUGGINGFACETOKEN01";
    const _: () = assert!(HUGGING_FACE_BODY.len() == 34);
    /// npm's suffix is matched as an exact 36-byte length, not a minimum, so
    /// it needs its own fixed-length synthetic body rather than [`BODY`].
    const NPM_BODY: &str = "SYNTHETICREVOKEDNPMACCESSTOKENVALUE1";
    /// Google's suffix is matched as an exact 35-byte length, not a minimum,
    /// so it needs its own fixed-length synthetic body rather than [`BODY`].
    const GOOGLE_BODY: &str = "SYNTHETIC_REVOKED_GOOGLE_API_KEY012";
    /// Grafana Cloud's suffix has a 32-byte minimum, longer than [`BODY`]'s
    /// 30 bytes, so it needs its own body.
    const GRAFANA_CLOUD_BODY: &str = "SYNTHETICREVOKEDGRAFANACLOUDACCESSPOLICYTOKEN";
    /// Exactly [`DOCKER_PAT_SUFFIX_LEN`] bytes: the documented `dckr_pat_`
    /// suffix length (issue #370).
    const DOCKER_PAT_BODY: &str = "SYNTHETICREVOKEDDOCKERPAT00";
    /// Exactly [`DOCKER_OAT_SUFFIX_LEN`] bytes: the documented `dckr_oat_`
    /// suffix length (issue #370).
    const DOCKER_OAT_BODY: &str = "SYNTHETICREVOKEDDOCKERORGTOKEN00";
    const _: () = assert!(DOCKER_PAT_BODY.len() == DOCKER_PAT_SUFFIX_LEN);
    const _: () = assert!(DOCKER_OAT_BODY.len() == DOCKER_OAT_SUFFIX_LEN);
    /// `DigitalOcean`'s suffix is exactly 64 lowercase hex bytes (issue
    /// #369), so each documented prefix gets its own fixed-length synthetic
    /// body. The hex-only alphabet admits no `SYNTHETIC…` marker, so each
    /// body is instead an unmistakably patterned hex run — the same
    /// counting idiom [`super::datadog`] and [`super::new_relic`] already use
    /// for their own hex-only bodies — rather than the look-alike random
    /// bytes issue #419 replaced. None was ever provider-issued.
    const DIGITALOCEAN_BODY: &str =
        "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
    const DIGITALOCEAN_OAUTH_BODY: &str =
        "fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210";
    /// Exactly 40 bytes from `[a-z0-9]` (no uppercase, no `_`/`-`): the
    /// tool-corroborated `sbp_`/`sbp_v0_` personal-access-token body length
    /// (issue #515). The lowercase-only alphabet admits no `SYNTHETIC…`
    /// marker, so this is a lowercase, unmistakably patterned synthetic run
    /// instead, the same style [`DIGITALOCEAN_BODY`] uses for its own
    /// narrowed alphabet.
    const SUPABASE_PAT_BODY: &str = "synthetic0revoked1provider2value3padding";
    /// The documented `sb_secret_` body (issue #742): a 22-byte random part,
    /// `_`, and an 8-byte checksum part, all base64url.
    const SUPABASE_BODY: &str = "SYNTHETIC_REVOKED_SUPA_CHECKSUM";
    const _: () = assert!(SUPABASE_BODY.len() == SUPABASE_BODY_LEN);
    const _: () = assert!(SUPABASE_PAT_BODY.len() == 40);
    const DIGITALOCEAN_REFRESH_BODY: &str =
        "123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0";
    /// Exactly 40 lowercase hex bytes: the tool-corroborated Pulumi access
    /// token body length (issue #522). The hex-only alphabet admits no
    /// `SYNTHETIC…` marker, so this is the same unmistakably patterned hex
    /// run style [`DIGITALOCEAN_BODY`] uses for its own narrowed alphabet.
    /// None was ever provider-issued.
    const PULUMI_BODY: &str = "0123456789abcdef0123456789abcdef01234567";
    const _: () = assert!(PULUMI_BODY.len() == 40);

    fn detect(detector: &KnownFormatProviderDetector, input: &str) -> Vec<Candidate> {
        detector
            .detect(input, &DetectorContext::new(input.len()))
            .unwrap()
    }

    struct Family {
        detector: KnownFormatProviderDetector,
        value: String,
        /// `value` with an invalid-alphabet byte inserted four bytes into
        /// the suffix, so the run breaks before any family's minimum or
        /// exact length is reached.
        broken: String,
        short: &'static str,
    }

    fn family(
        detector: KnownFormatProviderDetector,
        prefix: &str,
        body: &str,
        short: &'static str,
    ) -> Family {
        Family {
            detector,
            value: format!("{prefix}{body}"),
            broken: format!("{prefix}{}!{}", &body[..4], &body[4..]),
            short,
        }
    }

    fn families() -> Vec<Family> {
        vec![
            family(STRIPE, "sk_live_", BODY, "sk_live_SYNTHETICSHORT"),
            family(
                PYPI,
                "pypi-",
                &"SYNTHETIC_REVOKED_".repeat(5),
                "pypi-SYNTHETICSHORT",
            ),
            family(HUGGING_FACE, "hf_", HUGGING_FACE_BODY, "hf_SYNTHETIC_SHORT"),
            family(
                DOCKER,
                "dckr_pat_",
                DOCKER_PAT_BODY,
                "dckr_pat_SYNTHETIC_SHORT",
            ),
            family(
                DIGITALOCEAN,
                "dop_v1_",
                DIGITALOCEAN_BODY,
                "dop_v1_SYNTHETIC_SHORT",
            ),
            family(
                SUPABASE,
                "sb_secret_",
                SUPABASE_BODY,
                "sb_secret_SYNTHETIC_SHORT",
            ),
            family(
                SUPABASE_PAT,
                "sbp_",
                SUPABASE_PAT_BODY,
                "sbp_synthetic0short",
            ),
            family(NPM, "npm_", NPM_BODY, "npm_SYNTHETICSHORT"),
            family(GOOGLE, "AIza", GOOGLE_BODY, "AIzaSYNTHETICSHORT"),
            family(
                GRAFANA_CLOUD,
                "glc_",
                GRAFANA_CLOUD_BODY,
                "glc_SYNTHETICSHORT",
            ),
            family(PULUMI, "pul-", PULUMI_BODY, "pul-0123456789abcdef"),
        ]
    }

    #[test]
    fn detects_a_synthetic_credential_with_provider_specificity() {
        for family in families() {
            let candidates = detect(&family.detector, &family.value);
            assert_eq!(candidates.len(), 1, "{}", family.detector.id());
            assert_eq!(candidates[0].confidence(), Confidence::High);
            assert_eq!(candidates[0].effective_specificity(), Specificity::Provider);
            assert_eq!(
                candidates[0].range(),
                ByteRange::new(0, family.value.len()).unwrap()
            );
        }
    }

    #[test]
    fn rejects_short_invalid_alphabet_and_embedded_lookalikes() {
        for family in families() {
            let embedded = format!("X{}Y", family.value);
            for input in [family.short, family.broken.as_str(), embedded.as_str()] {
                assert_eq!(
                    detect(&family.detector, input).len(),
                    0,
                    "{} {input}",
                    family.detector.id()
                );
            }
        }
    }

    #[test]
    fn accepts_punctuation_boundaries() {
        for family in families() {
            let input = format!("({}).", family.value);
            let candidates = detect(&family.detector, &input);
            assert_eq!(candidates.len(), 1, "{}", family.detector.id());
            assert_eq!(
                candidates[0].range(),
                ByteRange::new(1, family.value.len() + 1).unwrap(),
                "{}",
                family.detector.id()
            );
        }
    }

    #[test]
    fn detects_every_documented_prefix_variant() {
        // Docker's two prefixes carry different exact lengths, so they are
        // asserted by `docker_accepts_each_segment_at_exactly_its_own_length`
        // instead of against the shared minimum-length `BODY`. Slack moved
        // out to `super::slack` (issue #371) and Linear to `super::linear`
        // (issue #374); each is covered by its own tests there.
        let cases: [(&KnownFormatProviderDetector, &str); 10] = [
            (&STRIPE, "sk_test_"),
            (&STRIPE, "sk_live_"),
            (&STRIPE, "rk_test_"),
            (&STRIPE, "rk_live_"),
            (&STRIPE, "sk_org_"),
            (&STRIPE, "sk_org_live_"),
            (&STRIPE, "sk_org_test_"),
            (&DIGITALOCEAN, "dop_v1_"),
            (&DIGITALOCEAN, "doo_v1_"),
            (&DIGITALOCEAN, "dor_v1_"),
        ];
        for (detector, prefix) in cases {
            // DigitalOcean's contracted body is exactly 64 lowercase hex
            // bytes (issue #369), so it cannot share the generic [`BODY`].
            let body = if detector.id() == DIGITALOCEAN.id() {
                DIGITALOCEAN_BODY
            } else {
                BODY
            };
            let value = format!("{prefix}{body}");
            let candidates = detect(detector, &value);
            assert_eq!(candidates.len(), 1, "{prefix}");
            assert_eq!(
                candidates[0].range(),
                ByteRange::new(0, value.len()).unwrap(),
                "{prefix}"
            );
        }
    }

    #[test]
    fn does_not_classify_neighboring_public_or_identifier_only_formats() {
        for input in [
            format!("pk_live_{BODY}"),
            // Issue #513: Stripe's sandbox-mode publishable key is
            // documented exactly as safe to expose as its live-mode
            // counterpart (docs.stripe.com/keys, observed 2026-09-20).
            format!("pk_test_{BODY}"),
            format!("sb_publishable_{SUPABASE_BODY}"),
            format!("SK{}", "0".repeat(32)),
            // An undocumented near-miss prefix (not one byte-for-byte equal to
            // any documented prefix) stays a false-negative-by-design, never a
            // fuzzy match.
            format!("sk_liv_{BODY}"),
            format!("sb_secrets_{SUPABASE_BODY}"),
        ] {
            assert_eq!(detect(&STRIPE, &input).len(), 0, "{input}");
            assert_eq!(detect(&SUPABASE, &input).len(), 0, "{input}");
        }
    }

    /// Issue #742: only the documented `<22>_<8>` body layout is a
    /// Supabase secret key. Each twin below keeps the prefix and the
    /// base64url alphabet and breaks exactly one structural fact, so every
    /// one would have cleared the former 20-byte open floor.
    #[test]
    fn supabase_accepts_only_the_documented_random_checksum_layout() {
        let random = &SUPABASE_BODY[..SUPABASE_DELIMITER_OFFSET];
        let checksum = &SUPABASE_BODY[SUPABASE_DELIMITER_OFFSET + 1..];
        assert_eq!((random.len(), checksum.len()), (22, 8));

        // The alphabet admits `_` and `-` inside both segments, so a
        // documented-layout key may carry them anywhere but the delimiter.
        for body in [
            SUPABASE_BODY.to_string(),
            "a-b_c-d_e-f_g-h_i-j_k-_l-m_n-o_".to_string(),
            format!("{}_{}", "_-".repeat(11), "-_".repeat(4)),
        ] {
            assert_eq!(body.len(), SUPABASE_BODY_LEN, "{body}");
            let input = format!("SUPABASE_SECRET_KEY=sb_secret_{body}\n");
            let candidates = detect(&SUPABASE, &input);
            assert_eq!(candidates.len(), 1, "{input}");
            assert_eq!(
                candidates[0].range(),
                ByteRange::new(20, 20 + 10 + SUPABASE_BODY_LEN).unwrap(),
                "{input}"
            );
        }

        for body in [
            // Random part 21 instead of 22.
            format!("{}_{checksum}", &random[..21]),
            // Random part 23 instead of 22.
            format!("{random}X_{checksum}"),
            // Checksum 9 instead of 8.
            format!("{random}_{checksum}X"),
            // Checksum 7 instead of 8.
            format!("{random}_{}", &checksum[..7]),
            // `-` in the delimiter position.
            format!("{random}-{checksum}"),
            // No delimiter at all: 31 bytes with no `_` at offset 22.
            format!("{random}X{checksum}"),
            // The former 40-byte alphanumeric-only shape.
            "SYNTHETICREVOKEDSYNTHETICREVOKEDSYNTHETI".to_string(),
        ] {
            for input in [
                format!("sb_secret_{body}"),
                format!("SUPABASE_SECRET_KEY=sb_secret_{body}\n"),
            ] {
                assert_eq!(detect(&SUPABASE, &input).len(), 0, "{input}");
            }
        }
    }

    /// Issue #513: `sk_org_`'s and `whsec_`'s own documented-absence and
    /// separator near misses. `rk_org_` is a direct evidenced negative
    /// (`docs.stripe.com/keys/organization-api-keys`, observed 2026-09-20:
    /// "There's no `rk_org` prefix"), not merely an untested guess; the
    /// remaining cases are missing- or wrong-separator variants of
    /// `sk_org_`/`whsec_`, undocumented near-misses by the same
    /// false-negative-by-design rule as `sk_liv_` above.
    #[test]
    fn rejects_organization_and_webhook_documented_absence_and_separator_near_misses() {
        for input in [
            format!("rk_org_{BODY}"),
            format!("sk_org{BODY}"),
            format!("sk_org-{BODY}"),
            format!("whsec{BODY}"),
            format!("whsec-{BODY}"),
            format!("wh_sec_{BODY}"),
        ] {
            assert_eq!(detect(&STRIPE, &input).len(), 0, "{input}");
        }
    }

    /// Issue #1030: `sk_org_` with a `live_`/`test_` mode segment, floor at
    /// exactly 20 and above, boundaries, and the near misses. Values are built
    /// at runtime from repeated filler, never written as a key-shaped literal.
    #[test]
    fn claims_organization_mode_segment_with_the_same_floor_as_sk_org() {
        for mode in ["live", "test"] {
            let prefix = format!("sk_org_{mode}_");
            for len in [20usize, 21, 32, 64, 120] {
                let body = "A".repeat(len);
                let value = format!("{prefix}{body}");
                for input in [
                    value.clone(),
                    format!("KEY={value}\n"),
                    format!("\"{value}\""),
                    format!("\u{ac00}{value}\u{ac00}"),
                    format!("x {value}."),
                ] {
                    let c = detect(&STRIPE, &input);
                    assert_eq!(c.len(), 1, "{mode} {len}");
                    let start = input.find("sk_org_").unwrap();
                    assert_eq!(
                        c[0].range(),
                        ByteRange::new(start, start + value.len()).unwrap(),
                        "{mode} {len}"
                    );
                }
            }
            // Mixed-case and digit body within the alphabet.
            let mixed = format!("{prefix}{}", "aZ09".repeat(6));
            assert_eq!(detect(&STRIPE, &mixed).len(), 1, "{mixed}");
            // Below the floor, no body, non-alphanumeric inside the body.
            for input in [
                prefix.clone(),
                format!("{prefix}{}", "A".repeat(19)),
                format!("{prefix}{}_{}", "A".repeat(10), "A".repeat(10)),
                format!("{prefix}{}-{}", "A".repeat(10), "A".repeat(10)),
                format!("{prefix}{}", "A".repeat(10)),
            ] {
                let c = detect(&STRIPE, &input);
                assert!(c.iter().all(|x| x.range().end() <= input.len()), "{input}");
                assert_eq!(c.len(), 0, "{input}");
            }
            // Embedded in a wider identifier (leading alnum/underscore/dash).
            for lead in ["a", "9", "_", "-"] {
                let input = format!("{lead}{prefix}{}", "A".repeat(24));
                assert_eq!(detect(&STRIPE, &input).len(), 0, "{input}");
            }
            // A trailing glued `_` or `-` rejects, like the sk_org_ rule.
            for tail in ["_", "-"] {
                let input = format!("{prefix}{}{tail}", "A".repeat(24));
                assert_eq!(detect(&STRIPE, &input).len(), 0, "{input}");
            }
        }
        // Other mode words and cases are not claimed.
        for mode in ["prod", "Live", "LIVE", "lives", "li", ""] {
            let input = format!("sk_org_{mode}_{}", "A".repeat(24));
            assert_eq!(detect(&STRIPE, &input).len(), 0, "{input}");
        }
        // Regression: flat sk_org_ and sk_live_ unchanged.
        for prefix in ["sk_org_", "sk_live_", "sk_test_"] {
            let input = format!("{prefix}{}", "A".repeat(24));
            assert_eq!(detect(&STRIPE, &input).len(), 1, "{input}");
        }
        // `sk_org_live_` is one finding, not two.
        let two = format!("sk_org_live_{0} sk_org_test_{0}", "A".repeat(24));
        assert_eq!(detect(&STRIPE, &two).len(), 2);
    }

    /// A public-prefix identifier surrounded by punctuation or Unicode/CRLF
    /// context, and a documented secret prefix followed by a redaction mask
    /// or a template interpolation reference instead of a real suffix, must
    /// all stay unclassified.
    #[test]
    fn rejects_masked_interpolated_and_contextualized_near_misses() {
        for input in [
            format!("(pk_live_{BODY})."),
            format!("(sb_publishable_{SUPABASE_BODY})."),
            format!("# \u{1F511} caf\u{e9}\r\npk_live_{BODY}\r\n"),
            format!("# \u{1F511} caf\u{e9}\r\nsb_publishable_{SUPABASE_BODY}\r\n"),
            "sk_live_********************".to_string(),
            "sb_secret_********************".to_string(),
            "sk_live_${STRIPE_SECRET_KEY}".to_string(),
            "sb_secret_${SUPABASE_SERVICE_ROLE_KEY}".to_string(),
        ] {
            assert_eq!(detect(&STRIPE, &input).len(), 0, "{input}");
            assert_eq!(detect(&SUPABASE, &input).len(), 0, "{input}");
        }
    }

    /// A public identifier and a secret credential on adjacent lines: the
    /// public prefix never generates a candidate, while the paired secret is
    /// still classified with the correct range.
    #[test]
    fn classifies_only_the_secret_half_of_a_mixed_public_and_secret_input() {
        let input = format!("pk_live_SYNTHETICREVOKEDSYNT\nsk_live_{BODY}");
        let candidates = detect(&STRIPE, &input);
        assert_eq!(candidates.len(), 1);
        let expected_start = input.find("sk_live_").unwrap();
        assert_eq!(
            candidates[0].range(),
            ByteRange::new(expected_start, input.len()).unwrap()
        );
    }

    /// Issue #513: the same public/secret pairing in sandbox mode. Stripe
    /// documents `pk_test_` as equally safe to expose as `pk_live_`
    /// (docs.stripe.com/keys, observed 2026-09-20), so pairing it with a
    /// real-shaped `sk_test_` secret in the same file must classify only
    /// the secret half, the same as the live-mode pairing above.
    #[test]
    fn classifies_only_the_secret_half_of_a_mixed_public_and_secret_input_in_sandbox_mode() {
        let input = format!("pk_test_SYNTHETICREVOKEDSYNT\nsk_test_{BODY}");
        let candidates = detect(&STRIPE, &input);
        assert_eq!(candidates.len(), 1);
        let expected_start = input.find("sk_test_").unwrap();
        assert_eq!(
            candidates[0].range(),
            ByteRange::new(expected_start, input.len()).unwrap()
        );
    }

    /// Issue #320: the four infrastructure-provider detectors (Docker,
    /// Cloudflare, `DigitalOcean`, Vercel; Vercel moved to `super::vercel`
    /// in issue #1036 and repeats these dimensions there) each get the same false-positive
    /// assurance the earlier prefix-family issues (#316/#317) established
    /// for Stripe/Shopify/Supabase/`OpenAI`/Anthropic, across every
    /// documented prefix variant.
    /// 27 bytes: a valid suffix for every minimum-length infra prefix and,
    /// since issue #370, exactly the documented `dckr_pat_` length too.
    const INFRA_SUFFIX: &str = "SYNTHETIC_REVOKED_KEY_VALUE";
    /// 32 bytes: exactly the documented `dckr_oat_` length (issue #370).
    const DOCKER_OAT_SUFFIX: &str = "SYNTHETIC_REVOKED_OAT_KEY_VALUE3";
    const _: () = assert!(INFRA_SUFFIX.len() == DOCKER_PAT_SUFFIX_LEN);
    const _: () = assert!(DOCKER_OAT_SUFFIX.len() == DOCKER_OAT_SUFFIX_LEN);

    /// One documented prefix of an infrastructure-provider detector, paired
    /// with a synthetic body that satisfies that detector's contracted
    /// shape and a documentation-style placeholder built entirely from the
    /// detector's own suffix alphabet at a length its contract accepts.
    struct InfraVariant {
        detector: &'static KnownFormatProviderDetector,
        prefix: &'static str,
        body: &'static str,
        placeholder: String,
    }

    /// `DigitalOcean`'s contract is exactly 64 lowercase hex bytes (issue
    /// #369), so its variants carry a fixed-length hex body and a hex-only
    /// placeholder.
    fn digitalocean_variant(prefix: &'static str, body: &'static str) -> InfraVariant {
        InfraVariant {
            detector: &DIGITALOCEAN,
            prefix,
            body,
            placeholder: "a".repeat(64),
        }
    }

    /// Docker Hub's two prefixes carry different exact lengths (issue
    /// #370), so each gets a body of its own documented length and a
    /// placeholder of that same length.
    fn docker_variant(prefix: &'static str, body: &'static str) -> InfraVariant {
        InfraVariant {
            detector: &DOCKER,
            prefix,
            body,
            placeholder: "x".repeat(body.len()),
        }
    }

    fn infra_provider_variants() -> Vec<InfraVariant> {
        vec![
            docker_variant("dckr_pat_", INFRA_SUFFIX),
            docker_variant("dckr_oat_", DOCKER_OAT_SUFFIX),
            digitalocean_variant("dop_v1_", DIGITALOCEAN_BODY),
            digitalocean_variant("doo_v1_", DIGITALOCEAN_OAUTH_BODY),
            digitalocean_variant("dor_v1_", DIGITALOCEAN_REFRESH_BODY),
        ]
    }

    #[test]
    fn infra_providers_accept_a_doc_style_placeholder_built_from_valid_alphabet_characters() {
        for variant in infra_provider_variants() {
            let input = format!("{}{}", variant.prefix, variant.placeholder);
            assert_eq!(
                detect(variant.detector, &input).len(),
                1,
                "{}",
                variant.detector.id()
            );
        }
    }

    #[test]
    fn infra_providers_reject_a_prefix_embedded_in_a_wider_benign_identifier() {
        // A leading alnum/dash byte right before the documented prefix means
        // this is a truncated slice of a longer identifier, not a
        // boundary-delimited credential.
        for variant in infra_provider_variants() {
            let input = format!("legacy{}{}", variant.prefix, variant.body);
            assert_eq!(
                detect(variant.detector, &input).len(),
                0,
                "{}",
                variant.detector.id()
            );
        }
    }

    /// Issue #551: the shared boundary/delimiter regression set, mirrored
    /// from `digitalocean-token`'s existing leading/trailing/dash
    /// identifier-embedding fixtures, for every `docker-token` and
    /// `digitalocean-token` shape here. `vercel-token`'s interim `vci_`/`vck_`
    /// shapes keep the open-floor defect; see `super::vercel`.
    #[test]
    fn infra_providers_reject_every_shape_embedded_in_a_wider_identifier_leading_trailing_or_dash_joined()
     {
        for variant in infra_provider_variants() {
            let value = format!("{}{}", variant.prefix, variant.body);
            assert!(
                detect(variant.detector, &format!("legacy{value}")).is_empty(),
                "{} leading",
                variant.detector.id()
            );
            assert!(
                detect(variant.detector, &format!("{value}_backup")).is_empty(),
                "{} trailing",
                variant.detector.id()
            );
            assert!(
                detect(variant.detector, &format!("{value}-1")).is_empty(),
                "{} dash",
                variant.detector.id()
            );
        }
    }

    #[test]
    fn infra_providers_reject_case_changed_wrong_prefixes() {
        for variant in infra_provider_variants() {
            let input = format!("{}{}", variant.prefix.to_ascii_uppercase(), variant.body);
            assert_eq!(
                detect(variant.detector, &input).len(),
                0,
                "{}",
                variant.detector.id()
            );
        }
    }

    #[test]
    fn infra_providers_reject_masked_and_interpolated_near_misses() {
        for variant in infra_provider_variants() {
            for input in [
                format!("{}{}", variant.prefix, "*".repeat(variant.body.len())),
                format!("{}${{ENV_VAR}}", variant.prefix),
            ] {
                assert_eq!(
                    detect(variant.detector, &input).len(),
                    0,
                    "{} {input}",
                    variant.detector.id()
                );
            }
        }
    }

    #[test]
    fn infra_providers_bound_a_match_against_trailing_prose_punctuation() {
        for variant in infra_provider_variants() {
            let token = format!("{}{}", variant.prefix, variant.body);
            let input = format!("Rotate {token}, then redeploy.");
            let candidates = detect(variant.detector, &input);
            assert_eq!(candidates.len(), 1, "{}", variant.detector.id());
            let start = "Rotate ".len();
            let end = start + token.len();
            assert_eq!(
                candidates[0].range(),
                ByteRange::new(start, end).unwrap(),
                "{}",
                variant.detector.id()
            );
        }
    }

    /// A container registry/image reference qualified by a `sha256:` digest
    /// (the well-known hash of the empty string, not a credential) has
    /// neither Docker Hub's documented prefix nor its alphabet shape.
    #[test]
    fn docker_rejects_an_ordinary_registry_image_digest_reference() {
        let input = "docker pull registry.example.com/myorg/app@sha256:\
            e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85";
        assert_eq!(detect(&DOCKER, input).len(), 0);
    }

    /// Issue #370: `dckr_pat_` and `dckr_oat_` are validated separately, each
    /// at exactly its own documented length (27 and 32 bytes), instead of
    /// sharing one 20-byte minimum.
    #[test]
    fn docker_accepts_each_segment_at_exactly_its_own_length() {
        for (prefix, body) in [
            ("dckr_pat_", DOCKER_PAT_BODY),
            ("dckr_oat_", DOCKER_OAT_BODY),
        ] {
            let value = format!("{prefix}{body}");
            let candidates = detect(&DOCKER, &value);
            assert_eq!(candidates.len(), 1, "{prefix}");
            assert_eq!(candidates[0].confidence(), Confidence::High);
            assert_eq!(candidates[0].effective_specificity(), Specificity::Provider);
            assert_eq!(
                candidates[0].range(),
                ByteRange::new(0, value.len()).unwrap(),
                "{prefix}"
            );
        }
    }

    /// Issue #370: one byte short of, or one byte past, either documented
    /// length is an intentional false negative — the beta.4 benchmark's
    /// `docker-token-pat-plain-twin` (26) and `docker-token-oat-plain-twin`
    /// (31) mutations, plus their one-byte-long counterparts. A longer run is
    /// not misread as the exact shape followed by trailing bytes.
    #[test]
    fn docker_rejects_a_suffix_one_byte_off_either_documented_length() {
        for (prefix, body) in [
            ("dckr_pat_", DOCKER_PAT_BODY),
            ("dckr_oat_", DOCKER_OAT_BODY),
        ] {
            let one_short = format!("{prefix}{}", &body[..body.len() - 1]);
            let one_long = format!("{prefix}{body}0");
            for input in [one_short, one_long] {
                assert_eq!(detect(&DOCKER, &input).len(), 0, "{input}");
            }
        }
    }

    /// Issue #370: the two segment names do not share a length — the PAT
    /// length under the OAT prefix and the OAT length under the PAT prefix
    /// are both rejected.
    #[test]
    fn docker_does_not_accept_the_oat_width_under_the_pat_prefix() {
        let input = format!("dckr_pat_{DOCKER_OAT_BODY}");
        assert_eq!(detect(&DOCKER, &input).len(), 0, "{input}");
    }

    /// Issue #708: Docker's Hub API reference shows an organization access
    /// token with a 27-byte body, so `dckr_oat_` accepts exactly 27 or
    /// exactly 32 bytes. Each width is matched over the full span, and every
    /// width in between, or just outside, is rejected rather than truncated.
    #[test]
    fn docker_oat_accepts_exactly_the_27_and_32_byte_widths() {
        for body in [DOCKER_PAT_BODY, DOCKER_OAT_BODY] {
            let input = format!("DOCKER_TOKEN=dckr_oat_{body}");
            let candidates = detect(&DOCKER, &input);
            assert_eq!(candidates.len(), 1, "len={}", body.len());
            assert_eq!(
                candidates[0].range(),
                ByteRange::new("DOCKER_TOKEN=".len(), input.len()).unwrap(),
                "len={}",
                body.len()
            );
        }
        let padding = "SYNTHETICREVOKEDDOCKERORGTOKEN0000";
        for len in [26usize, 28, 29, 30, 31, 33] {
            let input = format!("dckr_oat_{}", &padding[..len]);
            assert_eq!(detect(&DOCKER, &input).len(), 0, "len={len}");
        }
    }

    /// Issue #370: the benchmark's Unicode/CRLF twins
    /// (`docker-token-pat-unicode-crlf-twin`,
    /// `docker-token-oat-unicode-crlf-twin`) stay silent while their paired
    /// positives are reported at exact UTF-8 byte offsets — the 24-byte
    /// comment line before each token is the same prefix the benchmark uses.
    #[test]
    fn docker_distinguishes_unicode_crlf_twins_from_their_paired_positives() {
        const COMMENT: &str = "# \u{1F511} reviewed format\r\n";
        assert_eq!(COMMENT.len(), 24);
        for (prefix, body) in [
            ("dckr_pat_", DOCKER_PAT_BODY),
            ("dckr_oat_", DOCKER_OAT_BODY),
        ] {
            let positive = format!("{COMMENT}{prefix}{body}\n\r\n");
            let candidates = detect(&DOCKER, &positive);
            assert_eq!(candidates.len(), 1, "{prefix}");
            assert_eq!(
                candidates[0].range(),
                ByteRange::new(COMMENT.len(), COMMENT.len() + prefix.len() + body.len()).unwrap(),
                "{prefix}"
            );

            let twin = format!("{COMMENT}{prefix}{}\n\r\n", &body[..body.len() - 1]);
            assert_eq!(detect(&DOCKER, &twin).len(), 0, "{prefix}");
        }
    }

    /// Issue #370: a valid PAT, its 26-byte twin, a valid OAT, and its
    /// 31-byte twin on adjacent lines are discriminated independently, and a
    /// quoted, backticked, or `key=` value is still bounded exactly.
    #[test]
    fn docker_discriminates_adjacent_twins_and_bounds_delimited_values() {
        let pat = format!("dckr_pat_{DOCKER_PAT_BODY}");
        let oat = format!("dckr_oat_{DOCKER_OAT_BODY}");
        let pat_twin = &pat[..pat.len() - 1];
        let oat_twin = &oat[..oat.len() - 1];
        let input = format!("{pat}\n{pat_twin}\n{oat}\n{oat_twin}\n");
        let candidates = detect(&DOCKER, &input);
        let ranges: Vec<(usize, usize)> = candidates
            .iter()
            .map(|candidate| (candidate.range().start(), candidate.range().end()))
            .collect();
        let oat_start = pat.len() + 1 + pat_twin.len() + 1;
        assert_eq!(
            ranges,
            vec![(0, pat.len()), (oat_start, oat_start + oat.len())]
        );

        for (input, start, len) in [
            (format!("\"{pat}\""), 1, pat.len()),
            (format!("`{oat}`"), 1, oat.len()),
            (
                format!("DOCKER_TOKEN={pat}"),
                "DOCKER_TOKEN=".len(),
                pat.len(),
            ),
        ] {
            let candidates = detect(&DOCKER, &input);
            assert_eq!(candidates.len(), 1, "{input}");
            assert_eq!(
                candidates[0].range(),
                ByteRange::new(start, start + len).unwrap(),
                "{input}"
            );
        }
    }

    /// A `DigitalOcean` App Platform deployment/resource identifier is an
    /// ordinary UUID with no `v1` token prefix.
    #[test]
    fn digitalocean_rejects_an_ordinary_deployment_resource_id() {
        let input = "resource: do:app:3f900b88-8eb1-4de4-b7a3-93c1fb2f8b1d";
        assert_eq!(detect(&DIGITALOCEAN, input).len(), 0);
    }

    /// Issue #320 follow-up: an identical value repeated in the same input
    /// is reported once per independent occurrence, not deduplicated, the
    /// same dimension #321 established for `HuggingFace`/Linear/Slack but
    /// not yet exercised for the four infra-provider families.
    #[test]
    fn infra_providers_report_a_repeated_identical_value_once_per_occurrence() {
        for variant in infra_provider_variants() {
            let value = format!("{}{}", variant.prefix, variant.body);
            let input = format!("{value} {value}");
            let candidates = detect(variant.detector, &input);
            assert_eq!(candidates.len(), 2, "{}", variant.detector.id());
        }
    }

    /// Issue #321: this dimension is scoped to `HUGGING_FACE`, without
    /// widening the shared [`families`] list. Slack moved out to
    /// `super::slack` (issue #371) and Linear to `super::linear` (issue
    /// #374); each repeats this dimension there for its own prefixes.
    #[test]
    fn application_providers_accept_an_all_valid_alphabet_documentation_placeholder() {
        let value = format!("hf_{}", "x".repeat(34));
        let candidates = detect(&HUGGING_FACE, &value);
        assert_eq!(candidates.len(), 1);
        assert_eq!(candidates[0].confidence(), Confidence::High);
    }

    #[test]
    fn application_providers_reject_the_prefix_embedded_in_a_wider_identifier() {
        let value = format!("legacyhf_{HUGGING_FACE_BODY}");
        assert_eq!(detect(&HUGGING_FACE, &value).len(), 0);
    }

    /// Issue #551: the shared boundary/delimiter regression set, mirrored
    /// from `digitalocean-token`'s existing leading/trailing/dash
    /// identifier-embedding fixtures, for `huggingface-token`'s `hf_` shape.
    #[test]
    fn hf_rejects_every_embedding_shape_leading_trailing_or_dash_joined() {
        let value = format!("hf_{HUGGING_FACE_BODY}");
        assert!(detect(&HUGGING_FACE, &format!("legacy{value}")).is_empty());
        assert!(detect(&HUGGING_FACE, &format!("{value}_backup")).is_empty());
        assert!(detect(&HUGGING_FACE, &format!("{value}-1")).is_empty());
    }

    #[test]
    fn application_providers_reject_a_percent_encoded_delimiter_lookalike() {
        assert_eq!(
            detect(&HUGGING_FACE, "hf%5FSYNTHETIC_REVOKED_CONFORMANCE_KEY").len(),
            0
        );
    }

    #[test]
    fn application_providers_report_a_repeated_identical_value_once_per_occurrence() {
        let value = format!("hf_{HUGGING_FACE_BODY}");
        let input = format!("{value} {value}");
        assert_eq!(detect(&HUGGING_FACE, &input).len(), 2);
    }

    /// Issue #372: the frozen precision contract
    /// (`docs/contracts/precision/precision-contracts.json`, `families.
    /// huggingface-token`) narrows the body to exactly 34 bytes. A 33-byte
    /// body — one byte short, the beta.4
    /// `huggingface-token-user-plain-twin` regression fixture — is an
    /// intentional false negative, and a 35-byte body (one byte past the
    /// documented length) is not misread as the exact shape followed by a
    /// trailing byte.
    #[test]
    fn huggingface_rejects_a_body_one_byte_off_the_documented_length() {
        for body in [
            &HUGGING_FACE_BODY[..HUGGING_FACE_BODY.len() - 1],
            &format!("{HUGGING_FACE_BODY}A"),
        ] {
            let value = format!("hf_{body}");
            assert_eq!(detect(&HUGGING_FACE, &value).len(), 0, "{value}");
        }
    }

    /// Issue #372: both gitleaks 8.30.1 and trufflehog 3.97.4 agree the body
    /// excludes `_`/`-`; the beta.4 shared minimum-length shape's acceptance
    /// of them was a shared-rule artifact, not evidence. An otherwise
    /// documented-length body containing either byte is rejected rather
    /// than truncated to its longest valid-alphabet prefix.
    #[test]
    fn huggingface_rejects_a_documented_length_body_containing_underscore_or_dash() {
        for byte in ['_', '-'] {
            let mut body = HUGGING_FACE_BODY.to_string();
            body.replace_range(4..5, &byte.to_string());
            let value = format!("hf_{body}");
            assert_eq!(detect(&HUGGING_FACE, &value).len(), 0, "{value}");
        }
    }

    /// Issue #372: the two tools disagree on the body alphabet (gitleaks:
    /// letters only; trufflehog: letters and digits). That conflict is
    /// resolved as a support-policy choice for the union rather than
    /// guessed into the letters-only intersection, so a digit-bearing body
    /// is still accepted.
    #[test]
    fn huggingface_accepts_a_digit_bearing_documented_length_body() {
        let mut body = HUGGING_FACE_BODY.to_string();
        body.replace_range(0..2, "42");
        let value = format!("hf_{body}");
        assert_eq!(detect(&HUGGING_FACE, &value).len(), 1, "{value}");
    }

    /// Issue #485: `api_org_` is adopted over the identical `hf_` body
    /// grammar (34-byte `[A-Za-z0-9]`). Detected at exactly the documented
    /// range, and `hf_` stays unaffected by the added shape.
    #[test]
    fn huggingface_organization_token_detects_the_api_org_prefix_at_the_documented_shape() {
        let value = format!("api_org_{HUGGING_FACE_BODY}");
        let candidates = detect(&HUGGING_FACE, &value);
        assert_eq!(candidates.len(), 1);
        assert_eq!(candidates[0].type_name(), "huggingface_token");
        assert_eq!(candidates[0].confidence(), Confidence::High);
        assert_eq!(candidates[0].effective_specificity(), Specificity::Provider);
        assert_eq!(
            candidates[0].range(),
            ByteRange::new(0, value.len()).unwrap()
        );

        let user_value = format!("hf_{HUGGING_FACE_BODY}");
        assert_eq!(detect(&HUGGING_FACE, &user_value).len(), 1);
    }

    /// Issue #485: an `api_org_` value and an `hf_` value in the same input
    /// are both reported, at their own ranges, without either shape
    /// swallowing the other.
    #[test]
    fn huggingface_organization_token_and_user_token_are_both_reported_independently() {
        let user_value = format!("hf_{HUGGING_FACE_BODY}");
        let org_value = format!("api_org_{HUGGING_FACE_BODY}");
        let input = format!("{user_value} {org_value}");
        let candidates = detect(&HUGGING_FACE, &input);
        assert_eq!(candidates.len(), 2);
        assert_eq!(
            candidates[0].range(),
            ByteRange::new(0, user_value.len()).unwrap()
        );
        let org_start = input.find(&org_value).unwrap();
        assert_eq!(
            candidates[1].range(),
            ByteRange::new(org_start, org_start + org_value.len()).unwrap()
        );
    }

    /// Issue #485: the frozen contract's exact 34-byte body applies
    /// identically to `api_org_`. A 33-byte body — the `api_org_` twin of
    /// the beta.4 `huggingface-token-user-plain-twin` regression — is an
    /// intentional false negative, and a 35-byte body is not misread as the
    /// exact shape followed by a trailing byte.
    #[test]
    fn huggingface_organization_token_rejects_a_body_one_byte_off_the_documented_length() {
        for body in [
            &HUGGING_FACE_BODY[..HUGGING_FACE_BODY.len() - 1],
            &format!("{HUGGING_FACE_BODY}A"),
        ] {
            let value = format!("api_org_{body}");
            assert_eq!(detect(&HUGGING_FACE, &value).len(), 0, "{value}");
        }
    }

    /// Issue #485: an ordinary identifier that begins `api_org_` but does
    /// not carry the documented 34-byte body (for example, a variable or
    /// key name) does not match.
    #[test]
    fn huggingface_organization_token_rejects_an_ordinary_non_conforming_identifier() {
        for value in ["api_org_name", "api_org_id", "api_org_12345"] {
            assert_eq!(detect(&HUGGING_FACE, value).len(), 0, "{value}");
        }
    }

    /// Issue #485: the prefix embedded in a wider identifier, or the
    /// documented-length body containing `_`/`-`, is rejected for
    /// `api_org_` exactly as it already is for `hf_` (issue #372) — the
    /// same tool-agreed exclusion, not a length shortfall.
    #[test]
    fn huggingface_organization_token_rejects_embedded_prefix_and_underscore_or_dash_in_body() {
        let embedded = format!("legacyapi_org_{HUGGING_FACE_BODY}");
        assert_eq!(detect(&HUGGING_FACE, &embedded).len(), 0);

        for byte in ['_', '-'] {
            let mut body = HUGGING_FACE_BODY.to_string();
            body.replace_range(4..5, &byte.to_string());
            let value = format!("api_org_{body}");
            assert_eq!(detect(&HUGGING_FACE, &value).len(), 0, "{value}");
        }
    }

    /// Issue #551: the shared boundary/delimiter regression set, mirrored
    /// from `digitalocean-token`'s existing leading/trailing/dash
    /// identifier-embedding fixtures, for `huggingface-token`'s `api_org_`
    /// shape.
    #[test]
    fn huggingface_organization_token_rejects_every_embedding_shape_leading_trailing_or_dash_joined()
     {
        let value = format!("api_org_{HUGGING_FACE_BODY}");
        assert!(detect(&HUGGING_FACE, &format!("legacy{value}")).is_empty());
        assert!(detect(&HUGGING_FACE, &format!("{value}_backup")).is_empty());
        assert!(detect(&HUGGING_FACE, &format!("{value}-1")).is_empty());
    }

    /// Issue #485: the `hf_`/`api_org_` alphabet conflict (gitleaks:
    /// letters only; trufflehog: letters and digits) is resolved identically
    /// to `hf_` (issue #372) — the union, as a support-policy choice — so a
    /// digit-bearing `api_org_` body is still accepted.
    #[test]
    fn huggingface_organization_token_accepts_a_digit_bearing_documented_length_body() {
        let mut body = HUGGING_FACE_BODY.to_string();
        body.replace_range(0..2, "42");
        let value = format!("api_org_{body}");
        assert_eq!(detect(&HUGGING_FACE, &value).len(), 1, "{value}");
    }

    // Issue #369: the DigitalOcean v1 token contract. DigitalOcean's API
    // release notes (2022-03-29) document the `dop_v1_` / `doo_v1_` /
    // `dor_v1_` prefixes; gitleaks v8.30.1 and trufflehog v3.97.4
    // independently pin the body to `[a-f0-9]{64}`. Every body below is a
    // locally constructed synthetic value from the issue's self-contained
    // snapshot; none was ever provider-issued.

    /// The three documented prefixes, each with its synthetic 64-byte body.
    fn digitalocean_tokens() -> [String; 3] {
        [
            format!("dop_v1_{DIGITALOCEAN_BODY}"),
            format!("doo_v1_{DIGITALOCEAN_OAUTH_BODY}"),
            format!("dor_v1_{DIGITALOCEAN_REFRESH_BODY}"),
        ]
    }

    #[test]
    fn digitalocean_accepts_exactly_sixty_four_lowercase_hex_bytes_for_every_prefix() {
        for token in digitalocean_tokens() {
            assert_eq!(token.len(), 71);
            let candidates = detect(&DIGITALOCEAN, &token);
            assert_eq!(candidates.len(), 1, "{token}");
            assert_eq!(candidates[0].type_name(), "digitalocean_token");
            assert_eq!(candidates[0].confidence(), Confidence::High);
            assert_eq!(candidates[0].effective_specificity(), Specificity::Provider);
            assert_eq!(candidates[0].range(), ByteRange::new(0, 71).unwrap());
        }
    }

    // The reproduced beta.4 failure -- a 63-byte body (the paired positive
    // with its final byte dropped) accepted under the old 20-byte minimum,
    // both bare and in the Unicode/CRLF framing the benchmark used -- is the
    // exact scenario `tests/digitalocean_precision.rs` exists to pin, at
    // both the whole-input and isolated-detector level; not repeated here.

    /// A longer run of the boundary alphabet is a wider identifier, not a
    /// token with a valid-looking 64-byte substring: nothing is carved out
    /// of it on either side.
    #[test]
    fn digitalocean_never_extracts_a_token_from_a_wider_identifier() {
        for token in digitalocean_tokens() {
            for input in [
                // One extra hex byte: a 65-byte run.
                format!("{token}0"),
                // A trailing underscore- or dash-joined segment.
                format!("{token}_backup"),
                format!("{token}-1"),
                // A leading alphabet byte or identifier fragment.
                format!("x{token}"),
                format!("legacy{token}"),
            ] {
                assert!(detect(&DIGITALOCEAN, &input).is_empty(), "{input}");
            }
        }
    }

    #[test]
    fn digitalocean_rejects_uppercase_hex_and_non_hex_bytes_inside_the_body() {
        let token = format!("dop_v1_{DIGITALOCEAN_BODY}");
        let body_at = |index: usize, replacement: &str| {
            let at = "dop_v1_".len() + index;
            format!("{}{replacement}{}", &token[..at], &token[at + 1..])
        };
        for input in [
            // One uppercase hex digit inside the body.
            body_at(8, "D"),
            // One byte outside `[0-9a-f]`.
            body_at(8, "g"),
            // Whitespace splits the run.
            body_at(8, " "),
            // An uppercase final byte: 63 valid bytes then a boundary byte.
            body_at(63, "A"),
        ] {
            assert!(detect(&DIGITALOCEAN, &input).is_empty(), "{input}");
        }
    }

    /// Quotes, Markdown code spans, prose punctuation, and URL query
    /// delimiters all bound the token without joining it.
    #[test]
    fn digitalocean_bounds_the_token_against_quotes_code_spans_and_urls() {
        let token = format!("dop_v1_{DIGITALOCEAN_BODY}");
        for (input, start) in [
            (format!("\"{token}\""), 1),
            (format!("`{token}`"), 1),
            (format!("token: '{token}',"), 8),
            (format!("https://example.test/?token={token}&x=1"), 28),
        ] {
            let candidates = detect(&DIGITALOCEAN, &input);
            assert_eq!(candidates.len(), 1, "{input}");
            assert_eq!(
                candidates[0].range(),
                ByteRange::new(start, start + 71).unwrap(),
                "{input}"
            );
        }
    }

    #[test]
    fn digitalocean_rejects_wrong_and_encoded_prefixes_with_a_contracted_body() {
        for input in [
            format!("dov_v1_{DIGITALOCEAN_BODY}"),
            format!("dop_v2_{DIGITALOCEAN_BODY}"),
            format!("DOP_V1_{DIGITALOCEAN_BODY}"),
            format!("dop%5Fv1%5F{DIGITALOCEAN_BODY}"),
        ] {
            assert!(detect(&DIGITALOCEAN, &input).is_empty(), "{input}");
        }
    }

    // Issue #522: the Pulumi access token contract. The `pul-` prefix is
    // provider-documented (Pulumi's own Cloud REST API reference); the
    // exact 40-lowercase-hex body is tool-corroborated (gitleaks and
    // pleno-dlp independently agree). Every body below is a locally
    // constructed synthetic value; none was ever provider-issued.

    /// The documented shape, matched at `Confidence::High`,
    /// `Specificity::Provider`, at exactly the token's own range. Personal,
    /// organization, and team tokens share this one literal prefix and body
    /// grammar, so one synthetic body stands in for all three kinds.
    #[test]
    fn pulumi_accepts_exactly_forty_lowercase_hex_bytes() {
        let token = format!("pul-{PULUMI_BODY}");
        assert_eq!(token.len(), 44);
        let candidates = detect(&PULUMI, &token);
        assert_eq!(candidates.len(), 1);
        assert_eq!(candidates[0].type_name(), "pulumi_access_token");
        assert_eq!(candidates[0].confidence(), Confidence::High);
        assert_eq!(candidates[0].effective_specificity(), Specificity::Provider);
        assert_eq!(candidates[0].range(), ByteRange::new(0, 44).unwrap());
    }

    /// Length negative twin: gitleaks and pleno-dlp both pin the body to
    /// exactly 40 bytes, so a 39-byte or 41-byte body is an intentional
    /// false negative, not a fuzzy match against a minimum or a truncation
    /// to the documented width.
    #[test]
    fn pulumi_rejects_a_body_one_hex_byte_short_or_long_of_the_documented_length() {
        for body in [
            &PULUMI_BODY[..PULUMI_BODY.len() - 1],
            &format!("{PULUMI_BODY}0"),
        ] {
            let value = format!("pul-{body}");
            assert_eq!(detect(&PULUMI, &value).len(), 0, "{value}");
        }
    }

    /// Alphabet negative twin: both corroborating tools pin the body to
    /// lowercase hex only. An uppercase hex digit, a non-hex letter, or
    /// whitespace inside an otherwise documented-length body is rejected
    /// rather than truncated to its longest valid-alphabet prefix.
    #[test]
    fn pulumi_rejects_uppercase_hex_and_non_hex_bytes_inside_the_body() {
        let token = format!("pul-{PULUMI_BODY}");
        let body_at = |index: usize, replacement: &str| {
            let at = "pul-".len() + index;
            format!("{}{replacement}{}", &token[..at], &token[at + 1..])
        };
        for input in [
            body_at(8, "D"),
            body_at(8, "g"),
            body_at(8, " "),
            body_at(39, "A"),
        ] {
            assert!(detect(&PULUMI, &input).is_empty(), "{input}");
        }
    }

    /// Prefix negative twin: an undocumented near-miss prefix (missing or
    /// wrong separator, wrong case, one letter off, or the documented
    /// prefix embedded in a wider identifier) is a false negative by
    /// design, never a fuzzy match, the same rule this registry's other
    /// documented-prefix families already apply.
    #[test]
    fn pulumi_rejects_undocumented_near_miss_prefixes() {
        for input in [
            format!("pu-{PULUMI_BODY}"),
            format!("pull-{PULUMI_BODY}"),
            format!("pul_{PULUMI_BODY}"),
            format!("pul{PULUMI_BODY}"),
            format!("PUL-{PULUMI_BODY}"),
            format!("legacypul-{PULUMI_BODY}"),
            format!("pul%2D{PULUMI_BODY}"),
        ] {
            assert!(detect(&PULUMI, &input).is_empty(), "{input}");
        }
    }

    /// Benign controls (issue #522): a fully qualified Pulumi stack
    /// reference, a bare project name, `pulumi up`/`pulumi version`-style
    /// CLI output, and a documentation-style `x`-filled placeholder all
    /// carry no `pul-`-prefixed hex run and must stay unclassified.
    #[test]
    fn pulumi_rejects_stack_project_and_version_identifiers_as_benign_controls() {
        for input in [
            "stack: myorg/my-infra-project/production",
            "Updating (dev):\n    pulumi:pulumi:Stack my-infra-project-dev running\nResources: 3 unchanged\nUpdate succeeded in 8s",
            "Previewing update (staging)\n    Type                 Name\n +   pulumi:providers:aws default",
            "pulumi version\nv3.142.0",
            "PULUMI_ACCESS_TOKEN=pul-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        ] {
            assert!(detect(&PULUMI, input).is_empty(), "{input}");
        }
    }

    /// Quotes, Markdown code spans, and a `KEY=` assignment all bound the
    /// token without joining it, the same boundary behavior `DIGITALOCEAN`
    /// already exercises.
    #[test]
    fn pulumi_bounds_the_token_against_quotes_code_spans_and_assignments() {
        let token = format!("pul-{PULUMI_BODY}");
        for (input, start) in [
            (format!("\"{token}\""), 1),
            (format!("`{token}`"), 1),
            (
                format!("PULUMI_ACCESS_TOKEN={token}"),
                "PULUMI_ACCESS_TOKEN=".len(),
            ),
        ] {
            let candidates = detect(&PULUMI, &input);
            assert_eq!(candidates.len(), 1, "{input}");
            assert_eq!(
                candidates[0].range(),
                ByteRange::new(start, start + token.len()).unwrap(),
                "{input}"
            );
        }
    }
}