@lamentis/naome 1.4.1 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/Cargo.lock +2 -2
  2. package/README.md +17 -122
  3. package/crates/naome-cli/Cargo.toml +1 -1
  4. package/crates/naome-cli/src/main.rs +14 -5
  5. package/crates/naome-cli/src/task_commands/agent_snapshot.rs +173 -0
  6. package/crates/naome-cli/src/task_commands/can_edit.rs +64 -0
  7. package/crates/naome-cli/src/task_commands/check_run/output.rs +34 -0
  8. package/crates/naome-cli/src/task_commands/check_run/receipts.rs +163 -0
  9. package/crates/naome-cli/src/task_commands/check_run/verification.rs +165 -0
  10. package/crates/naome-cli/src/task_commands/check_run.rs +196 -0
  11. package/crates/naome-cli/src/task_commands/commit_preflight.rs +89 -0
  12. package/crates/naome-cli/src/task_commands/common.rs +39 -1
  13. package/crates/naome-cli/src/task_commands/compact_proof.rs +69 -0
  14. package/crates/naome-cli/src/task_commands/complete.rs +43 -0
  15. package/crates/naome-cli/src/task_commands/loop_control.rs +73 -0
  16. package/crates/naome-cli/src/task_commands/path_policy.rs +57 -0
  17. package/crates/naome-cli/src/task_commands/planner/checks.rs +166 -0
  18. package/crates/naome-cli/src/task_commands/planner/impact.rs +35 -0
  19. package/crates/naome-cli/src/task_commands/planner/mod.rs +24 -0
  20. package/crates/naome-cli/src/task_commands/preflight.rs +208 -0
  21. package/crates/naome-cli/src/task_commands/readiness.rs +14 -10
  22. package/crates/naome-cli/src/task_commands/record.rs +176 -37
  23. package/crates/naome-cli/src/task_commands/repair.rs +58 -11
  24. package/crates/naome-cli/src/task_commands/scope_suggestions.rs +109 -0
  25. package/crates/naome-cli/src/task_commands.rs +26 -3
  26. package/crates/naome-cli/tests/task_cli_agent_controls.rs +9 -16
  27. package/crates/naome-cli/tests/task_cli_fast_flow.rs +290 -0
  28. package/crates/naome-cli/tests/task_cli_loop.rs +383 -0
  29. package/crates/naome-cli/tests/task_cli_loop_edit.rs +144 -0
  30. package/crates/naome-cli/tests/task_cli_support/mod.rs +28 -0
  31. package/crates/naome-core/Cargo.toml +1 -1
  32. package/crates/naome-core/src/lib.rs +7 -7
  33. package/crates/naome-core/src/task_state/evidence_fingerprint.rs +47 -0
  34. package/crates/naome-core/src/task_state/mod.rs +2 -0
  35. package/crates/naome-core/src/task_state/status/control/repair.rs +2 -2
  36. package/crates/naome-core/src/task_state/status/model.rs +2 -0
  37. package/crates/naome-core/src/task_state/status/proof.rs +59 -9
  38. package/crates/naome-core/src/task_state/status/proof_read.rs +14 -0
  39. package/crates/naome-core/src/task_state/status/report_context.rs +23 -1
  40. package/crates/naome-core/src/task_state/status/transition.rs +29 -1
  41. package/crates/naome-core/tests/task_status.rs +122 -0
  42. package/installer/context.js +1 -1
  43. package/installer/harness-verification.js +2 -6
  44. package/installer/manifest-state.js +2 -2
  45. package/installer/native.js +3 -31
  46. package/native/darwin-arm64/naome +0 -0
  47. package/native/linux-x64/naome +0 -0
  48. package/package.json +1 -1
  49. package/templates/naome-root/.naome/bin/check-harness-health.js +2 -2
  50. package/templates/naome-root/.naome/bin/check-task-state.js +4 -39
  51. package/templates/naome-root/.naome/bin/naome.js +2 -30
  52. package/templates/naome-root/.naome/manifest.json +2 -2
