Skip to content

Commit 6596489

Browse files
knasherclaude
andcommitted
test: guard the generated Collection impl for camelCase record NSIDs
`cargo build` does not compile the test target, so nothing catches codegen dropping a `Collection` impl. #345 fixed exactly that: `app.bsky.actor. contentVisibilityDeclaration` is the first record whose NSID leaf is camelCase, and the NSID was rebuilt from the snake_case'd file stem, so the record never matched its own schema and got no `Collection` impl. `KnownRecord` is keyed on schema ids, so it *did* gain the variant, leaving downstream crates with an arm they could not satisfy. Two assertions, neither coupled to lexicon contents: - Naming `ContentVisibilityDeclaration::NSID` requires the `Collection` impl to exist; comparing it against the literal requires it to carry the NSID verbatim rather than a mangled form. - A never-called function taking `<ContentVisibilityDeclaration as Collection>::Record` and returning the corresponding `KnownRecord` variant asserts at compile time that the two halves agree on the record type. Drifting the associated type fails to build here while the NSID assertions still pass, so this catches a case the runtime checks cannot. Verified by reintroducing the #345 breakage against the current tree: deleting the `Collection` impl fails the test target to compile, as does pointing its `Record` at a different record type. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent a2e623a commit 6596489

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//! Fidelity tests for the code generated by `atrium-codegen`.
2+
//!
3+
//! These assert properties of the *generated code itself* — the shape of the
4+
//! `Collection` impl and its agreement with `KnownRecord` — so they are not
5+
//! coupled to the contents of any particular lexicon revision.
6+
7+
#![cfg(feature = "namespace-appbsky")]
8+
9+
use atrium_api::app::bsky::actor::ContentVisibilityDeclaration;
10+
use atrium_api::record::KnownRecord;
11+
use atrium_api::types::Collection;
12+
13+
/// `app.bsky.actor.contentVisibilityDeclaration` is the first record whose NSID
14+
/// leaf is camelCase, and it broke an assumption in codegen: the NSID was
15+
/// rebuilt from the snake_case'd file stem, so the record never matched its own
16+
/// schema and got no `Collection` impl. `KnownRecord` is keyed on schema ids, so
17+
/// it *did* gain the variant — leaving downstream crates with an arm they could
18+
/// not satisfy.
19+
#[test]
20+
fn camel_case_record_nsid_is_generated_verbatim() {
21+
const NSID: &str = "app.bsky.actor.contentVisibilityDeclaration";
22+
23+
// Naming `NSID` at all requires the `Collection` impl to exist; the
24+
// assertions require it to carry the NSID verbatim, rather than a
25+
// snake_case'd or otherwise mangled form.
26+
assert_eq!(ContentVisibilityDeclaration::NSID, NSID);
27+
assert_eq!(ContentVisibilityDeclaration::nsid().as_str(), NSID);
28+
}
29+
30+
/// The `Collection` and `KnownRecord` halves must *agree* on the record type,
31+
/// not merely both exist. This is never called: it is a compile-time assertion,
32+
/// and fails to build if the `Collection` impl disappears again or its `Record`
33+
/// drifts from the type the corresponding `KnownRecord` variant holds.
34+
#[allow(dead_code)]
35+
fn collection_record_is_the_known_record_payload(
36+
record: <ContentVisibilityDeclaration as Collection>::Record,
37+
) -> KnownRecord {
38+
KnownRecord::AppBskyActorContentVisibilityDeclaration(Box::new(record))
39+
}

0 commit comments

Comments
 (0)