FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
opencode/packages/opencode/test/plugin/trigger.test.ts at dev · argszero/opencode · GitHub
argszero
/
opencode
Public
forked from
anomalyco/opencode
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
opencode
/
packages
/
opencode
/
test
/
plugin
/
trigger.test.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
108 lines (102 loc) · 3.23 KB
Breadcrumbs
opencode
/
packages
/
opencode
/
test
/
plugin
/
trigger.test.ts
Copy path
File metadata and controls
108 lines (102 loc) · 3.23 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
{
describe
,
expect
}
from
"bun:test"
import
{
Effect
}
from
"effect"
import
{
CrossSpawnSpawner
}
from
"@opencode-ai/core/cross-spawn-spawner"
import
{
Npm
}
from
"@opencode-ai/core/npm"
import
path
from
"path"
import
{
pathToFileURL
}
from
"url"
import
{
Account
}
from
"../../src/account/account"
import
{
Auth
}
from
"../../src/auth"
import
{
RuntimeFlags
}
from
"../../src/effect/runtime-flags"
import
{
Plugin
}
from
"../../src/plugin/index"
import
{
TestInstance
}
from
"../fixture/fixture"
import
{
testEffect
}
from
"../lib/effect"
import
{
AccountTest
}
from
"../fake/account"
import
{
AuthTest
}
from
"../fake/auth"
import
{
NpmTest
}
from
"../fake/npm"
import
{
ProviderV2
}
from
"@opencode-ai/core/provider"
import
{
ModelV2
}
from
"@opencode-ai/core/model"
import
{
AppNodeBuilder
}
from
"@opencode-ai/core/effect/app-node-builder"
import
{
LayerNode
}
from
"@opencode-ai/core/effect/layer-node"
const
it
=
testEffect
(
AppNodeBuilder
.
build
(
LayerNode
.
group
(
[
Plugin
.
node
,
CrossSpawnSpawner
.
node
]
)
,
[
[
Auth
.
node
,
AuthTest
.
empty
]
,
[
Account
.
node
,
AccountTest
.
empty
]
,
[
Npm
.
node
,
NpmTest
.
noop
]
,
[
RuntimeFlags
.
node
,
RuntimeFlags
.
layer
(
{
disableDefaultPlugins
:
true
}
)
]
,
]
)
,
)
const
systemHook
=
"experimental.chat.system.transform"
function
withProject
<
A
,
E
,
R
>
(
source
:
string
,
self
:
Effect
.
Effect
<
A
,
E
,
R
>
)
{
return
Effect
.
gen
(
function
*
(
)
{
const
test
=
yield
*
TestInstance
const
file
=
path
.
join
(
test
.
directory
,
"plugin.ts"
)
yield
*
Effect
.
all
(
[
Effect
.
promise
(
(
)
=>
Bun
.
write
(
file
,
source
)
)
,
Effect
.
promise
(
(
)
=>
Bun
.
write
(
path
.
join
(
test
.
directory
,
"opencode.json"
)
,
JSON
.
stringify
(
{
$schema
:
"https://opencode.ai/config.json"
,
plugin
:
[
pathToFileURL
(
file
)
.
href
]
,
}
,
null
,
2
,
)
,
)
,
)
,
]
,
{
discard
:
true
,
concurrency
:
2
}
,
)
return
yield
*
self
}
)
}
const
triggerSystemTransform
=
Effect
.
fn
(
"PluginTriggerTest.triggerSystemTransform"
)
(
function
*
(
)
{
const
plugin
=
yield
*
Plugin
.
Service
const
out
=
{
system
:
[
]
as
string
[
]
}
yield
*
plugin
.
trigger
(
systemHook
,
{
model
:
{
providerID
:
ProviderV2
.
ID
.
anthropic
,
modelID
:
ModelV2
.
ID
.
make
(
"claude-sonnet-4-6"
)
,
}
,
}
,
out
,
)
return
out
.
system
}
)
describe
(
"plugin.trigger"
,
(
)
=>
{
it
.
instance
(
"runs synchronous hooks without crashing"
,
(
)
=>
withProject
(
[
"export default async () => ({"
,
`
${
JSON
.
stringify
(
systemHook
)
}
: (_input, output) => {`
,
' output.system.unshift("sync")'
,
" },"
,
"})"
,
""
,
]
.
join
(
"\n"
)
,
Effect
.
gen
(
function
*
(
)
{
expect
(
yield
*
triggerSystemTransform
(
)
)
.
toEqual
(
[
"sync"
]
)
}
)
,
)
,
)
it
.
instance
(
"awaits asynchronous hooks"
,
(
)
=>
withProject
(
[
"export default async () => ({"
,
`
${
JSON
.
stringify
(
systemHook
)
}
: async (_input, output) => {`
,
" await Bun.sleep(1)"
,
' output.system.unshift("async")'
,
" },"
,
"})"
,
""
,
]
.
join
(
"\n"
)
,
Effect
.
gen
(
function
*
(
)
{
expect
(
yield
*
triggerSystemTransform
(
)
)
.
toEqual
(
[
"async"
]
)
}
)
,
)
,
)
}
)
Back
|
FazBrowse Home
|
New Git URL