import { describe, expect, it } from 'vitest' import { DEFAULT_BASE, readBase, runtime } from '../../src/app/runtime' function docWith(content: string | null): Document { const doc = document.implementation.createHTMLDocument('test') if (content !== null) { const meta = doc.createElement('meta') meta.setAttribute('name', 'summer-admin-base') meta.setAttribute('content', content) doc.head.appendChild(meta) } return doc } describe('runtime base', () => { it('derives the router base and the API base from the served meta', () => { expect(runtime.base).toBe('/admin-test') expect(runtime.api).toBe('/admin-test/api/v1') }) it('reads a custom prefix and trims trailing slashes and whitespace', () => { expect(readBase(docWith('/acp'))).toBe('/acp') expect(readBase(docWith(' /acp/panel// '))).toBe('/acp/panel') }) it.each([ ['a missing meta', null], ['an empty value', ''], ['the unreplaced build token', '__SUMMER_ADMIN_BASE__'], ['a relative path', 'backend'], ['an absolute URL', 'https://evil.example/backend'], ['the root alone', '/'], ['slashes only', '///'], ])('falls back to the default for %s', (_label, content) => { expect(readBase(docWith(content))).toBe(DEFAULT_BASE) }) it('uses /backend as the default', () => { expect(DEFAULT_BASE).toBe('/backend') }) })