Compare commits
9 Commits
v0.0.1.alp
...
2cbc6adebc
| Author | SHA1 | Date | |
|---|---|---|---|
| 2cbc6adebc | |||
| f1e2f0c03f | |||
| 19f31a87fb | |||
|
|
425e423753 | ||
| 1d900af7bc | |||
| 5379aa0847 | |||
| 84442fd28e | |||
|
|
22e3127e90 | ||
| ef9f7e44dd |
9
.github/workflows/release.yml
vendored
9
.github/workflows/release.yml
vendored
@@ -7,17 +7,18 @@ on:
|
||||
|
||||
jobs:
|
||||
push:
|
||||
if: ${{ github.server_url == 'https://github.com' }}
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
id-token: write
|
||||
environment: release
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: ruby/setup-ruby@v1
|
||||
- uses: ruby/setup-ruby@003a5c4d8d6321bd302e38f6f0ec593f77f06600 # v1.319.0
|
||||
with:
|
||||
ruby-version: ruby
|
||||
ruby-version: "4.0"
|
||||
bundler-cache: true
|
||||
- uses: rubygems/release-gem@v1
|
||||
- uses: rubygems/release-gem@052cc82692552de3ef2b81fd670e41d13cba8092 # v1.4.0
|
||||
|
||||
6
.github/workflows/test.yml
vendored
6
.github/workflows/test.yml
vendored
@@ -12,12 +12,12 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
ruby: ["3.2", "3.3", "3.4"]
|
||||
ruby: ["3.2", "3.3", "3.4", "4.0"]
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
|
||||
|
||||
- name: Set up Ruby ${{ matrix.ruby }}
|
||||
uses: ruby/setup-ruby@v1
|
||||
uses: ruby/setup-ruby@003a5c4d8d6321bd302e38f6f0ec593f77f06600 # v1.319.0
|
||||
with:
|
||||
ruby-version: ${{ matrix.ruby }}
|
||||
bundler-cache: true
|
||||
|
||||
@@ -100,5 +100,7 @@ First public alpha. HTTP + SSE client for OpenCode REST API.
|
||||
### Compatibility
|
||||
|
||||
- Ruby ≥ 3.2
|
||||
- OpenCode server ≥ 1.15 (tested against the message bus schema in `packages/opencode/src/session/message-v2.ts`)
|
||||
- OpenCode targeted the then-current 1.15 message-bus shape. This historical
|
||||
target was not a blanket SemVer compatibility guarantee; use the README's
|
||||
current compatibility evidence for deployment decisions.
|
||||
- Runtime dependency: `activesupport (>= 6.1)` for `blank?`/`present?`/`presence`/`truncate`/`duplicable?`/`megabytes`. ActiveSupport is *not* Rails — it's a standalone helpers gem.
|
||||
|
||||
42
README.md
42
README.md
@@ -67,7 +67,9 @@ child = client.create_session(
|
||||
|
||||
Model strings use OpenCode's `provider/model` form; a preformatted model hash
|
||||
with `providerID` and `id` keys is also accepted. These configured-session
|
||||
fields require OpenCode 1.16.1 or newer.
|
||||
fields first appeared in OpenCode 1.16.1. That is an API-introduction note,
|
||||
not evidence that every later server is compatible; use the
|
||||
[certified compatibility evidence](#compatibility) for deployment choices.
|
||||
|
||||
### Streaming (the headline)
|
||||
|
||||
@@ -106,8 +108,9 @@ client.update_session(session_id, permissions: permission_rules)
|
||||
|
||||
OpenCode appends PATCHed permission rules and evaluates the last matching
|
||||
rule. Hosts should send a complete ordered policy and fingerprint it so the
|
||||
same policy is not appended on every turn. This endpoint requires OpenCode
|
||||
1.16.1 or newer; the rest of the client remains compatible with 1.15.
|
||||
same policy is not appended on every turn. This endpoint first appeared in
|
||||
OpenCode 1.16.1; that version floor describes endpoint availability, not
|
||||
compatibility with every later server.
|
||||
|
||||
### Lower-level event firehose
|
||||
|
||||
@@ -199,9 +202,29 @@ Want every OpenCode endpoint auto-generated from the OpenAPI spec? Use [`opencod
|
||||
## Compatibility
|
||||
|
||||
- Ruby ≥ 3.2
|
||||
- OpenCode server ≥ 1.15
|
||||
- Runtime dependency: `activesupport (>= 6.1)` — *not* Rails. ActiveSupport is a standalone helpers gem (`blank?`, `present?`, `presence`, `truncate`, etc.).
|
||||
|
||||
OpenCode server compatibility is evidence-based, not an open-ended SemVer
|
||||
promise. OpenCode's HTTP, SSE, and runtime behavior can change independently
|
||||
of a numeric version floor, so this gem does not infer compatibility from a
|
||||
constraint such as `>= 1.15`.
|
||||
|
||||
Use the [OpenCode compatibility corpus](https://github.com/ajaynomics/opencode-compat)
|
||||
as the source of current evidence. Its
|
||||
[image matrix](https://github.com/ajaynomics/opencode-compat/blob/main/manifests/image-matrix.json)
|
||||
records the exact gem commit and immutable OpenCode OCI digest exercised by
|
||||
the `ruby-rest-sse` profile. Its
|
||||
[runtime tuples](https://github.com/ajaynomics/opencode-compat/blob/main/manifests/runtime-tuples.json)
|
||||
add the exact consumer commit and canary evidence needed for promotion and
|
||||
rollback. A version label or image tag is provenance only, never the execution
|
||||
coordinate.
|
||||
|
||||
A combination absent from passing evidence is **unverified**, not necessarily
|
||||
incompatible. Run the corpus against the exact gem, image digest, and consumer
|
||||
commit before adopting or promoting it. See the
|
||||
[certification policy](https://github.com/ajaynomics/opencode-compat/blob/main/docs/certification.md)
|
||||
for the full process.
|
||||
|
||||
## Development
|
||||
|
||||
```sh
|
||||
@@ -213,10 +236,13 @@ The smoke suite covers Client end-to-end against WebMock-stubbed OpenCode
|
||||
endpoints, including subscription-before-prompt ordering and
|
||||
reconnect-without-repost.
|
||||
|
||||
Releases use RubyGems trusted publishing. After the repository's
|
||||
`release.yml` workflow is registered as a trusted publisher with the `release`
|
||||
environment, pushing a `v*` tag builds, attests, and publishes the gem without
|
||||
a long-lived RubyGems API key.
|
||||
The repository contains a tag-triggered `release.yml` workflow intended for
|
||||
RubyGems trusted publishing, but its RubyGems trusted-publisher registration is
|
||||
not configured as of `0.0.1.alpha7`; that release was published manually. A
|
||||
`v*` tag push therefore does not currently guarantee publication. Before a
|
||||
future release, verify the RubyGems registry result explicitly. Once the
|
||||
workflow is registered as a trusted publisher for the `release` environment,
|
||||
it can build, attest, and publish without a long-lived RubyGems API key.
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -126,6 +126,57 @@ class SmokeTest < Minitest::Test
|
||||
assert_equal({}, response)
|
||||
end
|
||||
|
||||
def test_send_message_async_serializes_a_structured_child_prompt
|
||||
schema = {
|
||||
type: "object",
|
||||
properties: {
|
||||
requirement_suggestions: {
|
||||
type: "array",
|
||||
items: { type: "string" }
|
||||
}
|
||||
},
|
||||
required: [ "requirement_suggestions" ],
|
||||
additionalProperties: false
|
||||
}
|
||||
invocation_query =
|
||||
"Complete the bounded structured request from the preloaded worker skill and immutable Rails context."
|
||||
expected_body = {
|
||||
messageID: "msg_worker_1",
|
||||
parts: [ { type: "text", text: invocation_query } ],
|
||||
agent: "destination-list-curator",
|
||||
format: {
|
||||
type: "json_schema",
|
||||
schema: schema,
|
||||
retryCount: 0
|
||||
},
|
||||
system: "Immutable Rails context"
|
||||
}
|
||||
serialized_body = nil
|
||||
|
||||
prompt = stub_request(:post, "#{BASE}/session/#{SESSION_ID}/prompt_async")
|
||||
.with(body: expected_body.to_json)
|
||||
.to_return do |request|
|
||||
serialized_body = request.body
|
||||
{ status: 204, body: "" }
|
||||
end
|
||||
|
||||
@client.send_message_async(
|
||||
SESSION_ID,
|
||||
invocation_query,
|
||||
agent: "destination-list-curator",
|
||||
system: "Immutable Rails context",
|
||||
message_id: "msg_worker_1",
|
||||
format: {
|
||||
type: "json_schema",
|
||||
schema: schema,
|
||||
retryCount: 0
|
||||
}
|
||||
)
|
||||
|
||||
assert_equal expected_body.to_json, serialized_body
|
||||
assert_requested prompt, times: 1
|
||||
end
|
||||
|
||||
def test_stream_returns_typed_Reply_Result_with_full_text
|
||||
stub_request(:post, "#{BASE}/session/#{SESSION_ID}/prompt_async")
|
||||
.to_return(status: 204, body: "")
|
||||
|
||||
19
test/readme_contract_test.rb
Normal file
19
test/readme_contract_test.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
|
||||
class ReadmeContractTest < Minitest::Test
|
||||
README = File.read(File.expand_path("../README.md", __dir__))
|
||||
|
||||
def test_server_compatibility_points_to_exact_certification_evidence
|
||||
assert_includes README, "https://github.com/ajaynomics/opencode-compat"
|
||||
assert_includes README, "manifests/image-matrix.json"
|
||||
assert_includes README, "manifests/runtime-tuples.json"
|
||||
refute_match(/OpenCode server\s*(?:>=|≥)\s*\d/, README)
|
||||
end
|
||||
|
||||
def test_release_guidance_does_not_claim_trusted_publishing_is_configured
|
||||
assert_includes README, "not configured as of `0.0.1.alpha7`"
|
||||
assert_includes README, "does not currently guarantee publication"
|
||||
end
|
||||
end
|
||||
38
test/release_workflow_test.rb
Normal file
38
test/release_workflow_test.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "minitest/autorun"
|
||||
require "yaml"
|
||||
|
||||
class ReleaseWorkflowTest < Minitest::Test
|
||||
ROOT = File.expand_path("..", __dir__)
|
||||
WORKFLOW_PATH = File.join(ROOT, ".github", "workflows", "release.yml")
|
||||
SETUP_RUBY_ACTION = "ruby/setup-ruby@003a5c4d8d6321bd302e38f6f0ec593f77f06600"
|
||||
RELEASE_GEM_ACTION = "rubygems/release-gem@052cc82692552de3ef2b81fd670e41d13cba8092"
|
||||
|
||||
def workflow
|
||||
@workflow ||= YAML.safe_load(File.read(WORKFLOW_PATH), aliases: false)
|
||||
end
|
||||
|
||||
def push_job
|
||||
workflow.fetch("jobs").fetch("push")
|
||||
end
|
||||
|
||||
def test_release_job_is_inert_on_non_github_runners
|
||||
assert_equal "${{ github.server_url == 'https://github.com' }}", push_job.fetch("if")
|
||||
end
|
||||
|
||||
def test_release_job_keeps_the_trusted_publisher_boundary
|
||||
assert_equal "release", push_job.fetch("environment")
|
||||
assert_equal(
|
||||
{ "contents" => "write", "id-token" => "write" },
|
||||
push_job.fetch("permissions")
|
||||
)
|
||||
|
||||
steps = push_job.fetch("steps")
|
||||
setup_ruby = steps.find { |step| step["uses"] == SETUP_RUBY_ACTION }
|
||||
|
||||
assert_equal "4.0", setup_ruby.dig("with", "ruby-version")
|
||||
assert_equal 1, steps.count { |step| step["uses"] == RELEASE_GEM_ACTION }
|
||||
refute steps.any? { |step| step.fetch("run", "").match?(/\bgem\s+push\b/) }
|
||||
end
|
||||
end
|
||||
67
test/workflow_contract_test.rb
Normal file
67
test/workflow_contract_test.rb
Normal file
@@ -0,0 +1,67 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "minitest/autorun"
|
||||
require "yaml"
|
||||
|
||||
class WorkflowContractTest < Minitest::Test
|
||||
ROOT = File.expand_path("..", __dir__)
|
||||
WORKFLOW_DIRECTORY = File.join(ROOT, ".github", "workflows")
|
||||
TEST_WORKFLOW_PATH = File.join(WORKFLOW_DIRECTORY, "test.yml")
|
||||
ACTION_PINS = {
|
||||
"actions/checkout" => "9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0",
|
||||
"ruby/setup-ruby" => "003a5c4d8d6321bd302e38f6f0ec593f77f06600",
|
||||
"rubygems/release-gem" => "052cc82692552de3ef2b81fd670e41d13cba8092"
|
||||
}.freeze
|
||||
|
||||
def test_matrix_covers_every_supported_ruby
|
||||
workflow = YAML.safe_load(File.read(TEST_WORKFLOW_PATH), aliases: false)
|
||||
versions = workflow.dig("jobs", "test", "strategy", "matrix", "ruby")
|
||||
|
||||
assert_equal %w[3.2 3.3 3.4 4.0], versions
|
||||
end
|
||||
|
||||
def test_every_third_party_action_uses_its_reviewed_commit
|
||||
action_uses = Dir[File.join(WORKFLOW_DIRECTORY, "*.{yml,yaml}")].sort.flat_map do |path|
|
||||
workflow = YAML.safe_load(File.read(path), aliases: false)
|
||||
|
||||
workflow_uses(workflow)
|
||||
end
|
||||
|
||||
assert_equal 5, action_uses.length
|
||||
action_uses.each do |action_use|
|
||||
action, separator, revision = action_use.rpartition("@")
|
||||
|
||||
assert_equal "@", separator
|
||||
assert_equal ACTION_PINS.fetch(action), revision
|
||||
assert_match(/\A[0-9a-f]{40}\z/, revision)
|
||||
end
|
||||
end
|
||||
|
||||
def test_action_discovery_only_reads_workflow_action_locations
|
||||
workflow = YAML.safe_load(<<~YAML, aliases: false)
|
||||
jobs:
|
||||
reusable:
|
||||
uses: "owner/workflow@revision"
|
||||
with:
|
||||
uses: ordinary-job-input
|
||||
test:
|
||||
steps:
|
||||
- uses: "owner/action@revision"
|
||||
with:
|
||||
uses: ordinary-step-input
|
||||
YAML
|
||||
|
||||
assert_equal %w[owner/workflow@revision owner/action@revision], workflow_uses(workflow)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def workflow_uses(node)
|
||||
node.fetch("jobs").values.flat_map do |job|
|
||||
action_uses = job.key?("uses") ? [job.fetch("uses")] : []
|
||||
step_uses = job.fetch("steps", []).filter_map { |step| step["uses"] }
|
||||
|
||||
action_uses.concat(step_uses)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user