mirror of
https://github.com/we-promise/sure.git
synced 2026-07-27 20:22:16 +00:00
Revert "Refactor application workflows and update test coverage"
This reverts commit 565e049f89.
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
require "test_helper"
|
||||
|
||||
class Provider::GithubTest < ActiveSupport::TestCase
|
||||
test "release notes cache is scoped to the configured repository" do
|
||||
provider = Provider::Github.new
|
||||
|
||||
Rails.cache.expects(:fetch)
|
||||
.with("latest_github_release_notes/we-promise/sure", expires_in: Provider::Github::CACHE_TTL)
|
||||
.yields
|
||||
.returns(nil)
|
||||
|
||||
provider.client.expects(:releases).with("we-promise/sure").returns([])
|
||||
|
||||
assert_nil provider.fetch_latest_release_notes
|
||||
end
|
||||
end
|
||||
@@ -8,51 +8,6 @@ class Provider::OpenaiTest < ActiveSupport::TestCase
|
||||
@subject_model = "gpt-4.1"
|
||||
end
|
||||
|
||||
test "decodes ChatGPT account ID from OAuth token claims" do
|
||||
token = oauth_token_for("account-123")
|
||||
|
||||
assert_equal "account-123", Provider::Openai.oauth_account_id(token)
|
||||
end
|
||||
|
||||
test "returns nil when OAuth token claims cannot be decoded" do
|
||||
assert_nil Provider::Openai.oauth_account_id("not-a-jwt")
|
||||
end
|
||||
|
||||
test "configures Codex subscription endpoint and headers for OAuth" do
|
||||
provider = Provider::Openai.new(oauth_token_for("account-123"), oauth: true)
|
||||
client = provider.send(:client)
|
||||
|
||||
assert provider.oauth?
|
||||
refute provider.custom_provider?
|
||||
assert provider.supports_responses_endpoint?
|
||||
assert_equal Provider::Openai::CODEX_URI_BASE, client.uri_base
|
||||
assert_equal "account-123", client.extra_headers["ChatGPT-Account-ID"]
|
||||
assert_equal Provider::Openai::CODEX_ORIGINATOR, client.extra_headers["originator"]
|
||||
assert_equal "OpenAI (Codex subscription)", provider.provider_name
|
||||
end
|
||||
|
||||
test "uses explicit account ID for opaque OAuth tokens" do
|
||||
provider = Provider::Openai.new("opaque-token", oauth: true, account_id: "account-456")
|
||||
|
||||
assert_equal "account-456", provider.send(:client).extra_headers["ChatGPT-Account-ID"]
|
||||
end
|
||||
|
||||
test "requires an account ID for opaque OAuth tokens" do
|
||||
error = assert_raises(Provider::Openai::Error) do
|
||||
Provider::Openai.new("opaque-token", oauth: true)
|
||||
end
|
||||
|
||||
assert_match(/ChatGPT account ID is required/, error.message)
|
||||
end
|
||||
|
||||
test "uses Codex default model when OAuth is configured" do
|
||||
ClimateControl.modify("OPENAI_OAUTH_TOKEN" => oauth_token_for("account-123"), "OPENAI_MODEL" => nil) do
|
||||
Setting.stubs(:openai_model).returns(nil)
|
||||
|
||||
assert_equal Provider::Openai::CODEX_DEFAULT_MODEL, Provider::Openai.effective_model
|
||||
end
|
||||
end
|
||||
|
||||
test "openai errors are automatically raised" do
|
||||
VCR.use_cassette("openai/chat/error") do
|
||||
response = @openai.chat_response("Test", model: "invalid-model-that-will-trigger-api-error")
|
||||
@@ -549,14 +504,4 @@ class Provider::OpenaiTest < ActiveSupport::TestCase
|
||||
config.build_input(prompt: "hi", messages: [ { role: "user", content: "old" } ])
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def oauth_token_for(account_id)
|
||||
header = Base64.urlsafe_encode64({ alg: "none", typ: "JWT" }.to_json, padding: false)
|
||||
payload = Base64.urlsafe_encode64({
|
||||
"https://api.openai.com/auth" => { "chatgpt_account_id" => account_id }
|
||||
}.to_json, padding: false)
|
||||
"#{header}.#{payload}.signature"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,12 +5,10 @@ class Provider::RegistryTest < ActiveSupport::TestCase
|
||||
# Ensure no LLM provider is configured
|
||||
ClimateControl.modify(
|
||||
"OPENAI_ACCESS_TOKEN" => nil,
|
||||
"OPENAI_OAUTH_TOKEN" => nil,
|
||||
"ANTHROPIC_ACCESS_TOKEN" => nil,
|
||||
"ANTHROPIC_API_KEY" => nil
|
||||
) do
|
||||
Setting.stubs(:openai_access_token).returns(nil)
|
||||
Setting.stubs(:openai_oauth_token).returns(nil)
|
||||
Setting.stubs(:anthropic_access_token).returns(nil)
|
||||
|
||||
registry = Provider::Registry.for_concept(:llm)
|
||||
@@ -42,9 +40,8 @@ class Provider::RegistryTest < ActiveSupport::TestCase
|
||||
|
||||
test "get_provider returns nil when provider not configured" do
|
||||
# Ensure OpenAI is not configured
|
||||
ClimateControl.modify("OPENAI_ACCESS_TOKEN" => nil, "OPENAI_OAUTH_TOKEN" => nil) do
|
||||
ClimateControl.modify("OPENAI_ACCESS_TOKEN" => nil) do
|
||||
Setting.stubs(:openai_access_token).returns(nil)
|
||||
Setting.stubs(:openai_oauth_token).returns(nil)
|
||||
|
||||
registry = Provider::Registry.for_concept(:llm)
|
||||
|
||||
@@ -96,12 +93,10 @@ class Provider::RegistryTest < ActiveSupport::TestCase
|
||||
# Use stub_env helper which properly stubs ENV access
|
||||
ClimateControl.modify(
|
||||
"OPENAI_ACCESS_TOKEN" => "",
|
||||
"OPENAI_OAUTH_TOKEN" => "",
|
||||
"OPENAI_URI_BASE" => "",
|
||||
"OPENAI_MODEL" => ""
|
||||
) do
|
||||
Setting.stubs(:openai_access_token).returns("test-token-from-setting")
|
||||
Setting.stubs(:openai_oauth_token).returns(nil)
|
||||
Setting.stubs(:openai_uri_base).returns(nil)
|
||||
Setting.stubs(:openai_model).returns(nil)
|
||||
|
||||
@@ -113,22 +108,6 @@ class Provider::RegistryTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
test "openai provider uses Codex OAuth credentials when configured" do
|
||||
ClimateControl.modify(
|
||||
"OPENAI_OAUTH_TOKEN" => "oauth-token",
|
||||
"OPENAI_ACCOUNT_ID" => "account-123",
|
||||
"OPENAI_ACCESS_TOKEN" => "api-key",
|
||||
"OPENAI_MODEL" => "gpt-5.6"
|
||||
) do
|
||||
provider = Provider::Registry.get_provider(:openai)
|
||||
|
||||
assert provider.oauth?
|
||||
assert_equal "account-123", provider.send(:client).extra_headers["ChatGPT-Account-ID"]
|
||||
assert_equal Provider::Openai::CODEX_URI_BASE, provider.send(:client).uri_base
|
||||
end
|
||||
end
|
||||
|
||||
test "preferred_llm_provider returns openai by default" do
|
||||
openai = mock("openai")
|
||||
Provider::Registry.stubs(:openai).returns(openai)
|
||||
|
||||
Reference in New Issue
Block a user