Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix: keep deployment forks aligned with upstream

tianma-if55f66465df56
diff --git a/.github/workflows/deploy-tools.yml b/.github/workflows/deploy-tools.yml
index 351edcaf..166e35d9 100644
--- a/.github/workflows/deploy-tools.yml
+++ b/.github/workflows/deploy-tools.yml
@@ -6,6 +6,7 @@ on:
- "scripts/cloudflare-deploy.mjs"
- "scripts/wrangler-output.mjs"
- "scripts/run-wrangler.mjs"
+ - "scripts/upstream-sync-plan.mjs"
- "scripts/wrangler-runner.mjs"
- "scripts/verify-deployment.mjs"
- ".dev.vars.example"
@@ -23,6 +24,7 @@ on:
- "scripts/cloudflare-deploy.mjs"
- "scripts/wrangler-output.mjs"
- "scripts/run-wrangler.mjs"
+ - "scripts/upstream-sync-plan.mjs"
- "scripts/wrangler-runner.mjs"
- "scripts/verify-deployment.mjs"
- ".dev.vars.example"
diff --git a/.github/workflows/sync-edgeever-upstream.yml b/.github/workflows/sync-edgeever-upstream.yml
index dee6c717..de6375e8 100644
--- a/.github/workflows/sync-edgeever-upstream.yml
+++ b/.github/workflows/sync-edgeever-upstream.yml
@@ -1,9 +1,9 @@
name: Update deployed EdgeEver
# Keeps a deployment Fork aligned with upstream EdgeEver.
-# 99.99% of forks never change application code — they only need a stable
-# mirror of the official release (or edge main) plus a Cloudflare rebuild.
-# Customized forks still merge when needed and fail closed on conflicts.
+# Deployment Forks are read-only mirrors by default: when content differs,
+# main resets to the selected Release (or edge main) and triggers Cloudflare.
+# The rare customized Fork must explicitly opt in to merge preservation.
on:
schedule:
@@ -35,7 +35,7 @@ concurrency:
jobs:
update:
if: github.repository != 'tianma-if/edgeever'
- name: Sync, verify, and publish
+ name: Align and publish upstream
runs-on: ubuntu-latest
timeout-minutes: 20
env:
@@ -43,6 +43,7 @@ jobs:
UPSTREAM_REPOSITORY: tianma-if/edgeever
UPDATE_CHANNEL: ${{ inputs.channel || vars.EDGE_EVER_UPDATE_CHANNEL || 'stable' }}
FORCE_REDEPLOY: ${{ inputs.force_redeploy || false }}
+ PRESERVE_FORK_CHANGES: ${{ vars.EDGE_EVER_PRESERVE_FORK_CHANGES || 'false' }}
steps:
- name: Checkout deployed repository
@@ -94,64 +95,40 @@ jobs:
head_version="unknown"
fi
- # Product content diff ignores only this updater workflow so deploy
- # forks that only differ in history or the updater file can reset.
- content_diff="$(git diff --name-only "${target_commit}" HEAD -- ':!.github/workflows/sync-edgeever-upstream.yml' || true)"
-
- root_commit="$(git rev-list --max-parents=0 HEAD | head -n 1)"
- root_subject="$(git show -s --format=%s "${root_commit}")"
- non_workflow_changes="$(git diff --name-only "${root_commit}" HEAD -- ':!.github/workflows/sync-edgeever-upstream.yml' || true)"
- bootstrap_import=false
- if [ "${root_subject}" = "source repo import" ] && [ -z "${non_workflow_changes}" ]; then
- bootstrap_import=true
+ # Updater-only differences do not trigger a product update.
+ content_diff="$(git diff --name-only "${target_commit}" HEAD -- ':!.github/workflows/sync-edgeever-upstream.yml' ':!scripts/upstream-sync-plan.mjs' || true)"
+ content_matches_target=false
+ if [ -z "${content_diff}" ]; then
+ content_matches_target=true
fi
- update_required=false
- align_mode=none
- reason=""
- republish_only=false
+ fork_mode=mirror
+ if [ "${PRESERVE_FORK_CHANGES}" = "true" ]; then
+ fork_mode=customized
+ fi
- if [ -z "${content_diff}" ]; then
- update_required=false
- align_mode=none
- if [ "${head_commit}" = "${target_commit}" ]; then
- reason=already_on_target
- else
- reason=content_matches_target
- fi
- if [ "${FORCE_REDEPLOY}" = "true" ]; then
- republish_only=true
- fi
- elif git merge-base --is-ancestor HEAD "${target_commit}" 2>/dev/null; then
- # Strictly behind upstream target — safe fast-forward via reset.
- update_required=true
- align_mode=reset
- reason=behind_target
- elif [ "${bootstrap_import}" = "true" ]; then
- # Cloudflare import history with no app customizations.
- update_required=true
- align_mode=reset
- reason=bootstrap_import
- elif git merge-base --is-ancestor "${target_commit}" HEAD 2>/dev/null; then
- # Target is already in history but working tree still differs
- # (should be rare). Prefer merge to preserve any local tip commits.
- update_required=true
- align_mode=merge
- reason=ahead_with_content_drift
- else
- # Diverged or unrelated history with real content differences.
- # Deploy-only forks (only the updater workflow ever changed) reset;
- # customized forks merge and fail closed on conflicts.
- if [ -z "${non_workflow_changes}" ] || [ "${bootstrap_import}" = "true" ]; then
- update_required=true
- align_mode=reset
- reason=deploy_mirror_reset
- else
- update_required=true
- align_mode=merge
- reason=customized_merge
- fi
+ head_equals_target=false
+ if [ "${head_commit}" = "${target_commit}" ]; then
+ head_equals_target=true
+ fi
+ head_is_ancestor_of_target=false
+ if git merge-base --is-ancestor HEAD "${target_commit}" 2>/dev/null; then
+ head_is_ancestor_of_target=true
fi
+ target_is_ancestor_of_head=false
+ if git merge-base --is-ancestor "${target_commit}" HEAD 2>/dev/null; then
+ target_is_ancestor_of_head=true
+ fi
+
+ IFS=$'\t' read -r update_required align_mode reason republish_only < <(
+ EDGE_SYNC_CONTENT_MATCHES_TARGET="${content_matches_target}" \
+ EDGE_SYNC_FORCE_REDEPLOY="${FORCE_REDEPLOY}" \
+ EDGE_SYNC_HEAD_EQUALS_TARGET="${head_equals_target}" \
+ EDGE_SYNC_HEAD_IS_ANCESTOR_OF_TARGET="${head_is_ancestor_of_target}" \
+ EDGE_SYNC_PRESERVE_FORK_CHANGES="${PRESERVE_FORK_CHANGES}" \
+ EDGE_SYNC_TARGET_IS_ANCESTOR_OF_HEAD="${target_is_ancestor_of_head}" \
+ node scripts/upstream-sync-plan.mjs
+ )
{
echo "target_ref=${target_ref}"
@@ -171,6 +148,7 @@ jobs:
echo "| Field | Value |"
echo "| --- | --- |"
echo "| Channel | \`${UPDATE_CHANNEL}\` |"
+ echo "| Fork mode | \`${fork_mode}\` |"
echo "| Upstream target | \`${target_ref}\` (\`${target_commit:0:12}\`, v${target_version}) |"
echo "| Fork main before | \`${head_commit:0:12}\` (v${head_version}) |"
echo "| Decision | \`${reason}\` / align=\`${align_mode}\` / update=\`${update_required}\` / republish=\`${republish_only}\` |"
@@ -185,14 +163,17 @@ jobs:
behind_target)
echo "**Fork is behind upstream.** Aligning with a hard reset to the target commit (deploy-mirror path)."
;;
- bootstrap_import)
- echo "**Cloudflare import history detected.** Resetting onto upstream target so the fork becomes a normal EdgeEver history."
- ;;
deploy_mirror_reset)
- echo "**Deploy-only fork with diverged history.** Resetting onto upstream target."
+ echo "**Deployment mirror differs from upstream.** Resetting onto the selected target; no Fork code is preserved in the default mode."
+ ;;
+ deploy_mirror_ahead)
+ echo "**Deploy-only fork is ahead of the selected upstream target.** Resetting onto that target."
+ ;;
+ customized_contains_target)
+ echo "**Opt-in customized fork already contains the upstream target.** Preserving its application changes without another merge."
;;
- customized_merge|ahead_with_content_drift)
- echo "**Local application changes detected.** Merging upstream target and leaving production unchanged if verification fails."
+ customized_merge)
+ echo "**Opt-in customized fork.** Merging upstream target and leaving production unchanged if verification fails."
;;
*)
echo "Decision reason: \`${reason}\`."
@@ -203,7 +184,7 @@ jobs:
echo "\`force_redeploy\` is set: will push an empty commit so Cloudflare Workers Builds runs again."
fi
echo ""
- echo "Prefer this workflow over GitHub **Sync fork**. Sync fork tracks upstream \`main\` history and can make the next stable run look like a no-op even when you expected a merge step to run."
+ echo "Prefer this workflow over GitHub **Sync fork**. The default mirror mode intentionally owns \`main\` and resets it to the selected upstream target."
} >> "${GITHUB_STEP_SUMMARY}"
echo "channel=${UPDATE_CHANNEL} target=${target_ref}@${target_commit:0:12} (v${target_version}) head=${head_commit:0:12} (v${head_version}) reason=${reason} align=${align_mode} update=${update_required} republish=${republish_only}"
@@ -230,7 +211,7 @@ jobs:
if ! git merge --no-edit -m "chore: update EdgeEver from ${TARGET_REF}" "${TARGET_COMMIT}"; then
git merge --abort || true
echo "Merge from ${TARGET_REF} conflicted with local application changes." >&2
- echo "Resolve the customized fork manually, or reset main to upstream if you do not need local code changes." >&2
+ echo "Resolve the customized fork manually, or remove EDGE_EVER_PRESERVE_FORK_CHANGES to return to mirror mode." >&2
exit 1
fi
echo "Merged ${TARGET_REF} (${TARGET_COMMIT:0:12}) because ${REASON}."
@@ -242,18 +223,18 @@ jobs:
esac
- name: Set up Bun
- if: steps.upstream.outputs.update_required == 'true'
+ if: steps.upstream.outputs.align_mode == 'merge'
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- - name: Verify update
- if: steps.upstream.outputs.update_required == 'true'
+ - name: Verify customized merge
+ if: steps.upstream.outputs.align_mode == 'merge'
run: |
set -euo pipefail
bun install --frozen-lockfile
bun run db:migrate:local
- bun test
+ bun test --path-ignore-patterns='tests/e2e/**'
bun run typecheck
bun run build
@@ -265,6 +246,7 @@ jobs:
UPDATE_REQUIRED: ${{ steps.upstream.outputs.update_required }}
REPUBLISH_ONLY: ${{ steps.upstream.outputs.republish_only }}
ALIGN_MODE: ${{ steps.upstream.outputs.align_mode }}
+ REASON: ${{ steps.upstream.outputs.reason }}
run: |
set -euo pipefail
git config user.name "edgeever-updater[bot]"
@@ -279,10 +261,16 @@ jobs:
fi
if [ "${ALIGN_MODE}" = "reset" ]; then
- # Deploy mirrors may rewrite short import/divergent history.
- git push --force-with-lease origin HEAD:main
- echo "mode=force_with_lease" >> "${GITHUB_OUTPUT}"
- echo "Published reset main for ${TARGET_REF}."
+ if [ "${REASON}" = "behind_target" ]; then
+ git push origin HEAD:main
+ echo "mode=fast_forward" >> "${GITHUB_OUTPUT}"
+ echo "Published fast-forward main for ${TARGET_REF}."
+ else
+ # Diverged mirrors require a guarded history rewrite.
+ git push --force-with-lease origin HEAD:main
+ echo "mode=force_with_lease" >> "${GITHUB_OUTPUT}"
+ echo "Published reset main for ${TARGET_REF}."
+ fi
else
git push origin HEAD:main
echo "mode=push" >> "${GITHUB_OUTPUT}"
diff --git a/README.md b/README.md
index 6e8948e4..1d43f593 100644
--- a/README.md
+++ b/README.md
@@ -68,9 +68,11 @@ Copy this prompt into an AI Agent configured with GitHub and Cloudflare MCP serv
Deploy EdgeEver online:
1. Fork https://github.com/tianma-if/edgeever.
2. Import the Fork into Cloudflare Workers & Pages.
-3. Configure D1, R2, `EDGE_EVER_AUTH_USERNAME` (prefilled as `admin`, customizable), the `EDGE_EVER_AUTH_PASSWORD` Worker Secret, and the production `main` build.
+3. Configure D1, R2, `EDGE_EVER_AUTH_USERNAME` (prefilled as `admin`, customizable),
+ the `EDGE_EVER_AUTH_PASSWORD` Worker Secret, and the production `main` build.
4. Start the first build and verify `/api/health`, `/api/openapi.json`, and login.
-5. Enable and run `Update deployed EdgeEver` once.
+5. Enable and manually run the GitHub Actions workflow named `Update deployed EdgeEver`
+ once so the Fork can automatically receive the latest EdgeEver features and fixes.
```
> Detailed requirements: [AI Agent Cloudflare Deployment](docs/agent-deploy-cloudflare.md).
@@ -79,7 +81,7 @@ Deploy EdgeEver online:
Complete setup in 4 simple web steps:
-1. **Fork the Repository**: Click **Fork** at the top right of GitHub to fork EdgeEver into your personal account.
+1. **Fork & Enable Actions**: Fork EdgeEver into your personal account, then open the Fork's **Actions** tab and click **I understand my workflows, go ahead and enable them** so the GitHub Actions workflow named **Update deployed EdgeEver** can run automatically, keeping you up to date with the latest **EdgeEver** features and fixes.
2. **Import into Cloudflare**: Log into the Cloudflare Dashboard, navigate to **Workers & Pages**, and choose to import your Fork repository.
3. **Bind Resources & Credentials**: Bind the D1 database (`DB`), R2 bucket (`RESOURCES`), set `EDGE_EVER_AUTH_USERNAME` (default `admin`, customizable), and set the Worker Secret `EDGE_EVER_AUTH_PASSWORD` as your admin password.
4. **Build & Verify**: Start the first build with default settings. Once complete, visit `/api/health` to verify a `200` response before logging in.
diff --git a/README.zh-CN.md b/README.zh-CN.md
index bd40658c..58ba00df 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -68,9 +68,11 @@ EdgeEver 采用纯 Serverless 架构,完全运行在 Cloudflare 免费配额
请在线完成 EdgeEver 部署:
1. Fork https://github.com/tianma-if/edgeever。
2. 将这个 Fork 导入 Cloudflare Workers & Pages。
-3. 配置 D1、R2、`EDGE_EVER_AUTH_USERNAME`(预填为 `admin`,可自定义)、`EDGE_EVER_AUTH_PASSWORD` Worker Secret 和生产环境 `main` 构建。
+3. 配置 D1、R2、`EDGE_EVER_AUTH_USERNAME`(预填为 `admin`,可自定义)、
+ `EDGE_EVER_AUTH_PASSWORD` Worker Secret 和生产环境 `main` 构建。
4. 启动首次构建,验证 `/api/health`、`/api/openapi.json` 和登录。
-5. 启用并手动运行一次 `Update deployed EdgeEver`。
+5. 启用并手动运行一次名为 `Update deployed EdgeEver` 的 GitHub Actions 工作流,
+ 以便后续自动同步更新,持续获得 EdgeEver 最新的产品特性和问题修复。
```
> 详细约定与要求请查看:[AI Agent 在线部署约定](docs/agent-deploy-cloudflare.zh-CN.md)。
@@ -79,7 +81,7 @@ EdgeEver 采用纯 Serverless 架构,完全运行在 Cloudflare 免费配额
仅需在网页端完成 4 步极简配置:
-1. **Fork 仓库**:在 GitHub 点击右上角 **Fork**,将项目 Fork 到您的个人账户下。
+1. **Fork 仓库并启用 Actions**:将项目 Fork 到您的个人账户后,进入 Fork 的 **Actions** 标签页,点击 **I understand my workflows, go ahead and enable them**,确保名为 **Update deployed EdgeEver** 的 GitHub Actions 工作流能够自动运行,从而持续获得 **EdgeEver** 最新的产品特性和问题修复。
2. **导入 Cloudflare**:登录 Cloudflare 控制台,进入 **Workers & Pages**,选择导入该 Fork 仓库。
3. **绑定资源与登录凭据**:绑定 D1 数据库(`DB`)、R2 存储桶(`RESOURCES`),设置 `EDGE_EVER_AUTH_USERNAME`(默认为 `admin`,可自定义),并添加 Worker Secret `EDGE_EVER_AUTH_PASSWORD` 作为管理员登录密码。
4. **启动构建与验证**:使用默认构建配置启动首次构建,部署完成后访问 `/api/health` 确认返回 `200` 即可开始使用。
diff --git a/docs/agent-deploy-cloudflare.md b/docs/agent-deploy-cloudflare.md
index d79e3cd4..3426aebb 100644
--- a/docs/agent-deploy-cloudflare.md
+++ b/docs/agent-deploy-cloudflare.md
@@ -13,6 +13,8 @@ This document defines the standard operating specifications and conventions for
2. **Enable Workflow**
- In the **Actions** tab of the Forked repository, enable the **Update deployed EdgeEver** automatic update workflow (required on public forks: scheduled workflows are disabled by default).
+ - An ordinary Fork is a deployment mirror by default. No update variable is required: the workflow owns `main` and may reset it to the selected upstream Release before triggering Cloudflare.
+ - Only a Fork that intentionally maintains application-code changes should create the Actions repository variable `EDGE_EVER_PRESERVE_FORK_CHANGES=true`. This opts into merges and requires the owner to resolve future conflicts; it is not needed for normal deployments.
3. **Cloudflare Project Import**
- Log into the Cloudflare **Workers & Pages** console and import the Fork repository.
@@ -43,6 +45,6 @@ This document defines the standard operating specifications and conventions for
7. **Verify Upstream Update Channel**
- Manually trigger **Update deployed EdgeEver** once in the Fork's **Actions** tab.
- - Open the job **Summary** and confirm it reports the upstream target (stable Release or edge `main`) and either an update publish or an explicit *already aligned* result.
+ - Open the job **Summary** and confirm it reports Fork mode `mirror`, the upstream target (stable Release or edge `main`), and either an update publish or an explicit *already aligned* result.
- Confirm Cloudflare **Deployments** builds the published `main` commit when a push occurred.
- - Do not rely on GitHub **Sync fork** for routine upgrades; use this workflow as the deploy-mirror path.
+ - Do not edit deployment files or rely on GitHub **Sync fork** for routine upgrades; the workflow is the only synchronization path needed by a normal deployment Fork.
diff --git a/docs/agent-deploy-cloudflare.zh-CN.md b/docs/agent-deploy-cloudflare.zh-CN.md
index ca760e7f..2567981b 100644
--- a/docs/agent-deploy-cloudflare.zh-CN.md
+++ b/docs/agent-deploy-cloudflare.zh-CN.md
@@ -13,6 +13,8 @@
2. **启用工作流**
- 在 Fork 仓库的 **Actions** 标签页中,启用 **Update deployed EdgeEver** 自动更新工作流(公共 Fork 上定时任务默认关闭,必须手动启用)。
+ - 普通 Fork 默认作为部署镜像,无需配置任何更新变量:工作流负责管理 `main`,可将其重置到选定的上游 Release,再触发 Cloudflare。
+ - 只有明确维护了应用代码修改的 Fork,才应创建 Actions 仓库变量 `EDGE_EVER_PRESERVE_FORK_CHANGES=true`。启用后改为 merge,并由仓库所有者处理未来冲突;普通部署无需设置。
3. **Cloudflare 项目导入**
- 登录 Cloudflare **Workers & Pages** 控制台,导入该 Fork 仓库。
@@ -43,6 +45,6 @@
7. **验证上游更新通道**
- 在 Fork 的 **Actions** 中手动运行一次 **Update deployed EdgeEver**。
- - 打开 Job **Summary**,确认已显示上游目标(stable Release 或 edge `main`),以及「已发布更新」或明确的「已对齐」结果。
+ - 打开 Job **Summary**,确认 Fork mode 为 `mirror`,并显示上游目标(stable Release 或 edge `main`),以及「已发布更新」或明确的「已对齐」结果。
- 若发生了 push,确认 Cloudflare **Deployments** 构建的是对应的 `main` commit。
- - 日常升级不要依赖 GitHub **Sync fork**,请以本工作流作为部署镜像同步路径。
+ - 普通部署 Fork 不应修改部署文件,日常升级也不要依赖 GitHub **Sync fork**;本工作流就是唯一需要的同步路径。
diff --git a/package.json b/package.json
index 2d67e858..7ac7372d 100644
--- a/package.json
+++ b/package.json
@@ -8,6 +8,7 @@
"packages/*"
],
"scripts": {
+ "test": "bun test --path-ignore-patterns='tests/e2e/**'",
"dev": "bun run dev:local",
"dev:api": "bun run dev:api:local",
"dev:local": "bun scripts/local-dev.mjs start local",
diff --git a/scripts/upstream-sync-plan.mjs b/scripts/upstream-sync-plan.mjs
new file mode 100644
index 00000000..1467c8e0
--- /dev/null
+++ b/scripts/upstream-sync-plan.mjs
@@ -0,0 +1,73 @@
+import { resolve } from "node:path";
+import { fileURLToPath } from "node:url";
+
+const noUpdate = (reason, forceRedeploy) => ({
+ alignMode: "none",
+ reason,
+ republishOnly: forceRedeploy,
+ updateRequired: false,
+});
+
+const update = (alignMode, reason) => ({
+ alignMode,
+ reason,
+ republishOnly: false,
+ updateRequired: true,
+});
+
+export function decideUpstreamSync({
+ contentMatchesTarget,
+ forceRedeploy,
+ headEqualsTarget,
+ headIsAncestorOfTarget,
+ preserveForkChanges,
+ targetIsAncestorOfHead,
+}) {
+ if (contentMatchesTarget) {
+ return noUpdate(headEqualsTarget ? "already_on_target" : "content_matches_target", forceRedeploy);
+ }
+
+ if (!preserveForkChanges) {
+ if (headIsAncestorOfTarget) {
+ return update("reset", "behind_target");
+ }
+ if (targetIsAncestorOfHead) {
+ return update("reset", "deploy_mirror_ahead");
+ }
+ return update("reset", "deploy_mirror_reset");
+ }
+
+ if (headIsAncestorOfTarget) {
+ return update("reset", "behind_target");
+ }
+ if (targetIsAncestorOfHead) {
+ return noUpdate("customized_contains_target", forceRedeploy);
+ }
+ return update("merge", "customized_merge");
+}
+
+function readBooleanEnvironment(name) {
+ const value = process.env[name];
+ if (value === "true") return true;
+ if (value === "false") return false;
+ throw new Error(`${name} must be either true or false`);
+}
+
+function runCli() {
+ const plan = decideUpstreamSync({
+ contentMatchesTarget: readBooleanEnvironment("EDGE_SYNC_CONTENT_MATCHES_TARGET"),
+ forceRedeploy: readBooleanEnvironment("EDGE_SYNC_FORCE_REDEPLOY"),
+ headEqualsTarget: readBooleanEnvironment("EDGE_SYNC_HEAD_EQUALS_TARGET"),
+ headIsAncestorOfTarget: readBooleanEnvironment("EDGE_SYNC_HEAD_IS_ANCESTOR_OF_TARGET"),
+ preserveForkChanges: readBooleanEnvironment("EDGE_SYNC_PRESERVE_FORK_CHANGES"),
+ targetIsAncestorOfHead: readBooleanEnvironment("EDGE_SYNC_TARGET_IS_ANCESTOR_OF_HEAD"),
+ });
+ process.stdout.write(
+ `${plan.updateRequired}\t${plan.alignMode}\t${plan.reason}\t${plan.republishOnly}\n`,
+ );
+}
+
+const invokedPath = process.argv[1] ? resolve(process.argv[1]) : "";
+if (invokedPath === fileURLToPath(import.meta.url)) {
+ runCli();
+}
diff --git a/tests/deployment-entrypoints.test.ts b/tests/deployment-entrypoints.test.ts
index a7e9f4e1..85bc69f6 100644
--- a/tests/deployment-entrypoints.test.ts
+++ b/tests/deployment-entrypoints.test.ts
@@ -9,6 +9,7 @@ import {
} from "node:fs";
import { resolve } from "node:path";
import { tmpdir } from "node:os";
+import { decideUpstreamSync } from "../scripts/upstream-sync-plan.mjs";
const repositoryRoot = resolve(import.meta.dir, "..");
const readRepositoryFile = (path: string) => readFileSync(resolve(repositoryRoot, path), "utf8");
@@ -157,6 +158,8 @@ describe("Cloudflare deployment entrypoints", () => {
test("deployed repositories receive guarded daily upstream updates", () => {
const workflow = readRepositoryFile(".github/workflows/sync-edgeever-upstream.yml");
+ const packageJson = JSON.parse(readRepositoryFile("package.json"));
+ const scripts = packageJson.scripts as Record<string, string>;
expect(workflow).toContain("github.repository != 'tianma-if/edgeever'");
expect(workflow).toContain("UPSTREAM_REPOSITORY: tianma-if/edgeever");
@@ -167,19 +170,99 @@ describe("Cloudflare deployment entrypoints", () => {
expect(workflow).toContain("edge)");
expect(workflow).toContain("force_redeploy");
expect(workflow).toContain("bun run db:migrate:local");
- expect(workflow).toContain("bun test");
+ expect(scripts.test).toBe("bun test --path-ignore-patterns='tests/e2e/**'");
+ expect(workflow).toContain(scripts.test);
+ expect(workflow.match(/if: steps\.upstream\.outputs\.align_mode == 'merge'/g)).toHaveLength(2);
expect(workflow).toContain("git push origin HEAD:main");
expect(workflow).toContain("git push --force-with-lease origin HEAD:main");
+ expect(workflow).toContain('if [ "${REASON}" = "behind_target" ]');
+ expect(workflow).toContain("mode=fast_forward");
expect(workflow).toContain("git reset --hard");
- expect(workflow).toContain("source repo import");
expect(workflow).toContain("content_matches_target");
expect(workflow).toContain("already_on_target");
+ expect(workflow).toContain("fork_mode=mirror");
expect(workflow).toContain("GITHUB_STEP_SUMMARY");
expect(workflow).toContain("EDGE_EVER_CLOUDFLARE_DEPLOY_HOOK_URL");
- expect(workflow).toContain("non_workflow_changes");
+ expect(workflow).toContain("EDGE_EVER_PRESERVE_FORK_CHANGES");
+ expect(workflow).toContain("PRESERVE_FORK_CHANGES");
+ expect(workflow).not.toContain("upstream_merge_base");
+ expect(workflow).not.toContain("local_app_changes");
+ expect(workflow).toContain("scripts/upstream-sync-plan.mjs");
expect(workflow).toContain("Prefer this workflow over GitHub **Sync fork**");
});
+ test("keeps a forced-redeploy commit on the deploy-mirror update path", () => {
+ expect(
+ decideUpstreamSync({
+ contentMatchesTarget: false,
+ forceRedeploy: false,
+ headEqualsTarget: false,
+ headIsAncestorOfTarget: false,
+ preserveForkChanges: false,
+ targetIsAncestorOfHead: false,
+ }),
+ ).toEqual({
+ alignMode: "reset",
+ reason: "deploy_mirror_reset",
+ republishOnly: false,
+ updateRequired: true,
+ });
+ });
+
+ test("resets a deploy mirror that moved ahead of the stable release", () => {
+ expect(
+ decideUpstreamSync({
+ contentMatchesTarget: false,
+ forceRedeploy: false,
+ headEqualsTarget: false,
+ headIsAncestorOfTarget: false,
+ preserveForkChanges: false,
+ targetIsAncestorOfHead: true,
+ }),
+ ).toEqual({
+ alignMode: "reset",
+ reason: "deploy_mirror_ahead",
+ republishOnly: false,
+ updateRequired: true,
+ });
+ });
+
+ test("preserves changes only when a customized fork explicitly opts in", () => {
+ expect(
+ decideUpstreamSync({
+ contentMatchesTarget: false,
+ forceRedeploy: false,
+ headEqualsTarget: false,
+ headIsAncestorOfTarget: false,
+ preserveForkChanges: true,
+ targetIsAncestorOfHead: true,
+ }),
+ ).toEqual({
+ alignMode: "none",
+ reason: "customized_contains_target",
+ republishOnly: false,
+ updateRequired: false,
+ });
+ });
+
+ test("merges a diverged customized fork only after explicit opt-in", () => {
+ expect(
+ decideUpstreamSync({
+ contentMatchesTarget: false,
+ forceRedeploy: false,
+ headEqualsTarget: false,
+ headIsAncestorOfTarget: false,
+ preserveForkChanges: true,
+ targetIsAncestorOfHead: false,
+ }),
+ ).toEqual({
+ alignMode: "merge",
+ reason: "customized_merge",
+ republishOnly: false,
+ updateRequired: true,
+ });
+ });
+
test("public deployment documentation exposes only Fork and Agent paths", () => {
const englishReadme = readRepositoryFile("README.md");
const chineseReadme = readRepositoryFile("README.zh-CN.md");
@@ -198,10 +281,14 @@ describe("Cloudflare deployment entrypoints", () => {
expect(englishAgentDoc).toContain("Workers & Pages");
expect(englishAgentDoc).toContain("Update deployed EdgeEver");
+ expect(englishAgentDoc).toContain("deployment mirror by default");
+ expect(englishAgentDoc).toContain("EDGE_EVER_PRESERVE_FORK_CHANGES");
expect(englishAgentDoc).not.toContain("bun run deploy:manual");
expect(englishAgentDoc).not.toContain("deploy:setup");
expect(englishAgentDoc).not.toContain(".env.local");
expect(chineseAgentDoc).toContain("Workers & Pages");
+ expect(chineseAgentDoc).toContain("默认作为部署镜像");
+ expect(chineseAgentDoc).toContain("EDGE_EVER_PRESERVE_FORK_CHANGES");
expect(chineseAgentDoc).not.toContain("bun run deploy:manual");
expect(chineseAgentDoc).not.toContain("bun run deploy:manual");
});