fix: 修正 logo 中 N 和 G 字母造型
N 添加对角线笔画(█▄ █),G 添加内横杠(█ ▀█), 避免与 O 字母造型雷同。同步更新 ui.ts 中的硬编码 wordmark。
This commit is contained in:
60
packages/core/test/fixture/effect-flock-worker.ts
Normal file
60
packages/core/test/fixture/effect-flock-worker.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import fs from "fs/promises"
|
||||
import os from "os"
|
||||
import { Effect, Layer } from "effect"
|
||||
import { FSUtil } from "@opencode-ai/core/fs-util"
|
||||
import { EffectFlock } from "@opencode-ai/core/util/effect-flock"
|
||||
import { Global } from "@opencode-ai/core/global"
|
||||
|
||||
type Msg = {
|
||||
key: string
|
||||
dir: string
|
||||
holdMs?: number
|
||||
ready?: string
|
||||
active?: string
|
||||
done?: string
|
||||
}
|
||||
|
||||
function sleep(ms: number) {
|
||||
return new Promise<void>((resolve) => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
const msg: Msg = JSON.parse(process.argv[2])
|
||||
|
||||
const testGlobal = Global.layerWith({
|
||||
home: os.homedir(),
|
||||
data: os.tmpdir(),
|
||||
cache: os.tmpdir(),
|
||||
config: os.tmpdir(),
|
||||
state: os.tmpdir(),
|
||||
bin: os.tmpdir(),
|
||||
log: os.tmpdir(),
|
||||
})
|
||||
|
||||
const testLayer = EffectFlock.layer.pipe(Layer.provide(testGlobal), Layer.provide(FSUtil.defaultLayer))
|
||||
|
||||
async function job() {
|
||||
if (msg.ready) await fs.writeFile(msg.ready, String(process.pid))
|
||||
if (msg.active) await fs.writeFile(msg.active, String(process.pid), { flag: "wx" })
|
||||
|
||||
try {
|
||||
if (msg.holdMs && msg.holdMs > 0) await sleep(msg.holdMs)
|
||||
if (msg.done) await fs.appendFile(msg.done, "1\n")
|
||||
} finally {
|
||||
if (msg.active) await fs.rm(msg.active, { force: true })
|
||||
}
|
||||
}
|
||||
|
||||
await Effect.runPromise(
|
||||
Effect.gen(function* () {
|
||||
const flock = yield* EffectFlock.Service
|
||||
yield* flock.withLock(
|
||||
Effect.promise(() => job()),
|
||||
msg.key,
|
||||
msg.dir,
|
||||
)
|
||||
}).pipe(Effect.provide(testLayer)),
|
||||
).catch((err) => {
|
||||
const text = err instanceof Error ? (err.stack ?? err.message) : String(err)
|
||||
process.stderr.write(text)
|
||||
process.exit(1)
|
||||
})
|
||||
72
packages/core/test/fixture/flock-worker.ts
Normal file
72
packages/core/test/fixture/flock-worker.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import fs from "fs/promises"
|
||||
import { Flock } from "@opencode-ai/core/util/flock"
|
||||
|
||||
type Msg = {
|
||||
key: string
|
||||
dir: string
|
||||
staleMs?: number
|
||||
timeoutMs?: number
|
||||
baseDelayMs?: number
|
||||
maxDelayMs?: number
|
||||
holdMs?: number
|
||||
ready?: string
|
||||
active?: string
|
||||
done?: string
|
||||
}
|
||||
|
||||
function sleep(ms: number) {
|
||||
return new Promise<void>((resolve) => {
|
||||
setTimeout(resolve, ms)
|
||||
})
|
||||
}
|
||||
|
||||
function input() {
|
||||
const raw = process.argv[2]
|
||||
if (!raw) {
|
||||
throw new Error("Missing flock worker input")
|
||||
}
|
||||
|
||||
return JSON.parse(raw) as Msg
|
||||
}
|
||||
|
||||
async function job(input: Msg) {
|
||||
if (input.ready) {
|
||||
await fs.writeFile(input.ready, String(process.pid))
|
||||
}
|
||||
|
||||
if (input.active) {
|
||||
await fs.writeFile(input.active, String(process.pid), { flag: "wx" })
|
||||
}
|
||||
|
||||
try {
|
||||
if (input.holdMs && input.holdMs > 0) {
|
||||
await sleep(input.holdMs)
|
||||
}
|
||||
|
||||
if (input.done) {
|
||||
await fs.appendFile(input.done, "1\n")
|
||||
}
|
||||
} finally {
|
||||
if (input.active) {
|
||||
await fs.rm(input.active, { force: true })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const msg = input()
|
||||
|
||||
await Flock.withLock(msg.key, () => job(msg), {
|
||||
dir: msg.dir,
|
||||
staleMs: msg.staleMs,
|
||||
timeoutMs: msg.timeoutMs,
|
||||
baseDelayMs: msg.baseDelayMs,
|
||||
maxDelayMs: msg.maxDelayMs,
|
||||
})
|
||||
}
|
||||
|
||||
await main().catch((err) => {
|
||||
const text = err instanceof Error ? (err.stack ?? err.message) : String(err)
|
||||
process.stderr.write(text)
|
||||
process.exit(1)
|
||||
})
|
||||
49
packages/core/test/fixture/git.ts
Normal file
49
packages/core/test/fixture/git.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { execFile } from "child_process"
|
||||
import fs from "fs/promises"
|
||||
import path from "path"
|
||||
import { promisify } from "util"
|
||||
import { pathToFileURL } from "url"
|
||||
import { Repository } from "@opencode-ai/core/repository"
|
||||
|
||||
const exec = promisify(execFile)
|
||||
|
||||
export async function gitRemote(root: string) {
|
||||
const origin = path.join(root, "origin.git")
|
||||
const source = path.join(root, "source")
|
||||
await git(root, "init", "--bare", origin)
|
||||
await git(root, "init", source)
|
||||
await git(source, "config", "user.email", "test@example.com")
|
||||
await git(source, "config", "user.name", "Test")
|
||||
await fs.writeFile(path.join(source, "README.md"), "one\n")
|
||||
await git(source, "add", "README.md")
|
||||
await git(source, "commit", "-m", "initial")
|
||||
await git(source, "branch", "-M", "main")
|
||||
await git(source, "remote", "add", "origin", pathToFileURL(origin).href)
|
||||
await git(source, "push", "-u", "origin", "main")
|
||||
await git(root, "--git-dir", origin, "symbolic-ref", "HEAD", "refs/heads/main")
|
||||
return {
|
||||
root,
|
||||
source,
|
||||
remote: pathToFileURL(origin).href,
|
||||
reference: { ...Repository.parseRemote("owner/repo"), remote: pathToFileURL(origin).href },
|
||||
}
|
||||
}
|
||||
|
||||
export async function commit(source: string, content: string, message: string) {
|
||||
await fs.writeFile(path.join(source, "README.md"), content)
|
||||
await git(source, "add", "README.md")
|
||||
await git(source, "commit", "-m", message)
|
||||
await git(source, "push")
|
||||
}
|
||||
|
||||
export async function branch(source: string, name: string, content: string) {
|
||||
await git(source, "checkout", "-b", name)
|
||||
await fs.writeFile(path.join(source, "README.md"), content)
|
||||
await git(source, "add", "README.md")
|
||||
await git(source, "commit", "-m", name)
|
||||
await git(source, "push", "-u", "origin", name)
|
||||
}
|
||||
|
||||
export async function git(cwd: string, ...args: string[]) {
|
||||
await exec("git", args, { cwd })
|
||||
}
|
||||
12
packages/core/test/fixture/location.ts
Normal file
12
packages/core/test/fixture/location.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Location } from "@opencode-ai/core/location"
|
||||
import { Project } from "@opencode-ai/core/project"
|
||||
import { AbsolutePath } from "@opencode-ai/core/schema"
|
||||
|
||||
export function location(ref: Location.Ref, input: { projectDirectory?: AbsolutePath; vcs?: Project.Vcs } = {}) {
|
||||
return {
|
||||
directory: ref.directory,
|
||||
workspaceID: ref.workspaceID,
|
||||
project: { id: Project.ID.global, directory: input.projectDirectory ?? ref.directory },
|
||||
vcs: input.vcs,
|
||||
} satisfies Location.Interface
|
||||
}
|
||||
25
packages/core/test/fixture/tmpdir.ts
Normal file
25
packages/core/test/fixture/tmpdir.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import fs from "fs/promises"
|
||||
import { tmpdir as osTmpdir } from "os"
|
||||
import path from "path"
|
||||
|
||||
export const tmpdir = async () => {
|
||||
const dir = await fs.realpath(await fs.mkdtemp(path.join(osTmpdir(), "opencode-core-test-")))
|
||||
return {
|
||||
path: dir,
|
||||
async [Symbol.asyncDispose]() {
|
||||
await remove(dir)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(dir: string, retries = 30): Promise<void> {
|
||||
try {
|
||||
await fs.rm(dir, { recursive: true, force: true })
|
||||
} catch (error) {
|
||||
if (retries === 0 || !error || typeof error !== "object" || !("code" in error) || error.code !== "EBUSY")
|
||||
throw error
|
||||
Bun.gc(true)
|
||||
await Bun.sleep(100)
|
||||
return remove(dir, retries - 1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user