chore: generate
This commit is contained in:
parent
a9ef5a0fae
commit
7d2c1ce6c6
4 changed files with 74 additions and 20 deletions
|
|
@ -79,7 +79,10 @@ export const layer = Layer.effect(
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
export const defaultLayer = layer.pipe(Layer.provide(AppFileSystem.defaultLayer), Layer.provide(AppProcess.defaultLayer))
|
export const defaultLayer = layer.pipe(
|
||||||
|
Layer.provide(AppFileSystem.defaultLayer),
|
||||||
|
Layer.provide(AppProcess.defaultLayer),
|
||||||
|
)
|
||||||
|
|
||||||
interface Result {
|
interface Result {
|
||||||
readonly exitCode: number
|
readonly exitCode: number
|
||||||
|
|
@ -97,7 +100,7 @@ function run(cwd: string, proc: AppProcess.Interface) {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.pipe(
|
.pipe(
|
||||||
Effect.map((result) => ({ exitCode: result.exitCode, text: result.stdout.toString("utf8") } satisfies Result)),
|
Effect.map((result) => ({ exitCode: result.exitCode, text: result.stdout.toString("utf8") }) satisfies Result),
|
||||||
Effect.catch(() => Effect.succeed({ exitCode: 1, text: "" } satisfies Result)),
|
Effect.catch(() => Effect.succeed({ exitCode: 1, text: "" } satisfies Result)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,10 @@ async function rootCommit(dir: string) {
|
||||||
describe("ProjectV2.resolve", () => {
|
describe("ProjectV2.resolve", () => {
|
||||||
it.live("returns global for non-git directory", () =>
|
it.live("returns global for non-git directory", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const tmp = yield* Effect.acquireRelease(Effect.promise(() => tmpdir()), (tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()))
|
const tmp = yield* Effect.acquireRelease(
|
||||||
|
Effect.promise(() => tmpdir()),
|
||||||
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
||||||
|
)
|
||||||
const project = yield* Project.Service
|
const project = yield* Project.Service
|
||||||
|
|
||||||
const result = yield* project.resolve(abs(tmp.path))
|
const result = yield* project.resolve(abs(tmp.path))
|
||||||
|
|
@ -54,7 +57,10 @@ describe("ProjectV2.resolve", () => {
|
||||||
|
|
||||||
it.live("returns git global for repo with no commits and no remote", () =>
|
it.live("returns git global for repo with no commits and no remote", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const tmp = yield* Effect.acquireRelease(Effect.promise(() => tmpdir()), (tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()))
|
const tmp = yield* Effect.acquireRelease(
|
||||||
|
Effect.promise(() => tmpdir()),
|
||||||
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
||||||
|
)
|
||||||
yield* Effect.promise(() => initRepo(tmp.path))
|
yield* Effect.promise(() => initRepo(tmp.path))
|
||||||
const project = yield* Project.Service
|
const project = yield* Project.Service
|
||||||
|
|
||||||
|
|
@ -69,7 +75,10 @@ describe("ProjectV2.resolve", () => {
|
||||||
|
|
||||||
it.live("falls back to root commit when origin is missing", () =>
|
it.live("falls back to root commit when origin is missing", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const tmp = yield* Effect.acquireRelease(Effect.promise(() => tmpdir()), (tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()))
|
const tmp = yield* Effect.acquireRelease(
|
||||||
|
Effect.promise(() => tmpdir()),
|
||||||
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
||||||
|
)
|
||||||
yield* Effect.promise(() => initRepo(tmp.path, { commit: true }))
|
yield* Effect.promise(() => initRepo(tmp.path, { commit: true }))
|
||||||
const project = yield* Project.Service
|
const project = yield* Project.Service
|
||||||
|
|
||||||
|
|
@ -84,7 +93,10 @@ describe("ProjectV2.resolve", () => {
|
||||||
|
|
||||||
it.live("prefers normalized origin over root commit", () =>
|
it.live("prefers normalized origin over root commit", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const tmp = yield* Effect.acquireRelease(Effect.promise(() => tmpdir()), (tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()))
|
const tmp = yield* Effect.acquireRelease(
|
||||||
|
Effect.promise(() => tmpdir()),
|
||||||
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
||||||
|
)
|
||||||
yield* Effect.promise(() => initRepo(tmp.path, { commit: true, remote: "git@github.com:Acme/App.git" }))
|
yield* Effect.promise(() => initRepo(tmp.path, { commit: true, remote: "git@github.com:Acme/App.git" }))
|
||||||
const project = yield* Project.Service
|
const project = yield* Project.Service
|
||||||
|
|
||||||
|
|
@ -99,8 +111,14 @@ describe("ProjectV2.resolve", () => {
|
||||||
|
|
||||||
it.live("normalizes ssh and https remotes to the same id", () =>
|
it.live("normalizes ssh and https remotes to the same id", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const ssh = yield* Effect.acquireRelease(Effect.promise(() => tmpdir()), (tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()))
|
const ssh = yield* Effect.acquireRelease(
|
||||||
const https = yield* Effect.acquireRelease(Effect.promise(() => tmpdir()), (tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()))
|
Effect.promise(() => tmpdir()),
|
||||||
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
||||||
|
)
|
||||||
|
const https = yield* Effect.acquireRelease(
|
||||||
|
Effect.promise(() => tmpdir()),
|
||||||
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
||||||
|
)
|
||||||
yield* Effect.promise(() => initRepo(ssh.path, { commit: true, remote: "git@github.com:owner/repo.git" }))
|
yield* Effect.promise(() => initRepo(ssh.path, { commit: true, remote: "git@github.com:owner/repo.git" }))
|
||||||
yield* Effect.promise(() => initRepo(https.path, { commit: true, remote: "https://github.com/owner/repo.git" }))
|
yield* Effect.promise(() => initRepo(https.path, { commit: true, remote: "https://github.com/owner/repo.git" }))
|
||||||
const project = yield* Project.Service
|
const project = yield* Project.Service
|
||||||
|
|
@ -115,7 +133,10 @@ describe("ProjectV2.resolve", () => {
|
||||||
|
|
||||||
it.live("ignores file remotes and falls back to root commit", () =>
|
it.live("ignores file remotes and falls back to root commit", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const tmp = yield* Effect.acquireRelease(Effect.promise(() => tmpdir()), (tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()))
|
const tmp = yield* Effect.acquireRelease(
|
||||||
|
Effect.promise(() => tmpdir()),
|
||||||
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
||||||
|
)
|
||||||
yield* Effect.promise(() => initRepo(tmp.path, { commit: true, remote: `file://${tmp.path}` }))
|
yield* Effect.promise(() => initRepo(tmp.path, { commit: true, remote: `file://${tmp.path}` }))
|
||||||
const project = yield* Project.Service
|
const project = yield* Project.Service
|
||||||
|
|
||||||
|
|
@ -127,7 +148,10 @@ describe("ProjectV2.resolve", () => {
|
||||||
|
|
||||||
it.live("returns previous cached id from common dir", () =>
|
it.live("returns previous cached id from common dir", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const tmp = yield* Effect.acquireRelease(Effect.promise(() => tmpdir()), (tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()))
|
const tmp = yield* Effect.acquireRelease(
|
||||||
|
Effect.promise(() => tmpdir()),
|
||||||
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
||||||
|
)
|
||||||
yield* Effect.promise(() => initRepo(tmp.path, { commit: true, remote: "git@github.com:owner/repo.git" }))
|
yield* Effect.promise(() => initRepo(tmp.path, { commit: true, remote: "git@github.com:owner/repo.git" }))
|
||||||
yield* Effect.promise(() => Bun.write(path.join(tmp.path, ".git", "opencode"), "old-id"))
|
yield* Effect.promise(() => Bun.write(path.join(tmp.path, ".git", "opencode"), "old-id"))
|
||||||
const project = yield* Project.Service
|
const project = yield* Project.Service
|
||||||
|
|
@ -141,7 +165,10 @@ describe("ProjectV2.resolve", () => {
|
||||||
|
|
||||||
it.live("does not write the cache while resolving", () =>
|
it.live("does not write the cache while resolving", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const tmp = yield* Effect.acquireRelease(Effect.promise(() => tmpdir()), (tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()))
|
const tmp = yield* Effect.acquireRelease(
|
||||||
|
Effect.promise(() => tmpdir()),
|
||||||
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
||||||
|
)
|
||||||
yield* Effect.promise(() => initRepo(tmp.path, { commit: true, remote: "git@github.com:owner/repo.git" }))
|
yield* Effect.promise(() => initRepo(tmp.path, { commit: true, remote: "git@github.com:owner/repo.git" }))
|
||||||
const project = yield* Project.Service
|
const project = yield* Project.Service
|
||||||
|
|
||||||
|
|
@ -153,7 +180,10 @@ describe("ProjectV2.resolve", () => {
|
||||||
|
|
||||||
it.live("resolves from nested directories to repo root", () =>
|
it.live("resolves from nested directories to repo root", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const tmp = yield* Effect.acquireRelease(Effect.promise(() => tmpdir()), (tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()))
|
const tmp = yield* Effect.acquireRelease(
|
||||||
|
Effect.promise(() => tmpdir()),
|
||||||
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
||||||
|
)
|
||||||
yield* Effect.promise(() => initRepo(tmp.path, { commit: true }))
|
yield* Effect.promise(() => initRepo(tmp.path, { commit: true }))
|
||||||
yield* Effect.promise(() => fs.mkdir(path.join(tmp.path, "a", "b"), { recursive: true }))
|
yield* Effect.promise(() => fs.mkdir(path.join(tmp.path, "a", "b"), { recursive: true }))
|
||||||
const project = yield* Project.Service
|
const project = yield* Project.Service
|
||||||
|
|
@ -166,9 +196,14 @@ describe("ProjectV2.resolve", () => {
|
||||||
|
|
||||||
it.live("linked worktree returns opened worktree directory and previous from common dir", () =>
|
it.live("linked worktree returns opened worktree directory and previous from common dir", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const tmp = yield* Effect.acquireRelease(Effect.promise(() => tmpdir()), (tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()))
|
const tmp = yield* Effect.acquireRelease(
|
||||||
|
Effect.promise(() => tmpdir()),
|
||||||
|
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
||||||
|
)
|
||||||
const worktree = `${tmp.path}-worktree`
|
const worktree = `${tmp.path}-worktree`
|
||||||
yield* Effect.addFinalizer(() => Effect.promise(() => $`rm -rf ${worktree}`.quiet().nothrow()).pipe(Effect.ignore))
|
yield* Effect.addFinalizer(() =>
|
||||||
|
Effect.promise(() => $`rm -rf ${worktree}`.quiet().nothrow()).pipe(Effect.ignore),
|
||||||
|
)
|
||||||
yield* Effect.promise(() => initRepo(tmp.path, { commit: true, remote: "git@github.com:owner/repo.git" }))
|
yield* Effect.promise(() => initRepo(tmp.path, { commit: true, remote: "git@github.com:owner/repo.git" }))
|
||||||
yield* Effect.promise(() => Bun.write(path.join(tmp.path, ".git", "opencode"), "old-id"))
|
yield* Effect.promise(() => Bun.write(path.join(tmp.path, ".git", "opencode"), "old-id"))
|
||||||
yield* Effect.promise(() => $`git worktree add ${worktree} -b test-${Date.now()}`.cwd(tmp.path).quiet())
|
yield* Effect.promise(() => $`git worktree add ${worktree} -b test-${Date.now()}`.cwd(tmp.path).quiet())
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,10 @@ export const layer = Layer.effect(
|
||||||
|
|
||||||
const scope = yield* Scope.Scope
|
const scope = yield* Scope.Scope
|
||||||
|
|
||||||
const migrateProjectId = Effect.fn("Project.migrateProjectId")(function* (oldID: ProjectID | undefined, newID: ProjectID) {
|
const migrateProjectId = Effect.fn("Project.migrateProjectId")(function* (
|
||||||
|
oldID: ProjectID | undefined,
|
||||||
|
newID: ProjectID,
|
||||||
|
) {
|
||||||
if (!oldID) return
|
if (!oldID) return
|
||||||
if (oldID === ProjectID.global) return
|
if (oldID === ProjectID.global) return
|
||||||
if (oldID === newID) return
|
if (oldID === newID) return
|
||||||
|
|
@ -255,7 +258,11 @@ export const layer = Layer.effect(
|
||||||
vcs: data.vcs?.type ?? fakeVcs,
|
vcs: data.vcs?.type ?? fakeVcs,
|
||||||
time: { ...existing.time, updated: Date.now() },
|
time: { ...existing.time, updated: Date.now() },
|
||||||
}
|
}
|
||||||
if (projectID !== ProjectID.global && data.directory !== result.worktree && !result.sandboxes.includes(data.directory))
|
if (
|
||||||
|
projectID !== ProjectID.global &&
|
||||||
|
data.directory !== result.worktree &&
|
||||||
|
!result.sandboxes.includes(data.directory)
|
||||||
|
)
|
||||||
result.sandboxes.push(data.directory)
|
result.sandboxes.push(data.directory)
|
||||||
result.sandboxes = yield* Effect.forEach(
|
result.sandboxes = yield* Effect.forEach(
|
||||||
result.sandboxes,
|
result.sandboxes,
|
||||||
|
|
|
||||||
|
|
@ -239,10 +239,19 @@ describe("Project.fromDirectory", () => {
|
||||||
const { project } = yield* projects.fromDirectory(tmp)
|
const { project } = yield* projects.fromDirectory(tmp)
|
||||||
|
|
||||||
expect(project.id).toBe(remoteID)
|
expect(project.id).toBe(remoteID)
|
||||||
expect(Database.use((db) => db.select().from(ProjectTable).where(eq(ProjectTable.id, rootProject.id)).get())).toBeUndefined()
|
expect(
|
||||||
expect(Database.use((db) => db.select().from(SessionTable).where(eq(SessionTable.id, sessionID)).get())?.project_id).toBe(remoteID)
|
Database.use((db) => db.select().from(ProjectTable).where(eq(ProjectTable.id, rootProject.id)).get()),
|
||||||
expect(Database.use((db) => db.select().from(PermissionTable).where(eq(PermissionTable.project_id, remoteID)).get())).toBeDefined()
|
).toBeUndefined()
|
||||||
expect(Database.use((db) => db.select().from(WorkspaceTable).where(eq(WorkspaceTable.id, workspaceID)).get())?.project_id).toBe(remoteID)
|
expect(
|
||||||
|
Database.use((db) => db.select().from(SessionTable).where(eq(SessionTable.id, sessionID)).get())?.project_id,
|
||||||
|
).toBe(remoteID)
|
||||||
|
expect(
|
||||||
|
Database.use((db) => db.select().from(PermissionTable).where(eq(PermissionTable.project_id, remoteID)).get()),
|
||||||
|
).toBeDefined()
|
||||||
|
expect(
|
||||||
|
Database.use((db) => db.select().from(WorkspaceTable).where(eq(WorkspaceTable.id, workspaceID)).get())
|
||||||
|
?.project_id,
|
||||||
|
).toBe(remoteID)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue