## Summary - implement the canonical shared fixture profile model with minimal, standard, and full semantics plus temporary legacy alias resolution - slim default factory behavior for operation runs, backup sets, provider connections, and provider credentials while keeping explicit heavy opt-in states - migrate the first console, navigation, RBAC, and drift caller packs to explicit lean helpers and wire lane comparison reporting into the existing Spec 206 seams - reconcile spec 207 docs, contracts, quickstart guidance, and task tracking with the implemented behavior ## Validation - `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Unit/Support/CreateUserWithTenantProfilesTest.php tests/Unit/Factories/TenantFactoryTest.php tests/Unit/Factories/OperationRunFactoryTest.php tests/Unit/Factories/BackupSetFactoryTest.php tests/Unit/Factories/ProviderConnectionFactoryTest.php tests/Unit/Factories/ProviderCredentialFactoryTest.php tests/Feature/Guards/FixtureCostProfilesGuardTest.php tests/Feature/Guards/FixtureLaneImpactBudgetTest.php tests/Feature/Guards/TestLaneArtifactsContractTest.php tests/Feature/Console/ReconcileOperationRunsCommandTest.php tests/Feature/Console/ReconcileBackupScheduleOperationRunsCommandTest.php tests/Feature/Navigation/RelatedNavigationResolverMemoizationTest.php tests/Feature/Spec080WorkspaceManagedTenantAdminMigrationTest.php tests/Feature/BaselineDriftEngine/FindingFidelityTest.php` - `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent` - `./scripts/platform-test-lane fast-feedback` - `./scripts/platform-test-lane confidence` - `./scripts/platform-test-report fast-feedback` - `./scripts/platform-test-report confidence` ## Lane outcome - `fast-feedback`: 136.400761s vs 176.73623s baseline, status `improved` - `confidence`: 394.5669s vs 394.383441s baseline, status `stable` Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #240
101 lines
3.0 KiB
PHP
101 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\OperationRun;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use App\Models\Workspace;
|
|
use App\Support\OperationRunOutcome;
|
|
use App\Support\OperationRunStatus;
|
|
use App\Support\OperationRunType;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends Factory<OperationRun>
|
|
*/
|
|
class OperationRunFactory extends Factory
|
|
{
|
|
protected $model = OperationRun::class;
|
|
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'tenant_id' => Tenant::factory()->for(Workspace::factory()),
|
|
'workspace_id' => function (array $attributes): int {
|
|
$tenantId = $attributes['tenant_id'] ?? null;
|
|
|
|
if (! is_numeric($tenantId)) {
|
|
return (int) Workspace::factory()->create()->getKey();
|
|
}
|
|
|
|
$tenant = Tenant::query()->whereKey((int) $tenantId)->first();
|
|
|
|
if (! $tenant instanceof Tenant) {
|
|
return (int) Workspace::factory()->create()->getKey();
|
|
}
|
|
|
|
if ($tenant->workspace_id === null) {
|
|
$workspaceId = (int) Workspace::factory()->create()->getKey();
|
|
$tenant->forceFill(['workspace_id' => $workspaceId])->save();
|
|
|
|
return $workspaceId;
|
|
}
|
|
|
|
return (int) $tenant->workspace_id;
|
|
},
|
|
'user_id' => null,
|
|
'initiator_name' => 'System',
|
|
'type' => fake()->randomElement(OperationRunType::values()),
|
|
'status' => OperationRunStatus::Queued->value,
|
|
'outcome' => OperationRunOutcome::Pending->value,
|
|
'run_identity_hash' => fake()->sha256(),
|
|
'summary_counts' => [],
|
|
'failure_summary' => [],
|
|
'context' => [],
|
|
'started_at' => null,
|
|
'completed_at' => null,
|
|
];
|
|
}
|
|
|
|
public function minimal(): static
|
|
{
|
|
return $this->state(fn (): array => [
|
|
'user_id' => null,
|
|
'initiator_name' => 'System',
|
|
]);
|
|
}
|
|
|
|
public function withUser(?User $user = null): static
|
|
{
|
|
return $this->state(fn (): array => [
|
|
'user_id' => $user?->getKey() ?? User::factory(),
|
|
'initiator_name' => $user?->name ?? fake()->name(),
|
|
]);
|
|
}
|
|
|
|
public function forTenant(Tenant $tenant): static
|
|
{
|
|
return $this->state(fn (): array => [
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
'workspace_id' => (int) $tenant->workspace_id,
|
|
]);
|
|
}
|
|
|
|
public function tenantlessForWorkspace(Workspace $workspace): static
|
|
{
|
|
return $this->state(fn (): array => [
|
|
'tenant_id' => null,
|
|
'workspace_id' => (int) $workspace->getKey(),
|
|
]);
|
|
}
|
|
|
|
public function queued(): static
|
|
{
|
|
return $this->state(fn (): array => [
|
|
'status' => OperationRunStatus::Queued->value,
|
|
'outcome' => OperationRunOutcome::Pending->value,
|
|
]);
|
|
}
|
|
}
|