Skip to repository content119 lines · 4.1 KB · javascript
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T06:12:30.070Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
observation_stub_effectd.mjs
1// A daemon stub for testing `issue31_observation` (omega#97).
2//
3// This exists to drive the OBSERVER's own failure handling, which a real
4// `omega-effectd` will not do on command: there is no way to ask a healthy
5// daemon to list a run and then refuse to describe it.
6//
7// It is a test double for our error paths, never host authority. Nothing it
8// emits is published to a relay by any test, and the omega#97 live proof
9// (`a_running_daemon_supplies_the_reading_a_paired_device_reads_on_a_live_relay`)
10// runs against the packaged `omega-effectd` instead — because putting recorded
11// or scripted daemon output on the wire in place of live host state is exactly
12// the substitution omega#49's exit forbids.
13//
14// The scenario lives in the data root so parallel tests cannot collide through
15// a shared environment variable.
16
17import { readFileSync } from "node:fs"
18import path from "node:path"
19import readline from "node:readline"
20
21const SCHEMA = "openagents.omega.effectd.v1"
22const dataRoot = process.env.OPENAGENTS_OMEGA_EFFECTD_DATA_ROOT
23if (!dataRoot) {
24 process.stderr.write("OPENAGENTS_OMEGA_EFFECTD_DATA_ROOT is required\n")
25 process.exit(1)
26}
27
28const scenario = JSON.parse(readFileSync(path.join(dataRoot, "scenario.json"), "utf8"))
29const runs = scenario.runs ?? []
30const details = scenario.details ?? {}
31const reports = scenario.reports ?? {}
32const receipts = scenario.receipts ?? {}
33const refuseGetRun = new Set(scenario.refuseGetRun ?? [])
34const refuseListRuns = scenario.refuseListRuns === true
35const refuseCapacity = scenario.refuseCapacity === true
36
37const respond = (id, ok, result, error) => {
38 const frame = { schema: SCHEMA, kind: "response", id, generation: 1, ok }
39 if (result !== undefined) frame.result = result
40 if (error !== undefined) frame.error = error
41 process.stdout.write(`${JSON.stringify(frame)}\n`)
42}
43
44const refusal = (message) => ({ code: "internal", message })
45
46readline.createInterface({ input: process.stdin }).on("line", (line) => {
47 if (!line.trim()) return
48 let request
49 try {
50 request = JSON.parse(line)
51 } catch {
52 return
53 }
54 if (request.kind !== "request") return
55 const { id, method, params } = request
56
57 switch (method) {
58 case "initialize":
59 respond(id, true, {
60 schema: SCHEMA,
61 protocolVersion: 1,
62 serviceVersion: "0.0.0-observation-stub",
63 generation: 1,
64 capabilities: ["list_runs", "get_run", "get_capacity", "get_report", "get_receipt"],
65 dataRoot,
66 activeRunLimit: 8,
67 })
68 return
69 case "list_runs":
70 if (refuseListRuns) {
71 respond(id, false, undefined, refusal("The stub was told to refuse list_runs."))
72 return
73 }
74 respond(id, true, { runs })
75 return
76 case "get_capacity":
77 if (refuseCapacity) {
78 respond(id, false, undefined, refusal("The stub was told to refuse get_capacity."))
79 return
80 }
81 respond(id, true, scenario.capacity ?? { activeRunLimit: 8, activeRunCount: 0, lanes: [] })
82 return
83 case "get_run": {
84 const runRef = params?.runRef
85 if (refuseGetRun.has(runRef)) {
86 respond(id, false, undefined, refusal(`The stub was told to refuse get_run for ${runRef}.`))
87 return
88 }
89 const run = details[runRef]
90 if (!run) {
91 respond(id, false, undefined, { code: "run_not_found", message: `No run ${runRef}.` })
92 return
93 }
94 respond(id, true, { run })
95 return
96 }
97 case "get_report": {
98 const report = reports[params?.runRef]
99 if (!report) {
100 respond(id, false, undefined, { code: "run_not_found", message: "No report." })
101 return
102 }
103 respond(id, true, { report })
104 return
105 }
106 case "get_receipt": {
107 const receipt = receipts[params?.runRef]
108 if (!receipt) {
109 respond(id, false, undefined, { code: "run_not_found", message: "No receipt." })
110 return
111 }
112 respond(id, true, { receipt })
113 return
114 }
115 default:
116 respond(id, false, undefined, { code: "unsupported", message: `Unsupported ${method}.` })
117 }
118})
119