From 4f148a50dea41ac4cfbe4eeac3362c754dffb355 Mon Sep 17 00:00:00 2001 From: bQUARKz Date: Tue, 29 Sep 2026 11:40:02 +0100 Subject: [PATCH] verify real MCP runtime and DEV framebuffer parity --- README.md | 22 +- ...CP Tools and Project Knowledge Contract.md | 30 +- prometeu-app/build.gradle.kts | 13 +- .../app/runtime/DirectHeadlessOracle.java | 73 +++++ .../app/runtime/HeadlessMcpDesktopTest.java | 280 ++++++++++++++++++ .../javafx/workspaces/dev/DevWorkspace.java | 1 + .../dev/DevWorkspaceProjectionTest.java | 9 + 7 files changed, 419 insertions(+), 9 deletions(-) create mode 100644 prometeu-app/src/test/java/p/studio/app/runtime/DirectHeadlessOracle.java create mode 100644 prometeu-app/src/test/java/p/studio/app/runtime/HeadlessMcpDesktopTest.java diff --git a/README.md b/README.md index 8679dd72..46ceb89a 100644 --- a/README.md +++ b/README.md @@ -74,8 +74,26 @@ This gate builds an installed PBS example, launches the actual runtime, checks canonical PNGs and explicit reset/reboot, cancels an advance and verifies process cleanup. It also runs the actual app composition through saved-file LSP queries, rebuilds and corrective loops after compile errors and guest faults. It does not -download a runtime or substitute a protocol fixture. Full HTTP/visual integration -and external-agent acceptance remain subsequent integration gates. +download a runtime or substitute a protocol fixture. + +To verify the complete HTTP-to-runtime-to-DEV image path, run this separate gate +in a desktop environment: + +```bash +./gradlew :prometeu-app:headlessMcpDesktopTest -PstudioRuntimeInstall=/absolute/path/to/runtime --max-workers=2 +``` + +It opens the real DEV view, grants control, uses an HTTP MCP client to query LSP, +edit/build the installed PBS example and execute a fixed input timeline. PNG bytes, +frame identities, state and fault are compared with a separate direct-JSONL runtime +process; every decoded ImageView pixel and its visible identity/stale label are +checked. Reset, fresh-session repetition and rebuild are included. This automated +client is not the external coding-agent acceptance gate. + +Known language limitation: definition lookup for the bundled SDK's `Input.pad()` +currently returns no location. Project-source navigation and indexed SDK reference +reads work; an empty definition result must not be interpreted as missing runtime +support or permission to edit the SDK. ## Requirements diff --git a/docs/specs/studio/11. MCP Tools and Project Knowledge Contract.md b/docs/specs/studio/11. MCP Tools and Project Knowledge Contract.md index 65ba939c..d965626b 100644 --- a/docs/specs/studio/11. MCP Tools and Project Knowledge Contract.md +++ b/docs/specs/studio/11. MCP Tools and Project Knowledge Contract.md @@ -425,8 +425,8 @@ compression/padding. Logical and render frame counters are independent. The adapter MUST NOT invent a frame when none exists or substitute another session's image. The same neutral capture feeds DEV and MCP. Real runtime -production/cross-language equality remain phase 4 gates; encoding test pixels in -contract tests does not satisfy that integration requirement. +production/cross-language equality is verified by the phase 4 desktop integration +gate below; encoding test pixels in contract tests alone does not satisfy it. ## 7. Conformance and Delivery Boundary @@ -448,7 +448,25 @@ build/runtime ports; a separate HTTP test uses the real compiler/packer. This completes MCP-phase conformance. The packaged-runtime gate additionally exercises actual app composition, project LSP, compiler/packer, saved edits, explicit reset/reboot, build identity invalidation and corrective loops after compile -errors/guest faults. Full HTTP/visual and external-agent acceptance remain -subsequent integration gates, not implied by this service-composition gate. -API/Core and -JavaFX MUST NOT import MCP/HTTP implementations; architecture tests enforce it. +errors/guest faults. + +Step 24 adds `headlessMcpDesktopTest`: a real HTTP client drives the composed app, +installed compiler/packer/LSP and packaged Rust runtime, while the actual JavaFX +DEV view observes the shared session. An independent test-only JSONL client runs +the same saved cartridge and input timeline in another real process, without the +Studio process adapter or capture DTOs. Raw PNG bytes and each capture metadata +field match MCP; all decoded framebuffer pixels and the visible identity/stale +labels match DEV. State/fault and deterministic reset/fresh-session repetitions +are also checked. Rebuilding changes pixels/build identity and visibly marks the +old capture stale. Images remain in memory; window screenshots are not evidence. + +The fixture uses supported project-source LSP definition/symbol navigation and +indexed SDK reads. A probe of the installed SDK's `Input.pad()` definition returns +an empty result with the current language service; the gate does not claim SDK +symbol navigation where no location is returned. This is a language tooling +limitation, not a headless or MCP execution fallback. + +The automated client is not an external coding agent. Adversarial integrated +lifecycle, real-agent compatibility and final packaging acceptance remain later +gates. API/Core and JavaFX MUST NOT import MCP/HTTP implementations; architecture +tests enforce it. diff --git a/prometeu-app/build.gradle.kts b/prometeu-app/build.gradle.kts index 1912d4cf..269af92d 100644 --- a/prometeu-app/build.gradle.kts +++ b/prometeu-app/build.gradle.kts @@ -32,7 +32,7 @@ javafx { } // Opt-in desktop gate: real JavaFX toolkit and windows, no display required by normal unit tests. -tasks.named("test") { exclude("**/DevDesktopTest.class", "**/InstalledKnowledgeTest.class", "**/HeadlessInstalledRuntimeTest.class", "**/HeadlessTaskIntegrationTest.class") } +tasks.named("test") { exclude("**/DevDesktopTest.class", "**/InstalledKnowledgeTest.class", "**/HeadlessInstalledRuntimeTest.class", "**/HeadlessTaskIntegrationTest.class", "**/HeadlessMcpDesktopTest.class") } tasks.register("devDesktopTest") { group = "verification" description = "Runs the DEV/Debug desktop lifecycle and handoff smoke tests (requires a display)." @@ -66,3 +66,14 @@ tasks.register("headlessProcessTest") { include("**/HeadlessTaskIntegrationTest.class") systemProperty("studio.test.runtimeInstall", providers.gradleProperty("studioRuntimeInstall").getOrElse("")) } + +tasks.register("headlessMcpDesktopTest") { + group = "verification" + description = "Proves HTTP MCP, packaged runtime and actual DEV framebuffer parity (requires a display and -PstudioRuntimeInstall)." + testClassesDirs = sourceSets["test"].output.classesDirs + classpath = sourceSets["test"].runtimeClasspath + useJUnitPlatform() + include("**/HeadlessMcpDesktopTest.class") + systemProperty("java.awt.headless", "false") + systemProperty("studio.test.runtimeInstall", providers.gradleProperty("studioRuntimeInstall").getOrElse("")) +} diff --git a/prometeu-app/src/test/java/p/studio/app/runtime/DirectHeadlessOracle.java b/prometeu-app/src/test/java/p/studio/app/runtime/DirectHeadlessOracle.java new file mode 100644 index 00000000..c19e9b9e --- /dev/null +++ b/prometeu-app/src/test/java/p/studio/app/runtime/DirectHeadlessOracle.java @@ -0,0 +1,73 @@ +package p.studio.app.runtime; + +import com.fasterxml.jackson.databind.*; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import java.util.*; +import java.util.concurrent.*; +import static org.junit.jupiter.api.Assertions.*; + +/** Independent test-only JSONL client: no Studio gateway/DTO/capture transformation. */ +final class DirectHeadlessOracle implements AutoCloseable { + private final ObjectMapper mapper = new ObjectMapper(); + private final Process process; + private final BufferedReader output; + private final BufferedWriter input; + private final ExecutorService reader = Executors.newVirtualThreadPerTaskExecutor(); + private final Set descendants = new HashSet<>(); + private String session; + + DirectHeadlessOracle(Path installation, Path cartridge) throws Exception { + process = new ProcessBuilder(installation.resolve(System.getProperty("os.name").startsWith("Windows") ? "prometeu.exe" : "prometeu").toString(), + "headless", "--stdio").redirectError(ProcessBuilder.Redirect.DISCARD).start(); + output = process.inputReader(StandardCharsets.UTF_8); + input = process.outputWriter(StandardCharsets.UTF_8); + try { + var hello = event(); + assertEquals("hello", hello.path("type").asText()); + session = hello.path("sessionId").asText(); assertFalse(session.isBlank()); + assertEquals(1, hello.path("protocolVersion").path("major").asInt()); + var initialize = mapper.createObjectNode(); + initialize.putObject("protocolVersion").put("major", 1).put("minor", 0); + initialize.set("requiredCapabilities", hello.path("capabilities")); + call("initialize", initialize); + call("boot", mapper.createObjectNode().put("path", cartridge.toString())); + } catch (Throwable failure) { terminate(); throw failure; } + } + private JsonNode event() throws Exception { + String line = reader.submit(output::readLine).get(10, TimeUnit.SECONDS); + assertNotNull(line, "Runtime stdout closed before reply"); + process.descendants().forEach(descendants::add); + return mapper.readTree(line); + } + JsonNode call(String command, JsonNode params) throws Exception { + String id = UUID.randomUUID().toString(); + var request = mapper.createObjectNode().put("requestId", id).put("command", command).set("params", params); + input.write(request.toString()); input.newLine(); input.flush(); + while (true) { + var response = event(); + assertEquals(session, response.path("sessionId").asText()); + assertEquals(id, response.path("requestId").asText()); + if (response.path("type").asText().equals("progress")) continue; + assertEquals("response", response.path("type").asText()); + assertFalse(response.has("error"), response.toString()); + return response.path("result"); + } + } + JsonNode call(String command) throws Exception { return call(command, mapper.createObjectNode()); } + private void terminate() { + process.descendants().forEach(descendants::add); + descendants.forEach(ProcessHandle::destroyForcibly); process.destroyForcibly(); reader.shutdownNow(); + try { + assertTrue(process.waitFor(5, TimeUnit.SECONDS)); + for (var child : descendants) child.onExit().get(5, TimeUnit.SECONDS); + } catch (Exception failure) { throw new AssertionError("Oracle process cleanup failed", failure); } + } + @Override public void close() throws Exception { + try { + assertTrue(call("shutdown").path("closed").asBoolean()); + assertTrue(process.waitFor(5, TimeUnit.SECONDS)); + } finally { terminate(); } + } +} diff --git a/prometeu-app/src/test/java/p/studio/app/runtime/HeadlessMcpDesktopTest.java b/prometeu-app/src/test/java/p/studio/app/runtime/HeadlessMcpDesktopTest.java new file mode 100644 index 00000000..fbfe576d --- /dev/null +++ b/prometeu-app/src/test/java/p/studio/app/runtime/HeadlessMcpDesktopTest.java @@ -0,0 +1,280 @@ +package p.studio.app.runtime; + +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.node.ObjectNode; +import javafx.application.Platform; +import javafx.scene.Scene; +import javafx.scene.control.*; +import javafx.scene.image.ImageView; +import javafx.stage.Stage; +import org.junit.jupiter.api.*; +import org.junit.jupiter.api.io.TempDir; +import org.springframework.boot.WebApplicationType; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.context.ConfigurableApplicationContext; +import p.studio.api.automation.*; +import p.studio.api.project.*; +import p.studio.api.session.*; +import p.studio.app.StudioApplicationConfiguration; +import p.studio.app.mcp.LocalMcpServer; +import p.studio.core.project.ProjectLocalStudioSetupStore; +import p.studio.ui.javafx.events.StudioEventBus; +import p.studio.ui.javafx.utilities.i18n.*; +import p.studio.ui.javafx.workspaces.dev.DevWorkspace; +import java.io.ByteArrayInputStream; +import java.net.http.*; +import java.nio.file.*; +import java.time.Duration; +import java.util.*; +import java.util.concurrent.*; +import static org.junit.jupiter.api.Assertions.*; + +/** Full real loop: external HTTP client -> app -> Rust JSONL -> MCP image and JavaFX DEV. */ +class HeadlessMcpDesktopTest { + @TempDir Path root; + final ObjectMapper mapper = new ObjectMapper(); + final Set owned = new HashSet<>(); + ConfigurableApplicationContext app; + ProjectSession project; + LocalMcpServer server; + HttpClient client; + String connection, task, build, session; + Path installation, source; + DevWorkspace dev; + Stage stage; + I18nService locale; + + @BeforeAll static void toolkit() throws Exception { + var ready = new CompletableFuture(); + Platform.startup(() -> { Platform.setImplicitExit(false); ready.complete(null); }); + ready.get(10, TimeUnit.SECONDS); + } + @AfterAll static void stopToolkit() { Platform.exit(); } + static void fx(Runnable work) throws Exception { + var completed = new CompletableFuture(); + Platform.runLater(() -> { try { work.run(); completed.complete(null); } catch (Throwable failure) { completed.completeExceptionally(failure); } }); + completed.get(10, TimeUnit.SECONDS); + } + @BeforeEach void open() throws Exception { + String configured = System.getProperty("studio.test.runtimeInstall", ""); + assertFalse(configured.isBlank(), "Supply -PstudioRuntimeInstall="); + installation = Path.of(configured).toRealPath(); root = root.toRealPath(); + app = new SpringApplicationBuilder(StudioApplicationConfiguration.class).web(WebApplicationType.NONE).headless(false).run(); + for (var ref : p.studio.compiler.FrontendRegistryService.require("pbs").documentation().orElseThrow().references(1, p.studio.AppMode.Game)) { + if (!ref.id().startsWith("pbs:example:game:1:")) continue; + Path file = root.resolve(ref.id().substring("pbs:example:game:1:".length())); + Files.createDirectories(file.getParent()); Files.writeString(file, ref.text()); + } + source = root.resolve("src/main.pbs"); + var reference = app.getBean(ProjectCatalog.class).openProject(root); + app.getBean(ProjectLocalStudioSetupStore.class).save(reference, new ProjectLocalStudioSetup(installation.toString(), null)); + project = app.getBean(ProjectSessionFactory.class).open(reference); + server = app.getBean(LocalMcpServer.class); client = HttpClient.newHttpClient(); + fx(() -> { + locale = new I18nService(); locale.setLocale(Locale.ENGLISH); + dev = new DevWorkspace(reference, project.automation(), locale, new StudioEventBus(), app.getBean(AgentConnectionGuide.class)); + stage = new Stage(); stage.setTitle("Real MCP / headless / DEV conformance"); + stage.setScene(new Scene((javafx.scene.Parent) dev.rootNode(), 1000, 800)); stage.show(); dev.load(); + }); + var initialize = request("initialize"); + var params = initialize.putObject("params").put("protocolVersion", "2025-06-18"); + params.putObject("capabilities"); params.putObject("clientInfo").put("name", "real-loop-test").put("version", "1"); + var response = post(initialize); assertEquals(200, response.statusCode()); + connection = response.headers().firstValue("Mcp-Session-Id").orElseThrow(); + assertEquals(202, post(mapper.createObjectNode().put("jsonrpc", "2.0").put("method", "notifications/initialized")).statusCode()); + } + @AfterEach void close() throws Exception { + try { fx(() -> { if (dev != null) dev.unLoad(); if (stage != null) stage.close(); }); } + finally { + try { if (project != null) project.close(); } + finally { if (client != null) client.close(); if (app != null) app.close(); } + } + assertTrue(owned.stream().noneMatch(ProcessHandle::isAlive), "No managed runtime may survive the test"); + } + + @Test void fullHttpLoopMatchesRawRuntimePixelsAndDisplayedDevAcrossResetAndRebuild() throws Exception { + assertEquals(17, mapper.readTree(post(request("tools/list")).body()).path("result").path("tools").size()); + assertTrue(value(call("studio_project_context", args())).path("languages").toString().contains("pbs")); + value(call("studio_reference_read", args().put("referenceId", "pbs:quickstart").put("limit", 100))); + var sdk = value(call("studio_reference_read", args().put("referenceId", "pbs:sdk:game:1:sdk/input/main.pbs").put("limit", 1000))); + assertTrue(sdk.toString().contains("InputPad"), "Consult installed SDK source through the indexed read-only reference"); + assertEquals("NOT_GRANTED", call("studio_control_acquire", args()).path("structuredContent").path("error").path("code").asText()); + fx(() -> ((Button) dev.rootNode().lookup("#dev-grant")).fire()); + assertEquals(ControlState.WAITING_FOR_AGENT, project.automation().snapshot().state()); + task = value(call("studio_control_acquire", args())).path("taskId").asText(); + assertFalse(task.isBlank()); + // Agent-native edit of the installed example; SDK remains unchanged. + String edited = Files.readString(source).replace("import { Gfx } from @sdk:gfx;", + "import { Gfx } from @sdk:gfx;\nimport { Input } from @sdk:input;") + .replace("x = x + 1;", "if (Input.pad().right().down()) { x = x + 3; } else { x = x + 1; }"); + Files.writeString(source, edited); + var query = args().put("operation", "diagnostics"); query.putObject("parameters").put("uri", source.toUri().toString()); + assertTrue(value(call("studio_language_query", query)).path("result").isEmpty()); + var symbols = args().put("operation", "documentSymbols"); symbols.putObject("parameters").put("uri", source.toUri().toString()); + assertTrue(value(call("studio_language_query", symbols)).path("result").toString().contains("frame")); + int inputOffset = edited.indexOf("x = x + 3;") + "x = ".length(); + String preceding = edited.substring(0, inputOffset); + var definition = args().put("operation", "definition"); + definition.putObject("parameters").put("uri", source.toUri().toString()).putObject("position") + .put("line", preceding.chars().filter(c -> c == '\n').count()) + .put("character", inputOffset - preceding.lastIndexOf('\n') - 1); + var locations = value(call("studio_language_query", definition)).path("result"); + assertFalse(locations.isEmpty(), "Navigate the saved PBS source through the actual LSP"); + assertEquals(source.toUri().toString(), locations.get(0).path("uri").asText()); + build("first-build"); boot(); + assertEquals("NO_FRAME_AVAILABLE", call("studio_headless_capture", args()).path("structuredContent").path("error").path("code").asText()); + + List first; + try (var oracle = new DirectHeadlessOracle(installation, root.resolve("build"))) { + first = timeline("first", oracle); + } + value(call("studio_headless_reset", args())); assertStale(true); + String previousSession = session; boot(); assertEquals(previousSession, session); + try (var oracle = new DirectHeadlessOracle(installation, root.resolve("build"))) { + assertSameTimeline(first, timeline("reset", oracle)); + } + value(call("studio_headless_shutdown", args())); assertStale(true); + boot(); assertNotEquals(previousSession, session); + try (var oracle = new DirectHeadlessOracle(installation, root.resolve("build"))) { + assertSameTimeline(first, timeline("fresh", oracle)); + } + + String oldBuild = build; + Files.writeString(source, edited.replace("Color.rgb(16, 20, 28)", "Color.rgb(80, 40, 20)")); + assertTrue(value(call("studio_language_query", query)).path("result").isEmpty()); + build("rebuild"); assertNotEquals(oldBuild, build); assertStale(true); + var historical = value(call("studio_operation_get", args().put("clientRequestId", "fresh-0"))); + assertTrue(historical.path("capture").path("stale").asBoolean()); + boot(); + try (var oracle = new DirectHeadlessOracle(installation, root.resolve("build"))) { + var rebuilt = timeline("rebuilt", oracle); + assertFalse(Arrays.equals(png(first.getFirst()), png(rebuilt.getFirst()))); + } + value(call("studio_control_release", args())); + assertEquals(ControlState.MANUAL, project.automation().snapshot().state()); assertStale(true); + fx(() -> assertFalse(((Button) dev.rootNode().lookup("#dev-grant")).isDisabled())); + assertTrue(Files.readString(source).contains("Color.rgb(80, 40, 20)")); + } + + List timeline(String prefix, DirectHeadlessOracle oracle) throws Exception { + // RIGHT held for two frames, released for one, held for another three. + int[] frames = {2, 1, 3}; int[] logical = {2, 3, 6}; int[] x = {3, 6, 13}; + var captures = new ArrayList(); + for (int i = 0; i < frames.length; i++) { + if (i == 1) { value(call("studio_headless_clear_input", args())); oracle.call("clear_input"); } + else { + var input = mapper.createObjectNode().put("right", true); + value(call("studio_headless_set_input", args().set("input", input))); oracle.call("set_input", input); + } + String requestId = prefix + "-" + i; + var receipt = value(call("studio_headless_advance", args().put("clientRequestId", requestId).put("frames", frames[i]))); + var result = completed(requestId); + assertEquals("SUCCEEDED", value(result).path("result").path("status").asText()); + assertEquals(frames[i], value(result).path("progress").path("completedFrames").asInt()); + // Retrying the same receipt must not execute another batch of frames. + assertEquals(receipt.path("operationId"), value(call("studio_headless_advance", + args().put("clientRequestId", requestId).put("frames", frames[i]))).path("operationId")); + var advanced = oracle.call("advance", mapper.createObjectNode().put("frames", frames[i])); + assertEquals("completed", advanced.path("stop").asText()); + var raw = oracle.call("capture"); + var image = call("studio_headless_capture", args()); + assertArrayEquals(png(result), png(image)); + assertEquals(value(result).path("capture"), value(image)); + compareCapture(raw, image, logical[i], x[i]); + captures.add(raw.deepCopy()); + var actualState = value(call("studio_headless_state", args())).path("state"); + assertEquals(oracle.call("get_state"), actualState); + assertEquals(oracle.call("get_fault"), value(call("studio_headless_fault", args())).path("fault")); + } + return captures; + } + void compareCapture(JsonNode raw, JsonNode image, int logical, int rectangleX) throws Exception { + var metadata = value(image); + for (String field : List.of("logicalFrameIndex", "frameId", "width", "height", "stridePixels", "pixelFormat", "mimeType")) + assertEquals(raw.path(field), metadata.path(field), field); + assertEquals(logical, metadata.path("logicalFrameIndex").asInt()); + assertEquals(build, metadata.path("buildId").asText()); assertEquals(session, metadata.path("sessionId").asText()); + byte[] expected = Base64.getDecoder().decode(raw.path("data").asText()); + assertArrayEquals(expected, png(image)); + final java.awt.image.BufferedImage decoded; + try (var encoded = new javax.imageio.stream.MemoryCacheImageInputStream(new ByteArrayInputStream(expected))) { + var decoder = javax.imageio.ImageIO.getImageReaders(encoded).next(); + try { decoder.setInput(encoded); decoded = decoder.read(0); } + finally { decoder.dispose(); } + } + int width = decoded.getWidth(), height = decoded.getHeight(); + assertEquals(metadata.path("width").asInt(), width); assertEquals(metadata.path("height").asInt(), height); + assertEquals(0xfff0a030, decoded.getRGB(rectangleX, 32)); // Actual input-sensitive rectangle, not only matching blank images. + assertNotEquals(0xfff0a030, decoded.getRGB(rectangleX - 1, 32)); + int[] pixels = decoded.getRGB(0, 0, width, height, null, 0, width); + var snapshot = project.automation().snapshot(); + assertArrayEquals(expected, snapshot.capture().png()); + assertEquals(metadata.path("frameId").bigIntegerValue(), snapshot.capture().frameId()); + fx(() -> { + var canvas = (ImageView) dev.rootNode().lookup("#dev-framebuffer"); + assertNotNull(canvas.getImage()); assertFalse(canvas.getImage().isError()); + assertEquals(width, (int) canvas.getImage().getWidth()); assertEquals(height, (int) canvas.getImage().getHeight()); + var reader = canvas.getImage().getPixelReader(); + int[] displayed = new int[width * height]; + reader.getPixels(0, 0, width, height, javafx.scene.image.PixelFormat.getIntArgbInstance(), displayed, 0, width); + assertArrayEquals(pixels, displayed, "Every displayed framebuffer pixel must match the Rust PNG"); + assertFalse(canvas.isSmooth()); + String label = ((Label) dev.rootNode().lookup("#dev-capture-identity")).getText(); + assertEquals("session=" + session + " | build=" + build + " | logical=" + logical + + " | FrameId=" + metadata.path("frameId").asText() + " | " + width + "×" + height + + " | stride=" + metadata.path("stridePixels").asText(), label); + }); + assertStale(false); + } + void assertStale(boolean stale) throws Exception { + assertEquals(stale, project.automation().snapshot().stale()); + fx(() -> assertEquals(locale.text(stale ? I18n.DEV_STALE_FRAME : I18n.DEV_CURRENT_FRAME), + ((Label) dev.rootNode().lookup("#dev-image-status")).getText())); + } + void assertSameTimeline(List expected, List actual) { + assertEquals(expected, actual, "Raw runtime captures, pixels and both frame identities repeat exactly"); + } + void build(String requestId) throws Exception { + value(call("studio_build_start", args().put("clientRequestId", requestId))); + var result = value(completed(requestId)).path("result"); + assertEquals("SUCCESS", result.path("status").asText(), result.toString()); + build = result.path("buildId").asText(); assertFalse(build.isBlank()); + } + void boot() throws Exception { + session = value(call("studio_headless_boot", args().put("buildId", build))).path("sessionId").asText(); + assertFalse(session.isBlank()); + ProcessHandle.current().descendants().filter(p -> p.info().command().orElse("").startsWith(installation + "/")).forEach(owned::add); + assertFalse(owned.isEmpty(), "Observe the actual packaged runtime, not an in-process replacement"); + } + JsonNode completed(String id) throws Exception { + long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(30); + do { + var reply = call("studio_operation_get", args().put("clientRequestId", id)); + var result = value(reply); + if (result.path("workerTerminated").asBoolean()) { assertTrue(result.path("failure").isNull(), result.toString()); return reply; } + Thread.sleep(10); + } while (System.nanoTime() < deadline); + throw new AssertionError("Operation did not finish: " + id); + } + ObjectNode args() { var args = mapper.createObjectNode().put("projectRoot", root.toString()); if (task != null) args.put("taskId", task); return args; } + ObjectNode request(String method) { return mapper.createObjectNode().put("jsonrpc", "2.0").put("id", UUID.randomUUID().toString()).put("method", method); } + JsonNode call(String name, ObjectNode args) throws Exception { + var request = request("tools/call"); request.putObject("params").put("name", name).set("arguments", args); + var response = post(request); assertEquals(200, response.statusCode()); + var body = mapper.readTree(response.body()); assertFalse(body.has("error"), body.toString()); return body.path("result"); + } + HttpResponse post(JsonNode body) throws Exception { + var request = HttpRequest.newBuilder(server.connection().endpoint()).timeout(Duration.ofSeconds(15)) + .header("Authorization", server.connection().authorizationHeader()).header("Content-Type", "application/json") + .header("Accept", "application/json, text/event-stream").header("MCP-Protocol-Version", "2025-06-18"); + if (connection != null) request.header("Mcp-Session-Id", connection); + return client.send(request.POST(HttpRequest.BodyPublishers.ofString(body.toString())).build(), HttpResponse.BodyHandlers.ofString()); + } + JsonNode value(JsonNode result) { assertFalse(result.path("isError").asBoolean(), result.toString()); return result.path("structuredContent").path("value"); } + byte[] png(JsonNode result) { + if (result.has("data")) return Base64.getDecoder().decode(result.path("data").asText()); + assertEquals("image", result.path("content").get(1).path("type").asText()); + assertEquals("image/png", result.path("content").get(1).path("mimeType").asText()); + return Base64.getDecoder().decode(result.path("content").get(1).path("data").asText()); + } +} diff --git a/prometeu-studio-ui-javafx/src/main/java/p/studio/ui/javafx/workspaces/dev/DevWorkspace.java b/prometeu-studio-ui-javafx/src/main/java/p/studio/ui/javafx/workspaces/dev/DevWorkspace.java index b1fe3936..f3585aac 100644 --- a/prometeu-studio-ui-javafx/src/main/java/p/studio/ui/javafx/workspaces/dev/DevWorkspace.java +++ b/prometeu-studio-ui-javafx/src/main/java/p/studio/ui/javafx/workspaces/dev/DevWorkspace.java @@ -46,6 +46,7 @@ public final class DevWorkspace extends Workspace { scroll.setFitToWidth(true); root.setPadding(new Insets(16)); root.getStyleClass().add("dev-workspace"); grant.setId("dev-grant"); reclaim.setId("dev-reclaim"); + canvas.setId("dev-framebuffer"); identity.setId("dev-capture-identity"); imageStatus.setId("dev-image-status"); grant.textProperty().bind(i18n.bind(I18n.DEV_GRANT)); reclaim.textProperty().bind(i18n.bind(I18n.DEV_RECLAIM)); grant.setOnAction(e -> grant(false)); diff --git a/prometeu-studio-ui-javafx/src/test/java/p/studio/ui/javafx/workspaces/dev/DevWorkspaceProjectionTest.java b/prometeu-studio-ui-javafx/src/test/java/p/studio/ui/javafx/workspaces/dev/DevWorkspaceProjectionTest.java index cf26fa4c..b03e7744 100644 --- a/prometeu-studio-ui-javafx/src/test/java/p/studio/ui/javafx/workspaces/dev/DevWorkspaceProjectionTest.java +++ b/prometeu-studio-ui-javafx/src/test/java/p/studio/ui/javafx/workspaces/dev/DevWorkspaceProjectionTest.java @@ -25,6 +25,15 @@ class DevWorkspaceProjectionTest { assertTrue(view.identity().contains("session-A")); assertTrue(view.identity().contains("build-B")); assertEquals("diagnostic", view.diagnostics()); assertEquals("call", view.calls()); } + @Test void projectionDoesNotNarrowUnsignedFrameIdentities() { + var logical = new java.math.BigInteger("18446744073709551615"); + var render = new java.math.BigInteger("9223372036854775808"); + var frame = new CanonicalCapture("session", "build", logical, render, 2, 1, 3, new byte[]{1}); + var view = DevWorkspaceProjection.from(snapshot(ControlState.AGENT_WORKING, frame, false, false)); + assertSame(frame, view.capture()); + assertEquals("session=session | build=build | logical=18446744073709551615 | FrameId=9223372036854775808 | 2×1 | stride=3", view.identity()); + assertFalse(view.stale()); + } private AutomationSnapshot snapshot(ControlState state, CanonicalCapture frame, boolean stale, boolean closed) { return new AutomationSnapshot(Path.of("."), state, false, closed, 0, null, null, frame, stale, List.of("diagnostic"), List.of("call")); }