Files
breeze/tests/practice_downloads_host.c
waozi 017d3565d3 Build on Ziran 0.5.0 and Kryon's namespaced widgets, with the Tao picture page
Pin only pushed commits, with no local overrides: Ziran v0.5.0
(f9f92b46), Kryon b45cc524 (one lock entry, ref master, shared with the
Css and Plot master edges), Apps 352901e, Entity b30dd4a and practices
893e5b6f, whose sharpened banners and regenerated Lumi guide clips the
narration check now matches.

The Library opens each Tao Te Ching chapter on its own picture page: the
chapter art and its title, centered together; the text pages follow.
The reader keeps the picture page across reflow, and a chapter start or
a Contents pick opens it. The 81 approved chapter pictures are included.

Breeze now uses Kryon's namespaced widgets (Text.Draw/Text.Props,
Button, Image, Modal.ActionModal, Layout, TabBar, LoadingScreen,
LoadingIndicator, Shape.Circle) instead of the removed Kryon/Widgets
facades. Hosted apps import std/text explicitly, since a short "text"
import now names Kryon's widget. AGENTS.md and the Text/Button API checks
describe the namespaced forms; two unused test doubles are removed.

Build fixes for the new toolchain: the bundle runtime carries Ziran's
instruction engine (no BOOTSTRAP=1) and takes the pinned host zi2c for
cross builds; the Apps controller's lock context has the manifest's
module roots; the app codec generator lists Kryon's raw modules only;
the package scripts read ZX revision 28 bundle assets. The Apps
controller digest matches the Apps 352901e build.

Also included: the stopped lanes' work in this tree (Radio download,
Photos install, Lists, Lumi, Habits shop rewards, astral exercise
selection, appearance and download recovery) and the raylib-free desktop
lane's host modules (app_trace, host_input, host_window, host_clock),
inactive unless DESKTOP_HOST is defined.

Not included: the crash-recovery lane's picture-window and storage
crash-safety changes, which that lane commits itself.

Local tests: zi-check (510 modules), native and Android source checks,
hosted app checks, build-laws, clean-text-api-check, button-api-check,
library-reader-test, library-ui-test, storage-crash-zi-test and
native-image-decode-test pass. The bundled Arcade is still ZX revision 26
and waits for an Arcade build on these pins.
2026-11-16 14:20:12 -03:00

150 lines
5.7 KiB
C

