mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 23:24:00 +03:00
fix(cli): default the Windows service to port 45278 (#55547)
This commit is contained in:
committed by
GitHub
Unverified
parent
1e63a3bb73
commit
3943b84ef0
@@ -43,7 +43,16 @@ export function filename(channel = OPENCODE_CHANNEL) {
|
||||
return `service-${channel.replace(/[^a-zA-Z0-9._-]/g, "-")}.json`
|
||||
}
|
||||
|
||||
export function defaultPort(channel = OPENCODE_CHANNEL) {
|
||||
export function defaultPort(channel = OPENCODE_CHANNEL, platform = process.platform) {
|
||||
const port = channelPort(channel)
|
||||
// Windows hands out 0xC000-0xFFFF for outgoing connections, and Hyper-V and WinNAT reserve blocks of that range at
|
||||
// boot, so a port there can fail as in use while nothing listens on it. Moving into the 0xB000 block keeps the low
|
||||
// 12 bits: 0xC0DE becomes 0xB0DE, which is 0xC0DE - 4096, a nod to the v1 port.
|
||||
if (platform === "win32" && port >= 0xc000) return 0xb000 | (port & 0xfff)
|
||||
return port
|
||||
}
|
||||
|
||||
function channelPort(channel: string) {
|
||||
if (channel === "latest" || channel === "dev" || channel === "beta" || channel === "next") return 0xc0de
|
||||
if (channel === "local") return 0xc0df
|
||||
return 10_000 + (Number.parseInt(Hash.fast(channel).slice(0, 8), 16) % 50_000)
|
||||
|
||||
@@ -18,13 +18,27 @@ import { testEffect } from "../../core/test/lib/effect"
|
||||
const it = testEffect(NodeFileSystem.layer)
|
||||
|
||||
test("managed service ports are stable per installation channel", () => {
|
||||
expect(ServiceConfig.defaultPort("latest")).toBe(0xc0de)
|
||||
expect(ServiceConfig.defaultPort("dev")).toBe(0xc0de)
|
||||
expect(ServiceConfig.defaultPort("beta")).toBe(0xc0de)
|
||||
expect(ServiceConfig.defaultPort("next")).toBe(0xc0de)
|
||||
expect(ServiceConfig.defaultPort("local")).toBe(0xc0df)
|
||||
expect(ServiceConfig.defaultPort("preview-a")).toBe(ServiceConfig.defaultPort("preview-a"))
|
||||
expect(ServiceConfig.defaultPort("preview-a")).not.toBe(ServiceConfig.defaultPort("preview-b"))
|
||||
expect(ServiceConfig.defaultPort("latest", "linux")).toBe(0xc0de)
|
||||
expect(ServiceConfig.defaultPort("dev", "linux")).toBe(0xc0de)
|
||||
expect(ServiceConfig.defaultPort("beta", "linux")).toBe(0xc0de)
|
||||
expect(ServiceConfig.defaultPort("next", "linux")).toBe(0xc0de)
|
||||
expect(ServiceConfig.defaultPort("local", "linux")).toBe(0xc0df)
|
||||
expect(ServiceConfig.defaultPort("latest", "darwin")).toBe(0xc0de)
|
||||
expect(ServiceConfig.defaultPort("preview-a", "linux")).toBe(ServiceConfig.defaultPort("preview-a", "linux"))
|
||||
expect(ServiceConfig.defaultPort("preview-a", "linux")).not.toBe(ServiceConfig.defaultPort("preview-b", "linux"))
|
||||
})
|
||||
|
||||
test("managed service ports on Windows stay below the range Windows reserves", () => {
|
||||
expect(ServiceConfig.defaultPort("latest", "win32")).toBe(0xc0de - 4096)
|
||||
expect(ServiceConfig.defaultPort("dev", "win32")).toBe(0xc0de - 4096)
|
||||
expect(ServiceConfig.defaultPort("local", "win32")).toBe(0xc0df - 4096)
|
||||
const ports = Array.from({ length: 200 }, (_, index) => ({
|
||||
windows: ServiceConfig.defaultPort(`preview-${index}`, "win32"),
|
||||
linux: ServiceConfig.defaultPort(`preview-${index}`, "linux"),
|
||||
}))
|
||||
expect(ports.some((port) => port.linux >= 0xc000)).toBe(true)
|
||||
expect(ports.every((port) => port.windows >= 10_000 && port.windows < 0xc000)).toBe(true)
|
||||
expect(ports.filter((port) => port.linux < 0xc000 && port.windows !== port.linux)).toEqual([])
|
||||
})
|
||||
|
||||
test("service disabled accepts only booleans without changing configuration on invalid input", async () => {
|
||||
|
||||
@@ -32,8 +32,23 @@ and open the printed link locally:
|
||||
$ ssh -L 49374:127.0.0.1:49374 my-server
|
||||
```
|
||||
|
||||
By default the server runs on port 49374 and listens only on localhost. You can
|
||||
change this config with the `opencode service` command.
|
||||
By default the server listens only on localhost. Its port depends on the
|
||||
platform:
|
||||
|
||||
| Platform | Default port |
|
||||
| --------------------- | ------------ |
|
||||
| macOS, Linux, and WSL | 49374 |
|
||||
| Windows | 45278 |
|
||||
|
||||
Windows reserves ports from 49152 up. Print the current address with
|
||||
`opencode service status`:
|
||||
|
||||
```bash
|
||||
$ opencode service status
|
||||
http://127.0.0.1:49374
|
||||
```
|
||||
|
||||
You can change this config with the `opencode service` command.
|
||||
|
||||
### Remote access
|
||||
|
||||
|
||||
Reference in New Issue
Block a user