Start the Orca Cloud Sync Cursor at Zero (#17263)

Fixes #17256

On a machine with no saved `sync_state`, the first `sync/pull` sent whatever was in memory as `?cursor=`. The server answered 400, nothing was downloaded, and the account's presets never arrived because only a 410 clears the cursor.

`SyncState::last_sync_timestamp` now starts at zero, so a session with no saved state pulls everything. `SyncPullResponse::next_cursor` had the same problem on a 304, where a stray value would have been saved to `sync_state` and sent on every later pull, so it and the other scalars in `ProfileUpsert` and `SyncPushResult` start at zero too.

(cherry picked from commit dd0079ec64)
This commit is contained in:
HanifKoh authored and SoftFever committed 2026-11-07 02:14:51 +08:00
1 parent b39046ad04
commit 2c7d5a4b88
2 files changed
+34 -9

No files matched your search

@@ -876,3 +876,28 @@ TEST_CASE("A delete that fails to reach the gateway keeps its .info for a later
CHECK(fs::exists(fixture.info_path));
CHECK(fixture.queue.size() == 1);
}
TEST_CASE_METHOD(HealthCheckFixture, "A session with no saved sync state pulls without a cursor", "[OrcaCloudServiceAgent]")
{
// Nothing has been pulled yet, so there is no cursor to resume from.
CHECK(agent->get_sync_state().last_sync_timestamp == 0);
sign_in("user-a");
server.set_reply("200 OK", R"({"upserts":[],"deletes":[],"next_cursor":0})");
REQUIRE(agent->get_setting_list2("", nullptr, nullptr, nullptr) == BAMBU_NETWORK_SUCCESS);
const auto requests = server.requests();
REQUIRE(requests.size() == 1);
CHECK(requests.front().request_line == "GET /api/v1/sync/pull HTTP/1.1");
}
TEST_CASE_METHOD(HealthCheckFixture, "A pull answered 304 keeps the sync state it had", "[OrcaCloudServiceAgent]")
{
sign_in("user-a");
server.set_reply("304 Not Modified", "");
REQUIRE(agent->get_setting_list2("", nullptr, nullptr, nullptr) == BAMBU_NETWORK_SUCCESS);
// Nothing changed, so there is still no cursor and none is written for the next session.
CHECK(agent->get_sync_state().last_sync_timestamp == 0);
CHECK_FALSE(fs::exists(dir.path() / "user" / "user-a" / "sync_state"));
}