Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cloud = false
53 changes: 53 additions & 0 deletions acceptance/cmd/workspace/alerts-v2-not-found/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

=== trashed alert is still readable

>>> [CLI] alerts-v2 trash-alert [ALERT_ID]

>>> [CLI] alerts-v2 get-alert [ALERT_ID]
DELETED

>>> [CLI] alerts-v2 trash-alert [ALERT_ID]
Error: Alert [ALERT_ID] is already trashed

Exit code: 1

>>> [CLI] alerts-v2 update-alert [ALERT_ID] display_name --json {"display_name": "x"}
Error: Cannot move node 'myalert.dbalert.json' (ID: [ALERT_ID]) because it is in trash folder

Exit code: 1

=== purged alert is gone

>>> [CLI] alerts-v2 trash-alert [ALERT_ID] --purge

>>> [CLI] alerts-v2 get-alert [ALERT_ID]
Error: Tree node with id [ALERT_ID] does not exist

Exit code: 1

>>> [CLI] alerts-v2 trash-alert [ALERT_ID]
Error: Tree node with id [ALERT_ID] does not exist

Exit code: 1

>>> [CLI] alerts-v2 update-alert [ALERT_ID] display_name --json {"display_name": "x"}
Error: Tree node with id [ALERT_ID] does not exist

Exit code: 1

=== unknown alert

>>> [CLI] alerts-v2 get-alert [UUID]
Error: Alert with id [UUID] not found or has no folder node internal name

Exit code: 1

>>> [CLI] alerts-v2 trash-alert [UUID]
Error: Alert with id [UUID] not found

Exit code: 1

>>> [CLI] alerts-v2 update-alert [UUID] display_name --json {"display_name": "x"}
Error: Alert with id [UUID] not found or has no folder node internal name

Exit code: 1
27 changes: 27 additions & 0 deletions acceptance/cmd/workspace/alerts-v2-not-found/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Alert get/update/trash responses for trashed, purged and unknown alerts.
# Expected output was recorded against AWS on 2026-11-11; the test is local-only
# because the messages are backend-owned and have changed before.

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.

Against the cloud the output differs in two known places (trash-again UUID, timestamp suffix on the file name); can this comment name them so nobody flips Cloud = true blind?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in #7546. The header comment now lists both differences: trash-again reports a different UUID, and update on a trashed alert names the file myalert-<timestamp>.dbalert.json.

AI agent (harness_auto, isaac_claude, opus5.5)

create_alert() {
$CLI alerts-v2 create-alert --json '{"display_name": "'$1'", "query_text": "select 1", "warehouse_id": "w1", "evaluation": {"comparison_operator": "EQUAL", "source": {"name": "1"}, "threshold": {"value": {"double_value": 1}}}, "schedule": {"quartz_cron_schedule": "0 0 * * * ?", "timezone_id": "UTC"}}' | jq -r .id
}

alert_id=$(create_alert myalert)
add_repl "$alert_id" ALERT_ID

title "trashed alert is still readable"
trace $CLI alerts-v2 trash-alert $alert_id
trace $CLI alerts-v2 get-alert $alert_id | jq -r .lifecycle_state

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.

The golden shows a bare DELETED; projecting with jq '{lifecycle_state}' like alerts/with_file/script:31 labels the value. Worth matching?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. #7546 switches it to jq '{lifecycle_state}', the same as alerts/with_file/script, so the golden now shows "lifecycle_state": "DELETED".

AI agent (harness_auto, isaac_claude, opus5.5)

errcode trace $CLI alerts-v2 trash-alert $alert_id
errcode trace $CLI alerts-v2 update-alert $alert_id display_name --json '{"display_name": "x"}'

title "purged alert is gone"
trace $CLI alerts-v2 trash-alert $alert_id --purge
errcode trace $CLI alerts-v2 get-alert $alert_id
errcode trace $CLI alerts-v2 trash-alert $alert_id
errcode trace $CLI alerts-v2 update-alert $alert_id display_name --json '{"display_name": "x"}'

title "unknown alert"
unknown_id=00000000-0000-0000-0000-000000000000
errcode trace $CLI alerts-v2 get-alert $unknown_id
errcode trace $CLI alerts-v2 trash-alert $unknown_id
errcode trace $CLI alerts-v2 update-alert $unknown_id display_name --json '{"display_name": "x"}'
52 changes: 49 additions & 3 deletions libs/testserver/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,37 @@ func (s *FakeWorkspace) writeAlertFile(alert sql.AlertV2) error {
return nil
}

