import * as Mpp from './Mpp.js' const fingerprint = Mpp.fingerprintForRealm('openai.mpp.tempo.xyz') // Layout: 0x + tag(4 bytes) + version(1 byte) + fingerprint(10 bytes) + padding(17 bytes). const attributionMemo = `0xef1ed71201${fingerprint.slice(2)}${'0'.repeat(34)}` as const describe('fingerprintForRealm', () => { test('derives a 10-byte lowercase fingerprint from a realm', () => { expect(Mpp.fingerprintForRealm('openai.mpp.tempo.xyz')).toMatchInlineSnapshot( `"0x254953331c1e3c7ae53d"`, ) }) }) describe('isAttributionMemo', () => { test('accepts a 32-byte memo prefixed with the attribution tag', () => { expect(Mpp.isAttributionMemo(attributionMemo)).toBe(true) }) test('rejects a memo without the tag', () => { expect(Mpp.isAttributionMemo(`0x${'0'.repeat(64)}`)).toBe(false) }) test('rejects a tagged memo of the wrong length', () => { expect(Mpp.isAttributionMemo('0xef1ed712')).toBe(false) }) }) describe('extractFingerprint', () => { test('extracts the fingerprint from an attribution memo', () => { expect(Mpp.extractFingerprint(attributionMemo)).toBe(fingerprint) }) test('returns undefined for a non-attribution memo', () => { expect(Mpp.extractFingerprint(`0x${'0'.repeat(64)}`)).toBe(undefined) }) }) describe('resolve', () => { test('resolves the directory entry for a memo fingerprint', () => { expect( Mpp.resolve({ fingerprintMap: { [fingerprint]: 'OpenAI' }, memo: attributionMemo, }), ).toMatchInlineSnapshot(`"OpenAI"`) }) test('falls back to the generic label for an unresolved attribution memo', () => { expect(Mpp.resolve({ fingerprintMap: {}, memo: attributionMemo })).toMatchInlineSnapshot( `"MPP Service"`, ) }) test('returns undefined when there is no memo', () => { expect(Mpp.resolve({ fingerprintMap: { [fingerprint]: 'OpenAI' } })).toBe(undefined) }) test('returns undefined for a non-attribution memo', () => { expect( Mpp.resolve({ fingerprintMap: { [fingerprint]: 'OpenAI' }, memo: `0x${'0'.repeat(64)}` }), ).toBe(undefined) }) })