| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- import { lstatSync, mkdtempSync, rmSync } from 'node:fs'
- import { tmpdir } from 'node:os'
- import { join } from 'node:path'
- import { afterEach, describe, expect, it } from 'vitest'
- import {
- currentTarget,
- formatCommandFailure,
- serviceInstallInvocation,
- switchCurrent,
- validateManifest,
- } from '../bin/hermes-yaoyao-updater.mjs'
- const roots: string[] = []
- afterEach(() => {
- for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true })
- })
- describe('standalone updater primitives', () => {
- it('atomically switches the stable current symlink', () => {
- const root = mkdtempSync(join(tmpdir(), 'hermes-updater-'))
- roots.push(root)
- const first = join(root, 'releases', '0.2.0-a')
- const second = join(root, 'releases', '0.3.0-b')
- switchCurrent(root, first, 'first')
- expect(currentTarget(root)).toBe(first)
- switchCurrent(root, second, 'second')
- expect(currentTarget(root)).toBe(second)
- expect(lstatSync(join(root, 'current')).isSymbolicLink()).toBe(true)
- })
- it('rejects a mismatched release manifest before any service transition', () => {
- expect(() => validateManifest({
- schemaVersion: 1,
- releaseVersion: '0.3.0',
- webVersion: '0.3.1',
- pluginVersion: '1.8.0',
- gitTag: 'v0.3.0',
- })).toThrow('版本组合不一致')
- })
- it('keeps useful command output while redacting credentials', () => {
- const error = Object.assign(new Error('Command failed'), {
- status: 127,
- stdout: '\u001B[31m发布版本校验通过\u001B[0m',
- stderr: 'https://secret@example.test/release.git\nsh: vue-tsc: command not found',
- })
- const message = formatCommandFailure('npm', ['run', 'build'], error)
- expect(message).toContain('npm run build 失败,退出码 127')
- expect(message).toContain('发布版本校验通过')
- expect(message).toContain('https://***@example.test/release.git')
- expect(message).toContain('vue-tsc: command not found')
- expect(message).not.toContain('secret')
- expect(message).not.toContain('\u001B')
- })
- it('uses the new lifecycle code while starting a rolled-back release', () => {
- const releaseRoot = '/Users/test/.local/share/hermes-yaoyao'
- const oldRelease = join(releaseRoot, 'releases', '0.2.11-old')
- const newRelease = join(releaseRoot, 'releases', '0.2.12-new')
- const invocation = serviceInstallInvocation(
- oldRelease,
- { releaseRoot, source: 'https://example.test/hermes-yaoyao.git' },
- true,
- newRelease,
- )
- expect(invocation.cli).toBe(join(newRelease, 'bin', 'hermes-yaoyao.mjs'))
- expect(invocation.env.HERMES_YAOYAO_SERVICE_ROOT).toBe(join(releaseRoot, 'current'))
- expect(invocation.env.HERMES_YAOYAO_RELEASE_SOURCE).toBe('https://example.test/hermes-yaoyao.git')
- const sourceRollback = serviceInstallInvocation(
- oldRelease,
- { releaseRoot, source: 'https://example.test/hermes-yaoyao.git' },
- false,
- newRelease,
- )
- expect(sourceRollback.cli).toBe(join(newRelease, 'bin', 'hermes-yaoyao.mjs'))
- expect(sourceRollback.env.HERMES_YAOYAO_SERVICE_ROOT).toBeUndefined()
- })
- })
|