Repository navigation
feat(airc-core): convert ID newtypes from String to UUIDv4 - #664
Merged
Merged
Conversation
PR-1 of the airc-core UUID migration per the substrate design doc's
"Identifiers — UUIDv4 everywhere" section. Locks the mesh-native
identifier discipline at compile time: every runtime ID is now a
typed UUIDv4 wrapper, not a bare String.
Changes:
- Cargo.toml: add `uuid = { version = "1", features = ["v4", "serde"] }`
- ids.rs: rewrite as macro-generated UUIDv4 newtypes —
EventId(Uuid), RoomId(Uuid), PeerId(Uuid), ClientId(Uuid),
FileId(Uuid). Each gets `::new()` (UUIDv4 random), `::from_u128()`
(deterministic for tests), `::from_uuid()`, `::as_uuid()`,
`Default`, `Display`.
- ContentHash stays as `pub struct ContentHash(pub String)` —
content addressing has different requirements (deterministic +
payload-derived) than runtime ids; UUIDs would defeat both
properties.
- transcript.rs: `event_id.clone()` → `event_id` (now Copy)
- cursor.rs + filter.rs: test helpers use `EventId::from_u128(N)`
+ named locals so assertions reference UUIDs directly instead
of string literals.
- attachment.rs: test uses deterministic UUID for FileId; serde
assert updated to expect canonical hyphenated UUID string on
the wire.
7 new ids.rs tests pin the contract:
- new_event_id_is_random_uuidv4
- from_u128_is_deterministic_for_tests
- serde_roundtrips_via_hyphenated_string
- display_uses_hyphenated_lowercase
- malformed_uuid_string_fails_parse (fail-loud at envelope deserialize)
- all_id_newtypes_share_the_uuidv4_contract
- content_hash_is_not_uuid_typed (pins the discipline distinction)
Wire shape unchanged: serde encodes Uuid as canonical hyphenated
string, so JSON envelopes stay human-readable and cross-language
parsers work. Backward-compat with Python+bash airc envelopes that
happen to carry UUID-shaped strings already; non-UUID strings now
fail to parse (fail-loud over silent String coercion).
Full airc-core: 23/23 tests pass (was 16; +7 from ids.rs). Clippy
`--all-targets --all-features -- -D warnings`: 0 warnings. cargo
fmt --check: 0 diffs. Conforms to the rust.yml gates landing in #661.
Stacks on the rust-rewrite integration branch.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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.
Summary
Locks the UUIDv4 mesh-native identifier discipline at the compile-time level. Every runtime ID in airc-core is now a typed UUID newtype.
Companion to docs PR #663 (which anchors the policy). This PR is the code-side implementation.
Changes
Wire shape unchanged
serde encodes Uuid as the canonical hyphenated string (`"550e8400-e29b-41d4-a716-446655440000"`). JSON envelopes stay human-readable and cross-language parsers work. Backward-compat with Python+bash airc envelopes that happen to carry UUID-shaped strings.
Fail-loud upgrade: non-UUID strings (e.g. legacy "e1" test IDs) now fail to parse at envelope deserialize instead of silently coercing into a String. This is the substrate's discipline — malformed identifiers don't reach routing.
Test plan
What this does NOT add
🤖 Generated with Claude Code