mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-06 07:38:47 +01:00
Reconcile Cloud membership and credential wake producers
Keep the coalesced membership lock separate from per-request authority reads and supply the company scope on the upstream credential-change path. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
e50a5148a2
commit
89bf37f557
2 files changed
+7
-5
No files matched your search
@@ -46,7 +46,7 @@ function createFakeDb(options: {
|
||||
: options.settingsRow;
|
||||
const insertedTables: unknown[] = [];
|
||||
const deletedTables: unknown[] = [];
|
||||
const selectWheres: Array<{ table: unknown; condition: unknown }> = [];
|
||||
const selectWheres: Array<{ table: unknown; condition: unknown; locked?: boolean }> = [];
|
||||
function writeChain(table: unknown) {
|
||||
let values: unknown;
|
||||
const chain: Record<string, unknown> = {};
|
||||
@@ -81,7 +81,8 @@ function createFakeDb(options: {
|
||||
if (options.selectThrows && table === instanceSettings) {
|
||||
throw new Error("select unavailable");
|
||||
}
|
||||
selectWheres.push({ table, condition });
|
||||
const selected: (typeof selectWheres)[number] = { table, condition };
|
||||
selectWheres.push(selected);
|
||||
const rows =
|
||||
table === instanceSettings && settingsRow
|
||||
? [settingsRow]
|
||||
@@ -90,7 +91,7 @@ function createFakeDb(options: {
|
||||
: [];
|
||||
let locked = false;
|
||||
const result = {
|
||||
for: () => { locked = true; return result; },
|
||||
for: () => { locked = true; selected.locked = true; return result; },
|
||||
then: (resolve: (v: unknown) => unknown, reject?: (error: unknown) => unknown) => {
|
||||
// The optional cross-company read can fail independently of
|
||||
// the primary membership transaction, which must succeed.
|
||||
@@ -269,7 +270,8 @@ describe("resolveCloudTenantActor (shared-pool hardening)", () => {
|
||||
expect(insertedTables.filter(table => table === companyMemberships)).toHaveLength(1);
|
||||
expect(deletedTables.filter(table => table === instanceUserRoles)).toHaveLength(20);
|
||||
expect(selectWheres.filter(entry => entry.table === instanceSettings)).toHaveLength(20);
|
||||
expect(selectWheres.filter(entry => entry.table === companyMemberships)).toHaveLength(20);
|
||||
expect(selectWheres.filter(entry => entry.table === companyMemberships && !entry.locked)).toHaveLength(20);
|
||||
expect(selectWheres.filter(entry => entry.table === companyMemberships && entry.locked)).toHaveLength(1);
|
||||
expect(actors.every(actor => actor?.memberships?.[0]?.membershipRole === "owner")).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
@@ -383,7 +383,7 @@ export function createChatCredentials(db: Db, options: ChatCredentialsOptions) {
|
||||
.set({ credentialSecretRefs: refs, updatedAt: new Date() })
|
||||
.where(eq(toolConnections.id, endpoint.connectionId));
|
||||
if (changedFields.length) {
|
||||
await notifyChatEndpointWork(tx, endpoint.connectionId);
|
||||
await notifyChatEndpointWork(tx, endpoint.connectionId, endpoint.companyId);
|
||||
const [currentEndpoint] = await tx.select({ setup: chatEndpoints.setup }).from(chatEndpoints)
|
||||
.where(and(eq(chatEndpoints.id, endpoint.id), eq(chatEndpoints.companyId, endpoint.companyId))).for("update");
|
||||
if (!currentEndpoint) throw notFound("Chat endpoint not found");
|
||||
|
||||
Reference in new issue
Block a user