@@ -22,8 +22,13 @@ import { assertSnapshotDate } from '../queries/depsSql'
2222// produced by the resolution pipeline and were unaffected, so they are not probed here.
2323
2424export interface CheckEdgeSnapshotQualityInput {
25- snapshotDate : string // YYYY-MM-DD — the resolved BQ partition date being ingested
25+ snapshotDate : string // YYYY-MM-DD — the BQ partition the incremental diff reads (ignored when fullScan)
2626 ecosystems : string [ ]
27+ // Probe the SAME source the ingest reads, so the guard validates the snapshot that actually gets
28+ // ingested. Full/fill scan the *Latest views (newest snapshot, no date filter) → probe *Latest.
29+ // Incremental reads the `snapshotDate` partition → probe that partition. Without this, a full run
30+ // with an older --snapshot-date would validate a stale partition while ingesting a corrupt *Latest.
31+ fullScan : boolean
2732}
2833
2934export interface CanaryStat {
@@ -99,8 +104,6 @@ export async function checkEdgeSnapshotQuality(
99104 return { ok : true , canaries : [ ] }
100105 }
101106
102- assertSnapshotDate ( input . snapshotDate )
103-
104107 // Group canaries by system into `(System = x AND Name IN (...))` predicates so the filter prunes
105108 // on the (System, Name, Version) clustering — keeps the probe in the single-GB / pennies range.
106109 const bySystem = new Map < string , string [ ] > ( )
@@ -116,6 +119,22 @@ export async function checkEdgeSnapshotQuality(
116119 )
117120 . join ( '\n OR ' )
118121
122+ // Probe the same source the ingest reads (see fullScan): full/fill scan the *Latest view (newest
123+ // snapshot, no date filter); incremental reads the `snapshotDate` partition. The date is only
124+ // interpolated (and validated) on the partition path; *Latest needs no date.
125+ let edgesTable : string
126+ let snapshotFilter : string
127+ if ( input . fullScan ) {
128+ edgesTable = 'bigquery-public-data.deps_dev_v1.DependencyGraphEdgesLatest'
129+ snapshotFilter = ''
130+ } else {
131+ assertSnapshotDate ( input . snapshotDate )
132+ edgesTable = 'bigquery-public-data.deps_dev_v1.DependencyGraphEdges'
133+ snapshotFilter = `e.SnapshotAt >= TIMESTAMP('${ input . snapshotDate } ')
134+ AND e.SnapshotAt < TIMESTAMP(DATE_ADD(DATE '${ input . snapshotDate } ', INTERVAL 1 DAY))
135+ AND `
136+ }
137+
119138 // Direct edges only (From = graph root), matching what the ingest reads. %T formats NULLs
120139 // as the literal "NULL" so COUNT(DISTINCT ...) isn't nulled out by unresolved To.Version.
121140 const query = `
@@ -124,10 +143,8 @@ export async function checkEdgeSnapshotQuality(
124143 e.Name AS name,
125144 COUNT(*) AS row_count,
126145 COUNT(DISTINCT FORMAT('%T|%T|%T', e.From.Version, e.To.Name, e.To.Version)) AS edge_count
127- FROM \`bigquery-public-data.deps_dev_v1.DependencyGraphEdges\` e
128- WHERE e.SnapshotAt >= TIMESTAMP('${ input . snapshotDate } ')
129- AND e.SnapshotAt < TIMESTAMP(DATE_ADD(DATE '${ input . snapshotDate } ', INTERVAL 1 DAY))
130- AND e.From.Name = e.Name AND e.From.Version = e.Version
146+ FROM \`${ edgesTable } \` e
147+ WHERE ${ snapshotFilter } e.From.Name = e.Name AND e.From.Version = e.Version
131148 AND (
132149 ${ systemPredicates }
133150 )
0 commit comments