-
Notifications
You must be signed in to change notification settings - Fork 333
Guard entire attach against overwriting checkpoints from other machines
#1014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3e4757f
guard attach checkpoints
Soph 5a875d5
warn on checkpoint overwrite
Soph 6fd6d49
polish attach guards
Soph a5be08c
fast-path local checkpoint, smarter fetch hint
Soph cf2dbdd
plug remote-tracking loophole in attach guard
Soph 6bf884d
pin log level in tripwire test
Soph f114341
point v2-only attach refuses at the v2 ref
Soph 4332652
refuse tripwire instead of warning
Soph aae2449
port session-0 refuse to v2 writes
Soph File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| package checkpoint | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/entireio/cli/cmd/entire/cli/checkpoint/id" | ||
| "github.com/entireio/cli/cmd/entire/cli/jsonutil" | ||
| "github.com/entireio/cli/cmd/entire/cli/logging" | ||
| "github.com/entireio/cli/cmd/entire/cli/paths" | ||
| "github.com/entireio/cli/cmd/entire/cli/versioninfo" | ||
| "github.com/entireio/cli/redact" | ||
|
|
||
| "github.com/go-git/go-git/v6" | ||
| "github.com/go-git/go-git/v6/plumbing/filemode" | ||
| "github.com/go-git/go-git/v6/plumbing/object" | ||
| ) | ||
|
|
||
| func TestWriteStandardCheckpointEntries_WarnsOnUnexpectedSessionZeroOverwrite(t *testing.T) { | ||
| tmpDir := t.TempDir() | ||
| t.Chdir(tmpDir) | ||
|
|
||
| repo, err := git.PlainInit(tmpDir, false) | ||
| if err != nil { | ||
| t.Fatalf("PlainInit() error = %v", err) | ||
| } | ||
| store := NewGitStore(repo) | ||
|
|
||
| if err := logging.Init(context.Background(), ""); err != nil { | ||
| t.Fatalf("logging.Init() error = %v", err) | ||
| } | ||
|
Soph marked this conversation as resolved.
|
||
|
|
||
| checkpointID, err := id.Generate() | ||
| if err != nil { | ||
| t.Fatalf("id.Generate() error = %v", err) | ||
| } | ||
| basePath := checkpointID.Path() + "/" | ||
|
|
||
| oldMetadata := CommittedMetadata{ | ||
| CheckpointID: checkpointID, | ||
| SessionID: "session-old", | ||
| Strategy: "manual-commit", | ||
| CLIVersion: versioninfo.Version, | ||
| } | ||
| oldMetadataJSON, err := jsonutil.MarshalIndentWithNewline(oldMetadata, "", " ") | ||
| if err != nil { | ||
| t.Fatalf("marshal old metadata: %v", err) | ||
| } | ||
| oldMetadataHash, err := CreateBlobFromContent(repo, oldMetadataJSON) | ||
| if err != nil { | ||
| t.Fatalf("CreateBlobFromContent(old metadata) error = %v", err) | ||
| } | ||
|
|
||
| entries := map[string]object.TreeEntry{ | ||
| basePath + "0/" + paths.MetadataFileName: { | ||
| Name: basePath + "0/" + paths.MetadataFileName, | ||
| Mode: filemode.Regular, | ||
| Hash: oldMetadataHash, | ||
| }, | ||
| } | ||
|
|
||
| opts := WriteCommittedOptions{ | ||
| CheckpointID: checkpointID, | ||
| SessionID: "session-new", | ||
| Strategy: "manual-commit", | ||
| Transcript: redact.AlreadyRedacted([]byte("{\"type\":\"user\",\"message\":\"hi\"}\n")), | ||
| Prompts: []string{"hi"}, | ||
| } | ||
|
|
||
| if err := store.writeStandardCheckpointEntries(context.Background(), opts, basePath, entries); err != nil { | ||
| t.Fatalf("writeStandardCheckpointEntries() error = %v", err) | ||
| } | ||
| logging.Close() | ||
|
|
||
| logPath := filepath.Join(tmpDir, logging.LogsDir, "entire.log") | ||
| logData, err := os.ReadFile(logPath) | ||
| if err != nil { | ||
| t.Fatalf("ReadFile(%s) error = %v", logPath, err) | ||
| } | ||
| logText := string(logData) | ||
| if !strings.Contains(logText, "checkpoint write overwrites session 0 with a different sessionID") { | ||
| t.Fatalf("expected tripwire warning in log, got:\n%s", logText) | ||
| } | ||
| if !strings.Contains(logText, "session-old") || !strings.Contains(logText, "session-new") { | ||
| t.Fatalf("expected log to include both session IDs, got:\n%s", logText) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.