diff --git a/client/client_test.go b/client/client_test.go index b80a4da..b349cdc 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -2489,7 +2489,8 @@ func TestImportHistory(t *testing.T) { require.Equal(t, "305", out) out = tester.RunInteractiveShell(t, ` hishtory export -pipefail`) require.Contains(t, out, "echo command-305") - + out = tester.RunInteractiveShell(t, ` hishtory export -pipefail`) + testutils.CompareGoldens(t, out, "TestImportHistory-export") // TODO: There is a bug here that will be evident if you check that the export is in the correct order on the remote device, because timestamps don't have sufficient granularity } diff --git a/client/lib/lib.go b/client/lib/lib.go index 8b89703..b3a6089 100644 --- a/client/lib/lib.go +++ b/client/lib/lib.go @@ -290,6 +290,7 @@ func ImportHistory(ctx context.Context, shouldReadStdin, force bool) (int, error numEntriesImported := 0 var iteratorError error = nil var batch []data.HistoryEntry + importTimestamp := time.Now().UTC() batchSize := 100 entriesIter(func(cmd string, err error) bool { if err != nil { @@ -300,6 +301,8 @@ func ImportHistory(ctx context.Context, shouldReadStdin, force bool) (int, error if isBashWeirdness(cmd) || strings.HasPrefix(cmd, " ") { return true } + startTime := importTimestamp.Add(time.Millisecond * time.Duration(numEntriesImported*2)) + endTime := startTime.Add(time.Millisecond) entry := normalizeEntryTimezone(data.HistoryEntry{ LocalUsername: currentUser.Name, Hostname: hostname, @@ -307,8 +310,8 @@ func ImportHistory(ctx context.Context, shouldReadStdin, force bool) (int, error CurrentWorkingDirectory: "Unknown", HomeDirectory: homedir, ExitCode: 0, - StartTime: time.Now().UTC(), - EndTime: time.Now().UTC(), + StartTime: startTime, + EndTime: endTime, DeviceId: config.DeviceId, EntryId: uuid.Must(uuid.NewRandom()).String(), })