## Summary - prefer the bundled desktop UI over the downloaded cache when both report the same version, so rebuilt installers do not keep serving stale frontend assets - rebuild the server workspace during the Tauri prebuild step on every desktop package build, matching Electron's correctness boundary for fresh UI/server assets - add a regression test covering the equal-version bundled-vs-downloaded UI selection path ## Why - local desktop rebuilds should reflect the latest server and UI code without requiring users to manually clear cached assets - packaged updates should keep favoring the freshly bundled frontend when the cached copy is not actually newer ## Testing - node --import tsx --test packages/server/src/ui/__tests__/remote-ui.test.ts - npm run build:tauri
86 lines
2.8 KiB
TypeScript
86 lines
2.8 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import { mkdtempSync, rmSync, writeFileSync } from "node:fs"
|
|
import { mkdir } from "node:fs/promises"
|
|
import os from "node:os"
|
|
import path from "node:path"
|
|
import { afterEach, beforeEach, describe, it } from "node:test"
|
|
|
|
import type { Logger } from "../../logger"
|
|
import { resolveUi } from "../remote-ui"
|
|
|
|
const noopLogger: Logger = {
|
|
debug: () => {},
|
|
info: () => {},
|
|
warn: () => {},
|
|
error: () => {},
|
|
trace: () => {},
|
|
child: () => noopLogger,
|
|
isLevelEnabled: () => false,
|
|
} as any
|
|
|
|
let tempRoot: string
|
|
|
|
beforeEach(() => {
|
|
tempRoot = mkdtempSync(path.join(os.tmpdir(), "codenomad-ui-test-"))
|
|
})
|
|
|
|
afterEach(() => {
|
|
rmSync(tempRoot, { recursive: true, force: true })
|
|
})
|
|
|
|
describe("resolveUi local version preference", () => {
|
|
it("prefers bundled when bundled version is higher", async () => {
|
|
const bundledDir = path.join(tempRoot, "bundled")
|
|
const configDir = path.join(tempRoot, "config")
|
|
const currentDir = path.join(configDir, "ui", "current")
|
|
|
|
await mkdir(bundledDir, { recursive: true })
|
|
await mkdir(currentDir, { recursive: true })
|
|
|
|
writeFileSync(path.join(bundledDir, "index.html"), "<html>bundled</html>")
|
|
writeFileSync(path.join(bundledDir, "ui-version.json"), JSON.stringify({ uiVersion: "0.8.1" }))
|
|
|
|
writeFileSync(path.join(currentDir, "index.html"), "<html>current</html>")
|
|
writeFileSync(path.join(currentDir, "ui-version.json"), JSON.stringify({ uiVersion: "0.8.0" }))
|
|
|
|
const result = await resolveUi({
|
|
serverVersion: "0.8.1",
|
|
bundledUiDir: bundledDir,
|
|
autoUpdate: false,
|
|
configDir,
|
|
logger: noopLogger,
|
|
})
|
|
|
|
assert.equal(result.source, "bundled")
|
|
assert.equal(result.uiStaticDir, bundledDir)
|
|
assert.equal(result.uiVersion, "0.8.1")
|
|
})
|
|
|
|
it("prefers bundled when bundled and downloaded versions are equal", async () => {
|
|
const bundledDir = path.join(tempRoot, "bundled")
|
|
const configDir = path.join(tempRoot, "config")
|
|
const currentDir = path.join(configDir, "ui", "current")
|
|
|
|
await mkdir(bundledDir, { recursive: true })
|
|
await mkdir(currentDir, { recursive: true })
|
|
|
|
writeFileSync(path.join(bundledDir, "index.html"), "<html>bundled</html>")
|
|
writeFileSync(path.join(bundledDir, "ui-version.json"), JSON.stringify({ uiVersion: "0.8.1" }))
|
|
|
|
writeFileSync(path.join(currentDir, "index.html"), "<html>current</html>")
|
|
writeFileSync(path.join(currentDir, "ui-version.json"), JSON.stringify({ uiVersion: "0.8.1" }))
|
|
|
|
const result = await resolveUi({
|
|
serverVersion: "0.8.1",
|
|
bundledUiDir: bundledDir,
|
|
autoUpdate: false,
|
|
configDir,
|
|
logger: noopLogger,
|
|
})
|
|
|
|
assert.equal(result.source, "bundled")
|
|
assert.equal(result.uiStaticDir, bundledDir)
|
|
assert.equal(result.uiVersion, "0.8.1")
|
|
})
|
|
})
|