feat: old channel

This commit is contained in:
hashbro
2026-10-07 05:19:52 +08:00
parent 2d3b6e1f2c
commit ba5d3c5731
30 changed files with 1517 additions and 896 deletions
+99 -23
View File
@@ -29,6 +29,7 @@ class ChannelProjectServiceTest extends TestCase
'coruna.channel_builder.python' => 'python3',
'coruna.channel_builder.artifact_root' => storage_path('app/channel-artifacts-test'),
'coruna.channel_builder.timeout' => 30,
'coruna.channel_builder.seed' => '11111111111111111111111111111111',
'coruna.channel_builder_new.python' => 'python3',
'coruna.channel_builder_new.state_root' => storage_path('app/channel-builder-new-test'),
'coruna.channel_domains' => ['fallback.test'],
@@ -102,12 +103,15 @@ class ChannelProjectServiceTest extends TestCase
return str_contains($joined, 'new_project.py')
&& str_contains($joined, self::CHANNEL_ID)
&& str_contains($joined, '--support-template')
&& str_contains($joined, 'blank');
&& str_contains($joined, 'blank')
&& str_contains($joined, '--deployment-seed')
&& str_contains($joined, '11111111111111111111111111111111')
&& str_contains($joined, '--reporting-seed');
});
}
#[Test]
public function it_forwards_optional_seeds_to_builder(): void
public function it_forwards_env_seed_and_ignores_request_seeds(): void
{
Process::fake([
'*' => Process::result(output: $this->fakeBuildResult(['seeds_initialized' => false, 'sync_rebuilt' => false])),
@@ -116,41 +120,30 @@ class ChannelProjectServiceTest extends TestCase
app(ChannelProjectService::class)->generate(
self::CHANNEL_ID,
'test',
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
'cccccccccccccccccccccccccccccccc',
'dddddddddddddddddddddddddddddddd',
);
Process::assertRan(function ($process) {
$joined = is_array($process->command) ? implode(' ', $process->command) : (string) $process->command;
return str_contains($joined, '--deployment-seed')
&& str_contains($joined, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
&& str_contains($joined, '11111111111111111111111111111111')
&& str_contains($joined, '--reporting-seed')
&& substr_count($joined, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa') >= 2;
&& ! str_contains($joined, 'cccccccccccccccccccccccccccccccc')
&& ! str_contains($joined, 'dddddddddddddddddddddddddddddddd');
});
}
#[Test]
public function it_rejects_partial_seed_pair(): void
public function old_builder_requires_env_seed(): void
{
config(['coruna.channel_builder.seed' => '']);
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('deployment_seed 与 reporting_seed 必须同时提供');
$this->expectExceptionMessage('CORUNA_CHANNEL_SEED');
app(ChannelProjectService::class)->generate(self::CHANNEL_ID, 'test', 'only-one', null);
}
#[Test]
public function it_rejects_mismatched_seed_pair(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('deployment_seed 与 reporting_seed 必须相同');
app(ChannelProjectService::class)->generate(
self::CHANNEL_ID,
'test',
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
);
app(ChannelProjectService::class)->generate(self::CHANNEL_ID, 'test');
}
#[Test]
@@ -664,6 +657,89 @@ class ChannelProjectServiceTest extends TestCase
});
}
#[Test]
public function it_rebuilds_existing_old_channels_in_place(): void
{
$otherOld = 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb';
Channel::query()->create([
'channel_id' => self::CHANNEL_ID,
'builder_type' => Channel::BUILDER_OLD,
'user_id' => 0,
'status' => 1,
]);
Channel::query()->create([
'channel_id' => $otherOld,
'builder_type' => Channel::BUILDER_OLD,
'user_id' => 0,
'status' => 1,
]);
Channel::query()->create([
'channel_id' => self::NEW_CHANNEL_ID,
'builder_type' => Channel::BUILDER_NEW,
'user_id' => 0,
'status' => 1,
]);
Process::fake([
'*' => Process::result(output: $this->fakeBuildResult()),
]);
$result = app(ChannelProjectService::class)->rebuildOldChannels();
$this->assertCount(2, $result['channels']);
Process::assertRanTimes(function ($process) {
$joined = is_array($process->command) ? implode(' ', $process->command) : (string) $process->command;
return str_contains($joined, 'new_project.py')
&& str_contains($joined, '--deployment-seed')
&& str_contains($joined, '11111111111111111111111111111111');
}, 2);
Process::assertRan(function ($process) {
$joined = is_array($process->command) ? implode(' ', $process->command) : (string) $process->command;
return str_contains($joined, 'new_project.py') && str_contains($joined, self::CHANNEL_ID);
});
Process::assertRan(function ($process) {
$joined = is_array($process->command) ? implode(' ', $process->command) : (string) $process->command;
return str_contains($joined, 'new_project.py') && str_contains($joined, 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb');
});
}
#[Test]
public function it_rejects_invalid_old_channel_ids_when_repacking(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('旧版渠道 ID 必须是 32 位 hex');
app(ChannelProjectService::class)->resolveOldChannelIds(['not-a-channel']);
}
#[Test]
public function coruna_repack_dry_run_lists_old_channels(): void
{
Channel::query()->create([
'channel_id' => self::CHANNEL_ID,
'builder_type' => Channel::BUILDER_OLD,
'user_id' => 0,
'status' => 1,
]);
Channel::query()->create([
'channel_id' => self::NEW_CHANNEL_ID,
'builder_type' => Channel::BUILDER_NEW,
'user_id' => 0,
'status' => 1,
]);
Process::fake();
$this->artisan('coruna:repack', ['--dry-run' => true])
->expectsOutputToContain('将重打 1 个旧版渠道')
->expectsOutputToContain('/web/'.self::CHANNEL_ID.'/support.html')
->assertSuccessful();
Process::assertNothingRan();
}
#[Test]
public function version_format_required_for_new_channel_ids(): void
{