Rinomina: crate akode-*, cartelle akode-rs/ e akode-cli/, binario akode, ~/.akode, AKODE_* (A)
Riapplica la fase 5 di aKode (86e7c72e) sulla base ripulita:
- crate codex-* -> akode-*, codex-rs -> akode-rs, codex-cli -> akode-cli, binario e ausiliari akode;
- ~/.codex -> ~/.akode, CODEX_HOME -> AKODE_HOME, variabili CODEX_* -> AKODE_*, .codex/ -> .akode/ di progetto;
nessun fallback a ~/.codex o a CODEX_*;
- testi per l'utente "Codex" -> "aKode"; testi verso il modello e istruzioni di sistema invariati;
- snapshot insta rinominati (non ancora rigenerati).
I conflitti con la base ripulita sono stati risolti riapplicando la rinomina ai file senza le
funzioni di imeAI (script di mappa dei token per file).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
157
akode-rs/prompts/src/guardian_instructions_tests.rs
Normal file
157
akode-rs/prompts/src/guardian_instructions_tests.rs
Normal file
@@ -0,0 +1,157 @@
|
||||
//! Covers policy substitution, terminal output contracts, truncation, and rejection-text overrides.
|
||||
|
||||
use akode_context_fragments::ContextualUserFragment;
|
||||
use akode_guardian_context::TRANSCRIPT_JSON_INSTRUCTIONS;
|
||||
use akode_guardian_context::truncate_text;
|
||||
use akode_protocol::TranscriptFormat;
|
||||
use akode_protocol_test_support::ContentItemTestExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::GuardianClassifierInstructions;
|
||||
use super::GuardianPolicyInstructions;
|
||||
use super::render_guardian_rejection;
|
||||
|
||||
#[test]
|
||||
fn reviewer_policy_substitution_preserves_template_layout_and_appends_contract() {
|
||||
for (template, policy, expected) in [
|
||||
(
|
||||
" Review:\n{{ tenant_policy_config }}\nAgain: {{ tenant_policy_config }}\n \t",
|
||||
" \nTenant policy.\n ",
|
||||
" Review:\nTenant policy.\nAgain: Tenant policy.\n\nReview contract.\n",
|
||||
),
|
||||
(
|
||||
"Policy: {{ tenant_policy_config }}",
|
||||
"",
|
||||
"Policy: \n\nReview contract.\n",
|
||||
),
|
||||
(
|
||||
"Tenant: {{ tenant_policy_config }}\nAdditional: {{ extra_policy }}",
|
||||
"Tenant policy.",
|
||||
"Tenant: Tenant policy.\nAdditional: \n\nReview contract.\n",
|
||||
),
|
||||
("", "Tenant policy.", "\n\nReview contract.\n"),
|
||||
] {
|
||||
assert_eq!(
|
||||
GuardianPolicyInstructions::new(
|
||||
TranscriptFormat::Json,
|
||||
policy,
|
||||
"",
|
||||
template,
|
||||
"Review contract."
|
||||
)
|
||||
.render()
|
||||
.expect_text(),
|
||||
format!("{TRANSCRIPT_JSON_INSTRUCTIONS}\n\n{expected}"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reviewer_extra_policy_substitution_preserves_tenant_policy() {
|
||||
for (template, extra_policy, expected) in [
|
||||
(
|
||||
"Tenant: {{ tenant_policy_config }}\nAdditional: {{ extra_policy }}\nAgain: {{ extra_policy }}",
|
||||
" \nAdditional policy.\n ",
|
||||
"Tenant: Tenant policy.\nAdditional: Additional policy.\nAgain: Additional policy.\n\nReview contract.\n",
|
||||
),
|
||||
(
|
||||
"Tenant: {{ tenant_policy_config }}\nAdditional: {{ extra_policy }}",
|
||||
" \n\t",
|
||||
"Tenant: Tenant policy.\nAdditional: \n\nReview contract.\n",
|
||||
),
|
||||
(
|
||||
"Tenant: {{ tenant_policy_config }}",
|
||||
"Additional policy.",
|
||||
"Tenant: Tenant policy.\n\nReview contract.\n",
|
||||
),
|
||||
] {
|
||||
assert_eq!(
|
||||
GuardianPolicyInstructions::new(
|
||||
TranscriptFormat::Json,
|
||||
"Tenant policy.",
|
||||
extra_policy,
|
||||
template,
|
||||
"Review contract.",
|
||||
)
|
||||
.render()
|
||||
.expect_text(),
|
||||
format!("{TRANSCRIPT_JSON_INSTRUCTIONS}\n\n{expected}"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reviewer_policy_substitution_keeps_inserted_policy_text_literal() {
|
||||
assert_eq!(
|
||||
GuardianPolicyInstructions::new(
|
||||
TranscriptFormat::Json,
|
||||
"Tenant says {{ tenant_policy_config }} and {{ extra_policy }}.",
|
||||
"Additional says {{ tenant_policy_config }} and {{ extra_policy }}.",
|
||||
"Tenant: {{ tenant_policy_config }}\nAdditional: {{ extra_policy }}",
|
||||
"Review contract.",
|
||||
)
|
||||
.render()
|
||||
.expect_text(),
|
||||
format!(
|
||||
"{TRANSCRIPT_JSON_INSTRUCTIONS}\n\nTenant: Tenant says {{{{ tenant_policy_config }}}} and {{{{ extra_policy }}}}.\nAdditional: Additional says {{{{ tenant_policy_config }}}} and {{{{ extra_policy }}}}.\n\nReview contract.\n"
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn classifier_policy_substitution_and_legacy_append_keep_one_terminal_contract_before_truncation() {
|
||||
for (instructions, policy, expected) in [
|
||||
(
|
||||
"Classify: {{ tenant_policy_config }}",
|
||||
" Tenant policy.\n",
|
||||
"Classify: Tenant policy.\n\n\nClassifier contract.",
|
||||
),
|
||||
(
|
||||
"Classify: {{ tenant_policy_config }}\n\nClassifier contract.\n \t",
|
||||
"Tenant policy.",
|
||||
"Classify: Tenant policy.\n\nClassifier contract.\n \t",
|
||||
),
|
||||
(
|
||||
"Legacy classifier.",
|
||||
"Tenant policy.",
|
||||
"Legacy classifier.\n\n# Security Policy\nTenant policy.\n\nClassifier contract.",
|
||||
),
|
||||
] {
|
||||
for max_tokens in [None, Some(20)] {
|
||||
let expected = match max_tokens {
|
||||
Some(max_tokens) => truncate_text(expected, max_tokens),
|
||||
None => expected.to_owned(),
|
||||
};
|
||||
assert_eq!(
|
||||
GuardianClassifierInstructions::new(
|
||||
TranscriptFormat::Json,
|
||||
instructions,
|
||||
policy,
|
||||
"Classifier contract.",
|
||||
max_tokens,
|
||||
)
|
||||
.render()
|
||||
.expect_text(),
|
||||
format!("{TRANSCRIPT_JSON_INSTRUCTIONS}\n\n{expected}"),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejection_feedback_trims_rationale_and_preserves_instruction_overrides() {
|
||||
for (rationale, instructions, expected) in [
|
||||
(
|
||||
" \nSensitive data would leave the workspace.\t ",
|
||||
" Ask for approval.\n",
|
||||
"This action was rejected due to unacceptable risk.\nReason: Sensitive data would leave the workspace.\n Ask for approval.\n",
|
||||
),
|
||||
(
|
||||
" \n\t",
|
||||
"",
|
||||
"This action was rejected due to unacceptable risk.\nReason: Auto-reviewer denied the action without a specific rationale.\n",
|
||||
),
|
||||
] {
|
||||
assert_eq!(render_guardian_rejection(rationale, instructions), expected);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user