Repository navigation
refactor(forgekeeper): derive RPC types, type GraphQL responses, and gate tests on events - #94
Merged
Merged
Conversation
OpenCode types the values of JSON Schema RPC definitions as `unknown`, so the server and the CLI each cast them to a hand-written shape that nothing tied to the schemas. Derive the input, output, and event types from the schemas with json-schema-to-ts, a type-only dev dependency that adds nothing to the bundles. Handlers now receive typed input through one adapter, and the CLI casts to the derived types. Describe `statuses` and the snapshots as snapshots, and close the output and event schemas with additionalProperties, so they match what the server sends.
GitLab's GraphQL transport returned `Record<string, any>`, and GitHub's returned `Record<string, unknown>`, so each call site cast the response to the shape it expected, or relied on `any`. Pair each query with the shape of the `data` it selects. The transports return `unknown`, because they can only vouch that the response parsed, and one adapter applies the query's shape. Call sites then read typed results without casts, and the `any` is gone.
Tests of ordering, concurrency, and cancellation held work in flight with real timers: `Bun.sleep(1)` and `setTimeout(1)`, plus a settle helper that slept five times. They passed because the timers were usually long enough, not because anything told them the work had finished. Hold that work on promises that the test settles, and wait for the condition each test checks with `until`, which counts turns of the event loop instead of milliseconds. The ordering test now asserts the whole order, including the task that arrives during a handoff. Where a test only needs queued promise reactions to run, `flush` names that, in place of `Bun.sleep(0)`.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do and why?
Follow-ups from the forgekeeper review. No behavior changes, apart from stricter RPC schemas.
json-schema-to-ts, a type-only dev dependency, so the schemas are the single description of the contract.data. The transports returnunknown, and one adapter applies the shape, which removes theany.until, instead of real timers.The RPC output and event schemas now set
additionalProperties: false, so the host rejects fields the server never sends.How to set up and validate locally
mise run typecheck && mise run test && mise run lintmise run build forgekeeper, then point anopencode.jsonplugin entry atpackages/forgekeeper/dist.target,watch,refresh, andreleaseanswer under/api/rpc/opencode-forgekeeper/.Because the commits are
refactorandtest, release-please opens no release for them.