Files
api/services/nginx/app/tests/Unit/XLVask/XLVaskUsageRouteContractTest.php
T
Jeppe Bandopenhands 5441fea665 fix(api): simplify XLVask Selvvask surface by removing AI autopilot pipeline (#367)
## Summary

Removes the XLVask autopilot / automation / MiniMax / OpenAI pipeline
and the related module config, CLI, cron, and migration scaffolding. The
Selvvask view (Superuser -> Fakturaer -> Periode -> Selvvask) is reduced
to a single read-only listing of usage logs plus operator-driven ignore
/ unignore / accept / reject endpoints gated on the
`review_xlvask_usage_order` permission.

See `inventory/self-serve-inventory.md` for the full surface map.

## Test plan

- [x] `vendor/bin/pest --testsuite=Unit` -> **1266 passed**, 1 unrelated
pre-existing failure (`BirdControlPlaneActivationTest`, needs
`PLENO_REPO_ROOT_FOR_TESTS`).
- [x] `php -l` on every modified PHP file -> no syntax errors.
- [x] Grep validation -> zero production-code references to removed
surfaces (`xlvask_autopilot_service`, `xlvask_automation_service`,
`xlvask_automation_policy_service`, `EnsureXLVaskAutomationSchema`,
`runScheduledAutomationIfReady`, `processAutopilotQueue`, `MiniMax`,
`minimax`, ...).
- [ ] Qodana + Tests workflows green on this PR.

Co-authored-by: openhands <openhands@all-hands.dev>

---------

Co-authored-by: openhands <openhands@all-hands.dev>
2026-08-12 20:02:30 +02:00

231 lines
11 KiB
PHP

<?php
it('exposes direct linked order metadata on XL Vask usage order rows', function (): void {
$route = file_get_contents(WD . '/routes/xlvaskUsageLogsRoute.php');
expect($route)->not->toBeFalse();
$route = (string)$route;
expect($route)
->toContain('$linked_order_ids_by_wash_id = []')
->and($route)->toContain('array_key_exists($wash_id, $linked_order_ids_by_wash_id)')
->and($route)->toContain('selectByWashId($wash_id)')
->and($route)->toContain("'linked_order_id' => \$linked_order_id")
->and($route)->toContain("'usage_log_id' => \$id");
});
it('limits the usage-logs endpoint to the reviewer permission set', function (): void {
$route = file_get_contents(WD . '/routes/xlvaskUsageLogsRoute.php');
expect($route)->not->toBeFalse();
$route = (string)$route;
expect($route)
->toContain("list_xlvask_usage_orders_own")
->toContain("list_xlvask_usage_orders_all")
->not->toContain('xlvask_autopilot_service')
->not->toContain('xlvask_automation_service')
->not->toContain('xlvask_automation_policy_service')
->not->toContain('manage_xlvask_usage_automation')
->not->toContain('evaluateUsageLogRow')
->not->toContain('source_hash')
->not->toContain('source_revision')
->not->toContain('import_state')
->not->toContain('resolution_state')
->not->toContain('certainty')
->not->toContain('planned_action')
->not->toContain('expected_version')
->not->toContain('last_run_id');
expect($route)
->toContain("if (\$allowedHallIds === [])")
->toContain("No XL Vask hall scope is available', 403")
->not->toContain('__no_authorized_xlvask_hall__');
});
it('returns cached amount summaries on XL Vask usage order rows without widening the usage-log object payload', function (): void {
$route = file_get_contents(WD . '/routes/xlvaskUsageLogsRoute.php');
expect($route)->not->toBeFalse();
$route = (string)$route;
expect($route)
->toContain('$amount_summary = $xlvask_usage_logs->getAmountSummaryReadOnly($log)')
->and($route)->toContain("\$usage_log_payload = array_intersect_key(\$log, array_flip([")
->and($route)->toContain("\$tmp->setProperties(\$usage_log_payload)")
->and($route)->toContain("\$tmp_res['order']['total_net_amount'] = \$amount_summary['total_net_amount']")
->and($route)->toContain("\$tmp_res['order']['xlvask_primary_product_name'] = \$amount_summary['primary_product_name']")
->and($route)->toContain("\$tmp_res['order']['xlvask_amount_cached'] = \$amount_summary['cached']");
});
it('keeps ignore metadata out of the strict legacy XL Vask helper payload', function (): void {
$route = file_get_contents(WD . '/routes/xlvaskUsageLogsRoute.php');
expect($route)->not->toBeFalse();
$route = (string)$route;
expect($route)
->not->toContain("'source_hash'")
->not->toContain("'source_revision'")
->not->toContain("'import_state'")
->not->toContain("'resolution_state'")
->not->toContain("'certainty'")
->not->toContain("'planned_action'")
->not->toContain("'expected_version'")
->not->toContain("'last_run_id'");
});
it('exposes review, accept, reject and ignore endpoints gated on review_xlvask_usage_order', function (): void {
$route = file_get_contents(WD . '/routes/xlvaskUsageLogsRoute.php');
expect($route)->not->toBeFalse();
$route = (string)$route;
expect($route)
->toContain("patch('/modules/xlvask/services/usage/orders/{id}/ignore'")
->toContain("post('/modules/xlvask/services/usage/orders/{id}/unignore'")
->toContain("post('/modules/xlvask/services/usage/orders/{id}/accept'")
->toContain("post('/modules/xlvask/services/usage/orders/{id}/reject'")
->toContain("requirePermission('review_xlvask_usage_order')")
->toContain("'ignored_at' => \$log['ignored_at'] ?? null")
->toContain("'ignored_by' => isset(\$log['ignored_by']) ? (int)\$log['ignored_by'] : null")
->toContain("'ignored_reason' => \$log['ignored_reason'] ?? null")
->not->toContain('Ignored at server-generated automation decision preview');
});
it('exposes a reviewer summary endpoint that does not invoke the autopilot service', function (): void {
$route = file_get_contents(WD . '/routes/xlvaskUsageLogsRoute.php');
expect($route)->not->toBeFalse();
$route = (string)$route;
expect($route)
->toContain("get('/modules/xlvask/services/usage/orders/summary'")
->toContain('(new xlvask_usage_logs_o())->summarizeUsageOrdersReadOnly(')
->not->toContain('xlvask_autopilot_service()->getSummary(');
});
it('routes legacy autopilot, calibration and policy transition paths through 410 Gone stubs', function (): void {
$route = file_get_contents(WD . '/routes/xlvaskUsageLogsRoute.php');
expect($route)->not->toBeFalse();
$route = (string)$route;
expect($route)
->not->toContain("'/modules/xlvask/services/usage/autopilot-runs'")
->not->toContain("'/modules/xlvask/services/usage/autopilot-runs/active'")
->not->toContain("'/modules/xlvask/services/usage/automation/admin/policy/previews'")
->not->toContain("'/modules/xlvask/services/usage/automation/admin/policy/apply'")
->not->toContain("'/modules/xlvask/services/usage/automation/admin/halt'")
->not->toContain("'/modules/xlvask/services/usage/automation/admin/calibrations/backtest'")
->not->toContain("'/modules/xlvask/services/usage/automation/admin/calibrations/labels'")
->not->toContain("'/modules/xlvask/services/usage/automation/admin/calibrations/{id}/activate'")
->not->toContain("'/modules/xlvask/services/usage/automation/admin/wash-id-uniqueness/activate'")
->not->toContain("'/modules/xlvask/services/usage/automation/decisions/preview'")
->not->toContain("'/modules/xlvask/services/usage/automation/decisions/apply'")
->not->toContain("'/modules/xlvask/services/usage/automation/capabilities'")
->not->toContain("'/modules/xlvask/services/usage/automation/admin/readiness'");
});
it('allows all-only permission and uses every configured scanner hall for all scope', function (): void {
$route = file_get_contents(WD . '/routes/xlvaskUsageLogsRoute.php');
expect($route)->not->toBeFalse();
$route = (string)$route;
expect($route)
->toContain("if (!\$this->hasPermission(\$permission_list_all))")
->toContain("if (\$this->hasPermission('list_xlvask_usage_orders_all'))")
->toContain("if (!\$this->hasPermission('list_xlvask_usage_orders_all'))")
->toContain('private function allowedHallIdsForUser(object $user): array')
->not->toContain('private static function allowedHallIdsForUser')
->toContain('SELECT DISTINCT HallId FROM plate_scanners');
});
it('does not let pending automation schema block ordinary invoice period operations', function (): void {
$bootstrap = (string)file_get_contents(WD . '/classes/invoice_period_flag_schema_bootstrap.php');
expect($bootstrap)
->not->toContain('xlvask_usage_logs_schema_bootstrap::ensureTables()')
->toContain('XL Vask automation migration is pending');
});
it('does not invoke the autopilot service anywhere on the usage-log listing path', function (): void {
$route = file_get_contents(WD . '/routes/xlvaskUsageLogsRoute.php');
$object = file_get_contents(WD . '/objects/xlvask_usage_logs_o.php');
expect($route)
->not->toBeFalse()
->and($object)->not->toBeFalse();
expect((string)$route)
->not->toContain('xlvask_autopilot_service')
->not->toContain('xlvask_automation_policy_service')
->not->toContain('readAutomationStateByUsageLogId')
->not->toContain('evaluateUsageLogRow');
expect((string)$object)
->toContain('summarizeUsageOrdersReadOnly')
->toContain('getAmountSummaryReadOnly');
});
it('removes the AI autopilot and policy service files entirely', function (): void {
expect(file_exists(WD . '/classes/xlvask_autopilot_service.php'))->toBeFalse();
expect(file_exists(WD . '/classes/xlvask_automation_service.php'))->toBeFalse();
expect(file_exists(WD . '/classes/xlvask_automation_policy_service.php'))->toBeFalse();
expect(file_exists(WD . '/classes/minimax.php'))->toBeFalse();
expect(is_dir(WD . '/modules/miniMax'))->toBeFalse();
expect(file_exists(WD . '/modules/xlvask/AUTOMATION_RUNBOOK.md'))->toBeFalse();
expect(file_exists(WD . '/cron/EnsureXLVaskAutomationSchema.php'))->toBeFalse();
});
it('removes the MiniMax config endpoints from moduleConfigRoute and the cli migrate command', function (): void {
$route = (string)file_get_contents(WD . '/routes/moduleConfigRoute.php');
expect($route)
->not->toContain("'/minimax/config'")
->not->toContain('modules_minimax_config')
->not->toContain('MiniMax config');
$cli = (string)file_get_contents(WD . '/cli.php');
expect($cli)
->not->toContain("'xlvask-automation-migrate'")
->not->toContain('EnsureXLVaskAutomationSchema.php');
});
it('exposes the simplified operator flow in OpenAPI and removes the AI autopilot surface', function (): void {
$openApi = file_get_contents(WD . '/openapi.yaml');
expect($openApi)->not->toBeFalse();
$openApi = (string)$openApi;
expect($openApi)
->toContain('/modules/xlvask/services/usage/orders/summary:')
->toContain('/modules/xlvask/services/usage/orders/{id}/ignore:')
->toContain('/modules/xlvask/services/usage/orders/{id}/unignore:')
->toContain('/modules/xlvask/services/usage/orders/{id}/accept:')
->toContain('/modules/xlvask/services/usage/orders/{id}/reject:')
->not->toContain('/modules/xlvask/services/usage/autopilot-runs:')
->not->toContain('/modules/xlvask/services/usage/automation/decisions/preview:')
->not->toContain('/modules/xlvask/services/usage/automation/decisions/apply:')
->not->toContain('/modules/xlvask/services/usage/automation/admin/readiness:')
->not->toContain('/modules/xlvask/services/usage/automation/admin/policy/previews:')
->not->toContain('/modules/xlvask/services/usage/automation/admin/policy/apply:')
->not->toContain('/modules/xlvask/services/usage/automation/admin/halt:')
->not->toContain('/modules/xlvask/services/usage/automation/admin/calibrations/')
->not->toContain('/modules/xlvask/services/usage/automation/admin/wash-id-uniqueness/')
->not->toContain('/modules/xlvask/services/usage/automation/capabilities:')
->not->toContain('/modules/xlvask/services/usage/autopilot-runs/{id}:')
->not->toContain('/modules/xlvask/services/usage/autopilot-runs/active:')
->not->toContain('xlvaskAutomationPolicyService')
->not->toContain('xlvaskAutomationService')
->not->toContain('xlvaskAutopilotService');
});