Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ”¨ chore(release): repair trusted validation for older main branches (#22028)

Inneiadf8847d9112
diff --git a/.agents/skills/version-release/references/desktop-stable-sources.md b/.agents/skills/version-release/references/desktop-stable-sources.md
index 6cf72f6a631..12f9c2ad1df 100644
--- a/.agents/skills/version-release/references/desktop-stable-sources.md
+++ b/.agents/skills/version-release/references/desktop-stable-sources.md
@@ -10,6 +10,7 @@ Stable desktop releases bind OSS and Cloud in the Release asset `desktop-sources
| Rebuild the same version | Read its existing source record; never choose HEAD again. |
| Hotfix, model-only patch, or targeted migration | Explicitly inherit a delivered base version, with optional documented Cloud repair. |
| Historical version with no record | Import a verified full Cloud SHA and original run/attempt before rebuilding. |
+| New hotfix recovering an undelivered main version | Explicitly pin the actual main base SHA, full Cloud SHA and recovery reason. |
For a hotfix, use `bun run hotfix:branch --base v2.2.21` (the example version must already be delivered). Omit `--base` to select interactively from delivered versions. `--cloud-ref <full-SHA> --reason <repair>` records a Cloud fix on the new version. The script includes the selected base, full Cloud SHA and base-record hash in machine-readable PR metadata.
@@ -24,6 +25,27 @@ The **Desktop Release Sources** PR check validates the base's delivery proof, ha
Manual `release_mode=hotfix` resumes a Release with that bound intent; optional `base_version`, `cloud_ref` and repair reason inputs must match it. It cannot create a new hotfix intent or bypass PR validation. An older Release without metadata uses explicit historical import instead. For both ordinary and hotfix releases, only attempt 1 may create a missing source record; a later attempt must reuse an existing record or recover explicitly.
+## Recover an undelivered version as a new hotfix
+
+When main has a version whose desktop installers were never delivered, ordinary `--base` inheritance is unavailable. A new hotfix may instead carry an explicit `recovery` intent. This selects sources for the new release and does not claim the old version was delivered.
+
+```bash
+GITHUB_REPOSITORY=lobehub/lobehub \
+ RECOVERY_BASE_SHA=FULL_MAIN_BASE_SHA CLOUD_REF=FULL_CLOUD_SHA \
+ CLOUD_OVERRIDE_REASON='Reason for explicitly selecting these sources' \
+ node .github/scripts/desktopReleaseCli.mjs recovery-intent
+```
+
+Replace both SHA placeholders with verified full commits. Read the current main tip (`gh api repos/lobehub/lobehub/commits/main --jq .sha`), and append the generated comment to the PR. GitHub's PR `base.sha` can be an older snapshot. The open-PR check reads live main; after merge the check reads the actual merge commit's first parent. If either differs from the frozen base, reselect and verify the source combination. Auto-tag binds the intent to the actual PR number, merge parent and merge SHA. Stable verifies that identity again, records `selection=recovery` with its frozen base/reason, and checks out the explicit Cloud SHA. It never selects HEAD or invents delivery proof for the old version.
+
+Use Merge or Squash for hotfix/recovery PRs, so the resulting commit's first parent is the target main tip. Rebasing multiple PR commits does not preserve this boundary and is unsupported.
+
+Manual `release_mode=recovery` only resumes a Release with that bound recovery intent; supplied Cloud SHA and reason must agree. The first-attempt/create-only rules still apply. Later rebuilds read the saved record. The new version becomes a delivered baseline only after its own complete publication succeeds.
+
+If the initial source-record write failed before any build/publication, a later attempt with no record must stop. Verify the Release's bound recovery intent, actual merged PR/tag and pinned Cloud SHA, then start a **new manual Release Desktop Stable run** from the current tooling ref with `release_mode=recovery`, the new `version`, and `source_ref=v<version>`. Leave optional Cloud/reason inputs empty to use the bound intent; keep both upload-skip inputs enabled for a verification build. Attempt 1 of this explicit run may create the missing record from those same pinned sources; it cannot overwrite an existing record. If a previously saved record was lost, recover its original content instead; do not replace its identity or invent historical import evidence.
+
+## Rebuild and historical import
+
To rebuild an older version, run the repaired **Release Desktop Stable** workflow from a ref containing the current release tooling. Select `release_mode=rebuild`, target `version`, and `source_ref=v<version>`; the latter must resolve to that version's tag SHA. Keep both upload-skip inputs enabled for a dry-run. `release_mode=import` is a separate metadata-only operation: supply `cloud_ref`, `evidence_run_id` and `evidence_run_attempt`; it records sources without building or publishing installers. An import does not create delivery proof.
Current Core OTA and Canary/Beta source selection are outside this Stable change. Existing runs use their original workflow code; start a new manual run to use repaired tooling.
diff --git a/.github/scripts/desktopReleaseCli.mjs b/.github/scripts/desktopReleaseCli.mjs
index 8f7b027a09d..340cc581967 100644
--- a/.github/scripts/desktopReleaseCli.mjs
+++ b/.github/scripts/desktopReleaseCli.mjs
@@ -67,6 +67,8 @@ export async function runReleaseCli(command, env = process.env) {
const event = JSON.parse(await readFile(env.GITHUB_EVENT_PATH, 'utf8'));
const pr = event.pull_request;
if (!pr) throw new Error('A pull request event is required');
+ if (command === 'prepare-release' && pr.merged !== true)
+ throw new Error('Release preparation requires a merged PR');
const intent = await validatePrIntent(pr, store);
if (command === 'check-pr') {
await output(env, { release_mode: intent?.mode || 'none' });
@@ -77,7 +79,9 @@ export async function runReleaseCli(command, env = process.env) {
...intent,
mergeSha: pr.merge_commit_sha,
prNumber: pr.number,
- ...(intent.mode === 'hotfix' && { prBaseSha: pr.base.sha }),
+ ...(['hotfix', 'recovery'].includes(intent.mode) && {
+ prBaseSha: await store.resolvePrBase(pr),
+ }),
};
const file = path.join(env.RUNNER_TEMP, 'desktop-release-body.md');
await writeFile(
@@ -112,6 +116,18 @@ export async function runReleaseCli(command, env = process.env) {
);
return;
}
+ if (command === 'recovery-intent') {
+ console.log(
+ formatIntent({
+ schemaVersion: 1,
+ mode: 'recovery',
+ cloudSha: env.CLOUD_REF,
+ recoveryBaseSha: env.RECOVERY_BASE_SHA,
+ overrideReason: env.CLOUD_OVERRIDE_REASON,
+ }),
+ );
+ return;
+ }
const version = normalizeVersion(env.RELEASE_VERSION);
if (command === 'publish') {
const outcomes = JSON.parse(env.PUBLICATION_OUTCOMES || '{}');
@@ -157,20 +173,26 @@ export async function runReleaseCli(command, env = process.env) {
intent = validateReleaseIntent(event.release?.body || '', ossSha);
mode = intent?.mode || 'rebuild';
}
- if (mode === 'hotfix') {
+ if (mode === 'hotfix' || mode === 'recovery') {
intent ||= validateReleaseIntent(targetRelease.body || '', ossSha);
- if (intent?.mode !== 'hotfix')
- throw new Error('Hotfix requires bound release intent metadata from its merged PR');
+ if (intent?.mode !== mode)
+ throw new Error(
+ 'Hotfix/recovery requires matching bound release intent metadata from its merged PR',
+ );
if (
- (env.BASE_VERSION && normalizeVersion(env.BASE_VERSION) !== intent.baseVersion) ||
+ (env.BASE_VERSION &&
+ (mode !== 'hotfix' || normalizeVersion(env.BASE_VERSION) !== intent.baseVersion)) ||
(env.CLOUD_REF && env.CLOUD_REF !== intent.cloudSha) ||
(env.BASE_SOURCES_HASH && env.BASE_SOURCES_HASH !== intent.baseSourcesHash) ||
- (env.CLOUD_OVERRIDE_REASON && env.CLOUD_OVERRIDE_REASON.trim() !== intent.overrideReason)
+ (env.CLOUD_OVERRIDE_REASON && env.CLOUD_OVERRIDE_REASON.trim() !== intent.overrideReason) ||
+ (env.RECOVERY_BASE_SHA && env.RECOVERY_BASE_SHA !== intent.recoveryBaseSha)
)
throw new Error('Manual hotfix inputs conflict with the bound release intent');
- const baseline = await deliveredBaseline(store, intent.baseVersion, intent.baseSourcesHash);
await store.assertReleasePr(intent);
- await store.assertHotfixBase(baseline, intent.prBaseSha);
+ if (mode === 'hotfix') {
+ const baseline = await deliveredBaseline(store, intent.baseVersion, intent.baseSourcesHash);
+ await store.assertHotfixBase(baseline, intent.prBaseSha);
+ }
}
const result = await resolveSources(
{
@@ -183,6 +205,7 @@ export async function runReleaseCli(command, env = process.env) {
baseVersion: intent?.baseVersion || env.BASE_VERSION || undefined,
baseSourcesHash: intent?.baseSourcesHash || env.BASE_SOURCES_HASH || undefined,
overrideReason: intent?.overrideReason || env.CLOUD_OVERRIDE_REASON || undefined,
+ recoveryBaseSha: intent?.recoveryBaseSha || env.RECOVERY_BASE_SHA || undefined,
evidence: {
runId: mode === 'import' ? env.EVIDENCE_RUN_ID : env.GITHUB_RUN_ID,
runAttempt: Number(mode === 'import' ? env.EVIDENCE_RUN_ATTEMPT : env.GITHUB_RUN_ATTEMPT),
diff --git a/.github/scripts/desktopReleaseCli.test.mjs b/.github/scripts/desktopReleaseCli.test.mjs
index 04180627d36..143bbd41446 100644
--- a/.github/scripts/desktopReleaseCli.test.mjs
+++ b/.github/scripts/desktopReleaseCli.test.mjs
@@ -109,6 +109,7 @@ test('prepare-release binds weekly intent once and automatic source resolution c
JSON.stringify({
pull_request: {
number: 22000,
+ merged: true,
title: 'πŸš€ release: 20261031',
body: 'Release notes',
html_url: 'https://example.test/pull/22000',
@@ -258,6 +259,8 @@ async function hotfixFixture(t) {
const context = await fixture(t);
const { github, root } = context;
const store = createGithubStore(github.options);
+ github.parents.set(fixtureNextOss, [fixtureCloud]);
+ github.commits.set('main', fixtureCloud);
await store.createSources('2.2.21', fixtureSources);
await recordPublication(
{
@@ -324,11 +327,11 @@ test('manual hotfix cannot invent a PR identity or change a bound baseline', asy
/PR|identity|merge/i.test(error.stderr),
);
github.state.pullRequest.merge_commit_sha = fixtureNextOss;
- github.state.pullRequest.base.sha = fixtureOss;
+ github.parents.set(fixtureNextOss, [fixtureOss]);
await assert.rejects(run({ ...input, RELEASE_MODE: 'hotfix' }), (error) =>
/PR|identity|base/i.test(error.stderr),
);
- github.state.pullRequest.base.sha = fixtureCloud;
+ github.parents.set(fixtureNextOss, [fixtureCloud]);
github.state.comparison = { status: 'ahead', total_commits: 1, files: [] };
await assert.rejects(run({ ...input, RELEASE_MODE: 'hotfix', BASE_VERSION: '2.2.20' }), (error) =>
/conflict|mismatch/i.test(error.stderr),
@@ -381,3 +384,186 @@ test('automatic hotfix reruns cannot initialize missing locks but can reuse the
await run({ ...automatic, GITHUB_RUN_ATTEMPT: '2' });
assert.equal(github.releases.get('2.2.22').assets.length, 1);
});
+
+async function recoveryFixture(t) {
+ const context = await fixture(t);
+ const { github, root } = context;
+ github.commits.set('main', fixtureOss);
+ const request = {
+ schemaVersion: 1,
+ mode: 'recovery',
+ recoveryBaseSha: fixtureOss,
+ cloudSha: fixtureCloud,
+ overrideReason: 'Publish the pending main hotfix with its verified Cloud revision',
+ };
+ const bound = { ...request, mergeSha: fixtureNextOss, prNumber: 22001, prBaseSha: fixtureOss };
+ const rawIntent = (value) => `<!-- desktop-release-request ${JSON.stringify(value)} -->`;
+ const pr = {
+ number: 22001,
+ merged: true,
+ merge_commit_sha: fixtureNextOss,
+ title: 'πŸ› fix(chat): pending main hotfix',
+ head: { ref: 'hotfix/message-send-scroll' },
+ base: { ref: 'main', sha: fixtureOss },
+ html_url: 'https://example.test/pull/22001',
+ body: rawIntent(request),
+ };
+ github.state.pullRequest = pr;
+ github.state.rejectHead = true;
+ const eventPath = path.join(root, 'recovery-event.json');
+ const setIntent = async (intent) => {
+ const body = rawIntent(intent);
+ github.releases.get('2.2.22').body = body;
+ await writeFile(eventPath, JSON.stringify({ action: 'published', release: { body } }));
+ };
+ await setIntent(bound);
+ const input = {
+ RELEASE_VERSION: '2.2.22',
+ SOURCE_REF: 'v2.2.22',
+ RELEASE_MODE: 'auto',
+ GITHUB_EVENT_NAME: 'release',
+ GITHUB_EVENT_PATH: eventPath,
+ GITHUB_RUN_ATTEMPT: '1',
+ WRITE_SOURCES: 'true',
+ };
+ return { ...context, input, request, bound, pr, eventPath, setIntent };
+}
+
+test('explicit recovery pins a new release without inventing a delivered baseline', async (t) => {
+ const { github, input, run, request } = await recoveryFixture(t);
+ await run(input);
+ const names = github.releases.get('2.2.22').assets.map((asset) => asset.name);
+ assert.deepEqual(names, ['desktop-sources.v1.json']);
+ const saved = JSON.parse(
+ [...github.assets.values()].find((asset) => asset.name === names[0]).content,
+ );
+ assert.equal(saved.version, '2.2.22');
+ assert.equal(saved.ossSha, fixtureNextOss);
+ assert.equal(saved.cloudSha, fixtureCloud);
+ assert.equal(saved.selection, 'recovery');
+ assert.equal(saved.baseVersion, null);
+ assert.equal(saved.recoveryBaseSha, fixtureOss);
+ assert.equal(saved.overrideReason, request.overrideReason);
+ assert.equal(github.releases.get('2.2.21').assets.length, 0);
+});
+
+test('recovery PR validation freezes the actual main base before binding its merge identity', async (t) => {
+ const { github, input, run, pr, eventPath, root } = await recoveryFixture(t);
+ await writeFile(eventPath, JSON.stringify({ pull_request: pr }));
+ await run(input, 'check-pr');
+ await run(input, 'prepare-release');
+ const intent = parseIntent(await readFile(path.join(root, 'desktop-release-body.md'), 'utf8'));
+ assert.equal(intent.mode, 'recovery');
+ assert.equal(intent.mergeSha, fixtureNextOss);
+ assert.equal(intent.recoveryBaseSha, fixtureOss);
+ assert.equal(intent.prBaseSha, fixtureOss);
+ github.parents.set(fixtureNextOss, [fixtureCloud]);
+ await writeFile(eventPath, JSON.stringify({ pull_request: pr }));
+ await assert.rejects(run(input, 'check-pr'), (error) => /base|recovery/i.test(error.stderr));
+});
+
+test('recovery cannot change or invent the merged PR base', async (t) => {
+ const { github, input, run, bound, setIntent } = await recoveryFixture(t);
+ github.parents.set(fixtureNextOss, [fixtureCloud]);
+ await assert.rejects(run(input), (error) => /PR|base/i.test(error.stderr));
+ github.parents.set(fixtureNextOss, [fixtureOss]);
+ await setIntent({ ...bound, recoveryBaseSha: fixtureCloud });
+ await assert.rejects(run(input), (error) => /base|recovery/i.test(error.stderr));
+ assert.equal(github.releases.get('2.2.22').assets.length, 0);
+});
+
+test('recovery requires a reason and cannot initialize missing records on a rerun', async (t) => {
+ const { github, input, run, bound, setIntent } = await recoveryFixture(t);
+ await setIntent({ ...bound, overrideReason: '' });
+ await assert.rejects(run(input), (error) => /reason/i.test(error.stderr));
+ await setIntent(bound);
+ await assert.rejects(run({ ...input, GITHUB_RUN_ATTEMPT: '2' }), (error) =>
+ /missing|first|import/i.test(error.stderr),
+ );
+ assert.equal(github.releases.get('2.2.22').assets.length, 0);
+ await run(input);
+ await run({ ...input, RELEASE_MODE: 'rebuild', GITHUB_RUN_ATTEMPT: '2' });
+ assert.equal(github.releases.get('2.2.22').assets.length, 1);
+});
+
+test('manual recovery resumes bound intent and rejects conflicting explicit inputs', async (t) => {
+ const { github, input, run } = await recoveryFixture(t);
+ const manual = { ...input, RELEASE_MODE: 'recovery' };
+ await assert.rejects(run({ ...manual, CLOUD_REF: fixtureOss }), (error) =>
+ /conflict/i.test(error.stderr),
+ );
+ await assert.rejects(run({ ...manual, CLOUD_OVERRIDE_REASON: 'Changed choice' }), (error) =>
+ /conflict/i.test(error.stderr),
+ );
+ await run(manual);
+ assert.equal(github.releases.get('2.2.22').assets.length, 1);
+});
+
+test('an open recovery checks live main even when the PR base snapshot is unchanged', async (t) => {
+ const { github, input, run, pr, eventPath } = await recoveryFixture(t);
+ github.commits.set('main', fixtureNextOss);
+ await writeFile(eventPath, JSON.stringify({ pull_request: { ...pr, merged: false } }));
+ await assert.rejects(run(input, 'check-pr'), (error) => /base|main|recovery/i.test(error.stderr));
+});
+
+test('recovery preparation rejects a changed merge parent hidden by the PR base snapshot', async (t) => {
+ const { github, input, run, pr, eventPath } = await recoveryFixture(t);
+ github.parents.set(fixtureNextOss, [fixtureCloud, fixtureOss]);
+ await writeFile(eventPath, JSON.stringify({ pull_request: pr }));
+ await assert.rejects(run(input, 'prepare-release'), (error) =>
+ /base|recovery/i.test(error.stderr),
+ );
+});
+
+test('Stable rejects recovery metadata whose base differs from the actual merge parent', async (t) => {
+ const { github, input, run } = await recoveryFixture(t);
+ github.parents.set(fixtureNextOss, [fixtureCloud, fixtureOss]);
+ await assert.rejects(run(input), (error) => /base|PR|parent/i.test(error.stderr));
+ assert.equal(github.releases.get('2.2.22').assets.length, 0);
+});
+
+test('hotfix binding uses the actual merge parent rather than a stale PR base snapshot', async (t) => {
+ const { github, input, run, root, eventPath } = await hotfixFixture(t);
+ const request = parseIntent(github.releases.get('2.2.22').body);
+ delete request.mergeSha;
+ delete request.prNumber;
+ delete request.prBaseSha;
+ github.parents.set(fixtureNextOss, [fixtureCloud, fixtureOss]);
+ github.state.pullRequest.base.sha = fixtureOss;
+ github.state.comparison = { status: 'ahead', total_commits: 1, files: [] };
+ await writeFile(
+ eventPath,
+ JSON.stringify({
+ pull_request: {
+ ...github.state.pullRequest,
+ title: 'πŸ› fix: targeted repair',
+ head: { ref: 'hotfix/a-repair' },
+ body: formatIntent(request),
+ },
+ }),
+ );
+ await run({ ...input, GITHUB_EVENT_PATH: eventPath }, 'prepare-release');
+ const intent = parseIntent(await readFile(path.join(root, 'desktop-release-body.md'), 'utf8'));
+ assert.equal(intent.prBaseSha, fixtureCloud);
+ await run({ ...input, RELEASE_MODE: 'hotfix' });
+});
+
+test('prepare-release does not bind an unmerged PR to its temporary test merge', async (t) => {
+ const { input, run, pr, eventPath } = await recoveryFixture(t);
+ await writeFile(eventPath, JSON.stringify({ pull_request: { ...pr, merged: false } }));
+ await assert.rejects(run(input, 'prepare-release'), (error) => /merged/i.test(error.stderr));
+});
+
+test('operators can generate explicit recovery metadata with a frozen base and reason', async (t) => {
+ const { run, request } = await recoveryFixture(t);
+ const env = {
+ RECOVERY_BASE_SHA: fixtureOss,
+ CLOUD_REF: fixtureCloud,
+ CLOUD_OVERRIDE_REASON: request.overrideReason,
+ };
+ const result = await run(env, 'recovery-intent');
+ assert.deepEqual(parseIntent(result.stdout), request);
+ await assert.rejects(run({ ...env, CLOUD_OVERRIDE_REASON: '' }, 'recovery-intent'), (error) =>
+ /reason/i.test(error.stderr),
+ );
+});
diff --git a/.github/scripts/desktopReleaseGithub.mjs b/.github/scripts/desktopReleaseGithub.mjs
index 0fed177ce66..ae42dbfd15e 100644
--- a/.github/scripts/desktopReleaseGithub.mjs
+++ b/.github/scripts/desktopReleaseGithub.mjs
@@ -122,6 +122,16 @@ export function createGithubStore(options) {
return assertSha(commit.sha, 'Resolved OSS');
}
+ // PR base.sha is a historical snapshot, not necessarily the merge's first parent.
+ async function resolvePrBase(pr) {
+ if (pr.base?.ref !== 'main') throw new Error('Release PR must target main');
+ if (pr.merged !== true) return resolveCommit('main');
+ const mergeSha = assertSha(pr.merge_commit_sha, 'Release merge');
+ const commit = await (await request(`${root}/commits/${mergeSha}`)).json();
+ if (commit.sha !== mergeSha) throw new Error('Release merge commit SHA mismatch');
+ return assertSha(commit.parents?.[0]?.sha, 'Actual merge parent');
+ }
+
async function cloudCommit(ref) {
if (!options.cloudToken) throw new Error('A Cloud read token is required');
const cloud = repositoryPath(options.cloudRepository);
@@ -135,6 +145,7 @@ export function createGithubStore(options) {
release,
listAssets,
resolveCommit,
+ resolvePrBase,
readSources: (version) => readAsset(version, sourceAssetName),
createSources: (version, record) => createAsset(version, sourceAssetName, record),
readPublication: (version) => readAsset(version, publicationAssetName),
@@ -203,7 +214,7 @@ export function createGithubStore(options) {
pr.merged !== true ||
pr.merge_commit_sha !== intent.mergeSha ||
pr.base?.ref !== 'main' ||
- pr.base.sha !== intent.prBaseSha
+ (await resolvePrBase(pr)) !== intent.prBaseSha
)
throw new Error('Release intent does not match the actual merged PR identity/base');
},
diff --git a/.github/scripts/desktopReleaseIntent.mjs b/.github/scripts/desktopReleaseIntent.mjs
index 5aef29ef7a6..f8c61f32c1e 100644
--- a/.github/scripts/desktopReleaseIntent.mjs
+++ b/.github/scripts/desktopReleaseIntent.mjs
@@ -1,4 +1,5 @@
import {
+ assertOverrideReason,
assertSha,
deliveredBaseline,
normalizeVersion,
@@ -8,7 +9,11 @@ import {
const marker = /<!-- desktop-release-request ([\s\S]*?)-->/g;
function validateIntent(value) {
- if (!value || value.schemaVersion !== 1 || !['initialize', 'hotfix'].includes(value.mode))
+ if (
+ !value ||
+ value.schemaVersion !== 1 ||
+ !['initialize', 'hotfix', 'recovery'].includes(value.mode)
+ )
throw new Error('Invalid desktop release intent metadata');
const intent = { schemaVersion: 1, mode: value.mode };
if (value.mode === 'hotfix') {
@@ -17,15 +22,14 @@ function validateIntent(value) {
if (!/^[a-f0-9]{64}$/.test(value.baseSourcesHash || ''))
throw new Error('Hotfix metadata requires the baseline source hash');
intent.baseSourcesHash = value.baseSourcesHash;
- if (value.overrideReason !== undefined) {
- if (
- typeof value.overrideReason !== 'string' ||
- !value.overrideReason.trim() ||
- value.overrideReason.length > 500
- )
- throw new Error('Invalid Cloud repair reason');
- intent.overrideReason = value.overrideReason.trim();
- }
+ if (value.overrideReason !== undefined)
+ intent.overrideReason = assertOverrideReason(value.overrideReason);
+ } else if (value.mode === 'recovery') {
+ if (value.baseVersion || value.baseSourcesHash)
+ throw new Error('Recovery metadata cannot claim a delivered baseline');
+ intent.cloudSha = assertSha(value.cloudSha, 'Recovery Cloud');
+ intent.recoveryBaseSha = assertSha(value.recoveryBaseSha, 'Recovery OSS base');
+ intent.overrideReason = assertOverrideReason(value.overrideReason);
} else if (value.baseVersion || value.cloudSha) {
throw new Error('Ordinary initialization cannot carry a hotfix baseline');
}
@@ -38,7 +42,10 @@ function validateIntent(value) {
if (!Number.isSafeInteger(value.prNumber) || value.prNumber < 1)
throw new Error('Release intent requires its PR number');
intent.prNumber = value.prNumber;
- if (value.mode === 'hotfix') intent.prBaseSha = assertSha(value.prBaseSha, 'Release PR base');
+ if (value.mode === 'hotfix' || value.mode === 'recovery')
+ intent.prBaseSha = assertSha(value.prBaseSha, 'Release PR base');
+ if (value.mode === 'recovery' && intent.recoveryBaseSha !== intent.prBaseSha)
+ throw new Error('Recovery OSS base differs from the bound PR base');
}
return intent;
}
@@ -82,9 +89,9 @@ export function requestFromPr(pr) {
if (intent?.mergeSha)
throw new Error('PR metadata must not preassign the release merge identity');
if (ordinary) return intent || { schemaVersion: 1, mode: 'initialize' };
- if (!intent || intent.mode !== 'hotfix')
+ if (!intent || !['hotfix', 'recovery'].includes(intent.mode))
throw new Error(
- 'Targeted main patches need hotfix intent metadata with an explicitly delivered base; use hotfix:branch --base',
+ 'Targeted main patches need hotfix intent metadata with a delivered base or explicit recovery metadata',
);
return intent;
}
@@ -92,10 +99,18 @@ export function requestFromPr(pr) {
export async function validatePrIntent(pr, store) {
const intent = requestFromPr(pr);
if (!intent || intent.mode === 'initialize') return intent;
+ const baseSha = await store.resolvePrBase(pr);
+ if (intent.mode === 'recovery') {
+ if (baseSha !== intent.recoveryBaseSha)
+ throw new Error(
+ 'Recovery requires its explicitly selected main base SHA; reselect sources if main changed',
+ );
+ return intent;
+ }
const baseline = await deliveredBaseline(store, intent.baseVersion, intent.baseSourcesHash);
if (intent.cloudSha !== baseline.cloudSha && !intent.overrideReason)
throw new Error('A different Cloud SHA needs a repair reason');
- await store.assertHotfixBase(baseline, pr.base.sha);
+ await store.assertHotfixBase(baseline, baseSha);
return { ...intent, baseSourcesHash: sourcesHash(baseline) };
}
diff --git a/.github/scripts/desktopReleaseIntent.test.mjs b/.github/scripts/desktopReleaseIntent.test.mjs
index 89798dfa104..cc26c0fc494 100644
--- a/.github/scripts/desktopReleaseIntent.test.mjs
+++ b/.github/scripts/desktopReleaseIntent.test.mjs
@@ -36,6 +36,7 @@ const pr = (overrides = {}) => ({
async function delivered(t) {
const github = await startGithubFixture();
+ github.commits.set('main', fixtureOss);
t.after(github.close);
const store = createGithubStore(github.options);
await store.createSources('2.2.21', fixtureSources);
@@ -130,7 +131,8 @@ test('a different Cloud SHA needs a recorded repair reason', async (t) => {
test('main may advance with release tooling, but undistributed product changes block hotfix inheritance', async (t) => {
const { github, store } = await delivered(t);
- const changed = pr({ base: { ref: 'main', sha: fixtureNextOss } });
+ const changed = pr();
+ github.commits.set('main', fixtureNextOss);
github.state.comparison = {
status: 'ahead',
total_commits: 1,
diff --git a/.github/scripts/desktopReleaseSources.mjs b/.github/scripts/desktopReleaseSources.mjs
index 9a4f97ab704..5fad0580cbc 100644
--- a/.github/scripts/desktopReleaseSources.mjs
+++ b/.github/scripts/desktopReleaseSources.mjs
@@ -19,6 +19,12 @@ export function assertSha(value, name = 'commit') {
return value;
}
+export function assertOverrideReason(value) {
+ if (typeof value !== 'string' || !value.trim() || value.length > 500)
+ throw new Error('A Cloud override requires a concise reason');
+ return value.trim();
+}
+
const assertHash = (value) => {
if (typeof value !== 'string' || !/^[a-f0-9]{64}$/.test(value))
throw new Error('Invalid source record hash');
@@ -40,7 +46,7 @@ const validateEvidence = (value) => {
export function validateSources(value) {
if (!value || value.schemaVersion !== 1 || value.channel !== 'stable')
throw new Error('Unsupported stable source record schema/channel');
- if (!['latest', 'inherit', 'historical-import'].includes(value.selection))
+ if (!['latest', 'inherit', 'historical-import', 'recovery'].includes(value.selection))
throw new Error('Invalid source selection');
const record = {
schemaVersion: 1,
@@ -56,18 +62,17 @@ export function validateSources(value) {
if (!record.baseVersion || record.baseVersion === record.version)
throw new Error('A hotfix must reference a different base version');
record.baseSourcesHash = assertHash(value.baseSourcesHash);
- if (value.overrideReason !== undefined) {
- if (
- typeof value.overrideReason !== 'string' ||
- !value.overrideReason.trim() ||
- value.overrideReason.length > 500
- )
- throw new Error('A Cloud override requires a concise reason');
- record.overrideReason = value.overrideReason.trim();
- }
+ if (value.overrideReason !== undefined)
+ record.overrideReason = assertOverrideReason(value.overrideReason);
} else if (record.baseVersion !== null) {
throw new Error('Only a hotfix may have a base version');
}
+ if (record.selection === 'recovery') {
+ record.recoveryBaseSha = assertSha(value.recoveryBaseSha, 'Recovery OSS base');
+ if (record.recoveryBaseSha === record.ossSha)
+ throw new Error('Recovery requires a new merged OSS commit');
+ record.overrideReason = assertOverrideReason(value.overrideReason);
+ }
return record;
}
@@ -86,6 +91,14 @@ const assertIdentity = (record, input) => {
throw new Error('Hotfix base version conflicts with the source record');
if (input.baseSourcesHash && record.baseSourcesHash !== input.baseSourcesHash)
throw new Error('Hotfix baseline hash conflicts with the source record');
+ if (input.recoveryBaseSha && record.recoveryBaseSha !== input.recoveryBaseSha)
+ throw new Error('Recovery base SHA conflicts with the source record');
+ if (
+ record.selection === 'recovery' &&
+ input.overrideReason &&
+ record.overrideReason !== input.overrideReason.trim()
+ )
+ throw new Error('Cloud repair reason conflicts with the source record');
};
export function validatePublication(value, sources) {
@@ -127,7 +140,7 @@ export async function resolveSources(input, dependencies) {
const version = normalizeVersion(input.version);
const ossSha = assertSha(input.ossSha, 'OSS');
if (input.cloudSha) assertSha(input.cloudSha, 'Cloud');
- if (!['initialize', 'rebuild', 'hotfix', 'import'].includes(input.mode))
+ if (!['initialize', 'rebuild', 'hotfix', 'import', 'recovery'].includes(input.mode))
throw new Error('An explicit release mode is required');
const stored = await dependencies.store.readSources(version);
if (stored !== null) {
@@ -148,6 +161,7 @@ export async function resolveSources(input, dependencies) {
let baseVersion = null;
let baseSourcesHash;
let overrideReason;
+ let recoveryBaseSha;
if (input.mode === 'initialize') {
if (input.firstRelease !== true || evidence.runAttempt !== 1)
throw new Error('Missing record: only the initial release attempt may initialize sources');
@@ -173,6 +187,13 @@ export async function resolveSources(input, dependencies) {
overrideReason = input.overrideReason;
}
selection = 'inherit';
+ } else if (input.mode === 'recovery') {
+ if (input.baseVersion || input.baseSourcesHash)
+ throw new Error('Explicit recovery does not claim a delivered version baseline');
+ recoveryBaseSha = assertSha(input.recoveryBaseSha, 'Recovery OSS base');
+ cloudSha = assertSha(input.cloudSha, 'Recovery Cloud');
+ overrideReason = assertOverrideReason(input.overrideReason);
+ selection = 'recovery';
} else {
cloudSha = assertSha(input.cloudSha, 'Cloud');
await dependencies.assertImportEvidence({ ...input, version, ossSha, evidence });
@@ -191,13 +212,21 @@ export async function resolveSources(input, dependencies) {
evidence,
...(baseSourcesHash && { baseSourcesHash }),
...(overrideReason && { overrideReason }),
+ ...(recoveryBaseSha && { recoveryBaseSha }),
});
if (!input.write) return { sources: candidate, hash: sourcesHash(candidate), persisted: false };
await dependencies.store.createSources(version, candidate);
const winner = await dependencies.store.readSources(version);
if (!winner) throw new Error('Source record was not persisted');
const sources = validateSources(winner);
- assertIdentity(sources, { version, ossSha, cloudSha, baseVersion, baseSourcesHash });
+ assertIdentity(sources, {
+ version,
+ ossSha,
+ cloudSha,
+ baseVersion,
+ baseSourcesHash,
+ recoveryBaseSha,
+ });
if (sources.selection !== selection || sources.overrideReason !== candidate.overrideReason)
throw new Error('Concurrent source initialization conflict');
return { sources, hash: sourcesHash(sources), persisted: true };
diff --git a/.github/scripts/desktopReleaseTestUtils.mjs b/.github/scripts/desktopReleaseTestUtils.mjs
index c1a2d1e1f59..ae8287bca13 100644
--- a/.github/scripts/desktopReleaseTestUtils.mjs
+++ b/.github/scripts/desktopReleaseTestUtils.mjs
@@ -23,7 +23,11 @@ export async function startGithubFixture() {
['v2.2.21', fixtureOss],
['v2.2.22', fixtureNextOss],
['main', fixtureNextOss],
+ [fixtureOss, fixtureOss],
+ [fixtureNextOss, fixtureNextOss],
+ [fixtureCloud, fixtureCloud],
]);
+ const parents = new Map([[fixtureNextOss, [fixtureOss]]]);
let serial = 100;
const state = { cloud: fixtureNextCloud, error: null, rejectHead: false, intercept: null };
const json = (response, status, value) => {
@@ -45,7 +49,13 @@ export async function startGithubFixture() {
}
if (route.startsWith('/commits/')) {
const sha = commits.get(decodeURIComponent(route.slice('/commits/'.length)));
- return json(response, sha ? 200 : 404, sha ? { sha } : { message: 'not found' });
+ return json(
+ response,
+ sha ? 200 : 404,
+ sha
+ ? { sha, parents: (parents.get(sha) || []).map((sha) => ({ sha })) }
+ : { message: 'not found' },
+ );
}
if (route.startsWith('/actions/runs/'))
return json(response, 200, { id: 40841847688, head_sha: fixtureOss, run_attempt: 1 });
@@ -122,6 +132,7 @@ export async function startGithubFixture() {
state,
releases,
commits,
+ parents,
assets,
addAsset,
addRelease,
diff --git a/.github/scripts/desktopReleaseWorkflow.test.mjs b/.github/scripts/desktopReleaseWorkflow.test.mjs
index 4b765d7f4f8..16067f70071 100644
--- a/.github/scripts/desktopReleaseWorkflow.test.mjs
+++ b/.github/scripts/desktopReleaseWorkflow.test.mjs
@@ -24,9 +24,15 @@ const setup = await readFile(
new URL('../actions/desktop-build-setup/action.yml', import.meta.url),
'utf8',
);
+const requestWorkflow = await readFile(
+ new URL('../workflows/desktop-release-request.yml', import.meta.url),
+ 'utf8',
+);
function shippedStep(source, name) {
const section = source.split(`- name: ${name}\n`)[1]?.split(/\n *- (?:name:|uses:)/)[0];
+ const inline = section?.match(/^ +run: ([^|\n].*)$/m);
+ if (inline) return inline[1];
const block = section?.match(/^( +)run: \|\n/m);
assert.ok(block, `shipped run step ${name} exists`);
const indent = block[1].length + 2;
@@ -38,6 +44,99 @@ function shippedStep(source, name) {
return lines.join('\n').trimEnd();
}
+test('PR validation loads trusted workflow tooling even when the product base predates it', async (t) => {
+ const github = await startGithubFixture();
+ t.after(github.close);
+ github.commits.set('main', fixtureSources.ossSha);
+ const root = await mkdtemp(path.join(os.tmpdir(), 'release-validator-bootstrap-'));
+ t.after(() => rm(root, { recursive: true, force: true }));
+ const repo = path.join(root, 'repo');
+ const checkout = path.join(root, 'checkout');
+ await mkdir(repo);
+ const git = (...args) => exec('git', ['-C', repo, ...args]);
+ const commit = async () => {
+ await git('add', '.');
+ await git(
+ '-c',
+ 'core.hooksPath=/dev/null',
+ '-c',
+ 'commit.gpgsign=false',
+ '-c',
+ 'user.name=Fixture',
+ '-c',
+ 'commit',
+ '-qm',
+ 'fixture',
+ );
+ return (await git('rev-parse', 'HEAD')).stdout.trim();
+ };
+ await git('init', '-q');
+ await writeFile(path.join(repo, 'README.md'), 'Old product source without release tooling');
+ const productSha = await commit();
+ await mkdir(path.join(repo, '.github/scripts'), { recursive: true });
+ for (const name of ['Cli', 'Github', 'Intent', 'Sources'])
+ await copyFile(
+ path.join(repository, `.github/scripts/desktopRelease${name}.mjs`),
+ path.join(repo, `.github/scripts/desktopRelease${name}.mjs`),
+ );
+ const toolingSha = await commit();
+ const marker = path.join(root, 'untrusted-script-executed');
+ await writeFile(
+ path.join(repo, '.github/scripts/desktopReleaseCli.mjs'),
+ "import { writeFileSync } from 'node:fs'; writeFileSync(process.env.BOOTSTRAP_ATTACK_PATH, 'executed'); console.log(JSON.stringify({release_mode:'recovery'}));",
+ );
+ const headSha = await commit();
+ const context = {
+ 'github.workflow_sha': toolingSha,
+ 'github.event.pull_request.base.sha': productSha,
+ 'github.event.pull_request.head.sha': headSha,
+ };
+ const ref = requestWorkflow.match(/^ +ref: \$\{\{ ([\w.]+) \}\}/m)?.[1];
+ assert.ok(context[ref], 'checkout selects a known GitHub context');
+ const archive = path.join(root, 'tooling.tar');
+ await git('archive', '--format=tar', `--output=${archive}`, context[ref]);
+ await mkdir(checkout);
+ await exec('tar', ['-xf', archive, '-C', checkout]);
+ const eventPath = path.join(root, 'event.json');
+ const request = {
+ schemaVersion: 1,
+ mode: 'recovery',
+ cloudSha: fixtureSources.cloudSha,
+ recoveryBaseSha: fixtureSources.ossSha,
+ overrideReason: 'Verified recovery of the pending release',
+ };
+ await writeFile(
+ eventPath,
+ JSON.stringify({
+ pull_request: {
+ title: 'fix: pending hotfix',
+ head: { ref: 'hotfix/pending' },
+ base: { ref: 'main', sha: fixtureSources.ossSha },
+ merged: false,
+ body: `<!-- desktop-release-request ${JSON.stringify(request)} -->`,
+ },
+ }),
+ );
+ const { stdout } = await exec(
+ 'bash',
+ ['-c', shippedStep(requestWorkflow, 'Validate release intent')],
+ {
+ cwd: checkout,
+ env: {
+ ...process.env,
+ GITHUB_REPOSITORY: 'example/lobehub',
+ GITHUB_API_URL: github.apiUrl,
+ GH_TOKEN: 'oss-test-token',
+ GITHUB_EVENT_PATH: eventPath,
+ BOOTSTRAP_ATTACK_PATH: marker,
+ },
+ },
+ );
+ assert.equal(JSON.parse(stdout).release_mode, 'recovery');
+ await assert.rejects(readFile(marker), { code: 'ENOENT' });
+});
+
test('the shipped Stable resolver reuses its old Cloud when the current HEAD has advanced', async (t) => {
const github = await startGithubFixture();
t.after(github.close);
diff --git a/.github/workflows/desktop-release-request.yml b/.github/workflows/desktop-release-request.yml
index f493b448711..274e357e010 100644
--- a/.github/workflows/desktop-release-request.yml
+++ b/.github/workflows/desktop-release-request.yml
@@ -18,10 +18,11 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- # Only trusted base scripts execute; PR text is data read from the event file.
+ # Tooling follows the trusted workflow revision, independently of an older product base.
+ # PR text stays data; no PR-head scripts execute with the target event's token.
- uses: actions/checkout@v7
with:
- ref: ${{ github.event.pull_request.base.sha }}
+ ref: ${{ github.workflow_sha }}
sparse-checkout: .github/scripts
- uses: actions/setup-node@v6
with:
diff --git a/.github/workflows/release-desktop-stable.yml b/.github/workflows/release-desktop-stable.yml
index c332cb51b81..4336428a0d3 100644
--- a/.github/workflows/release-desktop-stable.yml
+++ b/.github/workflows/release-desktop-stable.yml
@@ -30,15 +30,15 @@ on:
required: true
type: string
cloud_ref:
- description: 'Cloud SHA for import, or verify the SHA already bound in the hotfix Release'
+ description: 'Cloud SHA for import, or verify the SHA already bound in the hotfix/recovery Release'
required: false
type: string
default: ''
release_mode:
- description: 'Rebuild pinned sources, resume a PR-bound hotfix, or import historical sources only'
+ description: 'Rebuild pinned sources, resume a PR-bound hotfix/recovery, or import historical sources only'
required: true
type: choice
- options: [rebuild, hotfix, import]
+ options: [rebuild, hotfix, recovery, import]
default: rebuild
source_ref:
description: 'Product source ref; defaults to the target version tag and must resolve to its SHA'
@@ -49,7 +49,7 @@ on:
type: string
default: ''
cloud_override_reason:
- description: 'Optional verification of the Cloud repair reason already bound in the hotfix Release'
+ description: 'Optional verification of the Cloud repair reason already bound in the hotfix/recovery Release'
type: string
default: ''
evidence_run_id: