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
@@ -35,6 +35,56 @@ class StudioPlayDesktopTest {
var ready=new CompletableFuture<Void>();Platform.startup(()->{Platform.setImplicitExit(false);ready.complete(null);});ready.get(15,TimeUnit.SECONDS);
}
@AfterAll static void stopToolkit(){Platform.exit();}
@Test void realTrapShowsExecutedSourceAfterEditDeletionAndFailedPreparation() throws Exception {
Path root=Files.createDirectories(temporary.resolve("diagnostic-project"));Files.createDirectories(root.resolve("src"));
Files.writeString(root.resolve("prometeu.json"),"""
{"name":"diagnostic-project","version":"1","language":"pbs","stdlib":"1","target":"Game","dependencies":[]}
""");
Files.writeString(root.resolve("src/mod.barrel"),"pub fn frame() -> void;");
String original="// execução 😀\r\n[Frame] fn frame() -> void { let zero = 0; let value = 123 / zero; }\r\n";
Path source=root.resolve("src/main.pbs");Files.writeString(source,original);
var initial=p.studio.ui.javafx2.appearance.PresentationSettings.defaults(Locale.ENGLISH);
var resources=new WindowResources(initial,new p.studio.ui.javafx2.preferences.SettingsStore(){
public p.studio.ui.javafx2.appearance.PresentationSettings load(){return initial;}
public void save(p.studio.ui.javafx2.appearance.PresentationSettings value){}
});
try(var app=new SpringApplicationBuilder(StudioApplicationConfiguration.class).web(WebApplicationType.NONE).headless(false).run()) {
var catalog=app.getBean(ProjectCatalog.class);var setups=app.getBean(ProjectLocalStudioSetupStore.class);
var ref=catalog.openProject(root);setups.save(ref,new ProjectLocalStudioSetup(System.getProperty("studio.test.runtimeInstall"),null));
var access=app.getBean(ProjectAccessRegistry.class);
var factory=new DefaultExecutionControllerFactory(app.getBean(p.studio.api.shipper.Shipper.class),
new StudioRuntimeGateway(app.getBean(ObjectMapper.class)),app.getBean(p.studio.api.operation.OperationExecutor.class),access);
var known=new KnownProjects(){public List<ProjectReference> listKnownProjects(){return List.of(ref);}public void remember(ProjectReference r){}public void forget(ProjectReference r){}};
Stage stage=fx(Stage::new);
var window=fx(()->new StudioWindowCoordinator2(stage,catalog,known,app.getBean(ProjectSessionFactory.class),factory,
setups::save,app.getBean("studioExecutor",ExecutorService.class),resources));
try {
fx(()->{window.showLauncher();window.openProject(root);return null;});
await(()->{try{return fx(()->window.projectSession()!=null);}catch(Exception e){throw new RuntimeException(e);}},()->"Diagnostic project did not open");
focus(stage);fire(stage,"play");
Supplier<String> facts=()->{try{return fx(()->window.projectSession().executionSession().snapshot().toString());}catch(Exception e){return e.toString();}};
await(()->{try{return fx(()->window.projectSession().executionSession().snapshot().state()==ExecutionState.RUNTIME_FAILED);}catch(Exception e){throw new RuntimeException(e);}},facts);
var diagnostic=fx(()->window.projectSession().executionSession().snapshot().diagnostics().getFirst());
assertEquals("vm_trap",diagnostic.fault().kind());assertNotNull(diagnostic.fault().pc());
assertEquals("available",diagnostic.excerpt().availability());assertEquals(2,diagnostic.excerpt().line());
assertEquals(ExecutionSources.digest(original.getBytes(java.nio.charset.StandardCharsets.UTF_8)),diagnostic.excerpt().revision());
Files.writeString(source,"// edited after execution\n");Files.delete(source);
await(()->{try{return fx(()->stage.getScene().lookup("#runtime-diagnostic-source")!=null);}catch(Exception e){throw new RuntimeException(e);}},facts);
fx(()->{assertTrue(((Label)stage.getScene().lookup("#runtime-diagnostic-source")).getText().contains("123 / zero"));
assertTrue(((Label)stage.getScene().lookup("#runtime-diagnostic-location")).getText().contains(":2:"));
assertNull(stage.getScene().lookup("#code-editor"));return null;});
dragGameplayDivider(stage,.4);capture(stage,"diagnostic-executed-source.png");
// A later build fails; its message is shown alongside the retained execution.
focus(stage);fire(stage,"play");
await(()->{try{return fx(()->window.projectSession().executionSession().snapshot().state()==ExecutionState.PREPARE_FAILED);}catch(Exception e){throw new RuntimeException(e);}},facts);
var after=fx(()->window.projectSession().executionSession().snapshot().diagnostics());
assertEquals(2,after.size());assertEquals("preparation",after.getFirst().fault().kind());assertEquals(diagnostic,after.getLast());
fx(()->{var tabs=(TabPane)stage.getScene().lookup("#project-tabs");tabs.getSelectionModel().select(0);return null;});
capture(stage,"diagnostic-retained-after-prepare-failure.png");
} finally {fx(window::closeAsync).toCompletableFuture().get(15,TimeUnit.SECONDS);}
}
}
private static void await(BooleanSupplier condition,Supplier<String> failure)throws Exception{
long deadline=System.nanoTime()+TimeUnit.SECONDS.toNanos(20);
while(System.nanoTime()<deadline){if(condition.getAsBoolean())return;Thread.sleep(25);}fail(failure.get());
@@ -58,8 +108,12 @@ class StudioPlayDesktopTest {
public boolean interactive(){return true;}
public p.studio.core.runtime.RuntimeConnection start(ProjectReference p,ProjectLocalStudioSetup s,Consumer<p.studio.api.runtime.RuntimeLogEntry> logs)throws Exception{return start(p,s,logs,PlayOptions.PERSISTENT);}
public p.studio.core.runtime.RuntimeConnection start(ProjectReference p,ProjectLocalStudioSetup s,Consumer<p.studio.api.runtime.RuntimeLogEntry> logs,PlayOptions options)throws Exception{
var actual=nativeGateway.start(p,s,logs,options);
return start(p,s,logs,options,UUID.randomUUID().toString().replace("-",""),ExecutionSources.EMPTY,d->{});
}
public p.studio.core.runtime.RuntimeConnection start(ProjectReference p,ProjectLocalStudioSetup s,Consumer<p.studio.api.runtime.RuntimeLogEntry> logs,PlayOptions options,String runId,ExecutionSources sources,Consumer<RuntimeDiagnostic> diagnostics)throws Exception{
var actual=nativeGateway.start(p,s,logs,options,runId,sources,diagnostics);
return new p.studio.core.runtime.RuntimeConnection(){
public String verifiedProgramSha256(){return actual.verifiedProgramSha256();}
public CompletableFuture<Integer> completion(){return actual.completion();}
public CompletableFuture<Void> startExecution(){return actual.startExecution();}
public CompletableFuture<Void> pause(){
@@ -64,6 +64,9 @@ class AnimationIntegrationTest {
var result=p.studio.compiler.workspaces.BuilderPipelineService.INSTANCE.compile(build,p.studio.utilities.logs.LogAggregator.stdout());assertTrue(result.bytecodeBytes().length>0);
var source=new p.studio.compiler.workspaces.AssetSurfaceContextLoader(layouts).load(root).animations().getFirst();
Path generatedPath=null;String generatedText=null;
var captured=p.studio.compiler.source.diagnostics.ConsumedSources.capture(build.fileTable,4*1024*1024,1024,16*1024*1024);
assertEquals(2,captured.stream().filter(s->s.kind().equals("generated")).count());
assertTrue(captured.stream().anyMatch(s->s.kind().equals("sdk")));
for(var id:build.fileTable.identifiers()){var handle=build.fileTable.get(id);if(handle.getCanonPath().startsWith(Path.of("/virtual/generated/animations"))&&handle.getFilename().equals("main.pbs")){generatedPath=handle.getCanonPath();generatedText=handle.readUtf8().orElseThrow();}}
assertNotNull(generatedPath);assertFalse(generatedText.contains(root.toString()));
var bridge=new p.studio.lsp.services.compiler.CompilerLanguageServiceBridge(layouts);
@@ -0,0 +1,42 @@
package p.studio.app.compiler;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import p.studio.api.execution.ExecutionSources;
import p.studio.api.project.*;
import java.nio.file.*;
import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.*;
class ExecutionSourceBuildTest {
@TempDir Path root;
@Test void capturesProjectDependencyAndSdkWithDistinctLogicalOriginsAndRejectsOversizedInput() throws Exception {
Files.createDirectories(root.resolve("src"));
Path dependency=Files.createDirectories(root.resolve(".workspace/repos/lib/src/probe")).getParent().getParent();
Files.writeString(root.resolve(".workspace/repos/registry.json"),"{}");
Files.writeString(root.resolve("prometeu.json"),"""
{"name":"app","version":"1","language":"pbs","stdlib":"1","target":"Game","dependencies":[{"path":".workspace/repos/lib"}]}
""");
Files.writeString(dependency.resolve("prometeu.json"),"""
{"name":"lib","version":"1","language":"pbs","stdlib":"1","target":"Game","dependencies":[]}
""");
Files.writeString(dependency.resolve("src/probe/main.pbs"),"fn value() -> int { return 42; }");
Files.writeString(dependency.resolve("src/probe/mod.barrel"),"pub fn value() -> int;");
Files.writeString(root.resolve("src/mod.barrel"),"pub fn frame() -> void;");
String text="import { value } from @lib:probe;\nimport { math } from @sdk:math;\n[Frame] fn frame() -> void { let number = math.abs(value()); }\n";
Path main=root.resolve("src/main.pbs");Files.writeString(main,text);
var project=new ProjectReference("app","1","pbs",1,ProjectTarget.Game,root);
var adapter=new CompilerBuildGatewayAdapter();var build=adapter.compile(project,ignored->{});
var capture=build.executionSources();
assertEquals(ExecutionSources.digest(Files.readAllBytes(build.bytecodeArtifact())),capture.programSha256());
assertTrue(capture.sources().values().stream().anyMatch(s->s.kind().equals("dependency")&&s.logicalPath().startsWith("@lib:")));
assertTrue(capture.sources().values().stream().anyMatch(s->s.kind().equals("sdk")));
Files.delete(main);
assertTrue(capture.sources().values().stream().anyMatch(s->s.text().equals(text)));
assertFalse(build.context().toString().contains("let number"));
Files.writeString(main,"[Frame] fn frame() -> void {}\n//"+"x".repeat(ExecutionSources.MAX_FILE_BYTES));
var failure=assertThrows(IllegalStateException.class,()->adapter.compile(project,ignored->{}));
assertTrue(failure.getMessage().contains("source byte limit"),failure.toString());
assertTrue(capture.sources().values().stream().anyMatch(s->s.sha256().equals(ExecutionSources.digest(text.getBytes(StandardCharsets.UTF_8)))));
}
}
@@ -71,6 +71,7 @@ class HeadlessTaskIntegrationTest {
String successfulBuild(String request) throws Exception {
var result = build(request); assertNull(result.failure());
assertNotNull(result.buildResult()); assertTrue(result.buildResult().success(), result.buildResult().diagnostics().toString());
assertTrue(result.buildResult().executionSources().sources().isEmpty(),"Managed task history must not retain interactive source captures");
assertNotNull(result.buildId()); return result.buildId();
}
TaskTools.HeadlessReply call(TaskTools.HeadlessAction action, String build) {
@@ -47,7 +47,7 @@ class StudioPlayInstalledRuntimeTest {
finally{formatting.shutdown().toCompletableFuture().get(7,TimeUnit.SECONDS);}
assertTrue(Files.isRegularFile(image));
var gateway=new StudioRuntimeGateway(json);
var persistent=gateway.start(project,setup,logs::add,PlayOptions.PERSISTENT);
var persistent=assertDoesNotThrow(()->gateway.start(project,setup,logs::add,PlayOptions.PERSISTENT),logs::toString);
try{
persistent.startExecution().get(5,TimeUnit.SECONDS);awaitColor(persistent,0,0,255,logs); // BGRA red
var refusal=assertThrows(ExecutionException.class,()->persistent.stopAsync().get(5,TimeUnit.SECONDS));
@@ -0,0 +1,75 @@
package p.studio.app.runtime.studio;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.jupiter.api.Test;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import static org.junit.jupiter.api.Assertions.*;
class StudioFaultsTest {
private static final ObjectMapper JSON = new ObjectMapper();
private static final byte[] SESSION = HexFormat.of().parseHex("03".repeat(16));
private static final String PROGRAM = "ab".repeat(32);
private static byte[] fixture() throws IOException {
try(var in=StudioFaultsTest.class.getResourceAsStream("/studio-protocol/fixtures/fault.hex")) {
assertNotNull(in);
var bytes=HexFormat.of().parseHex(new String(in.readAllBytes(),StandardCharsets.US_ASCII).replaceAll("\\s+",""));
var message=new StudioWire.Reader(new ByteArrayInputStream(bytes)).receive();
assertEquals(StudioWire.FAULT,message.header().kind());
return message.payload();
}
}
@Test void sharedRustFixtureKeepsUnsignedPcSpanAndUnicode() throws Exception {
var fault=StudioFaults.decode(fixture(),SESSION,PROGRAM);
assertEquals(4294967295L,fault.pc());assertEquals(7,fault.span().fileId());
assertEquals(18,fault.span().start());assertTrue(fault.message().contains("ação"));
assertEquals(PROGRAM,fault.programSha256());assertFalse(fault.truncated());
}
@Test void rejectsInvalidIdentityNumericFieldsAndEnvelope() throws Exception {
for(String field:List.of("sessionId","programSha256","schemaVersion","tick","truncated")) {
var root=(ObjectNode)JSON.readTree(fixture());root.put(field,"invalid");
assertThrows(IOException.class,()->StudioFaults.decode(JSON.writeValueAsBytes(root),SESSION,PROGRAM),field);
}
for(String field:List.of("pc","code","opcode")) {
var root=(ObjectNode)JSON.readTree(fixture());((ObjectNode)root.path("fault").path("trap")).put(field,-1);
assertThrows(IOException.class,()->StudioFaults.decode(JSON.writeValueAsBytes(root),SESSION,PROGRAM),field);
}
var root=(ObjectNode)JSON.readTree(fixture());
((ObjectNode)root.path("fault").path("trap").path("span")).put("end",1);
assertThrows(IOException.class,()->StudioFaults.decode(JSON.writeValueAsBytes(root),SESSION,PROGRAM));
assertThrows(IOException.class,()->StudioFaults.decode(new byte[65537],SESSION,PROGRAM));
assertThrows(IOException.class,()->StudioFaults.decode((new String(fixture(),StandardCharsets.UTF_8)+" {}").getBytes(StandardCharsets.UTF_8),SESSION,PROGRAM));
assertThrows(IOException.class,()->StudioFaults.decode(new byte[]{(byte)0xff},SESSION,PROGRAM));
}
@Test void initFailureHasNoFabricatedPcOrProgramAndLimitsAreEnforced() throws Exception {
var root=(ObjectNode)JSON.readTree(fixture());root.putNull("programSha256");root.put("truncated",true);
root.set("fault",JSON.readTree("{\"kind\":\"vm_init\",\"pc\":null,\"summary\":\"invalid PBX\",\"initError\":{\"code\":\"malformed\"}}"));
var result=StudioFaults.decode(JSON.writeValueAsBytes(root),SESSION,PROGRAM);
assertNull(result.pc());assertNull(result.span());assertEquals("",result.programSha256());assertTrue(result.truncated());
((ObjectNode)root.get("fault")).put("summary","😀".repeat(2049));
assertThrows(IOException.class,()->StudioFaults.decode(JSON.writeValueAsBytes(root),SESSION,PROGRAM));
((ObjectNode)root.get("fault")).put("summary","invalid PBX");
((ObjectNode)root.get("fault")).put("pc",1);
assertThrows(IOException.class,()->StudioFaults.decode(JSON.writeValueAsBytes(root),SESSION,PROGRAM));
}
@Test void hostCategoriesAreStructuredAndCannotClaimAVmPc() throws Exception {
for(String kind:List.of("load","host","transport","watchdog")) {
var root=(ObjectNode)JSON.readTree(fixture());root.putNull("programSha256");
root.set("fault",JSON.createObjectNode().put("kind",kind).put("summary","host failure").putNull("pc"));
var fault=StudioFaults.decodeHost(JSON.writeValueAsBytes(root),SESSION,PROGRAM);
assertEquals(kind,fault.kind());assertNull(fault.pc());assertNull(fault.span());
((ObjectNode)root.get("fault")).put("pc",5);
assertThrows(IOException.class,()->StudioFaults.decodeHost(JSON.writeValueAsBytes(root),SESSION,PROGRAM));
}
}
@Test void unsignedSpanFactsArePreservedAndSchemaNumbersCannotWrap() throws Exception {
var root=(ObjectNode)JSON.readTree(fixture());
((ObjectNode)root.path("fault").path("trap").path("span")).put("file_id",4294967295L).put("start",4294967294L).put("end",4294967295L);
var fault=StudioFaults.decode(JSON.writeValueAsBytes(root),SESSION,PROGRAM);
assertEquals(4294967295L,fault.span().fileId());assertEquals(4294967295L,fault.span().end());
root.put("schemaVersion",4294967297L);
assertThrows(IOException.class,()->StudioFaults.decode(JSON.writeValueAsBytes(root),SESSION,PROGRAM));
}
}
@@ -19,25 +19,33 @@ class StudioPlayProcessTest {
static final class Native implements AutoCloseable {
final ExecutorService io=Executors.newVirtualThreadPerTaskExecutor();
final List<String> logs=new CopyOnWriteArrayList<>();
final List<p.studio.api.execution.RuntimeDiagnostic> faults=new CopyOnWriteArrayList<>();
Message startup;
Process process;Socket control,video;StudioRuntimeConnection connection;
Native()throws Exception {
Native()throws Exception {this(java.nio.file.Path.of(System.getProperty("studio.test.studioCartridge")),null);assertNotNull(connection);}
Native(java.nio.file.Path cartridge,String expectedDigest)throws Exception {
try(ServerSocket c=new ServerSocket(0,4,InetAddress.getByName("127.0.0.1"));
ServerSocket v=new ServerSocket(0,4,InetAddress.getByName("127.0.0.1"))){
process=new ProcessBuilder(System.getProperty("studio.test.studioHost"),"--studio","--run",
System.getProperty("studio.test.studioCartridge")).start();
cartridge.toString()).start();
var stdout=StudioRuntimeGateway.drain(process.getInputStream(),false,e->logs.add(e.message()),io);
var stderr=StudioRuntimeGateway.drain(process.getErrorStream(),true,e->logs.add(e.message()),io);
String digest=expectedDigest==null?p.studio.api.execution.ExecutionSources.digest(java.nio.file.Files.readAllBytes(cartridge.resolve("program.pbx"))):expectedDigest;
byte[] session=new byte[16],token=new byte[32];Arrays.fill(session,(byte)3);Arrays.fill(token,(byte)7);
try(var input=process.getOutputStream()){new Writer(input).send(BOOTSTRAP,0,little(53)
.put(session).put(token).putShort((short)c.getLocalPort()).putShort((short)v.getLocalPort()).put((byte)1).array());}
try(var input=process.getOutputStream()){new Writer(input).send(BOOTSTRAP,0,little(85)
.put(session).put(token).putShort((short)c.getLocalPort()).putShort((short)v.getLocalPort()).put((byte)1).put(HexFormat.of().parseHex(digest)).array());}
c.setSoTimeout(10000);v.setSoTimeout(10000);control=c.accept();video=v.accept();
control.setSoTimeout(10000);video.setSoTimeout(10000);
Reader cr=new Reader(control.getInputStream()),vr=new Reader(video.getInputStream());
assertEquals(HELLO,cr.receive().header().kind());assertEquals(HELLO,vr.receive().header().kind());
var ready=cr.receive();assertEquals(READY,ready.header().kind());
var ready=cr.receive();startup=ready;
if(ready.header().kind()==FAULT){faults.add(StudioFaults.decode(ready.payload(),session,digest));return;}
if(ready.header().kind()==ERROR){faults.add(StudioFaults.decodeHost(ready.payload(),session,digest));return;}
assertEquals(READY,ready.header().kind());
var b=ByteBuffer.wrap(ready.payload()).order(ByteOrder.LITTLE_ENDIAN);int width=b.getInt(),height=b.getInt();
control.setSoTimeout(0);video.setSoTimeout(0);
connection=new StudioRuntimeConnection(process,control,video,cr,vr,session,width,height,e->logs.add(e.message()),io,stdout,stderr);
assertArrayEquals(HexFormat.of().parseHex(digest),Arrays.copyOfRange(ready.payload(),16,48));
connection=new StudioRuntimeConnection(process,control,video,cr,vr,session,width,height,digest,faults::add,e->logs.add(e.message()),io,stdout,stderr);
}catch(Throwable failure){close();throw failure;}
}
ExecutionFrame image()throws Exception {
@@ -53,6 +61,53 @@ class StudioPlayProcessTest {
io.shutdownNow();
}
}
@Test void differentLoadedProgramIsRejectedBeforeReadyOrStart() throws Exception {
try(var nativeRun=new Native(java.nio.file.Path.of(System.getProperty("studio.test.studioCartridge")),"ab".repeat(32))) {
assertNull(nativeRun.connection);assertEquals(ERROR,nativeRun.startup.header().kind());
assertTrue(nativeRun.faults.getFirst().message().contains("differs from prepared compilation"));
assertNull(nativeRun.faults.getFirst().pc());
}
}
@Test void invalidPbxProducesAnInitializationFaultBeforeReadyWithoutInventingPc(@org.junit.jupiter.api.io.TempDir java.nio.file.Path root) throws Exception {
var original=java.nio.file.Path.of(System.getProperty("studio.test.studioCartridge"));
try(var files=java.nio.file.Files.walk(original)) {
for(var file:files.toList()) {
var target=root.resolve(original.relativize(file));
if(java.nio.file.Files.isDirectory(file))java.nio.file.Files.createDirectories(target);
else java.nio.file.Files.copy(file,target);
}
}
java.nio.file.Files.write(root.resolve("program.pbx"),new byte[]{1,2,3});
try(var nativeRun=new Native(root,null)) {
assertEquals(FAULT,nativeRun.startup.header().kind(),nativeRun.logs.toString());
var fault=nativeRun.faults.getFirst();assertEquals("vm_init",fault.kind());assertNull(fault.pc());assertNull(fault.span());
assertTrue(fault.facts().containsKey("initError"));assertNull(nativeRun.connection);
}
}
@Test void realCompiledTrapArrivesBeforeEofAndKeepsItsSourceSpan(@org.junit.jupiter.api.io.TempDir java.nio.file.Path root) throws Exception {
java.nio.file.Files.createDirectories(root.resolve("src"));
java.nio.file.Files.writeString(root.resolve("prometeu.json"),"{\"name\":\"fault-probe\",\"version\":\"1\",\"language\":\"pbs\",\"stdlib\":\"1\",\"target\":\"Game\",\"dependencies\":[]}");
java.nio.file.Files.writeString(root.resolve("src/mod.barrel"),"pub fn frame() -> void;");
java.nio.file.Files.writeString(root.resolve("src/main.pbs"),"// ação 😀\r\n[Frame] fn frame() -> void { let zero = 0; let value = 123 / zero; }\r\n");
var mapper=new com.fasterxml.jackson.databind.ObjectMapper();
var project=new p.studio.core.project.ProjectCatalogService(root,mapper,new p.studio.core.project.ProjectLocalStudioSetupStore(mapper)).openProject(root);
try(var workers=Executors.newFixedThreadPool(2);var packer=p.packer.Packer.bootstrap(mapper,e->{})) {
var shipper=new p.studio.core.shipper.StudioShipperService(new p.studio.app.compiler.CompilerBuildGatewayAdapter(),packer.workspaceService(),mapper,new p.studio.app.operation.ExecutorOperationExecutor(workers));
var build=shipper.prepare(project,e->{}).completion().toCompletableFuture().get(30,TimeUnit.SECONDS);
assertTrue(build.success(),build.diagnostics().toString());
try(var nativeRun=new Native(root.resolve("build"),null)) {
assertNotNull(nativeRun.connection,nativeRun.faults.toString());
java.nio.file.Files.delete(root.resolve("src/main.pbs"));
nativeRun.connection.startExecution().get(3,TimeUnit.SECONDS);
assertThrows(ExecutionException.class,()->nativeRun.connection.completion().get(5,TimeUnit.SECONDS));
var fault=nativeRun.faults.getFirst();assertEquals("vm_trap",fault.kind(),()->nativeRun.faults+"\n"+nativeRun.logs);assertNotNull(fault.pc());assertNotNull(fault.span());
var source=build.executionSources().sources().get(Math.toIntExact(fault.span().fileId()));
assertNotNull(source);assertTrue(source.text().contains("123 / zero"));
assertEquals(build.executionSources().programSha256(),fault.programSha256());
assertFalse(nativeRun.process.isAlive());
}
}
}
@Test void liveFramesRemainStableDuringSlowPresentationAndStopIsConfirmed()throws Exception {
try(var s=new Native()){
long pid=s.process.pid();s.connection.startExecution().get(3,TimeUnit.SECONDS);
@@ -27,6 +27,11 @@ class StudioWireTest {
assertArrayEquals(fixture("pause.hex"),new Header(PAUSE,0,1,42).encode());
assertEquals(42,Header.decode(fixture("pause.hex")).request());
}
@Test void v1IsRejectedWithTheRequiredVersionBeforeAnyCommand() throws Exception {
byte[] header=fixture("pause.hex");header[4]=1;
var failure=assertThrows(IOException.class,()->Header.decode(header));
assertTrue(failure.getMessage().contains("required 2.0"));
}
@Test void fragmentedReadsWorkButTruncationAndReplayFail() throws Exception {
byte[] bytes=fixture("pause.hex");
InputStream fragmented=new FilterInputStream(new ByteArrayInputStream(bytes)) {
@@ -0,0 +1,27 @@
50 53 54 31 02 00 00 00 10 00 00 00 82 01 00 00
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
7b 22 73 63 68 65 6d 61 56 65 72 73 69 6f 6e 22
3a 31 2c 22 73 65 73 73 69 6f 6e 49 64 22 3a 22
30 33 30 33 30 33 30 33 30 33 30 33 30 33 30 33
30 33 30 33 30 33 30 33 30 33 30 33 30 33 30 33
22 2c 22 70 72 6f 67 72 61 6d 53 68 61 32 35 36
22 3a 22 61 62 61 62 61 62 61 62 61 62 61 62 61
62 61 62 61 62 61 62 61 62 61 62 61 62 61 62 61
62 61 62 61 62 61 62 61 62 61 62 61 62 61 62 61
62 61 62 61 62 61 62 61 62 61 62 61 62 61 62 61
62 61 62 22 2c 22 74 69 63 6b 22 3a 37 2c 22 74
72 75 6e 63 61 74 65 64 22 3a 66 61 6c 73 65 2c
22 66 61 75 6c 74 22 3a 7b 22 6b 69 6e 64 22 3a
22 76 6d 5f 74 72 61 70 22 2c 22 70 63 22 3a 34
32 39 34 39 36 37 32 39 35 2c 22 73 75 6d 6d 61
72 79 22 3a 22 64 69 76 69 73 69 6f 6e 20 62 79
20 7a 65 72 6f 20 e2 80 94 20 61 c3 a7 c3 a3 6f
22 2c 22 74 72 61 70 22 3a 7b 22 70 63 22 3a 34
32 39 34 39 36 37 32 39 35 2c 22 63 6f 64 65 22
3a 32 2c 22 6f 70 63 6f 64 65 22 3a 31 34 2c 22
73 70 61 6e 22 3a 7b 22 66 69 6c 65 5f 69 64 22
3a 37 2c 22 73 74 61 72 74 22 3a 31 38 2c 22 65
6e 64 22 3a 32 33 7d 2c 22 6d 65 73 73 61 67 65
22 3a 22 64 69 76 69 73 69 6f 6e 20 62 79 20 7a
65 72 6f 20 e2 80 94 20 61 c3 a7 c3 a3 6f 22 7d
7d 7d
@@ -1,2 +1 @@
50 53 54 31 01 00 00 00 04 00 00 00 00 00 00 00
01 00 00 00 00 00 00 00 2a 00 00 00 00 00 00 00
50 53 54 31 02 00 00 00 04 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 2a 00 00 00 00 00 00 00
@@ -1,6 +1 @@
50 53 54 31 01 00 00 00 09 00 00 00 38 00 00 00
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
01 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00
02 00 00 00 01 00 00 00 02 00 00 00 01 00 00 00
ff 00 00 ff 00 00 ff 80
50 53 54 31 02 00 00 00 09 00 00 00 38 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 01 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 02 00 00 00 01 00 00 00 02 00 00 00 01 00 00 00 ff 00 00 ff 00 00 ff 80