#include "zir_string.h"
#include "practice_downloads_behavior.h"
#include "assets.h"
#include "practice_downloads.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdatomic.h>
#include <time.h>
void FixtureContentYield(void) { usleep(1000); }
static atomic_int content_blocked;
static atomic_int content_entered;
void FixtureBlockContent(bool blocked)
{
atomic_store(&content_entered, 0);
atomic_store(&content_blocked, blocked);
}
bool FixtureContentStarted(void) { return atomic_load(&content_entered) != 0; }
uint64_t FixtureContentNow(void)
{
struct timespec value;
assert(clock_gettime(CLOCK_MONOTONIC, &value) == 0);
return (uint64_t)value.tv_sec * 1000000000ULL + value.tv_nsec;
}
void __real_Sha256Hex(const unsigned char *data, int64_t size, unsigned char *digest);
void __wrap_Sha256Hex(const unsigned char *data, int64_t size, unsigned char *digest)
{
if (atomic_load(&content_blocked)) {
atomic_store(&content_entered, 1);
while (atomic_load(&content_blocked)) usleep(1000);
}
__real_Sha256Hex(data, size, digest);
}
static const char *fixtures;
static char database[4096];
static int mode, starts;
static int bad_catalog;
static int shipped;
static int granted_starts;
static void *allocations[64];
static size_t allocation_count;
static String read_fixture(const char *name) {
char path[4096];
snprintf(path, sizeof path, "%s/%s", fixtures, name);
FILE *file = fopen(path, "rb");
assert(file);
fseek(file, 0, SEEK_END);
long size = ftell(file);
rewind(file);
char *data = malloc((size_t)size);
assert(data && fread(data, 1, (size_t)size, file) == (size_t)size);
fclose(file);
assert(allocation_count < 64);
allocations[allocation_count++] = data;
return StringView(data, (size_t)size);
}
String FixtureCatalog(void) { return read_fixture("catalog.json"); }
AssetView FixtureAsset(String path) {
AssetView result = {0};
if (StringEqual(path, StringLiteral("assets/practices/catalog.json"))) {
static String catalog;
if (!catalog.data) catalog = FixtureCatalog();
result.data = bad_catalog ? StringLiteral("{\"schema\":1,\"packs\":[]}") : catalog;
result.found = true;
} else if (shipped && StringEqual(path, StringLiteral("assets/practices/default/whm.zx"))) {
static String pack;
if (!pack.data) pack = read_fixture("default-whm.zx");
result.data = pack;
result.found = true;
} else if (shipped && StringEqual(path, StringLiteral("assets/practices/shipped/patterns.zx"))) {
static String pack;
if (!pack.data) pack = read_fixture("shipped-patterns.zx");
result.data = pack;
result.found = true;
} else if (StringEqual(path, StringLiteral("locales/index.txt"))) {
result.data = StringLiteral("en|English\nes|Español\n");
result.found = true;
}
return result;
}
void FixtureMode(int32_t value) { mode = value; }
void FixtureCatalogMode(int32_t value) { bad_catalog = value; }
void FixtureShipped(int32_t value) { shipped = value; }
int32_t FixtureGrantedStarts(void) { return granted_starts; }
int32_t FixtureStarts(void) { return starts; }
bool FixtureTaiChiSaved(void) {
char path[4096];
snprintf(path, sizeof path, "%s/cache/packages/practice-taichi.zx", fixtures);
return access(path, F_OK) == 0;
}
String __wrap_storage_db_path(void) { return StringView(database, strlen(database)); }
EmbeddedAssetEntry *asset_entry_at(size_t index) { (void)index; return NULL; }
size_t asset_entry_total(void) { return 0; }
void app_web_storage_flush(void) {}
bool __wrap_file_download_FileDownloadStart(FileDownload *download, String url, String destination) {
const char prefix[] = "https://api.waozi.xyz/api/v2/packages/inbe.practices/";
const char grant[] = "/fixture-grant";
const char suffix[] = ".zx";
const size_t named = 64 + sizeof suffix - 1;
// A paid pack's grant is the last path segment; free packs have none.
if (url.length == sizeof prefix - 1 + named + sizeof grant - 1) {
assert(memcmp(url.data + sizeof prefix - 1 + named, grant, sizeof grant - 1) == 0);
granted_starts++;
} else {
assert(url.length == sizeof prefix - 1 + named);
}
assert(memcmp(url.data, prefix, sizeof prefix - 1) == 0);
assert(memcmp(url.data + sizeof prefix - 1 + 64, suffix, sizeof suffix - 1) == 0);
char name[69];
memcpy(name, url.data + sizeof prefix - 1, named);
name[named] = 0;
String bytes = read_fixture(name);
assert(bytes.length == download->maximum_bytes);
snprintf((char *)download->destination, sizeof download->destination,
"%.*s", (int)destination.length, destination.data);
FILE *file = fopen((char *)download->destination, "wb");
assert(file);
assert(fwrite(bytes.data, 1, bytes.length, file) == bytes.length);
if (mode == 1) { fseek(file, -1, SEEK_END); fputc(bytes.data[bytes.length - 1] ^ 1, file); }
fclose(file);
download->status = FileDownloadStatus_Downloading;
starts++;
return true;
}
FileDownloadStatus __wrap_file_download_FileDownloadPoll(FileDownload *download) {
download->status = mode == 2 ? FileDownloadStatus_Error : FileDownloadStatus_Ready;
return download->status;
}
void __wrap_file_download_FileDownloadRelease(FileDownload *download) { download->handle = 0; }
int main(int argc, char **argv) {
assert(argc == 2);
fixtures = argv[1];
snprintf(database, sizeof database, "%s/cache/inbe.db", fixtures);
int result = CheckPracticeDownloads();
if (result) fprintf(stderr, "Practice downloads failed at check %d\n", result);
for (size_t index = 0; index < allocation_count; index++) free(allocations[index]);
return result != 0;
}