@@ -1456,3 +1456,103 @@ func TestObsidianExportWatchModeCallsInjectedWatcher(t *testing.T) {
14561456 t .Fatalf ("expected non-nil Logf in WatcherConfig" )
14571457 }
14581458}
1459+
1460+ // ─── Delete command tests ─────────────────────────────────────────────────────
1461+
1462+ func TestCmdDeleteSoftDeleteSuccess (t * testing.T ) {
1463+ cfg := testConfig (t )
1464+ id := mustSeedObservation (t , cfg , "s-del" , "proj-del" , "decision" , "to-delete" , "delete me" , "project" )
1465+
1466+ withArgs (t , "engram" , "delete" , strconv .FormatInt (id , 10 ))
1467+ stdout , stderr := captureOutput (t , func () { cmdDelete (cfg ) })
1468+ if stderr != "" {
1469+ t .Fatalf ("expected no stderr, got: %q" , stderr )
1470+ }
1471+ if ! strings .Contains (stdout , "deleted" ) {
1472+ t .Fatalf ("expected deletion confirmation, got: %q" , stdout )
1473+ }
1474+ if ! strings .Contains (stdout , strconv .FormatInt (id , 10 )) {
1475+ t .Fatalf ("expected id in output, got: %q" , stdout )
1476+ }
1477+ }
1478+
1479+ func TestCmdDeleteHardDeleteSuccess (t * testing.T ) {
1480+ cfg := testConfig (t )
1481+ id := mustSeedObservation (t , cfg , "s-del2" , "proj-del2" , "decision" , "hard-delete" , "hard delete me" , "project" )
1482+
1483+ withArgs (t , "engram" , "delete" , strconv .FormatInt (id , 10 ), "--hard" )
1484+ stdout , stderr := captureOutput (t , func () { cmdDelete (cfg ) })
1485+ if stderr != "" {
1486+ t .Fatalf ("expected no stderr, got: %q" , stderr )
1487+ }
1488+ if ! strings .Contains (stdout , "deleted" ) {
1489+ t .Fatalf ("expected deletion confirmation, got: %q" , stdout )
1490+ }
1491+ if ! strings .Contains (stdout , strconv .FormatInt (id , 10 )) {
1492+ t .Fatalf ("expected id in output, got: %q" , stdout )
1493+ }
1494+ }
1495+
1496+ func TestCmdDeleteNonExistentID (t * testing.T ) {
1497+ cfg := testConfig (t )
1498+
1499+ exited := false
1500+ oldExit := exitFunc
1501+ exitFunc = func (code int ) { exited = true }
1502+ t .Cleanup (func () { exitFunc = oldExit })
1503+
1504+ withArgs (t , "engram" , "delete" , "999999" )
1505+ _ , stderr := captureOutput (t , func () { cmdDelete (cfg ) })
1506+
1507+ if ! exited {
1508+ t .Fatalf ("expected exitFunc to be called for non-existent observation" )
1509+ }
1510+ if ! strings .Contains (stderr , "not found" ) && ! strings .Contains (stderr , "observation" ) {
1511+ t .Fatalf ("expected not-found error in stderr, got: %q" , stderr )
1512+ }
1513+ }
1514+
1515+ func TestCmdDeleteMissingIDArg (t * testing.T ) {
1516+ cfg := testConfig (t )
1517+
1518+ exited := false
1519+ oldExit := exitFunc
1520+ exitFunc = func (code int ) { exited = true }
1521+ t .Cleanup (func () { exitFunc = oldExit })
1522+
1523+ withArgs (t , "engram" , "delete" )
1524+ _ , stderr := captureOutput (t , func () { cmdDelete (cfg ) })
1525+
1526+ if ! exited {
1527+ t .Fatalf ("expected exitFunc to be called when no ID arg provided" )
1528+ }
1529+ if ! strings .Contains (stderr , "usage" ) {
1530+ t .Fatalf ("expected usage message in stderr, got: %q" , stderr )
1531+ }
1532+ }
1533+
1534+ func TestCmdDeleteInvalidIDArg (t * testing.T ) {
1535+ cfg := testConfig (t )
1536+
1537+ exited := false
1538+ oldExit := exitFunc
1539+ exitFunc = func (code int ) { exited = true }
1540+ t .Cleanup (func () { exitFunc = oldExit })
1541+
1542+ withArgs (t , "engram" , "delete" , "not-a-number" )
1543+ _ , stderr := captureOutput (t , func () { cmdDelete (cfg ) })
1544+
1545+ if ! exited {
1546+ t .Fatalf ("expected exitFunc to be called for invalid id" )
1547+ }
1548+ if ! strings .Contains (stderr , "invalid" ) {
1549+ t .Fatalf ("expected invalid id error in stderr, got: %q" , stderr )
1550+ }
1551+ }
1552+
1553+ func TestCmdDeleteInUsage (t * testing.T ) {
1554+ stdout , _ := captureOutput (t , func () { printUsage () })
1555+ if ! strings .Contains (stdout , "delete" ) {
1556+ t .Fatalf ("expected 'delete' in usage output, got: %q" , stdout )
1557+ }
1558+ }
0 commit comments