import assert from 'node:assert/strict' import { describe, it } from 'node:test' import { request } from './core.ts' import { defaultSecretResolution } from './secret-resolution.ts' describe('defaultSecretResolution', () => { it('defaults file-content uploads to headers-only', () => { assert.equal(defaultSecretResolution('POST', '/repos/o/r/git/blobs'), 'headers-only') assert.equal(defaultSecretResolution('post', 'repos/o/r/git/trees'), 'headers-only') assert.equal(defaultSecretResolution('PUT', '/repos/o/r/contents/src/a.test.ts'), 'headers-only') assert.equal(defaultSecretResolution('POST', 'https://api.github.com/repos/o/r/git/blobs?x=1'), 'headers-only') }) it('leaves other calls alone', () => { assert.equal(defaultSecretResolution('GET', '/repos/o/r/git/blobs/abc'), undefined) assert.equal(defaultSecretResolution('POST', '/repos/o/r/git/commits'), undefined) assert.equal(defaultSecretResolution('POST', '/repos/o/r/issues/1/comments'), undefined) assert.equal(defaultSecretResolution('DELETE', '/repos/o/r/contents/a.ts'), undefined) }) }) describe('request secret-resolution header', () => { it('sets headers-only for blob uploads and respects a caller header', async () => { const seen: Array = [] ;(globalThis as { __kodyFetch?: unknown }).__kodyFetch = async (_url: unknown, init?: RequestInit) => { seen.push(new Headers(init?.headers).get('x-kody-secret-resolution')) return new Response('{"sha":"x"}', { status: 201, headers: { 'content-type': 'application/json' } }) } await request({ path: '/repos/o/r/git/blobs', body: { content: 'YQ==', encoding: 'base64' } }) await request({ path: '/repos/o/r/git/blobs', headers: { 'x-kody-secret-resolution': 'off' }, body: { content: 'YQ==', encoding: 'base64' }, }) await request({ path: '/repos/o/r/issues/1/comments', body: { body: 'hi' } }) assert.deepEqual(seen, ['headers-only', 'off', null]) }) })