Skip to content

No spec compliance test validating constants.py against table.csv #41

Description

@sumanjeet0012

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

  1. Add the multicodec spec as a git submodule or download table.csv in CI:

    git submodule add https://github.com/multiformats/multicodec multicodec-spec
  2. 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
  3. 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions