Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(control-api): prove seven-day setup resend expiry (R1-L1)

Josué5ec54cb5e1b0
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 41ca58423..11a4080f9 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.828",
+ "version": "0.1.830",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.828",
+ "version": "0.1.830",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",
diff --git a/control-api/package.json b/control-api/package.json
index f54b934cc..b43cb6d2b 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.828",
+ "version": "0.1.830",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/test/passwordResetInvitations.realPostgres.integration.test.ts b/control-api/test/passwordResetInvitations.realPostgres.integration.test.ts
index 59a015e68..35828db9d 100644
--- a/control-api/test/passwordResetInvitations.realPostgres.integration.test.ts
+++ b/control-api/test/passwordResetInvitations.realPostgres.integration.test.ts
@@ -4,6 +4,7 @@ import { Pool } from 'pg'
import { initDb } from '../src/db.js'
import {
createInvitationForTeams,
+ createPasswordSetupInvitationForUser,
createSilentInvitationForTeams,
} from '../src/services/directory/membership.js'
import {
@@ -129,6 +130,40 @@ realPg('password reset issuance ownership on PostgreSQL 16', () => {
expect(sender).toHaveBeenCalledTimes(1)
})
+ it('resends password setup as a seven-day member invitation without changing the accepted row', async () => {
+ const user = await principal()
+ const acceptedExpiry = new Date(Date.now() + 9 * 24 * 60 * 60 * 1000)
+ const accepted = await local.query(
+ `INSERT INTO invitations
+ (email, invitee_name, role, token, status, purpose, accepted_at, accepted_user_id, expires_at)
+ VALUES ($1, 'Captured display name', 'member', $2, 'accepted', 'member_invitation', NOW(), $3, $4)
+ RETURNING id, expires_at`,
+ [user.email, randomBytes(12).toString('hex'), user.id, acceptedExpiry]
+ )
+ const acceptedRow = accepted.rows[0] as { id: string; expires_at: Date }
+
+ await expect(createPasswordSetupInvitationForUser(user.id)).resolves.toMatchObject({
+ sent: true,
+ email: user.email,
+ })
+
+ const invitationRows = await rows(user.email)
+ const resent = invitationRows.find(row => row.id !== acceptedRow.id)
+ expect(resent).toMatchObject({ purpose: 'member_invitation', status: 'pending' })
+ expect(resent.expires_at.getTime() - resent.created_at.getTime()).toBe(168 * 60 * 60 * 1000)
+ expect(invitationRows.find(row => row.id === acceptedRow.id)?.expires_at.getTime()).toBe(
+ acceptedRow.expires_at.getTime()
+ )
+ expect(sender).toHaveBeenCalledWith(
+ user.email,
+ resent.token,
+ null,
+ resent.created_at.toISOString(),
+ resent.expires_at.toISOString(),
+ { purpose: 'member_invitation', teamNames: [] }
+ )
+ })
+
it('uses the same real lock/insert in silent mode without dispatch', async () => {
const user = await principal()
const row = await createSilentPasswordResetInvitation({
diff --git a/control-api/test/services.invitationTtl.test.ts b/control-api/test/services.invitationTtl.test.ts
new file mode 100644
index 000000000..d4983cab4
--- /dev/null
+++ b/control-api/test/services.invitationTtl.test.ts
@@ -0,0 +1,71 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+import { insertInvitationForTeams } from '../src/services/directory/invitationStore.js'
+
+const dbModule = vi.hoisted(() => ({
+ poolQuery: vi.fn(),
+}))
+
+vi.mock('../src/db.js', () => ({
+ pool: { query: dbModule.poolQuery },
+}))
+
+describe('invitation expiration policy', () => {
+ beforeEach(() => {
+ dbModule.poolQuery.mockReset()
+ })
+
+ async function insert(purpose?: 'member_invitation' | 'password_reset') {
+ const normalizedPurpose = purpose || 'member_invitation'
+ const createdAt = new Date('2026-10-26T12:00:00.000Z')
+ const query = vi.fn(async (sql: string) => {
+ if (sql.includes('WITH inserted AS')) {
+ return {
+ rows: [
+ {
+ id: 'invitation-1',
+ team_id: null,
+ invitee_name: 'Setup member',
+ email: '[email protected]',
+ role: 'member',
+ token: 'invitation-token',
+ status: 'pending',
+ purpose: normalizedPurpose,
+ created_at: createdAt,
+ expires_at: new Date(createdAt.getTime() + 7 * 24 * 60 * 60 * 1000),
+ accepted_at: null,
+ accepted_user_id: null,
+ team_name: null,
+ },
+ ],
+ rowCount: 1,
+ }
+ }
+ if (sql.includes('FROM invitation_teams it')) return { rows: [], rowCount: 0 }
+ throw new Error(`unexpected invitation query: ${sql}`)
+ })
+
+ const result = await insertInvitationForTeams(
+ { query },
+ {
+ inviteeName: 'Setup member',
+ email: '[email protected]',
+ purpose,
+ status: 'pending',
+ }
+ )
+ const insertValues = query.mock.calls[0]?.[1] as unknown[]
+ return { result, insertValues }
+ }
+
+ it('uses seven days for password-setup resends and 48 hours for dedicated resets', async () => {
+ const setup = await insert()
+ expect(setup.result.invitation.purpose).toBe('member_invitation')
+ expect(setup.insertValues[5]).toBe('member_invitation')
+ expect(setup.insertValues[6]).toBe('168')
+
+ const reset = await insert('password_reset')
+ expect(reset.result.invitation.purpose).toBe('password_reset')
+ expect(reset.insertValues[5]).toBe('password_reset')
+ expect(reset.insertValues[6]).toBe('48')
+ })
+})