diff --git a/deploy/finance-batch-imports.json b/deploy/finance-batch-imports.json index 673bdba1..ced46090 100644 --- a/deploy/finance-batch-imports.json +++ b/deploy/finance-batch-imports.json @@ -23,6 +23,7 @@ "jst-order-labels:import", "business:import-jushuitan-shop-balances", "pinduoduo-bills:import-authoritative", + "planting-details:sync-work-orders", "planting-details:import", "product-catalog:import-authoritative-export", "product:monthly-weighted-average:base", diff --git a/deploy/run-finance-batch.sh b/deploy/run-finance-batch.sh index 0a90b63f..a3d887fa 100644 --- a/deploy/run-finance-batch.sh +++ b/deploy/run-finance-batch.sh @@ -8,7 +8,7 @@ is_import=0 CAIWU_BATCH_CALLER_DIR="$PWD" export CAIWU_BATCH_CALLER_DIR case "${1:-}" in - *:import|*:import-*|*:import:*|product:monthly-weighted-average:base) is_import=1 ;; + *:import|*:import-*|*:import:*|product:monthly-weighted-average:base|planting-details:sync-work-orders) is_import=1 ;; jushuitan:sync-shipping|store-receipt:order-match:sync|store-receipt:product-cost:sync|store-receipt:auto-resync|order-data:warm-shop-candidates|business-mirror:sync-tables|business-mirror:sync-ding-process-details|business-mirror:process-ding-refresh-requests|business-mirror:index-work-order-waybills|business-mirror:refresh-paid-sales|account-bills:exports:run|finance-ledger:recalculate|product:monthly-weighted-average:auto|product:monthly-weighted-average:compute|product:monthly-weighted-average:report|finance:monthly-weighted-product-cost:auto) ;; *) echo 'Unsupported finance batch command' >&2; exit 64 ;; esac diff --git a/tests/Unit/Deployment/FinanceBatchIsolationTest.php b/tests/Unit/Deployment/FinanceBatchIsolationTest.php index 75a97694..00110056 100644 --- a/tests/Unit/Deployment/FinanceBatchIsolationTest.php +++ b/tests/Unit/Deployment/FinanceBatchIsolationTest.php @@ -108,6 +108,36 @@ class FinanceBatchIsolationTest extends TestCase } } + public function test_planting_work_order_sync_uses_the_isolated_import_entry(): void + { + $directory = sys_get_temp_dir() . '/caiwu-planting-import-' . bin2hex(random_bytes(6)); + mkdir($directory); + file_put_contents($directory . '/run-finance-import.py', ''); + file_put_contents( + $directory . '/python3', + '#!/bin/sh' . "\n" . 'printf "%s\n" "$@" > "$CAIWU_CAPTURE"' . "\n", + ); + chmod($directory . '/python3', 0700); + + try { + $process = $this->runBatch($directory, [ + 'planting-details:sync-work-orders', + '--month=2026-10', + ]); + + $this->assertTrue($process->isSuccessful(), $process->getErrorOutput()); + $arguments = file($directory . '/called', FILE_IGNORE_NEW_LINES); + $this->assertContains($directory . '/run-finance-import.py', $arguments); + $this->assertContains('planting-details:sync-work-orders', $arguments); + $this->assertContains('--month=2026-10', $arguments); + } finally { + foreach (glob($directory . '/*') as $path) { + unlink($path); + } + rmdir($directory); + } + } + public function test_business_mirror_history_backfill_runs_in_the_isolated_batch_profile(): void { $directory = sys_get_temp_dir() . '/caiwu-mirror-batch-' . bin2hex(random_bytes(6)); diff --git a/tests/Unit/Deployment/FinanceImportRuntimeTest.php b/tests/Unit/Deployment/FinanceImportRuntimeTest.php index 81c0afbc..420d6023 100644 --- a/tests/Unit/Deployment/FinanceImportRuntimeTest.php +++ b/tests/Unit/Deployment/FinanceImportRuntimeTest.php @@ -51,6 +51,19 @@ class FinanceImportRuntimeTest extends TestCase (new RequireImportBatchContainer())->handle($this->starting('product:monthly-weighted-average:base')); } + public function test_work_order_sync_is_registered_as_a_protected_import(): void + { + config([ + 'finance_batch.import_commands' => [ + 'planting-details:sync-work-orders', + ], + ]); + + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('run-finance-batch.sh'); + (new RequireImportBatchContainer())->handle($this->starting('planting-details:sync-work-orders')); + } + public function test_production_batch_runtime_can_import_and_health_checks_stay_available(): void { $listener = new RequireImportBatchContainer();