// Test inputs for ref data validation // Lexicon with a string definition const stringRefLexicon = { lexicon: 1, id: 'app.test.stringref', defs: { main: { type: 'record', key: 'tid', record: { type: 'object', properties: { content: { type: 'ref', ref: '#post' }, }, }, }, post: { type: 'string', maxLength: 280, }, }, }; // Lexicon with an object definition const objectRefLexicon = { lexicon: 1, id: 'app.test.objectref', defs: { main: { type: 'record', key: 'tid', record: { type: 'object', properties: { user: { type: 'ref', ref: '#userDef' }, }, }, }, userDef: { type: 'object', required: ['name'], properties: { name: { type: 'string' }, age: { type: 'integer' }, }, }, }, }; // Lexicon with nested reference chain: refA -> refB -> actualString const nestedRefLexicon = { lexicon: 1, id: 'app.test.nested', defs: { main: { type: 'record', key: 'tid', record: { type: 'object', properties: { data: { type: 'ref', ref: '#refA' }, }, }, }, refA: { type: 'ref', ref: '#refB', }, refB: { type: 'ref', ref: '#actualString', }, actualString: { type: 'string', }, }, }; // Lexicon with circular reference: refA -> refB -> refA const circularRefLexicon = { lexicon: 1, id: 'app.test.circular', defs: { main: { type: 'record', key: 'tid', record: { type: 'object', properties: { data: { type: 'ref', ref: '#refA' }, }, }, }, refA: { type: 'ref', ref: '#refB', }, refB: { type: 'ref', ref: '#refA', }, }, }; // Cross-lexicon reference const crossRefLexicon1 = { lexicon: 1, id: 'app.test.schema', defs: { main: { type: 'record', key: 'tid', record: { type: 'object', properties: { user: { type: 'ref', ref: 'app.test.types#user' }, }, }, }, }, }; const crossRefLexicon2 = { lexicon: 1, id: 'app.test.types', defs: { user: { type: 'object', required: ['id'], properties: { id: { type: 'string' }, }, }, }, }; // Lexicon with nonexistent ref const badRefLexicon = { lexicon: 1, id: 'app.test.badref', defs: { main: { type: 'record', key: 'tid', record: { type: 'object', properties: { data: { type: 'ref', ref: '#nonexistent' }, }, }, }, }, }; // Cross-lexicon reference with nested local refs // Tests: when A refs B#foo, and B#foo refs #bar, it should resolve to B#bar (not A#bar) // This mirrors real-world case: app.bsky.actor.profile -> com.atproto.label.defs#selfLabels -> #selfLabel const crossRefNestedLexicon1 = { lexicon: 1, id: 'app.test.profile', defs: { main: { type: 'record', key: 'tid', record: { type: 'object', properties: { labels: { type: 'ref', ref: 'app.test.labels#selfLabels' }, }, }, }, // This should NOT be used - the ref should resolve to app.test.labels#selfLabel selfLabel: { type: 'object', required: ['wrongField'], properties: { wrongField: { type: 'string' }, }, }, }, }; const crossRefNestedLexicon2 = { lexicon: 1, id: 'app.test.labels', defs: { selfLabels: { type: 'object', properties: { values: { type: 'array', items: { type: 'ref', ref: '#selfLabel' }, }, }, }, selfLabel: { type: 'object', required: ['val'], properties: { val: { type: 'string' }, }, }, }, }; export const refDataInputs = [ { name: 'ref-data-valid-to-string', lexicons: [stringRefLexicon], collection: 'app.test.stringref', record: { content: 'Hello, world!', }, }, { name: 'ref-data-invalid-string-too-long', lexicons: [stringRefLexicon], collection: 'app.test.stringref', record: { content: 'a'.repeat(281), }, }, { name: 'ref-data-valid-to-object', lexicons: [objectRefLexicon], collection: 'app.test.objectref', record: { user: { name: 'Alice', age: 30 }, }, }, { name: 'ref-data-invalid-object-missing-required', lexicons: [objectRefLexicon], collection: 'app.test.objectref', record: { user: { age: 30 }, }, }, { name: 'ref-data-valid-nested-chain', lexicons: [nestedRefLexicon], collection: 'app.test.nested', record: { data: 'Hello!', }, }, { name: 'ref-data-invalid-circular-reference', lexicons: [circularRefLexicon], collection: 'app.test.circular', record: { data: 'test', }, }, { name: 'ref-data-valid-cross-lexicon', lexicons: [crossRefLexicon1, crossRefLexicon2], collection: 'app.test.schema', record: { user: { id: 'user123' }, }, }, { name: 'ref-data-invalid-cross-lexicon-missing-required', lexicons: [crossRefLexicon1, crossRefLexicon2], collection: 'app.test.schema', record: { user: { name: 'Alice' }, }, }, { name: 'ref-data-invalid-not-found', lexicons: [badRefLexicon], collection: 'app.test.badref', record: { data: 'test', }, }, // Cross-lexicon ref with nested local ref - should resolve to target lexicon's def { name: 'ref-data-valid-cross-lexicon-nested-local-ref', lexicons: [crossRefNestedLexicon1, crossRefNestedLexicon2], collection: 'app.test.profile', record: { labels: { values: [{ val: 'self-label-value' }] }, }, }, // This should fail because it uses the wrong lexicon's selfLabel definition { name: 'ref-data-invalid-cross-lexicon-wrong-context', lexicons: [crossRefNestedLexicon1, crossRefNestedLexicon2], collection: 'app.test.profile', record: { labels: { values: [{ wrongField: 'this-uses-wrong-lexicon' }] }, }, }, ];