feat(studio): deliver asset authoring and automation workflows
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:
+1
-1
@@ -62,7 +62,7 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
||||
final var parsedSourceFiles = new PbsGenericProgramService().prepare(assembly.parsedSourceFiles(), sourceContexts,
|
||||
assembly.moduleTable(), diagnostics, feSurfaceContext);
|
||||
final var importedSemanticContexts = importedSemanticContextService.build(parsedSourceFiles, assembly.moduleTable(), assembly.siblingDeclarationsByModule());
|
||||
projectLifecycleSemanticsValidator.validate(parsedSourceFiles.asList(), diagnostics);
|
||||
projectLifecycleSemanticsValidator.validate(parsedSourceFiles.asList(), diagnostics, ctx);
|
||||
final var failedModuleIds = assembly.mutableFailedModuleIds();
|
||||
final var moduleDependencyGraph = assembly.moduleDependencyGraph();
|
||||
final var canonicalModulePool = assembly.canonicalModulePool();
|
||||
|
||||
+9
@@ -12,6 +12,11 @@ final class PbsProjectLifecycleSemanticsValidator {
|
||||
void validate(
|
||||
final java.util.List<PbsParsedSourceFile> parsedSourceFiles,
|
||||
final DiagnosticSink diagnostics) {
|
||||
validate(parsedSourceFiles, diagnostics, null);
|
||||
}
|
||||
|
||||
void validate(final java.util.List<PbsParsedSourceFile> parsedSourceFiles, final DiagnosticSink diagnostics,
|
||||
final p.studio.compiler.messages.FrontendPhaseContext context) {
|
||||
final var frames = new ArrayList<PbsAst.FunctionDecl>();
|
||||
final var hooks = new java.util.EnumMap<PbsAst.LifecycleMarker, PbsAst.FunctionDecl>(PbsAst.LifecycleMarker.class);
|
||||
final var declarations = new java.util.HashSet<String>();
|
||||
@@ -45,6 +50,10 @@ final class PbsProjectLifecycleSemanticsValidator {
|
||||
}
|
||||
}
|
||||
if (functionDecl.lifecycleMarker() == PbsAst.LifecycleMarker.FRAME) {
|
||||
if (context != null && context.entrypoint() != null
|
||||
&& !context.entrypoint().equals(context.fileTable.get(parsedSource.fileId()).getCanonPath()))
|
||||
p.studio.compiler.source.diagnostics.Diagnostics.error(diagnostics, "E_SEM_TEST_TARGET_ENTRYPOINT",
|
||||
"Selected test [Frame] must belong to entrypoint " + context.entrypoint(), span);
|
||||
frames.add(functionDecl);
|
||||
}
|
||||
}
|
||||
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
# Shared glyph and scene authoring
|
||||
|
||||
Use the existing Assets workspace or the current-task `studio_assets_*` tools.
|
||||
Both call the same authoring, reference analysis, packer and publication service.
|
||||
Sound authoring and capacity qualification are deferred.
|
||||
|
||||
## Inspect, preview, publish
|
||||
|
||||
1. Obtain a fresh human grant and `studio_control_acquire`. Every tool below
|
||||
requires the current `projectRoot` and `taskId`.
|
||||
2. Query `studio_assets_catalog`, `studio_assets_inspect`,
|
||||
`studio_assets_artifacts`, `studio_assets_dependencies` and
|
||||
`studio_assets_budget`. Catalog accepts `offset` and `limit` (maximum 1024).
|
||||
3. Freeze the complete `revision` from `studio_assets_revision`. Use that exact
|
||||
object as `request.expectedRevision` in `studio_assets_preview`.
|
||||
4. Review `files` (including both hashes), affected assets, producer diagnostics,
|
||||
conflicts and `affectedReferences`. Preview stages bytes without publishing.
|
||||
5. Commit only a ready/no-op preview using `studio_assets_commit` with its
|
||||
`batchId`, exact `expectedRevision` and a fresh `clientRequestId`.
|
||||
6. Recover a lost response using `studio_assets_result`. Retry the same request
|
||||
with identical parameters; changing parameters under a request ID conflicts.
|
||||
Cancellation after the durable commit marker cannot undo publication.
|
||||
|
||||
A human uses the PNG picker to authorize an external source. A task may use a
|
||||
project-contained input with its exact SHA-256, or an opaque grant already issued
|
||||
for this project. Caller-supplied external paths are never a grant.
|
||||
|
||||
## Create a glyph bank from an existing project PNG
|
||||
|
||||
The following is the `request` body for `studio_assets_preview`. Replace `REVISION`
|
||||
with the queried object and `PNG_SHA256` with the exact bytes of `art/red.png`.
|
||||
The placeholders are instructional; they are not valid submitted values.
|
||||
|
||||
```json
|
||||
{
|
||||
"expectedRevision": "REVISION",
|
||||
"mutations": [
|
||||
{"kind":"create","changeId":"bank","relativeRoot":"sprites","name":"sprites","family":"GLYPH_BANK","outputFormat":"GLYPH_INDEXED_V1","outputCodec":"NONE","preload":true},
|
||||
{"kind":"update_contract","changeId":"geometry","bank":"asset:root:sprites","preload":true,"outputCodec":"NONE","codecFields":{},"metadataFields":{"tile_size":"16x16"}},
|
||||
{"kind":"import","changeId":"source","source":{"projectRelativePath":"art/red.png","externalGrantId":null,"sha256":"PNG_SHA256"},"bank":"asset:root:sprites","destination":"red.png"},
|
||||
{"kind":"compose_palettes","changeId":"palette","bank":"asset:root:sprites","palettes":[{"index":0,"rgba8888":[4278190335]}]},
|
||||
{"kind":"compose_bank","changeId":"selection","bank":"asset:root:sprites","selectedPaths":["red.png"]}
|
||||
],
|
||||
"rebinds": [],
|
||||
"ownership": []
|
||||
}
|
||||
```
|
||||
|
||||
After publication, query the assigned asset identity and its artifacts. Subsequent
|
||||
requests should use those returned identities. Importing identical bytes is a
|
||||
no-op; appending selected paths retains earlier identities and indices. Reorder,
|
||||
removal, content/size and layout changes require reference analysis. A rejected
|
||||
preview lists the exact animation/scene/metadata uses. Query
|
||||
`studio_assets_artifacts` with its `batchId` to inspect candidate targets, then
|
||||
submit a fresh preview request with explicit `rebinds` covering every affected use.
|
||||
Targets remain stable across amended previews. No automatic rebind is inferred.
|
||||
|
||||
## Compose a scene
|
||||
|
||||
Create a `SCENE_BANK` with `outputFormat: "SCENE_TILED_V1"`. A `compose_scene`
|
||||
mutation supplies exactly four layers. An active layer names its glyph bank,
|
||||
tileSize, nonnegative parallax factors, width/height and exactly width*height
|
||||
tiles. Active tiles name the stable `{bank, artifactId}` returned by the artifact
|
||||
query, plus `paletteId`, `flipX` and `flipY`. Inactive tiles use `artifact: null`.
|
||||
Inactive layers remain present. The shared scene service emits the canonical
|
||||
request; callers never write the packer request file or invent glyph indices.
|
||||
A draft scene may exist without accepted composition, but its missing canonical
|
||||
request still blocks cartridge publication.
|
||||
|
||||
## Read the correct budget
|
||||
|
||||
Per-bank glyph content and global residency are separate. For each bank type,
|
||||
inspect existing banks, declared build selection, effective final preloads (with
|
||||
actual slots and dependencies), and potential dynamic banks. Scene layers and
|
||||
logical maps do not allocate another bank. A scene's cold glyph dependencies must
|
||||
be in the pack set; they do not become automatic preloads.
|
||||
|
||||
The shipped macOS arm64 profile qualifies 16 glyph and 16 scene preloads with
|
||||
actual 16/17 process evidence and exact dispatcher/headless/desktop hashes.
|
||||
Unknown or changed executables never inherit these limits from a version string.
|
||||
Known excess fails before replacing the previous cartridge. Potential dynamic
|
||||
excess is a warning, not proof of simultaneous residency. Unqualified builds may
|
||||
be inspected, but managed headless/desktop starts require a matching known profile
|
||||
and unchanged qualified cartridge bytes. Sound has no published limit here.
|
||||
|
||||
## Declare ownership without executing a generator
|
||||
|
||||
`ownership` entries name owner, an existing project-relative `outputPath`, a
|
||||
human-readable producer, dependency bank identities and `stale`. Query the graph
|
||||
with `studio_assets_dependencies`. Changes to dependency/output hashes mark an
|
||||
output stale. This declaration never runs scripts, generators or transitive
|
||||
regeneration. Regeneration requires explicit internal authoring mutations and a
|
||||
new reviewed batch.
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
# Isolated guest test targets
|
||||
|
||||
This independent fixture demonstrates production, life and deliberately failing
|
||||
life-fail selections without editing production sources or barrels. Support under
|
||||
tests/support is included only by the declared targets. Assertions call existing
|
||||
public life functions with ordinary PBS module visibility.
|
||||
|
||||
The host structured-test service requires negotiated headless protocol 1.2
|
||||
log_read. Capability absence must refuse the run before guest execution. Production
|
||||
build/Play remains independent. Use explicit memory_fresh media; this fixture has
|
||||
no save image or durability claim. Cartridges without memcard_slots have no card
|
||||
namespace or boot media choice; the fresh owned process supplies fresh RAM.
|
||||
|
||||
Events are emitted across three frames using sdk/log tag 41000. The helper chooses
|
||||
between complete versioned JSON literals for a boolean predicate. expected/actual
|
||||
are the predicate booleans, not an invented numeric health observation. Numeric or
|
||||
other optional details may be omitted; the host retains their availability. Every
|
||||
assertion has a distinct eventId, name and message. No runtime string formatter,
|
||||
private access or extra machine budget is assumed.
|
||||
|
||||
A pass requires both declared cases, an assertion, explicit suite completion and
|
||||
no false assertion, native fault, invalid event or log loss. life-fail deliberately
|
||||
checks health against eight after subtracting three from ten; it must report a
|
||||
failed assertion while still completing both cases and the suite. A fault or an
|
||||
empty/incomplete transcript is never an assertion pass.
|
||||
|
||||
Use an explicit targetId with studio_build_start. Test artifacts belong to
|
||||
.studio/test-builds/<targetId>/<buildId>/; production keeps build/. A lost response
|
||||
is recovered by request/operation lookup, without replaying guest advancement.
|
||||
|
||||
## Run through Studio
|
||||
|
||||
Open the project Tests workspace, select life or life-fail, Fresh RAM and explicit
|
||||
frame/time bounds, then Run tests. The same service is available through MCP:
|
||||
|
||||
1. After a human grant, acquire the task and call studio_tests_targets.
|
||||
2. Call studio_tests_start with a unique clientRequestId and the request below.
|
||||
3. Poll studio_tests_get by the original request/operation identity until
|
||||
workerTerminated. SUCCEEDED is worker completion; inspect result.verdict for
|
||||
the test verdict. A deliberately false assertion completes with failed.
|
||||
4. Read studio_tests_transcript in bounded pages. Queries never advance the guest.
|
||||
Recover a lost start response with the original identity, without a new run.
|
||||
|
||||
```json
|
||||
{
|
||||
"targetId": "life",
|
||||
"maxFrames": 120,
|
||||
"blockFrames": 1,
|
||||
"timeoutMs": 30000,
|
||||
"media": "memory_fresh",
|
||||
"reopenRunId": null,
|
||||
"discardUnsaved": false
|
||||
}
|
||||
```
|
||||
|
||||
Each unique event payload has a contiguous zero-based ordinal. suite_end includes
|
||||
eventCount, counting every unique event including itself. Duplicate identical
|
||||
events are idempotent; missing producer events are failures even when native
|
||||
sequences have no gap. Each complete encoded literal fits 256 UTF-8 bytes and the
|
||||
example emits at most three events/frame, within the unchanged ten-message app
|
||||
budget. Ordinary application logs consume the same budget. Historical native
|
||||
overflow alone is informational; unread gaps and continuity failures reject a run.
|
||||
|
||||
## Disposable persistence tests
|
||||
|
||||
A project declaring memcard_slots may explicitly use disposable_create. The
|
||||
service creates its image under .studio/test-runs/<runId>/ and retains the run's
|
||||
media descriptor/result. For a distinct reader target use disposable_reopen and
|
||||
the creating run's ID as reopenRunId. The writer process must close before the
|
||||
reader opens the same image in a new process. Assert readback through the game's
|
||||
existing public API; commit acceptance alone does not establish readback.
|
||||
|
||||
The service never selects the configured/personal image. A native dirty or
|
||||
pending-data refusal remains visible with runtimeRetained=true; choose an explicit
|
||||
studio_tests_shutdown discard policy to recover. A failed advance, including
|
||||
zero completed frames, is not automatically replayed. Keep its native cause and
|
||||
inspect the original result before any intentional further action. The life
|
||||
fixture does not test persistence; it makes no save/durability claim.
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"name": "isolatedtests",
|
||||
"version": "1.0.0",
|
||||
"language": "pbs",
|
||||
"stdlib": "1",
|
||||
"target": "Game",
|
||||
"app_id": 470396923,
|
||||
"dependencies": [],
|
||||
"testTargets": {
|
||||
"schemaVersion": 1,
|
||||
"targets": [
|
||||
{
|
||||
"id": "life",
|
||||
"entrypoint": "tests/life/main.pbs",
|
||||
"sourceRoots": [
|
||||
"src",
|
||||
"tests/life"
|
||||
],
|
||||
"supportRoots": [
|
||||
"tests/support"
|
||||
],
|
||||
"exclusions": [
|
||||
"src/main.pbs"
|
||||
],
|
||||
"cases": [
|
||||
"damage",
|
||||
"heal"
|
||||
],
|
||||
"logTag": 41000
|
||||
},
|
||||
{
|
||||
"id": "life-fail",
|
||||
"entrypoint": "tests/life-fail/main.pbs",
|
||||
"sourceRoots": [
|
||||
"src",
|
||||
"tests/life-fail"
|
||||
],
|
||||
"supportRoots": [
|
||||
"tests/support"
|
||||
],
|
||||
"exclusions": [
|
||||
"src/main.pbs"
|
||||
],
|
||||
"cases": [
|
||||
"damage",
|
||||
"heal"
|
||||
],
|
||||
"logTag": 41000
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
declare global health: int = 10;
|
||||
|
||||
fn damage(amount: int) -> void { health = health - amount; }
|
||||
fn heal(amount: int) -> void {
|
||||
health = health + amount;
|
||||
if (health > 10) { health = 10; }
|
||||
}
|
||||
fn current() -> int { return health; }
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
pub fn damage(amount: int) -> void;
|
||||
pub fn heal(amount: int) -> void;
|
||||
pub fn current() -> int;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
[Frame]
|
||||
fn frame() -> void {}
|
||||
+1
@@ -0,0 +1 @@
|
||||
pub fn frame() -> void;
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
import { damage, heal, current } from @isolatedtests:life;
|
||||
import { emit_event, assert_true } from @isolatedtests:assertions;
|
||||
|
||||
declare global phase: int = 0;
|
||||
|
||||
[Frame]
|
||||
fn frame() -> void {
|
||||
if (phase == 0) {
|
||||
emit_event(41000, "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":null,\"eventId\":\"suite.start\",\"kind\":\"suite_start\",\"payload\":{\"ordinal\":0}}");
|
||||
emit_event(41000, "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":\"damage\",\"eventId\":\"damage.start\",\"kind\":\"case_start\",\"payload\":{\"ordinal\":1}}");
|
||||
damage(3);
|
||||
phase = 1;
|
||||
} else {
|
||||
if (phase == 1) {
|
||||
assert_true(41000, current() == 8, "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":\"damage\",\"eventId\":\"damage.assert\",\"kind\":\"assertion\",\"payload\":{\"name\":\"damage predicate\",\"message\":\"Public health predicate\",\"expected\":true,\"actual\":true,\"passed\":true,\"ordinal\":2}}", "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":\"damage\",\"eventId\":\"damage.assert\",\"kind\":\"assertion\",\"payload\":{\"name\":\"damage predicate\",\"message\":\"Public health predicate\",\"expected\":true,\"actual\":false,\"passed\":false,\"ordinal\":2}}");
|
||||
emit_event(41000, "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":\"damage\",\"eventId\":\"damage.end\",\"kind\":\"case_end\",\"payload\":{\"ordinal\":3}}");
|
||||
emit_event(41000, "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":\"heal\",\"eventId\":\"heal.start\",\"kind\":\"case_start\",\"payload\":{\"ordinal\":4}}");
|
||||
heal(99);
|
||||
phase = 2;
|
||||
} else {
|
||||
if (phase == 2) {
|
||||
assert_true(41000, current() == 10, "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":\"heal\",\"eventId\":\"heal.assert\",\"kind\":\"assertion\",\"payload\":{\"name\":\"heal predicate\",\"message\":\"Public health predicate\",\"expected\":true,\"actual\":true,\"passed\":true,\"ordinal\":5}}", "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":\"heal\",\"eventId\":\"heal.assert\",\"kind\":\"assertion\",\"payload\":{\"name\":\"heal predicate\",\"message\":\"Public health predicate\",\"expected\":true,\"actual\":false,\"passed\":false,\"ordinal\":5}}");
|
||||
emit_event(41000, "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":\"heal\",\"eventId\":\"heal.end\",\"kind\":\"case_end\",\"payload\":{\"ordinal\":6}}");
|
||||
emit_event(41000, "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":null,\"eventId\":\"suite.end\",\"kind\":\"suite_end\",\"payload\":{\"ordinal\":7,\"eventCount\":8}}");
|
||||
phase = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
import { damage, heal, current } from @isolatedtests:life;
|
||||
import { emit_event, assert_true } from @isolatedtests:assertions;
|
||||
|
||||
declare global phase: int = 0;
|
||||
|
||||
[Frame]
|
||||
fn frame() -> void {
|
||||
if (phase == 0) {
|
||||
emit_event(41000, "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":null,\"eventId\":\"suite.start\",\"kind\":\"suite_start\",\"payload\":{\"ordinal\":0}}");
|
||||
emit_event(41000, "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":\"damage\",\"eventId\":\"damage.start\",\"kind\":\"case_start\",\"payload\":{\"ordinal\":1}}");
|
||||
damage(3);
|
||||
phase = 1;
|
||||
} else {
|
||||
if (phase == 1) {
|
||||
assert_true(41000, current() == 7, "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":\"damage\",\"eventId\":\"damage.assert\",\"kind\":\"assertion\",\"payload\":{\"name\":\"damage predicate\",\"message\":\"Public health predicate\",\"expected\":true,\"actual\":true,\"passed\":true,\"ordinal\":2}}", "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":\"damage\",\"eventId\":\"damage.assert\",\"kind\":\"assertion\",\"payload\":{\"name\":\"damage predicate\",\"message\":\"Public health predicate\",\"expected\":true,\"actual\":false,\"passed\":false,\"ordinal\":2}}");
|
||||
emit_event(41000, "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":\"damage\",\"eventId\":\"damage.end\",\"kind\":\"case_end\",\"payload\":{\"ordinal\":3}}");
|
||||
emit_event(41000, "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":\"heal\",\"eventId\":\"heal.start\",\"kind\":\"case_start\",\"payload\":{\"ordinal\":4}}");
|
||||
heal(99);
|
||||
phase = 2;
|
||||
} else {
|
||||
if (phase == 2) {
|
||||
assert_true(41000, current() == 10, "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":\"heal\",\"eventId\":\"heal.assert\",\"kind\":\"assertion\",\"payload\":{\"name\":\"heal predicate\",\"message\":\"Public health predicate\",\"expected\":true,\"actual\":true,\"passed\":true,\"ordinal\":5}}", "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":\"heal\",\"eventId\":\"heal.assert\",\"kind\":\"assertion\",\"payload\":{\"name\":\"heal predicate\",\"message\":\"Public health predicate\",\"expected\":true,\"actual\":false,\"passed\":false,\"ordinal\":5}}");
|
||||
emit_event(41000, "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":\"heal\",\"eventId\":\"heal.end\",\"kind\":\"case_end\",\"payload\":{\"ordinal\":6}}");
|
||||
emit_event(41000, "{\"schemaVersion\":1,\"suiteId\":\"life\",\"caseId\":null,\"eventId\":\"suite.end\",\"kind\":\"suite_end\",\"payload\":{\"ordinal\":7,\"eventCount\":8}}");
|
||||
phase = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import { Log } from @sdk:log;
|
||||
|
||||
// Callers supply complete versioned JSON literals; no runtime string formatter is assumed.
|
||||
fn emit_event(tag: int, json: str) -> void { Log.info(tag, json); }
|
||||
fn assert_true(tag: int, condition: bool, passed_json: str, failed_json: str) -> void {
|
||||
if (condition) { Log.info(tag, passed_json); }
|
||||
else { Log.info(tag, failed_json); }
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
pub fn emit_event(tag: int, json: str) -> void;
|
||||
pub fn assert_true(tag: int, condition: bool, passed_json: str, failed_json: str) -> void;
|
||||
+11
-1
@@ -6,7 +6,15 @@ public record BuilderPipelineConfig(
|
||||
boolean explain,
|
||||
String rootProjectPath,
|
||||
String vmProfile,
|
||||
SourceProviderFactory sourceProviderFactory) {
|
||||
SourceProviderFactory sourceProviderFactory,
|
||||
String buildTargetId,
|
||||
java.nio.file.Path outputDirectory) {
|
||||
public BuilderPipelineConfig(boolean explain, String rootProjectPath, String vmProfile, SourceProviderFactory factory, String buildTargetId) {
|
||||
this(explain, rootProjectPath, vmProfile, factory, buildTargetId, null);
|
||||
}
|
||||
public BuilderPipelineConfig(boolean explain, String rootProjectPath, String vmProfile, SourceProviderFactory factory) {
|
||||
this(explain, rootProjectPath, vmProfile, factory, "production", null);
|
||||
}
|
||||
|
||||
public BuilderPipelineConfig(
|
||||
final boolean explain,
|
||||
@@ -22,6 +30,8 @@ public record BuilderPipelineConfig(
|
||||
}
|
||||
|
||||
public BuilderPipelineConfig {
|
||||
buildTargetId = buildTargetId == null ? "production" : buildTargetId;
|
||||
if (!buildTargetId.matches("[A-Za-z0-9][A-Za-z0-9_.-]{0,127}")) throw new IllegalArgumentException("Invalid build target ID");
|
||||
vmProfile = vmProfile == null || vmProfile.isBlank() ? "core-v1" : vmProfile;
|
||||
sourceProviderFactory = sourceProviderFactory == null ? SourceProviderFactory.filesystem() : sourceProviderFactory;
|
||||
}
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ public class FrontendPhasePipelineStage implements PipelineStage {
|
||||
ctx.resolvedWorkspace.stdlib(),
|
||||
ctx.resolvedWorkspace.target(),
|
||||
p.studio.compiler.messages.HostAdmissionContext.permissiveDefault(),
|
||||
surface);
|
||||
surface, ctx.resolvedWorkspace.buildTargetId(), ctx.resolvedWorkspace.mainProject().getEntrypoint());
|
||||
final var diagnostics = DiagnosticSink.empty();
|
||||
ctx.irBackend = provider.compiler().compile(frontendPhaseContext, diagnostics, logs, issues);
|
||||
adaptDiagnostics(diagnostics, issues);
|
||||
|
||||
+19
-1
@@ -37,6 +37,7 @@ public class LoadSourcesPipelineStage implements PipelineStage {
|
||||
logs.using(log).debug("Project [ " + pd.getName() + " ] source loading...");
|
||||
|
||||
final var allowedExtensions = normalize(ctx.resolvedWorkspace.frontendSpec().getAllowedExtensions());
|
||||
final var selectedFiles = new java.util.TreeSet<Path>();
|
||||
// Iterates source roots; crawls files; registers them
|
||||
for (final var sourceRootPath : pd.getSourceRoots()) {
|
||||
logs.using(log).debug("Walking source root [ " + sourceRootPath + " ]");
|
||||
@@ -54,8 +55,25 @@ public class LoadSourcesPipelineStage implements PipelineStage {
|
||||
.exception(e));
|
||||
}
|
||||
|
||||
registerFiles(pId, pd, paths, ctx, logs, issues);
|
||||
selectedFiles.addAll(paths);
|
||||
}
|
||||
if (pd.getTestTarget() != null) {
|
||||
for (var exclusion : pd.getTestTarget().exclusions()) {
|
||||
final Path declared = pd.getRootPath().resolve(exclusion);
|
||||
try {
|
||||
if (!selectedFiles.contains(declared.toRealPath()))
|
||||
issues.report(b -> b.error(true).code("TEST_TARGET_EXCLUSION_INVALID")
|
||||
.message("Exact test exclusion is not an eligible selected source: " + declared));
|
||||
} catch (IOException failure) {
|
||||
issues.report(b -> b.error(true).code("TEST_TARGET_EXCLUSION_INVALID").message("Missing exact test exclusion: " + declared));
|
||||
}
|
||||
}
|
||||
}
|
||||
selectedFiles.removeIf(path -> pd.getExcludedSources().asList().contains(path)
|
||||
|| pd.getExcludedSourceRoots().stream().anyMatch(path::startsWith));
|
||||
if (pd.getEntrypoint() != null && !selectedFiles.contains(pd.getEntrypoint()))
|
||||
issues.report(b -> b.error(true).code("TEST_TARGET_ENTRYPOINT_INVALID").message("Selected entrypoint was not admitted: " + pd.getEntrypoint()));
|
||||
registerFiles(pId, pd, new ArrayList<>(selectedFiles), ctx, logs, issues);
|
||||
}
|
||||
|
||||
private static void registerFiles(
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ public class ResolveDepsPipelineStage implements PipelineStage {
|
||||
.message("[BUILD]: root project directory no found: " + ctx.config.rootProjectPath())
|
||||
.exception(e));
|
||||
}
|
||||
final var dependencyConfig = new DependencyConfig(ctx.config.explain(), ctx.rootProjectPathCanon);
|
||||
final var dependencyConfig = new DependencyConfig(ctx.config.explain(), ctx.rootProjectPathCanon, ctx.config.buildTargetId());
|
||||
ctx.resolvedWorkspace = DependencyService.INSTANCE.run(dependencyConfig, logs);
|
||||
ctx.fileTable = new FileTable(ctx.resolvedWorkspace.graph().projectTable().size());
|
||||
return BuildingIssueSink.empty();
|
||||
|
||||
+11
-3
@@ -38,15 +38,23 @@ public class WriteBytecodeArtifactPipelineStage implements PipelineStage {
|
||||
.message("[BUILD]: bytecode bytes are missing before WriteBytecodeArtifact stage"));
|
||||
}
|
||||
|
||||
final var outputDir = ctx.rootProjectPathCanon.resolve(OUTPUT_DIR);
|
||||
if (!"production".equals(ctx.config.buildTargetId()) && ctx.config.outputDirectory() == null)
|
||||
return BuildingIssueSink.empty().report(b -> b.error(true).code("TEST_TARGET_OUTPUT_REQUIRED")
|
||||
.message("Test builds require an exclusive target/build output directory"));
|
||||
final var outputDir = ctx.config.outputDirectory() == null ? ctx.rootProjectPathCanon.resolve(OUTPUT_DIR)
|
||||
: ctx.config.outputDirectory().toAbsolutePath().normalize();
|
||||
final var outputPath = outputDir.resolve(OUTPUT_FILE);
|
||||
try {
|
||||
var existingParent = outputDir;
|
||||
while (existingParent != null && !Files.exists(existingParent, java.nio.file.LinkOption.NOFOLLOW_LINKS)) existingParent = existingParent.getParent();
|
||||
if (existingParent == null || !existingParent.toRealPath().startsWith(ctx.rootProjectPathCanon.toRealPath())) throw new IOException("Build output escapes the project");
|
||||
Files.createDirectories(outputDir);
|
||||
if (!outputDir.toRealPath().startsWith(ctx.rootProjectPathCanon.toRealPath())) throw new IOException("Build output escapes the project");
|
||||
Files.write(
|
||||
outputPath,
|
||||
bytes,
|
||||
StandardOpenOption.CREATE,
|
||||
StandardOpenOption.TRUNCATE_EXISTING,
|
||||
"production".equals(ctx.config.buildTargetId()) ? StandardOpenOption.CREATE : StandardOpenOption.CREATE_NEW,
|
||||
"production".equals(ctx.config.buildTargetId()) ? StandardOpenOption.TRUNCATE_EXISTING : StandardOpenOption.WRITE,
|
||||
StandardOpenOption.WRITE);
|
||||
ctx.bytecodeArtifactPath = outputPath;
|
||||
logs.using(log).info("[BUILD]: wrote bytecode artifact to " + outputPath);
|
||||
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package p.studio.compiler.workspaces;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import p.studio.compiler.messages.*;
|
||||
import p.studio.compiler.models.*;
|
||||
import p.studio.compiler.utilities.SourceProviderFactory;
|
||||
import p.studio.utilities.logs.LogAggregator;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class IsolatedBuildTargetsTest {
|
||||
@TempDir Path root;
|
||||
@BeforeEach void fixture()throws Exception {
|
||||
root=root.toRealPath();
|
||||
write("prometeu.json","""
|
||||
{"name":"fixture","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":["tests/support"],"exclusions":["src/main.pbs"],"cases":["health"],"logTag":41000},
|
||||
{"id":"shop-save","entrypoint":"tests/shop/main.pbs","sourceRoots":["src","tests/shop"],"supportRoots":["tests/support"],"exclusions":["src/main.pbs"],"cases":["save"],"logTag":41001}]}}
|
||||
""");
|
||||
write("src/main.pbs","[Frame] fn frame() -> void {}\n");
|
||||
write("src/mod.barrel","pub fn frame() -> void;\n");
|
||||
write("src/domain/main.pbs","fn alive() -> bool { return true; }\n");
|
||||
write("src/domain/mod.barrel","pub fn alive() -> bool;\n");
|
||||
write("tests/life/main.pbs","import { alive } from @fixture:domain; import { check } from @fixture:assert; [Frame] fn frame() -> void { let health: bool = check(alive()); }\n");
|
||||
write("tests/shop/main.pbs","import { alive } from @fixture:domain; import { check } from @fixture:assert; [Frame] fn frame() -> void { let saved: bool = check(alive()); }\n");
|
||||
write("tests/support/assert/main.pbs","fn check(value: bool) -> bool { return value; }\n");
|
||||
write("tests/support/assert/mod.barrel","pub fn check(value: bool) -> bool;\n");
|
||||
}
|
||||
BuilderPipelineContext context(String target) {
|
||||
return BuilderPipelineContext.fromConfig(new BuilderPipelineConfig(false,root.toString(),"core-v1",SourceProviderFactory.filesystem(),target));
|
||||
}
|
||||
@Test void twoTargetsAndDefaultProductionUseSameResolverWithoutChangingSourcesOrMachineIdentity()throws Exception {
|
||||
var before=hashes();
|
||||
for(var target:List.of("life","shop-save","production")) {
|
||||
var ctx=context(target);p.studio.compiler.models.CompileResult compiled;
|
||||
try {compiled=BuilderPipelineService.INSTANCE.compile(ctx,LogAggregator.empty());}
|
||||
catch(p.studio.compiler.exceptions.BuildException failure){throw new AssertionError(target+": "+failure.getDiagnostics().stream().map(i->i.getCode()+": "+i.getMessage()).toList(),failure);}
|
||||
assertTrue(compiled.diagnostics().stream().noneMatch(BuildingIssue::isError),compiled.diagnostics().toString());
|
||||
assertEquals(target,ctx.resolvedWorkspace.buildTargetId());assertEquals(p.studio.AppMode.Game,ctx.resolvedWorkspace.target());
|
||||
var paths=paths(ctx);assertTrue(paths.contains("src/domain/main.pbs"));assertTrue(paths.contains("src/mod.barrel"));
|
||||
if(target.equals("production")) {
|
||||
assertTrue(paths.contains("src/main.pbs"));assertTrue(paths.stream().noneMatch(p->p.startsWith("tests/")));assertNull(ctx.resolvedWorkspace.mainProject().getEntrypoint());
|
||||
}else {
|
||||
assertFalse(paths.contains("src/main.pbs"));assertTrue(paths.contains("tests/support/assert/main.pbs"));
|
||||
assertTrue(paths.contains(target.equals("life")?"tests/life/main.pbs":"tests/shop/main.pbs"));
|
||||
assertFalse(paths.contains(target.equals("life")?"tests/shop/main.pbs":"tests/life/main.pbs"));
|
||||
assertEquals(root.resolve(target.equals("life")?"tests/life/main.pbs":"tests/shop/main.pbs"),ctx.resolvedWorkspace.mainProject().getEntrypoint());
|
||||
}
|
||||
assertEquals(before,hashes());
|
||||
}
|
||||
var omitted=BuilderPipelineContext.fromConfig(new BuilderPipelineConfig(false,root.toString()));
|
||||
BuilderPipelineService.INSTANCE.compile(omitted,LogAggregator.empty());assertEquals("production",omitted.resolvedWorkspace.buildTargetId());
|
||||
assertFalse(Files.exists(root.resolve("build")),"Compile-only target validation must not publish output");
|
||||
}
|
||||
@Test void includedBadSourceIsDiagnosedAtItsOriginalPathAndDoesNotAffectSiblingOrProduction()throws Exception {
|
||||
write("tests/life/bad.pbs","fn broken( this is invalid\n");var before=hashes();var ctx=context("life");
|
||||
var analysis=BuilderPipelineService.INSTANCE.analyze(ctx,LogAggregator.empty());
|
||||
assertTrue(analysis.diagnostics().stream().anyMatch(BuildingIssue::isError));
|
||||
assertTrue(analysis.diagnostics().stream().filter(i->i.getFileId()!=null)
|
||||
.anyMatch(i->ctx.fileTable.get(new p.studio.compiler.source.identifiers.FileId(i.getFileId())).getCanonPath().equals(root.resolve("tests/life/bad.pbs"))));
|
||||
assertEquals(before,hashes());
|
||||
assertDoesNotThrow(()->BuilderPipelineService.INSTANCE.compile(context("shop-save"),LogAggregator.empty()));
|
||||
assertDoesNotThrow(()->BuilderPipelineService.INSTANCE.compile(context("production"),LogAggregator.empty()));
|
||||
}
|
||||
@Test void selectedEntrypointOwnsFrameAndOrdinaryModuleVisibilityStillApplies()throws Exception {
|
||||
write("tests/life/main.pbs","fn helper() -> void {}\n");write("tests/life/driver.pbs","[Frame] fn frame() -> void {}\n");
|
||||
var invalid=BuilderPipelineService.INSTANCE.analyze(context("life"),LogAggregator.empty());
|
||||
assertTrue(invalid.diagnostics().stream().anyMatch(i->i.getCode().equals("E_SEM_TEST_TARGET_ENTRYPOINT")));
|
||||
Files.delete(root.resolve("tests/life/driver.pbs"));
|
||||
write("src/private/main.pbs","fn secret() -> int { return 42; }\n");write("src/private/mod.barrel","");
|
||||
write("tests/life/main.pbs","import { secret } from @fixture:private; [Frame] fn frame() -> void { let value: int = secret(); }\n");
|
||||
assertTrue(BuilderPipelineService.INSTANCE.analyze(context("life"),LogAggregator.empty()).diagnostics().stream().anyMatch(BuildingIssue::isError));
|
||||
}
|
||||
@Test void exactExclusionsAndCanonicalSourceScopeAreValidatedBeforeCompiling()throws Exception {
|
||||
assertThrows(p.studio.compiler.exceptions.BuildException.class,()->BuilderPipelineService.INSTANCE.compile(context("missing"),LogAggregator.empty()));
|
||||
var manifest=Files.readString(root.resolve("prometeu.json"));
|
||||
write("prometeu.json",manifest.replace("\"exclusions\":[\"src/main.pbs\"]","\"exclusions\":[\"src/missing.pbs\"]"));
|
||||
assertThrows(p.studio.compiler.exceptions.BuildException.class,()->BuilderPipelineService.INSTANCE.compile(context("life"),LogAggregator.empty()));
|
||||
write("prometeu.json",manifest.replace("\"sourceRoots\":[\"src\",\"tests/life\"]","\"sourceRoots\":[\"src\",\"tests/escape\"]"));
|
||||
Path external=Files.createTempDirectory("outside-target-");
|
||||
try {Files.createSymbolicLink(root.resolve("tests/escape"),external);
|
||||
assertThrows(p.studio.compiler.exceptions.BuildException.class,()->BuilderPipelineService.INSTANCE.compile(context("life"),LogAggregator.empty()));
|
||||
}finally{Files.deleteIfExists(external);}
|
||||
}
|
||||
void write(String path,String text)throws Exception {var file=root.resolve(path);Files.createDirectories(file.getParent());Files.writeString(file,text);}
|
||||
Set<String> paths(BuilderPipelineContext ctx) {
|
||||
var result=new HashSet<String>();for(var file:ctx.fileTable.values())if(file.getCanonPath().startsWith(root))result.add(root.relativize(file.getCanonPath()).toString());return result;
|
||||
}
|
||||
Map<String,String> hashes()throws Exception {
|
||||
var result=new TreeMap<String,String>();try(var files=Files.walk(root)) {for(var f:files.filter(Files::isRegularFile).toList())result.put(root.relativize(f).toString(),HexFormat.of().formatHex(java.security.MessageDigest.getInstance("SHA-256").digest(Files.readAllBytes(f))));}return result;
|
||||
}
|
||||
}
|
||||
+9
@@ -16,5 +16,14 @@ public final class ProjectDescriptor {
|
||||
private final AppMode target; // project target (Game or System)
|
||||
private final ReadOnlyList<Path> sourceRoots; // source roots canon paths for the project
|
||||
@Builder.Default
|
||||
private final String buildTargetId = "production";
|
||||
private final TestTargets.Target testTarget;
|
||||
private final Path entrypoint;
|
||||
private final String manifestSha256;
|
||||
@Builder.Default
|
||||
private final ReadOnlyList<Path> excludedSources = ReadOnlyList.empty();
|
||||
@Builder.Default
|
||||
private final ReadOnlyList<Path> excludedSourceRoots = ReadOnlyList.empty();
|
||||
@Builder.Default
|
||||
private final SourceKind sourceKind = SourceKind.PROJECT;
|
||||
}
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
/** Versioned project declarations; selection does not change AppMode or project identity. */
|
||||
public record TestTargets(int schemaVersion, List<Target> targets) {
|
||||
public TestTargets {
|
||||
if (schemaVersion != 1) throw new IllegalArgumentException("testTargets.schemaVersion must be 1");
|
||||
targets = List.copyOf(targets);
|
||||
if (targets.stream().map(Target::id).distinct().count() != targets.size()) throw new IllegalArgumentException("Duplicate test target ID");
|
||||
}
|
||||
public static TestTargets empty() { return new TestTargets(1, List.of()); }
|
||||
public Optional<Target> find(String id) { return targets.stream().filter(t -> t.id().equals(id)).findFirst(); }
|
||||
public record Target(String id, String entrypoint, List<String> sourceRoots, List<String> supportRoots,
|
||||
List<String> exclusions, List<String> cases, int logTag) {
|
||||
public Target {
|
||||
if (id == null || !id.matches("[A-Za-z0-9][A-Za-z0-9_.-]{0,127}") || id.equals("production"))
|
||||
throw new IllegalArgumentException("Invalid or reserved test target ID");
|
||||
path(entrypoint);sourceRoots = paths(sourceRoots);supportRoots = paths(supportRoots);exclusions = paths(exclusions);
|
||||
cases = List.copyOf(cases);
|
||||
if (sourceRoots.isEmpty() || exclusions.contains(entrypoint) || logTag < 0 || logTag > 65535
|
||||
|| new HashSet<>(cases).size() != cases.size() || cases.stream().anyMatch(c -> !c.matches("[A-Za-z0-9][A-Za-z0-9_.-]{0,127}")))
|
||||
throw new IllegalArgumentException("Invalid test target sources, cases or logTag");
|
||||
}
|
||||
private static List<String> paths(List<String> paths) {
|
||||
paths = List.copyOf(paths);paths.forEach(Target::path);
|
||||
if (new HashSet<>(paths).size() != paths.size()) throw new IllegalArgumentException("Duplicate test target path"); return paths;
|
||||
}
|
||||
private static void path(String value) {
|
||||
Objects.requireNonNull(value);var path = Path.of(value);
|
||||
if (value.isBlank() || path.isAbsolute() || path.normalize().startsWith("..") || value.equals(".")
|
||||
|| value.contains("\\") || !path.normalize().toString().equals(value)) throw new IllegalArgumentException("Expected normalized project-relative target path");
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -13,7 +13,8 @@ public record PrometeuManifestDTO(
|
||||
String target,
|
||||
List<DependencyDeclaration> dependencies,
|
||||
@JsonProperty("app_id") com.fasterxml.jackson.databind.JsonNode appId,
|
||||
@JsonProperty("memcard_slots") com.fasterxml.jackson.databind.JsonNode memcardSlots) {
|
||||
@JsonProperty("memcard_slots") com.fasterxml.jackson.databind.JsonNode memcardSlots,
|
||||
com.fasterxml.jackson.databind.JsonNode testTargets) {
|
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
|
||||
@JsonSubTypes({
|
||||
|
||||
+7
-1
@@ -4,5 +4,11 @@ import java.nio.file.Path;
|
||||
|
||||
public record DependencyConfig(
|
||||
boolean explain,
|
||||
Path cacheDir) {
|
||||
Path cacheDir,
|
||||
String buildTargetId) {
|
||||
public DependencyConfig(boolean explain, Path cacheDir) { this(explain, cacheDir, "production"); }
|
||||
public DependencyConfig {
|
||||
buildTargetId = buildTargetId == null ? "production" : buildTargetId;
|
||||
if (!buildTargetId.matches("[A-Za-z0-9][A-Za-z0-9_.-]{0,127}")) throw new IllegalArgumentException("Invalid build target ID");
|
||||
}
|
||||
}
|
||||
|
||||
+15
-2
@@ -12,9 +12,22 @@ public record PrometeuManifest(
|
||||
AppMode target,
|
||||
ReadOnlyList<DependencyReference> dependencies,
|
||||
Long appId,
|
||||
Integer memcardSlots) {
|
||||
Integer memcardSlots,
|
||||
TestTargets testTargets,
|
||||
String manifestSha256) {
|
||||
public PrometeuManifest(String name, String version, String language, int stdlib, AppMode target,
|
||||
ReadOnlyList<DependencyReference> dependencies, Long appId, Integer memcardSlots, TestTargets testTargets) {
|
||||
this(name, version, language, stdlib, target, dependencies, appId, memcardSlots, testTargets, null);
|
||||
}
|
||||
public PrometeuManifest {
|
||||
testTargets = testTargets == null ? TestTargets.empty() : testTargets;
|
||||
}
|
||||
public PrometeuManifest(String name, String version, String language, int stdlib, AppMode target,
|
||||
ReadOnlyList<DependencyReference> dependencies, Long appId, Integer memcardSlots) {
|
||||
this(name, version, language, stdlib, target, dependencies, appId, memcardSlots, TestTargets.empty());
|
||||
}
|
||||
public PrometeuManifest(String name, String version, String language, int stdlib, AppMode target,
|
||||
ReadOnlyList<DependencyReference> dependencies) {
|
||||
this(name, version, language, stdlib, target, dependencies, null, null);
|
||||
this(name, version, language, stdlib, target, dependencies, null, null, TestTargets.empty());
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -13,4 +13,6 @@ public record ResolvedWorkspace(
|
||||
public ProjectDescriptor mainProject() {
|
||||
return graph.projectDescriptor(mainProjectId);
|
||||
}
|
||||
public String buildTargetId() { return mainProject().getBuildTargetId(); }
|
||||
public TestTargets.Target testTarget() { return mainProject().getTestTarget(); }
|
||||
}
|
||||
|
||||
+34
-2
@@ -36,7 +36,15 @@ public final class PrometeuManifestUtils {
|
||||
final Path manifestPathCanon,
|
||||
final BuildingIssueSink issues) {
|
||||
final var issuesLocal = BuildingIssueSink.empty();
|
||||
final PrometeuManifestDTO dto = read(manifestPathCanon);
|
||||
final PrometeuManifestDTO dto;
|
||||
final String manifestSha256;
|
||||
try {
|
||||
var bytes = java.nio.file.Files.readAllBytes(manifestPathCanon);
|
||||
dto = MAPPER.readValue(bytes, PrometeuManifestDTO.class);
|
||||
manifestSha256 = java.util.HexFormat.of().formatHex(java.security.MessageDigest.getInstance("SHA-256").digest(bytes));
|
||||
} catch (IOException | java.security.NoSuchAlgorithmException failure) {
|
||||
throw new IllegalStateException("failed to read manifest " + manifestPathCanon, failure);
|
||||
}
|
||||
if (StringUtils.isBlank(dto.name())) {
|
||||
issuesLocal.report(builder -> builder
|
||||
.error(true)
|
||||
@@ -65,12 +73,36 @@ public final class PrometeuManifestUtils {
|
||||
final var dependencies = DependencyResolver.resolveDependencies(mainProjectRootPathCanon, dto.dependencies(), issuesLocal);
|
||||
final var appId = optionalInteger(dto.appId(), "app_id", 0, 0xffff_ffffL, issuesLocal);
|
||||
final var slots = optionalInteger(dto.memcardSlots(), "memcard_slots", 1, 64, issuesLocal);
|
||||
var testTargets = p.studio.compiler.models.TestTargets.empty();
|
||||
if (dto.testTargets() != null) {
|
||||
try {
|
||||
validateTargetTypes(dto.testTargets());
|
||||
testTargets = MAPPER.treeToValue(dto.testTargets(), p.studio.compiler.models.TestTargets.class);
|
||||
} catch (IOException | IllegalArgumentException failure) {
|
||||
issuesLocal.report(b -> b.error(true).code("TEST_TARGETS_INVALID")
|
||||
.message("[DEPS]: invalid testTargets in " + manifestPathCanon + ": " + failure.getMessage()));
|
||||
}
|
||||
}
|
||||
if (ReadOnlyCollection.isNotEmpty(issuesLocal)) {
|
||||
issues.merge(issuesLocal);
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(new PrometeuManifest(dto.name(), dto.version(), language, stdlibMaybe.getAsInt(), target,
|
||||
ReadOnlyList.wrap(dependencies), appId, slots == null ? null : slots.intValue()));
|
||||
ReadOnlyList.wrap(dependencies), appId, slots == null ? null : slots.intValue(), testTargets, manifestSha256));
|
||||
}
|
||||
|
||||
private static void validateTargetTypes(com.fasterxml.jackson.databind.JsonNode value) {
|
||||
if (!value.isObject() || !value.path("schemaVersion").isIntegralNumber() || !value.path("schemaVersion").canConvertToInt()
|
||||
|| !value.path("targets").isArray()) throw new IllegalArgumentException("testTargets requires integer schemaVersion and targets array");
|
||||
for (var target : value.path("targets")) {
|
||||
if (!target.isObject() || !target.path("id").isTextual() || !target.path("entrypoint").isTextual()
|
||||
|| !target.path("logTag").isIntegralNumber() || !target.path("logTag").canConvertToInt())
|
||||
throw new IllegalArgumentException("Target requires id, entrypoint and integer logTag");
|
||||
for (var field : java.util.List.of("sourceRoots", "supportRoots", "exclusions", "cases")) {
|
||||
if (!target.path(field).isArray()) throw new IllegalArgumentException("Target requires " + field + " array");
|
||||
for (var item : target.path(field)) if (!item.isTextual()) throw new IllegalArgumentException("Target " + field + " requires strings");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Long optionalInteger(com.fasterxml.jackson.databind.JsonNode value, String name,
|
||||
|
||||
+2
-1
@@ -40,7 +40,8 @@ public final class DependencyService {
|
||||
final var issues = dependencyPhase.run(ctx);
|
||||
issues.forEach(issue -> issue.print(logs.using(log)));
|
||||
if (issues.hasErrors()) {
|
||||
throw new BuildException("[DEPS]: issues found during dependency phase: " + dependencyPhase.getClass().getSimpleName());
|
||||
throw new BuildException("[DEPS]: issues found during dependency phase: " + dependencyPhase.getClass().getSimpleName(),
|
||||
null, issues.asCollection().stream().toList(), dependencyPhase.getClass().getSimpleName(), java.util.Map.of());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+63
-2
@@ -11,6 +11,7 @@ import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -67,10 +68,19 @@ public final class WireProjectsPhase implements DependencyPhase {
|
||||
final BuildingIssueSink issues) {
|
||||
final BuildingIssueSink sourceRootIssues = BuildingIssueSink.empty();
|
||||
final List<Path> sourceRoots = new ArrayList<>();
|
||||
for (final var sourceRoot : ctx.frontendSpec.getSourceRoots()) {
|
||||
boolean main = projectInfo.rootDirectory.equals(ctx.mainProjectRootPathCanon);
|
||||
String targetId = main ? ctx.config.buildTargetId() : "production";
|
||||
var selected = "production".equals(targetId) ? null : projectInfo.manifest.testTargets().find(targetId).orElse(null);
|
||||
if (!"production".equals(targetId) && selected == null)
|
||||
issues.report(b -> b.error(true).code("TEST_TARGET_NOT_FOUND").message("[DEPS]: no test target '" + targetId + "' in " + projectInfo.rootDirectory.resolve("prometeu.json")));
|
||||
var declaredRoots = selected == null ? ctx.frontendSpec.getSourceRoots().asCollection().stream().toList()
|
||||
: java.util.stream.Stream.concat(selected.sourceRoots().stream(), selected.supportRoots().stream()).distinct().toList();
|
||||
for (final var sourceRoot : declaredRoots) {
|
||||
final var sourceRootPath = projectInfo.rootDirectory.resolve(sourceRoot);
|
||||
try {
|
||||
final var sourceRootPathCanon = sourceRootPath.toRealPath();
|
||||
if (selected != null && (!sourceRootPathCanon.startsWith(projectInfo.rootDirectory) || !Files.isDirectory(sourceRootPathCanon)))
|
||||
throw new IOException("Test source root escapes the project or is not a directory");
|
||||
sourceRoots.add(sourceRootPathCanon);
|
||||
} catch (IOException e) {
|
||||
sourceRootIssues.report(builder -> builder
|
||||
@@ -79,11 +89,49 @@ public final class WireProjectsPhase implements DependencyPhase {
|
||||
.exception(e));
|
||||
}
|
||||
}
|
||||
if (sourceRootIssues.size() == ctx.frontendSpec.getSourceRoots().size()) {
|
||||
if (selected != null || sourceRootIssues.size() == declaredRoots.size()) {
|
||||
// no source roots were found at all
|
||||
issues.merge(sourceRootIssues);
|
||||
}
|
||||
|
||||
Path entrypoint = null;
|
||||
var excludedSources = new ArrayList<Path>();
|
||||
var excludedRoots = new ArrayList<Path>();
|
||||
if (selected != null) {
|
||||
try {
|
||||
entrypoint = admittedFile(projectInfo.rootDirectory, selected.entrypoint(), sourceRoots);
|
||||
for (var exclusion : selected.exclusions()) excludedSources.add(admittedFile(projectInfo.rootDirectory, exclusion, sourceRoots));
|
||||
if (excludedSources.contains(entrypoint)) throw new IOException("Selected entrypoint is excluded");
|
||||
} catch (IOException failure) {
|
||||
issues.report(b -> b.error(true).code("TEST_TARGET_SOURCE_INVALID")
|
||||
.message("[DEPS]: invalid sources for test target '" + targetId + "': " + failure.getMessage()));
|
||||
}
|
||||
}
|
||||
// Explicit declarations of another target do not leak into production or a selected sibling.
|
||||
// A root shared with the ordinary source roots remains ordinary production code.
|
||||
for (var target : projectInfo.manifest.testTargets().targets()) {
|
||||
if (target.id().equals(targetId)) continue;
|
||||
for (var root : java.util.stream.Stream.concat(target.sourceRoots().stream(), target.supportRoots().stream()).distinct().toList()) {
|
||||
if (ctx.frontendSpec.getSourceRoots().asCollection().contains(root)) continue;
|
||||
try {
|
||||
var candidate = projectInfo.rootDirectory.resolve(root).toRealPath();
|
||||
if (candidate.startsWith(projectInfo.rootDirectory) && sourceRoots.stream().noneMatch(p -> p.startsWith(candidate)))
|
||||
excludedRoots.add(candidate);
|
||||
} catch (IOException ignored) { /* Unselected source existence is checked only when selected. */ }
|
||||
}
|
||||
try {
|
||||
var candidate = projectInfo.rootDirectory.resolve(target.entrypoint()).toRealPath();
|
||||
if (candidate.startsWith(projectInfo.rootDirectory)) excludedSources.add(candidate);
|
||||
} catch (IOException ignored) { /* Unselected entrypoints are not required for production. */ }
|
||||
}
|
||||
// Selected support under a common production root must still be test-only during production builds.
|
||||
if (selected == null) for (var target : projectInfo.manifest.testTargets().targets()) for (var root : target.supportRoots()) {
|
||||
try {
|
||||
var candidate = projectInfo.rootDirectory.resolve(root).toRealPath();
|
||||
if (candidate.startsWith(projectInfo.rootDirectory)) excludedRoots.add(candidate);
|
||||
} catch (IOException ignored) { }
|
||||
}
|
||||
|
||||
return ProjectDescriptor
|
||||
.builder()
|
||||
.rootPath(projectInfo.rootDirectory)
|
||||
@@ -91,6 +139,19 @@ public final class WireProjectsPhase implements DependencyPhase {
|
||||
.version(projectInfo.manifest.version())
|
||||
.target(projectInfo.manifest.target())
|
||||
.sourceRoots(ReadOnlyList.wrap(sourceRoots))
|
||||
.buildTargetId(targetId)
|
||||
.testTarget(selected)
|
||||
.entrypoint(entrypoint)
|
||||
.manifestSha256(projectInfo.manifest.manifestSha256())
|
||||
.excludedSources(ReadOnlyList.wrap(excludedSources.stream().distinct().toList()))
|
||||
.excludedSourceRoots(ReadOnlyList.wrap(excludedRoots.stream().distinct().toList()))
|
||||
.build();
|
||||
}
|
||||
|
||||
private static Path admittedFile(Path root, String relative, List<Path> sourceRoots) throws IOException {
|
||||
Path file = root.resolve(relative).toRealPath();
|
||||
if (!file.startsWith(root) || !Files.isRegularFile(file) || sourceRoots.stream().noneMatch(file::startsWith))
|
||||
throw new IOException("Target file is outside its selected source roots: " + relative);
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
+18
@@ -15,6 +15,24 @@ class PrometeuManifestUtilsTest {
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@Test void testTargetsAreVersionedStrictAndPreserveMachineAndApplicationIdentity() throws Exception {
|
||||
String target="""
|
||||
{"id":"life","entrypoint":"tests/life/main.pbs","sourceRoots":["src","tests/life"],"supportRoots":["tests/support"],"exclusions":["src/main.pbs"],"cases":["health"],"logTag":41000}
|
||||
""";
|
||||
String prefix="{\"name\":\"fixture\",\"version\":\"1\",\"language\":\"pbs\",\"stdlib\":\"1\",\"target\":\"Game\",\"app_id\":123,\"dependencies\":[],\"testTargets\":{\"schemaVersion\":1,\"targets\":[";
|
||||
var path=writeManifest(prefix+target+"]}}");var issues=BuildingIssueSink.empty();
|
||||
var manifest=PrometeuManifestUtils.buildManifest(tempDir,path,issues).orElseThrow();
|
||||
assertEquals(123L,manifest.appId());assertEquals(p.studio.AppMode.Game,manifest.target());
|
||||
assertEquals("tests/life/main.pbs",manifest.testTargets().find("life").orElseThrow().entrypoint());
|
||||
for(var invalid:java.util.List.of(target.replace("41000","1.5"),target.replace("41000","\"41000\""),target.replace("\"life\"","\"production\""),target.replace("tests/life/main.pbs","../main.pbs"))) {
|
||||
path=writeManifest(prefix+invalid+"]}}");issues=BuildingIssueSink.empty();
|
||||
assertTrue(PrometeuManifestUtils.buildManifest(tempDir,path,issues).isEmpty());
|
||||
assertTrue(issues.asCollection().stream().anyMatch(i->"TEST_TARGETS_INVALID".equals(i.getCode())));
|
||||
}
|
||||
path=writeManifest(prefix+target+","+target+"]}}");issues=BuildingIssueSink.empty();
|
||||
assertTrue(PrometeuManifestUtils.buildManifest(tempDir,path,issues).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildManifestParsesStdlib() throws IOException {
|
||||
final var manifestPath = writeManifest("""
|
||||
|
||||
+13
@@ -17,6 +17,8 @@ public class FrontendPhaseContext {
|
||||
private final AppMode target;
|
||||
private final HostAdmissionContext hostAdmissionContext;
|
||||
private final FESurfaceContext feSurfaceContext;
|
||||
private final String buildTargetId;
|
||||
private final java.nio.file.Path entrypoint;
|
||||
|
||||
public FrontendPhaseContext(
|
||||
final ProjectTableReader projectTable,
|
||||
@@ -53,12 +55,21 @@ public class FrontendPhaseContext {
|
||||
final AppMode target,
|
||||
final HostAdmissionContext hostAdmissionContext,
|
||||
final FESurfaceContext feSurfaceContext) {
|
||||
this(projectTable, fileTable, stack, stdlibVersion, target, hostAdmissionContext, feSurfaceContext, "production", null);
|
||||
}
|
||||
|
||||
public FrontendPhaseContext(
|
||||
final ProjectTableReader projectTable, final FileTableReader fileTable, final BuildStack stack,
|
||||
final int stdlibVersion, final AppMode target, final HostAdmissionContext hostAdmissionContext,
|
||||
final FESurfaceContext feSurfaceContext, final String buildTargetId, final java.nio.file.Path entrypoint) {
|
||||
this.projectTable = projectTable;
|
||||
this.fileTable = fileTable;
|
||||
this.stack = stack;
|
||||
this.nameTable = new NameTable();
|
||||
this.stdlibVersion = stdlibVersion;
|
||||
this.target = target;
|
||||
this.buildTargetId = buildTargetId == null ? "production" : buildTargetId;
|
||||
this.entrypoint = entrypoint;
|
||||
this.hostAdmissionContext = hostAdmissionContext == null
|
||||
? HostAdmissionContext.permissiveDefault()
|
||||
: hostAdmissionContext;
|
||||
@@ -70,6 +81,8 @@ public class FrontendPhaseContext {
|
||||
public SourceKind sourceKind(final ProjectId projectId) {
|
||||
return projectTable.sourceKind(projectId);
|
||||
}
|
||||
public String buildTargetId() { return buildTargetId; }
|
||||
public java.nio.file.Path entrypoint() { return entrypoint; }
|
||||
|
||||
public int stdlibVersion() {
|
||||
return stdlibVersion;
|
||||
|
||||
Reference in New Issue
Block a user