Files
apps/tests/native_behavior.zi
waozi 07420f6b06 Build add-ons with their base's code on one-format ZX
Ziran's one-format ZX has no bundle libraries. An add-on now imports its
base's modules and the linker builds that code into the add-on's own
bundle, so shared_code, OpenBundleBytesWithLibraries and the own-asset
split are removed; catalogs that name shared_code are rejected.
Dependencies stay for resource links and shared records, verified on the
preparation worker, and a running base's verified bundle is still leased
once so its bytes count once toward the memory limit.

Pin Ziran 768495fc and Kryon 0dea8bc2. The game HUD and notification
tests call zi2zx without the removed bundle verb and --vm, and the audio
test links the Opus decoder Kryon's media audio now uses.
2026-11-16 02:40:40 -03:00

2255 lines
107 KiB
Ziran

#import "std/vec"
#import "std/file"
#import "std/byte_text_linux"
#import "std/text_buffer"
#import "std/c_string"
#import "std/bundle_host"
#import "std/json_scan"
#import "kryon/hosted_app"
#import "kryon/hosted_values"
#import "kryon/app_context_host"
#import "kryon/app_protocol"
#import "kryon/app_files"
#import "kryon/session"
#import "kryon/geometry"
#import "kryon/drawing_props"
#import "kryon/Frame"
#import "kryon/tree"
#import "kryon/paint_queue"
#import "kryon/widget_host"
#import "kryon/widget_kind"
#import "kryon/tree_input"
#import "kryon/input_protocol"
#import "kryon/frame_snapshot"
#import "kryon/widget_codec"
Scroll :: #import "kryon/scroll";
TextField :: #import "kryon/text_field";
#import, file "../src/controller.zi";
#import, file "../src/protocol.zi";
#import, file "../src/catalog.zi";
#import, file "../src/tree.zi";
#import, file "../src/host.zi";
#import, file "../src/node_host.zi";
#import, file "../src/preparation.zi";
Node :: #import "node_types";
// The host interface these fixtures run on; their games declare an older one.
TEST_HOST_API :: 41
using HostValueKind;
using FrameStatus;
using PaintKind;
using WidgetKind;
libc :: #system_library "libc";
PreparationTestBegin :: () #foreign libc;
PreparationTestBlock :: (enabled: bool) #foreign libc;
PreparationTestStarted :: () -> bool #foreign libc;
PreparationTestOpens :: () -> s32 #foreign libc;
PreparationTestLive :: () -> s32 #foreign libc;
PreparationTestFrameOpens :: () -> s32 #foreign libc;
PreparationTestYield :: () #foreign libc;
PreparationTestNow :: () -> float64 #foreign libc;
PreparationTestTiming :: (synchronous: float64, activation: float64) #foreign libc;
PreparationTestLocatorTiming :: (synchronous: float64, maximum_poll: float64) #foreign libc;
GetEnvironment :: (name: *u8) -> *u8 #foreign libc "getenv";
FixtureEnvironment :: (name: string) -> string {
key: [64]u8
if !CopyCString(name, key[:]) { return "" }
return TextFromCString(GetEnvironment(*key[0]))
}
stored: string = "legacy saved value";
node_stored: string;
effect_calls: s32;
flush_failed: bool;
ui_host: *AppHost;
ui_session: Session;
ui_frame: u64;
preview_first: Rectangle;
preview_second: Rectangle;
first_card_fill: Color;
menu_triggers: s32;
invalid_trigger: s32;
button_codec: WidgetButtonPropsCodec;
host_version_calls: s32;
open_decision: s32 = APP_OPEN_DECLARED;
sound_enabled: bool = true;
sound_calls: s32;
host_frame_input: FrameInputSnapshot;
session_codec: WidgetSessionCodec;
host_open_calls: s32;
host_open_chain: s64;
host_open_leaf: [65]u8;
host_open_bad: bool;
#program_export
MeasureGlyphWidth :: (value: string, font: s32, typeface: string) -> s32 {
return cast(s32)value.count * font / 2
}
#program_export
MeasureGlyphLineHeight :: (font: s32, typeface: string) -> s32 { return font }
#program_export
ImageWidth :: (path: string) -> s32 { return 1 }
#program_export
ImageHeight :: (path: string) -> s32 { return 1 }
#program_export
SystemClipboardOpenHost :: () -> s32 { return -1 }
#program_export
SystemClipboardByteHost :: (index: s32) -> s32 { return -1 }
#program_export
SystemClipboardWriteHost :: (text: string) -> bool { return false }
#program_export
RasterRoundedRectangle :: (bounds: Rectangle, radius: float32, segments: s32, color: Color) {}
#program_export
RasterRoundedRectangleOutline :: (bounds: Rectangle, radius: float32, segments: s32, width: float32, color: Color) {}
#program_export
RasterLine :: (line: Rectangle, color: Color) {}
#program_export
RasterTriangles :: (points: []Vector2, color: Color) {}
#program_export
RasterText :: (value: string, x: s32, y: s32, font: s32, color: Color) {}
#program_export
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32,
color: Color, clip: Rectangle, origin: Vector2, rotation: float32,
outer_clip: Rectangle, outer_clipped: bool, emphasis: bool, italic: bool) {}
#program_export
RasterTextClipped :: (value: string, x: s32, y: s32, font: s32, color: Color, clip: Rectangle) {}
#program_export
RasterImage :: (path: string, texture: u32, source: Rectangle, destination: Rectangle,
clip: Rectangle, origin: Vector2, rotation: float32, radius: float32, tint: Color) {}
#program_export
RasterImageMesh :: (path: string, texture: u32, source: Rectangle, points: []Vector2,
columns: s32, rows: s32, clip: Rectangle, tint: Color) {}
AllowImage :: (path: string) -> bool {
return path == "" || AppHostAsset(AppHostActiveRuntime(ui_host).node, path).found
}
ResolveImage :: (path: string) -> string {
return ifx path == "assets/preview.png" then "fixture/verified-parent/preview.png" else ""
}
Widgets :: (context: *void, node: *AppNode, module: *u8, function: *u8,
arguments: *HostValue, count: s32, result: *HostValue) -> s32 {
if TextFromCString(function) == "ButtonHostedHost" && count == 2 && WidgetValidButtonProps(arguments[1]) {
props := WidgetDecodeButtonProps(arguments[1], *button_codec)
if props.icon_shape == "S3rr:M12 5H12.01M12 12H12.01M12 19H12.01" {
menu_triggers += 1
scale := AppHostActiveRuntime(ui_host).app.scale
if !props.icon_only || props.bounds.width != 36.0 * scale || props.bounds.height != 36.0 * scale { invalid_trigger += 1 }
}
}
return WidgetHostCall(context, module, function, arguments, count, result)
}
State :: (context: *void, account: string, identity: *AppIdentity, state: *AppState) -> bool {
state.* = AppState.{.installed = true, .bytes = 12345, .actions_known = true,
.actions = cast(u64)4092, .update_available = true, .history_count = 1}
unused CopyCString("1.0", state.current_version[:])
unused CopyCString("2.0", state.available_version[:])
unused CopyCString("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", state.available_sha256[:])
unused CopyCString("0.9", state.history[0].version[:])
unused CopyCString("cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", state.history[0].sha256[:])
return true
}
// Inspect actual opaque card fills; ellipsis buttons are Ghost and have no
// fill, so their precise props are checked in Widgets before native drawing.
CardPaintGeometry :: (scale: float32) -> bool {
fills: s32
for index: cast(s32)0..PendingPaintCount(ui_session) - 1 {
paint := PendingPaintAt(ui_session, index)
if paint.kind != PaintKindRoundedFill { continue }
node := TreeSubmittedNodeAt(ui_session, paint.node)
if node.kind == WidgetKindDropdown { return false }
if node.kind != WidgetKindBox { continue }
// The update dot on a card's options is not a card.
if node.bounds.width == 8.0 * scale && node.bounds.height == 8.0 * scale { continue }
if paint.color.a != cast(u8)255 || node.bounds.height != 232.0 * scale { return false }
if fills == 0 { first_card_fill = paint.color }
fills += 1
}
return fills > 0 && menu_triggers == fills && invalid_trigger == 0
}
Draw :: (host: *AppHost, width: s32, height: s32, require_preview: bool = true,
dark: bool = false, scale: float32 = 1.0) -> bool {
ui_host = host
if ui_session.epoch == cast(u64)0 { ui_session = SessionOpen() }
ui_frame += cast(u64)1
bounds := Rectangle.{0.0, 0.0, cast(float32)width, cast(float32)height}
BeginFrame(ui_session, cast(u64)1, bounds)
runtime := AppHostActiveRuntime(host)
runtime.app.session = ui_session
runtime.app.bounds = bounds
runtime.app.font = 18
runtime.app.scale = scale
runtime.app.dark = dark
runtime.legacy.frame.session = ui_session
runtime.legacy.frame.width = width
runtime.legacy.frame.height = height
// Host chrome and guest Back both use key 2; the runtime mount keeps
// them in separate tree scopes.
unused TreeSubmitCurrent(ui_session, cast(u64)2, 0, bounds)
menu_triggers = 0; invalid_trigger = 0
input_open := FrameInputBegin(ui_session, host_frame_input)
WidgetHostBegin(ui_session, AllowImage, ResolveImage)
ran := AppHostRun(host, APP_FRAME)
WidgetHostEnd()
if input_open { FrameInputEnd(ui_session) }
image: bool
images: s32 = 0
for index: cast(s32)0..PendingPaintCount(ui_session) - 1 {
paint := PendingPaintAt(ui_session, index)
if paint.asset_path == "fixture/verified-parent/preview.png" {
image = true
if images == 0 { preview_first = paint.bounds }
if images == 1 { preview_second = paint.bounds }
images += 1
}
}
geometry := !require_preview || CardPaintGeometry(scale)
ended := EndFrame(ui_session) == cast(FrameStatus)FrameOk
AppHostCollect(host)
return ran && ended && geometry && (image || !require_preview)
}
Allows :: (context: *void, node: *AppNode, function: string) -> bool {
return function == "DocumentReadHost" || function == "DocumentWriteHost" ||
function == "AppRecordHost" || function == "SaveAppRecordHost" ||
((function == "AppSoundHost" || function == "echo") && sound_enabled) || TextUntilNul(node.identity.id[:]) == "inbe.chess"
}
Call :: (context: *void, node: *AppNode, module: *u8, function: *u8,
arguments: *HostValue, count: s32, result: *HostValue) -> s32 {
name := TextFromCString(function)
if TextUntilNul(node.identity.id[:]) == "fixture.node" {
if name == "AppRecordHost" && count == 1 {
result.* = AppHostText(node_stored)
return 1
}
// Sounds come only from the calling app's own verified assets.
if name == "AppSoundHost" && count == 1 && AppHostAsset(node, AppArgumentText(arguments[0])).found {
sound_calls += 1
result.* = HostScalar("bool", 1)
return 1
}
if name == "AppServiceHost" && count == 2 && AppArgumentText(arguments[0]) == "echo" &&
AppArgumentText(arguments[1]) == "ping" {
result.* = AppHostText("{\"echo\":\"ping\"}")
return 1
}
if name == "SaveAppRecordHost" && count == 2 && AppArgumentText(arguments[1]) == "node saved" {
node_stored = "node saved"
result.* = HostScalar("bool", 1)
return 1
}
return 0
}
if TextUntilNul(node.identity.id[:]) != "fixture.counter" { return 0 }
if name == "AppRecordHost" && count == 1 && AppArgumentText(arguments[0]) == "local.campaign" {
result.* = AppHostText("counter campaign")
return 1
}
if name == "DocumentReadHost" && count == 1 {
result.* = AppHostText(stored)
return 1
}
if name == "DocumentWriteHost" && count == 2 {
if AppArgumentText(arguments[0]) != "position" || AppArgumentText(arguments[1]) != "after" { return 0 }
stored = "after"
result.* = HostScalar("bool", 1)
return 1
}
return 0
}
Save :: (context: *void, node: *AppNode) -> bool { return !flush_failed }
Effect :: (context: *void, account: string, locator: *AppLocator, operation: s32, reply: *AppsReply) -> bool {
effect_calls += 1
reply.status = APPS_APPLIED
return account == "account-a"
}
HostVersionEffect :: (context: *void, account: string, locator: *AppLocator, request: *AppsRequest, reply: *AppsReply) -> bool {
if ui_host.tree.busy || !ui_host.tree.draining || account != "account-a" ||
TextUntilNul(locator.identity.id[:]) != "fixture.middle" || request.operation != APPS_UPDATE ||
TextUntilNul(request.sha256[:]) != "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" { return false }
host_version_calls += 1
reply.status = APPS_APPLIED
return true
}
// Every guest OPEN reaches here after its caller saved and the declared child
// verified; no guest VM is running and the caller is still the active page.
HostOpenEffect :: (context: *void, account: string, locator: *AppLocator, request: *AppsRequest, reply: *AppsReply) -> s32 {
host_open_calls += 1
active := AppHostActiveRuntime(ui_host)
if ui_host.tree.busy || !ui_host.tree.draining || active == null || active.busy ||
(active.frontend != null && active.frontend.busy) || account != "account-a" || request.operation != APPS_OPEN ||
TextUntilNul(locator.identity.id[:]) != TextUntilNul(request.id[:]) || locator.chain.count < 2 ||
TextUntilNul(locator.chain[0].sha256[:]) != FixtureEnvironment("APPS_FIXTURE_ROOT_SHA256") { host_open_bad = true }
host_open_chain = locator.chain.count
unused CopyCString(TextUntilNul(locator.chain[locator.chain.count - 1].sha256[:]), host_open_leaf[:])
unused CopyCString("native-leaf", reply.receipt[:])
return open_decision
}
native_controller: AppController;
native_catalog: string;
native_request: AppsRequest;
native_queued: s32;
native_applied: s32;
native_tiles: s32;
native_actions: s32;
native_dots: s32;
native_icons: s32;
native_bad: bool;
native_size_detail: bool;
box_codec: WidgetBoxPropsCodec;
native_icon_mode: bool = true;
native_handle_bounds: Rectangle;
native_tile_bounds: Rectangle;
native_other_bounds: Rectangle;
native_label_bounds: Rectangle;
native_still_emphasis: s32;
native_still_tone: s32;
native_still_bounds: Rectangle;
native_still_class: s32;
native_still_icon_only: bool;
native_reorder_emphasis: s32;
native_reorder_tone: s32;
native_reorder_bounds: Rectangle;
native_reorder_class: s32;
native_reorder_icon_only: bool;
native_capture_actions: bool;
native_still_captured: bool;
native_reorder_captured: bool;
NativeService :: (context: *void, text: string) -> string {
request: AppsRequest
if !AppsReadRequest(text, *request) { return "{}" }
if request.operation == APPS_CATALOG { return native_catalog }
if request.operation == APPS_STATUS { return "{\"v\":1,\"status\":\"applied\",\"request\":1}" }
// The app's own icon comes first; reading choices changes nothing.
if request.operation == APPS_ICONS {
if TextUntilNul(request.id[:]) != "native.breathing" { native_bad = true }
native_icons += 1
return "{\"v\":1,\"icons\":[{\"id\":\"\",\"shape\":\"S2rr:M4 12H20\"},{\"id\":\"leaf\",\"shape\":\"S2rr:M12 3V21\"}]}"
}
// This is a native root catalog; it has no AppNode, slot, or fake tree.
// Reentrant runs and disposal cannot invalidate the in-flight VM.
if AppControllerRun(*native_controller, APP_FRAME) || AppControllerClose(*native_controller) { native_bad = true }
native_request = request
native_queued += 1
return "{\"v\":1,\"status\":\"queued\",\"request\":1}"
}
NativeWidgets :: (context: *void, module: *u8, function: *u8, arguments: *HostValue,
count: s32, result: *HostValue) -> s32 {
if TextFromCString(function) == "ButtonHostedHost" && count == 2 && WidgetValidButtonProps(arguments[1]) {
props := WidgetDecodeButtonProps(arguments[1], *button_codec)
// The card itself; its own icon in Properties shares its title.
if props.key == AppCardKey("native.breathing") {
native_size_detail = props.detail == "12.3 kB"
native_tile_bounds = props.bounds
native_tiles += 1
if native_icon_mode && (props.bounds.height != 88.0 || props.class_name != 501 || !props.selected ||
cast(s32)props.tone != 1 || cast(s32)props.emphasis != 0 || cast(s32)props.icon_placement != 2 ||
props.image.asset_path != "assets/preview.png") { native_bad = true }
}
if props.key == AppReorderKey("native.breathing") { native_handle_bounds = props.bounds }
if props.key == AppCardKey("native.clock") { native_other_bounds = props.bounds }
// Each card has its options, or the download symbol while it is not
// on the device; the download dialog's own Download has a label.
if props.label == "App options" || (props.label == "Download" && props.icon_only) {
native_actions += 1
download := "S1.6rr:M12 3V15M7 10L12 15L17 10M5 20H19"
options := "S3rr:M12 5H12.01M12 12H12.01M12 19H12.01"
shape := ifx props.label == "Download" then download else options
if props.bounds.height != 36.0 || !props.icon_only || props.class_name != 502 ||
(cast(s32)props.emphasis != 3 && !(props.circle && cast(s32)props.emphasis == 1)) || props.icon_shape != shape { native_bad = true }
if native_capture_actions && native_actions == 1 {
if !native_still_captured {
native_still_emphasis = cast(s32)props.emphasis
native_still_tone = cast(s32)props.tone
native_still_bounds = props.bounds
native_still_class = props.class_name
native_still_icon_only = props.icon_only
native_still_captured = true
} else {
native_reorder_emphasis = cast(s32)props.emphasis
native_reorder_tone = cast(s32)props.tone
native_reorder_bounds = props.bounds
native_reorder_class = props.class_name
native_reorder_icon_only = props.icon_only
native_reorder_captured = true
}
}
}
}
// An update not yet installed or seen is a small dot on the options.
if TextFromCString(function) == "BoxHostedHost" && count == 2 && WidgetValidBoxProps(arguments[1]) {
box := WidgetDecodeBoxProps(arguments[1], *box_codec)
if box.bounds.width == 8.0 && box.bounds.height == 8.0 { native_dots += 1 }
}
return WidgetHostCall(context, module, function, arguments, count, result)
}
NativeImage :: (path: string) -> bool { return path == "" || path == "assets/preview.png" }
NativeLoadCatalog :: (name: string) -> bool {
path: Vec(u8)
BuilderPrint(*path, "%/%-catalog.json", FixtureEnvironment("APPS_FIXTURE_NATIVE_CATALOG_ROOT"), name)
text, found := ReadEntireFile(TextView(VecSlice(path, 0, path.count)))
VecFree(path)
if !found { return false }
AppFileFree(native_catalog)
native_catalog = text
return true
}
NativeDraw :: (quiet: bool = false, cards_only: bool = true) -> bool {
native_tiles = 0; native_actions = 0; native_dots = 0
native_size_detail = false
BeginFrame(ui_session, cast(u64)6, Rectangle.{0.0, 0.0, 480.0, 600.0})
native_controller.app.session = ui_session
native_controller.app.bounds = Rectangle.{0.0, 0.0, 480.0, 600.0}
outer: bool
if native_icon_mode {
group := Scroll.Draw(ui_session, Scroll.Props.{.key = cast(u64)99, .bounds = Rectangle.{0.0, 0.0, 480.0, 88.0}, .content_height = 200})
if !group.opened { return false }
outer = true
native_controller.app.bounds = Rectangle.{group.content.x, group.content.y, group.content.width, 88.0}
}
native_controller.app.scale = 1.0
native_controller.app.font = 18
WidgetHostBegin(ui_session, NativeImage)
ran := AppControllerRun(*native_controller, APP_FRAME, quiet)
WidgetHostEnd()
if outer { End(ui_session) }
if EndFrame(ui_session) != cast(FrameStatus)FrameOk || native_bad { return false }
return ran && (!cards_only || (native_tiles == 1 && native_actions == 2))
}
NativeLabel :: (label: string, kind: s32 = -1) -> s32 {
for index: cast(s32)0..TreeCount(ui_session) - 1 {
node := TreeNodeAt(ui_session, index)
if node.semantic_label == label && (kind < 0 || node.kind == kind) {
native_label_bounds = node.bounds
return index
}
}
return -1
}
// The last node with this label, such as a dialog's button over a card's.
NativeClickLast :: (label: string, kind: s32 = -1) -> bool {
target: s32 = -1
for index: cast(s32)0..TreeCount(ui_session) - 1 {
node := TreeNodeAt(ui_session, index)
if node.semantic_label == label && (kind < 0 || node.kind == kind) {
native_label_bounds = node.bounds
target = index
}
}
if target < 0 { return false }
x := native_label_bounds.x + native_label_bounds.width * 0.5
y := native_label_bounds.y + native_label_bounds.height * 0.5
// Portrait neighbours peek into this 480x600 fixture viewport.
if x > 464.0 { x = 464.0 }
if x < 16.0 { x = 16.0 }
if y > 584.0 { y = 584.0 }
hit := TreeHitAt(ui_session, x, y)
return hit == target && TreeActivateAt(ui_session, hit)
}
// An icon choice in Properties: a round button inside the dialog.
NativeIconButton :: (label: string) -> s32 {
for index: cast(s32)0..TreeCount(ui_session) - 1 {
node := TreeNodeAt(ui_session, index)
if node.kind == WidgetKindButton && node.semantic_label == label && node.bounds.width == 40.0 { return index }
}
return -1
}
// The first menu entry in tree order.
NativeFirstSelectable :: () -> string {
for index: cast(s32)0..TreeCount(ui_session) - 1 {
node := TreeNodeAt(ui_session, index)
if node.kind == WidgetKindSelectable { return node.semantic_label }
}
return ""
}
// The last menu entry in tree order.
NativeLastSelectable :: () -> string {
last := ""
for index: cast(s32)0..TreeCount(ui_session) - 1 {
node := TreeNodeAt(ui_session, index)
if node.kind == WidgetKindSelectable { last = node.semantic_label }
}
return last
}
NativeClick :: (label: string, kind: s32 = -1) -> bool {
target := NativeLabel(label, kind)
if target < 0 { return false }
// Hit testing proves the real overlay/menu target receives the click.
x := native_label_bounds.x + native_label_bounds.width * 0.5
y := native_label_bounds.y + native_label_bounds.height * 0.5
// Carousel neighbours can extend beyond this fixture's 480 x 600 viewport.
if x > 464.0 { x = 464.0 }
if x < 16.0 { x = 16.0 }
if y > 584.0 { y = 584.0 }
hit := TreeHitAt(ui_session, x, y)
// Cover names remain assistive actions beneath the pointer gesture area.
// Real swipe/tap routing is exercised by Arcade's private window test.
if hit >= 0 && TreeNodeAt(ui_session, hit).key == cast(u64)50020 {
return TreeActivateAt(ui_session, target)
}
return hit == target && TreeActivateAt(ui_session, hit)
}
NativeControllerCheck :: () -> s32 {
bytes, found := ReadEntireFile(FixtureEnvironment("APPS_FIXTURE_UI_BUNDLE"))
if !found { return 50 }
platform := AppControllerPlatform.{.service = NativeService, .widgets = NativeWidgets}
if !NativeLoadCatalog("native") || !AppControllerOpen(*native_controller, bytes,
FixtureEnvironment("APPS_FIXTURE_HARNESS_SHA256"), platform) { return 51 }
// The options carry the update's dot instead of a separate update symbol.
if !NativeDraw() || native_dots != 1 || native_queued != 0 || NativeLabel("Update available") >= 0 ||
NativeLabel("Native apps") >= 0 || NativeLabel("12.3 kB") >= 0 { return 52 }
// Opening them shows Update first and marks exactly that offer as seen.
if !NativeClick("App options") || !NativeDraw() || native_queued != 1 || native_request.operation != APPS_SEEN ||
TextUntilNul(native_request.version[:]) != "2.0" ||
TextUntilNul(native_request.sha256[:]) != "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" ||
NativeFirstSelectable() != "Update" { return 53 }
// Once seen, the dot goes; Update stays in the menu until it is installed.
if !NativeLoadCatalog("seen") || !NativeDraw() || native_dots != 0 || NativeLabel("Update", WidgetKindSelectable) < 0 { return 74 }
if !NativeClick("Update", WidgetKindSelectable) || !NativeDraw() || native_queued != 1 ||
NativeLabel("Update", WidgetKindButton) < 0 { return 75 }
// A verified target changing while the confirmation is open disables its
// old target; the modal cannot silently submit the newly offered bytes.
if !NativeLoadCatalog("changed-update") || !NativeDraw() { return 54 }
if NativeClick("Update", WidgetKindButton) { return 55 }
if !NativeClick("Cancel", WidgetKindButton) || !NativeDraw() || native_queued != 1 { return 56 }
if !NativeLoadCatalog("native") || !NativeDraw() || !NativeClick("App options") || !NativeDraw() ||
!NativeClick("Update", WidgetKindSelectable) || !NativeDraw() ||
!NativeClick("Update", WidgetKindButton) || !NativeDraw() || native_queued != 3 || native_applied != 0 ||
native_request.operation != 10 || TextUntilNul(native_request.version[:]) != "2.0" ||
TextUntilNul(native_request.sha256[:]) != "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" { return 57 }
// Native account storage mutates only after Run returns.
native_applied += 1
if !NativeLoadCatalog("no-update") || !NativeDraw() || native_dots != 0 || NativeLabel("Updated") >= 0 { return 58 }
if !NativeClick("App options") || !NativeDraw() || NativeLabel("Rollback", WidgetKindSelectable) < 0 ||
NativeLastSelectable() != "Properties" || native_queued != 3 { return 59 }
if !NativeClick("Rollback", WidgetKindSelectable) || !NativeDraw() || native_queued != 3 { return 60 }
if !NativeClick("0.9", WidgetKindButton) || !NativeDraw() || !NativeDraw() || native_queued != 3 { return 61 }
if !NativeClick("Rollback", WidgetKindButton) { return 620 }
if !NativeDraw() { return 621 }
if native_queued != 4 { return 622 }
if native_request.operation != 11 { return 623 }
if TextUntilNul(native_request.version[:]) != "0.9" { return 624 }
if TextUntilNul(native_request.sha256[:]) != "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc" { return 625 }
// Properties renames the app and chooses one of the offered icons.
if !NativeDraw() || !NativeClick("App options") || !NativeDraw() || !NativeClick("Properties", WidgetKindSelectable) ||
!NativeDraw() || native_icons != 1 || native_queued != 4 || NativeLabel("Name", WidgetKindTextField) < 0 ||
NativeIconButton("Breathing") < 0 || NativeIconButton("leaf") < 0 { return 76 }
leaf := NativeIconButton("leaf")
if leaf < 0 || !TreeActivateAt(ui_session, leaf) || !NativeDraw() { return 77 }
field := NativeLabel("Name", WidgetKindTextField)
if field < 0 || !TreeFocusAt(ui_session, field) || !NativeDraw() || !NativeDraw() { return 78 }
native_controller.app.input = TextField.Input.{.select_all = true}
if !NativeDraw() { return 79 }
native_controller.app.input = TextField.Input.{.text = "Calm"}
if !NativeDraw() { return 80 }
native_controller.app.input = TextField.Input.{}
if !NativeDraw() || !NativeClick("Save", WidgetKindButton) || !NativeDraw() || native_queued != 5 ||
native_request.operation != APPS_PROPERTIES || TextUntilNul(native_request.id[:]) != "native.breathing" ||
TextUntilNul(native_request.title[:]) != "Calm" || TextUntilNul(native_request.icon[:]) != "leaf" ||
!NativeDraw() || NativeLabel("Save", WidgetKindButton) >= 0 { return 81 }
// Cancel keeps the app's properties; its own title and icon save as empty.
if !NativeClick("App options") || !NativeDraw() || !NativeClick("Properties", WidgetKindSelectable) || !NativeDraw() ||
!NativeClick("Cancel", WidgetKindButton) || !NativeDraw() || !NativeDraw() || native_queued != 5 ||
NativeLabel("Save", WidgetKindButton) >= 0 { return 82 }
if !NativeClick("App options") || !NativeDraw() || !NativeClick("Properties", WidgetKindSelectable) || !NativeDraw() ||
!NativeClick("Save", WidgetKindButton) || !NativeDraw() || native_queued != 6 ||
native_request.operation != APPS_PROPERTIES || TextUntilNul(native_request.title[:]) != "" ||
TextUntilNul(native_request.icon[:]) != "" { return 83 }
// Quiet frames show the recorded cards again without running the
// controller, and the cards they show still take the next click.
if !NativeDraw(true) || !NativeDraw(true) || native_controller.app.app.replay == null ||
!native_controller.app.app.replay.ready { return 87 }
if !NativeClick("Breathing", WidgetKindButton) || !NativeDraw() || native_request.operation != APPS_OPEN { return 63 }
// An app not on this device has the download symbol instead of its
// options. It opens a dialog with the app's size and what it may reach,
// whose Download installs it; the dialog then follows the download.
queued := native_queued
if !NativeLoadCatalog("download") || !NativeDraw() { return 630 }
if NativeLabel("4.1 kB") < 0 { return 632 }
if !NativeClick("Download") || !NativeDraw() || native_queued != queued ||
NativeLabel("Download size: 4.1 kB") < 0 || NativeLabel("• Keep its data in your account") < 0 ||
NativeLabel("• Read and change your photo library") < 0 || NativeLabel("• Play sound") >= 0 { return 633 }
// Opening the app itself asks the same; Cancel downloads nothing.
if !NativeClick("Cancel", WidgetKindButton) || !NativeDraw() || !NativeDraw() ||
NativeLabel("Download size: 4.1 kB") >= 0 || !NativeClick("Clock", WidgetKindButton) || !NativeDraw() ||
native_queued != queued || NativeLabel("Download size: 4.1 kB") < 0 { return 639 }
if !NativeClickLast("Download", WidgetKindButton) || !NativeDraw() || native_queued != queued + 1 { return 634 }
if native_request.operation != APPS_INSTALL || TextUntilNul(native_request.id[:]) != "native.clock" { return 635 }
if !NativeLoadCatalog("downloading") || !NativeDraw() || NativeLabel("Downloading 40%") < 0 ||
NativeLabel("Hide", WidgetKindButton) < 0 { return 631 }
// Hide leaves the download running and the card saying so.
if !NativeClick("Hide", WidgetKindButton) || !NativeDraw() || !NativeDraw() ||
NativeLabel("Hide", WidgetKindButton) >= 0 || NativeLabel("Downloading") < 0 || NativeLabel("4.1 kB") >= 0 ||
native_queued != queued + 1 { return 636 }
// A failed download says so instead of failing silently, and tries again.
if !NativeLoadCatalog("download-failed") || !NativeDraw() || !NativeClick("Download") || !NativeDraw() ||
NativeLabel("Download failed") < 0 || !NativeClick("Try again", WidgetKindButton) || !NativeDraw() ||
native_queued != queued + 2 || native_request.operation != APPS_INSTALL { return 637 }
if !NativeClick("Close", WidgetKindButton) || !NativeDraw() || !NativeDraw() ||
NativeLabel("Download failed") >= 0 { return 638 }
// A requested download finishes verified installation before opening.
completed := native_queued
if !NativeLoadCatalog("download") || !NativeDraw() || !NativeClick("Clock", WidgetKindButton) || !NativeDraw() ||
!NativeClickLast("Download", WidgetKindButton) || !NativeDraw() ||
!NativeLoadCatalog("download-ready") || !NativeDraw() || native_queued != completed + 2 ||
native_request.operation != APPS_INSTALL || !NativeDraw() || native_queued != completed + 2 ||
!NativeLoadCatalog("download-installed") || !NativeDraw() || native_queued != completed + 3 ||
native_request.operation != APPS_OPEN || !NativeDraw() || NativeLabel("Hide", WidgetKindButton) >= 0 { return 640 }
if !NativeLoadCatalog("download-request") || !NativeDraw() || NativeLabel("Download size: 4.1 kB") < 0 ||
!NativeClick("Cancel", WidgetKindButton) || !NativeDraw() || !NativeDraw() ||
NativeLabel("Download size: 4.1 kB") >= 0 { return 641 }
covered := native_queued
native_icon_mode = false
if !NativeLoadCatalog("cover-download") || !NativeDraw(false, false) { return 642 }
if NativeLabel("Open", WidgetKindButton) < 0 { return 643 }
if !NativeClick("Open", WidgetKindButton) { return 644 }
if !NativeDraw(false, false) || NativeLabel("Download size: 4.1 kB") < 0 { return 645 }
if native_queued != covered { return 646 }
if !NativeClick("Cancel", WidgetKindButton) || !NativeDraw(false, false) { return 647 }
if !NativeLoadCatalog("cover-buy") || !NativeDraw(false, false) || NativeLabel("Buy", WidgetKindButton) < 0 { return 648 }
covered = native_queued
if !NativeClick("Buy", WidgetKindButton) || !NativeDraw(false, false) || native_queued != covered + 1 ||
native_request.operation != APPS_INSTALL || TextUntilNul(native_request.id[:]) != "native.clock" ||
NativeLabel("Download size: 4.1 kB") >= 0 { return 649 }
if !NativeLoadCatalog("cover-buy-de") || !NativeDraw(false, false) || NativeLabel("Kaufen", WidgetKindButton) < 0 { return 650 }
covered = native_queued
if !NativeClick("Kaufen", WidgetKindButton) || !NativeDraw(false, false) || native_queued != covered + 1 ||
native_request.operation != APPS_INSTALL || TextUntilNul(native_request.id[:]) != "native.clock" { return 651 }
if !NativeLoadCatalog("cover-buy-denied") || !NativeDraw(false, false) { return 652 }
covered = native_queued
unused NativeClick("Buy", WidgetKindButton)
if !NativeDraw(false, false) || native_queued != covered { return 653 }
native_icon_mode = true
// A host chooses compact cards without discarding bytes from its catalog.
native_capture_actions = true
if !NativeLoadCatalog("simple-grid") || !NativeDraw() || NativeLabel("12.3 kB") >= 0 { return 88 }
native_capture_actions = false
if !NativeLoadCatalog("simple-downloading") || !NativeDraw() ||
NativeLabel("Downloading") < 0 || NativeLabel("12.3 kB") >= 0 { return 89 }
native_icon_mode = false
if !NativeLoadCatalog("simple-list") || !NativeDraw() || native_size_detail { return 90 }
if !NativeLoadCatalog("reorder-list") || !NativeDraw() || NativeLabel("Move app") < 0 ||
native_size_detail ||
native_tile_bounds.x < native_handle_bounds.x + native_handle_bounds.width ||
native_other_bounds.x != native_tile_bounds.x ||
native_other_bounds.y < native_tile_bounds.y + native_tile_bounds.height + 36.0 { return 84 }
hit := TreeHitAt(ui_session, native_handle_bounds.x + 22.0, native_handle_bounds.y + 22.0)
if hit < 0 || TreeNodeAt(ui_session, hit).key != AppReorderKey("native.breathing") { return 85 }
native_capture_actions = true
if !NativeLoadCatalog("reorder-grid") || !NativeDraw() || NativeLabel("Move app") < 0 ||
native_other_bounds.y < native_tile_bounds.y + native_tile_bounds.height + 36.0 { return 86 }
if !native_still_captured || !native_reorder_captured { return 649 }
if native_still_emphasis != native_reorder_emphasis { return 648 }
if native_still_tone != native_reorder_tone { return 650 }
if native_still_bounds.x != native_reorder_bounds.x ||
native_still_bounds.y != native_reorder_bounds.y ||
native_still_bounds.width != native_reorder_bounds.width ||
native_still_bounds.height != native_reorder_bounds.height { return 651 }
if native_still_class != native_reorder_class ||
native_still_icon_only != native_reorder_icon_only { return 652 }
if !NativeLoadCatalog("preview") || !NativeDraw() || NativeLabel("Native apps") < 0 { return 64 }
// The covers themselves open apps, without separate launch buttons.
if !NativeLoadCatalog("cover-grid") || !NativeDraw(false, false) ||
NativeLabel("Native apps") >= 0 || NativeLabel("Next", WidgetKindButton) >= 0 { return 91 }
if native_tile_bounds.width < 230.0 || native_tile_bounds.height < 350.0 ||
native_other_bounds.height >= native_tile_bounds.height || native_other_bounds.x <= native_tile_bounds.x { return 92 }
if NativeLabel("Open", WidgetKindButton) >= 0 || NativeLabel("Play", WidgetKindButton) >= 0 { return 93 }
if NativeLabel("Breathing", WidgetKindText) >= 0 || NativeLabel("Clock", WidgetKindText) >= 0 { return 96 }
cover_opened := native_queued
if !NativeClick("Breathing", WidgetKindButton) || !NativeDraw(false, false) ||
native_queued != cover_opened + 1 || native_request.operation != APPS_OPEN ||
TextUntilNul(native_request.id[:]) != "native.breathing" { return 94 }
// Artwork has no captions. A neighbouring cover only selects; the selected
// cover downloads in place with progress, without a launch page or modal.
if !NativeLoadCatalog("cover-grid-download") { return 951 }
if !NativeDraw(false, false) { return 952 }
if NativeLabel("4.1 kB", WidgetKindText) >= 0 || NativeLabel("12.3 kB", WidgetKindText) >= 0 { return 953 }
covered = native_queued
if !NativeClick("Clock", WidgetKindButton) || !NativeDraw(false, false) || !NativeDraw(false, false) ||
native_queued != covered { return 954 }
if !NativeClick("Clock", WidgetKindButton) || !NativeDraw(false, false) { return 955 }
if native_queued != covered + 1 || native_request.operation != APPS_INSTALL ||
TextUntilNul(native_request.id[:]) != "native.clock" { return 956 }
if !NativeDraw(false, false) || NativeLabel("Downloading", WidgetKindText) < 0 || NativeLabel("Download size: 4.1 kB", WidgetKindText) >= 0 ||
NativeLabel("Cancel", WidgetKindButton) >= 0 || NativeLabel("Clock", WidgetKindModal) >= 0 { return 957 }
// Activating it again never queues a duplicate transfer.
if !NativeClick("Clock", WidgetKindButton) || !NativeDraw(false, false) || native_queued != covered + 1 { return 958 }
// The finished transfer installs in the background, once, without another activation.
if !NativeLoadCatalog("cover-grid-cached") || !NativeDraw(false, false) || !NativeDraw(false, false) ||
native_queued != covered + 2 || native_request.operation != APPS_INSTALL ||
TextUntilNul(native_request.id[:]) != "native.clock" || NativeLabel("Clock", WidgetKindModal) >= 0 { return 959 }
// Once installed, a fresh activation opens the game.
if !NativeLoadCatalog("cover-grid") || !NativeDraw(false, false) || NativeLabel("Downloading", WidgetKindText) >= 0 ||
!NativeClick("Clock", WidgetKindButton) || !NativeDraw(false, false) || native_queued != covered + 3 ||
native_request.operation != APPS_OPEN || TextUntilNul(native_request.id[:]) != "native.clock" { return 960 }
// Games with required downloads also start in place, as one install request.
covered = native_queued
if !NativeLoadCatalog("cover-grid-dependencies") || !NativeDraw(false, false) ||
!NativeClick("Clock", WidgetKindButton) || !NativeDraw(false, false) || native_queued != covered + 1 ||
native_request.operation != APPS_INSTALL || !NativeDraw(false, false) ||
NativeLabel("Breathing (required) · 100 B", WidgetKindText) >= 0 || NativeLabel("Downloading", WidgetKindText) < 0 { return 97 }
// A game's request for its missing editor opens the named install page
// instead of a background install, so the editor can open afterwards.
covered = native_queued
if !NativeLoadCatalog("cover-grid-request") || !NativeDraw(false, false) || !NativeDraw(false, false) ||
native_queued != covered || NativeLabel("Download size: 4.1 kB", WidgetKindText) < 0 { return 961 }
if !NativeClick("Back", WidgetKindButton) || !NativeDraw(false, false) || !NativeDraw(false, false) ||
NativeLabel("Download size: 4.1 kB", WidgetKindText) >= 0 || native_queued != covered { return 962 }
if !AppControllerClose(*native_controller) { return 65 }
AppFileFree(bytes); AppFileFree(native_catalog); native_catalog = ""
return 0
}
Command :: (host: *AppHost, command: string) -> bool {
node := AppTreeNode(*host.tree, host.tree.active)
runtime := cast(*AppRuntime)node.runtime
runtime.app.command = command
return AppHostRun(host, APP_COMMAND)
}
PreparationWait :: (preparation: *AppPreparation) -> bool {
end := PreparationTestNow() + 10.0
while !AppPreparationReady(preparation) && PreparationTestNow() < end {
PreparationTestYield()
}
return AppPreparationReady(preparation)
}
PreparationParserWait :: () -> bool {
end := PreparationTestNow() + 10.0
while !PreparationTestStarted() && PreparationTestNow() < end {
PreparationTestYield()
}
return PreparationTestStarted()
}
PreparationNavigationWait :: (host: *AppHost, previous: AppHandle) -> bool {
end := PreparationTestNow() + 10.0
while AppHandleEqual(previous, host.tree.active) && PreparationTestNow() < end {
unused AppTreeDrain(*host.tree)
AppHostCollect(host)
PreparationTestYield()
}
return !AppHandleEqual(previous, host.tree.active)
}
PreparationNavigationCheck :: (bytes: string, digest: string, harness_digest: string,
platform: AppPlatform) -> s32 {
live := PreparationTestLive()
preparation := AppPrepare(bytes, digest, "fixture.root")
host: AppHost
if preparation == null || !PreparationWait(preparation) ||
!AppHostStartPrepared(*host, preparation, "fixture.test", "fixture.root", "collection", "account-a", platform, harness_digest) ||
!AppPreparationClose(preparation) {
return 730
}
root := host.tree.active
frame_opens := PreparationTestFrameOpens()
root_node := AppTreeNode(*host.tree, root)
declared := AppCatalogAt(*root_node.catalog, 0)
correct := declared.sha256
declared.sha256[0] = ifx declared.sha256[0] == #char "0" then #char "1" else #char "0"
if !Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.middle\"}") ||
host.preparation == null || !PreparationWait(host.preparation) {
return 742
}
unused AppTreeDrain(*host.tree)
AppHostCollect(*host)
declared.sha256 = correct
if !AppHandleEqual(root, host.tree.active) || host.preparation != null ||
host.tree.pending[host.tree.pending.count - 1].reply.status != APPS_REJECTED {
return 743
}
PreparationTestBlock(true)
if !Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.middle\"}") ||
!PreparationParserWait() || host.preparation == null ||
!AppHandleEqual(root, host.tree.active) || !Draw(*host, 800, 600) || !Draw(*host, 360, 640) {
PreparationTestBlock(false)
return 731
}
PreparationTestBlock(false)
if !PreparationWait(host.preparation) {
return 732
}
// A save failure still preserves the page and disposes only the unused
// prepared programs. Another request can then make progress.
flush_failed = true
unused AppTreeDrain(*host.tree)
AppHostCollect(*host)
if !AppHandleEqual(root, host.tree.active) || host.preparation != null {
return 733
}
flush_failed = false
if !Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.middle\"}") ||
!PreparationNavigationWait(*host, root) || !Draw(*host, 800, 600) {
return 734
}
middle := host.tree.active
// Back may retire the parent while a worker still borrows its bytes.
// Collection keeps that owner alive until the obsolete job completes.
PreparationTestBlock(true)
if !Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.counter\"}") ||
!PreparationParserWait() || AppHostBack(*host) != 1 ||
!AppHandleEqual(root, host.tree.active) || AppTreeNode(*host.tree, middle) != null {
PreparationTestBlock(false)
return 735
}
AppHostCollect(*host)
if host.preparation == null || host.retired == null || !Draw(*host, 360, 640) {
PreparationTestBlock(false)
return 736
}
PreparationTestBlock(false)
end := PreparationTestNow() + 10.0
while host.preparation != null && PreparationTestNow() < end {
AppHostCollect(*host)
PreparationTestYield()
}
if host.preparation != null || host.retired != null ||
!AppHandleEqual(root, host.tree.active) || PreparationTestFrameOpens() != frame_opens {
return 737
}
PreparationTestBlock(true)
if !Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.middle\"}") || !PreparationParserWait() {
PreparationTestBlock(false)
return 744
}
host.tree.account_epoch += 1
unused AppTreeDrain(*host.tree)
AppHostCollect(*host)
if host.preparation == null || !host.preparation_canceled || !AppHandleEqual(root, host.tree.active) {
PreparationTestBlock(false)
return 745
}
PreparationTestBlock(false)
end = PreparationTestNow() + 10.0
while host.preparation != null && PreparationTestNow() < end {
AppHostCollect(*host)
PreparationTestYield()
}
if host.preparation != null || !AppHandleEqual(root, host.tree.active) {
return 746
}
// Stop is also a nonblocking poll. An unfinished worker preserves the
// whole tree/account; it never forces a join or frees borrowed input.
PreparationTestBlock(true)
if !Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.middle\"}") || !PreparationParserWait() {
PreparationTestBlock(false)
return 738
}
start := PreparationTestNow()
for frame: cast(s32)0..99 {
if AppHostStop(*host) || host.tree.nodes.count == 0 {
PreparationTestBlock(false)
return 739
}
}
if PreparationTestNow() - start > 0.05 {
PreparationTestBlock(false)
return 740
}
PreparationTestBlock(false)
end = PreparationTestNow() + 10.0
stopped := false
while !stopped && PreparationTestNow() < end {
stopped = AppHostStop(*host)
PreparationTestYield()
}
if !stopped || PreparationTestLive() != live || PreparationTestFrameOpens() != frame_opens {
return 741
}
return 0
}
PreparationCheck :: (bytes: string, digest: string, harness_digest: string,
platform: AppPlatform) -> s32 {
live := PreparationTestLive()
before := PreparationTestOpens()
owned, loaded := ReadEntireFile(FixtureEnvironment("APPS_FIXTURE_ROOT_BUNDLE"))
if !loaded {
return 700
}
PreparationTestBlock(true)
preparation := AppPrepare(owned, digest, "fixture.root")
if preparation == null {
PreparationTestBlock(false)
return 701
}
end := PreparationTestNow() + 10.0
while !PreparationTestStarted() && PreparationTestNow() < end {
PreparationTestYield()
}
if !PreparationTestStarted() {
PreparationTestBlock(false)
return 702
}
host: AppHost
start := PreparationTestNow()
for frame: cast(s32)0..99 {
if AppPreparationReady(preparation) || AppPreparationClose(preparation) ||
AppHostStartPrepared(*host, preparation, "fixture.test", "fixture.root", "collection", "account-a", platform, harness_digest) {
PreparationTestBlock(false)
return 703
}
}
if PreparationTestNow() - start > 0.05 {
PreparationTestBlock(false)
return 704
}
PreparationTestBlock(false)
if !PreparationWait(preparation) || !preparation.valid || PreparationTestOpens() != before + 2 {
return 705
}
// A prepared program cannot stand in for another root or source span.
if AppHostStartPrepared(*host, preparation, "fixture.test", "different.root", "collection", "account-a", platform, harness_digest) {
return 706
}
copy, found := ReadEntireFile(FixtureEnvironment("APPS_FIXTURE_ROOT_BUNDLE"))
if !found || AppHostStart(*host, copy, "fixture.test", "fixture.root", "collection", digest,
"account-a", platform, harness_digest, "en", APPS_CONTEXT_PROTOCOL, false, preparation) {
return 707
}
AppFileFree(copy)
// Ready releases the caller's source lifetime. Activated bundles and
// controller assets must remain owned after this memory is released.
AppFileFree(owned)
before = PreparationTestOpens()
start = PreparationTestNow()
if !AppHostStartPrepared(*host, preparation, "fixture.test", "fixture.root", "collection", "account-a", platform, harness_digest) {
return 708
}
activation := PreparationTestNow() - start
if PreparationTestOpens() != before || !AppPreparationClose(preparation) || !Draw(*host, 800, 600) ||
!AppHostStop(*host) {
return 709
}
start = PreparationTestNow()
if !AppHostStart(*host, bytes, "fixture.test", "fixture.root", "collection", digest, "account-a", platform, harness_digest) {
return 710
}
PreparationTestTiming(PreparationTestNow() - start, activation)
if !AppHostStop(*host) {
return 711
}
wrong := "0000000000000000000000000000000000000000000000000000000000000000"
before = PreparationTestOpens()
preparation = AppPrepare(bytes, wrong, "fixture.root")
if preparation == null || !PreparationWait(preparation) || preparation.valid ||
PreparationTestOpens() != before || !AppPreparationClose(preparation) {
return 712
}
// Opening code on a worker never grants an untrusted controller access.
preparation = AppPrepare(bytes, digest, "fixture.root")
if preparation == null || !PreparationWait(preparation) ||
AppHostStartPrepared(*host, preparation, "fixture.test", "fixture.root", "collection", "account-a", platform, wrong) ||
host.tree.nodes.count != 0 || !AppPreparationClose(preparation) {
return 713
}
// Identity validation still runs at activation, after parsing completed.
preparation = AppPrepare(bytes, digest, "fixture.root")
if preparation == null || !PreparationWait(preparation) ||
AppHostStartPrepared(*host, preparation, "fixture.test", "fixture.root", "wrong", "account-a", platform, harness_digest) ||
!AppPreparationClose(preparation) {
return 714
}
preparation = AppPrepare(bytes, digest, "fixture.root")
if preparation == null || !PreparationWait(preparation) || !AppHostTrustHarness(*host, harness_digest) ||
!AppHostStartPrepared(*host, preparation, "fixture.test", "fixture.root", "collection", "account-a", platform, wrong) ||
!AppPreparationClose(preparation) || !AppHostStop(*host) {
return 715
}
// Both supported leaf protocols take their verified program through the
// same host policy and handshake, without opening the source again.
for legacy: cast(s32)0..1 {
path := FixtureEnvironment(ifx legacy == 1 then "APPS_FIXTURE_NODE_BUNDLE" else "APPS_FIXTURE_COUNTER_BUNDLE")
leaf, exists := ReadEntireFile(path)
hash := FixtureEnvironment(ifx legacy == 1 then "APPS_FIXTURE_NODE_SHA256" else "APPS_FIXTURE_COUNTER_SHA256")
id := ifx legacy == 1 then "fixture.node" else "fixture.counter"
expected := ifx legacy == 1 then "node" else "counter"
protocol: s32 = ifx legacy == 1 then APPS_NODE_PROTOCOL else APPS_CONTEXT_PROTOCOL
if !exists {
return 716
}
preparation = AppPrepare(leaf, hash, id)
if preparation == null || !PreparationWait(preparation) || !preparation.valid {
return 717
}
before = PreparationTestOpens()
if !AppHostStartPrepared(*host, preparation, "fixture.test", id, expected, "account-a", platform, "", "en", protocol) ||
PreparationTestOpens() != before || !AppPreparationClose(preparation) || !AppHostStop(*host) {
return 718
}
AppFileFree(leaf)
}
if PreparationTestLive() != live {
return 719
}
return 0
}
// Native discovery must leave rendering and queued navigation responsive.
PreparationChildWait :: (host: *AppHost, parent: AppHandle, id: string, output: *AppHandle) -> s32 {
end := PreparationTestNow() + 10.0
result: s32 = 0
while result == 0 && PreparationTestNow() < end {
result = AppHostOpenChild(host, parent, id, output)
AppHostCollect(host)
PreparationTestYield()
}
return result
}
PreparationChildCheck :: (bytes: string, digest: string, harness_digest: string,
platform: AppPlatform) -> s32 {
live := PreparationTestLive()
host: AppHost
if !AppHostStart(*host, bytes, "fixture.test", "fixture.root", "collection", digest,
"account-a", platform, harness_digest) {
return 750
}
root := host.tree.active
frame_opens := PreparationTestFrameOpens()
child: AppHandle
if AppHostOpenChild(*host, root, "missing", *child) != -1 || child.slot != -1 {
return 751
}
host.tree.busy = true
if AppHostOpenChild(*host, root, "fixture.middle", *child) != 0 {
return 752
}
host.tree.busy = false
PreparationTestBlock(true)
if AppHostOpenChild(*host, root, "fixture.middle", *child) != 0 || !PreparationParserWait() {
PreparationTestBlock(false)
return 753
}
started := PreparationTestNow()
for frame: cast(s32)0..99 {
if AppHostOpenChild(*host, root, "fixture.middle", *child) != 0 ||
!AppHandleEqual(root, host.tree.active) || child.slot != -1 {
PreparationTestBlock(false)
return 754
}
}
if PreparationTestNow() - started > 0.05 || !Draw(*host, 800, 600) || !Draw(*host, 360, 640) {
PreparationTestBlock(false)
return 755
}
// Discovery never saves or runs an install/open effect.
flush_failed = true
effects := effect_calls
opens := host_open_calls
PreparationTestBlock(false)
if PreparationChildWait(*host, root, "fixture.middle", *child) != 1 ||
!AppHandleEqual(root, host.tree.active) || effect_calls != effects || host_open_calls != opens {
return 756
}
flush_failed = false
middle := child
if PreparationChildWait(*host, middle, "fixture.counter", *child) != 1 ||
!AppHandleEqual(root, host.tree.active) {
return 757
}
node := AppTreeNode(*host.tree, child)
if node == null || TextUntilNul(node.identity.id[:]) != "fixture.counter" ||
TextUntilNul(node.identity.authority[:]) != "fixture.test" {
return 758
}
AppTreeDrop(*host.tree, child)
AppTreeDrop(*host.tree, middle)
AppHostCollect(*host)
// A native scan cannot hold up a queued user request. Its unfinished
// worker stays owned until completion, then the queued request prepares.
PreparationTestBlock(true)
if AppHostOpenChild(*host, root, "fixture.middle", *child) != 0 || !PreparationParserWait() ||
!Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.middle\"}") ||
host.preparation == null || !host.preparation_canceled || !AppHandleEqual(root, host.tree.active) {
PreparationTestBlock(false)
return 759
}
PreparationTestBlock(false)
if !PreparationNavigationWait(*host, root) {
return 760
}
middle = host.tree.active
PreparationTestBlock(true)
if !Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.counter\"}") || !PreparationParserWait() {
PreparationTestBlock(false)
return 761
}
// A background scan neither replaces nor cancels queued navigation.
AppHostCancelChild(*host)
if AppHostOpenChild(*host, root, "fixture.middle", *child) != 0 ||
host.preparation_sequence == 0 || host.preparation_canceled {
PreparationTestBlock(false)
return 762
}
PreparationTestBlock(false)
if !PreparationNavigationWait(*host, middle) || AppHostBack(*host) != 1 {
return 763
}
AppHostCollect(*host)
middle = host.tree.active
// Back retires a scanned parent but must keep its borrowed bytes alive.
PreparationTestBlock(true)
if AppHostOpenChild(*host, middle, "fixture.counter", *child) != 0 || !PreparationParserWait() ||
AppHostBack(*host) != 1 || !AppHandleEqual(root, host.tree.active) {
PreparationTestBlock(false)
return 764
}
AppHostCollect(*host)
if host.preparation == null || host.retired == null || !Draw(*host, 360, 640) {
PreparationTestBlock(false)
return 765
}
PreparationTestBlock(false)
end := PreparationTestNow() + 10.0
while host.preparation != null && PreparationTestNow() < end {
AppHostCollect(*host)
PreparationTestYield()
}
if host.preparation != null || host.retired != null {
return 766
}
declared := AppCatalogAt(*AppTreeNode(*host.tree, root).catalog, 0)
correct := declared.sha256
declared.sha256[0] = ifx declared.sha256[0] == #char "0" then #char "1" else #char "0"
if PreparationChildWait(*host, root, "fixture.middle", *child) != -1 ||
!AppHandleEqual(root, host.tree.active) || child.slot != -1 {
return 767
}
declared.sha256 = correct
// Cancel is a nonblocking poll; subsequent collection releases the job.
PreparationTestBlock(true)
if AppHostOpenChild(*host, root, "fixture.middle", *child) != 0 || !PreparationParserWait() {
PreparationTestBlock(false)
return 768
}
AppHostCancelChild(*host)
if host.preparation == null || !host.preparation_canceled || !Draw(*host, 800, 600) {
PreparationTestBlock(false)
return 769
}
PreparationTestBlock(false)
end = PreparationTestNow() + 10.0
while host.preparation != null && PreparationTestNow() < end {
AppHostCollect(*host)
PreparationTestYield()
}
if host.preparation != null || !AppHostStop(*host) ||
PreparationTestLive() != live || PreparationTestFrameOpens() != frame_opens {
return 770
}
return 0
}
locator_maximum_poll: float64;
PreparationLocatorPoll :: (host: *AppHost, locator: *AppLocator) -> s32 {
started := PreparationTestNow()
result := AppHostOpenLocator(host, locator)
elapsed := PreparationTestNow() - started
if elapsed > locator_maximum_poll {
locator_maximum_poll = elapsed
}
return result
}
PreparationLocatorWait :: (host: *AppHost, locator: *AppLocator, source: AppHandle) -> s32 {
end := PreparationTestNow() + 10.0
result: s32 = 0
while result == 0 && PreparationTestNow() < end {
result = PreparationLocatorPoll(host, locator)
if result == 0 && !AppHandleEqual(source, host.tree.active) {
return -2
}
AppHostCollect(host)
PreparationTestYield()
}
return result
}
PreparationLocatorStaged :: (host: *AppHost, locator: *AppLocator) -> bool {
source := host.tree.active
end := PreparationTestNow() + 10.0
while host.navigation.staged.count == 0 && PreparationTestNow() < end {
if PreparationLocatorPoll(host, locator) != 0 || !AppHandleEqual(source, host.tree.active) {
return false
}
AppHostCollect(host)
PreparationTestYield()
}
return host.navigation.staged.count == 1 && host.preparation == null
}
PreparationLocatorCheck :: (bytes: string, digest: string, harness_digest: string,
platform: AppPlatform) -> s32 {
live := PreparationTestLive()
preparation := AppPrepare(bytes, digest, "fixture.root")
host: AppHost
if preparation == null || !PreparationWait(preparation) ||
!AppHostStartPrepared(*host, preparation, "fixture.test", "fixture.root", "collection",
"account-a", platform, harness_digest) || !AppPreparationClose(preparation) {
return 780
}
root := host.tree.active
root_bytes := host.tree.bytes
middle: AppHandle
child: AppHandle
locator: AppLocator
if PreparationChildWait(*host, root, "fixture.middle", *middle) != 1 ||
PreparationChildWait(*host, middle, "fixture.counter", *child) != 1 ||
!AppTreeLocate(*host.tree, child, *locator) || locator.chain.count != 3 {
return 781
}
AppTreeDrop(*host.tree, child)
AppTreeDrop(*host.tree, middle)
AppHostCollect(*host)
started := PreparationTestNow()
if !AppTreeOpenLocator(*host.tree, *locator) {
return 782
}
synchronous := PreparationTestNow() - started
if AppHostBack(*host) != 1 || AppHostBack(*host) != 1 || !AppHandleEqual(root, host.tree.active) {
return 783
}
AppHostCollect(*host)
frame_opens := PreparationTestFrameOpens()
locator_maximum_poll = 0.0
PreparationTestBlock(true)
if PreparationLocatorPoll(*host, *locator) != 0 || !PreparationParserWait() {
PreparationTestBlock(false)
return 784
}
for frame: cast(s32)0..99 {
if PreparationLocatorPoll(*host, *locator) != 0 || !AppHandleEqual(root, host.tree.active) {
PreparationTestBlock(false)
return 785
}
}
if !Draw(*host, 800, 600) || !Draw(*host, 360, 640) {
PreparationTestBlock(false)
return 786
}
PreparationTestBlock(false)
if PreparationLocatorWait(*host, *locator, root) != 1 || !AppHostAtLocator(*host, *locator) ||
!Command(*host, "read") || host.last_reply != stored {
return 787
}
// Selecting the current page performs no save, parse or VM replacement.
active := host.tree.active
opens := PreparationTestOpens()
flush_failed = true
for frame: cast(s32)0..99 {
if PreparationLocatorPoll(*host, *locator) != 1 || !AppHandleEqual(active, host.tree.active) {
return 788
}
}
flush_failed = false
if PreparationTestOpens() != opens || AppHostBack(*host) != 1 || AppHostBack(*host) != 1 {
return 789
}
AppHostCollect(*host)
flush_failed = true
if PreparationLocatorWait(*host, *locator, root) != -1 || !AppHandleEqual(root, host.tree.active) {
return 790
}
flush_failed = false
AppHostCollect(*host)
if host.tree.bytes != root_bytes || host.tree.nodes.count != 1 || host.retired != null {
return 791
}
correct := locator.chain[2].sha256
locator.chain[2].sha256[0] = ifx locator.chain[2].sha256[0] == #char "0" then #char "1" else #char "0"
if PreparationLocatorWait(*host, *locator, root) != -1 || !AppHandleEqual(root, host.tree.active) {
return 792
}
locator.chain[2].sha256 = correct
// Interactive navigation wins. Collection must preserve the canceled
// request's rejection so a later poll cannot silently restart it.
PreparationTestBlock(true)
if PreparationLocatorPoll(*host, *locator) != 0 || !PreparationParserWait() ||
!Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.middle\"}") {
PreparationTestBlock(false)
return 793
}
PreparationTestBlock(false)
if !PreparationNavigationWait(*host, root) {
return 794
}
AppHostCollect(*host)
active = host.tree.active
if !host.navigation.canceled || PreparationLocatorPoll(*host, *locator) != -1 ||
!AppHandleEqual(active, host.tree.active) || host.navigation.next_child != 0 || AppHostBack(*host) != 1 {
return 795
}
AppHostCollect(*host)
// An obsolete account request is rejected before saving or activating.
PreparationTestBlock(true)
if PreparationLocatorPoll(*host, *locator) != 0 || !PreparationParserWait() {
PreparationTestBlock(false)
return 796
}
host.tree.account_epoch += 1
AppHostCollect(*host)
if !host.navigation.canceled || PreparationLocatorPoll(*host, *locator) != -1 ||
!AppHandleEqual(root, host.tree.active) {
PreparationTestBlock(false)
return 797
}
PreparationTestBlock(false)
end := PreparationTestNow() + 10.0
while host.preparation != null && PreparationTestNow() < end {
AppHostCollect(*host)
PreparationTestYield()
}
if host.preparation != null {
return 798
}
// Returning to the page already visible cancels a pending favorite
// immediately, even while its parser still borrows the root's bytes.
root_locator: AppLocator
if !AppTreeLocate(*host.tree, root, *root_locator) {
return 808
}
PreparationTestBlock(true)
if PreparationLocatorPoll(*host, *locator) != 0 || !PreparationParserWait() ||
PreparationLocatorPoll(*host, *root_locator) != 1 ||
!AppHandleEqual(root, host.tree.active) || host.preparation == null ||
!host.preparation_canceled || host.navigation.next_child != 0 || !Draw(*host, 360, 640) {
PreparationTestBlock(false)
return 809
}
AppLocatorClear(*root_locator)
PreparationTestBlock(false)
end = PreparationTestNow() + 10.0
while host.preparation != null && PreparationTestNow() < end {
AppHostCollect(*host)
PreparationTestYield()
}
if host.preparation != null || host.tree.bytes != root_bytes {
return 810
}
// Native discovery cannot replace the favorite's worker. Back cancels
// the favorite even at the root, where no active route changes.
PreparationTestBlock(true)
if PreparationLocatorPoll(*host, *locator) != 0 || !PreparationParserWait() ||
AppHostOpenChild(*host, root, "fixture.middle", *child) != 0 ||
child.slot != -1 || AppHostBack(*host) != 0 || !host.navigation.canceled ||
PreparationLocatorPoll(*host, *locator) != -1 || !AppHandleEqual(root, host.tree.active) {
PreparationTestBlock(false)
return 811
}
PreparationTestBlock(false)
end = PreparationTestNow() + 10.0
while host.preparation != null && PreparationTestNow() < end {
AppHostCollect(*host)
PreparationTestYield()
}
if host.preparation != null || host.tree.bytes != root_bytes {
return 812
}
// Cancel while a worker borrows a staged parent's bytes. The parent
// retires immediately, but its storage stays until that worker finishes.
if !PreparationLocatorStaged(*host, *locator) {
return 799
}
PreparationTestBlock(true)
if PreparationLocatorPoll(*host, *locator) != 0 || !PreparationParserWait() {
PreparationTestBlock(false)
return 800
}
AppHostCancelLocator(*host)
AppHostCollect(*host)
if host.retired == null || host.preparation == null || !Draw(*host, 360, 640) ||
PreparationLocatorPoll(*host, *locator) != -1 || !AppHandleEqual(root, host.tree.active) {
PreparationTestBlock(false)
return 801
}
PreparationTestBlock(false)
end = PreparationTestNow() + 10.0
while host.preparation != null && PreparationTestNow() < end {
AppHostCollect(*host)
PreparationTestYield()
}
if host.preparation != null || host.retired != null || host.tree.bytes != root_bytes {
return 802
}
if !PreparationLocatorStaged(*host, *locator) {
return 803
}
PreparationTestBlock(true)
if PreparationLocatorPoll(*host, *locator) != 0 || !PreparationParserWait() {
PreparationTestBlock(false)
return 804
}
started = PreparationTestNow()
for frame: cast(s32)0..99 {
if AppHostStop(*host) || host.tree.nodes.count == 0 {
PreparationTestBlock(false)
return 805
}
}
if PreparationTestNow() - started > 0.05 {
PreparationTestBlock(false)
return 806
}
PreparationTestBlock(false)
end = PreparationTestNow() + 10.0
stopped := false
while !stopped && PreparationTestNow() < end {
stopped = AppHostStop(*host)
PreparationTestYield()
}
AppLocatorClear(*locator)
if !stopped || PreparationTestLive() != live || PreparationTestFrameOpens() != frame_opens ||
locator_maximum_poll > 0.05 {
print("Preparation stop: stopped=%, live=%/%, frame opens=%/%, maximum poll=% ms\n",
stopped, PreparationTestLive(), live, PreparationTestFrameOpens(), frame_opens,
locator_maximum_poll * 1000.0)
return 807
}
PreparationTestLocatorTiming(synchronous, locator_maximum_poll)
return 0
}
cached_base: string;
cached_addon: string;
cached_resident: [2]bool;
cached_pending: [2]bool;
cached_restores: s32;
CachedIndex :: (entry: *AppEntry) -> s32 {
id := TextUntilNul(entry.id[:])
if id == "fixture.counter" { return 0 }
if id == "fixture.addon" { return 1 }
return -1
}
CachedBundle :: (context: *void, parent: *AppNode, entry: *AppEntry) -> HostedAsset {
index := CachedIndex(entry)
if index < 0 || !cached_resident[index] { return HostedAsset.{} }
return HostedAsset.{.found = true, .data = ifx index == 0 then cached_base else cached_addon}
}
CachedDownload :: (context: *void, parent: *AppNode, entry: *AppEntry, download: *AppDownload) -> bool {
index := CachedIndex(entry)
if index < 0 || cached_resident[index] { return false }
download.cached = true
download.downloading = cached_pending[index]
return true
}
CachedFetch :: (context: *void, account: string, parent: *AppNode, entry: *AppEntry,
operation: s32, reply: *AppsReply) -> bool {
index := CachedIndex(entry)
if index < 0 || operation != APPS_INSTALL { return false }
if !cached_pending[index] { cached_restores += 1 }
cached_pending[index] = true
reply.status = APPS_QUEUED
return true
}
BundleOwnershipCheck :: () -> s32 {
bytes, found := ReadEntireFile(FixtureEnvironment("APPS_FIXTURE_CACHED_ROOT_BUNDLE"))
base, base_found := ReadEntireFile(FixtureEnvironment("APPS_FIXTURE_COUNTER_BUNDLE"))
addon, addon_found := ReadEntireFile(FixtureEnvironment("APPS_FIXTURE_ADDON_BUNDLE"))
duplicate, duplicate_found := ReadEntireFile(FixtureEnvironment("APPS_FIXTURE_COUNTER_BUNDLE"))
if !found || !base_found || !addon_found || !duplicate_found { return 1300 }
defer { AppFileFree(bytes); AppFileFree(base); AppFileFree(addon); AppFileFree(duplicate) }
cached_base = base
cached_addon = addon
cached_resident[0] = false
cached_resident[1] = false
cached_pending[0] = false
cached_pending[1] = false
cached_restores = 0
host: AppHost
defer { PreparationTestBlock(false); unused SlimStop(*host) }
platform := AppPlatform.{.host_api = TEST_HOST_API, .allows = Allows, .call = Call,
.widgets = Widgets, .save = Save, .state = State, .bundle = CachedBundle,
.download = CachedDownload, .fetch = CachedFetch}
digest := FixtureEnvironment("APPS_FIXTURE_CACHED_ROOT_SHA256")
harness := FixtureEnvironment("APPS_FIXTURE_HARNESS_SHA256")
if !AppHostStart(*host, bytes, "fixture.test", "fixture.cached", "collection", digest,
"account-a", platform, harness) { return 1301 }
root := AppTreeNode(*host.tree, host.tree.active)
runtime := cast(*AppRuntime)root.runtime
// Shelf probes see verified files, but never cause resident reloads.
for frame: cast(s32)0..9 {
card := CatalogCard(AppArgumentText(AppHostCatalog(runtime.frontend)), "fixture.addon")
if TextHas(card, "\"on_device\":false") || TextHas(card, "\"installed\":false") ||
cached_restores != 0 || AppHostBorrowsBundle(*host, base) ||
AppHostBorrowsBundle(*host, addon) { return 1302 }
}
if !AppHostBorrowsBundle(*host, bytes) || AppHostBorrowsBundle(*host, duplicate) { return 1303 }
// An actual open restores its dependency, then its own package, without
// another consent dialog or attempting to parse absent storage.
if !Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.addon\"}") ||
cached_restores != 1 || !cached_pending[0] || host.preparation != null { return 1304 }
cached_resident[0] = true
cached_pending[0] = false
unused AppTreeDrain(*host.tree)
if cached_restores != 2 || !cached_pending[1] || host.preparation != null { return 1305 }
cached_resident[1] = true
cached_pending[1] = false
PreparationTestBlock(true)
unused AppTreeDrain(*host.tree)
if !PreparationParserWait() || !AppHostBorrowsBundle(*host, base) ||
!AppHostBorrowsBundle(*host, addon) || AppHostBorrowsBundle(*host, duplicate) { return 1306 }
// Canceled workers retain every input until the parser is actually done.
if AppHostStop(*host) || !AppHostBorrowsBundle(*host, base) ||
!AppHostBorrowsBundle(*host, addon) { return 1307 }
AppHostCollect(*host)
if !AppHostBorrowsBundle(*host, base) || !AppHostBorrowsBundle(*host, addon) { return 1308 }
PreparationTestBlock(false)
if !SlimStop(*host) || AppHostBorrowsBundle(*host, base) ||
AppHostBorrowsBundle(*host, addon) || AppHostBorrowsBundle(*host, bytes) { return 1309 }
if !AppHostStart(*host, bytes, "fixture.test", "fixture.cached", "collection", digest,
"account-a", platform, harness) { return 1310 }
root_handle := host.tree.active
base_handle: AppHandle
if PreparationChildWait(*host, root_handle, "fixture.counter", *base_handle) != 1 { return 1311 }
base_node := AppTreeNode(*host.tree, base_handle)
base_runtime := cast(*AppRuntime)base_node.runtime
if !Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.addon\"}") ||
!PreparationNavigationWait(*host, root_handle) { return 1312 }
runtime = AppHostActiveRuntime(*host)
if runtime.dependency_count != 1 || runtime.dependency_owners[0] != base_runtime ||
base_runtime.dependency_leases != 1 || !AppHostBorrowsBundle(*host, base[4:24]) ||
AppHostBorrowsBundle(*host, duplicate) { return 1313 }
// Navigation-inactive and even retired dependencies remain borrowed by the
// live add-on. Collection cannot release their storage or original charge.
AppTreeDrop(*host.tree, base_handle)
AppHostCollect(*host)
if !AppHostBorrowsBundle(*host, base) || !AppHostBorrowsBundle(*host, addon) ||
host.retired == null { return 1314 }
host.tree.busy = true
guarded := AppHostBorrowsBundle(*host, duplicate)
host.tree.busy = false
if !guarded { return 1315 }
if AppHostBack(*host) != 1 || !AppHostBorrowsBundle(*host, base) ||
!AppHostBorrowsBundle(*host, addon) { return 1316 }
// Paint still has its source before Collect, then both leases retire.
AppHostCollect(*host)
if AppHostBorrowsBundle(*host, base) || AppHostBorrowsBundle(*host, addon) ||
!AppHostBorrowsBundle(*host, bytes) || host.retired != null || cached_restores != 2 { return 1317 }
if !SlimStop(*host) || AppHostBorrowsBundle(*host, bytes) { return 1318 }
cached_base = ""
cached_addon = ""
return 0
}
remote_bytes: string;
remote_fetches: s32;
RemoteBundle :: (context: *void, parent: *AppNode, entry: *AppEntry) -> HostedAsset {
if TextUntilNul(entry.id[:]) != "fixture.remote" || remote_bytes.count == 0 { return HostedAsset.{} }
return HostedAsset.{.found = true, .data = remote_bytes}
}
RemoteDownload :: (context: *void, parent: *AppNode, entry: *AppEntry, download: *AppDownload) -> bool {
if TextUntilNul(entry.id[:]) != "fixture.remote" || remote_bytes.count > 0 { return false }
download.downloading = remote_fetches > 0
download.bytes = 4096
download.progress = ifx remote_fetches > 0 then 40 else -1
return true
}
RemoteFetch :: (context: *void, account: string, parent: *AppNode, entry: *AppEntry,
operation: s32, reply: *AppsReply) -> bool {
if TextUntilNul(entry.id[:]) != "fixture.remote" || remote_bytes.count > 0 || operation != APPS_INSTALL { return false }
remote_fetches += 1
reply.status = APPS_QUEUED
return true
}
// The card text of one child in a catalog reply.
CatalogCard :: (catalog: string, id: string) -> string {
needle := TextJoinForTest("{\"id\":\"", id)
at: s64 = 0
while at + needle.count <= catalog.count && catalog[at:at + needle.count] != needle { at += 1 }
if at + needle.count > catalog.count { return "" }
end := at + 1
while end + 6 <= catalog.count && catalog[end:end + 6] != "{\"id\":" { end += 1 }
return catalog[at:ifx end + 6 <= catalog.count then end else catalog.count]
}
TextJoinForTest :: (left: string, right: string) -> string {
out: Vec(u8)
BuilderPrint(*out, "%", left)
BuilderPrint(*out, "%", right)
BuilderPrint(*out, "\"")
return BuilderFinish(out)
}
TextHas :: (text: string, needle: string) -> bool {
at: s64 = 0
while at + needle.count <= text.count {
if text[at:at + needle.count] == needle { return true }
at += 1
}
return false
}
DependencyCodeCheck :: () -> s32 {
bytes, found := ReadEntireFile(FixtureEnvironment("APPS_FIXTURE_THIN_ROOT_BUNDLE"))
if !found { return 134 }
defer { AppFileFree(bytes) }
live := PreparationTestLive()
platform := AppPlatform.{.host_api = TEST_HOST_API, .allows = Allows, .call = Call, .widgets = Widgets, .save = Save, .state = State}
for corrupt: cast(s32)0..1 {
host: AppHost
if !AppHostStart(*host, bytes, "fixture.test", "fixture.thin", "collection",
FixtureEnvironment("APPS_FIXTURE_THIN_ROOT_SHA256"), "account-a", platform,
FixtureEnvironment("APPS_FIXTURE_HARNESS_SHA256")) { return 135 }
root := AppTreeNode(*host.tree, host.tree.active)
if corrupt == 1 {
base := AppCatalogAt(*root.catalog, 0)
base.sha256[0] = ifx base.sha256[0] == #char "a" then #char "b" else #char "a"
}
unused Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.addon\"}")
deadline := PreparationTestNow() + 10.0
while AppTreeNode(*host.tree, host.tree.active) == root && PreparationTestNow() < deadline {
unused AppTreeDrain(*host.tree)
AppHostCollect(*host)
if host.tree.pending.count > 0 && host.tree.pending[host.tree.pending.count - 1].complete { break }
PreparationTestYield()
}
if corrupt == 0 {
if AppTreeNode(*host.tree, host.tree.active) == root { return 136 }
runtime := AppHostActiveRuntime(*host)
if runtime.dependency_count != 1 { return 137 }
runtime.app.command = "shared"
if !AppHostRun(*host, APP_COMMAND) || runtime.app.reply != "shared code" { return 138 }
} else if host.tree.nodes.count != 1 { return 139 }
if !AppHostStop(*host) || PreparationTestLive() != live { return 140 }
}
return 0
}
DependencyAssetsCheck :: () -> s32 {
bytes, found := ReadEntireFile(FixtureEnvironment("APPS_FIXTURE_DEPENDENCY_ROOT_BUNDLE"))
if !found { return 127 }
defer { AppFileFree(bytes) }
live := PreparationTestLive()
platform := AppPlatform.{.host_api = TEST_HOST_API, .allows = Allows, .call = Call, .widgets = Widgets, .save = Save, .state = State}
for corrupt: cast(s32)0..1 {
host: AppHost
if !AppHostStart(*host, bytes, "fixture.test", "fixture.dependencies", "collection",
FixtureEnvironment("APPS_FIXTURE_DEPENDENCY_ROOT_SHA256"), "account-a", platform,
FixtureEnvironment("APPS_FIXTURE_HARNESS_SHA256")) { return 128 }
root := AppTreeNode(*host.tree, host.tree.active)
if corrupt == 1 {
base := AppCatalogAt(*root.catalog, 0)
base.sha256[0] = ifx base.sha256[0] == #char "a" then #char "b" else #char "a"
}
unused Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.editor\"}")
if corrupt == 0 {
editor := AppTreeNode(*host.tree, host.tree.active)
if editor == root { return 129 }
resource := AppHostAsset(editor, "assets/counter/shared.wav")
if !resource.found || resource.data.count < 4 || resource.data[:4] != "RIFF" ||
AppHostAsset(editor, "assets/other/sound.wav").found { return 130 }
} else if host.tree.nodes.count != 1 { return 131 }
if !AppHostStop(*host) || PreparationTestLive() != live { return 132 }
}
return 0
}
// A game its collection only declares is downloaded on its own: its card says
// it is not on the device, Install fetches it without opening anything, and
// it opens only from the platform's bytes that match the catalog digest.
DeclaredChildCheck :: () -> s32 {
bytes, found := ReadEntireFile(FixtureEnvironment("APPS_FIXTURE_REMOTE_ROOT_BUNDLE"))
counter, counter_found := ReadEntireFile(FixtureEnvironment("APPS_FIXTURE_COUNTER_BUNDLE"))
other, other_found := ReadEntireFile(FixtureEnvironment("APPS_FIXTURE_NODE_BUNDLE"))
if !found || !counter_found || !other_found { return 900 }
// Without the open effect, which inspects the main check's host.
platform := AppPlatform.{.host_api = TEST_HOST_API, .allows = Allows, .call = Call, .widgets = Widgets, .save = Save, .effect = Effect,
.state = State, .bundle = RemoteBundle, .download = RemoteDownload, .fetch = RemoteFetch}
host: AppHost
if !AppHostStart(*host, bytes, "fixture.test", "fixture.remote-root", "collection",
FixtureEnvironment("APPS_FIXTURE_REMOTE_ROOT_SHA256"), "account-a", platform,
FixtureEnvironment("APPS_FIXTURE_HARNESS_SHA256")) { return 901 }
root := AppTreeNode(*host.tree, host.tree.active)
runtime := cast(*AppRuntime)root.runtime
// As once native discovery has run: queued requests prepare first.
host.tree.provider.prepare = AppHostPrepareChild
catalog := AppArgumentText(AppHostCatalog(runtime.frontend))
remote := CatalogCard(catalog, "fixture.remote")
packed := CatalogCard(catalog, "fixture.counter")
if !TextHas(remote, "\"on_device\":false") || !TextHas(remote, "\"downloading\":false") || !TextHas(remote, "\"bytes\":4096") ||
packed == "" || TextHas(packed, "on_device") { return 902 }
// Not on the device: Open verifies nothing and opens nothing.
unused Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.remote\"}")
if host.tree.nodes.count != 1 { return 903 }
if !Command(*host, "{\"v\":1,\"op\":\"install\",\"id\":\"fixture.remote\"}") || remote_fetches != 1 ||
host.tree.nodes.count != 1 || host.retired_bytes != 0 { return 904 }
remote = CatalogCard(AppArgumentText(AppHostCatalog(runtime.frontend)), "fixture.remote")
if !TextHas(remote, "\"downloading\":true,\"progress\":40") { return 905 }
// Downloaded bytes that are not the declared game never open.
remote_bytes = other
unused Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.remote\"}")
if host.tree.nodes.count != 1 || AppHostActiveRuntime(*host) != runtime { return 906 }
AppHostCollect(*host)
remote_bytes = counter
remote = CatalogCard(AppArgumentText(AppHostCatalog(runtime.frontend)), "fixture.remote")
if remote == "" || TextHas(remote, "on_device") { return 907 }
if !Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.remote\"}") { return 908 }
// Preparation opens it on a worker; later frames finish the open.
deadline := PreparationTestNow() + 10.0
while host.tree.nodes.count != 2 && PreparationTestNow() < deadline {
unused AppTreeDrain(*host.tree)
PreparationTestYield()
}
if host.tree.nodes.count != 2 { return 911 }
opened := AppTreeNode(*host.tree, host.tree.active)
if opened == null || TextUntilNul(opened.identity.id[:]) != "fixture.remote" { return 909 }
end := PreparationTestNow() + 10.0
stopped := false
while !stopped && PreparationTestNow() < end {
stopped = AppHostStop(*host)
PreparationTestYield()
}
remote_bytes = ""
if !stopped { return 910 }
return 0
}
slim_controller: string;
slim_art: string;
slim_art_fetches: s32;
SlimController :: (context: *void) -> HostedAsset {
return HostedAsset.{.found = slim_controller.count > 0, .data = slim_controller}
}
SlimBundle :: (context: *void, parent: *AppNode, entry: *AppEntry) -> HostedAsset {
if TextUntilNul(entry.bundle[:]) != "assets/apps/art.zx" || slim_art.count == 0 { return HostedAsset.{} }
return HostedAsset.{.found = true, .data = slim_art}
}
SlimFetch :: (context: *void, account: string, parent: *AppNode, entry: *AppEntry,
operation: s32, reply: *AppsReply) -> bool {
if TextUntilNul(entry.bundle[:]) != "assets/apps/art.zx" || operation != APPS_INSTALL { return false }
slim_art_fetches += 1
reply.status = APPS_QUEUED
return true
}
SlimStop :: (host: *AppHost) -> bool {
end := PreparationTestNow() + 10.0
stopped := false
while !stopped && PreparationTestNow() < end {
stopped = AppHostStop(host)
PreparationTestYield()
}
return stopped
}
// A collection like Arcade's: it packs neither the Apps controller, which the
// host supplies by its exact digest, nor its children's art, which arrives
// as one separate bundle the platform downloads like a child.
SlimCollectionCheck :: () -> s32 {
bytes, found := ReadEntireFile(FixtureEnvironment("APPS_FIXTURE_SLIM_ROOT_BUNDLE"))
ui, ui_found := ReadEntireFile(FixtureEnvironment("APPS_FIXTURE_UI_BUNDLE"))
art, art_found := ReadEntireFile(FixtureEnvironment("APPS_FIXTURE_ART_BUNDLE"))
if !found || !ui_found || !art_found { return 1200 }
digest := FixtureEnvironment("APPS_FIXTURE_SLIM_ROOT_SHA256")
harness := FixtureEnvironment("APPS_FIXTURE_HARNESS_SHA256")
platform := AppPlatform.{.host_api = TEST_HOST_API, .allows = Allows, .call = Call, .widgets = Widgets, .save = Save,
.state = State, .bundle = SlimBundle, .fetch = SlimFetch}
// Without a host controller the collection cannot open.
refused: AppHost
if AppHostStart(*refused, bytes, "fixture.test", "fixture.slim", "collection", digest, "account-a", platform, harness) {
unused SlimStop(*refused)
return 1201
}
// Other bytes in the controller's place are refused.
platform.controller = SlimController
slim_controller = art
other: AppHost
if AppHostStart(*other, bytes, "fixture.test", "fixture.slim", "collection", digest, "account-a", platform, harness) {
unused SlimStop(*other)
return 1202
}
slim_controller = ui
host: AppHost
if !AppHostStart(*host, bytes, "fixture.test", "fixture.slim", "collection", digest, "account-a", platform, harness) {
return 1203
}
root := AppTreeNode(*host.tree, host.tree.active)
if !AppHostBorrowsBundle(*host, ui) || AppHostBorrowsBundle(*host, art) { return 1210 }
// The art is missing until it arrives; the first request asks for it once.
if AppHostAsset(root, "assets/preview.png").found || slim_art_fetches != 1 ||
!AppHostAssetPending(root, "assets/preview.png") || AppHostAssetPending(root, "../preview.png") { unused SlimStop(*host); return 1204 }
unused AppHostAsset(root, "assets/preview.png")
if slim_art_fetches != 1 { unused SlimStop(*host); return 1205 }
// Bytes that are not the catalog's art never open.
slim_art = ui
if AppHostAsset(root, "assets/preview.png").found { unused SlimStop(*host); return 1206 }
// A corrected copy is accepted once the retry wait ends.
slim_art = art
preview: HostedAsset
art_end := PreparationTestNow() + 10.0
while !preview.found && PreparationTestNow() < art_end {
preview = AppHostAsset(root, "assets/preview.png")
PreparationTestYield()
}
if !preview.found || preview.data.count < 8 || preview.data[1:4] != "PNG" ||
AppHostAssetPending(root, "assets/missing.png") { unused SlimStop(*host); return 1207 }
if !AppHostBorrowsBundle(*host, art) { return 1211 }
if !SlimStop(*host) { return 1208 }
if AppHostBorrowsBundle(*host, art) || AppHostBorrowsBundle(*host, ui) { return 1212 }
slim_controller = ""
slim_art = ""
return 0
}
dependency_installed: bool;
dependency_fetches: s32;
dependency_queued: bool;
dependency_first: [128]u8;
DependencyCatalog :: (catalog: *AppCatalog, base_dependencies: string = "", required: string = "game", source: string = "assets/game/sprites/") -> bool {
bytes: Vec(u8)
BuilderPrint(*bytes, "{\"schema\":1,\"id\":\"collection\",\"title\":\"Games\",\"harness\":\"assets/apps.zx\",\"children\":[")
BuilderPrint(*bytes, "{\"id\":\"game\",\"title\":\"Original\",\"bundle\":\"assets/game.zx\",\"protocol\":\"node/2\",\"expected_id\":\"game\",\"version\":\"1\",\"sha256\":\"%\"%},", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", base_dependencies)
BuilderPrint(*bytes, "{\"id\":\"editor\",\"title\":\"Editor\",\"bundle\":\"assets/editor.zx\",\"protocol\":\"node/2\",\"expected_id\":\"editor\",\"version\":\"1\",\"sha256\":\"%\",\"dependencies\":[\"%\"],\"resources\":[{\"dependency\":\"%\",\"path\":\"assets/editor/shared/\",\"source\":\"%\"}]}]}", "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", required, required, source)
result := AppCatalogRead(TextView(VecSlice(bytes, 0, bytes.count)), "collection", catalog)
VecFree(bytes)
return result
}
DependencyDownload :: (context: *void, parent: *AppNode, entry: *AppEntry, download: *AppDownload) -> bool {
if TextUntilNul(entry.id[:]) == "game" {
if dependency_installed { return false }
download.bytes = 100
} else { download.bytes = 40 }
download.progress = -1
return true
}
DependencyFetch :: (context: *void, account: string, parent: *AppNode, entry: *AppEntry, operation: s32, reply: *AppsReply) -> bool {
if dependency_fetches == 0 { dependency_first = entry.id }
dependency_fetches += 1
reply.status = ifx dependency_queued then APPS_QUEUED else APPS_APPLIED
return true
}
shared_record_reads: s32;
shared_record_denied: bool;
SharedRecordAllows :: (context: *void, node: *AppNode, function: string) -> bool {
return !shared_record_denied && function == "AppRecordHost" &&
TextUntilNul(node.identity.authority[:]) == "trusted.test" && TextUntilNul(node.identity.id[:]) == "game"
}
SharedRecordCall :: (context: *void, node: *AppNode, module: *u8, function: *u8,
arguments: *HostValue, count: s32, result: *HostValue) -> s32 {
if !SharedRecordAllows(context, node, TextFromCString(function)) || count != 1 ||
AppArgumentText(arguments[0]) != "local.campaign" { return 0 }
shared_record_reads += 1
result.* = AppHostText("private \"board\"")
return 1
}
SharedRecordsCheck :: () -> s32 {
parent: AppNode
if !DependencyCatalog(*parent.catalog, ",\"shared_records\":[\"local.campaign\"]") { return 200 }
defer { AppCatalogClear(*parent.catalog) }
if DependencyCatalog(*parent.catalog, ",\"shared_records\":[\"../campaign\"]") ||
DependencyCatalog(*parent.catalog, ",\"shared_records\":[\"local.campaign\",\"local.campaign\"]") ||
DependencyCatalog(*parent.catalog, ",\"shared_records\":[]") { return 201 }
donor := AppCatalogAt(*parent.catalog, 0)
guest := AppNode.{.entry = AppCatalogAt(*parent.catalog, 1).*}
unused CopyCString("trusted.test", guest.identity.authority[:])
unused CopyCString("editor", guest.identity.id[:])
host: AppHost
host.platform.allows = SharedRecordAllows
host.platform.call = SharedRecordCall
runtime := AppRuntime.{.host = *host, .node = *guest, .dependency_count = 1}
runtime.dependency_entries[0] = donor
defer { AppFileFree(host.reply) }
if !AppHostAllows(cast(*void)*runtime, "apps.records") { return 202 }
answer := AppArgumentText(AppHostDependencyRecord(*runtime,
"{\"operation\":\"get\",\"app\":\"game\",\"record\":\"local.campaign\"}"))
text: [64]u8
if ReadStringText(answer, FieldAt(answer, 0, "text"), text[:]) < 0 ||
TextUntilNul(text[:]) != "private \"board\"" || shared_record_reads != 1 { return 203 }
requests: [5]string = .[
"{\"operation\":\"put\",\"app\":\"game\",\"record\":\"local.campaign\"}",
"{\"operation\":\"get\",\"app\":\"game\",\"record\":\"rewards\"}",
"{\"operation\":\"get\",\"app\":\"game\",\"record\":\"../local.campaign\"}",
"{\"operation\":\"get\",\"app\":\"other\",\"record\":\"local.campaign\"}",
"{\"operation\":\"get\",\"app\":\"game\",\"record\":\"local.campaign\",\"authority\":\"other\"}"
]
for request: requests {
unused AppHostDependencyRecord(*runtime, request)
if shared_record_reads != 1 { return 204 }
}
request := "{\"operation\":\"get\",\"app\":\"game\",\"record\":\"local.campaign\"}"
shared_record_denied = true
unused AppHostDependencyRecord(*runtime, request)
shared_record_denied = false
runtime.retired = true
unused AppHostDependencyRecord(*runtime, request)
runtime.retired = false
runtime.dependency_count = 0
unused AppHostDependencyRecord(*runtime, request)
runtime.dependency_count = 1
guest.entry.dependency_count = 0
unused AppHostDependencyRecord(*runtime, request)
guest.entry.dependency_count = 1
donor.shared_record_count = 0
unused AppHostDependencyRecord(*runtime, request)
if shared_record_reads != 1 { return 205 }
return 0
}
DependenciesCheck :: () -> s32 {
parent: AppNode
if !DependencyCatalog(*parent.catalog) { return 120 }
defer { AppCatalogClear(*parent.catalog) }
if DependencyCatalog(*parent.catalog, ",\"dependencies\":[\"editor\"]") || parent.catalog.count != 2 { return 121 }
// Bundle libraries are gone: a catalog naming the retired key is rejected.
if DependencyCatalog(*parent.catalog, ",\"shared_code\":true") { return 141 }
if DependencyCatalog(*parent.catalog, "", "missing") || parent.catalog.count != 2 { return 122 }
if DependencyCatalog(*parent.catalog, "", "game", "assets/other/sprites/") ||
DependencyCatalog(*parent.catalog, "", "game", "assets/game/../private/") { return 123 }
host: AppHost
host.platform.download = DependencyDownload
host.platform.fetch = DependencyFetch
editor := AppCatalogAt(*parent.catalog, 1)
plan: AppInstallPlan
if !AppHostInstallPlan(*host, *parent, editor, *plan) || plan.count != 2 ||
plan.download.bytes != 140 || TextUntilNul(plan.entries[0].id[:]) != "game" { return 124 }
reply: AppsReply
if !AppHostFetch(cast(*void)(*host), "local", *parent, editor, APPS_INSTALL, *reply) ||
reply.status != APPS_APPLIED || dependency_fetches != 2 || TextUntilNul(dependency_first[:]) != "game" { return 125 }
dependency_installed = true
if !AppHostInstallPlan(*host, *parent, editor, *plan) || plan.count != 1 || plan.download.bytes != 40 ||
TextUntilNul(plan.entries[0].id[:]) != "editor" { return 126 }
dependency_queued = true
dependency_fetches = 0
if !AppHostFetch(cast(*void)(*host), "local", *parent, editor, APPS_INSTALL, *reply) ||
reply.status != APPS_QUEUED || dependency_fetches != 1 { return 133 }
return 0
}
FrameInputBoundaryCheck :: (node: *NodeContext) -> s32 {
package_module := ""
for index: cast(u64)0..BundleCapabilities(node.app.bundle) - 1 {
if TextFromCString(BundleCapabilityFunctionName(node.app.bundle, index)) == "CaptureFrameInputHost" {
package_module = TextFromCString(BundleCapabilityModuleName(node.app.bundle, index))
}
}
if package_module == "" || !NodeAllows(cast(*void)node, package_module, "CaptureFrameInputHost") ||
!NodeAllows(cast(*void)node, "frame_snapshot", "CaptureFrameInputHost") ||
NodeAllows(cast(*void)node, "kryon_other", "CaptureFrameInputHost") ||
NodeAllows(cast(*void)node, "kryon_tree_input", "KeyboardTake") { return 80 }
arguments: [1]HostValue
result: HostValue
arguments[0] = WidgetEncodeSession(ui_session, *session_codec)
node.message.action = APP_FRAME
if NodeCall(cast(*void)node, HostTextData(package_module),
HostTextData("CaptureFrameInputHost"), *arguments[0], 1, *result) != 0 { return 81 }
foreign := SessionOpen()
sample: FrameInputSnapshot
sample.available = true
sample.focused = true
sample.sequence = cast(u64)1
sample.elapsed_ms = 239
sample.pointer = PointerFrame.{9.0, 12.0, true, true, false}
sample.keys[KeyLeft] = cast(u8)(FrameKeyHeld | FrameKeyPressed)
if !FrameInputBegin(ui_session, sample) { return 82 }
WidgetHostBegin(ui_session, AllowImage, ResolveImage)
arguments[0] = WidgetEncodeSession(foreign, *session_codec)
foreign_rejected := NodeCall(cast(*void)node, HostTextData("frame_snapshot"),
HostTextData("CaptureFrameInputHost"), *arguments[0], 1, *result) != 0
arguments[0] = WidgetEncodeSession(ui_session, *session_codec)
active_accepted := NodeCall(cast(*void)node, HostTextData(package_module),
HostTextData("CaptureFrameInputHost"), *arguments[0], 1, *result) == 1
WidgetHostEnd()
FrameInputEnd(ui_session)
unused SessionClose(foreign)
if foreign_rejected || !active_accepted { return 83 }
return 0
}
#program_export
Check :: () -> s32 {
shared_records_check := SharedRecordsCheck()
if shared_records_check != 0 { return shared_records_check }
dependencies := DependenciesCheck()
if dependencies != 0 { return dependencies }
PreparationTestBegin()
bytes, found := ReadEntireFile(FixtureEnvironment("APPS_FIXTURE_ROOT_BUNDLE"))
digest := FixtureEnvironment("APPS_FIXTURE_ROOT_SHA256")
harness_digest := FixtureEnvironment("APPS_FIXTURE_HARNESS_SHA256")
if !found { return 1 }
host: AppHost
platform := AppPlatform.{.host_api = TEST_HOST_API, .allows = Allows, .call = Call, .widgets = Widgets, .save = Save, .effect = Effect, .state = State, .version_effect = HostVersionEffect,
.open_effect = HostOpenEffect}
prepared := PreparationCheck(bytes, digest, harness_digest, platform)
if prepared != 0 {
return prepared
}
navigation := PreparationNavigationCheck(bytes, digest, harness_digest, platform)
if navigation != 0 {
return navigation
}
discovery := PreparationChildCheck(bytes, digest, harness_digest, platform)
if discovery != 0 {
return discovery
}
ownership := BundleOwnershipCheck()
if ownership != 0 { return ownership }
declared := DeclaredChildCheck()
if declared != 0 {
return declared
}
slim := SlimCollectionCheck()
if slim != 0 {
return slim
}
locator_result := PreparationLocatorCheck(bytes, digest, harness_digest, platform)
if locator_result != 0 {
return locator_result
}
shared := DependencyAssetsCheck()
if shared != 0 { return shared }
code := DependencyCodeCheck()
if code != 0 { return code }
if !AppHostStart(*host, bytes, "fixture.test", "fixture.root", "collection", digest, "account-a", platform, harness_digest) { return 2 }
root := AppTreeNode(*host.tree, host.tree.active)
runtime := cast(*AppRuntime)root.runtime
if runtime.controller || runtime.frontend == null || !runtime.frontend.controller { return 15 }
host.platform.presentation.cover_logo_width = 180.0
host.platform.presentation.cover_logo_top = 116.0
if !Draw(*host, 800, 600) || !Draw(*host, 360, 640) { return 28 }
languages: [12]string = .["cs", "de", "en", "es", "fr", "id", "it", "ja", "ko", "pt", "ru", "zh"]
for language: languages {
unused CopyCString(language, host.locale[:])
if !Draw(*host, 360, 640) { return 29 }
}
unused CopyCString("en", host.locale[:])
catalog_reply := AppHostCatalog(runtime.frontend)
catalog_text := AppArgumentText(catalog_reply)
presentation := FieldAt(catalog_text, 0, "presentation")
if ReadNumber(catalog_text, FieldAt(catalog_text, presentation, "cover_logo_width")).value != 180.0 ||
ReadNumber(catalog_text, FieldAt(catalog_text, presentation, "cover_logo_top")).value != 116.0 { return 201 }
children := FieldAt(catalog_text, 0, "children")
first := Space(catalog_text, children + 1)
// This host has not opted into content fetching, so the catalog hides
// automatic updates while preserving the provider's package inventory.
if !MatchLiteral(catalog_text, Space(catalog_text, FieldAt(catalog_text, first, "update_available")), "false") ||
ReadNumber(catalog_text, FieldAt(catalog_text, first, "bytes")).value != 12345.0 { return 66 }
// A controller holding the current catalog is not sent it again.
revision := cast(s64)ReadNumber(catalog_text, FieldAt(catalog_text, 0, "revision")).value
if revision < 1 || !MatchLiteral(AppArgumentText(AppHostCatalog(runtime.frontend, revision)), 0, "{\"v\":1,\"unchanged\":true}") ||
AppArgumentText(AppHostCatalog(runtime.frontend, revision + 1)) == "{\"v\":1,\"unchanged\":true}" { return 74 }
active_root := host.tree.active
if !Command(*host, "{\"v\":1,\"op\":\"update\",\"id\":\"fixture.middle\",\"version\":\"2.0\",\"sha256\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\"}") ||
host_version_calls != 1 || !AppHandleEqual(host.tree.active, active_root) { return 67 }
AppHostCollect(*host)
if !Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.middle\"}") || host.tree.nodes.count != 2 { return 3 }
middle := AppTreeNode(*host.tree, host.tree.active)
if TextUntilNul(middle.identity.id[:]) != "fixture.middle" { return 4 }
runtime = cast(*AppRuntime)middle.runtime
if !Draw(*host, 480, 600) || preview_second.x <= preview_first.x || preview_second.y != preview_first.y { return 30 }
light := first_card_fill
if !Draw(*host, 480, 600, true, true) { return 36 }
dark := first_card_fill
if cast(s32)dark.r + cast(s32)dark.g + cast(s32)dark.b >=
cast(s32)light.r + cast(s32)light.g + cast(s32)light.b { return 37 }
if !Draw(*host, 720, 900, true, false, 1.5) { return 38 }
if !Draw(*host, 360, 640) || preview_second.y <= preview_first.y { return 35 }
limit := host.tree.byte_limit
resource := AppHostAsset(middle, "assets/node.zx")
host.tree.byte_limit = host.tree.bytes + resource.data.count + 65536 + cast(s64)size_of(AppNode)
if !Command(*host, "{\"v\":1,\"op\":\"install\",\"id\":\"fixture.node\"}") || effect_calls != 1 || host.retired_bytes <= 0 { return 32 }
if !Command(*host, "{\"v\":1,\"op\":\"install\",\"id\":\"fixture.node\"}") || effect_calls != 1 { return 33 }
host.tree.byte_limit = limit
AppHostCollect(*host)
if host.retired_bytes != 0 { return 34 }
node_entry := AppCatalogAt(*middle.catalog, AppCatalogFind(*middle.catalog, "fixture.node")).*
unused CopyCString("other", node_entry.expected_id[:])
rejected := AppTreeOpenChild(*host.tree, host.tree.active, *node_entry)
if AppTreeNode(*host.tree, rejected) != null || AppHostActiveRuntime(*host) != runtime { return 31 }
// The node bundle's digest is remembered from its install above; a
// catalog entry declaring another digest for it still never opens.
node_entry = AppCatalogAt(*middle.catalog, AppCatalogFind(*middle.catalog, "fixture.node")).*
node_entry.sha256[0] = ifx node_entry.sha256[0] == #char "0" then #char "1" else #char "0"
rejected = AppTreeOpenChild(*host.tree, host.tree.active, *node_entry)
if AppTreeNode(*host.tree, rejected) != null || AppHostActiveRuntime(*host) != runtime { return 626 }
// Native OPEN boundary over real bundles: the counter's exact verified
// chain reaches the provider; HANDLED and REJECTED keep the middle page
// and retire only the temporary counter VM.
counter_entry := AppCatalogAt(*middle.catalog, AppCatalogFind(*middle.catalog, "fixture.counter"))
outcomes: [2]s32 = .[APP_OPEN_HANDLED, APP_OPEN_REJECTED]
for outcome: outcomes {
open_decision = outcome
calls := host_open_calls
if !Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.counter\"}") || host.tree.nodes.count != 2 ||
AppHostActiveRuntime(*host) != runtime || host.retired_bytes <= 0 || host_open_calls != calls + 1 ||
host_open_bad || host_open_chain != 3 || TextUntilNul(host_open_leaf[:]) != TextUntilNul(counter_entry.sha256[:]) { return 68 }
status := AppTreeQueue(*host.tree, host.tree.active, AppsRequest.{.operation = APPS_STATUS, .request = host.tree.sequence})
expected := ifx outcome == APP_OPEN_HANDLED then APPS_QUEUED else APPS_REJECTED
if status.status != expected || (outcome == APP_OPEN_HANDLED && TextUntilNul(status.receipt[:]) != "native-leaf") { return 69 }
AppHostCollect(*host)
if host.retired_bytes != 0 || !Draw(*host, 480, 600) { return 70 }
}
// A failed save or a declared digest mismatch never reaches the provider
// and opens no temporary child.
open_decision = APP_OPEN_HANDLED
calls := host_open_calls
flush_failed = true
unused Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.counter\"}")
flush_failed = false
if host_open_calls != calls || host.tree.nodes.count != 2 || host.retired_bytes != 0 || AppHostActiveRuntime(*host) != runtime { return 71 }
digest_first := counter_entry.sha256[0]
counter_entry.sha256[0] = ifx digest_first == #char "0" then #char "1" else #char "0"
unused Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.counter\"}")
counter_entry.sha256[0] = digest_first
if host_open_calls != calls || host.tree.nodes.count != 2 || host.retired_bytes != 0 || AppHostActiveRuntime(*host) != runtime { return 72 }
// DECLARED, the default, opens the verified counter exactly as before.
open_decision = APP_OPEN_DECLARED
if !Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.counter\"}") || host.tree.nodes.count != 3 ||
host_open_calls != calls + 1 || host_open_bad { return 5 }
child := host.tree.active
if !Command(*host, "read") || host.last_reply != "legacy saved value" { return 6 }
if !Command(*host, "write") || stored != "after" { return 7 }
locator: AppLocator
if !AppTreeLocate(*host.tree, host.tree.active, *locator) || locator.chain.count != 3 { return 8 }
flush_failed = true
unused AppTreeQueue(*host.tree, host.tree.active, AppsRequest.{.operation = APPS_BACK}); unused AppTreeDrain(*host.tree)
if !AppHandleEqual(host.tree.active, child) { return 9 }
flush_failed = false
unused AppTreeQueue(*host.tree, host.tree.active, AppsRequest.{.operation = APPS_BACK}); unused AppTreeDrain(*host.tree)
returned := AppTreeNode(*host.tree, host.tree.active)
if TextUntilNul(returned.identity.id[:]) != "fixture.middle" { return 10 }
// A direct favorite reopens the same verified leaf bytes and save owner.
if !AppTreeOpenLocator(*host.tree, *locator) || !Command(*host, "read") ||
host.last_reply != "after" { return 11 }
// Corrupt revision and wrong expected handshake leave the working leaf.
active := host.tree.active
locator.chain[2].sha256[0] = ifx locator.chain[2].sha256[0] == #char "0" then #char "1" else #char "0"
if AppTreeOpenLocator(*host.tree, *locator) || !AppHandleEqual(host.tree.active, active) { return 12 }
AppLocatorClear(*locator)
if AppHostBack(*host) != 1 { return 16 }
if !Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"fixture.node\"}") { return 17 }
runtime = AppHostActiveRuntime(*host)
if runtime.protocol != APPS_NODE_PROTOCOL { return 18 }
runtime.legacy.frame.width = 1
runtime.app.key = 42
runtime.app.input = .{.text = "hi", .backspace = true}
host_frame_input.available = true
host_frame_input.focused = true
host_frame_input.sequence = cast(u64)1
host_frame_input.elapsed_ms = 239
host_frame_input.pointer = PointerFrame.{9.0, 12.0, true, true, false}
host_frame_input.keys[KeyLeft] = cast(u8)(FrameKeyHeld | FrameKeyPressed)
if !Draw(*host, 1, 600, false) || node_stored != "node saved" ||
runtime.legacy.message.name != "node" || runtime.legacy.message.account != "" { return 19 }
if sound_calls != 1 { return 73 }
sound_enabled = false
runtime.legacy.frame.width = 2
runtime.app.input = .{}
host_frame_input = FrameInputSnapshot.{}
if !Draw(*host, 2, 600, false) || sound_calls != 1 { return 20 }
frame_input := FrameInputBoundaryCheck(*runtime.legacy)
if frame_input != 0 { return frame_input }
active = host.tree.active
runtime.legacy.message.screen = 42
if AppHostBack(*host) != 1 || !AppHandleEqual(host.tree.active, active) { return 21 }
runtime.legacy.message.screen = 0
flush_failed = true
if AppHostBack(*host) != -1 || !AppHandleEqual(host.tree.active, active) { return 22 }
flush_failed = false
if AppHostBack(*host) != 1 || AppHandleEqual(host.tree.active, active) { return 23 }
chess_digest := FixtureEnvironment("APPS_FIXTURE_CHESS_SHA256")
if chess_digest != "" {
if !Command(*host, "{\"v\":1,\"op\":\"open\",\"id\":\"inbe.chess\"}") { return 24 }
runtime = AppHostActiveRuntime(*host)
if runtime.protocol != APPS_NODE_PROTOCOL || TextUntilNul(runtime.node.entry.sha256[:]) != chess_digest { return 25 }
if !AppHostRoute(*host) { return 26 }
if AppHostBack(*host) != 1 { return 27 }
}
AppHostCollect(*host)
if !AppHostStop(*host) { return 13 }
if AppHostStart(*host, bytes, "fixture.test", "fixture.root", "wrong", digest, "account-a", platform, harness_digest) { return 14 }
// A collection published with an earlier controller opens only while
// the platform still trusts that controller.
newer := "0000000000000000000000000000000000000000000000000000000000000000"
untrusted: AppHost
if AppHostStart(*untrusted, bytes, "fixture.test", "fixture.root", "collection", digest, "account-a", platform, newer) { return 627 }
unused AppHostStop(*untrusted)
trusting: AppHost
earlier: [6]string = .[
"1111111111111111111111111111111111111111111111111111111111111111",
"2222222222222222222222222222222222222222222222222222222222222222",
"3333333333333333333333333333333333333333333333333333333333333333",
"4444444444444444444444444444444444444444444444444444444444444444",
"5555555555555555555555555555555555555555555555555555555555555555",
"6666666666666666666666666666666666666666666666666666666666666666"]
for previous: earlier {
if !AppHostTrustHarness(*trusting, previous) { return 630 }
}
if !AppHostTrustHarness(*trusting, harness_digest) || AppHostTrustHarness(*trusting, "not a digest") ||
AppHostTrustHarness(*trusting, newer) || !AppHostTrustHarness(*trusting, earlier[0]) ||
!AppHostStart(*trusting, bytes, "fixture.test", "fixture.root", "collection", digest, "account-a", platform, newer) { return 628 }
if !AppHostStop(*trusting) { return 629 }
return NativeControllerCheck()
}
// Independently runnable UI coverage; no host/library fixture is required.
#program_export
ControllerCheck :: () -> s32 {
PreparationTestBegin()
ui_session = SessionOpen()
if !SessionValid(ui_session) { return 50 }
defer { SessionClose(ui_session) }
return NativeControllerCheck()
}