mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-24 14:01:46 +02:00
Remove debugging information and give up on that test, and add work around for weird zsh bug with importing
This commit is contained in:
parent
99b51a356e
commit
ee6680f571
@ -547,7 +547,7 @@ func cleanDatabase() error {
|
|||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
return result.Error
|
return result.Error
|
||||||
}
|
}
|
||||||
// TODO: Clean the database by deleting entries for users that haven't been used in X amount of time
|
// TODO(future): Clean the database by deleting entries for users that haven't been used in X amount of time
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -867,16 +867,16 @@ echo other`)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testHishtoryBackgroundSaving(t *testing.T, tester shellTester) {
|
func testHishtoryBackgroundSaving(t *testing.T, tester shellTester) {
|
||||||
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
|
if runtime.GOOS == "darwin" {
|
||||||
t.Skip("skip testing background saving since it is too flakey on M1")
|
t.Skip("skip testing background saving since it is flakey on MacOs")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup
|
// Setup
|
||||||
defer shared.BackupAndRestore(t)()
|
defer shared.BackupAndRestore(t)()
|
||||||
|
|
||||||
p, err := exec.LookPath("go")
|
// Check that we can find the go binary
|
||||||
|
_, err := exec.LookPath("go")
|
||||||
shared.Check(t, err)
|
shared.Check(t, err)
|
||||||
fmt.Printf("TODO: DDWORKENDEBUG: go=%s path=%s\n", p, os.Getenv("PATH"))
|
|
||||||
|
|
||||||
// Test install with an unset HISHTORY_TEST var so that we save in the background (this is likely to be flakey!)
|
// Test install with an unset HISHTORY_TEST var so that we save in the background (this is likely to be flakey!)
|
||||||
out := tester.RunInteractiveShell(t, `unset HISHTORY_TEST
|
out := tester.RunInteractiveShell(t, `unset HISHTORY_TEST
|
||||||
@ -1387,7 +1387,13 @@ echo %v-bar`, randomCmdUuid, randomCmdUuid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check that the previously recorded commands are in hishtory
|
// Check that the previously recorded commands are in hishtory
|
||||||
// TODO: change the below to | grep -v pipefail and see that it fails weirdly with zsh
|
out = tester.RunInteractiveShell(t, `hishtory export | grep -v pipefail`)
|
||||||
|
expectedOutput = fmt.Sprintf("hishtory export %s\necho %s-foo\necho %s-bar\n/tmp/client install \nhishtory export %s\nhishtory import\n", randomCmdUuid, randomCmdUuid, randomCmdUuid, randomCmdUuid)
|
||||||
|
if diff := cmp.Diff(expectedOutput, out); diff != "" {
|
||||||
|
t.Fatalf("hishtory export mismatch (-expected +got):\n%s\nout=%#v", diff, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// And check a different way
|
||||||
out = tester.RunInteractiveShell(t, `hishtory export `+randomCmdUuid)
|
out = tester.RunInteractiveShell(t, `hishtory export `+randomCmdUuid)
|
||||||
expectedOutput = fmt.Sprintf("hishtory export %s\necho %s-foo\necho %s-bar\nhishtory export %s\n", randomCmdUuid, randomCmdUuid, randomCmdUuid, randomCmdUuid)
|
expectedOutput = fmt.Sprintf("hishtory export %s\necho %s-foo\necho %s-bar\nhishtory export %s\n", randomCmdUuid, randomCmdUuid, randomCmdUuid, randomCmdUuid)
|
||||||
if diff := cmp.Diff(expectedOutput, out); diff != "" {
|
if diff := cmp.Diff(expectedOutput, out); diff != "" {
|
||||||
@ -1499,4 +1505,5 @@ ls /tmp`, randomCmdUuid, randomCmdUuid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add a test with different users
|
// TODO(future): Add a test with different users
|
||||||
|
// TODO(future): Can we do a fuzz test with lots of users and lots of devices?
|
||||||
|
@ -154,6 +154,17 @@ func BuildHistoryEntry(ctx *context.Context, args []string) (*data.HistoryEntry,
|
|||||||
return &entry, nil
|
return &entry, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isZshWeirdness(cmd string) bool {
|
||||||
|
// Zsh has this weird behavior where the currently running command is persisted to
|
||||||
|
// the history file with a weird prefix. This only matters to us when running
|
||||||
|
// an import, in which case we want to just skip it.
|
||||||
|
// For example, if the running command was echo foo the command would
|
||||||
|
// show up in the history file as `: 1663823053:0;echo foo`
|
||||||
|
firstCommandBugRegex := regexp.MustCompile(`: \d+:\d;(.*)`)
|
||||||
|
matches := firstCommandBugRegex.FindStringSubmatch(cmd)
|
||||||
|
return len(matches) == 2
|
||||||
|
}
|
||||||
|
|
||||||
func buildRegexFromTimeFormat(timeFormat string) string {
|
func buildRegexFromTimeFormat(timeFormat string) string {
|
||||||
expectedRegex := ""
|
expectedRegex := ""
|
||||||
lastCharWasPercent := false
|
lastCharWasPercent := false
|
||||||
@ -399,13 +410,17 @@ func ImportHistory(ctx *context.Context) (int, error) {
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
for _, cmd := range historyEntries {
|
for _, cmd := range historyEntries {
|
||||||
|
if isZshWeirdness(cmd) {
|
||||||
|
// Skip it
|
||||||
|
continue
|
||||||
|
}
|
||||||
entry := data.HistoryEntry{
|
entry := data.HistoryEntry{
|
||||||
LocalUsername: currentUser.Name,
|
LocalUsername: currentUser.Name,
|
||||||
Hostname: hostname,
|
Hostname: hostname,
|
||||||
Command: cmd,
|
Command: cmd,
|
||||||
CurrentWorkingDirectory: "Unknown",
|
CurrentWorkingDirectory: "Unknown",
|
||||||
HomeDirectory: homedir,
|
HomeDirectory: homedir,
|
||||||
ExitCode: 0, // Unknown, but assumed
|
ExitCode: 0,
|
||||||
StartTime: time.Now(),
|
StartTime: time.Now(),
|
||||||
EndTime: time.Now(),
|
EndTime: time.Now(),
|
||||||
DeviceId: config.DeviceId,
|
DeviceId: config.DeviceId,
|
||||||
|
@ -91,6 +91,13 @@ func TestBuildHistoryEntry(t *testing.T) {
|
|||||||
if entry.StartTime.Unix() != 1641774958 {
|
if entry.StartTime.Unix() != 1641774958 {
|
||||||
t.Fatalf("history entry has incorrect Unix time in the start time: %v", entry.StartTime.Unix())
|
t.Fatalf("history entry has incorrect Unix time in the start time: %v", entry.StartTime.Unix())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test the weird zsh bug
|
||||||
|
entry, err = BuildHistoryEntry(hctx.MakeContext(), []string{"unused", "saveHistoryEntry", "zsh", "120", ": 1663823053:0;echo foo\n", "1641774958"})
|
||||||
|
shared.Check(t, err)
|
||||||
|
if entry.Command != "echo foo" {
|
||||||
|
t.Fatalf("expected the zsh command to be worked around, actual=%s", entry.Command)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPersist(t *testing.T) {
|
func TestPersist(t *testing.T) {
|
||||||
|
@ -281,7 +281,7 @@ func saveHistoryEntry(ctx *context.Context) {
|
|||||||
|
|
||||||
// Persist it locally
|
// Persist it locally
|
||||||
db := hctx.GetDb(ctx)
|
db := hctx.GetDb(ctx)
|
||||||
err = lib.ReliableDbCreate(db, entry)
|
err = lib.ReliableDbCreate(db, *entry)
|
||||||
lib.CheckFatalError(err)
|
lib.CheckFatalError(err)
|
||||||
|
|
||||||
// Persist it remotely
|
// Persist it remotely
|
||||||
|
Loading…
x
Reference in New Issue
Block a user