feat(settings): add Nous Portal provider (#175)
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
Settings gains hermes' `nous` slug as a fourth provider on every surface and the Provider Keys page — endpoint https://inference-api.nousresearch.com/v1, NOUS_API_KEY, the 5-level OpenAI-compatible effort ladder, switch flagship anthropic/claude-sonnet-5 (live-probed: the portal's docs-listed Hermes-4 ids 404 — the inference API serves the OpenRouter catalog, so the switch keeps the app's sonnet posture billed through Nous). The probe speaks plain OpenAI chat-completions; an unkeyed test borrows the shared Portal session's agent_key (the engine's own credential — hermes' nous runtime is OAuth-only, and a portal key and subscription bill the same account credits), gated to the official https endpoint so the implicit credential never rides a user-edited URL. Pass readiness rides the same fallback, so a logged-in machine runs passes with no key. Suite 635. Closes #175
This commit is contained in:
1 parent
d305f822aa
commit
b2db859887
15 files changed
+410
-30
No files matched your search
@@ -149,6 +149,103 @@ struct SettingsModelWritePathTests {
|
||||
#expect(model.probeModel(for: .zai) == ModelProvider.zai.switchDefaultModel)
|
||||
}
|
||||
|
||||
// Scenario: Nous Portal as a fourth provider — From user story #175
|
||||
// Given Hermes' own registry offers the `nous` slug (OpenAI-compatible
|
||||
// inference API — one account bill behind key and subscription alike)
|
||||
// When Settings offers Nous Portal
|
||||
// Then the pinned facts match the live-probed wire: the portal inference
|
||||
// endpoint, the env var hermes' tooling maps the slug to, and the label.
|
||||
@Test func `nous provider facts pin the portal wire`() {
|
||||
#expect(ModelProvider.nous.rawValue == "nous")
|
||||
#expect(ModelProvider.nous.label == "Nous Portal")
|
||||
#expect(ModelProvider.nous.defaultEndpoint == "https://inference-api.nousresearch.com/v1")
|
||||
#expect(ModelProvider.nous.envVarName == "NOUS_API_KEY")
|
||||
}
|
||||
|
||||
// Scenario: Test Connection on an unkeyed Nous Portal — From user story #175
|
||||
// Given hermes logged into the Nous Portal (the shared auth.json session —
|
||||
// the engine's own credential; API key and subscription bill the same
|
||||
// account credits)
|
||||
// When the user tests Nous with no key pasted
|
||||
// Then the probe borrows the session's agent_key as its Bearer — and with
|
||||
// no session either, it names the portal login path, not a bare "no key".
|
||||
@Test @MainActor func `nous connection borrows the shared portal session key`() async throws {
|
||||
final class AuthSaw: @unchecked Sendable { var header: String? }
|
||||
let saw = AuthSaw()
|
||||
let dir = FileManager.default.temporaryDirectory.appendingPathComponent("nous-auth-\(UUID().uuidString)")
|
||||
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
|
||||
let authPath = dir.appendingPathComponent("auth.json").path
|
||||
try #"{"providers":{"nous":{"agent_key":"ak-shared-123"}}}"#.write(toFile: authPath, atomically: true, encoding: .utf8)
|
||||
|
||||
let model = SettingsModel(
|
||||
registry: liveShapedRegistry(),
|
||||
writer: RecordingWriter(),
|
||||
writeDebounce: 0,
|
||||
probeTransport: { request in
|
||||
saw.header = request.value(forHTTPHeaderField: "Authorization")
|
||||
if request.url!.path.hasSuffix("/models") {
|
||||
return (probeData(#"{"object":"list","data":[{},{},{},{}]}"#), probeHTTPResponse(200))
|
||||
}
|
||||
return (
|
||||
Data("data: {\"choices\":[{\"delta\":{\"content\":\"Hi\"},\"finish_reason\":\"stop\"}]}\n\n".utf8),
|
||||
probeHTTPResponse(200),
|
||||
)
|
||||
},
|
||||
portalAuthPath: authPath,
|
||||
)
|
||||
await model.testConnection(for: .nous)
|
||||
#expect(saw.header == "Bearer ak-shared-123")
|
||||
guard case let .done(outcome) = model.testStates[.nous], case .works = outcome else {
|
||||
Issue.record("expected works over the session key, got \(String(describing: model.testStates[.nous]))")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
/// Finish-audit #175: the implicit session credential never rides a
|
||||
/// hand-edited endpoint — a custom endpoint with an empty key refuses
|
||||
/// before any network, pointing at the key field.
|
||||
@Test @MainActor func `nous session key never rides a custom endpoint`() async throws {
|
||||
let dir = FileManager.default.temporaryDirectory.appendingPathComponent("nous-gate-\(UUID().uuidString)")
|
||||
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
|
||||
let authPath = dir.appendingPathComponent("auth.json").path
|
||||
try #"{"providers":{"nous":{"agent_key":"ak-shared-123"}}}"#.write(toFile: authPath, atomically: true, encoding: .utf8)
|
||||
|
||||
let model = SettingsModel(
|
||||
registry: liveShapedRegistry(),
|
||||
writer: RecordingWriter(),
|
||||
writeDebounce: 0,
|
||||
probeTransport: { _ in
|
||||
Issue.record("a custom endpoint must never receive the session key")
|
||||
throw URLError(.badURL)
|
||||
},
|
||||
portalAuthPath: authPath,
|
||||
)
|
||||
model.setEndpoint("http://proxy.example/v1", for: .nous)
|
||||
await model.testConnection(for: .nous)
|
||||
guard case let .done(outcome) = model.testStates[.nous], case let .authFailed(detail) = outcome else {
|
||||
Issue.record("expected the custom-endpoint refusal, got \(String(describing: model.testStates[.nous]))")
|
||||
return
|
||||
}
|
||||
#expect(detail.contains("paste an API key"))
|
||||
}
|
||||
|
||||
@Test @MainActor func `nous connection with no key and no login names the portal path`() async {
|
||||
let missing = FileManager.default.temporaryDirectory
|
||||
.appendingPathComponent("nous-auth-missing-\(UUID().uuidString)").path
|
||||
let model = SettingsModel(
|
||||
registry: liveShapedRegistry(),
|
||||
writer: RecordingWriter(),
|
||||
writeDebounce: 0,
|
||||
portalAuthPath: missing,
|
||||
)
|
||||
await model.testConnection(for: .nous)
|
||||
guard case let .done(outcome) = model.testStates[.nous], case let .authFailed(detail) = outcome else {
|
||||
Issue.record("expected authFailed, got \(String(describing: model.testStates[.nous]))")
|
||||
return
|
||||
}
|
||||
#expect(detail.contains("hermes auth add nous"))
|
||||
}
|
||||
|
||||
// Scenario: Saving a Chat model change reaches the resident engine
|
||||
// From user story #137 acceptance 2
|
||||
// Given the Settings pane is open
|
||||
|
||||
Reference in new issue
Block a user