TenantAtlas/apps/platform/tests/Feature/Baselines/BaselineSnapshotBackfillTest.php
ahmido ce0615a9c1 Spec 182: relocate Laravel platform to apps/platform (#213)
## Summary
- move the Laravel application into `apps/platform` and keep the repository root for orchestration, docs, and tooling
- update the local command model, Sail/Docker wiring, runtime paths, and ignore rules around the new platform location
- add relocation quickstart/contracts plus focused smoke coverage for bootstrap, command model, routes, and runtime behavior

## Validation
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/PlatformRelocation`
- integrated browser smoke validated `/up`, `/`, `/admin`, `/admin/choose-workspace`, and tenant route semantics for `200`, `403`, and `404`

## Remaining Rollout Checks
- validate Dokploy build context and working-directory assumptions against the new `apps/platform` layout
- confirm web, queue, and scheduler processes all start from the expected working directory in staging/production
- verify no legacy volume mounts or asset-publish paths still point at the old root-level `public/` or `storage/` locations

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #213
2026-04-08 08:40:47 +00:00

114 lines
4.6 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\BaselineProfile;
use App\Models\BaselineSnapshot;
use App\Models\BaselineSnapshotItem;
use App\Models\OperationRun;
use App\Models\Workspace;
use App\Support\Baselines\BaselineReasonCodes;
use App\Support\Baselines\BaselineSnapshotLifecycleState;
use App\Support\OperationRunOutcome;
use App\Support\OperationRunType;
use Illuminate\Database\Migrations\Migration;
function classifyLegacySnapshotForTest(BaselineSnapshot $snapshot): array
{
/** @var Migration $migration */
$migration = require base_path('database/migrations/2026_03_23_000001_add_lifecycle_state_to_baseline_snapshots_table.php');
$reflection = new ReflectionMethod($migration, 'classifyLegacySnapshot');
$reflection->setAccessible(true);
return $reflection->invoke(
$migration,
(object) [
'id' => (int) $snapshot->getKey(),
'workspace_id' => (int) $snapshot->workspace_id,
'baseline_profile_id' => (int) $snapshot->baseline_profile_id,
'captured_at' => $snapshot->captured_at,
'created_at' => $snapshot->created_at,
'updated_at' => $snapshot->updated_at,
'summary_jsonb' => json_encode($snapshot->summary_jsonb),
],
is_array($snapshot->summary_jsonb) ? $snapshot->summary_jsonb : [],
BaselineSnapshotItem::query()->where('baseline_snapshot_id', (int) $snapshot->getKey())->count(),
);
}
it('classifies legacy snapshots as complete when summary counts prove completion', function (): void {
$workspace = Workspace::factory()->create();
$profile = BaselineProfile::factory()->active()->create([
'workspace_id' => (int) $workspace->getKey(),
]);
$snapshot = BaselineSnapshot::factory()->complete()->create([
'workspace_id' => (int) $workspace->getKey(),
'baseline_profile_id' => (int) $profile->getKey(),
'summary_jsonb' => ['total_items' => 2],
]);
BaselineSnapshotItem::factory()->count(2)->create([
'baseline_snapshot_id' => (int) $snapshot->getKey(),
]);
$classification = classifyLegacySnapshotForTest($snapshot);
expect($classification['lifecycle_state'])->toBe(BaselineSnapshotLifecycleState::Complete->value)
->and(data_get($classification, 'completion_meta.expected_items'))->toBe(2)
->and(data_get($classification, 'completion_meta.persisted_items'))->toBe(2);
});
it('classifies proven empty legacy captures as complete when the producer run confirms zero subjects', function (): void {
$workspace = Workspace::factory()->create();
$profile = BaselineProfile::factory()->active()->create([
'workspace_id' => (int) $workspace->getKey(),
]);
$snapshot = BaselineSnapshot::factory()->complete()->create([
'workspace_id' => (int) $workspace->getKey(),
'baseline_profile_id' => (int) $profile->getKey(),
'summary_jsonb' => ['total_items' => 0],
]);
OperationRun::factory()->create([
'workspace_id' => (int) $workspace->getKey(),
'type' => OperationRunType::BaselineCapture->value,
'outcome' => OperationRunOutcome::Succeeded->value,
'context' => [
'baseline_profile_id' => (int) $profile->getKey(),
'result' => ['snapshot_id' => (int) $snapshot->getKey()],
'baseline_capture' => ['subjects_total' => 0],
],
'completed_at' => now(),
]);
$classification = classifyLegacySnapshotForTest($snapshot);
expect($classification['lifecycle_state'])->toBe(BaselineSnapshotLifecycleState::Complete->value)
->and(data_get($classification, 'completion_meta.was_empty_capture'))->toBeTrue();
});
it('classifies ambiguous legacy snapshots as incomplete with a conservative reason code', function (): void {
$workspace = Workspace::factory()->create();
$profile = BaselineProfile::factory()->active()->create([
'workspace_id' => (int) $workspace->getKey(),
]);
$snapshot = BaselineSnapshot::factory()->complete()->create([
'workspace_id' => (int) $workspace->getKey(),
'baseline_profile_id' => (int) $profile->getKey(),
'summary_jsonb' => ['total_items' => 2],
]);
BaselineSnapshotItem::factory()->create([
'baseline_snapshot_id' => (int) $snapshot->getKey(),
]);
$classification = classifyLegacySnapshotForTest($snapshot);
expect($classification['lifecycle_state'])->toBe(BaselineSnapshotLifecycleState::Incomplete->value)
->and(data_get($classification, 'completion_meta.finalization_reason_code'))->toBe(BaselineReasonCodes::SNAPSHOT_LEGACY_CONTRADICTORY);
});