OverviewFilesCommitsIssuesDocsReleasesPeers

pear-git-v3 / test / p1-profile-links.test.js

55 lines · javascript ref:
/**
 * P1 UX gaps: issue/comment authors link to their profile; SSH pushes get
 * attributed via the record-push UDS RPC.
 */

import test from 'brittle'
import { renderIssueShow } from '../lib/web/pages/issues.js'
import { sshKeyHandlers } from '../lib/handlers/ssh-keys.js'
import { listUserPushes } from '../lib/services/push-index.js'

const pk = 'cc'.repeat(32)

test('issue author renders as a profile link; legacy author is escaped, not linked', async (t) => {
  const svc = {
    _sync: { repos: { has: () => true } },
    identityRegistry: {
      getUserWithIdentities: async (id) => id === 'u1'
        ? ({ user: { userId: 'u1', name: 'Alice' }, identities: [{ identityId: pk, method: 'web-identity' }] })
        : null
    },
    issueRegistry: {
      getForRepo: async () => ({
        get: async () => ({ id: 1, title: 'T', body: 'b', author: 'u1', status: 'open', createdAt: 0, labels: [] }),
        getComments: async () => [{ id: 1, author: 'weird<b>', body: 'c', createdAt: 0 }]
      })
    }
  }
  const html = await renderIssueShow(svc, 1, { prefix: '/git' }, { repo: 'app' })
  t.ok(html.includes('/git/profile/' + pk), 'resolved author linked to /profile/:pubkey')
  t.ok(html.includes('>Alice</a>'), 'link labelled with the display name')
  t.absent(html.includes('weird<b>'), 'legacy author not emitted raw')
  t.ok(html.includes('weird&lt;b&gt;'), 'legacy author HTML-escaped')
})

test('record-push handler: UDS-only, resolves ssh fingerprint → userId → push', async (t) => {
  const svc = {
    identityRegistry: {
      getIdentityBySSHKey: async (fp) => fp === 'SHA256:good' ? ({ identityId: 'idhex' }) : null,
      getUserByIdentity: async (id) => id === 'idhex' ? ({ userId: 'sshuser' }) : null
    }
  }
  const handlers = sshKeyHandlers(svc)
  const rp = handlers.find(h => h.name === 'record-push')
  t.ok(rp, 'record-push handler registered')

  await t.exception(() => rp.fn({ transport: 'http' }, { repo: 'r', fingerprint: 'SHA256:good' }), /UDS-only/)

  const res = await rp.fn({ transport: 'uds' }, { repo: 'sshrepo', fingerprint: 'SHA256:good' })
  t.is(res.recorded, true, 'recorded on UDS with a resolvable fingerprint')
  t.ok(listUserPushes('sshuser').some(p => p.repo === 'sshrepo'), 'push indexed for the resolved user')

  const res2 = await rp.fn({ transport: 'uds' }, { repo: 'x', fingerprint: 'SHA256:unknown' })
  t.is(res2.recorded, false, 'unknown fingerprint → not recorded')
})