Реверснутый zcode с своими фишками и плагинами · VibeGit
Реверснутый zcode с своими фишками и плагинами Реверснутая ade zcode без z ai, с массовой загрузкой ключей, умным апи роутингом, плагином для командной разработки
reversnutyy-zcode-s-svoimi-fishkami-i-plaginami / fork / team / test / service.test.mjs 944 строк · изменён 13 нояб., 21:19
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
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
import { test, before, after } from 'node:test' ;
import assert from 'node:assert/strict' ;
import http from 'node:http' ;
import crypto from 'node:crypto' ;
import fs from 'node:fs' ;
import os from 'node:os' ;
import path from 'node:path' ;
import { spawn, execFileSync } from
path
path
path
process
fake
fake
backend http
url req
p url
body obj obj
res code body
res body
chunks
c req chunks c
rawBody chunks
fake req p
rawBody
authed req
req p
b
b b fake
req p
authed
base
req p
req p
b
b fake
fake b
req p
fake
req p
b
assignee m b
t crypto b b b assignee id b b b
fake t assignee displayName t
t t t
m p
m req
t fake x m
t
b
t b
b t x b displayName
t
m p
m req
m
req p
req p
tok crypto
fake tok
tok tok
m p
m req
fake m
req p fake k
req p
b
k b
key crypto b k
fake key
value pub key
pub
req p
req p
fake
fake
req p p
ct req
boundary ct
boundary
headEnd rawBody
head rawBody headEnd
tail
rawBody rawBody tail tail
content rawBody headEnd rawBody tail
plain head
up
p
url
plain plain
content
crypto content
req
rawBody
fake up
crypto up
fake
backend
url req
url url
socket
accept crypto
socket
socket
socket
fake socket
payload obj
socket payload payload
tmp
backendUrl
svc
svcLog
csrf
env
fs path file
fs file value
fs file
end ms
last
end
v
v v
err last err
r
res
csrf headers
method params
body res
res body body
res
token token
method params
res res
args cwd
tmp fs path os
backend r
backendUrl
cli path tmp
path cli
path cli
path tmp
path tmp
env
path tmp
cli
path tmp
path tmp
backendUrl
svc process process env
svc svcLog d
svc svcLog d
st
r
r r
csrf st
fs env
svc svc
svc
svc r r
backend
s fake s
backend r
fs tmp
env
st
assert st
assert st
assert st backendUrl
assert st
assert st
assert st
assert st
assert st
a env
assert a
assert a
assert path a path
noToken
assert noToken
assert noToken
wrong
assert wrong
settings
assert settings
r
assert r
assert r
pre
assert pre
host
http res res
assert host
assert
s
assert s
bad
assert bad
ok fake
assert ok ok
session
assert session
teams
assert teams
sel
assert sel
st
assert st
assert st
assert st
assert fs path env
r
assert r
assert r
assert r
r fake
assert r
assert fake
assert fake
none
assert none
wrong
assert wrong
withOrigin
assert withOrigin
forbidden fake
assert forbidden
created
assert created created
t created
assert t
assert t
assert t t
assert t
forPetr
assert forPetr
tok
board tok
assert board t
assert board
my tok
assert my
assert my t t
got tok
assert got
assert got fake
assert got
short tok
assert short
moved tok
assert moved
badStatus tok
assert badStatus
re tok
assert re
assert re
act tok
assert act
dir fs path tmp
noTok dir
assert noTok
r
dir
assert r
st
assert path st path dir
assert path st path dir
assert st
events
req http
res req resolve
assert res
assert res
res
buf
res
buf c
i
i buf
block buf i
buf buf i
ev block
data block
ev events ev data
events e
s
csrf
assert s
events e e
req
st
assert st
r
assert r
text r
assert text text text
gw r x
assert gw
assert gw
assert gw
assert gw
assert gw
cl r x
assert cl
assert r x
first
assert first first
assert first
assert first
assert first
k fake x
assert k
assert k
assert k
assert k
assert k
assert k
again
assert again
assert again
cl
assert cl
assert fake
file env
original file
r
assert r r
providerId
assert r providerId
doc file
rule doc x providerId
token fake
assert token
assert rule
providerId
token
assert doc providerId
assert doc original
assert doc x providerId original
mr doc x providerId
assert mr x
assert mr
assert doc
assert fs path path file
assert path path file original
lp x providerId
assert lp
assert lp token
r2
assert r2
assert fake token
doc2 file
rules2 doc2 x providerId
assert rules2
assert rules2
assert rules2 fake
assert doc2 x providerId x
assert doc2 x providerId
ra
ruleA file x ra
assert ruleA
assert ruleA
lastToken fake
assert providerId
assert fake lastToken
assert ra
assert file original
assert
data crypto
sha crypto data
name
noCsrf name data
assert noCsrf
res
csrf name
data
body res
assert res body
up fake
assert up
assert up data
assert up sha
assert up name
assert up up
assert up
assert body sha
tmpDir path env
fs tmpDir fs tmpDir
arch
csrf
data
assert arch
assert fake
assert fake
repo fs path tmp
repo
repo
repo
repo
fs path repo
fs path repo
s repo
assert s
assert s
assert s
none repo
assert none
assert none
assert repo
assert repo
s repo
assert s x x
assert s
c1 repo
assert c1 c1
assert c1
assert c1
assert fake c1
assert path fake path repo
assert c1 fake
repo
c2 repo
assert c2
logR repo
assert logR
assert logR
assert logR c1
assert logR x
assert logR
assert repo
assert repo
shown repo c2
assert shown
assert shown
assert shown f f f f
assert shown
assert shown
assert repo
fs path repo
fs path repo
d repo
assert d
du repo
assert du
assert du
repo
assert repo
assert repo
s repo
assert s
assert s x
assert repo
disc repo
assert disc disc
assert disc
assert fs path repo
assert fs path repo
s repo
assert s
assert repo
assert repo
br repo
assert br b b
assert br
nr tmp
assert nr
events
req http
res req resolve
res
buf
res
buf c
i
i buf
block buf i
buf buf i
ev block
data block
ev events ev data
ticketsBefore fake r
s fake s
events e e
team events e e
assert team
assert fake r ticketsBefore
req
cfgFile path env
r
assert r
s r
assert s
assert s
assert s
assert s
assert s fake t t
cfg cfgFile
cfg
cfgFile cfg
s
assert s
assert s
cfg
cfg
cfgFile cfg
assert
cfg
cfgFile cfg
assert
assert
notify
assert notify
p
assert p
assert p
assert p
assetsDir path
fs assetsDir
probe path assetsDir
fs probe
a
assert a
assert a
assert a
fs probe
assert
assert
r fake
assert r r
assert r
assert
child process path
process env
buf
waiting
child
child
buf c
i
i buf
line buf i
buf buf i
line
msg line
waiting msg msg
waiting msg
next
child
id next
child
waiting id resolve
child
child
s
init s
assert init
assert init
s
assert s
list s
names list t
assert names
board list t
assert board
assert list t
assert list t
my s
assert my my
text my
assert text
assert text
assert my
created s
assert created
bad s
assert bad
unknown s
assert unknown
s
fakeAgent path tmp
fakeAgent tmp
child process path
process fakeAgent
child
out
c child out c
msg out
assert msg
assert msg
child process path
process agentFile
out
child out c
child code out
child stdin
r env tmp
assert r
out r
assert out
assert out
assert out
st
assert path st path tmp
assert st
down path tmp tmp
assert down
assert down
garbage env
assert garbage
assert
st
assert st
assert st
ps
assert ps
assert ps
'node:child_process'
;
import
{ fileURLToPath }
from
'node:url'
;
const
HERE
=
.
dirname
(
fileURLToPath
(
import
.
meta
.
url
)
)
;
const
SERVICE
=
.
resolve
(
HERE
,
'..'
,
'server.mjs'
)
;
const
PLUGIN_SCRIPTS
=
.
resolve
(
HERE
,
'..'
,
'..'
,
'marketplace'
,
'plugins'
,
'aura-team'
,
'scripts'
)
;
const
PORT
=
Number
(
.
env
.
ZTEAM_TEST_PORT
||
8791
)
;
const
SVC
=
` http://127.0.0.1: ${ PORT } `
;
const
ORIGIN
=
SVC
;
const
TEAM
=
'7e4c1a90-1111-4222-8333-944455556666'
;
const
ME
=
{
id
:
'u1-ivan'
,
email
:
'ivan@example.com'
,
displayName
:
'Ivan'
}
;
const
PETR
=
{
id
:
'u2-petr'
,
email
:
'petr@example.com'
,
displayName
:
'Petr'
}
;
const
LOCAL_KEY
=
'sk-local-secret-ABCDEFGH1234'
;
const
POOL_KEY
=
'sk-pool-secret-ZYXWVUTS9876'
;
const
=
{
tasks
:
[
]
,
keys
:
[
]
,
proxyTokens
:
[
]
,
revoked
:
[
]
,
commits
:
[
]
,
uploads
:
[
]
,
password
:
'secret-pass'
,
requests
:
[
]
,
}
;
function
seedTasks
(
)
{
.
tasks
=
[
{
id
:
'1a2b3c4d-0000-4000-8000-000000000001'
,
title
:
'Сделать вход'
,
description
:
'OAuth'
,
status
:
'doing'
,
assigneeId
:
ME
.
id
,
assigneeName
:
ME
.
displayName
,
priority
:
'high'
,
labels
:
[
'auth'
]
,
dueAt
:
'2026-11-20'
,
position
:
0
}
,
{
id
:
'5e6f7a8b-0000-4000-8000-000000000002'
,
title
:
'Ревью API'
,
description
:
''
,
status
:
'todo'
,
assigneeId
:
PETR
.
id
,
assigneeName
:
PETR
.
displayName
,
priority
:
'normal'
,
labels
:
[
]
,
dueAt
:
null
,
position
:
0
}
,
{
id
:
'9c0d1e2f-0000-4000-8000-000000000003'
,
title
:
'Старое'
,
description
:
''
,
status
:
'done'
,
assigneeId
:
ME
.
id
,
assigneeName
:
ME
.
displayName
,
priority
:
'low'
,
labels
:
[
]
,
dueAt
:
null
,
position
:
0
}
,
]
;
}
const
=
.
createServer
(
async
(
req, res
)
=>
{
const
=
new
URL
(
.
url
,
'http://x'
)
;
const
=
.
pathname
;
const
send
=
(
code, obj
)
=>
{
const
=
===
undefined
?
''
:
JSON
.
stringify
(
)
;
.
writeHead
(
,
?
{
'content-type'
:
'application/json'
}
:
{
}
)
;
.
end
(
)
;
}
;
const
=
[
]
;
for
await
(
const
of
)
.
push
(
)
;
const
=
Buffer
.
concat
(
)
;
.
requests
.
push
(
{
method
:
.
method
,
path
:
}
)
;
const
json
=
(
)
=>
{
try
{
return
JSON
.
parse
(
.
toString
(
'utf8'
)
||
'{}'
)
;
}
catch
{
return
{
}
;
}
}
;
const
=
.
headers
.
authorization
===
'Bearer access-1'
;
if
(
.
method
===
'POST'
&&
===
'/v1/auth/login'
)
{
const
=
json
(
)
;
if
(
.
email
===
ME
.
email
&&
.
password
===
.
password
)
return
send
(
200
,
{
accessToken
:
'access-1'
,
refreshToken
:
'refresh-1'
,
expiresIn
:
900
}
)
;
return
send
(
401
,
{
message
:
'Invalid email or password'
}
)
;
}
if
(
.
method
===
'POST'
&&
===
'/v1/auth/refresh'
)
return
send
(
401
,
{
message
:
'Unauthorized'
}
)
;
if
(
!
)
return
send
(
401
,
{
message
:
'Authentication required'
}
)
;
const
=
` /v1/teams/ ${ TEAM } `
;
if
(
.
method
===
'GET'
&&
===
'/v1/me'
)
{
return
send
(
200
,
{
user
:
ME
,
teams
:
[
{
id
:
TEAM
,
name
:
'Alpha'
,
role
:
'owner'
,
memberCount
:
2
}
]
,
entitlements
:
[
]
,
admin
:
false
}
)
;
}
if
(
.
method
===
'POST'
&&
===
'/v1/auth/password'
)
{
const
=
json
(
)
;
if
(
.
currentPassword
!==
.
password
)
return
send
(
401
,
{
message
:
'Current password is incorrect'
}
)
;
.
password
=
.
newPassword
;
return
send
(
200
,
{
ok
:
true
}
)
;
}
if
(
.
method
===
'GET'
&&
===
` ${ base} /board `
)
{
return
send
(
200
,
{
members
:
[
{
...
ME
,
role
:
'owner'
}
,
{
...
PETR
,
role
:
'dev'
}
]
,
projects
:
[
]
,
tasks
:
.
tasks
}
)
;
}
if
(
.
method
===
'POST'
&&
===
` ${ base} /tasks `
)
{
const
=
json
(
)
;
const
=
[
ME
,
PETR
]
.
find
(
(
m
)
=>
.
id
===
(
.
assigneeId
??
ME
.
id
)
)
;
const
=
{
id
:
.
randomUUID
(
)
,
title
:
.
title
,
description
:
.
description
??
''
,
status
:
.
status
??
'todo'
,
assigneeId
:
?.
??
null
,
priority
:
.
priority
??
'normal'
,
labels
:
.
labels
??
[
]
,
due_at
:
.
dueAt
??
null
,
position
:
0
}
;
.
tasks
.
push
(
{
...
,
assigneeName
:
?.
,
dueAt
:
.
due_at
}
)
;
return
send
(
201
,
{
...
,
assignee_id
:
.
assigneeId
,
labels
:
.
labels
}
)
;
}
let
=
new
RegExp
(
` ^ ${ base} /tasks/([^/]+)$ `
)
.
exec
(
)
;
if
(
&&
.
method
===
'PATCH'
)
{
const
=
.
tasks
.
find
(
(
x
)
=>
.
id
===
[
1
]
)
;
if
(
!
)
return
send
(
404
,
{
message
:
'Not Found'
}
)
;
const
=
json
(
)
;
Object
.
assign
(
,
)
;
if
(
'assigneeId'
in
)
.
assigneeName
=
[
ME
,
PETR
]
.
find
(
(
x
)
=>
.
id
===
.
assigneeId
)
?.
??
null
;
return
send
(
200
,
{
...
}
)
;
}
=
new
RegExp
(
` ^ ${ base} /tasks/([^/]+)/(history|commits)$ `
)
.
exec
(
)
;
if
(
&&
.
method
===
'GET'
)
{
return
send
(
200
,
[
2
]
===
'history'
?
[
{
action
:
'task.create'
,
details
:
{
}
,
createdAt
:
'2026-11-10T10:00:00.000Z'
,
userName
:
'Ivan'
}
]
:
[
]
)
;
}
if
(
.
method
===
'GET'
&&
===
` ${ base} /activity `
)
{
return
send
(
200
,
[
{
id
:
1
,
action
:
'task.create'
,
userName
:
'Ivan'
,
taskTitle
:
'Сделать вход'
,
createdAt
:
'2026-11-10T10:00:00.000Z'
}
]
)
;
}
if
(
.
method
===
'POST'
&&
===
` ${ base} /proxy-tokens `
)
{
const
=
{
id
:
.
randomUUID
(
)
,
token
:
` aura_pt_ ${ crypto. randomBytes ( 8 ) . toString ( 'hex' ) } `
,
body
:
json
(
)
}
;
.
proxyTokens
.
push
(
)
;
return
send
(
201
,
{
id
:
.
id
,
token
:
.
token
}
)
;
}
=
new
RegExp
(
` ^ ${ base} /proxy-tokens/([^/]+)$ `
)
.
exec
(
)
;
if
(
&&
.
method
===
'DELETE'
)
{
.
revoked
.
push
(
[
1
]
)
;
return
send
(
204
)
;
}
if
(
.
method
===
'GET'
&&
===
` ${ base} /keys `
)
return
send
(
200
,
.
keys
.
map
(
(
{ value, ... k }
)
=>
)
)
;
if
(
.
method
===
'POST'
&&
===
` ${ base} /keys `
)
{
const
=
json
(
)
;
const
=
.
value
.
trim
(
)
;
const
=
{
id
:
.
randomUUID
(
)
,
...
,
keyHint
:
.
length
<=
8
?
'••••'
:
` ${ k. slice ( 0 , 3 ) } … ${ k. slice ( - 4 ) } `
}
;
.
keys
.
push
(
)
;
const
{
,
...
}
=
;
return
send
(
201
,
)
;
}
if
(
.
method
===
'POST'
&&
===
` ${ base} /events-ticket `
)
return
send
(
200
,
{
ticket
:
'tkt'
,
expiresIn
:
30
}
)
;
if
(
.
method
===
'POST'
&&
===
` ${ base} /commits `
)
{
.
commits
.
push
(
json
(
)
)
;
return
send
(
201
,
{
taskId
:
.
tasks
[
0
]
.
id
}
)
;
}
if
(
.
method
===
'POST'
&&
(
===
` ${ base} /files `
||
===
` ${ base} /archives `
)
)
{
const
=
.
headers
[
'content-type'
]
??
''
;
const
=
/ boundary=( . + ) $ /
.
exec
(
)
?.
[
1
]
;
if
(
!
)
return
send
(
400
,
{
message
:
'no boundary'
}
)
;
const
=
.
indexOf
(
'\r\n\r\n'
)
;
const
=
.
subarray
(
0
,
)
.
toString
(
'utf8'
)
;
const
=
Buffer
.
from
(
` \r\n-- ${ boundary} --\r\n `
)
;
if
(
!
.
subarray
(
.
length
-
.
length
)
.
equals
(
)
)
return
send
(
400
,
{
message
:
'bad tail'
}
)
;
const
=
.
subarray
(
+
4
,
.
length
-
.
length
)
;
const
=
/ filename="( [ ^ "\r \n ] * ) " /
.
exec
(
)
;
const
=
{
kind
:
.
endsWith
(
'/files'
)
?
'file'
:
'archive'
,
query
:
Object
.
fromEntries
(
.
searchParams
)
,
name
:
?
[
1
]
:
null
,
bytes
:
.
length
,
sha256
:
.
createHash
(
'sha256'
)
.
update
(
)
.
digest
(
'hex'
)
,
contentLength
:
Number
(
.
headers
[
'content-length'
]
)
,
received
:
.
length
,
}
;
.
uploads
.
push
(
)
;
return
send
(
201
,
{
id
:
.
randomUUID
(
)
,
...
}
)
;
}
return
send
(
404
,
{
message
:
` fake: no route ${ req. method } ${ p} `
}
)
;
}
)
;
.
ws
=
[
]
;
.
on
(
'upgrade'
,
(
req, socket
)
=>
{
const
=
new
URL
(
.
url
,
'http://x'
)
;
if
(
.
pathname
!==
` /v1/teams/ ${ TEAM } /events `
||
.
searchParams
.
get
(
'ticket'
)
!==
'tkt'
)
{
.
end
(
'HTTP/1.1 401 Unauthorized\r\n\r\n'
)
;
return
;
}
const
=
.
createHash
(
'sha1'
)
.
update
(
` ${ req. headers [ 'sec-websocket-key' ] } 258EAFA5-E914-47DA-95CA-C5AB0DC85B11 `
)
.
digest
(
'base64'
)
;
.
write
(
` HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: ${ accept} \r\n\r\n `
)
;
.
on
(
'error'
,
(
)
=>
{
}
)
;
.
on
(
'data'
,
(
)
=>
{
}
)
;
.
ws
.
push
(
)
;
const
frame
=
(
obj
)
=>
{
const
=
Buffer
.
from
(
JSON
.
stringify
(
)
)
;
.
write
(
Buffer
.
concat
(
[
Buffer
.
from
(
[
0x81
,
.
length
]
)
,
]
)
)
;
}
;
frame
(
{
type
:
'connected'
,
at
:
new
Date
(
)
.
toISOString
(
)
}
)
;
setTimeout
(
(
)
=>
frame
(
{
type
:
'task.changed'
,
at
:
'2026-11-11T12:00:00.000Z'
}
)
,
100
)
;
}
)
;
let
;
let
;
let
;
let
=
''
;
let
;
const
=
{
}
;
function
writeJson
(
file, value
)
{
.
mkdirSync
(
.
dirname
(
)
,
{
recursive
:
true
}
)
;
.
writeFileSync
(
,
JSON
.
stringify
(
,
null
,
2
)
)
;
}
const
readJson
=
(
file
)
=>
JSON
.
parse
(
.
readFileSync
(
,
'utf8'
)
)
;
function
providerDoc
(
)
{
return
{
schemaVersion
:
1
,
config
:
{
providerOrder
:
[
'local-openai'
,
'local-claude'
]
,
providerConfigRules
:
{
providerRules
:
[
{
providerId
:
'local-openai'
,
providerName
:
'Local GW'
,
enabled
:
true
,
config
:
{
group
:
'standard-personal'
,
access
:
{
type
:
'api-key'
,
apiKey
:
LOCAL_KEY
}
,
api
:
{
type
:
'openai-chat-completions'
,
baseUrl
:
'https://gw.example.com/v1'
}
,
personalModelIds
:
[
'gpt-x'
,
'gpt-y'
]
,
modelOrder
:
[
'gpt-y'
,
'gpt-x'
]
,
}
,
}
,
{
providerId
:
'local-claude'
,
providerName
:
'Claude'
,
config
:
{
group
:
'standard-personal'
,
access
:
{
type
:
'api-key'
,
apiKey
:
'sk-ant-another-secret-0000'
}
,
api
:
{
type
:
'anthropic-messages'
,
baseUrl
:
'https://api.anthropic.com'
}
,
personalModelIds
:
[
'claude-z'
]
,
modelOrder
:
[
]
,
}
,
}
,
{
providerId
:
'empty'
,
providerName
:
'Empty'
,
config
:
{
group
:
'standard-personal'
,
access
:
{
type
:
'api-key'
}
,
personalModelIds
:
[
]
,
modelOrder
:
[
]
}
}
,
]
,
}
,
modelConfigRules
:
{
providerModelRules
:
[
{
modelId
:
'gpt-x'
,
config
:
{
enabled
:
true
,
properties
:
{
inputFormat
:
{
supportsText
:
true
,
supportsImage
:
true
}
}
}
,
providerId
:
'local-openai'
}
,
]
,
manualProviderModelRules
:
[
]
,
}
,
defaultModelSelection
:
{
providerId
:
'local-openai'
,
modelId
:
'gpt-y'
}
,
}
,
}
;
}
async
function
waitFor
(
fn, ms = 10_000
)
{
const
=
Date
.
now
(
)
+
;
let
;
while
(
Date
.
now
(
)
<
)
{
try
{
const
=
await
fn
(
)
;
if
(
)
return
;
}
catch
(
)
{
=
;
}
await
new
Promise
(
(
r
)
=>
setTimeout
(
,
100
)
)
;
}
throw
new
Error
(
` timeout waiting: ${ last?. message ?? '' } \n--- service log ---\n ${ svcLog} `
)
;
}
async
function
rpc
(
method, params = { } , { headers = { } } = { }
)
{
const
=
await
fetch
(
` ${ SVC } /rpc `
,
{
method
:
'POST'
,
headers
:
{
'content-type'
:
'application/json'
,
'x-zteam-csrf'
:
,
origin
:
ORIGIN
,
...
}
,
body
:
JSON
.
stringify
(
{
,
}
)
,
}
)
;
const
=
await
.
json
(
)
;
return
{
status
:
.
status
,
,
result
:
.
result
}
;
}
async
function
agent
(
method, params = { } , token
)
{
const
=
await
fetch
(
` ${ SVC } /agent/rpc `
,
{
method
:
'POST'
,
headers
:
{
'content-type'
:
'application/json'
,
...
(
?
{
'x-zteam-agent'
:
}
:
{
}
)
}
,
body
:
JSON
.
stringify
(
{
,
}
)
,
}
)
;
return
{
status
:
.
status
,
body
:
await
.
json
(
)
}
;
}
function
git
(
cwd, ... args
)
{
return
execFileSync
(
'git'
,
,
{
,
encoding
:
'utf8'
,
windowsHide
:
true
}
)
;
}
before
(
async
(
)
=>
{
=
.
mkdtempSync
(
.
join
(
.
tmpdir
(
)
,
'zteam-test-'
)
)
;
seedTasks
(
)
;
await
new
Promise
(
(
r
)
=>
.
listen
(
0
,
'127.0.0.1'
,
)
)
;
=
` http://127.0.0.1: ${ backend. address ( ) . port } `
;
const
=
.
join
(
,
'home'
,
'.zcode'
,
'cli'
)
;
writeJson
(
.
join
(
,
'config.json'
)
,
{
plugins
:
{
enabled
:
true
,
enabledPlugins
:
{
'aura-team@local-marketplace'
:
true
}
}
}
)
;
writeJson
(
.
join
(
,
'plugins'
,
'installed_plugins.json'
)
,
{
version
:
1
,
plugins
:
[
{
id
:
'aura-team@local-marketplace'
,
name
:
'aura-team'
,
marketplace
:
'local-marketplace'
,
version
:
'1.0.0'
}
]
}
)
;
writeJson
(
.
join
(
,
'v2'
,
'provider_config.json'
)
,
providerDoc
(
)
)
;
writeJson
(
.
join
(
,
'v2'
,
'key_pool.json'
)
,
{
version
:
1
,
providers
:
{
'local-openai'
:
{
keys
:
[
POOL_KEY
,
LOCAL_KEY
]
,
tiers
:
{
}
}
}
}
)
;
Object
.
assign
(
,
{
ZTEAM_PORT
:
String
(
PORT
)
,
ZTEAM_STATE_DIR
:
.
join
(
,
'state'
)
,
ZTEAM_ZCODE_HOME
:
,
ZTEAM_PROVIDER_CONFIG
:
.
join
(
,
'v2'
,
'provider_config.json'
)
,
ZTEAM_AGENT_FILE
:
.
join
(
,
'aura-team'
,
'agent.json'
)
,
ZTEAM_SERVER_URL
:
,
}
)
;
=
spawn
(
.
execPath
,
[
SERVICE
]
,
{
env
:
{
...
.
env
,
...
}
,
stdio
:
[
'ignore'
,
'pipe'
,
'pipe'
]
,
windowsHide
:
true
}
)
;
.
stdout
.
on
(
'data'
,
(
d
)
=>
{
+=
;
}
)
;
.
stderr
.
on
(
'data'
,
(
d
)
=>
{
+=
;
}
)
;
const
=
await
waitFor
(
async
(
)
=>
{
const
=
await
fetch
(
` ${ SVC } /state `
)
;
return
.
ok
?
.
json
(
)
:
null
;
}
)
;
=
.
csrfToken
;
await
waitFor
(
(
)
=>
.
existsSync
(
.
ZTEAM_AGENT_FILE
)
)
;
}
)
;
after
(
async
(
)
=>
{
if
(
&&
.
exitCode
===
null
)
{
.
kill
(
)
;
await
new
Promise
(
(
r
)
=>
{
.
once
(
'exit'
,
)
;
setTimeout
(
,
2000
)
;
}
)
;
}
.
closeAllConnections
?.
(
)
;
for
(
const
of
.
ws
??
[
]
)
.
destroy
(
)
;
await
new
Promise
(
(
r
)
=>
.
close
(
)
)
;
try
{
.
rmSync
(
,
{
recursive
:
true
,
force
:
true
}
)
;
}
catch
{
}
}
)
;
const
agentToken
=
(
)
=>
readJson
(
.
ZTEAM_AGENT_FILE
)
.
token
;
test
(
'GET /state: shape, version 2, plugin state'
,
async
(
)
=>
{
const
=
await
(
await
fetch
(
` ${ SVC } /state `
)
)
.
json
(
)
;
.
equal
(
.
version
,
'2'
)
;
.
equal
(
.
signedIn
,
false
)
;
.
equal
(
.
serverUrl
,
)
;
.
deepEqual
(
.
recentWorkspaces
,
[
]
)
;
.
deepEqual
(
.
ui
,
{
}
)
;
.
deepEqual
(
.
plugin
,
{
installed
:
true
,
enabled
:
true
}
)
;
.
equal
(
.
ide
,
null
)
;
.
match
(
.
csrfToken
,
/ ^ [ 0- 9 a- f ] {48} $ /
)
;
}
)
;
test
(
'agent.json written with port, token, serviceDir'
,
(
)
=>
{
const
=
readJson
(
.
ZTEAM_AGENT_FILE
)
;
.
equal
(
.
port
,
PORT
)
;
.
match
(
.
token
,
/ ^ [ 0- 9 a- f ] {64} $ /
)
;
.
equal
(
.
resolve
(
.
serviceDir
)
,
.
dirname
(
SERVICE
)
)
;
}
)
;
test
(
'CSRF: POST /rpc without or with a wrong token is rejected'
,
async
(
)
=>
{
const
=
await
fetch
(
` ${ SVC } /rpc `
,
{
method
:
'POST'
,
headers
:
{
'content-type'
:
'application/json'
}
,
body
:
'{"method":"teams"}'
}
)
;
.
equal
(
.
status
,
403
)
;
.
match
(
(
await
.
json
(
)
)
.
error
,
/ csrf /
)
;
const
=
await
rpc
(
'teams'
,
{
}
,
{
headers
:
{
'x-zteam-csrf'
:
'nope'
}
}
)
;
.
equal
(
.
status
,
403
)
;
const
=
await
fetch
(
` ${ SVC } /settings `
,
{
method
:
'POST'
,
body
:
'{"workspace":"x"}'
}
)
;
.
equal
(
.
status
,
403
)
;
}
)
;
test
(
'foreign Origin and Host are rejected even with a valid CSRF token'
,
async
(
)
=>
{
const
=
await
rpc
(
'teams'
,
{
}
,
{
headers
:
{
origin
:
'http://evil.example'
}
}
)
;
.
equal
(
.
status
,
403
)
;
.
match
(
.
body
.
error
,
/ origin /
)
;
const
=
await
fetch
(
` ${ SVC } /rpc `
,
{
method
:
'OPTIONS'
,
headers
:
{
origin
:
'http://evil.example'
}
}
)
;
.
equal
(
.
status
,
403
)
;
const
=
await
new
Promise
(
(
resolve
)
=>
{
.
get
(
{
host
:
'127.0.0.1'
,
port
:
PORT
,
path
:
'/state'
,
headers
:
{
host
:
'evil.example'
}
}
,
(
res
)
=>
{
.
resume
(
)
;
resolve
(
.
statusCode
)
;
}
)
;
}
)
;
.
equal
(
,
403
)
;
}
)
;
test
(
'unknown method → 404; not signed in → 401 from upstream semantics'
,
async
(
)
=>
{
.
equal
(
(
await
rpc
(
'nope'
)
)
.
status
,
404
)
;
const
=
await
rpc
(
'session'
)
;
.
equal
(
.
status
,
401
)
;
}
)
;
test
(
'login → session → teams → selectTeam'
,
async
(
)
=>
{
const
=
await
rpc
(
'login'
,
{
email
:
ME
.
email
,
password
:
'wrong'
}
)
;
.
equal
(
.
status
,
401
)
;
const
=
await
rpc
(
'login'
,
{
email
:
ME
.
email
,
password
:
.
password
}
)
;
.
equal
(
.
status
,
200
,
JSON
.
stringify
(
.
body
)
)
;
const
=
await
rpc
(
'session'
)
;
.
equal
(
.
result
.
user
.
email
,
ME
.
email
)
;
const
=
await
rpc
(
'teams'
)
;
.
equal
(
.
result
[
0
]
.
id
,
TEAM
)
;
const
=
await
rpc
(
'selectTeam'
,
{
teamId
:
TEAM
}
)
;
.
equal
(
.
result
.
teamId
,
TEAM
)
;
const
=
await
(
await
fetch
(
` ${ SVC } /state `
)
)
.
json
(
)
;
.
equal
(
.
signedIn
,
true
)
;
.
equal
(
.
teamId
,
TEAM
)
;
.
ok
(
!
JSON
.
stringify
(
)
.
includes
(
'access-1'
)
)
;
.
ok
(
!
.
readFileSync
(
.
join
(
.
ZTEAM_STATE_DIR
,
'state.json'
)
,
'utf8'
)
.
includes
(
'access-1'
)
)
;
}
)
;
test
(
'board via /rpc (teamId defaults to the selected team)'
,
async
(
)
=>
{
const
=
await
rpc
(
'board'
)
;
.
equal
(
.
status
,
200
)
;
.
equal
(
.
result
.
tasks
.
length
,
3
)
;
.
equal
(
.
result
.
members
.
length
,
2
)
;
}
)
;
test
(
'updateTask passes changes through verbatim (null kept)'
,
async
(
)
=>
{
const
=
await
rpc
(
'updateTask'
,
{
taskId
:
.
tasks
[
1
]
.
id
,
changes
:
{
dueAt
:
null
,
priority
:
'urgent'
}
}
)
;
.
equal
(
.
status
,
200
)
;
.
equal
(
.
tasks
[
1
]
.
dueAt
,
null
)
;
.
equal
(
.
tasks
[
1
]
.
priority
,
'urgent'
)
;
}
)
;
test
(
'/agent/rpc: rejects without token, with Origin; createTask with token'
,
async
(
)
=>
{
const
=
await
agent
(
'myTasks'
)
;
.
equal
(
.
status
,
401
)
;
const
=
await
agent
(
'myTasks'
,
{
}
,
'f'
.
repeat
(
64
)
)
;
.
equal
(
.
status
,
401
)
;
const
=
await
fetch
(
` ${ SVC } /agent/rpc `
,
{
method
:
'POST'
,
headers
:
{
'content-type'
:
'application/json'
,
'x-zteam-agent'
:
agentToken
(
)
,
origin
:
ORIGIN
}
,
body
:
'{"method":"myTasks"}'
,
}
)
;
.
equal
(
.
status
,
403
)
;
const
=
await
agent
(
'deleteTask'
,
{
taskId
:
.
tasks
[
0
]
.
id
}
,
agentToken
(
)
)
;
.
equal
(
.
status
,
404
)
;
const
=
await
agent
(
'createTask'
,
{
title
:
'Из агента'
,
priority
:
'high'
,
labels
:
[
'ai'
]
,
dueAt
:
'2026-12-01'
}
,
agentToken
(
)
)
;
.
equal
(
.
status
,
200
,
JSON
.
stringify
(
.
body
)
)
;
const
=
.
body
.
result
;
.
equal
(
.
title
,
'Из агента'
)
;
.
equal
(
.
assigneeId
,
ME
.
id
,
'assignee defaults to me'
)
;
.
equal
(
.
shortId
,
.
id
.
slice
(
0
,
8
)
)
;
.
equal
(
.
dueAt
,
'2026-12-01'
)
;
const
=
await
agent
(
'createTask'
,
{
title
:
'Для Петра'
,
assignee
:
'petr'
}
,
agentToken
(
)
)
;
.
equal
(
.
body
.
result
.
assigneeId
,
PETR
.
id
)
;
}
)
;
test
(
'/agent/rpc: board, myTasks, getTask by prefix, moveTask, updateTask assignee'
,
async
(
)
=>
{
const
=
agentToken
(
)
;
const
=
(
await
agent
(
'board'
,
{
status
:
'doing'
}
,
)
)
.
body
.
result
;
.
ok
(
.
tasks
.
every
(
(
t
)
=>
.
status
===
'doing'
)
)
;
.
ok
(
.
tasks
[
0
]
.
shortId
.
length
===
8
)
;
const
=
(
await
agent
(
'myTasks'
,
{
}
,
)
)
.
body
.
result
;
.
equal
(
.
teamName
,
'Alpha'
)
;
.
ok
(
.
tasks
.
every
(
(
t
)
=>
.
assigneeId
===
ME
.
id
&&
.
status
!==
'done'
)
)
;
const
=
await
agent
(
'getTask'
,
{
taskId
:
'#1a2b3c'
}
,
)
;
.
equal
(
.
status
,
200
)
;
.
equal
(
.
body
.
result
.
id
,
.
tasks
[
0
]
.
id
)
;
.
equal
(
.
body
.
result
.
history
.
length
,
1
)
;
const
=
await
agent
(
'getTask'
,
{
taskId
:
'1a2b'
}
,
)
;
.
equal
(
.
status
,
400
)
;
const
=
await
agent
(
'moveTask'
,
{
taskId
:
'1a2b3c4d'
,
status
:
'review'
}
,
)
;
.
equal
(
.
body
.
result
.
status
,
'review'
)
;
const
=
await
agent
(
'moveTask'
,
{
taskId
:
'1a2b3c4d'
,
status
:
'wip'
}
,
)
;
.
equal
(
.
status
,
400
)
;
const
=
await
agent
(
'updateTask'
,
{
taskId
:
'1a2b3c4d'
,
assignee
:
'Petr'
,
priority
:
'low'
}
,
)
;
.
equal
(
.
body
.
result
.
assigneeName
,
'Petr'
)
;
.
equal
(
.
body
.
result
.
priority
,
'low'
)
;
const
=
await
agent
(
'activity'
,
{
limit
:
5
}
,
)
;
.
equal
(
.
body
.
result
[
0
]
.
action
,
'task.create'
)
;
}
)
;
test
(
'/ide/context: requires agent token, sets workspace if empty, emits SSE'
,
async
(
)
=>
{
const
=
.
mkdtempSync
(
.
join
(
,
'ws-'
)
)
;
const
=
await
fetch
(
` ${ SVC } /ide/context `
,
{
method
:
'POST'
,
body
:
JSON
.
stringify
(
{
cwd
:
}
)
}
)
;
.
equal
(
.
status
,
401
)
;
const
=
await
fetch
(
` ${ SVC } /ide/context `
,
{
method
:
'POST'
,
headers
:
{
'content-type'
:
'application/json'
,
'x-zteam-agent'
:
agentToken
(
)
}
,
body
:
JSON
.
stringify
(
{
cwd
:
,
event
:
'SessionStart'
,
sessionId
:
's1'
}
)
,
}
)
;
.
equal
(
.
status
,
200
)
;
const
=
await
(
await
fetch
(
` ${ SVC } /state `
)
)
.
json
(
)
;
.
equal
(
.
resolve
(
.
workspace
)
,
.
resolve
(
)
)
;
.
equal
(
.
resolve
(
.
ide
.
cwd
)
,
.
resolve
(
)
)
;
.
equal
(
.
recentWorkspaces
.
length
,
1
)
;
}
)
;
test
(
'SSE /events: hello + local state event after /settings'
,
async
(
)
=>
{
const
=
[
]
;
const
=
.
get
(
{
host
:
'127.0.0.1'
,
port
:
PORT
,
path
:
'/events'
,
headers
:
{
origin
:
ORIGIN
}
}
)
;
const
=
await
new
Promise
(
(
resolve
)
=>
.
on
(
'response'
,
)
)
;
.
equal
(
.
statusCode
,
200
)
;
.
match
(
.
headers
[
'content-type'
]
,
/ text\/ event-stream /
)
;
.
setEncoding
(
'utf8'
)
;
let
=
''
;
.
on
(
'data'
,
(
c
)
=>
{
+=
;
let
;
while
(
(
=
.
indexOf
(
'\n\n'
)
)
>=
0
)
{
const
=
.
slice
(
0
,
)
;
=
.
slice
(
+
2
)
;
const
=
/ ^ event: ( . + ) $ / m
.
exec
(
)
?.
[
1
]
;
const
=
/ ^ data: ( . + ) $ / m
.
exec
(
)
?.
[
1
]
;
if
(
)
.
push
(
{
,
data
:
JSON
.
parse
(
)
}
)
;
}
}
)
;
await
waitFor
(
(
)
=>
.
some
(
(
e
)
=>
.
data
.
type
===
'hello'
)
,
3000
)
;
const
=
await
fetch
(
` ${ SVC } /settings `
,
{
method
:
'POST'
,
headers
:
{
'content-type'
:
'application/json'
,
'x-zteam-csrf'
:
,
origin
:
ORIGIN
}
,
body
:
JSON
.
stringify
(
{
ui
:
{
theme
:
'dark'
,
dock
:
420
}
}
)
,
}
)
;
.
equal
(
.
status
,
200
)
;
await
waitFor
(
(
)
=>
.
some
(
(
e
)
=>
.
ev
===
'local'
&&
.
data
.
type
===
'state'
)
,
3000
)
;
.
destroy
(
)
;
const
=
await
(
await
fetch
(
` ${ SVC } /state `
)
)
.
json
(
)
;
.
deepEqual
(
.
ui
,
{
theme
:
'dark'
,
dock
:
420
}
)
;
}
)
;
test
(
'localProviders: masked hints, key counts, never raw keys'
,
async
(
)
=>
{
const
=
await
rpc
(
'localProviders'
)
;
.
equal
(
.
status
,
200
)
;
const
=
JSON
.
stringify
(
.
body
)
;
.
ok
(
!
.
includes
(
LOCAL_KEY
)
&&
!
.
includes
(
POOL_KEY
)
&&
!
.
includes
(
'another-secret'
)
,
'raw key leaked'
)
;
const
=
.
result
.
find
(
(
x
)
=>
.
providerId
===
'local-openai'
)
;
.
equal
(
.
keyHint
,
'sk-…1234'
)
;
.
equal
(
.
keyCount
,
2
,
'primary + pool extra, deduped'
)
;
.
deepEqual
(
.
models
,
[
'gpt-y'
,
'gpt-x'
]
,
'modelOrder wins'
)
;
.
equal
(
.
apiType
,
'openai-chat-completions'
)
;
.
equal
(
.
teamManaged
,
false
)
;
const
=
.
result
.
find
(
(
x
)
=>
.
providerId
===
'local-claude'
)
;
.
deepEqual
(
.
models
,
[
'claude-z'
]
,
'falls back to personalModelIds'
)
;
.
ok
(
!
.
result
.
some
(
(
x
)
=>
.
providerId
===
'empty'
)
,
'providers without endpoint skipped'
)
;
}
)
;
test
(
'shareLocalProvider: creates keys with raw value server-side, dedupes on repeat'
,
async
(
)
=>
{
const
=
await
rpc
(
'shareLocalProvider'
,
{
providerId
:
'local-openai'
,
models
:
[
'gpt-x'
]
,
dailyLimit
:
100
,
accessRole
:
'dev'
,
allKeys
:
true
}
)
;
.
equal
(
.
status
,
200
,
JSON
.
stringify
(
.
body
)
)
;
.
equal
(
.
result
.
created
,
2
)
;
.
equal
(
.
result
.
skipped
,
0
)
;
.
ok
(
!
JSON
.
stringify
(
.
body
)
.
includes
(
LOCAL_KEY
)
)
;
const
=
.
keys
.
find
(
(
x
)
=>
.
value
===
LOCAL_KEY
)
;
.
equal
(
.
provider
,
'openai'
)
;
.
equal
(
.
baseUrl
,
'https://gw.example.com/v1'
)
;
.
equal
(
.
model
,
'gpt-x'
)
;
.
deepEqual
(
.
models
,
[
'gpt-x'
]
)
;
.
equal
(
.
dailyLimit
,
100
)
;
.
equal
(
.
label
,
'Local GW (shared)'
)
;
const
=
await
rpc
(
'shareLocalProvider'
,
{
providerId
:
'local-openai'
,
models
:
[
'gpt-x'
]
,
dailyLimit
:
null
,
accessRole
:
'dev'
,
allKeys
:
true
}
)
;
.
equal
(
.
result
.
created
,
0
)
;
.
equal
(
.
result
.
skipped
,
2
)
;
const
=
await
rpc
(
'shareLocalProvider'
,
{
providerId
:
'local-claude'
,
models
:
[
]
,
dailyLimit
:
null
,
accessRole
:
'viewer'
}
)
;
.
equal
(
.
result
.
created
,
1
)
;
.
equal
(
.
keys
.
at
(
-
1
)
.
provider
,
'anthropic'
)
;
}
)
;
test
(
'connectTeamProvider writes a valid rule, preserves other fields; reconnect revokes; disconnect restores'
,
async
(
)
=>
{
const
=
.
ZTEAM_PROVIDER_CONFIG
;
const
=
readJson
(
)
;
const
=
await
rpc
(
'connectTeamProvider'
,
{
provider
:
'openai'
,
models
:
[
'gpt-x'
,
'gpt-new'
]
}
)
;
.
equal
(
.
status
,
200
,
JSON
.
stringify
(
.
body
)
)
;
const
=
` team-openai- ${ TEAM . slice ( 0 , 8 ) } `
;
.
deepEqual
(
.
result
,
{
,
models
:
[
'gpt-x'
,
'gpt-new'
]
}
)
;
const
=
readJson
(
)
;
const
=
.
config
.
providerConfigRules
.
providerRules
.
find
(
(
x
)
=>
.
providerId
===
)
;
const
=
.
proxyTokens
.
at
(
-
1
)
;
.
deepEqual
(
.
body
,
{
provider
:
'openai'
,
model
:
'*'
}
)
;
.
deepEqual
(
,
{
,
providerName
:
'Team · Alpha'
,
enabled
:
true
,
config
:
{
group
:
'standard-personal'
,
access
:
{
type
:
'api-key'
,
apiKey
:
.
token
}
,
api
:
{
type
:
'openai-chat-completions'
,
baseUrl
:
` ${ backendUrl} /v1/teams/ ${ TEAM } /proxy/openai/v1 `
}
,
personalModelIds
:
[
'gpt-x'
,
'gpt-new'
]
,
modelOrder
:
[
'gpt-x'
,
'gpt-new'
]
,
}
,
}
,
'rule has no extra keys (ZCode schema is strict)'
)
;
.
deepEqual
(
.
config
.
providerOrder
,
[
'local-openai'
,
'local-claude'
,
]
)
;
.
deepEqual
(
.
config
.
defaultModelSelection
,
.
config
.
defaultModelSelection
)
;
.
deepEqual
(
.
config
.
providerConfigRules
.
providerRules
.
filter
(
(
x
)
=>
.
providerId
!==
)
,
.
config
.
providerConfigRules
.
providerRules
)
;
const
=
.
config
.
modelConfigRules
.
providerModelRules
.
filter
(
(
x
)
=>
.
providerId
===
)
;
.
deepEqual
(
.
map
(
(
x
)
=>
.
modelId
)
.
sort
(
)
,
[
'gpt-new'
,
'gpt-x'
]
)
;
.
deepEqual
(
[
0
]
.
config
,
{
enabled
:
true
,
properties
:
{
inputFormat
:
{
supportsText
:
true
}
}
}
)
;
.
deepEqual
(
.
config
.
modelConfigRules
.
manualProviderModelRules
,
[
]
)
;
.
ok
(
.
existsSync
(
.
join
(
.
dirname
(
)
,
'provider_config.before-team.json'
)
)
,
'backup made'
)
;
.
deepEqual
(
readJson
(
.
join
(
.
dirname
(
)
,
'provider_config.before-team.json'
)
)
,
)
;
const
=
(
await
rpc
(
'localProviders'
)
)
.
result
.
find
(
(
x
)
=>
.
providerId
===
)
;
.
equal
(
.
teamManaged
,
true
)
;
.
ok
(
!
JSON
.
stringify
(
)
.
includes
(
.
token
)
)
;
const
=
await
rpc
(
'connectTeamProvider'
,
{
provider
:
'openai'
,
models
:
[
'gpt-x'
]
,
name
:
'Моя команда'
}
)
;
.
equal
(
.
status
,
200
)
;
.
ok
(
.
revoked
.
includes
(
.
id
)
,
'old proxy token revoked'
)
;
const
=
readJson
(
)
;
const
=
.
config
.
providerConfigRules
.
providerRules
.
filter
(
(
x
)
=>
.
providerId
===
)
;
.
equal
(
.
length
,
1
)
;
.
equal
(
[
0
]
.
providerName
,
'Моя команда'
)
;
.
equal
(
[
0
]
.
config
.
access
.
apiKey
,
.
proxyTokens
.
at
(
-
1
)
.
token
)
;
.
deepEqual
(
.
config
.
modelConfigRules
.
providerModelRules
.
filter
(
(
x
)
=>
.
providerId
===
)
.
map
(
(
x
)
=>
.
modelId
)
,
[
'gpt-x'
]
)
;
.
equal
(
.
config
.
providerOrder
.
filter
(
(
x
)
=>
===
)
.
length
,
1
)
;
const
=
await
rpc
(
'connectTeamProvider'
,
{
provider
:
'anthropic'
,
models
:
[
'claude-z'
]
}
)
;
const
=
readJson
(
)
.
config
.
providerConfigRules
.
providerRules
.
find
(
(
x
)
=>
.
providerId
===
.
result
.
providerId
)
;
.
equal
(
.
config
.
api
.
type
,
'anthropic-messages'
)
;
.
equal
(
.
config
.
api
.
baseUrl
,
` ${ backendUrl} /v1/teams/ ${ TEAM } /proxy/anthropic `
)
;
const
=
.
proxyTokens
.
at
(
-
2
)
.
id
;
.
equal
(
(
await
rpc
(
'disconnectTeamProvider'
,
{
}
)
)
.
status
,
200
)
;
.
ok
(
.
revoked
.
includes
(
)
)
;
.
equal
(
(
await
rpc
(
'disconnectTeamProvider'
,
{
providerId
:
.
result
.
providerId
}
)
)
.
status
,
200
)
;
.
deepEqual
(
readJson
(
)
,
,
'disconnect restores the original document'
)
;
.
equal
(
(
await
rpc
(
'disconnectTeamProvider'
,
{
providerId
:
'local-openai'
}
)
)
.
status
,
404
,
'cannot remove non-team providers'
)
;
}
)
;
test
(
'/upload streams a 5 MB file to the backend as intact multipart'
,
async
(
)
=>
{
const
=
.
randomBytes
(
5
*
1024
*
1024
)
;
const
=
.
createHash
(
'sha256'
)
.
update
(
)
.
digest
(
'hex'
)
;
const
=
'отчёт 2026 (финал).bin'
;
const
=
await
fetch
(
` ${ SVC } /upload?kind=file `
,
{
method
:
'POST'
,
headers
:
{
'x-file-name'
:
encodeURIComponent
(
)
}
,
body
:
}
)
;
.
equal
(
.
status
,
403
)
;
const
=
await
fetch
(
` ${ SVC } /upload?kind=file&recipientId= ${ PETR . id } ¬e= ${ encodeURIComponent ( 'привет' ) } `
,
{
method
:
'POST'
,
headers
:
{
'x-zteam-csrf'
:
,
origin
:
ORIGIN
,
'x-file-name'
:
encodeURIComponent
(
)
,
'content-type'
:
'application/octet-stream'
}
,
body
:
,
}
)
;
const
=
await
.
json
(
)
;
.
equal
(
.
status
,
200
,
JSON
.
stringify
(
)
)
;
const
=
.
uploads
.
at
(
-
1
)
;
.
equal
(
.
kind
,
'file'
)
;
.
equal
(
.
bytes
,
.
length
)
;
.
equal
(
.
sha256
,
)
;
.
equal
(
.
name
,
)
;
.
equal
(
.
contentLength
,
.
received
,
'explicit content-length matches the streamed body'
)
;
.
deepEqual
(
.
query
,
{
recipientId
:
PETR
.
id
,
note
:
'привет'
}
)
;
.
equal
(
.
sha256
,
)
;
const
=
.
join
(
.
ZTEAM_STATE_DIR
,
'.tmp'
)
;
await
waitFor
(
(
)
=>
!
.
existsSync
(
)
||
.
readdirSync
(
)
.
length
===
0
,
3000
)
;
const
=
await
fetch
(
` ${ SVC } /upload?kind=archive&projectName= ${ encodeURIComponent ( 'Проект' ) } `
,
{
method
:
'POST'
,
headers
:
{
'x-zteam-csrf'
:
,
origin
:
ORIGIN
,
'x-file-name'
:
encodeURIComponent
(
'src.zip'
)
}
,
body
:
.
subarray
(
0
,
1000
)
,
}
)
;
.
equal
(
.
status
,
200
)
;
.
equal
(
.
uploads
.
at
(
-
1
)
.
kind
,
'archive'
)
;
.
deepEqual
(
.
uploads
.
at
(
-
1
)
.
query
,
{
projectName
:
'Проект'
}
)
;
}
)
;
test
(
'git: status / stage / commit (+task link) / log / show / diff / unstage / discard / branches'
,
async
(
)
=>
{
const
=
.
mkdtempSync
(
.
join
(
,
'repo-'
)
)
;
git
(
,
'init'
,
'-q'
,
'-b'
,
'main'
)
;
git
(
,
'config'
,
'user.email'
,
'ivan@example.com'
)
;
git
(
,
'config'
,
'user.name'
,
'Ivan'
)
;
git
(
,
'config'
,
'core.autocrlf'
,
'false'
)
;
.
writeFileSync
(
.
join
(
,
'a.txt'
)
,
'one\n'
)
;
.
writeFileSync
(
.
join
(
,
'файл b.txt'
)
,
'b\n'
)
;
let
=
(
await
rpc
(
'git'
,
{
dir
:
}
)
)
.
result
;
.
equal
(
.
isRepo
,
true
)
;
.
equal
(
.
branch
,
'main'
)
;
.
deepEqual
(
.
untracked
.
sort
(
)
,
[
'a.txt'
,
'файл b.txt'
]
.
sort
(
)
)
;
const
=
await
rpc
(
'gitCommit'
,
{
dir
:
,
message
:
'empty'
}
)
;
.
equal
(
.
status
,
400
)
;
.
match
(
.
body
.
error
,
/ Nothing staged /
)
;
.
equal
(
(
await
rpc
(
'gitStage'
,
{
dir
:
,
files
:
[
'-rf'
]
}
)
)
.
status
,
400
,
'option-like file rejected'
)
;
.
equal
(
(
await
rpc
(
'gitStage'
,
{
dir
:
,
files
:
[
'a.txt'
]
}
)
)
.
status
,
200
)
;
=
(
await
rpc
(
'git'
,
{
dir
:
}
)
)
.
result
;
.
deepEqual
(
.
staged
.
map
(
(
x
)
=>
[
.
path
,
.
status
]
)
,
[
[
'a.txt'
,
'added'
]
]
)
;
.
deepEqual
(
.
untracked
,
[
'файл b.txt'
]
)
;
const
=
await
rpc
(
'gitCommit'
,
{
dir
:
,
message
:
'feat: first #1a2b3c4d'
}
)
;
.
equal
(
.
status
,
200
,
JSON
.
stringify
(
.
body
)
)
;
.
match
(
.
result
.
hash
,
/ ^ [ 0- 9 a- f ] {40} $ /
)
;
.
equal
(
.
result
.
pushed
,
false
)
;
.
equal
(
.
commits
.
at
(
-
1
)
.
commitHash
,
.
result
.
hash
)
;
.
equal
(
.
resolve
(
.
commits
.
at
(
-
1
)
.
repositoryUrl
)
,
.
resolve
(
)
,
'no remote → cwd'
)
;
.
equal
(
.
result
.
linkedTaskId
,
.
tasks
[
0
]
.
id
)
;
await
rpc
(
'gitStageAll'
,
{
dir
:
}
)
;
const
=
await
rpc
(
'gitCommit'
,
{
dir
:
,
message
:
'second\n\nbody line'
}
)
;
.
equal
(
.
status
,
200
)
;
const
=
(
await
rpc
(
'gitLog'
,
{
dir
:
,
limit
:
10
}
)
)
.
result
;
.
equal
(
.
length
,
2
)
;
.
equal
(
[
0
]
.
subject
,
'second'
)
;
.
equal
(
[
0
]
.
parents
[
0
]
,
.
result
.
hash
)
;
.
ok
(
[
0
]
.
refs
.
some
(
(
x
)
=>
/ main /
.
test
(
)
)
)
;
.
ok
(
!
Number
.
isNaN
(
Date
.
parse
(
[
0
]
.
date
)
)
)
;
.
equal
(
(
await
rpc
(
'gitLog'
,
{
dir
:
,
limit
:
10
,
skip
:
1
}
)
)
.
result
.
length
,
1
)
;
.
equal
(
(
await
rpc
(
'gitLog'
,
{
dir
:
,
file
:
'a.txt'
}
)
)
.
result
.
length
,
1
)
;
const
=
(
await
rpc
(
'gitShow'
,
{
dir
:
,
hash
:
.
result
.
hash
}
)
)
.
result
;
.
equal
(
.
subject
,
'second'
)
;
.
equal
(
.
body
,
'body line'
)
;
.
deepEqual
(
.
files
.
map
(
(
f
)
=>
[
.
path
,
.
status
,
.
additions
,
.
deletions
]
)
,
[
[
'файл b.txt'
,
'added'
,
1
,
0
]
]
)
;
.
match
(
.
patch
,
/ \+ b/
)
;
.
equal
(
.
truncated
,
false
)
;
.
equal
(
(
await
rpc
(
'gitShow'
,
{
dir
:
,
hash
:
'--all'
}
)
)
.
status
,
400
)
;
.
writeFileSync
(
.
join
(
,
'a.txt'
)
,
'one\ntwo\n'
)
;
.
writeFileSync
(
.
join
(
,
'new.txt'
)
,
'n\n'
)
;
const
=
(
await
rpc
(
'gitDiff'
,
{
dir
:
,
file
:
'a.txt'
}
)
)
.
result
;
.
match
(
.
diff
,
/ \+ two/
)
;
const
=
(
await
rpc
(
'gitDiff'
,
{
dir
:
,
file
:
'new.txt'
}
)
)
.
result
;
.
equal
(
.
untracked
,
true
)
;
.
match
(
.
diff
,
/ \+ n/
)
;
await
rpc
(
'gitStage'
,
{
dir
:
,
files
:
[
'a.txt'
]
}
)
;
.
match
(
(
await
rpc
(
'gitDiff'
,
{
dir
:
,
staged
:
true
}
)
)
.
result
.
diff
,
/ \+ two/
)
;
.
equal
(
(
await
rpc
(
'gitUnstage'
,
{
dir
:
,
files
:
[
'a.txt'
]
}
)
)
.
status
,
200
)
;
=
(
await
rpc
(
'git'
,
{
dir
:
}
)
)
.
result
;
.
equal
(
.
staged
.
length
,
0
)
;
.
deepEqual
(
.
unstaged
.
map
(
(
x
)
=>
.
path
)
,
[
'a.txt'
]
)
;
.
equal
(
(
await
rpc
(
'gitDiscard'
,
{
dir
:
,
files
:
[
'../outside.txt'
]
}
)
)
.
status
,
400
,
'path escape rejected'
)
;
const
=
await
rpc
(
'gitDiscard'
,
{
dir
:
,
files
:
[
'a.txt'
,
'new.txt'
]
}
)
;
.
equal
(
.
status
,
200
,
JSON
.
stringify
(
.
body
)
)
;
.
deepEqual
(
.
result
.
removed
,
[
'new.txt'
]
)
;
.
equal
(
.
readFileSync
(
.
join
(
,
'a.txt'
)
,
'utf8'
)
,
'one\n'
)
;
.
equal
(
.
existsSync
(
.
join
(
,
'new.txt'
)
)
,
false
)
;
=
(
await
rpc
(
'git'
,
{
dir
:
}
)
)
.
result
;
.
equal
(
.
counts
.
total
,
0
)
;
.
equal
(
(
await
rpc
(
'gitCheckout'
,
{
dir
:
,
branch
:
'bad..name'
,
create
:
true
}
)
)
.
status
,
400
)
;
.
equal
(
(
await
rpc
(
'gitCheckout'
,
{
dir
:
,
branch
:
'feat/x'
,
create
:
true
}
)
)
.
status
,
200
)
;
const
=
(
await
rpc
(
'gitBranches'
,
{
dir
:
}
)
)
.
result
;
.
deepEqual
(
.
map
(
(
b
)
=>
[
.
name
,
.
current
]
)
.
sort
(
)
,
[
[
'feat/x'
,
true
]
,
[
'main'
,
false
]
]
)
;
.
equal
(
[
0
]
.
lastCommit
.
hash
.
length
>=
7
,
true
)
;
const
=
(
await
rpc
(
'git'
,
{
dir
:
}
)
)
.
result
;
.
equal
(
.
isRepo
,
false
)
;
}
)
;
test
(
'realtime: backend WebSocket events (re-ticketed) are relayed to SSE as event: team'
,
async
(
)
=>
{
const
=
[
]
;
const
=
.
get
(
{
host
:
'127.0.0.1'
,
port
:
PORT
,
path
:
'/events'
,
headers
:
{
origin
:
ORIGIN
}
}
)
;
const
=
await
new
Promise
(
(
resolve
)
=>
.
on
(
'response'
,
)
)
;
.
setEncoding
(
'utf8'
)
;
let
=
''
;
.
on
(
'data'
,
(
c
)
=>
{
+=
;
let
;
while
(
(
=
.
indexOf
(
'\n\n'
)
)
>=
0
)
{
const
=
.
slice
(
0
,
)
;
=
.
slice
(
+
2
)
;
const
=
/ ^ event: ( . + ) $ / m
.
exec
(
)
?.
[
1
]
;
const
=
/ ^ data: ( . + ) $ / m
.
exec
(
)
?.
[
1
]
;
if
(
)
.
push
(
{
,
data
:
JSON
.
parse
(
)
}
)
;
}
}
)
;
try
{
const
=
.
requests
.
filter
(
(
r
)
=>
.
path
.
endsWith
(
'/events-ticket'
)
)
.
length
;
for
(
const
of
.
ws
)
.
destroy
(
)
;
await
waitFor
(
(
)
=>
.
some
(
(
e
)
=>
.
ev
===
'team'
&&
.
data
.
type
===
'task.changed'
)
,
8000
)
;
const
=
.
find
(
(
e
)
=>
.
ev
===
'team'
&&
.
data
.
type
===
'task.changed'
)
;
.
deepEqual
(
.
data
,
{
type
:
'task.changed'
,
at
:
'2026-11-11T12:00:00.000Z'
}
)
;
.
ok
(
.
requests
.
filter
(
(
r
)
=>
.
path
.
endsWith
(
'/events-ticket'
)
)
.
length
>
,
'new ticket per connection'
)
;
await
waitFor
(
async
(
)
=>
(
await
(
await
fetch
(
` ${ SVC } /state `
)
)
.
json
(
)
)
.
realtime
===
'connected'
,
3000
)
;
}
finally
{
.
destroy
(
)
;
}
}
)
;
test
(
'/plugin-state reflects config.json toggles without restart (CORS *)'
,
async
(
)
=>
{
const
=
.
join
(
.
ZTEAM_ZCODE_HOME
,
'config.json'
)
;
let
=
await
fetch
(
` ${ SVC } /plugin-state `
,
{
headers
:
{
origin
:
'app://zcode'
}
}
)
;
.
equal
(
.
headers
.
get
(
'access-control-allow-origin'
)
,
'*'
)
;
let
=
await
.
json
(
)
;
.
equal
(
.
installed
,
true
)
;
.
equal
(
.
enabled
,
true
)
;
.
equal
(
.
signedIn
,
true
)
;
.
equal
(
typeof
.
pending
,
'number'
)
;
.
equal
(
.
pending
,
.
tasks
.
filter
(
(
t
)
=>
.
assigneeId
===
ME
.
id
&&
.
status
!==
'done'
)
.
length
)
;
const
=
readJson
(
)
;
.
plugins
.
enabledPlugins
[
'aura-team@local-marketplace'
]
=
false
;
writeJson
(
,
)
;
=
await
(
await
fetch
(
` ${ SVC } /plugin-state `
)
)
.
json
(
)
;
.
equal
(
.
enabled
,
false
)
;
.
equal
(
.
installed
,
true
)
;
.
plugins
.
enabledPlugins
[
'aura-team@local-marketplace'
]
=
true
;
.
plugins
.
enabled
=
false
;
writeJson
(
,
)
;
.
equal
(
(
await
(
await
fetch
(
` ${ SVC } /plugin-state `
)
)
.
json
(
)
)
.
enabled
,
false
,
'global plugins.enabled=false wins'
)
;
.
plugins
.
enabled
=
true
;
writeJson
(
,
)
;
.
equal
(
(
await
(
await
fetch
(
` ${ SVC } /plugin-state `
)
)
.
json
(
)
)
.
enabled
,
true
)
;
.
deepEqual
(
(
await
(
await
fetch
(
` ${ SVC } /state `
)
)
.
json
(
)
)
.
plugin
,
{
installed
:
true
,
enabled
:
true
}
)
;
const
=
await
(
await
fetch
(
` ${ SVC } /notify/pending `
)
)
.
json
(
)
;
.
equal
(
typeof
.
count
,
'number'
)
;
}
)
;
test
(
'/panel and /panel/assets'
,
async
(
)
=>
{
const
=
await
fetch
(
` ${ SVC } /panel `
)
;
.
equal
(
.
status
,
200
)
;
.
equal
(
.
headers
.
get
(
'cache-control'
)
,
'no-store'
)
;
.
match
(
.
headers
.
get
(
'content-type'
)
,
/ text\/ html /
)
;
const
=
.
resolve
(
HERE
,
'..'
,
'assets'
)
;
.
mkdirSync
(
,
{
recursive
:
true
}
)
;
const
=
.
join
(
,
` zteam-test- ${ process. pid } .css `
)
;
.
writeFileSync
(
,
'body{}'
)
;
try
{
const
=
await
fetch
(
` ${ SVC } /panel/assets/ ${ path. basename ( probe) } `
)
;
.
equal
(
.
status
,
200
)
;
.
match
(
.
headers
.
get
(
'content-type'
)
,
/ text\/ css /
)
;
.
equal
(
await
.
text
(
)
,
'body{}'
)
;
}
finally
{
.
rmSync
(
,
{
force
:
true
}
)
;
}
.
equal
(
(
await
fetch
(
` ${ SVC } /panel/assets/..%2Fserver.mjs `
)
)
.
status
,
400
)
;
.
equal
(
(
await
fetch
(
` ${ SVC } /panel/assets/missing.png `
)
)
.
status
,
404
)
;
}
)
;
test
(
'changePassword re-logs in with the new password'
,
async
(
)
=>
{
const
=
await
rpc
(
'changePassword'
,
{
currentPassword
:
.
password
,
newPassword
:
'new-secret-pass'
}
)
;
.
equal
(
.
status
,
200
,
JSON
.
stringify
(
.
body
)
)
;
.
equal
(
.
result
.
relogged
,
true
)
;
.
equal
(
(
await
rpc
(
'session'
)
)
.
status
,
200
)
;
}
)
;
function
mcpSession
(
)
{
const
=
spawn
(
.
execPath
,
[
.
join
(
PLUGIN_SCRIPTS
,
'mcp-server.mjs'
)
]
,
{
env
:
{
...
.
env
,
ZTEAM_AGENT_FILE
:
.
ZTEAM_AGENT_FILE
}
,
stdio
:
[
'pipe'
,
'pipe'
,
'pipe'
]
,
windowsHide
:
true
,
}
)
;
let
=
''
;
const
=
new
Map
(
)
;
.
stdout
.
setEncoding
(
'utf8'
)
;
.
stdout
.
on
(
'data'
,
(
c
)
=>
{
+=
;
let
;
while
(
(
=
.
indexOf
(
'\n'
)
)
>=
0
)
{
const
=
.
slice
(
0
,
)
;
=
.
slice
(
+
1
)
;
if
(
!
.
trim
(
)
)
continue
;
const
=
JSON
.
parse
(
)
;
.
get
(
.
id
)
?.
(
)
;
.
delete
(
.
id
)
;
}
}
)
;
let
=
1
;
return
{
,
request
(
method, params
)
{
const
=
++
;
.
stdin
.
write
(
` ${ JSON . stringify ( { jsonrpc : '2.0' , id, method, params } ) } \n `
)
;
return
new
Promise
(
(
resolve, reject
)
=>
{
.
set
(
,
)
;
setTimeout
(
(
)
=>
reject
(
new
Error
(
` MCP timeout on ${ method} `
)
)
,
8000
)
;
}
)
;
}
,
notify
(
method, params
)
{
.
stdin
.
write
(
` ${ JSON . stringify ( { jsonrpc : '2.0' , method, params } ) } \n `
)
;
}
,
close
(
)
{
.
stdin
.
end
(
)
;
}
,
}
;
}
test
(
'MCP server: initialize, tools/list, tools/call team_my_tasks + team_create_task'
,
async
(
)
=>
{
const
=
mcpSession
(
)
;
try
{
const
=
await
.
request
(
'initialize'
,
{
protocolVersion
:
'2025-03-26'
,
capabilities
:
{
}
,
clientInfo
:
{
name
:
'test'
,
version
:
'0'
}
}
)
;
.
equal
(
.
result
.
protocolVersion
,
'2025-03-26'
)
;
.
equal
(
.
result
.
serverInfo
.
name
,
'aura-team'
)
;
.
notify
(
'notifications/initialized'
)
;
.
deepEqual
(
(
await
.
request
(
'ping'
)
)
.
result
,
{
}
)
;
const
=
await
.
request
(
'tools/list'
,
{
}
)
;
const
=
.
result
.
tools
.
map
(
(
t
)
=>
.
name
)
.
sort
(
)
;
.
deepEqual
(
,
[
'team_activity'
,
'team_board'
,
'team_create_task'
,
'team_get_task'
,
'team_members'
,
'team_move_task'
,
'team_my_tasks'
,
'team_update_task'
,
'team_whoami'
]
)
;
const
=
.
result
.
tools
.
find
(
(
t
)
=>
.
name
===
'team_board'
)
;
.
equal
(
.
annotations
.
readOnlyHint
,
true
)
;
.
equal
(
.
result
.
tools
.
find
(
(
t
)
=>
.
name
===
'team_create_task'
)
.
annotations
.
readOnlyHint
,
false
)
;
.
deepEqual
(
.
result
.
tools
.
find
(
(
t
)
=>
.
name
===
'team_create_task'
)
.
inputSchema
.
required
,
[
'title'
]
)
;
const
=
await
.
request
(
'tools/call'
,
{
name
:
'team_my_tasks'
,
arguments
:
{
}
}
)
;
.
equal
(
.
result
.
isError
,
undefined
,
JSON
.
stringify
(
.
result
)
)
;
const
=
.
result
.
content
[
0
]
.
text
;
.
match
(
,
/ Команда «Alpha» /
)
;
.
match
(
,
/ \[ ( todo| doing| review) \] #[ 0- 9 a- f ] {8} «/
)
;
.
ok
(
Array
.
isArray
(
.
result
.
structuredContent
.
tasks
)
)
;
const
=
await
.
request
(
'tools/call'
,
{
name
:
'team_create_task'
,
arguments
:
{
title
:
'Из MCP'
,
dueAt
:
'2026-11-30'
,
priority
:
'high'
}
}
)
;
.
match
(
.
result
.
content
[
0
]
.
text
,
/ Создана задача \[ todo\] #[ 0- 9 a- f ] {8} «Из MCP» — @Ivan · high · до 2026-11-30 /
)
;
const
=
await
.
request
(
'tools/call'
,
{
name
:
'team_get_task'
,
arguments
:
{
taskId
:
'zzzzzzzz'
}
}
)
;
.
equal
(
.
result
.
isError
,
true
)
;
const
=
await
.
request
(
'nope/method'
,
{
}
)
;
.
equal
(
.
error
.
code
,
-
32601
)
;
}
finally
{
.
close
(
)
;
}
}
)
;
test
(
'MCP server: clear error when the service is down'
,
async
(
)
=>
{
const
=
.
join
(
,
'down-agent.json'
)
;
writeJson
(
,
{
port
:
1
,
token
:
'a'
.
repeat
(
64
)
,
serviceDir
:
}
)
;
const
=
spawn
(
.
execPath
,
[
.
join
(
PLUGIN_SCRIPTS
,
'mcp-server.mjs'
)
]
,
{
env
:
{
...
.
env
,
ZTEAM_AGENT_FILE
:
}
,
stdio
:
[
'pipe'
,
'pipe'
,
'pipe'
]
,
windowsHide
:
true
,
}
)
;
.
stdin
.
end
(
` ${ JSON . stringify ( { jsonrpc : '2.0' , id : 1 , method : 'tools/call' , params : { name : 'team_my_tasks' , arguments : { } } } )}\n `
)
;
let
=
''
;
for
await
(
const
of
.
stdout
)
+=
;
const
=
JSON
.
parse
(
.
trim
(
)
.
split
(
'\n'
)
[
0
]
)
;
.
equal
(
.
result
.
isError
,
true
)
;
.
match
(
.
result
.
content
[
0
]
.
text
,
/ Aura Team сервис не запущен /
)
;
}
)
;
test
(
'SessionStart hook: posts ide context and prints additionalContext JSON; silent when down'
,
async
(
)
=>
{
const
run
=
(
agentFile, stdin
)
=>
new
Promise
(
(
resolve
)
=>
{
const
=
spawn
(
.
execPath
,
[
.
join
(
PLUGIN_SCRIPTS
,
'session-start.mjs'
)
]
,
{
env
:
{
...
.
env
,
ZTEAM_AGENT_FILE
:
}
,
stdio
:
[
'pipe'
,
'pipe'
,
'pipe'
]
,
windowsHide
:
true
,
}
)
;
let
=
''
;
.
stdout
.
on
(
'data'
,
(
c
)
=>
{
+=
;
}
)
;
.
on
(
'exit'
,
(
code
)
=>
resolve
(
{
,
}
)
)
;
.
stdin
.
end
(
)
;
}
)
;
const
=
await
run
(
.
ZTEAM_AGENT_FILE
,
JSON
.
stringify
(
{
cwd
:
,
hook_event_name
:
'SessionStart'
,
session_id
:
'sess_x'
}
)
)
;
.
equal
(
.
code
,
0
)
;
const
=
JSON
.
parse
(
.
out
)
;
.
equal
(
.
hookSpecificOutput
.
hookEventName
,
'SessionStart'
)
;
.
match
(
.
hookSpecificOutput
.
additionalContext
,
/ ^ Aura Team · команда «Alpha»: у вас \d + открыт/
)
;
.
ok
(
.
hookSpecificOutput
.
additionalContext
.
split
(
'\n'
)
.
length
<=
12
)
;
const
=
await
(
await
fetch
(
` ${ SVC } /state `
)
)
.
json
(
)
;
.
equal
(
.
resolve
(
.
ide
.
cwd
)
,
.
resolve
(
)
)
;
.
equal
(
.
ide
.
sessionId
,
'sess_x'
)
;
const
=
await
run
(
.
join
(
,
'down-agent.json'
)
,
JSON
.
stringify
(
{
cwd
:
}
)
)
;
.
equal
(
.
code
,
0
)
;
.
equal
(
.
out
,
''
)
;
const
=
await
run
(
.
ZTEAM_AGENT_FILE
,
'not json'
)
;
.
equal
(
.
code
,
0
)
;
}
)
;
test
(
'logout clears session'
,
async
(
)
=>
{
.
equal
(
(
await
rpc
(
'logout'
)
)
.
status
,
200
)
;
const
=
await
(
await
fetch
(
` ${ SVC } /state `
)
)
.
json
(
)
;
.
equal
(
.
signedIn
,
false
)
;
.
equal
(
.
teamId
,
null
)
;
const
=
await
(
await
fetch
(
` ${ SVC } /plugin-state `
)
)
.
json
(
)
;
.
equal
(
.
signedIn
,
false
)
;
.
equal
(
.
pending
,
0
)
;
}
)
;