Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(web): do not post document history for GitHub PR entities (#6382)

Will Hutchinson1ed220be5023
diff --git a/apps/web/src/lib/core/internal/trackBlockOpened.test.ts b/apps/web/src/lib/core/internal/trackBlockOpened.test.ts
new file mode 100644
index 0000000000..ac3791f3c1
--- /dev/null
+++ b/apps/web/src/lib/core/internal/trackBlockOpened.test.ts
@@ -0,0 +1,48 @@
+import type { QueryClient } from '@tanstack/solid-query';
+import type { Accessor } from 'solid-js';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+const mutate = vi.fn();
+
+vi.mock('@queries/history/history', () => ({
+ useUpsertToHistoryMutation: () => ({ mutate }),
+}));
+
+vi.mock('@queries/soup/cache', () => ({
+ hasSoupEntity: () => false,
+ optimisticUpdateSoupItemViewedAt: vi.fn(),
+ refetchSoupEntity: vi.fn(),
+}));
+
+import { track } from './trackBlockOpened';
+
+const unusedClient = (() => {
+ throw new Error('history mutation should not read the query client');
+}) as Accessor<QueryClient>;
+
+describe('track', () => {
+ beforeEach(() => {
+ mutate.mockReset();
+ });
+
+ it('does not POST user history for GitHub PR foreign entities', () => {
+ track({
+ itemId: 'foreign-entity-1',
+ blockName: 'pr',
+ client: unusedClient,
+ });
+ expect(mutate).not.toHaveBeenCalled();
+ });
+
+ it('POSTs document history for markdown documents', () => {
+ track({
+ itemId: 'doc-1',
+ blockName: 'md',
+ client: unusedClient,
+ });
+ expect(mutate).toHaveBeenCalledWith({
+ itemId: 'doc-1',
+ itemType: 'document',
+ });
+ });
+});
diff --git a/apps/web/src/lib/core/internal/trackBlockOpened.ts b/apps/web/src/lib/core/internal/trackBlockOpened.ts
index fd25080110..77d906bc3f 100644
--- a/apps/web/src/lib/core/internal/trackBlockOpened.ts
+++ b/apps/web/src/lib/core/internal/trackBlockOpened.ts
@@ -41,6 +41,10 @@ function isSoupEntityTag(
// `viewed_updated` sort joins UserHistory generically — so writing
// these rows is what surfaces recently-opened companies/contacts in
// Quick Access and the @ mention menu.
+//
+// Foreign entities (GitHub PRs) are intentionally omitted: they are not
+// documents, and posting `/history/document/{id}` 401s because ACL looks
+// up a document that does not exist.
function shouldTrackInUserHistory(itemType: ItemType): boolean {
return (
isCloudStorageItem(itemType) ||
diff --git a/apps/web/src/lib/service-clients/service-storage/itemType.test.ts b/apps/web/src/lib/service-clients/service-storage/itemType.test.ts
index 3b6fd4d9ba..7f8683f3a0 100644
--- a/apps/web/src/lib/service-clients/service-storage/itemType.test.ts
+++ b/apps/web/src/lib/service-clients/service-storage/itemType.test.ts
@@ -72,6 +72,7 @@ describe('blockNameToItemType', () => {
['automation', 'automation'],
['company', 'crm_company'],
['contact', 'crm_contact'],
+ ['pr', 'foreign'],
] as const)('maps block %s to item type %s', (blockName, itemType) => {
expect(blockNameToItemType(blockName)).toBe(itemType);
});
diff --git a/apps/web/src/lib/service-clients/service-storage/itemType.ts b/apps/web/src/lib/service-clients/service-storage/itemType.ts
index 3f0d7421c1..ee1d901d8e 100644
--- a/apps/web/src/lib/service-clients/service-storage/itemType.ts
+++ b/apps/web/src/lib/service-clients/service-storage/itemType.ts
@@ -64,6 +64,7 @@ export function blockNameToItemType(
.with('calendar', () => 'calendar_event')
.with('company', () => 'crm_company')
.with('contact', () => 'crm_contact')
+ .with('pr', () => 'foreign')
.otherwise(() => DEFAULT_ITEM_TYPE);
}