feat(pbs): add Beacon Workshop composition example
Add an original-asset minigame with modern controls, independent movement and tool animations, randomized safe beacon layouts and 2D drone patrols. Distribute the canonical project through installed knowledge and exercise compiled cartridges and animation boundaries. Fix lowering of admitted sibling constants and add a regression test. Focused compiler, installed knowledge and direct native checks passed; user tested and approved. Full make verify remains blocked by sandbox sysctl restrictions in ACP tests. WRK-0022 remains open.
This commit is contained in:
@@ -127,6 +127,7 @@ tasks.register<Test>("headlessProcessTest") {
|
||||
include("**/HeadlessInstalledRuntimeTest.class")
|
||||
include("**/GuestTestsInstalledRuntimeTest.class")
|
||||
include("**/AnimationInstalledRuntimeTest.class")
|
||||
include("**/BeaconWorkshopInstalledRuntimeTest.class")
|
||||
systemProperty("pbs.registryConformanceDirectory",
|
||||
project(":prometeu-compiler:prometeu-build-pipeline").layout.buildDirectory.dir("registry-conformance").get().asFile.absolutePath)
|
||||
include("**/HeadlessTaskIntegrationTest.class")
|
||||
|
||||
+256
@@ -0,0 +1,256 @@
|
||||
package p.studio.app.animation;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import p.packer.Packer;
|
||||
import p.studio.api.automation.*;
|
||||
import p.studio.api.project.*;
|
||||
import p.studio.app.assets.PackerGlyphBankLayouts;
|
||||
import p.studio.app.compiler.CompilerBuildGatewayAdapter;
|
||||
import p.studio.app.operation.ExecutorOperationExecutor;
|
||||
import p.studio.app.runtime.HeadlessProcessGateway;
|
||||
import p.studio.core.project.*;
|
||||
import p.studio.core.shipper.StudioShipperService;
|
||||
import p.studio.core.runtime.HeadlessGateway;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.nio.file.*;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** Compiles the exact resource-distributed game, then drives the packaged native process. */
|
||||
@Tag("integration")
|
||||
class BeaconWorkshopInstalledRuntimeTest {
|
||||
@TempDir Path root;
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
void extract() throws Exception {
|
||||
var loader = p.studio.compiler.FrontendRegistryService.require("pbs").getClass().getClassLoader();
|
||||
try (var input = loader.getResourceAsStream("pbs-knowledge/examples/game/1/beacon-workshop/distribution.json")) {
|
||||
assertNotNull(input, "Missing canonical game projection");
|
||||
var inventory = mapper.readTree(input);
|
||||
for (var file : inventory.path("files")) {
|
||||
Path target = root.resolve(file.path("path").asText());
|
||||
assertTrue(target.normalize().startsWith(root));
|
||||
try (var resource = loader.getResourceAsStream(file.path("resource").asText())) {
|
||||
assertNotNull(resource, file.toString());
|
||||
byte[] bytes = resource.readAllBytes();
|
||||
assertEquals(file.path("sha256").asText(), HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(bytes)));
|
||||
Files.createDirectories(target.getParent()); Files.write(target, bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface interface Scenario { void run(HeadlessGateway.Session session) throws Exception; }
|
||||
|
||||
void runGame(boolean probe, boolean brokenInitialization, Scenario scenario) throws Exception {
|
||||
extract();
|
||||
if (probe) {
|
||||
try (var input = getClass().getResourceAsStream("/beacon-workshop/verify.pbs")) {
|
||||
assertNotNull(input); Files.write(root.resolve("src/verify.pbs"), input.readAllBytes());
|
||||
}
|
||||
Files.writeString(root.resolve("src/mod.barrel"), "\nmod fn verify_components(value: Workshop) -> result<AnimationError> bool;\nmod fn verify_variation(value: Workshop, trial: int) -> void;\n", StandardOpenOption.APPEND);
|
||||
Path main = root.resolve("src/main.pbs");
|
||||
Files.writeString(main, Files.readString(main).replace("fn run_frame() -> result<AnimationError> {", """
|
||||
fn run_frame() -> result<AnimationError> {
|
||||
if !probe_done {
|
||||
if let value = slot.value {
|
||||
handle verify_components(value) { _ -> { fail("Guest verification failed"); ok(false) } };
|
||||
}
|
||||
probe_done = true;
|
||||
}
|
||||
if variation_trial < 512 {
|
||||
if let value = slot.value { verify_variation(value, variation_trial); }
|
||||
variation_trial += 1;
|
||||
}
|
||||
""") + "\ndeclare global probe_done: bool = false;\ndeclare global variation_trial: int = 0;\n");
|
||||
}
|
||||
if (brokenInitialization) {
|
||||
Path file = root.resolve("src/workshop.pbs");
|
||||
Files.writeString(file, Files.readString(file).replace("let body = create_robot(0)!", "let body = create_robot(300)!"));
|
||||
}
|
||||
String install = System.getProperty("studio.test.runtimeInstall");
|
||||
assertNotNull(install, "Supply -PstudioRuntimeInstall");
|
||||
var setup = new ProjectLocalStudioSetupStore(mapper);
|
||||
var project = new ProjectCatalogService(root.getParent(), mapper, setup).openProject(root);
|
||||
setup.save(project, new ProjectLocalStudioSetup(install, null));
|
||||
try (var workers = Executors.newSingleThreadExecutor(); var packer = Packer.bootstrap(mapper, ignored -> {})) {
|
||||
var layouts = new PackerGlyphBankLayouts(packer.workspaceService(), mapper);
|
||||
var build = new StudioShipperService(new CompilerBuildGatewayAdapter(layouts), packer.workspaceService(), mapper,
|
||||
new ExecutorOperationExecutor(workers)).withAssetPreflight(new p.studio.app.assets.AssetBudgetInspection(
|
||||
mapper, packer.workspaceService(), setup::load)).prepare(project, ignored -> {}).completion().toCompletableFuture().get(60, TimeUnit.SECONDS);
|
||||
if (!build.success()) for (var issue : build.issues()) System.out.println(mapper.writeValueAsString(issue.toMap()));
|
||||
assertTrue(build.success(), build.diagnostics().toString());
|
||||
{
|
||||
String variant = probe ? "component-checks" : brokenInitialization ? "initialization-error" : "cartridge";
|
||||
Path artifact = Path.of(System.getProperty("pbs.registryConformanceDirectory")).resolve("beacon-workshop/" + variant);
|
||||
try (var files = Files.walk(build.manifestPath().getParent())) {
|
||||
for (Path file : files.filter(Files::isRegularFile).toList()) {
|
||||
Path target = artifact.resolve(build.manifestPath().getParent().relativize(file).toString());
|
||||
Files.createDirectories(target.getParent()); Files.copy(file, target, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
}
|
||||
var session = new HeadlessProcessGateway(mapper, setup::load).boot(project, "beacon-workshop", build);
|
||||
try {
|
||||
scenario.run(session);
|
||||
} finally { session.shutdown().toCompletableFuture().get(10, TimeUnit.SECONDS); }
|
||||
}
|
||||
}
|
||||
|
||||
BufferedImage advance(HeadlessGateway.Session session, int ticks, Map<String, Object> input) throws Exception {
|
||||
session.call(TaskTools.HeadlessAction.CLEAR_INPUT, Map.of());
|
||||
if (!input.isEmpty()) session.call(TaskTools.HeadlessAction.SET_INPUT, input);
|
||||
var outcome = session.advance(ticks, ignored -> {});
|
||||
assertEquals(AutomationOutcome.Kind.SUCCEEDED, outcome.kind(), outcome.toString());
|
||||
assertNull(session.call(TaskTools.HeadlessAction.FAULT, Map.of()).values().get("fault"));
|
||||
var image = ImageIO.read(new ByteArrayInputStream(outcome.capture().png()));
|
||||
assertEquals(640, image.getWidth()); assertEquals(360, image.getHeight());
|
||||
return image;
|
||||
}
|
||||
|
||||
void save(String name, BufferedImage image) throws Exception {
|
||||
Path directory = Path.of(System.getProperty("pbs.registryConformanceDirectory")).resolve("beacon-workshop");
|
||||
Files.createDirectories(directory); ImageIO.write(image, "png", directory.resolve(name + ".png").toFile());
|
||||
}
|
||||
|
||||
// Image-driven test pilot uses independent art signatures and live drone positions.
|
||||
// It sends real logical input; it never changes production state or sources.
|
||||
static int[] robot(BufferedImage image) {
|
||||
for(int y=64;y<=288;y++) for(int x=32;x<=576;x++)
|
||||
if(image.getRGB(x+15,y+1)==0xfff9ead3 && image.getRGB(x+10,y+5)==0xffc9edf0
|
||||
&& image.getRGB(x+8,y+12)==0xffc9edf0 && image.getRGB(x+14,y+19)==0xffffbf69)
|
||||
return new int[]{x,y};
|
||||
throw new AssertionError("Robot art signature missing");
|
||||
}
|
||||
static List<int[]> drones(BufferedImage image) {
|
||||
var points=new ArrayList<int[]>();
|
||||
for(int y=64;y<=288;y++) for(int x=32;x<=576;x++)
|
||||
if(image.getRGB(x+9,y+11)==0xffe27858 && image.getRGB(x+10,y+12)==0xffffbf69
|
||||
&& image.getRGB(x+12,y+15)==0xff233549 && image.getRGB(x+14,y+15)==0xfff9ead3)
|
||||
points.add(new int[]{x,y});
|
||||
return points;
|
||||
}
|
||||
static boolean walkable(int x,int y) {
|
||||
return x>=32&&x<=576&&y>=64&&y<=288&&!(x>264&&x<344&&y>104&&y<184);
|
||||
}
|
||||
static int nextDirection(int x,int y,int gx,int gy,List<int[]> hazards) {
|
||||
int columns=81; var queue=new ArrayDeque<Integer>(); var parent=new HashMap<Integer,Integer>();
|
||||
int start=(y/8)*columns+x/8,goal=(gy/8)*columns+gx/8;queue.add(start);parent.put(start,-1);
|
||||
int[] dx={0,1,0,-1},dy={-1,0,1,0};
|
||||
while(!queue.isEmpty()&&!parent.containsKey(goal)) {
|
||||
int cell=queue.remove();int cx=cell%columns*8,cy=cell/columns*8;
|
||||
for(int n=0;n<4;n++) {
|
||||
int nx=cx+dx[n]*8,ny=cy+dy[n]*8,key=(ny/8)*columns+nx/8;
|
||||
if(!walkable(nx,ny)||parent.containsKey(key)) continue;
|
||||
boolean blocked=false;
|
||||
for(int[] drone:hazards) if(Math.abs(nx-drone[0])<40&&Math.abs(ny-drone[1])<40) blocked=true;
|
||||
if(blocked) continue;parent.put(key,cell);queue.add(key);
|
||||
}
|
||||
}
|
||||
if(!parent.containsKey(goal)) return -1;
|
||||
int next=goal;while(parent.get(next)!=start) next=parent.get(next);
|
||||
int nx=next%columns*8,ny=next/columns*8;
|
||||
return nx>x?1:nx<x?3:ny>y?2:0;
|
||||
}
|
||||
static boolean victory(BufferedImage image) {
|
||||
if(image.getRGB(150,140)!=0xff101c2a) return false;
|
||||
for(int y=156;y<168;y++)for(int x=176;x<464;x++)if(image.getRGB(x,y)==0xff4de3b5)return true;
|
||||
return false;
|
||||
}
|
||||
BufferedImage navigate(HeadlessGateway.Session session,BufferedImage image,int gx,int gy,boolean finish) throws Exception {
|
||||
String[] directions={"up","right","down","left"};
|
||||
for(int n=0;n<600;n++) {
|
||||
if(finish&&victory(image)) return image;
|
||||
int[] position=robot(image); if(position[0]==gx&&position[1]==gy)return image;
|
||||
int direction=nextDirection(position[0],position[1],gx,gy,drones(image));
|
||||
image=advance(session,4,direction<0?Map.of():Map.of(directions[direction],true));
|
||||
}
|
||||
throw new AssertionError("Pilot could not reach "+gx+","+gy);
|
||||
}
|
||||
BufferedImage pulse(HeadlessGateway.Session session,BufferedImage image,String direction,String reverse) throws Exception {
|
||||
advance(session,1,Map.of(direction,true,"a",true));
|
||||
advance(session,1,Map.of(reverse,true,"a",true));
|
||||
return advance(session,24,Map.of("a",true)); // held button never repeats the action
|
||||
}
|
||||
static int beaconMask(BufferedImage image) {
|
||||
int[][] anchors={{64,80},{144,80},{64,144},{176,112},{400,80},{496,80},{400,144},{528,144},
|
||||
{192,256},{288,256},{384,256},{480,288}};
|
||||
int mask=0;
|
||||
for(int n=0;n<anchors.length;n++) {
|
||||
int x=anchors[n][0],y=anchors[n][1];
|
||||
if(image.getRGB(x+8,y+4)==0xffffbf69&&image.getRGB(x+8,y+23)==0xff39556a)mask|=1<<n;
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
static int countBeacons(BufferedImage image,int color) {
|
||||
int[][] anchors={{64,80},{144,80},{64,144},{176,112},{400,80},{496,80},{400,144},{528,144},
|
||||
{192,256},{288,256},{384,256},{480,288}};
|
||||
int count=0;for(int[] point:anchors)if(image.getRGB(point[0]+8,point[1]+4)==0xffffbf69
|
||||
&& image.getRGB(point[0]+8,point[1]+23)==0xff39556a && image.getRGB(point[0]+16,point[1]+8)==color)count++;
|
||||
return count;
|
||||
}
|
||||
|
||||
@Test void distributedGameAcceptsInputActivatesAllBeaconsWinsAndRestarts() throws Exception {
|
||||
runGame(false, false, session -> {
|
||||
var initial = advance(session, 1, Map.of()); save("initial", initial);
|
||||
// Seed 2026 -> regional choices (2,3,0), independently checked against
|
||||
// @sdk:random in verify.pbs. Color oracles come from original authored art.
|
||||
int[][] beacons = {{64,144},{528,144},{192,256}};
|
||||
for (int[] point : beacons) assertEquals(0xff233549, initial.getRGB(point[0]+16,point[1]+8));
|
||||
var opposed = advance(session, 5, Map.of("left", true, "right", true, "up", true, "down", true));
|
||||
assertArrayEquals(initial.getRGB(64,256,32,32,null,0,32),opposed.getRGB(64,256,32,32,null,0,32));
|
||||
BufferedImage image = opposed;
|
||||
image = navigate(session,image,64,176,false);
|
||||
image = pulse(session,image,"up","down");
|
||||
assertEquals(0xff4de3b5,image.getRGB(80,152)); save("first-beacon",image);
|
||||
image = navigate(session,image,480,144,false);
|
||||
image = pulse(session,image,"right","left");
|
||||
assertEquals(0xff4de3b5,image.getRGB(544,152));
|
||||
image = navigate(session,image,192,288,false);
|
||||
image = pulse(session,image,"up","down");
|
||||
for (int[] point:beacons) assertEquals(0xff4de3b5,image.getRGB(point[0]+16,point[1]+8));
|
||||
assertEquals(0xff4de3b5,image.getRGB(588,268)); save("all-beacons",image);
|
||||
var won=navigate(session,image,576,256,true); assertTrue(victory(won));save("victory",won);
|
||||
var frozen=advance(session,20,Map.of("left",true,"a",true));
|
||||
assertArrayEquals(won.getRGB(0,0,640,360,null,0,640),frozen.getRGB(0,0,640,360,null,0,640));
|
||||
var restarted=advance(session,1,Map.of("start",true));save("restarted",restarted);
|
||||
assertFalse(victory(restarted));
|
||||
assertEquals(3,countBeacons(restarted,0xff233549));
|
||||
assertNotEquals(beaconMask(initial),beaconMask(restarted),"New match must change the layout itself");
|
||||
// A new native boot repeats the exact seed/ordered-input initial state.
|
||||
session.call(TaskTools.HeadlessAction.RESET,Map.of());
|
||||
session.call(TaskTools.HeadlessAction.BOOT,Map.of());
|
||||
var replay=advance(session,1,Map.of());
|
||||
assertArrayEquals(initial.getRGB(0,0,640,360,null,0,640),replay.getRGB(0,0,640,360,null,0,640));
|
||||
});
|
||||
}
|
||||
|
||||
@Test void componentsBoundariesCancellationErrorsAndRepeatedEmissionRunNatively() throws Exception {
|
||||
runGame(true, false, session -> {
|
||||
var image = advance(session, 1, Map.of());
|
||||
// A failed guest check traps, while handled result errors remain playable.
|
||||
assertEquals(0xff4de3b5, image.getRGB(76, 265));
|
||||
save("component-checks", image);
|
||||
advance(session, 512, Map.of());
|
||||
});
|
||||
}
|
||||
|
||||
@Test void voidInitializationHandlesFactoryFailureWithoutEnteringGameplay() throws Exception {
|
||||
runGame(false, true, session -> {
|
||||
var image = advance(session, 3, Map.of("a", true));
|
||||
assertEquals(0xff101c2a, image.getRGB(112, 108));
|
||||
// First letter of the error message has the declared coral diagnostic color.
|
||||
boolean found = false;
|
||||
for (int y=160;y<176;y++) for(int x=32;x<340;x++) found |= image.getRGB(x,y)==0xffe27858;
|
||||
assertTrue(found, "Handled factory failure must show the diagnostic screen");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ public final class InstalledKnowledgeProbe {
|
||||
check(!Files.exists(Path.of("settings.gradle.kts")) && !Files.exists(Path.of("docs")), "No repository in working directory");
|
||||
verifyRuntimeCatalogs(provider.getClass().getClassLoader());
|
||||
if (arguments.length == 1 && arguments[0].equals("--catalog-only")) return;
|
||||
verifyBeaconWorkshop(provider.getClass().getClassLoader());
|
||||
var guideType = Class.forName("p.studio.app.mcp.McpConnectionGuide");
|
||||
check(guideType.getProtectionDomain().getCodeSource().getLocation().getPath().endsWith(".jar"), "Lifecycle guide must come from installed JAR");
|
||||
var guide = (String)guideType.getField("INSTRUCTIONS").get(null);
|
||||
@@ -283,6 +284,48 @@ public final class InstalledKnowledgeProbe {
|
||||
System.out.println("Packaged external sources verified: JAR bytes, SDK/host/core navigation, hover, tokens, read-only, reconnect, no extraction");
|
||||
}
|
||||
|
||||
private static void verifyBeaconWorkshop(ClassLoader loader) throws Exception {
|
||||
String resource = "pbs-knowledge/examples/game/1/beacon-workshop/distribution.json";
|
||||
var location = loader.getResource(resource);
|
||||
check(location != null && location.getProtocol().equals("jar"), "Beacon Workshop must come from installed JAR");
|
||||
var mapper = new ObjectMapper();
|
||||
Path root = Files.createDirectory(Path.of("beacon-workshop")).toRealPath();
|
||||
try (var input = location.openStream()) {
|
||||
for (var file : mapper.readTree(input).path("files")) {
|
||||
Path target = root.resolve(file.path("path").asText()).normalize();
|
||||
check(target.startsWith(root), "Packaged game path must stay inside project");
|
||||
var url = loader.getResource(file.path("resource").asText());
|
||||
check(url != null && url.getProtocol().equals("jar"), "Every game resource must come from installed JAR");
|
||||
try (var bytes = url.openStream()) {
|
||||
byte[] data = bytes.readAllBytes();
|
||||
check(java.util.HexFormat.of().formatHex(java.security.MessageDigest.getInstance("SHA-256").digest(data))
|
||||
.equals(file.path("sha256").asText()), "Installed game resource hash mismatch");
|
||||
Files.createDirectories(target.getParent()); Files.write(target, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
var setup = new ProjectLocalStudioSetupStore(mapper);
|
||||
var project = new ProjectCatalogService(root.getParent(), mapper, setup).openProject(root);
|
||||
try (var workers = java.util.concurrent.Executors.newSingleThreadExecutor(); var packer = p.packer.Packer.bootstrap(mapper, ignored -> {})) {
|
||||
var layouts = new p.studio.app.assets.PackerGlyphBankLayouts(packer.workspaceService(), mapper);
|
||||
var build = new p.studio.core.shipper.StudioShipperService(new p.studio.app.compiler.CompilerBuildGatewayAdapter(layouts),
|
||||
packer.workspaceService(), mapper, new p.studio.app.operation.ExecutorOperationExecutor(workers))
|
||||
.prepare(project, ignored -> {}).completion().toCompletableFuture().get(60, java.util.concurrent.TimeUnit.SECONDS);
|
||||
check(build.success(), "Installed Beacon Workshop must compile and pack: " + build.diagnostics());
|
||||
Path output = Path.of(System.getProperty("pbs.registryConformanceDirectory")).resolve("beacon-workshop/installed-cartridge");
|
||||
try (var files = Files.walk(build.manifestPath().getParent())) {
|
||||
for (Path source : files.filter(Files::isRegularFile).toList()) {
|
||||
Path target = output.resolve(build.manifestPath().getParent().relativize(source).toString());
|
||||
Files.createDirectories(target.getParent()); Files.copy(source, target, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
mapper.writeValue(output.resolve("installed-source.json").toFile(), java.util.Map.of("resource", location.toString(),
|
||||
"programSha256", java.util.HexFormat.of().formatHex(java.security.MessageDigest.getInstance("SHA-256")
|
||||
.digest(Files.readAllBytes(output.resolve("program.pbx"))))));
|
||||
}
|
||||
System.out.println("Installed Beacon Workshop verified: original resources, hashes, generated factories, compile and pack");
|
||||
}
|
||||
|
||||
private static int[] position(String text, String needle, int offset) {
|
||||
int index = text.indexOf(needle);
|
||||
check(index >= 0, "Missing source fragment: " + needle);
|
||||
|
||||
@@ -29,6 +29,7 @@ class InstalledKnowledgeTest {
|
||||
assertTrue(log.contains("Installed generated animation verified"), log);
|
||||
assertTrue(log.contains("Installed production contracts verified: 21 compile classifications"), log);
|
||||
assertTrue(log.contains("Installed generated animation project: zelda-1"), log);
|
||||
assertTrue(log.contains("Installed Beacon Workshop verified: original resources, hashes, generated factories, compile and pack"), log);
|
||||
}
|
||||
|
||||
@Test void installedCompilerAndSdkCarryTheSameVerifiedCatalog() throws Exception {
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
// Test-only guest checks. Installed production sources are copied unchanged;
|
||||
// this extra module is injected into a disposable project by the process test.
|
||||
import { AnimationError, PlaybackState } from @core:animation;
|
||||
import { make_sprite, SpriteView } from @core:sprite;
|
||||
import { Composer } from @sdk:composer;
|
||||
import { Random, random } from @sdk:random;
|
||||
import { Log } from @sdk:log;
|
||||
|
||||
fn check(condition: bool) -> void { if !condition { let failure = 1 / 0; } }
|
||||
|
||||
fn verify_components(value: Workshop) -> result<AnimationError> bool {
|
||||
// Independent SDK oracle, without calling the game's layout selection code.
|
||||
let root_rng = random.new(2026 as long);
|
||||
let reference = random.new(random.next(root_rng));
|
||||
let expected_west = random.range(reference, 0 as long, 4 as long) as int;
|
||||
let expected_east = random.range(reference, 0 as long, 4 as long) as int;
|
||||
let expected_south = random.range(reference, 0 as long, 4 as long) as int;
|
||||
check(value.layout.west == expected_west && value.layout.east == expected_east && value.layout.south == expected_south);
|
||||
Log.info(expected_west, "SDK reference: west");
|
||||
Log.info(expected_east, "SDK reference: east");
|
||||
Log.info(expected_south, "SDK reference: south");
|
||||
let robot = value.robot;
|
||||
robot.reset()!;
|
||||
robot.motor.move(1, 1);
|
||||
check(robot.spatial.x == 64 * 256 + 362 && robot.spatial.y == 256 * 256 + 362);
|
||||
robot.motor.move(0, 0);
|
||||
check(!robot.motor.moving && robot.spatial.facing_x == 1 && robot.spatial.facing_y == 1);
|
||||
robot.spatial.reset(32, 64);
|
||||
robot.motor.move(-1, -1);
|
||||
check(robot.spatial.x == 32 * 256 && robot.spatial.y == 64 * 256);
|
||||
check(robot.spatial.facing_x == -1 && robot.spatial.facing_y == -1);
|
||||
robot.spatial.reset(256, 144);
|
||||
robot.motor.move(1, 0);
|
||||
check(robot.spatial.x == 258 * 256);
|
||||
for n: int from 0 until 20 { robot.motor.move(1, 0); }
|
||||
check(robot.spatial.x == 264 * 256);
|
||||
|
||||
// The very same robot consumes an AI controller and then the human controller.
|
||||
robot.reset()!;
|
||||
robot.move(value.first.controller);
|
||||
check(robot.spatial.x == 64 * 256 + 362 && robot.spatial.y == 256 * 256 - 362);
|
||||
robot.move(value.player);
|
||||
check(robot.spatial.x == 64 * 256 + 362 && !robot.motor.moving);
|
||||
|
||||
robot.spatial.facing_x = 1; robot.spatial.facing_y = 0;
|
||||
check(robot.tool.request(true, robot.spatial)!);
|
||||
check(robot.tool.starts == 1 && robot.tool.active);
|
||||
robot.tool.advance()!;
|
||||
check(!robot.tool.request(true, robot.spatial)! && !robot.tool.pending);
|
||||
for n: int from 0 until 7 { robot.tool.advance()!; }
|
||||
check(robot.tool.remaining == 4);
|
||||
let body_before = robot.visual.animator.sprite().glyph_id;
|
||||
check(!robot.tool.request(true, robot.spatial)! && robot.tool.pending);
|
||||
for n: int from 0 until 4 { robot.tool.advance()!; }
|
||||
check(robot.tool.animator.state() == PlaybackState.Finished);
|
||||
robot.spatial.facing_x = 0; robot.spatial.facing_y = -1;
|
||||
check(robot.tool.request(false, robot.spatial)!);
|
||||
check(robot.tool.starts == 2 && !robot.tool.pending && robot.tool.direction_y == -1);
|
||||
check(robot.visual.animator.sprite().glyph_id == body_before);
|
||||
check(!robot.tool.request(false, robot.spatial)!);
|
||||
robot.tool.cancel();
|
||||
check(!robot.tool.active && !robot.tool.pending && !robot.tool.request(false, robot.spatial)!);
|
||||
|
||||
// A normal body transition advances continuously and does not touch the tool.
|
||||
robot.reset()!;
|
||||
robot.spatial.facing_x = 1; robot.spatial.facing_y = 0;
|
||||
for n: int from 0 until 5 { robot.visual.advance(robot.spatial, true)!; }
|
||||
check(robot.visual.animator.sprite().glyph_id == 4);
|
||||
robot.visual.advance(robot.spatial, true)!;
|
||||
check(robot.visual.animator.sprite().glyph_id == 5);
|
||||
check(!robot.tool.active && robot.tool.starts == 0);
|
||||
let drone_before = value.second.animator.sprite().glyph_id;
|
||||
value.first.animator.advance(6)!;
|
||||
check(value.second.animator.sprite().glyph_id == drone_before);
|
||||
|
||||
// Real error recovery preserves playback, rather than catching a VM trap.
|
||||
let body = robot.visual.animator;
|
||||
let glyph = body.sprite().glyph_id;
|
||||
handle body.advance(-1) { AnimationError.invalid_ticks -> { ok(()) }, _ -> AnimationError.overflow };
|
||||
check(body.sprite().glyph_id == glyph);
|
||||
|
||||
// Start a buffered action, then make contact take priority over its completion.
|
||||
value.reset()!;
|
||||
robot.spatial.reset(value.first.spatial.pixel_x(), value.first.spatial.pixel_y());
|
||||
robot.tool.request(true, robot.spatial)!;
|
||||
for n: int from 0 until 8 { robot.tool.advance()!; }
|
||||
robot.tool.request(true, robot.spatial)!;
|
||||
check(robot.tool.pending);
|
||||
value.update()!;
|
||||
check(value.contacts == 1 && robot.spatial.pixel_x() == 64 && robot.spatial.pixel_y() == 256);
|
||||
check(!robot.tool.active && !robot.tool.pending && !value.first_beacon.lit);
|
||||
|
||||
// Multiple emission calls preserve positions, glyphs, playback, requests and events.
|
||||
value.reset()!;
|
||||
robot.tool.request(true, robot.spatial)!;
|
||||
robot.tool.advance()!;
|
||||
robot.visual.advance(robot.spatial, true)!;
|
||||
let x = robot.spatial.x; let y = robot.spatial.y;
|
||||
let remaining = robot.tool.remaining; let starts = robot.tool.starts;
|
||||
let tool_glyph = robot.tool.animator.sprite().glyph_id;
|
||||
let body_glyph = robot.visual.animator.sprite().glyph_id;
|
||||
let first_glyph = value.first.animator.sprite().glyph_id;
|
||||
let second_glyph = value.second.animator.sprite().glyph_id;
|
||||
check(render(value)); check(render(value));
|
||||
check(robot.spatial.x == x && robot.spatial.y == y && robot.tool.remaining == remaining);
|
||||
check(robot.tool.starts == starts && robot.tool.animator.sprite().glyph_id == tool_glyph);
|
||||
check(value.first.animator.sprite().glyph_id == first_glyph && !value.first_beacon.lit);
|
||||
check(value.second.animator.sprite().glyph_id == second_glyph);
|
||||
check(robot.visual.animator.sprite().glyph_id == body_glyph);
|
||||
check(robot.tool.animator.state() == PlaybackState.Playing && !robot.tool.pending);
|
||||
// Check the exact next boundaries: equal glyphs alone could hide phase drift.
|
||||
robot.tool.animator.advance(2)!;
|
||||
check(robot.tool.animator.sprite().glyph_id == tool_glyph);
|
||||
robot.tool.animator.advance(1)!;
|
||||
check(robot.tool.animator.sprite().glyph_id != tool_glyph);
|
||||
robot.visual.animator.advance(4)!;
|
||||
check(robot.visual.animator.sprite().glyph_id == body_glyph);
|
||||
robot.visual.animator.advance(1)!;
|
||||
check(robot.visual.animator.sprite().glyph_id != body_glyph);
|
||||
value.first.animator.advance(5)!;
|
||||
check(value.first.animator.sprite().glyph_id == first_glyph);
|
||||
value.first.animator.advance(1)!;
|
||||
check(value.first.animator.sprite().glyph_id != first_glyph);
|
||||
|
||||
// Invalid numeric bank/glyph identifiers can be valid Sprite values but fail emission.
|
||||
let invalid = handle make_sprite(255, 65535) { _ -> AnimationError.invalid_glyph };
|
||||
let image = invalid.sprite();
|
||||
check(Composer.emit_sprite(image.glyph_id, 0, 32, 64, 1, image.bank_id, false, false, 0) != 0);
|
||||
|
||||
// A deliberately blocked connection returns along the last known leg.
|
||||
robot.spatial.reset(264, 112);
|
||||
let stuck = new PatrolController(random.new(7 as long), 8, 3, 1, 0, false, 264, 112);
|
||||
for n: int from 0 until 32 {
|
||||
let command = stuck.intent(robot.spatial.pixel_x(), robot.spatial.pixel_y());
|
||||
robot.motor.move(command.move_x, command.move_y);
|
||||
}
|
||||
check(stuck.recovering && stuck.target == 8 && robot.spatial.x < 264 * 256);
|
||||
value.reset()!;
|
||||
check(robot.tool.starts == 0 && value.contacts == 0 && !value.won);
|
||||
check(!value.first_beacon.lit && !value.second_beacon.lit && !value.third_beacon.lit);
|
||||
return ok(true);
|
||||
}
|
||||
|
||||
// One bounded batch per guest frame: eight seeds, eight successive matches each.
|
||||
declare global first_seed_code: int = -1;
|
||||
declare global seed_diversity: bool = false;
|
||||
declare global first_vertical: bool = false;
|
||||
declare global first_diagonal: bool = false;
|
||||
declare global second_vertical: bool = false;
|
||||
declare global second_diagonal: bool = false;
|
||||
|
||||
fn verify_variation(value: Workshop, trial: int) -> void {
|
||||
if trial < 64 {
|
||||
let seed = (trial / 8) as long;
|
||||
let a = new BeaconLayout(random.new(seed), -1, -1, -1);
|
||||
let b = new BeaconLayout(random.new(seed), -1, -1, -1);
|
||||
for n: int from 0 until trial % 8 + 1 {
|
||||
let west = a.west; let east = a.east; let south = a.south;
|
||||
a.next(); b.next();
|
||||
check(a.west != west || a.east != east || a.south != south);
|
||||
check(a.west == b.west && a.east == b.east && a.south == b.south);
|
||||
}
|
||||
check(a.valid());
|
||||
if trial % 8 == 0 {
|
||||
let code = a.west * 16 + a.east * 4 + a.south;
|
||||
if trial == 0 { first_seed_code = code; }
|
||||
else if code != first_seed_code { seed_diversity = true; }
|
||||
}
|
||||
if trial == 63 { check(seed_diversity); }
|
||||
// Advancing one stream does not mutate the independent copy.
|
||||
let west = b.west; let east = b.east; let south = b.south;
|
||||
a.next();
|
||||
check(b.west == west && b.east == east && b.south == south);
|
||||
}
|
||||
check(clear_position(value.first.spatial.x, value.first.spatial.y));
|
||||
check(clear_position(value.second.spatial.x, value.second.spatial.y));
|
||||
check(!touches(value.robot.spatial, value.first.spatial) && !touches(value.robot.spatial, value.second.spatial));
|
||||
if value.first.spatial.pixel_y() != route_y(0) { first_vertical = true; }
|
||||
if value.second.spatial.pixel_y() != route_y(4) { second_vertical = true; }
|
||||
if value.first.motor.moving && value.first.spatial.facing_x != 0 && value.first.spatial.facing_y != 0 { first_diagonal = true; }
|
||||
if value.second.motor.moving && value.second.spatial.facing_x != 0 && value.second.spatial.facing_y != 0 { second_diagonal = true; }
|
||||
if trial == 511 {
|
||||
check(first_vertical && first_diagonal && second_vertical && second_diagonal);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user