import { expect, test } from 'vitest' import { decidePackagePushRef } from './package-push-ref-policy.ts' test('decidePackagePushRef rejects non-branches, reserved refs, and protected default branch', () => { const cases = [ { ref: 'refs/tags/v1', mainProtected: false, reason: 'only branches can be pushed', }, { ref: 'refs/heads/kody/topic', mainProtected: false, reason: 'kody/ is reserved for Kody', }, { ref: 'refs/heads/sessions/run-1', mainProtected: false, reason: 'sessions/ is reserved for Kody', }, { ref: 'refs/heads/kody-published', mainProtected: false, reason: 'kody-published is reserved for Kody', }, { ref: 'refs/heads/kody-source-repair', mainProtected: false, reason: 'kody-source-repair is reserved for Kody', }, { ref: 'refs/heads/main', mainProtected: true, reason: 'default branch is protected; push a branch and open a merge request', }, ] as const for (const item of cases) { expect( decidePackagePushRef({ ref: item.ref, defaultBranch: 'main', mainProtected: item.mainProtected, }), ).toMatchObject({ reason: item.reason }) } expect( decidePackagePushRef({ ref: 'refs/heads/main', defaultBranch: 'main', mainProtected: false, }), ).toBeNull() expect( decidePackagePushRef({ ref: 'refs/heads/trunk', defaultBranch: 'trunk', mainProtected: true, }), ).toMatchObject({ reason: 'default branch is protected; push a branch and open a merge request', guidance: 'The trunk branch is protected. Push to a branch, then open a merge request in Kody.', }) expect( decidePackagePushRef({ ref: 'refs/heads/agent/task', defaultBranch: 'main', mainProtected: true, }), ).toBeNull() })