@@ -31,6 +31,9 @@ def _office_args(**overrides):
3131 "output_root" : "~/Documents/SourceOS/agent-output" ,
3232 "downloads_root" : "~/Downloads/SourceOS/agent-downloads" ,
3333 "template_root" : "~/dev" ,
34+ "execute" : False ,
35+ "policy_ok" : False ,
36+ "evidence_out" : None ,
3437 }
3538 values .update (overrides )
3639 return _Args (** values )
@@ -77,8 +80,67 @@ def test_office_generate_dry_run_via_main(self):
7780 ])
7881 self .assertEqual (rc , 0 )
7982
80- def test_office_generate_no_dry_run_rejected (self ):
81- args = _office_args (dry_run = False , template = None , prompt_ref = None , data_ref = None )
83+ def test_office_generate_execute_requires_policy_ok (self ):
84+ args = _office_args (
85+ execute = True ,
86+ policy_ok = False ,
87+ format = "md" ,
88+ template = None ,
89+ prompt_ref = None ,
90+ data_ref = None ,
91+ )
92+ self .assertEqual (office .generate (args ), 1 )
93+
94+ def test_office_generate_execute_rejects_binary_formats (self ):
95+ with tempfile .TemporaryDirectory () as tmpdir :
96+ args = _office_args (
97+ execute = True ,
98+ policy_ok = True ,
99+ format = "docx" ,
100+ output_root = tmpdir ,
101+ template = None ,
102+ prompt_ref = None ,
103+ data_ref = None ,
104+ )
105+ self .assertEqual (office .generate (args ), 1 )
106+
107+ def test_office_generate_execute_writes_markdown_and_evidence (self ):
108+ with tempfile .TemporaryDirectory () as tmpdir :
109+ evidence_path = os .path .join (tmpdir , "evidence" , "office.json" )
110+ rc = main ([
111+ "office" ,
112+ "generate" ,
113+ "--execute" ,
114+ "--policy-ok" ,
115+ "--artifact-type" ,
116+ "document" ,
117+ "--format" ,
118+ "md" ,
119+ "--title" ,
120+ "Safe Report" ,
121+ "--output-root" ,
122+ tmpdir ,
123+ "--evidence-out" ,
124+ evidence_path ,
125+ ])
126+ self .assertEqual (rc , 0 )
127+ self .assertTrue (os .path .exists (os .path .join (tmpdir , "safe-report.md" )))
128+ with open (evidence_path , "r" , encoding = "utf-8" ) as handle :
129+ evidence = json .load (handle )
130+ self .assertEqual (evidence ["kind" ], "OfficeArtifactEvidence" )
131+ self .assertEqual (evidence ["operation" ], "generate" )
132+ self .assertEqual (evidence ["status" ], "requires-review" )
133+
134+ def test_office_generate_execute_rejects_whole_home_output_root (self ):
135+ args = _office_args (
136+ execute = True ,
137+ policy_ok = True ,
138+ format = "md" ,
139+ output_root = "~" ,
140+ template = None ,
141+ prompt_ref = None ,
142+ data_ref = None ,
143+ )
82144 self .assertEqual (office .generate (args ), 1 )
83145
84146 def test_office_convert_dry_run_via_main (self ):
@@ -91,10 +153,21 @@ def test_office_convert_dry_run_via_main(self):
91153 finally :
92154 os .unlink (tmp_path )
93155
94- def test_office_convert_no_dry_run_rejected (self ):
95- args = _office_args (dry_run = False , input = "/tmp/example.docx" , to = "pdf" )
156+ def test_office_convert_execute_requires_policy_ok (self ):
157+ args = _office_args (execute = True , policy_ok = False , input = "/tmp/example.docx" , to = "pdf" )
96158 self .assertEqual (office .convert (args ), 1 )
97159
160+ def test_office_convert_execute_missing_input_rejected (self ):
161+ with tempfile .TemporaryDirectory () as tmpdir :
162+ args = _office_args (
163+ execute = True ,
164+ policy_ok = True ,
165+ input = "/nonexistent/example.docx" ,
166+ to = "pdf" ,
167+ output_root = tmpdir ,
168+ )
169+ self .assertEqual (office .convert (args ), 1 )
170+
98171 def test_office_inspect_valid_file (self ):
99172 with tempfile .NamedTemporaryFile (suffix = ".txt" , mode = "w" , delete = False ) as handle :
100173 handle .write ("hello" )
@@ -109,14 +182,12 @@ def test_office_inspect_missing_file(self):
109182
110183 def test_office_evidence_inspect_valid (self ):
111184 payload = {
112- "type" : "OfficeArtifactEvidence" ,
113- "officeArtifact" : {
114- "artifactId" : "office-artifact-test" ,
115- "workroomId" : "workroom-test" ,
116- "artifactType" : "document" ,
117- "format" : "docx" ,
118- "evidenceRefs" : ["evidence://office/test" ],
119- },
185+ "kind" : "OfficeArtifactEvidence" ,
186+ "artifactId" : "office-artifact-test" ,
187+ "workroomId" : "workroom-test" ,
188+ "artifactType" : "document" ,
189+ "format" : "docx" ,
190+ "evidenceRefs" : ["evidence://office/test" ],
120191 }
121192 with tempfile .NamedTemporaryFile (suffix = ".json" , mode = "w" , delete = False ) as handle :
122193 json .dump (payload , handle )
0 commit comments