From 7adcb172788cd9fb2f76192b4427244a1555aedb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Wed, 18 Nov 2026 19:43:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=95=99=E6=88=91=E5=81=9A=E2=80=94?= =?UTF-8?q?=E2=80=94=E8=A8=8A=E6=81=AF=E6=99=82=E9=96=93=E6=98=AF=200?= =?UTF-8?q?=EF=BC=88=E8=A8=98=E4=B8=8B=E6=99=82=E9=96=93=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E7=9A=84=E8=A8=8A=E6=81=AF=EF=BC=89=E4=B8=8D=E7=AE=97=E6=8C=87?= =?UTF-8?q?=E5=90=8D=E5=93=AA=E4=B8=80=E5=9B=9E=E5=90=88=EF=BC=8C=E7=85=A7?= =?UTF-8?q?=E5=AD=97=E6=89=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 審查(e755e58)的 P2:手機對記下時間之前的訊息送 at: 0,taught_turn 拿 0 去比,任何沒記時間的回合 都對得上,按一則跟它無關的舊訊息也會學到最新那個沒記時間的回合。0 當成沒給時間,走照字的那條路。 已驗證: memory 測試補兩句(at 0+同樣的字找得到、at 0+不同的字找不到);拿掉修正時 a_message_with_a_file_and_an_older_turn_can_be_taught 失敗,放回後逐位元組相同; 全部 cargo test(不帶金鑰、DOCKER_HOST 指到不存在)通過;clippy -D warnings 乾淨 未驗證: 真的資料夾裡升級前的回合(只有單元測試) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Uirha5sXAsDLzxz6UZJgoC --- src/memory.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/memory.rs b/src/memory.rs index cd0056b..54cab7e 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -213,6 +213,8 @@ fn plain_words(t: &str) -> String { /// the trail had the time (0), it is the latest turn started by the same words. `starts`: the /// turns' first lines (store::turn_starts). Ok: (that turn, the words the person typed). pub fn taught_turn(prompt: &str, at: Option, starts: &[crate::oplog::Record]) -> Result<(String, String), String> { + // A message from before times were kept says `at: 0`: that names no turn — go by its words. + let at = at.filter(|t| *t > 0); let key: String = plain_words(prompt).chars().take(40).collect(); let same_words = |p: &crate::oplog::Prompt| plain_words(crate::attach::typed_part(&p.text)).chars().take(40).collect::() == key; let latest = |ok: &dyn Fn(&crate::oplog::Prompt) -> bool| { @@ -1519,6 +1521,10 @@ mod tests { assert_eq!(taught_turn("看這張", None, &starts).map(|t| t.0), Ok("with-file".into()), "by its words too"); assert_eq!(taught_turn("以前的簽到", Some(400), &starts).map(|t| t.0), Ok("old".into()), "a turn from before the time was kept"); assert!(taught_turn("以前的", Some(400), &starts).is_err(), "…by all its words, not a part"); + // A message from before times were kept comes with `at: 0`: found by its words, never as + // whichever untimed turn is newest. + assert_eq!(taught_turn("以前的簽到", Some(0), &starts).map(|t| t.0), Ok("old".into())); + assert!(taught_turn("完全不同的一句話", Some(0), &starts).is_err(), "at 0 names no turn"); } #[test] fn remember_tells_the_same_thing_from_another_fact() {