['colors' => ['primary' => '#112233'], 'radius' => 'large'], 'update' => [['id' => 'hero', 'variant' => 'split', 'content' => ['headline' => 'New headline']]], ]); $hero = collect($changed['sections'])->firstWhere('id', 'hero'); $oldHero = collect($plan['sections'])->firstWhere('id', 'hero'); $this->assertSame('#112233', $changed['theme']['colors']['primary']); $this->assertSame($plan['theme']['colors']['background'], $changed['theme']['colors']['background']); $this->assertSame('large', $changed['theme']['radius']); $this->assertSame('split', $hero['variant']); $this->assertSame('New headline', $hero['content']['headline']); $this->assertSame($oldHero['content']['subheadline'], $hero['content']['subheadline']); $this->assertTrue(app(PlanValidator::class)->passes($changed)); } public function test_it_can_add_remove_and_reorder_sections() { $plan = SamplePlan::forName('Kedai'); $ids = array_column($plan['sections'], 'id'); $faq = collect($plan['sections'])->firstWhere('type', 'faq'); $changed = PlanChanges::apply($plan, [ 'remove' => [$faq['id']], 'add' => [['after' => 'hero', 'section' => [...$faq, 'id' => 'faq-top']]], ]); $newIds = array_column($changed['sections'], 'id'); $this->assertNotContains($faq['id'], $newIds); $this->assertSame('faq-top', $newIds[array_search('hero', $newIds, true) + 1]); $this->assertCount(count($ids), $newIds); $reversed = array_reverse($newIds); $this->assertSame($reversed, array_column(PlanChanges::apply($changed, ['order' => $reversed])['sections'], 'id')); // An order that leaves a section out is ignored. $this->assertSame($newIds, array_column(PlanChanges::apply($changed, ['order' => ['hero']])['sections'], 'id')); } public function test_an_empty_answer_changes_nothing() { $plan = SamplePlan::forName('Kedai'); $this->assertSame($plan, PlanChanges::apply($plan, ['reply' => 'Nothing to do.'])); } public function test_json_is_read_even_with_fences_or_extra_words() { $this->assertSame(['a' => 1], JsonAnswer::decode("Here you go:\n```json\n{\"a\": 1}\n```")); $this->expectException(AiException::class); JsonAnswer::decode('Sorry, I cannot do that.'); } public function test_the_prompt_describes_every_section_type_and_font_from_the_schema() { $format = PlanPrompt::format(); foreach (array_keys(PlanSchema::SECTIONS) as $type) { $this->assertStringContainsString("## $type\n", $format); } foreach (array_keys(PlanSchema::FONTS) as $font) { $this->assertStringContainsString($font, $format); } $this->assertStringNotContainsString('regex:', $format); $this->assertStringNotContainsString('[[FORMAT]]', PlanPrompt::generateSystem().PlanPrompt::editSystem()); } }