pi-agent: Implement operation coordination
This commit is contained in:
@@ -23,6 +23,19 @@ func (m *recordingModule) Dispatch(intent app.Intent) app.Result {
|
||||
m.intents = append(m.intents, intent)
|
||||
return app.Result{Snapshot: m.snapshot, Notice: "done"}
|
||||
}
|
||||
func (m *recordingModule) StartOperation(intent app.Intent) app.OperationStream {
|
||||
result := m.Dispatch(intent)
|
||||
updates := make(chan app.OperationUpdate, 1)
|
||||
phase := app.OperationSucceeded
|
||||
status := app.OperationStatus{Kind: app.StatusSuccess, Summary: result.Notice}
|
||||
if result.Err != nil {
|
||||
phase = app.OperationFailed
|
||||
status = app.OperationStatus{Kind: app.StatusError, Summary: "Operation failed", Detail: result.Err.Error()}
|
||||
}
|
||||
updates <- app.OperationUpdate{Snapshot: result.Snapshot, Phase: phase, Status: status, Err: result.Err}
|
||||
close(updates)
|
||||
return app.OperationStream{Snapshot: m.snapshot, Updates: updates}
|
||||
}
|
||||
|
||||
func TestMainAndProfilePagesMapKeysAndObscurePasswords(t *testing.T) {
|
||||
module := &recordingModule{snapshot: app.Snapshot{
|
||||
@@ -46,10 +59,14 @@ func TestMainAndProfilePagesMapKeysAndObscurePasswords(t *testing.T) {
|
||||
t.Fatalf("Profile page exposed proxy password:\n%s", view)
|
||||
}
|
||||
|
||||
model = updateKey(model, "a")
|
||||
if len(module.intents) != 1 || module.intents[0].Kind != app.ActivateProfile || module.intents[0].Name != "office" {
|
||||
updated, command := model.Update(keyMessage("a"))
|
||||
model = updated.(Model)
|
||||
if command == nil || len(module.intents) != 1 || module.intents[0].Kind != app.ActivateProfile || module.intents[0].Name != "office" {
|
||||
t.Fatalf("activate key dispatched %#v", module.intents)
|
||||
}
|
||||
updated, _ = model.Update(command())
|
||||
model = updated.(Model)
|
||||
model = updateKey(model, "p")
|
||||
model = updateKey(model, "d")
|
||||
if !strings.Contains(model.View(), "Delete Profile") {
|
||||
t.Fatalf("delete key did not request confirmation:\n%s", model.View())
|
||||
|
||||
Reference in New Issue
Block a user