From 57e4dc72aa77795ab70fcf11d274bbedddb36038 Mon Sep 17 00:00:00 2001 From: admin123 Date: Mon, 25 May 2026 10:32:39 +0800 Subject: [PATCH] feat: switch extension updates to COS --- README.md | 1 + dist-release/popup/index.js | 2 +- docs/internal-extension-distribution.md | 16 ++- .../plans/2026-05-25-cos-extension-update.md | 128 ++++++++++++++++++ release/latest.json | 6 +- scripts/write-latest-manifest-data.mjs | 15 ++ scripts/write-latest-manifest.mjs | 16 +-- src/shared/update-config.ts | 2 +- tests/update-config.test.ts | 11 ++ tests/write-latest-manifest-data.test.ts | 29 ++++ 10 files changed, 205 insertions(+), 21 deletions(-) create mode 100644 docs/superpowers/plans/2026-05-25-cos-extension-update.md create mode 100644 scripts/write-latest-manifest-data.mjs create mode 100644 tests/update-config.test.ts create mode 100644 tests/write-latest-manifest-data.test.ts diff --git a/README.md b/README.md index 346b3d3..7533bf8 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ npm run write:latest - 这个压缩包不是给 Chrome 商店上传的 - 它是发给公司内部同事使用的交付包 - 同事收到后需要解压,再到 `chrome://extensions` 中 `Load unpacked` +- COS 发布时,`latest.json` 放在 `star-chart-search-enhancer/latest.json`,ZIP 和 PDF 放在对应版本目录下 --- diff --git a/dist-release/popup/index.js b/dist-release/popup/index.js index 2c2f7b5..49af92e 100644 --- a/dist-release/popup/index.js +++ b/dist-release/popup/index.js @@ -263,7 +263,7 @@ } // src/shared/update-config.ts - var UPDATE_MANIFEST_URL = "https://example.com/star-chart-search-enhancer/latest.json"; + var UPDATE_MANIFEST_URL = "https://wksgx-1343191620.cos.ap-nanjing.myqcloud.com/star-chart-search-enhancer/latest.json"; // src/popup/index.ts async function bootPopup(options = {}) { diff --git a/docs/internal-extension-distribution.md b/docs/internal-extension-distribution.md index 65b3042..d087117 100644 --- a/docs/internal-extension-distribution.md +++ b/docs/internal-extension-distribution.md @@ -23,17 +23,23 @@ The popup checks `src/shared/update-config.ts` for the update manifest URL. Before publishing the COS-based update flow: 1. Upload these files to COS: - - `release/latest.json` - - `release/star-chart-search-enhancer-internal.zip` - - `release/星图增强插件-超简单安装使用指南.pdf` + - `star-chart-search-enhancer/latest.json` + - `star-chart-search-enhancer/releases//star-chart-search-enhancer-internal.zip` + - `star-chart-search-enhancer/releases//星图增强插件-超简单安装使用指南.pdf` 2. Make the COS path publicly readable. -3. Replace the placeholder `UPDATE_MANIFEST_URL` in `src/shared/update-config.ts`. +3. Replace the placeholder `UPDATE_MANIFEST_URL` in `src/shared/update-config.ts` if your COS bucket changes. 4. Rebuild and package the extension. The release manifest can be generated with a real public base URL: ```bash -UPDATE_PUBLIC_BASE_URL="https:///star-chart-search-enhancer/releases/" npm run write:latest +UPDATE_PUBLIC_BASE_URL="https://wksgx-1343191620.cos.ap-nanjing.myqcloud.com/star-chart-search-enhancer/releases/" npm run write:latest +``` + +Quick access check: + +```bash +curl -I https://wksgx-1343191620.cos.ap-nanjing.myqcloud.com/star-chart-search-enhancer/latest.json ``` ## Coworker Install Steps diff --git a/docs/superpowers/plans/2026-05-25-cos-extension-update.md b/docs/superpowers/plans/2026-05-25-cos-extension-update.md new file mode 100644 index 0000000..b99babe --- /dev/null +++ b/docs/superpowers/plans/2026-05-25-cos-extension-update.md @@ -0,0 +1,128 @@ +# COS Extension Update Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Point the popup update flow at the real COS release bucket and keep the generated release manifest, docs, and tests aligned with that COS-based distribution path. + +**Architecture:** Reuse the existing update-check flow already in `src/shared/update-check.ts`, `src/popup/index.ts`, `src/popup/view.ts`, and `src/background/index.ts`. The only behavior change is the source of truth: the popup should fetch a stable COS-hosted `latest.json`, while `scripts/write-latest-manifest.mjs` should keep generating versioned asset URLs under the COS release folder. Everything else stays manual and user-driven. + +**Tech Stack:** TypeScript, Chrome MV3, Vitest, Node.js ESM scripts, Tencent COS public HTTPS URLs + +--- + +### Task 1: Lock the popup manifest URL to COS + +**Files:** +- Modify: `src/shared/update-config.ts` +- Test: `tests/update-config.test.ts` + +- [ ] **Step 1: Write the failing URL test** + +Add a small test that asserts `UPDATE_MANIFEST_URL` points at the stable COS-hosted `latest.json` URL for this bucket: + +```ts +expect(UPDATE_MANIFEST_URL).toBe( + "https://wksgx-1343191620.cos.ap-nanjing.myqcloud.com/star-chart-search-enhancer/latest.json" +); +``` + +- [ ] **Step 2: Run the focused test** + +Run: + +```bash +npm test -- tests/update-config.test.ts +``` + +Expected: FAIL because the current constant still uses the placeholder example URL. + +- [ ] **Step 3: Update the constant** + +Replace the placeholder string in `src/shared/update-config.ts` with the COS `latest.json` URL above. + +- [ ] **Step 4: Verify** + +Run: + +```bash +npm test -- tests/update-config.test.ts tests/popup-entry.test.ts +``` + +Expected: PASS. + +### Task 2: Generate release assets from the COS base + +**Files:** +- Modify: `scripts/write-latest-manifest.mjs` +- Modify: `release/latest.json` +- Test: `tests/update-check.test.ts` + +- [ ] **Step 1: Write a manifest generation regression test** + +Add or extend a test that proves the generated manifest uses the COS release base for assets, not `example.com`. Use the COS base: + +```ts +https://wksgx-1343191620.cos.ap-nanjing.myqcloud.com/star-chart-search-enhancer/releases/0.2.0421.2 +``` + +Assert that `zipUrl` and `guideUrl` are derived from that base. + +- [ ] **Step 2: Run the focused test** + +Run: + +```bash +npm test -- tests/update-check.test.ts +``` + +Expected: FAIL until the generator default points at COS. + +- [ ] **Step 3: Update the generator default** + +Change `publicBaseUrl` in `scripts/write-latest-manifest.mjs` to default to the COS release base for this bucket and region, while keeping `UPDATE_PUBLIC_BASE_URL` as the override path for future releases. + +- [ ] **Step 4: Regenerate the tracked manifest** + +Run: + +```bash +npm run write:latest +``` + +Then confirm `release/latest.json` contains the COS URLs. + +- [ ] **Step 5: Verify** + +Run: + +```bash +npm test -- tests/update-check.test.ts tests/popup-entry.test.ts tests/background-index.test.ts +``` + +Expected: PASS. + +### Task 3: Update distribution docs and verify COS access + +**Files:** +- Modify: `docs/internal-extension-distribution.md` +- Modify: `README.md` + +- [ ] **Step 1: Update the release instructions** + +Document the stable manifest URL, the versioned asset base, and the upload flow to COS. Keep the user-facing manual install steps unchanged. + +- [ ] **Step 2: Add the COS verification command** + +Document a `curl -I` check for the public `latest.json` URL and the uploaded ZIP/PDF so a failed COS ACL is caught before release. + +- [ ] **Step 3: Run the final verification** + +Run: + +```bash +npm test +npm run build:release +``` + +Expected: PASS, and the generated release bundle should still open the popup update card correctly. + diff --git a/release/latest.json b/release/latest.json index 5f155bf..a90ae94 100644 --- a/release/latest.json +++ b/release/latest.json @@ -1,11 +1,11 @@ { - "guideUrl": "https://example.com/star-chart-search-enhancer/releases/0.2.0421.2/星图增强插件-超简单安装使用指南.pdf", + "guideUrl": "https://wksgx-1343191620.cos.ap-nanjing.myqcloud.com/star-chart-search-enhancer/releases/0.2.0421.2/星图增强插件-超简单安装使用指南.pdf", "latestVersion": "0.2.0421.2", "minSupportedVersion": "0.2.0421.2", - "publishedAt": "2026-05-19", + "publishedAt": "2026-05-25", "releaseNotes": [ "支持在插件弹窗中检查新版本", "支持一键下载最新版插件压缩包和使用说明" ], - "zipUrl": "https://example.com/star-chart-search-enhancer/releases/0.2.0421.2/star-chart-search-enhancer-internal.zip" + "zipUrl": "https://wksgx-1343191620.cos.ap-nanjing.myqcloud.com/star-chart-search-enhancer/releases/0.2.0421.2/star-chart-search-enhancer-internal.zip" } diff --git a/scripts/write-latest-manifest-data.mjs b/scripts/write-latest-manifest-data.mjs new file mode 100644 index 0000000..02a2006 --- /dev/null +++ b/scripts/write-latest-manifest-data.mjs @@ -0,0 +1,15 @@ +export function createLatestManifest(options) { + const publishedAt = options.publishedAt ?? new Date().toISOString().slice(0, 10); + + return { + guideUrl: `${options.publicBaseUrl}/星图增强插件-超简单安装使用指南.pdf`, + latestVersion: options.latestVersion, + minSupportedVersion: options.minSupportedVersion, + publishedAt, + releaseNotes: [ + "支持在插件弹窗中检查新版本", + "支持一键下载最新版插件压缩包和使用说明" + ], + zipUrl: `${options.publicBaseUrl}/star-chart-search-enhancer-internal.zip` + }; +} diff --git a/scripts/write-latest-manifest.mjs b/scripts/write-latest-manifest.mjs index dc68d31..56d3ff3 100644 --- a/scripts/write-latest-manifest.mjs +++ b/scripts/write-latest-manifest.mjs @@ -2,6 +2,7 @@ import { mkdir, writeFile } from "node:fs/promises"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { createManifest } from "./manifest.mjs"; +import { createLatestManifest } from "./write-latest-manifest-data.mjs"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -11,19 +12,12 @@ const releaseManifest = createManifest({ target: "release" }); const latestVersion = process.env.LATEST_VERSION ?? releaseManifest.version; const publicBaseUrl = process.env.UPDATE_PUBLIC_BASE_URL ?? - `https://example.com/star-chart-search-enhancer/releases/${latestVersion}`; - -const latestManifest = { - guideUrl: `${publicBaseUrl}/星图增强插件-超简单安装使用指南.pdf`, + `https://wksgx-1343191620.cos.ap-nanjing.myqcloud.com/star-chart-search-enhancer/releases/${latestVersion}`; +const latestManifest = createLatestManifest({ latestVersion, minSupportedVersion: releaseManifest.version, - publishedAt: new Date().toISOString().slice(0, 10), - releaseNotes: [ - "支持在插件弹窗中检查新版本", - "支持一键下载最新版插件压缩包和使用说明" - ], - zipUrl: `${publicBaseUrl}/star-chart-search-enhancer-internal.zip` -}; + publicBaseUrl +}); await mkdir(releaseDir, { recursive: true }); await writeFile( diff --git a/src/shared/update-config.ts b/src/shared/update-config.ts index 360e599..7ac3560 100644 --- a/src/shared/update-config.ts +++ b/src/shared/update-config.ts @@ -1,2 +1,2 @@ export const UPDATE_MANIFEST_URL = - "https://example.com/star-chart-search-enhancer/latest.json"; + "https://wksgx-1343191620.cos.ap-nanjing.myqcloud.com/star-chart-search-enhancer/latest.json"; diff --git a/tests/update-config.test.ts b/tests/update-config.test.ts new file mode 100644 index 0000000..77f0df1 --- /dev/null +++ b/tests/update-config.test.ts @@ -0,0 +1,11 @@ +import { describe, expect, test } from "vitest"; + +import { UPDATE_MANIFEST_URL } from "../src/shared/update-config"; + +describe("update-config", () => { + test("points popup update checks at the COS latest manifest", () => { + expect(UPDATE_MANIFEST_URL).toBe( + "https://wksgx-1343191620.cos.ap-nanjing.myqcloud.com/star-chart-search-enhancer/latest.json" + ); + }); +}); diff --git a/tests/write-latest-manifest-data.test.ts b/tests/write-latest-manifest-data.test.ts new file mode 100644 index 0000000..36064b3 --- /dev/null +++ b/tests/write-latest-manifest-data.test.ts @@ -0,0 +1,29 @@ +import { describe, expect, test } from "vitest"; + +import { createLatestManifest } from "../scripts/write-latest-manifest-data.mjs"; + +describe("write-latest-manifest-data", () => { + test("builds COS asset URLs from the release base", () => { + expect( + createLatestManifest({ + latestVersion: "0.2.0421.2", + minSupportedVersion: "0.2.0421.2", + publicBaseUrl: + "https://wksgx-1343191620.cos.ap-nanjing.myqcloud.com/star-chart-search-enhancer/releases/0.2.0421.2", + publishedAt: "2026-05-25" + }) + ).toEqual({ + guideUrl: + "https://wksgx-1343191620.cos.ap-nanjing.myqcloud.com/star-chart-search-enhancer/releases/0.2.0421.2/星图增强插件-超简单安装使用指南.pdf", + latestVersion: "0.2.0421.2", + minSupportedVersion: "0.2.0421.2", + publishedAt: "2026-05-25", + releaseNotes: [ + "支持在插件弹窗中检查新版本", + "支持一键下载最新版插件压缩包和使用说明" + ], + zipUrl: + "https://wksgx-1343191620.cos.ap-nanjing.myqcloud.com/star-chart-search-enhancer/releases/0.2.0421.2/star-chart-search-enhancer-internal.zip" + }); + }); +});