Skip to content

Commit 79a6877

Browse files
committed
test(runtime): fixture members enter through the operator door
Claude-Session: https://claude.ai/code/session_01QSeKYn5CmmdShCJifm6WYj Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3536fcf commit 79a6877

4 files changed

Lines changed: 71 additions & 74 deletions

‎packages/runtime/src/declarative-update-refusal-order.pin.test.ts‎

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import type { Plugin, PluginContext } from '@objectstack/core';
4848
import { ObjectQLPlugin } from '@objectstack/objectql';
4949
import { HonoServerPlugin } from '@objectstack/plugin-hono-server';
5050
import { createRestApiPlugin } from '@objectstack/rest';
51-
import { AuthPlugin } from '@objectstack/plugin-auth';
51+
import { AuthManager, AuthPlugin } from '@objectstack/plugin-auth';
5252
import { SecurityPlugin, appSecurityPluginOptions } from '@objectstack/plugin-security';
5353
import { SharingServicePlugin } from '@objectstack/plugin-sharing';
5454
import { PlatformObjectsPlugin } from '@objectstack/platform-objects/plugin';
@@ -215,25 +215,23 @@ async function signIn(who: { email: string; password: string }): Promise<string>
215215
}
216216

217217
async function signUpMember(who: { email: string; password: string }, n: number): Promise<string> {
218-
// Default audience posture is invite_only: enter through a pending invitation.
219-
await engine.insert(
220-
'sys_invitation',
221-
{
222-
id: `inv_pin_30848_${n}`,
223-
email: who.email,
224-
status: 'pending',
225-
organization_id: ORG,
226-
role: 'member',
227-
inviter_id: 'usr_pin_30848',
228-
expires_at: new Date(Date.now() + 3_600_000),
229-
},
230-
{ context: { isSystem: true } },
231-
);
232-
const res = await req('/auth/sign-up/email', {
233-
method: 'POST',
234-
headers: { 'Content-Type': 'application/json' },
235-
body: JSON.stringify({ email: who.email, password: who.password, name: `pin member ${n}`, invitationId: `inv_pin_30848_${n}` }),
236-
});
218+
// Default audience posture is invite_only. A member bound at creation enters
219+
// through the operator door — the ticket the stack's own auth manager stages
220+
// for exactly this address, as `@objectstack/verify`'s signUp mints its
221+
// member. A sign-up admitted by the invitation it presents joins no
222+
// organization until it verifies its address and accepts.
223+
const auth: any = await kernel.getServiceAsync('auth');
224+
const ticket = auth.stageOperatorProvisioning(who.email);
225+
let res: Response;
226+
try {
227+
res = await req('/auth/sign-up/email', {
228+
method: 'POST',
229+
headers: { 'Content-Type': 'application/json' },
230+
body: JSON.stringify({ email: who.email, password: who.password, name: `pin member ${n}`, [AuthManager.OPERATOR_PROVISIONING_TICKET_FIELD]: ticket }),
231+
});
232+
} finally {
233+
auth.clearOperatorProvisioning(who.email);
234+
}
237235
if (!res.ok) throw new Error(`pin signUp failed: ${res.status} ${await res.text()}`);
238236
return (await res.json() as any).token;
239237
}

