1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//! Memory read path: read (including --format raw), list, and the not-found contract.
//!
//! Split out of `integration_memory_crud.rs` by GAP-SG-208: that file reached
//! 1018 lines, past the 800-line ceiling this project sets for itself. It was
//! itself carved out of a 2485-line `integration.rs` in v1.2.5, so this is the
//! second pass of the same decomposition. Helpers stay in `tests/common/`.
#[path = "common/mod.rs"]
mod common;
#[allow(unused_imports)]
use assert_cmd::Command;
#[allow(unused_imports)]
use common::{
cmd, home_isolated_cmd, init_db, isolated_cmd_in, seed_memory_with_entities, sgr_cmd,
};
#[allow(unused_imports)]
use tempfile::TempDir;
// ---------------------------------------------------------------------------
#[test]
fn test_read_existing_memory() {
let tmp = TempDir::new().unwrap();
init_db(&tmp);
cmd(&tmp)
.args([
"remember",
"--name",
"memory-readable",
"--type",
"project",
"--description",
"A readable memory",
"--body",
"O conteudo do corpo da memoria",
])
.assert()
.success();
let output = cmd(&tmp)
.args(["read", "--name", "memory-readable"])
.assert()
.success()
.get_output()
.stdout
.clone();
let json: serde_json::Value = serde_json::from_slice(&output).unwrap();
assert_eq!(json["name"], "memory-readable");
assert_eq!(json["memory_type"], "project");
assert_eq!(json["description"], "A readable memory");
}
/// GAP-SG-50: `read --format raw` writes the pure body to stdout with no JSON
/// envelope. The unit layer covers the formatter; this asserts the end-to-end
/// CLI stdout contract a caller pipes into `jaq`/files.
#[test]
fn test_read_format_raw_emits_pure_body() {
let tmp = TempDir::new().unwrap();
init_db(&tmp);
cmd(&tmp)
.args([
"remember",
"--name",
"raw-body-memory",
"--type",
"note",
"--description",
"raw read contract",
"--body",
"CORPO_PURO_SEM_ENVELOPE",
])
.assert()
.success();
let output = cmd(&tmp)
.args(["read", "--name", "raw-body-memory", "--format", "raw"])
.assert()
.success()
.get_output()
.stdout
.clone();
let stdout = String::from_utf8(output).expect("raw stdout must be valid UTF-8");
assert!(
!stdout.trim_start().starts_with('{'),
"raw output must not be a JSON envelope, got: {stdout:?}"
);
assert!(
stdout.contains("CORPO_PURO_SEM_ENVELOPE"),
"raw output must contain the verbatim body, got: {stdout:?}"
);
}
#[test]
fn test_read_nonexistent_returns_exit_4() {
let tmp = TempDir::new().unwrap();
init_db(&tmp);
cmd(&tmp)
.args(["read", "--name", "nao-existe"])
.assert()
.failure()
.code(4);
}
// ---------------------------------------------------------------------------
// list
// ---------------------------------------------------------------------------
#[test]
fn test_list_memories() {
let tmp = TempDir::new().unwrap();
init_db(&tmp);
cmd(&tmp)
.args([
"remember",
"--name",
"lista-mem-1",
"--type",
"user",
"--description",
"desc1",
"--body",
"corpo1",
])
.assert()
.success();
cmd(&tmp)
.args([
"remember",
"--name",
"lista-mem-2",
"--type",
"feedback",
"--description",
"desc2",
"--body",
"corpo2",
])
.assert()
.success();
let output = cmd(&tmp)
.arg("list")
.assert()
.success()
.get_output()
.stdout
.clone();
let json: serde_json::Value = serde_json::from_slice(&output).unwrap();
assert!(json["items"].as_array().unwrap().len() >= 2);
}
// ---------------------------------------------------------------------------
// forget