-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add base Assistant entity (#14) #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
martinydeAI
wants to merge
1
commit into
feature/issue-2-user-login
Choose a base branch
from
feature/issue-14-assistant-base-entity
base: feature/issue-2-user-login
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace DoctrineMigrations; | ||
|
|
||
| use Doctrine\DBAL\Schema\Schema; | ||
| use Doctrine\Migrations\AbstractMigration; | ||
|
|
||
| /** | ||
| * Initial `assistant` table for the catalogue (#14). | ||
| */ | ||
| final class Version20260612120840 extends AbstractMigration | ||
| { | ||
| public function getDescription(): string | ||
| { | ||
| return 'Create the assistant table with base fields (title, description, languageModel, framework, tags).'; | ||
| } | ||
|
|
||
| public function up(Schema $schema): void | ||
| { | ||
| $this->addSql('CREATE TABLE assistant (id INT AUTO_INCREMENT NOT NULL, title VARCHAR(255) NOT NULL, description LONGTEXT NOT NULL, language_model VARCHAR(255) NOT NULL, framework VARCHAR(255) NOT NULL, tags JSON NOT NULL, PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4'); | ||
| } | ||
|
|
||
| public function down(Schema $schema): void | ||
| { | ||
| $this->addSql('DROP TABLE assistant'); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Entity; | ||
|
|
||
| use App\Repository\AssistantRepository; | ||
| use Doctrine\DBAL\Types\Types; | ||
| use Doctrine\ORM\Mapping as ORM; | ||
|
|
||
| #[ORM\Entity(repositoryClass: AssistantRepository::class)] | ||
| #[ORM\Table(name: 'assistant')] | ||
| class Assistant | ||
| { | ||
| #[ORM\Id] | ||
| #[ORM\GeneratedValue] | ||
| #[ORM\Column] | ||
| private ?int $id = null; | ||
|
|
||
| #[ORM\Column(length: 255)] | ||
| private string $title; | ||
|
|
||
| #[ORM\Column(type: Types::TEXT)] | ||
| private string $description; | ||
|
|
||
| /** | ||
| * Captured at creation time from the creator's organisation (see | ||
| * ADR 005); stored on the assistant so an organisation switching | ||
| * its default later does not silently rewrite older catalogue | ||
| * rows. | ||
| */ | ||
| #[ORM\Column(length: 255)] | ||
| private string $languageModel; | ||
|
|
||
| /** | ||
| * @see self::$languageModel for the snapshot rationale | ||
| */ | ||
| #[ORM\Column(length: 255)] | ||
| private string $framework; | ||
|
|
||
| /** | ||
| * @var list<string> | ||
| */ | ||
| #[ORM\Column(type: Types::JSON)] | ||
| private array $tags = []; | ||
|
|
||
| /** | ||
| * @param list<string> $tags | ||
| */ | ||
| public function __construct( | ||
| string $title, | ||
| string $description, | ||
| string $languageModel, | ||
| string $framework, | ||
| array $tags = [], | ||
| ) { | ||
| $this->title = $title; | ||
| $this->description = $description; | ||
| $this->languageModel = $languageModel; | ||
| $this->framework = $framework; | ||
| $this->tags = array_values($tags); | ||
| } | ||
|
|
||
| public function getId(): ?int | ||
| { | ||
| return $this->id; | ||
| } | ||
|
|
||
| public function getTitle(): string | ||
| { | ||
| return $this->title; | ||
| } | ||
|
|
||
| public function setTitle(string $title): static | ||
| { | ||
| $this->title = $title; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function getDescription(): string | ||
| { | ||
| return $this->description; | ||
| } | ||
|
|
||
| public function setDescription(string $description): static | ||
| { | ||
| $this->description = $description; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function getLanguageModel(): string | ||
| { | ||
| return $this->languageModel; | ||
| } | ||
|
|
||
| public function setLanguageModel(string $languageModel): static | ||
| { | ||
| $this->languageModel = $languageModel; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function getFramework(): string | ||
| { | ||
| return $this->framework; | ||
| } | ||
|
|
||
| public function setFramework(string $framework): static | ||
| { | ||
| $this->framework = $framework; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * @return list<string> | ||
| */ | ||
| public function getTags(): array | ||
| { | ||
| return $this->tags; | ||
| } | ||
|
|
||
| /** | ||
| * @param list<string> $tags | ||
| */ | ||
| public function setTags(array $tags): static | ||
| { | ||
| $this->tags = array_values($tags); | ||
|
|
||
| return $this; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Repository; | ||
|
|
||
| use App\Entity\Assistant; | ||
| use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||
| use Doctrine\Persistence\ManagerRegistry; | ||
|
|
||
| /** | ||
| * @extends ServiceEntityRepository<Assistant> | ||
| */ | ||
| class AssistantRepository extends ServiceEntityRepository | ||
| { | ||
| public function __construct(ManagerRegistry $registry) | ||
| { | ||
| parent::__construct($registry, Assistant::class); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\Tests\Entity; | ||
|
|
||
| use App\Entity\Assistant; | ||
| use App\Repository\AssistantRepository; | ||
| use App\Tests\Support\ResetsDatabaseSchemaTrait; | ||
| use Doctrine\ORM\EntityManagerInterface; | ||
| use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
|
|
||
| /** | ||
| * Round-trips an Assistant through the entity manager so every getter | ||
| * and setter sees real persistence + hydration rather than in-memory | ||
| * object-graph wiring only. | ||
| */ | ||
| final class AssistantTest extends KernelTestCase | ||
| { | ||
| use ResetsDatabaseSchemaTrait; | ||
|
|
||
| private EntityManagerInterface $em; | ||
| private AssistantRepository $repository; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| self::bootKernel(); | ||
| $container = self::getContainer(); | ||
| self::resetSchema($container->get(EntityManagerInterface::class)); | ||
|
|
||
| $this->em = $container->get(EntityManagerInterface::class); | ||
| $this->repository = $container->get(AssistantRepository::class); | ||
| } | ||
|
|
||
| public function testPersistsAndHydratesBaseFields(): void | ||
| { | ||
| $assistant = new Assistant( | ||
| title: 'Borgerservice-vejviser', | ||
| description: 'Hjælper sagsbehandlere med at finde den rigtige paragraf.', | ||
| languageModel: 'gpt-4o', | ||
| framework: 'openwebui', | ||
| tags: ['borgerservice', 'paragraf'], | ||
| ); | ||
|
|
||
| $this->em->persist($assistant); | ||
| $this->em->flush(); | ||
| $id = $assistant->getId(); | ||
| self::assertNotNull($id); | ||
|
|
||
| $this->em->clear(); | ||
| $reloaded = $this->repository->find($id); | ||
|
|
||
| self::assertInstanceOf(Assistant::class, $reloaded); | ||
| self::assertSame('Borgerservice-vejviser', $reloaded->getTitle()); | ||
| self::assertSame('Hjælper sagsbehandlere med at finde den rigtige paragraf.', $reloaded->getDescription()); | ||
| self::assertSame('gpt-4o', $reloaded->getLanguageModel()); | ||
| self::assertSame('openwebui', $reloaded->getFramework()); | ||
| self::assertSame(['borgerservice', 'paragraf'], $reloaded->getTags()); | ||
| } | ||
|
|
||
| public function testSettersUpdatePersistedValues(): void | ||
| { | ||
| $assistant = new Assistant('original-title', 'original-desc', 'gpt-4o', 'openwebui'); | ||
| $this->em->persist($assistant); | ||
| $this->em->flush(); | ||
| $id = $assistant->getId(); | ||
| self::assertNotNull($id); | ||
|
|
||
| $assistant | ||
| ->setTitle('new-title') | ||
| ->setDescription('new-desc') | ||
| ->setLanguageModel('claude-3.5-sonnet') | ||
| ->setFramework('custom-runtime') | ||
| ->setTags(['x', 'y']); | ||
| $this->em->flush(); | ||
| $this->em->clear(); | ||
|
|
||
| $reloaded = $this->repository->find($id); | ||
| self::assertInstanceOf(Assistant::class, $reloaded); | ||
| self::assertSame('new-title', $reloaded->getTitle()); | ||
| self::assertSame('new-desc', $reloaded->getDescription()); | ||
| self::assertSame('claude-3.5-sonnet', $reloaded->getLanguageModel()); | ||
| self::assertSame('custom-runtime', $reloaded->getFramework()); | ||
| self::assertSame(['x', 'y'], $reloaded->getTags()); | ||
| } | ||
|
|
||
| public function testTagsDefaultToEmptyListAndAreReindexedOnSet(): void | ||
| { | ||
| $assistant = new Assistant('t', 'd', 'm', 'f'); | ||
| self::assertSame([], $assistant->getTags()); | ||
|
|
||
| // Setting with non-sequential keys must produce a clean list<string> | ||
| // — `array_values()` in setTags() guarantees JSON serialises as an | ||
| // array, not an object. | ||
| $assistant->setTags([3 => 'alpha', 7 => 'beta']); | ||
| self::assertSame(['alpha', 'beta'], $assistant->getTags()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this migration generated by doctrine:migrations:diff or claude? It should be generated by diff, and then you can add comments afterwards.
In os2display we have adopted Doctrine's schema tool to ensure portability with other databases than mariadb. See https://github.com/os2display/display-api-service/blob/release/3.0.0/migrations/Version20260506215847.php