@kabmo-labs/kabmo 0.11.1 → 0.12.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.
- package/README.md +67 -421
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +426 -413
- package/dist/client/static/js/{index-amss8pge.js → index-0smc9gm2.js} +1123 -747
- package/dist/client/static/js/index-shexbk5f.css +1 -0
- package/marketplace/marketplace.json +13 -3
- package/marketplace/plugins/command-runner/package.json +4 -2
- package/marketplace/plugins/git-forge/README.md +219 -0
- package/marketplace/plugins/git-forge/icon.svg +20 -0
- package/marketplace/plugins/git-forge/package.json +56 -0
- package/marketplace/plugins/git-forge/src/app.tsx +82 -0
- package/marketplace/plugins/git-forge/src/command.test.ts +181 -0
- package/marketplace/plugins/git-forge/src/command.ts +119 -0
- package/marketplace/plugins/git-forge/src/header.tsx +87 -0
- package/marketplace/plugins/git-forge/src/panel/Badge.tsx +76 -0
- package/marketplace/plugins/git-forge/src/panel/Change.tsx +150 -0
- package/marketplace/plugins/git-forge/src/panel/CiBadge.tsx +51 -0
- package/marketplace/plugins/git-forge/src/panel/Credential.tsx +107 -0
- package/marketplace/plugins/git-forge/src/panel/Glyph.tsx +70 -0
- package/marketplace/plugins/git-forge/src/panel/Header.tsx +255 -0
- package/marketplace/plugins/git-forge/src/panel/ItemView.tsx +198 -0
- package/marketplace/plugins/git-forge/src/panel/List.tsx +89 -0
- package/marketplace/plugins/git-forge/src/panel/Row.tsx +68 -0
- package/marketplace/plugins/git-forge/src/panel/Sidebar.tsx +94 -0
- package/marketplace/plugins/git-forge/src/panel/Write.tsx +236 -0
- package/marketplace/plugins/git-forge/src/panel/format.ts +78 -0
- package/marketplace/plugins/git-forge/src/panel/index.test.tsx +344 -0
- package/marketplace/plugins/git-forge/src/panel/index.tsx +193 -0
- package/marketplace/plugins/git-forge/src/panel/use-forge.ts +250 -0
- package/marketplace/plugins/git-forge/src/panel/write.test.tsx +269 -0
- package/marketplace/plugins/git-forge/src/protocol.ts +308 -0
- package/marketplace/plugins/git-forge/src/server/adapters.test.ts +274 -0
- package/marketplace/plugins/git-forge/src/server/bitbucket.ts +307 -0
- package/marketplace/plugins/git-forge/src/server/capabilities.test.ts +116 -0
- package/marketplace/plugins/git-forge/src/server/capabilities.ts +105 -0
- package/marketplace/plugins/git-forge/src/server/ci.test.ts +88 -0
- package/marketplace/plugins/git-forge/src/server/ci.ts +118 -0
- package/marketplace/plugins/git-forge/src/server/context.ts +76 -0
- package/marketplace/plugins/git-forge/src/server/diff.test.ts +127 -0
- package/marketplace/plugins/git-forge/src/server/diff.ts +120 -0
- package/marketplace/plugins/git-forge/src/server/filters.test.ts +138 -0
- package/marketplace/plugins/git-forge/src/server/filters.ts +138 -0
- package/marketplace/plugins/git-forge/src/server/forges.test.ts +235 -0
- package/marketplace/plugins/git-forge/src/server/gitea.ts +296 -0
- package/marketplace/plugins/git-forge/src/server/github-extras.ts +92 -0
- package/marketplace/plugins/git-forge/src/server/github.ts +320 -0
- package/marketplace/plugins/git-forge/src/server/gitlab-detail.ts +207 -0
- package/marketplace/plugins/git-forge/src/server/gitlab.test.ts +195 -0
- package/marketplace/plugins/git-forge/src/server/gitlab.ts +176 -0
- package/marketplace/plugins/git-forge/src/server/http.test.ts +270 -0
- package/marketplace/plugins/git-forge/src/server/http.ts +329 -0
- package/marketplace/plugins/git-forge/src/server/map.ts +120 -0
- package/marketplace/plugins/git-forge/src/server/registry.ts +47 -0
- package/marketplace/plugins/git-forge/src/server/remote.test.ts +146 -0
- package/marketplace/plugins/git-forge/src/server/remote.ts +188 -0
- package/marketplace/plugins/git-forge/src/server/scope-probe.test.ts +98 -0
- package/marketplace/plugins/git-forge/src/server/scope-probe.ts +128 -0
- package/marketplace/plugins/git-forge/src/server/scope.ts +66 -0
- package/marketplace/plugins/git-forge/src/server/test-context.ts +67 -0
- package/marketplace/plugins/git-forge/src/server/test-host.ts +51 -0
- package/marketplace/plugins/git-forge/src/server/token.test.ts +107 -0
- package/marketplace/plugins/git-forge/src/server/token.ts +139 -0
- package/marketplace/plugins/git-forge/src/server/write-http.test.ts +127 -0
- package/marketplace/plugins/git-forge/src/server/write-http.ts +110 -0
- package/marketplace/plugins/git-forge/src/server/writes.test.ts +218 -0
- package/marketplace/plugins/git-forge/src/server/writes.ts +313 -0
- package/marketplace/plugins/git-forge/src/server.ts +284 -0
- package/marketplace/plugins/git-forge/tsconfig.json +16 -0
- package/marketplace/plugins/session-info/package.json +4 -2
- package/marketplace/plugins/stats/package.json +4 -2
- package/package.json +6 -1
- package/src/client/components/common/code-surface/blame-hover.ts +188 -0
- package/src/client/components/common/code-surface/blame-panel.test.ts +304 -0
- package/src/client/components/common/code-surface/blame-panel.ts +306 -0
- package/src/client/components/common/code-surface/blame.test.ts +303 -0
- package/src/client/components/common/code-surface/blame.ts +227 -0
- package/src/client/components/common/code-surface/conflict-markers.test.ts +135 -0
- package/src/client/components/common/code-surface/conflict-markers.ts +144 -0
- package/src/client/components/common/code-surface/documents.ts +48 -1
- package/src/client/components/common/code-surface/extensions.test.ts +4 -0
- package/src/client/components/common/code-surface/extensions.ts +44 -0
- package/src/client/components/common/code-surface/fold-stack.test.ts +4 -0
- package/src/client/components/common/code-surface/indent.test.ts +5 -0
- package/src/client/components/common/code-surface/index.tsx +16 -2
- package/src/client/components/common/code-surface/lint-parsers.test.ts +109 -0
- package/src/client/components/common/code-surface/lint-parsers.ts +134 -0
- package/src/client/components/common/code-surface/lint.test.ts +101 -0
- package/src/client/components/common/code-surface/lint.ts +85 -0
- package/src/client/components/common/code-surface/props.ts +17 -0
- package/src/client/components/common/code-surface/surface-failures.test.ts +132 -0
- package/src/client/components/common/code-surface/theme.ts +71 -0
- package/src/client/components/common/header-controls/index.test.tsx +1 -1
- package/src/client/components/common/header-controls/plugin-entry.test.tsx +1 -1
- package/src/client/components/common/header-controls/shell-chrome.test.tsx +1 -1
- package/src/client/components/common/provider-icon/Plate.tsx +88 -0
- package/src/client/components/common/provider-icon/index.tsx +55 -11
- package/src/client/components/layout/session-sidebar/SessionsView.tsx +5 -2
- package/src/client/components/mobile/SessionSidebar.tsx +2 -10
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +6 -0
- package/src/client/components/mobile/mobile-right-sidebar/StatusBar.tsx +8 -0
- package/src/client/components/settings/categories/AppearanceSettings.tsx +3 -0
- package/src/client/components/settings/categories/ProviderSettings.tsx +43 -41
- package/src/client/components/settings/categories/appearance-settings/EditorBlameSection.tsx +97 -0
- package/src/client/components/settings/categories/panel-plugins/AvailableList.tsx +106 -54
- package/src/client/components/settings/categories/panel-plugins/GitFreshness.tsx +14 -1
- package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +39 -150
- package/src/client/components/settings/categories/panel-plugins/Meta.test.tsx +143 -0
- package/src/client/components/settings/categories/panel-plugins/Meta.tsx +157 -0
- package/src/client/components/settings/categories/panel-plugins/Placement.test.tsx +149 -0
- package/src/client/components/settings/categories/panel-plugins/Placement.tsx +99 -0
- package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +270 -0
- package/src/client/components/settings/categories/panel-plugins/Section.tsx +11 -3
- package/src/client/components/settings/categories/provider-settings/AddModelModal.tsx +25 -0
- package/src/client/components/settings/categories/provider-settings/AuthSection.tsx +135 -80
- package/src/client/components/settings/categories/provider-settings/DeleteProviderModal.tsx +51 -21
- package/src/client/components/settings/categories/provider-settings/EntryAdvanced.tsx +175 -0
- package/src/client/components/settings/categories/provider-settings/EntryModal.tsx +275 -0
- package/src/client/components/settings/categories/provider-settings/Header.tsx +40 -9
- package/src/client/components/settings/categories/provider-settings/LoginModal.tsx +142 -160
- package/src/client/components/settings/categories/provider-settings/LogoutProviderModal.tsx +2 -2
- package/src/client/components/settings/categories/provider-settings/ModelCapabilitiesModal.tsx +84 -46
- package/src/client/components/settings/categories/provider-settings/ModelsList.tsx +217 -102
- package/src/client/components/settings/categories/provider-settings/PresetPicker.tsx +5 -2
- package/src/client/components/settings/categories/provider-settings/SidebarList.plugin.test.ts +3 -3
- package/src/client/components/settings/categories/provider-settings/SidebarList.tsx +158 -102
- package/src/client/components/settings/categories/provider-settings/auth-section.test.tsx +135 -0
- package/src/client/components/settings/categories/provider-settings/groups.test.ts +98 -0
- package/src/client/components/settings/categories/provider-settings/groups.ts +108 -0
- package/src/client/components/settings/categories/provider-settings/layout.test.tsx +325 -0
- package/src/client/components/settings/categories/provider-settings/model-dialogs.test.tsx +135 -0
- package/src/client/components/settings/categories/provider-settings/preset-picker.test.tsx +73 -0
- package/src/client/components/settings/categories/usage-settings/ProviderCard.tsx +22 -2
- package/src/client/components/settings/categories/usage-settings/ProviderDetail.tsx +2 -0
- package/src/client/components/settings/categories/usage-settings/SidebarList.tsx +16 -6
- package/src/client/components/settings/categories/usage-settings/providers.ts +3 -0
- package/src/client/components/settings/categories/usage-settings/usage-and-picker.test.ts +19 -0
- package/src/client/components/settings/categories/usage-settings/usage-icons.test.tsx +143 -0
- package/src/client/components/workspace/chat-timeline/MinimapShortcuts.test.ts +2 -1
- package/src/client/components/workspace/chat-timeline/chat-input/GoalBanner.test.ts +23 -19
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.test.ts +23 -19
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +20 -18
- package/src/client/components/workspace/chat-timeline/chat-input/compact.test.tsx +19 -6
- package/src/client/components/workspace/chat-timeline/index.tsx +7 -16
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.missing.test.ts +100 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +3 -47
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +8 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/wait-test-util.ts +62 -0
- package/src/client/components/workspace/diff-panel/HunkStepper.tsx +62 -0
- package/src/client/components/workspace/diff-panel/MergeDiffView.tsx +29 -0
- package/src/client/components/workspace/diff-panel/Toolbar.tsx +32 -1
- package/src/client/components/workspace/diff-panel/changes.ts +69 -0
- package/src/client/components/workspace/diff-panel/chunks.ts +85 -0
- package/src/client/components/workspace/diff-panel/index.tsx +21 -1
- package/src/client/components/workspace/diff-panel/merge.test.ts +145 -0
- package/src/client/components/workspace/diff-panel/merge.ts +63 -68
- package/src/client/components/workspace/editor/EditorDropOverlay.tsx +6 -1
- package/src/client/components/workspace/editor/FileDocument.tsx +51 -1
- package/src/client/components/workspace/editor/FilePane.tsx +25 -1
- package/src/client/components/workspace/editor/StatusBar.tsx +19 -0
- package/src/client/components/workspace/editor/Toolbar.tsx +29 -5
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +86 -0
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +48 -16
- package/src/client/components/workspace/editor/viewers/bytes.ts +16 -0
- package/src/client/components/workspace/git-panel/index.test.ts +46 -1
- package/src/client/components/workspace/git-panel/index.tsx +11 -38
- package/src/client/components/workspace/model-dropdown/Item.plugin.test.ts +66 -0
- package/src/client/components/workspace/model-dropdown/Item.tsx +71 -62
- package/src/client/components/workspace/model-dropdown/Section.tsx +31 -14
- package/src/client/components/workspace/model-dropdown/collapsed.ts +72 -0
- package/src/client/components/workspace/model-dropdown/index.tsx +42 -19
- package/src/client/components/workspace/model-dropdown/refresh.test.tsx +260 -0
- package/src/client/components/workspace/model-dropdown/trigger.test.ts +34 -0
- package/src/client/components/workspace/model-dropdown/use-catalog.ts +13 -2
- package/src/client/components/workspace/usage-panel/ProviderSelect.tsx +19 -3
- package/src/client/hooks/chat/omp/folder-auto-expand.ts +113 -0
- package/src/client/hooks/chat/omp/index.ts +20 -0
- package/src/client/hooks/chat/omp/pending-rows.ts +21 -0
- package/src/client/hooks/chat/omp/pending-sessions.test.ts +16 -1
- package/src/client/hooks/chat/omp/session-sidebar-controller.test.ts +102 -0
- package/src/client/hooks/chat/omp/session-sidebar-controller.ts +21 -1
- package/src/client/hooks/chat/omp/stream.ts +8 -1
- package/src/client/hooks/chat/timeline/index.ts +1 -1
- package/src/client/hooks/chat/timeline/new-chat-open.ts +60 -0
- package/src/client/hooks/editor/blame-settings.ts +67 -0
- package/src/client/hooks/editor/blame.test.ts +272 -0
- package/src/client/hooks/editor/blame.ts +232 -0
- package/src/client/hooks/editor/file-editor-types.ts +23 -0
- package/src/client/hooks/editor/save-file.test.ts +20 -0
- package/src/client/hooks/editor/use-editor-drop.test-util.ts +198 -0
- package/src/client/hooks/editor/use-editor-drop.test.ts +70 -175
- package/src/client/hooks/editor/use-editor-drop.ts +19 -36
- package/src/client/hooks/editor/use-file-editor.ts +7 -1
- package/src/client/hooks/settings/providers/actions.ts +90 -194
- package/src/client/hooks/settings/providers/api.ts +7 -1
- package/src/client/hooks/settings/providers/index.ts +171 -59
- package/src/client/hooks/settings/providers/login.test.ts +79 -0
- package/src/client/hooks/settings/providers/login.ts +276 -0
- package/src/client/hooks/settings/providers/messages.ts +28 -0
- package/src/client/hooks/settings/providers/model-actions.ts +178 -0
- package/src/client/hooks/ui/editor-error-toast.ts +47 -0
- package/src/client/hooks/ui/open-file.ts +7 -0
- package/src/client/hooks/ui/toasts.ts +7 -0
- package/src/client/hooks/workspace/file-tabs.ts +4 -1
- package/src/client/hooks/workspace/folder-expansion.test.ts +62 -0
- package/src/client/hooks/workspace/folder-expansion.ts +33 -0
- package/src/client/hooks/workspace/git-action-outcome.ts +86 -0
- package/src/client/hooks/workspace/git-actions.ts +29 -2
- package/src/client/hooks/workspace/plugin-contributions.test.ts +117 -0
- package/src/client/hooks/workspace/plugin-contributions.ts +146 -0
- package/src/client/lib/editor-errors.test.ts +85 -0
- package/src/client/lib/editor-errors.ts +71 -0
- package/src/client/lib/fs/resolve-open.test.ts +125 -0
- package/src/client/lib/fs/resolve-open.ts +90 -0
- package/src/client/lib/git/action-message.test.ts +82 -0
- package/src/client/lib/git/action-message.ts +160 -0
- package/src/client/lib/launch/device-files.test.ts +160 -0
- package/src/client/lib/launch/device-files.ts +197 -0
- package/src/client/lib/native/open-paths.test.ts +140 -0
- package/src/client/lib/native/open-paths.ts +157 -0
- package/src/client/lib/plugins/bootstrap.test.ts +1 -1
- package/src/client/main.tsx +20 -0
- package/src/server/db.server.test.ts +39 -0
- package/src/server/db.server.ts +21 -2
- package/src/server/lib/db/schema.ts +2 -0
- package/src/server/lib/fs/external-roots.test.ts +100 -0
- package/src/server/lib/fs/external-roots.ts +101 -0
- package/src/server/lib/fs/git-actions-branch.ts +15 -2
- package/src/server/lib/fs/git-actions-shared.ts +24 -0
- package/src/server/lib/fs/git-actions-sync.test.ts +18 -7
- package/src/server/lib/fs/git-actions-worktree.ts +5 -1
- package/src/server/lib/fs/git-blame.test.ts +206 -0
- package/src/server/lib/fs/git-blame.ts +189 -0
- package/src/server/lib/fs/root.ts +14 -0
- package/src/server/lib/http/same-origin.ts +28 -7
- package/src/server/lib/models/catalog.server.ts +230 -0
- package/src/server/lib/models/catalog.test.ts +83 -0
- package/src/server/lib/models/credential-origin.server.ts +108 -0
- package/src/server/lib/models/credential-origin.test.ts +132 -0
- package/src/server/lib/models/provider-icon-fetch.ts +115 -0
- package/src/server/lib/models/provider-icon-parse.test.ts +134 -0
- package/src/server/lib/models/provider-icon-parse.ts +139 -0
- package/src/server/lib/models/provider-icon-store.server.ts +118 -0
- package/src/server/lib/models/provider-icon-store.test.ts +107 -0
- package/src/server/lib/models/provider-icon.server.ts +209 -0
- package/src/server/lib/models/provider-items.server.ts +211 -37
- package/src/server/lib/models/provider-items.test.ts +201 -0
- package/src/server/lib/models/provider-registry.server.test.ts +27 -9
- package/src/server/lib/models/provider-registry.server.ts +160 -67
- package/src/server/lib/models/registry.server.test.ts +3 -3
- package/src/server/lib/models/registry.server.ts +8 -0
- package/src/server/lib/omp/config/definitions.test.ts +5 -4
- package/src/server/lib/omp/config/models-config.ts +42 -0
- package/src/server/lib/omp/config/provider-entry.test.ts +205 -0
- package/src/server/lib/omp/config/provider-entry.ts +197 -0
- package/src/server/lib/omp/config/provider-seeds.ts +10 -0
- package/src/server/lib/omp/core/models-json.ts +69 -0
- package/src/server/lib/omp/session/messages.ts +17 -3
- package/src/server/lib/omp/session/sidebar-data.canonical.test.ts +13 -3
- package/src/server/lib/panels/bundled-catalog.server.ts +7 -0
- package/src/server/lib/panels/catalog-offers.server.ts +68 -0
- package/src/server/lib/panels/git-update.server.test.ts +14 -0
- package/src/server/lib/panels/git-update.server.ts +63 -1
- package/src/server/lib/panels/manifest.test.ts +65 -0
- package/src/server/lib/panels/manifest.ts +55 -1
- package/src/server/lib/panels/offers.server.test.ts +191 -0
- package/src/server/lib/panels/offers.server.ts +108 -0
- package/src/server/lib/panels/registry.server.test.ts +35 -1
- package/src/server/lib/panels/registry.server.ts +51 -142
- package/src/server/lib/panels/scan.server.ts +162 -0
- package/src/server/lib/route-adapter.ts +13 -2
- package/src/server/lib/tray/tray.test.ts +2 -1
- package/src/server/lib/usage/providers.server.ts +4 -1
- package/src/server/routes/chat/session.ts +7 -1
- package/src/server/routes/fs/git-blame-loader.test.ts +146 -0
- package/src/server/routes/fs/git.ts +17 -0
- package/src/server/routes/fs/grant.test.ts +135 -0
- package/src/server/routes/fs/grant.ts +79 -0
- package/src/server/routes/fs/index.ts +2 -0
- package/src/server/routes/fs/scope.ts +34 -17
- package/src/server/routes/omp/login.ts +41 -14
- package/src/server/routes/omp/routes.test.ts +23 -10
- package/src/server/routes/settings/index.ts +8 -0
- package/src/server/routes/settings/provider-entry.ts +108 -0
- package/src/server/routes/settings/provider-icon.ts +99 -0
- package/src/server/routes/settings/provider-model.ts +4 -1
- package/src/server/routes/settings/provider-refresh.ts +87 -0
- package/src/server/routes/settings/providers.ts +31 -2
- package/src/shared/lib/chat/omp/fold.test.ts +34 -0
- package/src/shared/lib/chat/omp/tool-frames.test.ts +20 -0
- package/src/shared/lib/chat/omp/tool-frames.ts +5 -1
- package/src/shared/lib/chat/omp/tool-results.ts +29 -3
- package/src/shared/lib/chat/tool/wait-facts.ts +4 -0
- package/src/shared/lib/fs/git-blame.test.ts +266 -0
- package/src/shared/lib/fs/git-blame.ts +246 -0
- package/src/shared/lib/git/url.ts +18 -0
- package/src/shared/lib/markdown/sanitize.test.ts +57 -0
- package/src/shared/lib/markdown/sanitize.ts +30 -7
- package/src/shared/lib/models/provider/connection.ts +135 -0
- package/src/shared/lib/models/provider/dialect.test.ts +4 -2
- package/src/shared/lib/models/provider/dialect.ts +76 -6
- package/src/shared/lib/models/provider/models.ts +2 -0
- package/src/shared/lib/models/provider/origin.ts +94 -0
- package/src/shared/lib/models/provider/provider-ui.test.ts +7 -0
- package/src/shared/lib/models/server-cache.ts +8 -3
- package/src/shared/lib/omp/session/messages-map-pending.test.ts +110 -0
- package/src/shared/lib/omp/session/messages-map.ts +34 -2
- package/src/shared/lib/omp/session/prewarm-misc.test.ts +7 -90
- package/src/shared/lib/omp/session/prewarm.test.ts +133 -0
- package/src/shared/lib/omp/session/prewarm.ts +23 -1
- package/src/shared/lib/omp/session/wait.test.ts +28 -0
- package/src/shared/lib/omp/session/wait.ts +38 -3
- package/src/shared/lib/panels/slot-labels.test.ts +61 -0
- package/src/shared/lib/panels/slot-labels.ts +133 -0
- package/src/shared/lib/workspace/panel-ids.ts +11 -0
- package/src/shared/types/fs.ts +6 -0
- package/src/shared/types/index.ts +1 -0
- package/src/shared/types/models.ts +12 -0
- package/src/shared/types/panels-registry.ts +277 -0
- package/src/shared/types/panels.ts +46 -213
- package/src/shared/types/settings/provider.ts +58 -0
- package/src/shared/types/settings/usage.ts +10 -0
- package/src/test-support/pristine-globals.ts +7 -0
- package/dist/client/static/js/index-bq6qeayr.css +0 -1
- package/src/client/components/settings/categories/provider-settings/ReconnectModal.tsx +0 -184
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Picking a provider's icon URL from its own page.
|
|
8
|
+
*
|
|
9
|
+
* Every case here is a way the row shows the wrong picture: the root ICO
|
|
10
|
+
* instead of the declared 192px logo, Safari's monochrome `mask-icon` painted as
|
|
11
|
+
* a blob, or `https://host/v1/favicon.ico` — a 404 on nearly every gateway.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { describe, expect, test } from 'bun:test';
|
|
15
|
+
import {
|
|
16
|
+
looksLikeSvg,
|
|
17
|
+
pickIconHrefs,
|
|
18
|
+
providerOrigin,
|
|
19
|
+
readLinkTags,
|
|
20
|
+
} from '@/server/lib/models/provider-icon-parse';
|
|
21
|
+
|
|
22
|
+
const ORIGIN = 'https://kenari.id';
|
|
23
|
+
|
|
24
|
+
describe('providerOrigin', () => {
|
|
25
|
+
test('drops the path, because baseUrl usually ends in /v1', () => {
|
|
26
|
+
expect(providerOrigin('https://kenari.id/v1')).toBe(ORIGIN);
|
|
27
|
+
expect(providerOrigin('https://kenari.id/v1/')).toBe(ORIGIN);
|
|
28
|
+
expect(providerOrigin('http://localhost:11434/v1')).toBe('http://localhost:11434');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('a bare host gets https', () => {
|
|
32
|
+
expect(providerOrigin('kenari.id')).toBe(ORIGIN);
|
|
33
|
+
expect(providerOrigin('kenari.id/v1')).toBe(ORIGIN);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('anything without a site has no origin', () => {
|
|
37
|
+
expect(providerOrigin(undefined)).toBeNull();
|
|
38
|
+
expect(providerOrigin('')).toBeNull();
|
|
39
|
+
expect(providerOrigin(' ')).toBeNull();
|
|
40
|
+
expect(providerOrigin('/tmp/models')).toBeNull();
|
|
41
|
+
expect(providerOrigin('ftp://kenari.id')).toBeNull();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('readLinkTags', () => {
|
|
46
|
+
test('reads attributes in either quote style, case-insensitively', () => {
|
|
47
|
+
const tags = readLinkTags(`<link REL='icon' Href="/a.png"><link rel="icon" href=/b.png>`);
|
|
48
|
+
expect(tags).toEqual([
|
|
49
|
+
{ rel: 'icon', href: '/a.png' },
|
|
50
|
+
{ rel: 'icon', href: '/b.png' },
|
|
51
|
+
]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('ignores a link with no rel or no href', () => {
|
|
55
|
+
expect(readLinkTags('<link href="/a.png"><link rel="icon">')).toEqual([]);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('pickIconHrefs', () => {
|
|
60
|
+
test('an apple-touch-icon wins over a 16px icon', () => {
|
|
61
|
+
const html = `
|
|
62
|
+
<link rel="icon" href="/favicon-16.png" sizes="16x16">
|
|
63
|
+
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
|
|
64
|
+
`;
|
|
65
|
+
expect(pickIconHrefs(html, ORIGIN)).toEqual([
|
|
66
|
+
'https://kenari.id/apple-touch-icon.png',
|
|
67
|
+
'https://kenari.id/favicon-16.png',
|
|
68
|
+
]);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('a larger declared size beats a smaller one', () => {
|
|
72
|
+
const html = `
|
|
73
|
+
<link rel="icon" href="/small.png" sizes="32x32">
|
|
74
|
+
<link rel="icon" href="/large.png" sizes="192x192">
|
|
75
|
+
`;
|
|
76
|
+
expect(pickIconHrefs(html, ORIGIN)[0]).toBe('https://kenari.id/large.png');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('an SVG (`sizes="any"`) outranks a fixed size', () => {
|
|
80
|
+
const html = `
|
|
81
|
+
<link rel="icon" href="/icon.png" sizes="192x192">
|
|
82
|
+
<link rel="icon" href="/icon.svg" type="image/svg+xml" sizes="any">
|
|
83
|
+
`;
|
|
84
|
+
expect(pickIconHrefs(html, ORIGIN)[0]).toBe('https://kenari.id/icon.svg');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('mask-icon is skipped — it is a monochrome silhouette', () => {
|
|
88
|
+
const html = `
|
|
89
|
+
<link rel="mask-icon" href="/pinned.svg" color="#000">
|
|
90
|
+
<link rel="icon" href="/icon.png">
|
|
91
|
+
`;
|
|
92
|
+
expect(pickIconHrefs(html, ORIGIN)).toEqual(['https://kenari.id/icon.png']);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('relative, root-relative and absolute hrefs all resolve', () => {
|
|
96
|
+
const html = `
|
|
97
|
+
<link rel="icon" href="favicon.png">
|
|
98
|
+
<link rel="icon" href="/assets/icon.png">
|
|
99
|
+
<link rel="icon" href="https://cdn.example.com/icon.png">
|
|
100
|
+
`;
|
|
101
|
+
expect(pickIconHrefs(html, ORIGIN)).toEqual([
|
|
102
|
+
'https://kenari.id/favicon.png',
|
|
103
|
+
'https://kenari.id/assets/icon.png',
|
|
104
|
+
'https://cdn.example.com/icon.png',
|
|
105
|
+
]);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('a non-http href is not a candidate', () => {
|
|
109
|
+
const html = '<link rel="icon" href="data:image/png;base64,AAAA">';
|
|
110
|
+
expect(pickIconHrefs(html, ORIGIN)).toEqual([]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('duplicates collapse and the list is capped', () => {
|
|
114
|
+
const html = Array.from({ length: 8 }, (_, index) => (
|
|
115
|
+
`<link rel="icon" href="/i${index}.png" sizes="${index + 1}x${index + 1}">`
|
|
116
|
+
)).join('') + '<link rel="icon" href="/i7.png">';
|
|
117
|
+
const urls = pickIconHrefs(html, ORIGIN, 4);
|
|
118
|
+
expect(urls).toHaveLength(4);
|
|
119
|
+
expect(new Set(urls).size).toBe(4);
|
|
120
|
+
// Highest score first: 8x8, then 7x7, then 6x6, then 5x5.
|
|
121
|
+
expect(urls[0]).toBe('https://kenari.id/i7.png');
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('looksLikeSvg', () => {
|
|
126
|
+
test('recognises a document and one behind a prolog', () => {
|
|
127
|
+
expect(looksLikeSvg(new TextEncoder().encode('<svg xmlns="http://www.w3.org/2000/svg"/>'))).toBe(true);
|
|
128
|
+
expect(looksLikeSvg(new TextEncoder().encode('<?xml version="1.0"?>\n<svg/>'))).toBe(true);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('a PNG is not an SVG', () => {
|
|
132
|
+
expect(looksLikeSvg(new Uint8Array([0x89, 0x50, 0x4e, 0x47]))).toBe(false);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Reading a provider site's icon: which URL it declares, and whether the bytes
|
|
8
|
+
* are really a picture.
|
|
9
|
+
*
|
|
10
|
+
* The panel's marks are hand-drawn shapes for the providers omp ships. A
|
|
11
|
+
* `models.yml` entry has no such mark — nobody can draw a logo for a gateway the
|
|
12
|
+
* user registered yesterday — so every one of those rows fell back to initials.
|
|
13
|
+
* The endpoint's own host is the only identity that row has, and its favicon is
|
|
14
|
+
* the only logo available for it.
|
|
15
|
+
*
|
|
16
|
+
* These are the decisions that go wrong silently, so they live here as pure
|
|
17
|
+
* functions and are pinned by tests:
|
|
18
|
+
*
|
|
19
|
+
* - `/favicon.ico` is the LAST resort, not the first: a page that declares
|
|
20
|
+
* `<link rel="icon" sizes="192x192">` is offering a better picture than the
|
|
21
|
+
* 16px ICO at the root.
|
|
22
|
+
* - `mask-icon` is never used: it is a monochrome silhouette for Safari's pinned
|
|
23
|
+
* tabs, so painting it in a plate shows a solid blob.
|
|
24
|
+
* - a `baseUrl` of `https://host/v1` resolves against the ORIGIN, because
|
|
25
|
+
* `https://host/v1/favicon.ico` is a 404 on nearly every gateway.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/** The scheme+host a provider's endpoint lives on, or null when it has none. */
|
|
29
|
+
export function providerOrigin(baseUrl: string | undefined): string | null {
|
|
30
|
+
if (!baseUrl) return null;
|
|
31
|
+
const trimmed = baseUrl.trim();
|
|
32
|
+
if (!trimmed) return null;
|
|
33
|
+
let parsed: URL;
|
|
34
|
+
try {
|
|
35
|
+
parsed = new URL(trimmed);
|
|
36
|
+
} catch {
|
|
37
|
+
// A bare host (`kenari.id`) is a common hand-typed value; give it https.
|
|
38
|
+
if (!/^[\w.-]+\.[a-z]{2,}(:\d+)?(\/|$)/i.test(trimmed)) return null;
|
|
39
|
+
try {
|
|
40
|
+
parsed = new URL(`https://${trimmed}`);
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') return null;
|
|
46
|
+
return parsed.origin;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** One `<link>` tag's `rel`/`href`/`sizes`, as far as the markup states them. */
|
|
50
|
+
interface LinkTag {
|
|
51
|
+
rel: string;
|
|
52
|
+
href: string;
|
|
53
|
+
sizes?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const LINK_TAG_RE = /<link\b[^>]*>/gi;
|
|
57
|
+
const ATTR_RE = /([a-zA-Z:_-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/g;
|
|
58
|
+
|
|
59
|
+
/** Every `<link>` in a document, with its attributes lower-cased by name. */
|
|
60
|
+
export function readLinkTags(html: string): LinkTag[] {
|
|
61
|
+
const tags: LinkTag[] = [];
|
|
62
|
+
for (const match of html.matchAll(LINK_TAG_RE)) {
|
|
63
|
+
const attributes: Record<string, string> = {};
|
|
64
|
+
for (const attr of match[0].matchAll(ATTR_RE)) {
|
|
65
|
+
attributes[attr[1].toLowerCase()] = attr[2] ?? attr[3] ?? attr[4] ?? '';
|
|
66
|
+
}
|
|
67
|
+
const rel = attributes.rel?.toLowerCase().trim();
|
|
68
|
+
const href = attributes.href?.trim();
|
|
69
|
+
if (!rel || !href) continue;
|
|
70
|
+
tags.push({ rel, href, ...(attributes.sizes ? { sizes: attributes.sizes } : {}) });
|
|
71
|
+
}
|
|
72
|
+
return tags;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* How much one `<link>` is worth as a logo.
|
|
77
|
+
*
|
|
78
|
+
* Tiers rather than raw pixels: an SVG (`sizes="any"`) scales to any plate, an
|
|
79
|
+
* `apple-touch-icon` is a large PNG by convention, and among fixed sizes the
|
|
80
|
+
* bigger one wins. A pixel count alone ranked `any` BELOW `192x192`, which put
|
|
81
|
+
* the smaller raster ahead of a vector — measured: the rule returned
|
|
82
|
+
* `icon.png` for a page declaring both.
|
|
83
|
+
*/
|
|
84
|
+
function linkScore(rel: string, sizes: string | undefined): number {
|
|
85
|
+
const rels = rel.split(/\s+/);
|
|
86
|
+
const isApple = rels.includes('apple-touch-icon') || rels.includes('apple-touch-icon-precomposed');
|
|
87
|
+
if (!isApple && /any/i.test(sizes ?? '')) return 1000;
|
|
88
|
+
if (isApple) return 900;
|
|
89
|
+
let best = 0;
|
|
90
|
+
for (const part of (sizes ?? '').toLowerCase().split(/\s+/)) {
|
|
91
|
+
const match = /^(\d+)x(\d+)$/.exec(part);
|
|
92
|
+
if (match) best = Math.max(best, Number(match[1]));
|
|
93
|
+
}
|
|
94
|
+
// A declared size, however small, still beats a tag that states none.
|
|
95
|
+
return best > 0 ? 100 + Math.min(best, 512) : 50;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Candidate icon URLs, best first, resolved against `origin`.
|
|
100
|
+
*
|
|
101
|
+
* Ranking is by what the tag is worth: an `apple-touch-icon` is a large PNG by
|
|
102
|
+
* convention, a plain `icon` with a big `sizes` beats a small one, and an
|
|
103
|
+
* explicit size beats an unstated one.
|
|
104
|
+
*/
|
|
105
|
+
export function pickIconHrefs(html: string, origin: string, limit = 4): string[] {
|
|
106
|
+
const scored: Array<{ url: string; score: number }> = [];
|
|
107
|
+
for (const tag of readLinkTags(html)) {
|
|
108
|
+
const rels = tag.rel.split(/\s+/);
|
|
109
|
+
if (rels.includes('mask-icon')) continue;
|
|
110
|
+
const isApple = rels.includes('apple-touch-icon') || rels.includes('apple-touch-icon-precomposed');
|
|
111
|
+
const isIcon = rels.includes('icon');
|
|
112
|
+
if (!isApple && !isIcon) continue;
|
|
113
|
+
let url: string;
|
|
114
|
+
try {
|
|
115
|
+
url = new URL(tag.href, `${origin}/`).toString();
|
|
116
|
+
} catch {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (!url.startsWith('http://') && !url.startsWith('https://')) continue;
|
|
120
|
+
scored.push({ url, score: linkScore(tag.rel, tag.sizes) });
|
|
121
|
+
}
|
|
122
|
+
scored.sort((left, right) => right.score - left.score);
|
|
123
|
+
const seen = new Set<string>();
|
|
124
|
+
const urls: string[] = [];
|
|
125
|
+
for (const entry of scored) {
|
|
126
|
+
if (seen.has(entry.url)) continue;
|
|
127
|
+
seen.add(entry.url);
|
|
128
|
+
urls.push(entry.url);
|
|
129
|
+
}
|
|
130
|
+
return urls.slice(0, limit);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** True when the bytes are an SVG document (which no magic-byte table catches). */
|
|
134
|
+
export function looksLikeSvg(bytes: Uint8Array): boolean {
|
|
135
|
+
// Decode only the head: an SVG's first tag is within the first few hundred
|
|
136
|
+
// bytes even with a prolog and a long `<style>`.
|
|
137
|
+
const head = new TextDecoder().decode(bytes.subarray(0, 2048)).trimStart();
|
|
138
|
+
return head.startsWith('<svg') || (head.startsWith('<?xml') && head.includes('<svg'));
|
|
139
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Storing a provider's fetched web icon.
|
|
8
|
+
*
|
|
9
|
+
* The bytes live in Kabmo's database rather than in a temp directory or in the
|
|
10
|
+
* settings blob, for the reasons each of those fails:
|
|
11
|
+
*
|
|
12
|
+
* - **A temp file is lost** on a container restart, and the panel would refetch
|
|
13
|
+
* every icon from a third party each time.
|
|
14
|
+
* - **The settings blob is written by the modal** (`app_settings`), so an icon
|
|
15
|
+
* write would race a settings save for one row and one of them would lose.
|
|
16
|
+
* - **A data URL in the provider payload** would put ~10-50 KB per provider into
|
|
17
|
+
* `GET /api/settings/providers` on every load, for a list of ~100 — that
|
|
18
|
+
* payload is the panel's first paint. The bytes are served by
|
|
19
|
+
* `GET /api/provider-icon` instead, and the item carries only a URL.
|
|
20
|
+
*
|
|
21
|
+
* A MISS is stored too (`status = 'missing'`): a private gateway, a host behind
|
|
22
|
+
* auth and a site with no favicon all look the same from here, and without a
|
|
23
|
+
* negative row every panel load would retry a 4s timeout per provider.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import type { DbClient } from '@/server/lib/db/client';
|
|
27
|
+
|
|
28
|
+
const PROVIDER_ICON_SCHEMA_SQL = `
|
|
29
|
+
CREATE TABLE IF NOT EXISTS provider_icons (
|
|
30
|
+
slug TEXT PRIMARY KEY,
|
|
31
|
+
status TEXT NOT NULL,
|
|
32
|
+
mime TEXT,
|
|
33
|
+
bytes BLOB,
|
|
34
|
+
source TEXT,
|
|
35
|
+
error TEXT,
|
|
36
|
+
fetched_at INTEGER NOT NULL
|
|
37
|
+
);
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
/** Idempotent: the provider-icon table, created on every database open. */
|
|
41
|
+
export async function ensureProviderIconSchema(db: DbClient): Promise<void> {
|
|
42
|
+
await db.exec(PROVIDER_ICON_SCHEMA_SQL);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface StoredProviderIcon {
|
|
46
|
+
slug: string;
|
|
47
|
+
status: 'ok' | 'missing';
|
|
48
|
+
mime?: string;
|
|
49
|
+
bytes?: Uint8Array;
|
|
50
|
+
source?: string;
|
|
51
|
+
error?: string;
|
|
52
|
+
fetchedAt: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** One stored icon row, or null when this provider has never been fetched. */
|
|
56
|
+
export async function readProviderIcon(db: DbClient, slug: string): Promise<StoredProviderIcon | null> {
|
|
57
|
+
const row = await db.get<{
|
|
58
|
+
slug: string;
|
|
59
|
+
status: string;
|
|
60
|
+
mime: string | null;
|
|
61
|
+
bytes: Uint8Array | null;
|
|
62
|
+
source: string | null;
|
|
63
|
+
error: string | null;
|
|
64
|
+
fetched_at: number;
|
|
65
|
+
}>(
|
|
66
|
+
'SELECT slug, status, mime, bytes, source, error, fetched_at FROM provider_icons WHERE slug = ?',
|
|
67
|
+
[slug],
|
|
68
|
+
);
|
|
69
|
+
if (!row) return null;
|
|
70
|
+
return {
|
|
71
|
+
slug: row.slug,
|
|
72
|
+
status: row.status === 'ok' ? 'ok' : 'missing',
|
|
73
|
+
...(row.mime ? { mime: row.mime } : {}),
|
|
74
|
+
...(row.bytes ? { bytes: row.bytes } : {}),
|
|
75
|
+
...(row.source ? { source: row.source } : {}),
|
|
76
|
+
...(row.error ? { error: row.error } : {}),
|
|
77
|
+
fetchedAt: row.fetched_at,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Slug → status/fetch time for every stored icon. What the registry stamps. */
|
|
82
|
+
export async function readProviderIconStamps(
|
|
83
|
+
db: DbClient,
|
|
84
|
+
): Promise<Map<string, { status: 'ok' | 'missing'; fetchedAt: number }>> {
|
|
85
|
+
const rows = await db.all<{ slug: string; status: string; fetched_at: number }>(
|
|
86
|
+
'SELECT slug, status, fetched_at FROM provider_icons',
|
|
87
|
+
);
|
|
88
|
+
const stamps = new Map<string, { status: 'ok' | 'missing'; fetchedAt: number }>();
|
|
89
|
+
for (const row of rows) {
|
|
90
|
+
stamps.set(row.slug, {
|
|
91
|
+
status: row.status === 'ok' ? 'ok' : 'missing',
|
|
92
|
+
fetchedAt: row.fetched_at,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return stamps;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Write (or replace) one provider's icon row. */
|
|
99
|
+
export async function writeProviderIcon(db: DbClient, icon: StoredProviderIcon): Promise<void> {
|
|
100
|
+
await db.run(
|
|
101
|
+
`INSERT OR REPLACE INTO provider_icons (slug, status, mime, bytes, source, error, fetched_at)
|
|
102
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
|
103
|
+
[
|
|
104
|
+
icon.slug,
|
|
105
|
+
icon.status,
|
|
106
|
+
icon.mime ?? null,
|
|
107
|
+
icon.bytes ?? null,
|
|
108
|
+
icon.source ?? null,
|
|
109
|
+
icon.error ?? null,
|
|
110
|
+
icon.fetchedAt,
|
|
111
|
+
],
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Forget one provider's icon, so the next read refetches it. */
|
|
116
|
+
export async function deleteProviderIcon(db: DbClient, slug: string): Promise<void> {
|
|
117
|
+
await db.run('DELETE FROM provider_icons WHERE slug = ?', [slug]);
|
|
118
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The provider-icon table: one row per provider, the bytes of its site's icon.
|
|
8
|
+
*
|
|
9
|
+
* Isolated (`isolateDb`) because the handle is a process-wide singleton and the
|
|
10
|
+
* writes here are real — a suite that skipped this would put a fake provider's
|
|
11
|
+
* icon into the developer's own `~/.kabmo/db.sqlite`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
15
|
+
import { getDb } from '@/server/db.server';
|
|
16
|
+
import { isolateDb, releaseDb } from '@/test-support/isolated-db';
|
|
17
|
+
import {
|
|
18
|
+
deleteProviderIcon,
|
|
19
|
+
ensureProviderIconSchema,
|
|
20
|
+
readProviderIcon,
|
|
21
|
+
readProviderIconStamps,
|
|
22
|
+
writeProviderIcon,
|
|
23
|
+
} from '@/server/lib/models/provider-icon-store.server';
|
|
24
|
+
|
|
25
|
+
beforeEach(async () => {
|
|
26
|
+
await isolateDb();
|
|
27
|
+
await ensureProviderIconSchema(await getDb());
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
afterEach(async () => {
|
|
31
|
+
await releaseDb();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const PNG = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 1, 2, 3]);
|
|
35
|
+
|
|
36
|
+
describe('provider_icons', () => {
|
|
37
|
+
test('a stored icon round-trips its bytes, type and source', async () => {
|
|
38
|
+
const db = await getDb();
|
|
39
|
+
await writeProviderIcon(db, {
|
|
40
|
+
slug: 'kenari',
|
|
41
|
+
status: 'ok',
|
|
42
|
+
mime: 'image/png',
|
|
43
|
+
bytes: PNG,
|
|
44
|
+
source: 'https://kenari.id/apple-touch-icon.png',
|
|
45
|
+
fetchedAt: 1_700_000_000_000,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const stored = await readProviderIcon(db, 'kenari');
|
|
49
|
+
expect(stored?.status).toBe('ok');
|
|
50
|
+
expect(stored?.mime).toBe('image/png');
|
|
51
|
+
expect(stored?.source).toBe('https://kenari.id/apple-touch-icon.png');
|
|
52
|
+
expect(stored?.fetchedAt).toBe(1_700_000_000_000);
|
|
53
|
+
expect([...(stored?.bytes ?? [])]).toEqual([...PNG]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('a MISS is a row too, so the next load does not retry the host', async () => {
|
|
57
|
+
const db = await getDb();
|
|
58
|
+
await writeProviderIcon(db, {
|
|
59
|
+
slug: 'private-gateway',
|
|
60
|
+
status: 'missing',
|
|
61
|
+
error: 'no usable icon on the endpoint host',
|
|
62
|
+
fetchedAt: 1_700_000_000_000,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const stored = await readProviderIcon(db, 'private-gateway');
|
|
66
|
+
expect(stored?.status).toBe('missing');
|
|
67
|
+
expect(stored?.bytes).toBeUndefined();
|
|
68
|
+
expect(stored?.error).toContain('no usable icon');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('a rewrite replaces the row rather than accumulating one', async () => {
|
|
72
|
+
const db = await getDb();
|
|
73
|
+
const base = { slug: 'gateway', status: 'missing' as const, fetchedAt: 1 };
|
|
74
|
+
await writeProviderIcon(db, base);
|
|
75
|
+
await writeProviderIcon(db, {
|
|
76
|
+
slug: 'gateway',
|
|
77
|
+
status: 'ok',
|
|
78
|
+
mime: 'image/png',
|
|
79
|
+
bytes: PNG,
|
|
80
|
+
fetchedAt: 2,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
expect((await readProviderIconStamps(db)).size).toBe(1);
|
|
84
|
+
expect((await readProviderIcon(db, 'gateway'))?.status).toBe('ok');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('the stamps carry no bytes — that is the point of the split', async () => {
|
|
88
|
+
const db = await getDb();
|
|
89
|
+
await writeProviderIcon(db, {
|
|
90
|
+
slug: 'kenari', status: 'ok', mime: 'image/png', bytes: PNG, fetchedAt: 42,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const stamps = await readProviderIconStamps(db);
|
|
94
|
+
expect(stamps.get('kenari')).toEqual({ status: 'ok', fetchedAt: 42 });
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('deleting a row forgets the icon so the next read refetches', async () => {
|
|
98
|
+
const db = await getDb();
|
|
99
|
+
await writeProviderIcon(db, { slug: 'kenari', status: 'ok', bytes: PNG, fetchedAt: 1 });
|
|
100
|
+
await deleteProviderIcon(db, 'kenari');
|
|
101
|
+
expect(await readProviderIcon(db, 'kenari')).toBeNull();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('an unknown provider has no row', async () => {
|
|
105
|
+
expect(await readProviderIcon(await getDb(), 'nope')).toBeNull();
|
|
106
|
+
});
|
|
107
|
+
});
|