Add shared human/task asset batches with reviewed atomic publication, explicit reference rebinds, ownership inspection and qualified glyph/scene budgets. Expose the same authoring and capacity results through Assets and MCP. Deliver isolated guest test targets, retained visual evidence and immutable runtime lifecycle/control observations. Preserve provider qualification and installed authoring examples alongside the completed discussion lessons. Close AGD-106 coordination and the delivered discussion workflows through housekeeping, updating lesson references and preserving qualification limits. Sound remains outside the asset delivery wave. Validation: 579 module tests and 31 additional desktop, process and installed checks passed; native glyph/scene 16/17 boundaries qualified. Discussion validation passed after housekeeping.
334 lines
25 KiB
Java
334 lines
25 KiB
Java
package p.studio.app;
|
|
|
|
import javafx.application.Platform;
|
|
import javafx.scene.Scene;
|
|
import javafx.scene.control.*;
|
|
import javafx.scene.layout.VBox;
|
|
import javafx.stage.Stage;
|
|
import org.junit.jupiter.api.*;
|
|
import org.junit.jupiter.api.io.TempDir;
|
|
import p.studio.api.automation.*;
|
|
import p.studio.api.operation.OperationSubscription;
|
|
import p.studio.api.project.*;
|
|
import p.studio.app.operation.ExecutorOperationExecutor;
|
|
import p.studio.core.execution.DefaultExecutionSession;
|
|
import p.studio.core.session.DefaultAutomationSession;
|
|
import p.studio.ui.javafx.controls.forms.*;
|
|
import p.studio.ui.javafx.events.StudioEventBus;
|
|
import p.studio.ui.javafx.utilities.i18n.I18nService;
|
|
import p.studio.ui.javafx.workspaces.*;
|
|
import p.studio.ui.javafx.workspaces.debug.DebugWorkspace;
|
|
import p.studio.ui.javafx.workspaces.dev.*;
|
|
import java.nio.file.*;
|
|
import java.util.List;
|
|
import java.util.concurrent.*;
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
/** Uses the actual desktop toolkit; runtime, operation and document inputs are test consumers only. */
|
|
class DevDesktopTest {
|
|
@TempDir Path root;
|
|
@BeforeAll static void toolkit() throws Exception {
|
|
var ready = new CompletableFuture<Void>();
|
|
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<Void>();
|
|
Platform.runLater(() -> { try { work.run(); completed.complete(null); } catch (Throwable failure) { completed.completeExceptionally(failure); } });
|
|
completed.get(10, TimeUnit.SECONDS);
|
|
}
|
|
|
|
static void awaitWaiting(AutomationSession authority) throws Exception {
|
|
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(5);
|
|
while (authority.snapshot().state() != ControlState.WAITING_FOR_AGENT && System.nanoTime() < deadline) Thread.sleep(5);
|
|
assertEquals(ControlState.WAITING_FOR_AGENT, authority.snapshot().state());
|
|
}
|
|
|
|
@Test void visualEvidenceInspectorShowsSharedMetricsExactPixelsAndExplicitBaselineReview() throws Exception {
|
|
root=root.toRealPath();var pool=Executors.newSingleThreadExecutor();
|
|
var authority=new DefaultAutomationSession(root,new ExecutorOperationExecutor(pool));
|
|
var projects=new p.studio.core.project.ProjectAccessRegistry();projects.register(root,authority::enterManual,()->!authority.snapshot().closed(),authority);
|
|
var codec=new p.studio.app.evidence.PngEvidenceCodec();var mapper=new com.fasterxml.jackson.databind.ObjectMapper();
|
|
var tools=new p.studio.core.session.DefaultEvidenceTools(projects,null,new p.studio.app.evidence.FileEvidenceStore(mapper),codec);
|
|
byte[] original={10,20,30,0,40,50,60,(byte)255,70,80,90,(byte)255,1,2,3,(byte)255,4,5,6,(byte)255,7,8,9,(byte)255};
|
|
Path expectedFile=root.resolve("expected.png"),actualFile=root.resolve("actual.png");
|
|
Files.write(expectedFile,codec.encode(new Evidence.Pixels(3,2,original)));var changed=original.clone();changed[20]=8;
|
|
Files.write(actualFile,codec.encode(new Evidence.Pixels(3,2,changed)));
|
|
var expected=tools.importReference(root,null,"expected",expectedFile,null).artifacts().getFirst();
|
|
var actual=tools.importReference(root,null,"actual",actualFile,null).artifacts().getFirst();
|
|
var report=tools.compare(root,null,"desktop-comparison",expected.id(),actual.id(),Evidence.Parameters.exact(Evidence.Alpha.compare));
|
|
assertEquals(1,report.report().differentPixels());
|
|
var registry=new p.studio.app.mcp.McpToolRegistry(new p.studio.app.mcp.McpToolCatalog(mapper),mapper,p.studio.app.mcp.McpEvidenceTools.handlers(tools,mapper));
|
|
var inspector=new EvidenceInspector[1];var stage=new Stage[1];
|
|
try {
|
|
fx(()->{inspector[0]=new EvidenceInspector(root,authority,tools);stage[0]=new Stage();stage[0].setTitle("Visual checkpoint evidence qualification");
|
|
var scroll=new ScrollPane(inspector[0]);scroll.setFitToWidth(true);stage[0].setScene(new Scene(scroll,1100,850));stage[0].show();inspector[0].refresh();});
|
|
long deadline=System.nanoTime()+TimeUnit.SECONDS.toNanos(10);var ready=new java.util.concurrent.atomic.AtomicBoolean();
|
|
while(!ready.get()&&System.nanoTime()<deadline){fx(()->{var facts=(TextArea)inspector[0].lookup("#evidence-facts");ready.set(facts.getText().contains("Different pixels: 1"));});Thread.sleep(10);}
|
|
assertTrue(ready.get());
|
|
fx(()->{
|
|
assertNotNull(inspector[0].lookup("#evidence-expected"));assertNotNull(inspector[0].lookup("#evidence-actual"));assertNotNull(inspector[0].lookup("#evidence-diff"));
|
|
assertEquals("Expected (0, 0) RGBA = 10, 20, 30, 0",EvidenceInspector.pixelText("Expected",new Evidence.Pixels(3,2,original),0,0));
|
|
var preview=inspector[0].lookup("#evidence-expected");
|
|
var pointer=preview.localToScene(8,8);
|
|
preview.fireEvent(new javafx.scene.input.MouseEvent(javafx.scene.input.MouseEvent.MOUSE_MOVED,
|
|
pointer.getX(),pointer.getY(),8,8,javafx.scene.input.MouseButton.NONE,0,false,false,false,false,false,false,false,false,false,false,
|
|
new javafx.scene.input.PickResult(preview,pointer.getX(),pointer.getY())));
|
|
assertTrue(((Label)inspector[0].lookup("#evidence-pixel")).getText().contains("RGBA = 10, 20, 30, 0"));
|
|
var approve=(Button)inspector[0].lookup("#evidence-approve-baseline");assertFalse(approve.isDisabled());
|
|
// The desktop action requires an explicit confirmation before invoking the manual service.
|
|
Platform.runLater(()->{for(var window:java.util.List.copyOf(javafx.stage.Window.getWindows()))if(window.getScene()!=null&&window.getScene().getRoot() instanceof DialogPane pane)
|
|
((Button)pane.lookupButton(ButtonType.OK)).fire();});
|
|
approve.fire();
|
|
});
|
|
deadline=System.nanoTime()+TimeUnit.SECONDS.toNanos(10);
|
|
while(tools.list(root,null).stream().noneMatch(p->p.baseline()!=null)&&System.nanoTime()<deadline)Thread.sleep(10);
|
|
var baseline=tools.list(root,null).stream().filter(p->p.baseline()!=null).findFirst().orElseThrow();assertEquals(expected.id(),baseline.baseline().artifactId());
|
|
authority.grant(false).toCompletableFuture().get(5,TimeUnit.SECONDS);String task=authority.acquire().task().value();
|
|
var arguments=mapper.createObjectNode().put("projectRoot",root.toString()).put("taskId",task).put("limit",100);
|
|
var wire=registry.call("studio_evidence_list",arguments).wire().path("structuredContent").path("value").path("publications");
|
|
var mcpReport=java.util.stream.StreamSupport.stream(wire.spliterator(),false).filter(p->p.path("id").asText().equals(report.id())).findFirst().orElseThrow().path("report");
|
|
assertEquals(mapper.valueToTree(report.report()),mcpReport);
|
|
fx(()->{
|
|
inspector[0].setManual(false);assertTrue(((Button)inspector[0].lookup("#evidence-approve-baseline")).isDisabled());
|
|
assertFalse(((ComboBox<?>)inspector[0].lookup("#evidence-publications")).isDisabled());
|
|
var image=stage[0].getScene().snapshot(null);var buffer=new java.awt.image.BufferedImage((int)image.getWidth(),(int)image.getHeight(),java.awt.image.BufferedImage.TYPE_INT_ARGB);
|
|
for(int y=0;y<buffer.getHeight();y++)for(int x=0;x<buffer.getWidth();x++)buffer.setRGB(x,y,image.getPixelReader().getArgb(x,y));
|
|
try{Path file=Path.of("build/evidence-qualification/inspector.png");Files.createDirectories(file.getParent());javax.imageio.ImageIO.write(buffer,"png",file.toFile());}catch(Exception e){throw new RuntimeException(e);}
|
|
});
|
|
}finally{fx(()->{if(stage[0]!=null)stage[0].close();});authority.closeAsync().toCompletableFuture().join();pool.shutdownNow();}
|
|
}
|
|
|
|
@Test void devDebugNavigationBackgroundProjectionAndDisposal() throws Exception {
|
|
var pool = Executors.newSingleThreadExecutor();
|
|
var authority = new DefaultAutomationSession(root, new ExecutorOperationExecutor(pool));
|
|
var subscriptions = new AtomicInteger();
|
|
var observed = (AutomationSession) java.lang.reflect.Proxy.newProxyInstance(getClass().getClassLoader(),
|
|
new Class[]{AutomationSession.class}, (proxy, method, args) -> {
|
|
var result = method.invoke(authority, args);
|
|
if (method.getName().equals("subscribe")) {
|
|
subscriptions.incrementAndGet();
|
|
return (OperationSubscription) () -> { ((OperationSubscription) result).unsubscribe(); subscriptions.decrementAndGet(); };
|
|
}
|
|
return result;
|
|
});
|
|
var stage = new Stage[1]; var host = new WorkspaceHost[1]; var dev = new DevWorkspace[1];
|
|
var locale = new I18nService();
|
|
try {
|
|
fx(() -> {
|
|
var project = new ProjectReference("DEV smoke", "1", "pbs", 1, ProjectTarget.Game, root);
|
|
var events = new StudioEventBus();
|
|
host[0] = new WorkspaceHost();
|
|
dev[0] = new DevWorkspace(project, observed, locale, events);
|
|
host[0].register(dev[0]);
|
|
host[0].register(new DebugWorkspace(project, new DefaultExecutionSession(), locale, events));
|
|
stage[0] = new Stage(); stage[0].setTitle("DEV/Debug desktop verification");
|
|
stage[0].setScene(new Scene(host[0], 1050, 800)); stage[0].show(); host[0].change(WorkspaceId.DEV);
|
|
});
|
|
fx(() -> {
|
|
assertEquals(1, subscriptions.get());
|
|
assertTrue(((Button) dev[0].rootNode().lookup("#dev-mcp-config")).isDisabled());
|
|
((Button) dev[0].rootNode().lookup("#dev-grant")).fire();
|
|
});
|
|
awaitWaiting(authority);
|
|
fx(() -> {
|
|
assertEquals(ControlState.WAITING_FOR_AGENT, authority.snapshot().state());
|
|
host[0].change(WorkspaceId.DEBUG); assertEquals(0, subscriptions.get());
|
|
assertEquals(ControlState.WAITING_FOR_AGENT, authority.snapshot().state());
|
|
host[0].change(WorkspaceId.DEV);
|
|
});
|
|
fx(() -> assertEquals(1, subscriptions.get()));
|
|
var task = authority.acquire(); // Intentionally outside the FX thread.
|
|
authority.attachRuntime(task.task(), new ManagedHeadlessSession() {
|
|
public String sessionId() { return "smoke-session"; }
|
|
public void cancel() { }
|
|
public CompletionStage<Void> shutdown() { return CompletableFuture.completedFuture(null); }
|
|
});
|
|
// Real 1x1 PNG, supplied by the test runtime. Product never fabricates captures.
|
|
var png = java.util.Base64.getDecoder().decode("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+a9l0AAAAASUVORK5CYII=");
|
|
authority.submit(task.task(), "capture", () -> new AutomationOutcome(AutomationOutcome.Kind.SUCCEEDED, 4, 4, List.of(),
|
|
new CanonicalCapture("smoke-session", "smoke-build", 4, 1, 1, 1, 1, png))).termination().toCompletableFuture().get(5, TimeUnit.SECONDS);
|
|
fx(() -> {
|
|
assertTrue(((Button) dev[0].rootNode().lookup("#dev-grant")).isDisabled());
|
|
assertTrue(dev[0].rootNode().lookupAll(".label").stream().filter(n -> n instanceof Label)
|
|
.map(n -> ((Label) n).getText()).anyMatch(t -> t.contains("logical=4") && t.contains("FrameId=1")));
|
|
((Button) dev[0].rootNode().lookup("#dev-reclaim")).fire();
|
|
assertEquals(ControlState.MANUAL, authority.snapshot().state());
|
|
assertTrue(authority.snapshot().stale());
|
|
locale.setLocale(java.util.Locale.forLanguageTag("pt-BR"));
|
|
host[0].deactivateCurrentWorkspace(); assertEquals(0, subscriptions.get());
|
|
authority.grant(false); locale.setLocale(java.util.Locale.ENGLISH);
|
|
});
|
|
awaitWaiting(authority);
|
|
} finally {
|
|
fx(() -> { if (host[0] != null) host[0].deactivateCurrentWorkspace(); if (stage[0] != null) stage[0].close(); });
|
|
authority.closeAsync().toCompletableFuture().get(5, TimeUnit.SECONDS); pool.shutdownNow();
|
|
}
|
|
}
|
|
|
|
@Test void explainedDiagnosticPaneExpandsFactsAndOpensCurrentReadOnlySource() throws Exception {
|
|
var source = root.resolve("main.pbs"); Files.writeString(source, "fn x() {}\n");
|
|
var digest = java.util.HexFormat.of().formatHex(java.security.MessageDigest.getInstance("SHA-256").digest(Files.readAllBytes(source)));
|
|
var value = new java.util.LinkedHashMap<>(p.studio.utilities.json.DiagnosticPayloads.issue("TEST_EXPLAINED", "ERROR", "Recorded detector failure"));
|
|
value.put("checkId", "compiler.verify.ret-stack-height");
|
|
value.put("explanation", java.util.Map.of("availability", "available", "summary", "RET must match the declared result slot count."));
|
|
value.put("facts", java.util.Map.of("expectedHeight", 0, "actualHeight", 1));
|
|
value.put("origin", java.util.Map.of("uri", source.toUri().toString(), "revision", digest, "range", java.util.Map.of("start", java.util.Map.of("line", 0, "character", 3), "end", java.util.Map.of("line", 0, "character", 4))));
|
|
var pane = new p.studio.ui.javafx.diagnostics.DiagnosticResultsPane[1]; var window = new Stage[1];
|
|
try {
|
|
fx(() -> {
|
|
pane[0] = new p.studio.ui.javafx.diagnostics.DiagnosticResultsPane(root,
|
|
origin -> p.studio.core.project.DiagnosticNavigation.read(root, origin));
|
|
var view = p.studio.utilities.json.DiagnosticPayloads.view(java.util.List.of(value), "build", "failed", java.util.List.of(), "partial");
|
|
pane[0].show(java.util.Map.of("issues", view.issues(), "summary", view.summary(), "context", java.util.Map.of()));
|
|
window[0] = new Stage(); window[0].setTitle("Explained diagnostics desktop qualification");
|
|
var scroll = new ScrollPane(pane[0]); scroll.setFitToWidth(true);
|
|
window[0].setScene(new Scene(scroll, 1050, 900)); window[0].show();
|
|
pane[0].getChildren().stream().filter(n -> n instanceof TitledPane).map(n -> (TitledPane)n).findFirst().orElseThrow().setExpanded(true); pane[0].applyCss(); pane[0].layout();
|
|
var body = (VBox)pane[0].getChildren().stream().filter(n -> n instanceof TitledPane).map(n -> (TitledPane)n).findFirst().orElseThrow().getContent();
|
|
assertTrue(body.getChildren().stream().filter(n -> n instanceof Label).anyMatch(n -> ((Label)n).getText().contains("RET")));
|
|
body.getChildren().stream().filter(n -> n instanceof TitledPane && ((TitledPane)n).getText().equals("facts")).map(n -> (TitledPane)n).forEach(n -> n.setExpanded(true));
|
|
pane[0].applyCss(); pane[0].layout();
|
|
var image = window[0].getScene().snapshot(null); var pixels = image.getPixelReader();
|
|
var buffer = new java.awt.image.BufferedImage((int)image.getWidth(), (int)image.getHeight(), java.awt.image.BufferedImage.TYPE_INT_ARGB);
|
|
for (int y=0; y<buffer.getHeight(); y++) for (int x=0; x<buffer.getWidth(); x++) buffer.setRGB(x,y,pixels.getArgb(x,y));
|
|
try { var path = Path.of("build/diagnostic-qualification/diagnostic-desktop.png"); Files.createDirectories(path.getParent()); javax.imageio.ImageIO.write(buffer,"png",path.toFile()); }
|
|
catch (Exception error) { throw new RuntimeException(error); }
|
|
body.getChildren().stream().filter(n -> n instanceof Button && ((Button)n).getText().equals("Open source")).map(n -> (Button)n).findFirst().orElseThrow().fire();
|
|
});
|
|
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(5); var opened = new java.util.concurrent.atomic.AtomicBoolean();
|
|
while (!opened.get() && System.nanoTime() < deadline) {
|
|
fx(() -> { for (var visible : javafx.stage.Window.getWindows()) if (visible instanceof Stage stage && stage.getTitle().startsWith("Current source")) {
|
|
var viewer = (TextArea)((VBox)stage.getScene().getRoot()).getChildren().get(1);
|
|
assertFalse(viewer.isEditable()); assertEquals("x", viewer.getSelectedText()); opened.set(true);
|
|
} });
|
|
if (!opened.get()) Thread.sleep(10);
|
|
}
|
|
assertTrue(opened.get(), "Source viewer opened with verified revision and selection");
|
|
} finally { fx(() -> { for (var visible : java.util.List.copyOf(javafx.stage.Window.getWindows())) visible.hide(); }); }
|
|
}
|
|
|
|
@Test void formsSaveFailurePreservesDraftAndReturnReadsExternalContent() throws Exception {
|
|
var file = root.resolve("document.txt"); Files.writeString(file, "initial");
|
|
fx(() -> {
|
|
var form = new TestForm(); form.draft = "edited"; form.dirty = true;
|
|
form.fail = true;
|
|
assertThrows(CompletionException.class, () -> form.saveForHandoff().toCompletableFuture().join());
|
|
assertTrue(form.hasUnsavedDraft()); assertEquals("edited", form.draft);
|
|
form.fail = false; form.saveForHandoff().toCompletableFuture().join(); assertFalse(form.hasUnsavedDraft());
|
|
form.draft = "stale presentation";
|
|
try { Files.writeString(file, "external agent edit"); } catch (Exception failure) { throw new RuntimeException(failure); }
|
|
form.discardDraftForHandoff();
|
|
try { form.draft = Files.readString(file); } catch (Exception failure) { throw new RuntimeException(failure); }
|
|
assertEquals("external agent edit", form.draft);
|
|
});
|
|
}
|
|
@Test void protectedReturnShowsExplicitDiscardAndCancelDoesNotGrantConsent() throws Exception {
|
|
try (var pool = Executors.newSingleThreadExecutor()) {
|
|
var authority = new DefaultAutomationSession(root, new ExecutorOperationExecutor(pool));
|
|
var discarded = new java.util.concurrent.atomic.AtomicBoolean();
|
|
authority.grant(false).toCompletableFuture().get(5, TimeUnit.SECONDS);
|
|
var task = authority.acquire().task();
|
|
authority.attachRuntime(task, new ManagedHeadlessSession() {
|
|
public String sessionId() { return "dirty"; }
|
|
public void cancel() { }
|
|
public CompletionStage<Void> shutdown() { return shutdown(false); }
|
|
public CompletionStage<Void> shutdown(boolean consent) {
|
|
if (!consent) return CompletableFuture.failedFuture(new AutomationException(new AutomationFailure(
|
|
AutomationFailure.Code.MEMCARD_ERROR, "Unsaved changes", java.util.Map.of("reason", "unsaved_changes"))));
|
|
discarded.set(true); return CompletableFuture.completedFuture(null);
|
|
}
|
|
});
|
|
var view = new DevWorkspace[1]; var stage = new Stage[1];
|
|
try {
|
|
fx(() -> {
|
|
view[0] = new DevWorkspace(new ProjectReference("Dirty", "1", "pbs", 1, ProjectTarget.Game, root),
|
|
authority, new I18nService(), new StudioEventBus());
|
|
stage[0] = new Stage(); stage[0].setScene(new Scene(new VBox(view[0].rootNode()), 1050, 800)); stage[0].show(); view[0].load();
|
|
assertFalse(view[0].rootNode().lookup("#dev-discard-game-data").isVisible());
|
|
});
|
|
assertEquals(ControlResult.Status.CLEANUP_FAILED, authority.reclaim().toCompletableFuture().get(5, TimeUnit.SECONDS).status());
|
|
fx(() -> {
|
|
var discard = (Button) view[0].rootNode().lookup("#dev-discard-game-data"); assertTrue(discard.isVisible());
|
|
Platform.runLater(() -> javafx.stage.Window.getWindows().stream().filter(w -> w instanceof Stage && w != stage[0]).findFirst()
|
|
.ifPresent(w -> ((Button) ((DialogPane) w.getScene().getRoot()).lookupButton(ButtonType.CANCEL)).fire()));
|
|
discard.fire(); assertFalse(discarded.get());
|
|
Platform.runLater(() -> javafx.stage.Window.getWindows().stream().filter(w -> w instanceof Stage && w != stage[0]).findFirst()
|
|
.ifPresent(w -> ((Button) ((DialogPane) w.getScene().getRoot()).lookupButton(ButtonType.OK)).fire()));
|
|
discard.fire();
|
|
assertTrue(discarded.get()); assertTrue(authority.snapshot().manualAllowed());
|
|
assertFalse(discard.isVisible());
|
|
});
|
|
} finally {
|
|
fx(() -> { if (view[0] != null) view[0].unLoad(); if (stage[0] != null) stage[0].close(); });
|
|
authority.reclaimDiscardingUnsavedGameData().toCompletableFuture().get(5, TimeUnit.SECONDS);
|
|
authority.closeAsync().toCompletableFuture().get(5, TimeUnit.SECONDS);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Test void preparesConnectionWithoutGrantAndRemainsAvailableWhenTransportStops() throws Exception {
|
|
var mapper = new com.fasterxml.jackson.databind.ObjectMapper();
|
|
var projects = new p.studio.core.project.ProjectAccessRegistry();
|
|
var prepared = new CompletableFuture<Void>();
|
|
var view = new DevWorkspace[1]; var stage = new Stage[1];
|
|
try (var pool = Executors.newSingleThreadExecutor();
|
|
var server = new p.studio.app.mcp.LocalMcpServer(mapper, new p.studio.app.mcp.McpToolRegistry(
|
|
new p.studio.app.mcp.McpToolCatalog(mapper), mapper, java.util.Map.of()))) {
|
|
var authority = new DefaultAutomationSession(root, new ExecutorOperationExecutor(pool));
|
|
var registration = projects.register(root, authority::enterManual, () -> !authority.snapshot().closed(), authority);
|
|
var guide = new p.studio.app.mcp.McpConnectionGuide(server, projects, mapper, project -> {
|
|
prepared.complete(null);
|
|
return new p.studio.api.automation.AgentIntegrationPreparation.Result(true, "Prepared; trust/reload once.");
|
|
});
|
|
server.start();
|
|
try {
|
|
fx(() -> {
|
|
var project = new ProjectReference("Connection smoke", "1", "pbs", 1, ProjectTarget.Game, root);
|
|
view[0] = new DevWorkspace(project, authority, new I18nService(), new StudioEventBus(), guide);
|
|
stage[0] = new Stage(); stage[0].setScene(new Scene(new VBox(view[0].rootNode()), 1050, 800)); stage[0].show();
|
|
view[0].load();
|
|
var button = (Button) view[0].rootNode().lookup("#dev-mcp-config"); assertFalse(button.isDisabled()); button.fire();
|
|
});
|
|
prepared.get(5, TimeUnit.SECONDS);
|
|
assertEquals(ControlState.MANUAL, authority.snapshot().state());
|
|
server.close();
|
|
fx(() -> assertFalse(((Button) view[0].rootNode().lookup("#dev-mcp-config")).isDisabled()));
|
|
server.start(); authority.grant(false).toCompletableFuture().join();
|
|
assertEquals(ControlState.WAITING_FOR_AGENT, authority.snapshot().state());
|
|
authority.closeAsync().toCompletableFuture().get(5, TimeUnit.SECONDS);
|
|
fx(() -> assertTrue(((Button) view[0].rootNode().lookup("#dev-mcp-config")).isDisabled()));
|
|
} finally {
|
|
fx(() -> { if (view[0] != null) view[0].unLoad(); if (stage[0] != null) stage[0].close(); });
|
|
authority.closeAsync().toCompletableFuture().get(5, TimeUnit.SECONDS); registration.close();
|
|
}
|
|
}
|
|
}
|
|
|
|
@Test void lockedUiBlocksMutationActionsButNotReadOnlyActions() throws Exception {
|
|
fx(() -> {
|
|
var root = new VBox(); var mutate = new Button("write"); var inspect = new Button("inspect");
|
|
inspect.getProperties().put(ManualProjectUiGuard.READ_ONLY_ACTION, true);
|
|
var writes = new AtomicInteger(); var reads = new AtomicInteger();
|
|
mutate.setOnAction(e -> writes.incrementAndGet()); inspect.setOnAction(e -> reads.incrementAndGet());
|
|
root.getChildren().addAll(mutate, inspect); ManualProjectUiGuard.install(root, () -> false);
|
|
mutate.fire(); inspect.fire(); assertEquals(0, writes.get()); assertEquals(1, reads.get());
|
|
});
|
|
}
|
|
static class TestForm extends StudioFormSection {
|
|
boolean dirty, fail; String draft = "";
|
|
TestForm() { super(new I18nService()); }
|
|
protected String formSectionId() { return "test"; }
|
|
protected String sectionTitle() { return "test"; }
|
|
protected StudioFormMode formMode() { return StudioFormMode.EDITING; }
|
|
protected boolean isDirty() { return dirty; }
|
|
protected void renderSection() { }
|
|
protected void beginEdit() { }
|
|
protected void apply() { if (!fail) dirty = false; finishHandoffSave(!fail, "save failure"); }
|
|
protected void reset() { }
|
|
protected void cancel() { dirty = false; draft = ""; }
|
|
}
|
|
}
|