Repository navigation
fix(opencode): updating restarts the background service on the new version #34606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+374
−6
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
752be37
fix(opencode): updating moves the running server onto the new binary
mkantenko 464e8fa
fix(opencode): replace only the updated instance's service
mkantenko a88a8ac
fix(opencode): leave the 1.x helper out of the service fix
mkantenko 8e9ae74
fix(opencode): never send the local service password to the configure…
mkantenko caede3c
fix(opencode): report a failed service replacement as a failed update…
mkantenko 3fed040
fix(opencode): match the service URL by address family and keep stder…
mkantenko fbee882
fix(opencode): compare URL protocols and keep the replacement error's…
mkantenko 95c6ead
fix(opencode): keep the replaced service independent of T3 Code
mkantenko d9576a5
docs(opencode): name the Server URLs that restart the service on update
mkantenko 12987a0
Merge remote-tracking branch 'origin/main' into t3/opencode-service-u…
mkantenko 526e6c8
fix(opencode): reconnect after replacing the service so its new versi…
mkantenko c16df60
fix(opencode): forget every instance's service connection when an upd…
mkantenko 8ed7062
Merge remote-tracking branch 'github/main' into pr-31152
maria-rcks ae5ebed
fix(opencode): replace the shared service before any instance forgets…
maria-rcks c7e2cb5
Merge github/main into t3/opencode-service-update
maria-rcks f719da1
Merge remote-tracking branch 'origin/main' into t3/opencode-service-u…
t3dotgg df1a7e5
fix(opencode): a failed service replacement still reports what is run…
t3dotgg f83e025
Merge remote-tracking branch 'origin/main' into t3/opencode-service-u…
t3dotgg acdd2fb
Merge remote-tracking branch 'origin/main' into t3/opencode-service-u…
t3dotgg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -257,6 +257,7 @@ export const replayServer = ( | |
| borrowers.current -= 1; | ||
| }), | ||
| ), | ||
| forget: Effect.void, | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
packages/provider-opencode/src/server/v2/OpenCode2Service.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import * as NodeServices from "@effect/platform-node/NodeServices"; | ||
| import { it } from "@effect/vitest"; | ||
| import * as HostProcess from "@t3tools/shared/HostProcess"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as FileSystem from "effect/FileSystem"; | ||
| import * as Path from "effect/Path"; | ||
| import { expect, vi } from "vite-plus/test"; | ||
|
|
||
| import * as OpenCodeRuntime from "../OpenCodeRuntime.ts"; | ||
| import { replaceOutdatedService } from "./OpenCode2Service.ts"; | ||
|
|
||
| const service = vi.hoisted(() => ({ discover: vi.fn(), stop: vi.fn(), ensure: vi.fn() })); | ||
| vi.mock("@opencode/client/effect/service", () => ({ Service: service })); | ||
|
|
||
| const runtimeWithBinaryVersion = (stdout: string) => | ||
| ({ | ||
| runOpenCodeCommand: () => Effect.succeed({ stdout, stderr: "", code: 0 }), | ||
| }) as unknown as OpenCodeRuntime.OpenCodeRuntime["Service"]; | ||
|
|
||
| it.layer(NodeServices.layer)("replaceOutdatedService", (it) => { | ||
| it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")( | ||
| "replaces only this install's 2.x service, keeping its configured env", | ||
| () => | ||
| Effect.gen(function* () { | ||
| const fileSystem = yield* FileSystem.FileSystem; | ||
| const path = yield* Path.Path; | ||
| const home = yield* fileSystem.makeTempDirectoryScoped(); | ||
| const binDirectory = path.join(home, "bin"); | ||
| yield* fileSystem.makeDirectory(binDirectory); | ||
| yield* fileSystem.writeFileString(path.join(binDirectory, "opencode"), ""); | ||
| yield* fileSystem.chmod(path.join(binDirectory, "opencode"), 0o755); | ||
| const environment = { | ||
| HOME: home, | ||
| PATH: binDirectory, | ||
| OPENCODE_CONFIG_DIR: home, | ||
| ELECTRON_RUN_AS_NODE: "1", | ||
| }; | ||
| yield* fileSystem.writeFileString( | ||
| path.join(home, "service.json"), | ||
| JSON.stringify({ env: { PATH: "/nowhere", XDG_STATE_HOME: "/elsewhere" } }), | ||
| ); | ||
| const file = path.join(home, ".local", "state", "opencode", "service.json"); | ||
| const run = (binary: string, serverUrl = "http://127.0.0.1:49374") => | ||
| replaceOutdatedService({ | ||
| binaryPath: "opencode", | ||
| serverUrl, | ||
| environment, | ||
| }).pipe( | ||
| Effect.provideService( | ||
| OpenCodeRuntime.OpenCodeRuntime, | ||
| runtimeWithBinaryVersion(binary), | ||
| ), | ||
| ); | ||
| service.stop.mockReturnValue(Effect.void); | ||
| service.ensure.mockReturnValue(Effect.void); | ||
| const outdated = (options: { readonly version?: string }) => | ||
| Effect.succeed( | ||
| options.version === undefined ? { url: "http://0.0.0.0:49374" } : undefined, | ||
| ); | ||
|
|
||
| service.discover.mockImplementation(outdated); | ||
| yield* run("opencode v1.18.32"); | ||
| expect(service.discover).not.toHaveBeenCalled(); | ||
|
|
||
| for (const elsewhere of [ | ||
| "http://192.168.1.5:49374", | ||
| "http://127.0.0.1:49999", | ||
| "http://[::1]:49374", | ||
| "http://localhost:49374", | ||
| ]) { | ||
| yield* run("opencode v2.2.5", elsewhere); | ||
| } | ||
| expect(service.discover).toHaveBeenCalledWith({ file }); | ||
| service.discover.mockReturnValue(Effect.succeed({ url: "http://0.0.0.0" })); | ||
| yield* run("opencode v2.2.5", "https://127.0.0.1"); | ||
| expect(service.ensure).not.toHaveBeenCalled(); | ||
|
|
||
| service.discover.mockReturnValue(Effect.undefined); | ||
| yield* run("opencode v2.2.5"); | ||
| expect(service.ensure).not.toHaveBeenCalled(); | ||
|
|
||
| service.discover.mockReturnValue(Effect.succeed({ url: "http://0.0.0.0:49374" })); | ||
| yield* run("opencode v2.2.5"); | ||
| expect(service.stop).not.toHaveBeenCalled(); | ||
|
|
||
| service.discover.mockImplementation(outdated); | ||
| yield* run("opencode v2.2.5"); | ||
| expect(service.stop).toHaveBeenCalledWith({ file, pty: "handoff" }); | ||
| expect(service.ensure).toHaveBeenCalledWith({ | ||
| file, | ||
| command: [path.join(binDirectory, "opencode"), "serve", "--service"], | ||
| env: { ...environment, PATH: "/nowhere", ELECTRON_RUN_AS_NODE: undefined }, | ||
| }); | ||
| }).pipe(Effect.scoped), | ||
| ); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.