Files
prometeu-studio/prometeu-studio-api/src/main/java/p/studio/api/automation/Evidence.java
T
bquarkz 1471b427f1
Test / Tests and coverage occurred while executing withChecks step.
Intrepid/Prometeu/Studio/pipeline/pr-master There was a failure building this commit
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.
2026-11-11 01:21:25 +00:00

91 lines
5.1 KiB
Java

package p.studio.api.automation;
import p.studio.api.values.ValueMaps;
import java.util.*;
/** Neutral immutable visual evidence. Image bytes and historical identities never change. */
public final class Evidence {
private Evidence() {}
public static final long DEFAULT_QUOTA = 512L * 1024 * 1024;
public static final int MAX_READ = 1024 * 1024;
public record Pixels(int width, int height, byte[] rgba) {
public Pixels {
if (width <= 0 || height <= 0 || (long) width * height > 16_777_216
|| (long) width * height * 4 != rgba.length) throw new IllegalArgumentException("Invalid RGBA8 layout");
rgba = rgba.clone();
}
@Override public byte[] rgba() { return rgba.clone(); }
public int channel(int x, int y, int channel) {
if (x < 0 || y < 0 || x >= width || y >= height || channel < 0 || channel > 3)
throw new IllegalArgumentException("Invalid RGBA coordinate");
return Byte.toUnsignedInt(rgba[(y * width + x) * 4 + channel]);
}
}
public record Rect(int x, int y, int width, int height) {
public Rect {
if (x < 0 || y < 0 || width <= 0 || height <= 0) throw new IllegalArgumentException("Invalid rectangle");
}
public boolean contains(int px, int py) {
return px >= x && py >= y && (long)px < (long)x + width && (long)py < (long)y + height;
}
public void requireInside(int w, int h) {
if ((long)x + width > w || (long)y + height > h) throw new IllegalArgumentException("Rectangle exceeds image bounds");
}
}
public enum Alpha { compare, ignore }
public record Parameters(Rect roi, List<Rect> masks, Alpha alpha, int channelLimit, long allowedDifferentPixels) {
public Parameters {
Objects.requireNonNull(alpha, "Explicit alpha policy required");
masks = List.copyOf(masks == null ? List.of() : masks);
if (masks.size() > 1024 || channelLimit < 0 || channelLimit > 255 || allowedDifferentPixels < 0)
throw new IllegalArgumentException("Invalid comparison parameters");
}
public static Parameters exact(Alpha alpha) { return new Parameters(null, List.of(), alpha, 0, 0); }
}
public record Artifact(String id, String publicationId, String sha256, long byteSize, String mime,
int width, int height, Map<String,Object> provenance) {
public Artifact {
Objects.requireNonNull(id); Objects.requireNonNull(publicationId); Objects.requireNonNull(sha256);
if (!id.matches("[a-f0-9-]{36}") || !publicationId.matches("[a-f0-9-]{36}") || !sha256.matches("[a-f0-9]{64}")
|| byteSize <= 0 || byteSize > 32L*1024*1024 || !"image/png".equals(mime)
|| width <= 0 || height <= 0 || (long)width*height > 16_777_216)
throw new IllegalArgumentException("Invalid evidence metadata");
provenance = normalizeProvenance(provenance);
}
}
public enum Verdict { passed, rejected, dimension_mismatch }
public record Report(String id, String expectedId, String actualId, String diffId,
String expectedSha256, String actualSha256, Parameters parameters, Verdict verdict,
long comparedPixels, long differentPixels, int maximumChannelError, Rect boundingBox) {}
public record Baseline(String id, String previousRevision, String artifactId,
Map<String,Object> origin, String reviewedAt) {
public Baseline { origin = normalizeProvenance(origin); }
}
public record Publication(String id, String requestId, String parameterKey, String projectRoot,
String createdAt, List<Artifact> artifacts, Report report, Baseline baseline) {
public Publication { artifacts = List.copyOf(artifacts); }
}
public record Blob(Artifact artifact, byte[] bytes) {
public Blob { bytes = bytes.clone(); }
@Override public byte[] bytes() { return bytes.clone(); }
}
public record View(Artifact artifact, boolean stale) {}
public record Read(String artifactId, long offset, long totalBytes, byte[] bytes) {
public Read { bytes = bytes.clone(); }
@Override public byte[] bytes() { return bytes.clone(); }
}
public record ImportedReference(byte[] bytes, String canonicalPath, boolean humanAuthorized) {
public ImportedReference { bytes = bytes.clone(); Objects.requireNonNull(canonicalPath); }
@Override public byte[] bytes() { return bytes.clone(); }
}
private static Map<String,Object> normalizeProvenance(Map<String,Object> values) {
var normalized = new LinkedHashMap<String,Object>(values);
for (var key : List.of("logicalFrameIndex", "frameId")) if (normalized.get(key) != null) {
var value = new java.math.BigInteger(normalized.get(key).toString());
if (value.signum() < 0 || value.bitLength() > 64) throw new IllegalArgumentException("Frame identity must be uint64");
normalized.put(key, value);
}
return ValueMaps.object(normalized);
}
}