@@ -563,6 +563,114 @@ func TestCloudCommandIsolationDoesNotMutateLocalState(t *testing.T) {
563563 }
564564}
565565
566+ func TestCmdSaveCreatesManualSessionWithCWDDirectory (t * testing.T ) {
567+ stubExitWithPanic (t )
568+ stubRuntimeHooks (t )
569+
570+ cfg := testConfig (t )
571+ cwd := t .TempDir ()
572+ oldWd , err := os .Getwd ()
573+ if err != nil {
574+ t .Fatalf ("get wd: %v" , err )
575+ }
576+ if err := os .Chdir (cwd ); err != nil {
577+ t .Fatalf ("chdir: %v" , err )
578+ }
579+ t .Cleanup (func () { _ = os .Chdir (oldWd ) })
580+
581+ withArgs (t , "engram" , "save" , "Manual title" , "Manual content" , "--project" , "manual-proj" )
582+ _ , stderr , recovered := captureOutputAndRecover (t , func () { cmdSave (cfg ) })
583+ if recovered != nil || stderr != "" {
584+ t .Fatalf ("cmdSave should succeed, panic=%v stderr=%q" , recovered , stderr )
585+ }
586+
587+ s , err := store .New (cfg )
588+ if err != nil {
589+ t .Fatalf ("open store: %v" , err )
590+ }
591+ defer s .Close ()
592+ session , err := s .GetSession ("manual-save-manual-proj" )
593+ if err != nil {
594+ t .Fatalf ("get manual session: %v" , err )
595+ }
596+ wantDir , err := filepath .EvalSymlinks (cwd )
597+ if err != nil {
598+ t .Fatalf ("resolve cwd symlinks: %v" , err )
599+ }
600+ gotDir , err := filepath .EvalSymlinks (session .Directory )
601+ if err != nil {
602+ t .Fatalf ("resolve session directory symlinks: %v" , err )
603+ }
604+ if gotDir != wantDir {
605+ t .Fatalf ("manual session directory = %q, want %q" , session .Directory , cwd )
606+ }
607+ }
608+
609+ func TestCloudEnrollAndSyncHelpDoNotMutateLocalState (t * testing.T ) {
610+ stubExitWithPanic (t )
611+ stubRuntimeHooks (t )
612+
613+ for _ , tc := range []struct {
614+ name string
615+ args []string
616+ run func (store.Config )
617+ }{
618+ {name : "cloud enroll help" , args : []string {"engram" , "cloud" , "enroll" , "--help" }, run : cmdCloud },
619+ {name : "sync help" , args : []string {"engram" , "sync" , "--help" }, run : cmdSync },
620+ } {
621+ t .Run (tc .name , func (t * testing.T ) {
622+ tmpHome := t .TempDir ()
623+ cfg := testConfig (t )
624+ cfg .DataDir = filepath .Join (tmpHome , ".engram" )
625+
626+ withArgs (t , tc .args ... )
627+ stdout , stderr , recovered := captureOutputAndRecover (t , func () { tc .run (cfg ) })
628+ if recovered != nil || stderr != "" {
629+ t .Fatalf ("help should return cleanly, panic=%v stderr=%q stdout=%q" , recovered , stderr , stdout )
630+ }
631+ if ! strings .Contains (stdout , "usage:" ) {
632+ t .Fatalf ("expected usage output, got %q" , stdout )
633+ }
634+ if _ , err := os .Stat (filepath .Join (cfg .DataDir , "engram.db" )); err == nil {
635+ t .Fatalf ("help should not create local database" )
636+ }
637+ })
638+ }
639+ }
640+
641+ func TestUpdateChecksSkipCriticalStartupCommands (t * testing.T ) {
642+ if shouldCheckForUpdates ([]string {"mcp" }) {
643+ t .Fatal ("mcp startup must not run update check" )
644+ }
645+ if shouldCheckForUpdates ([]string {"serve" }) {
646+ t .Fatal ("serve startup must not run update check" )
647+ }
648+ if shouldCheckForUpdates ([]string {"cloud" , "serve" }) {
649+ t .Fatal ("cloud serve startup must not run update check" )
650+ }
651+ if ! shouldCheckForUpdates ([]string {"version" }) {
652+ t .Fatal ("normal commands should keep update output" )
653+ }
654+ }
655+
656+ func TestMainCloudHelpDoesNotCreateLocalDatabase (t * testing.T ) {
657+ stubRuntimeHooks (t )
658+ dataDir := filepath .Join (t .TempDir (), ".engram" )
659+ t .Setenv ("ENGRAM_DATA_DIR" , dataDir )
660+ withArgs (t , "engram" , "cloud" , "--help" )
661+
662+ stdout , stderr , recovered := captureOutputAndRecover (t , func () { main () })
663+ if recovered != nil || stderr != "" {
664+ t .Fatalf ("cloud help should return cleanly, panic=%v stderr=%q stdout=%q" , recovered , stderr , stdout )
665+ }
666+ if ! strings .Contains (stdout , "usage: engram cloud" ) {
667+ t .Fatalf ("expected cloud usage output, got %q" , stdout )
668+ }
669+ if _ , err := os .Stat (filepath .Join (dataDir , "engram.db" )); err == nil {
670+ t .Fatal ("cloud help should not create local database" )
671+ }
672+ }
673+
566674func TestCmdCloudStatusDistinguishesAuthAndSyncReadiness (t * testing.T ) {
567675 stubExitWithPanic (t )
568676 stubRuntimeHooks (t )
0 commit comments