Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 9 additions & 41 deletions rs/hang/src/catalog/audio/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,26 @@ pub enum AudioCodec {
}

/// Coarse audio codec family, used for tag-only matching.
// Explicit discriminants keep `as` values stable: a new kind takes the next number.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum AudioCodecKind {
/// Advanced Audio Coding.
AAC,
AAC = 0,
/// Opus.
Opus,
Opus = 1,
/// Unknown or unsupported codec.
Unknown,
Unknown = 2,
/// Free Lossless Audio Codec.
Flac,
Flac = 3,
/// MPEG-1/2 Audio Layer III.
Mp3,
Mp3 = 4,
/// Uncompressed interleaved little-endian IEEE-754 binary32 PCM.
Pcm,
Pcm = 5,
/// Dolby Digital (AC-3).
Ac3,
Ac3 = 6,
/// Dolby Digital Plus (E-AC-3).
Ec3,
Ec3 = 7,
}

impl AudioCodec {
Expand Down Expand Up @@ -124,36 +125,3 @@ impl FromStr for AudioCodec {
Ok(Self::Unknown(s.to_string()))
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the discriminant regression guard

Removing codec_kind_discriminants_are_stable leaves no repository-wide assertion for this public enum's implicit as values. If a future codec kind is inserted anywhere but the end, the change compiles while silently renumbering every later variant; retain this guard or assign explicit discriminants so the required append-only invariant is enforced.

AGENTS.md reference: rs/AGENTS.md:L47-L48

Useful? React with 👍 / 👎.

@kixelated kixelated Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ac843a5: AudioCodecKind now has explicit discriminants AAC = 0 through Ec3 = 7, so the type enforces the append-only values itself. A kind inserted mid-list without a number collides with the next explicit discriminant and fails to compile. (Written by Claude Opus 5.5)


#[cfg(test)]
mod tests {
use super::*;

#[test]
fn flac_roundtrip() {
let codec = AudioCodec::from_str("flac").unwrap();
assert_eq!(codec, AudioCodec::Flac);
assert_eq!(codec.to_string(), "flac");
assert_eq!(codec.kind(), AudioCodecKind::Flac);
}

#[test]
fn pcm_roundtrip() {
let codec = AudioCodec::from_str("pcm").unwrap();
assert_eq!(codec, AudioCodec::Pcm);
assert_eq!(codec.to_string(), "pcm");
assert_eq!(codec.kind(), AudioCodecKind::Pcm);
}

#[test]
fn codec_kind_discriminants_are_stable() {
assert_eq!(AudioCodecKind::AAC as isize, 0);
assert_eq!(AudioCodecKind::Opus as isize, 1);
assert_eq!(AudioCodecKind::Unknown as isize, 2);
assert_eq!(AudioCodecKind::Flac as isize, 3);
assert_eq!(AudioCodecKind::Mp3 as isize, 4);
assert_eq!(AudioCodecKind::Pcm as isize, 5);
assert_eq!(AudioCodecKind::Ac3 as isize, 6);
assert_eq!(AudioCodecKind::Ec3 as isize, 7);
}
}
11 changes: 0 additions & 11 deletions rs/hang/src/catalog/audio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,17 +302,6 @@ mod test {
assert_eq!(catalog.enabled().count(), 1);
}

#[test]
fn label_round_trips() {
let mut config = AudioConfig::new(AudioCodec::Opus, 48_000, 2);
config.label = Some("English".to_string());

let encoded = serde_json::to_value(&config).expect("failed to encode");
assert_eq!(encoded["label"], "English");
let decoded: AudioConfig = serde_json::from_value(encoded).expect("failed to decode");
assert_eq!(decoded.label.as_deref(), Some("English"));
}

#[test]
fn enabled_is_written_only_when_false() {
let mut config = AudioConfig::new(AudioCodec::Opus, 48_000, 2);
Expand Down
15 changes: 0 additions & 15 deletions rs/hang/src/catalog/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,6 @@ impl FromStr for Mode {
mod test {
use super::*;

#[test]
fn known_roundtrip() {
for (mode, json) in [(Mode::Snapshot, r#""snapshot""#), (Mode::Stream, r#""stream""#)] {
let config = crate::catalog::JsonConfig::new(mode.clone());
let encoded = serde_json::to_value(&config).unwrap();
assert_eq!(encoded["mode"].to_string(), json);
assert_eq!(
serde_json::from_value::<crate::catalog::JsonConfig>(encoded)
.unwrap()
.mode,
mode
);
}
}

#[test]
fn unknown_roundtrip() {
let wire = serde_json::json!({ "mode": "future" });
Expand Down
13 changes: 0 additions & 13 deletions rs/hang/src/catalog/priority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,3 @@ pub const PRIORITY: Priorities = Priorities {
audio: 80,
video: 60,
};

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn media_priorities_match_the_browser() {
assert_eq!(PRIORITY.catalog, 100);
assert_eq!(PRIORITY.text, 90);
assert_eq!(PRIORITY.audio, 80);
assert_eq!(PRIORITY.video, 60);
}
}
15 changes: 0 additions & 15 deletions rs/hang/src/catalog/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,14 +887,6 @@ mod test {
assert!(output.contains(r#""magic":7"#), "unknown fields dropped: {output}");
}

#[test]
fn empty_text_section_omitted() {
// A catalog without captions omits the text section, as it does for empty video and audio.
let catalog = Catalog::<()>::default();
let output = catalog.to_json().expect("failed to encode");
assert!(!output.contains("text"), "empty text section leaked: {output}");
}

#[test]
fn empty_video_and_audio_sections_omitted() {
// A data-only broadcast must not advertise media it does not have. An old publisher's
Expand Down Expand Up @@ -1083,13 +1075,6 @@ mod test {
);
}

#[test]
fn clock_stays_off_the_wire_when_absent() {
// Absent clock stays off the wire. Empty video and audio are omitted as well.
let output = Catalog::<()>::default().to_json().expect("failed to encode");
assert_eq!(output, "{}");
}

#[test]
fn packaged_clock_fixture_decodes() {
// The canonical new shape: the root clock plus an archive without a wall field.
Expand Down
25 changes: 0 additions & 25 deletions rs/hang/src/catalog/text/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,38 +87,13 @@ impl FromStr for TextRole {
mod tests {
use super::*;

#[test]
fn format_roundtrip() {
for (s, f) in [
("vtt", TextFormat::Vtt),
("ttml", TextFormat::Ttml),
("utf8", TextFormat::Utf8),
] {
assert_eq!(TextFormat::from_str(s).unwrap(), f);
assert_eq!(f.to_string(), s);
}
}

#[test]
fn format_unknown_preserved() {
let parsed = TextFormat::from_str("cea708").unwrap();
assert_eq!(parsed, TextFormat::Unknown("cea708".to_string()));
assert_eq!(parsed.to_string(), "cea708");
}

#[test]
fn role_default_is_subtitle() {
assert_eq!(TextRole::default(), TextRole::Subtitle);
}

#[test]
fn role_roundtrip() {
for (s, r) in [("subtitle", TextRole::Subtitle), ("caption", TextRole::Caption)] {
assert_eq!(TextRole::from_str(s).unwrap(), r);
assert_eq!(r.to_string(), s);
}
}

#[test]
fn role_unknown_preserved() {
let parsed = TextRole::from_str("commentary").unwrap();
Expand Down
15 changes: 0 additions & 15 deletions rs/hang/src/catalog/video/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,3 @@ impl FromStr for VideoCodec {
Ok(Self::Unknown(s.to_string()))
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_vp8() {
let encoded = "vp8";
let decoded = VideoCodec::from_str(encoded).expect("failed to parse");
assert_eq!(decoded, VideoCodec::VP8);

let output = decoded.to_string();
assert_eq!(output, encoded);
}
}
11 changes: 0 additions & 11 deletions rs/hang/src/catalog/video/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,17 +457,6 @@ mod test {
assert_eq!(catalog.enabled().count(), 1);
}

#[test]
fn label_round_trips() {
let mut config = VideoConfig::new(VideoCodec::VP8);
config.label = Some("Main camera".to_string());

let encoded = serde_json::to_value(&config).expect("failed to encode");
assert_eq!(encoded["label"], "Main camera");
let decoded: VideoConfig = serde_json::from_value(encoded).expect("failed to decode");
assert_eq!(decoded.label.as_deref(), Some("Main camera"));
}

#[test]
fn display_aspect_uses_canonical_json_names() {
let mut config = VideoConfig::new(H264 {
Expand Down
23 changes: 0 additions & 23 deletions rs/hang/src/container/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,6 @@ mod test {
assert_eq!(decoded.timestamp, Timestamp::from_micros(1_234_567).expect("timestamp"));
}

/// Publishers stamp the kind's priority, which is what keeps audio ahead of video
/// both on the wire and in `bandwidth::Allocator`. It is a parameter precisely so
/// this can't silently fall back to the undifferentiated default.
#[test]
fn track_info_carries_the_publisher_priority() {
use crate::catalog::PRIORITY;

assert_eq!(track_info(PRIORITY.video).priority, PRIORITY.video);
assert_eq!(track_info(PRIORITY.audio).priority, PRIORITY.audio);
}

#[test]
fn track_info_uses_container_timescale() {
assert_eq!(track_info(crate::catalog::PRIORITY.video).timescale, Some(TIMESCALE));
}

#[test]
fn media_tracks_declare_their_retention() {
// A media track is read as history (a segmented egress FETCHes segments a playlist
Expand All @@ -188,11 +172,4 @@ mod test {
assert_eq!(at.timescale, Some(Timescale::MILLI));
assert_eq!(at.max_age, Some(MAX_AGE));
}

#[test]
fn non_media_tracks_keep_the_default_retention() {
// Catalog and timeline metadata impose no publisher age limit; local cache policy
// still controls storage.
assert_eq!(crate::Catalog::default_track_info().max_age, None);
}
}
1 change: 0 additions & 1 deletion rs/hang/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ mod tests {
assert!(echo::is_echo(&moq_net::Path::new("room/alice.echo")));
assert!(!echo::is_echo(&moq_net::Path::new("room.echo/alice")));
assert!(!echo::is_echo(&moq_net::Path::new("room/alice.echoes")));
assert_eq!(echo::TRACK, "feedback.json");
}

#[test]
Expand Down
5 changes: 0 additions & 5 deletions rs/hang/src/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,6 @@ mod test {
}
}

#[test]
fn default_name_appends_the_suffix() {
assert_eq!(default_name("video0"), "video0.timeline.z");
}

#[test]
fn typed_extension_flattens() {
// An application extends the record with its own typed section, flattened into the object.
Expand Down
17 changes: 0 additions & 17 deletions rs/kio/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,23 +412,6 @@ mod test {
assert_eq!(queue.poll_push_with(&push_waiter, || 3), Poll::Ready(Err(Closed)));
}

#[test]
fn accessors() {
let queue = Queue::bounded(2);
assert_eq!(queue.capacity(), Some(2));
assert!(queue.is_empty());
queue.try_push(1).unwrap();
assert_eq!(queue.len(), 1);
assert!(!queue.is_empty());
assert!(!queue.is_closed());

let clone = queue.clone();
let other = Queue::<u32>::new();
assert!(queue.same_channel(&clone));
assert!(!queue.same_channel(&other));
assert_eq!(other.capacity(), None);
}

#[test]
#[should_panic(expected = "zero-capacity")]
fn zero_capacity_panics() {
Expand Down
10 changes: 0 additions & 10 deletions rs/kio/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,4 @@ mod test {

assert_eq!(task.await.unwrap(), Some(3));
}

#[test]
fn same_channel_tracks_identity() {
let shared = Shared::<Vec<u32>>::default();
let clone = shared.clone();
let other = Shared::<Vec<u32>>::default();

assert!(shared.same_channel(&clone));
assert!(!shared.same_channel(&other));
}
}
20 changes: 0 additions & 20 deletions rs/moq-audio/src/encode/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,20 +901,6 @@ mod tests {
assert_eq!(enc.bitrate(), original);
}

#[test]
fn codec_roundtrips_as_str() {
assert_eq!(Codec::Opus.as_str(), "opus");
assert_eq!(Codec::Opus.to_string(), "opus");
assert_eq!("opus".parse::<Codec>().unwrap(), Codec::Opus);
assert_eq!(Codec::Pcm.as_str(), "pcm");
assert_eq!(Codec::Pcm.to_string(), "pcm");
assert_eq!("pcm".parse::<Codec>().unwrap(), Codec::Pcm);
assert_eq!(Codec::Aac.as_str(), "aac");
assert_eq!(Codec::Aac.to_string(), "aac");
assert_eq!("aac".parse::<Codec>().unwrap(), Codec::Aac);
assert!("mp3".parse::<Codec>().is_err());
}

#[test]
fn settings_fix_the_codec_rate() {
let enc = Encoder::new(&Settings::new(24_000, Layout::Mono)).unwrap();
Expand Down Expand Up @@ -1170,10 +1156,4 @@ mod tests {
assert_eq!(finish.packets().len(), 3);
assert_eq!(finish.discard_padding(), 3 * 1024 - backend::stub::DELAY);
}

/// Opus signals its lookahead as pre-skip, so the producer folds none of it.
#[test]
fn opus_folds_no_delay() {
assert_eq!(Encoder::new(&Settings::default()).unwrap().folded_delay(), 0);
}
}
Loading
Loading