Skip to content

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

TypeScript

test(desktop): r1-m3 add pending-link state properties

Josué3cef65db1c95
diff --git a/desktop-app/package-lock.json b/desktop-app/package-lock.json
index 961298c21..217be56ab 100644
--- a/desktop-app/package-lock.json
+++ b/desktop-app/package-lock.json
@@ -40,6 +40,7 @@
"concurrently": "^9.2.1",
"cross-env": "^10.0.0",
"electron": "^41.3.0",
+ "fast-check": "^4.9.0",
"jsdom": "^29.0.2",
"typescript": "^5.9.2",
"vite": "^7.1.7",
@@ -6993,6 +6994,29 @@
"@types/yauzl": "^2.9.1"
}
},
+ "node_modules/fast-check": {
+ "version": "4.9.0",
+ "resolved": "https://registry.npmjs.org/fast-check/-/fast-check-4.9.0.tgz",
+ "integrity": "sha512-7ms6T7SybUev/PQITciI0yLM2pOSFy5zpG8Ty7tQofcVaQUvrMXp6CBwqF6fThLCLOrfBtuHAtwq6Yu4XPCllg==",
+ "dev": true,
+ "funding": [
+ {
+ "type": "individual",
+ "url": "https://github.com/sponsors/dubzzz"
+ },
+ {
+ "type": "opencollective",
+ "url": "https://opencollective.com/fast-check"
+ }
+ ],
+ "license": "MIT",
+ "dependencies": {
+ "pure-rand": "^8.0.0"
+ },
+ "engines": {
+ "node": ">=12.17.0"
+ }
+ },
"node_modules/fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
@@ -11053,6 +11077,23 @@
"node": ">=6"
}
},
+ "node_modules/pure-rand": {
+ "version": "8.4.2",
+ "resolved": "https://registry.npmjs.org/pure-rand/-/pure-rand-8.4.2.tgz",
+ "integrity": "sha512-vvuOGgcuPJAirlHvuQw1TrOiw7ptaIXXmIbNuiNOY6lNGJJH49PQ1Kj4nd783nPdQhQdicgOjVI2yI/9BD6/Ng==",
+ "dev": true,
+ "funding": [
+ {
+ "type": "individual",
+ "url": "https://github.com/sponsors/dubzzz"
+ },
+ {
+ "type": "opencollective",
+ "url": "https://opencollective.com/fast-check"
+ }
+ ],
+ "license": "MIT"
+ },
"node_modules/queue-microtask": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",
diff --git a/desktop-app/package.json b/desktop-app/package.json
index f95c2947a..bc9ba85c2 100644
--- a/desktop-app/package.json
+++ b/desktop-app/package.json
@@ -73,6 +73,7 @@
"concurrently": "^9.2.1",
"cross-env": "^10.0.0",
"electron": "^41.3.0",
+ "fast-check": "^4.9.0",
"jsdom": "^29.0.2",
"typescript": "^5.9.2",
"vite": "^7.1.7",
diff --git a/desktop-app/ui/src/lib/__tests__/sandboxUiDeepLinkState.test.ts b/desktop-app/ui/src/lib/__tests__/sandboxUiDeepLinkState.test.ts
index 47b9a8359..54f98fafc 100644
--- a/desktop-app/ui/src/lib/__tests__/sandboxUiDeepLinkState.test.ts
+++ b/desktop-app/ui/src/lib/__tests__/sandboxUiDeepLinkState.test.ts
@@ -1,5 +1,8 @@
import { describe, expect, it } from 'vitest'
-import type { PendingSandboxUiDeepLink } from '@/App.types'
+import fc from 'fast-check'
+import type { SandboxUiConversationOrigin } from '@pages/SandboxUiPage.types'
+import type { PendingSandboxUiDeepLink, SandboxUiDeepLinkEnvelope } from '@/App.types'
+import { SandboxUiDeepLinkQueue } from '../../../../src/sandboxUiDeepLinkQueue.js'
import {
MAX_PENDING_SANDBOX_UI_DEEP_LINKS,
MAX_SANDBOX_UI_DEEP_LINK_RETRY_ATTEMPTS,
@@ -15,6 +18,146 @@ import {
shouldPurgeSandboxUiDeepLinks,
} from '../sandboxUiDeepLinkState'
+type LinkOperation = {
+ conversationOrigin: SandboxUiConversationOrigin | null
+ link: SandboxUiDeepLinkEnvelope
+ receivedIdentity: string | null
+}
+
+type TargetParts = {
+ name: string
+ path?: string
+ teamId?: string
+}
+
+const lowerAlpha = [...'abcdefghijklmnopqrstuvwxyz']
+const lowerAlphaNumericDash = [...'abcdefghijklmnopqrstuvwxyz0123456789-']
+
+const segmentArb = fc
+ .tuple(
+ fc.constantFrom(...lowerAlpha),
+ fc.array(fc.constantFrom(...lowerAlphaNumericDash), { maxLength: 10 })
+ )
+ .map(([first, rest]) => `${first}${rest.join('')}`)
+
+const routePathArb = fc.oneof(
+ fc.constant(undefined),
+ fc.constant('/'),
+ fc.array(segmentArb, { minLength: 1, maxLength: 4 }).map(segments => `/${segments.join('/')}`)
+)
+
+const teamIdArb = fc.oneof(
+ fc.constant(undefined),
+ segmentArb.map(segment => `team-${segment}`)
+)
+
+const targetPartsArb: fc.Arbitrary<TargetParts> = fc.record({
+ name: segmentArb,
+ path: routePathArb,
+ teamId: teamIdArb,
+})
+
+const conversationOriginArb: fc.Arbitrary<SandboxUiConversationOrigin | null> = fc.oneof(
+ fc.constant(null),
+ fc.record({
+ agentName: segmentArb,
+ chatId: segmentArb.map(segment => `chat-${segment}`),
+ teamId: fc.oneof(
+ fc.constant(undefined),
+ segmentArb.map(segment => `team-${segment}`)
+ ),
+ title: segmentArb,
+ })
+)
+
+const receivedIdentityArb = fc.constantFrom<string | null>(null, 'user-a', 'user-b', 'user-c')
+
+function producerEnvelopes(parts: TargetParts[]): SandboxUiDeepLinkEnvelope[] {
+ const queue = new SandboxUiDeepLinkQueue(parts.length + 1)
+ return parts.map((part, index) =>
+ queue.enqueue({
+ appRef: `sandbox-recipes/${part.name}-${index}`,
+ path: part.path,
+ teamId: part.teamId,
+ })
+ )
+}
+
+function linkOperationArb(): fc.Arbitrary<LinkOperation> {
+ return fc
+ .tuple(targetPartsArb, conversationOriginArb, receivedIdentityArb)
+ .map(([parts, conversationOrigin, receivedIdentity]) => ({
+ conversationOrigin,
+ link: producerEnvelopes([parts])[0]!,
+ receivedIdentity,
+ }))
+}
+
+function producerBackedInterleavingsArb(): fc.Arbitrary<LinkOperation[]> {
+ return fc
+ .array(targetPartsArb, { minLength: 1, maxLength: MAX_PENDING_SANDBOX_UI_DEEP_LINKS + 15 })
+ .chain(parts => {
+ const envelopes = producerEnvelopes(parts)
+ return fc
+ .array(
+ fc.record({
+ conversationOrigin: conversationOriginArb,
+ envelopeIndex: fc.integer({ min: 0, max: envelopes.length - 1 }),
+ receivedIdentity: receivedIdentityArb,
+ }),
+ { maxLength: MAX_PENDING_SANDBOX_UI_DEEP_LINKS + 30 }
+ )
+ .map(records =>
+ records.map(record => ({
+ conversationOrigin: record.conversationOrigin,
+ link: envelopes[record.envelopeIndex]!,
+ receivedIdentity: record.receivedIdentity,
+ }))
+ )
+ })
+}
+
+function enqueueOperations(operations: LinkOperation[]): PendingSandboxUiDeepLink[] {
+ return operations.reduce<PendingSandboxUiDeepLink[]>(
+ (pending, operation) =>
+ enqueuePendingSandboxUiDeepLink(
+ pending,
+ operation.link,
+ operation.conversationOrigin,
+ operation.receivedIdentity
+ ),
+ []
+ )
+}
+
+function expectedRetainedOperations(operations: LinkOperation[]): LinkOperation[] {
+ const firstById = new Map<number, LinkOperation>()
+ operations.forEach(operation => {
+ if (!firstById.has(operation.link.id)) {
+ firstById.set(operation.link.id, operation)
+ }
+ })
+ return [...firstById.values()]
+ .sort((left, right) => left.link.id - right.link.id)
+ .slice(-MAX_PENDING_SANDBOX_UI_DEEP_LINKS)
+}
+
+function comparablePending(pending: PendingSandboxUiDeepLink[]) {
+ return pending.map(item => ({
+ conversationOrigin: item.conversationOrigin,
+ link: item.link,
+ receivedIdentity: item.receivedIdentity,
+ }))
+}
+
+function comparableOperations(operations: LinkOperation[]) {
+ return operations.map(operation => ({
+ conversationOrigin: operation.conversationOrigin,
+ link: operation.link,
+ receivedIdentity: operation.receivedIdentity,
+ }))
+}
+
describe('shouldPurgeSandboxUiDeepLinks', () => {
it('keeps a cold-start link as pending user intent while the first user authenticates', () => {
expect(shouldPurgeSandboxUiDeepLinks(undefined, null)).toBe(false)
@@ -101,4 +244,66 @@ describe('pending sandbox UI deep-link state', () => {
expect(pending[0]?.failedMessage).toBeUndefined()
expect(pending[0]?.retryCount).toBe(0)
})
+
+ it('matches the retention model for arbitrary producer-backed interleavings', () => {
+ fc.assert(
+ fc.property(producerBackedInterleavingsArb(), operations => {
+ const pending = enqueueOperations(operations)
+ const ids = pending.map(item => item.link.id)
+
+ expect(ids).toEqual([...ids].sort((left, right) => left - right))
+ expect(new Set(ids).size).toBe(ids.length)
+ expect(pending.length).toBeLessThanOrEqual(MAX_PENDING_SANDBOX_UI_DEEP_LINKS)
+ expect(comparablePending(pending)).toEqual(
+ comparableOperations(expectedRetainedOperations(operations))
+ )
+ })
+ )
+ })
+
+ it('is idempotent when the same producer-backed link is enqueued repeatedly', () => {
+ fc.assert(
+ fc.property(producerBackedInterleavingsArb(), linkOperationArb(), (operations, link) => {
+ const current = enqueueOperations(operations)
+ const once = enqueuePendingSandboxUiDeepLink(
+ current,
+ link.link,
+ link.conversationOrigin,
+ link.receivedIdentity
+ )
+ const twice = enqueuePendingSandboxUiDeepLink(
+ once,
+ link.link,
+ link.conversationOrigin,
+ link.receivedIdentity
+ )
+
+ expect(twice).toEqual(once)
+ })
+ )
+ })
+
+ it('retains the correct high-id suffix when more than MAX links are represented', () => {
+ fc.assert(
+ fc.property(
+ fc.array(targetPartsArb, {
+ minLength: MAX_PENDING_SANDBOX_UI_DEEP_LINKS + 1,
+ maxLength: MAX_PENDING_SANDBOX_UI_DEEP_LINKS + 15,
+ }),
+ parts => {
+ const envelopes = producerEnvelopes(parts)
+ const operations = [...envelopes].reverse().map<LinkOperation>(link => ({
+ conversationOrigin: null,
+ link,
+ receivedIdentity: 'user-a',
+ }))
+ const pending = enqueueOperations(operations)
+
+ expect(pending.map(item => item.link.id)).toEqual(
+ envelopes.slice(-MAX_PENDING_SANDBOX_UI_DEEP_LINKS).map(link => link.id)
+ )
+ }
+ )
+ )
+ })
})