Files
openwork/apps/app/scripts/events.mjs
Omar McAdam 2b91b4d777 refactor: repo folder structure (#1038)
* refactor(repo): move OpenWork apps into apps and ee layout

Rebase the monorepo layout migration onto the latest dev changes so the moved app, desktop, share, and cloud surfaces keep working from their new paths. Carry the latest deeplink, token persistence, build, Vercel, and docs updates forward to avoid stale references and broken deploy tooling.

* chore(repo): drop generated desktop artifacts

Ignore the moved Tauri target and sidecar paths so local cargo checks do not pollute the branch. Remove the accidentally committed outputs from the repo while keeping the layout migration intact.

* fix(release): drop built server cli artifact

Stop tracking the locally built apps/server/cli binary so generated server outputs do not leak into commits. Also update the release workflow to check the published scoped package name for @openwork/server before deciding whether npm publish is needed.

* fix(workspace): add stable CLI bin wrappers

Point the server and router package bins at committed wrapper scripts so workspace installs can create shims before dist outputs exist. Keep the wrappers compatible with built binaries and source checkouts to avoid Vercel install warnings without changing runtime behavior.
2026-03-19 11:41:38 -07:00

68 lines
1.8 KiB
JavaScript

import assert from "node:assert/strict";
import {
findFreePort,
makeClient,
normalizeEvent,
parseArgs,
spawnOpencodeServe,
waitForHealthy,
} from "./_util.mjs";
const args = parseArgs(process.argv.slice(2));
const directory = args.get("dir") ?? process.cwd();
const port = await findFreePort();
const server = await spawnOpencodeServe({ directory, port });
try {
const client = makeClient({ baseUrl: server.baseUrl, directory: server.cwd });
await waitForHealthy(client);
const events = [];
const controller = new AbortController();
const sub = await client.event.subscribe(undefined, { signal: controller.signal });
const reader = (async () => {
try {
for await (const raw of sub.stream) {
const evt = normalizeEvent(raw);
if (!evt) continue;
events.push(evt);
if (events.length >= 25) break;
}
} catch {
// Ignore abort errors.
}
})();
// Trigger something that should emit events.
const created = await client.session.create({ title: "OpenWork events test" });
// Wait briefly to collect events.
await new Promise((r) => setTimeout(r, 1200));
controller.abort();
await Promise.race([reader, new Promise((r) => setTimeout(r, 500))]);
// We expect to see at least one server or session event.
assert.ok(events.length > 0, "expected SSE events");
const types = new Set(events.map((e) => e.type));
console.log(
JSON.stringify({
ok: true,
baseUrl: server.baseUrl,
createdSessionId: created.id,
eventTypes: Array.from(types),
sample: events.slice(0, 5),
}),
);
} catch (e) {
const message = e instanceof Error ? e.message : String(e);
console.error(JSON.stringify({ ok: false, error: message, stderr: server.getStderr() }));
process.exitCode = 1;
} finally {
await server.close();
}