Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"preview": "vite preview",
"preview": "vite preview --base /Prometheus/",
"test": "vitest run",
"test:e2e": "playwright test"
},
Expand Down
10 changes: 9 additions & 1 deletion web/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BookText, Check, Copy, Download, FileCode2, Github, Loader2, Play, RotateCcw, Share2, Square } from "lucide-react"
import { BookText, Check, Copy, Download, FileCode2, Github, Loader2, Play, RotateCcw, Share2, Square, TriangleAlert } from "lucide-react"
import { useEffect, useRef, useState } from "react"
import { toast } from "sonner"

Expand Down Expand Up @@ -602,6 +602,14 @@ export default function App() {
<TooltipContent>Share link</TooltipContent>
</Tooltip>
</div>
{preset === "Strong" ? (
<div className="flex items-start gap-2 rounded-md border border-amber-300 bg-amber-50 px-3 py-2 text-xs leading-snug text-amber-900 md:col-span-2 xl:col-span-5 dark:border-amber-500/40 dark:bg-amber-500/10 dark:text-amber-200">
<TriangleAlert className="mt-0.5 size-3.5 shrink-0" aria-hidden="true" />
<p>
Strong is very strict and only supports Lua 5.1. It will fail in environments such as the web playground runtime (Lua 5.4).
</p>
</div>
) : null}
</div>
</section>

Expand Down
16 changes: 16 additions & 0 deletions web/src/e2e/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ test("runs input script and shows logs", async ({ page }) => {
await expect(page.getByText("Run works")).toBeVisible()
})

test("shows a strictness warning for the Strong preset", async ({ page }) => {
await page.goto("/")
await expect(page.getByRole("heading", { name: "Prometheus Playground" })).toBeVisible()

const warning = page.getByText("Strong is very strict and only supports Lua 5.1. It will fail in environments such as the web playground runtime (Lua 5.4).")
await expect(warning).toBeHidden()

await page.getByRole("combobox").first().click()
await page.getByRole("option", { name: "Strong" }).click()
await expect(warning).toBeVisible()

await page.getByRole("combobox").first().click()
await page.getByRole("option", { name: "Medium" }).click()
await expect(warning).toBeHidden()
})

test("share link roundtrip keeps the same obfuscated output", async ({ browser, page, context }) => {
await context.grantPermissions(["clipboard-read", "clipboard-write"])
await page.goto("/")
Expand Down
12 changes: 10 additions & 2 deletions web/src/worker/prometheusRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ type LuaFactoryConstructor = new (

let luaFactoryCtorPromise: Promise<LuaFactoryConstructor> | null = null

function resolveWasmUri(wasmUrl: string): string {
if (typeof process !== "undefined" && process.versions?.node && wasmUrl.startsWith("/@fs/")) {
return wasmUrl.slice("/@fs".length)
}

return wasmUrl
}

async function getLuaFactoryConstructor(): Promise<LuaFactoryConstructor> {
if (luaFactoryCtorPromise) {
return luaFactoryCtorPromise
Expand Down Expand Up @@ -174,7 +182,7 @@ export async function runPrometheus(options: PrometheusOptions): Promise<Prometh
// Force a local Vite-managed Wasm URL so dev/preview behave the same and
// we don't depend on wasmoon's default CDN URL resolution in workers.
const LuaFactory = await getLuaFactoryConstructor()
lua = await new LuaFactory(glueWasmUrl).createEngine({ openStandardLibs: true })
lua = await new LuaFactory(resolveWasmUri(glueWasmUrl)).createEngine({ openStandardLibs: true })

const result = (await lua.doString(buildRunLua(options))) as {
ok?: unknown
Expand Down Expand Up @@ -210,7 +218,7 @@ export async function runLuaScript(

try {
const LuaFactory = await getLuaFactoryConstructor()
lua = await new LuaFactory(glueWasmUrl).createEngine({ openStandardLibs: true })
lua = await new LuaFactory(resolveWasmUri(glueWasmUrl)).createEngine({ openStandardLibs: true })
if (onLog) {
const luaGlobal = lua.global as unknown as {
set?: (name: string, value: (...args: unknown[]) => void) => void
Expand Down
Loading