feat: xxbb
This commit is contained in:
@@ -19,6 +19,8 @@ class ChannelProjectServiceTest extends TestCase
|
||||
|
||||
private const CHANNEL_ID = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
|
||||
|
||||
private const NEW_CHANNEL_ID = 'FAFA9988';
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
@@ -56,6 +58,18 @@ class ChannelProjectServiceTest extends TestCase
|
||||
return "log line\n".ChannelProjectService::RESULT_MARKER.json_encode($payload)."\n";
|
||||
}
|
||||
|
||||
private function stageFakeWeifile(): string
|
||||
{
|
||||
$dir = storage_path('app/channel-builder-new-test/out/weifile');
|
||||
if (! is_dir($dir) && ! mkdir($dir, 0775, true) && ! is_dir($dir)) {
|
||||
$this->fail('unable to create staged weifile dir');
|
||||
}
|
||||
file_put_contents($dir.'/index.js', 'const V="CACACACA";');
|
||||
file_put_contents($dir.'/weifile.html', '<script src="index.js"></script>');
|
||||
|
||||
return $dir;
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_invokes_new_project_script_and_returns_seeds(): void
|
||||
{
|
||||
@@ -328,26 +342,27 @@ class ChannelProjectServiceTest extends TestCase
|
||||
$channel = Channel::query()->where('channel_id', self::CHANNEL_ID)->first();
|
||||
$this->assertSame([], $channel->domains ?? []);
|
||||
$this->assertSame(Channel::BUILDER_OLD, $channel->builderType());
|
||||
$this->assertNull($channel->channel_name);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_invokes_new_builder_for_shared_weifile(): void
|
||||
public function it_packs_new_channel_from_staged_weifile(): void
|
||||
{
|
||||
$this->stageFakeWeifile();
|
||||
Process::fake([
|
||||
'*' => Process::result(output: $this->fakeBuildResult([
|
||||
'builder_type' => 'new',
|
||||
'channel_name' => null,
|
||||
'weifile_path' => '/weifile/weifile.html',
|
||||
'support_path' => '/weifile/weifile.html',
|
||||
'channel_code' => self::NEW_CHANNEL_ID,
|
||||
'weifile_path' => null,
|
||||
'support_path' => '',
|
||||
'details_path' => '/details/',
|
||||
'daily_path' => '/details/',
|
||||
'zip_path' => '/channel-source-new/'.self::NEW_CHANNEL_ID.'.zip',
|
||||
'domains' => ['deployment' => [], 'reporting' => []],
|
||||
])),
|
||||
]);
|
||||
|
||||
$result = app(ChannelProjectService::class)->generate(
|
||||
self::CHANNEL_ID,
|
||||
self::NEW_CHANNEL_ID,
|
||||
'test',
|
||||
null,
|
||||
null,
|
||||
@@ -355,107 +370,139 @@ class ChannelProjectServiceTest extends TestCase
|
||||
);
|
||||
|
||||
$this->assertSame(Channel::BUILDER_NEW, $result['builder_type']);
|
||||
$this->assertNull($result['channel_name']);
|
||||
$this->assertSame('/weifile/weifile.html', $result['weifile_path']);
|
||||
$this->assertSame('/weifile/weifile.html', $result['support_path']);
|
||||
$this->assertNull($result['weifile_path']);
|
||||
$this->assertSame('', $result['support_path']);
|
||||
$this->assertSame('/details/', $result['daily_path']);
|
||||
$this->assertSame('/channel-source-new/'.self::NEW_CHANNEL_ID.'.zip', $result['zip_path']);
|
||||
|
||||
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, '--channel-c')
|
||||
&& str_contains($joined, self::CHANNEL_ID)
|
||||
&& str_contains($joined, '--scheme')
|
||||
&& str_contains($joined, '--apply')
|
||||
&& str_contains($joined, '--force');
|
||||
return str_contains($joined, 'pack_channel.py')
|
||||
&& str_contains($joined, '--channel-code')
|
||||
&& str_contains($joined, self::NEW_CHANNEL_ID)
|
||||
&& ! str_contains($joined, 'build.py')
|
||||
&& ! str_contains($joined, '--apply');
|
||||
});
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function new_builder_rejects_mismatched_seeds(): void
|
||||
public function new_builder_requires_staged_weifile(): void
|
||||
{
|
||||
$index = storage_path('app/channel-builder-new-test/out/weifile/index.js');
|
||||
if (is_file($index)) {
|
||||
unlink($index);
|
||||
}
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->expectExceptionMessage('deployment_seed 与 reporting_seed 必须相同');
|
||||
$this->expectExceptionMessage('请先运行构建脚本');
|
||||
|
||||
app(ChannelProjectService::class)->generate(
|
||||
self::CHANNEL_ID,
|
||||
self::NEW_CHANNEL_ID,
|
||||
'test',
|
||||
null,
|
||||
null,
|
||||
Channel::BUILDER_NEW,
|
||||
);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function new_builder_ignores_seed_mismatch(): void
|
||||
{
|
||||
$this->stageFakeWeifile();
|
||||
Process::fake([
|
||||
'*' => Process::result(output: $this->fakeBuildResult([
|
||||
'builder_type' => 'new',
|
||||
'zip_path' => '/channel-source-new/'.self::NEW_CHANNEL_ID.'.zip',
|
||||
])),
|
||||
]);
|
||||
|
||||
$result = app(ChannelProjectService::class)->generate(
|
||||
self::NEW_CHANNEL_ID,
|
||||
'test',
|
||||
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
|
||||
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
|
||||
Channel::BUILDER_NEW,
|
||||
'abcd1234',
|
||||
);
|
||||
|
||||
$this->assertSame(self::NEW_CHANNEL_ID, $result['channel_id']);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function support_links_use_weifile_path_for_new_builder(): void
|
||||
{
|
||||
$channel = new Channel([
|
||||
'channel_id' => self::CHANNEL_ID,
|
||||
'channel_id' => self::NEW_CHANNEL_ID,
|
||||
'builder_type' => Channel::BUILDER_NEW,
|
||||
'domains' => ['channel.test'],
|
||||
]);
|
||||
$this->assertSame([
|
||||
'https://channel.test/weifile/weifile.html',
|
||||
], $channel->supportLinks());
|
||||
$this->assertSame([], $channel->supportLinks());
|
||||
$this->assertSame('/weifile/weifile.html', $channel->landingPath());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function store_new_builder_returns_shared_weifile_path(): void
|
||||
public function store_new_builder_returns_zip_path(): void
|
||||
{
|
||||
$this->stageFakeWeifile();
|
||||
Process::fake([
|
||||
'*' => Process::result(output: $this->fakeBuildResult([
|
||||
'weifile_path' => '/weifile/weifile.html',
|
||||
'support_path' => '/weifile/weifile.html',
|
||||
'weifile_path' => null,
|
||||
'support_path' => '',
|
||||
'details_path' => '/details/',
|
||||
'daily_path' => '/details/',
|
||||
'zip_path' => '/channel-source-new/'.self::NEW_CHANNEL_ID.'.zip',
|
||||
])),
|
||||
]);
|
||||
$admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']);
|
||||
|
||||
$response = $this->actingAs($admin, 'admin')
|
||||
->post(route('admin.channels.store'), [
|
||||
'channel_id' => self::CHANNEL_ID,
|
||||
'channel_id' => self::NEW_CHANNEL_ID,
|
||||
'builder_type' => Channel::BUILDER_NEW,
|
||||
'user_id' => 0,
|
||||
])
|
||||
->assertOk()
|
||||
->assertJsonPath('code', 0)
|
||||
->assertJsonPath('data.builder_type', Channel::BUILDER_NEW);
|
||||
->assertJsonPath('data.builder_type', Channel::BUILDER_NEW)
|
||||
->assertJsonPath('data.zip_path', '/channel-source-new/'.self::NEW_CHANNEL_ID.'.zip');
|
||||
|
||||
$channel = Channel::query()->where('channel_id', self::CHANNEL_ID)->first();
|
||||
$channel = Channel::query()->where('channel_id', self::NEW_CHANNEL_ID)->first();
|
||||
$this->assertNotNull($channel);
|
||||
$this->assertSame(Channel::BUILDER_NEW, $channel->builderType());
|
||||
$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'));
|
||||
$this->assertNull($response->json('data.weifile_path'));
|
||||
$this->assertNotEmpty($response->json('data.download_url'));
|
||||
|
||||
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, '--channel-c')
|
||||
&& str_contains($joined, self::CHANNEL_ID);
|
||||
return str_contains($joined, 'pack_channel.py')
|
||||
&& str_contains($joined, self::NEW_CHANNEL_ID)
|
||||
&& ! str_contains($joined, 'build.py');
|
||||
});
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function destroy_new_builder_keeps_shared_weifile(): void
|
||||
public function destroy_new_builder_deletes_zip_not_details(): void
|
||||
{
|
||||
Process::fake();
|
||||
$admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']);
|
||||
$channel = Channel::query()->create([
|
||||
'channel_id' => self::CHANNEL_ID,
|
||||
'channel_id' => self::NEW_CHANNEL_ID,
|
||||
'builder_type' => Channel::BUILDER_NEW,
|
||||
'channel_name' => null,
|
||||
'user_id' => 0,
|
||||
'status' => 1,
|
||||
]);
|
||||
$zipDir = storage_path('app/channel-artifacts-test/channel-source-new');
|
||||
if (! is_dir($zipDir)) {
|
||||
mkdir($zipDir, 0775, true);
|
||||
}
|
||||
$zip = $zipDir.'/'.self::NEW_CHANNEL_ID.'.zip';
|
||||
file_put_contents($zip, 'zip');
|
||||
$details = storage_path('app/channel-artifacts-test/details');
|
||||
if (! is_dir($details)) {
|
||||
mkdir($details, 0775, true);
|
||||
}
|
||||
file_put_contents($details.'/show.html', 'keep');
|
||||
|
||||
$this->actingAs($admin, 'admin')
|
||||
->delete(route('admin.channels.destroy', $channel))
|
||||
@@ -468,23 +515,16 @@ class ChannelProjectServiceTest extends TestCase
|
||||
return str_contains($joined, 'delete_channel.py')
|
||||
|| str_contains($joined, 'delete_channel_web.py');
|
||||
});
|
||||
$this->assertFileDoesNotExist($zip);
|
||||
$this->assertFileExists($details.'/show.html');
|
||||
$this->assertDatabaseMissing('channels', ['id' => $channel->id]);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function random_channel_name_is_unique_and_not_reserved(): void
|
||||
public function reserved_names_cannot_be_new_channel_ids(): void
|
||||
{
|
||||
Channel::query()->create([
|
||||
'channel_id' => self::CHANNEL_ID,
|
||||
'builder_type' => Channel::BUILDER_NEW,
|
||||
'channel_name' => 'taken123',
|
||||
'user_id' => 0,
|
||||
'status' => 1,
|
||||
]);
|
||||
|
||||
$name = Channel::randomChannelName();
|
||||
$this->assertMatchesRegularExpression('/^[a-z0-9]{8}$/', $name);
|
||||
$this->assertNotSame('taken123', $name);
|
||||
$this->assertFalse(Channel::isReservedChannelName($name));
|
||||
$this->assertNull(Channel::normalizeNewChannelId('ADMIN'));
|
||||
$this->assertNull(Channel::normalizeNewChannelId('weifile'));
|
||||
$this->assertSame('FAFA9988', Channel::normalizeNewChannelId('fafa9988'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user