Skip to content

Commit 9e2a85c

Browse files
fix(session): ids are transparent on the wire, so a timeline crosses JSON
A `Response::Timeline` did not survive `facet-json`: its maps are keyed by `LaneId` and `ItemId`, which it wrote as strings and could not read back as ids ("expected LaneId, but got String"). Ignition's cue lists, the first caller to read the timeline through the extension face, hit it. The id newtypes are now `#[facet(transparent)]`: on every wire (JSON, vox) an id is the string it wraps, a map key included. New test: a lane and an item put and read back over JSON, keyed by their ids. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b36a447 commit 9e2a85c

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

‎crates/session/src/id.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ use std::fmt;
1111
macro_rules! id {
1212
($(#[$doc:meta])* $name:ident) => {
1313
$(#[$doc])*
14+
// Transparent: on every wire (JSON, vox) an id is the string it
15+
// wraps, so it works as a map key too.
1416
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, facet::Facet)]
17+
#[facet(transparent)]
1518
pub struct $name(pub String);
1619

1720
impl $name {

‎crates/session/tests/session/extension.rs‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,61 @@ fn payloads_cross_json_whole() {
125125
assert_eq!(meta.get("capo"), Some(&Value::Int(2)));
126126
assert_eq!(meta.get("swing"), Some(&Value::Float(0.6)));
127127
}
128+
129+
/// Every response crosses JSON: the timeline's maps are keyed by ids.
130+
#[test]
131+
fn the_timeline_crosses_json_keyed_by_ids() {
132+
use session::{ExtensionId, Item, ItemId, Lane, LaneId};
133+
let s = sessions();
134+
let lane = LaneId::from("cues");
135+
let put = call_json(
136+
"song-1",
137+
Request::PutLane {
138+
id: lane.clone(),
139+
lane: Lane {
140+
owner: ExtensionId::from("ignition"),
141+
kind: "ignition.cues".into(),
142+
name: "Main".into(),
143+
order: 0.0,
144+
parent: None,
145+
},
146+
},
147+
)
148+
.unwrap();
149+
answer(&s, WRITE, &put, Some("ignition")).unwrap();
150+
let item = call_json(
151+
"song-1",
152+
Request::PutItem {
153+
id: ItemId::from("cues/1"),
154+
item: Item {
155+
owner: ExtensionId::from("ignition"),
156+
lane: lane.clone(),
157+
kind: "ignition.cue".into(),
158+
at: Time::QuarterNotes(4.0),
159+
end: None,
160+
payload: Value::map([("look", Value::from("Warm"))]),
161+
},
162+
},
163+
)
164+
.unwrap();
165+
answer(&s, WRITE, &item, Some("ignition")).unwrap();
166+
let read = call_json("song-1", Request::ReadTimeline).unwrap();
167+
let Response::Timeline { lanes, items } =
168+
response_of(&answer(&s, READ, &read, Some("ignition")).unwrap()).unwrap()
169+
else {
170+
panic!("not the timeline")
171+
};
172+
assert_eq!(lanes[&lane].name, "Main");
173+
assert_eq!(items[&ItemId::from("cues/1")].at, Time::QuarterNotes(4.0));
174+
// An id is the string it wraps on the wire.
175+
assert!(
176+
call_json(
177+
"cues",
178+
Request::RemoveItem {
179+
id: ItemId::from("cues/1")
180+
}
181+
)
182+
.unwrap()
183+
.contains("\"cues/1\"")
184+
);
185+
}

0 commit comments

Comments
 (0)