|
| 1 | +/** |
| 2 | + * E2E test: traces the full resolve pipeline against the live GitHub API. |
| 3 | + * |
| 4 | + * This test calls the real GitHub API (no mocks) to verify the widget |
| 5 | + * can resolve identity data from auths-dev/example-verify-badge. |
| 6 | + * |
| 7 | + * Run with: npx vitest run tests/e2e/live-resolve.test.ts |
| 8 | + */ |
| 9 | +import { describe, it, expect } from 'vitest'; |
| 10 | +import { detectForge } from '../../src/resolvers/detect'; |
| 11 | +import { githubAdapter } from '../../src/resolvers/github'; |
| 12 | +import { cesrToPublicKeyHex } from '../../src/resolvers/did-utils'; |
| 13 | +import { resolveFromRepo } from '../../src/resolvers/resolver'; |
| 14 | + |
| 15 | +const REPO_SHORTHAND = 'auths-dev/example-verify-badge'; |
| 16 | +const REPO_FULL_URL = 'https://github.com/auths-dev/example-verify-badge'; |
| 17 | + |
| 18 | +describe('live resolve pipeline', () => { |
| 19 | + // Step 1: detectForge |
| 20 | + describe('Step 1: detectForge', () => { |
| 21 | + it('parses full URL', () => { |
| 22 | + const config = detectForge(REPO_FULL_URL); |
| 23 | + console.log('detectForge(full URL):', JSON.stringify(config)); |
| 24 | + expect(config).not.toBeNull(); |
| 25 | + expect(config!.type).toBe('github'); |
| 26 | + expect(config!.owner).toBe('auths-dev'); |
| 27 | + expect(config!.repo).toBe('example-verify-badge'); |
| 28 | + expect(config!.baseUrl).toBe('https://api.github.com'); |
| 29 | + }); |
| 30 | + |
| 31 | + it('parses owner/repo shorthand', () => { |
| 32 | + const config = detectForge(REPO_SHORTHAND); |
| 33 | + console.log('detectForge(shorthand):', JSON.stringify(config)); |
| 34 | + expect(config).not.toBeNull(); |
| 35 | + expect(config!.type).toBe('github'); |
| 36 | + expect(config!.owner).toBe('auths-dev'); |
| 37 | + expect(config!.repo).toBe('example-verify-badge'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('parses shorthand with forge hint', () => { |
| 41 | + const config = detectForge(REPO_SHORTHAND, 'github'); |
| 42 | + console.log('detectForge(shorthand + hint):', JSON.stringify(config)); |
| 43 | + expect(config).not.toBeNull(); |
| 44 | + expect(config!.type).toBe('github'); |
| 45 | + }); |
| 46 | + }); |
| 47 | + |
| 48 | + // Step 2: listAuthsRefs (live API call) |
| 49 | + describe('Step 2: listAuthsRefs (live)', () => { |
| 50 | + it('finds refs/auths/registry', async () => { |
| 51 | + const config = detectForge(REPO_FULL_URL)!; |
| 52 | + const refs = await githubAdapter.listAuthsRefs(config); |
| 53 | + console.log('listAuthsRefs:', JSON.stringify(refs)); |
| 54 | + expect(refs.length).toBeGreaterThan(0); |
| 55 | + const registryRef = refs.find(r => r.ref === 'refs/auths/registry'); |
| 56 | + expect(registryRef).toBeDefined(); |
| 57 | + console.log('registry ref SHA:', registryRef!.sha); |
| 58 | + }); |
| 59 | + }); |
| 60 | + |
| 61 | + // Step 3: full resolve (live API call) |
| 62 | + describe('Step 3: full resolve (live)', () => { |
| 63 | + it('resolves identity bundle from registry', async () => { |
| 64 | + const config = detectForge(REPO_FULL_URL)!; |
| 65 | + const result = await githubAdapter.resolve(config); |
| 66 | + console.log('resolve result:', JSON.stringify(result, null, 2)); |
| 67 | + |
| 68 | + if (result.error) { |
| 69 | + console.error('RESOLVE ERROR:', result.error); |
| 70 | + } |
| 71 | + |
| 72 | + expect(result.error).toBeUndefined(); |
| 73 | + expect(result.bundle).not.toBeNull(); |
| 74 | + expect(result.bundle!.identity_did).toMatch(/^did:keri:/); |
| 75 | + expect(result.bundle!.public_key_hex).toMatch(/^[0-9a-f]{64}$/); |
| 76 | + console.log('identity_did:', result.bundle!.identity_did); |
| 77 | + console.log('public_key_hex:', result.bundle!.public_key_hex); |
| 78 | + console.log('attestation_chain length:', result.bundle!.attestation_chain.length); |
| 79 | + }); |
| 80 | + }); |
| 81 | + |
| 82 | + // Step 4: resolveFromRepo (the entry point the widget uses) |
| 83 | + describe('Step 4: resolveFromRepo (live)', () => { |
| 84 | + it('resolves via full URL', async () => { |
| 85 | + const result = await resolveFromRepo(REPO_FULL_URL); |
| 86 | + console.log('resolveFromRepo(full URL):', JSON.stringify(result, null, 2)); |
| 87 | + if (result.error) console.error('ERROR:', result.error); |
| 88 | + expect(result.bundle).not.toBeNull(); |
| 89 | + }); |
| 90 | + |
| 91 | + it('resolves via shorthand', async () => { |
| 92 | + const result = await resolveFromRepo(REPO_SHORTHAND); |
| 93 | + console.log('resolveFromRepo(shorthand):', JSON.stringify(result, null, 2)); |
| 94 | + if (result.error) console.error('ERROR:', result.error); |
| 95 | + expect(result.bundle).not.toBeNull(); |
| 96 | + }); |
| 97 | + |
| 98 | + it('resolves via shorthand + forge hint (what the demo uses)', async () => { |
| 99 | + const result = await resolveFromRepo(REPO_SHORTHAND, 'github'); |
| 100 | + console.log('resolveFromRepo(shorthand + github hint):', JSON.stringify(result, null, 2)); |
| 101 | + if (result.error) console.error('ERROR:', result.error); |
| 102 | + expect(result.bundle).not.toBeNull(); |
| 103 | + }); |
| 104 | + }); |
| 105 | + |
| 106 | + // Step 5: CESR key decoding |
| 107 | + describe('Step 5: CESR decoding', () => { |
| 108 | + it('decodes the test CESR key', () => { |
| 109 | + const hex = cesrToPublicKeyHex('DQIS37c2Ar3CzozrmU9KpbUWBYWMJhBWPV-wN50i-RGI'); |
| 110 | + console.log('CESR decoded hex:', hex); |
| 111 | + expect(hex).toMatch(/^[0-9a-f]{64}$/); |
| 112 | + }); |
| 113 | + }); |
| 114 | +}); |
0 commit comments