8000 feat(fix): pick findings and open a fix session on them by dominikwozniak · Pull Request #33 · dominikwozniak/dw-mc · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CONTEXT.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,8 @@ When a review run is repeated on a pull request that has already had one: only w
_Avoid_: cache, debounce

**Fix session**:
An interactive agent session mission control opens for me in a fresh worktree, carrying the findings I selected and my notes on them. It is never the review run that produced the findings; the re-review of its result is a new review run.
An interactive agent session mission control opens for me in a fresh worktree, carrying the findings I selected and my notes on them. The worktree stands on a branch of the tool's own that tracks the pull request's, and it outlives the session, because what I commit in it is mine. It is never the review run that produced the findings; the re-review of its result is a new review run.
_Avoid_: auto-fix, repair run

**Note**:
What I say about a finding when I pick it for a fix session. It is my word on the finding and outranks what the review run said about it.
55 changes: 29 additions & 26 deletions docs/v1-design.md

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/adapters/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ describe("settingsFor", () => {
path_instructions: [{ path: "src/**", instructions: "Read the seams first" }]
},
ci: { ignore: ["advisory"], flaky_patterns: ["ECONNRESET"] },
fix: { commits: true },
rebase: { enabled: true },
stamp: { blocks_on: "info" }
}
Expand All @@ -246,12 +247,14 @@ describe("merge", () => {
base: "develop",
review: { effort: "low", docs_only: ["**/*.md"] },
ci: { ignore: ["advisory"] },
fix: { commits: false },
rebase: { enabled: false },
stamp: { blocks_on: "error" }
}
const delta: SettingsPatch = {
review: { effort: "high" },
ci: { flaky_patterns: ["ECONNRESET"] },
fix: { commits: true },
rebase: { enabled: true },
stamp: { blocks_on: "warning" }
}
Expand All @@ -260,6 +263,7 @@ describe("merge", () => {
base: "develop",
review: { effort: "high", docs_only: ["**/*.md"] },
ci: { ignore: ["advisory"], flaky_patterns: ["ECONNRESET"] },
fix: { commits: true },
rebase: { enabled: true },
stamp: { blocks_on: "warning" }
})
Expand Down
12 changes: 12 additions & 0 deletions src/adapters/config.ts
< 8BD0 td class="blob-num blob-num-addition empty-cell">
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ const SettingsPatch = Schema.Struct({
flaky_patterns: Schema.optionalKey(Schema.Array(Schema.String))
})
),
fix: Schema.optionalKey(
Schema.Struct({
commits: Schema.optionalKey(Schema.Boolean)
})
),
rebase: Schema.optionalKey(
Schema.Struct({
enabled: Schema.optionalKey(Schema.Boolean)
Expand Down Expand Up @@ -79,6 +84,7 @@ export interface Settings {
8000 readonly base: string | null
readonly review: Section<"review">
readonly ci: Section<"ci">
readonly fix: Section<"fix">
readonly rebase: Section<"rebase">
readonly stamp: Section<"stamp">
}
Expand All @@ -95,6 +101,7 @@ export const builtIn: Settings = {
path_instructions: []
},
ci: { ignore: [], flaky_patterns: [] },
fix: { commits: false },
rebase: { enabled: false },
stamp: { blocks_on: "error" }
}
Expand Down Expand Up @@ -123,6 +130,7 @@ const apply = (settings: Settings, patch: SettingsPatch | undefined): Settings =
ignore: over(patch.ci?.ignore, settings.ci.ignore),
flaky_patterns: over(patch.ci?.flaky_patterns, settings.ci.flaky_patterns)
},
fix: { commits: over(patch.fix?.commits, settings.fix.commits) },
rebase: { enabled: over(patch.rebase?.enabled, settings.rebase.enabled) },
stamp: { blocks_on: over(patch.stamp?.blocks_on, settings.stamp.blocks_on) }
}
Expand All @@ -141,6 +149,9 @@ export const merge = (patch: SettingsPatch, delta: SettingsPatch): SettingsPatch
if (patch.ci !== undefined && delta.ci !== undefined) {
merged.ci = { ...patch.ci, ...delta.ci }
}
if (patch.fix !== undefined && delta.fix !== undefined) {
merged.fix = { ...patch.fix, ...delta.fix }
}
if (patch.rebase !== undefined && delta.rebase !== undefined) {
merged.rebase = { ...patch.rebase, ...delta.rebase }
}
Expand Down Expand Up @@ -304,6 +315,7 @@ const settingsDocument = (patch: SettingsPatch): Value =>
["flaky_patterns", patch.ci.flaky_patterns]
])
],
["fix", patch.fix === undefined ? undefined : mapping([["commits", patch.fix.commits]])],
["rebase", patch.rebase === undefined ? undefined : mapping([["enabled", patch.rebase.enabled]])],
["stamp", patch.stamp === undefined ? undefined : mapping([["blocks_on", patch.stamp.blocks_on]])]
])
Expand Down
3 changes: 2 additions & 1 deletion src/adapters/gh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,15 @@ const PrView = Schema.fromJsonString(
url: Schema.String,
isDraft: Schema.Boolean,
headRefOid: Schema.String,
headRefName: Schema.String,
mergeable: Schema.String,
reviewDecision: Schema.String,
statusCheckRollup: Schema.NullOr(Schema.Array(CheckEntry))
})
)
export type PrView = typeof PrView.Type

