feat: 品牌替换 + 启动优化 + AGENTS.md 模板定制
- 品牌替换:OpenCode/opencode → AirCoding/aircoding(16+ 文件) - Logo ASCII art:修复 left/right 行数不匹配导致的启动崩溃 - 启动诊断:添加 OPENCODE_PRINT_TIMING 计时探针 - dev 模式默认 --pure 跳过外部插件加载 - AGENTS.md 模板:追加 AirCoding 多 Agent 专项段落 - architect prompt + plugin:强化 AGENTS.md 产出验证
This commit is contained in:
93
packages/opencode/test/util/repository.test.ts
Normal file
93
packages/opencode/test/util/repository.test.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import path from "path"
|
||||
import { pathToFileURL } from "url"
|
||||
import { Global } from "@opencode-ai/core/global"
|
||||
import {
|
||||
InvalidRepositoryBranchError,
|
||||
InvalidRepositoryReferenceError,
|
||||
UnsupportedLocalRepositoryError,
|
||||
isFileRepositoryReference,
|
||||
isRemoteRepositoryReference,
|
||||
parseRemoteRepositoryReference,
|
||||
parseRepositoryReference,
|
||||
repositoryCacheIdentity,
|
||||
repositoryCachePath,
|
||||
sameRepositoryReference,
|
||||
validateRepositoryBranch,
|
||||
} from "../../src/util/repository"
|
||||
|
||||
describe("util.repository", () => {
|
||||
test("parses github shorthand and preserves cache path", () => {
|
||||
const reference = parseRemoteRepositoryReference("owner/repo")
|
||||
|
||||
expect(reference).toMatchObject({
|
||||
host: "github.com",
|
||||
path: "owner/repo",
|
||||
segments: ["owner", "repo"],
|
||||
owner: "owner",
|
||||
repo: "repo",
|
||||
label: "owner/repo",
|
||||
})
|
||||
expect(repositoryCachePath(reference)).toBe(path.join(Global.Path.repos, "github.com", "owner", "repo"))
|
||||
expect(repositoryCacheIdentity(reference)).toBe("github.com/owner/repo")
|
||||
})
|
||||
|
||||
test("parses host path and scp remote references", () => {
|
||||
const hostPath = parseRemoteRepositoryReference("gitlab.com/group/repo")
|
||||
const scp = parseRemoteRepositoryReference("git@github.com:owner/repo.git")
|
||||
|
||||
expect(hostPath).toMatchObject({
|
||||
host: "gitlab.com",
|
||||
path: "group/repo",
|
||||
remote: "https://gitlab.com/group/repo.git",
|
||||
label: "gitlab.com/group/repo",
|
||||
})
|
||||
expect(scp).toMatchObject({
|
||||
host: "github.com",
|
||||
path: "owner/repo",
|
||||
remote: "git@github.com:owner/repo.git",
|
||||
label: "owner/repo",
|
||||
})
|
||||
})
|
||||
|
||||
test("keeps local file repositories distinct from remote repositories", () => {
|
||||
const localPath = path.resolve("repo.git")
|
||||
const reference = parseRepositoryReference(pathToFileURL(localPath).href)
|
||||
|
||||
expect(reference).toMatchObject({
|
||||
host: "file",
|
||||
protocol: "file:",
|
||||
label: localPath,
|
||||
})
|
||||
expect(reference && isFileRepositoryReference(reference)).toBe(true)
|
||||
expect(reference && isRemoteRepositoryReference(reference)).toBe(false)
|
||||
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", () => {
|
||||
const shorthand = parseRemoteRepositoryReference("owner/repo")
|
||||
const url = parseRemoteRepositoryReference("https://github.com/owner/repo.git")
|
||||
const hostPath = parseRemoteRepositoryReference("github.com/owner/repo")
|
||||
|
||||
expect(sameRepositoryReference(shorthand, url)).toBe(true)
|
||||
expect(sameRepositoryReference(shorthand, hostPath)).toBe(true)
|
||||
})
|
||||
|
||||
test("validates repository branch names", () => {
|
||||
expect(() => validateRepositoryBranch("feature/docs.v1")).not.toThrow()
|
||||
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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user