refactor(settings): provider facts as data
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
#181: ModelProvider is the provider-descriptor table — label, effort ladder, flagship, endpoint, env var joined by wire dialect (chat/models paths + the SSE decoder selector), auth mode (Bearer vs Anthropic's header pair), keyless (nous rides the Portal login), and the ONE trailing-slash endpoint trim. The probe's URL builders, auth headers, and stream-decoder picks select by data; the per-dialect bodies and decoders stay separate functions, not switch clothing. ProviderCredential.resolve is the ONE credential rail (provider key, else the shared Portal session key for keyless providers — official endpoint ONLY, never a user-set URL). Settings' Test Connection and the new PassReadiness module both call it; the twice-implemented #175 fallback can no longer drift. One deliberate tightening, reviewer- blessed: a nous pass profile on a custom base_url with no pasted key now reads missingKey where the old session-model fallback said ready — the old copy had no endpoint gate at all. Pass readiness leaves the session model (PassReadiness.swift maps each pass surface to ready/missingKey/unknown over the descriptor; MentorSessionModel stores the verdicts and reads no keys or auth files). runPass and blindRead run their guards through one shared rail (guardOpenPieceRun) — identical refusal strings, blockers named honestly. No app-side model-settings store (ADR-0014 red line). Rider: the #179 mid-pass repoint pin polls the rig's hasHeldPrompt before releasing the held turn — runningPass flips before the one-shot engine parks its prompt, so firing into that window false-failed under parallel-suite load. Full suite 668/668 (xcresult executed count). Finish-audit: three reviewers (ponytail/security/general), zero findings above LOW; two ponytail trims and one pin tightening applied. Closes #181
This commit is contained in:
1 parent
218e2db397
commit
f49e4b6ca0
15 files changed
+506
-184
No files matched your search
@@ -39,12 +39,12 @@ Conventions every suite follows. Per-suite pin inventories are NOT kept here —
|
||||
- `MicropubTests`, `MicropubModelTests`, `MicropubMediaTests` — publish wire contract, model flow, media/illustration surface.
|
||||
- `MCPToolsTests`, `MCPServerWireTests`, `MCPToolsPromoteTests`, `ToolPayloadsTests`, `LearningsPaneTests`, `LearningDecayTests` — museion-tools store, wire, promote, tool-payload decoder shapes (strict + lenient, #177), learnings pane, decay.
|
||||
- `FixCardApplyTests` — fix-card apply/skip/done lifecycle.
|
||||
- `PostsModelTests`, `PassRunTests`, `BlindReadTests`, `EngineLifecycleTests`, `SessionLifecycleTests`, `SessionScopeTests`, `TranscriptRailTests` — model orchestration over the scripted in-process engine (#178): passes, blind read, per-surface engines, session lifecycle, scoped hosting, the typed transcript rail (#177 — speaker/notice type facts through the scripted engine, prefix-free invariant, append-seam classifiers), and the #179 write-rail pins in PostsModelTests (write → one library refresh + strip cleared; failed write owns the strip; nil-Home refuses cleanly; import batch keeps per-file strip messages; mid-pass Home repoint refuses the advance — `endHeldPrompt` is the rig hook that ends a held turn normally).
|
||||
- `PostsModelTests`, `PassRunTests`, `BlindReadTests`, `EngineLifecycleTests`, `SessionLifecycleTests`, `SessionScopeTests`, `TranscriptRailTests` — model orchestration over the scripted in-process engine (#178): passes, blind read, per-surface engines, session lifecycle, scoped hosting, the typed transcript rail (#177 — speaker/notice type facts through the scripted engine, prefix-free invariant, append-seam classifiers), and the #179 write-rail pins in PostsModelTests (write → one library refresh + strip cleared; failed write owns the strip; nil-Home refuses cleanly; import batch keeps per-file strip messages; mid-pass Home repoint refuses the advance — `endHeldPrompt` is the rig hook that ends a held turn normally, polled to via `hasHeldPrompt` first: `runningPass` flips before the one-shot engine parks its prompt, so firing into that window false-fails under load).
|
||||
- `DeslopLintTests` (with the `DeslopLintWiringTests` member) — native lint findings, config story, emit loop.
|
||||
- `EditorSessionTests`, `ReadingPresenterTests`, `ProsePresenterTests`, `FocusModeTests`, `ImportExternalTests`, `ImageIngestTests` — editor session, reading pipeline, editing-surface parity, focus math, import + image ingest.
|
||||
- `OutlineTreeTests`, `OutlinePresenterTests`, `OutlineDragTests`, `EscEventProbeTests` — outliner model, projection, drag plumbing, Esc delivery probe.
|
||||
- `ProseListTests`, `ProseRekeyTests` — prose list model + fold rendering, fold rekey pipeline.
|
||||
- `SettingsModelTests`, `SettingsModelWritePathTests`, `HermesSettingsWriterTests`, `ProviderProbeTests`, `ProviderProbeTransportTests` — settings model, real CLI write path, probe decode + request builders.
|
||||
- `SettingsModelTests`, `SettingsModelWritePathTests`, `HermesSettingsWriterTests`, `ProviderProbeTests`, `ProviderProbeTransportTests`, `ProviderCredentialTests` — settings model, real CLI write path, probe decode + request builders, the #181 ONE credential resolution (pasted key wins, keyless fallback on the official endpoint, custom-endpoint and no-login refusals).
|
||||
- `WordBoundaryTruncationTests`, `PolishSeamTests`, `ResearchCandidateTests`, `PersonaLoadOrderTests` — UI pure seams, research candidates, persona payload contract (the four-shared-sections + load-order pins).
|
||||
|
||||
## Verification
|
||||
|
||||
@@ -110,7 +110,7 @@ func textRows(of model: MentorSessionModel) -> [String] {
|
||||
|
||||
await model.runPass(.pass1, mentor: mentor)
|
||||
|
||||
#expect(model.lastError?.contains("post") == true)
|
||||
#expect(model.lastError == "Open a saved post to run a pass.")
|
||||
// Nothing landed on disk — the draft never even materialized a folder.
|
||||
#expect(!FileManager.default.fileExists(atPath: home.appendingPathComponent("projects/posts").path))
|
||||
}
|
||||
|
||||
@@ -581,9 +581,13 @@ struct PostsModelWriteRailTests {
|
||||
try FileManager.default.createDirectory(at: homeB, withIntermediateDirectories: true)
|
||||
rig.model.bind(home: homeB) // the Settings repoint, mid-pass
|
||||
// Release the held turn as a NORMALLY ended one — .ended + no refusal.
|
||||
// #require: nothing held means the parked prompt already timed out
|
||||
// under machine load — fail loudly, not on a confusing nil strip.
|
||||
// Poll for the PARK first: runningPass flips before the one-shot
|
||||
// engine spawns, so ending the hold in that window false-fails
|
||||
// under load (the #30/#147 flake family). #require afterwards:
|
||||
// nothing held after the poll means the parked prompt hit its
|
||||
// deadline — fail loudly, not on a confusing nil strip.
|
||||
let engine = try #require(rig.mentor.host.oneShot as? ScriptedEngine)
|
||||
try await pollUntil { engine.hasHeldPrompt }
|
||||
try #require(engine.endHeldPrompt())
|
||||
await run.value
|
||||
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
//
|
||||
// ProviderCredentialTests.swift
|
||||
// MuseionTests
|
||||
//
|
||||
|
||||
// ## Scenario: one credential resolution behind probe and readiness
|
||||
// From #181
|
||||
//
|
||||
// Given a provider, its `.env` key (possibly empty), and the endpoint the
|
||||
// key would ride
|
||||
// When the ONE credential resolution runs — Settings' Test Connection and
|
||||
// pass readiness both call it
|
||||
// Then a pasted key always wins, a keyless provider on its official
|
||||
// endpoint borrows the shared Portal session key, and every other empty
|
||||
// case refuses honestly — the implicit session credential never rides a
|
||||
// user-set URL.
|
||||
|
||||
import Foundation
|
||||
@testable import Museion
|
||||
import Testing
|
||||
|
||||
@Suite("Provider credential resolution")
|
||||
struct ProviderCredentialTests {
|
||||
/// Writes a portal auth store carrying `agent_key` and answers its path.
|
||||
private func makeAuthFile(key: String) throws -> String {
|
||||
let dir = FileManager.default.temporaryDirectory
|
||||
.appendingPathComponent("cred-\(UUID().uuidString)")
|
||||
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
|
||||
let path = dir.appendingPathComponent("auth.json").path
|
||||
try #"{"providers":{"nous":{"agent_key":"\#(key)"}}}"#.write(toFile: path, atomically: true, encoding: .utf8)
|
||||
return path
|
||||
}
|
||||
|
||||
/// A pasted key always wins — no provider's resolution touches the
|
||||
/// Portal auth store when its own key is set.
|
||||
@Test func `pasted key wins for every provider`() async {
|
||||
let missingAuth = FileManager.default.temporaryDirectory
|
||||
.appendingPathComponent("cred-missing-\(UUID().uuidString)").path
|
||||
for provider in ModelProvider.allCases {
|
||||
let resolved = await ProviderCredential.resolve(
|
||||
provider: provider,
|
||||
envKey: "sk-pasted",
|
||||
endpoint: provider.defaultEndpoint,
|
||||
portalAuthPath: missingAuth,
|
||||
)
|
||||
#expect(resolved == .key("sk-pasted"))
|
||||
}
|
||||
}
|
||||
|
||||
/// A keyed provider with no key refuses the paste path — the probe's
|
||||
/// old empty-key precondition, now the shared rail's.
|
||||
@Test func `keyed provider without a key refuses the paste path`() async {
|
||||
let resolved = await ProviderCredential.resolve(
|
||||
provider: .anthropic,
|
||||
envKey: "",
|
||||
endpoint: ModelProvider.anthropic.defaultEndpoint,
|
||||
portalAuthPath: "/nonexistent/auth.json",
|
||||
)
|
||||
guard case let .refused(message) = resolved else {
|
||||
Issue.record("expected a refusal, got \(resolved)")
|
||||
return
|
||||
}
|
||||
#expect(message == "no API key set — paste the key first")
|
||||
}
|
||||
|
||||
/// The keyless fallback: nous on the official endpoint (trailing slash
|
||||
/// tolerated) borrows the session's agent_key.
|
||||
@Test func `keyless provider borrows the portal session key on the official endpoint`() async throws {
|
||||
let authPath = try makeAuthFile(key: "ak-shared-123")
|
||||
for endpoint in [
|
||||
ModelProvider.nous.defaultEndpoint,
|
||||
ModelProvider.nous.defaultEndpoint + "/",
|
||||
] {
|
||||
let resolved = await ProviderCredential.resolve(
|
||||
provider: .nous,
|
||||
envKey: "",
|
||||
endpoint: endpoint,
|
||||
portalAuthPath: authPath,
|
||||
)
|
||||
#expect(resolved == .key("ak-shared-123"))
|
||||
}
|
||||
}
|
||||
|
||||
/// Finish-audit #175, on the shared rail: the implicit session
|
||||
/// credential never rides a user-set URL — a custom endpoint with an
|
||||
/// empty key refuses even though the login exists.
|
||||
@Test func `the session key never rides a custom endpoint`() async throws {
|
||||
let authPath = try makeAuthFile(key: "ak-shared-123")
|
||||
let resolved = await ProviderCredential.resolve(
|
||||
provider: .nous,
|
||||
envKey: "",
|
||||
endpoint: "http://proxy.example/v1",
|
||||
portalAuthPath: authPath,
|
||||
)
|
||||
guard case let .refused(message) = resolved else {
|
||||
Issue.record("expected the custom-endpoint refusal, got \(resolved)")
|
||||
return
|
||||
}
|
||||
#expect(message.contains("paste an API key"))
|
||||
}
|
||||
|
||||
/// Keyless with neither key nor login names the portal login path,
|
||||
/// not a bare "no key".
|
||||
@Test func `keyless without key or login names the portal path`() async {
|
||||
let resolved = await ProviderCredential.resolve(
|
||||
provider: .nous,
|
||||
envKey: "",
|
||||
endpoint: ModelProvider.nous.defaultEndpoint,
|
||||
portalAuthPath: "/nonexistent/auth.json",
|
||||
)
|
||||
guard case let .refused(message) = resolved else {
|
||||
Issue.record("expected a refusal, got \(resolved)")
|
||||
return
|
||||
}
|
||||
#expect(message.contains("hermes auth add nous"))
|
||||
}
|
||||
}
|
||||
@@ -157,6 +157,14 @@ final class ScriptedEngine: EngineTransport, @unchecked Sendable {
|
||||
queue.sync { heldLoad != nil }
|
||||
}
|
||||
|
||||
/// True while a hangOnPrompt prompt is parked — the #179 repoint pin
|
||||
/// polls for the PARK (runningPass flips before the one-shot engine
|
||||
/// even spawns; ending the hold in that window false-fails under load,
|
||||
/// the #30/#147 flake family).
|
||||
var hasHeldPrompt: Bool {
|
||||
queue.sync { heldPromptID != nil }
|
||||
}
|
||||
|
||||
// MARK: EngineTransport
|
||||
|
||||
/// The fake always spawns cleanly — there is no process.
|
||||
|
||||
Reference in new issue
Block a user