fix(coderd/database): prevent AcquireProvisionerJob from grabbing canceled jobs by mafredri · Pull Request #21852 · coder/coder

@mafredri

…celed jobs

The AcquireProvisionerJob query only checked started_at IS NULL, allowing
it to acquire jobs that were canceled while pending (which have
completed_at set but started_at still NULL).

Added completed_at IS NULL check to the query to prevent this.

Also fixed JobCompleteBuilder.Do() in dbfake to set started_at when
completing jobs, ensuring test provisioner daemons don't attempt to
acquire already-completed fake jobs.

Fixes coder/internal#1323

deansheather

@mafredri

Adds a test case to TestAcquireProvisionerJob that verifies the query
correctly skips jobs that were canceled while pending (started_at is NULL
but completed_at is set).

deansheather