interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / dl / tests / fstub.om

490 lines · 8361 bytes Raw Blame History
1note dl/tests/fstub.om: TEST-ONLY stand-in for server/util.om (contract v1 names), so dl/dl.om can be
2note compiled and exercised before the server lands. Never composed into forged.
3note Differences from the real util: the storage root and the allow-list come from the test main
4note (gtstore, gtan/gtnm/gtrid), tfdata points at /tmp/forge-dltest/data/, frepohd is a marker.
5global fmeth ulong 1
6global fpath uchar 4096
7global fpathl ulong 1
8global fqs uchar 4096
9global fqsl ulong 1
10global fbase uchar 64
11global fbasel ulong 1
12global fridx ulong 1
13global frid uchar 64
14global fridl ulong 1
15global fown uchar 64
16global fownl ulong 1
17global frepo uchar 128
18global frepol ulong 1
19global frest uchar 4096
20global frestl ulong 1
21global finm uchar 256
22global finml ulong 1
23global fan ulong 1
24global fob uchar 8388608
25global fobl ulong 1
26note fobtr (server/util.om): a byte was dropped or a cut copy was read (dlmsg sets it when git fails)
27global fobtr ulong 1
28global fkind ulong 1
29global fct uchar 128
30global fctl ulong 1
31global fcd uchar 512
32global fcdl ulong 1
33global fti uchar 256
34global ftil ulong 1
35global floc uchar 4096
36global flocl ulong 1
37global ffile uchar 4096
38global ffilel ulong 1
39global fetag uchar 128
40global fetagl ulong 1
41global fcc uchar 128
42global fccl ulong 1
43global fretry ulong 1
44global fval uchar 4096
45global fpk uchar 8192
46global fpkl ulong 1
47global fpkr ulong 1
48global fxo uchar 16777216
49global fxol ulong 1
50global fxotr ulong 1
51note fincut (server/repos.om): the stub only records the call
52global ficut ulong 1
53fn fincut to void
54put ficut 0 1
55end
56global fpfd uchar 8
57global fwst uchar 4
58global fjunk uchar 4096
59global gtstore uchar 512
60global gtstl ulong 1
61text tfstore "/home/drakestapleton/.radicle/storage/"
62text tfgit "/usr/bin/git"
63text tfdata "/tmp/forge-dltest/data/"
64text tfowner "drakestapleton"
65text tfnid "z6MkfZDue1TbaNFi3ZzcD9uiTeduPLC52ucdFVuLKZwexxhK"
66text tfgitd "--git-dir="
67text tfnul "/dev/null"
68text tfamp "&"
69text tflt "<"
70text tfgt ">"
71text tfquot """
72text tfapos "'"
73text tfhd "<!-- repo header tab "
74text tfhdx " -->\n"
75fn fputc c uchar to void
76n = get fobl 0
77if lt n len fob
78put fob n c
79put fobl 0 add n 1
80ret
81end
82put fobtr 0 1
83end
84fn fput s view uchar * to void
85for i ulong len s
86fputc get s i
87end
88end
89fn fescc c uchar to void
90if eq c 38
91fput tfamp
92ret
93end
94if eq c 60
95fput tflt
96ret
97end
98if eq c 62
99fput tfgt
100ret
101end
102if eq c 34
103fput tfquot
104ret
105end
106if eq c 39
107fput tfapos
108ret
109end
110fputc c
111end
112fn fesc s view uchar * to void
113for i ulong len s
114fescc get s i
115end
116end
117note fxesc (server/util.om): fxo[a, a+n) escaped into the body; dlmsg's subject and notes use it
118fn fxesc a ulong n ulong to void
119for i ulong n bound 16777216
120fescc get fxo add a i
121end
122end
123fn fnum v ulong to void
124d = new uchar 20 0
125i = ulong 20
126x = v
127for it ulong 20
128i = sub i 1
129put d i uchar add rem x 10 48
130x = div x 10
131if eq x 0
132break
133end
134end
135for k ulong sub 20 i
136fputc get d add i k
137end
138end
139fn fputb to void
140for i ulong get fbasel 0
141fputc get fbase i
142end
143end
144fn fputrepo to void
145for i ulong get fownl 0
146fescc get fown i
147end
148fputc 47
149for i ulong get frepol 0
150fescc get frepo i
151end
152end
153fn frepohd tab ulong to void
154fput tfhd
155fnum tab
156fput tfhdx
157end
158fn fsetct t view uchar * to void
159for i ulong len t
160put fct i get t i
161end
162put fctl 0 len t
163end
164fn fsetcd t view uchar * to void
165for i ulong len t
166put fcd i get t i
167end
168put fcdl 0 len t
169end
170fn fcdc c uchar to void
171n = get fcdl 0
172if lt n 512
173put fcd n c
174put fcdl 0 add n 1
175end
176end
177fn fsetti t view uchar * to void
178put ftil 0 0
179for i ulong len t
180ftic get t i
181end
182end
183fn ftic c uchar to void
184n = get ftil 0
185if lt n 256
186put fti n c
187put ftil 0 add n 1
188end
189end
190fn flocb to void
191n = get fbasel 0
192for i ulong n
193put floc i get fbase i
194end
195put flocl 0 n
196end
197fn flocc c uchar to void
198n = get flocl 0
199if lt n 4096
200put floc n c
201put flocl 0 add n 1
202end
203end
204fn floct t view uchar * to void
205for i ulong len t
206flocc get t i
207end
208end
209note fqget: query param n from fqs into fval (percent-decoded, + = space); length or -1
210fn fqget n view uchar * to long
211q = get fqsl 0
212s = ulong 0
213for i ulong add q 1
214if or eq i q eq get fqs i 38
215if fqmatch s i n
216ret fqdec add s add len n 1 i
217end
218s = add i 1
219end
220end
221ret -1
222end
223fn fqmatch s ulong e ulong n view uchar * to bool
224if lt sub e s add len n 1
225ret false
226end
227for i ulong len n
228if ne get fqs add s i get n i
229ret false
230end
231end
232ret eq get fqs add s len n 61
233end
234fn fqdec a ulong e ulong to long
235k = ulong 0
236i = a
237for it ulong 4096
238if ge i e
239break
240end
241c = get fqs i
242if eq c 43
243c = 32
244end
245put fval k c
246k = add k 1
247i = add i 1
248end
249ret long k
250end
251note ---- argv packet fpk
252fn fkb to void
253put fpk 0 0
254put fpk 1 0
255put fpkl 0 2
256end
257fn fkopen to void
258n = get fpkl 0
259put fpkr 0 n
260put fpk n 0
261put fpk add n 1 0
262put fpkl 0 add n 2
263c = add or ulong get fpk 0 shl ulong get fpk 1 8 1
264put fpk 0 uchar and c 255
265put fpk 1 uchar shr c 8
266end
267fn fkc c uchar to void
268n = get fpkl 0
269if lt n 8191
270put fpk n c
271put fpkl 0 add n 1
272r = get fpkr 0
273k = add or ulong get fpk r shl ulong get fpk add r 1 8 1
274put fpk r uchar and k 255
275put fpk add r 1 uchar shr k 8
276end
277end
278fn fka t view uchar * to void
279fkopen
280for i ulong len t
281fkc get t i
282end
283end
284fn fksource to void
285fkgit
286end
287fn fkgit to void
288fkb
289fka tfgit
290fkopen
291for i ulong len tfgitd
292fkc get tfgitd i
293end
294for i ulong get gtstl 0
295fkc get gtstore i
296end
297for i ulong get fridl 0
298fkc get frid i
299end
300end
301fn fpfdv i ulong to int
302b = mul i 4
303v = or ulong get fpfd b shl ulong get fpfd add b 1 8
304v = or v shl ulong get fpfd add b 2 16
305v = or v shl ulong get fpfd add b 3 24
306ret int v
307end
308fn fchild wfd int to void
309nul = fopen tfnul 0 len tfnul 2 0
310if lt nul 0
311exit 126
312end
313x = dupfd int nul 0 0
314x = dupfd wfd 1 0
315x = dupfd int nul 2 0
316x = execprog fpk 0 get fpkl 0
317exit 127
318end
319fn fdrain fd int dl long to bool
320for it ulong 1000000
321left = sub dl long monons
322if le left 0
323ret false
324end
325w = waitio fd 1 left
326if lt w 0
327if ne w -4
328ret false
329end
330continue
331end
332if eq w 0
333continue
334end
335n = get fxol 0
336if ge n len fxo
337put fxotr 0 1
338r = read fd fjunk 0 4096
339if eq r 0
340ret true
341end
342if and lt r 0 and ne r -4 ne r -11
343ret false
344end
345continue
346end
347r = read fd fxo n sub len fxo n
348if eq r 0
349ret true
350end
351if lt r 0
352if and ne r -4 ne r -11
353ret false
354end
355continue
356end
357put fxol 0 add n ulong r
358end
359ret false
360end
361fn freap pid int dl long to long
362for it ulong 100000
363w = waitpid pid fwst 0 4 1
364if eq w long pid
365s = or ulong get fwst 0 shl ulong get fwst 1 8
366if eq and s 127 0
367ret long and shr s 8 255
368end
369ret -3
370end
371if lt w 0
372if ne w -4
373ret -4
374end
375continue
376end
377if gt long monons dl
378x = killpid pid 9
379w = waitpid pid fwst 0 4 0
380ret -1
381end
382x = sleepns 2000000
383end
384ret -4
385end
386fn fexec tmo long to long
387put fxol 0 0
388put fxotr 0 0
389r = pipefds fpfd 0 8 524288
390if lt r 0
391ret -2
392end
393rfd = fpfdv 0
394wfd = fpfdv 1
395dl = add long monons tmo
396pid = fork
397if lt pid 0
398x = fclose rfd
399x = fclose wfd
400ret -2
401end
402if eq pid 0
403fchild wfd
404exit 127
405end
406x = fclose wfd
407ok = fdrain rfd dl
408x = fclose rfd
409if not ok
410x = killpid int pid 9
411end
412st = freap int pid dl
413if not ok
414ret -1
415end
416ret st
417end
418note ---- path builder fpth and whole-file read into fxo: copy of server/util.om fpb fpc fpt frdall, for
419note nodes/head.om nshead (dldefbr), which the test compose now includes as run.sh units does
420global fpth uchar 4096
421global fpthl ulong 1
422fn fpb to void
423put fpthl 0 0
424end
425fn fpc c uchar to void
426n = get fpthl 0
427if lt n 4095
428put fpth n c
429put fpthl 0 add n 1
430end
431end
432fn fpt t view uchar * to void
433for i ulong len t bound 4096
434fpc get t i
435end
436end
437fn frdall to long
438put fxol 0 0
439put fxotr 0 0
440fd = fopen fpth 0 get fpthl 0 524288 0
441if lt fd 0
442ret fd
443end
444for it ulong 100000
445n = get fxol 0
446if ge n len fxo
447put fxotr 0 1
448break
449end
450r = read int fd fxo n sub len fxo n
451if le r 0
452break
453end
454put fxol 0 add n ulong r
455end
456x = fclose int fd
457ret long get fxol 0
458end
459note ---- machine-form seams (server/json.om, server/jsonp.om): the driver asks for HTML only, so
460note fjwant is false and dljrels / dljrtag are never entered here; they are exercised over HTTP
461note against a trial forged (docs/API.md). fyalt is a no-op: the driver prints no head.
462fn fjwant to bool
463ret false
464end
465fn fyalt to void
466end
467fn fputrl to void
468fputb
469fputrepo
470end
471fn fyrhead t view uchar * to void
472end
473fn fyk t view uchar * to void
474end
475fn fyk0 t view uchar * to void
476end
477fn fyend to void
478end
479fn fybool b bool to void
480end
481fn fynull to void
482end
483fn fjtb to void
484end
485fn fjtc c uchar to void
486end
487fn fjstr to void
488end
489fn fjiso t ulong to void
490end