‎packages/runtime/src/mcp-list-objects-statements.pin.test.ts‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { ObjectKernel, assembleExecutionContext, type Plugin, type PluginContext
4949
import { ObjectQLPlugin } from '@objectstack/objectql';
5050
import { HonoServerPlugin } from '@objectstack/plugin-hono-server';
5151
import { createRestApiPlugin } from '@objectstack/rest';
52-
import { AuthPlugin } from '@objectstack/plugin-auth';
52+
import { AuthManager, AuthPlugin } from '@objectstack/plugin-auth';
5353
import { SecurityPlugin, appSecurityPluginOptions } from '@objectstack/plugin-security';
5454
import { SharingServicePlugin } from '@objectstack/plugin-sharing';
5555
import { PlatformObjectsPlugin } from '@objectstack/platform-objects/plugin';
@@ -269,16 +269,22 @@ beforeAll(async () => {
269269
statements.getStore()?.push(String(q?.sql ?? ''));
270270
});
271271
const owner = await personContext(await signIn(OWNER));
272-
// The default audience posture is invite_only: the member enters the
273-
// owner's organization through a pending invitation.
274-
await engine.insert('sys_invitation', {
275-
id: 'inv_pin_33179', email: MEMBER.email, status: 'pending', organization_id: owner.tenantId,
276-
role: 'member', inviter_id: owner.userId, expires_at: new Date(Date.now() + 3_600_000),
277-
}, { context: { isSystem: true } });
278-
const signUp = await app.request(`${ORIGIN}${API}/auth/sign-up/email`, {
279-
method: 'POST', headers: { 'Content-Type': 'application/json' },
280-
body: JSON.stringify({ ...MEMBER, invitationId: 'inv_pin_33179' }),
281-
});
272+
// The default audience posture is invite_only. The member is bound to the
273+
// owner's organization at creation through the operator door — the ticket
274+
// the stack's own auth manager stages for exactly this address. A sign-up
275+
// admitted by the invitation it presents joins no organization until it
276+
// verifies its address and accepts.
277+
const auth: any = await kernel.getServiceAsync('auth');
278+
const ticket = auth.stageOperatorProvisioning(MEMBER.email);
279+
let signUp: Response;
280+
try {
281+
signUp = await app.request(`${ORIGIN}${API}/auth/sign-up/email`, {
282+
method: 'POST', headers: { 'Content-Type': 'application/json' },
283+
body: JSON.stringify({ ...MEMBER, [AuthManager.OPERATOR_PROVISIONING_TICKET_FIELD]: ticket }),
284+
});
285+
} finally {
286+
auth.clearOperatorProvisioning(MEMBER.email);
287+
}
282288
expect(signUp.status, await signUp.clone().text()).toBe(200);
283289
const member = await personContext(await signIn(MEMBER));
284290
callers = { owner, member, ownerAgent: agentFor(owner), memberAgent: agentFor(member) };

‎packages/runtime/src/plugin-driver-external-object.spike.test.ts‎

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import type { DriverQuery, IDataDriver, IExternalDatasourceService } from '@obje
4242
import { ObjectQLPlugin, EXTERNAL_ROW_CAP, unwrapExternalDriverFloor } from '@objectstack/objectql';
4343
import { HonoServerPlugin } from '@objectstack/plugin-hono-server';
4444
import { createRestApiPlugin } from '@objectstack/rest';
45-
import { AuthPlugin } from '@objectstack/plugin-auth';
45+
import { AuthManager, AuthPlugin } from '@objectstack/plugin-auth';
4646
import { SecurityPlugin, appSecurityPluginOptions, RLS_DENY_FILTER } from '@objectstack/plugin-security';
4747
import { SharingServicePlugin } from '@objectstack/plugin-sharing';
4848
import { PlatformObjectsPlugin } from '@objectstack/platform-objects/plugin';
@@ -369,28 +369,25 @@ async function signIn(email: string, password: string): Promise<string> {
369369
}
370370

371371
/**
372-
* A second human under the default `invite_only` audience posture enters
373-
* through a pending invitation, as `@objectstack/verify`'s `signUp` does.
372+
* A second human under the default `invite_only` audience posture, bound to
373+
* the organization at creation: the operator door — the ticket the stack's
374+
* own auth manager stages for exactly this address — as `@objectstack/verify`'s
375+
* `signUp` mints its member. A sign-up admitted by the invitation it presents
376+
* joins no organization until it verifies its address and accepts.
374377
*/
375378
async function signUp(email: string): Promise<string> {
376-
await engine.insert(
377-
'sys_invitation',
378-
{
379-
id: `inv_spike_${email.split('@')[0]}`,
380-
email,
381-
status: 'pending',
382-
organization_id: 'org_spike_audience_gate',
383-
role: 'member',
384-
inviter_id: 'usr_spike_audience_gate',
385-
expires_at: new Date(Date.now() + 3_600_000),
386-
},
387-
{ context: { isSystem: true } },
388-
);
389-
const res = await req('/auth/sign-up/email', {
390-
method: 'POST',
391-
headers: { 'Content-Type': 'application/json' },
392-
body: JSON.stringify({ email, password: MEMBER_PASSWORD, name: email.split('@')[0], invitationId: `inv_spike_${email.split('@')[0]}` }),
393-
});
379+
const auth: any = await kernel.getServiceAsync('auth');
380+
const ticket = auth.stageOperatorProvisioning(email);
381+
let res: Response;
382+
try {
383+
res = await req('/auth/sign-up/email', {
384+
method: 'POST',
385+
headers: { 'Content-Type': 'application/json' },
386+
body: JSON.stringify({ email, password: MEMBER_PASSWORD, name: email.split('@')[0], [AuthManager.OPERATOR_PROVISIONING_TICKET_FIELD]: ticket }),
387+
});
388+
} finally {
389+
auth.clearOperatorProvisioning(email);
390+
}
394391
if (!res.ok) throw new Error(`spike signUp failed: ${res.status} ${await res.text()}`);
395392
return ((await res.json()) as any).token;
396393
}

‎packages/runtime/src/stored-metadata-reader-contexts.pin.test.ts‎

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import { ObjectQLPlugin } from '@objectstack/objectql';
6363
import type { ObjectQL } from '@objectstack/objectql';
6464
import { HonoServerPlugin } from '@objectstack/plugin-hono-server';
6565
import { createRestApiPlugin } from '@objectstack/rest';
66-
import { AuthPlugin } from '@objectstack/plugin-auth';
66+
import { AuthManager, AuthPlugin } from '@objectstack/plugin-auth';
6767
import { SecurityPlugin, appSecurityPluginOptions } from '@objectstack/plugin-security';
6868
import { SharingServicePlugin } from '@objectstack/plugin-sharing';
6969
import { PlatformObjectsPlugin } from '@objectstack/platform-objects/plugin';
@@ -384,27 +384,23 @@ async function signIn(who: { email: string; password: string }): Promise<string>
384384
}
385385

