import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { runSplice } from '../../server/utils/splice' import { fakeGithubFetch, GitFixture, localReceivePackFactory } from '../utils/git-wire' describe('runSplice thin-pack negotiation (knot already holds the base)', () => { let fx: GitFixture let realFetch: typeof globalThis.fetch beforeEach(() => { fx = new GitFixture() realFetch = globalThis.fetch }) afterEach(() => { globalThis.fetch = realFetch fx.cleanup() }) it('pushes an incremental update where the knot advertises the base commit as a have', async () => { // GitHub side: two commits on main (base -> head). const gh = fx.initBare('gh.git') const work = fx.initWork('work') const base = fx.commit(work, 'a.txt', 'hello') fx.pushTo(work, gh, 'HEAD:refs/heads/main') const head = fx.commit(work, 'b.txt', 'world') fx.pushTo(work, gh, 'HEAD:refs/heads/main') // Knot side: already has `base` on main (the state after the first sync). const knot = fx.initBare('knot.git') fx.pushTo(work, knot, `${base}:refs/heads/main`) globalThis.fetch = fakeGithubFetch(new Map([['owner/repo', gh]])) as unknown as typeof globalThis.fetch const result = await runSplice(localReceivePackFactory(knot), { repoFullName: 'owner/repo', ref: 'refs/heads/main', want: head, token: 't', }) expect(result.status).toBe('synced') expect(fx.revParse(knot, 'refs/heads/main')).toBe(head) }) })