feat(api): expose REST-only agent routes
This commit is contained in:
@@ -61,4 +61,79 @@ describe("SessionMetadataStore", () => {
|
||||
);
|
||||
expect(fetched?.title).toBe("新标题");
|
||||
});
|
||||
|
||||
it("does not expose a session across users or projects", async () => {
|
||||
await store.ensure({
|
||||
actorKey: "actor-a",
|
||||
projectId: "project-a",
|
||||
projectKey: "project-key-a",
|
||||
sessionId: "private-session",
|
||||
userId: "user-a",
|
||||
});
|
||||
|
||||
expect(
|
||||
await store.get(
|
||||
{
|
||||
actorKey: "actor-b",
|
||||
projectId: "project-a",
|
||||
projectKey: "project-key-a",
|
||||
userId: "user-b",
|
||||
},
|
||||
"private-session",
|
||||
),
|
||||
).toBeNull();
|
||||
expect(
|
||||
await store.get(
|
||||
{
|
||||
actorKey: "actor-a",
|
||||
projectId: "project-b",
|
||||
projectKey: "project-key-b",
|
||||
userId: "user-a",
|
||||
},
|
||||
"private-session",
|
||||
),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("rejects idempotent creation when the session belongs to another scope", async () => {
|
||||
await store.ensure({
|
||||
actorKey: "actor-a",
|
||||
projectId: "project-a",
|
||||
projectKey: "project-key-a",
|
||||
sessionId: "claimed-session",
|
||||
userId: "user-a",
|
||||
});
|
||||
|
||||
await expect(
|
||||
store.ensure({
|
||||
actorKey: "actor-b",
|
||||
projectId: "project-b",
|
||||
projectKey: "project-key-b",
|
||||
sessionId: "claimed-session",
|
||||
userId: "user-b",
|
||||
}),
|
||||
).rejects.toThrow("session metadata ownership mismatch");
|
||||
});
|
||||
|
||||
it("keeps long session ids with the same slug prefix distinct", async () => {
|
||||
const prefix = "s".repeat(64);
|
||||
const firstSessionId = `${prefix}-first`;
|
||||
const secondSessionId = `${prefix}-second`;
|
||||
const context = {
|
||||
actorKey: "actor-long",
|
||||
projectId: "project-long",
|
||||
projectKey: "project-key-long",
|
||||
userId: "user-long",
|
||||
};
|
||||
|
||||
await store.ensure({ ...context, sessionId: firstSessionId });
|
||||
await store.ensure({ ...context, sessionId: secondSessionId });
|
||||
|
||||
expect((await store.get(context, firstSessionId))?.sessionId).toBe(
|
||||
firstSessionId,
|
||||
);
|
||||
expect((await store.get(context, secondSessionId))?.sessionId).toBe(
|
||||
secondSessionId,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user