@@ -0,0 +1,290 @@
1
+ use std::fs;
2
+ use std::process::Command;
3
+
4
+ use serde_json::{json, Value};
5
+
6
+ mod task_cli_support;
7
+
8
+ use task_cli_support::{
9
+ active_task, fixture_root, git, init_git, run_json, task_state, task_state_with_active_task,
10
+ write_fixture_file, write_json,
11
+ };
12
+
13
+ #[test]
14
+ fn agent_snapshot_reports_missing_proof_and_safe_commands() {
15
+ let root = fixture_root(task_state());
16
+ init_git(&root);
17
+ write_fixture_file(&root, "README.md", "changed\n");
18
+
19
+ let snapshot = run_json(&root, ["task", "agent-snapshot", "--json"]);
20
+
21
+ assert_eq!(snapshot["schema"], "naome.task.agent-snapshot.v1");
22
+ assert_eq!(snapshot["proof"]["missingChecks"], json!(["diff-check"]));
23
+ assert_eq!(snapshot["nextAction"]["type"], "run_checks");
24
+ assert_eq!(snapshot["checks"]["safeToRun"][0]["checkId"], "diff-check");
25
+ }
26
+
27
+ #[test]
28
+ fn preflight_reports_path_policy_and_check_plan() {
29
+ let root = fixture_root(task_state_with_active_task(active_task(json!({
30
+ "allowedPaths": ["scripts/*.js"],
31
+ "proofResults": []
32
+ }))));
33
+ fs::write(
34
+ root.join(".naomeignore"),
35
+ ".naome/archive/\n.naome/tasks/\ndist/\n",
36
+ )
37
+ .unwrap();
38
+ init_git(&root);
39
+
40
+ let allowed = run_json(
41
+ &root,
42
+ ["task", "preflight", "--path", "scripts/check.js", "--json"],
43
+ );
44
+ assert_eq!(allowed["paths"][0]["editable"], true);
45
+ assert_eq!(allowed["paths"][0]["risk"], "medium");
46
+
47
+ let ignored = run_json(
48
+ &root,
49
+ ["task", "preflight", "--path", "dist/bundle.js", "--json"],
50
+ );
51
+ assert_eq!(ignored["paths"][0]["editable"], false);
52
+ assert_eq!(ignored["findings"][0]["id"], "task.preflight.ignored_path");
53
+
54
+ let traversal = run_json(
55
+ &root,
56
+ ["task", "preflight", "--path", "..\\outside.js", "--json"],
57
+ );
58
+ assert_eq!(traversal["paths"][0]["editable"], false);
59
+ assert_eq!(traversal["findings"][0]["id"], "task.preflight.unsafe_path");
60
+
61
+ let control = run_json(
62
+ &root,
63
+ ["task", "preflight", "--path", ".naomeignore", "--json"],
64
+ );
65
+ assert_eq!(control["paths"][0]["editable"], false);
66
+ assert_eq!(control["findings"][0]["id"], "task.preflight.control_path");
67
+ }
68
+
69
+ #[test]
70
+ fn preflight_blocks_when_no_target_paths_are_selected() {
71
+ let root = fixture_root(task_state());
72
+ init_git(&root);
73
+
74
+ let preflight = run_json(&root, ["task", "preflight", "--json"]);
75
+
76
+ assert_eq!(preflight["schema"], "naome.task.preflight.v1");
77
+ assert_eq!(
78
+ preflight["findings"][0]["id"],
79
+ "task.preflight.missing_target_paths"
80
+ );
81
+ assert_eq!(preflight["nextAction"]["type"], "blocked");
82
+ assert_eq!(preflight["nextAction"]["safeToExecute"], false);
83
+ }
84
+
85
+ #[test]
86
+ fn preflight_from_changed_allows_clean_changed_set() {
87
+ let root = fixture_root(task_state());
88
+ init_git(&root);
89
+ git(&root, ["add", ".naome/task-state.json"]);
90
+ git(&root, ["commit", "-m", "record admission head"]);
91
+
92
+ let preflight = run_json(&root, ["task", "preflight", "--from-changed", "--json"]);
93
+
94
+ assert_eq!(preflight["schema"], "naome.task.preflight.v1");
95
+ assert!(preflight["findings"].as_array().unwrap().is_empty());
96
+ assert_eq!(preflight["paths"], json!([]));
97
+ assert_eq!(preflight["nextAction"]["type"], "edit");
98
+ }
99
+
100
+ #[test]
101
+ fn commit_preflight_blocks_missing_proof() {
102
+ let root = fixture_root(task_state());
103
+ init_git(&root);
104
+ write_fixture_file(&root, "README.md", "changed\n");
105
+
106
+ let preflight = run_json(&root, ["task", "commit-preflight", "--json"]);
107
+
108
+ assert_eq!(preflight["schema"], "naome.task.commit-preflight.v1");
109
+ assert_eq!(preflight["wouldPass"], false);
110
+ assert_eq!(
111
+ preflight["blockingFindings"][0]["id"],
112
+ "task.proof.missing_check"
113
+ );
114
+ assert_eq!(preflight["nextAction"]["type"], "rerun_checks");
115
+ assert_eq!(preflight["nextAction"]["checkIds"], json!(["diff-check"]));
116
+ }
117
+
118
+ #[test]
119
+ fn agent_snapshot_prefers_commit_ready_over_more_editing() {
120
+ let root = fixture_root(task_state());
121
+ init_git(&root);
122
+ write_fixture_file(&root, "README.md", "changed\n");
123
+
124
+ let checked = run_json(
125
+ &root,
126
+ [
127
+ "task",
128
+ "run-check",
129
+ "--check",
130
+ "diff-check",
131
+ "--record-proof",
132
+ "--json",
133
+ ],
134
+ );
135
+ assert_eq!(checked["recordedProof"], true);
136
+
137
+ let snapshot = run_json(&root, ["task", "agent-snapshot", "--json"]);
138
+
139
+ assert_eq!(snapshot["commit"]["canCommit"], true);
140
+ assert_eq!(snapshot["nextAction"]["type"], "commit_ready");
141
+ assert_eq!(snapshot["nextAction"]["safeToExecute"], false);
142
+ }
143
+
144
+ #[test]
145
+ fn commit_preflight_surfaces_transition_blocker_action_and_exit_code() {
146
+ let root = fixture_root(task_state_with_active_task(active_task(json!({
147
+ "requiredCheckIds": [],
148
+ "humanReview": {
149
+ "required": true,
150
+ "approved": false,
151
+ "reason": "Release owner approval required."
152
+ },
153
+ "proofResults": []
154
+ }))));
155
+ init_git(&root);
156
+ write_fixture_file(&root, "README.md", "changed\n");
157
+
158
+ let preflight = run_json(&root, ["task", "commit-preflight", "--json"]);
159
+
160
+ assert_eq!(preflight["wouldPass"], false);
161
+ assert_eq!(
162
+ preflight["blockingFindings"][0]["id"],
163
+ "task.transition.human_review_required"
164
+ );
165
+ assert_eq!(preflight["nextAction"]["type"], "blocked");
166
+ assert_eq!(preflight["nextAction"]["safeToExecute"], false);
167
+
168
+ let output = Command::new(env!("CARGO_BIN_EXE_naome"))
169
+ .args(["task", "commit-preflight", "--json", "--exit-code"])
170
+ .current_dir(root)
171
+ .output()
172
+ .unwrap();
173
+
174
+ assert_eq!(output.status.code(), Some(1));
175
+ }
176
+
177
+ #[test]
178
+ fn compact_proof_dry_run_and_write_remove_verbose_fields() {
179
+ let root = fixture_root(task_state());
180
+ let path = root.join(".naome/task-state.json");
181
+ let mut state: Value = serde_json::from_str(&fs::read_to_string(&path).unwrap()).unwrap();
182
+ state["activeTask"]["proofPathSets"] = json!({ "current": ["README.md"] });
183
+ state["activeTask"]["proofBatches"] = json!([{
184
+ "id": "batch",
185
+ "checkedAt": "2026-05-14T00:00:00.000Z",
186
+ "evidencePathSet": "current",
187
+ "proofs": [{
188
+ "checkId": "diff-check",
189
+ "command": "git diff --check",
190
+ "cwd": ".",
191
+ "exitCode": 0,
192
+ "evidenceFingerprint": "fnv64:test",
193
+ "stdoutSummary": "large",
194
+ "stderrSummary": "large",
195
+ "durationMs": 42
196
+ }]
197
+ }]);
198
+ write_json(&root, ".naome/task-state.json", &state);
199
+
200
+ let dry = run_json(&root, ["task", "compact-proof", "--dry-run", "--json"]);
201
+ assert_eq!(dry["dryRun"], true);
202
+ assert_eq!(dry["removedVerboseFields"], 3);
203
+ let unchanged = fs::read_to_string(&path).unwrap();
204
+ assert!(unchanged.contains("stdoutSummary"));
205
+
206
+ let compacted = run_json(&root, ["task", "compact-proof", "--json"]);
207
+ assert_eq!(compacted["compacted"], true);
208
+ let changed = fs::read_to_string(&path).unwrap();
209
+ assert!(!changed.contains("stdoutSummary"));
210
+ assert!(changed.contains("evidenceFingerprint"));
211
+ }
212
+
213
+ #[test]
214
+ fn record_proof_rejects_task_and_path_mismatched_receipts() {
215
+ let root = fixture_root(task_state_with_active_task(active_task(json!({
216
+ "allowedPaths": ["README.md", "docs/**"],
217
+ "proofResults": []
218
+ }))));
219
+ init_git(&root);
220
+ write_fixture_file(&root, "README.md", "changed\n");
221
+
222
+ let checked = run_json(
223
+ &root,
224
+ ["task", "run-check", "--check", "diff-check", "--json"],
225
+ );
226
+ assert_eq!(checked["exitCode"], 0);
227
+
228
+ let mut state: Value =
229
+ serde_json::from_str(&fs::read_to_string(root.join(".naome/task-state.json")).unwrap())
230
+ .unwrap();
231
+ state["activeTask"]["id"] = json!("different-task");
232
+ write_json(&root, ".naome/task-state.json", &state);
233
+ let task_mismatch = run_json(
234
+ &root,
235
+ ["task", "record-proof", "--from-proof-plan", "--json"],
236
+ );
237
+ assert_eq!(
238
+ task_mismatch["findings"][0]["id"],
239
+ "task.proof.receipt_task_mismatch"
240
+ );
241
+
242
+ state["activeTask"]["id"] = json!("cli-task");
243
+ write_json(&root, ".naome/task-state.json", &state);
244
+ write_fixture_file(&root, "docs/new.md", "new\n");
245
+ let path_mismatch = run_json(
246
+ &root,
247
+ ["task", "record-proof", "--from-proof-plan", "--json"],
248
+ );
249
+ assert_eq!(
250
+ path_mismatch["findings"][0]["id"],
251
+ "task.proof.receipt_path_mismatch"
252
+ );
253
+ }
254
+
255
+ #[test]
256
+ fn scope_suggestions_reports_test_support_helpers() {
257
+ let root = fixture_root(task_state_with_active_task(active_task(json!({
258
+ "allowedPaths": ["scripts/**"],
259
+ "proofResults": []
260
+ }))));
261
+ init_git(&root);
262
+ write_fixture_file(&root, "scripts/new-flow.test.js", "test('x', () => {});\n");
263
+
264
+ let suggestions = run_json(
265
+ &root,
266
+ ["task", "scope-suggestions", "--from-changed", "--json"],
267
+ );
268
+
269
+ assert_eq!(suggestions["schema"], "naome.task.scope-suggestions.v1");
270
+ assert!(suggestions["suggestions"]
271
+ .as_array()
272
+ .unwrap()
273
+ .iter()
274
+ .any(|suggestion| suggestion["path"] == "scripts/naome-installer-support.js"));
275
+ }
276
+
277
+ #[test]
278
+ fn commit_preflight_exit_code_reports_blocker() {
279
+ let root = fixture_root(task_state());
280
+ init_git(&root);
281
+ write_fixture_file(&root, "README.md", "changed\n");
282
+
283
+ let output = Command::new(env!("CARGO_BIN_EXE_naome"))
284
+ .args(["task", "commit-preflight", "--json", "--exit-code"])
285
+ .current_dir(root)
286
+ .output()
287
+ .unwrap();
288
+
289
+ assert_eq!(output.status.code(), Some(10));
290
+ }
@@ -0,0 +1,383 @@
1
+ use std::fs;
2
+ use std::process::Command;
3
+
4
+ use serde_json::{json, Value};
5
+
6
+ mod task_cli_support;
7
+
8
+ use task_cli_support::{
9
+ active_task, fixture_root, git, init_git, run_json, task_state, task_state_with_active_task,
10
+ write_fixture_file, write_verification_checks,
11
+ };
12
+
13
+ #[test]
14
+ fn run_check_rejects_unknown_and_records_successful_safe_checks() {
15
+ let root = fixture_root(task_state());
16
+ init_git(&root);
17
+ write_fixture_file(&root, "README.md", "changed\n");
18
+
19
+ let unknown = run_json(&root, ["task", "run-check", "--check", "missing", "--json"]);
20
+ assert_eq!(unknown["schema"], "naome.task.run-check.v1");
21
+ assert_eq!(unknown["executed"], false);
22
+ assert_eq!(unknown["findings"][0]["id"], "task.check.unknown");
23
+
24
+ let result = run_json(
25
+ &root,
26
+ [
27
+ "task",
28
+ "run-check",
29
+ "--check",
30
+ "diff-check",
31
+ "--record-proof",
32
+ "--json",
33
+ "--agent-session",
34
+ "loop-a",
35
+ ],
36
+ );
37
+ assert_eq!(result["executed"], true);
38
+ assert_eq!(result["exitCode"], 0);
39
+ assert_eq!(result["recordedProof"], true);
40
+ assert_eq!(result["agentSession"], "loop-a");
41
+
42
+ let task_state: Value =
43
+ serde_json::from_str(&fs::read_to_string(root.join(".naome/task-state.json")).unwrap())
44
+ .unwrap();
45
+ assert_eq!(
46
+ task_state["activeTask"]["proofBatches"][0]["proofs"][0]["agentSession"],
47
+ "loop-a"
48
+ );
49
+ assert_eq!(
50
+ task_state["activeTask"]["proofBatches"][0]["proofs"][0]["command"],
51
+ "git diff --check"
52
+ );
53
+ assert_eq!(
54
+ task_state["activeTask"]["proofBatches"][0]["proofs"][0]["cwd"],
55
+ "."
56
+ );
57
+ }
58
+
59
+ #[test]
60
+ fn record_proof_requires_recent_success_evidence() {
61
+ let root = fixture_root(task_state());
62
+ init_git(&root);
63
+ write_fixture_file(&root, "README.md", "changed\n");
64
+
65
+ let recorded = run_json(
66
+ &root,
67
+ ["task", "record-proof", "--from-proof-plan", "--json"],
68
+ );
69
+
70
+ assert_eq!(recorded["recorded"], false);
71
+ assert_eq!(
72
+ recorded["findings"][0]["id"],
73
+ "task.proof.no_recent_success"
74
+ );
75
+ }
76
+
77
+ #[test]
78
+ fn record_proof_rejects_receipts_from_older_same_path_content() {
79
+ let root = fixture_root(task_state());
80
+ init_git(&root);
81
+ write_fixture_file(&root, "README.md", "changed\n");
82
+
83
+ let checked = run_json(
84
+ &root,
85
+ ["task", "run-check", "--check", "diff-check", "--json"],
86
+ );
87
+ assert_eq!(checked["executed"], true);
88
+ assert_eq!(checked["exitCode"], 0);
89
+
90
+ write_fixture_file(&root, "README.md", "changed with trailing whitespace \n");
91
+ let recorded = run_json(
92
+ &root,
93
+ ["task", "record-proof", "--from-proof-plan", "--json"],
94
+ );
95
+
96
+ assert_eq!(recorded["recorded"], false);
97
+ assert_eq!(
98
+ recorded["findings"][0]["id"],
99
+ "task.proof.stale_receipt_content"
100
+ );
101
+ }
102
+
103
+ #[test]
104
+ fn record_proof_rejects_receipts_from_old_check_metadata() {
105
+ let root = fixture_root(task_state());
106
+ init_git(&root);
107
+ write_fixture_file(&root, "README.md", "changed\n");
108
+
109
+ let checked = run_json(
110
+ &root,
111
+ ["task", "run-check", "--check", "diff-check", "--json"],
112
+ );
113
+ assert_eq!(checked["executed"], true);
114
+ assert_eq!(checked["exitCode"], 0);
115
+
116
+ write_verification_checks(
117
+ &root,
118
+ json!([{
119
+ "id": "diff-check",
120
+ "command": "node .naome/bin/naome.js quality check --changed",
121
+ "cwd": ".",
122
+ "purpose": "Updated check command.",
123
+ "cost": "fast",
124
+ "source": "test",
125
+ "evidence": ["README.md"],
126
+ "lastVerified": null
127
+ }]),
128
+ );
129
+ git(&root, ["add", ".naome/verification.json"]);
130
+ git(&root, ["commit", "-m", "update verification metadata"]);
131
+
132
+ let recorded = run_json(
133
+ &root,
134
+ ["task", "record-proof", "--from-proof-plan", "--json"],
135
+ );
136
+
137
+ assert_eq!(recorded["recorded"], false);
138
+ assert_eq!(
139
+ recorded["findings"][0]["id"],
140
+ "task.proof.no_recent_success"
141
+ );
142
+ }
143
+
144
+ #[test]
145
+ fn run_check_diff_check_covers_staged_diff() {
146
+ let root = fixture_root(task_state());
147
+ init_git(&root);
148
+ write_fixture_file(&root, "README.md", "staged trailing whitespace \n");
149
+ git(&root, ["add", "README.md"]);
150
+
151
+ let result = run_json(
152
+ &root,
153
+ [
154
+ "task",
155
+ "run-check",
156
+ "--check",
157
+ "diff-check",
158
+ "--record-proof",
159
+ "--json",
160
+ ],
161
+ );
162
+
163
+ assert_eq!(result["executed"], true);
164
+ assert_ne!(result["exitCode"], 0);
165
+ assert_eq!(result["recordedProof"], false);
166
+ assert!(result["stdoutSummary"]
167
+ .as_str()
168
+ .is_some_and(|summary| summary.contains("trailing whitespace")));
169
+ }
170
+
171
+ #[test]
172
+ fn repair_execute_safe_runs_checks_but_refuses_scope_repairs() {
173
+ let root = fixture_root(task_state());
174
+ init_git(&root);
175
+ write_fixture_file(&root, "README.md", "changed\n");
176
+ write_fixture_file(&root, "src/lib.rs", "outside\n");
177
+
178
+ let scope = run_json(
179
+ &root,
180
+ [
181
+ "task",
182
+ "repair",
183
+ "--plan",
184
+ "remove_out_of_scope_change_src_lib_rs",
185
+ "--execute-safe",
186
+ "--json",
187
+ ],
188
+ );
189
+ assert_eq!(scope["executed"], false);
190
+ assert_eq!(scope["requiresUserApproval"], true);
191
+
192
+ fs::remove_file(root.join("src/lib.rs")).unwrap();
193
+ let check = run_json(
194
+ &root,
195
+ [
196
+ "task",
197
+ "repair",
198
+ "--plan",
199
+ "rerun_diff-check",
200
+ "--execute-safe",
201
+ "--json",
202
+ ],
203
+ );
204
+ assert_eq!(check["executed"], true);
205
+ assert_eq!(check["steps"][0]["schema"], "naome.task.run-check.v1");
206
+ }
207
+
208
+ #[test]
209
+ fn repair_execute_safe_rejects_dry_run_combo_and_unsafe_check_plans() {
210
+ let root = fixture_root(task_state_with_active_task(active_task(json!({
211
+ "requiredCheckIds": ["unsafe-check"],
212
+ "proofResults": []
213
+ }))));
214
+ write_verification_checks(
215
+ &root,
216
+ json!([{
217
+ "id": "unsafe-check",
218
+ "command": "sh -c 'echo unsafe'",
219
+ "cwd": ".",
220
+ "purpose": "Unsafe check for repair planning tests.",
221
+ "cost": "fast",
222
+ "source": "test",
223
+ "evidence": ["README.md"],
224
+ "lastVerified": null
225
+ }]),
226
+ );
227
+ init_git(&root);
228
+ write_fixture_file(&root, "README.md", "changed\n");
229
+
230
+ let combo = Command::new(env!("CARGO_BIN_EXE_naome"))
231
+ .args([
232
+ "task",
233
+ "repair",
234
+ "--plan",
235
+ "rerun_unsafe-check",
236
+ "--dry-run",
237
+ "--execute-safe",
238
+ "--json",
239
+ ])
240
+ .current_dir(&root)
241
+ .output()
242
+ .unwrap();
243
+ assert!(!combo.status.success());
244
+ assert!(String::from_utf8_lossy(&combo.stderr).contains("--dry-run"));
245
+
246
+ let unsafe_repair = run_json(
247
+ &root,
248
+ [
249
+ "task",
250
+ "repair",
251
+ "--plan",
252
+ "rerun_unsafe-check",
253
+ "--execute-safe",
254
+ "--json",
255
+ ],
256
+ );
257
+ assert_eq!(unsafe_repair["executed"], false);
258
+ assert_eq!(unsafe_repair["requiresUserApproval"], true);
259
+ assert!(unsafe_repair["steps"].as_array().unwrap().is_empty());
260
+ }
261
+
262
+ #[test]
263
+ fn run_check_rejects_changed_npm_scripts_from_safe_execution() {
264
+ let root = fixture_root(task_state_with_active_task(active_task(json!({
265
+ "requiredCheckIds": ["task-state-tests"],
266
+ "allowedPaths": ["package.json"],
267
+ "proofResults": []
268
+ }))));
269
+ write_verification_checks(
270
+ &root,
271
+ json!([{
272
+ "id": "task-state-tests",
273
+ "command": "npm run test:task-state",
274
+ "cwd": ".",
275
+ "purpose": "Task-state regression tests.",
276
+ "cost": "medium",
277
+ "source": "test",
278
+ "evidence": ["package.json"],
279
+ "lastVerified": null
280
+ }]),
281
+ );
282
+ init_git(&root);
283
+ write_fixture_file(
284
+ &root,
285
+ "package.json",
286
+ r#"{"scripts":{"test:task-state":"node -e \"process.exit(0)\"}}"#,
287
+ );
288
+
289
+ let result = run_json(
290
+ &root,
291
+ ["task", "run-check", "--check", "task-state-tests", "--json"],
292
+ );
293
+
294
+ assert_eq!(result["executed"], false);
295
+ assert_eq!(result["findings"][0]["id"], "task.check.unsafe_command");
296
+ }
297
+
298
+ #[test]
299
+ fn run_check_rejects_pack_dry_run_as_not_read_only() {
300
+ let root = fixture_root(task_state_with_active_task(active_task(json!({
301
+ "requiredCheckIds": ["package-dry-run"],
302
+ "proofResults": []
303
+ }))));
304
+ write_verification_checks(
305
+ &root,
306
+ json!([{
307
+ "id": "package-dry-run",
308
+ "command": "npm run pack:dry-run",
309
+ "cwd": ".",
310
+ "purpose": "Package dry run.",
311
+ "cost": "medium",
312
+ "source": "test",
313
+ "evidence": ["README.md"],
314
+ "lastVerified": null
315
+ }]),
316
+ );
317
+ init_git(&root);
318
+ write_fixture_file(&root, "README.md", "changed\n");
319
+
320
+ let result = run_json(
321
+ &root,
322
+ ["task", "run-check", "--check", "package-dry-run", "--json"],
323
+ );
324
+
325
+ assert_eq!(result["executed"], false);
326
+ assert_eq!(result["findings"][0]["id"], "task.check.unsafe_command");
327
+ }
328
+
329
+ #[test]
330
+ fn task_loop_read_only_and_execute_safe_drive_proof_to_completion() {
331
+ let root = fixture_root(task_state());
332
+ init_git(&root);
333
+ write_fixture_file(&root, "README.md", "changed\n");
334
+
335
+ let read_only = run_json(&root, ["task", "loop", "--json"]);
336
+ assert_eq!(read_only["schema"], "naome.task.loop.v1");
337
+ assert_eq!(read_only["mode"], "read_only");
338
+ assert!(read_only["executedSteps"].as_array().unwrap().is_empty());
339
+ assert_eq!(
340
+ read_only["status"]["proof"]["missingChecks"],
341
+ json!(["diff-check"])
342
+ );
343
+
344
+ let executed = run_json(&root, ["task", "loop", "--execute-safe", "--json"]);
345
+ assert_eq!(executed["mode"], "execute_safe");
346
+ assert_eq!(
347
+ executed["executedSteps"][0]["schema"],
348
+ "naome.task.run-check.v1"
349
+ );
350
+ assert_eq!(executed["executedSteps"][0]["recordedProof"], true);
351
+
352
+ let completed = run_json(
353
+ &root,
354
+ ["task", "complete", "--from-can-transition", "--json"],
355
+ );
356
+ assert_eq!(completed["schema"], "naome.task.complete.v1");
357
+ assert_eq!(completed["completed"], true);
358
+
359
+ let state: Value =
360
+ serde_json::from_str(&fs::read_to_string(root.join(".naome/task-state.json")).unwrap())
361
+ .unwrap();
362
+ assert_eq!(state["status"], "complete");
363
+ }
364
+
365
+ #[test]
366
+ fn complete_blocks_when_transition_is_not_allowed() {
367
+ let root = fixture_root(task_state_with_active_task(active_task(json!({
368
+ "proofResults": []
369
+ }))));
370
+ init_git(&root);
371
+ write_fixture_file(&root, "README.md", "changed\n");
372
+
373
+ let completed = run_json(
374
+ &root,
375
+ ["task", "complete", "--from-can-transition", "--json"],
376
+ );
377
+
378
+ assert_eq!(completed["completed"], false);
379
+ assert_eq!(
380
+ completed["blockingFindings"][0]["id"],
381
+ "task.proof.missing_check"
382
+ );
383
+ }