claude-connector: an old document is refused at load, the installer authors it again

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-29 18:18:23 +01:00
commit b0ac65edde
3 changed files with 7 additions and 8 deletions

View file

@ -11,10 +11,9 @@ pub(crate) const PROVIDER: &str = "claude-code";
/// connector; the credential itself is the systemd credential
/// [`ClaudeCodeConfig::token_credential`] names, and it reaches the child on a
/// pipe whichever this is.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ClaudeAuth {
/// The subscription's OAuth token. The plan's usage is metered.
#[default]
OAuthToken,
/// An Anthropic API key. Nothing is metered: a key has no subscription plan.
ApiKey,

View file

@ -108,8 +108,9 @@ pub struct ClaudeConnectorConfig {
#[cultcache(key = 22)]
pub handle_secret_credential: String,
/// Which credential `token_credential` holds: the subscription token, or an
/// Anthropic API key. A document without this field is the token.
#[cultcache(key = 23, default)]
/// Anthropic API key. A document written before this field existed is refused at
/// load (the canonical-form check): the installer authors the document again.
#[cultcache(key = 23)]
pub auth: ClaudeAuth,
}

View file

@ -298,10 +298,9 @@ fn serve_refuses_a_document_that_is_not_there() {
}
#[test]
fn the_auth_choice_round_trips_and_defaults_to_the_token() {
fn the_auth_choice_round_trips() {
let scratch = Scratch::new();
let path = scratch.path("connector.cc");
assert_eq!(valid().auth, ClaudeAuth::OAuthToken);
let keyed = ClaudeConnectorConfig {
auth: ClaudeAuth::ApiKey,
..valid()
@ -361,7 +360,7 @@ struct BeforeAuth {
}
#[test]
fn a_document_without_the_auth_field_is_the_token() {
fn a_document_from_before_the_auth_field_is_refused_until_it_is_authored_again() {
let scratch = Scratch::new();
let path = scratch.path("before.cc");
let now = valid();
@ -401,7 +400,7 @@ fn a_document_without_the_auth_field_is_the_token() {
)
.unwrap();
}
assert_eq!(load_config(&path).unwrap(), now);
assert!(matches!(load_config(&path), Err(ConfigError::Store)));
}
#[test]