feat(studio): deliver asset authoring and automation workflows
Test / Tests and coverage occurred while executing withChecks step.
Intrepid/Prometeu/Studio/pipeline/pr-master There was a failure building this commit

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.
This commit is contained in:
2026-11-11 01:21:25 +00:00
parent b351f2e582
commit 1471b427f1
325 changed files with 61179 additions and 323 deletions
@@ -0,0 +1,139 @@
package p.studio.app.compiler;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import p.studio.api.automation.*;
import p.studio.api.project.ProjectCatalog;
import p.studio.api.session.*;
import p.studio.api.shipper.Shipper;
import p.studio.app.StudioApplicationConfiguration;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.nio.file.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.*;
/** Real compiler/packer/project composition, no guest or runtime installation required. */
class TargetBuildIntegrationTest {
@TempDir Path root;
ConfigurableApplicationContext app;ProjectSession project;TaskTools tools;String task;ObjectMapper mapper;
@BeforeEach void open()throws Exception {
root=root.toRealPath();Files.createDirectories(root.resolve("src"));Files.createDirectories(root.resolve("tests/life"));Files.createDirectories(root.resolve("tests/shop"));
Files.writeString(root.resolve("src/main.pbs"),"[Frame] fn frame() -> void {}\n");
Files.writeString(root.resolve("src/mod.barrel"),"pub fn frame() -> void;\n");
Files.writeString(root.resolve("tests/life/main.pbs"),"[Frame] fn frame() -> void {}\n");
Files.writeString(root.resolve("tests/shop/main.pbs"),"[Frame] fn frame() -> void {}\n");
Files.writeString(root.resolve("prometeu.json"),"""
{"name":"targetfixture","version":"1.0.0","language":"pbs","stdlib":"1","target":"Game","app_id":123,"dependencies":[],
"testTargets":{"schemaVersion":1,"targets":[
{"id":"life","entrypoint":"tests/life/main.pbs","sourceRoots":["src","tests/life"],"supportRoots":[],"exclusions":["src/main.pbs"],"cases":["health"],"logTag":41000},
{"id":"shop-save","entrypoint":"tests/shop/main.pbs","sourceRoots":["src","tests/shop"],"supportRoots":[],"exclusions":["src/main.pbs"],"cases":["save"],"logTag":41001}]}}
""");
app=new SpringApplicationBuilder(StudioApplicationConfiguration.class).web(WebApplicationType.NONE).headless(true).run();
mapper=app.getBean(ObjectMapper.class);project=app.getBean(ProjectSessionFactory.class).open(app.getBean(ProjectCatalog.class).openProject(root));
tools=app.getBean(TaskTools.class);project.automation().grant(false).toCompletableFuture().get(5,TimeUnit.SECONDS);task=tools.acquire(root).task().value();
}
@AfterEach void close(){try{if(project!=null)project.close();}finally{if(app!=null)app.close();}}
TrackedOperation build(String request,String target)throws Exception {
tools.build(root,task,request,target);long deadline=System.nanoTime()+TimeUnit.SECONDS.toNanos(30);
do {var operation=tools.operation(root,task,new OperationLookup(null,request));if(operation.workerTerminated())return operation;Thread.sleep(5);}while(System.nanoTime()<deadline);
throw new AssertionError("Target build worker did not terminate");
}
@Test void immutableTargetArtifactsProvenanceDedupAndManualProductionBuildAreIndependent()throws Exception {
byte[] production=Files.readAllBytes(root.resolve("src/main.pbs"));
var first=build("life-build","life");assertNotNull(first.buildResult());assertTrue(first.buildResult().success(),first.buildResult().diagnostics().toString());
assertNotNull(first.buildId());Path firstRoot=root.resolve(".studio/test-builds/life").resolve(first.buildId());
assertEquals(firstRoot.resolve("manifest.json"),first.buildResult().manifestPath());assertFalse(Files.exists(root.resolve("build/manifest.json")));
byte[] originalPbx=Files.readAllBytes(firstRoot.resolve("program.pbx"));byte[] originalManifest=Files.readAllBytes(firstRoot.resolve("manifest.json"));
var provenance=mapper.readTree(firstRoot.resolve("build-provenance.json").toFile());
assertEquals("life",provenance.path("targetId").asText());assertEquals(first.buildId(),provenance.path("buildId").asText());
assertTrue(provenance.path("sources").has(root.resolve("tests/life/main.pbs").toString()));
assertFalse(provenance.path("sources").has(root.resolve("src/main.pbs").toString()));
assertTrue(provenance.path("dependencyConfigurationSha256").has(root.resolve("prometeu.json").toString()));
assertEquals(64,provenance.path("revision").asText().length());
var duplicate=tools.build(root,task,"life-build","life");assertEquals(first.operation().id(),duplicate.operation().id());
assertEquals(AutomationFailure.Code.CLIENT_REQUEST_CONFLICT,assertThrows(AutomationException.class,()->tools.build(root,task,"life-build","shop-save")).failure().code());
var second=build("shop-build","shop-save");assertTrue(second.buildResult().success(),second.buildResult().diagnostics().toString());
assertNotEquals(first.buildId(),second.buildId());
assertArrayEquals(originalPbx,Files.readAllBytes(firstRoot.resolve("program.pbx")));assertArrayEquals(originalManifest,Files.readAllBytes(firstRoot.resolve("manifest.json")));
assertEquals(first.buildId(),tools.operation(root,task,new OperationLookup(null,"life-build")).buildId());
tools.release(root,task).toCompletableFuture().get(10,TimeUnit.SECONDS);
var manual=app.getBean(Shipper.class).prepare(project.projectReference(),ignored->{}).completion().toCompletableFuture().get(30,TimeUnit.SECONDS);
assertTrue(manual.success(),manual.diagnostics().toString());assertEquals(root.resolve("build/manifest.json"),manual.manifestPath());assertEquals("production",manual.context().get("targetId"));
assertArrayEquals(production,Files.readAllBytes(root.resolve("src/main.pbs")));assertArrayEquals(originalPbx,Files.readAllBytes(firstRoot.resolve("program.pbx")));
}
@Test void invalidSelectedSourceCannotPublishATestCartridgeOrUsableBuildIdentity()throws Exception {
byte[] source=Files.readAllBytes(root.resolve("src/main.pbs"));Files.writeString(root.resolve("tests/life/bad.pbs"),"fn broken( this is invalid\n");
var result=build("bad-test","life");assertNull(result.buildId());assertNotNull(result.buildResult());assertFalse(result.buildResult().success());
assertNull(result.buildResult().manifestPath());
assertTrue(result.buildResult().issues().stream().anyMatch(issue->String.valueOf(issue.toMap().get("origin")).contains("tests/life/bad.pbs")),result.buildResult().issues().toString());
try(var files=Files.walk(root.resolve(".studio/test-builds/life"))) {assertTrue(files.noneMatch(p->p.getFileName().toString().equals("manifest.json")));}
assertArrayEquals(source,Files.readAllBytes(root.resolve("src/main.pbs")));
var production=build("production-after-rejection",null);assertTrue(production.buildResult().success(),production.buildResult().diagnostics().toString());
}
@Test void cancellationWaitsForCleanupAndSourceRevisionChangesRefusePublication()throws Exception {
var before=build("retained","shop-save");assertTrue(before.buildResult().success(),before.buildResult().diagnostics().toString());
byte[] manifest=Files.readAllBytes(before.buildResult().manifestPath());
var entered=new java.util.concurrent.CountDownLatch(1);var staged=new java.util.concurrent.atomic.AtomicReference<Path>();
var paused=shipperAfterCompile((project,output)->{
staged.set(output);entered.countDown();
try {new java.util.concurrent.CountDownLatch(1).await();}
catch(InterruptedException interrupted){Thread.currentThread().interrupt();throw new java.util.concurrent.CancellationException("Cancelled fixture after compile");}
});
var candidate=new BuildSelection("life",UUID.randomUUID().toString());
var operation=project.automation().submit(project.automation().snapshot().task(),"Test build cancellation",()->{
paused.prepareNow(project.projectReference(),candidate,ignored->{});
return new AutomationOutcome(AutomationOutcome.Kind.CANCELLED,0,0,List.of(),null);
});
assertTrue(entered.await(10,TimeUnit.SECONDS));assertTrue(Files.isRegularFile(staged.get().resolve("program.pbx")));
operation.cancel();operation.termination().toCompletableFuture().get(10,TimeUnit.SECONDS);
assertFalse(Files.exists(staged.get()));assertFalse(Files.exists(root.resolve(".studio/test-builds/life").resolve(candidate.buildId())));
assertArrayEquals(manifest,Files.readAllBytes(before.buildResult().manifestPath()));
var changed=shipperAfterCompile((project,output)->{
try {Files.writeString(root.resolve("tests/life/main.pbs"),"[Frame] fn frame() -> void { let external: int = 1; }\n");}
catch(java.io.IOException failure){throw new java.io.UncheckedIOException(failure);}
});
var changedSelection=new BuildSelection("life",UUID.randomUUID().toString());
var result=new java.util.concurrent.atomic.AtomicReference<p.studio.api.shipper.ShipperPrepareResult>();
var changeOperation=project.automation().submit(project.automation().snapshot().task(),"Changed source build",()->{
result.set(changed.prepareNow(project.projectReference(),changedSelection,ignored->{}));
return new AutomationOutcome(AutomationOutcome.Kind.SUCCEEDED,0,0,List.of(),null);
});
changeOperation.completion().toCompletableFuture().get(10,TimeUnit.SECONDS);changeOperation.termination().toCompletableFuture().get(10,TimeUnit.SECONDS);
assertFalse(result.get().success());assertTrue(result.get().diagnostics().stream().anyMatch(m->m.contains("Consumed source changed")),result.get().diagnostics().toString());
assertFalse(Files.exists(root.resolve(".studio/test-builds/life").resolve(changedSelection.buildId())));
assertArrayEquals(manifest,Files.readAllBytes(before.buildResult().manifestPath()));
}
@Test void packagedLifeExamplesCompileBothTargetsWithLogSupportAbsentFromProduction()throws Exception {
project.close();Path copy=root.resolve("packaged-example");Files.createDirectories(copy);
String prefix="pbs:example:game:1:isolated-tests/";int files=0;
for(var reference:p.studio.compiler.FrontendRegistryService.require("pbs").documentation().orElseThrow().references(1,p.studio.AppMode.Game)) {
if(!reference.id().startsWith(prefix))continue;
Path destination=copy.resolve(reference.id().substring(prefix.length()));Files.createDirectories(destination.getParent());Files.writeString(destination,reference.text());files++;
}
assertTrue(files>=10,"Packaged isolated test example is missing");root=copy.toRealPath();
project=app.getBean(ProjectSessionFactory.class).open(app.getBean(ProjectCatalog.class).openProject(root));
project.automation().grant(false).toCompletableFuture().get(5,TimeUnit.SECONDS);task=tools.acquire(root).task().value();
byte[] barrel=Files.readAllBytes(root.resolve("src/mod.barrel"));
for(String target:List.of("life","life-fail","production")) {
var result=build("packaged-"+target,target);assertTrue(result.buildResult().success(),result.buildResult().diagnostics().toString());
var manifest=mapper.readTree(result.buildResult().manifestPath().toFile());
boolean usesLog=java.util.stream.StreamSupport.stream(manifest.path("capabilities").spliterator(),false).anyMatch(v->v.asText().equals("log"));
assertEquals(!target.equals("production"),usesLog);
assertArrayEquals(barrel,Files.readAllBytes(root.resolve("src/mod.barrel")));
}
}
p.studio.core.shipper.StudioShipperService shipperAfterCompile(java.util.function.BiConsumer<p.studio.api.project.ProjectReference,Path> after) {
var actual=app.getBean(p.studio.core.shipper.CompilerBuildGateway.class);
var wrapped=new p.studio.core.shipper.CompilerBuildGateway() {
public CompilerBuildOutput compile(p.studio.api.project.ProjectReference project,java.util.function.Consumer<String> sink){return actual.compile(project,sink);}
public CompilerBuildOutput compile(p.studio.api.project.ProjectReference project,BuildSelection selection,Path output,java.util.function.Consumer<String> sink){
var result=actual.compile(project,selection,output,sink);after.accept(project,output);return result;
}
};
return new p.studio.core.shipper.StudioShipperService(wrapped,app.getBean(p.packer.PackerWorkspaceService.class),mapper,app.getBean(p.studio.api.operation.OperationExecutor.class));
}
}