feat: install and update through the Geek2API mirror (0.1.2)
Every entry point serves /dsh/latest.json and the release tarballs, synced from GitHub; the version check asks the mirror first through the endpoint pool and installs the mirrored tarball, with GitHub as the fallback. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
f4f4ce55b3
commit
1379421095
9 files changed
+171
-18
No files matched your search
@@ -71,6 +71,6 @@ Never reuse, move, or delete a published tag or release asset. If a released ver
|
|||||||
git push origin v<version>
|
git push origin v<version>
|
||||||
```
|
```
|
||||||
|
|
||||||
[`.github/workflows/release.yml`](.github/workflows/release.yml) refuses a tag that does not match `package.json`, runs `pnpm run check`, refuses a stale `lib/`, and creates the release with `dsh-geek2api-<version>.tgz` attached. The plugin's update check reads `releases/latest` and installs that asset.
|
[`.github/workflows/release.yml`](.github/workflows/release.yml) refuses a tag that does not match `package.json`, runs `pnpm run check`, refuses a stale `lib/`, and creates the release with `dsh-geek2api-<version>.tgz` attached. Every Geek2API entry point mirrors the release at `/dsh/` within about 10 minutes (origin timer `dsh-mirror-sync`); the plugin's update check reads the mirror's `latest.json` first and GitHub `releases/latest` as the fallback.
|
||||||
|
|
||||||
5. Confirm the workflow succeeded and the asset is attached before announcing the release.
|
5. Confirm the workflow succeeded and the asset is attached before announcing the release.
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.1.2
|
||||||
|
|
||||||
|
- Installs and updates no longer depend on reaching GitHub. Every Geek2API entry point serves a mirror of the releases at `/dsh/` (`latest.json`, each `dsh-geek2api-<version>.tgz`, and `dsh-geek2api.tgz`), synced from GitHub every 10 minutes. The version card asks the mirror first through the endpoint pool and installs the mirrored tarball; GitHub is the fallback. Install address: `https://hk.geek2api.com/dsh/dsh-geek2api.tgz`.
|
||||||
|
|
||||||
## 0.1.1
|
## 0.1.1
|
||||||
|
|
||||||
- Updates come from GitHub Releases (`CoderKuo/dsh-geek2api`) instead of npm: the version card reads the latest release, links its release notes, and installs its tarball in place for installs from a release tarball (or the npm registry). The release workflow builds, tests, and attaches `dsh-geek2api-<version>.tgz` plus an unversioned `dsh-geek2api.tgz` for a stable install address.
|
- Updates come from GitHub Releases (`CoderKuo/dsh-geek2api`) instead of npm: the version card reads the latest release, links its release notes, and installs its tarball in place for installs from a release tarball (or the npm registry). The release workflow builds, tests, and attaches `dsh-geek2api-<version>.tgz` plus an unversioned `dsh-geek2api.tgz` for a stable install address.
|
||||||
|
|||||||
+2
-2
@@ -27,7 +27,7 @@ Installing it adds a `Geek2API` group to the model picker. No YAML and no provid
|
|||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
1. In the desktop app, open **Plugins → Add plugin**, enter `https://github.com/CoderKuo/dsh-geek2api/releases/latest/download/dsh-geek2api.tgz`, and install. No restart is needed for a first install. You can also download the `.tgz` from [Releases](https://github.com/CoderKuo/dsh-geek2api/releases) and install it from a local path.
|
1. In the desktop app, open **Plugins → Add plugin**, enter `https://hk.geek2api.com/dsh/dsh-geek2api.tgz` (Geek2API's mirror of the GitHub release, reachable from mainland networks; synced every 10 minutes) or `https://github.com/CoderKuo/dsh-geek2api/releases/latest/download/dsh-geek2api.tgz`, and install. No restart is needed for a first install. You can also download the `.tgz` from [Releases](https://github.com/CoderKuo/dsh-geek2api/releases) and install it from a local path.
|
||||||
2. Open **Settings → Geek2API** and paste an API key (create one under API Keys in the Geek2API console). Add more keys for other groups; the plugin picks the right one per model.
|
2. Open **Settings → Geek2API** and paste an API key (create one under API Keys in the Geek2API console). Add more keys for other groups; the plugin picks the right one per model.
|
||||||
3. Pick a model under the `Geek2API` group.
|
3. Pick a model under the `Geek2API` group.
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ Whether a key can use a model depends on its group; trust the ✓ / ✕ in setti
|
|||||||
|
|
||||||
## Update and uninstall
|
## Update and uninstall
|
||||||
|
|
||||||
The version card in **Settings → Geek2API** checks the latest GitHub release; update from there, then fully quit and reopen the desktop app. Before uninstalling, set web search back to "leave DSH alone" if you used it, then uninstall from the Plugins page and restart.
|
The version card in **Settings → Geek2API** checks the Geek2API mirror first and GitHub when no mirror answers; update from there, then fully quit and reopen the desktop app. Before uninstalling, set web search back to "leave DSH alone" if you used it, then uninstall from the Plugins page and restart.
|
||||||
|
|
||||||
## Security
|
## Security
|
||||||
|
|
||||||
|
|||||||
@@ -36,10 +36,12 @@
|
|||||||
打开桌面应用的**插件**页,点击**添加插件**,在**包名或地址**中填入:
|
打开桌面应用的**插件**页,点击**添加插件**,在**包名或地址**中填入:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
https://github.com/CoderKuo/dsh-geek2api/releases/latest/download/dsh-geek2api.tgz
|
https://hk.geek2api.com/dsh/dsh-geek2api.tgz
|
||||||
```
|
```
|
||||||
|
|
||||||
然后点击**安装**。首次安装后不用重启 DSH。也可以先从 [Releases](https://github.com/CoderKuo/dsh-geek2api/releases) 下载 `.tgz`,再填本地文件路径安装。
|
然后点击**安装**。首次安装后不用重启 DSH。
|
||||||
|
|
||||||
|
这是 Geek2API 自己的镜像,国内直连就能下载,内容与 GitHub Release 相同(每 10 分钟同步一次);hk2 / hk3 / hk4 换掉域名里的 `hk` 也可以。能访问 GitHub 的话,也可以填 `https://github.com/CoderKuo/dsh-geek2api/releases/latest/download/dsh-geek2api.tgz`,或从 [Releases](https://github.com/CoderKuo/dsh-geek2api/releases) 下载后填本地文件路径。
|
||||||
|
|
||||||
### 2. 添加 Key
|
### 2. 添加 Key
|
||||||
|
|
||||||
@@ -118,7 +120,7 @@ https://github.com/CoderKuo/dsh-geek2api/releases/latest/download/dsh-geek2api.t
|
|||||||
|
|
||||||
## 更新与卸载
|
## 更新与卸载
|
||||||
|
|
||||||
**更新:** 打开 **设置 → Geek2API**,「插件版本」卡片会检查 GitHub 上的最新发布;有新版本时点「更新插件」,完成后完全退出并重新打开桌面应用。「更新说明」链接到这个版本的发布页。
|
**更新:** 打开 **设置 → Geek2API**,「插件版本」卡片会先从 Geek2API 镜像检查最新版本(国内直连可用),镜像不可用时再查 GitHub;有新版本时点「更新插件」,完成后完全退出并重新打开桌面应用。「更新说明」链接到这个版本的发布页。
|
||||||
|
|
||||||
**卸载:** 用过 Geek2API 网页搜索的话,先在 **设置 → Geek2API → 网页搜索** 切回「不接管」,再到**插件**页卸载,然后重启桌面应用。否则 `cordis.patch.yml` 里会留下指向已卸载后端的配置;这时手动删掉带 `dsh-geek2api: web search provider` 标记的那一段即可。
|
**卸载:** 用过 Geek2API 网页搜索的话,先在 **设置 → Geek2API → 网页搜索** 切回「不接管」,再到**插件**页卸载,然后重启桌面应用。否则 `cordis.patch.yml` 里会留下指向已卸载后端的配置;这时手动删掉带 `dsh-geek2api: web search provider` 标记的那一段即可。
|
||||||
|
|
||||||
|
|||||||
+50
-6
@@ -5213,8 +5213,10 @@ function createModelSelectionController({ readPreference, writePreference, isWri
|
|||||||
* Version self-knowledge for the settings panel.
|
* Version self-knowledge for the settings panel.
|
||||||
*
|
*
|
||||||
* The running version comes from this package. The latest version comes from
|
* The running version comes from this package. The latest version comes from
|
||||||
* the GitHub releases of this repository: the newest non-draft release names
|
* the Geek2API mirror first — every entry point serves `/dsh/latest.json` and
|
||||||
* the version in its tag and carries the packed tarball as an asset. An
|
* the packed tarballs, synced from GitHub, because GitHub release downloads
|
||||||
|
* are unreachable from mainland networks — and from the GitHub releases of
|
||||||
|
* this repository when no mirror answers. An
|
||||||
* in-place update is offered for an install from a release tarball (or the
|
* in-place update is offered for an install from a release tarball (or the
|
||||||
* npm registry), and it installs that exact tarball with the host's own pnpm
|
* npm registry), and it installs that exact tarball with the host's own pnpm
|
||||||
* — never through `dsh plugin --profile desktop`, which the desktop app
|
* — never through `dsh plugin --profile desktop`, which the desktop app
|
||||||
@@ -5226,6 +5228,25 @@ const PACKAGE_NAME = "dsh-geek2api";
|
|||||||
const GITHUB_LATEST_RELEASE_URL = `https://api.github.com/repos/CoderKuo/dsh-geek2api/releases/latest`;
|
const GITHUB_LATEST_RELEASE_URL = `https://api.github.com/repos/CoderKuo/dsh-geek2api/releases/latest`;
|
||||||
/** The tarball asset a release must carry for an in-place update. */
|
/** The tarball asset a release must carry for an in-place update. */
|
||||||
const releaseAssetName = (version) => `${PACKAGE_NAME}-${version}.tgz`;
|
const releaseAssetName = (version) => `${PACKAGE_NAME}-${version}.tgz`;
|
||||||
|
/** Where every Geek2API entry point serves the mirrored releases. */
|
||||||
|
const MIRROR_PATH = "/dsh";
|
||||||
|
/**
|
||||||
|
* Normalize the mirror's `latest.json` as served by one entry point.
|
||||||
|
* @param payload - the manifest body.
|
||||||
|
* @param host - the entry point that served it.
|
||||||
|
* @returns `{ version, tarballUrl, releaseUrl }`, or undefined when unusable.
|
||||||
|
*/
|
||||||
|
function parseMirrorManifest(payload, host) {
|
||||||
|
if (payload === null || typeof payload !== "object" || typeof host !== "string") return void 0;
|
||||||
|
const version = typeof payload.version === "string" ? payload.version : void 0;
|
||||||
|
if (parseSemver(version) === void 0 || payload.tarball !== releaseAssetName(version)) return void 0;
|
||||||
|
const releaseUrl = typeof payload.releaseUrl === "string" && /^https:\/\/github\.com\//u.test(payload.releaseUrl) ? payload.releaseUrl : void 0;
|
||||||
|
return {
|
||||||
|
version,
|
||||||
|
tarballUrl: `${host}${MIRROR_PATH}/${payload.tarball}`,
|
||||||
|
...releaseUrl === void 0 ? {} : { releaseUrl }
|
||||||
|
};
|
||||||
|
}
|
||||||
const DEFAULT_VERSION_TTL_MS = 5 * 6e4;
|
const DEFAULT_VERSION_TTL_MS = 5 * 6e4;
|
||||||
const DEFAULT_VERSION_TIMEOUT_MS = 1e4;
|
const DEFAULT_VERSION_TIMEOUT_MS = 1e4;
|
||||||
const DEFAULT_UPDATE_TIMEOUT_MS = 18e4;
|
const DEFAULT_UPDATE_TIMEOUT_MS = 18e4;
|
||||||
@@ -5444,7 +5465,7 @@ function spawnRunCommand({ command, args, cwd }, { signal, timeoutMs }) {
|
|||||||
* The running version, the latest registry version, which profile installed
|
* The running version, the latest registry version, which profile installed
|
||||||
* this copy, and registry-spec updates against that profile.
|
* this copy, and registry-spec updates against that profile.
|
||||||
*/
|
*/
|
||||||
function createGeek2APIPluginManager({ fetchImpl = ambientFetch, runCommand = spawnRunCommand, execPath = process.execPath, argv = process.argv, env = process.env, ownPackageJsonUrl = new URL("../package.json", import.meta.url), releaseUrl = GITHUB_LATEST_RELEASE_URL, now = Date.now, ttlMs = DEFAULT_VERSION_TTL_MS, timeoutMs = DEFAULT_VERSION_TIMEOUT_MS, updateTimeoutMs = DEFAULT_UPDATE_TIMEOUT_MS, settleDelayMs = 250 } = {}) {
|
function createGeek2APIPluginManager({ fetchImpl = ambientFetch, runCommand = spawnRunCommand, execPath = process.execPath, argv = process.argv, env = process.env, ownPackageJsonUrl = new URL("../package.json", import.meta.url), releaseUrl = GITHUB_LATEST_RELEASE_URL, hosts, now = Date.now, ttlMs = DEFAULT_VERSION_TTL_MS, timeoutMs = DEFAULT_VERSION_TIMEOUT_MS, updateTimeoutMs = DEFAULT_UPDATE_TIMEOUT_MS, settleDelayMs = 250 } = {}) {
|
||||||
if (typeof fetchImpl !== "function") throw new Error("Geek2API plugin manager requires fetch");
|
if (typeof fetchImpl !== "function") throw new Error("Geek2API plugin manager requires fetch");
|
||||||
if (typeof runCommand !== "function") throw new Error("Geek2API plugin manager requires runCommand");
|
if (typeof runCommand !== "function") throw new Error("Geek2API plugin manager requires runCommand");
|
||||||
const dshHome = typeof env.DSH_HOME === "string" && env.DSH_HOME !== "" ? env.DSH_HOME : join(homedir(), ".dsh");
|
const dshHome = typeof env.DSH_HOME === "string" && env.DSH_HOME !== "" ? env.DSH_HOME : join(homedir(), ".dsh");
|
||||||
@@ -5453,8 +5474,31 @@ function createGeek2APIPluginManager({ fetchImpl = ambientFetch, runCommand = sp
|
|||||||
execPath
|
execPath
|
||||||
});
|
});
|
||||||
let updating = false;
|
let updating = false;
|
||||||
/** The newest release: its version, tarball asset, and page. */
|
/**
|
||||||
const fetchLatest = async (signal) => {
|
* The newest release from the mirror, through the entry point the pool
|
||||||
|
* prefers. Undefined when no entry point serves a usable manifest.
|
||||||
|
*/
|
||||||
|
const fetchFromMirror = async (signal) => {
|
||||||
|
if (typeof hosts?.withFailover !== "function") return void 0;
|
||||||
|
try {
|
||||||
|
return await hosts.withFailover(async (host) => {
|
||||||
|
const response = await boundedFetch(`${host}${MIRROR_PATH}/latest.json`, { headers: { Accept: "application/json" } }, {
|
||||||
|
fetchImpl,
|
||||||
|
timeoutMs,
|
||||||
|
signal
|
||||||
|
});
|
||||||
|
if (!response.ok) return void 0;
|
||||||
|
return parseMirrorManifest(await response.json(), host);
|
||||||
|
}, { signal });
|
||||||
|
} catch (error) {
|
||||||
|
if (signal?.aborted) throw error;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/** The newest release: mirror first, then GitHub. */
|
||||||
|
const fetchLatest = async (signal) => await fetchFromMirror(signal) ?? fetchFromGitHub(signal);
|
||||||
|
/** The newest GitHub release: its version, tarball asset, and page. */
|
||||||
|
const fetchFromGitHub = async (signal) => {
|
||||||
let response;
|
let response;
|
||||||
try {
|
try {
|
||||||
response = await boundedFetch(releaseUrl, { headers: {
|
response = await boundedFetch(releaseUrl, { headers: {
|
||||||
@@ -7198,7 +7242,7 @@ function apply(ctx, config) {
|
|||||||
preference: modelPreference,
|
preference: modelPreference,
|
||||||
claudeRuntime,
|
claudeRuntime,
|
||||||
claudeCli,
|
claudeCli,
|
||||||
pluginManager: createGeek2APIPluginManager(),
|
pluginManager: createGeek2APIPluginManager({ hosts }),
|
||||||
search,
|
search,
|
||||||
modelSelection
|
modelSelection
|
||||||
});
|
});
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dsh-geek2api",
|
"name": "dsh-geek2api",
|
||||||
"version": "0.1.1",
|
"version": "0.1.2",
|
||||||
"packageManager": "pnpm@10.32.1",
|
"packageManager": "pnpm@10.32.1",
|
||||||
"description": "Use Geek2API API keys in DeepSeek Harness: a built-in multi-protocol model route with key rotation, multi-endpoint failover, and balance display",
|
"description": "Use Geek2API API keys in DeepSeek Harness: a built-in multi-protocol model route with key rotation, multi-endpoint failover, and balance display",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
+1
-1
@@ -330,7 +330,7 @@ export function apply(ctx, config) {
|
|||||||
preference: modelPreference,
|
preference: modelPreference,
|
||||||
claudeRuntime,
|
claudeRuntime,
|
||||||
claudeCli,
|
claudeCli,
|
||||||
pluginManager: createGeek2APIPluginManager(),
|
pluginManager: createGeek2APIPluginManager({ hosts }),
|
||||||
search,
|
search,
|
||||||
modelSelection,
|
modelSelection,
|
||||||
})
|
})
|
||||||
|
|||||||
+44
-4
@@ -2,8 +2,10 @@
|
|||||||
* Version self-knowledge for the settings panel.
|
* Version self-knowledge for the settings panel.
|
||||||
*
|
*
|
||||||
* The running version comes from this package. The latest version comes from
|
* The running version comes from this package. The latest version comes from
|
||||||
* the GitHub releases of this repository: the newest non-draft release names
|
* the Geek2API mirror first — every entry point serves `/dsh/latest.json` and
|
||||||
* the version in its tag and carries the packed tarball as an asset. An
|
* the packed tarballs, synced from GitHub, because GitHub release downloads
|
||||||
|
* are unreachable from mainland networks — and from the GitHub releases of
|
||||||
|
* this repository when no mirror answers. An
|
||||||
* in-place update is offered for an install from a release tarball (or the
|
* in-place update is offered for an install from a release tarball (or the
|
||||||
* npm registry), and it installs that exact tarball with the host's own pnpm
|
* npm registry), and it installs that exact tarball with the host's own pnpm
|
||||||
* — never through `dsh plugin --profile desktop`, which the desktop app
|
* — never through `dsh plugin --profile desktop`, which the desktop app
|
||||||
@@ -29,6 +31,22 @@ export const GITHUB_REPOSITORY = 'CoderKuo/dsh-geek2api'
|
|||||||
export const GITHUB_LATEST_RELEASE_URL = `https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/latest`
|
export const GITHUB_LATEST_RELEASE_URL = `https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/latest`
|
||||||
/** The tarball asset a release must carry for an in-place update. */
|
/** The tarball asset a release must carry for an in-place update. */
|
||||||
export const releaseAssetName = version => `${PACKAGE_NAME}-${version}.tgz`
|
export const releaseAssetName = version => `${PACKAGE_NAME}-${version}.tgz`
|
||||||
|
/** Where every Geek2API entry point serves the mirrored releases. */
|
||||||
|
export const MIRROR_PATH = '/dsh'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalize the mirror's `latest.json` as served by one entry point.
|
||||||
|
* @param payload - the manifest body.
|
||||||
|
* @param host - the entry point that served it.
|
||||||
|
* @returns `{ version, tarballUrl, releaseUrl }`, or undefined when unusable.
|
||||||
|
*/
|
||||||
|
export function parseMirrorManifest(payload, host) {
|
||||||
|
if (payload === null || typeof payload !== 'object' || typeof host !== 'string') return undefined
|
||||||
|
const version = typeof payload.version === 'string' ? payload.version : undefined
|
||||||
|
if (parseSemver(version) === undefined || payload.tarball !== releaseAssetName(version)) return undefined
|
||||||
|
const releaseUrl = typeof payload.releaseUrl === 'string' && /^https:\/\/github\.com\//u.test(payload.releaseUrl) ? payload.releaseUrl : undefined
|
||||||
|
return { version, tarballUrl: `${host}${MIRROR_PATH}/${payload.tarball}`, ...(releaseUrl === undefined ? {} : { releaseUrl }) }
|
||||||
|
}
|
||||||
export const DEFAULT_VERSION_TTL_MS = 5 * 60_000
|
export const DEFAULT_VERSION_TTL_MS = 5 * 60_000
|
||||||
export const DEFAULT_VERSION_TIMEOUT_MS = 10_000
|
export const DEFAULT_VERSION_TIMEOUT_MS = 10_000
|
||||||
export const DEFAULT_UPDATE_TIMEOUT_MS = 180_000
|
export const DEFAULT_UPDATE_TIMEOUT_MS = 180_000
|
||||||
@@ -245,6 +263,7 @@ export function createGeek2APIPluginManager({
|
|||||||
env = process.env,
|
env = process.env,
|
||||||
ownPackageJsonUrl = new URL('../package.json', import.meta.url),
|
ownPackageJsonUrl = new URL('../package.json', import.meta.url),
|
||||||
releaseUrl = GITHUB_LATEST_RELEASE_URL,
|
releaseUrl = GITHUB_LATEST_RELEASE_URL,
|
||||||
|
hosts,
|
||||||
now = Date.now,
|
now = Date.now,
|
||||||
ttlMs = DEFAULT_VERSION_TTL_MS,
|
ttlMs = DEFAULT_VERSION_TTL_MS,
|
||||||
timeoutMs = DEFAULT_VERSION_TIMEOUT_MS,
|
timeoutMs = DEFAULT_VERSION_TIMEOUT_MS,
|
||||||
@@ -257,8 +276,29 @@ export function createGeek2APIPluginManager({
|
|||||||
const launcher = resolveLauncher({ argv, execPath })
|
const launcher = resolveLauncher({ argv, execPath })
|
||||||
let updating = false
|
let updating = false
|
||||||
|
|
||||||
/** The newest release: its version, tarball asset, and page. */
|
/**
|
||||||
const fetchLatest = async signal => {
|
* The newest release from the mirror, through the entry point the pool
|
||||||
|
* prefers. Undefined when no entry point serves a usable manifest.
|
||||||
|
*/
|
||||||
|
const fetchFromMirror = async signal => {
|
||||||
|
if (typeof hosts?.withFailover !== 'function') return undefined
|
||||||
|
try {
|
||||||
|
return await hosts.withFailover(async host => {
|
||||||
|
const response = await boundedFetch(`${host}${MIRROR_PATH}/latest.json`, { headers: { Accept: 'application/json' } }, { fetchImpl, timeoutMs, signal })
|
||||||
|
if (!response.ok) return undefined
|
||||||
|
return parseMirrorManifest(await response.json(), host)
|
||||||
|
}, { signal })
|
||||||
|
} catch (error) {
|
||||||
|
if (signal?.aborted) throw error
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The newest release: mirror first, then GitHub. */
|
||||||
|
const fetchLatest = async signal => (await fetchFromMirror(signal)) ?? fetchFromGitHub(signal)
|
||||||
|
|
||||||
|
/** The newest GitHub release: its version, tarball asset, and page. */
|
||||||
|
const fetchFromGitHub = async signal => {
|
||||||
let response
|
let response
|
||||||
try {
|
try {
|
||||||
response = await boundedFetch(releaseUrl, {
|
response = await boundedFetch(releaseUrl, {
|
||||||
|
|||||||
@@ -420,3 +420,66 @@ test('a release without its tarball is reported but not installed', async () =>
|
|||||||
assert.equal(info.updatable, false)
|
assert.equal(info.updatable, false)
|
||||||
await assert.rejects(() => manager.update(), /^Error: Geek2API plugin release has no package to install$/u)
|
await assert.rejects(() => manager.update(), /^Error: Geek2API plugin release has no package to install$/u)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** A host pool over fixed hosts that fails over on thrown transport errors. */
|
||||||
|
const mirrorPool = hosts => ({
|
||||||
|
current: () => hosts[0],
|
||||||
|
async withFailover(task) {
|
||||||
|
let last
|
||||||
|
for (const host of hosts) {
|
||||||
|
try {
|
||||||
|
return await task(host)
|
||||||
|
} catch (error) {
|
||||||
|
last = error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw last
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
test('the mirror answers first, and the update installs its tarball', async () => {
|
||||||
|
const root = await mkdtemp(join(tmpdir(), 'geek2api-version-mirror-'))
|
||||||
|
const ownPackageJsonUrl = await releaseInstall(root, '1.0.3')
|
||||||
|
const urls = []
|
||||||
|
const calls = []
|
||||||
|
const manager = createGeek2APIPluginManager({
|
||||||
|
env: { DSH_HOME: root },
|
||||||
|
ownPackageJsonUrl,
|
||||||
|
hosts: mirrorPool(['https://down.example', 'https://hk.example']),
|
||||||
|
fetchImpl: async url => {
|
||||||
|
urls.push(url)
|
||||||
|
if (url.startsWith('https://down.example')) throw new TypeError('fetch failed')
|
||||||
|
if (url === 'https://hk.example/dsh/latest.json') {
|
||||||
|
return { ok: true, status: 200, async json() { return { version: '1.0.4', tarball: `${PACKAGE_NAME}-1.0.4.tgz`, releaseUrl: releasePage('1.0.4') } } }
|
||||||
|
}
|
||||||
|
throw new Error(`unexpected ${url}`)
|
||||||
|
},
|
||||||
|
runCommand: async (call, options) => {
|
||||||
|
calls.push(call)
|
||||||
|
return installRecorder(call, options)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const info = await manager.read()
|
||||||
|
assert.equal(info.latest, '1.0.4')
|
||||||
|
assert.equal(info.updatable, true)
|
||||||
|
assert.equal(info.releaseUrl, releasePage('1.0.4'))
|
||||||
|
assert.equal(urls.some(url => url.includes('api.github.com')), false, 'GitHub is not asked when the mirror answers')
|
||||||
|
await manager.update()
|
||||||
|
assert.equal(calls[0].args.at(-1), `${PACKAGE_NAME}@https://hk.example/dsh/${PACKAGE_NAME}-1.0.4.tgz`)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('without a usable mirror the version check falls back to GitHub', async () => {
|
||||||
|
const root = await mkdtemp(join(tmpdir(), 'geek2api-version-fallback-'))
|
||||||
|
const ownPackageJsonUrl = await releaseInstall(root, '1.0.3')
|
||||||
|
const manager = createGeek2APIPluginManager({
|
||||||
|
env: { DSH_HOME: root },
|
||||||
|
ownPackageJsonUrl,
|
||||||
|
hosts: mirrorPool(['https://hk.example']),
|
||||||
|
fetchImpl: async url => {
|
||||||
|
if (url.endsWith('/dsh/latest.json')) return { ok: true, status: 200, async json() { return { version: '1.0.4', tarball: 'something-else.tgz' } } }
|
||||||
|
return registryOk('1.0.5')()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const info = await manager.read()
|
||||||
|
assert.equal(info.latest, '1.0.5')
|
||||||
|
})
|
||||||
Reference in new issue
Block a user