Add version history with rollback and per-note created/synced info
Server (schema v2, auto-migrates): every accepted overwrite snapshots the
superseded revision into note_history (capped at 50 per note); new
GET /api/v1/notes/{id}/history endpoint; compact purges orphaned history.
Client: notes get a synced_at stamp on every confirmed server exchange;
an info footer under the editor and a Ctrl/Cmd+I panel show created/
modified/last-synced plus the revision list. Restoring a revision applies
it as a normal edit through the sync path, so rollback is non-destructive.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -229,6 +229,45 @@ func TestTwoClientsConverge(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHistoryEndpoint(t *testing.T) {
|
||||
srv, tok := newTestServer(t)
|
||||
a := newClient(t, srv.URL, tok)
|
||||
|
||||
a.edit("n1", "v1")
|
||||
a.sync()
|
||||
a.edit("n1", "v2")
|
||||
a.notes["n1"].ModifiedAt = 2
|
||||
a.sync()
|
||||
|
||||
var body struct {
|
||||
Revisions []store.Revision `json:"revisions"`
|
||||
}
|
||||
if code := a.req("GET", "/api/v1/notes/n1/history", nil, &body); code != 200 {
|
||||
t.Fatalf("history HTTP %d", code)
|
||||
}
|
||||
if len(body.Revisions) != 1 || body.Revisions[0].Content != "v1" {
|
||||
t.Fatalf("history: %+v", body.Revisions)
|
||||
}
|
||||
|
||||
// Unknown note → empty list, not an error.
|
||||
if code := a.req("GET", "/api/v1/notes/nope/history", nil, &body); code != 200 {
|
||||
t.Fatalf("unknown note HTTP %d", code)
|
||||
}
|
||||
if len(body.Revisions) != 0 {
|
||||
t.Fatalf("want empty history, got %+v", body.Revisions)
|
||||
}
|
||||
|
||||
// Auth required.
|
||||
res, err := http.Get(srv.URL + "/api/v1/notes/n1/history")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
res.Body.Close()
|
||||
if res.StatusCode != http.StatusUnauthorized {
|
||||
t.Fatalf("want 401, got %d", res.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeleteEditConflictAcrossClients(t *testing.T) {
|
||||
srv, tok := newTestServer(t)
|
||||
a := newClient(t, srv.URL, tok)
|
||||
|
||||
Reference in New Issue
Block a user