Skip to content

chore: integrate coder/quartz - #175

Merged
johnstcn merged 5 commits into
mainfrom
cj/quartz
Jan 27, 2026
Merged

chore: integrate coder/quartz#175
johnstcn merged 5 commits into
mainfrom
cj/quartz

Conversation

@johnstcn

@johnstcnjohnstcn commented Jan 26, 2026

Copy link
Copy Markdown
Member

Refactors existing usage of time.Sleep etc. to use github.com/coder/quartz.

🤖 Written by Claude Opus 4.5, reviewed by me.

@github-actions

Copy link
Copy Markdown

✅ Preview binaries are ready!

To test with modules: agentapi_version = "agentapi_175" or download from: https://github.com/coder/agentapi/releases/tag/agentapi_175

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request integrates the coder/quartz library to provide a clock abstraction throughout the codebase, enabling better testability by allowing time-dependent code to use mock clocks in tests.

Changes:

  • Added github.com/coder/quartz dependency to replace direct time package usage
  • Replaced time.Now(), time.Sleep(), time.After(), and time.Since() calls with clock-based equivalents
  • Updated test files to use quartz.NewMock(t) for deterministic time-based testing

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
FileDescription
go.modAdded github.com/coder/quartz v0.1.2 dependency and removed unused go.uber.org/atomic
go.sumUpdated dependency checksums including quartz and transitive dependencies
lib/util/util.goAdded Clock field to WaitTimeout struct and replaced time operations with clock-based equivalents
lib/termexec/termexec.goAdded clock field to Process struct and replaced time operations with clock methods
lib/screentracker/conversation.goReplaced GetTime function with Clock field and updated all time operations to use the clock
lib/screentracker/conversation_test.goUpdated tests to use mock clocks for deterministic testing
lib/httpapi/server.goAdded clock field to Server struct and updated ticker usage in snapshot loop

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadlib/termexec/termexec.go Outdated
Comment threadlib/screentracker/conversation.go Outdated
Comment threadlib/screentracker/conversation.go Outdated
Comment threadlib/termexec/termexec.go Outdated
@johnstcn
johnstcn marked this pull request as ready for review January 26, 2026 18:26
@johnstcn
johnstcn requested a review from CopilotJanuary 26, 2026 18:27

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadlib/termexec/termexec.go Outdated
Comment threadlib/httpapi/server.go
Comment threadlib/screentracker/conversation.go Outdated
Comment threadlib/screentracker/conversation.go Outdated
Comment threadlib/screentracker/conversation.go Outdated
time.Sleep(1 * time.Second)
timer := c.cfg.Clock.NewTimer(1 * time.Second)
defer timer.Stop()
<-timer.C

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggestion: Maybe this could be a little helper? Say, sleep(clock, time.Second)? Seems re-usable (at least below) and clarifies the code.

Might be a useful addition to quartz. Having <-clock.After(time.Second) would also be nice.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Comment threadlib/util/util.go
Comment threadlib/util/util.go
return nil
}
time.Sleep(interval)
sleepTimer := clock.NewTimer(interval)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggestion: Consider wrapping in if err := func() error { ... } so you can defer stop to avoid stopping on each case.

Alternatively, perhaps a helper function that contains the select since at least 2 are identical.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Addressed in d211695

@johnstcn
johnstcn merged commit 2ab7a0b into mainJan 27, 2026
3 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@johnstcn@mafredri@35C4n0r