const viewFields = "number,title,url,isDraft,headRefOid,mergeable,reviewDecision,statusCheckRollup"
const viewFields = "number,title,url,isDraft,headRefOid,headRefName,mergeable,reviewDecision,statusCheckRollup"

/**
* Everything about one pull request that arrives without paging through it:
Expand Down
132 changes: 131 additions & 1 deletion src/adapters/git.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { assert, describe, it } from "@effect/vitest"
import { ConfigProvider, Effect, Layer, Path } from "effect"

import { withWorktree } from "#adapters/git.ts"
import { fixWorktree, withWorktree } from "#adapters/git.ts"
import { fakeHandle, layerFake } from "#adapters/spawner.ts"

const state = "/home/dw/.local/state/dw-mc"
const clone = `${state}/repos/dominikwozniak/dw-mc.git`
const worktree = `${state}/worktrees/dominikwozniak/dw-mc/28`
const fix = `${state}/fixes/dominikwozniak/dw-mc/28`
const head = "284d599022a55d4dcae74b31b9a49a0f50061014"
const fetched = `-C ${clone} fetch --no-tags --force origin +refs/pull/28/head:refs/dw-mc/pr/28 +refs/heads/*:refs/heads/*`

Expand All @@ -23,6 +24,13 @@ const git = (options: {
readonly cloned?: boolean | undefined
/** The vector that refuses, and what `git` says on stderr instead. */
readonly refuses?: { readonly argv: string; readonly detail: string } | undefined
/** The worktrees the clone already knows about. */
readonly worktrees?: ReadonlyArray<string> | undefined
/**
* How far the fix branch has gone past the head, where the clone has that
* branch at all. Left out, the branch is not there.
*/
readonly ahead?: number | undefined
}) =>
layerFake((command) => {
if (command._tag !== "StandardCommand") {
Expand All @@ -42,6 +50,18 @@ const git = (options: {
if (argv === `-C ${clone} rev-parse refs/dw-mc/pr/28`) {
return Effect.succeed(fakeHandle({ stdout: `${head}\n` }))
}
if (argv === `-C ${clone} rev-parse --verify --quiet refs/heads/dw-mc/fix/28`) {
return options.ahead === undefined
? Effect.succeed(fakeHandle({ exitCode: 1 }))
: Effect.succeed(fakeHandle({ stdout: `${head}\n` }))
}
if (argv === `-C ${clone} rev-list --count refs/heads/dw-mc/fix/28 ^${head}`) {
return Effect.succeed(fakeHandle({ stdout: `${options.ahead ?? 0}\n` }))
}
if (argv === `-C ${clone} worktree list --porcelain`) {
const listed = (options.worktrees ?? []).map((directory) => `worktree ${directory}\nbare\n`)
return Effect.succeed(fakeHandle({ stdout: [`worktree ${clone}\nbare\n`, ...listed].join("\n") }))
}
return Effect.succeed(fakeHandle({}))
})

Expand Down Expand Up @@ -134,3 +154,113 @@ describe("the tool's own clone and its throwaway worktree", () => {
}).pipe(Effect.provide(machine(git({ spawned, cloned: true, refuses }))))
})
})

