@@ -135,6 +135,29 @@ def test_result_records_the_target(self):
135135 value = json .loads (manifest .read_text ());value ['target' ]= 'gutenberg' ;manifest .write_text (json .dumps (value ))
136136 self .run_client (service )
137137 self .assertEqual (self .outcome ()['target' ],'gutenberg' )
138+ def test_a_flash_convert_finalizes_its_ledger_only_when_the_host_says_so (self ):
139+ # The pack re-runs finalize. A Flash plan passes it only with --flash,
140+ # which the Mac app's host asks for through H2WP_BLOCKPLAN_FLASH=1;
141+ # without it the unreviewed ledger is an incomplete plan, as before.
142+ scripts = self .ws .parent / (self .ws .name + '-scripts' )
143+ shutil .copytree (CLIENT .parent ,scripts ,ignore = shutil .ignore_patterns ('__pycache__' ,'*.png' ,'node_modules' ))
144+ calls = self .ws .parent / (self .ws .name + '-finalize.log' )
145+ (scripts / 'prepare-block-plan.mjs' ).write_text (
146+ "import {appendFileSync} from 'node:fs';\n "
147+ "appendFileSync(%r, process.argv.slice(2).join(' ') + '\\ n');\n "
148+ "process.exit(process.argv.includes('--flash') ? 0 : 1);\n " % str (calls ))
149+ manifest = self .ws / 'conversion-manifest.json'
150+ value = json .loads (manifest .read_text ());value ['schema' ]= 'html2wp/2' ;value ['target' ]= 'gutenberg' ;manifest .write_text (json .dumps (value ))
151+ service = self .service ()
152+ def run (** extra ):
153+ env = dict (os .environ );env .pop ('H2WP_BLOCKPLAN_FLASH' ,None );env .update (extra )
154+ subprocess .run (['bash' ,str (scripts / 'convert-remote.sh' ),str (self .ws ),'--api=' + service .url ,'--key=local-test' ],text = True ,capture_output = True ,env = env ,timeout = 20 )
155+ return self .outcome ()['code' ]
156+ self .assertEqual (run (),'INVALID_BLOCK_PLAN' )
157+ self .assertNotIn ('--flash' ,calls .read_text ())
158+ self .assertNotEqual (run (H2WP_BLOCKPLAN_FLASH = '1' ),'INVALID_BLOCK_PLAN' )
159+ self .assertEqual (calls .read_text ().splitlines ()[- 1 ].split ()[- 1 ],'--flash' )
160+ self .assertEqual (run (H2WP_BLOCKPLAN_FLASH = 'yes' ),'INVALID_BLOCK_PLAN' ,'only the exact value asks for it' )
138161 def test_strict_expired_fails_without_new_job (self ):
139162 service = self .service ();self .run_client (service );service .refusals = [(403 ,'expired' )]
140163 self .run_client (service ,ok = False ,H2WP_STRICT_JOBS = '1' )
0 commit comments