// alertNotFound mirrors the cloud's 404 for an alert that is not in the
// workspace: a purged alert is reported by its tree node, an id that never
// existed gets a per-method message.
func (s *FakeWorkspace) alertNotFound(alertId, unknownMessage string) Response {
message := unknownMessage
if s.PurgedAlertIDs[alertId] {
message = fmt.Sprintf("Tree node with id %s does not exist", alertId)
}
return Response{
StatusCode: http.StatusNotFound,
Body: map[string]string{
"error_code": "NOT_FOUND",
"message": message,
},
}
}

func (s *FakeWorkspace) AlertsGet(alertId string) Response {
defer s.LockUnlock()()

// A trashed (not purged) alert is still readable, with lifecycle_state DELETED.
alert, ok := s.Alerts[alertId]
if !ok {
return s.alertNotFound(alertId, fmt.Sprintf("Alert with id %s not found or has no folder node internal name", alertId))
}

return Response{
Body: alert,
}
}

func (s *FakeWorkspace) AlertsUpsert(req Request, alertId string) Response {
var alert sql.AlertV2

Expand All @@ -163,10 +194,17 @@ func (s *FakeWorkspace) AlertsUpsert(req Request, alertId string) Response {
defer s.LockUnlock()()

if alertId != "" {
_, ok := s.Alerts[alertId]
existing, ok := s.Alerts[alertId]
if !ok {
return s.alertNotFound(alertId, fmt.Sprintf("Alert with id %s not found or has no folder node internal name", alertId))
}
if existing.LifecycleState == sql.AlertLifecycleStateDeleted {
return Response{
StatusCode: 404,
StatusCode: http.StatusBadRequest,
Body: map[string]string{
"error_code": "INVALID_PARAMETER_VALUE",
"message": fmt.Sprintf("Cannot move node '%s' (ID: %s) because it is in trash folder", path.Base(alertFilePath(existing)), alertId),
},
}
}
} else {
Expand Down Expand Up @@ -195,15 +233,23 @@ func (s *FakeWorkspace) AlertsDelete(alertId string, purge bool) Response {

alert, ok := s.Alerts[alertId]
if !ok {
return s.alertNotFound(alertId, fmt.Sprintf("Alert with id %s not found", alertId))
}
if alert.LifecycleState == sql.AlertLifecycleStateDeleted && !purge {
return Response{
StatusCode: 404,
StatusCode: http.StatusBadRequest,
Body: map[string]string{
"error_code": "BAD_REQUEST",
"message": fmt.Sprintf("Alert %s is already trashed", alertId),
},
}
}

delete(s.files, alertFilePath(alert))

if purge {
delete(s.Alerts, alertId)
s.PurgedAlertIDs[alertId] = true
} else {
alert.LifecycleState = sql.AlertLifecycleStateDeleted
s.Alerts[alertId] = alert
Expand Down
2 changes: 2 additions & 0 deletions libs/testserver/fake_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ type FakeWorkspace struct {
GenieSpaces map[string]dashboards.GenieSpace
SqlWarehouses map[string]sql.GetWarehouseResponse
Alerts map[string]sql.AlertV2
PurgedAlertIDs map[string]bool
Experiments map[string]ml.GetExperimentResponse
ModelRegistryModels map[string]ml.Model
ModelRegistryModelIDs map[string]string // model name -> numeric ID
Expand Down Expand Up @@ -588,6 +589,7 @@ func NewFakeWorkspace(url, token string) *FakeWorkspace {
DmsDeployments: map[string]*DmsDeployment{},
DmsDeploymentNodes: map[string]string{},
Alerts: map[string]sql.AlertV2{},
PurgedAlertIDs: map[string]bool{},
Experiments: map[string]ml.GetExperimentResponse{},
ModelRegistryModels: map[string]ml.Model{},
ModelRegistryModelIDs: map[string]string{},
Expand Down
17 changes: 1 addition & 16 deletions libs/testserver/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/databricks/databricks-sdk-go/service/compute"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/databricks/databricks-sdk-go/service/sql"
"github.com/databricks/databricks-sdk-go/service/workspace"
)

Expand Down Expand Up @@ -1178,21 +1177,7 @@ func AddDefaultHandlers(server *Server) {

// Alerts v2:
server.Handle("GET", "/api/2.0/alerts/{id}", func(req Request) any {
defer req.Workspace.LockUnlock()()

id := req.Vars["id"]

value, ok := req.Workspace.Alerts[id]
if !ok || value.LifecycleState == sql.AlertLifecycleStateDeleted {
return Response{
StatusCode: 404,
Body: map[string]string{"message": "Alert with ID '" + id + "' does not exist."},
}
}

return Response{
Body: value,
}
return req.Workspace.AlertsGet(req.Vars["id"])
})

server.Handle("GET", "/api/2.0/alerts", func(req Request) any {
Expand Down
Loading