There is no test that validates the contents of constants.py against the authoritative upstream multicodec table.csv. This means the codec table can silently drift from the spec — codecs can be missing, have wrong codes, or be extra.
Problem
The CODECS dict in constants.py is generated from table.csv by tools/update-table.py, but:
- The generation is manual (not automated in CI)
- There is no test that verifies the generated output matches the source CSV
- A developer could hand-edit
constants.py and introduce inconsistencies
- Codecs added to the upstream CSV won't be detected as missing
go-multicodec has a spec compliance test (TestSpec) that validates its generated code against the CSV:
func TestSpec(t *testing.T) {
// Reads multicodec/table.csv
// Validates every entry matches the generated code
}
Proposed Solution
-
Add the multicodec spec as a git submodule or download table.csv in CI:
git submodule add https://github.com/multiformats/multicodec multicodec-spec
-
Create tests/test_spec.py with a test that:
- Reads
multicodec-spec/table.csv
- Verifies every CSV entry with
tag != "none" exists in CODECS with the correct prefix
- Verifies no extra entries exist in
CODECS that aren't in the CSV
- Verifies
NAME_TABLE and CODE_TABLE are consistent with CODECS
-
Example test structure:
def test_spec_table_completeness():
"""Every entry in table.csv should be in CODECS."""
csv_entries = load_csv("multicodec-spec/table.csv")
for name, tag, code, status, desc in csv_entries:
if tag == "none":
continue
assert name in NAME_TABLE, f"Missing codec: {name} ({code})"
assert NAME_TABLE[name] == int(code, 16), f"Code mismatch for {name}"
Related
There is no test that validates the contents of
constants.pyagainst the authoritative upstream multicodec table.csv. This means the codec table can silently drift from the spec — codecs can be missing, have wrong codes, or be extra.Problem
The
CODECSdict inconstants.pyis generated fromtable.csvbytools/update-table.py, but:constants.pyand introduce inconsistenciesgo-multicodec has a spec compliance test (
TestSpec) that validates its generated code against the CSV:Proposed Solution
Add the multicodec spec as a git submodule or download
table.csvin CI:Create
tests/test_spec.pywith a test that:multicodec-spec/table.csvtag != "none"exists inCODECSwith the correct prefixCODECSthat aren't in the CSVNAME_TABLEandCODE_TABLEare consistent withCODECSExample test structure:
Related