Skip to content
← Public packages

@kody/kody-factory

Forkable multi-project software factory: signals, priority queue, project UI, sweep job. Agent runners and Sentry reach it by events.

FollowFork

Files

push-branch.test.ts

51 lines · 1.7 KB · TypeScript
import assert from 'node:assert/strict'
import { registerHooks } from 'node:module'
import { test } from 'node:test'

const STUB = `
export const packageStorage = () => ({ async get() { return null }, async set() {} });
export async function credential(key) { throw new Error('credential_unbound: ' + key); }
export async function credentials() { return [] }
`
registerHooks({
	resolve(s, c, n) {
		return s === 'kody:runtime' ? { url: `data:text/javascript,${encodeURIComponent(STUB)}`, shortCircuit: true } : n(s, c)
	},
})

const { default: pushBranch } = await import('./push-branch.ts')
const { GithubOwnerSetupError, GITHUB_OWNER_UNMAPPED_MESSAGE } = await import('./owner-github-request.ts')

test('dryRun validates and does not open githubOwner or github', async () => {
	const result = await pushBranch({
		repo: 'kody-hq/kody',
		branch: 'friction-log/test',
		message: 'fix: test',
		files: [{ path: 'README.md', content: 'hi' }],
		pullRequest: { title: 'fix: test', body: 'body' },
		dryRun: true,
	})
	assert.equal(result.ok, true)
	assert.equal(result.dryRun, true)
	assert.equal(result.repo, 'kody-hq/kody')
	assert.equal(result.branch, 'friction-log/test')
	assert.equal(result.fileCount, 1)
	assert.equal(result.openPullRequest, true)
})

test('live push-branch fails clearly when githubOwner is unmapped', async () => {
	await assert.rejects(
		() =>
			pushBranch({
				repo: 'kody-hq/kody',
				branch: 'friction-log/test',
				message: 'fix: test',
				files: [{ path: 'README.md', content: 'hi' }],
			}),
		(err: unknown) => {
			assert.ok(err instanceof GithubOwnerSetupError)
			assert.equal((err as Error).message, GITHUB_OWNER_UNMAPPED_MESSAGE)
			return true
		},
	)
})