mirror of
https://github.com/storytold/craft-ai-integrations.git
synced 2026-11-21 12:00:42 +01:00
* feat(ai-native): encrypted-file fallback in the standard secret chain A machine with no OS keychain could not save a key through the standard setup: AiClient::standard and ConnectionManager::standard layered only the environment and the keychain, so every save failed with "no secret store". standard_store(passphrase) now builds environment, keychain, then the encrypted file at the default location. Without a passphrase the file layer is a locked stand-in: no file reads as "no key", an existing file is reported as locked rather than empty, and a save asks for a passphrase. passphrase_need() tells a host when to ask (create or unlock). Both standard constructors gain standard_with_passphrase. Deliberate-bug group kf (7 cases, all caught). The real keychain round trip passed by hand on Windows; Linux and macOS keychains, a bare Linux session and a host prompting for the passphrase are not run. * fix(ai-native): a failed file check counts as a locked file, not a missing one Path::exists returns false when the check itself fails, such as an ancestor folder that denies access. The locked stand-in then read a key as absent, and both it and EncryptedFileStore::delete reported a delete as done while the key could still be in the file. Use try_exists. In the locked stand-in and passphrase_need, a failed check counts as present, so it is reported as locked. In EncryptedFileStore::delete, it is a storage error. Two new deliberate-bug cases in kf, both caught (9 of 9). * docs(ai-native): document the encrypted file store's set * docs(ai-native): document the encrypted file store's name and get * docs(ai-native): document the encrypted file store's error mapping and Debug * fix(ai-client): show why a key save was refused when it needs a passphrase ConnectionManager replaced every refused key save with the general "keychain failed, set an environment variable" advice. On a machine with no keychain, the person never saw that the secret file needs a passphrase. A credentials refusal (Auth) from the store is now shown as given; store errors never carry a secret. Other refusals keep the general advice. New deliberate-bug case in kf, caught (10 of 10).
24 lines
2.4 KiB
Python
24 lines
2.4 KiB
Python
"""Deliberate-bug cases for group `kf`: the standard secret chain and its encrypted-file fallback
|
|
for a machine with no OS keychain (`ai-native/src/secrets/standard.rs`, `file.rs` deletes, and how
|
|
`ai-client/src/manage.rs` reports a refused save).
|
|
|
|
Loaded by mutation_check.py. Each case breaks one rule and names the test that should notice.
|
|
Format: (name, file, old, new, package, test target, test filter).
|
|
"""
|
|
S = 'crates/ai-native/src/secrets/standard.rs'
|
|
F = 'crates/ai-native/src/secrets/file.rs'
|
|
N = 'craft-ai-native'
|
|
|
|
KF = [
|
|
('locked-file-reads-as-empty', S, ' return Err(self.refuse());\n }\n Ok(None)', ' return Ok(None);\n }\n Ok(None)', N, 'lib', 'a_locked_file_is_reported'),
|
|
('locked-file-delete-pretends', S, ' return Err(self.refuse());\n }\n Ok(())', ' return Ok(());\n }\n Ok(())', N, 'lib', 'a_locked_file_is_reported'),
|
|
('locked-file-left-out', S, 'None => Box::new(LockedFile { path }),', 'None => {\n let _ = path;\n Box::new(EnvStore::with_lookup(|_| None))\n }', N, 'lib', 'not_hidden_by_a_locked_file'),
|
|
('empty-passphrase-used', S, 'passphrase.filter(|p| !p.is_empty())', 'passphrase', N, 'lib', 'an_empty_passphrase'),
|
|
('unlock-skipped-beside-a-keychain', S, 'Some(true) => PassphraseNeed::Unlock,', 'Some(true) if !keychain => PassphraseNeed::Unlock,', N, 'lib', 'passphrase_is_asked_for'),
|
|
('create-asked-beside-a-keychain', S, 'Some(false) if !keychain => PassphraseNeed::Create,', 'Some(false) => PassphraseNeed::Create,', N, 'lib', 'passphrase_is_asked_for'),
|
|
('save-refusal-names-no-fix', S, '"this computer has no system keychain, so choose a passphrase to keep keys in an \\\n encrypted file",', '"no store",', N, 'lib', 'says_what_to_do'),
|
|
('failed-check-reads-as-missing', S, 'found.unwrap_or(true)', 'found.unwrap_or(false)', N, 'lib', 'a_failed_file_check_counts_as_locked'),
|
|
('passphrase-request-hidden-on-save', 'crates/ai-client/src/manage.rs', 'let shown = if e.kind == ErrorKind::Auth {', 'let shown = if false {', 'craft-ai-client', 'manage_passphrase', 'needs_a_passphrase'),
|
|
('unlocked-delete-ignores-failed-check', F, 'match self.path.try_exists() {', 'match self.path.try_exists().or(Ok::<bool, std::io::Error>(false)) {', N, 'lib', 'an_unlocked_delete_that_cannot_check'),
|
|
]
|