@imbue-ai/detent 1.15.2 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1617,6 +1617,202 @@ describe('builtin schemas: slack', () => {
1617
1617
  .get('slack-reminders-write')
1618
1618
  .match(makeSlackRequest({ path: '/api/reminders.list' }))).toBe(false);
1619
1619
  });
1620
+ const slackReadPermissionsByMethod = {
1621
+ '/api/api.test': 'slack-auth-read',
1622
+ '/api/team.info': 'slack-auth-read',
1623
+ '/api/team.profile.get': 'slack-auth-read',
1624
+ '/api/bots.info': 'slack-auth-read',
1625
+ '/api/drafts.list': 'slack-chat-read',
1626
+ '/api/client.counts': 'slack-conversations-read',
1627
+ '/api/client.userBoot': 'slack-conversations-read',
1628
+ '/api/client.init': 'slack-conversations-read',
1629
+ '/api/client.dms': 'slack-conversations-read',
1630
+ '/api/client.shouldReload': 'slack-conversations-read',
1631
+ '/api/conversations.view': 'slack-conversations-read',
1632
+ '/api/conversations.genericInfo': 'slack-conversations-read',
1633
+ '/api/conversations.listPrefs': 'slack-conversations-read',
1634
+ '/api/threads.getView': 'slack-conversations-read',
1635
+ '/api/subscriptions.thread.getView': 'slack-conversations-read',
1636
+ '/api/users.prefs.get': 'slack-users-read',
1637
+ '/api/users.counts': 'slack-users-read',
1638
+ '/api/users.channelSections.list': 'slack-users-read',
1639
+ '/api/users.priority.list': 'slack-users-read',
1640
+ '/api/usergroups.list': 'slack-users-read',
1641
+ '/api/usergroups.users.list': 'slack-users-read',
1642
+ '/api/dnd.info': 'slack-users-read',
1643
+ '/api/dnd.teamInfo': 'slack-users-read',
1644
+ '/api/canvases.sections.lookup': 'slack-files-read',
1645
+ '/api/emoji.list': 'slack-reactions-read',
1646
+ '/api/search.modules.channels': 'slack-search',
1647
+ '/api/search.modules.people': 'slack-search',
1648
+ '/api/search.inline': 'slack-search',
1649
+ '/api/search.autocomplete': 'slack-search',
1650
+ '/api/saved.list': 'slack-later-read',
1651
+ '/api/stars.list': 'slack-later-read',
1652
+ '/api/reminders.list': 'slack-later-read',
1653
+ };
1654
+ const slackWritePermissionsByMethod = {
1655
+ '/api/chat.command': 'slack-chat-write',
1656
+ '/api/drafts.create': 'slack-chat-write',
1657
+ '/api/drafts.update': 'slack-chat-write',
1658
+ '/api/drafts.delete': 'slack-chat-write',
1659
+ '/api/conversations.canvases.create': 'slack-conversations-write',
1660
+ '/api/subscriptions.thread.mark': 'slack-conversations-write',
1661
+ '/api/subscriptions.thread.add': 'slack-conversations-write',
1662
+ '/api/subscriptions.thread.remove': 'slack-conversations-write',
1663
+ '/api/users.prefs.set': 'slack-users-write',
1664
+ '/api/users.setActive': 'slack-users-write',
1665
+ '/api/users.setPhoto': 'slack-users-write',
1666
+ '/api/usergroups.create': 'slack-users-write',
1667
+ '/api/usergroups.users.update': 'slack-users-write',
1668
+ '/api/dnd.setSnooze': 'slack-users-write',
1669
+ '/api/dnd.endDnd': 'slack-users-write',
1670
+ '/api/files.edit': 'slack-files-write',
1671
+ '/api/files.share': 'slack-files-write',
1672
+ '/api/files.upload': 'slack-files-write',
1673
+ '/api/canvases.create': 'slack-files-write',
1674
+ '/api/canvases.access.set': 'slack-files-write',
1675
+ '/api/saved.add': 'slack-later-write',
1676
+ '/api/saved.delete': 'slack-later-write',
1677
+ '/api/saved.update': 'slack-later-write',
1678
+ '/api/saved.clearCompleted': 'slack-later-write',
1679
+ '/api/stars.add': 'slack-later-write',
1680
+ '/api/reminders.add': 'slack-later-write',
1681
+ };
1682
+ it('private and newly added read methods are covered by their cluster and by slack-read-all', () => {
1683
+ for (const [path, permission] of Object.entries(slackReadPermissionsByMethod)) {
1684
+ expectSchemaExists(permission);
1685
+ const request = makeSlackRequest({ path });
1686
+ expect(builtinRegistry.get(permission).match(request), `Expected ${permission} to match "${path}"`).toBe(true);
1687
+ expect(builtinRegistry.get('slack-read-all').match(request), `Expected slack-read-all to match "${path}"`).toBe(true);
1688
+ expect(builtinRegistry.get('slack-write-all').match(request), `Expected slack-write-all to reject "${path}"`).toBe(false);
1689
+ }
1690
+ });
1691
+ it('private and newly added write methods are covered by their cluster and by slack-write-all', () => {
1692
+ for (const [path, permission] of Object.entries(slackWritePermissionsByMethod)) {
1693
+ expectSchemaExists(permission);
1694
+ const request = makeSlackRequest({ path });
1695
+ expect(builtinRegistry.get(permission).match(request), `Expected ${permission} to match "${path}"`).toBe(true);
1696
+ expect(builtinRegistry.get('slack-write-all').match(request), `Expected slack-write-all to match "${path}"`).toBe(true);
1697
+ expect(builtinRegistry.get('slack-read-all').match(request), `Expected slack-read-all to reject "${path}"`).toBe(false);
1698
+ }
1699
+ });
1700
+ it('slack-read-all and slack-write-all are exactly the union of the fine-grained clusters', () => {
1701
+ const readPermissions = Object.keys(getAllBuiltinSchemas()).filter((name) => name.startsWith('slack-') &&
1702
+ !name.endsWith('-all') &&
1703
+ !name.endsWith('-write') &&
1704
+ name !== 'slack-api');
1705
+ const writePermissions = Object.keys(getAllBuiltinSchemas()).filter((name) => name.startsWith('slack-') && name.endsWith('-write') && !name.endsWith('-all'));
1706
+ expect(readPermissions.length).toBeGreaterThan(5);
1707
+ expect(writePermissions.length).toBeGreaterThan(5);
1708
+ const probes = [
1709
+ ...Object.keys(slackReadPermissionsByMethod),
1710
+ ...Object.keys(slackWritePermissionsByMethod),
1711
+ '/api/chat.postMessage',
1712
+ '/api/conversations.history',
1713
+ '/api/users.info',
1714
+ '/api/files.delete',
1715
+ '/api/pins.add',
1716
+ '/api/bookmarks.list',
1717
+ '/api/auth.revoke',
1718
+ '/api/channels.delete',
1719
+ '/api/users.admin.invite',
1720
+ '/api/unknown.method',
1721
+ '/not-an-api-path',
1722
+ ].map((path) => makeSlackRequest({ path }));
1723
+ probes.push(makeRequest({ domain: 'files.slack.com', path: '/files-pri/T1-F1/image.png' }), makeRequest({ domain: 'edgeapi.slack.com', path: '/cache/T1/users/search' }), makeRequest({ domain: 'edgeapi.slack.com', path: '/cache/T1/channels/membership' }), makeRequest({ domain: 'edgeapi.slack.com', path: '/cache/T1/unknown/thing' }));
1724
+ for (const request of probes) {
1725
+ const matchedByReadCluster = readPermissions.some((name) => builtinRegistry.get(name).match(request));
1726
+ const matchedByWriteCluster = writePermissions.some((name) => builtinRegistry.get(name).match(request));
1727
+ const label = `${request.domain}${request.path}`;
1728
+ expect(builtinRegistry.get('slack-read-all').match(request), `slack-read-all drifted from its clusters for "${label}"`).toBe(matchedByReadCluster);
1729
+ expect(builtinRegistry.get('slack-write-all').match(request), `slack-write-all drifted from its clusters for "${label}"`).toBe(matchedByWriteCluster);
1730
+ expect(matchedByReadCluster && matchedByWriteCluster, `"${label}" is matched by both a read and a write cluster`).toBe(false);
1731
+ }
1732
+ });
1733
+ it('destructive admin methods are not covered by any slack permission', () => {
1734
+ const slackPermissions = Object.keys(getAllBuiltinSchemas()).filter((name) => name.startsWith('slack-') && name !== 'slack-api');
1735
+ for (const path of [
1736
+ '/api/channels.delete',
1737
+ '/api/conversations.delete',
1738
+ '/api/users.admin.invite',
1739
+ '/api/users.admin.setInactive',
1740
+ ]) {
1741
+ for (const name of slackPermissions) {
1742
+ expect(builtinRegistry.get(name).match(makeSlackRequest({ path })), `Expected ${name} to reject "${path}"`).toBe(false);
1743
+ }
1744
+ }
1745
+ });
1746
+ it('slack-later-read and slack-later-write are supersets of the reminders permissions', () => {
1747
+ expectSchemaExists('slack-later-read');
1748
+ expectSchemaExists('slack-later-write');
1749
+ for (const path of ['/api/reminders.info', '/api/reminders.list', '/api/saved.list']) {
1750
+ expect(builtinRegistry.get('slack-later-read').match(makeSlackRequest({ path }))).toBe(true);
1751
+ expect(builtinRegistry.get('slack-later-write').match(makeSlackRequest({ path }))).toBe(false);
1752
+ }
1753
+ for (const path of ['/api/reminders.add', '/api/saved.add', '/api/saved.update']) {
1754
+ expect(builtinRegistry.get('slack-later-write').match(makeSlackRequest({ path }))).toBe(true);
1755
+ expect(builtinRegistry.get('slack-later-read').match(makeSlackRequest({ path }))).toBe(false);
1756
+ }
1757
+ expect(builtinRegistry
1758
+ .get('slack-reminders-read')
1759
+ .match(makeSlackRequest({ path: '/api/saved.list' }))).toBe(false);
1760
+ expect(builtinRegistry
1761
+ .get('slack-reminders-write')
1762
+ .match(makeSlackRequest({ path: '/api/saved.add' }))).toBe(false);
1763
+ });
1764
+ it('slack permissions accept workspace subdomains as API hosts', () => {
1765
+ for (const domain of ['slack.com', 'my-team.slack.com', 'my-team.enterprise.slack.com']) {
1766
+ expect(builtinRegistry.get('slack-api').match(makeRequest({ domain }))).toBe(true);
1767
+ expect(builtinRegistry
1768
+ .get('slack-conversations-read')
1769
+ .match(makeRequest({ domain, path: '/api/conversations.history' })), `Expected slack-conversations-read to match on ${domain}`).toBe(true);
1770
+ expect(builtinRegistry
1771
+ .get('slack-chat-write')
1772
+ .match(makeRequest({ domain, path: '/api/chat.postMessage' })), `Expected slack-chat-write to match on ${domain}`).toBe(true);
1773
+ }
1774
+ for (const domain of ['slack.com.example.com', 'notslack.com', 'slack.company.com']) {
1775
+ expect(builtinRegistry.get('slack-api').match(makeRequest({ domain }))).toBe(false);
1776
+ expect(builtinRegistry
1777
+ .get('slack-read-all')
1778
+ .match(makeRequest({ domain, path: '/api/conversations.history' }))).toBe(false);
1779
+ }
1780
+ });
1781
+ it('API methods are not accepted on the file-storage or edge hosts', () => {
1782
+ for (const domain of ['files.slack.com', 'edgeapi.slack.com']) {
1783
+ expect(builtinRegistry
1784
+ .get('slack-read-all')
1785
+ .match(makeRequest({ domain, path: '/api/conversations.history' }))).toBe(false);
1786
+ expect(builtinRegistry
1787
+ .get('slack-write-all')
1788
+ .match(makeRequest({ domain, path: '/api/chat.postMessage' }))).toBe(false);
1789
+ }
1790
+ });
1791
+ it('edge cache lookups are covered by the matching read clusters', () => {
1792
+ const edgePermissionsByPath = {
1793
+ '/cache/T0123/users/info': 'slack-users-read',
1794
+ '/cache/T0123/users/list': 'slack-users-read',
1795
+ '/cache/T0123/users/search': 'slack-users-read',
1796
+ '/cache/T0123/users/counts': 'slack-users-read',
1797
+ '/cache/E0123/channels/info': 'slack-conversations-read',
1798
+ '/cache/E0123/channels/search': 'slack-conversations-read',
1799
+ '/cache/E0123/channels/membership': 'slack-conversations-read',
1800
+ '/cache/E0123/huddles/info': 'slack-conversations-read',
1801
+ '/cache/E0123/emojis/info': 'slack-reactions-read',
1802
+ '/cache/E0123/permissions/info': 'slack-auth-read',
1803
+ };
1804
+ for (const [path, permission] of Object.entries(edgePermissionsByPath)) {
1805
+ const request = makeRequest({ domain: 'edgeapi.slack.com', path });
1806
+ expect(builtinRegistry.get('slack-api').match(request)).toBe(true);
1807
+ expect(builtinRegistry.get(permission).match(request), `Expected ${permission} to match "${path}" on edgeapi.slack.com`).toBe(true);
1808
+ expect(builtinRegistry.get('slack-read-all').match(request)).toBe(true);
1809
+ expect(builtinRegistry.get('slack-write-all').match(request)).toBe(false);
1810
+ expect(builtinRegistry.get(permission).match(makeSlackRequest({ path })), `Expected ${permission} to reject "${path}" on slack.com`).toBe(false);
1811
+ }
1812
+ expect(builtinRegistry
1813
+ .get('slack-read-all')
1814
+ .match(makeRequest({ domain: 'edgeapi.slack.com', path: '/cache/E0123/users/delete' }))).toBe(false);
1815
+ });
1620
1816
  });
1621
1817
  describe('builtin schemas: stripe', () => {
1622
1818
  it('stripe scope matches api.stripe.com', () => {