test: cover the data/metrics.json render contract (tests/metrics-data.test.mjs) - #287
Open
kubestellar-hive[bot] wants to merge 1 commit into
Open
kubestellar-hive[bot] wants to merge 1 commit into
kubestellar-hive[bot] wants to merge 1 commit into
Conversation
scripts/validate-metrics.mjs is tolerant exactly where src/components/MetricsDashboard/index.js is not, so a metrics.json that passes npm run validate:metrics can still crash npm run build. Assert the real data/metrics.json against the invariants the dashboard depends on and the validator does not enforce: omitted present and an array, non-empty breakdown values with a positive descending-sorted divisor, finite numeric metric and lifecycle card values, and the referenceArchitectureLifecycle.trends shape Sparkline consumes, which the validator never inspects. Test-only; no production code, workflow or dependency is changed. Signed-off-by: kubestellar-hive[bot] <kubestellar-hive@hive.kubestellar.io>
Contributor
Author
|
Important Held for human review by the hive's ACMM level gate. This PR was opened by the "quality" agent while Hive policy required a human checkpoint for that agent. Non-outreach agents are held at ACMM L3–L5; the Hive will automatically remove the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test Improvement
Adds one new test-only file,
tests/metrics-data.test.mjs(11 tests),asserting the real
data/metrics.jsonagainst the render contract thatsrc/components/MetricsDashboard/index.jsdepends on.Files claimed by this PR:
tests/metrics-data.test.mjs(new). Nothingelse — no production code, no workflow, no
package.json, no lockfile, nodependency. It uses only
node:test,node:assert/strictandnode:fs.The gap
scripts/validate-metrics.mjsis tolerant exactly whereMetricsDashboardisnot, so a
data/metrics.jsonthat passesnpm run validate:metricscan stillcrash
npm run build:data.omitted || []; the component callsmetricsData.omitted.map(...)with no fallbackArray.isArray(chart.values); the component readschart.values[0].valueas the bar-width divisorundefined/null/''for a metric value; thecomponent calls
metric.value.toLocaleString()expecting a numberreferenceArchitectureLifecycle.cardsand.omittedbut never inspects
.trends, whichSparklinemaps overBar width is
item.value / chart.values[0].value * 100, so each breakdown mustalso be sorted descending with a divisor greater than zero. A zero divisor is
finite, so it validates clean and makes every bar width
NaN.Verification
Local clone of
cncf/endusersat00b44df, node v26.8.2.npm run test:unit: 66 pass, 0 fail (55 before; the 11 new tests are allthat changed).
npx prettier --check tests/metrics-data.test.mjs: clean.npm run validate:metricson restored data:Validated 2 metrics.The validator is blind to all of it. Seven mutations applied one at a time,
each passing the existing validator, each caught by this file:
validate:metricsdelete omittedbreakdowns.projectMaturity.values = []breakdowns.projectMaturity.values[0].value = 0breakdowns.projectCategories.values.reverse()metrics[0].value = '1,234'trends.submissions.values = 'x'delete trends.publications.values[0].dateFour further mutations — duplicate breakdown name, reversed series, a
non-finite lifecycle card value, and an unparseable
generatedAt— each failan assertion too, so all 11 tests are mutation-checked and none can silently
pass.
The first mutation was carried through a full build to confirm the consequence
is real rather than theoretical:
data/metrics.jsonwas restored byte-identical afterwards;git statusshowsonly the new test file.
Coverage evidence
npm run test:unitandnode --test --experimental-test-coverage,local clone at
00b44df, 2026-09-18, node v26.8.2. These invariants arecovered by no unit test.
data/metrics.jsonis data rather than anexecutable module, so it appears in no coverage report at any percentage —
this gap is invisible to
--experimental-test-coveragerather than shown asa low number. The only existing test that reads the real file is the smoke
test, which asserts just that the validator exits zero.
suite and publishes no coverage artifact from any suite (tracked in [quality] CI publishes no coverage evidence, so coverage findings cannot be verified #186).
No claim is made that these paths lack end-to-end coverage.
Disjointness
One new file, touched by no other open PR. Distinct from #263, which covers
scripts/validate-metrics.mjsbranch behaviour with synthetic fixtures andasserts nothing about the real
data/metrics.json— the mutation table aboveis precisely the set of shapes #263 proves the validator accepts. Distinct from
the other data-file contract tests (#235, #239, #241, #253, #257, #260, #270),
the navigation contract (#275) and the script wiring contract (#278), none of
which read
data/metrics.json. Unlike #225 and #229 it does not modifypackage.json, and unlike #229/#268 it adds no JSX or hook importinfrastructure, so it cannot conflict with either.
Related Issue
Closes #286 — merging this leaves nothing for that issue to track: it asks for
exactly this file, and its three completion criteria (the file exists and runs
under
npm run test:unit; every assertion mutation-checked; no productioncode, workflow,
package.jsonor dependency modified) are all met above.Filed by quality agent (hold-gated mode). Human review required.
— hive: agent=quality backend=copilot model=claude-opus-5