Skip to content

Commit fab1188

Browse files
committed
fix(build-notes): withdraw any recorded evaluation when the baseline moves
1 parent 1a8045d commit fab1188

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎apps/sim/lib/build-notes/build-notes.integration.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,31 @@ check(
597597
}
598598
)
599599

600+
check('a new baseline withdraws a verdict recorded between a build and its baseline', async () => {
601+
const { workflowId, startId } = await seedWorkflow()
602+
await createNotes(workflowId)
603+
await writeNotes(workflowId, notesWith(functionBatch(startId, 'score')))
604+
expect((await evaluate(workflowId)).passed).toBe(true)
605+
const evaluatedOn = await notesRow(workflowId)
606+
// A late verdict lands while the recorded baseline is still the one it was evaluated against.
607+
expect(
608+
await recordBuildNotesEvaluation(
609+
evaluatedOn.id,
610+
{
611+
evaluatedNotesHash: evaluatedOn.evaluatedNotesHash ?? '',
612+
evaluatedOperationsHash: evaluatedOn.evaluatedOperationsHash ?? '',
613+
},
614+
{ baselineWorkflowUpdatedAt: evaluatedOn.baselineWorkflowUpdatedAt }
615+
)
616+
).toBe(true)
617+
await apply(person, workflowId, functionBatch(startId, 'committed'))
618+
await writeBaseline(evaluatedOn, await loadCurrentBaselineState(workflowId), {
619+
userId: ownerId,
620+
source: 'copilot',
621+
})
622+
expect((await notesRow(workflowId)).evaluatedNotesHash).toBeNull()
623+
})
624+
600625
check('notes created while their workflow is archived roll back with their files', async () => {
601626
const { workflowId } = await seedWorkflow()
602627
await archiveWorkflow(workflowId, { requestId: generateId(), notifySocket: false })

‎apps/sim/lib/build-notes/repository.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ export async function getLiveBuildNotesByFileId(
6868
/**
6969
* Records a baseline only if it is not older than the one recorded, so a rebase that read the
7070
* graph before a build committed cannot replace that build's baseline. False when it is older.
71+
* A new baseline also withdraws any recorded evaluation: it was reached against the previous one,
72+
* including a late verdict recorded after a build committed but before its baseline was saved.
7173
*/
7274
export async function setBuildNotesBaseline(
7375
notesId: string,
@@ -76,7 +78,12 @@ export async function setBuildNotesBaseline(
7678
): Promise<boolean> {
7779
const set = await executor
7880
.update(workflowBuildNotes)
79-
.set({ ...baseline, updatedAt: new Date() })
81+
.set({
82+
...baseline,
83+
evaluatedNotesHash: null,
84+
evaluatedOperationsHash: null,
85+
updatedAt: new Date(),
86+
})
8087
.where(
8188
and(
8289
eq(workflowBuildNotes.id, notesId),

0 commit comments

Comments
 (0)