Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/sync-get-latest-commit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@getcirrus/pds": minor
---

Implement `com.atproto.sync.getLatestCommit`.

This sync XRPC endpoint was previously unimplemented, so requests fell through to the XRPC proxy and returned `501 MethodNotImplemented`. Relays call `getLatestCommit` during their crawl bootstrap, so a freshly created repo could never be indexed by a fresh `requestCrawl`. The endpoint now returns the repo's head commit as `{ cid, rev }` (sourced from the same `rpcGetRepoStatus` data used by `getRepoStatus`/`listRepos`).
3 changes: 3 additions & 0 deletions packages/pds/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ app.get("/xrpc/com.atproto.sync.getRepo", (c) =>
app.get("/xrpc/com.atproto.sync.getRepoStatus", (c) =>
sync.getRepoStatus(c, getAccountDO(c.env)),
);
app.get("/xrpc/com.atproto.sync.getLatestCommit", (c) =>
sync.getLatestCommit(c, getAccountDO(c.env)),
);
app.get("/xrpc/com.atproto.sync.getBlocks", (c) =>
sync.getBlocks(c, getAccountDO(c.env)),
);
Expand Down
49 changes: 49 additions & 0 deletions packages/pds/src/xrpc/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,55 @@ export async function listRepos(
});
}

export async function getLatestCommit(
c: Context<AppEnv>,
accountDO: DurableObjectStub<AccountDurableObject>,
): Promise<Response> {
const did = c.req.query("did");

if (!did) {
return c.json(
{
error: "InvalidRequest",
message: "Missing required parameter: did",
},
400,
);
}

// Validate DID format
if (!isDid(did)) {
return c.json(
{ error: "InvalidRequest", message: "Invalid DID format" },
400,
);
}

if (did !== c.env.DID) {
return c.json(
{
error: "RepoNotFound",
message: `Repository not found for DID: ${did}`,
},
404,
);
}

const [data, active] = await Promise.all([
accountDO.rpcGetRepoStatus(),
accountDO.rpcGetActive(),
]);

if (!active) {
return c.json(
{ error: "RepoDeactivated", message: "Repository has been deactivated" },
400,
);
}

return c.json({ cid: data.head, rev: data.rev });
}

export async function listBlobs(
c: Context<AppEnv>,
_accountDO: DurableObjectStub<AccountDurableObject>,
Expand Down
40 changes: 40 additions & 0 deletions packages/pds/test/xrpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,46 @@ describe("XRPC Endpoints", () => {
expect(data.status).toBeUndefined();
});

it("should get latest commit", async () => {
const response = await worker.fetch(
new Request(
`http://pds.test/xrpc/com.atproto.sync.getLatestCommit?did=${env.DID}`,
),
env,
);
expect(response.status).toBe(200);

const data = (await response.json()) as Record<string, unknown>;
expect(data).toMatchObject({
cid: expect.any(String),
rev: expect.any(String),
});
});

it("should reject getLatestCommit without a did", async () => {
const response = await worker.fetch(
new Request("http://pds.test/xrpc/com.atproto.sync.getLatestCommit"),
env,
);
expect(response.status).toBe(400);

const data = (await response.json()) as Record<string, unknown>;
expect(data.error).toBe("InvalidRequest");
});

it("should return RepoNotFound for an unknown did on getLatestCommit", async () => {
const response = await worker.fetch(
new Request(
"http://pds.test/xrpc/com.atproto.sync.getLatestCommit?did=did:web:unknown.example.com",
),
env,
);
expect(response.status).toBe(404);

const data = (await response.json()) as Record<string, unknown>;
expect(data.error).toBe("RepoNotFound");
});

it("should return deactivated status when account is inactive", async () => {
const deactivateResponse = await worker.fetch(
new Request(
Expand Down
Loading