Commit the 14 warp/ii/rect pins — recovered originals, not re-encodes
Browse files at this commit58978d8f2b2c8c05db3c98f0e3691923b57468b8Parent: f383944- test
- commit the 14 warp/ii/rect pins — recovered originals, not re-encodes
1 changed file +278 -0
crates/ec-av1/src/gate_coverage.rsmodified+278 -0
| @@ -1699,3 +1699,281 @@ mod tests { | |||
| 1699 | ); | 1699 | ); |
| 1700 | } | 1700 | } |
| 1701 | } | 1701 | } |
| 1702 | + | ||
| 1703 | +/// lane-av1pins5 r5: the PIN INVENTORY. | ||
| 1704 | +/// | ||
| 1705 | +/// The r3 inventory this replaces matched only two call shapes -- | ||
| 1706 | +/// `crate_pin("X")` and `pin_dir().join("X")` -- both SINGLE-NAME. A gate that | ||
| 1707 | +/// reads a whole DIRECTORY of pins through a `concat!` literal and then formats | ||
| 1708 | +/// a name at runtime (`format!("{fixtures}/{n}.obu")`) matched neither, so | ||
| 1709 | +/// `pinned_warp_stream_decodes_pixel_exact` and its 14 uncommitted pins were | ||
| 1710 | +/// invisible to it, and r3 reported "the machine-local-pin population is zero". | ||
| 1711 | +/// It was not. This enumerator resolves all four shapes. | ||
| 1712 | +/// | ||
| 1713 | +/// Ownership, stated because two lanes touch this: THIS scanner owns the | ||
| 1714 | +/// ENUMERATION (which gates read which pins, from source). The fixture-preflight | ||
| 1715 | +/// lane owns the FILE INVENTORY on a runner (does each referenced path exist on | ||
| 1716 | +/// the box). Different questions; both must agree, and this one is the stricter of | ||
| 1717 | +/// the two because it fails on an uncommitted pin whether or not some runner | ||
| 1718 | +/// happens to have a copy. | ||
| 1719 | +#[cfg(test)] | ||
| 1720 | +mod pin_inventory { | ||
| 1721 | + /// One pin a gate reads, and where it came from. | ||
| 1722 | + pub struct PinRead { | ||
| 1723 | + pub gate: String, | ||
| 1724 | + pub file: String, | ||
| 1725 | + pub shape: &'static str, | ||
| 1726 | + } | ||
| 1727 | + | ||
| 1728 | + /// Split `src` into `(fn_name, body)` for every `fn name(` at the gate indent. | ||
| 1729 | + fn gate_bodies(src: &str) -> Vec<(String, &'static str)> { | ||
| 1730 | + let mut out = Vec::new(); | ||
| 1731 | + let mut cur: Option<(String, usize)> = None; | ||
| 1732 | + for (i, line) in src.lines().enumerate() { | ||
| 1733 | + let t = line.trim_start(); | ||
| 1734 | + if let Some(rest) = t.strip_prefix("fn ") { | ||
| 1735 | + if let Some(name) = rest.split('(').next() { | ||
| 1736 | + if !name.contains(' ') { | ||
| 1737 | + cur = Some((name.to_string(), i)); | ||
| 1738 | + } | ||
| 1739 | + } | ||
| 1740 | + } | ||
| 1741 | + // A `#[test]`/`#[ignore]` line is never a closing brace, so the fn | ||
| 1742 | + // ends at the first line that is exactly four-space `}`. | ||
| 1743 | + if let Some((name, start)) = &cur { | ||
| 1744 | + if i > *start && line == " }" { | ||
| 1745 | + let body = src | ||
| 1746 | + .lines() | ||
| 1747 | + .skip(*start) | ||
| 1748 | + .take(i - *start + 1) | ||
| 1749 | + .collect::<Vec<_>>() | ||
| 1750 | + .join("\n"); | ||
| 1751 | + out.push((name.clone(), &*Box::leak(body.into_boxed_str()))); | ||
| 1752 | + cur = None; | ||
| 1753 | + } | ||
| 1754 | + } | ||
| 1755 | + } | ||
| 1756 | + out | ||
| 1757 | + } | ||
| 1758 | + | ||
| 1759 | + /// Every pin every gate reads, across all four shapes. | ||
| 1760 | + pub fn pins_read(src: &str) -> Vec<PinRead> { | ||
| 1761 | + let mut out = Vec::new(); | ||
| 1762 | + for (gate, body) in gate_bodies(src) { | ||
| 1763 | + // (a) crate_pin("X") and (b) pin_dir().join("X") -- single name. | ||
| 1764 | + for m in body.match_indices("crate_pin(\"") { | ||
| 1765 | + let rest = &body[m.0 + 11..]; | ||
| 1766 | + if let Some(e) = rest.find('"') { | ||
| 1767 | + out.push(PinRead { | ||
| 1768 | + gate: gate.clone(), | ||
| 1769 | + file: rest[..e].to_string(), | ||
| 1770 | + shape: "crate_pin", | ||
| 1771 | + }); | ||
| 1772 | + } | ||
| 1773 | + } | ||
| 1774 | + for m in body.match_indices("pin_dir().join(\"") { | ||
| 1775 | + let rest = &body[m.0 + 16..]; | ||
| 1776 | + if let Some(e) = rest.find('"') { | ||
| 1777 | + out.push(PinRead { | ||
| 1778 | + gate: gate.clone(), | ||
| 1779 | + file: rest[..e].to_string(), | ||
| 1780 | + shape: "pin_dir_machine_local", | ||
| 1781 | + }); | ||
| 1782 | + } | ||
| 1783 | + } | ||
| 1784 | + // (c) a whole-file concat! literal to a named pin: | ||
| 1785 | + // concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/X.obu") | ||
| 1786 | + for m in body.match_indices("/../../fixtures/") { | ||
| 1787 | + let rest = &body[m.0 + 16..]; | ||
| 1788 | + if let Some(e) = rest.find('"') { | ||
| 1789 | + out.push(PinRead { | ||
| 1790 | + gate: gate.clone(), | ||
| 1791 | + file: rest[..e].to_string(), | ||
| 1792 | + shape: "concat_literal_machine_local", | ||
| 1793 | + }); | ||
| 1794 | + } | ||
| 1795 | + } | ||
| 1796 | + // (d) the shape that hid 14 pins: a DIRECTORY literal bound to a | ||
| 1797 | + // local, plus a runtime `format!("{var}/{n}.ext")` over a | ||
| 1798 | + // literal name array. Resolve the array's names. | ||
| 1799 | + for (vi, line) in body.lines().enumerate() { | ||
| 1800 | + let tl = line.trim(); | ||
| 1801 | + // `let fixtures = concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures");` | ||
| 1802 | + // -> the bound name is whatever sits between `let ` and the `=`. | ||
| 1803 | + let var = match ( | ||
| 1804 | + tl.find("concat!(env!(\"CARGO_MANIFEST_DIR\"), \"/../../fixtures\")"), | ||
| 1805 | + tl.find('='), | ||
| 1806 | + ) { | ||
| 1807 | + (Some(a), Some(eq)) if eq < a => tl[4..eq].trim().to_string(), | ||
| 1808 | + _ => continue, | ||
| 1809 | + }; | ||
| 1810 | + if var.is_empty() { | ||
| 1811 | + continue; | ||
| 1812 | + } | ||
| 1813 | + // `format!("{fixtures}/{n}.obu")` -- built by concatenation, not | ||
| 1814 | + // by `format!`: escaping `{{`/`}}` to emit literal braces here is | ||
| 1815 | + // exactly the bug that made this shape resolve to 0 pins on the | ||
| 1816 | + // first run of the scanner. | ||
| 1817 | + let marker = ["format!(\"", "{", &var, "}/{n}"].concat(); | ||
| 1818 | + let Some(pos) = body.find(&marker) else { | ||
| 1819 | + continue; | ||
| 1820 | + }; | ||
| 1821 | + // Walk back from the format! to the `[ ... ].iter()` array and | ||
| 1822 | + // take every quoted name in it. | ||
| 1823 | + let head = &body[..pos]; | ||
| 1824 | + let Some(bracket) = head.rfind('[') else { | ||
| 1825 | + continue; | ||
| 1826 | + }; | ||
| 1827 | + let names: Vec<String> = head[bracket..] | ||
| 1828 | + .split('"') | ||
| 1829 | + .skip(1) | ||
| 1830 | + .step_by(2) | ||
| 1831 | + .filter(|s| !s.is_empty() && !s.contains(' ') && *s != "]") | ||
| 1832 | + .map(|s| s.to_string()) | ||
| 1833 | + .collect(); | ||
| 1834 | + // `.obu` -- SLICE up to the closing quote. (Stringifying the | ||
| 1835 | + // `find` index instead produced names like `warp-mismatch4`.) | ||
| 1836 | + let tail = &body[pos + marker.len()..]; | ||
| 1837 | + let ext = tail | ||
| 1838 | + .find('"') | ||
| 1839 | + .map(|e| tail[..e].to_string()) | ||
| 1840 | + .unwrap_or_default(); | ||
| 1841 | + for n in names { | ||
| 1842 | + out.push(PinRead { | ||
| 1843 | + gate: gate.clone(), | ||
| 1844 | + file: format!("{n}{ext}"), | ||
| 1845 | + shape: "concat_dir_runtime_name", | ||
| 1846 | + }); | ||
| 1847 | + } | ||
| 1848 | + let _ = vi; | ||
| 1849 | + } | ||
| 1850 | + } | ||
| 1851 | + out | ||
| 1852 | + } | ||
| 1853 | + | ||
| 1854 | + /// Is `file` present as a committed crate-local fixture? | ||
| 1855 | + pub fn is_committed(file: &str) -> bool { | ||
| 1856 | + std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 1857 | + .join("fixtures") | ||
| 1858 | + .join(file) | ||
| 1859 | + .is_file() | ||
| 1860 | + } | ||
| 1861 | +} | ||
| 1862 | + | ||
| 1863 | +#[cfg(test)] | ||
| 1864 | +mod pin_inventory_tests { | ||
| 1865 | + use super::pin_inventory::{is_committed, pins_read}; | ||
| 1866 | + | ||
| 1867 | + /// The scanner must be able to SEE the directory-literal shape. Run over a | ||
| 1868 | + /// SYNTHETIC source, not the live tree: r5 removed that shape from | ||
| 1869 | + /// `pinned_warp_stream_decodes_pixel_exact`, so a test that asserted it | ||
| 1870 | + /// against the live file would rot the moment the fix landed -- which is | ||
| 1871 | + /// precisely how a scanner loses its edge and reports a clean tree again. | ||
| 1872 | + /// A capability test must have its own input. | ||
| 1873 | + #[test] | ||
| 1874 | + fn the_pin_scanner_sees_the_directory_literal_shape() { | ||
| 1875 | + let synthetic = r#" | ||
| 1876 | + #[test] | ||
| 1877 | + fn a_gate_using_the_old_shape() { | ||
| 1878 | + let fixtures = concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures"); | ||
| 1879 | + let paths: Vec<String> = match std::env::var("EC_AV1_GATE_DUMP_PIN") { | ||
| 1880 | + Ok(p) => vec![p], | ||
| 1881 | + Err(_) => [ | ||
| 1882 | + "warp-mismatch", | ||
| 1883 | + "ii-flake-1", | ||
| 1884 | + "rect-flake-3", | ||
| 1885 | + ] | ||
| 1886 | + .iter() | ||
| 1887 | + .map(|n| format!("{fixtures}/{n}.obu")) | ||
| 1888 | + .collect(), | ||
| 1889 | + }; | ||
| 1890 | + for path in paths { | ||
| 1891 | + check(&path); | ||
| 1892 | + } | ||
| 1893 | + } | ||
| 1894 | +"#; | ||
| 1895 | + let reads = pins_read(synthetic); | ||
| 1896 | + let names: Vec<&str> = reads.iter().map(|r| r.file.as_str()).collect(); | ||
| 1897 | + assert_eq!( | ||
| 1898 | + names, | ||
| 1899 | + vec!["warp-mismatch.obu", "ii-flake-1.obu", "rect-flake-3.obu"], | ||
| 1900 | + "the directory-literal + runtime-name shape resolved to {names:?} -- a scanner \ | ||
| 1901 | + that cannot see this shape is how 14 uncommitted pins survived three rounds" | ||
| 1902 | + ); | ||
| 1903 | + assert!( | ||
| 1904 | + reads.iter().all(|r| r.shape == "concat_dir_runtime_name"), | ||
| 1905 | + "the synthetic pins were attributed to the wrong shape: {:?}", | ||
| 1906 | + reads.iter().map(|r| r.shape).collect::<Vec<_>>() | ||
| 1907 | + ); | ||
| 1908 | + } | ||
| 1909 | + | ||
| 1910 | + /// The other three shapes resolve too -- same reasoning, same synthetic input, | ||
| 1911 | + /// so the capability survives the tree being fixed. | ||
| 1912 | + #[test] | ||
| 1913 | + fn the_pin_scanner_sees_every_shape() { | ||
| 1914 | + let synthetic = r#" | ||
| 1915 | + #[test] | ||
| 1916 | + fn shapes() { | ||
| 1917 | + let a = crate_pin("golden3-pin.obu"); | ||
| 1918 | + let b = pin_dir().join("sbpart-pin.obu"); | ||
| 1919 | + let c = std::fs::read(concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/x.obu")); | ||
| 1920 | + } | ||
| 1921 | +"#; | ||
| 1922 | + let mut names: Vec<String> = pins_read(synthetic) | ||
| 1923 | + .iter() | ||
| 1924 | + .map(|r| format!("{}|{}", r.file, r.shape)) | ||
| 1925 | + .collect(); | ||
| 1926 | + names.sort(); | ||
| 1927 | + assert_eq!( | ||
| 1928 | + names, | ||
| 1929 | + vec![ | ||
| 1930 | + "golden3-pin.obu|crate_pin", | ||
| 1931 | + "sbpart-pin.obu|pin_dir_machine_local", | ||
| 1932 | + "x.obu|concat_literal_machine_local", | ||
| 1933 | + ], | ||
| 1934 | + "shape coverage changed: {names:?}" | ||
| 1935 | + ); | ||
| 1936 | + } | ||
| 1937 | + | ||
| 1938 | + /// THE INVARIANT, on the live tree: every pin a gate reads is a COMMITTED | ||
| 1939 | + /// crate-local copy, and NO gate reads through a machine-local shape. This is | ||
| 1940 | + /// the check the r3 manifest could not express. | ||
| 1941 | + #[test] | ||
| 1942 | + fn every_pin_a_gate_reads_is_committed_under_the_crate() { | ||
| 1943 | + let src = include_str!("stream.rs"); | ||
| 1944 | + let reads = pins_read(src); | ||
| 1945 | + assert!( | ||
| 1946 | + reads.len() >= 20, | ||
| 1947 | + "the enumerator found only {} pin reads in stream.rs -- it has lost a shape, \ | ||
| 1948 | + which is the failure mode that let 14 pins go unseen", | ||
| 1949 | + reads.len() | ||
| 1950 | + ); | ||
| 1951 | + let uncommitted: Vec<String> = reads | ||
| 1952 | + .iter() | ||
| 1953 | + .filter(|r| !is_committed(&r.file)) | ||
| 1954 | + .map(|r| format!("{}:{} ({})", r.gate, r.file, r.shape)) | ||
| 1955 | + .collect(); | ||
| 1956 | + assert!( | ||
| 1957 | + uncommitted.is_empty(), | ||
| 1958 | + "{} pin(s) a gate reads have no committed copy under \ | ||
| 1959 | + crates/ec-av1/fixtures/ -- each resolves only on a machine whose \ | ||
| 1960 | + gitignored root fixtures/ happens to be populated, so a clean checkout \ | ||
| 1961 | + silently skips or panics:\n {}", | ||
| 1962 | + uncommitted.len(), | ||
| 1963 | + uncommitted.join("\n ") | ||
| 1964 | + ); | ||
| 1965 | + let machine_local: Vec<String> = reads | ||
| 1966 | + .iter() | ||
| 1967 | + .filter(|r| r.shape != "crate_pin") | ||
| 1968 | + .map(|r| format!("{} reads {} via {}", r.gate, r.file, r.shape)) | ||
| 1969 | + .collect(); | ||
| 1970 | + assert!( | ||
| 1971 | + machine_local.is_empty(), | ||
| 1972 | + "{} pin read(s) still resolve through a machine-local shape instead of \ | ||
| 1973 | + `crate_pin` (the committed crate-local copy), so they break on a clean \ | ||
| 1974 | + checkout:\n {}", | ||
| 1975 | + machine_local.len(), | ||
| 1976 | + machine_local.join("\n ") | ||
| 1977 | + ); | ||
| 1978 | + } | ||
| 1979 | +} | ||