From 3fd0c6683db7bca4fc3b02cefb2e117b39e06dcc Mon Sep 17 00:00:00 2001 From: winewill Date: Thu, 12 Nov 2026 12:15:13 +0800 Subject: [PATCH] fix(desktop): narrow publisher metadata parse recovery --- apps/desktop-publisher/src/desktop-publish.ts | 7 ++++--- .../tests/desktop-publish.spec.ts | 19 +++++++++++++++++++ scripts/empty-catch.baseline.json | 3 --- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/apps/desktop-publisher/src/desktop-publish.ts b/apps/desktop-publisher/src/desktop-publish.ts index eb0f2a4ab6..37ba77d9a3 100644 --- a/apps/desktop-publisher/src/desktop-publish.ts +++ b/apps/desktop-publisher/src/desktop-publish.ts @@ -62,10 +62,11 @@ function same(left: DesktopObjectDigest | null, right: DesktopObjectDigest | nul } function version(contents: string, remote = false): string { + let parsed: { version: string } | undefined try { - const parsed = z.object({ version: z.string() }).parse(load(contents)) - if (valid(parsed.version) !== null) return parsed.version - } catch (_error) { /* Discard parser error details, which may include raw remote YAML. */ } + parsed = z.object({ version: z.string() }).parse(load(contents)) + } catch (_parseError) { /* Discard parser error details, which may include raw remote YAML. */ } + if (parsed !== undefined && valid(parsed.version) !== null) return parsed.version throw new DesktopPublishError(remote ? 'verification-failed' : 'invalid-plan', `desktop publish: invalid ${remote ? 'remote' : 'planned'} channel version`) } diff --git a/apps/desktop-publisher/tests/desktop-publish.spec.ts b/apps/desktop-publisher/tests/desktop-publish.spec.ts index 408129a913..f00d50c52c 100644 --- a/apps/desktop-publisher/tests/desktop-publish.spec.ts +++ b/apps/desktop-publisher/tests/desktop-publish.spec.ts @@ -127,3 +127,22 @@ it('classifies corrupted remote channel metadata separately from an invalid loca await expect(publishDesktopRelease(f.plan, f.operations)).rejects.toMatchObject({ code: 'verification-failed' }) expect(f.writes).toEqual([]) }) + +it.each(['version: [private-feed', 'version: 42\n', 'version: invalid-private-version\n'])( + 'rejects invalid channel metadata without exposing its contents: %s', async (contents) => { + for (const remote of [false, true]) { + const f = fixture() + const plan: DesktopUploadPlan = remote ? f.plan : { + ...f.plan, + artifacts: f.plan.artifacts.map(artifact => artifact.channelMetadata ? { ...artifact, contents } : artifact), + } + if (remote) f.objects.set('feed/nightly.yml', observed(contents)) + await expect(publishDesktopRelease(plan, f.operations)).rejects.toMatchObject({ + code: remote ? 'verification-failed' : 'invalid-plan', + message: `desktop publish: invalid ${remote ? 'remote' : 'planned'} channel version`, + }) + expect(f.writes).toEqual([]) + expect(f.tags()).toBe(0) + } + }, +) diff --git a/scripts/empty-catch.baseline.json b/scripts/empty-catch.baseline.json index 9ccfe4d5a4..432d1535ce 100644 --- a/scripts/empty-catch.baseline.json +++ b/scripts/empty-catch.baseline.json @@ -2,9 +2,6 @@ "apps/cli/tests/built-bin.e2e.ts": { "cf101add035f69891416d7350e9a824c2de6c0d1b7a253de6a73da923023b073": 1 }, - "apps/desktop/scripts/desktop-publish.ts": { - "d37e8639087921e2491d45d40d63b44e72b30a516ad3a5f3155f467c7f5c3ac7": 1 - }, "apps/desktop/src/client/WelcomePage.tsx": { "10ea16f7e56fe8d9176f54f90b2c2137b20e2c60e3f5cb45d6dc09fe23c52eae": 1 },