feat(studio): show executed source diagnostics in UI2
Test / Tests and coverage
Intrepid/Prometeu/Studio/pipeline/head This commit looks good

Capture bounded compiler inputs by revision and PBX identity, consume Play v2 faults and retain static diagnostic excerpts across failed preparation. Integrate the UI2 panel, qualification evidence and regression tests without adding an editor.
This commit is contained in:
2026-11-26 08:55:33 +00:00
parent 481c479427
commit 601997d163
47 changed files with 2811 additions and 58 deletions
@@ -0,0 +1,57 @@
package p.studio.ui.javafx2.play;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.VBox;
import p.studio.api.execution.ExecutionDiagnostic;
import p.studio.ui.javafx2.appearance.AppearanceContext;
import java.util.List;
/** Static values resolved by the execution service; no document or filesystem access. */
public final class RuntimeDiagnosticsPane extends VBox {
private final AppearanceContext context;
private final VBox content=new VBox(10);
private List<ExecutionDiagnostic> displayed=List.of();
public RuntimeDiagnosticsPane(AppearanceContext context) {
this.context=context;setId("runtime-diagnostics");getStyleClass().add("runtime-diagnostics");
var scroll=new ScrollPane(content);scroll.setFitToWidth(true);scroll.setMinHeight(0);scroll.setPrefHeight(240);
getChildren().add(scroll);setMinHeight(0);setMaxHeight(USE_PREF_SIZE);
context.observe(this::render);
}
public void show(List<ExecutionDiagnostic> diagnostics) {
if(displayed.equals(diagnostics))return;
displayed=List.copyOf(diagnostics);render();
}
private void render() {
boolean present=!displayed.isEmpty();setVisible(present);setManaged(present);content.getChildren().clear();
if(!present)return;
content.setPadding(new Insets(10));
for(int index=0;index<displayed.size();index++) {
var value=displayed.get(index);var fault=value.fault();var excerpt=value.excerpt();
String suffix=index==0?"":"-"+index;
var category=label(context.text("diagnostic.kind."+fault.kind()),"runtime-diagnostic-category"+suffix);
category.getStyleClass().add("runtime-diagnostic-category");
var message=label(fault.message(),"runtime-diagnostic-message"+suffix);
var location=label(excerpt.availability().equals("available")
?context.text("diagnostic.location",excerpt.logicalPath(),Integer.toString(excerpt.line()),Integer.toString(excerpt.column()),context.text("diagnostic.source."+excerpt.sourceKind()))
:context.text("diagnostic.unavailable."+excerpt.availability()),"runtime-diagnostic-location"+suffix);
var card=new VBox(5,category,message,location);
if(!excerpt.revision().isEmpty()) {
var revision=label(context.text("diagnostic.revision",excerpt.revision().substring(0,12),shortIdentity(excerpt.buildId()),shortIdentity(fault.runId())),"runtime-diagnostic-revision"+suffix);
revision.setAccessibleText(context.text("diagnostic.revision",excerpt.revision(),excerpt.buildId(),fault.runId()));
var source=label(excerpt.text(),"runtime-diagnostic-source"+suffix);source.setWrapText(false);
var sourceScroll=new ScrollPane(source);sourceScroll.setFitToHeight(true);sourceScroll.setMinHeight(0);
card.getChildren().addAll(revision,sourceScroll);
}
if(fault.truncated()||excerpt.truncated())card.getChildren().add(label(context.text("diagnostic.truncated"),"runtime-diagnostic-truncated"+suffix));
content.getChildren().add(card);
}
}
private static String shortIdentity(String value){return value.substring(0,Math.min(8,value.length()));}
private static Label label(String text,String id) {
var label=new Label(text);label.setId(id);label.setWrapText(true);label.setMinWidth(0);label.setMaxWidth(Double.MAX_VALUE);
label.setAccessibleText(text);return label;
}
}
@@ -18,6 +18,7 @@ import p.studio.ui.javafx2.appearance.AppearanceContext;
import p.studio.ui.javafx2.ai.AiWorkspace;
import p.studio.ui.javafx2.components.*;
import p.studio.ui.javafx2.play.PlaybackViewport;
import p.studio.ui.javafx2.play.RuntimeDiagnosticsPane;
import p.studio.ui.javafx2.shell.MinimalShell;
import p.studio.ui.javafx2.shell.ExecutionBar;
import p.studio.ui.javafx2.shell.TabStatusFooter;
@@ -97,6 +98,7 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
}
private Label stateLabel;
private TextArea logs;
private RuntimeDiagnosticsPane diagnostics;
private long lastLog=-1;
private long operationSequence;
private ExecutionState displayedState;
@@ -150,7 +152,7 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
public void resolved(ProjectReference reference){loadingProject.setText(reference.name());}
public void prepare(ProjectSession session,WindowGeometry geometry){project=session;showProject();restoreGeometry(geometry);}
public void present(){stage.setTitle(project.projectReference().name()+" · "+context.text("brand"));stage.show();stage.toFront();hideLoading();createdProject=null;refresh();connectAgent();}
public void discard(){if(projectGeometry!=null){projectGeometry.close();projectGeometry=null;}stage.hide();project=null;play=null;if(viewport!=null){viewport.close();viewport=null;}if(viewContext!=null){viewContext.close();viewContext=null;}shell.workspace().getChildren().clear();}
public void discard(){if(projectGeometry!=null){projectGeometry.close();projectGeometry=null;}stage.hide();project=null;play=null;clearDiagnostics();if(viewport!=null){viewport.close();viewport=null;}if(viewContext!=null){viewContext.close();viewContext=null;}shell.workspace().getChildren().clear();}
public void failed(Throwable failure,boolean cleanupRequired){hideLoading();showChooser();
String detail=diagnostic(failure);
chooser.feedback(cleanupRequired?"projects.cleanupFailed":createdProject==null?"projects.openFailed":"projects.createdOpenFailed",cleanupRequired,detail);
@@ -359,7 +361,9 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
var game=new BorderPane(viewport,localControls,null,null,null);game.setId("project-play");
viewport.setMinHeight(64);
logs=new TextArea();logs.setId("execution-logs");logs.setEditable(false);logs.setPrefRowCount(4);logs.setWrapText(true);logs.setMinHeight(64);
var split=new SplitPane(game,logs);split.setId("gameplay-split");split.getStyleClass().add("studio-gameplay-split");
diagnostics=new RuntimeDiagnosticsPane(c);
var executionDetails=new VBox(diagnostics,logs);executionDetails.setMinHeight(64);VBox.setVgrow(logs,Priority.ALWAYS);
var split=new SplitPane(game,executionDetails);split.setId("gameplay-split");split.getStyleClass().add("studio-gameplay-split");
split.getStyleClass().add("studio-workspace-split");
split.setOrientation(javafx.geometry.Orientation.VERTICAL);split.setDividerPositions(.8);
// Apply the initial ratio after the native window has received its actual size.
@@ -439,6 +443,7 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
private void refresh(){
if(project==null||play==null||closed)return;
var snapshot=project.executionSession().snapshot();var state=snapshot.state();boolean owned=controller!=null&&controller.ownsExecution();
if(diagnostics!=null)diagnostics.show(snapshot.diagnostics());
play.setText(context.text(owned?"play.stop":"play.start"));play.setAccessibleText(play.getText());
play.setDisable(busy||closing||state==ExecutionState.STOPPING);
pause.setDisable(busy||closing||state!=ExecutionState.RUNNING&&state!=ExecutionState.PAUSED);
@@ -484,11 +489,13 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
background(()->closeOwned(oldProject,oldController),(warning,failure)->{
if(failure!=null){closing=false;exitRequested=false;projectCloseRequested=false;error(failure);refresh();return;}
project=null;controller=null;agent=null;closing=false;projectCloseRequested=false;play=null;notice.setText("");
clearDiagnostics();
if(viewport!=null){viewport.close();viewport=null;}if(viewContext!=null){viewContext.close();viewContext=null;}shell.workspace().getChildren().clear();
if(exitRequested)finishExit();else {showChooser();if(warning!=null)error(warning);}
});
}));
}
private void clearDiagnostics(){if(diagnostics!=null){diagnostics.show(List.of());diagnostics=null;}}
private Throwable closeOwned(ProjectSession session,ExecutionController execution){
RuntimeException warning=null,failure=null;
try{if(execution!=null)execution.close();}catch(RuntimeException error){failure=error;}
@@ -72,7 +72,7 @@ state.PAUSING=Pausing…
state.PAUSED=Paused · Resume to continue
state.RESUMING=Resuming…
state.STOPPING=Stopping…
state.RUNTIME_FAILED=Runtime failed · see logs
state.RUNTIME_FAILED=Runtime failed · see diagnostics
state.STOPPED=Stopped
theme.label=Theme
theme.dark=Bananodore · dark
@@ -222,3 +222,24 @@ conversation.sample.intro=# Project inspection\n\nI found the **source** and the
conversation.sample.tool=Run project checks
conversation.sample.failure=The fixture found a missing configuration value.
conversation.sample.after=The check reported a configuration issue. The details above explain what needs to be adjusted.
diagnostic.kind.vm_trap=Application trap
diagnostic.kind.vm_panic=Application failure
diagnostic.kind.vm_init=Program initialization failed
diagnostic.kind.preparation=Preparation failed
diagnostic.kind.connection=Connection failed
diagnostic.kind.load=Cartridge loading failed
diagnostic.kind.host=Runtime host failure
diagnostic.kind.transport=Runtime connection interrupted
diagnostic.kind.watchdog=Runtime timed out
diagnostic.location={0}:{1}:{2} · {3}
diagnostic.revision=Executed source {0} · build {1} · execution {2}
diagnostic.truncated=Diagnostic or source excerpt was shortened.
diagnostic.unavailable.no-span=Source location unavailable for this failure.
diagnostic.unavailable.program-not-confirmed=Executed program identity was not confirmed.
diagnostic.unavailable.source-not-captured=Source for this location was not captured.
diagnostic.unavailable.invalid-span=Source location does not match the captured text.
diagnostic.source.sdk=SDK
diagnostic.source.generated=generated source
diagnostic.source.source=source
diagnostic.source.dependency=dependency source
@@ -72,7 +72,7 @@ state.PAUSING=Pausando…
state.PAUSED=Pausado · Resume para continuar
state.RESUMING=Retomando…
state.STOPPING=Encerrando…
state.RUNTIME_FAILED=Falha no runtime · consulte os logs
state.RUNTIME_FAILED=Falha no runtime · consulte o diagnóstico
state.STOPPED=Encerrado
theme.label=Tema
theme.dark=Bananodore · escuro
@@ -222,3 +222,24 @@ conversation.sample.intro=# Inspeção do projeto\n\nEncontrei o **código** e a
conversation.sample.tool=Executar verificações do projeto
conversation.sample.failure=O exemplo encontrou um valor ausente na configuração.
conversation.sample.after=A verificação apontou um problema na configuração. Os detalhes acima explicam o que precisa ser ajustado.
diagnostic.kind.vm_trap=Trap da aplicação
diagnostic.kind.vm_panic=Falha da aplicação
diagnostic.kind.vm_init=Falha na inicialização do programa
diagnostic.kind.preparation=Falha na preparação
diagnostic.kind.connection=Falha na conexão
diagnostic.kind.load=Falha no carregamento do cartucho
diagnostic.kind.host=Falha do host do runtime
diagnostic.kind.transport=Conexão com o runtime interrompida
diagnostic.kind.watchdog=Tempo de resposta do runtime excedido
diagnostic.location={0}:{1}:{2} · {3}
diagnostic.revision=Fonte executado {0} · build {1} · execução {2}
diagnostic.truncated=O diagnóstico ou trecho do fonte foi abreviado.
diagnostic.unavailable.no-span=Localização no fonte indisponível para esta falha.
diagnostic.unavailable.program-not-confirmed=A identidade do programa executado não foi confirmada.
diagnostic.unavailable.source-not-captured=O fonte desta localização não foi capturado.
diagnostic.unavailable.invalid-span=A localização não corresponde ao texto capturado.
diagnostic.source.sdk=SDK
diagnostic.source.generated=fonte gerado
diagnostic.source.source=fonte
diagnostic.source.dependency=fonte de dependência
@@ -40,6 +40,33 @@ class FoundationDesktopTest {
captures=Path.of(System.getProperty("studio.ui2.captureDir")); Files.createDirectories(captures);
}
@AfterAll static void stopToolkit() { Platform.exit(); }
@Test void staticRuntimeDiagnosticsFollowLanguageThemeScaleAndAvailability() throws Exception {
var context=fx(()->new AppearanceContext(PresentationSettings.defaults(Locale.ENGLISH),messages,fonts,value->{}));
var panel=fx(()->new p.studio.ui.javafx2.play.RuntimeDiagnosticsPane(context));
var fault=new p.studio.api.execution.RuntimeDiagnostic("1".repeat(32),"a".repeat(64),"vm_trap","Division by zero · ação 😀",42L,10L,35L,
new p.studio.api.execution.RuntimeDiagnostic.Span(7,0,5),false,Map.of());
var excerpt=new p.studio.api.execution.ExecutionDiagnostic.Excerpt("build-123","@generated/animation/main.pbs","generated","b".repeat(64),5,12,
"fn frame() {\n let value = 123 / zero;\n}",false,"available");
var value=new p.studio.api.execution.ExecutionDiagnostic(fault,excerpt);
var window=fx(()->{var stage=new Stage();var root=new VBox(panel);context.attach(root);stage.setScene(new Scene(root,800,440));
stage.setOnHidden(e->context.close());stage.show();panel.show(List.of(value));return new Window(stage,context,null,null);});
try {
for(Theme theme:Theme.values())for(StudioLanguage language:StudioLanguage.values()) {
fx(()->{context.update(context.settings().withTheme(theme).withLanguage(language).withScale(1.25));
window.stage.getScene().getRoot().applyCss();window.stage.getScene().getRoot().layout();
assertTrue(((Label)panel.lookup("#runtime-diagnostic-location")).getText().contains("@generated/animation/main.pbs:5:12"));
assertTrue(((Label)panel.lookup("#runtime-diagnostic-source")).getText().contains("123 / zero"));
assertTrue(panel.lookupAll(".text-input").isEmpty());
assertEquals(language==StudioLanguage.ENGLISH?"Application trap":"Trap da aplicação",((Label)panel.lookup("#runtime-diagnostic-category")).getText());return null;});
capture(window,"runtime-diagnostic-"+theme+"-"+language);
}
fx(()->{panel.show(List.of(new p.studio.api.execution.ExecutionDiagnostic(
p.studio.api.execution.RuntimeDiagnostic.failure("2".repeat(32),"connection","Connection interrupted"),
new p.studio.api.execution.ExecutionDiagnostic.Excerpt("","","","",0,0,"",false,"no-span"))));
assertNull(panel.lookup("#runtime-diagnostic-source"));assertTrue(panel.isVisible());
panel.show(List.of());assertFalse(panel.isVisible());assertFalse(panel.isManaged());return null;});
} finally {fx(()->{window.stage.close();return null;});}
}
@Test void shellGalleryStateThemesLocalesFontsAndLifecycle() throws Exception {
Window window=fx(() -> open(true));
try {