mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 08:03:39 +00:00
fix(coding-agent): tighten git source parsing and local path normalization (fixes #1426)
This commit is contained in:
parent
31f765ff1b
commit
0adce69b3b
8 changed files with 152 additions and 242 deletions
|
|
@ -1,89 +1,8 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { parseGitUrl } from "../src/utils/git.js";
|
||||
|
||||
describe("SSH Git URL Parsing", () => {
|
||||
describe("ssh:// protocol", () => {
|
||||
it("should parse basic ssh:// URL", () => {
|
||||
const result = parseGitUrl("ssh://git@github.com/user/repo");
|
||||
expect(result).toMatchObject({
|
||||
host: "github.com",
|
||||
path: "user/repo",
|
||||
repo: "ssh://git@github.com/user/repo",
|
||||
});
|
||||
expect(result?.ref).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should parse ssh:// URL with port", () => {
|
||||
const result = parseGitUrl("ssh://git@github.com:22/user/repo");
|
||||
expect(result).toMatchObject({
|
||||
host: "github.com",
|
||||
path: "user/repo",
|
||||
repo: "ssh://git@github.com:22/user/repo",
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse ssh:// URL with .git suffix", () => {
|
||||
const result = parseGitUrl("ssh://git@github.com/user/repo.git");
|
||||
expect(result).toMatchObject({
|
||||
host: "github.com",
|
||||
path: "user/repo",
|
||||
repo: "ssh://git@github.com/user/repo.git",
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse ssh:// URL with ref", () => {
|
||||
const result = parseGitUrl("ssh://git@github.com/user/repo@v1.0.0");
|
||||
expect(result).toMatchObject({
|
||||
host: "github.com",
|
||||
path: "user/repo",
|
||||
ref: "v1.0.0",
|
||||
repo: "ssh://git@github.com/user/repo",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("git@host:path pattern", () => {
|
||||
it("should parse basic git@host:path", () => {
|
||||
const result = parseGitUrl("git@github.com:user/repo");
|
||||
expect(result).toMatchObject({
|
||||
host: "github.com",
|
||||
path: "user/repo",
|
||||
repo: "git@github.com:user/repo",
|
||||
});
|
||||
expect(result?.ref).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should parse git@host:path with .git", () => {
|
||||
const result = parseGitUrl("git@github.com:user/repo.git");
|
||||
expect(result).toMatchObject({
|
||||
host: "github.com",
|
||||
path: "user/repo",
|
||||
repo: "git@github.com:user/repo.git",
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse git@host:path with ref", () => {
|
||||
const result = parseGitUrl("git@github.com:user/repo@v1.0.0");
|
||||
expect(result).toMatchObject({
|
||||
host: "github.com",
|
||||
path: "user/repo",
|
||||
ref: "v1.0.0",
|
||||
repo: "git@github.com:user/repo",
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse git@host:path with ref and .git", () => {
|
||||
const result = parseGitUrl("git@github.com:user/repo.git@main");
|
||||
expect(result).toMatchObject({
|
||||
host: "github.com",
|
||||
path: "user/repo",
|
||||
ref: "main",
|
||||
repo: "git@github.com:user/repo.git",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("HTTPS URLs", () => {
|
||||
describe("Git URL Parsing", () => {
|
||||
describe("protocol URLs (accepted without git: prefix)", () => {
|
||||
it("should parse HTTPS URL", () => {
|
||||
const result = parseGitUrl("https://github.com/user/repo");
|
||||
expect(result).toMatchObject({
|
||||
|
|
@ -93,25 +12,67 @@ describe("SSH Git URL Parsing", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it("should parse shorthand URL", () => {
|
||||
const result = parseGitUrl("github.com/user/repo");
|
||||
it("should parse ssh:// URL", () => {
|
||||
const result = parseGitUrl("ssh://git@github.com/user/repo");
|
||||
expect(result).toMatchObject({
|
||||
host: "github.com",
|
||||
path: "user/repo",
|
||||
repo: "ssh://git@github.com/user/repo",
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse protocol URL with ref", () => {
|
||||
const result = parseGitUrl("https://github.com/user/repo@v1.0.0");
|
||||
expect(result).toMatchObject({
|
||||
host: "github.com",
|
||||
path: "user/repo",
|
||||
ref: "v1.0.0",
|
||||
repo: "https://github.com/user/repo",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("shorthand URLs (accepted only with git: prefix)", () => {
|
||||
it("should parse git@host:path with git: prefix", () => {
|
||||
const result = parseGitUrl("git:git@github.com:user/repo");
|
||||
expect(result).toMatchObject({
|
||||
host: "github.com",
|
||||
path: "user/repo",
|
||||
repo: "git@github.com:user/repo",
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse host/path shorthand with git: prefix", () => {
|
||||
const result = parseGitUrl("git:github.com/user/repo");
|
||||
expect(result).toMatchObject({
|
||||
host: "github.com",
|
||||
path: "user/repo",
|
||||
repo: "https://github.com/user/repo",
|
||||
});
|
||||
});
|
||||
|
||||
it("should parse shorthand with ref and git: prefix", () => {
|
||||
const result = parseGitUrl("git:git@github.com:user/repo@v1.0.0");
|
||||
expect(result).toMatchObject({
|
||||
host: "github.com",
|
||||
path: "user/repo",
|
||||
ref: "v1.0.0",
|
||||
repo: "git@github.com:user/repo",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("edge cases", () => {
|
||||
it("should return null for invalid URLs", () => {
|
||||
expect(parseGitUrl("git@github.com")).toBeNull();
|
||||
expect(parseGitUrl("not-a-url")).toBeNull();
|
||||
describe("unsupported without git: prefix", () => {
|
||||
it("should reject git@host:path without git: prefix", () => {
|
||||
expect(parseGitUrl("git@github.com:user/repo")).toBeNull();
|
||||
});
|
||||
|
||||
it("should handle different hosts", () => {
|
||||
expect(parseGitUrl("git@gitlab.com:user/repo")?.host).toBe("gitlab.com");
|
||||
expect(parseGitUrl("git@bitbucket.org:user/repo")?.host).toBe("bitbucket.org");
|
||||
it("should reject host/path shorthand without git: prefix", () => {
|
||||
expect(parseGitUrl("github.com/user/repo")).toBeNull();
|
||||
});
|
||||
|
||||
it("should reject user/repo shorthand", () => {
|
||||
expect(parseGitUrl("user/repo")).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue