Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
Seanaye/feat/offline soup filter matrix (#6457)
Sean Ayebbaf81e5fc88
diff --git a/Cargo.lock b/Cargo.lockindex 58102aea0c..563676c9a5 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -3052,7 +3052,7 @@ dependencies = [[[package]]name = "cache-wasm"-version = "0.6.11"+version = "0.6.14"dependencies = ["async-lock","cache-core",diff --git a/apps/web/package.json b/apps/web/package.jsonindex c4711d1604..8bb631936a 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -13,7 +13,9 @@"native:e2e": "bash tests/native/run.sh","native:e2e:smoke": "bash tests/native/run.sh --smoke","native:e2e:fixtures": "bun test tests/native/fixtures",- "native:e2e:check": "tsc -p tests/native/tsconfig.json",+ "native:e2e:check": "tsc -p tests/native/tsconfig.json && tsc -p tests/native/tsconfig.browser.json",+ "native:e2e:matrix": "bash tests/native/run.sh --matrix",+ "native:e2e:generate-fixtures": "bun tests/native/generate-fixtures.ts","local:e2e": "LOCAL_E2E=true bunx playwright test","local:e2e:ui": "LOCAL_E2E=true bunx playwright test --ui","gen-api": "bun scripts/generate-api-schema.ts",diff --git a/apps/web/src/features/email-view/queries/email-query.test.ts b/apps/web/src/features/email-view/queries/email-query.test.tsindex b0342d42f7..4d3e1e959d 100644--- a/apps/web/src/features/email-view/queries/email-query.test.ts+++ b/apps/web/src/features/email-view/queries/email-query.test.ts@@ -159,8 +159,12 @@ describe('buildEmailQuery', () => {);expect(ef({ read: ['read'] })).toContain(serialize({ l: { Read: true } }));expect(ef({ done: ['done'] })).toContain(- serialize({ l: { NotificationState: 'done' } })+ serialize({ l: { InboxVisible: false } }));+ expect(ef({ done: ['not-done'] })).toContain(+ serialize({ l: { InboxVisible: true } })+ );+ expect(ef({ done: ['done'] })).not.toContain('NotificationState');expect(ef({ calendar: ['has-calendar-invite'] })).toContain(serialize({ l: { CalendarOnly: true } }));diff --git a/apps/web/src/features/next-soup/soup-view/document-tab-scope.test.ts b/apps/web/src/features/next-soup/soup-view/document-tab-scope.test.tsnew file mode 100644index 0000000000..768c150bc7--- /dev/null+++ b/apps/web/src/features/next-soup/soup-view/document-tab-scope.test.ts@@ -0,0 +1,162 @@+import {+ makeGraphqlGroupedSoupInput,+ makeGraphqlSoupInput,+} from '@queries/soup/graphql/ast';+import type { SoupApiItem } from '@service-storage/generated/schemas/soupApiItem';+import { describe, expect, it, vi } from 'vitest';+import {+ compileToAst,+ defineQueryFilters,+ queryStateFrom,+} from '../filters/filter-store/compile';+import { createQueryStore } from '../filters/filter-store/query-store';+import {+ applyDocumentTabScope,+ withDocumentTabItemScope,+} from './document-tab-scope';++const ME = 'macro|[email protected]';+const OTHER = 'macro|[email protected]';+const NIL = '00000000-0000-0000-0000-000000000000';+const params = { limit: 100, sort_method: 'updated_at' as const };++function sharedStore() {+ return createQueryStore({+ initial: defineQueryFilters({ exclude: { documentOwnerId: [ME] } }),+ });+}++function sharedBody(store: ReturnType<typeof sharedStore>) {+ return compileToAst(applyDocumentTabScope(store.state, 'shared', ME));+}++describe('Shared Files cache admission scope', () => {+ const document = (ownerId: string) =>+ ({ tag: 'document', data: { ownerId } }) as SoupApiItem;++ it('keeps cached query scope fixed after tab or viewer changes', () => {+ let tab = 'shared';+ let viewer = ME;+ const shared = withDocumentTabItemScope(tab, viewer, () => true);+ tab = 'owned';+ viewer = OTHER;+ expect(shared(document(ME))).toBe(false);+ expect(shared(document(OTHER))).toBe(true);+ expect(+ withDocumentTabItemScope(tab, viewer, () => true)(document(ME))+ ).toBe(true);+ });++ it('does not replace the downstream membership filter or filter non-document ownership', () => {+ const downstream = vi.fn(() => false);+ const filter = withDocumentTabItemScope('shared', ME, downstream);+ const otherDocument = document(OTHER);+ expect(filter(otherDocument)).toBe(false);+ expect(downstream).toHaveBeenCalledWith(otherDocument);+ downstream.mockReturnValue(true);+ const project = { tag: 'project', data: { ownerId: ME } } as SoupApiItem;+ expect(filter(project)).toBe(true);+ expect(downstream).toHaveBeenCalledWith(project);+ expect(+ withDocumentTabItemScope('shared', undefined, downstream)(project)+ ).toBe(true);+ });++ it('leaves admission for other tabs and non-Files queries unchanged', () => {+ const downstream = vi.fn(() => true);+ for (const tab of ['owned', 'attachments', 'folders', 'all', undefined]) {+ expect(withDocumentTabItemScope(tab, undefined, downstream)).toBe(+ downstream+ );+ }+ });+});++describe('Shared Files request scope', () => {+ it('ANDs Created by me with non-ownership in REST and flat/grouped GraphQL requests', () => {+ const store = sharedStore();+ store.set({ include: { documentOwnerId: [ME] } });+ const body = sharedBody(store);+ expect(body.df).toEqual({+ '&': [{ l: { o: ME } }, { '!': { l: { o: ME } } }],+ });+ const expected = {+ and: {+ left: { literal: { owner: ME } },+ right: { not: { literal: { owner: ME } } },+ },+ };+ expect(+ makeGraphqlSoupInput({ params, body }).initial?.filters?.documentFilter+ ).toEqual(expected);+ expect(+ makeGraphqlGroupedSoupInput({+ params,+ body,+ groupBy: { type: 'entity_type' },+ }).initial?.filters?.documentFilter+ ).toEqual(expected);+ });++ it('keeps the exclusion with a mixed creator selection and restores it after clearing', () => {+ const store = sharedStore();+ store.set({ include: { documentOwnerId: [ME, OTHER] } });+ expect(sharedBody(store).df).toEqual({+ '&': [+ { '|': [{ l: { o: ME } }, { l: { o: OTHER } }] },+ { '!': { l: { o: ME } } },+ ],+ });+ store.set({ include: { documentOwnerId: undefined } });+ expect(sharedBody(store).df).toEqual({ '!': { l: { o: ME } } });+ store.set({ include: { documentOwnerId: [OTHER] } });+ expect(sharedBody(store).df).toEqual({+ '&': [{ l: { o: OTHER } }, { '!': { l: { o: ME } } }],+ });+ });++ it('repairs legacy/restored filters without changing persisted state or other tabs', () => {+ const state = queryStateFrom(+ defineQueryFilters({ include: { documentOwnerId: [ME] } })+ );+ const saved = JSON.stringify(state);+ const scoped = applyDocumentTabScope(state, 'shared', ME);+ expect(compileToAst(scoped).df).toEqual({+ '&': [{ l: { o: ME } }, { '!': { l: { o: ME } } }],+ });+ expect(JSON.stringify(state)).toBe(saved);+ for (const tab of ['owned', 'attachments', 'folders', 'all', undefined]) {+ expect(applyDocumentTabScope(state, tab, ME)).toBe(state);+ }+ });++ it('retains type and tag refinements when injecting the tab constraint', () => {+ const state = queryStateFrom({+ include: {+ documentOwnerId: [ME],+ tagFilters: [+ { propertyId: 'definition', type: 'select', value: 'tag' },+ ],+ },+ exclude: {},+ documentWhere: { include: { fileType: ['pdf'] } },+ });+ const scoped = applyDocumentTabScope(state, 'shared', ME);+ expect(scoped.documentWhere).toEqual([+ { include: { fileType: ['pdf'] } },+ { exclude: { documentOwnerId: [ME] } },+ ]);+ expect(scoped.include).toEqual(state.include);+ expect(compileToAst(scoped).propf).toEqual(compileToAst(state).propf);+ expect(state.documentWhere).toHaveLength(1);+ });++ it('does not widen Shared before viewer identity is available', () => {+ const scoped = applyDocumentTabScope(+ queryStateFrom({}),+ 'shared',+ undefined+ );+ expect(compileToAst(scoped).df).toEqual({ l: { id: NIL } });+ });+});diff --git a/apps/web/src/features/next-soup/soup-view/document-tab-scope.ts b/apps/web/src/features/next-soup/soup-view/document-tab-scope.tsnew file mode 100644index 0000000000..107847938e--- /dev/null+++ b/apps/web/src/features/next-soup/soup-view/document-tab-scope.ts@@ -0,0 +1,50 @@+import type { SoupApiItem } from '@service-storage/generated/schemas/soupApiItem';+import { NIL_UUID } from '../filters/filter-store';+import type {+ DocumentFilterExpression,+ QueryState,+} from '../filters/filter-store/types';++type ItemFilter = (item: SoupApiItem) => boolean;++/** Bind cache membership to the query's tab/viewer, not later active-tab state. */+export function withDocumentTabItemScope(+ tab: string | undefined,+ userId: string | undefined,+ filter: ItemFilter+): ItemFilter {+ if (tab !== 'shared') return filter;+ return (item) => {+ if (item.tag === 'document' && (!userId || item.data.ownerId === userId))+ return false;+ return filter(item);+ };+}++/** Apply tab invariants at request time, including to older persisted filters. */+export function applyDocumentTabScope(+ state: QueryState,+ tab: string | undefined,+ userId: string | undefined+): QueryState {+ if (tab !== 'shared') return state;++ // Flat include values override matching flat excludes in the query store.+ // Reuse an intact preset, but never let an explicit creator remove its scope.+ if (+ userId &&+ state.exclude.documentOwnerId?.includes(userId) &&+ !state.include.documentOwnerId?.includes(userId)+ )+ return state;++ const scope: DocumentFilterExpression = userId+ ? { exclude: { documentOwnerId: [userId] } }+ : { include: { documentId: [NIL_UUID] } };+ return {+ ...state,+ // Separate clauses are ANDed; creator selection and non-ownership cannot+ // cancel each other here. Do not persist this derived constraint into other tabs.+ documentWhere: [...(state.documentWhere ?? []), scope],+ };+}diff --git a/apps/web/src/features/next-soup/soup-view/soup-view-context.tsx b/apps/web/src/features/next-soup/soup-view/soup-view-context.tsxindex 20c3a259f3..7ac8c25459 100644--- a/apps/web/src/features/next-soup/soup-view/soup-view-context.tsx+++ b/apps/web/src/features/next-soup/soup-view/soup-view-context.tsx@@ -106,6 +106,10 @@ import {useContext,} from 'solid-js';import { unwrap } from 'solid-js/store';+import {+ applyDocumentTabScope,+ withDocumentTabItemScope,+} from './document-tab-scope';type DataSource<T> = {data: Accessor<T[]>;@@ -852,6 +856,9 @@ export const SoupViewContextProvider: FlowComponent<let next = applyInboxFilter(state);next = applyInboxThreadFilter(next);next = applyInboxReadFilter(next);+ if (activeListView() === 'documents') {+ next = applyDocumentTabScope(next, activeTab(), userId());+ }return next;};@@ -1021,7 +1028,11 @@ export const SoupViewContextProvider: FlowComponent<showSupportedForeignEntities: showSupportedForeignEntitiesFF().enabled,onBeforeGraphqlRefresh: () => groupQueries.resetToInitialPage(),meta: {- itemFilter: (item) => soupItemMatchesActiveFilters(item, view),+ itemFilter: withDocumentTabItemScope(+ view === 'documents' ? activeTab() : undefined,+ userId(),+ (item) => soupItemMatchesActiveFilters(item, view)+ ),insertFilter: (item) =>emailItemMatchesImportance(item, emailImportance),},@@ -1210,7 +1221,11 @@ export const SoupViewContextProvider: FlowComponent<return {enabled: enabled() && !search.isSearching(),meta: {- itemFilter: (item) => soupItemMatchesActiveFilters(item, view),+ itemFilter: withDocumentTabItemScope(+ view === 'documents' ? activeTab() : undefined,+ userId(),+ (item) => soupItemMatchesActiveFilters(item, view)+ ),insertFilter: (item) =>emailItemMatchesImportance(item, emailImportance),},diff --git a/apps/web/src/features/property/constants.ts b/apps/web/src/features/property/constants.tsindex 8aed8fa0cd..5f57aa5a3f 100644--- a/apps/web/src/features/property/constants.ts+++ b/apps/web/src/features/property/constants.ts@@ -4,6 +4,9 @@*/import type { BlockAlias, BlockName } from '@core/block';+import { SYSTEM_PROPERTY_IDS } from './identifiers';++export { PROPERTY_OPTION_IDS, SYSTEM_PROPERTY_IDS } from './identifiers';export const NUMBER_DECIMAL_PLACES = 4;@@ -14,34 +17,6 @@ export const NUMBER_DECIMAL_PLACES = 4;*/export const CRM_TEAM_STAGE_DEFINITION_NAME = 'Deal Stage';-/**- * System property definition IDs (from backend seed migration).- * These are stable UUIDs that match the database.- */-export const SYSTEM_PROPERTY_IDS = {- // Task properties- ASSIGNEES: '00000001-0000-0000-0000-000000000001',- STATUS: '00000001-0000-0000-0000-000000000002',- PRIORITY: '00000001-0000-0000-0000-000000000003',- DUE_DATE: '00000001-0000-0000-0000-000000000004',- PARENT_TASK: '00000001-0000-0000-0000-000000000005',- SUBTASKS: '00000001-0000-0000-0000-000000000006',- DEPENDS_ON: '00000001-0000-0000-0000-000000000007',- EFFORT: '00000001-0000-0000-0000-000000000008',- STORY_POINTS: '00000001-0000-0000-0000-000000000009',- RELEVANT_DOCUMENTS: '00000001-0000-0000-0000-00000000000a',- // Email attachment properties- SOURCE: '00000001-0000-0000-0000-00000000000b',- COMPANIES: '00000001-0000-0000-0000-00000000000c',- SENDER: '00000001-0000-0000-0000-00000000000d',- RECIPIENTS: '00000001-0000-0000-0000-00000000000e',- SUBJECT: '00000001-0000-0000-0000-00000000000f',- // CRM company properties- STAGE: '00000001-0000-0000-0000-000000000010',- COMPANY_OWNER: '00000001-0000-0000-0000-000000000011',- REVENUE: '00000001-0000-0000-0000-000000000012',-} as const;-/*** Builtin property definition IDs by block type.* These properties are automatically attached to entities of this block type@@ -111,29 +86,3 @@ export function getBuiltinPropertyIds(export const FOCUS_CONFIG = {DELAY: 100,} as const;--// Common option ids for mapping to custom icons.-export const PROPERTY_OPTION_IDS = {- PRIORITY: {- LOW: '00000001-0000-0000-0003-000000000001',- MEDIUM: '00000001-0000-0000-0003-000000000002',- HIGH: '00000001-0000-0000-0003-000000000003',- URGENT: '00000001-0000-0000-0003-000000000004',- },- STATUS: {- NOT_STARTED: '00000001-0000-0000-0002-000000000001',- IN_PROGRESS: '00000001-0000-0000-0002-000000000002',- IN_REVIEW: '00000001-0000-0000-0002-000000000003',- COMPLETED: '00000001-0000-0000-0002-000000000004',- CANCELED: '00000001-0000-0000-0002-000000000005',- },- STAGE: {- LEAD: '00000001-0000-0000-0010-000000000001',- QUALIFIED: '00000001-0000-0000-0010-000000000002',- DEMO: '00000001-0000-0000-0010-000000000003',- TRIAL: '00000001-0000-0000-0010-000000000004',- NEGOTIATION: '00000001-0000-0000-0010-000000000005',- CUSTOMER: '00000001-0000-0000-0010-000000000006',- CHURNED: '00000001-0000-0000-0010-000000000007',- },-} as const;diff --git a/apps/web/src/features/property/identifiers.ts b/apps/web/src/features/property/identifiers.tsnew file mode 100644index 0000000000..f4b6072275--- /dev/null+++ b/apps/web/src/features/property/identifiers.ts@@ -0,0 +1,47 @@+/** Stable property definition IDs from the backend seed migrations. */+export const SYSTEM_PROPERTY_IDS = {+ ASSIGNEES: '00000001-0000-0000-0000-000000000001',+ STATUS: '00000001-0000-0000-0000-000000000002',+ PRIORITY: '00000001-0000-0000-0000-000000000003',+ DUE_DATE: '00000001-0000-0000-0000-000000000004',+ PARENT_TASK: '00000001-0000-0000-0000-000000000005',+ SUBTASKS: '00000001-0000-0000-0000-000000000006',+ DEPENDS_ON: '00000001-0000-0000-0000-000000000007',+ EFFORT: '00000001-0000-0000-0000-000000000008',+ STORY_POINTS: '00000001-0000-0000-0000-000000000009',+ RELEVANT_DOCUMENTS: '00000001-0000-0000-0000-00000000000a',+ SOURCE: '00000001-0000-0000-0000-00000000000b',+ COMPANIES: '00000001-0000-0000-0000-00000000000c',+ SENDER: '00000001-0000-0000-0000-00000000000d',+ RECIPIENTS: '00000001-0000-0000-0000-00000000000e',+ SUBJECT: '00000001-0000-0000-0000-00000000000f',+ STAGE: '00000001-0000-0000-0000-000000000010',+ COMPANY_OWNER: '00000001-0000-0000-0000-000000000011',+ REVENUE: '00000001-0000-0000-0000-000000000012',+} as const;++/** Stable option IDs, kept independent of UI/block registries for tooling. */+export const PROPERTY_OPTION_IDS = {+ PRIORITY: {+ LOW: '00000001-0000-0000-0003-000000000001',+ MEDIUM: '00000001-0000-0000-0003-000000000002',+ HIGH: '00000001-0000-0000-0003-000000000003',+ URGENT: '00000001-0000-0000-0003-000000000004',+ },+ STATUS: {+ NOT_STARTED: '00000001-0000-0000-0002-000000000001',+ IN_PROGRESS: '00000001-0000-0000-0002-000000000002',+ IN_REVIEW: '00000001-0000-0000-0002-000000000003',+ COMPLETED: '00000001-0000-0000-0002-000000000004',+ CANCELED: '00000001-0000-0000-0002-000000000005',+ },+ STAGE: {+ LEAD: '00000001-0000-0000-0010-000000000001',+ QUALIFIED: '00000001-0000-0000-0010-000000000002',+ DEMO: '00000001-0000-0000-0010-000000000003',+ TRIAL: '00000001-0000-0000-0010-000000000004',+ NEGOTIATION: '00000001-0000-0000-0010-000000000005',+ CUSTOMER: '00000001-0000-0000-0010-000000000006',+ CHURNED: '00000001-0000-0000-0010-000000000007',+ },+} as const;diff --git a/apps/web/src/features/soup/filters/facets/constants.ts b/apps/web/src/features/soup/filters/facets/constants.tsindex 4922ffd5d4..341f70b9d3 100644--- a/apps/web/src/features/soup/filters/facets/constants.ts+++ b/apps/web/src/features/soup/filters/facets/constants.ts@@ -81,8 +81,12 @@ export const FILTER_TARGETS = {},emailSeen: { backend: 'Read', domain: [true, false] },emailDone: {- backend: 'NotificationState',- notification: 'done',+ backend: 'InboxVisible',+ formatValue: (value) => {+ if (typeof value !== 'boolean')+ throw new Error('Invalid mail done filter');+ return !value;+ },domain: [true, false],},emailImportance: { backend: 'Importance', domain: [true, false] },diff --git a/apps/web/src/lib/graphql-cache/worker/browser-test/mail-projection-harness.ts b/apps/web/src/lib/graphql-cache/worker/browser-test/mail-projection-harness.tsindex 4199a86b51..9d12dea1ea 100644--- a/apps/web/src/lib/graphql-cache/worker/browser-test/mail-projection-harness.ts+++ b/apps/web/src/lib/graphql-cache/worker/browser-test/mail-projection-harness.ts@@ -21,7 +21,7 @@ const nil = id(0);const previewFields ='id subject snippet isDraft senderEmail senderName senderPhotoUrl';const previews = `mailAllPreview { ${previewFields} } mailDraftPreview { ${previewFields} } mailSentPreview { ${previewFields} }`;-const query = `query MailSeed { user { id emailLinks { id } soup(input:{initial:{limit:100,emailView:ALL}}) { items { __typename id cacheProjection ... on GraphqlSoupEmailThread { name linkId ownerId isRead inboxVisible isSignal latestInboundMessageTs ${previews} updatedAt } } } } }`;+const query = `query MailSeed { user { id emailLinks { id } soup(input:{initial:{limit:100,emailView:ALL}}) { items { __typename id cacheProjection ... on GraphqlSoupEmailThread { name linkId ownerId isRead inboxVisible isSignal latestInboundMessageTs ${previews} updatedAt properties { id } } } } } }`;const fragment = `fragment MailRow on GraphqlSoupEmailThread { __typename id emailName:name isRead inboxVisible ${previews} }`;const preview = (n: number, subject: string, isDraft: boolean) => ({id: id(n),@@ -136,6 +136,7 @@ await host.writeQuery({ownerId:n <= 50 ? 'offline-mail-viewer' : 'macro|[email protected]',cacheProjection: mailProjectionCapsules[index],+ properties: [],mailAllPreview:n === 7 ? null : preview(n + 10000, `Email ${n}`, false),mailDraftPreview:diff --git a/apps/web/src/lib/graphql-cache/worker/browser-test/notification-projection-harness.ts b/apps/web/src/lib/graphql-cache/worker/browser-test/notification-projection-harness.tsindex 9f318f1ad2..6f5909dc30 100644--- a/apps/web/src/lib/graphql-cache/worker/browser-test/notification-projection-harness.ts+++ b/apps/web/src/lib/graphql-cache/worker/browser-test/notification-projection-harness.ts@@ -17,6 +17,7 @@ const nil = '00000000-0000-0000-0000-000000000000';const snapshotQuery = `query Snapshot {user { id soup(input: { initial: { limit: 20 } }) { items {__typename id cacheProjection+ properties { id }notifications { id entityId entityType state }... on GraphqlSoupProject { ownerId parentId createdAt updatedAt }... on GraphqlSoupChannel {@@ -99,6 +100,7 @@ const snapshot = (isParticipant: true,id: entityId,cacheProjection: null,+ properties: [],ownerId: 'macro|[email protected]',parentId: null,createdAt: '2025-01-01T00:00:00Z',diff --git a/apps/web/src/lib/queries/soup/backfill.test.tsx b/apps/web/src/lib/queries/soup/backfill.test.tsxindex d0bc5d7e63..c1583b4d78 100644--- a/apps/web/src/lib/queries/soup/backfill.test.tsx+++ b/apps/web/src/lib/queries/soup/backfill.test.tsx@@ -409,7 +409,7 @@ describe('runSoupBackfills', () => {it('does not reuse pre-projection native backfill checkpoints', () => {localStorage.setItem(- 'graphql-soup-backfill:v12:user-1:email-filter-metadata',+ 'graphql-soup-backfill:v13:user-1:email-filter-metadata',JSON.stringify({userId: 'user-1',nextCursor: 'old-page',@@ -431,7 +431,7 @@ describe('runSoupBackfills', () => {it('restarts from the beginning when the cache generation is replaced', async () => {localStorage.setItem(- 'graphql-soup-backfill:v13:user-1:core-entities',+ 'graphql-soup-backfill:v14:user-1:core-entities',JSON.stringify({userId: 'user-1',nextCursor: 'stale-cursor',diff --git a/apps/web/src/lib/queries/soup/backfill.ts b/apps/web/src/lib/queries/soup/backfill.tsindex 36201fc4b0..537badeb5c 100644--- a/apps/web/src/lib/queries/soup/backfill.ts+++ b/apps/web/src/lib/queries/soup/backfill.ts@@ -26,9 +26,9 @@ import { createEffect, createSignal, onCleanup } from 'solid-js';// Bump when a default backfill input or completion guarantee changes so// persisted cursors cannot retain an older hydration contract.-// Native hosts now maintain Soup/Mail predicate projections. Restart old-// scans (including interrupted ones) so pre-index native records are rehydrated.-const BACKFILL_VERSION = 13;+// Rehydrate complete property snapshots for the property-aware Soup/Mail+// profiles. Preserve queued work; old or partial scans cannot supply new proof.+const BACKFILL_VERSION = 14;const PAGE_LIMIT = 100;// Five threads × twenty messages reaches the backend's 100-message cap.const EMAIL_CONTENT_PAGE_LIMIT = 5;diff --git a/apps/web/src/lib/queries/soup/graphql/ast.test.ts b/apps/web/src/lib/queries/soup/graphql/ast.test.tsindex df97b2567b..c8b9e4ac38 100644--- a/apps/web/src/lib/queries/soup/graphql/ast.test.ts+++ b/apps/web/src/lib/queries/soup/graphql/ast.test.ts@@ -370,12 +370,36 @@ describe('makeGraphqlSoupInput', () => {).toThrow('Unsupported GraphQL Soup AST');});- it('throws for REST-only file association literals so callers can fall back', () => {+ it('translates skill inclusion and markdown skill exclusions without falling back', () => {+ expect(makeInput({ include: { subType: ['skill'] } })).toMatchObject({+ initial: {+ filters: { documentFilter: { literal: { subType: 'SKILL' } } },+ },+ });+ expect(makeInput({ exclude: { subType: ['skill'] } })).toMatchObject({+ initial: {+ filters: { documentFilter: { not: { literal: { subType: 'SKILL' } } } },+ },+ });+ });++ it('expands file associations into native-evaluatable GraphQL file types', () => {+ expect(makeInput({ include: { fileAssoc: ['assoc:pdf'] } })).toMatchObject({+ initial: {+ filters: { documentFilter: { literal: { fileType: 'pdf' } } },+ },+ });+ const code = makeInput({ include: { fileAssoc: ['assoc:code'] } });+ const depth = (value: unknown): number =>+ value && typeof value === 'object'+ ? 1 + Math.max(0, ...Object.values(value).map(depth))+ : 0;+ expect(depth(code)).toBeLessThan(32);+ expect(JSON.stringify(code)).toContain('"fileType":"ts"');+ expect(JSON.stringify(code)).not.toContain('assoc:code');expect(() =>- makeInput({- include: { fileAssoc: ['assoc:pdf'] },- })- ).toThrow('Unsupported GraphQL Soup AST');+ makeInput({ include: { fileAssoc: ['assoc:unknown'] } })+ ).toThrow('unknown file association');});it('throws for REST-only top-level filters instead of silently widening the query', () => {diff --git a/apps/web/src/lib/queries/soup/graphql/ast.ts b/apps/web/src/lib/queries/soup/graphql/ast.tsindex 64df89baf6..e84797ee7d 100644--- a/apps/web/src/lib/queries/soup/graphql/ast.ts+++ b/apps/web/src/lib/queries/soup/graphql/ast.ts@@ -1,3 +1,4 @@+import { FileTypeMap } from '@service-storage/fileTypeMap';import type {GraphqlAgentSessionLiteral,GraphqlCalendarEventLiteral as GraphqlCalendarEventLiteralInput,@@ -95,26 +96,76 @@ function compileExpr<TLiteral>(ast: RestAst,mapLiteral: LiteralMapper<TLiteral>): GraphqlExprInput<TLiteral> {- if ('&' in ast) {+ return compileExprWithLeaf(ast, (literal) => ({+ literal: mapLiteral(literal),+ }));+}++function compileExprWithLeaf<TLiteral>(+ ast: RestAst,+ mapLeaf: (literal: unknown) => GraphqlExprInput<TLiteral>+): GraphqlExprInput<TLiteral> {+ if ('&' in ast)return {and: {- left: compileExpr(ast['&'][0], mapLiteral),- right: compileExpr(ast['&'][1], mapLiteral),+ left: compileExprWithLeaf(ast['&'][0], mapLeaf),+ right: compileExprWithLeaf(ast['&'][1], mapLeaf),},};- }- if ('|' in ast) {+ if ('|' in ast)return {or: {- left: compileExpr(ast['|'][0], mapLiteral),- right: compileExpr(ast['|'][1], mapLiteral),+ left: compileExprWithLeaf(ast['|'][0], mapLeaf),+ right: compileExprWithLeaf(ast['|'][1], mapLeaf),},};- }- if ('!' in ast) {- return { not: compileExpr(ast['!'], mapLiteral) };- }- return { literal: mapLiteral(ast.l) };+ if ('!' in ast) return { not: compileExprWithLeaf(ast['!'], mapLeaf) };+ return mapLeaf(ast.l);+}++function mapDocumentPredicate(+ literal: unknown+): GraphqlExprInput<GraphqlDocumentLiteralInput> {+ const [field, value] = singleLiteralField(literal);+ if (field !== 'fa') return { literal: mapDocumentLiteral(literal) };+ if (typeof value !== 'string' || !value.startsWith('assoc:'))+ unsupported('invalid file association');+ const association = value.slice('assoc:'.length);+ const types = Object.values(FileTypeMap);+ if (+ association !== 'other' &&+ !types.some((type) => type.app === association)+ )+ unsupported(`unknown file association ${association}`);+ // Match item_filters::ast::document::other. The Files Other category adds+ // its own image/document/video exclusions on top of this association.+ const extensions = [+ ...new Set(+ types+ .filter((type) =>+ association === 'other'+ ? !['write', 'pdf', 'md', 'canvas', 'code', 'video'].includes(+ type.app+ )+ : type.app === association+ )+ .map((type) => type.extension)+ ),+ ];+ const balanced = (+ start: number,+ end: number+ ): GraphqlExprInput<GraphqlDocumentLiteralInput> => {+ if (end - start === 1) return { literal: { fileType: extensions[start] } };+ const middle = Math.floor((start + end) / 2);+ return {+ or: { left: balanced(start, middle), right: balanced(middle, end) },+ };+ };+ // Balanced expansion keeps large Code/Other sets within the AST depth budget.+ return extensions.length+ ? balanced(0, extensions.length)+ : { literal: { id: '00000000-0000-0000-0000-000000000000' } };}function singleLiteralField(literal: unknown): [string, unknown] {@@ -150,10 +201,11 @@ function mapString(value: unknown, field: string): string {return value;}-function mapDocumentSubType(value: unknown): 'TASK' | 'SNIPPET' {+function mapDocumentSubType(value: unknown): 'TASK' | 'SNIPPET' | 'SKILL' {const subType = mapString(value, 'subType');if (subType === 'task') return 'TASK';if (subType === 'snippet') return 'SNIPPET';+ if (subType === 'skill') return 'SKILL';unsupported(`unsupported document subType ${subType}`);}@@ -573,7 +625,7 @@ function makeGraphqlFilters(body: AstBody): GraphqlEntityFilterAstInput {);}if (body.df)- filters.documentFilter = compileExpr(body.df, mapDocumentLiteral);+ filters.documentFilter = compileExprWithLeaf(body.df, mapDocumentPredicate);if (body.pf) filters.projectFilter = compileExpr(body.pf, mapProjectLiteral);if (body.cf) filters.chatFilter = compileExpr(body.cf, mapChatLiteral);if (body.ef)diff --git a/apps/web/src/lib/queries/soup/graphql/items.test.ts b/apps/web/src/lib/queries/soup/graphql/items.test.tsindex 63f2d34a11..e2ffe2c22e 100644--- a/apps/web/src/lib/queries/soup/graphql/items.test.ts+++ b/apps/web/src/lib/queries/soup/graphql/items.test.ts@@ -428,9 +428,16 @@ describe('createGraphqlSoupAstItemsQuery', () => {}});- it.each(['mail-page', 'incomplete', 'unsupported'] as const)(- 'handles a failed network refresh with %s local Mail proof',- async (kind) => {+ it.each([+ { mail: true, kind: 'mail-page' },+ { mail: true, kind: 'incomplete' },+ { mail: true, kind: 'unsupported' },+ { mail: false, kind: 'reconciled' },+ { mail: false, kind: 'incomplete' },+ { mail: false, kind: 'unsupported' },+ ] as const)(+ 'handles a failed network refresh with $kind local proof (mail=$mail)',+ async ({ mail, kind }) => {const fake = makeFakeClient();getGraphqlSoupClientMock.mockReturnValue(fake.client);getGraphqlSoupCacheHostMock.mockReturnValue({@@ -440,10 +447,15 @@ describe('createGraphqlSoupAstItemsQuery', () => {onCacheGenerationChanged: () => () => {},});makeGraphqlSoupInputMock.mockReturnValue({- initial: { emailView: 'ALL', sortMethod: 'UPDATED_AT', limit: 10 },+ initial: {+ ...(mail ? { emailView: 'ALL' } : {}),+ sortMethod: 'UPDATED_AT',+ limit: 10,+ },});entityFilterMock.mockResolvedValue({kind,+ retainedKeys: [],revision: REVISION_0,keys: [],sortTimestamps: [],@@ -469,9 +481,13 @@ describe('createGraphqlSoupAstItemsQuery', () => {networkError: new Error('API disconnected'),});fake.executions[0].fail(offlineError);- if (kind === 'mail-page') {- await vi.waitFor(() => expect(query.data()?.cachedMail).toBe(true));- expect(query.data()?.entities).toEqual([]);+ if (kind === 'mail-page' || kind === 'reconciled') {+ await vi.waitFor(() => expect(query.data()?.entities).toEqual([]));+ expect(query.data()?.cachedMail).toBe(mail);+ if (!mail)+ expect(entityFilterMock.mock.calls.at(-1)?.[0].baseline).toEqual(+ []+ );expect(query.error()).toBeUndefined();// Server-reported errors are not hidden just because local data exists.const serverError = new CombinedError({diff --git a/apps/web/src/lib/queries/soup/graphql/items.ts b/apps/web/src/lib/queries/soup/graphql/items.tsindex 98fd5d4cc9..0af9921d8a 100644--- a/apps/web/src/lib/queries/soup/graphql/items.ts+++ b/apps/web/src/lib/queries/soup/graphql/items.ts@@ -577,15 +577,15 @@ export function createGraphqlSoupAstItemsQuery(const error = (): CombinedError | undefined => {const error = query.error;- // A background transport failure must not replace usable cached Mail- // (including an exact empty page) with the full-screen error state.+ // A background transport failure must not replace usable current-query+ // cache results (including an empty result) with the full-screen error state.// Keep server responses (including HTTP auth failures), GraphQL errors,// and failures without current-query local proof visible.if (error?.networkError &&!error.response &&error.graphQLErrors.length === 0 &&- displayLocalProjection()?.mail+ displayLocalProjection()) {return undefined;}diff --git a/apps/web/src/lib/queries/soup/normalized-cache/operations.test.ts b/apps/web/src/lib/queries/soup/normalized-cache/operations.test.tsindex 01bbc61ab9..f6877cb0d9 100644--- a/apps/web/src/lib/queries/soup/normalized-cache/operations.test.ts+++ b/apps/web/src/lib/queries/soup/normalized-cache/operations.test.ts@@ -2,6 +2,7 @@* @vitest-environment jsdom*/+import { withDocumentTabItemScope } from '@app/features/next-soup/soup-view/document-tab-scope';import type { UnifiedSearchResponseItem } from '@service-search/generated/models';import type { SoupApiItem } from '@service-storage/generated/schemas';import type { SoupPage } from '@service-storage/generated/schemas/soupPage';@@ -1144,6 +1145,111 @@ describe('insertSoupEntity — folder membership gate', () => {});});+/** Shared's request scope must also gate immediate cache admission, even when+ * restored/mutable client predicates no longer contain `shared-entity`. */+describe('insertSoupEntity — Shared Files ownership gate', () => {+ const ME = 'macro|[email protected]';+ const OTHER = 'macro|[email protected]';+ const FOLDER = 'folder-1';+ const GROUP = 'in_progress';++ function document(+ id: string,+ ownerId: string,+ projectId = FOLDER+ ): SoupApiItem {+ const item = mockTaskItem(id, GROUP);+ if (item.tag !== 'document') throw new Error('expected document fixture');+ return { ...item, data: { ...item.data, ownerId, projectId } };+ }++ function seed(viewer: string | undefined) {+ const existing = document('existing', OTHER);+ const filter = withDocumentTabItemScope('shared', viewer, (item) =>+ soupItemMatchesProjectMembership(item, FOLDER)+ );+ const legacy = [...soupKeys.items._def, 'shared-admission'];+ const flat = [+ ...soupKeys.astItems._def,+ {},+ {},+ undefined,+ 'shared-admission',+ ];+ const grouped = [+ ...soupKeys.astItems._def,+ {},+ {},+ STATUS_GROUP_BY,+ 'shared-admission',+ ];+ const expanded = [...soupKeys.groupedGroup._def, 'shared-admission'];+ for (const key of [legacy, flat, grouped, expanded])+ testQueryClient.setQueryDefaults(key, {+ meta: { itemFilter: filter, groupBy: STATUS_GROUP_BY, groupKey: GROUP },+ });+ testQueryClient.setQueryData(legacy, mockSoupCache([[existing]]));+ testQueryClient.setQueryData(flat, {+ pages: [{ kind: 'flat', items: [existing], nextCursor: null }],+ pageParams: [null],+ });+ testQueryClient.setQueryData(+ grouped,+ mockGroupedParentCache([existing], [buildGroup(GROUP, ['existing'])])+ );+ testQueryClient.setQueryData(expanded, {+ pages: [{ items: { existing }, group: buildGroup(GROUP, ['existing']) }],+ pageParams: [null],+ });+ return { legacy, flat, grouped, expanded };+ }++ function expectIds(keys: ReturnType<typeof seed>, ids: string[]) {+ expect(+ testQueryClient+ .getQueryData<InfiniteData<SoupPage>>(keys.legacy)!+ .pages[0].items.map(getSoupItemId)+ ).toEqual(ids);+ expect(+ testQueryClient+ .getQueryData<InfiniteData<SoupAstItemsFlatPage>>(keys.flat)!+ .pages[0].items.map(getSoupItemId)+ ).toEqual(ids);+ const grouped = testQueryClient.getQueryData<+ InfiniteData<SoupAstItemsGroupedPage>+ >(keys.grouped)!.pages[0];+ expect(grouped.groups[0].itemIds).toEqual(ids);+ expect(Object.keys(grouped.items).sort()).toEqual([...ids].sort());+ const expanded = testQueryClient.getQueryData<+ InfiniteData<{ items: Record<string, SoupApiItem>; group: GroupMeta }>+ >(keys.expanded)!.pages[0];+ expect(expanded.group.itemIds).toEqual(ids);+ expect(Object.keys(expanded.items).sort()).toEqual([...ids].sort());+ }++ it('rejects owned documents in flat, grouped-parent and expanded-group caches', () => {+ const keys = seed(ME);+ insertSoupEntity(document('owned-new', ME));+ expectIds(keys, ['existing']);+ });++ it('rejects document admission before viewer identity is known', () => {+ const keys = seed(undefined);+ insertSoupEntity(document('unverified-new', OTHER));+ expectIds(keys, ['existing']);+ });++ it('retains the project gate and allows eligible shared documents with rollback', () => {+ const keys = seed(ME);+ insertSoupEntity(document('outside-folder', OTHER, 'other-folder'));+ expectIds(keys, ['existing']);+ const tx = insertSoupEntity(document('shared-new', OTHER));+ expectIds(keys, ['shared-new', 'existing']);+ tx.rollback();+ expectIds(keys, ['existing']);+ });+});+/*** Regression coverage for macro-3258: a channel row marked done is removed* from the done-filtered inbox pages, but the entity stays in the normalizeddiff --git a/apps/web/tauri/graphql_cache_plugin/src/engine/soup.rs b/apps/web/tauri/graphql_cache_plugin/src/engine/soup.rsindex 79db8456bc..9aefc537fe 100644--- a/apps/web/tauri/graphql_cache_plugin/src/engine/soup.rs+++ b/apps/web/tauri/graphql_cache_plugin/src/engine/soup.rs@@ -8,10 +8,10 @@ use predicate_index::{OptimisticProjectionMutation, RecordKey};use serde::{Deserialize, Serialize};use serde_json::Value;use soup_filter_cache_adapter::{- SoupFilterCompileOutcome, authoritative_projection_mutations, compile_filter_request,- dirty_projection_mutations, mail, notification_deletion_updates,- notification_projection_updates, optimistic_notification_updates,- optimistic_projection_mutations,+ SoupFilterCompileOutcome, authoritative_projection_mutations,+ compile_current_filter_request as compile_filter_request, dirty_projection_mutations, mail,+ notification_deletion_updates, notification_projection_updates,+ optimistic_notification_updates, optimistic_projection_mutations,};/// Same request shape as the browser host's `EntityFilterCacheArgs`.@@ -96,7 +96,7 @@ pub(super) async fn filter(request: EntityFilterRequest,) -> Result<EntityFilterResult, String> {if let Some(mail_request) = request.mail {- return mail::page(+ return mail::page_current(engine,generation,request.filters,@@ -224,7 +224,17 @@ pub(super) async fn write_projections(.await.map_err(|error| error.to_string())?,);- Ok(projections)+ soup_filter_cache_adapter::properties::augment_authoritative(+ engine.storage(),+ query,+ operation,+ variables,+ data,+ reuse_stored_identity,+ projections,+ )+ .await+ .map_err(|error| error.to_string())}pub(super) async fn optimistic_projections(@@ -249,7 +259,16 @@ pub(super) async fn optimistic_projections(.await.map_err(|error| error.to_string())?,));- Ok(projections)+ soup_filter_cache_adapter::properties::augment_optimistic(+ engine.storage(),+ query,+ operation,+ variables,+ data,+ projections,+ )+ .await+ .map_err(|error| error.to_string())}pub(super) async fn invalidation_projections(@@ -263,7 +282,14 @@ pub(super) async fn invalidation_projections(.await.map_err(|error| error.to_string())?,);- Ok(projections)+ projections.extend(+ soup_filter_cache_adapter::properties::deletion_updates(engine.storage(), keys)+ .await+ .map_err(|error| error.to_string())?,+ );+ Ok(soup_filter_cache_adapter::properties::current_mutations(+ projections,+ ))}pub(super) async fn deletion_projections(@@ -278,5 +304,12 @@ pub(super) async fn deletion_projections(.filter_map(|key| RecordKey::new(key.clone()).ok()).map(ProjectionMutation::Delete),);- Ok(projections)+ projections.extend(+ soup_filter_cache_adapter::properties::deletion_updates(engine.storage(), keys)+ .await+ .map_err(|error| error.to_string())?,+ );+ Ok(soup_filter_cache_adapter::properties::current_mutations(+ projections,+ ))}diff --git a/apps/web/tauri/graphql_cache_plugin/src/engine/test/mail.graphql b/apps/web/tauri/graphql_cache_plugin/src/engine/test/mail.graphqlindex cbcd9b11fa..908f3ddb93 100644--- a/apps/web/tauri/graphql_cache_plugin/src/engine/test/mail.graphql+++ b/apps/web/tauri/graphql_cache_plugin/src/engine/test/mail.graphql@@ -16,6 +16,7 @@ query NativeMailBackfill {isSignallatestInboundMessageTsupdatedAt+ properties { id }mailAllPreview { id subject snippet isDraft senderEmail senderName senderPhotoUrl }mailDraftPreview { id subject snippet isDraft senderEmail senderName senderPhotoUrl }mailSentPreview { id subject snippet isDraft senderEmail senderName senderPhotoUrl }diff --git a/apps/web/tauri/graphql_cache_plugin/src/engine/test/project.graphql b/apps/web/tauri/graphql_cache_plugin/src/engine/test/project.graphqlindex 5bf94f579e..14fd7e7bfb 100644--- a/apps/web/tauri/graphql_cache_plugin/src/engine/test/project.graphql+++ b/apps/web/tauri/graphql_cache_plugin/src/engine/test/project.graphql@@ -12,6 +12,7 @@ query NativeProject {createdAtupdatedAtnotifications { __typename id }+ properties { id }}}}diff --git a/apps/web/tauri/graphql_cache_plugin/src/engine/test/soup.rs b/apps/web/tauri/graphql_cache_plugin/src/engine/test/soup.rsindex fdbc1069b7..49a896eb84 100644--- a/apps/web/tauri/graphql_cache_plugin/src/engine/test/soup.rs+++ b/apps/web/tauri/graphql_cache_plugin/src/engine/test/soup.rs@@ -40,7 +40,7 @@ fn row(n: u16) -> Value {"__typename": "GraphqlSoupEmailThread", "id": id(n), "name": format!("Mail {n}"),"ownerId": VIEWER, "linkId": id(1000), "isRead": n.is_multiple_of(4),"inboxVisible": n.is_multiple_of(2), "isSignal": n.is_multiple_of(3),- "cacheProjection": capsule, "latestInboundMessageTs": TIMESTAMP, "updatedAt": TIMESTAMP,+ "cacheProjection": capsule, "latestInboundMessageTs": TIMESTAMP, "updatedAt": TIMESTAMP, "properties": [],"mailAllPreview": preview(n, 1000),"mailDraftPreview": n.is_multiple_of(3).then(|| preview(n, 2000)),"mailSentPreview": n.is_multiple_of(4).then(|| preview(n, 3000)),@@ -366,7 +366,7 @@ fn native_general_soup_filter_and_server_baseline_reconciliation() {json!({"user": {"id": VIEWER, "soup": {"items": [{"__typename": "GraphqlSoupProject", "id": id(100), "cacheProjection": null,"ownerId": VIEWER, "parentId": null, "createdAt": TIMESTAMP, "updatedAt": TIMESTAMP,- "notifications": []}],+ "notifications": [], "properties": []}],}}}),Some(VIEWER),);diff --git a/apps/web/tests/native/README.md b/apps/web/tests/native/README.mdindex 6192c10636..f1cfe389b8 100644--- a/apps/web/tests/native/README.md+++ b/apps/web/tests/native/README.md@@ -65,6 +65,67 @@ changing filters. Tab changes use the app's public numeric hotkeys (2 / 7) andverify `aria-current` before checking results. Assertions compare exact rowidentities, not just counts.+## Exhaustive filter-selection matrix++```sh+bun run native:e2e:matrix+```++This uses the new Email, Tasks and Channels views and the current Files view.+It generates requests with their **production query builders**, including the+real Files presets/type refinements and GraphQL translation. Grouping is pinned+to `none` and sorting to `UPDATED_AT DESC`; neither selector is covered yet.++The Cartesian product includes every static option and every subset of the+bounded fixture domains (two people, two tags and two linked inboxes, including+both All inboxes and an explicit empty inbox selection). Registry assertions+fail when a UI gains an option/facet that has not been added to the matrix.+The corpus has 75 entities and fits within one initial page: this suite does+not claim coverage of non-Mail offline pagination or every possible real-world+user/tag/file value.++After all five real backfill lanes finish, the fixture API and WebSockets are+closed. The browser-side runner calls the real Tauri cache host in bounded+read-only batches and asserts exact matching IDs against fixture truth. No+query-specific network baselines are supplied. Mail attachment selections also+run the production client predicates against records selected from the native+cache. Only identical native requests within a batch are shared (attachment+chips intentionally do not change the server AST); every selection is asserted.++Progress and failing inputs are saved to `filter-matrix.json`; the first request+is also saved before native evaluation. Exact per-view count assertions guard+against silently omitted selections: Email 20,160; Tasks 98,304; Files 69,632;+Channels 3. The exhaustive suite has a 90-minute watchdog (individual native+command timeouts are unchanged), rather than the smoke suite's four minutes.+To isolate a failure, use `bun run native:e2e:matrix --matrix-view=tasks`+(or `email`, `files`, `channels`). A focused run is not a full-matrix pass.+The test build keeps the development UI protocol but optimizes the Turso VM.+`filter-corpus.ts` owns fixture facts; `filter-capsules.json` is generated by the+canonical Rust capsule encoder, not a hand-built wire format. After changing+fixture document IDs or server-only facts, regenerate inside Nix:++```sh+bun run native:e2e:generate-fixtures+```++### Shared Files creator regression++```sh+bun run native:e2e:matrix --matrix-view=files-shared-creators+```++This focused 96-selection run reuses the full matrix's Files request builder,+including `applyDocumentTabScope`, the same request-time scope used online.+It checks every fixture creator/tag subset with no type filter, PDF, and PDF ++Code, on Shared and on All as a positive control for owned records. Shared + Me+must be empty; Me + another creator must return only non-owned matches; no+creator selection must return all matching Shared files. No Files query is+prefetched online, and no server membership baseline is supplied to native IPC.++The companion `document-tab-scope.test.ts` tests actual query-store edits,+clearing/restoring creator filters, and REST/flat/grouped GraphQL request parity.+The focused native run does not claim full Files matrix or grouped-offline coverage.+## Offline model and isolation`run.sh` creates unprivileged user/network/PID/mount namespaces with **only@@ -82,10 +143,10 @@ so native HTTP/WebSocket clients cannot bypass browser-only interception.Vite/WebDriver remain reachable to load lazy frontend chunks and drive controls.This models **API transport loss**, not an offline packaged-app cold launch.Linux has no iOS `NWPathMonitor`: the test does not fake `navigator.onLine` or-native reachability notifications. Dropdown filters (read/unread, done, etc.),-app restart/persistence, offline pagination, multiple accounts and iOS-reachability are follow-up scenarios. The initial test changes the real Mail-tabs, which change Soup's importance predicate and INBOX/ALL scope.+native reachability notifications. The matrix covers filter evaluation, while+the smoke scenario drives the real Mail tabs. Clicking every dropdown sequence,+packaged-app restart, non-Mail offline pagination, sorting/grouping and iOS+reachability remain separate follow-up scenarios.## Diagnostics and checksdiff --git a/apps/web/tests/native/build.sh b/apps/web/tests/native/build.shindex 7bdc5513fd..d4abfc1b4f 100644--- a/apps/web/tests/native/build.sh+++ b/apps/web/tests/native/build.sh@@ -32,6 +32,11 @@ TAURI_CONFIG=$(< "$web/tests/native/tauri.e2e.conf.json")export CARGO_TARGET_DIR="$out/cargo"\cd "$web/tauri/src-tauri"# Dev-protocol binary: Vite serves the real UI. No production bundle or OTA.-cargo build --locked -p app --no-default-features-cp "$CARGO_TARGET_DIR/debug/app" "$out/app"+# Keep the dev protocol/UI, but run the database VM with production optimization.+# Exhaustive matrices execute hundreds of thousands of real indexed queries.+cargo build --locked -p app --no-default-features \+ --config 'profile.dev.package.turso_core.opt-level=3'+# Publish atomically so an existing isolated run can finish on its old inode.+cp "$CARGO_TARGET_DIR/debug/app" "$out/app.next"+mv "$out/app.next" "$out/app"echo "Built isolated E2E application: $out/app"diff --git a/apps/web/tests/native/driver.ts b/apps/web/tests/native/driver.tsindex fed5bb39c3..aed9703926 100644--- a/apps/web/tests/native/driver.ts+++ b/apps/web/tests/native/driver.ts@@ -47,18 +47,18 @@ export async function checkpoints(browser: Browser) {);}-export async function waitForBackfill(browser: Browser) {+export async function waitForBackfill(browser: Browser, pages = 3) {await browser.waitUntil(async () =>(await checkpoints(browser)).some((checkpoint) =>checkpoint.key.endsWith(':email-filter-metadata') &&checkpoint.completed &&- checkpoint.pagesFetched === 3+ checkpoint.pagesFetched === pages),{timeout: 120_000,- timeoutMsg: 'Real metadata backfill did not checkpoint all three pages',+ timeoutMsg: `Real metadata backfill did not checkpoint all ${pages} pages`,});}diff --git a/apps/web/tests/native/filter-matrix.ts b/apps/web/tests/native/filter-matrix.tsnew file mode 100644index 0000000000..139914ec43--- /dev/null+++ b/apps/web/tests/native/filter-matrix.ts@@ -0,0 +1,604 @@+// Loaded by Vite inside the real Tauri webview, never in the Node/Bun runner.++import { print } from 'graphql';+import {+ CHANNELS_QUERY_DEFINITIONS,+ channelsQueryArgs,+} from '../../src/features/channels-view/queries';+import { EMAIL_TABS } from '../../src/features/email-view/constants';+import {+ EMAIL_FACETS,+ EMAIL_FILTER_GROUPS,+} from '../../src/features/email-view/filters/email-facets';+import { buildEmailQuery } from '../../src/features/email-view/queries/email-query';+import {+ buildDocumentTypeQuery,+ getActiveDocumentTypeFilterIds,+} from '../../src/features/next-soup/filters/configs/document-type-query';+import {+ compileToAst,+ queryStateFrom,+} from '../../src/features/next-soup/filters/filter-store';+import { mergeQuery } from '../../src/features/next-soup/filters/filter-store/query-store';+import {+ getViewPreset,+ VIEW_TAB_PRESETS,+} from '../../src/features/next-soup/sidebar/soup-filter-presets';+import { applyDocumentTabScope } from '../../src/features/next-soup/soup-view/document-tab-scope';+import { createTagFacetContext, testFacets } from '../../src/features/soup';+import { TASK_TABS } from '../../src/features/tasks-view/constants';+import {+ TASK_FACETS,+ TASK_PRIORITY_OPTIONS,+ TASK_STATUS_OPTIONS,+} from '../../src/features/tasks-view/filters/task-facets';+import { buildTaskQuery } from '../../src/features/tasks-view/queries/task-query';+import type {+ EntityFilterCacheArgs,+ EntityFilterCacheResult,+} from '../../src/lib/graphql-cache/protocol';+import { makeGraphqlSoupInput } from '../../src/lib/queries/soup/graphql/ast';+import {+ isCachedMailView,+ materializeMailView,+} from '../../src/lib/queries/soup/graphql/mail-view';+import {+ isDisplayableSoupItem,+ mapApiSoupItemToEntity,+} from '../../src/lib/queries/soup/transform-utils';+import {+ type MailItemFieldsFragment,+ MailItemFieldsFragmentDoc,+} from '../../src/lib/service-clients/service-storage/graphql/generated/graphql';+import {+ type GraphqlSoupItem,+ getGraphqlSoupCacheHost,+ mapGraphqlSoupItem,+} from '../../src/lib/service-clients/service-storage/graphql-soup';+import {+ FILE_TYPES,+ type FixtureRow,+ filterCorpus,+ LINKS,+ matrixTagSets,+ PEOPLE,+ PRIORITY,+ STATUS,+ TAG_DEFINITION,+ TAGS,+} from './fixtures/filter-corpus';+import { USER_ID } from './fixtures/mail';++const corpus = filterCorpus();+const byKey = new Map(corpus.map((row) => [key(row), row]));+const tagContext = createTagFacetContext(matrixTagSets);+const ALL_INBOXES = '__all_inboxes__';+const ordered = (ids: string[]) => [...ids].sort();+function key(row: FixtureRow) {+ return `${row.api.__typename}:${row.id}`;+}+function assert(condition: unknown, message: string): asserts condition {+ if (!condition) throw new Error(message);+}+const intersects = (selected: string[], values: readonly string[]) =>+ selected.length === 0 || selected.some((value) => values.includes(value));++function subsets(values: readonly string[]): string[][] {+ return values.reduce<string[][]>(+ (sets, value) => [...sets, ...sets.map((set) => [...set, value])],+ [[]]+ );+}+function* combinations(+ groups: Record<string, string[][]>,+ entries = Object.entries(groups),+ index = 0,+ selection: Record<string, string[]> = {}+): Generator<Record<string, string[]>> {+ if (index === entries.length) {+ yield selection;+ return;+ }+ const [id, choices] = entries[index];+ for (const choice of choices)+ yield* combinations(groups, entries, index + 1, {+ ...selection,+ [id]: choice,+ });+}+const staticChoices = (group: 'read' | 'done') => [+ [],+ ...EMAIL_FILTER_GROUPS.find((g) => g.id === group)!+ .options.filter((o) => o.id !== 'all')+ .map((o) => [o.id]),+];++type View = 'email' | 'tasks' | 'files' | 'channels';+type Scope = View | 'files-shared-creators';+type Case = {+ view: View;+ name: string;+ args: EntityFilterCacheArgs;+ expected: FixtureRow[];+ attachments?: string[];+ emailTab?: string;+};+function args(+ input: ReturnType<typeof makeGraphqlSoupInput>+): EntityFilterCacheArgs {+ assert(+ input.initial,+ 'Matrix only evaluates initial, ungrouped filter selections'+ );+ const { filters, emailView } = input.initial;+ if (emailView)+ assert(+ isCachedMailView(emailView),+ `Unsupported matrix Mail view ${emailView}`+ );+ return {+ filters: filters ?? {},+ sortMethod: 'UPDATED_AT',+ sortDirection: 'DESC',+ limit: 100,+ ...(emailView ? { mail: { view: emailView } } : { baseline: [] }),+ };+}+function translate(query: ReturnType<typeof buildEmailQuery>) {+ return args(+ makeGraphqlSoupInput({+ params: {+ ...query.params,+ sort_method: 'updated_at',+ sort_direction: 'desc',+ },+ body: query.body,+ })+ );+}+function emailMatch(+ row: FixtureRow,+ tab: string,+ selection: Record<string, string[]>+): boolean {+ if (row.kind !== 'email') return false;+ if (+ tab === 'shared'+ ? !row.shared || row.owner === USER_ID+ : !LINKS.includes(row.linkId!)+ )+ return false;+ if (tab === 'important' && (!row.signal || !row.inbox)) return false;+ if (tab === 'noise' && (row.signal || !row.inbox)) return false;+ if (tab === 'drafts' && !row.draft) return false;+ if (tab === 'sent' && !row.sent) return false;+ if (tab === 'calendar' && !row.calendar) return false;+ if (+ (selection.inboxes[0] !== ALL_INBOXES &&+ !selection.inboxes.includes(row.linkId!)) ||+ !intersects(selection.tags, row.tags)+ )+ return false;+ if (+ (selection.read[0] === 'read' && !row.read) ||+ (selection.read[0] === 'unread' && row.read)+ )+ return false;+ if (+ (selection.done[0] === 'done' && row.inbox) ||+ (selection.done[0] === 'not-done' && !row.inbox)+ )+ return false;+ return selection.calendar.length === 0 || row.calendar === true;+}++function* cases(scope?: Scope): Generator<Case> {+ const sharedCreators = scope === 'files-shared-creators';+ const view = sharedCreators ? 'files' : scope;+ // Coverage is exhaustive over the finite fixture domains, not pairwise.+ assert(+ TASK_STATUS_OPTIONS.map((o) => o.id).join() === STATUS.join(),+ 'Update status fixture domains for new UI options'+ );+ assert(+ TASK_PRIORITY_OPTIONS.map((o) => o.id).join() === PRIORITY.join(),+ 'Update priority fixture domains for new UI options'+ );+ assert(+ TASK_FACETS.map((facet) => facet.id).join() ===+ 'status,priority,assignees,created-by,tags',+ 'Add new task facets to the matrix'+ );+ assert(+ getActiveDocumentTypeFilterIds(() => true).join() === FILE_TYPES.join(),+ 'Add new file types to the matrix fixtures'+ );+ assert(+ Object.keys(VIEW_TAB_PRESETS.documents.tabs).join() ===+ 'owned,shared,attachments,folders,all',+ 'Add new Files tabs to the matrix'+ );+ assert(+ Object.keys(CHANNELS_QUERY_DEFINITIONS)+ .filter((scope) => scope !== 'search')+ .join() === 'recents,channels,direct_messages',+ 'Add new channel scopes to the matrix'+ );+ const attachmentOptions = EMAIL_FILTER_GROUPS.find(+ (g) => g.id === 'attachments'+ )!.options.map((o) => o.id);+ assert(+ attachmentOptions.join() ===+ 'attachment-pdf,attachment-image,attachment-document',+ 'Add new attachment types to matrix fixtures'+ );+ for (const tab of !view || view === 'email' ? EMAIL_TABS : []) {+ for (const selection of combinations({+ read: staticChoices('read'),+ done: staticChoices('done'),+ calendar: [[], ['has-calendar-invite']],+ tags: subsets(TAGS),+ inboxes: [[ALL_INBOXES], ...subsets(LINKS)],+ attachments: subsets(attachmentOptions),+ })) {+ const facets = {+ read: selection.read,+ done: selection.done,+ calendar: selection.calendar,+ tags: selection.tags,+ attachments: selection.attachments,+ };+ const query = buildEmailQuery({+ tab: tab.id,+ inboxIds:+ selection.inboxes[0] === ALL_INBOXES ? undefined : selection.inboxes,+ facets,+ facetContext: tagContext,+ });+ const expected: FixtureRow[] = [];+ for (const row of corpus) {+ if (emailMatch(row, tab.id, selection)) expected.push(row);+ }+ yield {+ view: 'email',+ name: `${tab.id} ${JSON.stringify(selection)}`,+ args: translate(query),+ expected,+ attachments: selection.attachments,+ emailTab: tab.id,+ };+ }+ }+ for (const tab of !view || view === 'tasks' ? TASK_TABS : []) {+ for (const selection of combinations({+ status: subsets(STATUS),+ priority: subsets(PRIORITY),+ assignees: subsets(PEOPLE),+ 'created-by': subsets(PEOPLE),+ tags: subsets(TAGS),+ })) {+ const query = buildTaskQuery({+ tab: tab.id,+ userId: USER_ID,+ facets: selection,+ facetContext: tagContext,+ groupBy: 'none',+ sort: [{ id: 'updated_at', reversed: false }],+ });+ const expected: FixtureRow[] = [];+ for (const row of corpus) {+ if (+ row.kind === 'task' &&+ (tab.id !== 'my-tasks' || row.assignees!.includes(USER_ID)) &&+ (tab.id !== 'created-by-me' || row.owner === USER_ID) &&+ intersects(selection.status, [row.status!]) &&+ intersects(selection.priority, [row.priority!]) &&+ intersects(selection.assignees, row.assignees!) &&+ intersects(selection['created-by'], [row.owner]) &&+ intersects(selection.tags, row.tags)+ )+ expected.push(row);+ }+ yield {+ view: 'tasks',+ name: `${tab.id} ${JSON.stringify(selection)}`,+ args: translate(query),+ expected,+ };+ }+ }+ for (const tab of !view || view === 'files'+ ? sharedCreators+ ? ['shared', 'all']+ : ['owned', 'shared', 'attachments', 'folders', 'all']+ : []) {+ const preset = getViewPreset('documents', tab, {+ userId: USER_ID,+ isTeamAdmin: false,+ });+ assert(preset, `Missing Files preset ${tab}`);+ for (const selection of combinations({+ type: sharedCreators+ ? [[], ['file-pdf'], ['file-pdf', 'file-code']]+ : subsets(FILE_TYPES),+ 'created-by': tab === 'owned' ? [[]] : subsets(PEOPLE),+ tags: subsets(TAGS),+ })) {+ let state = queryStateFrom(preset.filters);+ const types = buildDocumentTypeQuery(selection.type);+ if (types) state = mergeQuery(state, types);+ if (selection['created-by'].length)+ state = mergeQuery(state, {+ include: { documentOwnerId: selection['created-by'] },+ });+ state = mergeQuery(state, {+ include: {+ tagFilters: selection.tags.map((value) => ({+ propertyId: TAG_DEFINITION,+ type: 'select',+ value,+ })),+ },+ });+ const query = {+ params: { limit: 100 },+ body: compileToAst(applyDocumentTabScope(state, tab, USER_ID)),+ };+ const expected: FixtureRow[] = [];+ for (const row of corpus) {+ if (!intersects(selection.tags, row.tags)) continue;+ if (tab === 'folders') {+ if (row.kind === 'project') expected.push(row);+ continue;+ }+ if (row.kind !== 'file') continue;+ if (tab === 'owned' && (row.owner !== USER_ID || row.attachment))+ continue;+ if (tab === 'shared' && (row.owner === USER_ID || row.attachment))+ continue;+ if (tab === 'attachments' && !row.attachment) continue;+ if (+ intersects(selection['created-by'], [row.owner]) &&+ intersects(selection.type, [row.category!])+ )+ expected.push(row);+ }+ yield {+ view: 'files',+ name: `${tab} ${JSON.stringify(selection)}`,+ args: translate(query),+ expected,+ };+ }+ }+ for (const scope of !view || view === 'channels'+ ? (['recents', 'channels', 'direct_messages'] as const)+ : []) {+ assert(CHANNELS_QUERY_DEFINITIONS[scope], `Missing channel scope ${scope}`);+ yield {+ view: 'channels',+ name: scope,+ args: translate(channelsQueryArgs(scope)),+ expected: corpus.filter(+ (row) =>+ row.kind === 'channel' &&+ (scope === 'channels'+ ? !row.direct+ : scope === 'direct_messages'+ ? row.direct+ : true)+ ),+ };+ }+}++const host = (() => {+ const host = getGraphqlSoupCacheHost();+ assert(host, 'Real Tauri cache host must already be initialized');+ return host;+})();+let iterator: Generator<Case> | undefined;+const records = new Map<string, MailItemFieldsFragment>();+let revision: string | undefined;+const expectedSelectionCounts = {+ email: 20_160,+ tasks: 98_304,+ files: 69_632,+ channels: 3,+};+const progress = {+ scope: 'all' as Scope | 'all',+ evaluated: 0,+ nativeElapsedMs: 0,+ nativeRequests: 0,+ byView: {} as Record<string, number>,+ failures: [] as {+ name: string;+ error: string;+ args?: EntityFilterCacheArgs;+ fixture?: unknown;+ }[],+ done: false,+};++export function describeCases(size: number, view?: Scope) {+ const result = [];+ for (const test of cases(view)) {+ result.push({+ name: test.name,+ args: test.args,+ expected: test.expected.map(key),+ });+ if (result.length === size) break;+ }+ return result;+}++export async function runBatch(size = 128, view?: Scope) {+ if (iterator)+ assert(+ progress.scope === (view ?? 'all'),+ 'Cannot change matrix scope mid-run'+ );+ progress.scope = view ?? 'all';+ iterator ??= cases(view);+ if (!revision) {+ revision = await host.currentRevision();+ const selected = await host.readRecordsByKeys({+ document: print(MailItemFieldsFragmentDoc),+ fragmentName: 'MailItemFields',+ keys: [...byKey.keys()],+ });+ assert(+ selected.records.length === corpus.length,+ 'Every matrix entity must have been backfilled through the real API'+ );+ for (const row of selected.records)+ records.set(row.recordKey, row.record as MailItemFieldsFragment);+ }+ const batch: Case[] = [];+ for (let n = 0; n < size && !progress.done; n++) {+ const next = iterator.next();+ if (next.done) {+ progress.done = true;+ break;+ }+ batch.push(next.value);+ }+ const requests = [+ ...new Map(+ batch.map((test) => [JSON.stringify(test.args), test.args])+ ).entries(),+ ];+ const responses = new Map<string, EntityFilterCacheResult | Error>();+ // Amortize WebKit IPC round trips. The native engine still serializes every+ // evaluation through its real mutex, and no mutations run during this phase.+ const nativeStart = performance.now();+ for (let offset = 0; offset < requests.length; offset += 8) {+ await Promise.all(+ requests.slice(offset, offset + 8).map(async ([key, args]) => {+ try {+ responses.set(key, await host.entityFilter(args));+ } catch (error) {+ responses.set(+ key,+ error instanceof Error ? error : new Error(String(error))+ );+ }+ progress.nativeRequests++;+ })+ );+ }+ progress.nativeElapsedMs += performance.now() - nativeStart;+ for (const test of batch) {+ progress.evaluated++;+ progress.byView[test.view] = (progress.byView[test.view] ?? 0) + 1;+ try {+ const result = responses.get(JSON.stringify(test.args));+ if (result instanceof Error) throw result;+ assert(result, 'Missing native evaluation response');+ assert(+ result.kind === 'mail-page' || result.kind === 'reconciled',+ `Local evaluation returned ${result.kind}`+ );+ assert(result.revision === revision, 'Matrix crossed cache revisions');+ assert(+ JSON.stringify(ordered(result.keys)) ===+ JSON.stringify(ordered(test.expected.map(key))),+ `Wrong native matches: ${JSON.stringify(result.keys)}; expected ${JSON.stringify(test.expected.map(key))}`+ );+ if (result.kind === 'reconciled')+ assert(+ result.retainedKeys.length === 0,+ 'Matrix must not use server membership baselines'+ );+ if (test.attachments && result.kind === 'mail-page') {+ const view = test.args.mail!.view;+ const actual = result.keys.filter((key, i) => {+ const record = records.get(key);+ assert(record, `No normalized record for ${key}`);+ const projected = materializeMailView(+ record,+ view,+ result.sortTimestamps[i]+ );+ assert(projected, 'Canonical Mail preview is missing');+ const item = mapGraphqlSoupItem(projected as GraphqlSoupItem);+ assert(+ item && isDisplayableSoupItem(item),+ 'Cannot materialize Mail row'+ );+ const entity = mapApiSoupItemToEntity(item);+ assert(entity.type === 'email', 'Expected email entity');+ return testFacets(+ { attachments: test.attachments ?? [] },+ EMAIL_FACETS,+ entity,+ tagContext+ );+ });+ const expected = test.expected+ .filter(+ (row) =>+ !test.attachments!.length ||+ test.attachments!.includes(`attachment-${row.attachmentKind}`)+ )+ .map(key);+ assert(+ JSON.stringify(ordered(actual)) === JSON.stringify(ordered(expected)),+ 'Cached attachment refinement differs from fixture truth'+ );+ }+ } catch (error) {+ if (progress.failures.length < 20)+ progress.failures.push({+ name: `${test.view}: ${test.name}`,+ error: String(error),+ args: test.args,+ fixture:+ test.view === 'email'+ ? {+ links: LINKS,+ rows: corpus+ .filter((row) => row.kind === 'email')+ .map((row) => ({+ id: row.id,+ link: row.linkId,+ sent: row.sent,+ owner: row.owner,+ tags: row.tags,+ })),+ }+ : undefined,+ });+ }+ }+ try {+ assert(+ (await host.currentRevision()) === revision,+ 'Cache changed during the filter-only matrix'+ );+ } catch (error) {+ // Preserve the earlier failing inputs even if an outstanding native command+ // also prevents the final revision read from completing.+ if (progress.failures.length < 20)+ progress.failures.push({+ name: 'post-batch cache revision',+ error: String(error),+ });+ }+ if (progress.done) {+ const counts =+ view === 'files-shared-creators'+ ? { files: 96 }+ : expectedSelectionCounts;+ for (const [surface, count] of Object.entries(counts)) {+ if (!view || view === 'files-shared-creators' || view === surface)+ assert(+ progress.byView[surface] === count,+ `Selection coverage changed for ${surface}: ${progress.byView[surface]} != ${count}`+ );+ }+ }+ return progress;+}diff --git a/apps/web/tests/native/fixtures/filter-capsules.json b/apps/web/tests/native/fixtures/filter-capsules.jsonnew file mode 100644index 0000000000..c0db0b626c--- /dev/null+++ b/apps/web/tests/native/fixtures/filter-capsules.json@@ -0,0 +1,62 @@+{+ "00000000-0000-0000-0000-000000000101": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMDEIZG9jdW1lbnQBAQA",+ "00000000-0000-0000-0000-000000000102": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMDIIZG9jdW1lbnQAAQA",+ "00000000-0000-0000-0000-000000000103": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMDMIZG9jdW1lbnQAAQA",+ "00000000-0000-0000-0000-000000000104": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMDQIZG9jdW1lbnQBAQA",+ "00000000-0000-0000-0000-000000000105": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMDUIZG9jdW1lbnQAAQA",+ "00000000-0000-0000-0000-000000000106": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMDYIZG9jdW1lbnQAAQA",+ "00000000-0000-0000-0000-000000000107": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMDcIZG9jdW1lbnQBAQA",+ "00000000-0000-0000-0000-000000000108": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMDgIZG9jdW1lbnQAAQA",+ "00000000-0000-0000-0000-000000000109": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMDkIZG9jdW1lbnQAAQA",+ "00000000-0000-0000-0000-000000000110": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMTAIZG9jdW1lbnQBAQA",+ "00000000-0000-0000-0000-000000000111": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMTEIZG9jdW1lbnQAAQA",+ "00000000-0000-0000-0000-000000000112": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMTIIZG9jdW1lbnQAAQA",+ "00000000-0000-0000-0000-000000000113": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMTMIZG9jdW1lbnQBAQA",+ "00000000-0000-0000-0000-000000000114": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMTQIZG9jdW1lbnQAAQA",+ "00000000-0000-0000-0000-000000000115": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMTUIZG9jdW1lbnQAAQA",+ "00000000-0000-0000-0000-000000000116": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMTYIZG9jdW1lbnQBAQA",+ "00000000-0000-0000-0000-000000000117": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMTcIZG9jdW1lbnQAAQA",+ "00000000-0000-0000-0000-000000000118": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMTgIZG9jdW1lbnQAAQA",+ "00000000-0000-0000-0000-000000000119": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMTkIZG9jdW1lbnQBAQA",+ "00000000-0000-0000-0000-000000000120": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAxMjAIZG9jdW1lbnQAAQA",+ "00000000-0000-0000-0000-000000000201": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMDEIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAQ",+ "00000000-0000-0000-0000-000000000202": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMDIIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAQ",+ "00000000-0000-0000-0000-000000000203": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMDMIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAQ",+ "00000000-0000-0000-0000-000000000204": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMDQIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAQ",+ "00000000-0000-0000-0000-000000000205": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMDUIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAg",+ "00000000-0000-0000-0000-000000000206": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMDYIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAg",+ "00000000-0000-0000-0000-000000000207": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMDcIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAg",+ "00000000-0000-0000-0000-000000000208": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMDgIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAg",+ "00000000-0000-0000-0000-000000000209": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMDkIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAw",+ "00000000-0000-0000-0000-000000000210": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMTAIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAw",+ "00000000-0000-0000-0000-000000000211": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMTEIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAw",+ "00000000-0000-0000-0000-000000000212": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMTIIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAw",+ "00000000-0000-0000-0000-000000000213": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMTMIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAABA",+ "00000000-0000-0000-0000-000000000214": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMTQIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAABA",+ "00000000-0000-0000-0000-000000000215": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMTUIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAABA",+ "00000000-0000-0000-0000-000000000216": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMTYIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAABA",+ "00000000-0000-0000-0000-000000000217": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMTcIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAABQ",+ "00000000-0000-0000-0000-000000000218": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMTgIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAABQ",+ "00000000-0000-0000-0000-000000000219": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMTkIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAABQ",+ "00000000-0000-0000-0000-000000000220": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMjAIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAABQ",+ "00000000-0000-0000-0000-000000000221": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMjEIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAQ",+ "00000000-0000-0000-0000-000000000222": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMjIIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAQ",+ "00000000-0000-0000-0000-000000000223": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMjMIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAQ",+ "00000000-0000-0000-0000-000000000224": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMjQIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAQ",+ "00000000-0000-0000-0000-000000000225": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMjUIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAg",+ "00000000-0000-0000-0000-000000000226": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMjYIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAg",+ "00000000-0000-0000-0000-000000000227": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMjcIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAg",+ "00000000-0000-0000-0000-000000000228": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMjgIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAg",+ "00000000-0000-0000-0000-000000000229": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMjkIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAw",+ "00000000-0000-0000-0000-000000000230": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMzAIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAw",+ "00000000-0000-0000-0000-000000000231": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMzEIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAw",+ "00000000-0000-0000-0000-000000000232": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMzIIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAAAw",+ "00000000-0000-0000-0000-000000000233": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMzMIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAABA",+ "00000000-0000-0000-0000-000000000234": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMzQIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAABA",+ "00000000-0000-0000-0000-000000000235": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMzUIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAABA",+ "00000000-0000-0000-0000-000000000236": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMzYIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAABA",+ "00000000-0000-0000-0000-000000000237": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMzcIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAABQ",+ "00000000-0000-0000-0000-000000000238": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMzgIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAABQ",+ "00000000-0000-0000-0000-000000000239": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyMzkIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAABQ",+ "00000000-0000-0000-0000-000000000240": "Agxzb3VwLWZsYXQtdjM4R3JhcGhxbFNvdXBEb2N1bWVudDowMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAyNDAIZG9jdW1lbnQAAQEQAAAAAQAAAAAAAgAAAAAABQ"+}diff --git a/apps/web/tests/native/fixtures/filter-corpus.ts b/apps/web/tests/native/fixtures/filter-corpus.tsnew file mode 100644index 0000000000..f4a70581a5--- /dev/null+++ b/apps/web/tests/native/fixtures/filter-corpus.ts@@ -0,0 +1,406 @@+import {+ PROPERTY_OPTION_IDS,+ SYSTEM_PROPERTY_IDS,+} from '../../../src/features/property/identifiers';+import { mailProjectionCapsules } from '../../../src/lib/graphql-cache/worker/browser-test/mail-projection-capsules';+import type { TagSetResponse } from '../../../src/lib/service-clients/service-properties/generated/schemas/tagSetResponse';+import { EMAIL, fixtureId as id, USER_ID } from './mail';++export const PEOPLE = [USER_ID, 'macro|[email protected]'];+export const TAG_DEFINITION = id(7000);+export const TAGS = [id(7001), id(7002)];+export const LINKS = [id(1000), id(1001)];+export const STATUS = [+ 'not-started',+ 'in-progress',+ 'in-review',+ 'completed',+ 'canceled',+];+export const PRIORITY = ['urgent', 'high', 'medium', 'low'];+const statusIds = Object.values(PROPERTY_OPTION_IDS.STATUS);+const priorityIds = [+ PROPERTY_OPTION_IDS.PRIORITY.URGENT,+ PROPERTY_OPTION_IDS.PRIORITY.HIGH,+ PROPERTY_OPTION_IDS.PRIORITY.MEDIUM,+ PROPERTY_OPTION_IDS.PRIORITY.LOW,+];+export const FILE_TYPES = [+ 'doc-markdown',+ 'doc-canvas',+ 'file-code',+ 'file-image',+ 'file-pdf',+ 'file-docx',+ 'file-video',+ 'doc-snippet',+ 'doc-skill',+ 'file-other',+];+const fileTypes = [+ 'md',+ 'canvas',+ 'ts',+ 'png',+ 'pdf',+ 'docx',+ 'mp4',+ 'md',+ 'md',+ 'bin',+];+export const TIMESTAMP = '2025-01-04T00:00:00Z';++export type FixtureRow = {+ kind: 'file' | 'task' | 'project' | 'channel' | 'email';+ id: string;+ owner: string;+ tags: string[];+ fileType?: string;+ category?: string;+ attachment?: boolean;+ status?: string;+ priority?: string;+ assignees?: string[];+ linkId?: string;+ signal?: boolean;+ read?: boolean;+ inbox?: boolean;+ calendar?: boolean;+ shared?: boolean;+ draft?: boolean;+ sent?: boolean;+ attachmentKind?: 'pdf' | 'image' | 'document';+ direct?: boolean;+ api: Record<string, unknown>;+};++function property(+ n: number,+ definition: string,+ values: string[],+ entity = false+) {+ return {+ id: id(n),+ propertyDefinitionId: definition,+ displayName: definition,+ dataType: entity+ ? 'ENTITY'+ : definition === TAG_DEFINITION+ ? 'TAG'+ : 'SELECT_STRING',+ isMultiSelect: entity || definition === TAG_DEFINITION,+ specificEntityType: entity ? 'USER' : null,+ isSystem: definition !== TAG_DEFINITION,+ isMetadata: false,+ value: entity+ ? {+ __typename: 'GraphqlEntityReferencePropertyValue',+ references: values.map((entityId) => ({+ entityId,+ entityType: 'USER',+ specificMessageId: null,+ })),+ }+ : { __typename: 'GraphqlSelectOptionPropertyValue', optionIds: values },+ };+}+const tagsFor = (n: number) => TAGS.filter((_, bit) => (n & (1 << bit)) !== 0);++/** Portable API fixtures shared by browser-side matrix assertions and the HTTP server. */+export function filterCorpus(+ capsules: Readonly<Record<string, string>> = {}+): FixtureRow[] {+ const result: FixtureRow[] = [];+ for (let n = 0; n < 40; n++) {+ const index = 201 + n;+ const status = Math.floor((n % 20) / 4);+ const priority = n % 4;+ const owner = PEOPLE[Math.floor(n / 20)];+ const assignees = PEOPLE.filter(+ (_, bit) => ((n + Math.floor(n / 20)) & (1 << bit)) !== 0+ );+ const tags = tagsFor(n + Math.floor(n / 4));+ result.push({+ kind: 'task',+ id: id(index),+ owner,+ tags,+ status: STATUS[status],+ priority: PRIORITY[priority],+ assignees,+ api: {+ __typename: 'GraphqlSoupDocument',+ id: id(index),+ entityType: 'DOCUMENT',+ name: `Task ${index}`,+ displayName: `Task ${index}`,+ cacheProjection: capsules[id(index)],+ ownerId: owner,+ fileType: 'md',+ projectId: null,+ createdAt: TIMESTAMP,+ updatedAt: TIMESTAMP,+ viewedAt: null,+ deletedAt: null,+ subType: { __typename: 'GraphqlTaskSubType', isCompleted: status >= 3 },+ notifications: [],+ isFavorited: false,+ properties: [+ property(index * 10, SYSTEM_PROPERTY_IDS.STATUS, [statusIds[status]]),+ property(index * 10 + 1, SYSTEM_PROPERTY_IDS.PRIORITY, [+ priorityIds[priority],+ ]),+ property(+ index * 10 + 2,+ SYSTEM_PROPERTY_IDS.ASSIGNEES,+ assignees,+ true+ ),+ property(index * 10 + 3, TAG_DEFINITION, tags),+ ],+ },+ });+ }+ for (let n = 0; n < 20; n++) {+ const index = 101 + n;+ const category = n % FILE_TYPES.length;+ const owner = PEOPLE[Math.floor(n / 10)];+ const tags = tagsFor(n);+ const attachment = n % 3 === 0;+ result.push({+ kind: 'file',+ id: id(index),+ owner,+ tags,+ category: FILE_TYPES[category],+ fileType: fileTypes[category],+ attachment,+ api: {+ __typename: 'GraphqlSoupDocument',+ id: id(index),+ entityType: 'DOCUMENT',+ name: `File ${index}`,+ displayName: `File ${index}`,+ cacheProjection: capsules[id(index)],+ ownerId: owner,+ fileType: fileTypes[category],+ projectId: null,+ createdAt: TIMESTAMP,+ updatedAt: TIMESTAMP,+ viewedAt: null,+ deletedAt: null,+ subType:+ category === 7+ ? { __typename: 'GraphqlSnippetSubType' }+ : category === 8+ ? { __typename: 'GraphqlSkillSubType' }+ : null,+ notifications: [],+ isFavorited: false,+ properties: [property(index * 10 + 3, TAG_DEFINITION, tags)],+ },+ });+ }+ for (let n = 0; n < 2; n++) {+ const index = 401 + n;+ const tags = [TAGS[n]];+ result.push({+ kind: 'project',+ id: id(index),+ owner: PEOPLE[n],+ tags,+ api: {+ __typename: 'GraphqlSoupProject',+ id: id(index),+ entityType: 'PROJECT',+ name: `Folder ${index}`,+ displayName: `Folder ${index}`,+ ownerId: PEOPLE[n],+ parentId: null,+ createdAt: TIMESTAMP,+ updatedAt: TIMESTAMP,+ viewedAt: null,+ deletedAt: null,+ cacheProjection: null,+ notifications: [],+ isFavorited: false,+ properties: [property(index * 10, TAG_DEFINITION, tags)],+ },+ });+ }+ for (let n = 0; n < 3; n++) {+ const index = 501 + n;+ const message = {+ messageId: id(index + 10000),+ channelId: id(index),+ threadId: null,+ senderId: USER_ID,+ content: `Message ${index}`,+ createdAt: TIMESTAMP,+ updatedAt: TIMESTAMP,+ deletedAt: null,+ mentions: [],+ };+ result.push({+ kind: 'channel',+ id: id(index),+ owner: USER_ID,+ tags: [],+ direct: n === 2,+ api: {+ __typename: 'GraphqlSoupChannel',+ id: id(index),+ entityType: 'CHANNEL',+ name: `Channel ${index}`,+ displayName: `Channel ${index}`,+ channelType:+ n === 2 ? 'direct_message' : n === 1 ? 'private' : 'public',+ ownerId: USER_ID,+ organizationId: null,+ teamId: null,+ createdAt: TIMESTAMP,+ updatedAt: TIMESTAMP,+ viewedAt: null,+ interactedAt: null,+ isParticipant: true,+ participants: [+ {+ channelId: id(index),+ userId: USER_ID,+ role: 'owner',+ joinedAt: TIMESTAMP,+ leftAt: null,+ },+ ],+ latestMessage: message,+ latestNonThreadMessage: message,+ notifications: [],+ cacheProjection: null,+ isFavorited: false,+ },+ });+ }+ for (const n of [3, 4, 6, 8, 9, 10, 12, 60, 71, 72]) {+ const owner = n < 50 ? USER_ID : PEOPLE[1];+ const linkId = n < 50 ? LINKS[0] : n === 60 ? LINKS[1] : id(9999);+ const tags = tagsFor(n);+ const preview = (offset: number, subject: string) => ({+ id: id(n + offset),+ subject,+ snippet: subject,+ isDraft: offset === 20000,+ senderEmail: '[email protected]',+ senderName: 'Sender',+ senderPhotoUrl: null,+ });+ const attachmentKind = (['pdf', 'image', 'document'] as const)[n % 3];+ result.push({+ kind: 'email',+ id: id(n),+ owner,+ tags,+ linkId,+ signal: n % 3 === 0,+ read: n % 4 === 0,+ inbox: n % 2 === 0,+ calendar: n % 5 === 0,+ shared: n === 60 || n >= 71,+ draft: n % 3 === 0,+ // The canonical capsule for row 4 intentionally has no outbound timestamp.+ sent: n % 4 === 0 && n !== 4,+ attachmentKind,+ api: {+ __typename: 'GraphqlSoupEmailThread',+ id: id(n),+ entityType: 'EMAIL_THREAD',+ name: `Email ${n}`,+ displayName: `Email ${n}`,+ ownerId: owner,+ linkId,+ inboxVisible: n % 2 === 0,+ isRead: n % 4 === 0,+ isSignal: n % 3 === 0,+ isImportant: n % 3 === 0,+ isDraft: false,+ snippet: `Email ${n}`,+ senderEmail: '[email protected]',+ senderName: 'Sender',+ senderPhotoUrl: null,+ cacheProjection: mailProjectionCapsules[n - 1],+ latestInboundMessageTs: '2025-01-02T00:00:00Z',+ sortTs: TIMESTAMP,+ createdAt: TIMESTAMP,+ updatedAt: TIMESTAMP,+ viewedAt: null,+ mailAllPreview: preview(10000, `Email ${n}`),+ mailDraftPreview: n % 3 === 0 ? preview(20000, `Draft ${n}`) : null,+ mailSentPreview: n % 4 === 0 ? preview(30000, `Sent ${n}`) : null,+ notifications: [],+ participants: [],+ labels: [],+ isFavorited: false,+ attachments: [+ {+ id: id(9000 + n),+ messageId: id(n + 10000),+ providerAttachmentId: 'fixture',+ filename: `attachment.${attachmentKind === 'image' ? 'png' : attachmentKind === 'document' ? 'docx' : 'pdf'}`,+ mimeType:+ attachmentKind === 'image'+ ? 'image/png'+ : attachmentKind === 'pdf'+ ? 'application/pdf'+ : 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',+ sizeBytes: 100,+ contentId: null,+ createdAt: TIMESTAMP,+ },+ ],+ properties: [property(8000 + n, TAG_DEFINITION, tags)],+ },+ });+ }+ return result;+}++export const matrixAccounts = LINKS.map((id, n) => ({+ id,+ emailAddress: n === 0 ? EMAIL : '[email protected]',+ photoUrl: null,+}));+export const matrixTagSets: TagSetResponse[] = [+ {+ scope: 'user',+ definition: {+ id: TAG_DEFINITION,+ displayName: 'Fixture tags',+ dataType: 'TAG',+ isMetadata: false,+ isMultiSelect: true,+ isSystem: false,+ scope: 'user',+ user_id: USER_ID,+ },+ options: TAGS.map((id, n) => ({+ id,+ propertyDefinitionId: TAG_DEFINITION,+ displayOrder: n,+ color: null,+ value: { type: 'string', value: `Tag ${n + 1}` },+ })),+ },+];++export function documentCapsuleInputs() {+ return filterCorpus()+ .filter((row) => row.kind === 'file' || row.kind === 'task')+ .map((row) => ({+ id: row.id,+ isEmailAttachment: row.attachment ?? false,+ statusOptionIds: row.status+ ? [statusIds[STATUS.indexOf(row.status)]]+ : [],+ }));+}diff --git a/apps/web/tests/native/fixtures/server.test.ts b/apps/web/tests/native/fixtures/server.test.tsindex 27626ee348..652eb64ad6 100644--- a/apps/web/tests/native/fixtures/server.test.ts+++ b/apps/web/tests/native/fixtures/server.test.ts@@ -1,10 +1,12 @@import { afterEach, expect, test } from 'bun:test';import { type DocumentNode, type ExecutionResult, print, visit } from 'graphql';import {+ SoupBackfillDocument,SoupDocument,type SoupInput,SoupMailBackfillDocument,type SoupQuery,+ SoupSharedMailBackfillDocument,} from '../../../src/lib/service-clients/service-storage/graphql/generated/graphql';import { fixtureId } from './mail';import { startFixtureServer } from './server';@@ -211,6 +213,44 @@ for (const [name, input] of invalidSignalInputs) {});}+test('matrix fixtures validate against the production backfill selections', async () => {+ server = startFixtureServer(0, true);+ for (const [document, operationName, input, count] of [+ [+ SoupBackfillDocument,+ 'SoupBackfill',+ {+ initial: {+ limit: 100,+ emailView: 'ALL',+ filters: {+ emailFilter: { tree: { literal: { threadId: fixtureId(0) } } },+ },+ },+ },+ 65,+ ],+ [+ SoupSharedMailBackfillDocument,+ 'SoupSharedMailBackfill',+ { initial: { limit: 100, emailView: 'ALL' } },+ 3,+ ],+ ] as const) {+ const response = await fetch(`${server.origin}/dss/items/soup/graphql`, {+ method: 'POST',+ body: JSON.stringify({+ query: transportQuery(document),+ operationName,+ variables: { input },+ }),+ });+ const result = await response.json();+ expect(result.errors).toBeUndefined();+ expect(result.data.user.soup.items).toHaveLength(count);+ }+});+test('unknown endpoints fail closed; disconnect removes the TCP listener', async () => {server = startFixtureServer();expect((await fetch(`${server.origin}/unimplemented`)).status).toBe(501);diff --git a/apps/web/tests/native/fixtures/server.ts b/apps/web/tests/native/fixtures/server.tsindex 1c9e8d451f..7293d8ac6e 100644--- a/apps/web/tests/native/fixtures/server.ts+++ b/apps/web/tests/native/fixtures/server.ts@@ -1,6 +1,14 @@import { buildSchema, graphql } from 'graphql';import type { SoupInput } from '../../../src/lib/service-clients/service-storage/graphql/generated/graphql';import { bootstrapResponses } from './bootstrap';+import capsules from './filter-capsules.json';+import {+ filterCorpus,+ LINKS,+ matrixAccounts,+ matrixTagSets,+ PEOPLE,+} from './filter-corpus';import { accounts, fixtureId, mail, USER_ID } from './mail';const schema = buildSchema(@@ -27,7 +35,32 @@ export type RequestRecord = {/** HTTP fixtures at the production API paths: real platformFetch, urql,* checkpointed backfill, normalization and native storage remain in the app.* No forwarding to a hosted backend, cache seeding, or filter-result injection. */-export function startFixtureServer(port = 0) {+export function startFixtureServer(port = 0, filterMatrix = false) {+ const corpus = filterMatrix ? filterCorpus(capsules) : undefined;+ const metadataMail = corpus+ ? corpus+ .filter(+ (row) => row.kind === 'email' && LINKS.includes(row.linkId ?? '')+ )+ .map((row) => row.api)+ : mail;+ const sharedMail =+ corpus+ ?.filter((row) => row.kind === 'email' && row.shared)+ .map((row) => row.api) ?? [];+ const core =+ corpus?.filter((row) => row.kind !== 'email').map((row) => row.api) ?? [];+ const signalMail = corpus+ ? corpus+ .filter(+ (row) =>+ row.kind === 'email' &&+ row.signal &&+ row.inbox &&+ LINKS.includes(row.linkId ?? '')+ )+ .map((row) => row.api)+ : [mail[1], mail[5]];const requests: RequestRecord[] = [];const pageSize = 2;const cursors = new Map<string, number>();@@ -45,19 +78,22 @@ export function startFixtureServer(port = 0) {}const nextOffset = offset + pageSize;const nextCursor =- nextOffset < mail.length ? `metadata-${nextOffset}` : null;+ nextOffset < metadataMail.length ? `metadata-${nextOffset}` : null;if (nextCursor) cursors.set(nextCursor, nextOffset);pagesServed += 1;- return { items: mail.slice(offset, nextOffset), nextCursor };+ return { items: metadataMail.slice(offset, nextOffset), nextCursor };}- // This fixture has metadata, no core/shared entities or message bodies.- if (- operation === 'SoupBackfill' ||- operation === 'SoupSharedMailBackfill' ||- operation === 'SoupNotifications'- ) {- return { items: [], nextCursor: null };+ if (operation === 'SoupSharedMailBackfill')+ return { items: sharedMail, nextCursor: null };+ if (operation === 'SoupBackfill') {+ const coreLane =+ input.initial?.filters?.emailFilter?.tree?.literal?.threadId ===+ fixtureId(0) &&+ input.initial.filters.documentFilter?.literal?.id !== fixtureId(0);+ return { items: coreLane ? core : [], nextCursor: null };}+ if (operation === 'SoupNotifications')+ return { items: [], nextCursor: null };if (operation === 'Soup') {// The app sidebar also queries channel Soup, explicitly excluding mail.if (excludesMail(input)) {@@ -71,7 +107,7 @@ export function startFixtureServer(port = 0) {) {throw new Error('Only the initial Signal view may be fetched online');}- return { items: [mail[1], mail[5]], nextCursor: null };+ return { items: signalMail, nextCursor: null };}throw new Error(`Unimplemented Soup operation: ${operation}`);}@@ -103,7 +139,7 @@ export function startFixtureServer(port = 0) {rootValue: {user: {id: USER_ID,- emailLinks: accounts,+ emailLinks: filterMatrix ? matrixAccounts : accounts,emailLabels: [],favorites: [],soup: ({ input }: { input: SoupInput }) =>@@ -143,6 +179,18 @@ export function startFixtureServer(port = 0) {if (server.upgrade(request, { data: { path } })) return;throw new Error('WebSocket upgrade failed');}+ if (+ filterMatrix &&+ request.method === 'GET' &&+ path === '/dss/properties/tags'+ )+ return json(matrixTagSets);+ if (+ filterMatrix &&+ request.method === 'GET' &&+ path === '/contacts/contacts'+ )+ return json({ contacts: PEOPLE });const bootstrap = bootstrapResponses.get(`${request.method} ${path}`);if (bootstrap) return json(bootstrap.body, bootstrap.status);if (path === '/dss/items/soup/graphql' && request.method === 'POST') {@@ -181,6 +229,8 @@ export function startFixtureServer(port = 0) {get socketCount() {return sockets.size;},+ expectedMetadataPages: Math.ceil(metadataMail.length / pageSize),+ initialSignalIds: signalMail.map((row) => String(row.id)),get metadataPagesServed() {return pagesServed;},diff --git a/apps/web/tests/native/generate-fixtures.ts b/apps/web/tests/native/generate-fixtures.tsnew file mode 100644index 0000000000..663c67426a--- /dev/null+++ b/apps/web/tests/native/generate-fixtures.ts@@ -0,0 +1,33 @@+import { resolve } from 'node:path';+import { documentCapsuleInputs } from './fixtures/filter-corpus';++const web = resolve(import.meta.dirname, '../..');+const child = Bun.spawn(+ [+ 'cargo',+ 'run',+ '--quiet',+ '-p',+ 'soup-filter-cache-adapter',+ '--example',+ 'filter_fixture_capsules',+ ],+ {+ cwd: resolve(web, '../..'),+ env: {+ ...process.env,+ CARGO_TARGET_DIR:+ process.env.CARGO_TARGET_DIR ?? resolve(web, 'tauri/target/e2e/cargo'),+ },+ stdin: new Blob([JSON.stringify(documentCapsuleInputs())]),+ stdout: 'pipe',+ stderr: 'inherit',+ }+);+const capsules = await new Response(child.stdout).text();+if (await child.exited)+ throw new Error('Canonical Rust fixture encoding failed');+JSON.parse(capsules);+const path = resolve(import.meta.dirname, 'fixtures/filter-capsules.json');+await Bun.write(path, capsules);+console.log(`Generated ${path}`);diff --git a/apps/web/tests/native/runner.ts b/apps/web/tests/native/runner.tsindex e0f5d7deee..c88fc3b35c 100644--- a/apps/web/tests/native/runner.ts+++ b/apps/web/tests/native/runner.ts@@ -20,10 +20,25 @@ assert.equal('Use run.sh: native tests must have network isolation');assert(- process.argv.slice(2).every((arg) => arg === '--smoke'),- 'Usage: native:e2e [--smoke]'+ process.argv+ .slice(2)+ .every(+ (arg) =>+ arg === '--smoke' ||+ arg === '--matrix' ||+ /^--matrix-view=(email|tasks|files|channels|files-shared-creators)$/.test(+ arg+ )+ ),+ 'Usage: native:e2e [--smoke | --matrix [--matrix-view=email|tasks|files|channels|files-shared-creators]]');const smokeOnly = process.argv.includes('--smoke');+const matrixMode = process.argv.includes('--matrix');+const matrixView = process.argv+ .find((arg) => arg.startsWith('--matrix-view='))+ ?.split('=')[1];+assert(!matrixView || matrixMode, '--matrix-view requires --matrix');+assert(!(smokeOnly && matrixMode), 'Choose smoke or matrix mode');const web = resolve(import.meta.dirname, '../..');const binaries = resolve(web, 'tauri/target/e2e');const artifacts = resolve(@@ -48,7 +63,8 @@ const env = {};const children: ReturnType<typeof Bun.spawn>[] = [];let browser: Browser | undefined;-const fixture = startFixtureServer(18090);+const fixture = startFixtureServer(18090, matrixMode);+const timeoutMs = matrixMode ? 90 * 60_000 : 240_000;// Bound even a wedged WebDriver request or shutdown. The shell owns namespace// and profile cleanup, so forced exit cannot leave an app or fixture listening.const watchdog = setTimeout(() => {@@ -56,9 +72,9 @@ const watchdog = setTimeout(() => {resolve(artifacts, 'requests.json'),JSON.stringify(fixture.requests, null, 2));- console.error(`E2E timed out after four minutes. Artifacts: ${artifacts}`);+ console.error(`E2E timed out after ${timeoutMs}ms. Artifacts: ${artifacts}`);process.exit(1);-}, 240_000);+}, timeoutMs);function spawn(name: string, cmd: string[], extraEnv = {}) {const child = Bun.spawn(cmd, {@@ -128,6 +144,7 @@ try {VITE_ENABLE_GRAPHQL_SOUP: 'true',VITE_ENABLE_GRAPHQL_BACKFILL: 'true',VITE_ENABLE_NEW_APP_VIEWS: 'true',+ VITE_ENABLE_SNIPPETS: 'true',VITE_ENABLE_AUTO_UPDATE_UI: 'false',});@@ -157,9 +174,19 @@ try {const emailNavigation = browser.$('button[aria-label="Go to Email"]');await emailNavigation.waitForDisplayed({ timeout: 120_000 });await emailNavigation.click();- console.log('Waiting for three metadata backfill pages');- await waitForBackfill(browser);- assert.equal(fixture.metadataPagesServed, 3);+ console.log(+ `Waiting for ${fixture.expectedMetadataPages} metadata backfill pages`+ );+ await waitForBackfill(browser, fixture.expectedMetadataPages);+ if (matrixMode)+ await browser.waitUntil(+ async () => {+ const lanes = await checkpoints(browser!);+ return lanes.length === 5 && lanes.every((lane) => lane.completed);+ },+ { timeout: 60_000 }+ );+ assert.equal(fixture.metadataPagesServed, fixture.expectedMetadataPages);assert.deepEqual(fixture.requests.filter((request) => request.error),[]@@ -173,7 +200,7 @@ try {(await stat(cacheFile)).size > 0,'Expected the isolated native Turso database');- await expectRows(browser, [6, 12]);+ await expectRows(browser, matrixMode ? [6, 12, 60] : [6, 12]);const onlineSoupRequests = fixture.requests.filter((request) =>request.operation === 'Soup' &&@@ -184,7 +211,7 @@ try {'Initial Signal baseline must come from the API');console.log(- 'PASS: real UI, three backfill pages, and all six records in the native cache'+ `PASS: real UI, ${fixture.expectedMetadataPages} metadata pages, and native control records`);assert.equal(await nativeHttpReachable(browser, fixture.origin), true);@@ -200,7 +227,72 @@ try {);// Native storage still works with the API listener gone.await assertNativeRecords(browser);- if (!smokeOnly) {+ if (matrixMode) {+ await browser.setTimeout({ script: 120_000 });+ const preview = await browser.executeAsync(+ (view: string | undefined, done: (value: unknown) => void) => {+ void (async () => {+ const path = '/tests/native/filter-matrix.ts';+ const matrix = await import(path);+ done(matrix.describeCases(1, view));+ })();+ },+ matrixView+ );+ await Bun.write(+ resolve(artifacts, 'matrix-first-case.json'),+ JSON.stringify(preview, null, 2)+ );+ let progress: {+ done: boolean;+ evaluated: number;+ nativeRequests: number;+ nativeElapsedMs: number;+ byView: Record<string, number>;+ failures: { name: string; error: string }[];+ };+ do {+ const response = await browser.executeAsync(+ (+ view: string | undefined,+ done: (value: { progress?: typeof progress; error?: string }) => void+ ) => {+ void (async () => {+ try {+ const path = '/tests/native/filter-matrix.ts';+ const matrix = await import(path);+ done({ progress: await matrix.runBatch(256, view) });+ } catch (error) {+ done({ error: String(error) });+ }+ })();+ },+ matrixView+ );+ assert(+ response.progress,+ response.error ?? 'Matrix returned no progress'+ );+ progress = response.progress;+ console.log(+ `Matrix: ${progress.evaluated} selections, ${progress.nativeRequests} native evaluations (${Math.round(progress.nativeElapsedMs)}ms)`+ );+ await Bun.write(+ resolve(artifacts, 'filter-matrix.json'),+ JSON.stringify(progress, null, 2)+ );+ if (progress.failures.length > 0) break;+ } while (!progress.done);+ assert.deepEqual(+ progress.failures,+ [],+ 'Offline filter matrix failed; see filter-matrix.json'+ );+ assert(progress.done);+ console.log(+ `PASS: offline filter selection matrix (${matrixView ?? 'all'}) ${JSON.stringify(progress.byView)}`+ );+ } else if (!smokeOnly) {const requestsAtDisconnect = fixture.requests.length;// None of these views were fetched online: their rows must be selected// from backfilled normalized records, not replayed query-response caches.diff --git a/apps/web/tests/native/tsconfig.browser.json b/apps/web/tests/native/tsconfig.browser.jsonnew file mode 100644index 0000000000..49520100ba--- /dev/null+++ b/apps/web/tests/native/tsconfig.browser.json@@ -0,0 +1,6 @@+{+ "extends": "../../tsconfig.json",+ "compilerOptions": { "types": ["vite/client", "vite-plugin-solid-svg/types-component-solid", "vite-plugin-solid-svg/types", "wicg-file-system-access", "@types/gtag.js", "@types/facebook-pixel"] },+ "include": ["./filter-matrix.ts", "../../src/**/*.d.ts"],+ "exclude": []+}diff --git a/apps/web/tests/native/tsconfig.json b/apps/web/tests/native/tsconfig.jsonindex e87699bc20..75428895e6 100644--- a/apps/web/tests/native/tsconfig.json+++ b/apps/web/tests/native/tsconfig.json@@ -12,5 +12,6 @@"types": ["bun", "node"],"lib": ["ESNext", "DOM", "DOM.Iterable"]},- "include": ["./**/*.ts"]+ "include": ["./**/*.ts"],+ "exclude": ["./filter-matrix.ts"]}diff --git a/crates/client/cache-turso/src/storage.rs b/crates/client/cache-turso/src/storage.rsindex 4ac7244e53..7514977c70 100644--- a/crates/client/cache-turso/src/storage.rs+++ b/crates/client/cache-turso/src/storage.rs@@ -2536,18 +2536,20 @@ fn compile_predicate_selection(.map(|root| format!("SELECT source, document_id FROM {root}")).collect::<Vec<_>>().join(" UNION ");- compiler- .ctes- .push(format!("{matches}(source, document_id) AS ({union})"));- let effective_sort = compiler.next_name();+ compiler.ctes.push(format!(+ "{matches}(source, document_id) AS MATERIALIZED ({union})"+ ));+ let hits = compiler.next_name();compiler.parameters.push(text(descriptor.sort_attribute.as_str()));compiler.parameters.push(text(descriptor.sort_attribute.as_str()));+ // Look up identity and sort facts by their real primary keys. Joining three+ // materialized sets loses those indexes and makes even small queries quadratic.compiler.ctes.push(format!(- "{effective_sort}(source, document_id, value) AS (SELECT 0, document_id, value FROM sort_facts WHERE attribute = ? UNION ALL SELECT 1, document_id, value FROM optimistic_sort_facts WHERE attribute = ?)"+ "{hits}(record_key, value) AS MATERIALIZED (SELECT d.record_key, s.value FROM {matches} AS m JOIN index_documents AS d ON m.source = 0 AND d.id = m.document_id JOIN sort_facts AS s ON s.document_id = m.document_id AND s.attribute = ? UNION ALL SELECT d.record_key, s.value FROM {matches} AS m JOIN optimistic_index_documents AS d ON m.source = 1 AND d.id = m.document_id JOIN optimistic_sort_facts AS s ON s.document_id = m.document_id AND s.attribute = ?)"));compiler.parameters@@ -2560,14 +2562,18 @@ fn compile_predicate_selection(SortDirection::Asc => "ASC",SortDirection::Desc => "DESC",};- let sort_selection = if include_sort { ", s.value" } else { "" };+ let sort_selection = if include_sort { ", value" } else { "" };let sql = format!(- "WITH {} SELECT d.record_key{sort_selection} FROM {matches} AS m JOIN effective_documents AS d ON d.source = m.source AND d.document_id = m.document_id JOIN {effective_sort} AS s ON s.source = m.source AND s.document_id = m.document_id ORDER BY s.value {sort_direction}, d.record_key {tie_direction} LIMIT ?",+ "WITH {} SELECT record_key{sort_selection} FROM {hits} ORDER BY value {sort_direction}, record_key {tie_direction} LIMIT ?",compiler.ctes.join(", "));(sql, compiler.parameters)}+// Keep every set-algebra CTE materialized. The pinned Turso planner otherwise+// re-enters compound-query coroutines for joined rows, repeatedly evaluating+// the same child sets (millions of VM steps even on a small local corpus).+// This is generic query execution policy; application predicates remain in IR.struct SqlPredicateCompiler {ctes: Vec<String>,parameters: Vec<Value>,@@ -2585,9 +2591,11 @@ impl SqlPredicateCompiler {)};Self {- ctes: vec![format!(- "effective_documents(source, document_id, record_key, profile, partition) AS (SELECT 0, d.id, d.record_key, d.profile, d.partition FROM index_documents AS d WHERE d.state = 0 AND NOT EXISTS (SELECT 1 FROM optimistic_index_documents AS o WHERE o.record_key = d.record_key) UNION ALL SELECT 1, o.id, o.record_key, o.profile, o.partition FROM optimistic_index_documents AS o WHERE o.state = 0{exclusion})"- )],+ ctes: vec![+ "authoritative_documents(document_id, record_key, profile, partition) AS MATERIALIZED (SELECT d.id, d.record_key, d.profile, d.partition FROM index_documents AS d WHERE d.state = 0 AND NOT EXISTS (SELECT 1 FROM optimistic_index_documents AS o WHERE o.record_key = d.record_key))".to_owned(),+ format!("optimistic_documents(document_id, record_key, profile, partition) AS MATERIALIZED (SELECT o.id, o.record_key, o.profile, o.partition FROM optimistic_index_documents AS o WHERE o.state = 0{exclusion})"),+ "effective_documents(source, document_id, record_key, profile, partition) AS MATERIALIZED (SELECT 0, document_id, record_key, profile, partition FROM authoritative_documents UNION ALL SELECT 1, document_id, record_key, profile, partition FROM optimistic_documents)".to_owned(),+ ],parameters: excluded_optimistic.iter().copied()@@ -2604,28 +2612,22 @@ impl SqlPredicateCompiler {}fn compile(&mut self, expr: &PredicateExpr, profile: &Profile, partition: &Token) -> String {+ if matches!(expr, PredicateExpr::Or(_, _))+ && let Some((attribute, values)) = alternatives::exact_alternatives(expr)+ {+ return self.exact(attribute, &values, profile, partition);+ }match expr {PredicateExpr::All => self.universe(profile, partition),PredicateExpr::None => {let name = self.next_name();self.ctes.push(format!(- "{name}(source, document_id) AS (SELECT source, document_id FROM effective_documents WHERE 0)"+ "{name}(source, document_id) AS MATERIALIZED (SELECT source, document_id FROM effective_documents WHERE 0)"));name}PredicateExpr::Exact { attribute, value } => {- let name = self.next_name();- for _ in 0..2 {- self.parameters.push(text(profile.token().as_str()));- self.parameters.push(text(partition.as_str()));- self.parameters.push(text(attribute.as_str()));- self.parameters- .push(Value::from_blob(value.as_bytes().to_vec()));- }- self.ctes.push(format!(- "{name}(source, document_id) AS (SELECT 0, f.document_id FROM exact_facts AS f JOIN effective_documents AS d ON d.source = 0 AND d.document_id = f.document_id WHERE d.profile = ? AND d.partition = ? AND f.attribute = ? AND f.value = ? UNION SELECT 1, f.document_id FROM optimistic_exact_facts AS f JOIN effective_documents AS d ON d.source = 1 AND d.document_id = f.document_id WHERE d.profile = ? AND d.partition = ? AND f.attribute = ? AND f.value = ?)"- ));- name+ self.exact(attribute, &[value], profile, partition)}PredicateExpr::ExactExists { attribute } => {let name = self.next_name();@@ -2635,7 +2637,7 @@ impl SqlPredicateCompiler {self.parameters.push(text(attribute.as_str()));}self.ctes.push(format!(- "{name}(source, document_id) AS (SELECT 0, f.document_id FROM exact_facts AS f JOIN effective_documents AS d ON d.source = 0 AND d.document_id = f.document_id WHERE d.profile = ? AND d.partition = ? AND f.attribute = ? UNION SELECT 1, f.document_id FROM optimistic_exact_facts AS f JOIN effective_documents AS d ON d.source = 1 AND d.document_id = f.document_id WHERE d.profile = ? AND d.partition = ? AND f.attribute = ?)"+ "{name}(source, document_id) AS MATERIALIZED (SELECT 0, f.document_id FROM exact_facts AS f JOIN index_documents AS d ON d.id = f.document_id WHERE d.state = 0 AND NOT EXISTS (SELECT 1 FROM optimistic_index_documents AS o WHERE o.record_key = d.record_key) AND d.profile = ? AND d.partition = ? AND f.attribute = ? UNION SELECT 1, f.document_id FROM optimistic_exact_facts AS f JOIN optimistic_documents AS d ON d.document_id = f.document_id WHERE d.profile = ? AND d.partition = ? AND f.attribute = ?)"));name}@@ -2668,7 +2670,7 @@ impl SqlPredicateCompiler {}}self.ctes.push(format!(- "{name}(source, document_id) AS (SELECT 0, f.document_id FROM integer_facts AS f JOIN effective_documents AS d ON d.source = 0 AND d.document_id = f.document_id WHERE d.profile = ? AND d.partition = ? AND f.attribute = ?{range} UNION SELECT 1, f.document_id FROM optimistic_integer_facts AS f JOIN effective_documents AS d ON d.source = 1 AND d.document_id = f.document_id WHERE d.profile = ? AND d.partition = ? AND f.attribute = ?{range})"+ "{name}(source, document_id) AS MATERIALIZED (SELECT 0, f.document_id FROM integer_facts AS f JOIN index_documents AS d ON d.id = f.document_id WHERE d.state = 0 AND NOT EXISTS (SELECT 1 FROM optimistic_index_documents AS o WHERE o.record_key = d.record_key) AND d.profile = ? AND d.partition = ? AND f.attribute = ?{range} UNION SELECT 1, f.document_id FROM optimistic_integer_facts AS f JOIN optimistic_documents AS d ON d.document_id = f.document_id WHERE d.profile = ? AND d.partition = ? AND f.attribute = ?{range})"));name}@@ -2700,7 +2702,7 @@ impl SqlPredicateCompiler {text(key.as_str()),]);}- self.ctes.push(format!("{name}(source, document_id) AS (SELECT 0, f.document_id FROM sort_facts f JOIN effective_documents d ON d.source = 0 AND d.document_id = f.document_id WHERE d.profile = ? AND d.partition = ? AND f.attribute = ? AND (f.value {cmp} ? OR (f.value = ? AND d.record_key {tie} ?)) UNION SELECT 1, f.document_id FROM optimistic_sort_facts f JOIN effective_documents d ON d.source = 1 AND d.document_id = f.document_id WHERE d.profile = ? AND d.partition = ? AND f.attribute = ? AND (f.value {cmp} ? OR (f.value = ? AND d.record_key {tie} ?)))"));+ self.ctes.push(format!("{name}(source, document_id) AS MATERIALIZED (SELECT 0, f.document_id FROM sort_facts f JOIN index_documents d ON d.id = f.document_id WHERE d.state = 0 AND NOT EXISTS (SELECT 1 FROM optimistic_index_documents o WHERE o.record_key = d.record_key) AND d.profile = ? AND d.partition = ? AND f.attribute = ? AND (f.value {cmp} ? OR (f.value = ? AND d.record_key {tie} ?)) UNION SELECT 1, f.document_id FROM optimistic_sort_facts f JOIN optimistic_documents d ON d.document_id = f.document_id WHERE d.profile = ? AND d.partition = ? AND f.attribute = ? AND (f.value {cmp} ? OR (f.value = ? AND d.record_key {tie} ?)))"));name}PredicateExpr::And(left, right) | PredicateExpr::Or(left, right) => {@@ -2713,7 +2715,7 @@ impl SqlPredicateCompiler {};let name = self.next_name();self.ctes.push(format!(- "{name}(source, document_id) AS (SELECT source, document_id FROM {left} {operator} SELECT source, document_id FROM {right})"+ "{name}(source, document_id) AS MATERIALIZED (SELECT source, document_id FROM {left} {operator} SELECT source, document_id FROM {right})"));name}@@ -2722,19 +2724,48 @@ impl SqlPredicateCompiler {let child = self.compile(expr, profile, partition);let name = self.next_name();self.ctes.push(format!(- "{name}(source, document_id) AS (SELECT source, document_id FROM {universe} EXCEPT SELECT source, document_id FROM {child})"+ "{name}(source, document_id) AS MATERIALIZED (SELECT source, document_id FROM {universe} EXCEPT SELECT source, document_id FROM {child})"));name}}}+ fn exact(+ &mut self,+ attribute: &Token,+ values: &[&predicate_index::ExactValue],+ profile: &Profile,+ partition: &Token,+ ) -> String {+ let name = self.next_name();+ let condition = if values.len() == 1 {+ "= ?".to_owned()+ } else {+ format!("IN ({})", vec!["?"; values.len()].join(", "))+ };+ for _ in 0..2 {+ self.parameters.push(text(profile.token().as_str()));+ self.parameters.push(text(partition.as_str()));+ self.parameters.push(text(attribute.as_str()));+ self.parameters.extend(+ values+ .iter()+ .map(|value| Value::from_blob(value.as_bytes().to_vec())),+ );+ }+ self.ctes.push(format!(+ "{name}(source, document_id) AS MATERIALIZED (SELECT 0, f.document_id FROM exact_facts AS f JOIN index_documents AS d ON d.id = f.document_id WHERE d.state = 0 AND NOT EXISTS (SELECT 1 FROM optimistic_index_documents AS o WHERE o.record_key = d.record_key) AND d.profile = ? AND d.partition = ? AND f.attribute = ? AND f.value {condition} UNION SELECT 1, f.document_id FROM optimistic_exact_facts AS f JOIN optimistic_documents AS d ON d.document_id = f.document_id WHERE d.profile = ? AND d.partition = ? AND f.attribute = ? AND f.value {condition})"+ ));+ name+ }+fn universe(&mut self, profile: &Profile, partition: &Token) -> String {let name = self.next_name();self.parameters.push(text(profile.token().as_str()));self.parameters.push(text(partition.as_str()));self.ctes.push(format!(- "{name}(source, document_id) AS (SELECT source, document_id FROM effective_documents WHERE profile = ? AND partition = ?)"+ "{name}(source, document_id) AS MATERIALIZED (SELECT source, document_id FROM effective_documents WHERE profile = ? AND partition = ?)"));name}@@ -4760,6 +4791,8 @@ impl TursoStorage {}}+mod alternatives;+#[cfg(all(test, target_arch = "wasm32"))]mod browser_test;#[cfg(all(test, not(target_arch = "wasm32")))]diff --git a/crates/client/cache-turso/src/storage/alternatives.rs b/crates/client/cache-turso/src/storage/alternatives.rsnew file mode 100644index 0000000000..89ce71aa1f--- /dev/null+++ b/crates/client/cache-turso/src/storage/alternatives.rs@@ -0,0 +1,29 @@+use predicate_index::{ExactValue, PredicateExpr, Token};++/// Recognize an OR tree over one exact attribute without distributing Boolean+/// expressions. Its set union is one indexed IN lookup, not a CTE per value.+pub(super) fn exact_alternatives(expr: &PredicateExpr) -> Option<(&Token, Vec<&ExactValue>)> {+ let mut pending = vec![expr];+ let mut attribute = None;+ let mut values = Vec::new();+ while let Some(expr) = pending.pop() {+ match expr {+ PredicateExpr::Or(left, right) => {+ pending.push(right);+ pending.push(left);+ }+ PredicateExpr::Exact {+ attribute: next,+ value,+ } => {+ if attribute.is_some_and(|attribute| attribute != next) {+ return None;+ }+ attribute = Some(next);+ values.push(value);+ }+ _ => return None,+ }+ }+ Some((attribute?, values))+}diff --git a/crates/client/cache-turso/src/storage/test.rs b/crates/client/cache-turso/src/storage/test.rsindex ec1e47a1e0..dbea75a792 100644--- a/crates/client/cache-turso/src/storage/test.rs+++ b/crates/client/cache-turso/src/storage/test.rs@@ -1,4 +1,6 @@use super::*;++mod predicate_cost;use cache_core::normalize::RecordUpdates;use pollster::block_on;use std::sync::atomic::{AtomicU8, Ordering};diff --git a/crates/client/cache-turso/src/storage/test/predicate_cost.rs b/crates/client/cache-turso/src/storage/test/predicate_cost.rsnew file mode 100644index 0000000000..38f1d5598c--- /dev/null+++ b/crates/client/cache-turso/src/storage/test/predicate_cost.rs@@ -0,0 +1,132 @@+use super::*;+use predicate_index::{ExactValue, IndexQuery, PartitionPredicate};++#[test]+fn compound_predicates_materialize_sets_once_instead_of_reexecuting_for_each_join_row() {+ block_on(async {+ let mut storage = TursoStorage::open_in_memory("predicate-cost").unwrap();+ let projections = (0..75)+ .map(|n| {+ ProjectionMutation::Replace(authoritative_projection(+ &format!("Thing:{n:03}"),+ if n % 2 == 0 { "owner-1" } else { "owner-2" },+ ))+ })+ .collect();+ storage+ .put_batch_with_projections(Vec::new(), projections)+ .await+ .unwrap();+ let token = |value| Token::new(value).unwrap();+ let query = ValidatedIndexQuery::new(IndexQuery {+ profile: Profile::new(token("profile-v1")),+ partitions: ["thing", "other", "third", "fourth"]+ .into_iter()+ .map(|partition| PartitionPredicate {+ partition: token(partition),+ predicate: PredicateExpr::And(+ Box::new(PredicateExpr::Exact {+ attribute: token("owner"),+ value: ExactValue::utf8("owner-1").unwrap(),+ }),+ Box::new(PredicateExpr::Exact {+ attribute: token("server-relation"),+ value: ExactValue::new([1]).unwrap(),+ }),+ ),+ })+ .collect(),+ sort_attribute: token("updated-at"),+ sort_direction: SortDirection::Asc,+ tie_break_direction: SortDirection::Asc,+ limit: 100,+ })+ .unwrap();+ let (sql, parameters) = compile_predicate_selection(&query, &[], true);+ let mut statement = driver::prepare(&storage.connection(), &sql).unwrap();+ let rows = driver::query_prepared(&mut statement, parameters).unwrap();+ let actual: Vec<_> = rows+ .iter()+ .map(|row| required_text(row, 0).unwrap())+ .collect();+ let expected: Vec<_> = (0..75)+ .filter(|n| n % 2 == 0)+ .map(|n| format!("Thing:{n:03}"))+ .collect();+ assert_eq!(actual, expected);+ // A VM-work budget is deterministic across machines/build profiles. The+ // unmaterialized compound plan takes millions of steps on only 75 rows.+ let steps = statement.metrics().vm_steps;+ assert!(steps < 500_000, "compound query executed {steps} VM steps");+ });+}++#[test]+fn exact_alternatives_use_one_lookup_without_widening_nested_boolean_filters() {+ block_on(async {+ let mut storage = TursoStorage::open_in_memory("exact-alternatives").unwrap();+ storage+ .put_batch_with_projections(+ Vec::new(),+ (0..75)+ .map(|n| {+ ProjectionMutation::Replace(authoritative_projection(+ &format!("Thing:{n:03}"),+ if n % 2 == 0 { "owner-1" } else { "owner-2" },+ ))+ })+ .collect(),+ )+ .await+ .unwrap();+ let token = |value| Token::new(value).unwrap();+ let owner = |value: &str| PredicateExpr::Exact {+ attribute: token("owner"),+ value: ExactValue::utf8(value).unwrap(),+ };+ let alternatives = (1..=16)+ .map(|n| owner(&format!("owner-{n}")))+ .reduce(|left, right| PredicateExpr::Or(Box::new(left), Box::new(right)))+ .unwrap();+ for (predicate, expected) in [+ (alternatives.clone(), 75),+ (PredicateExpr::Not(Box::new(alternatives.clone())), 0),+ (+ PredicateExpr::And(+ Box::new(alternatives),+ Box::new(PredicateExpr::Not(Box::new(owner("owner-2")))),+ ),+ 38,+ ),+ ] {+ let query = ValidatedIndexQuery::new(IndexQuery {+ profile: Profile::new(token("profile-v1")),+ partitions: vec![PartitionPredicate {+ partition: token("thing"),+ predicate,+ }],+ sort_attribute: token("updated-at"),+ sort_direction: SortDirection::Asc,+ tie_break_direction: SortDirection::Asc,+ limit: 100,+ })+ .unwrap();+ let (sql, parameters) = compile_predicate_selection(&query, &[], true);+ assert!(sql.contains("f.value IN ("));+ assert!(+ sql.matches("FROM exact_facts AS f").count() <= 2,+ "one lookup for alternatives, at most one for negated owner"+ );+ let rows = driver::query(&storage.connection(), &sql, parameters).unwrap();+ assert_eq!(rows.len(), expected);+ }+ let mixed = PredicateExpr::Or(+ Box::new(owner("owner-1")),+ Box::new(PredicateExpr::Exact {+ attribute: token("other"),+ value: ExactValue::utf8("owner-2").unwrap(),+ }),+ );+ assert!(alternatives::exact_alternatives(&mixed).is_none());+ });+}diff --git a/crates/client/cache-wasm/Cargo.toml b/crates/client/cache-wasm/Cargo.tomlindex 99fd9e3a9d..9343cd74fc 100644--- a/crates/client/cache-wasm/Cargo.toml+++ b/crates/client/cache-wasm/Cargo.toml@@ -3,7 +3,7 @@ edition = "2024"name = "cache-wasm"publish = false# Rebuild for canonical Mail tab previews and viewer-scoped shared eligibility.-version = "0.6.11"+version = "0.6.14"[features]default = []diff --git a/crates/client/cache-wasm/src/shell.rs b/crates/client/cache-wasm/src/shell.rsindex 754aaa6996..3b1310e4b5 100644--- a/crates/client/cache-wasm/src/shell.rs+++ b/crates/client/cache-wasm/src/shell.rs@@ -24,10 +24,11 @@ use cache_turso::{use predicate_index::RecordKey;use serde::{Deserialize, Serialize};use soup_filter_cache_adapter::{- SoupFilterCompileOutcome, authoritative_projection_mutations, compile_filter_request,- dirty_projection_mutations, mail::ProjectionError as MailProjectionError,- notification_deletion_updates, notification_projection_updates,- optimistic_notification_updates, optimistic_projection_mutations,+ SoupFilterCompileOutcome, authoritative_projection_mutations,+ compile_current_filter_request as compile_filter_request, dirty_projection_mutations,+ mail::ProjectionError as MailProjectionError, notification_deletion_updates,+ notification_projection_updates, optimistic_notification_updates,+ optimistic_projection_mutations,};use std::cell::RefCell;use std::collections::HashMap;@@ -1022,7 +1023,7 @@ impl CacheEngine {serde_wasm_bindgen::from_value(request).map_err(err_js)?;if let Some(mail) = request.mail {let generation = state.mail_generation.clone();- let result = soup_filter_cache_adapter::mail::page(+ let result = soup_filter_cache_adapter::mail::page_current(state.engine_mut()?,&generation,request.filters,@@ -1181,6 +1182,17 @@ impl CacheEngine {.await.map_err(|error| state.mail_projection_error(error))?,);+ let projections = soup_filter_cache_adapter::properties::augment_authoritative(+ state.engine_mut()?.storage(),+ &query,+ operation_name.as_deref(),+ &vars,+ &data,+ reuse_stored_identity,+ projections,+ )+ .await+ .map_err(|error| state.mail_projection_error(error))?;let result = state.engine_mut()?.write_query_with_registration_and_projections(@@ -1254,6 +1266,17 @@ impl CacheEngine {.await.map_err(|error| state.mail_projection_error(error))?,);+ let projections = soup_filter_cache_adapter::properties::augment_authoritative(+ state.engine_mut()?.storage(),+ &query,+ operation_name.as_deref(),+ &variables,+ &data,+ reuse_stored_identity,+ projections,+ )+ .await+ .map_err(|error| state.mail_projection_error(error))?;let result = state.engine_mut()?.hydrate_query_with_projections(@@ -1339,6 +1362,16 @@ impl CacheEngine {.await.map_err(|error| state.mail_projection_error(error))?,));+ let projection_mutations = soup_filter_cache_adapter::properties::augment_optimistic(+ state.engine_mut()?.storage(),+ &query,+ operation_name.as_deref(),+ &vars,+ &data,+ projection_mutations,+ )+ .await+ .map_err(|error| state.mail_projection_error(error))?;let claim = MutationClaimRequest {owner: lease_owner,now_ms: parse_timestamp(now_ms, "claim timestamp")?,@@ -1557,6 +1590,17 @@ impl CacheEngine {.await.map_err(|error| state.mail_projection_error(error))?,);+ let projections = soup_filter_cache_adapter::properties::augment_authoritative(+ state.engine_mut()?.storage(),+ &query,+ operation_name.as_deref(),+ &vars,+ &data,+ true,+ projections,+ )+ .await+ .map_err(|error| state.mail_projection_error(error))?;let result = state.engine_mut()?.commit_optimistic_write_with_projections_outcome(@@ -1645,6 +1689,15 @@ impl CacheEngine {);let keys: Vec<EntityKey<'static>> =keys.into_iter().map(|key| EntityKey(key.into())).collect();+ projections.extend(+ soup_filter_cache_adapter::properties::deletion_updates(+ state.engine_mut()?.storage(),+ &keys.iter().map(ToString::to_string).collect::<Vec<_>>(),+ )+ .await+ .map_err(|error| state.mail_projection_error(error))?,+ );+ let projections = soup_filter_cache_adapter::properties::current_mutations(projections);let result = state.engine_mut()?.invalidate_keys_with_projections(&keys, projections)@@ -1677,6 +1730,15 @@ impl CacheEngine {);let keys: Vec<EntityKey<'static>> =keys.into_iter().map(|key| EntityKey(key.into())).collect();+ projections.extend(+ soup_filter_cache_adapter::properties::deletion_updates(+ state.engine_mut()?.storage(),+ &keys.iter().map(ToString::to_string).collect::<Vec<_>>(),+ )+ .await+ .map_err(|error| state.mail_projection_error(error))?,+ );+ let projections = soup_filter_cache_adapter::properties::current_mutations(projections);let result = state.engine_mut()?.delete_keys_with_projection_changes(&keys, projections)diff --git a/crates/client/cache-wasm/src/shell/test.rs b/crates/client/cache-wasm/src/shell/test.rsindex 8714ed4076..df4a65a676 100644--- a/crates/client/cache-wasm/src/shell/test.rs+++ b/crates/client/cache-wasm/src/shell/test.rs@@ -69,6 +69,7 @@ const SOUP_WITH_PROJECTION_QUERY: &str = r#"query SoupWithProjection($input: Sousoup(input: $input) {nextCursoritems {+ properties { id propertyDefinitionId value { __typename ... on GraphqlSelectOptionPropertyValue { optionIds } } }__typenameidcacheProjection @cacheOnly@@ -93,6 +94,7 @@ const SOUP_BACKFILL_WITH_PROJECTION_QUERY: &str = r#"query SoupBackfill($input:soup(input: $input) {nextCursoritems {+ properties { id propertyDefinitionId value { __typename ... on GraphqlSelectOptionPropertyValue { optionIds } } }__typenameidcacheProjection @cacheOnly@@ -116,6 +118,7 @@ const SOUP_UPDATES_WITH_PROJECTION_SUBSCRIPTION: &str = r#"subscription SoupUpda__typename... on SoupUpdated {item {+ properties { id propertyDefinitionId value { __typename ... on GraphqlSelectOptionPropertyValue { optionIds } } }__typenameidcacheProjection @cacheOnly@@ -365,6 +368,11 @@ fn projected_document_item_with_facts("__typename": "GraphqlSoupDocument","id": document_id,"notifications": [],+ "properties": if status_option_ids.is_empty() { serde_json::json!([]) } else { serde_json::json!([{+ "id": format!("status:{document_id}"),+ "propertyDefinitionId": "00000001-0000-0000-0000-000000000002",+ "value": {"__typename":"GraphqlSelectOptionPropertyValue", "optionIds": status_option_ids},+ }]) },"cacheProjection": v3_document_supplement(document_id,is_email_attachment,diff --git a/crates/graphql_soup_filter_input/src/lib.rs b/crates/graphql_soup_filter_input/src/lib.rsindex 22337256c8..a2e1018a4d 100644--- a/crates/graphql_soup_filter_input/src/lib.rs+++ b/crates/graphql_soup_filter_input/src/lib.rs@@ -49,7 +49,10 @@ mod test;/// Maximum accepted GraphQL filter expression depth.pub const MAX_FILTER_DEPTH: usize = 64;/// Maximum accepted JSON values in one GraphQL filter input.-pub const MAX_FILTER_NODES: usize = 2_048;+/// JSON literal/Boolean wrappers need more nodes than the resulting expression:+/// combined Files associations expand the finite file-type registry past 2,048+/// JSON values while staying inside the cache's 2,048-expression-node budget.+pub const MAX_FILTER_NODES: usize = 4_096;/// Maximum bytes accepted in one string value.pub const MAX_FILTER_STRING_BYTES: usize = 16 * 1_024;/// Maximum aggregate bytes across string values.diff --git a/crates/graphql_soup_filter_input/src/test.rs b/crates/graphql_soup_filter_input/src/test.rsindex 9dbae460a1..f330c65545 100644--- a/crates/graphql_soup_filter_input/src/test.rs+++ b/crates/graphql_soup_filter_input/src/test.rs@@ -49,6 +49,27 @@ fn rejects_rest_ast_shape() {assert!(matches!(error, MaterializeError::Shape(_)));}+fn balanced_file_types(leaves: usize) -> Value {+ if leaves == 1 {+ return json!({"literal":{"fileType":"md"}});+ }+ json!({"or":{"left":balanced_file_types(leaves / 2), "right":balanced_file_types(leaves - leaves / 2)}})+}++#[test]+fn finite_file_picker_unions_fit_but_unbounded_json_forests_do_not() {+ // 512 leaves are 1,023 expression nodes, but 2,559 JSON values after wrappers.+ let input = json!({"documentFilter":balanced_file_types(512)});+ assert!(materialize_graphql_filter(input.clone()).is_ok());+ let graphql: GraphqlEntityFilterAst = serde_json::from_value(input).unwrap();+ assert!(graphql.into_ast().is_ok());+ let oversized = json!({"documentFilter":balanced_file_types(1024)});+ assert!(matches!(+ materialize_graphql_filter(oversized),+ Err(MaterializeError::Bounds(_))+ ));+}+#[test]fn rejects_pathological_depth_before_materialization() {let mut expression = json!({diff --git a/crates/item_filter_index/src/lib.rs b/crates/item_filter_index/src/lib.rsindex 7208226778..8137da5f9b 100644--- a/crates/item_filter_index/src/lib.rs+++ b/crates/item_filter_index/src/lib.rs@@ -30,6 +30,7 @@ mod test;mod channels;pub mod mail;+pub mod properties;/// Stable direct-field profile name retained for existing browser projections.pub const SOUP_FLAT_V1: &str = "soup-flat-v1";@@ -39,6 +40,8 @@ pub const SOUP_FLAT_V2: &str = "soup-flat-v2";pub const SOUP_FLAT_V3: &str = "soup-flat-v3";/// Browser-composed profile with complete active-notification membership.pub const SOUP_FLAT_V4: &str = "soup-flat-v4";+/// Host-composed profile with complete selectable property snapshots.+pub const SOUP_FLAT_V5: &str = "soup-flat-v5";// Keep this lightweight crate wasm-compatible instead of depending on the// native `system_properties` crate. A native test locks this stable UUID to@@ -75,6 +78,11 @@ pub mod vocabulary {Profile::new(token(super::SOUP_FLAT_V4))}+ /// Host-composed property-aware Soup profile.+ pub fn profile_v5() -> Profile {+ Profile::new(token(super::SOUP_FLAT_V5))+ }+/// IDs of unseen notifications for the viewer and primary entity.pub fn notification_unseen() -> Token {token("notification-unseen")diff --git a/crates/item_filter_index/src/properties.rs b/crates/item_filter_index/src/properties.rsnew file mode 100644index 0000000000..f5959d1269--- /dev/null+++ b/crates/item_filter_index/src/properties.rs@@ -0,0 +1,125 @@+//! Select-option and entity-reference filters shared by Soup and Mail.+//! Property snapshots are versioned independently of the immutable server capsules.++use super::*;++/// Select-option posting for one property definition (status, priority or tags).+pub fn select_attribute(definition: Uuid) -> Token {+ Token::new(format!("property-select:{definition}")).expect("UUID attribute is bounded")+}++/// Entity-reference posting for one property definition (for example assignees).+pub fn entity_attribute(definition: Uuid) -> Token {+ Token::new(format!("property-entity:{definition}")).expect("UUID attribute is bounded")+}++/// Reverse ownership evidence for one normalized property row.+pub fn row_attribute(definition: Uuid) -> Token {+ Token::new(format!("property-row:{definition}")).expect("UUID attribute is bounded")+}++/// Whether an attribute belongs to this property projection family.+pub fn is_property_attribute(attribute: &Token) -> bool {+ ["property-select:", "property-entity:", "property-row:"]+ .iter()+ .any(|prefix| attribute.as_str().starts_with(prefix))+}++/// A cached-Mail profile containing the same canonical message facts plus properties.+pub fn mail_profile() -> Profile {+ Profile::new(mail::token("soup-mail-v3"))+}++fn supported(ast: &EntityFilterAst) -> bool {+ supported_expr(ast.properties_filter.as_deref(), |literal| {+ // Current view selections are untyped. Typed property-row lookups need+ // association evidence not present in the GraphQL property snapshot.+ literal.entity_type.is_none()+ })+}++fn property_predicate(+ ast: &EntityFilterAst,+ partition: &Token,+) -> Result<PredicateExpr, CompileError> {+ compile_expr(ast.properties_filter.as_deref(), |literal| {+ if partition == &vocabulary::channel_partition() {+ // Channels have no properties in Soup. Preserve Boolean semantics+ // for negations rather than pretending all property filters exclude them.+ return Ok(PredicateExpr::None);+ }+ Ok(match &literal.value {+ PropertyMatchValue::SelectOption(id) => {+ exact_uuid(select_attribute(literal.property_definition_id), id)+ }+ PropertyMatchValue::EntityRef(id) => exact_utf8(+ entity_attribute(literal.property_definition_id),+ id.to_string(),+ )?,+ })+ })+}++fn add_properties(+ ast: &EntityFilterAst,+ query: ValidatedIndexQuery,+ profile: Profile,+) -> Result<LocalCompileOutcome, CompileError> {+ let mut query = query.as_query().clone();+ query.profile = profile;+ if ast.properties_filter.is_some() {+ for partition in &mut query.partitions {+ partition.predicate = PredicateExpr::And(+ Box::new(std::mem::replace(+ &mut partition.predicate,+ PredicateExpr::None,+ )),+ Box::new(property_predicate(ast, &partition.partition)?),+ );+ }+ }+ Ok(LocalCompileOutcome::Supported(ValidatedIndexQuery::new(+ query,+ )?))+}++/// Compile the current flat Soup profile without broadening any non-property filters.+pub fn compile_soup(+ ast: &EntityFilterAst,+ request: SoupFlatRequest,+) -> Result<LocalCompileOutcome, CompileError> {+ if !supported(ast) {+ return Ok(LocalCompileOutcome::Unsupported(+ UnsupportedReason::GlobalProperties,+ ));+ }+ let mut base = ast.clone();+ base.properties_filter = None;+ match compile_soup_flat_v4(&base, request)? {+ LocalCompileOutcome::Supported(query) => {+ add_properties(ast, query, vocabulary::profile_v5())+ }+ unsupported => Ok(unsupported),+ }+}++/// Compile current Mail properties while retaining readable-account and shared-grant gates.+pub fn compile_mail(+ ast: &EntityFilterAst,+ request: SoupFlatRequest,+ view: &str,+ links: &[Uuid],+ viewer: &str,+) -> Result<LocalCompileOutcome, CompileError> {+ if !supported(ast) {+ return Ok(LocalCompileOutcome::Unsupported(+ UnsupportedReason::GlobalProperties,+ ));+ }+ let mut base = ast.clone();+ base.properties_filter = None;+ match mail::compile(&base, request, view, links, viewer)? {+ LocalCompileOutcome::Supported(query) => add_properties(ast, query, mail_profile()),+ unsupported => Ok(unsupported),+ }+}diff --git a/crates/soup_filter_cache_adapter/examples/filter_fixture_capsules.rs b/crates/soup_filter_cache_adapter/examples/filter_fixture_capsules.rsnew file mode 100644index 0000000000..3a1f4a7518--- /dev/null+++ b/crates/soup_filter_cache_adapter/examples/filter_fixture_capsules.rs@@ -0,0 +1,41 @@+//! Generates server-only document capsules for native filter-selection fixtures.+//! Reads JSON fixture descriptors from stdin; never writes to a cache/database.+use serde::Deserialize;+use soup_filter_projection::{SoupCacheProjectionSupplement, encode_cache_projection_supplement};+use std::io::Read;++#[derive(Deserialize)]+#[serde(rename_all = "camelCase")]+struct Fixture {+ id: String,+ is_email_attachment: bool,+ status_option_ids: Vec<uuid::Uuid>,+}+fn main() {+ let mut input = String::new();+ std::io::stdin()+ .read_to_string(&mut input)+ .expect("read fixture descriptions");+ let fixtures: Vec<Fixture> = serde_json::from_str(&input).expect("valid fixture descriptions");+ let capsules: std::collections::BTreeMap<_, _> = fixtures+ .into_iter()+ .map(|fixture| {+ let key =+ predicate_index::RecordKey::new(format!("GraphqlSoupDocument:{}", fixture.id))+ .expect("fixture key");+ let encoded =+ encode_cache_projection_supplement(&SoupCacheProjectionSupplement::document(+ key,+ fixture.is_email_attachment,+ true,+ fixture.status_option_ids,+ ))+ .expect("encode canonical document capsule");+ (fixture.id, encoded)+ })+ .collect();+ println!(+ "{}",+ serde_json::to_string_pretty(&capsules).expect("serialize capsules")+ );+}diff --git a/crates/soup_filter_cache_adapter/src/lib.rs b/crates/soup_filter_cache_adapter/src/lib.rsindex 03f572802e..f24a188db4 100644--- a/crates/soup_filter_cache_adapter/src/lib.rs+++ b/crates/soup_filter_cache_adapter/src/lib.rs@@ -26,6 +26,7 @@ use std::collections::HashSet;mod channels;pub mod mail;mod notifications;+pub mod properties;pub use notifications::{notification_deletion_updates, notification_projection_updates, optimistic_notification_updates,};@@ -50,6 +51,26 @@ pub fn compile_filter_request(sort_method: &str,sort_direction: &str,limit: u16,+) -> Result<SoupFilterCompileOutcome, SoupFilterCacheAdapterError> {+ compile_request(filters, sort_method, sort_direction, limit, false)+}++/// Compile the property-aware profile used by current browser and native hosts.+pub fn compile_current_filter_request(+ filters: serde_json::Value,+ sort_method: &str,+ sort_direction: &str,+ limit: u16,+) -> Result<SoupFilterCompileOutcome, SoupFilterCacheAdapterError> {+ compile_request(filters, sort_method, sort_direction, limit, true)+}++fn compile_request(+ filters: serde_json::Value,+ sort_method: &str,+ sort_direction: &str,+ limit: u16,+ current: bool,) -> Result<SoupFilterCompileOutcome, SoupFilterCacheAdapterError> {let ast = materialize_graphql_filter(filters).map_err(|error| SoupFilterCacheAdapterError(error.to_string()))?;@@ -67,7 +88,12 @@ pub fn compile_filter_request());}};- compile_soup_flat_v4(+ let compile = if current {+ item_filter_index::properties::compile_soup+ } else {+ compile_soup_flat_v4+ };+ compile(&ast,SoupFlatRequest {sort,diff --git a/crates/soup_filter_cache_adapter/src/mail.rs b/crates/soup_filter_cache_adapter/src/mail.rsindex d9970b0efe..320dc3ec0c 100644--- a/crates/soup_filter_cache_adapter/src/mail.rs+++ b/crates/soup_filter_cache_adapter/src/mail.rs@@ -531,6 +531,56 @@ pub async fn page<S: PredicateIndexStorage>(direction: &str,limit: u16,request: PageRequest,+) -> Result<PageResult, PageError<S::Error>> {+ page_impl(+ engine,+ generation,+ filters,+ sort_method,+ direction,+ limit,+ request,+ false,+ )+ .await+}++/// Evaluate Mail using complete property-aware projections.+pub async fn page_current<S: PredicateIndexStorage>(+ engine: &mut Engine<S>,+ generation: &str,+ filters: Value,+ sort_method: &str,+ direction: &str,+ limit: u16,+ request: PageRequest,+) -> Result<PageResult, PageError<S::Error>> {+ page_impl(+ engine,+ generation,+ filters,+ sort_method,+ direction,+ limit,+ request,+ true,+ )+ .await+}++#[expect(+ clippy::too_many_arguments,+ reason = "retains the host page API while selecting the projection version"+)]+async fn page_impl<S: PredicateIndexStorage>(+ engine: &mut Engine<S>,+ generation: &str,+ filters: Value,+ sort_method: &str,+ direction: &str,+ limit: u16,+ request: PageRequest,+ current: bool,) -> Result<PageResult, PageError<S::Error>> {let revision = engine.current_revision().to_string();if limit == 0 || limit >= predicate_index::MAX_QUERY_LIMIT {@@ -578,7 +628,12 @@ pub async fn page<S: PredicateIndexStorage>("DESC" => SortDirection::Desc,_ => return Err(error("invalid sort direction").into()),};- let outcome = vocabulary::compile(+ let compile = if current {+ item_filter_index::properties::compile_mail+ } else {+ vocabulary::compile+ };+ let outcome = compile(&ast,SoupFlatRequest {sort,diff --git a/crates/soup_filter_cache_adapter/src/notifications.rs b/crates/soup_filter_cache_adapter/src/notifications.rsindex 5cc3de77e8..a70a7a1f91 100644--- a/crates/soup_filter_cache_adapter/src/notifications.rs+++ b/crates/soup_filter_cache_adapter/src/notifications.rs@@ -273,7 +273,9 @@ async fn retain_complete_parents<S: Storage>(states.get(record_key),Some(Some(ProjectionState::Complete(document)))if document.record_key == *record_key- && document.profile == *profile+ && (document.profile == *profile+ || (*profile == vocabulary::profile_v4()+ && document.profile == vocabulary::profile_v5()))&& document.partition == *partition)})diff --git a/crates/soup_filter_cache_adapter/src/properties.rs b/crates/soup_filter_cache_adapter/src/properties.rsnew file mode 100644index 0000000000..23b04f097d--- /dev/null+++ b/crates/soup_filter_cache_adapter/src/properties.rs@@ -0,0 +1,231 @@+//! Property-aware host projections. Legacy capsule/notification composition is+//! reused, then upgraded with explicit property snapshots in the same write.+//! No database schema or queued-mutation format change is required.++use super::SoupFilterCacheAdapterError;+use crate::mail::ProjectionError;+use cache_core::predicate::{+ ProjectionMutation, ProjectionState, apply_authoritative_projection_mutations,+};+use item_filter_index::{properties as facts, vocabulary};+use predicate_index::{+ ExactFact, IndexDocument, OptimisticProjectionMutation, Profile, RecordKey, Token,+};+use serde_json::{Map, Value};+use std::collections::{BTreeMap, HashMap};++mod optimistic;+mod prepare;+#[cfg(all(test, not(target_arch = "wasm32")))]+mod test;++pub use optimistic::augment_optimistic;+use prepare::prepare;++fn error(error: impl std::fmt::Display) -> SoupFilterCacheAdapterError {+ SoupFilterCacheAdapterError(error.to_string())+}++fn current_profile(profile: &Profile) -> Profile {+ if profile == &vocabulary::profile_v4() {+ vocabulary::profile_v5()+ } else if profile == &item_filter_index::mail::profile() {+ facts::mail_profile()+ } else {+ profile.clone()+ }+}++fn legacy_profile(profile: &Profile) -> Profile {+ if profile == &vocabulary::profile_v5() {+ vocabulary::profile_v4()+ } else if profile == &facts::mail_profile() {+ item_filter_index::mail::profile()+ } else {+ profile.clone()+ }+}++fn is_current(profile: &Profile) -> bool {+ profile == &vocabulary::profile_v5() || profile == &facts::mail_profile()+}++fn property_facts(state: Option<&ProjectionState>) -> Option<Vec<ExactFact>> {+ let ProjectionState::Complete(document) = state? else {+ return None;+ };+ is_current(&document.profile).then(|| {+ document+ .exact_facts+ .iter()+ .filter(|fact| facts::is_property_attribute(&fact.attribute))+ .cloned()+ .collect()+ })+}++fn legacy_state(mut state: ProjectionState) -> ProjectionState {+ match &mut state {+ ProjectionState::Complete(document) => {+ document.profile = legacy_profile(&document.profile);+ document+ .exact_facts+ .retain(|fact| !facts::is_property_attribute(&fact.attribute));+ }+ ProjectionState::Incomplete { profile, .. } => *profile = legacy_profile(profile),+ }+ state+}++fn incomplete(key: RecordKey, profile: Profile, partition: Token) -> ProjectionMutation {+ ProjectionMutation::MarkIncomplete {+ record_key: key,+ profile,+ partition,+ kind: cache_core::predicate::ProjectionIncompleteKind::Missing,+ }+}++fn extend_document(+ mut document: IndexDocument,+ properties: Option<Vec<ExactFact>>,+) -> ProjectionMutation {+ document.profile = current_profile(&document.profile);+ if document.partition != vocabulary::channel_partition() {+ let Some(properties) = properties else {+ return incomplete(document.record_key, document.profile, document.partition);+ };+ document.exact_facts.extend(properties);+ }+ document.canonicalize();+ if document.validate().is_err() {+ return incomplete(document.record_key, document.profile, document.partition);+ }+ ProjectionMutation::Replace(document)+}++/// Upgrade legacy core/Mail mutations and maintain property-only writes atomically.+/// An absent property snapshot cannot establish completeness; it may only retain+/// same-identity property proof already present in the current profile.+pub async fn augment_authoritative<S: cache_core::predicate::PredicateIndexStorage>(+ storage: &S,+ query: &str,+ operation: Option<&str>,+ variables: &Map<String, Value>,+ data: &Value,+ reuse_stored_identity: bool,+ mutations: Vec<ProjectionMutation>,+) -> Result<Vec<ProjectionMutation>, ProjectionError<S::Error>> {+ let changes = prepare(+ storage,+ query,+ operation,+ variables,+ data,+ reuse_stored_identity,+ )+ .await?;+ let mut by_key: BTreeMap<RecordKey, Vec<ProjectionMutation>> = BTreeMap::new();+ for mutation in mutations {+ by_key+ .entry(mutation.record_key().clone())+ .or_default()+ .push(mutation);+ }+ for key in changes.keys() {+ by_key.entry(key.clone()).or_default();+ }+ let keys: Vec<_> = by_key.keys().cloned().collect();+ let bases = if reuse_stored_identity {+ storage+ .load_projection_states(&keys)+ .await+ .map_err(ProjectionError::Storage)?+ } else {+ vec![None; keys.len()]+ };+ let mut result = Vec::new();+ for ((key, mutations), base) in by_key.into_iter().zip(bases) {+ let properties = changes.get(&key).map_or_else(+ || property_facts(base.as_ref()),+ |change| change.apply(property_facts(base.as_ref())),+ );+ // Apply legacy core patches in scratch state only. Their field masks and+ // server-owned facts remain authoritative; property proof is kept apart.+ let mut states: HashMap<_, _> = base+ .map(|base| (key.clone(), legacy_state(base)))+ .into_iter()+ .collect();+ apply_authoritative_projection_mutations(&mut states, &mutations);+ if let Some(state) = states.remove(&key) {+ result.push(match state {+ ProjectionState::Complete(document) => extend_document(document, properties),+ ProjectionState::Incomplete {+ record_key,+ profile,+ partition,+ kind,+ } => ProjectionMutation::MarkIncomplete {+ record_key,+ profile: current_profile(&profile),+ partition,+ kind,+ },+ });+ } else if mutations+ .iter()+ .any(|mutation| matches!(mutation, ProjectionMutation::Delete(_)))+ {+ result.push(ProjectionMutation::Delete(key));+ }+ }+ if matches!(+ operation,+ Some("SoupBackfill" | "SoupMailBackfill" | "SoupSharedMailBackfill")+ ) && result+ .iter()+ .any(|mutation| matches!(mutation, ProjectionMutation::MarkIncomplete { .. }))+ {+ return Err(error("Soup backfill contains an incomplete property projection").into());+ }+ Ok(result)+}++/// Convert versioned invalidation/member-edit messages to the current profiles.+/// Used for direct deletion/invalidation paths which do not carry a GraphQL write.+pub fn current_mutations(mutations: Vec<ProjectionMutation>) -> Vec<ProjectionMutation> {+ mutations+ .into_iter()+ .map(|mut mutation| {+ match &mut mutation {+ ProjectionMutation::Replace(document) => {+ if !is_current(&document.profile)+ && document.partition != vocabulary::channel_partition()+ {+ return incomplete(+ document.record_key.clone(),+ current_profile(&document.profile),+ document.partition.clone(),+ );+ }+ document.profile = current_profile(&document.profile)+ }+ ProjectionMutation::Patch { profile, .. }+ | ProjectionMutation::PatchExact { profile, .. }+ | ProjectionMutation::MarkIncomplete { profile, .. } => {+ *profile = current_profile(profile)+ }+ ProjectionMutation::Delete(_) => {}+ }+ mutation+ })+ .collect()+}++/// Invalidate parent property evidence before a normalized property row is removed.+pub async fn deletion_updates<S: cache_core::predicate::PredicateIndexStorage>(+ storage: &S,+ keys: &[String],+) -> Result<Vec<ProjectionMutation>, ProjectionError<S::Error>> {+ prepare::deletion_updates(storage, keys).await+}diff --git a/crates/soup_filter_cache_adapter/src/properties/optimistic.rs b/crates/soup_filter_cache_adapter/src/properties/optimistic.rsnew file mode 100644index 0000000000..d3954ddcea--- /dev/null+++ b/crates/soup_filter_cache_adapter/src/properties/optimistic.rs@@ -0,0 +1,144 @@+use super::*;+use cache_core::predicate::PredicateIndexStorage;+use predicate_index::ExactAttributePatch;+use std::collections::BTreeSet;++fn upgrade(mut mutation: OptimisticProjectionMutation) -> OptimisticProjectionMutation {+ match &mut mutation {+ OptimisticProjectionMutation::Replace(document) => {+ document.profile = current_profile(&document.profile)+ }+ OptimisticProjectionMutation::Patch { profile, .. }+ | OptimisticProjectionMutation::PatchExact { profile, .. }+ | OptimisticProjectionMutation::Unknown { profile, .. }+ | OptimisticProjectionMutation::Delete { profile, .. } => {+ *profile = current_profile(profile)+ }+ }+ mutation+}++/// Prepare property-specific optimistic patches without snapshotting unrelated+/// properties from older layers. The existing queue owns commit/rollback/replay.+pub async fn augment_optimistic<S: PredicateIndexStorage>(+ storage: &S,+ query: &str,+ operation: Option<&str>,+ variables: &Map<String, Value>,+ data: &Value,+ mutations: Vec<OptimisticProjectionMutation>,+) -> Result<Vec<OptimisticProjectionMutation>, ProjectionError<S::Error>> {+ let changes = prepare(storage, query, operation, variables, data, true).await?;+ let keys: Vec<_> = mutations+ .iter()+ .map(|mutation| mutation.record_key().clone())+ .chain(changes.keys().cloned())+ .collect::<BTreeSet<_>>()+ .into_iter()+ .collect();+ let states = storage+ .load_projection_states(&keys)+ .await+ .map_err(ProjectionError::Storage)?;+ let bases: BTreeMap<_, _> = keys.into_iter().zip(states).collect();+ let mut result = Vec::new();+ for mutation in mutations {+ let mutation = if let OptimisticProjectionMutation::Replace(document) = mutation {+ let base = bases.get(&document.record_key).and_then(Option::as_ref);+ if let Some(ProjectionState::Complete(base)) =+ base.filter(|base| is_current(base.profile()))+ {+ // A core replacement derived from direct fields must not freeze+ // unrelated optimistic properties at their authoritative values.+ let attributes: BTreeSet<_> = base+ .exact_facts+ .iter()+ .chain(&document.exact_facts)+ .filter(|fact| !facts::is_property_attribute(&fact.attribute))+ .map(|fact| fact.attribute.clone())+ .collect();+ OptimisticProjectionMutation::Patch {+ record_key: document.record_key,+ profile: current_profile(&document.profile),+ partition: document.partition,+ exact: attributes+ .into_iter()+ .map(|attribute| ExactAttributePatch {+ values: document+ .exact_facts+ .iter()+ .filter(|fact| fact.attribute == attribute)+ .map(|fact| fact.value.clone())+ .collect(),+ attribute,+ })+ .collect(),+ integers: document+ .integer_facts+ .iter()+ .map(|fact| predicate_index::IntegerAttributePatch {+ attribute: fact.attribute.clone(),+ values: vec![fact.value],+ })+ .collect(),+ sorts: document.sort_facts,+ }+ } else {+ let properties = changes+ .get(&document.record_key)+ .and_then(|change| change.apply(property_facts(base)));+ match extend_document(document, properties) {+ ProjectionMutation::Replace(document) => {+ OptimisticProjectionMutation::Replace(document)+ }+ ProjectionMutation::MarkIncomplete {+ record_key,+ profile,+ partition,+ ..+ } => OptimisticProjectionMutation::Unknown {+ record_key,+ profile,+ partition,+ affected_attributes: vec![],+ },+ _ => unreachable!("extension is complete or explicitly unknown"),+ }+ }+ } else {+ upgrade(mutation)+ };+ result.push(mutation);+ }+ for (key, change) in changes {+ let base = bases.get(&key).and_then(Option::as_ref);+ let scope = result+ .iter()+ .find(|mutation| mutation.record_key() == &key)+ .map(|mutation| (mutation.profile().clone(), mutation.partition().clone()))+ .or_else(|| {+ base.map(|base| (current_profile(base.profile()), base.partition().clone()))+ });+ let Some((profile, partition)) = scope else {+ continue;+ };+ let old_properties = property_facts(base).unwrap_or_default();+ result.push(match change.patches(&old_properties) {+ Some(exact) => OptimisticProjectionMutation::Patch {+ record_key: key,+ profile,+ partition,+ exact,+ integers: vec![],+ sorts: vec![],+ },+ None => OptimisticProjectionMutation::Unknown {+ record_key: key,+ profile,+ partition,+ affected_attributes: vec![],+ },+ });+ }+ Ok(result)+}diff --git a/crates/soup_filter_cache_adapter/src/properties/prepare.rs b/crates/soup_filter_cache_adapter/src/properties/prepare.rsnew file mode 100644index 0000000000..e1bf4747d9--- /dev/null+++ b/crates/soup_filter_cache_adapter/src/properties/prepare.rs@@ -0,0 +1,426 @@+use super::*;+use cache_core::{+ document::{Document, OperationKind, resolve_args},+ normalize::normalize,+ predicate::PredicateIndexStorage,+ value::{CacheValue, EntityKey, Record},+};+use predicate_index::{+ ExactAttributePatch, ExactValue, IndexQuery, PartitionPredicate, PredicateExpr, SortDirection,+ ValidatedIndexQuery,+};+use std::collections::BTreeSet;+use uuid::Uuid;++#[derive(Default)]+pub(super) struct Changes {+ snapshot: Option<Result<Vec<ExactFact>, ()>>,+ values: BTreeMap<Uuid, Result<Vec<ExactFact>, ()>>,+}+impl Changes {+ pub(super) fn apply(&self, base: Option<Vec<ExactFact>>) -> Option<Vec<ExactFact>> {+ let mut result = match &self.snapshot {+ Some(snapshot) => snapshot.clone().ok()?,+ None => base?,+ };+ for (definition, value) in &self.values {+ let value = value.as_ref().ok()?;+ let attributes = attributes(*definition);+ result.retain(|fact| !attributes.contains(&fact.attribute));+ result.extend(value.iter().cloned());+ }+ Some(result)+ }+ pub(super) fn patches(&self, base: &[ExactFact]) -> Option<Vec<ExactAttributePatch>> {+ let mut selected = BTreeSet::new();+ let mut values = Vec::new();+ if let Some(snapshot) = &self.snapshot {+ values = snapshot.as_ref().ok()?.clone();+ selected.extend(base.iter().map(|fact| fact.attribute.clone()));+ selected.extend(values.iter().map(|fact| fact.attribute.clone()));+ }+ for (definition, value) in &self.values {+ let value = value.as_ref().ok()?;+ let attributes = attributes(*definition);+ values.retain(|fact| !attributes.contains(&fact.attribute));+ selected.extend(attributes);+ values.extend(value.iter().cloned());+ }+ Some(+ selected+ .into_iter()+ .map(|attribute| ExactAttributePatch {+ values: values+ .iter()+ .filter(|fact| fact.attribute == attribute)+ .map(|fact| fact.value.clone())+ .collect(),+ attribute,+ })+ .collect(),+ )+ }+}+fn attributes(definition: Uuid) -> [Token; 3] {+ [+ facts::select_attribute(definition),+ facts::entity_attribute(definition),+ facts::row_attribute(definition),+ ]+}+fn string(record: &Record, field: &str) -> Option<String> {+ match record.fields.get(field)? {+ CacheValue::String(value) => Some(value.clone()),+ _ => None,+ }+}+fn definition(record: &Record) -> Option<Uuid> {+ Uuid::parse_str(&string(record, "propertyDefinitionId")?).ok()+}+fn parent_key(kind: &str, id: &str) -> Option<RecordKey> {+ Uuid::parse_str(id).ok()?;+ let kind = match kind {+ "DOCUMENT" | "TASK" => "GraphqlSoupDocument",+ "PROJECT" => "GraphqlSoupProject",+ "CHAT" => "GraphqlSoupChat",+ "THREAD" => "GraphqlSoupEmailThread",+ _ => return None,+ };+ RecordKey::new(format!("{kind}:{id}")).ok()+}+fn is_parent(key: &EntityKey<'_>) -> bool {+ [+ "GraphqlSoupDocument:",+ "GraphqlSoupProject:",+ "GraphqlSoupChat:",+ "GraphqlSoupEmailThread:",+ ]+ .iter()+ .any(|prefix| key.as_ref().starts_with(prefix))+}+fn row_facts(key: &EntityKey<'_>, record: &Record) -> Result<(Uuid, Vec<ExactFact>), ()> {+ let definition = definition(record).ok_or(())?;+ let mut result = vec![ExactFact {+ attribute: facts::row_attribute(definition),+ value: ExactValue::utf8(key.as_ref()).map_err(|_| ())?,+ }];+ let value = record.fields.get("value").ok_or(())?;+ let CacheValue::Object(value) = value else {+ return if value == &CacheValue::Null {+ Ok((definition, result))+ } else {+ Err(())+ };+ };+ let Some(CacheValue::String(typename)) = value.get("__typename") else {+ return Err(());+ };+ match typename.as_str() {+ "GraphqlSelectOptionPropertyValue" => {+ let Some(CacheValue::List(options)) = value.get("optionIds") else {+ return Err(());+ };+ for option in options {+ let CacheValue::String(option) = option else {+ return Err(());+ };+ let id = Uuid::parse_str(option).map_err(|_| ())?;+ result.push(ExactFact {+ attribute: facts::select_attribute(definition),+ value: ExactValue::new(id.as_bytes()).map_err(|_| ())?,+ });+ }+ }+ "GraphqlEntityReferencePropertyValue" => {+ let Some(CacheValue::List(references)) = value.get("references") else {+ return Err(());+ };+ for reference in references {+ let CacheValue::Object(reference) = reference else {+ return Err(());+ };+ let Some(CacheValue::String(id)) = reference.get("entityId") else {+ return Err(());+ };+ result.push(ExactFact {+ attribute: facts::entity_attribute(definition),+ value: ExactValue::utf8(id).map_err(|_| ())?,+ });+ }+ }+ "GraphqlBooleanPropertyValue"+ | "GraphqlNumberPropertyValue"+ | "GraphqlStringPropertyValue"+ | "GraphqlDatePropertyValue"+ | "GraphqlLinkPropertyValue" => {}+ _ => return Err(()),+ }+ Ok((definition, result))+}++fn snapshot(+ value: &CacheValue,+ updates: &BTreeMap<EntityKey<'static>, Record>,+) -> Result<Vec<ExactFact>, ()> {+ let CacheValue::List(properties) = value else {+ return Err(());+ };+ let mut definitions = BTreeSet::new();+ let mut result = Vec::new();+ for property in properties {+ let CacheValue::Ref(key) = property else {+ return Err(());+ };+ // New completeness comes only from values selected in this response,+ // never a truncated fragment merged with older stored property values.+ let (definition, facts) = row_facts(key, updates.get(key).ok_or(())?)?;+ if !definitions.insert(definition) {+ return Err(());+ }+ result.extend(facts);+ }+ Ok(result)+}++fn mutation_owners(+ query: &str,+ operation: Option<&str>,+ variables: &Map<String, Value>,+ data: &Value,+) -> Result<BTreeMap<EntityKey<'static>, RecordKey>, SoupFilterCacheAdapterError> {+ let doc = Document::parse(query).map_err(error)?;+ let op = doc.operation(operation).map_err(error)?;+ let mut owners = BTreeMap::new();+ if op.kind != OperationKind::Mutation {+ return Ok(owners);+ }+ let mut fields = Vec::new();+ crate::collect_applicable_fields(+ &op.selection_set,+ cache_core::meta::MUTATION_ROOT_TYPE.unwrap_or(""),+ &mut fields,+ );+ for field in fields {+ if field.name != "setEntityProperty" {+ continue;+ }+ let args = resolve_args(field, variables).map_err(error)?;+ let Some(input) = args.get("input").and_then(Value::as_object) else {+ continue;+ };+ let Some((kind, id)) = input+ .get("entityType")+ .and_then(Value::as_str)+ .zip(input.get("entityId").and_then(Value::as_str))+ else {+ continue;+ };+ let Some(parent) = parent_key(kind, id) else {+ continue;+ };+ let Some(value) = data.get(&field.response_key) else {+ continue;+ };+ let mut selections = Vec::new();+ crate::collect_applicable_fields(&field.selection_set, "GraphqlProperty", &mut selections);+ let Some(id) = selections+ .iter()+ .find(|f| f.name == "id")+ .and_then(|f| value.get(&f.response_key))+ .and_then(Value::as_str)+ else {+ continue;+ };+ owners.insert(EntityKey(format!("GraphqlProperty:{id}").into()), parent);+ }+ Ok(owners)+}++async fn owners<S: PredicateIndexStorage>(+ storage: &S,+ property: &EntityKey<'_>,+ definition: Uuid,+) -> Result<Vec<RecordKey>, ProjectionError<S::Error>> {+ let mut result = Vec::new();+ for (profile, partitions, sort) in [+ (+ vocabulary::profile_v5(),+ vec![+ vocabulary::document_partition(),+ vocabulary::project_partition(),+ vocabulary::chat_partition(),+ ],+ vocabulary::updated_at(),+ ),+ (+ facts::mail_profile(),+ vec![item_filter_index::mail::partition()],+ item_filter_index::mail::token("mail-all-ts"),+ ),+ ] {+ let predicate = PredicateExpr::Exact {+ attribute: facts::row_attribute(definition),+ value: ExactValue::utf8(property.as_ref()).map_err(error)?,+ };+ let query = ValidatedIndexQuery::new(IndexQuery {+ profile,+ partitions: partitions+ .into_iter()+ .map(|partition| PartitionPredicate {+ partition,+ predicate: predicate.clone(),+ })+ .collect(),+ sort_attribute: sort,+ sort_direction: SortDirection::Asc,+ tie_break_direction: SortDirection::Asc,+ limit: 2,+ })+ .map_err(error)?;+ result.extend(+ storage+ .reconcile_predicate_index(&query, &[])+ .await+ .map_err(ProjectionError::Storage)?+ .keys,+ );+ }+ // A property row has one canonical owning entity. Refuse contradictory+ // ownership instead of scanning or updating a truncated owner set.+ if result.len() > 1 {+ return Err(error("property projection has multiple owners").into());+ }+ Ok(result)+}++pub(super) async fn prepare<S: PredicateIndexStorage>(+ storage: &S,+ query: &str,+ operation: Option<&str>,+ variables: &Map<String, Value>,+ data: &Value,+ reuse: bool,+) -> Result<BTreeMap<RecordKey, Changes>, ProjectionError<S::Error>> {+ let document = Document::parse(query).map_err(error)?;+ let op = document.operation(operation).map_err(error)?;+ let updates: BTreeMap<_, _> = normalize(op, variables, data)+ .map_err(error)?+ .into_iter()+ .collect();+ let mut result: BTreeMap<RecordKey, Changes> = BTreeMap::new();+ let mut snapshot_children = BTreeSet::new();+ for (key, record) in &updates {+ if !is_parent(key) {+ continue;+ }+ if let Some(properties) = record.fields.get("properties") {+ if let CacheValue::List(properties) = properties {+ snapshot_children.extend(properties.iter().filter_map(|v| {+ if let CacheValue::Ref(key) = v {+ Some(key.clone())+ } else {+ None+ }+ }));+ }+ result+ .entry(RecordKey::new(key.to_string()).map_err(error)?)+ .or_default()+ .snapshot = Some(snapshot(properties, &updates));+ }+ }+ let routed = mutation_owners(query, operation, variables, data)?;+ for (key, parent) in &routed {+ if updates+ .get(key)+ .is_none_or(|record| !record.fields.contains_key("value"))+ {+ // A successful explicit property mutation with an ID-only response+ // is not evidence that the old value survived unchanged.+ result.entry(parent.clone()).or_default().snapshot = Some(Err(()));+ }+ }+ for (key, update) in &updates {+ if !key.as_ref().starts_with("GraphqlProperty:")+ || !update.fields.contains_key("value")+ || snapshot_children.contains(key)+ {+ continue;+ }+ let mut record = if reuse {+ storage+ .get_batch(std::slice::from_ref(key))+ .await+ .map_err(ProjectionError::Storage)?+ .pop()+ .flatten()+ .unwrap_or_default()+ } else {+ Record::default()+ };+ record.merge(update.clone());+ let Some(definition) = definition(&record) else {+ if let Some(parent) = routed.get(key) {+ result.entry(parent.clone()).or_default().snapshot = Some(Err(()));+ }+ continue;+ };+ let parents = if let Some(parent) = routed.get(key) {+ vec![parent.clone()]+ } else if reuse {+ owners(storage, key, definition).await?+ } else {+ vec![]+ };+ for parent in parents {+ result+ .entry(parent)+ .or_default()+ .values+ .insert(definition, row_facts(key, &record).map(|(_, facts)| facts));+ }+ }+ Ok(result)+}++pub(super) async fn deletion_updates<S: PredicateIndexStorage>(+ storage: &S,+ keys: &[String],+) -> Result<Vec<ProjectionMutation>, ProjectionError<S::Error>> {+ let mut result = Vec::new();+ for key in keys+ .iter()+ .filter(|key| key.starts_with("GraphqlProperty:"))+ {+ let key = EntityKey(key.clone().into());+ let Some(record) = storage+ .get_batch(std::slice::from_ref(&key))+ .await+ .map_err(ProjectionError::Storage)?+ .pop()+ .flatten()+ else {+ continue;+ };+ let Some(definition) = definition(&record) else {+ continue;+ };+ for parent in owners(storage, &key, definition).await? {+ let Some(state) = storage+ .load_projection_states(std::slice::from_ref(&parent))+ .await+ .map_err(ProjectionError::Storage)?+ .pop()+ .flatten()+ else {+ continue;+ };+ result.push(incomplete(+ parent,+ state.profile().clone(),+ state.partition().clone(),+ ));+ }+ }+ Ok(result)+}diff --git a/crates/soup_filter_cache_adapter/src/properties/test.rs b/crates/soup_filter_cache_adapter/src/properties/test.rsnew file mode 100644index 0000000000..f706f96c9d--- /dev/null+++ b/crates/soup_filter_cache_adapter/src/properties/test.rs@@ -0,0 +1,365 @@+use super::*;+use cache_core::{+ engine::{BeginOptimisticWrite, Engine, InitialClaimOutcome, NetworkWrite},+ predicate::PredicateIndexStorage,+ queue::{MutationClaimRequest, MutationClaimToken},+ store::{InMemoryStorage, Storage},+};+use serde_json::json;+use uuid::Uuid;++const QUERY: &str = include_str!("test/project.graphql");+const SET: &str = include_str!("test/set.graphql");+const VIEWER: &str = "macro|[email protected]";+fn id(n: u128) -> String {+ Uuid::from_u128(n).to_string()+}+fn key() -> RecordKey {+ RecordKey::new(format!("GraphqlSoupProject:{}", id(100))).unwrap()+}+fn property(n: u128, option: u128) -> Value {+ json!({"id": id(n + 1000), "propertyDefinitionId": id(n), "value": {"__typename":"GraphqlSelectOptionPropertyValue", "optionIds": [id(option)]}})+}+fn data() -> Value {+ json!({"user": {"id": VIEWER, "soup": {"items": [{+ "__typename": "GraphqlSoupProject", "id": id(100), "cacheProjection": null,+ "ownerId": VIEWER, "parentId": null, "createdAt": "2025-01-01T00:00:00Z", "updatedAt": "2025-01-02T00:00:00Z", "notifications": [],+ "properties": [property(1, 11), property(2, 22)],+ }]}}})+}+fn filters(property: Option<Value>) -> Value {+ let nil = id(0);+ let mut filters = json!({+ "documentFilter":{"literal":{"id":nil}}, "projectFilter":{"literal":{"projectIdSelf": id(100)}},+ "chatFilter":{"literal":{"chatId":nil}}, "emailFilter":{"tree":{"literal":{"threadId":nil}}},+ "channelFilter":{"literal":{"channelId":nil}}, "channelThreadFilter":{"literal":{"threadId":nil}},+ "calendarEventFilter":{"literal":{"id":nil}}, "callFilter":{"literal":{"callId":nil}},+ "crmCompanyFilter":{"literal":{"id":nil}}, "foreignEntityFilter":{"literal":{"id":nil}},+ });+ if let Some(property) = property {+ filters["propertiesFilter"] = property;+ }+ filters+}+fn literal(definition: u128, option: u128) -> Value {+ json!({"literal":{"propertyDefinitionId": id(definition), "value":{"selectOption":id(option)}}})+}+async fn write<S: PredicateIndexStorage>(+ engine: &mut Engine<S>,+ query: &str,+ vars: &Map<String, Value>,+ data: &Value,+ identity: &str,+) {+ let core = crate::authoritative_projection_mutations(query, None, data).unwrap();+ let reuse = engine+ .current_identity()+ .await+ .unwrap()+ .as_deref()+ .is_none_or(|bound| bound == identity);+ let projections = augment_authoritative(engine.storage(), query, None, vars, data, reuse, core)+ .await+ .unwrap();+ engine+ .write_query_with_registration_and_projections(+ None,+ None,+ NetworkWrite {+ query,+ operation_name: None,+ variables: vars,+ data,+ identity: Some(identity),+ },+ projections,+ )+ .await+ .unwrap();+}+async fn matches<S: PredicateIndexStorage>(engine: &mut Engine<S>, property: Value) -> bool {+ let crate::SoupFilterCompileOutcome::Supported(query) =+ crate::compile_current_filter_request(filters(Some(property)), "UPDATED_AT", "DESC", 100)+ .unwrap()+ else {+ panic!("filter must be supported")+ };+ engine+ .reconcile_predicate_index(&query, &[])+ .await+ .unwrap()+ .value+ .keys+ == vec![key()]+}++#[test]+fn property_snapshots_and_single_property_writes_update_native_postings() {+ pollster::block_on(async {+ let mut engine =+ Engine::new(cache_turso::TursoStorage::open_in_memory("properties").unwrap());+ write(&mut engine, QUERY, &Map::new(), &data(), VIEWER).await;+ assert!(matches(&mut engine, literal(1, 11)).await);+ assert!(!matches(&mut engine, literal(1, 12)).await);+ let vars = json!({"input": {"entityType":"PROJECT", "entityId":id(100), "propertyDefinitionId":id(1)}}).as_object().unwrap().clone();+ write(+ &mut engine,+ SET,+ &vars,+ &json!({"setEntityProperty":property(1,12)}),+ VIEWER,+ )+ .await;+ assert!(!matches(&mut engine, literal(1, 11)).await);+ assert!(+ matches(+ &mut engine,+ json!({"and":{"left":literal(1,12),"right":literal(2,22)}})+ )+ .await+ );+ });+}++#[test]+fn missing_or_malformed_property_proof_is_unknown_not_a_negative_match() {+ pollster::block_on(async {+ for properties in [None, Some(Value::Null), Some(json!([{"id":id(1)}]))] {+ let mut payload = data();+ let row = payload["user"]["soup"]["items"][0].as_object_mut().unwrap();+ row.remove("properties");+ if let Some(properties) = properties {+ row.insert("properties".into(), properties);+ }+ let mut engine = Engine::new(InMemoryStorage::new());+ write(&mut engine, QUERY, &Map::new(), &payload, VIEWER).await;+ let state = engine+ .storage()+ .load_projection_states(&[key()])+ .await+ .unwrap()+ .pop()+ .flatten()+ .unwrap();+ assert!(matches!(state, ProjectionState::Incomplete { .. }));+ assert!(!matches(&mut engine, json!({"not":literal(1,11)})).await);+ }+ });+}++#[test]+fn empty_snapshots_clear_facts_but_deleted_child_records_make_them_unknown() {+ pollster::block_on(async {+ let mut engine =+ Engine::new(cache_turso::TursoStorage::open_in_memory("property-deletion").unwrap());+ write(&mut engine, QUERY, &Map::new(), &data(), VIEWER).await;+ let changes =+ deletion_updates(engine.storage(), &[format!("GraphqlProperty:{}", id(1001))])+ .await+ .unwrap();+ assert_eq!(changes.len(), 1);+ assert!(matches!(+ changes[0],+ ProjectionMutation::MarkIncomplete { .. }+ ));+ let mut payload = data();+ payload["user"]["soup"]["items"][0]["properties"] = json!([]);+ write(&mut engine, QUERY, &Map::new(), &payload, VIEWER).await;+ assert!(!matches(&mut engine, literal(1, 11)).await);+ assert!(matches(&mut engine, json!({"not":literal(1,11)})).await);+ });+}++#[test]+fn identity_changes_never_borrow_older_property_snapshots() {+ pollster::block_on(async {+ let mut engine = Engine::new(InMemoryStorage::new());+ write(&mut engine, QUERY, &Map::new(), &data(), VIEWER).await;+ let mut payload = data();+ payload["user"]["id"] = json!("macro|[email protected]");+ payload["user"]["soup"]["items"][0]+ .as_object_mut()+ .unwrap()+ .remove("properties");+ write(+ &mut engine,+ QUERY,+ &Map::new(),+ &payload,+ "macro|[email protected]",+ )+ .await;+ assert!(!matches(&mut engine, literal(1, 11)).await);+ assert!(!matches(&mut engine, json!({"not":literal(1,11)})).await);+ });+}++#[test]+fn independent_property_optimism_survives_rollback_and_commits() {+ pollster::block_on(async {+ let mut engine =+ Engine::new(cache_turso::TursoStorage::open_in_memory("property-queue").unwrap());+ write(&mut engine, QUERY, &Map::new(), &data(), VIEWER).await;+ let mut first = None;+ let mut second_data = Value::Null;+ let mut second_vars = Map::new();+ for (definition, option) in [(1, 12), (2, 23)] {+ let vars = json!({"input":{"entityType":"PROJECT","entityId":id(100),"propertyDefinitionId":id(definition)}}).as_object().unwrap().clone();+ let data = json!({"setEntityProperty":property(definition, option)});+ let projections = augment_optimistic(engine.storage(), SET, None, &vars, &data, vec![])+ .await+ .unwrap();+ let uuid = format!("00000000-0000-7000-8000-{definition:012}");+ let queued = engine+ .enqueue_optimistic_mutation_with_projections(+ None,+ BeginOptimisticWrite {+ uuid: &uuid,+ query: SET,+ operation_name: None,+ variables: &vars,+ data: &data,+ link_patches: &[],+ revalidations: &[],+ created_at_ms: 0,+ },+ MutationClaimRequest {+ owner: "runner".into(),+ now_ms: 0,+ lease_expires_at_ms: 1000,+ },+ projections,+ )+ .await+ .unwrap();+ if definition == 1 {+ first = Some(queued);+ } else {+ second_data = data;+ second_vars = vars;+ }+ }+ assert!(+ matches(+ &mut engine,+ json!({"and":{"left":literal(1,12),"right":literal(2,23)}})+ )+ .await+ );+ let first = first.unwrap();+ let InitialClaimOutcome::Claimed(claim) = first.initial_claim else {+ panic!("first claim")+ };+ engine+ .rollback_optimistic_write(+ first.transaction_id,+ MutationClaimToken {+ owner: "runner".into(),+ generation: claim.lease_generation,+ },+ )+ .await+ .unwrap();+ assert!(+ matches(+ &mut engine,+ json!({"and":{"left":literal(1,11),"right":literal(2,23)}})+ )+ .await+ );+ assert!(!matches(&mut engine, literal(1, 12)).await);+ let claim = engine+ .claim_next_mutation(MutationClaimRequest {+ owner: "runner".into(),+ now_ms: 1,+ lease_expires_at_ms: 1000,+ })+ .await+ .unwrap()+ .unwrap();+ let projections = augment_authoritative(+ engine.storage(),+ SET,+ None,+ &second_vars,+ &second_data,+ true,+ vec![],+ )+ .await+ .unwrap();+ engine+ .commit_optimistic_write_with_projections_outcome(+ claim.queued.id,+ MutationClaimToken {+ owner: "runner".into(),+ generation: claim.lease_generation,+ },+ SET,+ None,+ &second_vars,+ &second_data,+ projections,+ )+ .await+ .unwrap();+ assert!(+ matches(+ &mut engine,+ json!({"and":{"left":literal(1,11),"right":literal(2,23)}})+ )+ .await+ );+ assert!(+ engine+ .storage()+ .load_mutation_queue()+ .await+ .unwrap()+ .is_empty()+ );+ });+}++#[test]+fn id_only_property_mutation_responses_invalidate_old_value_proof() {+ pollster::block_on(async {+ let mut engine = Engine::new(InMemoryStorage::new());+ write(&mut engine, QUERY, &Map::new(), &data(), VIEWER).await;+ let vars = json!({"input":{"entityType":"PROJECT","entityId":id(100),"propertyDefinitionId":id(1)}}).as_object().unwrap().clone();+ write(&mut engine, "mutation Set($input: SetEntityPropertyInput!) { setEntityProperty(input: $input) { id } }", &vars,+ &json!({"setEntityProperty":{"id":id(1001)}}), VIEWER).await;+ assert!(!matches(&mut engine, literal(1, 11)).await);+ assert!(!matches(&mut engine, json!({"not":literal(1,11)})).await);+ });+}++#[test]+fn property_optimism_only_patches_the_modified_definition() {+ pollster::block_on(async {+ let mut engine = Engine::new(InMemoryStorage::new());+ write(&mut engine, QUERY, &Map::new(), &data(), VIEWER).await;+ let vars = json!({"input": {"entityType":"PROJECT", "entityId":id(100), "propertyDefinitionId":id(1)}}).as_object().unwrap().clone();+ let changes = augment_optimistic(+ engine.storage(),+ SET,+ None,+ &vars,+ &json!({"setEntityProperty":property(1,12)}),+ vec![],+ )+ .await+ .unwrap();+ let [OptimisticProjectionMutation::Patch { exact, profile, .. }] = changes.as_slice()+ else {+ panic!("property patch expected")+ };+ assert_eq!(profile, &vocabulary::profile_v5());+ assert_eq!(exact.len(), 3);+ assert!(+ exact+ .iter()+ .all(|patch| patch.attribute.as_str().contains(&id(1)))+ );+ });+}diff --git a/crates/soup_filter_cache_adapter/src/properties/test/project.graphql b/crates/soup_filter_cache_adapter/src/properties/test/project.graphqlnew file mode 100644index 0000000000..400ab6dd8c--- /dev/null+++ b/crates/soup_filter_cache_adapter/src/properties/test/project.graphql@@ -0,0 +1,21 @@+query PropertySeed {+ user {+ id+ soup(input: {initial: {limit: 100}}) {+ items {+ __typename id cacheProjection+ ... on GraphqlSoupProject {+ ownerId parentId createdAt updatedAt notifications { id }+ properties {+ id propertyDefinitionId+ value {+ __typename+ ... on GraphqlSelectOptionPropertyValue { optionIds }+ ... on GraphqlEntityReferencePropertyValue { references { entityId } }+ }+ }+ }+ }+ }+ }+}diff --git a/crates/soup_filter_cache_adapter/src/properties/test/set.graphql b/crates/soup_filter_cache_adapter/src/properties/test/set.graphqlnew file mode 100644index 0000000000..283ba139e1--- /dev/null+++ b/crates/soup_filter_cache_adapter/src/properties/test/set.graphql@@ -0,0 +1,10 @@+mutation Set($input: SetEntityPropertyInput!) {+ setEntityProperty(input: $input) {+ id propertyDefinitionId+ value {+ __typename+ ... on GraphqlSelectOptionPropertyValue { optionIds }+ ... on GraphqlEntityReferencePropertyValue { references { entityId } }+ }+ }+}diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.mdindex cf7f72c60e..2653d3a274 100644--- a/docs/AGENT_GUIDE/surfaces.md+++ b/docs/AGENT_GUIDE/surfaces.md@@ -2,7 +2,7 @@## Live updates in flat Soup lists-With browser GraphQL caching enabled, locally supported flat lists reconcile their+With browser or native Tauri GraphQL caching enabled, locally supported flat lists reconcile theirloaded server pages with matching cached entities. Complete matching updates canappear without a list refetch; confirmed non-matches and explicit deletions disappear.Rows whose current predicate facts are unknown retain their previous server membership@@ -11,7 +11,8 @@ notification-only cache records do not block other rows' updates. While recomputis pending, the last rendered result for the same query and cache generation staysvisible; local results do not trigger the tab-loading bar. A fresh server responsestill replaces that result, and initial loads without usable data retain normal loading-indicators.+indicators. A transport failure does not hide usable current-query local results,+including empty results; HTTP responses and GraphQL errors still surface.This is a best-effort display, not proof that every matching entity is cached. Outsidethe supported cached-Mail slice below, loading more follows the original server cursors@@ -20,7 +21,7 @@ Newly loaded server rows join the retained display immediately, without duplicatwaiting for local recomputation to succeed. Removing pages from the server baselineinvalidates overlays built from those pages.Changing filters or resetting the cache discards prior reconciliation evidence. Grouped-lists, unsupported filters/sorts, and native/non-cache transports keep their existing+lists, unsupported filters/sorts, and non-cache transports keep their existingnetwork behavior.For Documents (including Tasks), Projects, Chats, and participating Channels,@@ -43,9 +44,15 @@ backfill checkpoint is refreshed to index channel rows; queued work is preservedNotification facts use the existing active-only GraphQL edge and primary entityassociation. Missing/partial or over-budget snapshots remain incomplete, never anempty notification set; display metadata decoding omissions remain a best-effort-limitation. The v4 projection tracks individual notification IDs, bounded by the-shared 256-fact per-entity budget. This cache-format upgrade resets old cached data-and pending cache mutations, and the bumped backfill checkpoint rebuilds projections.+limitation. The current `soup-flat-v5` projection retains notification IDs and+adds complete select-option/entity-reference property snapshots. Tags, task status,+priority and assignee selections compose with owner and type filters. The shared+256-fact per-entity budget still applies: missing, malformed or over-budget property+snapshots are unknown, never evidence of absence. Property-only mutations update+these postings atomically; rollback does not restore unrelated property values.+Checkpoint v14 rehydrates older projections without wiping normalized records or+queued mutations. General Soup still uses its existing server pagination; filter-only+offline checks use an ungrouped view with a created/updated timestamp sort.Realtime Soup batches coalesce repeated entity IDs (including entity type), keepingthat entity's last operation in the batch. Emitted `SoupUpdated` items are non-null.@@ -216,16 +223,17 @@ necessarily evaluated from the last synchronized grants.The lightweight metadata backfill runs before body hydration. Its refreshes scan allmetadata: message-time watermarks alone miss archive/read changes on old threads.Filter availability therefore does not guarantee that opening every message body works offline. Missing-projection proof is unknown, never false. Sender/recipient, attachment chips,-property/tag refinements and non-created/updated sorts remain network-only or-existing client refinements; durable offline sending/archiving is not added by this slice. No cache-format wipe is required: Mail uses a separate versioned profile+projection proof is unknown, never false. Tag selections use cached property postings;+attachment chips refine the cached rows on the client. Sender/recipient filters and+non-created/updated sorts remain outside this local profile. Grouping and sort-selector+coverage are separate from the filter-selection matrix. No cache-format wipe is required: Mail uses a separate versioned profileand a new backfill checkpoint, preserving existing queued work. Deploy the backendschema additions before the client: it selects canonical message eligibility/recencyfields, body-free canonical preview references, and viewer-relative share facts.-The `soup-mail-v2` profile and new backfill checkpoint rebuild Mail proof without+The `soup-mail-v3` property-aware profile and new backfill checkpoint rebuild Mail proof withoutchanging the persisted mutation queue format. Native Tauri maintains the samepredicate projections and revision-bound local page contract as the browser.-Checkpoint v13 restarts older scans to populate native indexes without wiping+Checkpoint v14 restarts older scans to populate property-aware indexes without wipingqueued work. A background network failure does not hide a usable current-querycached Mail page; server-reported GraphQL errors still surface.@@ -326,6 +334,14 @@ copy, and move-to-folder actions are not offered on agent-session search rows.Tabs `Owned` / `Shared` / `Attachments` / `Folders` / `All`; `New` menu; rows show title,tags, updated time. Clicking a row opens the doc.+Shared always excludes files owned by you. Selecting **Created by → Me** therefore+returns no files; selecting Me together with another creator returns only that+other creator's shared files. Clearing the creator selection restores all Shared+results. This applies to restored filters and flat/grouped list requests—not+just client-side row filtering. Cached inserts enforce the same rule before a+refetch, including expanded groups and inactive cached Shared queries. Until+viewer identity is available, document inserts into Shared are rejected.+With `enable-new-app-views` enabled, Files opens **Drive** using the sameshell as Tasks. The sidebar contains `New file or folder`, `My Files`, `Recent`,`Shared with me`, collapsible Favorites, and a searchable folder hierarchy.