code wiki / _hdl_build / nx_vroom_gitea_stage.nx
nx_vroom_gitea_stage.nx source
↩ module page · 84 lines · 5313 B
1import "nx_gate_gn.nx"
2// nx_vroom_gitea_stage.nx -- promote the PUBLISHER-verified /video/ client into the GITEA-TRACKED
3// SOURCE (sites/nishifamily/video/), so the established Gitea push cycle deploys it (operator
4// 2026-06-23: "do it with the nishi team's capabilities ... so we don't crash with direct touches";
5// confirmed: /video/ is served from a dir fed by Gitea on 192.168.8.227).
6//
7// THE NO-CRASH GUARANTEE: this is a LOCAL write into the deployable git source -- NOT a hand-overwrite
8// of a live NAS file. git's atomic ref update + the NAS checkout/pull is what swaps the live bytes, so
9// a partial write can never leave a corrupt live file (the direct-touch crash risk).
10//
11// Source = the publisher's SHA-VERIFIED, atomically-promoted liveroot (knowledge/publish/video-live/),
12// so we stage exactly what the publisher approved -- the publisher stays the deploy authority. Byte-exact
13// copy + marker-verify (scaleX(-1) in index.html, 'tile self' in app.js) so a bad/empty source is HELD,
14// not committed. Idempotent (safe to run twice). NEXT rung: ark-push lane add(these 2 files only)+commit+
15// push to Gitea, then nx_live_verify must find scaleX(-1) in the SERVED bytes before it is 'done'.
16// license_tier: ORIGINAL
17import "nx_syscalls.nx"
18
19const SRC_IDX: *u8 = "knowledge/publish/video-live/video/index.html"
20const SRC_APP: *u8 = "knowledge/publish/video-live/video/app.js"
21const DST_IDX: *u8 = "sites/nishifamily/video/index.html"
22const DST_APP: *u8 = "sites/nishifamily/video/app.js"
23const GS_LOG: *u8 = "knowledge/status/vroom_gitea_stage.log"
24
25func gwf(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
26func gnf(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(fd,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(fd,bb,k); return 0 }
27func gw(s: *u8) -> i64 { return gwf(1, s) }
28func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
29func find_sub(hay: *u8, n: i64, needle: *u8) -> i64 {
30 let m: i64=slen(needle); if m==0 { return 0 }
31 var i: i64=0
32 while i+m<=n { var j: i64=0; var ok: i64=1; while j<m { if hay[i+j]!=needle[j] { ok=0; j=m } else { j=j+1 } } if ok==1 { return i } i=i+1 }
33 return 0-1
34}
35// byte-exact copy src->dst; -1 = read fail (source missing), -2 = write fail, else bytes written
36func copy_file(src: *u8, dst: *u8, lb: *i64) -> i64 {
37 let b: *u8 = sys_read_file(src, lb)
38 if (b as i64)==0 { return 0-1 }
39 let n: i64 = lb[0]
40 let fd: i64 = sys_openat_wr(dst, 0x1a4)
41 if fd<0 { return 0-2 }
42 sys_write(fd, b, n); sys_close(fd)
43 return n
44}
45
46func main() -> i64 {
47 gw("=== nx_vroom_gitea_stage -- promote publisher-verified /video/ client -> Gitea source (SAFE local write) ===\n")
48 let lb: *i64 = sys_mmap(8) as *i64
49
50 let ni: i64 = copy_file(SRC_IDX, DST_IDX, lb)
51 if ni == 0-1 { gw(" FATAL: publisher liveroot index.html missing -- run nx_vroom_emit + nx_pub_vroom_emit_handoff first\n"); sys_exit(1); return 1 }
52 if ni == 0-2 { gw(" FATAL: cannot write sites/nishifamily/video/index.html\n"); sys_exit(1); return 1 }
53 gw(" index.html: publisher-liveroot -> sites/nishifamily/video/index.html bytes="); gn(ni); gw("\n")
54
55 let na: i64 = copy_file(SRC_APP, DST_APP, lb)
56 if na == 0-1 { gw(" FATAL: publisher liveroot app.js missing -- run the upstream organs first\n"); sys_exit(1); return 1 }
57 if na == 0-2 { gw(" FATAL: cannot write sites/nishifamily/video/app.js\n"); sys_exit(1); return 1 }
58 gw(" app.js : publisher-liveroot -> sites/nishifamily/video/app.js bytes="); gn(na); gw("\n")
59
60 // VERIFY the fix markers are now in the Gitea SOURCE (exactly what git will commit + push)
61 var css_src: i64 = 0-1; var self_src: i64 = 0-1
62 let vi: *u8 = sys_read_file(DST_IDX, lb); let vin: i64 = lb[0]
63 if (vi as i64)!=0 { css_src = find_sub(vi, vin, "scaleX(-1)" as *u8) }
64 let va: *u8 = sys_read_file(DST_APP, lb); let van: i64 = lb[0]
65 if (va as i64)!=0 { self_src = find_sub(va, van, "tile self" as *u8) }
66 gw(" VERIFY Gitea source: index.html scaleX(-1) @"); gn(css_src); gw(" ; app.js 'tile self' @"); gn(self_src); gw("\n")
67
68 var ok: i64 = 1
69 if ni<=0 { ok=0 }
70 if na<=0 { ok=0 }
71 if css_src<0 { ok=0 }
72 if self_src<0 { ok=0 }
73
74 let lfd: i64 = sys_openat_append(GS_LOG, 420)
75 if lfd>=0 { gwf(lfd,"GITEASTAGE idx_bytes="); gnf(lfd,ni); gwf(lfd," app_bytes="); gnf(lfd,na); gwf(lfd," css@"); gnf(lfd,css_src); gwf(lfd," self@"); gnf(lfd,self_src); if ok==1 { gwf(lfd," verdict=GREEN\n") } else { gwf(lfd," verdict=RED\n") } sys_close(lfd) }
76
77 if ok==1 {
78 gw(" GREEN: the camera-fix is now in the Gitea-tracked SOURCE (sites/nishifamily/video/). git push deploys it -- no live-file overwrite, no crash.\n")
79 gw(" NEXT (final rungs): ark-push lane add(THESE 2 files only)+commit+push to Gitea, NAS checkout updates, then nx_live_verify must find scaleX(-1) in the SERVED bytes. No 'done' before that.\n")
80 sys_exit(0); return 0
81 }
82 gw(" RED: promote or marker-verify failed -- NOT staged for Gitea (would be a bad deploy -- HELD).\n")
83 sys_exit(1); return 1
84}