Keep one snapshot per session instead of one globally

Indexing used to discard every existing snapshot, so concurrent users
wiped out each other's landscapes. Only the same session's previous
snapshot and workspace are replaced now.
This commit is contained in:
Andy Dixon
2026-02-15 18:15:47 +00:00
parent 26800b9b66
commit 25e2d2f390
2 changed files with 43 additions and 4 deletions
+37
View File
@@ -286,3 +286,40 @@ func TestSessionCookieFlags(t *testing.T) {
}
}
}
// indexLocal uploads files as a local job and waits for the snapshot.
func (c client) indexLocal(files map[string]string) (jobID, snapshotID string) {
c.t.Helper()
var created struct{ JobID string }
c.json("POST", "/api/jobs", `{"kind":"local"}`, 201, &created)
for path, content := range files {
c.json("POST", "/api/jobs/"+created.JobID+"/files?path="+path, content, 200, nil)
}
c.json("POST", "/api/jobs/"+created.JobID+"/commit", "", 202, nil)
status, raw := c.do("GET", "/api/jobs/"+created.JobID+"/events", "")
var job Job
for line := range strings.Lines(string(raw)) {
if data, ok := strings.CutPrefix(line, "data: "); ok {
json.Unmarshal([]byte(data), &job)
}
}
if status != 200 || job.SnapshotID == nil {
c.t.Fatalf("job did not finish: %d %+v", status, job)
}
return created.JobID, *job.SnapshotID
}
func TestSessionsKeepIndependentSnapshots(t *testing.T) {
server, alice := newTestServer(t)
bob := alice.stranger()
_, aliceFirst := alice.indexLocal(map[string]string{"a.go": "package a"})
_, bobSnapshot := bob.indexLocal(map[string]string{"b.go": "package b"})
_, aliceSecond := alice.indexLocal(map[string]string{"c.go": "package c"})
alice.json("GET", "/api/snapshots/"+aliceFirst, "", 404, nil)
alice.json("GET", "/api/snapshots/"+aliceSecond, "", 200, nil)
bob.json("GET", "/api/snapshots/"+bobSnapshot, "", 200, nil)
if len(server.snapshots) != 2 {
t.Fatalf("snapshots = %d, want 2", len(server.snapshots))
}
}