ruvnet.
Python
fix: reconcile profile metrics provenance
rUv5d9d9b5f7ce0
diff --git a/data/metrics.json b/data/metrics.jsonindex 0bda7fd..b154150 100644--- a/data/metrics.json+++ b/data/metrics.json@@ -34,7 +34,7 @@"Owned nonfork describes GitHub metadata, not sole authorship or originality.","Stars, clones and downloads do not establish unique users or revenue.","The aggregate artifact count combines current npm/crates inventory with 30 historically verified PyPI/Hugging Face artifacts.",- "Five all-package-zero npm dates in Oct 6-19 UTC are unknown (null), never zero; Oct 20 is incomplete and excluded.",+ "9 all-package-zero npm dates in 2026-10-12 through 2026-10-25 UTC are unknown (null), never zero; 2026-10-26 is incomplete and excluded.","The npm download cohort is 401 packages; the current inventory contains 401."],"sources": [@@ -53,18 +53,22 @@"npm_latest_confirmed_daily_downloads": 720281,"npm_latest_confirmed_daily_package_count": 401,"npm_latest_daily_is_rolling_24h": false,- "github_activity_start": "2026-10-06",- "github_activity_end": "2026-10-19",- "npm_14_day_confirmed_download_events": 5225040,+ "github_activity_start": "2026-10-12",+ "github_activity_end": "2026-10-25",+ "npm_14_day_confirmed_download_events": 2733103,"npm_14_day_unknown_days": [- "2026-10-06","2026-10-13","2026-10-14","2026-10-15",- "2026-10-19"+ "2026-10-19",+ "2026-10-20",+ "2026-10-21",+ "2026-10-23",+ "2026-10-24",+ "2026-10-25"],"npm_14_day_complete_utc_days": 14,- "npm_14_day_confirmed_days": 9,+ "npm_14_day_confirmed_days": 5,"npm_14_day_is_rolling_24h": false},"verification_dates": {@@ -74,5 +78,5 @@"crates_io": "2026-10-26T05:50:18.892080Z","pypi_and_huggingface": "2026-07-12; historical ownership verification, not re-counted"},- "source_watermark": "data/snapshots/2026-10-20/collection-watermark.json"+ "source_watermark": "data/snapshots/2026-10-26/collection-watermark.json"}diff --git a/scripts/tests/test_registry_refresh.py b/scripts/tests/test_registry_refresh.pyindex 9053a86..f3c11bd 100644--- a/scripts/tests/test_registry_refresh.py+++ b/scripts/tests/test_registry_refresh.py@@ -35,7 +35,7 @@ def result(package='example', positive_through='2026-10-05', requested_end='2026class RegistryRefreshTest(unittest.TestCase):def test_ecosystem_compositor_preserves_canonical_latest_day(self):"""The GitHub compositor must not drop fields needed by profile verification."""- snapshot=ROOT/'data/snapshots/2026-10-17'+ snapshot=ROOT/'data/snapshots/2026-10-26'old=json.loads((snapshot/'ecosystem-summary.json').read_text())evidence=json.loads((snapshot/'ecosystem-evidence.json').read_text())payload={@@ -61,7 +61,7 @@ class RegistryRefreshTest(unittest.TestCase):shutil.copyfile(entry,root/entry.name)(root/'input.json').write_text(json.dumps(payload))run=subprocess.run([sys.executable,'scripts/update-ecosystem-snapshot.py',- '--date','2026-10-17','--input','input.json'],cwd=root,+ '--date','2026-10-26','--input','input.json'],cwd=root,capture_output=True,text=True)self.assertEqual(run.returncode,0,run.stderr)check=subprocess.run(['node','scripts/verify-profile.mjs'],cwd=root,@@ -69,7 +69,20 @@ class RegistryRefreshTest(unittest.TestCase):self.assertEqual(check.returncode,0,check.stderr)current=json.loads((root/'data/registry-stats.json').read_text())running=json.loads((root/'data/ecosystem-running-totals.json').read_text())+ metrics=json.loads((root/'data/metrics.json').read_text())self.assertEqual(running['npm']['latest_confirmed_daily']['day'],current['npm']['period_end'])+ self.assertEqual(metrics['source_watermark'],+ 'data/snapshots/2026-10-26/collection-watermark.json')+ self.assertEqual(metrics['current_windows']['github_activity_start'],+ evidence['window']['start'])+ self.assertEqual(metrics['current_windows']['github_activity_end'],+ evidence['window']['end'])+ self.assertEqual(metrics['current_windows']['npm_14_day_confirmed_download_events'],+ running['npm']['observed_downloads'])+ self.assertEqual(metrics['current_windows']['npm_14_day_unknown_days'],+ running['npm']['unknown_days'])+ self.assertEqual(metrics['current_windows']['npm_14_day_confirmed_days'],+ running['npm']['confirmed_days'])def test_new_npm_package_404_is_retried_without_inventing_zero(self):url='https://api.npmjs.org/downloads/range/2025-10-01:2026-10-11/new-package'diff --git a/scripts/update-ecosystem-snapshot.py b/scripts/update-ecosystem-snapshot.pyindex 83b9a9d..2dde0b2 100644--- a/scripts/update-ecosystem-snapshot.py+++ b/scripts/update-ecosystem-snapshot.py@@ -181,12 +181,14 @@ def main():else:npm_gap_sentence = 'All inventory packages have download-range evidence.'+ watermark_path = f'{folder}/collection-watermark.json'+ watermark = read(watermark_path) if (ROOT / watermark_path).exists() else Nonerunning = read('data/ecosystem-running-totals.json')generated_at = max(stamp, registry['generated_at'])same_snapshot = prior.get('verified_at') == stamprunning.update(verified_at=generated_at,- source_watermark=(read(f'{folder}/collection-watermark.json') if (ROOT / f'{folder}/collection-watermark.json').exists() else running.get('source_watermark')),+ source_watermark=(watermark if watermark is not None else running.get('source_watermark')),github=collection,activity=activity,npm={@@ -300,8 +302,30 @@ def main():'npm_period_start': registry['npm']['period_start'],'npm_period_end': registry['npm']['period_end'],'npm_download_package_count': registry['npm']['download_package_count'],+ 'github_activity_start': window_start,+ 'github_activity_end': window_end,+ 'npm_14_day_confirmed_download_events': running['npm']['observed_downloads'],+ 'npm_14_day_unknown_days': running['npm']['unknown_days'],+ 'npm_14_day_complete_utc_days': len(expected),+ 'npm_14_day_confirmed_days': running['npm']['confirmed_days'],+ 'npm_14_day_is_rolling_24h': False,})metrics['verification_dates'].update({'github': stamp, 'npm_inventory': registry['npm']['inventory_verified_at'], 'npm_downloads': registry['npm']['downloads_verified_at'], 'crates_io': crates['verified_at']})+ if watermark is not None:+ metrics['source_watermark'] = watermark_path+ retained_notes = [+ note for note in metrics.get('notes', [])+ if 'all-package-zero npm dates' not in note+ and not note.startswith('The npm download cohort is ')+ ]+ retained_notes.extend([+ (f"{len(missing_days)} all-package-zero npm dates in {window_start} through "+ f"{window_end} UTC are unknown (null), never zero; {args.date} is incomplete "+ "and excluded."),+ (f"The npm download cohort is {registry['npm']['download_package_count']} packages; "+ f"the current inventory contains {registry['npm']['package_count']}."),+ ])+ metrics['notes'] = retained_noteswrite('data/metrics.json', metrics)evidence = {diff --git a/scripts/verify-profile.mjs b/scripts/verify-profile.mjsindex 91cd250..5dbba8a 100644--- a/scripts/verify-profile.mjs+++ b/scripts/verify-profile.mjs@@ -36,6 +36,19 @@ for (const flagship of github.flagships) {const metrics = json('data/metrics.json');const registry = json('data/registry-stats.json');const npm = registry.npm, crates = registry.crates_io;+const expectedWatermarkPath = path.posix.join(path.posix.dirname(github.inventory), 'collection-watermark.json');+assert.equal(metrics.source_watermark, expectedWatermarkPath, 'Metrics must link the current GitHub snapshot watermark');+assert.ok(fs.existsSync(path.join(root, expectedWatermarkPath)), `Missing current source watermark: ${expectedWatermarkPath}`);+const watermark = json(expectedWatermarkPath);+assert.equal(watermark.repository, 'ruvnet/ruvnet');+assert.equal(watermark.snapshot_date, path.posix.basename(path.posix.dirname(expectedWatermarkPath)));+assert.equal(watermark.github_verified_at, github.verified_at);+assert.equal(watermark.npm_inventory_verified_at, metrics.verification_dates.npm_inventory);+assert.equal(watermark.npm_downloads_verified_at, metrics.verification_dates.npm_downloads);+assert.equal(watermark.crates_io_verified_at, metrics.verification_dates.crates_io);+assert.equal(watermark.public_repository_ids, expected.public_repositories);+assert.equal(watermark.npm_coverage.packages, npm.package_count);+assert.equal(watermark.crates_io_coverage.crates, crates.crate_count);assert.equal(metrics.counts.github_public_repositories, expected.public_repositories);assert.equal(metrics.counts.github_stars_owned_nonfork, expected.stars_across_owned_nonfork);assert.equal(metrics.counts.npm_packages, npm.package_count);@@ -107,6 +120,14 @@ assert.ok(reportingBlock.includes(npm.period_end));assert.ok(reportingBlock.includes(npm.downloads_evidence_path));assert.ok(reportingBlock.includes(npm.downloads_verified_at.slice(0, 10)));const running = json('data/ecosystem-running-totals.json');+assert.deepEqual(running.source_watermark, watermark, 'Embedded source watermark must match its dated file');+assert.equal(metrics.current_windows.github_activity_start, watermark.activity_window_utc.start);+assert.equal(metrics.current_windows.github_activity_end, watermark.activity_window_utc.end);+assert.equal(metrics.current_windows.npm_14_day_confirmed_download_events, running.npm.observed_downloads);+assert.deepEqual(metrics.current_windows.npm_14_day_unknown_days, running.npm.unknown_days);+assert.equal(metrics.current_windows.npm_14_day_complete_utc_days, watermark.activity_window_utc.complete_days);+assert.equal(metrics.current_windows.npm_14_day_confirmed_days, running.npm.confirmed_days);+assert.equal(metrics.current_windows.npm_14_day_is_rolling_24h, false);const milestone = running.download_milestone;const periodTotal = npm.monthly_downloads.reduce((sum,row)=>sum+row.downloads,0)+(npm.current_month?.downloads || 0);assert.equal(milestone.npm_observed_total, periodTotal, 'Dashboard milestone npm total must match registry');