test(backend): make task-history tests fail when the history is actually wrong (#2848)

Co-authored-by: nova28 <17953305+nova28@users.noreply.github.com>
Co-authored-by: Carlos Florencio <carlosmflorencio@gmail.com>
This commit is contained in:
nova28
2026-08-21 01:15:06 +08:00
committed by GitHub
parent d5039f89c0
commit e9bbb912b8
13 changed files with 1230 additions and 54 deletions
@@ -0,0 +1,15 @@
package pinfixtures
// Shape (a): a package-level const holding the mutating SQL, referenced by
// identifier in the function body. The naive detector only inspects
// *ast.BasicLit nodes found directly inside a function body, so a literal
// hoisted to a const and referenced by name puts zero matching BasicLit
// nodes there — this function is invisible to it.
const updateStepSQL = "UPDATE tasks SET workflow_step_id = ? WHERE id = ?"
type FixtureRepo struct{}
func (r *FixtureRepo) constHoistedStepMutator(id, step string) error {
_, err := r.exec(updateStepSQL, step, id)
return err
}
@@ -0,0 +1,20 @@
package pinfixtures
// Shape (c): two distinct receiver types define a method with the same bare
// name. A detector keyed on fn.Name.Name alone collapses RepoA.updateTaskTx
// and RepoB.updateTaskTx into a single "updateTaskTx" entry — if one of them
// were already registered (as the real package's *Repository.updateTaskTx
// is), the other's genuinely distinct mutator would be silently absorbed
// and reported clean.
type RepoA struct{}
type RepoB struct{}
func (r *RepoA) updateTaskTx(step, id string) error {
_, err := r.exec("UPDATE tasks SET workflow_step_id = ? WHERE id = ?", step, id)
return err
}
func (r *RepoB) updateTaskTx(step, id string) error {
_, err := r.exec("UPDATE tasks SET workflow_step_id = ? WHERE id = ?", step, id)
return err
}
@@ -0,0 +1,11 @@
package pinfixtures
// Shape (d): a step writer placed in a subdirectory of the scanned package.
// os.ReadDir(dir) is non-recursive, so this file is invisible unless the
// scan walks into nested directories.
type NestedRepo struct{}
func (r *NestedRepo) deeplyNestedStepMutator(step, id string) error {
_, err := r.exec("UPDATE tasks SET workflow_step_id = ? WHERE id = ?", step, id)
return err
}
@@ -0,0 +1,21 @@
package pinfixtures
import "fmt"
// Shape (b): the column name is interpolated via fmt.Sprintf, mirroring the
// live taskScalarColumns/execTaskScalar allowlist pattern in
// internal/office/repository/sqlite/tasks.go. Neither function alone
// contains the literal string "workflow_step_id" adjacent to "UPDATE
// tasks"/"SET" the way the naive detector's substring check requires: the
// SQL shape lives in execScalarColumn, and the mutating column name is only
// ever a plain string argument at the call site in
// sprintfInterpolatedStepMutator.
func (r *FixtureRepo) execScalarColumn(column, value, id string) error {
query := fmt.Sprintf("UPDATE tasks SET %s = ?, updated_at = ? WHERE id = ?", column)
_, err := r.exec(query, value, id)
return err
}
func (r *FixtureRepo) sprintfInterpolatedStepMutator(id, step string) error {
return r.execScalarColumn("workflow_step_id", step, id)
}