Skip to content

Commit 7588354

Browse files
committed
- always return JSON
- do not load input/ouputs in list workflows / get workflow - drop with force
1 parent 0ea74db commit 7588354

File tree

5 files changed

+55
-139
lines changed

5 files changed

+55
-139
lines changed

cmd/dbos/cli_integration_test.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -246,111 +246,111 @@ func testListWorkflows(t *testing.T, cliPath string) {
246246
}{
247247
{
248248
name: "BasicList",
249-
args: []string{"workflow", "list", "--json"},
249+
args: []string{"workflow", "list"},
250250
expectWorkflows: true,
251251
},
252252
{
253253
name: "LimitedList",
254-
args: []string{"workflow", "list", "--json", "--limit", "5"},
254+
args: []string{"workflow", "list", "--limit", "5"},
255255
expectWorkflows: true,
256256
maxCount: 5,
257257
},
258258
{
259259
name: "OffsetPagination",
260-
args: []string{"workflow", "list", "--json", "--limit", "3", "--offset", "1"},
260+
args: []string{"workflow", "list", "--limit", "3", "--offset", "1"},
261261
maxCount: 3,
262262
},
263263
{
264264
name: "SortDescending",
265-
args: []string{"workflow", "list", "--json", "--sort-desc", "--limit", "10"},
265+
args: []string{"workflow", "list", "--sort-desc", "--limit", "10"},
266266
expectWorkflows: true,
267267
maxCount: 10,
268268
},
269269
{
270270
name: "QueueNameFilter",
271-
args: []string{"workflow", "list", "--json", "--queue", "example-queue"},
271+
args: []string{"workflow", "list", "--queue", "example-queue"},
272272
expectWorkflows: true,
273273
expectQueuedCount: 10, // From QueueWorkflow which enqueues 10 workflows
274274
checkQueueNames: true,
275275
},
276276
{
277277
name: "StatusFilterSuccess",
278-
args: []string{"workflow", "list", "--json", "--status", "SUCCESS"},
278+
args: []string{"workflow", "list", "--status", "SUCCESS"},
279279
expectWorkflows: true,
280280
checkStatus: dbos.WorkflowStatusSuccess,
281281
},
282282
{
283283
name: "StatusFilterError",
284-
args: []string{"workflow", "list", "--json", "--status", "ERROR"},
284+
args: []string{"workflow", "list", "--status", "ERROR"},
285285
checkStatus: dbos.WorkflowStatusError,
286286
},
287287
{
288288
name: "StatusFilterEnqueued",
289-
args: []string{"workflow", "list", "--json", "--status", "ENQUEUED"},
289+
args: []string{"workflow", "list", "--status", "ENQUEUED"},
290290
checkStatus: dbos.WorkflowStatusEnqueued,
291291
minCount: 10, // We expect at least 10 enqueued workflows from QueueWorkflow
292292
},
293293
{
294294
name: "StatusFilterPending",
295-
args: []string{"workflow", "list", "--json", "--status", "PENDING"},
295+
args: []string{"workflow", "list", "--status", "PENDING"},
296296
checkStatus: dbos.WorkflowStatusPending,
297297
},
298298
{
299299
name: "StatusFilterCancelled",
300-
args: []string{"workflow", "list", "--json", "--status", "CANCELLED"},
300+
args: []string{"workflow", "list", "--status", "CANCELLED"},
301301
checkStatus: dbos.WorkflowStatusCancelled,
302302
},
303303
{
304304
name: "TimeRangeFilter",
305-
args: []string{"workflow", "list", "--json", "--start-time", currentTime.Add(-1 * time.Hour).Format(time.RFC3339), "--end-time", currentTime.Add(1 * time.Hour).Format(time.RFC3339)},
305+
args: []string{"workflow", "list", "--start-time", currentTime.Add(-1 * time.Hour).Format(time.RFC3339), "--end-time", currentTime.Add(1 * time.Hour).Format(time.RFC3339)},
306306
expectWorkflows: true,
307307
},
308308
{
309309
name: "CurrentTimeStartFilter",
310-
args: []string{"workflow", "list", "--json", "--start-time", currentTime.Format(time.RFC3339)},
310+
args: []string{"workflow", "list", "--start-time", currentTime.Format(time.RFC3339)},
311311
maxCount: 0, // Should return no workflows as all were created before currentTime
312312
},
313313
{
314314
name: "FutureTimeFilter",
315-
args: []string{"workflow", "list", "--json", "--start-time", currentTime.Add(1 * time.Hour).Format(time.RFC3339)},
315+
args: []string{"workflow", "list", "--start-time", currentTime.Add(1 * time.Hour).Format(time.RFC3339)},
316316
maxCount: 0, // Should return no workflows
317317
},
318318
{
319319
name: "PastTimeFilter",
320-
args: []string{"workflow", "list", "--json", "--end-time", currentTime.Add(1 * time.Hour).Format(time.RFC3339)},
320+
args: []string{"workflow", "list", "--end-time", currentTime.Add(1 * time.Hour).Format(time.RFC3339)},
321321
expectWorkflows: true, // Should return all workflows created before now + 1 hour
322322
},
323323
{
324324
name: "WorkflowNameFilter",
325-
args: []string{"workflow", "list", "--json", "--name", "main.QueueWorkflow"},
325+
args: []string{"workflow", "list", "--name", "main.QueueWorkflow"},
326326
expectWorkflows: true,
327327
minCount: 1, // Should find at least the QueueWorkflow
328328
},
329329
{
330330
name: "QueuesOnlyFilter",
331-
args: []string{"workflow", "list", "--json", "--queues-only"},
331+
args: []string{"workflow", "list", "--queues-only"},
332332
expectWorkflows: true,
333333
minCount: 10, // Should find at least the enqueued workflows
334334
},
335335
{
336336
name: "UserFilter",
337-
args: []string{"workflow", "list", "--json", "--user", "test-user"},
337+
args: []string{"workflow", "list", "--user", "test-user"},
338338
expectWorkflows: false, // No workflows with test-user in this test
339339
},
340340
{
341341
name: "LargeLimit",
342-
args: []string{"workflow", "list", "--json", "--limit", "100"},
342+
args: []string{"workflow", "list", "--limit", "100"},
343343
maxCount: 100,
344344
},
345345
{
346346
name: "CombinedTimeAndStatus",
347-
args: []string{"workflow", "list", "--json", "--status", "SUCCESS", "--start-time", currentTime.Add(-2 * time.Hour).Format(time.RFC3339)},
347+
args: []string{"workflow", "list", "--status", "SUCCESS", "--start-time", currentTime.Add(-2 * time.Hour).Format(time.RFC3339)},
348348
expectWorkflows: true,
349349
checkStatus: dbos.WorkflowStatusSuccess,
350350
},
351351
{
352352
name: "QueueAndTimeFilter",
353-
args: []string{"workflow", "list", "--json", "--queue", "example-queue", "--end-time", currentTime.Add(1 * time.Hour).Format(time.RFC3339)},
353+
args: []string{"workflow", "list", "--queue", "example-queue", "--end-time", currentTime.Add(1 * time.Hour).Format(time.RFC3339)},
354354
expectWorkflows: true,
355355
checkQueueNames: true,
356356
},
@@ -421,7 +421,7 @@ func testGetWorkflow(t *testing.T, cliPath string) {
421421
assert.NotEmpty(t, workflowID, "Workflow ID should not be empty")
422422

423423
t.Run("GetWorkflowJSON", func(t *testing.T) {
424-
cmd := exec.Command(cliPath, "workflow", "get", workflowID, "--json")
424+
cmd := exec.Command(cliPath, "workflow", "get", workflowID)
425425
cmd.Env = append(os.Environ(), "DBOS_SYSTEM_DATABASE_URL="+getDatabaseURL())
426426

427427
output, err := cmd.CombinedOutput()
@@ -436,7 +436,7 @@ func testGetWorkflow(t *testing.T, cliPath string) {
436436
assert.NotEmpty(t, status.Name, "Should have workflow name")
437437

438438
// Redo the test with the db url in flags
439-
cmd2 := exec.Command(cliPath, "workflow", "get", workflowID, "--json", "--db-url", getDatabaseURL())
439+
cmd2 := exec.Command(cliPath, "workflow", "get", workflowID, "--db-url", getDatabaseURL())
440440

441441
output2, err2 := cmd2.CombinedOutput()
442442
require.NoError(t, err2, "Get workflow JSON command failed: %s", string(output2))
@@ -481,7 +481,7 @@ func testCancelResumeWorkflow(t *testing.T, cliPath string) {
481481
assert.Contains(t, string(output), "Successfully cancelled", "Should confirm cancellation")
482482

483483
// Verify workflow is actually cancelled
484-
getCmd := exec.Command(cliPath, "workflow", "get", workflowID, "--json")
484+
getCmd := exec.Command(cliPath, "workflow", "get", workflowID)
485485
getCmd.Env = append(os.Environ(), "DBOS_SYSTEM_DATABASE_URL="+getDatabaseURL())
486486

487487
getOutput, err := getCmd.CombinedOutput()
@@ -494,7 +494,7 @@ func testCancelResumeWorkflow(t *testing.T, cliPath string) {
494494
})
495495

496496
t.Run("ResumeWorkflow", func(t *testing.T) {
497-
cmd := exec.Command(cliPath, "workflow", "resume", workflowID, "--json")
497+
cmd := exec.Command(cliPath, "workflow", "resume", workflowID)
498498
cmd.Env = append(os.Environ(), "DBOS_SYSTEM_DATABASE_URL="+getDatabaseURL())
499499

500500
output, err := cmd.CombinedOutput()
@@ -532,7 +532,7 @@ func testForkWorkflow(t *testing.T, cliPath string) {
532532
assert.NotEmpty(t, workflowID, "Workflow ID should not be empty")
533533

534534
t.Run("ForkWorkflow", func(t *testing.T) {
535-
cmd := exec.Command(cliPath, "workflow", "fork", workflowID, "--json")
535+
cmd := exec.Command(cliPath, "workflow", "fork", workflowID)
536536
cmd.Env = append(os.Environ(), "DBOS_SYSTEM_DATABASE_URL="+getDatabaseURL())
537537

538538
output, err := cmd.CombinedOutput()
@@ -549,7 +549,7 @@ func testForkWorkflow(t *testing.T, cliPath string) {
549549
})
550550

551551
t.Run("ForkWorkflowFromStep", func(t *testing.T) {
552-
cmd := exec.Command(cliPath, "workflow", "fork", workflowID, "--step", "2", "--json")
552+
cmd := exec.Command(cliPath, "workflow", "fork", workflowID, "--step", "2")
553553
cmd.Env = append(os.Environ(), "DBOS_SYSTEM_DATABASE_URL="+getDatabaseURL())
554554

555555
output, err := cmd.CombinedOutput()
@@ -587,7 +587,7 @@ func testGetWorkflowSteps(t *testing.T, cliPath string) {
587587
assert.NotEmpty(t, workflowID, "Workflow ID should not be empty")
588588

589589
t.Run("GetStepsJSON", func(t *testing.T) {
590-
cmd := exec.Command(cliPath, "workflow", "steps", workflowID, "--json")
590+
cmd := exec.Command(cliPath, "workflow", "steps", workflowID)
591591
cmd.Env = append(os.Environ(), "DBOS_SYSTEM_DATABASE_URL="+getDatabaseURL())
592592

593593
output, err := cmd.CombinedOutput()
@@ -731,7 +731,7 @@ func buildCLI(t *testing.T) string {
731731
}
732732

733733
func getFirstWorkflowID(t *testing.T, cliPath string) string {
734-
cmd := exec.Command(cliPath, "workflow", "list", "--json", "--limit", "1")
734+
cmd := exec.Command(cliPath, "workflow", "list", "--limit", "1")
735735
cmd.Env = append(os.Environ(), "DBOS_SYSTEM_DATABASE_URL="+getDatabaseURL())
736736

737737
output, err := cmd.CombinedOutput()

cmd/dbos/reset.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,7 @@ func runReset(cmd *cobra.Command, args []string) error {
6969

7070
// Drop the system database if it exists
7171
logger.Info("Resetting system database", "database", dbName)
72-
73-
// First, terminate all connections to the database
74-
terminateQuery := fmt.Sprintf(`
75-
SELECT pg_terminate_backend(pid)
76-
FROM pg_stat_activity
77-
WHERE datname = '%s' AND pid <> pg_backend_pid()
78-
`, dbName)
79-
80-
_, err = db.Exec(terminateQuery) // Ignore errors, database might not exist
81-
if err != nil {
82-
logger.Warn("Failed to terminate existing connections", "error", err)
83-
}
84-
85-
// Drop the database if it exists
86-
dropQuery := fmt.Sprintf("DROP DATABASE IF EXISTS %s", dbName)
72+
dropQuery := fmt.Sprintf("DROP DATABASE IF EXISTS %s WITH (FORCE)", dbName)
8773
if _, err := db.Exec(dropQuery); err != nil {
8874
return fmt.Errorf("failed to drop system database: %w", err)
8975
}

cmd/dbos/version.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,13 @@ var versionCmd = &cobra.Command{
4545
Use: "version",
4646
Short: "Show the version and exit",
4747
RunE: func(cmd *cobra.Command, args []string) error {
48-
if jsonOutput {
49-
return outputJSON(map[string]string{"version": Version})
50-
}
51-
l := logger.With("version", Version)
48+
versionInfo := map[string]string{"version": Version}
5249
if Commit != "" {
53-
l = l.With("commit", Commit)
50+
versionInfo["commit"] = Commit
5451
}
5552
if BuiltAt != "" {
56-
l = l.With("built", BuiltAt)
53+
versionInfo["built"] = BuiltAt
5754
}
58-
l.Info("DBOS CLI version")
59-
return nil
55+
return outputJSON(versionInfo)
6056
},
6157
}

0 commit comments

Comments
 (0)