memoryd: note answers name notes.md and the file that was not changed
This commit is contained in:
@@ -57,9 +57,21 @@ pub fn untrusted_refusal(file: MemoryFile) -> String {
|
||||
)
|
||||
}
|
||||
|
||||
/// The answer when an untrusted session's `add` became a note.
|
||||
pub const SAVED_AS_NOTE: &str =
|
||||
"saved as a note (untrusted): this session has read untrusted content";
|
||||
/// The answer when an untrusted session's `add` became a note. It names the file it did not change:
|
||||
/// on the device the model read a shorter answer as success.
|
||||
pub fn saved_as_note(file: MemoryFile) -> String {
|
||||
format!(
|
||||
"not added to {}: this session has read untrusted content, so it was saved in notes.md as an untrusted note",
|
||||
file.name()
|
||||
)
|
||||
}
|
||||
|
||||
/// The answer to a `note` from a session that has not read untrusted content.
|
||||
pub const NOTED: &str = "saved in notes.md";
|
||||
|
||||
/// The answer to a `note` from a session that has read untrusted content.
|
||||
pub const NOTED_UNTRUSTED: &str =
|
||||
"saved in notes.md, marked untrusted: this session has read untrusted content";
|
||||
|
||||
fn stale(file: MemoryFile) -> String {
|
||||
format!(
|
||||
@@ -97,13 +109,13 @@ pub fn apply(store: &Store, args: &MemoryArgs, ctx: &Context) -> Result<Outcome,
|
||||
| MemoryArgs::Consolidate { file, .. } => *file,
|
||||
};
|
||||
// 3. When `ctx.untrusted`: an Add becomes `noted(store, ctx, text, "add")?` with its answer
|
||||
// replaced by SAVED_AS_NOTE; any other action -> Err(untrusted_refusal(file)).
|
||||
// replaced by saved_as_note(file); any other action -> Err(untrusted_refusal(file)).
|
||||
if ctx.untrusted {
|
||||
match args {
|
||||
MemoryArgs::Add { text, .. } => {
|
||||
let outcome = noted(store, ctx, text, "add")?;
|
||||
return Ok(Outcome {
|
||||
answer: SAVED_AS_NOTE.to_string(),
|
||||
answer: saved_as_note(file),
|
||||
..outcome
|
||||
});
|
||||
}
|
||||
@@ -222,9 +234,9 @@ fn noted(
|
||||
Ok(Outcome {
|
||||
action,
|
||||
answer: if ctx.untrusted {
|
||||
"noted (untrusted)"
|
||||
NOTED_UNTRUSTED
|
||||
} else {
|
||||
"noted"
|
||||
NOTED
|
||||
}
|
||||
.to_string(),
|
||||
change: Change {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#[path = "support/tmp.rs"]
|
||||
mod tmp;
|
||||
|
||||
use memoryd::edit::{Context, SAVED_AS_NOTE, apply};
|
||||
use memoryd::edit::{Context, apply};
|
||||
use memoryd::files::Store;
|
||||
use memoryd::notes::{self, Kind};
|
||||
use proto::{DataClass, MemoryArgs, MemoryFile, Timestamp};
|
||||
@@ -94,14 +94,17 @@ fn a_note_is_labelled_by_the_session() {
|
||||
let f = Fixture::new("edit-note");
|
||||
assert_eq!(
|
||||
f.call(r#"{"action":"note","text":"The launch moved."}"#, false),
|
||||
Ok("noted".to_string())
|
||||
Ok("saved in notes.md".to_string())
|
||||
);
|
||||
assert_eq!(
|
||||
f.call(
|
||||
r#"{"action":"note","text":"example.org says March."}"#,
|
||||
true
|
||||
),
|
||||
Ok("noted (untrusted)".to_string())
|
||||
Ok(
|
||||
"saved in notes.md, marked untrusted: this session has read untrusted content"
|
||||
.to_string()
|
||||
)
|
||||
);
|
||||
assert_eq!(
|
||||
f.file("notes.md"),
|
||||
@@ -127,7 +130,7 @@ fn an_untrusted_session_can_take_notes_but_not_change_identity() {
|
||||
r#"{"action":"add","file":"user","text":"Owner lives in Oslo."}"#,
|
||||
true
|
||||
),
|
||||
Ok(SAVED_AS_NOTE.to_string())
|
||||
Ok("not added to user.md: this session has read untrusted content, so it was saved in notes.md as an untrusted note".to_string())
|
||||
);
|
||||
assert_eq!(f.file("user.md"), "");
|
||||
assert!(
|
||||
|
||||
@@ -175,7 +175,7 @@ fn an_untrusted_session_writes_notes_not_identity() {
|
||||
));
|
||||
assert_eq!(
|
||||
answer,
|
||||
"saved as a note (untrusted): this session has read untrusted content"
|
||||
"not added to memory.md: this session has read untrusted content, so it was saved in notes.md as an untrusted note"
|
||||
);
|
||||
let memory = std::fs::read_to_string(r.dir.path().join("memory/memory.md")).unwrap();
|
||||
assert_eq!(memory, "");
|
||||
@@ -232,7 +232,7 @@ fn review_holds_identity_writes_but_not_notes() {
|
||||
r#"{"action":"note","text":"Not held."}"#,
|
||||
false,
|
||||
));
|
||||
assert_eq!(noted, "noted");
|
||||
assert_eq!(noted, "saved in notes.md");
|
||||
let (untrusted, _) = content(call(
|
||||
&r,
|
||||
"mm-b",
|
||||
@@ -242,7 +242,7 @@ fn review_holds_identity_writes_but_not_notes() {
|
||||
));
|
||||
assert_eq!(
|
||||
untrusted,
|
||||
"saved as a note (untrusted): this session has read untrusted content"
|
||||
"not added to memory.md: this session has read untrusted content, so it was saved in notes.md as an untrusted note"
|
||||
);
|
||||
let admin = |command, arg: &str| match ask(
|
||||
&r.config.admin_socket(),
|
||||
|
||||
Reference in New Issue
Block a user