@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,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* GitLab's adapter, over recorded bodies.
|
|
8
|
+
*
|
|
9
|
+
* Split from the GitHub half because the two vendors disagree on nearly every
|
|
10
|
+
* field, and a single file that carried both made a failure ambiguous. The cases
|
|
11
|
+
* are the ones that silently mislead rather than fail: `opened` instead of
|
|
12
|
+
* `open`, a `changes_count` sent as a STRING, a project whose releases answer
|
|
13
|
+
* 404, and system notes that are an audit trail rather than a reply.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, expect, test } from 'bun:test';
|
|
17
|
+
|
|
18
|
+
import { listGitlab, mergeState, projectPath } from './gitlab';
|
|
19
|
+
import { detailGitlab } from './gitlab-detail';
|
|
20
|
+
import { host } from './test-host';
|
|
21
|
+
import { hostContext, openFilter } from './test-context';
|
|
22
|
+
|
|
23
|
+
const gitlab = (fetchImpl: typeof fetch, overrides: Parameters<typeof hostContext>[2] = {}) =>
|
|
24
|
+
hostContext('gitlab', fetchImpl, overrides);
|
|
25
|
+
|
|
26
|
+
/** The URL-encoded project every read is built on. */
|
|
27
|
+
const PROJECT = '/api/v4/projects/group%2Fproject';
|
|
28
|
+
|
|
29
|
+
describe('listGitlab', () => {
|
|
30
|
+
test('the project is addressed by its URL-encoded path', async () => {
|
|
31
|
+
const { asked, fetchImpl } = host({});
|
|
32
|
+
await listGitlab(gitlab(fetchImpl));
|
|
33
|
+
expect(asked.length).toBeGreaterThan(0);
|
|
34
|
+
expect(asked.every((url) => url.includes('/projects/group%2Fproject/'))).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('GitLab says opened, and an open merge request is open', async () => {
|
|
38
|
+
const { fetchImpl } = host({
|
|
39
|
+
[`${PROJECT}/merge_requests`]: [
|
|
40
|
+
{ iid: 1, title: 'Open', state: 'opened', author: { username: 'a' } },
|
|
41
|
+
{ iid: 2, title: 'Merged', state: 'merged', author: { username: 'a' } },
|
|
42
|
+
{ iid: 3, title: 'Draft', state: 'opened', draft: true, author: { username: 'a' } },
|
|
43
|
+
],
|
|
44
|
+
[`${PROJECT}/issues`]: [],
|
|
45
|
+
[`${PROJECT}/releases`]: [],
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const list = await listGitlab(gitlab(fetchImpl));
|
|
49
|
+
expect(list.sections.pulls.items.map((item) => item.state)).toEqual(['open', 'merged', 'draft']);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('the open filter is spelled `opened`, and mine is a scope', async () => {
|
|
53
|
+
const { asked, fetchImpl } = host({});
|
|
54
|
+
await listGitlab(gitlab(fetchImpl, { filter: { ...openFilter(), mine: true } }));
|
|
55
|
+
const issues = asked.find((url) => url.includes('/issues'));
|
|
56
|
+
expect(issues).toContain('state=opened');
|
|
57
|
+
expect(issues).toContain('scope=assigned_to_me');
|
|
58
|
+
// Sending both is a 400 on GitLab, so the builder must never emit both.
|
|
59
|
+
expect(issues).not.toContain('assignee_username');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('a project with no releases answers 404, which is an empty section', async () => {
|
|
63
|
+
const { fetchImpl } = host({
|
|
64
|
+
[`${PROJECT}/issues`]: [{ iid: 1, title: 'ok', state: 'opened' }],
|
|
65
|
+
[`${PROJECT}/merge_requests`]: [],
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const list = await listGitlab(gitlab(fetchImpl));
|
|
69
|
+
expect(list.sections.issues.items).toHaveLength(1);
|
|
70
|
+
expect(list.sections.releases.items).toEqual([]);
|
|
71
|
+
expect(list.notes).toEqual([]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('labels arrive as plain strings', async () => {
|
|
75
|
+
const { fetchImpl } = host({
|
|
76
|
+
[`${PROJECT}/issues`]: [{ iid: 1, title: 't', state: 'opened', labels: ['bug', 'p1'] }],
|
|
77
|
+
[`${PROJECT}/merge_requests`]: [],
|
|
78
|
+
[`${PROJECT}/releases`]: [],
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const list = await listGitlab(gitlab(fetchImpl));
|
|
82
|
+
expect(list.sections.issues.items[0].labels).toEqual([
|
|
83
|
+
{ name: 'bug', color: null },
|
|
84
|
+
{ name: 'p1', color: null },
|
|
85
|
+
]);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('mergeState', () => {
|
|
90
|
+
test('the word decides, not a merged_at field GitLab does not send', () => {
|
|
91
|
+
expect(mergeState({ state: 'merged' })).toBe('merged');
|
|
92
|
+
expect(mergeState({ state: 'closed' })).toBe('closed');
|
|
93
|
+
expect(mergeState({ state: 'opened' })).toBe('open');
|
|
94
|
+
expect(mergeState({ state: 'opened', draft: true })).toBe('draft');
|
|
95
|
+
expect(mergeState({ state: 'opened', work_in_progress: true })).toBe('draft');
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('detailGitlab', () => {
|
|
100
|
+
test('system notes are kept and flagged, not dropped', async () => {
|
|
101
|
+
const { fetchImpl } = host({
|
|
102
|
+
[`${PROJECT}/merge_requests/5`]: {
|
|
103
|
+
iid: 5,
|
|
104
|
+
title: 'A change',
|
|
105
|
+
state: 'opened',
|
|
106
|
+
description: 'Body text',
|
|
107
|
+
source_branch: 'feat',
|
|
108
|
+
target_branch: 'main',
|
|
109
|
+
changes_count: '3',
|
|
110
|
+
detailed_merge_status: 'mergeable',
|
|
111
|
+
head_pipeline: { status: 'failed', web_url: 'https://gitlab/p/1' },
|
|
112
|
+
// The files are NOT here: measured on a real project, the detail carries
|
|
113
|
+
// `changes_count` and no `changes` array.
|
|
114
|
+
},
|
|
115
|
+
[`${PROJECT}/merge_requests/5/changes`]: {
|
|
116
|
+
iid: 5,
|
|
117
|
+
changes: [
|
|
118
|
+
{ old_path: 'src/a.ts', new_path: 'src/a.ts', diff: '@@ -1 +1 @@' },
|
|
119
|
+
{ old_path: 'new.ts', new_path: 'new.ts', new_file: true, diff: '@@ -0,0 +1 @@' },
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
[`${PROJECT}/merge_requests/5/notes`]: [
|
|
123
|
+
{ id: 1, author: { username: 'ana' }, body: 'Real comment', created_at: '2026-01-01' },
|
|
124
|
+
{ id: 2, author: { username: 'ana' }, body: 'changed the description', system: true },
|
|
125
|
+
],
|
|
126
|
+
[`${PROJECT}/merge_requests/5/commits`]: [
|
|
127
|
+
{ id: 'abc', title: 'A commit', author_name: 'Ana', authored_date: '2026-01-01' },
|
|
128
|
+
],
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const detail = await detailGitlab(gitlab(fetchImpl), 'pulls', '5');
|
|
132
|
+
if ('error' in detail) throw new Error(detail.error);
|
|
133
|
+
|
|
134
|
+
expect(detail.comments.map((comment) => comment.body)).toEqual(['Real comment', 'changed the description']);
|
|
135
|
+
expect(detail.comments.map((comment) => comment.system)).toEqual([false, true]);
|
|
136
|
+
expect(detail.facts).toEqual([
|
|
137
|
+
{ label: 'branch', value: 'main ← feat' },
|
|
138
|
+
{ label: 'files', value: '3' },
|
|
139
|
+
{ label: 'mergeable', value: 'yes' },
|
|
140
|
+
]);
|
|
141
|
+
expect(detail.ci).toEqual({ state: 'failure', label: 'failed', url: 'https://gitlab/p/1' });
|
|
142
|
+
expect(detail.files.map((file) => [file.path, file.status])).toEqual([
|
|
143
|
+
['src/a.ts', 'modified'],
|
|
144
|
+
['new.ts', 'added'],
|
|
145
|
+
]);
|
|
146
|
+
expect(detail.commits.map((commit) => commit.message)).toEqual(['A commit']);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('the files come from the /changes sub-resource, because the detail carries none', async () => {
|
|
150
|
+
const { fetchImpl } = host({
|
|
151
|
+
[`${PROJECT}/merge_requests/8`]: { iid: 8, title: 't', state: 'opened', changes_count: '15' },
|
|
152
|
+
[`${PROJECT}/merge_requests/8/notes`]: [],
|
|
153
|
+
[`${PROJECT}/merge_requests/8/commits`]: [],
|
|
154
|
+
[`${PROJECT}/merge_requests/8/changes`]: {
|
|
155
|
+
changes: [{ old_path: 'a.ts', new_path: 'a.ts', diff: '@@ -1 +1 @@' }],
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const detail = await detailGitlab(gitlab(fetchImpl), 'pulls', '8');
|
|
160
|
+
if ('error' in detail) throw new Error(detail.error);
|
|
161
|
+
expect(detail.files.map((file) => file.path)).toEqual(['a.ts']);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('a conflicting merge request says conflicts, not no', async () => {
|
|
165
|
+
const { fetchImpl } = host({
|
|
166
|
+
[`${PROJECT}/merge_requests/6`]: { iid: 6, title: 't', state: 'opened', has_conflicts: true },
|
|
167
|
+
[`${PROJECT}/merge_requests/6/notes`]: [],
|
|
168
|
+
[`${PROJECT}/merge_requests/6/commits`]: [],
|
|
169
|
+
[`${PROJECT}/merge_requests/6/changes`]: { changes: [] },
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const detail = await detailGitlab(gitlab(fetchImpl), 'pulls', '6');
|
|
173
|
+
if ('error' in detail) throw new Error(detail.error);
|
|
174
|
+
expect(detail.facts).toContainEqual({ label: 'mergeable', value: 'conflicts' });
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('an issue has no files, no pipeline and no merge', async () => {
|
|
178
|
+
const { fetchImpl } = host({
|
|
179
|
+
[`${PROJECT}/issues/7`]: { iid: 7, title: 't', state: 'opened', description: 'x' },
|
|
180
|
+
[`${PROJECT}/issues/7/notes`]: [],
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
const detail = await detailGitlab(gitlab(fetchImpl), 'issues', '7');
|
|
184
|
+
if ('error' in detail) throw new Error(detail.error);
|
|
185
|
+
expect(detail.files).toEqual([]);
|
|
186
|
+
expect(detail.ci).toBeNull();
|
|
187
|
+
expect(detail.capabilities).toEqual({ comment: true, state: true, review: false, merge: false });
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
describe('projectPath', () => {
|
|
192
|
+
test('a subgroup is encoded as one path segment', () => {
|
|
193
|
+
expect(projectPath(gitlab(fetch as unknown as typeof fetch, { slug: 'a/b/c' }))).toBe('projects/a%2Fb%2Fc');
|
|
194
|
+
});
|
|
195
|
+
});
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* GitLab's REST API (v4), transcribed into this plugin's own shapes.
|
|
8
|
+
*
|
|
9
|
+
* ## Issues and merge requests are two collections here
|
|
10
|
+
*
|
|
11
|
+
* Unlike GitHub, GitLab does not fold merge requests into the issue list, so the
|
|
12
|
+
* two reads are genuinely independent — no filter, no double-counting. What it
|
|
13
|
+
* does NOT have is a search endpoint that returns both, so the filters travel as
|
|
14
|
+
* real parameters (`scope=assigned_to_me`, `labels`, `search`), which
|
|
15
|
+
* `filters.ts` builds.
|
|
16
|
+
*
|
|
17
|
+
* ## The project is addressed by its URL-ENCODED path
|
|
18
|
+
*
|
|
19
|
+
* `group/sub/project` becomes `group%2Fsub%2Fproject` in the path, and a plain
|
|
20
|
+
* `group/sub/project` would be read as three path segments and 404. That
|
|
21
|
+
* encoding is done once, in `remote.ts`'s `gitlabProject`, because a second
|
|
22
|
+
* implementation is how one read and one link disagree.
|
|
23
|
+
*
|
|
24
|
+
* ## The state vocabulary is GitLab's own
|
|
25
|
+
*
|
|
26
|
+
* `opened` rather than `open`, and a merge request reports `merged` only through
|
|
27
|
+
* `state: 'merged'` — not a `merged_at` field. Reading GitHub's words here is
|
|
28
|
+
* silently wrong in one direction: every open MR would read as closed.
|
|
29
|
+
*
|
|
30
|
+
* ## The pipeline is on the DETAIL, not the list
|
|
31
|
+
*
|
|
32
|
+
* Measured: `head_pipeline` is `failed` on `/merge_requests/:iid` and `null` on
|
|
33
|
+
* every row of `/merge_requests`. A row badge would cost one request per row.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
import type { ForgeItem, ForgeItemState, ForgeList, ForgeSection } from '../protocol';
|
|
37
|
+
import { get, joinUrl, pageSize, withParams, type ForgeContext } from './context';
|
|
38
|
+
import { gitlabParams } from './filters';
|
|
39
|
+
import { asRecord, count, flag, labelsOf, listAt, text, textAt } from './map';
|
|
40
|
+
import { gitlabProject } from './remote';
|
|
41
|
+
|
|
42
|
+
/** The project path every URL is built on. */
|
|
43
|
+
export function projectPath(context: ForgeContext): string {
|
|
44
|
+
return `projects/${gitlabProject(context.slug)}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function issueItem(raw: unknown): ForgeItem | null {
|
|
48
|
+
const record = asRecord(raw);
|
|
49
|
+
if (!record) return null;
|
|
50
|
+
const iid = count(record.iid, 0);
|
|
51
|
+
if (!iid) return null;
|
|
52
|
+
return {
|
|
53
|
+
id: String(iid),
|
|
54
|
+
number: iid,
|
|
55
|
+
title: text(record.title, '(untitled)'),
|
|
56
|
+
state: text(record.state) === 'closed' ? 'closed' : 'open',
|
|
57
|
+
author: textAt(record.author, 'username', 'unknown'),
|
|
58
|
+
updatedAt: text(record.updated_at),
|
|
59
|
+
url: text(record.web_url),
|
|
60
|
+
labels: labelsOf(record.labels),
|
|
61
|
+
comments: count(record.user_notes_count, 0),
|
|
62
|
+
tag: null,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A merge request's state.
|
|
68
|
+
*
|
|
69
|
+
* GitLab reports `merged` as a state of its own, so the check is on the word
|
|
70
|
+
* rather than on a `merged_at` field — and a draft is still open, which is why
|
|
71
|
+
* `draft`/`work_in_progress` are read after the state has been classified.
|
|
72
|
+
*/
|
|
73
|
+
export function mergeState(record: Record<string, unknown>): ForgeItemState {
|
|
74
|
+
const state = text(record.state);
|
|
75
|
+
if (state === 'merged') return 'merged';
|
|
76
|
+
if (state === 'closed') return 'closed';
|
|
77
|
+
return flag(record.draft) || flag(record.work_in_progress) ? 'draft' : 'open';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function mergeItem(raw: unknown): ForgeItem | null {
|
|
81
|
+
const record = asRecord(raw);
|
|
82
|
+
if (!record) return null;
|
|
83
|
+
const iid = count(record.iid, 0);
|
|
84
|
+
if (!iid) return null;
|
|
85
|
+
return {
|
|
86
|
+
id: String(iid),
|
|
87
|
+
number: iid,
|
|
88
|
+
title: text(record.title, '(untitled)'),
|
|
89
|
+
state: mergeState(record),
|
|
90
|
+
author: textAt(record.author, 'username', 'unknown'),
|
|
91
|
+
updatedAt: text(record.updated_at),
|
|
92
|
+
url: text(record.web_url),
|
|
93
|
+
labels: labelsOf(record.labels),
|
|
94
|
+
comments: count(record.user_notes_count, 0),
|
|
95
|
+
tag: null,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function releaseItem(raw: unknown): ForgeItem | null {
|
|
100
|
+
const record = asRecord(raw);
|
|
101
|
+
if (!record) return null;
|
|
102
|
+
const tag = text(record.tag_name);
|
|
103
|
+
if (!tag) return null;
|
|
104
|
+
return {
|
|
105
|
+
id: tag,
|
|
106
|
+
number: null,
|
|
107
|
+
title: text(record.name) || tag,
|
|
108
|
+
// GitLab has an `upcoming` release too: one that is scheduled and has no
|
|
109
|
+
// `released_at`. It is shown as a prerelease rather than as published,
|
|
110
|
+
// because nothing has been released yet.
|
|
111
|
+
state: text(record.released_at) ? 'published' : 'prerelease',
|
|
112
|
+
author: textAt(record.commit, 'author_name', 'unknown'),
|
|
113
|
+
updatedAt: text(record.released_at) || text(record.created_at),
|
|
114
|
+
url: textAt(record._links, 'self'),
|
|
115
|
+
labels: [],
|
|
116
|
+
comments: 0,
|
|
117
|
+
tag,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function readSection(
|
|
122
|
+
context: ForgeContext,
|
|
123
|
+
section: ForgeSection,
|
|
124
|
+
notes: string[],
|
|
125
|
+
): Promise<{ items: ForgeItem[]; truncated: boolean; total: number | null }> {
|
|
126
|
+
const perPage = pageSize(context);
|
|
127
|
+
const project = projectPath(context);
|
|
128
|
+
const collection = section === 'issues' ? 'issues' : section === 'pulls' ? 'merge_requests' : 'releases';
|
|
129
|
+
const params: Record<string, string> = {
|
|
130
|
+
per_page: String(perPage),
|
|
131
|
+
...(section === 'releases' ? {} : { order_by: 'updated_at' }),
|
|
132
|
+
...gitlabParams(section, context.filter),
|
|
133
|
+
};
|
|
134
|
+
const url = withParams(joinUrl(context.apiBase, `${project}/${collection}`), params);
|
|
135
|
+
|
|
136
|
+
const result = await get(context, url);
|
|
137
|
+
if (!result.ok) {
|
|
138
|
+
// A project with no releases answers 404 on that endpoint while issues and
|
|
139
|
+
// MRs read fine, so a missing releases collection is not an error.
|
|
140
|
+
if (section === 'releases' && result.status === 404) return { items: [], truncated: false, total: null };
|
|
141
|
+
notes.push(`${section}: ${result.message}`);
|
|
142
|
+
return { items: [], truncated: false, total: null };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const mapper = section === 'issues' ? issueItem : section === 'pulls' ? mergeItem : releaseItem;
|
|
146
|
+
const rows = listAt(result.value);
|
|
147
|
+
const items = rows.map(mapper).filter((item): item is ForgeItem => item !== null);
|
|
148
|
+
// GitLab reports the collection size on the response, and the cache stores the
|
|
149
|
+
// body rather than the headers, so the count a row shows is the page's own.
|
|
150
|
+
return { items, truncated: rows.length >= perPage, total: null };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export async function listGitlab(context: ForgeContext): Promise<ForgeList> {
|
|
154
|
+
const notes: string[] = [];
|
|
155
|
+
if (!context.token) {
|
|
156
|
+
notes.push(
|
|
157
|
+
'Reading anonymously: public projects only. Set GITLAB_TOKEN in the server environment, or run `glab auth login`, to read a private one.',
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const [issues, pulls, releases] = await Promise.all([
|
|
162
|
+
readSection(context, 'issues', notes),
|
|
163
|
+
readSection(context, 'pulls', notes),
|
|
164
|
+
readSection(context, 'releases', notes),
|
|
165
|
+
]);
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
provider: 'gitlab',
|
|
169
|
+
host: context.host,
|
|
170
|
+
slug: context.slug,
|
|
171
|
+
webUrl: context.webUrl,
|
|
172
|
+
filter: context.filter,
|
|
173
|
+
sections: { issues, pulls, releases },
|
|
174
|
+
notes,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The conditional read, over a fake host.
|
|
8
|
+
*
|
|
9
|
+
* The property that matters is the one the panel depends on: a second read of an
|
|
10
|
+
* unchanged resource must not cost a body, and a changed one must replace what is
|
|
11
|
+
* cached. Both are invisible against a live host (the second read looks the same
|
|
12
|
+
* either way) and both are wrong in a way nothing reports.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, test } from 'bun:test';
|
|
16
|
+
|
|
17
|
+
import type { PluginJson } from '@kabmo-labs/kabmo-sdk';
|
|
18
|
+
import {
|
|
19
|
+
authHeaders,
|
|
20
|
+
cacheKey,
|
|
21
|
+
describeFailure,
|
|
22
|
+
getJson,
|
|
23
|
+
isAuthenticated,
|
|
24
|
+
kvCache,
|
|
25
|
+
type CachedResponse,
|
|
26
|
+
type JsonCache,
|
|
27
|
+
} from './http';
|
|
28
|
+
|
|
29
|
+
/** An in-memory cache with the plugin's storage shape. */
|
|
30
|
+
function memoryCache(): JsonCache & { entries: Map<string, CachedResponse> } {
|
|
31
|
+
const entries = new Map<string, CachedResponse>();
|
|
32
|
+
return {
|
|
33
|
+
entries,
|
|
34
|
+
read: async (key) => entries.get(key),
|
|
35
|
+
write: async (key, entry) => {
|
|
36
|
+
entries.set(key, entry);
|
|
37
|
+
},
|
|
38
|
+
keys: async () => [...entries.keys()],
|
|
39
|
+
remove: async (key) => {
|
|
40
|
+
entries.delete(key);
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A fetch that records what it was asked and answers from a table. */
|
|
46
|
+
function recorder(responses: Response[]) {
|
|
47
|
+
const calls: Array<{ url: string; headers: Record<string, string> }> = [];
|
|
48
|
+
const fetchImpl = (async (input: string | URL | Request, init?: RequestInit) => {
|
|
49
|
+
calls.push({ url: String(input), headers: (init?.headers ?? {}) as Record<string, string> });
|
|
50
|
+
const next = responses.shift();
|
|
51
|
+
if (!next) throw new Error('no more responses');
|
|
52
|
+
return next;
|
|
53
|
+
}) as unknown as typeof fetch;
|
|
54
|
+
return { calls, fetchImpl };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function json(body: unknown, headers: Record<string, string> = {}): Response {
|
|
58
|
+
return new Response(JSON.stringify(body), {
|
|
59
|
+
status: 200,
|
|
60
|
+
headers: { 'content-type': 'application/json', ...headers },
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
describe('getJson', () => {
|
|
65
|
+
test('stores the payload and its validator', async () => {
|
|
66
|
+
const cache = memoryCache();
|
|
67
|
+
const { fetchImpl } = recorder([json({ issues: [1] }, { etag: 'W/"abc"' })]);
|
|
68
|
+
|
|
69
|
+
const first = await getJson({ cache, url: 'https://api.example/issues', fetchImpl });
|
|
70
|
+
expect(first).toEqual({ ok: true, value: { issues: [1] }, cached: false });
|
|
71
|
+
expect(cache.entries.get(cacheKey('https://api.example/issues'))?.etag).toBe('W/"abc"');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('a second read is conditional, and a 304 returns the cached payload', async () => {
|
|
75
|
+
const cache = memoryCache();
|
|
76
|
+
const { calls, fetchImpl } = recorder([
|
|
77
|
+
json({ issues: [1] }, { etag: 'W/"abc"' }),
|
|
78
|
+
new Response(null, { status: 304 }),
|
|
79
|
+
]);
|
|
80
|
+
|
|
81
|
+
await getJson({ cache, url: 'https://api.example/issues', fetchImpl });
|
|
82
|
+
const second = await getJson({ cache, url: 'https://api.example/issues', fetchImpl });
|
|
83
|
+
|
|
84
|
+
expect(calls[1].headers['if-none-match']).toBe('W/"abc"');
|
|
85
|
+
expect(second).toEqual({ ok: true, value: { issues: [1] }, cached: true });
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('a changed body replaces what is cached', async () => {
|
|
89
|
+
const cache = memoryCache();
|
|
90
|
+
const { fetchImpl } = recorder([
|
|
91
|
+
json({ issues: [1] }, { etag: 'W/"a"' }),
|
|
92
|
+
json({ issues: [1, 2] }, { etag: 'W/"b"' }),
|
|
93
|
+
]);
|
|
94
|
+
|
|
95
|
+
await getJson({ cache, url: 'https://api.example/issues', fetchImpl });
|
|
96
|
+
const second = await getJson({ cache, url: 'https://api.example/issues', fetchImpl });
|
|
97
|
+
|
|
98
|
+
expect(second).toEqual({ ok: true, value: { issues: [1, 2] }, cached: false });
|
|
99
|
+
expect(cache.entries.get(cacheKey('https://api.example/issues'))?.etag).toBe('W/"b"');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('one URL does not answer for another', async () => {
|
|
103
|
+
const cache = memoryCache();
|
|
104
|
+
const { calls, fetchImpl } = recorder([json({ a: 1 }), json({ b: 2 })]);
|
|
105
|
+
|
|
106
|
+
await getJson({ cache, url: 'https://api.example/a', fetchImpl });
|
|
107
|
+
const second = await getJson({ cache, url: 'https://api.example/b', fetchImpl });
|
|
108
|
+
|
|
109
|
+
expect(calls[1].headers['if-none-match']).toBeUndefined();
|
|
110
|
+
expect(second).toEqual({ ok: true, value: { b: 2 }, cached: false });
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('a 401 names the token, not the status', async () => {
|
|
114
|
+
const cache = memoryCache();
|
|
115
|
+
const { fetchImpl } = recorder([new Response('{}', { status: 401 })]);
|
|
116
|
+
const result = await getJson({ cache, url: 'https://api.example/x', fetchImpl });
|
|
117
|
+
|
|
118
|
+
expect(result.ok).toBe(false);
|
|
119
|
+
if (result.ok) return;
|
|
120
|
+
expect(result.status).toBe(401);
|
|
121
|
+
expect(result.message).toContain('token');
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('a rate-limited 403 says when to retry', async () => {
|
|
125
|
+
const cache = memoryCache();
|
|
126
|
+
const reset = String(Math.floor(Date.now() / 1000) + 600);
|
|
127
|
+
const { fetchImpl } = recorder([
|
|
128
|
+
new Response('{}', { status: 403, headers: { 'x-ratelimit-remaining': '0', 'x-ratelimit-reset': reset } }),
|
|
129
|
+
]);
|
|
130
|
+
const result = await getJson({ cache, url: 'https://api.example/x', fetchImpl });
|
|
131
|
+
|
|
132
|
+
expect(result.ok).toBe(false);
|
|
133
|
+
if (result.ok) return;
|
|
134
|
+
expect(result.message).toContain('Rate limit');
|
|
135
|
+
expect(result.message).toContain('Try again after');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('an unreachable host is reported, never thrown', async () => {
|
|
139
|
+
const cache = memoryCache();
|
|
140
|
+
const fetchImpl = (async () => {
|
|
141
|
+
throw new Error('connect ECONNREFUSED');
|
|
142
|
+
}) as unknown as typeof fetch;
|
|
143
|
+
const result = await getJson({ cache, url: 'https://api.example/x', fetchImpl });
|
|
144
|
+
|
|
145
|
+
expect(result.ok).toBe(false);
|
|
146
|
+
if (result.ok) return;
|
|
147
|
+
expect(result.message).toContain('ECONNREFUSED');
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('a body that is not JSON is reported', async () => {
|
|
151
|
+
const cache = memoryCache();
|
|
152
|
+
const { fetchImpl } = recorder([new Response('<html>', { status: 200 })]);
|
|
153
|
+
const result = await getJson({ cache, url: 'https://api.example/x', fetchImpl });
|
|
154
|
+
|
|
155
|
+
expect(result.ok).toBe(false);
|
|
156
|
+
if (result.ok) return;
|
|
157
|
+
expect(result.message).toContain('not JSON');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('the cache is bounded, and the oldest entry is what goes', async () => {
|
|
161
|
+
const cache = memoryCache();
|
|
162
|
+
let clock = 1_000;
|
|
163
|
+
const now = () => clock;
|
|
164
|
+
// 61 distinct URLs crosses the 60-entry ceiling.
|
|
165
|
+
for (let index = 0; index < 61; index += 1) {
|
|
166
|
+
clock += 1;
|
|
167
|
+
const { fetchImpl } = recorder([json({ index })]);
|
|
168
|
+
await getJson({ cache, url: `https://api.example/${index}`, fetchImpl, now });
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
expect(cache.entries.size).toBeLessThan(61);
|
|
172
|
+
expect(cache.entries.has(cacheKey('https://api.example/0'))).toBe(false);
|
|
173
|
+
expect(cache.entries.has(cacheKey('https://api.example/60'))).toBe(true);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe('authHeaders', () => {
|
|
178
|
+
test('each provider gets its own credential header', () => {
|
|
179
|
+
expect(authHeaders('github', 'ghp_x')).toEqual({
|
|
180
|
+
authorization: 'Bearer ghp_x',
|
|
181
|
+
'x-github-api-version': '2022-11-28',
|
|
182
|
+
});
|
|
183
|
+
expect(authHeaders('gitlab', 'glpat-x')).toEqual({ 'private-token': 'glpat-x' });
|
|
184
|
+
expect(authHeaders('gitea', 'abc')).toEqual({ authorization: 'token abc' });
|
|
185
|
+
expect(authHeaders('github', null)).toEqual({});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test('Bitbucket tells an app password from an access token', () => {
|
|
189
|
+
expect(authHeaders('bitbucket', 'access-token')).toEqual({ authorization: 'Bearer access-token' });
|
|
190
|
+
// An app password is a user/password pair, and Basic is the only header the
|
|
191
|
+
// host accepts for it — sent as Bearer it answers 401 and reads as a bad
|
|
192
|
+
// token.
|
|
193
|
+
expect(authHeaders('bitbucket', 'user:app-pass')).toEqual({
|
|
194
|
+
authorization: `Basic ${Buffer.from('user:app-pass').toString('base64')}`,
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe('isAuthenticated', () => {
|
|
200
|
+
test('any of the two header spellings counts', () => {
|
|
201
|
+
expect(isAuthenticated({ authorization: 'Bearer x' })).toBe(true);
|
|
202
|
+
expect(isAuthenticated({ 'private-token': 'x' })).toBe(true);
|
|
203
|
+
expect(isAuthenticated({})).toBe(false);
|
|
204
|
+
expect(isAuthenticated(undefined)).toBe(false);
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe('describeFailure', () => {
|
|
209
|
+
test('404 explains the two reasons a repository is invisible', () => {
|
|
210
|
+
expect(describeFailure(new Response(null, { status: 404 }), false)).toContain('private');
|
|
211
|
+
expect(describeFailure(new Response(null, { status: 404 }), true)).toContain('token');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test('a 401 to an anonymous read asks for a token, not for a different one', () => {
|
|
215
|
+
const anonymous = describeFailure(new Response(null, { status: 401 }), false);
|
|
216
|
+
expect(anonymous).toContain('needs a token');
|
|
217
|
+
expect(anonymous).not.toContain('rejected');
|
|
218
|
+
|
|
219
|
+
expect(describeFailure(new Response(null, { status: 401 }), true)).toContain('rejected');
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
test('a 403 to an ANONYMOUS read is not advice about a token scope', () => {
|
|
223
|
+
const anonymous = describeFailure(new Response(null, { status: 403 }), false);
|
|
224
|
+
expect(anonymous).toContain('anonymous');
|
|
225
|
+
expect(anonymous).not.toContain('may not have scope');
|
|
226
|
+
|
|
227
|
+
const authenticated = describeFailure(new Response(null, { status: 403 }), true);
|
|
228
|
+
expect(authenticated).toContain('scope');
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test('a rate-limited 403 wins over the anonymous wording', () => {
|
|
232
|
+
const message = describeFailure(
|
|
233
|
+
new Response(null, { status: 403, headers: { 'x-ratelimit-remaining': '0', 'x-ratelimit-reset': '9999999999' } }),
|
|
234
|
+
false,
|
|
235
|
+
);
|
|
236
|
+
expect(message).toContain('Rate limit');
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test('an unknown status still says which one', () => {
|
|
240
|
+
expect(describeFailure(new Response(null, { status: 500 }), true)).toContain('500');
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
describe('kvCache', () => {
|
|
245
|
+
test('round-trips through the plugin store shape', async () => {
|
|
246
|
+
const store = new Map<string, PluginJson>();
|
|
247
|
+
const cache = kvCache({
|
|
248
|
+
read: async <T,>(key: string) => store.get(key) as T | undefined,
|
|
249
|
+
write: async (key, value) => {
|
|
250
|
+
store.set(key, value);
|
|
251
|
+
},
|
|
252
|
+
keys: async () => [...store.keys()],
|
|
253
|
+
remove: async (key) => {
|
|
254
|
+
store.delete(key);
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
const entry: CachedResponse = {
|
|
258
|
+
url: 'u',
|
|
259
|
+
etag: null,
|
|
260
|
+
lastModified: null,
|
|
261
|
+
value: { ok: 1 },
|
|
262
|
+
at: 5,
|
|
263
|
+
};
|
|
264
|
+
await cache.write('k', entry);
|
|
265
|
+
expect(await cache.read('k')).toEqual(entry);
|
|
266
|
+
expect(await cache.keys()).toEqual(['k']);
|
|
267
|
+
await cache.remove('k');
|
|
268
|
+
expect(await cache.read('k')).toBeUndefined();
|
|
269
|
+
});
|
|
270
|
+
});
|