Skip to content
Merged
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
64 changes: 52 additions & 12 deletions packages/core/test/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,51 +98,91 @@ describe("Snapshot", () => {
),
)

testEffect(Layer.empty).live("isolates snapshot indexes by canonical Git worktree", () =>
Effect.acquireUseRelease(
Effect.promise(() => tmpdir()),
testEffect(Layer.empty).live("isolates snapshot indexes by canonical Git worktree", () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Test relies on default 5-second timeout without explicit declaration

The first test explicitly sets a 30-second timeout (line 83: }, 30_000)). This test omits the timeout argument, relying on testEffect's default (5 seconds per PR description). Given the extensive Git operations (init, config, add, commit, worktree add), this may timeout on slow CI — which appears intentional for diagnostics, but the intent is not documented in the test signature.

Consider adding an explicit timeout (or Infinity to disable) with a comment explaining the diagnostic purpose.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

// Keep the default budget: the last start/done pair identifies the Windows
// timeout boundary, including native Git setup and scoped layer disposal.
const startedAt = Date.now()
const phase = (name: string) =>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Inconsistent phase function signature vs. first test

The first test (line 20-21) defines phase as returning Effect.sync(...) for yielding inside Effect.gen. This test defines phase as a plain function calling console.error directly, requiring Effect.sync(() => phase(...)) wrappers when used in Effect.gen (lines 145, 148, 150, 154, 160, 168, 169, 176) but direct calls in async callbacks (lines 109, 111, 119, 121, etc.).

This works but creates inconsistency. Consider adding a comment explaining why this test uses a plain function (to support direct calls in Effect.promise async callbacks where yield* is unavailable).


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

console.error(`[snapshot-worktree-test] phase=${name} elapsedMs=${Date.now() - startedAt}`)
return Effect.acquireUseRelease(
Effect.promise(async () => {
phase("tmpdir:start")
const tmp = await tmpdir()
phase("tmpdir:done")
return tmp
}),
(tmp) =>
Effect.gen(function* () {
const project = path.join(tmp.path, "project")
const linked = path.join(tmp.path, "linked")
yield* Effect.promise(async () => {
phase("files:start")
await fs.mkdir(project)
await fs.writeFile(path.join(project, "tracked.txt"), "main\n")
phase("files:done")
phase("git-init:start")
await $`git init`.cwd(project).quiet()
phase("git-init:done")
phase("git-config:start")
await $`git config core.fsmonitor false`.cwd(project).quiet()
await $`git config commit.gpgsign false`.cwd(project).quiet()
await $`git config user.email [email protected]`.cwd(project).quiet()
await $`git config user.name Test`.cwd(project).quiet()
phase("git-config:done")
phase("git-add:start")
await $`git add .`.cwd(project).quiet()
phase("git-add:done")
phase("git-commit:start")
await $`git commit -m initial`.cwd(project).quiet()
phase("git-commit:done")
phase("git-worktree:start")
await $`git worktree add --detach ${linked} HEAD`.cwd(project).quiet()
phase("git-worktree:done")
})

const capture = (directory: string) =>
const capture = (directory: string, name: string) =>
Effect.gen(function* () {
const snapshot = yield* Snapshot.Service
return yield* snapshot.capture()
}).pipe(Effect.provide(snapshotLayer(tmp.path, directory)))
expect(yield* capture(project)).toBeDefined()
expect(yield* capture(linked)).toBeDefined()
yield* Effect.sync(() => phase(`${name}-layer:start`))
const result = yield* Effect.gen(function* () {
const snapshot = yield* Snapshot.Service
yield* Effect.sync(() => phase(`${name}-capture:start`))
const captured = yield* snapshot.capture()
yield* Effect.sync(() => phase(`${name}-capture:done`))
return captured
}).pipe(Effect.provide(snapshotLayer(tmp.path, directory)))
// Effect.provide has closed the layer scope before this marker.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Comment on layer scope closure could be more explicit

The comment // Effect.provide has closed the layer scope before this marker is accurate but terse. For future maintainers, it may not be obvious why this matters for the diagnostic (the layer:done phase measures post-scope-overhead).

Suggest: // Effect.provide closes the layer scope when the inner effect completes; this marker runs after scope teardown.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

yield* Effect.sync(() => phase(`${name}-layer:done`))
return result
})
expect(yield* capture(project, "project")).toBeDefined()
expect(yield* capture(linked, "linked")).toBeDefined()

yield* Effect.sync(() => phase("project-id:start"))
const projectID = yield* Effect.gen(function* () {
return (yield* Location.Service).project.id
}).pipe(
Effect.provide(
AppNodeBuilder.build(Location.boundNode(Location.Ref.make({ directory: AbsolutePath.make(project) }))),
),
)
yield* Effect.sync(() => phase("project-id:done"))
yield* Effect.sync(() => phase("indexes:start"))
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()
yield* Effect.sync(() => phase("indexes:done"))
}),
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
),
)
(tmp) =>
Effect.promise(async () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Cleanup swallows potential disposal errors without logging

The release function uses Effect.promise(async () => { ... }) with direct phase() calls. If tmp[Symbol.asyncDispose]() rejects, the rejection becomes an Effect failure (correct), but no phase marker logs the failure before the test fails. The cleanup:done marker (line 182) only runs on success.

Consider wrapping the disposal in a try/catch to emit a cleanup:error phase marker before re-throwing, preserving diagnostic value on cleanup failures.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

phase("cleanup:start")
await tmp[Symbol.asyncDispose]()
phase("cleanup:done")
}),
)
})

testEffect(Layer.empty).live("checks out a legacy revert snapshot without removing unrelated files", () =>
Effect.acquireUseRelease(
Expand Down
Loading