Files
wehub-resource-sync 719032b19f
Update Schema / Update configuration json schema (push) Has been cancelled
Memory Benchmark / Memory Test (Full Analysis) (push) Has been cancelled
CI Quality / Lint GitHub Actions (actionlint) (push) Has been cancelled
CI Quality / Lint GitHub Actions (zizmor) (push) Has been cancelled
CI Quality / Check typos (push) Has been cancelled
CI / Test coverage (push) Has been cancelled
CI / Test (22.x, windows-latest) (push) Has been cancelled
CI / Test (24.x, macos-latest) (push) Has been cancelled
CI / Test (24.x, ubuntu-latest) (push) Has been cancelled
CI / Test (24.x, windows-latest) (push) Has been cancelled
CI / Test (26.x, macos-latest) (push) Has been cancelled
CI / Test (26.x, ubuntu-latest) (push) Has been cancelled
CI / Test (26.x, windows-latest) (push) Has been cancelled
CI / Test with Bun (latest, macos-latest) (push) Has been cancelled
CI / Test with Bun (latest, ubuntu-latest) (push) Has been cancelled
CI / Test with Bun (latest, windows-latest) (push) Has been cancelled
CI / Build and run (22.x, macos-latest) (push) Has been cancelled
CI / Build and run (22.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (22.x, windows-latest) (push) Has been cancelled
autofix.ci / autofix (push) Has been cancelled
CI Browser Extension / Lint Browser Extension (push) Has been cancelled
CI Browser Extension / Test Browser Extension (push) Has been cancelled
Memory Benchmark / Memory Test (push) Has been cancelled
CI Website / Lint Website Client (push) Has been cancelled
CI Website / Lint Website Server (push) Has been cancelled
CI Website / Test Website Server (push) Has been cancelled
CI Website / Bundle Website Server (push) Has been cancelled
CI / Lint Biome (push) Has been cancelled
CI / Lint oxlint (push) Has been cancelled
CI / Lint TypeScript (push) Has been cancelled
CI / Lint Secretlint (push) Has been cancelled
CI / Test (22.x, macos-latest) (push) Has been cancelled
CI / Test (22.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (24.x, macos-latest) (push) Has been cancelled
CI / Build and run (24.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (24.x, windows-latest) (push) Has been cancelled
CI / Build and run (26.x, macos-latest) (push) Has been cancelled
CI / Build and run (26.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (26.x, windows-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, macos-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, ubuntu-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Docker / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Docker / build (linux/arm/v7, ubuntu-24.04-arm) (push) Has been cancelled
Docker / build (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Docker / merge (push) Has been cancelled
Pack repository with Repomix / pack-repo (push) Has been cancelled
Performance Benchmark History / Benchmark (macos-latest) (push) Has been cancelled
Performance Benchmark History / Benchmark (ubuntu-latest) (push) Has been cancelled
Performance Benchmark History / Benchmark (windows-latest) (push) Has been cancelled
Performance Benchmark History / Store Results (push) Has been cancelled
Test Repomix Action / Test Node.js 22 (push) Has been cancelled
Test Repomix Action / Test Node.js 24 (push) Has been cancelled
Test Repomix Action / Test Node.js 26 (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:37 +08:00

145 lines
5.7 KiB
TypeScript

import { describe, expect, test } from 'vitest';
import {
buildGitHubArchiveUrl,
buildGitHubMasterArchiveUrl,
buildGitHubTagArchiveUrl,
checkGitHubResponse,
} from '../../../src/core/git/gitHubArchiveApi.js';
import { parseGitHubRepoInfo } from '../../../src/core/git/gitRemoteParse.js';
import { RepomixError } from '../../../src/shared/errorHandle.js';
describe('GitHub Archive API', () => {
describe('buildGitHubArchiveUrl', () => {
test('should build URL for default branch (HEAD)', () => {
const repoInfo = { owner: 'user', repo: 'repo' };
const url = buildGitHubArchiveUrl(repoInfo);
expect(url).toBe('https://codeload.github.com/user/repo/tar.gz/HEAD');
});
test('should build URL for specific branch', () => {
const repoInfo = { owner: 'user', repo: 'repo', ref: 'develop' };
const url = buildGitHubArchiveUrl(repoInfo);
expect(url).toBe('https://codeload.github.com/user/repo/tar.gz/develop');
});
test('should build URL for commit SHA', () => {
const repoInfo = { owner: 'user', repo: 'repo', ref: 'abc123def456' };
const url = buildGitHubArchiveUrl(repoInfo);
expect(url).toBe('https://codeload.github.com/user/repo/tar.gz/abc123def456');
});
test('should build URL for full commit SHA', () => {
const repoInfo = { owner: 'user', repo: 'repo', ref: 'abc123def456789012345678901234567890abcd' };
const url = buildGitHubArchiveUrl(repoInfo);
expect(url).toBe('https://codeload.github.com/user/repo/tar.gz/abc123def456789012345678901234567890abcd');
});
});
describe('buildGitHubMasterArchiveUrl', () => {
test('should build URL for master branch fallback', () => {
const repoInfo = { owner: 'user', repo: 'repo' };
const url = buildGitHubMasterArchiveUrl(repoInfo);
expect(url).toBe('https://codeload.github.com/user/repo/tar.gz/master');
});
test('should return null when ref is specified', () => {
const repoInfo = { owner: 'user', repo: 'repo', ref: 'develop' };
const url = buildGitHubMasterArchiveUrl(repoInfo);
expect(url).toBeNull();
});
});
describe('buildGitHubTagArchiveUrl', () => {
test('should always return null since codeload.github.com resolves refs automatically', () => {
expect(buildGitHubTagArchiveUrl({ owner: 'user', repo: 'repo', ref: 'v1.0.0' })).toBeNull();
expect(buildGitHubTagArchiveUrl({ owner: 'user', repo: 'repo', ref: 'abc123def456' })).toBeNull();
expect(buildGitHubTagArchiveUrl({ owner: 'user', repo: 'repo' })).toBeNull();
});
});
describe('checkGitHubResponse', () => {
test('should not throw for successful response', () => {
const mockResponse = new Response('', { status: 200 });
expect(() => checkGitHubResponse(mockResponse)).not.toThrow();
});
test('should throw RepomixError for 404', () => {
const mockResponse = new Response('', { status: 404 });
expect(() => checkGitHubResponse(mockResponse)).toThrow(RepomixError);
expect(() => checkGitHubResponse(mockResponse)).toThrow('Repository not found or is private');
});
test('should throw RepomixError for 403 with rate limit', () => {
const mockResponse = new Response('', {
status: 403,
headers: { 'X-RateLimit-Remaining': '0', 'X-RateLimit-Reset': '1234567890' },
});
expect(() => checkGitHubResponse(mockResponse)).toThrow(RepomixError);
expect(() => checkGitHubResponse(mockResponse)).toThrow('GitHub API rate limit exceeded');
});
test('should throw RepomixError for 403 without rate limit', () => {
const mockResponse = new Response('', { status: 403 });
expect(() => checkGitHubResponse(mockResponse)).toThrow(RepomixError);
expect(() => checkGitHubResponse(mockResponse)).toThrow('Access denied');
});
test('should throw RepomixError for server errors', () => {
const mockResponse = new Response('', { status: 500 });
expect(() => checkGitHubResponse(mockResponse)).toThrow(RepomixError);
expect(() => checkGitHubResponse(mockResponse)).toThrow('GitHub server error');
});
test('should throw RepomixError for other errors', () => {
const mockResponse = new Response('', { status: 400 });
expect(() => checkGitHubResponse(mockResponse)).toThrow(RepomixError);
expect(() => checkGitHubResponse(mockResponse)).toThrow('GitHub API error');
});
});
describe('parseGitHubRepoInfo integration', () => {
test('should parse shorthand format', () => {
const result = parseGitHubRepoInfo('yamadashy/repomix');
expect(result).toEqual({
owner: 'yamadashy',
repo: 'repomix',
});
});
test('should parse HTTPS URL', () => {
const result = parseGitHubRepoInfo('https://github.com/yamadashy/repomix.git');
expect(result).toEqual({
owner: 'yamadashy',
repo: 'repomix',
});
});
test('should parse SSH URL', () => {
const result = parseGitHubRepoInfo('git@github.com:yamadashy/repomix.git');
expect(result).toEqual({
owner: 'yamadashy',
repo: 'repomix',
});
});
test('should parse URL with branch', () => {
const result = parseGitHubRepoInfo('https://github.com/yamadashy/repomix/tree/develop');
expect(result).toEqual({
owner: 'yamadashy',
repo: 'repomix',
ref: 'develop',
});
});
test('should return null for non-GitHub URLs', () => {
const result = parseGitHubRepoInfo('https://gitlab.com/user/repo.git');
expect(result).toBeNull();
});
test('should return null for invalid format', () => {
const result = parseGitHubRepoInfo('invalid-format');
expect(result).toBeNull();
});
});
});