cc-haha/scripts/release-update-metadata.test.ts
程序员阿江(Relakkes) 386a41e606 feat(desktop): enable Electron migration path
Introduce the Electron desktop shell alongside the existing React renderer and local Bun server boundary. The migration keeps the DesktopHost contract explicit across Tauri, Electron, and browser runtimes while adding Electron main/preload services for dialogs, shell, notifications, updates, tray/window lifecycle, terminal, preview WebContentsView, app mode, and release/package validation.

The commit also carries the latest local main desktop command updates, including agent slash entries and hidden-by-default markdown thinking details, so the packaged Electron build matches the current main UX surface.

Constraint: React renderer, local Bun server, REST/WebSocket, and sidecar boundaries must remain reusable during the migration
Constraint: macOS dev packages are ad-hoc signed and cannot prove Developer ID notarization or Gatekeeper release launch
Rejected: Browser-only smoke validation | it cannot exercise native dialogs, keychain prompts, notification behavior, or packaged app startup
Confidence: medium
Scope-risk: broad
Directive: Do not remove Tauri host support until signed Electron release artifacts pass native OS smoke on macOS, Windows, and Linux
Tested: bun run check:desktop
Tested: cd desktop && bun run check:electron
Tested: CSC_IDENTITY_AUTO_DISCOVERY=false bun run electron📦dir
Tested: bun run test:package-smoke --platform macos --package-kind dir --artifacts-dir desktop/build-artifacts/electron
Tested: Computer Use read packaged Electron app window at desktop/build-artifacts/electron/mac-arm64/Claude Code Haha.app
Not-tested: Developer ID signed/notarized Gatekeeper launch
Not-tested: Real OS notification click-to-session action
Not-tested: Windows and Linux packaged app smoke on real hosts
2026-06-01 22:43:16 +08:00

