Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/v2-lifecycle-contract.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- "src/source/opencode2/**"
- "src/source/runtime/**"
- "scripts/v2-event-bridge-test.mjs"
- "scripts/v2-event-stream-contract-test.mjs"
- "scripts/v2-plugin-sentinel-test.mjs"
- ".github/workflows/v2-lifecycle-contract.yml"
push:
Expand All @@ -14,6 +15,7 @@ on:
- "src/source/opencode2/**"
- "src/source/runtime/**"
- "scripts/v2-event-bridge-test.mjs"
- "scripts/v2-event-stream-contract-test.mjs"
- "scripts/v2-plugin-sentinel-test.mjs"
- ".github/workflows/v2-lifecycle-contract.yml"

Expand All @@ -40,5 +42,7 @@ jobs:
- run: node --check src/source/opencode2/event-bridge.js
- run: node --check src/source/opencode2/experimental.js
- run: node --check scripts/v2-event-bridge-test.mjs
- run: node --check scripts/v2-event-stream-contract-test.mjs
- run: node scripts/v2-event-bridge-test.mjs
- run: node scripts/v2-event-stream-contract-test.mjs
- run: node scripts/v2-plugin-sentinel-test.mjs
38 changes: 38 additions & 0 deletions scripts/v2-event-stream-contract-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import assert from "node:assert/strict"
import { createOpenCode2EventBridge } from "../src/source/opencode2/event-bridge.js"

const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
const seen = []
let subscribeArgs = -1
let cleanupCalls = 0

async function* stream() {
yield {
directory: "/project",
payload: {
type: "session.created",
properties: { info: { id: "ses_stream", directory: "/project" } },
},
}
}

const bridge = createOpenCode2EventBridge({
directory: "/project",
onEvent: async (event) => seen.push(event),
})

await bridge.attach(async (...args) => {
subscribeArgs = args.length
return { stream: stream(), dispose: async () => { cleanupCalls += 1 } }
})

for (let attempt = 0; attempt < 50 && seen.length === 0; attempt++) await delay(5)
assert.equal(subscribeArgs, 0)
assert.equal(seen[0]?.action, "created")
assert.ok(bridge.runtimeManager.peek("ses_stream"))

assert.equal(await bridge.dispose(), true)
assert.equal(cleanupCalls, 1)
assert.equal(bridge.runtimeManager.peek("ses_stream"), undefined)

console.log("OpenCode 2 event stream contract passed")