Skip to content

Commit 4610f3c

Browse files
committed
convert-remote: a Flash convert finalizes its ledger only when the host asks (from e9edbda)
1 parent 2dda955 commit 4610f3c

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎skills/html2wp/assets/scripts/convert-remote.sh‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,14 @@ MANIFEST_SCHEMA="$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]
309309
# v2 schema or an explicit gutenberg target), for the result record.
310310
RESULT_TARGET="$(python3 -c 'import json,sys; m=json.load(open(sys.argv[1])); print("gutenberg" if m.get("schema")=="html2wp/2" or m.get("target")=="gutenberg" else "html")' "$WS/conversion-manifest.json" 2>/dev/null || true)"
311311
if [ "$MANIFEST_SCHEMA" = "html2wp/2" ]; then
312-
if ! node "$SCRIPT_DIR/prepare-block-plan.mjs" finalize --manifest="$WS/conversion-manifest.json"; then
312+
# A Flash delivery finalizes the plan it recorded unreviewed: the Mac app's
313+
# host sets H2WP_BLOCKPLAN_FLASH=1 for a Flash convert (never a coordinator,
314+
# never the model), and --flash counts the ledger's entries as covered. The
315+
# theme stays labelled Flash, and gutenberg-package.py refuses it as full
316+
# packaging evidence while an entry has no reason.
317+
FLASH_ARGS=()
318+
[ "${H2WP_BLOCKPLAN_FLASH:-}" = "1" ] && FLASH_ARGS=(--flash)
319+
if ! node "$SCRIPT_DIR/prepare-block-plan.mjs" finalize --manifest="$WS/conversion-manifest.json" ${FLASH_ARGS[@]+"${FLASH_ARGS[@]}"}; then
313320
fail_with INVALID_BLOCK_PLAN pack "Gutenberg plan is incomplete or stale" \
314321
"resolve .gutenberg/check-report.json and complete worker checkpoints before uploading"
315322
fi

‎skills/html2wp/assets/scripts/gutenberg-test-client.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)