160 lines
5.3 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { parse } from 'yaml'
import { mergeUpdateMetadataArtifacts } from './release-update-metadata'
function tempDir() {
return mkdtempSync(join(tmpdir(), 'cc-haha-release-metadata-'))
}
function writeYaml(path: string, content: string) {
writeFileSync(path, content.trimStart().replace(/^ {6}/gm, ''))
}
describe('release update metadata merge', () => {
test('merges namespaced macOS x64 and arm64 metadata into standard latest-mac.yml', () => {
const inputDir = tempDir()
const outputDir = tempDir()
writeYaml(join(inputDir, 'latest-mac-macOS-ARM64.yml'), `
version: 0.3.2
files:
- url: Claude-Code-Haha-0.3.2-arm64.zip
sha512: arm64-checksum
size: 222
path: Claude-Code-Haha-0.3.2-arm64.zip
sha512: arm64-checksum
releaseDate: '2026-06-01T02:00:00.000Z'
`)
writeYaml(join(inputDir, 'latest-mac-macOS-x64.yml'), `
version: 0.3.2
files:
- url: Claude-Code-Haha-0.3.2-x64.zip
sha512: x64-checksum
size: 111
path: Claude-Code-Haha-0.3.2-x64.zip
sha512: x64-checksum
releaseDate: '2026-06-01T01:00:00.000Z'
`)
const result = mergeUpdateMetadataArtifacts({ metadataDir: inputDir, outDir: outputDir })
expect(result.writtenFiles.map(file => file.endsWith('latest-mac.yml'))).toContain(true)
const merged = parse(readFileSync(join(outputDir, 'latest-mac.yml'), 'utf8')) as {
files: Array<{ url: string, sha512: string, size: number }>
path: string
sha512: string
releaseDate: string
}
expect(merged.files.map(file => file.url)).toEqual([
'Claude-Code-Haha-0.3.2-x64.zip',
'Claude-Code-Haha-0.3.2-arm64.zip',
])
expect(merged.path).toBe('Claude-Code-Haha-0.3.2-x64.zip')
expect(merged.sha512).toBe('x64-checksum')
expect(merged.releaseDate).toBe('2026-06-01T02:00:00.000Z')
})
test('keeps macOS zip metadata primary when each architecture has dmg and zip files', () => {
const inputDir = tempDir()
const outputDir = tempDir()
writeYaml(join(inputDir, 'latest-mac-macOS-ARM64.yml'), `
version: 0.3.2
files:
- url: Claude-Code-Haha-0.3.2-arm64.dmg
sha512: arm64-dmg-checksum
size: 444
- url: Claude-Code-Haha-0.3.2-arm64.zip
sha512: arm64-zip-checksum
size: 333
path: Claude-Code-Haha-0.3.2-arm64.zip
sha512: arm64-zip-checksum
`)
writeYaml(join(inputDir, 'latest-mac-macOS-x64.yml'), `
version: 0.3.2
files:
- url: Claude-Code-Haha-0.3.2-x64.dmg
sha512: x64-dmg-checksum
size: 222
- url: Claude-Code-Haha-0.3.2-x64.zip
sha512: x64-zip-checksum
size: 111
path: Claude-Code-Haha-0.3.2-x64.zip
sha512: x64-zip-checksum
`)
mergeUpdateMetadataArtifacts({ metadataDir: inputDir, outDir: outputDir })
const merged = parse(readFileSync(join(outputDir, 'latest-mac.yml'), 'utf8')) as {
files: Array<{ url: string, sha512: string }>
path: string
sha512: string
}
expect(merged.files.map(file => file.url)).toEqual([
'Claude-Code-Haha-0.3.2-x64.zip',
'Claude-Code-Haha-0.3.2-x64.dmg',
'Claude-Code-Haha-0.3.2-arm64.zip',
'Claude-Code-Haha-0.3.2-arm64.dmg',
])
expect(merged.path).toBe('Claude-Code-Haha-0.3.2-x64.zip')
expect(merged.sha512).toBe('x64-zip-checksum')
})
test('restores standard linux channel names for x64 and arm64 metadata', () => {
const inputDir = tempDir()
const outputDir = tempDir()
writeYaml(join(inputDir, 'latest-linux-Linux-x64.yml'), `
version: 0.3.2
files:
- url: Claude-Code-Haha-0.3.2-x64.AppImage
sha512: linux-x64-checksum
size: 111
path: Claude-Code-Haha-0.3.2-x64.AppImage
sha512: linux-x64-checksum
`)
writeYaml(join(inputDir, 'latest-linux-Linux-ARM64.yml'), `
version: 0.3.2
files:
- url: Claude-Code-Haha-0.3.2-arm64.AppImage
sha512: linux-arm64-checksum
size: 222
path: Claude-Code-Haha-0.3.2-arm64.AppImage
sha512: linux-arm64-checksum
`)
mergeUpdateMetadataArtifacts({ metadataDir: inputDir, outDir: outputDir })
const x64 = parse(readFileSync(join(outputDir, 'latest-linux.yml'), 'utf8')) as { path: string }
const arm64 = parse(readFileSync(join(outputDir, 'latest-linux-arm64.yml'), 'utf8')) as { path: string }
expect(x64.path).toBe('Claude-Code-Haha-0.3.2-x64.AppImage')
expect(arm64.path).toBe('Claude-Code-Haha-0.3.2-arm64.AppImage')
})
test('rejects metadata groups with mixed app versions', () => {
const inputDir = tempDir()
const outputDir = tempDir()
writeYaml(join(inputDir, 'latest-mac-macOS-x64.yml'), `
version: 0.3.2
files:
- url: Claude-Code-Haha-0.3.2-x64.zip
sha512: x64-checksum
`)
writeYaml(join(inputDir, 'latest-mac-macOS-ARM64.yml'), `
version: 0.3.3
files:
- url: Claude-Code-Haha-0.3.3-arm64.zip
sha512: arm64-checksum
`)
expect(() => mergeUpdateMetadataArtifacts({ metadataDir: inputDir, outDir: outputDir }))
.toThrow('Cannot merge update metadata with different versions')
})
})