Fix child script detection in scheduler

Previous regex only matched literal bash/source calls with bare paths.
Orchestrators use shell variables like \$SCRIPT_DIR/../Transcodes/script.sh
and \$SCRIPTS_ROOT/Category/script.sh — the old pattern missed all of these.

New regex captures the Category/script.sh portion from either pattern,
requires at least one subdirectory (excludes load_config.sh and root-level
utilities), and validates each candidate against the filesystem.

transcode_management now correctly shows transcode_cleanup and transcode_manager.
Orchestrators using master.conf config arrays for dynamic dispatch still show
no children — correct, as those lists cannot be statically parsed.
This commit is contained in:
Gmer4Lfe
2026-05-23 17:04:36 -04:00
parent f6f3655810
commit b00918e080
@@ -79,21 +79,34 @@ function vv_job_tree(): array {
return $orchs;
}
// Parse an orchestrator script to find which child scripts it calls
// Parse an orchestrator script to find which child scripts it calls.
// Handles two common patterns:
// $SCRIPT_DIR/../Category/script.sh (relative via variable)
// $SCRIPTS_ROOT/Category/script.sh (absolute root via variable)
// Root-level files (load_config.sh, etc.) are excluded — must be in a subdirectory.
// Validates each candidate against the filesystem to filter false positives.
function vv_script_children(string $orchPath, array $schedule): array {
$scriptsDir = SCRIPTS_DIR;
$content = file_get_contents($orchPath) ?: '';
$children = [];
$seen = [];
// Match $ANY_VAR/../Category/script.sh or $ANY_VAR/Category/script.sh
// Capture only the Category/script.sh portion (requires at least one subdirectory)
preg_match_all(
'/\$[A-Z_]+\/(?:\.\.\/)?([A-Za-z][A-Za-z0-9_.\-]*\/[A-Za-z0-9_.\-]+\.sh)/',
$content,
$m
);
// Match: bash "path/to/script.sh" or source path/to/script.sh
preg_match_all('/(?:bash|source|\.)\s+"?([^"\s]+\.sh)"?/m', $content, $m);
foreach ($m[1] as $rel) {
// Normalise relative paths
$rel = ltrim(str_replace($scriptsDir . '/', '', $rel), './');
$id = $rel;
$entry = $schedule[$id] ?? ['enabled' => false, 'cron' => ''];
if (isset($seen[$rel])) continue;
if (!file_exists("$scriptsDir/$rel")) continue;
$seen[$rel] = true;
$entry = $schedule[$rel] ?? ['enabled' => false, 'cron' => ''];
$children[] = [
'id' => $id,
'id' => $rel,
'label' => basename($rel, '.sh'),
'type' => 'script',
'enabled' => (bool)($entry['enabled'] ?? false),