508 lines
28 KiB
Ziran
508 lines
28 KiB
Ziran
#import "std/vec"
|
|
#import "std/c_string"
|
|
#import "std/text_buffer"
|
|
#import "std/byte_text_linux"
|
|
#import, file "../src/protocol.zi";
|
|
#import, file "../src/catalog.zi";
|
|
#import, file "../src/tree.zi";
|
|
#import, file "../src/connection.zi";
|
|
#import "kryon/app_files"
|
|
|
|
test_c :: #system_library "c";
|
|
TestEnvironment :: (name: *u8) -> *u8 #foreign test_c "getenv";
|
|
|
|
Environment :: (name: string) -> string {
|
|
key: [64]u8
|
|
if !CopyCString(name, key[:]) { return "" }
|
|
return TextFromCString(TestEnvironment(*key[0]))
|
|
}
|
|
|
|
DIGEST :: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
|
|
ROOT_DIGEST :: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
fail_save: bool;
|
|
fail_open: bool;
|
|
fail_effect: bool;
|
|
installed: bool;
|
|
pinned: bool;
|
|
records: s32 = 41;
|
|
closed: s32;
|
|
depth: s32;
|
|
version_calls: s32;
|
|
version_seen: AppsRequest;
|
|
saves: s32;
|
|
open_tree: *AppTree;
|
|
open_decision: s32 = APP_OPEN_DECLARED;
|
|
open_calls: s32;
|
|
open_saves: s32;
|
|
open_reentered: bool;
|
|
open_seen: AppsRequest;
|
|
open_copy: AppLocator;
|
|
open_package_override: string;
|
|
fetched_direct: bool;
|
|
|
|
UpdateState :: (installed: bool) -> AppState {
|
|
state := AppState.{.installed = installed, .actions_known = true,
|
|
.actions = cast(u64)4092, .update_available = true}
|
|
unused CopyCString("2.0", state.available_version[:])
|
|
unused CopyCString(DIGEST, state.available_sha256[:])
|
|
return state
|
|
}
|
|
|
|
MakeCatalog :: (node: *AppNode, id: string, child: string, protocol: string = "app/1") -> bool {
|
|
bytes: Vec(u8)
|
|
BuilderPrint(*bytes, "{\"schema\":1,\"id\":\"%\",\"title\":\"Collection\",\"harness\":\"assets/apps/apps.zx\",\"children\":[", id)
|
|
if child != "" {
|
|
BuilderPrint(*bytes, "{\"id\":\"%\",\"title\":\"Child\",\"bundle\":\"assets/child.zx\",\"preview\":\"assets/previews/child.png\",\"protocol\":\"%\",\"expected_id\":\"child\",\"version\":\"1\",\"sha256\":\"%\"}", child, protocol, DIGEST)
|
|
}
|
|
BuilderPrint(*bytes, "]}")
|
|
result := AppCatalogRead(TextView(VecSlice(bytes, 0, bytes.count)), id, *node.catalog)
|
|
VecFree(bytes)
|
|
node.collection = true
|
|
return result
|
|
}
|
|
|
|
// One child downloads from its own node app; the other keeps the collection's.
|
|
PackageCatalog :: (catalog: *AppCatalog, package_field: string) -> bool {
|
|
bytes: Vec(u8)
|
|
BuilderPrint(*bytes, "{\"schema\":1,\"id\":\"inbe.arcade\",\"title\":\"Arcade\",\"harness\":\"assets/apps/apps.zx\",\"children\":[{\"id\":\"wurm\",\"title\":\"Wurm\",\"bundle\":\"assets/wurm.zx\",\"protocol\":\"node/2\",\"expected_id\":\"wurm\",\"version\":\"1\",\"sha256\":\"%\"%},{\"id\":\"chess\",\"title\":\"Chess\",\"bundle\":\"assets/chess.zx\",\"protocol\":\"node/2\",\"expected_id\":\"chess\",\"version\":\"1\",\"sha256\":\"%\"}]}", DIGEST, package_field, ROOT_DIGEST)
|
|
result := AppCatalogRead(TextView(VecSlice(bytes, 0, bytes.count)), "inbe.arcade", catalog)
|
|
VecFree(bytes)
|
|
return result
|
|
}
|
|
|
|
RouteMatches :: (entry: *AppEntry, expected_package: string, digest: string) -> bool {
|
|
route: Vec(u8)
|
|
expected: Vec(u8)
|
|
BuilderPrint(*route, "https://node.test")
|
|
BuilderPrint(*expected, "https://node.test/api/v2/packages/%/%.zx", expected_package, digest)
|
|
result := AppEntryPackageRoute(entry, *route) &&
|
|
TextView(VecSlice(route, 0, route.count)) == TextView(VecSlice(expected, 0, expected.count))
|
|
VecFree(route)
|
|
VecFree(expected)
|
|
return result
|
|
}
|
|
|
|
PackageOpen :: (context: *void, parent: *AppNode, entry: *AppEntry, candidate: *AppNode) -> bool {
|
|
if !Open(context, parent, entry, candidate) { return false }
|
|
if open_package_override != "" { unused CopyCString(open_package_override, candidate.entry.package_id[:]) }
|
|
return true
|
|
}
|
|
|
|
PackageFetch :: (context: *void, account: string, parent: *AppNode, entry: *AppEntry,
|
|
operation: s32, reply: *AppsReply) -> bool {
|
|
if operation != APPS_INSTALL { return false }
|
|
fetched_direct = RouteMatches(entry, "xyz.waozi.wurm", DIGEST)
|
|
reply.status = APPS_QUEUED
|
|
return true
|
|
}
|
|
|
|
CheckPackageIds :: () -> s32 {
|
|
catalog: AppCatalog
|
|
if !PackageCatalog(*catalog, ",\"package_id\":\"xyz.waozi.wurm\"") { return 70 }
|
|
direct := AppCatalogAt(*catalog, 0)
|
|
inherited := AppCatalogAt(*catalog, 1)
|
|
if TextUntilNul(direct.package_id[:]) != "xyz.waozi.wurm" ||
|
|
TextUntilNul(inherited.package_id[:]) != "inbe.arcade" { return 71 }
|
|
if !RouteMatches(direct, "xyz.waozi.wurm", DIGEST) { return 72 }
|
|
if !RouteMatches(inherited, "inbe.arcade", ROOT_DIGEST) { return 73 }
|
|
// A rejected id never replaces the visible collection.
|
|
long_id: Vec(u8)
|
|
BuilderPrint(*long_id, ",\"package_id\":\"")
|
|
for index: cast(s32)0..127 { BuilderPrint(*long_id, "a") }
|
|
BuilderPrint(*long_id, "\"")
|
|
rejected: [8]string = .[",\"package_id\":\"\"", ",\"package_id\":\"..\"", ",\"package_id\":\".\"",
|
|
",\"package_id\":\"Xyz.Waozi\"", ",\"package_id\":\"a/../b\"", ",\"package_id\":7",
|
|
",\"package_id\":\"a\",\"package_id\":\"b\"", TextView(VecSlice(long_id, 0, long_id.count))]
|
|
for field: rejected {
|
|
if PackageCatalog(*catalog, field) { VecFree(long_id); return 74 }
|
|
if AppCatalogAt(*catalog, 0) != direct || TextUntilNul(direct.package_id[:]) != "xyz.waozi.wurm" { VecFree(long_id); return 75 }
|
|
}
|
|
VecFree(long_id)
|
|
// A digest-less or package-less entry has no route, and appends nothing.
|
|
bare: AppEntry
|
|
route: Vec(u8)
|
|
if AppEntryPackageRoute(*bare, *route) || route.count != 0 { VecFree(route); return 76 }
|
|
unused CopyCString("xyz.waozi.wurm", bare.package_id[:])
|
|
if AppEntryPackageRoute(*bare, *route) || route.count != 0 { VecFree(route); return 77 }
|
|
VecFree(route)
|
|
// The tree hands the declared id to the download and the opened child, and
|
|
// refuses a provider that changes where the verified bundle comes from.
|
|
node := New(AppNode)
|
|
unused CopyCString("example.test", node.identity.authority[:])
|
|
unused CopyCString("inbe.arcade", node.identity.id[:])
|
|
node.runtime = cast(*void)1
|
|
node.collection = true
|
|
if !PackageCatalog(*node.catalog, ",\"package_id\":\"xyz.waozi.wurm\"") { return 78 }
|
|
tree: AppTree
|
|
provider := AppProvider.{.open = PackageOpen, .save = Save, .close = Close, .effect = Effect, .fetch = PackageFetch}
|
|
if !AppTreeStart(*tree, node, "account-a", provider) { return 79 }
|
|
root := tree.active
|
|
unused AppTreeQueue(*tree, root, Request(APPS_INSTALL, "wurm")); unused AppTreeDrain(*tree)
|
|
if !fetched_direct { return 80 }
|
|
open_package_override = "other.package"
|
|
unused AppTreeQueue(*tree, root, Request(APPS_OPEN, "wurm")); unused AppTreeDrain(*tree)
|
|
if !AppHandleEqual(tree.active, root) { return 81 }
|
|
open_package_override = ""
|
|
unused AppTreeQueue(*tree, root, Request(APPS_OPEN, "wurm")); unused AppTreeDrain(*tree)
|
|
opened := AppTreeNode(*tree, tree.active)
|
|
if AppHandleEqual(tree.active, root) || opened == null ||
|
|
TextUntilNul(opened.entry.package_id[:]) != "xyz.waozi.wurm" { return 82 }
|
|
if !AppTreeClose(*tree) { return 83 }
|
|
AppCatalogClear(*catalog)
|
|
return 0
|
|
}
|
|
|
|
ContentConsentCheck :: () -> s32 {
|
|
version_calls = 0
|
|
version_seen = AppsRequest.{}
|
|
origin := "https://content.test"
|
|
files: AppFiles
|
|
if !AppFilesOpen(*files, Environment("APPS_TREE_CONSENT")) { return 90 }
|
|
defer { AppFilesClose(*files) }
|
|
|
|
provider := AppProvider.{.open = Open, .save = Save, .close = Close, .effect = Effect}
|
|
tree: AppTree
|
|
root := Root()
|
|
if !AppTreeStart(*tree, root, "account-a", provider) { return 91 }
|
|
caller := tree.active
|
|
child := AppCatalogAt(*root.catalog, 0)
|
|
tree.provider.version_effect = VersionEffect
|
|
|
|
unanswered := UpdateState(true)
|
|
declined := UpdateState(true)
|
|
if AppTreeQueueContentUpdate(*tree, caller, child, *unanswered, false) ||
|
|
AppTreeQueueContentUpdate(*tree, caller, child, *declined, false) ||
|
|
version_calls != 0 || tree.pending.count != 0 { return 92 }
|
|
|
|
if !AppConnectionRemember(*files, origin, APP_CONNECTION_OFFLINE) ||
|
|
AppConnectionRead(*files, origin) != APP_CONNECTION_OFFLINE { return 93 }
|
|
if AppTreeQueueContentUpdate(*tree, caller, child, *declined,
|
|
AppConnectionRead(*files, origin) == APP_CONNECTION_ALLOWED) ||
|
|
version_calls != 0 || tree.pending.count != 0 { return 94 }
|
|
|
|
AppFilesClose(*files)
|
|
if !AppFilesOpen(*files, Environment("APPS_TREE_LEGACY_CONSENT")) { return 95 }
|
|
if AppConnectionRead(*files, origin) != APP_CONNECTION_ALLOWED { return 99 }
|
|
if !AppTreeQueueContentUpdate(*tree, caller, child, *unanswered,
|
|
AppConnectionRead(*files, origin) == APP_CONNECTION_ALLOWED) { return 96 }
|
|
if AppTreeQueueContentUpdate(*tree, caller, child, *unanswered, true) ||
|
|
tree.pending.count != 1 { return 100 }
|
|
if !AppTreeDrain(*tree) || version_calls != 1 ||
|
|
version_seen.operation != APPS_UPDATE || TextUntilNul(version_seen.id[:]) != "inbe.chess" ||
|
|
TextUntilNul(version_seen.version[:]) != "2.0" ||
|
|
TextUntilNul(version_seen.sha256[:]) != DIGEST { return 97 }
|
|
|
|
not_installed := UpdateState(false)
|
|
if AppTreeQueueContentUpdate(*tree, caller, child, *not_installed, true) ||
|
|
version_calls != 1 { return 98 }
|
|
if !AppTreeClose(*tree) { return 99 }
|
|
return 0
|
|
}
|
|
|
|
Open :: (context: *void, parent: *AppNode, entry: *AppEntry, candidate: *AppNode) -> bool {
|
|
if fail_open { return false }
|
|
candidate.identity.authority = parent.identity.authority
|
|
candidate.identity.id = entry.id
|
|
candidate.entry = entry.*
|
|
candidate.runtime = cast(*void)1
|
|
candidate.bytes = 1024
|
|
if entry.protocol == APPS_COLLECTION_PROTOCOL {
|
|
bytes: Vec(u8)
|
|
depth += 1
|
|
BuilderPrint(*bytes, "collection.%", depth + 1)
|
|
result := MakeCatalog(candidate, TextUntilNul(entry.id[:]), TextView(VecSlice(bytes, 0, bytes.count)), "collection/1")
|
|
VecFree(bytes)
|
|
return result
|
|
}
|
|
return true
|
|
}
|
|
|
|
Save :: (context: *void, node: *AppNode) -> bool {
|
|
if fail_save { return false }
|
|
saves += 1
|
|
return true
|
|
}
|
|
Close :: (context: *void, node: *AppNode) { closed += 1; node.runtime = null }
|
|
|
|
Effect :: (context: *void, account: string, locator: *AppLocator, operation: s32, reply: *AppsReply) -> bool {
|
|
if fail_effect || account != "account-a" || TextUntilNul(locator.identity.authority[:]) != "example.test" { return false }
|
|
if operation == APPS_INSTALL { installed = true }
|
|
if operation == APPS_UNINSTALL { installed = false }
|
|
if operation == APPS_PIN { pinned = true }
|
|
if operation == APPS_UNPIN { pinned = false }
|
|
reply.status = APPS_APPLIED
|
|
if operation == APPS_INSTALL_TO_LAUNCHER {
|
|
reply.status = APPS_QUEUED
|
|
unused CopyCString("android-prompt-1", reply.receipt[:])
|
|
}
|
|
return true
|
|
}
|
|
|
|
VersionEffect :: (context: *void, account: string, locator: *AppLocator, request: *AppsRequest, reply: *AppsReply) -> bool {
|
|
version_calls += 1
|
|
version_seen = request.*
|
|
if account != "account-a" || TextUntilNul(locator.identity.id[:]) != "inbe.chess" ||
|
|
TextUntilNul(locator.identity.authority[:]) != "example.test" ||
|
|
TextUntilNul(request.version[:]) != "2.0" || TextUntilNul(request.sha256[:]) != DIGEST { return false }
|
|
reply.status = APPS_APPLIED
|
|
return true
|
|
}
|
|
|
|
// A native consumer copies the verified target; it stages its own root only
|
|
// after the drain, so neither a guest run nor a locator open may reenter.
|
|
OpenEffect :: (context: *void, account: string, locator: *AppLocator, request: *AppsRequest, reply: *AppsReply) -> s32 {
|
|
open_calls += 1
|
|
open_saves = saves
|
|
open_seen = request.*
|
|
if !open_tree.draining || open_tree.busy || AppTreeBegin(open_tree, open_tree.active) ||
|
|
AppTreeOpenLocator(open_tree, locator) || account != "account-a" ||
|
|
reply.status != APPS_QUEUED || reply.request < 1 { open_reentered = true }
|
|
AppLocatorClear(*open_copy)
|
|
open_copy.identity = locator.identity
|
|
for index: cast(s64)0..locator.chain.count - 1 { unused VecPush(open_copy.chain, locator.chain[index]) }
|
|
unused CopyCString("leaf-stage-1", reply.receipt[:])
|
|
// The tree, not the provider, decides the reply status for each decision.
|
|
reply.status = APPS_APPLIED
|
|
return open_decision
|
|
}
|
|
|
|
OpenEffectCheck :: (provider: AppProvider) -> s32 {
|
|
tree: AppTree
|
|
open_tree = *tree
|
|
provider.open_effect = OpenEffect
|
|
if !AppTreeStart(*tree, Root(), "account-a", provider) { return 50 }
|
|
original := tree.active
|
|
// Default: after exactly the caller's save, the verified child opens.
|
|
saves = 0
|
|
unused AppTreeQueue(*tree, original, Request(APPS_OPEN, "inbe.chess")); unused AppTreeDrain(*tree)
|
|
if open_calls != 1 || open_saves != 1 || open_reentered || AppHandleEqual(tree.active, original) ||
|
|
tree.nodes.count != 2 || open_seen.operation != APPS_OPEN || TextUntilNul(open_seen.id[:]) != "inbe.chess" { return 51 }
|
|
if open_copy.chain.count != 2 || TextUntilNul(open_copy.identity.id[:]) != "inbe.chess" ||
|
|
TextUntilNul(open_copy.identity.authority[:]) != "example.test" ||
|
|
TextUntilNul(open_copy.chain[0].id[:]) != "arcade" || TextUntilNul(open_copy.chain[0].sha256[:]) != ROOT_DIGEST ||
|
|
TextUntilNul(open_copy.chain[1].id[:]) != "inbe.chess" || TextUntilNul(open_copy.chain[1].sha256[:]) != DIGEST { return 52 }
|
|
unused AppTreeQueue(*tree, tree.active, Request(APPS_BACK)); unused AppTreeDrain(*tree)
|
|
if !AppHandleEqual(tree.active, original) || tree.nodes.count != 1 { return 53 }
|
|
// Handled: the parent stays active, only the temporary child closes, and
|
|
// the copied target outlives the drain for native staging.
|
|
open_decision = APP_OPEN_HANDLED
|
|
closed_before := closed
|
|
reply := AppTreeQueue(*tree, original, Request(APPS_OPEN, "inbe.chess")); unused AppTreeDrain(*tree)
|
|
status := AppTreeQueue(*tree, original, AppsRequest.{.operation = APPS_STATUS, .request = reply.request})
|
|
if open_calls != 2 || open_reentered || !AppHandleEqual(tree.active, original) || tree.nodes.count != 1 ||
|
|
closed != closed_before + 1 || AppTreeNode(*tree, original).runtime == null ||
|
|
status.status != APPS_QUEUED || TextUntilNul(status.receipt[:]) != "leaf-stage-1" ||
|
|
open_copy.chain.count != 2 || TextUntilNul(open_copy.chain[1].sha256[:]) != DIGEST { return 54 }
|
|
decisions: [2]s32 = .[APP_OPEN_REJECTED, 7]
|
|
for decision: decisions {
|
|
open_decision = decision
|
|
closed_before = closed
|
|
calls := open_calls
|
|
reply = AppTreeQueue(*tree, original, Request(APPS_OPEN, "inbe.chess")); unused AppTreeDrain(*tree)
|
|
status = AppTreeQueue(*tree, original, AppsRequest.{.operation = APPS_STATUS, .request = reply.request})
|
|
if open_calls != calls + 1 || !AppHandleEqual(tree.active, original) || tree.nodes.count != 1 ||
|
|
closed != closed_before + 1 || status.status != APPS_REJECTED || TextUntilNul(status.receipt[:]) != "" { return 55 }
|
|
}
|
|
// A failed caller save, failed child verification or stale account never
|
|
// reaches the provider, and the working page stays active.
|
|
open_decision = APP_OPEN_HANDLED
|
|
calls := open_calls
|
|
fail_save = true
|
|
reply = AppTreeQueue(*tree, original, Request(APPS_OPEN, "inbe.chess")); unused AppTreeDrain(*tree)
|
|
fail_save = false
|
|
status = AppTreeQueue(*tree, original, AppsRequest.{.operation = APPS_STATUS, .request = reply.request})
|
|
if open_calls != calls || status.status != APPS_REJECTED || !AppHandleEqual(tree.active, original) || tree.nodes.count != 1 { return 56 }
|
|
fail_open = true
|
|
reply = AppTreeQueue(*tree, original, Request(APPS_OPEN, "inbe.chess")); unused AppTreeDrain(*tree)
|
|
fail_open = false
|
|
status = AppTreeQueue(*tree, original, AppsRequest.{.operation = APPS_STATUS, .request = reply.request})
|
|
if open_calls != calls || status.status != APPS_REJECTED || !AppHandleEqual(tree.active, original) || tree.nodes.count != 1 { return 57 }
|
|
unused AppTreeQueue(*tree, original, Request(APPS_OPEN, "inbe.chess"))
|
|
tree.account_epoch += 1
|
|
unused AppTreeDrain(*tree)
|
|
if open_calls != calls || tree.pending[tree.pending.count - 1].reply.status != APPS_REJECTED ||
|
|
!AppHandleEqual(tree.active, original) || tree.nodes.count != 1 { return 58 }
|
|
AppLocatorClear(*open_copy)
|
|
if !AppTreeClose(*tree) { return 59 }
|
|
return 0
|
|
}
|
|
|
|
Root :: (child: string = "inbe.chess", protocol: string = "app/1") -> *AppNode {
|
|
node := New(AppNode)
|
|
if node == null { return null }
|
|
unused CopyCString("example.test", node.identity.authority[:])
|
|
unused CopyCString("arcade", node.identity.id[:])
|
|
unused CopyCString(ROOT_DIGEST, node.entry.sha256[:])
|
|
node.runtime = cast(*void)1
|
|
node.bytes = 1024
|
|
if !MakeCatalog(node, "arcade", child, protocol) { free(node); return null }
|
|
return node
|
|
}
|
|
|
|
Request :: (operation: s32, id: string = "") -> AppsRequest {
|
|
request := AppsRequest.{.operation = operation}
|
|
unused CopyCString(id, request.id[:])
|
|
return request
|
|
}
|
|
|
|
#program_export
|
|
Check :: () -> s32 {
|
|
request: AppsRequest
|
|
if !AppsReadRequest("{\"v\":1,\"op\":\"open\",\"id\":\"inbe.chess\"}", *request) || request.operation != APPS_OPEN { return 1 }
|
|
if AppsReadRequest("{\"v\":1,\"op\":\"open\",\"id\":\"inbe.chess\",\"owner\":\"other\"}", *request) ||
|
|
AppsReadRequest("{\"v\":1,\"v\":2,\"op\":\"back\"}", *request) ||
|
|
AppsReadRequest("{\"v\":2,\"op\":\"back\"}", *request) ||
|
|
AppsReadRequest("{\"v\":1,\"op\":\"open\",\"id\":\"../other\"}", *request) { return 2 }
|
|
// A catalog request may name the revision the app already holds; no other request may.
|
|
if !AppsReadRequest("{\"v\":1,\"op\":\"catalog\",\"revision\":7}", *request) ||
|
|
request.operation != APPS_CATALOG || request.revision != 7 { return 32 }
|
|
if !AppsReadRequest("{\"v\":1,\"op\":\"catalog\"}", *request) || request.revision != 0 { return 33 }
|
|
if AppsReadRequest("{\"v\":1,\"op\":\"catalog\",\"revision\":0}", *request) ||
|
|
AppsReadRequest("{\"v\":1,\"op\":\"catalog\",\"revision\":1.5}", *request) ||
|
|
AppsReadRequest("{\"v\":1,\"op\":\"catalog\",\"revision\":\"7\"}", *request) ||
|
|
AppsReadRequest("{\"v\":1,\"op\":\"open\",\"id\":\"inbe.chess\",\"revision\":7}", *request) { return 34 }
|
|
if !AppBundlePathValid("assets/games/chess.zx") || AppBundlePathValid("assets/../other.zx") ||
|
|
AppBundlePathValid("/assets/child.zx") || AppBundlePathValid("assets/%2e%2e/child.zx") ||
|
|
AppBundlePathValid("assets//child.zx") { return 3 }
|
|
if !AppPreviewPathValid("assets/previews/chess.png") || !AppPreviewPathValid("assets/card.webp") ||
|
|
AppPreviewPathValid("https://example.test/chess.png") || AppPreviewPathValid("assets/../chess.png") ||
|
|
AppPreviewPathValid("assets/%2e%2e/chess.jpg") || AppPreviewPathValid("assets//chess.jpeg") ||
|
|
AppPreviewPathValid("assets/chess.zx") || AppAssetPathValid("assets/..") { return 30 }
|
|
if !AppsReadRequest("{\"v\":1,\"op\":\"update\",\"id\":\"inbe.chess\",\"version\":\"2.0\",\"sha256\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\"}", *request) || request.operation != 10 { return 40 }
|
|
if AppsReadRequest("{\"v\":1,\"op\":\"rollback\",\"id\":\"inbe.chess\",\"version\":\"2.0\"}", *request) ||
|
|
AppsReadRequest("{\"v\":1,\"op\":\"open\",\"id\":\"inbe.chess\",\"version\":\"2.0\"}", *request) ||
|
|
AppsReadRequest("{\"v\":1,\"op\":\"update\",\"id\":\"inbe.chess\",\"version\":\"2.0\",\"sha256\":\"bad\"}", *request) { return 41 }
|
|
covered: AppEntry
|
|
cover_json := "{\"id\":\"game\",\"title\":\"Game\",\"bundle\":\"assets/game.zx\",\"protocol\":\"app/1\",\"expected_id\":\"game\",\"version\":\"1.0\",\"sha256\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"cover\":{\"portrait\":\"assets/cover.png\",\"landscape\":\"assets/wide.png\",\"logo\":\"assets/logo.png\",\"caption\":\"Game\",\"action\":\"play\"}}"
|
|
if !AppReadEntry(cover_json, 0, *covered) || TextUntilNul(covered.cover.landscape[:]) != "assets/wide.png" { return 60 }
|
|
// A malformed optional cover cannot overwrite the previously valid entry.
|
|
if AppReadEntry("{\"id\":\"game\",\"title\":\"Game\",\"bundle\":\"assets/game.zx\",\"protocol\":\"app/1\",\"expected_id\":\"game\",\"version\":\"1.0\",\"sha256\":\"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\",\"cover\":{\"portrait\":\"assets/../other.png\"}}", 0, *covered) ||
|
|
TextUntilNul(covered.cover.landscape[:]) != "assets/wide.png" { return 61 }
|
|
// Cover presentation and download sizes are bounded catalog data.
|
|
catalog: AppCatalog
|
|
if !AppCatalogRead("{\"schema\":1,\"id\":\"library\",\"title\":\"Library\",\"harness\":\"assets/apps/apps.zx\",\"presentation\":{\"mode\":\"covers\"},\"children\":[]}", "library", *catalog) || !catalog.cover_grid { return 62 }
|
|
if AppCatalogRead("{\"schema\":1,\"id\":\"library\",\"title\":\"Library\",\"harness\":\"assets/apps/apps.zx\",\"presentation\":{\"mode\":\"unknown\"},\"children\":[]}", "library", *catalog) || !catalog.cover_grid { return 63 }
|
|
AppCatalogClear(*catalog)
|
|
amounts: [5]string = .["-1", "0", "1.5", "67108865", "4096"]
|
|
for amount: amounts {
|
|
sized: Vec(u8)
|
|
BuilderPrint(*sized, "%,\"bytes\":%}", cover_json[:cover_json.count - 1], amount)
|
|
accepted := AppReadEntry(TextView(VecSlice(sized, 0, sized.count)), 0, *covered)
|
|
VecFree(sized)
|
|
if accepted != (amount == "4096") { return 64 }
|
|
}
|
|
if covered.bytes != 4096 { return 65 }
|
|
package_result := CheckPackageIds()
|
|
if package_result != 0 { return package_result }
|
|
provider := AppProvider.{.open = Open, .save = Save, .close = Close, .effect = Effect}
|
|
tree: AppTree
|
|
root := Root()
|
|
first := AppCatalogAt(*root.catalog, 0)
|
|
if TextUntilNul(first.preview[:]) != "assets/previews/child.png" { return 31 }
|
|
if !AppTreeStart(*tree, root, "account-a", provider) { return 4 }
|
|
original := tree.active
|
|
update := Request(APPS_UPDATE, "inbe.chess")
|
|
unused CopyCString("2.0", update.version[:]); unused CopyCString(DIGEST, update.sha256[:])
|
|
if AppTreeQueue(*tree, original, update).status != APPS_REJECTED { return 42 }
|
|
tree.provider.version_effect = VersionEffect
|
|
if !AppTreeBegin(*tree, original) { return 43 }
|
|
version_reply := AppTreeQueue(*tree, original, update)
|
|
update.version[0] = #char "9"
|
|
if version_reply.status != APPS_QUEUED || AppTreeDrain(*tree) || version_calls != 0 { return 44 }
|
|
if !AppTreeEnd(*tree, original) || !AppTreeDrain(*tree) || version_calls != 1 ||
|
|
TextUntilNul(version_seen.version[:]) != "2.0" || !AppHandleEqual(tree.active, original) || tree.nodes.count != 1 { return 45 }
|
|
checked := AppTreeQueue(*tree, original, AppsRequest.{.operation = APPS_STATUS, .request = version_reply.request})
|
|
if checked.status != APPS_APPLIED { return 46 }
|
|
update = version_seen; update.operation = APPS_ROLLBACK
|
|
fail_save = true
|
|
unused AppTreeQueue(*tree, original, update); unused AppTreeDrain(*tree)
|
|
if version_calls != 1 || !AppHandleEqual(tree.active, original) { return 47 }
|
|
fail_save = false
|
|
update.sha256[0] = #char "0"
|
|
version_reply = AppTreeQueue(*tree, original, update); unused AppTreeDrain(*tree)
|
|
checked = AppTreeQueue(*tree, original, AppsRequest.{.operation = APPS_STATUS, .request = version_reply.request})
|
|
if checked.status != APPS_REJECTED || version_calls != 2 || !AppHandleEqual(tree.active, original) { return 48 }
|
|
update = version_seen; unused CopyCString(DIGEST, update.sha256[:])
|
|
version_reply = AppTreeQueue(*tree, original, update)
|
|
tree.account_epoch += 1
|
|
unused AppTreeDrain(*tree)
|
|
if version_calls != 2 { return 49 }
|
|
|
|
if AppTreeQueue(*tree, original, Request(APPS_OPEN, "missing")).status != APPS_REJECTED { return 5 }
|
|
if !AppTreeBegin(*tree, original) || AppTreeBegin(*tree, original) { return 6 }
|
|
reply := AppTreeQueue(*tree, original, Request(APPS_OPEN, "inbe.chess"))
|
|
if reply.status != APPS_QUEUED || AppTreeDrain(*tree) || !AppHandleEqual(tree.active, original) { return 7 }
|
|
if !AppTreeEnd(*tree, original) || !AppTreeDrain(*tree) { return 8 }
|
|
child := tree.active
|
|
if AppHandleEqual(child, original) || tree.nodes.count != 2 { return 9 }
|
|
locator: AppLocator
|
|
if !AppTreeLocate(*tree, child, *locator) || locator.chain.count != 2 || TextUntilNul(locator.identity.id[:]) != "inbe.chess" { return 10 }
|
|
fail_save = true
|
|
unused AppTreeQueue(*tree, child, Request(APPS_BACK)); unused AppTreeDrain(*tree)
|
|
if !AppHandleEqual(tree.active, child) { return 11 }
|
|
fail_save = false
|
|
unused AppTreeQueue(*tree, child, Request(APPS_BACK)); unused AppTreeDrain(*tree)
|
|
if !AppHandleEqual(tree.active, original) || AppTreeNode(*tree, child) != null { return 12 }
|
|
fail_open = true
|
|
unused AppTreeQueue(*tree, original, Request(APPS_OPEN, "inbe.chess")); unused AppTreeDrain(*tree)
|
|
if !AppHandleEqual(tree.active, original) || tree.nodes.count != 1 { return 13 }
|
|
fail_open = false
|
|
// Both installed records and favorites survive failed writes. Uninstall
|
|
// and reinstall preserve the provider's saved Chess record value.
|
|
unused AppTreeQueue(*tree, original, Request(APPS_INSTALL, "inbe.chess")); unused AppTreeDrain(*tree)
|
|
unused AppTreeQueue(*tree, original, Request(APPS_PIN, "inbe.chess")); unused AppTreeDrain(*tree)
|
|
if !installed || !pinned || tree.nodes.count != 1 { return 14 }
|
|
fail_effect = true
|
|
unused AppTreeQueue(*tree, original, Request(APPS_UNINSTALL, "inbe.chess")); unused AppTreeDrain(*tree)
|
|
if !installed || !pinned { return 15 }
|
|
fail_effect = false
|
|
unused AppTreeQueue(*tree, original, Request(APPS_UNPIN, "inbe.chess")); unused AppTreeDrain(*tree)
|
|
unused AppTreeQueue(*tree, original, Request(APPS_UNINSTALL, "inbe.chess")); unused AppTreeDrain(*tree)
|
|
unused AppTreeQueue(*tree, original, Request(APPS_INSTALL, "inbe.chess")); unused AppTreeDrain(*tree)
|
|
if !installed || pinned || records != 41 { return 16 }
|
|
reply = AppTreeQueue(*tree, original, Request(APPS_INSTALL_TO_LAUNCHER, "inbe.chess")); unused AppTreeDrain(*tree)
|
|
status := AppTreeQueue(*tree, original, AppsRequest.{.operation = APPS_STATUS, .request = reply.request})
|
|
if status.status != APPS_QUEUED || TextUntilNul(status.receipt[:]) != "android-prompt-1" { return 17 }
|
|
if !AppTreeOpenLocator(*tree, *locator) || AppTreeNode(*tree, child) != null { return 18 }
|
|
active := tree.active
|
|
locator.chain[1].sha256[0] = #char "0"
|
|
if AppTreeOpenLocator(*tree, *locator) || !AppHandleEqual(tree.active, active) { return 19 }
|
|
AppLocatorClear(*locator)
|
|
// Status history is bounded and reusable, not a lifetime click limit.
|
|
unused AppTreeQueue(*tree, tree.active, Request(APPS_BACK)); unused AppTreeDrain(*tree)
|
|
for index: cast(s32)0..299 {
|
|
unused AppTreeQueue(*tree, tree.active, Request(APPS_PIN, "inbe.chess")); unused AppTreeDrain(*tree)
|
|
}
|
|
if tree.pending.count > tree.pending_limit || tree.nodes.count != 1 { return 20 }
|
|
if !AppTreeClose(*tree) { return 21 }
|
|
// Dynamic routes go beyond both the widget scope and Session capacities.
|
|
root = Root("collection.1", "collection/1")
|
|
if !AppTreeStart(*tree, root, "account-a", provider) { return 22 }
|
|
for index: cast(s32)1..80 {
|
|
node := AppTreeNode(*tree, tree.active)
|
|
entry := AppCatalogAt(*node.catalog, 0).*
|
|
unused AppTreeQueue(*tree, tree.active, Request(APPS_OPEN, TextUntilNul(entry.id[:])))
|
|
unused AppTreeDrain(*tree)
|
|
if tree.nodes.count != index + 1 { return 23 }
|
|
}
|
|
if !AppTreeLocate(*tree, tree.active, *locator) || locator.chain.count != 81 { return 24 }
|
|
AppLocatorClear(*locator)
|
|
for index: cast(s32)1..80 {
|
|
unused AppTreeQueue(*tree, tree.active, Request(APPS_BACK)); unused AppTreeDrain(*tree)
|
|
}
|
|
if tree.nodes.count != 1 || !AppHandleEqual(tree.active, AppHandle.{0, 1}) { return 25 }
|
|
// A descendant's declared root identity is rejected as an ancestor cycle.
|
|
root = AppTreeNode(*tree, tree.active)
|
|
if !MakeCatalog(root, "arcade", "collection.1", "collection/1") { return 26 }
|
|
unused AppTreeQueue(*tree, tree.active, Request(APPS_OPEN, "collection.1")); unused AppTreeDrain(*tree)
|
|
node := AppTreeNode(*tree, tree.active)
|
|
if !MakeCatalog(node, "collection.1", "arcade", "collection/1") { return 27 }
|
|
before := tree.active
|
|
unused AppTreeQueue(*tree, before, Request(APPS_OPEN, "arcade")); unused AppTreeDrain(*tree)
|
|
if !AppHandleEqual(tree.active, before) || tree.nodes.count != 2 { return 28 }
|
|
if !AppTreeClose(*tree) { return 29 }
|
|
open_result := OpenEffectCheck(provider)
|
|
if open_result != 0 { return open_result }
|
|
return ContentConsentCheck()
|
|
}
|