fix(pbs): exclude transient state from packaged example knowledge
Test / Tests and coverage
Intrepid/Prometeu/Studio/pipeline/head This commit looks good

Keep canonical asset identities and verify cache-independent packaging and installed references.

Work: WRK-0027. Validation: make -C tooling verify, run 20261127T004152Z-e028bb55, PASSED.
This commit is contained in:
2026-11-27 00:51:37 +00:00
parent a2494e7d70
commit 219969b9e6
6 changed files with 71 additions and 1 deletions
@@ -74,6 +74,15 @@ public final class InstalledKnowledgeProbe {
var catalog = new ProjectCatalogService(root, mapper, new ProjectLocalStudioSetupStore(mapper));
var knowledge = new CompilerProjectKnowledge(access, catalog, mapper);
var context = knowledge.context(root);
String cacheReference = "pbs:example:game:1:beacon-workshop/assets/.prometeu/cache.json";
check(context.references().stream().noneMatch(ref -> ref.id().equals(cacheReference)), "Cache must not be advertised");
try {
knowledge.readReference(root, cacheReference, 0, 100);
throw new AssertionError("Installed cache reference must not be readable");
} catch (p.studio.api.automation.AutomationException failure) {
check(failure.failure().code() == p.studio.api.automation.AutomationFailure.Code.REFERENCE_NOT_FOUND,
"Cache must fail with REFERENCE_NOT_FOUND");
}
for (var kind : java.util.List.of(ProjectKnowledge.ReferenceKind.QUICKSTART, ProjectKnowledge.ReferenceKind.SYNTAX,
ProjectKnowledge.ReferenceKind.SEMANTICS, ProjectKnowledge.ReferenceKind.EXAMPLE, ProjectKnowledge.ReferenceKind.SDK))
check(context.references().stream().anyMatch(ref -> ref.kind() == kind), "Missing " + kind);
@@ -288,10 +297,20 @@ public final class InstalledKnowledgeProbe {
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");
String prefix = "pbs-knowledge/examples/game/1/beacon-workshop/";
var connection = (java.net.JarURLConnection) location.openConnection();
try (var jar = new java.util.jar.JarFile(Path.of(connection.getJarFileURL().toURI()).toFile())) {
check(jar.stream().map(java.util.jar.JarEntry::getName).filter(name -> name.startsWith(prefix))
.noneMatch(name -> name.equals(prefix + "assets/.prometeu/cache.json") || name.contains("__pycache__/")
|| name.matches("(?:.*/)?\\.(?:asset-publish|record|animation)-.*\\.tmp")),
"Installed JAR must not carry transient example resources");
}
var mapper = new ObjectMapper();
Path root = Files.createDirectory(Path.of("beacon-workshop")).toRealPath();
var paths = new java.util.HashSet<String>();
try (var input = location.openStream()) {
for (var file : mapper.readTree(input).path("files")) {
check(paths.add(file.path("path").asText()), "Game inventory paths must be unique");
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());
@@ -304,6 +323,11 @@ public final class InstalledKnowledgeProbe {
}
}
}
check(paths.containsAll(java.util.List.of("assets/.prometeu/index.json", "assets/workshop/asset.json",
"assets/workshop/animations.studio.json", "assets/workshop/beacon_on.png",
"assets/room/scene-bank.pack-request.json")), "Canonical asset resources must remain installed");
check(!paths.contains("assets/.prometeu/cache.json"), "Inventory must exclude local cache");
check(!Files.exists(root.resolve("assets/.prometeu/cache.json")), "Installed game must start without cache");
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 -> {})) {
@@ -324,6 +348,7 @@ public final class InstalledKnowledgeProbe {
.digest(Files.readAllBytes(output.resolve("program.pbx"))))));
}
System.out.println("Installed Beacon Workshop verified: original resources, hashes, generated factories, compile and pack");
System.out.println("Installed Beacon Workshop transient exclusion verified");
}
private static int[] position(String text, String needle, int offset) {