describe("the worktree a fix session opens in", () => {
it.effect("cuts it on a branch of the tool's own that tracks the pull request's", () => {
const spawned: Array<string> = []

return Effect.gen(function* () {
const cut = yield* fixWorktree("dominikwozniak/dw-mc", 28, "feat/28-a-branch")

assert.deepStrictEqual(cut, { directory: fix, head })
assert.deepStrictEqual(spawned, [
`git -C ${clone} rev-parse --is-bare-repository`,
`git ${fetched}`,
`git -C ${clone} rev-parse refs/dw-mc/pr/28`,
`git -C ${clone} rev-parse --verify --quiet refs/heads/dw-mc/fix/28`,
`git -C ${clone} worktree list --porcelain`,
`git -C ${clone} config extensions.worktreeConfig true`,
`git -C ${clone} config --worktree core.bare true`,
`git -C ${clone} config --unset core.bare`,
`git -C ${clone} worktree add -B dw-mc/fix/28 ${fix} ${head}`,
`git -C ${clone} config branch.dw-mc/fix/28.remote origin`,
`git -C ${clone} config branch.dw-mc/fix/28.merge refs/heads/feat/28-a-branch`,
`git -C ${fix} config --worktree push.default upstream`
])
}).pipe(Effect.provide(machine(git({ spawned, cloned: true }))))
})

it.effect("never stands on the pull request's own branch, which the next fetch would refuse", () => {
const spawned: Array<string> = []

return Effect.gen(function* () {
yield* fixWorktree("dominikwozniak/dw-mc", 28, "feat/28-a-branch")

// Verified by running it: `git` refuses to fetch into a branch a worktree
// has checked out, and this clone fetches every branch on every run.
const cut = spawned.find((vector) => vector.includes("worktree add"))
assert.include(cut, "-B dw-mc/fix/28")
assert.notInclude(cut, "feat/28-a-branch")
}).pipe(Effect.provide(machine(git({ spawned, cloned: true }))))
})

it.effect("keeps how a push behaves to the fix worktree, out of the clone every run shares", () => {
const spawned: Array<string> = []

return Effect.gen(function* () {
yield* fixWorktree("dominikwozniak/dw-mc", 28, "feat/28-a-branch")

assert.include(spawned, `git -C ${fix} config --worktree push.default upstream`)
assert.isFalse(spawned.some((vector) => vector === `git -C ${clone} config push.default upstream`))
}).pipe(Effect.provide(machine(git({ spawned, cloned: true }))))
})

it.effect("cuts the previous session's worktree away first, where it is finished with", () => {
const spawned: Array<string> = []

return Effect.gen(function* () {
yield* fixWorktree("dominikwozniak/dw-mc", 28, "feat/28-a-branch")

assert.include(spawned, `git -C ${clone} worktree remove ${fix}`)
assert.isFalse(spawned.some((vector) => vector.includes("worktree remove --force")))
}).pipe(Effect.provide(machine(git({ spawned, cloned: true, worktrees: [fix] }))))
})

it.effect("stops rather than throwing away changes a previous session left uncommitted", () => {
const spawned: Array<string> = []
const refuses = {
argv: `-C ${clone} worktree remove ${fix}`,
detail: `fatal: '${fix}' contains modified or untracked files, use --force to delete it\n`
}

return Effect.gen(function* () {
const error = yield* Effect.flip(fixWorktree("dominikwozniak/dw-mc", 28, "feat/28-a-branch"))

assert.strictEqual(error._tag, "GitFailed")
assert.include(error.message, "contains modified or untracked files")
assert.isFalse(spawned.some((vector) => vector.includes("worktree add")))
}).pipe(Effect.provide(machine(git({ spawned, cloned: true, worktrees: [fix], refuses }))))
})

it.effect("stops rather than resetting a branch over commits I have not pushed", () => {
const spawned: Array<string> = []

return Effect.gen(function* () {
const error = yield* Effect.flip(fixWorktree("dominikwozniak/dw-mc", 28, "feat/28-a-branch"))

if (error._tag !== "WorktreeHeld") {
return assert.fail(`expected a WorktreeHeld, got ${error._tag}`)
}
assert.include(error.message, "2 commits")
assert.include(error.message, fix)
assert.isFalse(spawned.some((vector) => vector.includes("worktree remove")))
assert.isFalse(spawned.some((vector) => vector.includes("worktree add")))
}).pipe(Effect.provide(machine(git({ spawned, cloned: true, worktrees: [fix], ahead: 2 }))))
})

it.effect("stops on those commits even where the worktree they were made in is gone", () => {
const spawned: Array<string> = []

return Effect.gen(function* () {
// The directory can be pruned or removed by hand; the branch that holds
// the commits stays, and `worktree add -B` would reset it to the head.
const error = yield* Effect.flip(fixWorktree("dominikwozniak/dw-mc", 28, "feat/28-a-branch"))

if (error._tag !== "WorktreeHeld") {
return assert.fail(`expected a WorktreeHeld, got ${error._tag}`)
}
assert.include(error.message, "2 commits")
assert.isFalse(spawned.some((vector) => vector.includes("worktree add")))
}).pipe(Effect.provide(machine(git({ spawned, cloned: true, worktrees: [], ahead: 2 }))))
})
})
Loading
0