fix(repository): type expected reference failures (#28880)

This commit is contained in:
Shoubhit Dash
2026-05-22 23:13:14 +05:30
committed by GitHub
parent 4f6eaf859b
commit aee552c043
3 changed files with 80 additions and 13 deletions

View File

@@ -3,6 +3,9 @@ import path from "path"
import { pathToFileURL } from "url"
import { Global } from "@opencode-ai/core/global"
import {
InvalidRepositoryBranchError,
InvalidRepositoryReferenceError,
UnsupportedLocalRepositoryError,
isFileRepositoryReference,
isRemoteRepositoryReference,
parseRemoteRepositoryReference,
@@ -61,6 +64,14 @@ describe("util.repository", () => {
expect(() => parseRemoteRepositoryReference(pathToFileURL(localPath).href)).toThrow(
"Local file repositories are not supported",
)
expect(() => parseRemoteRepositoryReference(pathToFileURL(localPath).href)).toThrow(UnsupportedLocalRepositoryError)
})
test("rejects invalid remote repository references with typed errors", () => {
expect(() => parseRemoteRepositoryReference("not-a-repo")).toThrow(InvalidRepositoryReferenceError)
expect(() => parseRemoteRepositoryReference("git@github.com:../../../etc/passwd")).toThrow(
InvalidRepositoryReferenceError,
)
})
test("compares cache identity independent of input spelling", () => {
@@ -77,5 +88,6 @@ describe("util.repository", () => {
expect(() => validateRepositoryBranch("-bad")).toThrow("Branch must contain only alphanumeric characters")
expect(() => validateRepositoryBranch("bad..branch")).toThrow("Branch must contain only alphanumeric characters")
expect(() => validateRepositoryBranch("bad branch")).toThrow("Branch must contain only alphanumeric characters")
expect(() => validateRepositoryBranch("bad branch")).toThrow(InvalidRepositoryBranchError)
})
})