SurfSense/surfsense_local/electron/scripts/opencode/enabled.test.mjs
DESKTOP-RTLN3BA\$punk 64cbff3f68 fix(agent): refuse an opencode switch that is neither 1 nor 0
With opencode on by default, any SURFSENSE_LOCAL_OPENCODE_ENABLED other than
"1" turned it off: "true", "yes", and the empty string an unset CI variable
gives all built an installer without the agent, and stage.mjs blamed "=0" as
it removed the stage. Now unset or empty keeps the default, 1 and 0 decide,
and anything else stops the build. The off message prints the value it read.
2026-10-07 13:31:46 -07:00

26 lines
985 B
JavaScript

import assert from "node:assert/strict"
import test from "node:test"
import { opencodeEnabled } from "./enabled.mjs"
test("opencode is on unless something turns it off, so every installer carries the agent", () => {
assert.equal(opencodeEnabled({}), true)
})
test("SURFSENSE_LOCAL_OPENCODE_ENABLED turns it on with 1 and off with 0", () => {
assert.equal(opencodeEnabled({ SURFSENSE_LOCAL_OPENCODE_ENABLED: "1" }), true)
assert.equal(opencodeEnabled({ SURFSENSE_LOCAL_OPENCODE_ENABLED: "0" }), false)
})
test("an empty switch, as an unset CI variable gives, keeps the default", () => {
assert.equal(opencodeEnabled({ SURFSENSE_LOCAL_OPENCODE_ENABLED: "" }), true)
})
test("any other value is refused, so a build never drops the agent on a misread switch", () => {
for (const value of ["true", "yes", "false"]) {
assert.throws(
() => opencodeEnabled({ SURFSENSE_LOCAL_OPENCODE_ENABLED: value }),
new RegExp(`is "${value}"; set it to 1 or 0`)
)
}
})