-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathMakefile.toml
More file actions
794 lines (698 loc) · 30 KB
/
Copy pathMakefile.toml
File metadata and controls
794 lines (698 loc) · 30 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
[config]
skip_core_tasks = true
default_to_workspace = false
[env]
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
CARGO_MAKE_WORKSPACE_INCLUDE_MEMBERS = ["contracts/room-contract", "contracts/web-container-contract", "delegates/chat-delegate", "ui"]
CONTRACT_TARGET = "wasm32-unknown-unknown"
CONTRACT_NAME = "room_contract"
DELEGATE_NAME = "chat_delegate"
BUILD_PROFILE = "release"
# Comma-separated list of features to enable
UI_FEATURES = ""
[tasks.clean]
description = "Clean build artifacts"
command = "cargo"
args = ["clean"]
[tasks.build-tailwind]
description = "Build Tailwind CSS"
command = "npm"
args = ["run", "build:css"]
cwd = "./ui"
[tasks.watch-tailwind]
description = "Watch and rebuild Tailwind CSS"
command = "npm"
args = ["run", "watch:css"]
cwd = "./ui"
[tasks.build-room-contract]
description = "Build the room contract WASM"
# The `-p room-contract` scoping is load-bearing: it builds ONLY the contract
# and its deps, so Cargo never unifies the river-core `migration` feature
# (enabled by river-ui / riverctl) into this WASM. Building the contract under
# a whole-workspace `cargo build` would unify `migration` on and could move the
# contract key. Keep this `-p room-contract` — never `--workspace`. See
# `common/src/migration.rs` and freenet/river#292.
#
# `--locked` is load-bearing for reproducibility (freenet/river#2776 A1): the
# contract key is BLAKE3(wasm || params), so the WASM must build from the
# committed Cargo.lock, not a freshly-resolved (possibly drifted) graph. Fails
# loudly if the lock is stale rather than silently re-keying the contract.
#
# NOT the canonical key-defining build. `scripts/sync-wasm.sh` (cargo make
# sync-wasm) is the ONLY producer of the committed room_contract.wasm, and it
# co-builds `-p room-contract -p chat-delegate` in ONE cargo invocation. That
# unifies river-core's `ecies` feature (which chat-delegate enables) into the
# shared river-core, so this task — building room-contract ALONE — produces
# DIFFERENT room_contract.wasm bytes (a different contract key). Its `target/`
# output must NEVER be copied into ui/public/contracts/ or cli/contracts/;
# doing so silently re-keys the room contract. Always use `cargo make
# sync-wasm` to regenerate committed WASMs. (Reconciling the two build entry
# points is a documented follow-up on freenet/river#2776 A1 — it re-keys, so it
# must ride a deliberate migration + republish.)
command = "cargo"
args = ["build", "--locked", "--profile", "${BUILD_PROFILE}", "--target", "${CONTRACT_TARGET}", "-p", "room-contract", "--target-dir", "target"]
[tasks.sync-cli-wasm]
description = "Sync room contract WASM to CLI package for crates.io publishing"
dependencies = ["build-room-contract"]
script = '''
#!/bin/bash
set -e
# Source and destination paths
SOURCE_WASM="ui/public/contracts/room_contract.wasm"
DEST_WASM="cli/contracts/room_contract.wasm"
# Check if source exists
if [ ! -f "$SOURCE_WASM" ]; then
echo "Error: Source WASM not found at $SOURCE_WASM"
echo "Please run 'cargo make build-room-contract' first"
exit 1
fi
# Create destination directory if it doesn't exist
mkdir -p cli/contracts
# Copy the WASM file
cp "$SOURCE_WASM" "$DEST_WASM"
echo "✓ Synced room_contract.wasm to CLI package"
# Check if the files differ (useful for CI)
if ! cmp -s "$SOURCE_WASM" "$DEST_WASM"; then
echo "Warning: WASM files were out of sync!"
exit 1
fi
'''
[tasks.publish-cli-dry-run]
description = "Test publishing River CLI to crates.io (dry run)"
dependencies = ["sync-cli-wasm"]
command = "cargo"
args = ["publish", "--dry-run", "--allow-dirty"]
cwd = "./cli"
[tasks.publish-cli]
description = "Publish River CLI to crates.io"
dependencies = ["sync-cli-wasm"]
script = '''
#!/bin/bash
set -e
echo "⚠️ About to publish River CLI to crates.io!"
echo "Have you:"
echo " 1. Updated the version in cli/Cargo.toml?"
echo " 2. Committed all changes?"
echo " 3. Created a git tag?"
echo ""
read -p "Continue? (y/N) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Aborted."
exit 1
fi
cd cli
cargo publish
'''
[tasks.build-chat-delegate]
description = "Build the chat delegate WASM"
# `--locked` is load-bearing for reproducibility (freenet/river#2776 A1): the
# delegate key is BLAKE3(BLAKE3(wasm) || params) and users store room data under
# it, so the WASM must build from the committed Cargo.lock, not a freshly
# re-resolved graph. See scripts/sync-wasm.sh, which already builds `--locked`.
command = "cargo"
args = ["build", "--locked", "--profile", "${BUILD_PROFILE}", "--target", "${CONTRACT_TARGET}", "-p", "chat-delegate", "--target-dir", "target"]
[tasks.build-web-container]
description = "Build the web container contract WASM"
# `--locked` for reproducibility (freenet/river#2776 A1): the web-container
# contract ID is derived from this WASM + committed parameters. Publishing uses
# the committed published-contract/web_container_contract.wasm, but a rebuild
# (e.g. update-published-contract) must also come from the committed lock.
command = "cargo"
args = ["build", "--locked", "--profile", "${BUILD_PROFILE}", "--target", "${CONTRACT_TARGET}", "-p", "web-container-contract", "--target-dir", "target"]
[tasks.build-web-container-tool]
description = "Build the web container tool for native platform"
dependencies = ["build-web-container"]
command = "cargo"
args = ["build", "--profile", "${BUILD_PROFILE}", "--package", "web-container-tool", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu"]
[tasks.build-ui]
description = "Build the Dioxus UI"
# build-chat-delegate is required because UI includes delegate WASM via include_bytes!
dependencies = ["build-chat-delegate", "build-tailwind", "uncomment-base-path"]
command = "dx"
args = ["build", "--${BUILD_PROFILE}", "--features", "${UI_FEATURES}"]
cwd = "./ui"
[tasks.uncomment-base-path]
private = true
script = '''
# Match lines starting with optional whitespace, '#', optional whitespace, 'base_path', optional whitespace, '=', and the rest.
# Replace with the leading whitespace and 'base_path = ...', effectively removing the '#' and the space after it.
sed -i 's/^\([[:space:]]*\)#[[:space:]]*\(base_path[[:space:]]*=.*\)/\1\2/' ui/Dioxus.toml
'''
[tasks.comment-base-path]
private = true
script = '''
# Match lines starting with optional whitespace, 'base_path', optional whitespace, '=', and the rest.
# Replace with the leading whitespace, '#', then 'base_path = ...'.
sed -i 's/^\([[:space:]]*\)\(base_path[[:space:]]*=.*\)/\1#\2/' ui/Dioxus.toml
'''
[tasks.touch-ui-files]
private = true
script = '''
# Touch main.rs to force rebuild
touch ui/src/main.rs
'''
[tasks.clean-stale-assets]
private = true
description = "Remove stale hashed assets from dx output to prevent bloated webapp archives"
script = '''
ASSETS_DIR="target/dx/river-ui/${BUILD_PROFILE}/web/public/assets"
if [ -d "$ASSETS_DIR" ]; then
rm -rf "$ASSETS_DIR"
fi
'''
[tasks.build-ui-with-cleanup]
description = "Build the Dioxus UI and clean up afterwards"
dependencies = ["clean-stale-assets", "touch-ui-files", "build-ui", "comment-base-path"]
[tasks.compress-webapp]
description = "Compress the built webapp into tar.xz"
dependencies = ["build-ui-with-cleanup"]
script = '''
mkdir -p target/webapp
cd target/dx/river-ui/${BUILD_PROFILE}/web/public && \
tar -cJf ../../../../../webapp/webapp.tar.xz *
'''
[tasks.sign-webapp]
description = "Sign the compressed webapp"
dependencies = ["compress-webapp", "build-web-container-tool", "build-web-container"]
script = '''
# Bump the version counter committed at published-contract/contract-version.txt
# and use that as the metadata version. The previous `seconds/60` timestamp
# scheme was fragile — if any past publish ever ran with a clock skewed
# ahead (or someone hand-bumped to a future round number), the on-network
# version is stuck ahead and the timestamp-derived value can't catch up
# without manual intervention. 2026-05-16 incident: the on-network version
# was 30000208 while the timestamp gave 29649402, so the publish was
# rejected.
#
# Counter lifecycle:
# 1. `sign-webapp` here writes a `.prev-version` snapshot BEFORE bumping
# the counter file, so a downstream `publish-river` failure can roll
# back atomically (see [tasks.publish-river]'s `on-failure` arm).
# 2. The counter file is bumped to `current+1` and the new metadata is
# signed with that value.
# 3. After a successful `fdev publish`, the caller commits the bumped
# counter file (the snapshot is left for the publish task to clean
# up). Skeptical-review (#258) flagged that bumping before publish
# risks leaving the local file ahead of on-network if publish fails;
# the .prev-version snapshot + rollback closes that window.
#
# Locking: this script is NOT safe under two parallel `publish-river`
# runs on the same workstation — they would race the read-modify-write.
# Wrap in `flock` if you need that:
# flock published-contract/contract-version.txt cargo make publish-river
version_file="published-contract/contract-version.txt"
prev_snapshot="$version_file.prev"
if [ ! -f "$version_file" ]; then
echo "ERROR: $version_file missing. Seed it with the current on-network version."
exit 1
fi
current=$(cat "$version_file" | tr -d '[:space:]')
version=$((current + 1))
cp "$version_file" "$prev_snapshot"
echo "$version" > "$version_file"
echo "Web-container version: $current -> $version (commit $version_file after a successful publish)"
target/native/x86_64-unknown-linux-gnu/${BUILD_PROFILE}/web-container-tool sign \
--input target/webapp/webapp.tar.xz \
--output target/webapp/webapp.metadata \
--parameters target/webapp/webapp.parameters \
--version $version
'''
[tasks.build-ui-example]
description = "Build the Dioxus UI with example data"
env = { UI_FEATURES = "example-data" }
# build-chat-delegate is required because UI includes delegate WASM via include_bytes!
dependencies = ["build-chat-delegate"]
command = "dx"
args = ["build", "--${BUILD_PROFILE}", "--features", "${UI_FEATURES}"]
cwd = "./ui"
[tasks.build-ui-no-sync]
description = "Build the Dioxus UI without Freenet sync"
env = { UI_FEATURES = "no-sync" }
# build-chat-delegate is required because UI includes delegate WASM via include_bytes!
dependencies = ["build-chat-delegate"]
command = "dx"
args = ["build", "--${BUILD_PROFILE}", "--features", "${UI_FEATURES}"]
cwd = "./ui"
[tasks.build-ui-example-no-sync]
description = "Build the Dioxus UI with example data and no Freenet sync"
env = { UI_FEATURES = "example-data,no-sync" }
# build-chat-delegate is required because UI includes delegate WASM via include_bytes!
dependencies = ["build-chat-delegate"]
command = "dx"
args = ["build", "--${BUILD_PROFILE}", "--features", "${UI_FEATURES}"]
cwd = "./ui"
[tasks.test-web-container]
description = "Run tests for web-container-contract"
command = "cargo"
args = ["test", "--package", "web-container-contract", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu", "--lib", "--bins"]
[tasks.test-web-container-integration]
description = "Run integration tests for web-container-contract"
command = "cargo"
args = ["test", "--package", "web-container-contract", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu", "--test", "integration_tests"]
[tasks.test-room-contract]
description = "Run tests for room-contract"
command = "cargo"
args = ["test", "--package", "room-contract", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu"]
[tasks.test-scaffold]
description = "Run tests for scaffold crate"
command = "cargo"
args = ["test", "--package", "freenet-scaffold", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu"]
[tasks.test-common]
description = "Run tests for common crate"
command = "cargo"
args = ["test", "--package", "river-core", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu"]
[tasks.test-chat-delegate]
description = "Run tests for chat-delegate"
command = "cargo"
args = ["test", "--package", "chat-delegate", "--target-dir", "target/native", "--target", "x86_64-unknown-linux-gnu"]
[tasks.test]
description = "Run all tests"
dependencies = ["test-web-container", "test-web-container-integration", "test-room-contract", "test-scaffold", "test-common", "test-chat-delegate"]
[tasks.test-ui-playwright]
description = "Run Playwright UI tests (requires dx serve on port 8082)"
script = '''
cd ui/tests && npx playwright test "$@"
'''
[tasks.test-ui-playwright-setup]
description = "Install Playwright browsers and dependencies"
script = '''
cd ui/tests && npm install && npx playwright install --with-deps chromium firefox webkit
'''
[tasks.update-published-contract]
description = "Build, publish, and update the published contract files"
dependencies = ["sign-webapp"]
script = '''
# Get the contract ID without publishing
contract_id=$(fdev get-contract-id \
--code target/wasm32-unknown-unknown/release/web_container_contract.wasm \
--parameters target/webapp/webapp.parameters)
# Update published files
mkdir -p published-contract
cp target/wasm32-unknown-unknown/release/web_container_contract.wasm published-contract/
cp target/webapp/webapp.parameters published-contract/
echo "$contract_id" > published-contract/contract-id.txt
echo "Published contract updated with ID: $contract_id"
echo "Please commit the changes to git"
'''
[tasks.publish-river]
# GUARDRAIL: any republish that regenerates the room-contract / chat-delegate
# WASM MUST go through a PR that COMMITS the regenerated WASM (run `cargo make
# sync-wasm`, stage ui/public/contracts/ + cli/contracts/ + the migration TOMLs
# per .claude/rules/delegate-migration.md). That is what makes CI's
# check-room-contract-migration / check-delegate-migration run and demand a
# migration entry. A local `sync-wasm` + `publish-river` that skips committing
# the new WASM would silently re-key the on-network contract with NO CI
# trip-wire and orphan every user's room data.
description = "Publish River to Freenet using the committed contract version"
dependencies = ["sign-webapp"]
script = '''
if [ ! -f "published-contract/contract-id.txt" ]; then
echo "No published contract found"
exit 1
fi
contract_id=$(cat published-contract/contract-id.txt)
echo "Publishing using committed contract: $contract_id"
version_file="published-contract/contract-version.txt"
prev_snapshot="$version_file.prev"
if fdev network publish \
--code published-contract/web_container_contract.wasm \
--parameters published-contract/webapp.parameters \
contract \
--webapp-archive target/webapp/webapp.tar.xz \
--webapp-metadata target/webapp/webapp.metadata; then
# Publish succeeded — the bumped counter file is the new truth.
# Discard the snapshot. Caller must commit $version_file.
rm -f "$prev_snapshot"
echo "Publish OK. Remember to commit $version_file."
else
rc=$?
# Publish failed — roll the counter back so subsequent retries
# don't accumulate a drift. The on-network version is unchanged,
# and our local counter is now matched to it again.
if [ -f "$prev_snapshot" ]; then
mv "$prev_snapshot" "$version_file"
echo "Publish failed (exit $rc); rolled $version_file back to its pre-publish value." >&2
fi
exit $rc
fi
'''
[tasks.publish-river-debug]
description = "Publish River to Freenet in debug mode"
env = { BUILD_PROFILE = "dev" }
dependencies = ["sign-webapp"]
script = '''
if [ ! -f "published-contract/contract-id.txt" ]; then
echo "No published contract found"
exit 1
fi
contract_id=$(cat published-contract/contract-id.txt)
echo "Publishing using committed contract in debug mode: $contract_id"
version_file="published-contract/contract-version.txt"
prev_snapshot="$version_file.prev"
if fdev network publish \
--code published-contract/web_container_contract.wasm \
--parameters published-contract/webapp.parameters \
contract \
--webapp-archive target/webapp/webapp.tar.xz \
--webapp-metadata target/webapp/webapp.metadata; then
rm -f "$prev_snapshot"
else
rc=$?
if [ -f "$prev_snapshot" ]; then
mv "$prev_snapshot" "$version_file"
echo "Publish failed (exit $rc); rolled $version_file back to its pre-publish value." >&2
fi
exit $rc
fi
'''
# Test publishing tasks - use separate keypair to avoid affecting production
[tasks.generate-test-keys]
description = "Generate test keypair for publishing (one-time)"
dependencies = ["build-web-container-tool"]
script = '''
mkdir -p test-contract
target/native/x86_64-unknown-linux-gnu/${BUILD_PROFILE}/web-container-tool generate \
--output test-contract/test-keys.toml
echo "Test keys generated in test-contract/test-keys.toml"
echo "Run 'cargo make sign-webapp-test' to sign with test keys"
'''
[tasks.compress-webapp-test]
description = "Build (retargeted to the test contract) and compress the webapp"
# NOTE: deliberately does NOT depend on build-ui-with-cleanup. That task bakes
# the PRODUCTION base_path into the build. For the test contract we must bake
# the TEST contract ID as the base_path BEFORE building, so we run the build
# ourselves here. build-chat-delegate + build-tailwind are the same UI build
# prerequisites build-ui depends on.
dependencies = [
"build-chat-delegate",
"build-tailwind",
"build-web-container",
"build-web-container-tool",
"clean-stale-assets",
]
script = '''
set -e
PROD_ID="raAqMhMG7KUpXBU2SxgCQ3Vh4PYjttxdSWd9ftV7RLv"
TOOL="target/native/x86_64-unknown-linux-gnu/${BUILD_PROFILE}/web-container-tool"
DIOXUS_TOML="ui/Dioxus.toml"
if [ ! -f "test-contract/test-keys.toml" ]; then
echo "No test keys found. Run 'cargo make generate-test-keys' first"
exit 1
fi
# The test contract ID is derive(web_container_contract.wasm, parameters),
# and parameters are just the test signing identity's verifying-key bytes.
# We need the ID BEFORE building the UI so the correct base_path is baked into
# the WASM as DIOXUS_ASSET_ROOT (release web builds resolve asset!() URLs from
# the compile-time-baked base_path, NOT from window.location). Generate the
# parameters from the test keys directly so we don't depend on a prior sign.
mkdir -p target/webapp
"$TOOL" export-parameters \
--parameters target/webapp/webapp-test.parameters \
--key-file test-contract/test-keys.toml
TEST_ID=$(fdev get-contract-id \
--code target/wasm32-unknown-unknown/release/web_container_contract.wasm \
--parameters target/webapp/webapp-test.parameters)
if [ -z "$TEST_ID" ]; then
echo "ERROR: Cannot determine test contract ID"
exit 1
fi
echo "Building webapp retargeted to test contract: $PROD_ID -> $TEST_ID"
# Set base_path to the TEST contract ID for this build, then restore the
# committed (commented, production) value afterwards. This is the same
# approach scripts/local-republish.sh uses and is the ONLY length-safe way to
# retarget the contract ID — rewriting the built WASM with a different-length
# base58 ID corrupts the module (freenet/river#257).
restore_dioxus() {
perl -pi -e "s|^\\s*#?\\s*base_path\\s*=\\s*\".*\"|#base_path = \"v1/contract/web/${PROD_ID}\"|" "$DIOXUS_TOML"
}
trap restore_dioxus EXIT
if grep -q "^#\\?base_path" "$DIOXUS_TOML"; then
perl -pi -e "s|^\\s*#?\\s*base_path\\s*=\\s*\".*\"|base_path = \"v1/contract/web/${TEST_ID}\"|" "$DIOXUS_TOML"
else
echo "ERROR: no base_path line found in $DIOXUS_TOML"
exit 1
fi
# Force the UI to recompile so the new base_path is actually baked in. dx keys
# its incremental build off source mtimes and does NOT treat a Dioxus.toml
# base_path edit as a source change, so without this a rerun after regenerating
# test keys (new TEST_ID) could reuse artifacts carrying the PREVIOUS test ID.
# (build-ui-with-cleanup gets this via its touch-ui-files dep; we replicate it.)
touch ui/src/main.rs
(cd ui && dx build --${BUILD_PROFILE} --features "${UI_FEATURES}")
restore_dioxus
trap - EXIT
# Sanity-check the freshly built output BEFORE packaging, so we never sign and
# publish a mis-targeted webapp:
# 1. POSITIVE: the loaders must reference THIS run's TEST_ID. This catches a
# stale build that still carries a previous test contract's ID (dx artifact
# reuse) — the production-ID check below would not.
# 2. NEGATIVE: the production contract ID must not appear anywhere
# (HTML/JS/WASM), i.e. the base_path retarget took full effect.
PUBLIC_DIR="target/dx/river-ui/${BUILD_PROFILE}/web/public"
if ! grep -rqF "$TEST_ID" "$PUBLIC_DIR/index.html"; then
echo "ERROR: built test webapp does not reference this run's test contract ID."
echo " Expected $TEST_ID in $PUBLIC_DIR/index.html (stale build?)."
exit 1
fi
if grep -rqF "$PROD_ID" "$PUBLIC_DIR"; then
echo "ERROR: built test webapp still references the production contract ID."
echo " The base_path retarget did not take effect; refusing to publish."
grep -rlF "$PROD_ID" "$PUBLIC_DIR" || true
exit 1
fi
# Compress
(cd "$PUBLIC_DIR" && tar -cJf "$OLDPWD/target/webapp/webapp-test.tar.xz" *)
echo "Test webapp: target/webapp/webapp-test.tar.xz"
'''
[tasks.sign-webapp-test]
description = "Sign webapp with test keypair"
dependencies = ["compress-webapp-test", "build-web-container-tool", "build-web-container"]
script = '''
if [ ! -f "test-contract/test-keys.toml" ]; then
echo "No test keys found. Run 'cargo make generate-test-keys' first"
exit 1
fi
# Monotonic counter in test-contract/contract-version.txt — same rationale
# as the production publish (see [tasks.sign-webapp] for the 2026-05-16
# incident). Test contract counter is NOT committed since the test
# contract ID is regenerated freely.
# .prev snapshot is captured here for the publish task to roll back on
# failure — same pattern as the production sign/publish flow.
version_file="test-contract/contract-version.txt"
prev_snapshot="$version_file.prev"
if [ ! -f "$version_file" ]; then
echo "0" > "$version_file"
fi
current=$(cat "$version_file" | tr -d '[:space:]')
version=$((current + 1))
cp "$version_file" "$prev_snapshot"
echo "$version" > "$version_file"
echo "Test web-container version: $current -> $version"
target/native/x86_64-unknown-linux-gnu/${BUILD_PROFILE}/web-container-tool sign \
--input target/webapp/webapp-test.tar.xz \
--output target/webapp/webapp-test.metadata \
--parameters target/webapp/webapp-test.parameters \
--version $version \
--key-file test-contract/test-keys.toml
'''
[tasks.update-test-contract]
description = "Update test contract files without publishing"
dependencies = ["sign-webapp-test"]
script = '''
contract_id=$(fdev get-contract-id \
--code target/wasm32-unknown-unknown/release/web_container_contract.wasm \
--parameters target/webapp/webapp-test.parameters)
mkdir -p test-contract
cp target/wasm32-unknown-unknown/release/web_container_contract.wasm test-contract/
cp target/webapp/webapp-test.parameters test-contract/webapp.parameters
echo "$contract_id" > test-contract/contract-id.txt
echo "Test contract updated with ID: $contract_id"
'''
[tasks.publish-river-test]
description = "Publish River to test contract (separate from production)"
dependencies = ["sign-webapp-test"]
script = '''
if [ ! -f "test-contract/test-keys.toml" ]; then
echo "No test keys found. Run 'cargo make generate-test-keys' first"
exit 1
fi
contract_id=$(fdev get-contract-id \
--code target/wasm32-unknown-unknown/release/web_container_contract.wasm \
--parameters target/webapp/webapp-test.parameters)
echo "Publishing TEST contract: $contract_id"
version_file="test-contract/contract-version.txt"
prev_snapshot="$version_file.prev"
if fdev network publish \
--code target/wasm32-unknown-unknown/release/web_container_contract.wasm \
--parameters target/webapp/webapp-test.parameters \
contract \
--webapp-archive target/webapp/webapp-test.tar.xz \
--webapp-metadata target/webapp/webapp-test.metadata; then
rm -f "$prev_snapshot"
else
rc=$?
if [ -f "$prev_snapshot" ]; then
mv "$prev_snapshot" "$version_file"
echo "Test publish failed (exit $rc); rolled $version_file back." >&2
fi
exit $rc
fi
echo ""
echo "Test River available at: http://127.0.0.1:7509/v1/contract/web/$contract_id/"
echo "Test contract ID: $contract_id"
'''
[tasks.bump-cli-version]
description = "Auto-increment riverctl patch version in cli/Cargo.toml"
script = '''
#!/bin/bash
set -e
CARGO_TOML="cli/Cargo.toml"
CURRENT=$(grep '^version' "$CARGO_TOML" | head -1 | sed 's/.*"\(.*\)".*/\1/')
MAJOR=$(echo "$CURRENT" | cut -d. -f1)
MINOR=$(echo "$CURRENT" | cut -d. -f2)
PATCH=$(echo "$CURRENT" | cut -d. -f3)
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
sed -i "0,/^version = \"$CURRENT\"/s//version = \"$NEW_VERSION\"/" "$CARGO_TOML"
echo "Bumped riverctl: $CURRENT → $NEW_VERSION"
'''
[tasks.publish-all]
# NOTE: the canonical way to release riverctl is now the tag-triggered CI
# workflow (.github/workflows/release-riverctl.yml) — push a `riverctl-v<ver>`
# tag and CI publishes to crates.io AND cuts the GitHub release with binaries.
# See .claude/rules/river-publish.md "Releasing riverctl". This local task
# remains for the coupled UI+riverctl WASM-change case / as a fallback; it
# publishes from your laptop and does NOT create a GitHub release.
description = "Publish River UI + riverctl locally (legacy; prefer tag-triggered CI for riverctl)"
dependencies = ["sync-cli-wasm"]
script = '''
#!/bin/bash
set -e
echo "========================================="
echo " River Publish-All"
echo "========================================="
echo ""
# Step 1: Build and publish River UI
echo "▶ Step 1/5: Building River UI..."
cargo make compress-webapp
cargo make sign-webapp
echo ""
echo "▶ Step 2/5: Publishing River UI to Freenet..."
cargo make publish-river
# Step 2: Bump riverctl version
echo ""
echo "▶ Step 3/5: Bumping riverctl version..."
cargo make bump-cli-version
NEW_VERSION=$(grep '^version' cli/Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
# Step 3: Commit the version bump
echo ""
echo "▶ Step 4/5: Committing version bump..."
git add cli/Cargo.toml
git commit -m "chore: bump riverctl to v${NEW_VERSION} (WASM sync)"
# Step 4: Publish to crates.io
echo ""
echo "▶ Step 5/5: Publishing riverctl v${NEW_VERSION} to crates.io..."
cd cli
cargo publish
cd ..
echo ""
echo "========================================="
echo " ✅ Publish complete!"
echo " River UI: published to Freenet"
echo " riverctl: v${NEW_VERSION} on crates.io"
echo "========================================="
echo ""
echo "Don't forget to: git push origin main"
'''
# =============================================================================
# Migration & WASM sync tasks
# =============================================================================
[tasks.check-migration]
description = "Check if delegate WASM changed and migration entry is needed"
script = ["scripts/check-migration.sh"]
[tasks.add-migration]
description = "Add migration entry for currently committed delegate WASM"
script = '''
#!/bin/bash
set -e
# Auto-detect next version number from TOML
LAST_VERSION=$(grep '^version' legacy_delegates.toml | tail -1 | sed 's/.*"V\([0-9]*\)".*/\1/')
NEXT_VERSION="V$((LAST_VERSION + 1))"
echo "Next version: $NEXT_VERSION"
read -p "Description of what changed: " DESCRIPTION
scripts/add-migration.sh "$NEXT_VERSION" "$DESCRIPTION"
'''
[tasks.check-room-contract-migration]
description = "Check if room-contract WASM changed and a registry entry is needed (#292)"
script = ["scripts/check-room-contract-migration.sh"]
[tasks.add-room-contract-migration]
description = "Add registry entry for currently committed room-contract WASM (#292)"
script = '''
#!/bin/bash
set -e
# Auto-detect next version number from the room-contract registry TOML.
LAST_VERSION=$(grep '^version' common/legacy_room_contracts.toml | tail -1 | sed 's/.*"V\([0-9]*\)".*/\1/')
NEXT_VERSION="V$((LAST_VERSION + 1))"
echo "Next version: $NEXT_VERSION"
read -p "Description of what changed: " DESCRIPTION
scripts/add-room-contract-migration.sh "$NEXT_VERSION" "$DESCRIPTION"
'''
[tasks.sync-wasm]
description = "Build all WASMs and copy to committed locations"
script = ["scripts/sync-wasm.sh"]
# ─── Developer Setup ───────────────────────────────────────────────────────────
#
# Run `cargo make setup` after cloning to enable git hooks that prevent
# accidental WASM commits (which break delegate key continuity and cause
# data loss). See .githooks/pre-commit and .claude/rules/wasm-safety.md.
[tasks.setup]
description = "One-time repo setup: configures git hooks for WASM safety"
script = '''
#!/bin/bash
set -e
echo "Configuring git hooks path → .githooks/"
git config core.hooksPath .githooks
echo ""
echo "✓ Git hooks enabled. The pre-commit hook will now block commits that"
echo " stage WASM files (ui/public/contracts/, cli/contracts/) without a"
echo " corresponding migration entry in legacy_delegates.toml."
echo ""
echo " This prevents accidental delegate key changes that break room data."
echo " See .claude/rules/wasm-safety.md for details."
echo ""
echo " To intentionally update WASMs:"
echo " 1. cargo make add-migration"
echo " 2. cargo make sync-wasm"
echo " 3. Stage legacy_delegates.toml alongside the WASMs"
'''
[tasks.clippy]
description = "Run clippy on all packages"
command = "cargo"
args = ["clippy", "--manifest-path", "./Cargo.toml", "--workspace", "--all-targets", "--", "-D", "warnings"]
[tasks.build]
description = "Build everything in release mode (optimized)"
dependencies = ["build-ui-with-cleanup", "build-web-container"]
[tasks.dev-example]
description = "Development build with example data"
env = { UI_FEATURES = "example-data", BUILD_PROFILE = "dev" }
# build-chat-delegate is required because UI includes delegate WASM via include_bytes!
dependencies = ["build-chat-delegate", "build-tailwind"]
command = "dx"
args = ["serve", "--features", "${UI_FEATURES}"]
cwd = "./ui"
[tasks.build-example]
description = "Build everything in release mode with example data"
dependencies = ["build-ui-example"]
[tasks.build-debug]
description = "Build everything in debug mode (faster builds)"
env = { BUILD_PROFILE = "dev" }
dependencies = ["build-ui"]
[tasks.dev]
description = "Development build"
env = { UI_FEATURES = "" }
# build-chat-delegate is required because UI includes delegate WASM via include_bytes!
dependencies = ["build-chat-delegate"]
command = "dx"
args = ["serve"]
cwd = "./ui"