386386
async function signUpMember(): Promise<string> {
387-
// Default audience posture is invite_only: enter through a pending invitation,
388-
// the same lane `@objectstack/verify`'s signUp takes.
389-
const engine: any = await kernel.getServiceAsync('objectql');
390-
await engine.insert(
391-
'sys_invitation',
392-
{
393-
id: 'inv_pin_21454',
394-
email: MEMBER.email,
395-
status: 'pending',
396-
organization_id: 'org_pin_audience_gate',
397-
role: 'member',
398-
inviter_id: 'usr_pin_audience_gate',
399-
expires_at: new Date(Date.now() + 3_600_000),
400-
},
401-
{ context: { isSystem: true } },
402-
);
403-
const res = await req('/auth/sign-up/email', {
404-
method: 'POST',
405-
headers: { 'Content-Type': 'application/json' },
406-
body: JSON.stringify({ email: MEMBER.email, password: MEMBER.password, name: 'pin member', invitationId: 'inv_pin_21454' }),
407-
});
387+
// Default audience posture is invite_only. A member bound at creation enters
388+
// through the operator door — the ticket the stack's own auth manager stages
389+
// for exactly this address, the lane `@objectstack/verify`'s signUp takes. A
390+
// sign-up admitted by the invitation it presents joins no organization until
391+
// it verifies its address and accepts.
392+
const auth: any = await kernel.getServiceAsync('auth');
393+
const ticket = auth.stageOperatorProvisioning(MEMBER.email);
394+
let res: Response;
395+
try {
396+
res = await req('/auth/sign-up/email', {
397+
method: 'POST',
398+
headers: { 'Content-Type': 'application/json' },
399+
body: JSON.stringify({ email: MEMBER.email, password: MEMBER.password, name: 'pin member', [AuthManager.OPERATOR_PROVISIONING_TICKET_FIELD]: ticket }),
400+
});
401+
} finally {
402+
auth.clearOperatorProvisioning(MEMBER.email);
403+
}
408404
if (!res.ok) throw new Error(`pin signUp failed: ${res.status} ${await res.text()}`);
409405
const data: any = await res.json();
410406
return data.token;

0 commit comments

Comments
 (0)