chore: generate
This commit is contained in:
@@ -96,8 +96,8 @@ export const layer = Layer.effect(
|
||||
if (patch) {
|
||||
const repository = yield* git.repo.discover(directory)
|
||||
if (!repository) return yield* new ApplyChangesError({ message: "Destination is not a Git repository" })
|
||||
yield* git
|
||||
.change.apply({ repository, path: directory, changes: patch })
|
||||
yield* git.change
|
||||
.apply({ repository, path: directory, changes: patch })
|
||||
.pipe(Effect.mapError((error) => new ApplyChangesError({ message: error.message })))
|
||||
}
|
||||
|
||||
|
||||
+68
-67
@@ -244,7 +244,10 @@ export const layer = Layer.effect(
|
||||
directory: AbsolutePath,
|
||||
args: string[],
|
||||
) {
|
||||
const result = yield* execute(directory, proc)(args).pipe(
|
||||
const result = yield* execute(
|
||||
directory,
|
||||
proc,
|
||||
)(args).pipe(
|
||||
Effect.mapError((cause) => new OperationError({ operation, directory, message: cause.message, cause })),
|
||||
)
|
||||
if (result.exitCode === 0) return
|
||||
@@ -306,10 +309,7 @@ export const layer = Layer.effect(
|
||||
])
|
||||
})
|
||||
|
||||
const reset = Effect.fn("Git.sync.resetHard")(function* (
|
||||
repository: Repository,
|
||||
revision: string,
|
||||
) {
|
||||
const reset = Effect.fn("Git.sync.resetHard")(function* (repository: Repository, revision: string) {
|
||||
yield* operation("reset", repository.worktree, ["reset", "--hard", revision])
|
||||
})
|
||||
|
||||
@@ -404,10 +404,12 @@ export const layer = Layer.effect(
|
||||
}),
|
||||
),
|
||||
)
|
||||
yield* fs.writeFileString(
|
||||
yield* fs
|
||||
.writeFileString(
|
||||
path.join(input.gitDirectory, "objects", "info", "alternates"),
|
||||
path.join(input.seed.commonDirectory, "objects") + "\n",
|
||||
).pipe(
|
||||
)
|
||||
.pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new OperationError({
|
||||
@@ -445,14 +447,9 @@ export const layer = Layer.effect(
|
||||
if (!candidates.length) return { skipped: [] }
|
||||
const ignored = input.ignores
|
||||
? new Set(
|
||||
(
|
||||
yield* repositoryOperation(
|
||||
"refresh",
|
||||
input.ignores,
|
||||
["check-ignore", "--no-index", "--stdin", "-z"],
|
||||
{ stdin: candidates.join("\0") + "\0" },
|
||||
).pipe(Effect.catch(() => Effect.succeed({ text: "", stderr: "" })))
|
||||
).text
|
||||
(yield* repositoryOperation("refresh", input.ignores, ["check-ignore", "--no-index", "--stdin", "-z"], {
|
||||
stdin: candidates.join("\0") + "\0",
|
||||
}).pipe(Effect.catch(() => Effect.succeed({ text: "", stderr: "" })))).text
|
||||
.split("\0")
|
||||
.filter(Boolean),
|
||||
)
|
||||
@@ -460,8 +457,7 @@ export const layer = Layer.effect(
|
||||
const allowed = candidates.filter((item) => !ignored.has(item))
|
||||
const maximum = input.maximumUntrackedFileBytes
|
||||
const skipped = maximum
|
||||
? (
|
||||
yield* Effect.forEach(
|
||||
? (yield* Effect.forEach(
|
||||
untracked.filter((item) => allowed.includes(item)),
|
||||
(item) =>
|
||||
fs.stat(path.join(input.repository.worktree, item)).pipe(
|
||||
@@ -471,8 +467,7 @@ export const layer = Layer.effect(
|
||||
Effect.catch(() => Effect.succeed(undefined)),
|
||||
),
|
||||
{ concurrency: 8 },
|
||||
)
|
||||
).filter((item): item is RelativePath => item !== undefined)
|
||||
)).filter((item): item is RelativePath => item !== undefined)
|
||||
: []
|
||||
const stage = allowed.filter((item) => !skipped.includes(RelativePath.make(item)))
|
||||
const remove = [...ignored, ...skipped]
|
||||
@@ -500,11 +495,10 @@ export const layer = Layer.effect(
|
||||
if (!input.paths.length) return new Set<RelativePath>()
|
||||
const result = yield* proc
|
||||
.run(
|
||||
ChildProcess.make(
|
||||
"git",
|
||||
repositoryArgs(input.repository, ["check-ignore", "--no-index", "--stdin", "-z"]),
|
||||
{ cwd: input.repository.worktree, extendEnv: true },
|
||||
),
|
||||
ChildProcess.make("git", repositoryArgs(input.repository, ["check-ignore", "--no-index", "--stdin", "-z"]), {
|
||||
cwd: input.repository.worktree,
|
||||
extendEnv: true,
|
||||
}),
|
||||
{ stdin: input.paths.join("\0") + "\0" },
|
||||
)
|
||||
.pipe(
|
||||
@@ -537,7 +531,8 @@ export const layer = Layer.effect(
|
||||
return TreeID.make((yield* repositoryOperation("write_tree", repository, ["write-tree"])).text.trim())
|
||||
})
|
||||
|
||||
const captureTree = Effect.fn("Git.tree.capture")((input: {
|
||||
const captureTree = Effect.fn("Git.tree.capture")(
|
||||
(input: {
|
||||
repository: Repository
|
||||
scopes: readonly RelativePath[]
|
||||
ignores?: Repository
|
||||
@@ -546,11 +541,7 @@ export const layer = Layer.effect(
|
||||
locked(
|
||||
input.repository,
|
||||
Effect.gen(function* () {
|
||||
yield* Effect.forEach(
|
||||
input.scopes,
|
||||
(scope) => refresh({ ...input, scope }),
|
||||
{ discard: true },
|
||||
)
|
||||
yield* Effect.forEach(input.scopes, (scope) => refresh({ ...input, scope }), { discard: true })
|
||||
return yield* writeTree(input.repository)
|
||||
}),
|
||||
),
|
||||
@@ -561,8 +552,14 @@ export const layer = Layer.effect(
|
||||
from: TreeID
|
||||
to: TreeID
|
||||
}) {
|
||||
return (yield* repositoryOperation("list_files", input.repository, ["diff", "--name-only", "-z", input.from, input.to]))
|
||||
.text.split("\0")
|
||||
return (yield* repositoryOperation("list_files", input.repository, [
|
||||
"diff",
|
||||
"--name-only",
|
||||
"-z",
|
||||
input.from,
|
||||
input.to,
|
||||
])).text
|
||||
.split("\0")
|
||||
.filter(Boolean)
|
||||
.map((file) => RelativePath.make(file))
|
||||
})
|
||||
@@ -577,8 +574,7 @@ export const layer = Layer.effect(
|
||||
const paths = input.paths ?? (yield* treeFiles(input))
|
||||
return yield* Effect.forEach(paths, (file) =>
|
||||
Effect.gen(function* () {
|
||||
const statusText = (
|
||||
yield* repositoryOperation("diff", input.repository, [
|
||||
const statusText = (yield* repositoryOperation("diff", input.repository, [
|
||||
"diff",
|
||||
"--name-status",
|
||||
"--no-renames",
|
||||
@@ -586,11 +582,9 @@ export const layer = Layer.effect(
|
||||
input.to,
|
||||
"--",
|
||||
file,
|
||||
])
|
||||
).text.trim()
|
||||
])).text.trim()
|
||||
const status = statusText.startsWith("A") ? "added" : statusText.startsWith("D") ? "deleted" : "modified"
|
||||
const stats = (
|
||||
yield* repositoryOperation("diff", input.repository, [
|
||||
const stats = (yield* repositoryOperation("diff", input.repository, [
|
||||
"diff",
|
||||
"--numstat",
|
||||
"--no-renames",
|
||||
@@ -598,13 +592,11 @@ export const layer = Layer.effect(
|
||||
input.to,
|
||||
"--",
|
||||
file,
|
||||
])
|
||||
).text.split("\t")
|
||||
])).text.split("\t")
|
||||
const binary = stats[0] === "-" || stats[1] === "-"
|
||||
const patch = binary
|
||||
? ""
|
||||
: (
|
||||
yield* repositoryOperation("diff", input.repository, [
|
||||
: (yield* repositoryOperation("diff", input.repository, [
|
||||
"diff",
|
||||
`--unified=${input.context ?? 3}`,
|
||||
"--no-renames",
|
||||
@@ -612,8 +604,7 @@ export const layer = Layer.effect(
|
||||
input.to,
|
||||
"--",
|
||||
file,
|
||||
])
|
||||
).text
|
||||
])).text
|
||||
return {
|
||||
path: file,
|
||||
status,
|
||||
@@ -626,12 +617,17 @@ export const layer = Layer.effect(
|
||||
})
|
||||
|
||||
const entry = Effect.fnUntraced(function* (repository: Repository, tree: TreeID, file: RelativePath) {
|
||||
const text = (
|
||||
yield* repositoryOperation("restore", repository, ["ls-tree", "-z", tree, "--", file])
|
||||
).text.replace(/\0$/, "")
|
||||
const text = (yield* repositoryOperation("restore", repository, [
|
||||
"ls-tree",
|
||||
"-z",
|
||||
tree,
|
||||
"--",
|
||||
file,
|
||||
])).text.replace(/\0$/, "")
|
||||
if (!text) return
|
||||
const match = text.match(/^(\d+)\s+\w+\s+([0-9a-f]+)\t/)
|
||||
if (!match) return yield* new OperationError({
|
||||
if (!match)
|
||||
return yield* new OperationError({
|
||||
operation: "restore",
|
||||
directory: repository.worktree,
|
||||
message: `Invalid tree entry for ${file}`,
|
||||
@@ -639,7 +635,8 @@ export const layer = Layer.effect(
|
||||
return { mode: match[1], object: match[2] }
|
||||
})
|
||||
|
||||
const preview = Effect.fn("Git.tree.preview")((input: {
|
||||
const preview = Effect.fn("Git.tree.preview")(
|
||||
(input: {
|
||||
repository: Repository
|
||||
current: TreeID
|
||||
files: ReadonlyMap<RelativePath, TreeID>
|
||||
@@ -690,10 +687,8 @@ export const layer = Layer.effect(
|
||||
),
|
||||
)
|
||||
|
||||
const restore = Effect.fn("Git.tree.restore")((input: {
|
||||
repository: Repository
|
||||
files: ReadonlyMap<RelativePath, TreeID>
|
||||
}) =>
|
||||
const restore = Effect.fn("Git.tree.restore")(
|
||||
(input: { repository: Repository; files: ReadonlyMap<RelativePath, TreeID> }) =>
|
||||
locked(
|
||||
input.repository,
|
||||
Effect.forEach(
|
||||
@@ -704,9 +699,7 @@ export const layer = Layer.effect(
|
||||
yield* repositoryOperation("restore", input.repository, ["checkout", tree, "--", file])
|
||||
return
|
||||
}
|
||||
yield* fs
|
||||
.remove(path.join(input.repository.worktree, file), { recursive: true, force: true })
|
||||
.pipe(
|
||||
yield* fs.remove(path.join(input.repository.worktree, file), { recursive: true, force: true }).pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new OperationError({
|
||||
@@ -733,10 +726,7 @@ export const layer = Layer.effect(
|
||||
),
|
||||
)
|
||||
|
||||
const capture = Effect.fn("Git.change.capture")(function* (input: {
|
||||
repository: Repository
|
||||
path: AbsolutePath
|
||||
}) {
|
||||
const capture = Effect.fn("Git.change.capture")(function* (input: { repository: Repository; path: AbsolutePath }) {
|
||||
const scope = path.relative(input.repository.worktree, input.path).replaceAll("\\", "/") || "."
|
||||
const tracked = yield* execute(
|
||||
input.repository.worktree,
|
||||
@@ -811,8 +801,7 @@ export const layer = Layer.effect(
|
||||
)
|
||||
.pipe(
|
||||
Effect.mapError(
|
||||
(cause) =>
|
||||
new PatchError({ operation: "apply", directory: input.path, message: cause.message, cause }),
|
||||
(cause) => new PatchError({ operation: "apply", directory: input.path, message: cause.message, cause }),
|
||||
),
|
||||
)
|
||||
if (result.exitCode === 0) return
|
||||
@@ -831,9 +820,10 @@ export const layer = Layer.effect(
|
||||
untracked: "preserve" | "remove"
|
||||
}) {
|
||||
const scope = path.relative(input.repository.worktree, input.path).replaceAll("\\", "/") || "."
|
||||
const restore = yield* execute(input.repository.worktree, proc)(
|
||||
input.index === "reset" ? ["checkout", "HEAD", "--", scope] : ["checkout", "--", scope],
|
||||
).pipe(
|
||||
const restore = yield* execute(
|
||||
input.repository.worktree,
|
||||
proc,
|
||||
)(input.index === "reset" ? ["checkout", "HEAD", "--", scope] : ["checkout", "--", scope]).pipe(
|
||||
Effect.mapError(
|
||||
(cause) => new PatchError({ operation: "reset", directory: input.path, message: cause.message, cause }),
|
||||
),
|
||||
@@ -846,7 +836,10 @@ export const layer = Layer.effect(
|
||||
})
|
||||
}
|
||||
if (input.untracked === "preserve") return
|
||||
const clean = yield* execute(input.repository.worktree, proc)(["clean", "-fd", "--", scope]).pipe(
|
||||
const clean = yield* execute(
|
||||
input.repository.worktree,
|
||||
proc,
|
||||
)(["clean", "-fd", "--", scope]).pipe(
|
||||
Effect.mapError(
|
||||
(cause) => new PatchError({ operation: "reset", directory: input.path, message: cause.message, cause }),
|
||||
),
|
||||
@@ -937,7 +930,15 @@ export const layer = Layer.effect(
|
||||
change: { capture, apply, discard },
|
||||
worktree: { create: worktreeCreate, remove: worktreeRemove, list: worktreeList },
|
||||
index: { refresh, ignored },
|
||||
tree: { capture: captureTree, write: writeTree, files: treeFiles, diff: treeDiff, preview, restore, checkout: checkoutTree },
|
||||
tree: {
|
||||
capture: captureTree,
|
||||
write: writeTree,
|
||||
files: treeFiles,
|
||||
diff: treeDiff,
|
||||
preview,
|
||||
restore,
|
||||
checkout: checkoutTree,
|
||||
},
|
||||
})
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -169,7 +169,8 @@ export const layer: Layer.Layer<Service, never, FSUtil.Service | Git.Service | E
|
||||
}
|
||||
|
||||
if (status === "refreshed") {
|
||||
if (!existing) return yield* new FetchFailedError({ repository, message: "Repository is unavailable" })
|
||||
if (!existing)
|
||||
return yield* new FetchFailedError({ repository, message: "Repository is unavailable" })
|
||||
yield* git.sync
|
||||
.fetchRemotes(existing)
|
||||
.pipe(Effect.mapError((error) => new FetchFailedError({ repository, message: error.message })))
|
||||
|
||||
@@ -172,7 +172,8 @@ export class Service extends Context.Service<Service, Interface>()("@opencode/v2
|
||||
|
||||
export const layer = Layer.unwrap(
|
||||
Effect.promise(() => import("./location-layer")).pipe(
|
||||
Effect.map(({ LocationServiceMap }) => Layer.effect(
|
||||
Effect.map(({ LocationServiceMap }) =>
|
||||
Layer.effect(
|
||||
Service,
|
||||
Effect.gen(function* () {
|
||||
const database = yield* Database.Service
|
||||
@@ -302,7 +303,10 @@ export const layer = Layer.unwrap(
|
||||
.select({ seq: SessionMessageTable.seq })
|
||||
.from(SessionMessageTable)
|
||||
.where(
|
||||
and(eq(SessionMessageTable.session_id, input.sessionID), eq(SessionMessageTable.id, input.cursor.id)),
|
||||
and(
|
||||
eq(SessionMessageTable.session_id, input.sessionID),
|
||||
eq(SessionMessageTable.id, input.cursor.id),
|
||||
),
|
||||
)
|
||||
.get()
|
||||
.pipe(Effect.orDie)
|
||||
@@ -436,7 +440,9 @@ export const layer = Layer.unwrap(
|
||||
)
|
||||
|
||||
export const defaultLayer = layer.pipe(
|
||||
Layer.provide(Layer.unwrap(Effect.promise(() => import("./location-layer")).pipe(Effect.map((m) => m.LocationServiceMap.layer)))),
|
||||
Layer.provide(
|
||||
Layer.unwrap(Effect.promise(() => import("./location-layer")).pipe(Effect.map((m) => m.LocationServiceMap.layer))),
|
||||
),
|
||||
Layer.provide(SessionExecution.noopLayer),
|
||||
Layer.provide(SessionStore.defaultLayer),
|
||||
Layer.provide(SessionProjector.defaultLayer),
|
||||
|
||||
@@ -40,9 +40,7 @@ export function fromRow(row: typeof SessionTable.$inferSelect): SessionSchema.In
|
||||
workspaceID: row.workspace_id ? WorkspaceV2.ID.make(row.workspace_id) : undefined,
|
||||
}),
|
||||
subpath: row.path ? RelativePath.make(row.path) : undefined,
|
||||
revert: row.revert
|
||||
? { ...row.revert, messageID: SessionMessageID.ID.make(row.revert.messageID) }
|
||||
: undefined,
|
||||
revert: row.revert ? { ...row.revert, messageID: SessionMessageID.ID.make(row.revert.messageID) } : undefined,
|
||||
time: {
|
||||
created: DateTime.makeUnsafe(row.time_created),
|
||||
updated: DateTime.makeUnsafe(row.time_updated),
|
||||
|
||||
@@ -418,13 +418,38 @@ export const layer = Layer.effectDiscard(
|
||||
const boundary = yield* db
|
||||
.select({ seq: SessionMessageTable.seq })
|
||||
.from(SessionMessageTable)
|
||||
.where(and(eq(SessionMessageTable.session_id, event.data.sessionID), eq(SessionMessageTable.id, event.data.messageID)))
|
||||
.where(
|
||||
and(
|
||||
eq(SessionMessageTable.session_id, event.data.sessionID),
|
||||
eq(SessionMessageTable.id, event.data.messageID),
|
||||
),
|
||||
)
|
||||
.get()
|
||||
.pipe(Effect.orDie)
|
||||
if (!boundary) return yield* Effect.die(`Revert boundary message not found: ${event.data.messageID}`)
|
||||
yield* db.delete(SessionMessageTable).where(and(eq(SessionMessageTable.session_id, event.data.sessionID), gt(SessionMessageTable.seq, boundary.seq))).run().pipe(Effect.orDie)
|
||||
yield* db.delete(SessionInputTable).where(and(eq(SessionInputTable.session_id, event.data.sessionID), or(gt(SessionInputTable.admitted_seq, boundary.seq), gt(SessionInputTable.promoted_seq, boundary.seq)))).run().pipe(Effect.orDie)
|
||||
yield* db.update(SessionTable).set({ revert: null, time_updated: DateTime.toEpochMillis(event.data.timestamp) }).where(eq(SessionTable.id, event.data.sessionID)).run().pipe(Effect.orDie)
|
||||
yield* db
|
||||
.delete(SessionMessageTable)
|
||||
.where(
|
||||
and(eq(SessionMessageTable.session_id, event.data.sessionID), gt(SessionMessageTable.seq, boundary.seq)),
|
||||
)
|
||||
.run()
|
||||
.pipe(Effect.orDie)
|
||||
yield* db
|
||||
.delete(SessionInputTable)
|
||||
.where(
|
||||
and(
|
||||
eq(SessionInputTable.session_id, event.data.sessionID),
|
||||
or(gt(SessionInputTable.admitted_seq, boundary.seq), gt(SessionInputTable.promoted_seq, boundary.seq)),
|
||||
),
|
||||
)
|
||||
.run()
|
||||
.pipe(Effect.orDie)
|
||||
yield* db
|
||||
.update(SessionTable)
|
||||
.set({ revert: null, time_updated: DateTime.toEpochMillis(event.data.timestamp) })
|
||||
.where(eq(SessionTable.id, event.data.sessionID))
|
||||
.run()
|
||||
.pipe(Effect.orDie)
|
||||
yield* SessionContextEpoch.reset(db, event.data.sessionID)
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -66,7 +66,7 @@ export const stage = Effect.fn("SessionRevert.stage")(function* (input: {
|
||||
const events = yield* EventV2.Service
|
||||
const original = input.session.revert?.snapshot
|
||||
? Snapshot.ID.make(input.session.revert.snapshot)
|
||||
: (yield* snapshot.capture())
|
||||
: yield* snapshot.capture()
|
||||
const next = yield* plan({ sessionID: input.session.id, messageID: input.messageID })
|
||||
const restore = new Map<RelativePath, Snapshot.ID>()
|
||||
if (original) {
|
||||
@@ -81,7 +81,10 @@ export const stage = Effect.fn("SessionRevert.stage")(function* (input: {
|
||||
const revert = {
|
||||
messageID: input.messageID,
|
||||
snapshot: original,
|
||||
diff: files.map((file) => file.patch).join("").trim(),
|
||||
diff: files
|
||||
.map((file) => file.patch)
|
||||
.join("")
|
||||
.trim(),
|
||||
files,
|
||||
} satisfies SessionSchema.Info["revert"]
|
||||
yield* events.publish(SessionEvent.RevertEvent.Staged, {
|
||||
|
||||
@@ -309,10 +309,14 @@ export const layer = Layer.effect(
|
||||
const stepSettlement = publisher.stepSettlement()
|
||||
if (stepSettlement && !publisher.hasProviderError()) {
|
||||
const endSnapshot = yield* snapshots.capture()
|
||||
const files = startSnapshot && endSnapshot
|
||||
? yield* snapshots.files({ from: startSnapshot, to: endSnapshot }).pipe(Effect.catch(() => Effect.succeed(undefined)))
|
||||
const files =
|
||||
startSnapshot && endSnapshot
|
||||
? yield* snapshots
|
||||
.files({ from: startSnapshot, to: endSnapshot })
|
||||
.pipe(Effect.catch(() => Effect.succeed(undefined)))
|
||||
: undefined
|
||||
yield* withPublication(events.publish(SessionEvent.Step.Ended, {
|
||||
yield* withPublication(
|
||||
events.publish(SessionEvent.Step.Ended, {
|
||||
sessionID: session.id,
|
||||
timestamp: yield* DateTime.now,
|
||||
assistantMessageID: yield* publisher.startAssistant(),
|
||||
@@ -321,7 +325,8 @@ export const layer = Layer.effect(
|
||||
tokens: stepSettlement.tokens,
|
||||
snapshot: endSnapshot,
|
||||
files,
|
||||
}))
|
||||
}),
|
||||
)
|
||||
}
|
||||
if (publisher.hasProviderError())
|
||||
yield* withPublication(publisher.failUnsettledTools("Tool execution interrupted"))
|
||||
|
||||
@@ -111,11 +111,13 @@ export const layer = Layer.effect(
|
||||
gitDirectory,
|
||||
commonDirectory: gitDirectory,
|
||||
})
|
||||
return yield* git.repo.create({
|
||||
return yield* git.repo
|
||||
.create({
|
||||
worktree,
|
||||
gitDirectory,
|
||||
seed: source,
|
||||
}).pipe(Effect.mapError((cause) => failure("capture", cause)))
|
||||
})
|
||||
.pipe(Effect.mapError((cause) => failure("capture", cause)))
|
||||
})
|
||||
|
||||
const enabled = Effect.fnUntraced(function* () {
|
||||
@@ -136,9 +138,7 @@ export const layer = Layer.effect(
|
||||
}),
|
||||
)
|
||||
}).pipe(
|
||||
Effect.catch((cause) =>
|
||||
Effect.logWarning("failed to capture snapshot", { cause }).pipe(Effect.as(undefined)),
|
||||
),
|
||||
Effect.catch((cause) => Effect.logWarning("failed to capture snapshot", { cause }).pipe(Effect.as(undefined))),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -189,12 +189,14 @@ export const layer = Layer.effect(
|
||||
if (!(yield* enabled())) return yield* new Error({ operation: "preview", message: "Snapshots are disabled" })
|
||||
const repo = yield* repository().pipe(Effect.mapError((cause) => failure("preview", cause)))
|
||||
const files = yield* plan("preview", input)
|
||||
const current = yield* git.tree.capture({
|
||||
const current = yield* git.tree
|
||||
.capture({
|
||||
repository: repo,
|
||||
scopes: Array.from(files.keys()),
|
||||
ignores: source,
|
||||
maximumUntrackedFileBytes: 2 * 1024 * 1024,
|
||||
}).pipe(Effect.mapError((cause) => failure("preview", cause)))
|
||||
})
|
||||
.pipe(Effect.mapError((cause) => failure("preview", cause)))
|
||||
return yield* git.tree
|
||||
.preview({
|
||||
repository: repo,
|
||||
|
||||
@@ -46,18 +46,52 @@ describe("SessionProjector", () => {
|
||||
it.effect("projects staged, cleared, and committed reverts", () =>
|
||||
Effect.gen(function* () {
|
||||
const db = (yield* Database.Service).db
|
||||
yield* db.insert(ProjectTable).values({ id: Project.ID.global, worktree: AbsolutePath.make("/project"), sandboxes: [] }).run()
|
||||
yield* db.insert(SessionTable).values({ id: sessionID, project_id: Project.ID.global, slug: "test", directory: "/project", title: "test", version: "test" }).run()
|
||||
yield* db
|
||||
.insert(ProjectTable)
|
||||
.values({ id: Project.ID.global, worktree: AbsolutePath.make("/project"), sandboxes: [] })
|
||||
.run()
|
||||
yield* db
|
||||
.insert(SessionTable)
|
||||
.values({
|
||||
id: sessionID,
|
||||
project_id: Project.ID.global,
|
||||
slug: "test",
|
||||
directory: "/project",
|
||||
title: "test",
|
||||
version: "test",
|
||||
})
|
||||
.run()
|
||||
const boundary = SessionMessage.ID.make("msg_boundary")
|
||||
yield* db.insert(SessionMessageTable).values([assistantRow(boundary, 1), assistantRow(SessionMessage.ID.make("msg_later"), 2)]).run()
|
||||
yield* db
|
||||
.insert(SessionMessageTable)
|
||||
.values([assistantRow(boundary, 1), assistantRow(SessionMessage.ID.make("msg_later"), 2)])
|
||||
.run()
|
||||
const events = yield* EventV2.Service
|
||||
yield* events.publish(SessionEvent.RevertEvent.Staged, { sessionID, timestamp: DateTime.makeUnsafe(1), revert: { messageID: boundary, snapshot: Snapshot.ID.make("tree"), diff: "patch", files: [] } })
|
||||
expect((yield* db.select({ revert: SessionTable.revert }).from(SessionTable).get())?.revert).toMatchObject({ messageID: boundary, snapshot: "tree", files: [] })
|
||||
yield* events.publish(SessionEvent.RevertEvent.Staged, {
|
||||
sessionID,
|
||||
timestamp: DateTime.makeUnsafe(1),
|
||||
revert: { messageID: boundary, snapshot: Snapshot.ID.make("tree"), diff: "patch", files: [] },
|
||||
})
|
||||
expect((yield* db.select({ revert: SessionTable.revert }).from(SessionTable).get())?.revert).toMatchObject({
|
||||
messageID: boundary,
|
||||
snapshot: "tree",
|
||||
files: [],
|
||||
})
|
||||
yield* events.publish(SessionEvent.RevertEvent.Cleared, { sessionID, timestamp: DateTime.makeUnsafe(2) })
|
||||
expect((yield* db.select({ revert: SessionTable.revert }).from(SessionTable).get())?.revert).toBeNull()
|
||||
yield* events.publish(SessionEvent.RevertEvent.Staged, { sessionID, timestamp: DateTime.makeUnsafe(3), revert: { messageID: boundary, files: [] } })
|
||||
yield* events.publish(SessionEvent.RevertEvent.Committed, { sessionID, messageID: boundary, timestamp: DateTime.makeUnsafe(4) })
|
||||
expect((yield* db.select({ id: SessionMessageTable.id }).from(SessionMessageTable).all()).map((row) => row.id)).toEqual([boundary])
|
||||
yield* events.publish(SessionEvent.RevertEvent.Staged, {
|
||||
sessionID,
|
||||
timestamp: DateTime.makeUnsafe(3),
|
||||
revert: { messageID: boundary, files: [] },
|
||||
})
|
||||
yield* events.publish(SessionEvent.RevertEvent.Committed, {
|
||||
sessionID,
|
||||
messageID: boundary,
|
||||
timestamp: DateTime.makeUnsafe(4),
|
||||
})
|
||||
expect(
|
||||
(yield* db.select({ id: SessionMessageTable.id }).from(SessionMessageTable).all()).map((row) => row.id),
|
||||
).toEqual([boundary])
|
||||
}),
|
||||
)
|
||||
|
||||
|
||||
@@ -123,8 +123,12 @@ describe("Snapshot", () => {
|
||||
),
|
||||
),
|
||||
)
|
||||
expect(yield* Effect.promise(() => fs.stat(path.join(tmp.path, "snapshot", projectID, Hash.fast(project))))).toBeDefined()
|
||||
expect(yield* Effect.promise(() => fs.stat(path.join(tmp.path, "snapshot", projectID, Hash.fast(linked))))).toBeDefined()
|
||||
expect(
|
||||
yield* Effect.promise(() => fs.stat(path.join(tmp.path, "snapshot", projectID, Hash.fast(project)))),
|
||||
).toBeDefined()
|
||||
expect(
|
||||
yield* Effect.promise(() => fs.stat(path.join(tmp.path, "snapshot", projectID, Hash.fast(linked)))),
|
||||
).toBeDefined()
|
||||
}),
|
||||
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
|
||||
),
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -58,7 +58,11 @@ export const MessageHandler = HttpApiBuilder.group(Api, "server.message", (handl
|
||||
const ref = `err_${crypto.randomUUID().slice(0, 8)}`
|
||||
return Effect.logError("failed to decode session message").pipe(
|
||||
Effect.annotateLogs({ ref, sessionID: error.sessionID, messageID: error.messageID }),
|
||||
Effect.andThen(Effect.fail(new UnknownError({ message: "Unexpected server error. Check server logs for details.", ref }))),
|
||||
Effect.andThen(
|
||||
Effect.fail(
|
||||
new UnknownError({ message: "Unexpected server error. Check server logs for details.", ref }),
|
||||
),
|
||||
),
|
||||
)
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -307,7 +307,11 @@ export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handl
|
||||
const ref = `err_${crypto.randomUUID().slice(0, 8)}`
|
||||
return Effect.logError("failed to decode session message").pipe(
|
||||
Effect.annotateLogs({ ref, sessionID: error.sessionID, messageID: error.messageID }),
|
||||
Effect.andThen(Effect.fail(new UnknownError({ message: "Unexpected server error. Check server logs for details.", ref }))),
|
||||
Effect.andThen(
|
||||
Effect.fail(
|
||||
new UnknownError({ message: "Unexpected server error. Check server logs for details.", ref }),
|
||||
),
|
||||
),
|
||||
)
|
||||
}),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user