Check build laws with Ziran instead of Bend

Sync retry and the private-data layout are ordinary Ziran modules with
#law obligations checked by ziran check. The Bend proofs, Node generators,
pinned Bend dependency and Node build tool are removed, and a mutation test
shows each law rejects a deliberately broken implementation.
This commit is contained in:
waozi committed 2026-09-28 19:23:19 -03:00
1 parent 7656f1a263
commit 61dcd9bbba
20 files changed
+412 -389

No files matched your search

+3 -3
View File
@@ -84,7 +84,7 @@ jobs:
- name: Fetch Ziran packages
run: sh scripts/packages.sh --locked
- name: Set up Node.js for Bend proofs
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
@@ -141,7 +141,7 @@ jobs:
- name: Fetch Ziran packages
run: sh scripts/packages.sh --locked
- name: Set up Node.js for Bend proofs
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
@@ -210,7 +210,7 @@ jobs:
- name: Fetch Ziran packages
run: sh scripts/packages.sh --locked
- name: Set up Node.js for Bend proofs
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
+12 -12
View File
@@ -55,7 +55,7 @@ jobs:
- name: Fetch Ziran packages
run: sh scripts/packages.sh --locked
- name: Set up Node.js for Bend proofs
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
@@ -93,7 +93,7 @@ jobs:
- name: Fetch Ziran packages
run: sh scripts/packages.sh --locked
- name: Set up Node.js for Bend proofs
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
@@ -157,7 +157,7 @@ jobs:
- name: Fetch Ziran packages
run: sh scripts/packages.sh --locked
- name: Set up Node.js for Bend proofs
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
@@ -221,7 +221,7 @@ jobs:
- name: Fetch Ziran packages
run: sh scripts/packages.sh --locked
- name: Set up Node.js for Bend proofs
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
@@ -295,7 +295,7 @@ jobs:
- name: Fetch Ziran packages
run: sh scripts/packages.sh --locked
- name: Set up Node.js for Bend proofs
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
@@ -403,7 +403,7 @@ jobs:
- name: Fetch Ziran packages
run: sh scripts/packages.sh --locked
- name: Set up Node.js for Bend proofs
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
@@ -463,7 +463,7 @@ jobs:
- name: Fetch Ziran packages
run: sh scripts/packages.sh --locked
- name: Set up Node.js for Bend proofs
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
@@ -523,7 +523,7 @@ jobs:
- name: Fetch Ziran packages
run: sh scripts/packages.sh --locked
- name: Set up Node.js for Bend proofs
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
@@ -580,7 +580,7 @@ jobs:
- name: Fetch Ziran packages
run: sh scripts/packages.sh --locked
- name: Set up Node.js for Bend proofs
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
@@ -627,7 +627,7 @@ jobs:
- name: Fetch Ziran packages
run: sh scripts/packages.sh --locked
- name: Set up Node.js for Bend proofs
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
@@ -677,7 +677,7 @@ jobs:
- name: Fetch Ziran packages
run: sh scripts/packages.sh --locked
- name: Set up Node.js for Bend proofs
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
@@ -742,7 +742,7 @@ jobs:
- name: Fetch Ziran packages
run: sh scripts/packages.sh --locked
- name: Set up Node.js for Bend proofs
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
+6 -12
View File
@@ -22,10 +22,12 @@
- `make build-laws` is mandatory for native, web, and Windows artifacts;
Gradle and CMake enforce the same version and proof checks independently.
Never bypass a failed gate or hand-edit generated policy tables.
- Retry behavior lives in `laws/sync_retry/main.bend`. Implement changes there
and prove `LAWS.bend` in `PROOF.bend`; the app consumes the checked table.
Do not weaken laws to make an implementation pass. Contract changes require
Never bypass a failed gate.
- Laws are Ziran `#law` obligations checked by `ziran check`. Retry behavior
lives in `src/app/sync_retry.zi` with its laws in `sync_retry_laws.zi`;
private-data names live in `src/storage/storage_layout.zi` with laws in
`storage_layout_laws.zi`. Change the implementation freely, but do not
weaken laws to make an implementation pass. Contract changes require
explicit product intent and separate review from implementation changes.
- Run `make proof-test sync-recovery-test version-test` for these contracts.
Coverage, trust boundaries, and the next proof migrations are described in
@@ -65,11 +67,3 @@
- Use descriptive names, explicit control flow, and focused helpers. Never
compress multiple statements, branches, declarations, or checks onto one line.
Format changed source, inspect the final diff, and run `git diff --check`.
## Bend
When using Bend:
- run `bend guide` to learn it
- use `LAWS.bend` to keep important rules
- run `bend PROOF.bend` before committing
- parallelize the code whenever possible
+17 -24
View File
@@ -47,6 +47,7 @@ ZIRAN_DIR := build/packages/ziran
ZIRAN_BUILD_DIR := $(abspath $(BUILD_DIR)/ziran-toolchain)
KRYON_LIBRARY_BUILD_DIR := $(abspath $(BUILD_DIR)/kryon-library)
ZI2C_BIN := $(ZIRAN_BUILD_DIR)/bin/zi2c
ZIRAN_BIN := $(ZIRAN_BUILD_DIR)/bin/ziran
ZI2ZIR_BIN := $(ZIRAN_BUILD_DIR)/bin/zi2zir
ZI_CHECK_STAMP := $(BUILD_DIR)/zi-check/native.fresh
ZIRAN_SOURCES := $(wildcard $(ZIRAN_DIR)/cmd/zir/*.[ch]) $(wildcard $(ZIRAN_DIR)/cmd/zir-c/*.[ch]) $(wildcard $(ZIRAN_DIR)/cmd/zir-ir/*.[ch]) $(ZIRAN_DIR)/Makefile
@@ -472,12 +473,9 @@ WEB_APP_INCLUDE = $(filter-out -iquote$(KRY_GEN_DIR)%,$(APP_INCLUDE)) \
WINDOWS_APP_INCLUDE = $(filter-out -iquote$(KRY_GEN_DIR)%,$(APP_INCLUDE)) \
-iquote$(WINDOWS_GEN_DIR) \
$(foreach dir,$(sort $(dir $(ZI_SRCS))),-iquote$(WINDOWS_GEN_DIR)/$(dir))
PROOF_DIR := $(BUILD_DIR)/proofs
SYNC_RETRY_SOURCE := src/app/sync_retry.zi
STORAGE_LAYOUT_HEADER := $(PROOF_DIR)/storage_layout.h
STORAGE_LAYOUT_ZIRAN := src/storage/storage_layout.zi
APP_INCLUDE += -I$(PROOF_DIR)
KRYON_INCLUDE += -I$(PROOF_DIR)
STORAGE_LAYOUT_HEADER := tests/storage_layout.h
LAW_MODULES := src/app/sync_retry_laws.zi src/storage/storage_layout_laws.zi
RAY_PKGS ?= sdl2 libdrm gbm egl glesv2
RAY_SDL_CFLAGS ?= $(shell pkg-config --cflags sdl2 2>/dev/null)
RAY_SDL_LDLIBS ?= $(shell pkg-config --libs sdl2 2>/dev/null)
@@ -884,7 +882,7 @@ $(KRYON_KSS_STAMP): Makefile $(ZI2C_BIN) $(KRYON_KSS_ZI) $(KRYON_DIR)/src/ui/mod
$(KRYON_KSS_C) $(KRYON_KSS_H): $(KRYON_KSS_STAMP)
@test -f $@
$(KRY_GEN_STAMP): Makefile $(ZI2C_BIN) $(ZI_SRCS) $(KRYON_ZI_MODULES) $(GAME2D_MODULES) $(DAOCHI_CLIENT_MODULES) $(ZIRAN_STD_MODULES) $(SYNC_RETRY_SOURCE) $(STORAGE_LAYOUT_HEADER) | build-laws zi-check
$(KRY_GEN_STAMP): Makefile $(ZI2C_BIN) $(ZI_SRCS) $(KRYON_ZI_MODULES) $(GAME2D_MODULES) $(DAOCHI_CLIENT_MODULES) $(ZIRAN_STD_MODULES) $(SYNC_RETRY_SOURCE) | build-laws zi-check
mkdir -p $(KRY_GEN_DIR)
sh scripts/run-ziran.sh $(ZI2C_BIN) --no-main --prune-stale --root . \
$(foreach define,$(ZI_NATIVE_DEFINES),--define $(define)) \
@@ -897,7 +895,7 @@ $(KRY_GEN_STAMP): Makefile $(ZI2C_BIN) $(ZI_SRCS) $(KRYON_ZI_MODULES) $(GAME2D_M
-o $(KRY_GEN_DIR) $(ZI_SRCS)
touch $@
$(WEB_GEN_STAMP): Makefile $(ZI2C_BIN) $(ZI_SRCS) $(KRYON_ZI_MODULES) $(GAME2D_MODULES) $(DAOCHI_CLIENT_MODULES) $(ZIRAN_STD_MODULES) $(SYNC_RETRY_SOURCE) $(STORAGE_LAYOUT_HEADER) | build-laws zi-check
$(WEB_GEN_STAMP): Makefile $(ZI2C_BIN) $(ZI_SRCS) $(KRYON_ZI_MODULES) $(GAME2D_MODULES) $(DAOCHI_CLIENT_MODULES) $(ZIRAN_STD_MODULES) $(SYNC_RETRY_SOURCE) | build-laws zi-check
rm -rf $(WEB_GEN_DIR)
mkdir -p $(WEB_GEN_DIR)
sh scripts/run-ziran.sh $(ZI2C_BIN) --no-main --root . \
@@ -915,7 +913,7 @@ $(WEB_GEN_STAMP): Makefile $(ZI2C_BIN) $(ZI_SRCS) $(KRYON_ZI_MODULES) $(GAME2D_M
$(WEB_GEN_SRCS) $(WEB_GEN_GAME_C): $(WEB_GEN_STAMP)
@test -f $@
$(WINDOWS_GEN_STAMP): Makefile $(ZI2C_BIN) $(ZI_SRCS) $(KRYON_ZI_MODULES) $(GAME2D_MODULES) $(DAOCHI_CLIENT_MODULES) $(ZIRAN_STD_MODULES) $(SYNC_RETRY_SOURCE) $(STORAGE_LAYOUT_HEADER) | build-laws zi-check
$(WINDOWS_GEN_STAMP): Makefile $(ZI2C_BIN) $(ZI_SRCS) $(KRYON_ZI_MODULES) $(GAME2D_MODULES) $(DAOCHI_CLIENT_MODULES) $(ZIRAN_STD_MODULES) $(SYNC_RETRY_SOURCE) | build-laws zi-check
rm -rf $(WINDOWS_GEN_DIR)
mkdir -p $(WINDOWS_GEN_DIR)
sh scripts/run-ziran.sh $(ZI2C_BIN) --no-main --root . \
@@ -1118,25 +1116,20 @@ version-test:
test: version-check version-test
# Proofs run on every invocation, even with existing generated source.
# Generators replace outputs only when their contents actually change.
# Laws are checked by the Ziran compiler on every invocation. `ziran check`
# exits nonzero on any disproved or unwaived unknown law.
.PHONY: proofs proof-test build-laws
proofs:
node scripts/generate-sync-retry.mjs $(SYNC_RETRY_SOURCE)
node scripts/generate-storage-layout.mjs $(STORAGE_LAYOUT_HEADER) $(STORAGE_LAYOUT_ZIRAN)
proofs: $(ZI2C_BIN)
@for module in $(LAW_MODULES); do \
$(ZIRAN_BIN) check --root src $$module > /dev/null || exit 1; \
done
proof-test:
node tests/sync_retry_proof_test.mjs
node tests/storage_layout_proof_test.mjs
# Deliberately broken implementations must be rejected by the laws.
proof-test: $(ZI2C_BIN)
sh tests/law_mutation_test.sh $(ZIRAN_BIN)
build-laws: version-check proofs
$(SYNC_RETRY_SOURCE): | proofs
@test -f $@
$(STORAGE_LAYOUT_HEADER): | proofs
@test -f $@
test: proof-test
secret-check:
@@ -1217,7 +1210,7 @@ $(STORAGE_IMPORT_TEST): tests/storage_import_test.c tests/test_locale_stub.c $(S
$(STORAGE_PATHS_TEST): tests/storage_paths_test.c $(STORAGE_CORE_SRCS) $(KRY_GEN_DIR)/src/storage/storage_sessions.c $(KRY_GEN_DIR)/src/storage/storage_elist.c $(KRY_GEN_DIR)/src/storage/sync_review.c $(KRY_GEN_DIR)/src/storage/db.c $(KRY_GEN_DIR)/src/storage/import.c $(KRY_GEN_DIR)/src/storage/data.c $(KRY_GEN_DIR)/src/habits/habit_model.c $(KRY_GEN_DIR)/src/habits/habit_sessions.c src/storage/storage.h src/storage/db.h src/storage/import.h src/storage/data.h $(STORAGE_LAYOUT_HEADER) $(SQLITE_SRC) $(SQLITE_AMALGAMATION_H) | $(TEST_BIN_DIR)
$(CC) -Wall -Wextra -std=c99 -D_DEFAULT_SOURCE -D_GNU_SOURCE -ffunction-sections -fdata-sections \
-Isrc -Isrc/app -Isrc/core -Isrc/screens -Isrc/screens/settings -Isrc/practices -Isrc/practices/whm -Isrc/practices/meditation -Isrc/storage -Isrc/platform/android -Isrc/third_party $(KRYON_INCLUDE) -I$(KRY_GEN_DIR) -I$(KRY_GEN_DIR)/src $(SQLITE_INCLUDE) \
-Isrc -Isrc/app -Isrc/core -Isrc/screens -Isrc/screens/settings -Isrc/practices -Isrc/practices/whm -Isrc/practices/meditation -Isrc/storage -Isrc/platform/android -Isrc/third_party -Itests $(KRYON_INCLUDE) -I$(KRY_GEN_DIR) -I$(KRY_GEN_DIR)/src $(SQLITE_INCLUDE) \
-o $@ \
tests/storage_paths_test.c $(STORAGE_CORE_SRCS) $(KRYON_DIR)/src/kry_std/kry_archive.c $(KRY_GEN_DIR)/src/storage/storage_sessions.c $(KRY_GEN_DIR)/src/storage/storage_elist.c $(KRY_GEN_DIR)/src/storage/sync_review.c $(KRY_GEN_DIR)/src/storage/db.c $(KRY_GEN_DIR)/src/storage/import.c $(KRY_GEN_DIR)/src/storage/data.c $(KRY_GEN_DIR)/src/habits/habit_model.c $(KRY_GEN_DIR)/src/habits/habit_sessions.c $(SQLITE_SRC) \
-Wl,--gc-sections $(NATIVE_SYSTEM_LDLIBS)
@@ -3008,4 +3001,4 @@ $(APPIMAGE_TARGET) $(DEB_TARGET) $(RPM_TARGET) $(SNAP_TARGET) $(FLATPAK_TARGET)
android-release android-bundle android-copy-release-apks android-copy-bundle windows-setup site: version-check
# Actual artifacts are gated too, including direct and incremental builds.
$(TARGET) $(KRYON_HOST_TARGET) $(WIN64_TARGET) $(WIN32_TARGET) $(WEB_JS_TARGET) $(WEB_CANVAS_TARGET): $(SYNC_RETRY_SOURCE) $(STORAGE_LAYOUT_HEADER) | build-laws
$(TARGET) $(KRYON_HOST_TARGET) $(WIN64_TARGET) $(WIN32_TARGET) $(WEB_JS_TARGET) $(WEB_CANVAS_TARGET): $(SYNC_RETRY_SOURCE) | build-laws
+4 -4
View File
@@ -29,10 +29,10 @@ optionally sync user-owned data through a Daochi-compatible sync server.
## Build
The build host needs Node.js 22.18 or newer for mandatory Bend proof checking,
as well as Python 3 and the platform's native build dependencies. Node and Bend
are build tools; they are not installed with the app. See
[build contracts and proofs](docs/build-laws-plan.md) for the checked behavior.
The build checks Inbe's laws with the Ziran compiler (`ziran check`); no
separate proof tool is needed. The build host needs Python 3 and the platform's
native build dependencies. See [build laws](docs/build-laws-plan.md) for the
checked behavior.
Initialize the submodules once:
+10 -10
View File
@@ -21,16 +21,16 @@ table recognizes both
Exports use `inbe-data/inbe.db` and `inbe-data/metadata.json` with format
`inbe-data-sqlite`.
`laws/storage_layout/LAWS.bend` proves the current and older directory names
are distinct on every target, the current and older database names, and that
both current and historical archive entries are importable. The
checked generator emits `storage_layout.h` and `src/storage/storage_layout.zi`;
the Ziran module supplies the current and historical directory and database
names, archive suffix, and import/export entry names. `data_root()` and import/export
code consume its names. The proof covers the finite naming policy. Native
storage tests cover path selection, database opening, and archive round trips.
The full app remains unbuildable during the Ziran migration, so those native
integration tests cannot currently be linked from the full app build.
`src/storage/storage_layout_laws.zi` states the current and older directory
names (distinct on every target), the current and older database names, and
the current and historical archive entries, and `ziran check` proves the
constants in `src/storage/storage_layout.zi` match. That module supplies the
directory and database names, archive suffix, and import/export entry names;
`data_root()` and import/export code consume its names. The laws cover the
finite naming policy only. Native storage tests cover path selection,
database opening, and archive round trips. The full app remains unbuildable
during the Ziran migration, so those native integration tests cannot currently
be linked from the full app build.
## Desktop profiles
+96 -101
View File
@@ -1,118 +1,113 @@
# Build contracts and Bend proofs
# Build laws in Ziran
Every Inbe law is stated, implemented, and checked in Ziran. Bend, its Node.js
checker, and the generated `.zi` tables are gone. This file records what the
laws cover, how they are enforced, and what is still to do.
## Implemented
Inbe's release metadata uses the numeric changelog release and the permanent
`APP_VERSION_*` macros. `update_version.sh` synchronizes the release fields;
`check-version.py` rejects inconsistencies. The version check now runs in the
native, web, and Windows artifact graphs and in both Gradle and CMake, including
incremental builds. Version semantics remain a structural build check, not a
formal theorem.
- **Release metadata.** `update_version.sh` synchronizes the release fields from
the numeric `CHANGELOG.md` entry; `check-version.py` rejects inconsistencies.
It runs in the native, web, and Windows artifact graphs and in Gradle and
CMake, including incremental builds. It is a structural build check, not a
formal theorem.
- **Sync retry** (`src/app/sync_retry.zi`, laws in `sync_retry_laws.zi`).
Ordinary hand-written Ziran, with 21 `#law` obligations checked by
`ziran check`. Result codes and retry states are checked exhaustively,
including out-of-range persisted integers. They establish: the wire result
codes; success resetting the retry state; temporary challenge and request
failures following 5/15/30/60 seconds with a saturated fourth attempt; each
actionable error class and every unknown code stopping automatic retry; the
saved-delay mapping; which results need user action; and the attempt never
leaving its saved range. Expected values are written independently of the
implementation.
- **Storage layout** (`src/storage/storage_layout.zi`, laws in
`storage_layout_laws.zi`). The current and older directory names (distinct on
every target), database names, export and historical import entries, web
homes, and temporary names are fixed by 11 laws. See `docs/STORAGE_LAYOUT.md`.
`tests/storage_layout.h` holds independently written expected names for the C
storage path test.
- **Ziran `forall` laws** (in `~/Projects/ziran`).
`#law NAME forall x: 0..4, k: SomeEnum => condition;` checks every
combination of integer ranges and enum members with the compile-time
evaluator. A failure reports the counterexample; a domain over 1,000,000
cases or a condition the evaluator cannot decide is `unknown`, which fails
the gate unless explicitly waived.
The retry implementation is **Bend 2 code evaluated into checked Ziran**:
1. `laws/sync_retry/main.bend` defines the actual pure retry policy.
2. `LAWS.bend` states 11 universally quantified contracts; `PROOF.bend` proves
them for the complete finite input types.
3. Inbe's `scripts/bend-laws.mjs` uses directly pinned Bend 2.0.16, commit
`15ae0c86f3193b8f645b4bedbc438655b648d0da`. It verifies the checker and Base
hashes before loading, checks termination and types, and rejects holes,
unproved declarations, `@unsafe`, foreign implementations, remote imports,
and imports outside the proof package.
4. The checked function is evaluated directly in Bend's kernel for all 45
combinations of result and retry state. `scripts/generate-sync-retry.mjs`
writes `src/app/sync_retry.zi`, which the Ziran compiler checks and lowers.
There is no separate handwritten retry implementation or Bend runtime on
the phone.
`src/storage/sync_result.zi` declares the wire result codes; generation
rejects changes to their names or numeric values.
5. Account-data and social retries both call that module. It clamps persisted
integers before selecting a proved decision, avoiding increment overflow.
Unknown results stop automatic retries.
The proofs establish success resetting the retry state; temporary challenge
and request failures following 5/15/30/60 seconds with a saturated fourth
attempt; actionable failures stopping automatic retry; and the mapping of
saved retry states and delays. Each error classification has its own law.
They do not prove server availability, delivery, alias/friend restoration,
or arbitrary `.zi` behavior. The integration tests for those effects remain,
but their native build currently stops at the unfinished Ziran source gate.
The private-data directory and database names come from the proved finite
Bend policy in `laws/storage_layout`. Its generated header is consumed by
`data_root()` and storage import/export code. The proof establishes current
names on each target and that the export entry is importable; it does not
establish filesystem or SQLite behavior. See `docs/STORAGE_LAYOUT.md`.
The laws do not prove server availability, delivery, alias/friend restoration,
filesystem or SQLite behavior, or arbitrary `.zi` code. Integration tests for
those effects remain, and the sync recovery native build still stops at the
unfinished Ziran source gate.
## Build behavior and verification
Install Node.js **22.18 or newer** on the build host and initialize the
`build/packages/bend`, `build/packages/ziran`, and `build/packages/kryon` submodules. The checker runs
offline once those dependencies are present.
CI and package builders provide Node explicitly. The container setup script
uses pinned, checksummed official Node archives; ordinary compilation never
downloads a proof tool. Flatpak removes its Node build tool from the app.
`make build-laws` runs the version check and `ziran check` on each module in
`LAW_MODULES`. Failed checking prevents compilation; no old generated output can
satisfy it because none exists. Gradle and CMake run the same checks. Node is no
longer required to build, and the Flatpak no longer carries a Node build tool.
- `make build-laws`: release consistency and proofs.
- `make proof-test`: deterministic generation, contract-breaking mutations,
enum mapping drift, and rejection with old generated Ziran source present.
- `make sync-retry-zi-test`: source and saved IR behavior across C, C++, Go,
and portable bundles.
- `make sync-recovery-test`: the generated Ziran C and coordinator, including
all known result codes, extreme persisted integers, and social retry state;
currently blocked by the unfinished app source gate.
- `make version-test`: release synchronization and rejecting mismatches.
- `make proof-test`: checker/evaluator acceptance and rejection, including
broken laws and changed wire codes.
- `make proof-test` runs `tests/law_mutation_test.sh`: the unmutated tree
passes, and eight deliberate breakages (a changed result code, delay,
saturation bound, stop rule, reset value, and storage names) are each rejected
by the specific law that should catch them. This is what shows the laws are
not vacuous.
- `make sync-retry-zi-test`: behavior across the portable bundle and the C, C++,
and Go targets, from source and saved IR.
- `make sync-recovery-test`: generated Ziran C and the coordinator; blocked by
the unfinished app source gate.
- `make version-test`: release synchronization and mismatch rejection.
Make's generated-source and app artifact prerequisites run the checks on
every invocation. Failed checking prevents compilation even if old source
exists. Successful generation preserves its timestamp when the proved policy
is unchanged. Gradle `preBuild` always checks; direct CMake builds regenerate
the Ziran module. Plan 9 compiles that module with the other app sources.
Compiler regression tests, the text/button scanners, migration tests, and the
sync integration suite are separate checks with their own scope; none is a
proof of application behavior.
The Ziran compiler's image surface restriction remains separate from these
application proofs. Compiler regression tests do not prove application
behavior.
The text/button scanners, migration tests, and sync integration suite remain
separate checks with their own scope.
## Toolchain pin
## Trust and use with smaller models
`ziran.lock` still pins Ziran v0.2.0, which has no `forall` laws. Locked and CI
builds cannot check the laws until the Ziran commit that adds `forall` is pushed
and the lock is bumped (`sh scripts/packages.sh` after updating `ziran.toml`).
Local builds use the `../ziran` working tree through `ziran.local.toml`.
A model can change the implementation and provide proofs while the contracts
stay fixed. Its output is accepted only when the checker verifies those
contracts. This reduces dependence on model quality for **specified behavior**;
it does not establish that a smaller model is equally good at designing the
contracts or diagnosing missing requirements.
## Remaining Ziran work
The trusted boundary is the pinned checker/Base, the finite-table generator,
the enum/integer adapter, build graph, and target compiler. Regression tests
exercise the integration boundary. An agent able to rewrite the laws or gates
can weaken the guarantee. Protected branches, required checks, and independent
review ownership should protect those files on the hosting service; repository
files alone cannot make themselves immutable. Hosting settings have not been
changed by this implementation.
`AGENTS.md` now states ownership, contract-change boundaries, and the remaining
product/review obligations instead of treating prose as a proof system.
1. **Stable law identity and waivers.** Duplicate names, waivers for unknown
names, and waivers on `disproved` laws are errors.
2. **Determinism matrix.** Law tables byte-identical across runs and between
source and saved IR (covered for `forall` in Ziran's `tests/laws.sh`, not yet
across the whole matrix).
3. **Mutation gate as a Ziran library.** Inbe's `tests/law_mutation_test.sh` is
a local script; Ziran should provide the reusable form.
4. **Local enum variables and named enum domains in more contexts.** Enum
members and typed parameters work in laws; locals of enum type inside pure
procedures are not yet resolved.
5. **Beyond finite tables.** Bounded quantification over sequences, and a stated
relation between the checked pure model and the lowered native code, so a
proof of a model is never claimed to prove a separately implemented C path.
Needed for collection merges and recovery.
## Next migrations, in order
1. Move practice lifecycle decisions into a pure finite policy: desktop focus
cannot pause a session, user pause remains explicit, and mobile background
transitions preserve the required timer behavior. Compile its proved table
through the same Bend checker; retain platform integration tests.
2. Specify sync recovery transitions: restoring an account cannot discard
queued local changes, partial social refresh cannot erase known friends,
and an account switch cannot apply responses belonging to the old account.
Model effects explicitly; proofs of scheduling do not prove network delivery.
3. For unbounded algorithms such as collection merges, define a checked direct
compilation path and its semantics before expanding beyond finite tables.
Do not claim a proof of a model also proves a separately implemented C path.
4. Specify widget behavior in ordinary Kryon Ziran modules and test the
portable values and host boundaries. Ziran remains unaware of UI widgets.
The current Inbe source gate still reports unsupported host operations.
1. **Practice lifecycle.** Desktop focus cannot pause a session, user pause
stays explicit, and mobile background transitions keep the required timer
behavior, as a pure finite policy with laws. Platform integration tests stay.
2. **Sync recovery transitions.** Restoring an account cannot discard queued
local changes, partial social refresh cannot erase known friends, and an
account switch cannot apply responses belonging to the old account. Model
effects explicitly; a proof of scheduling is not a proof of network delivery.
3. **Collection merges**, once Ziran supports bounded sequence quantification.
4. **Widget behavior** in ordinary Kryon Ziran modules with tests of the
portable values and host boundaries. Ziran stays unaware of UI widgets.
[Bend's upstream guide](https://github.com/bendlang/bend/blob/main/guide/GUIDE.md)
describes its law/proof convention. Inbe uses the actual checker rather than
naming ordinary assertions or tests mathematical proofs.
## Trust and use with smaller models
A model may change the implementation while the laws stay fixed; its output is
accepted only when `ziran check` proves them. This reduces dependence on model
quality for **specified behavior**. It does not make a small model as good at
designing contracts or noticing a missing requirement.
The trusted base is the Ziran checker and evaluator, the build graph, and the
target compiler. An agent that can rewrite `*_laws.zi`, the mutation test, or
the gates can weaken the guarantee, so protect them with protected branches,
required checks, and independent review ownership on the host; repository files
cannot make themselves immutable. Those hosting settings have not been changed.
`AGENTS.md` states ownership and the rule not to weaken laws.
+9 -13
View File
@@ -49,15 +49,12 @@ file(GLOB ZIRAN_SOURCES CONFIGURE_DEPENDS
"${ZIRAN_DIR}/cmd/zir-ir/*.c" "${ZIRAN_DIR}/cmd/zir-ir/*.h")
find_program(HOST_MAKE NAMES make gmake REQUIRED)
find_program(HOST_PYTHON NAMES python3 REQUIRED)
find_program(HOST_NODE NAMES node REQUIRED)
set(APP_PROOF_DIR "${CMAKE_BINARY_DIR}/proofs")
set(ZIRAN_BIN "${ZIRAN_BUILD_DIR}/bin/ziran")
add_custom_target(app_build_laws
COMMAND "${HOST_PYTHON}" "${REPO_ROOT}/scripts/check-version.py"
COMMAND "${HOST_NODE}" "${REPO_ROOT}/scripts/generate-sync-retry.mjs"
"${SRC_DIR}/app/sync_retry.zi"
COMMAND "${HOST_NODE}" "${REPO_ROOT}/scripts/generate-storage-layout.mjs"
"${APP_PROOF_DIR}/storage_layout.h" "${SRC_DIR}/storage/storage_layout.zi"
BYPRODUCTS "${APP_PROOF_DIR}/storage_layout.h"
COMMAND "${ZIRAN_BIN}" check --root "${SRC_DIR}" "${SRC_DIR}/app/sync_retry_laws.zi"
COMMAND "${ZIRAN_BIN}" check --root "${SRC_DIR}" "${SRC_DIR}/storage/storage_layout_laws.zi"
DEPENDS "${ZI2C_BIN}"
WORKING_DIRECTORY "${REPO_ROOT}"
COMMENT "Checking release consistency and proving app laws"
VERBATIM
@@ -99,11 +96,11 @@ execute_process(COMMAND "${HOST_MAKE}" -j1 -C "${ZIRAN_DIR}"
"BUILD_DIR=${ZIRAN_BUILD_DIR}" all COMMAND_ERROR_IS_FATAL ANY)
execute_process(COMMAND "${HOST_PYTHON}" "${REPO_ROOT}/scripts/check-version.py"
WORKING_DIRECTORY "${REPO_ROOT}" COMMAND_ERROR_IS_FATAL ANY)
execute_process(COMMAND "${HOST_NODE}" "${REPO_ROOT}/scripts/generate-sync-retry.mjs"
"${SRC_DIR}/app/sync_retry.zi" WORKING_DIRECTORY "${REPO_ROOT}"
COMMAND_ERROR_IS_FATAL ANY)
execute_process(COMMAND "${HOST_NODE}" "${REPO_ROOT}/scripts/generate-storage-layout.mjs"
"${APP_PROOF_DIR}/storage_layout.h" "${SRC_DIR}/storage/storage_layout.zi"
execute_process(COMMAND "${ZIRAN_BIN}" check --root "${SRC_DIR}"
"${SRC_DIR}/app/sync_retry_laws.zi"
WORKING_DIRECTORY "${REPO_ROOT}" COMMAND_ERROR_IS_FATAL ANY)
execute_process(COMMAND "${ZIRAN_BIN}" check --root "${SRC_DIR}"
"${SRC_DIR}/storage/storage_layout_laws.zi"
WORKING_DIRECTORY "${REPO_ROOT}" COMMAND_ERROR_IS_FATAL ANY)
set(APP_GENERATE_ZIRAN_COMMAND "${HOST_PYTHON}"
"${REPO_ROOT}/scripts/generate-android-sources.py"
@@ -278,7 +275,6 @@ add_library(main SHARED
add_dependencies(main app_ziran_generated app_clean_runtime_api app_build_laws app_zi_check)
target_include_directories(main PRIVATE
"${APP_PROOF_DIR}"
"${ZIRAN_DIR}/include"
"${MONOCYPHER_DIR}"
"${MONOCYPHER_DIR}/optional"
-16
View File
@@ -12,22 +12,6 @@ finish-args:
- --device=dri
- --filesystem=home
modules:
# Host build tool only; removed from the finished application.
- name: node-for-proofs
buildsystem: simple
build-commands:
- install -D -m755 bin/node /app/bin/node
cleanup:
- '*'
sources:
- type: archive
url: https://nodejs.org/dist/v22.23.2/node-v22.23.2-linux-x64.tar.xz
sha256: d60acfe00a2932254bb0ad20e01b0d74397a0875595de719654b214f4b03f307
only-arches: [x86_64]
- type: archive
url: https://nodejs.org/dist/v22.23.2/node-v22.23.2-linux-arm64.tar.xz
sha256: fff4078c5def658577f92c88db7db3bc0072924bfb93fe52c1e744a54e94abb8
only-arches: [aarch64]
- name: inbe
buildsystem: simple
build-commands:
+12 -12
View File
@@ -1,7 +1,6 @@
#!/usr/bin/env bash
# Storage vocabulary lives only in the proved laws package:
# laws/storage_layout -> scripts/generate-storage-layout.mjs ->
# storage_layout.h and the generated src/storage layout modules.
# Storage vocabulary lives only in src/storage/storage_layout.zi, whose values
# are fixed by the laws in src/storage/storage_layout_laws.zi.
# Hand-typed copies in src/ drift during renames and orphan user data.
set -euo pipefail
cd "$(dirname "$0")/.."
@@ -17,31 +16,32 @@ check_pattern() {
local pattern="$1"
local message="$2"
if rg -n "$pattern" src --glob '*.zi' --glob '*.c' --glob '*.h' \
--glob '!layout.zi' --glob '!storage_layout.zi'; then
--glob '!layout.zi' --glob '!storage_layout.zi' \
--glob '!storage_layout_laws.zi'; then
echo "$message" >&2
status=1
fi
}
check_pattern '"(breathing|inbe)\.db"' \
'Database names come from the generated storage layout.'
'Database names come from the storage layout.'
check_pattern '"(breathing|inbe)-data/' \
'Export and import entry names come from the generated storage layout.'
'Export and import entry names come from the storage layout.'
check_pattern '"(breathing|inbe)-data-sqlite"' \
'The export metadata format comes from the generated storage layout.'
'The export metadata format comes from the storage layout.'
check_pattern '"/home/(breathing|inbe)"' \
'Web home paths come from the generated storage layout.'
'Web home paths come from the storage layout.'
check_pattern '"BreathSession"' \
'Directory names come from the generated storage layout.'
'Directory names come from the storage layout.'
check_pattern '"(breathing|inbe)-sessions\.csv"|"breathing-web-export' \
'Export artifact names come from the generated storage layout.'
'Export artifact names come from the storage layout.'
check_pattern '\bjoin_path2\b' \
'Use storage_join_path (src/storage/db.zi) for path assembly.'
check_pattern 'snprintf\([^;]*"(breathing|inbe)["/]' \
'Paths are assembled from storage_layout.h constants, not hand-typed names.'
'Paths are assembled from storage_layout.zi constants, not hand-typed names.'
if [ "$status" -ne 0 ]; then
echo 'Storage vocabulary must be defined only by the proved storage layout laws.' >&2
echo 'Storage vocabulary must be defined only by the storage layout module and its laws.' >&2
exit 1
fi
echo 'Storage literal checks passed'
-1
View File
@@ -86,7 +86,6 @@ link curl curl
link liboqs liboqs
link monocypher monocypher
link rini rini
link bend bend
rm -rf "$links"
mv "$staging" "$links"
+23 -156
View File
@@ -1,7 +1,7 @@
#import, file "../storage/sync_result.zi";
// Generated by scripts/generate-sync-retry.mjs from proved Bend 2.0.16 policy.
// SyncResult wire codes are verified against src/storage/sync_result.zi.
// Sync retry policy. Its behavior is fixed by the laws in sync_retry_laws.zi,
// which `ziran check` proves for every result code and retry state.
RetryDecision :: struct {
attempt: s32
@@ -15,152 +15,32 @@ retry_attempt_index :: (attempt: s32) -> s32 {
return attempt
}
// Seconds to wait before the next automatic try, by saved retry state.
retry_delay_seconds :: (attempt: s32) -> s32 {
attempt = retry_attempt_index(attempt)
if attempt <= 1 { return 5 }
if attempt == 2 { return 15 }
if attempt == 3 { return 30 }
return 60
}
retry_is_temporary :: (result: s32) -> bool {
return result == cast(s32) SyncResult.SYNC_CHALLENGE_FAILED ||
result == cast(s32) SyncResult.SYNC_REQUEST_FAILED
}
#program_export
sync_retry_decision :: (result: s32, attempt: s32) -> RetryDecision {
if result < 0 || result > 7 { result = 8 }
attempt = retry_attempt_index(attempt)
if result == 0 {
// Success
if attempt == 0 {
return RetryDecision.{0, 0, 0}
}
if attempt == 1 {
return RetryDecision.{0, 0, 0}
}
if attempt == 2 {
return RetryDecision.{0, 0, 0}
}
if attempt == 3 {
return RetryDecision.{0, 0, 0}
}
if result == cast(s32) SyncResult.SYNC_OK {
return RetryDecision.{0, 0, 0}
}
if result == 1 {
// InvalidUrl
if attempt == 0 {
return RetryDecision.{0, 0, 1}
}
if attempt == 1 {
return RetryDecision.{1, 0, 1}
}
if attempt == 2 {
return RetryDecision.{2, 0, 1}
}
if attempt == 3 {
return RetryDecision.{3, 0, 1}
}
return RetryDecision.{4, 0, 1}
if retry_is_temporary(result) {
next := retry_attempt_index(attempt + 1)
return RetryDecision.{next, retry_delay_seconds(next), 0}
}
if result == 2 {
// NoAccount
if attempt == 0 {
return RetryDecision.{0, 0, 1}
}
if attempt == 1 {
return RetryDecision.{1, 0, 1}
}
if attempt == 2 {
return RetryDecision.{2, 0, 1}
}
if attempt == 3 {
return RetryDecision.{3, 0, 1}
}
return RetryDecision.{4, 0, 1}
}
if result == 3 {
// PayloadFailed
if attempt == 0 {
return RetryDecision.{0, 0, 1}
}
if attempt == 1 {
return RetryDecision.{1, 0, 1}
}
if attempt == 2 {
return RetryDecision.{2, 0, 1}
}
if attempt == 3 {
return RetryDecision.{3, 0, 1}
}
return RetryDecision.{4, 0, 1}
}
if result == 4 {
// ChallengeFailed
if attempt == 0 {
return RetryDecision.{1, 5, 0}
}
if attempt == 1 {
return RetryDecision.{2, 15, 0}
}
if attempt == 2 {
return RetryDecision.{3, 30, 0}
}
if attempt == 3 {
return RetryDecision.{4, 60, 0}
}
return RetryDecision.{4, 60, 0}
}
if result == 5 {
// SignFailed
if attempt == 0 {
return RetryDecision.{0, 0, 1}
}
if attempt == 1 {
return RetryDecision.{1, 0, 1}
}
if attempt == 2 {
return RetryDecision.{2, 0, 1}
}
if attempt == 3 {
return RetryDecision.{3, 0, 1}
}
return RetryDecision.{4, 0, 1}
}
if result == 6 {
// RequestFailed
if attempt == 0 {
return RetryDecision.{1, 5, 0}
}
if attempt == 1 {
return RetryDecision.{2, 15, 0}
}
if attempt == 2 {
return RetryDecision.{3, 30, 0}
}
if attempt == 3 {
return RetryDecision.{4, 60, 0}
}
return RetryDecision.{4, 60, 0}
}
if result == 7 {
// AuthFailed
if attempt == 0 {
return RetryDecision.{0, 0, 1}
}
if attempt == 1 {
return RetryDecision.{1, 0, 1}
}
if attempt == 2 {
return RetryDecision.{2, 0, 1}
}
if attempt == 3 {
return RetryDecision.{3, 0, 1}
}
return RetryDecision.{4, 0, 1}
}
// Unknown
if attempt == 0 {
return RetryDecision.{0, 0, 1}
}
if attempt == 1 {
return RetryDecision.{1, 0, 1}
}
if attempt == 2 {
return RetryDecision.{2, 0, 1}
}
if attempt == 3 {
return RetryDecision.{3, 0, 1}
}
return RetryDecision.{4, 0, 1}
// Unknown and actionable results stop automatic retry.
return RetryDecision.{attempt, 0, 1}
}
#program_export
@@ -171,18 +51,5 @@ app_sync_failure_needs_action :: (result: s32) -> s32 {
#program_export
app_sync_retry_delay :: (attempt: s32) -> float64 {
attempt = retry_attempt_index(attempt)
if attempt == 0 {
return 5.0
}
if attempt == 1 {
return 5.0
}
if attempt == 2 {
return 15.0
}
if attempt == 3 {
return 30.0
}
return 60.0
return cast(float64) retry_delay_seconds(attempt)
}
+69
View File
@@ -0,0 +1,69 @@
#import, file "sync_retry.zi";
#import, file "../storage/sync_result.zi";
// Laws for the sync retry policy. Each states the expected behavior
// independently of the implementation; `ziran check` proves it for every
// result code (including out-of-range codes) and retry state (including
// out-of-range saved states). An implementation edit may not change this file.
// Wire result codes are part of the saved-data and sync protocol.
#law WireOk custom cast(s32) SyncResult.SYNC_OK == 0;
#law WireInvalidUrl custom cast(s32) SyncResult.SYNC_INVALID_URL == 1;
#law WireNoAccount custom cast(s32) SyncResult.SYNC_NO_ACCOUNT == 2;
#law WirePayloadFailed custom cast(s32) SyncResult.SYNC_PAYLOAD_FAILED == 3;
#law WireChallengeFailed custom cast(s32) SyncResult.SYNC_CHALLENGE_FAILED == 4;
#law WireSignFailed custom cast(s32) SyncResult.SYNC_SIGN_FAILED == 5;
#law WireRequestFailed custom cast(s32) SyncResult.SYNC_REQUEST_FAILED == 6;
#law WireAuthFailed custom cast(s32) SyncResult.SYNC_AUTH_FAILED == 7;
// Expected schedule: 5, 15, 30, 60 seconds, then saturated at 60.
ExpectedNext :: (attempt: s32) -> s32 {
if attempt >= 4 { return 4 }
return attempt + 1
}
ExpectedDelay :: (attempt: s32) -> s32 {
if attempt <= 1 { return 5 }
if attempt == 2 { return 15 }
if attempt == 3 { return 30 }
return 60
}
ExpectedClamp :: (attempt: s32) -> s32 {
if attempt < 0 { return 0 }
if attempt > 4 { return 4 }
return attempt
}
#law SuccessResets forall attempt: -2..6 => sync_retry_decision(0, attempt) == RetryDecision.{0, 0, 0};
#law ChallengeRetries forall attempt: -2..6 => sync_retry_decision(4, attempt) == RetryDecision.{ExpectedNext(ExpectedClamp(attempt)), ExpectedDelay(ExpectedNext(ExpectedClamp(attempt))), 0};
#law RequestRetries forall attempt: -2..6 => sync_retry_decision(6, attempt) == RetryDecision.{ExpectedNext(ExpectedClamp(attempt)), ExpectedDelay(ExpectedNext(ExpectedClamp(attempt))), 0};
#law InvalidUrlStops forall attempt: -2..6 => sync_retry_decision(1, attempt) == RetryDecision.{ExpectedClamp(attempt), 0, 1};
#law NoAccountStops forall attempt: -2..6 => sync_retry_decision(2, attempt) == RetryDecision.{ExpectedClamp(attempt), 0, 1};
#law PayloadFailureStops forall attempt: -2..6 => sync_retry_decision(3, attempt) == RetryDecision.{ExpectedClamp(attempt), 0, 1};
#law SigningFailureStops forall attempt: -2..6 => sync_retry_decision(5, attempt) == RetryDecision.{ExpectedClamp(attempt), 0, 1};
#law AuthenticationFailureStops forall attempt: -2..6 => sync_retry_decision(7, attempt) == RetryDecision.{ExpectedClamp(attempt), 0, 1};
// Any other code, including extremes of the persisted integer, stops retry.
#law UnknownResultStops forall result: 8..40, attempt: -2..6 => sync_retry_decision(result, attempt) == RetryDecision.{ExpectedClamp(attempt), 0, 1};
#law NegativeResultStops forall result: -40..-1, attempt: -2..6 => sync_retry_decision(result, attempt) == RetryDecision.{ExpectedClamp(attempt), 0, 1};
#law SavedDelayMatches forall attempt: -2..6 => app_sync_retry_delay(attempt) == cast(float64) ExpectedDelay(ExpectedClamp(attempt));
// Success and the two temporary failures need no user action; everything
// else does.
ExpectedNeedsAction :: (result: s32) -> s32 {
if result == 0 || result == 4 || result == 6 { return 0 }
return 1
}
#law FailureNeedsAction forall result: -40..40 => app_sync_failure_needs_action(result) == ExpectedNeedsAction(result);
// The retry attempt never leaves the saved range.
#law AttemptStaysBounded forall result: -40..40, attempt: -2..6 => sync_retry_decision(result, attempt).attempt >= 0 && sync_retry_decision(result, attempt).attempt <= 4;
#program_export
sync_retry_laws_entry :: () -> s32 {
return 0
}
+2 -1
View File
@@ -1,4 +1,5 @@
// Generated from the proved Bend storage layout. Do not edit by hand.
// Private-data names. The laws in storage_layout_laws.zi fix these values;
// docs/STORAGE_LAYOUT.md describes them.
CurrentDirectoryName :: "inbe"
PreviousDirectoryPosix :: "breathing"
PreviousDirectoryWindows :: "BreathSession"
+28
View File
@@ -0,0 +1,28 @@
#import, file "storage_layout.zi";
// Laws for the private-data layout. They restate the names independently of
// storage_layout.zi; `ziran check` proves the constants match. Changing a
// name here is a data-migration decision, not an implementation detail.
#law CurrentDirectoryIsInbe custom CurrentDirectoryName == "inbe";
#law CurrentDatabaseIsInbe custom CurrentDatabaseName == "inbe.db";
#law PreviousDatabaseIsBreathing custom PreviousDatabaseName == "breathing.db";
// The older directory never equals the current one on any target, so an
// upgrade cannot mistake the current directory for the old one.
#law PreviousDirectoriesDiffer custom PreviousDirectoryPosix != CurrentDirectoryName && PreviousDirectoryWindows != CurrentDirectoryName && PreviousDirectoryAndroid != CurrentDirectoryName && PreviousDirectoryWeb != CurrentDirectoryName;
#law PreviousDirectoryNames custom PreviousDirectoryPosix == "breathing" && PreviousDirectoryAndroid == "breathing" && PreviousDirectoryWeb == "breathing" && PreviousDirectoryWindows == "BreathSession";
#law DatabaseNamesDiffer custom CurrentDatabaseName != PreviousDatabaseName;
// Exports use the current entry; both current and historical entries import.
#law ExportEntryIsCurrent custom CurrentDatabaseEntry == "inbe-data/inbe.db" && ExportMetadataEntry == "inbe-data/metadata.json" && ExportMetadataFormat == "inbe-data-sqlite";
#law HistoricalEntryStaysImportable custom PreviousDatabaseEntry == "breathing-data/breathing.db" && PreviousDatabaseEntry != CurrentDatabaseEntry;
#law WebHomes custom CurrentWebHome == "/home/inbe" && PreviousWebHome == "/home/breathing";
#law ExportFilenames custom ExportFilenameFormat == "inbe-%lld.zip" && ExportFilenameFallback == "inbe.zip" && ExportFilenamePrefix == "inbe-" && ExportFilenameSuffix == ".zip" && ExportSessionsCsv == "inbe-sessions.csv";
#law TemporaryNames custom ImportDatabaseTemporaryName == "import-inbe.db" && InspectDatabaseTemporaryName == "import-inspect-inbe.db" && ExportDatabaseTemporaryName == "export-inbe.db" && WebExportTemporaryPath == "/tmp/inbe-web-export.zip" && ArchiveDirectorySuffix == ".before-breathing-migration-";
#program_export
storage_layout_laws_entry :: () -> s32 {
return 0
}
+73
View File
@@ -0,0 +1,73 @@
#!/bin/sh
# Every deliberately broken implementation must be rejected by the laws, so
# the laws are known not to be vacuous. The unmutated tree must pass.
set -eu
ziran=${1:?pass the ziran command}
root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT HUP INT TERM
fresh() {
rm -rf "$work/src"
mkdir -p "$work/src/app" "$work/src/storage"
cp "$root"/src/app/sync_retry.zi "$root"/src/app/sync_retry_laws.zi \
"$work/src/app/"
cp "$root"/src/storage/sync_result.zi "$root"/src/storage/storage_layout.zi \
"$root"/src/storage/storage_layout_laws.zi "$work/src/storage/"
}
check() {
"$ziran" check --root "$work/src" "$work/src/$1" > "$work/out.json" \
2> "$work/out.err"
}
fresh
check app/sync_retry_laws.zi
check storage/storage_layout_laws.zi
# file, module to check, sed expression, expected disproved law
mutate() {
file=$1 module=$2 expression=$3 law=$4
fresh
sed -i "$expression" "$work/src/$file"
if cmp -s "$root/src/$file" "$work/src/$file"; then
echo "mutation did not change $file: $expression" >&2
exit 1
fi
if check "$module"; then
echo "laws accepted mutation: $file: $expression" >&2
exit 1
fi
if ! grep -q "law $law is disproved" "$work/out.err"; then
echo "mutation $expression did not disprove $law" >&2
cat "$work/out.err" >&2
exit 1
fi
}
sync=app/sync_retry.zi
mutate $sync app/sync_retry_laws.zi \
'0,/RetryDecision.{0, 0, 0}/s//RetryDecision.{0, 0, 1}/' SuccessResets
mutate $sync app/sync_retry_laws.zi \
's/if attempt == 2 { return 15 }/if attempt == 2 { return 16 }/' \
ChallengeRetries
mutate $sync app/sync_retry_laws.zi \
's/ ||$//; /result == cast(s32) SyncResult.SYNC_REQUEST_FAILED$/d' \
RequestRetries
mutate $sync app/sync_retry_laws.zi \
's/if attempt > 4 { return 4 }/if attempt > 5 { return 5 }/' \
AttemptStaysBounded
mutate $sync app/sync_retry_laws.zi \
's/return RetryDecision.{attempt, 0, 1}/return RetryDecision.{attempt, 0, 0}/' \
InvalidUrlStops
mutate storage/sync_result.zi app/sync_retry_laws.zi \
's/SYNC_AUTH_FAILED :: 7/SYNC_AUTH_FAILED :: 8/' WireAuthFailed
mutate storage/storage_layout.zi storage/storage_layout_laws.zi \
's/^CurrentDirectoryName :: "inbe"/CurrentDirectoryName :: "breathing"/' \
CurrentDirectoryIsInbe
mutate storage/storage_layout.zi storage/storage_layout_laws.zi \
's/^PreviousDatabaseEntry :: .*/PreviousDatabaseEntry :: "inbe-data\/inbe.db"/' \
HistoricalEntryStaysImportable
echo "law mutation test passed"
+46
View File
@@ -0,0 +1,46 @@
/* Expected storage names for tests/storage_paths_test.c. These are written
* independently of src/storage/storage_layout.zi so the test catches drift. */
#ifndef STORAGE_LAYOUT_H
#define STORAGE_LAYOUT_H
#define STORAGE_DIR_NAME "inbe"
#define STORAGE_DB_NAME "inbe.db"
#define STORAGE_DB_NAME_LEGACY "breathing.db"
#define STORAGE_DIR_ARCHIVE_SUFFIX ".before-breathing-migration-"
#define STORAGE_EXPORT_ENTRY_DB "inbe-data/inbe.db"
#define STORAGE_EXPORT_ENTRY_META "inbe-data/metadata.json"
#define STORAGE_EXPORT_META_FORMAT "inbe-data-sqlite"
#define STORAGE_EXPORT_PREFIX "inbe"
#define STORAGE_IMPORT_ENTRY_COUNT 2
static const char *const storage_import_entries[STORAGE_IMPORT_ENTRY_COUNT] = {
"inbe-data/inbe.db",
"breathing-data/breathing.db"
};
#define STORAGE_WEB_HOME "/home/inbe"
#define STORAGE_WEB_HOME_LEGACY "/home/breathing"
#define STORAGE_IMPORT_DB_TMP "import-inbe.db"
#define STORAGE_IMPORT_DB_INSPECT "import-inspect-inbe.db"
#define STORAGE_EXPORT_DB_TMP "export-inbe.db"
#define STORAGE_EXPORT_FILENAME_FMT "inbe-%lld.zip"
#define STORAGE_EXPORT_FILENAME_FALLBACK "inbe.zip"
#define STORAGE_EXPORT_SESSIONS_CSV "inbe-sessions.csv"
#define STORAGE_WEB_EXPORT_TMP "/tmp/inbe-web-export.zip"
#define STORAGE_EXPECT_DIR_ANDROID "inbe"
#define STORAGE_EXPECT_DIR_WEB "inbe"
#define STORAGE_EXPECT_DIR_WINDOWS "inbe"
#define STORAGE_EXPECT_DIR_POSIX "inbe"
#define STORAGE_DIR_LEGACY_ANDROID "breathing"
#define STORAGE_DIR_LEGACY_WEB "breathing"
#define STORAGE_DIR_LEGACY_WINDOWS "BreathSession"
#define STORAGE_DIR_LEGACY_POSIX "breathing"
#if defined(__EMSCRIPTEN__) || defined(PLATFORM_WEB)
#define STORAGE_EXPECT_DIR_HERE STORAGE_EXPECT_DIR_WEB
#elif defined(ANDROID_BUILD)
#define STORAGE_EXPECT_DIR_HERE STORAGE_EXPECT_DIR_ANDROID
#elif defined(_WIN32)
#define STORAGE_EXPECT_DIR_HERE STORAGE_EXPECT_DIR_WINDOWS
#else
#define STORAGE_EXPECT_DIR_HERE STORAGE_EXPECT_DIR_POSIX
#endif
#endif
+1 -9
View File
@@ -75,21 +75,13 @@ class VersionTest(unittest.TestCase):
shutil.copy2(REPO / name, self.root / name)
(self.root / "build/packages.mk").write_text("PACKAGES_READY := 1\n")
(self.root / "build/packages/kryon").symlink_to(REPO / "build/packages/kryon", target_is_directory=True)
(self.root / "build/packages/bend").symlink_to(REPO / "build/packages/bend", target_is_directory=True)
shutil.copytree(REPO / "laws", self.root / "laws")
shutil.copy2(REPO / "scripts/generate-sync-retry.mjs", self.root / "scripts")
shutil.copy2(REPO / "scripts/generate-storage-layout.mjs", self.root / "scripts")
shutil.copy2(REPO / "scripts/bend-laws.mjs", self.root / "scripts")
shutil.copy2(REPO / "scripts/bend-pin.json", self.root / "scripts")
def build():
return subprocess.run(["make", "build-laws"], cwd=self.root,
return subprocess.run(["make", "version-check"], cwd=self.root,
capture_output=True, text=True, check=False)
valid = build()
self.assertEqual(valid.returncode, 0, valid.stdout + valid.stderr)
generated = self.root / "src/app/sync_retry.zi"
self.assertTrue(generated.exists())
name = "droid/app/build.gradle"
self.write(name, self.read(name).replace(self.version, "9.8.7"))
invalid = build()
+1 -10
View File
@@ -69,19 +69,10 @@
"ref": "master",
"source": true,
"url": "https://github.com/LoupVaillant/Monocypher.git"
},
{
"commit": "15ae0c86f3193b8f645b4bedbc438655b648d0da",
"dependencies": {},
"id": "pd2aca867b123e7a4",
"name": "bend",
"ref": "main",
"source": true,
"url": "https://github.com/bendlang/bend.git"
}
],
"root": {
"dependencies": {"bend": "pd2aca867b123e7a4", "curl": "pc4b263336680098b", "daochi_client": "p5a3be391420a26d3", "game2d": "p8120950c86e3937b", "kryon": "p2fe874dd46c0c807", "liboqs": "p051fa9c56d0358ad", "monocypher": "pccdfe79ccaafde45", "rini": "p09fa77e94b0dfc6c", "sqlite": "p151b83a361c86f2d"},
"dependencies": {"curl": "pc4b263336680098b", "daochi_client": "p5a3be391420a26d3", "game2d": "p8120950c86e3937b", "kryon": "p2fe874dd46c0c807", "liboqs": "p051fa9c56d0358ad", "monocypher": "pccdfe79ccaafde45", "rini": "p09fa77e94b0dfc6c", "sqlite": "p151b83a361c86f2d"},
"name": "Inbe"
},
"toolchain": {
-5
View File
@@ -43,8 +43,3 @@ source = true
git = "https://github.com/raysan5/rini.git"
ref = "main"
source = true
[dependencies.bend]
git = "https://github.com/bendlang/bend.git"
ref = "main"
source = true