feat: xxbb

This commit is contained in:
hashbro
2026-08-13 07:08:02 +08:00
parent c6e386e069
commit dbe6358a3c
11 changed files with 311 additions and 159 deletions
+31 -41
View File
@@ -332,16 +332,16 @@ class ChannelProjectServiceTest extends TestCase
}
#[Test]
public function it_invokes_new_builder_with_channel_name(): void
public function it_invokes_new_builder_for_shared_weifile(): void
{
$name = 'abcd1234';
Process::fake([
'*' => Process::result(output: $this->fakeBuildResult([
'builder_type' => 'new',
'channel_name' => $name,
'weifile_path' => '/source/'.$name.'/index.html',
'support_path' => '/source/'.$name.'/index.html',
'daily_path' => '',
'channel_name' => null,
'weifile_path' => '/weifile/weifile.html',
'support_path' => '/weifile/weifile.html',
'details_path' => '/details/',
'daily_path' => '/details/',
'domains' => ['deployment' => [], 'reporting' => []],
])),
]);
@@ -352,20 +352,19 @@ class ChannelProjectServiceTest extends TestCase
null,
null,
Channel::BUILDER_NEW,
$name,
);
$this->assertSame(Channel::BUILDER_NEW, $result['builder_type']);
$this->assertSame($name, $result['channel_name']);
$this->assertSame('/source/'.$name.'/index.html', $result['weifile_path']);
$this->assertSame('/source/'.$name.'/index.html', $result['support_path']);
$this->assertNull($result['channel_name']);
$this->assertSame('/weifile/weifile.html', $result['weifile_path']);
$this->assertSame('/weifile/weifile.html', $result['support_path']);
$this->assertSame('/details/', $result['daily_path']);
Process::assertRan(function ($process) use ($name) {
Process::assertRan(function ($process) {
$joined = is_array($process->command) ? implode(' ', $process->command) : (string) $process->command;
return str_contains($joined, 'build.py')
&& str_contains($joined, '--channel-name')
&& str_contains($joined, $name)
&& ! str_contains($joined, '--channel-name')
&& str_contains($joined, '--channel-c')
&& str_contains($joined, self::CHANNEL_ID)
&& str_contains($joined, '--scheme')
@@ -391,28 +390,28 @@ class ChannelProjectServiceTest extends TestCase
}
#[Test]
public function support_links_use_channel_name_path_for_new_builder(): void
public function support_links_use_weifile_path_for_new_builder(): void
{
$channel = new Channel([
'channel_id' => self::CHANNEL_ID,
'builder_type' => Channel::BUILDER_NEW,
'channel_name' => 'abcd1234',
'domains' => ['channel.test'],
]);
$this->assertSame([
'https://channel.test/source/abcd1234/index.html',
'https://channel.test/weifile/weifile.html',
], $channel->supportLinks());
$this->assertSame('/source/abcd1234/index.html', $channel->landingPath());
$this->assertSame('/weifile/weifile.html', $channel->landingPath());
}
#[Test]
public function store_new_builder_persists_channel_name_and_returns_weifile_path(): void
public function store_new_builder_returns_shared_weifile_path(): void
{
Process::fake([
'*' => Process::result(output: $this->fakeBuildResult([
'weifile_path' => '/placeholder/placeholder.html',
'support_path' => '/placeholder/placeholder.html',
'daily_path' => '',
'weifile_path' => '/weifile/weifile.html',
'support_path' => '/weifile/weifile.html',
'details_path' => '/details/',
'daily_path' => '/details/',
])),
]);
$admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']);
@@ -430,38 +429,30 @@ class ChannelProjectServiceTest extends TestCase
$channel = Channel::query()->where('channel_id', self::CHANNEL_ID)->first();
$this->assertNotNull($channel);
$this->assertSame(Channel::BUILDER_NEW, $channel->builderType());
$this->assertMatchesRegularExpression('/^[a-z0-9]{8}$/', (string) $channel->channel_name);
$this->assertSame(
'/source/'.$channel->channel_name.'/index.html',
$channel->landingPath()
);
$this->assertSame($channel->channel_name, $response->json('data.channel_name'));
$this->assertSame($channel->landingPath(), $response->json('data.weifile_path'));
$this->assertNull($channel->channel_name);
$this->assertSame('/weifile/weifile.html', $channel->landingPath());
$this->assertNull($response->json('data.channel_name'));
$this->assertSame('/weifile/weifile.html', $response->json('data.weifile_path'));
Process::assertRan(function ($process) use ($channel) {
Process::assertRan(function ($process) {
$joined = is_array($process->command) ? implode(' ', $process->command) : (string) $process->command;
return str_contains($joined, 'build.py')
&& str_contains($joined, $channel->channel_name)
&& ! str_contains($joined, '--channel-name')
&& str_contains($joined, '--channel-c')
&& str_contains($joined, self::CHANNEL_ID);
});
}
#[Test]
public function destroy_new_builder_deletes_channel_name_tree(): void
public function destroy_new_builder_keeps_shared_weifile(): void
{
Process::fake([
'*' => Process::result(output: ChannelProjectService::RESULT_MARKER.json_encode([
'status' => 'deleted',
'removed' => true,
])."\n"),
]);
Process::fake();
$admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']);
$channel = Channel::query()->create([
'channel_id' => self::CHANNEL_ID,
'builder_type' => Channel::BUILDER_NEW,
'channel_name' => 'abcd1234',
'channel_name' => null,
'user_id' => 0,
'status' => 1,
]);
@@ -471,12 +462,11 @@ class ChannelProjectServiceTest extends TestCase
->assertOk()
->assertJsonPath('code', 0);
Process::assertRan(function ($process) {
Process::assertDidntRun(function ($process) {
$joined = is_array($process->command) ? implode(' ', $process->command) : (string) $process->command;
return str_contains($joined, 'delete_channel.py')
&& str_contains($joined, 'abcd1234')
&& ! str_contains($joined, 'delete_channel_web.py');
|| str_contains($joined, 'delete_channel_web.py');
});
$this->assertDatabaseMissing('channels', ['id' => $channel->id]);
}