Merge pull request #161 from Molecule-AI/fix/broken-update-tests-post-125

fix(tests): add EXISTS probe mock to 4 WorkspaceUpdate tests (post #125)
This commit is contained in:
Hongming Wang 2026-04-15 09:35:18 -07:00 committed by GitHub
commit bf4a0bc87d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

@ -115,6 +115,11 @@ func TestWorkspaceUpdate_ParentID(t *testing.T) {
broadcaster := newTestBroadcaster()
handler := NewWorkspaceHandler(broadcaster, nil, "http://localhost:8080", t.TempDir())
// #125 guard: handler now verifies the workspace exists before applying
// the UPDATE. Each PATCH test must mock the EXISTS probe first.
mock.ExpectQuery("SELECT EXISTS.*workspaces WHERE id").
WithArgs("ws-child").
WillReturnRows(sqlmock.NewRows([]string{"exists"}).AddRow(true))
mock.ExpectExec("UPDATE workspaces SET parent_id").
WithArgs("ws-child", "ws-parent").
WillReturnResult(sqlmock.NewResult(0, 1))
@ -144,6 +149,9 @@ func TestWorkspaceUpdate_NameOnly(t *testing.T) {
broadcaster := newTestBroadcaster()
handler := NewWorkspaceHandler(broadcaster, nil, "http://localhost:8080", t.TempDir())
mock.ExpectQuery("SELECT EXISTS.*workspaces WHERE id").
WithArgs("ws-rename").
WillReturnRows(sqlmock.NewRows([]string{"exists"}).AddRow(true))
mock.ExpectExec("UPDATE workspaces SET name").
WithArgs("ws-rename", "New Name").
WillReturnResult(sqlmock.NewResult(0, 1))

View File

@ -304,6 +304,10 @@ func TestWorkspaceUpdate_MultipleFields(t *testing.T) {
broadcaster := newTestBroadcaster()
handler := NewWorkspaceHandler(broadcaster, nil, "http://localhost:8080", t.TempDir())
// #125: existence probe fires once before any field update.
mock.ExpectQuery("SELECT EXISTS.*workspaces WHERE id").
WithArgs("ws-multi").
WillReturnRows(sqlmock.NewRows([]string{"exists"}).AddRow(true))
// Expect name, role, and tier updates
mock.ExpectExec("UPDATE workspaces SET name").
WithArgs("ws-multi", "Updated Agent").
@ -348,6 +352,9 @@ func TestWorkspaceUpdate_RuntimeField(t *testing.T) {
broadcaster := newTestBroadcaster()
handler := NewWorkspaceHandler(broadcaster, nil, "http://localhost:8080", t.TempDir())
mock.ExpectQuery("SELECT EXISTS.*workspaces WHERE id").
WithArgs("ws-rt").
WillReturnRows(sqlmock.NewRows([]string{"exists"}).AddRow(true))
mock.ExpectExec("UPDATE workspaces SET runtime").
WithArgs("ws-rt", "claude-code").
WillReturnResult(sqlmock.NewResult(0, 1))