Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.
Ruby agplai-assistantdockerdsgvogdprhotwireissue-trackerjira-alternativeknowledge-basellmmcp-servermeeting-notesopen-sourceproject-managementredmine-alternativeruby-on-railsself-hostedticketingtime-tracking
Build the Nordlicht world on production paths, for the screenshots and the demo
Guido Boykeb5ee728b0555
diff --git a/lib/lalabase/demo/fiction.rb b/lib/lalabase/demo/fiction.rbnew file mode 100644index 0000000..3469441--- /dev/null+++ b/lib/lalabase/demo/fiction.rb@@ -0,0 +1,275 @@+# frozen_string_literal: true++module Lalabase+ module Demo+ # The invented company of the product screenshots and the public demo: Nordlicht+ # Software GmbH, Kiel, six people, two clients. Everything here is invented.+ # Addresses use nordlicht.example (RFC 2606, never deliverable), avatars are+ # initials, and no name belongs to a real person we know of. Before a new set of+ # pictures goes to the website, every name in this file goes through+ # script/leak_guard.+ #+ # Each text exists in German and English, because the pictures for /en show the+ # English interface, and an English interface around German ticket titles would+ # look like a product made for Germany only.+ #+ # Times are relative (days, hours ago), so the same world can be built at a frozen+ # moment for the pictures and at the moment of a reset for the demo. A date inside+ # a text is a placeholder that Lalabase::Demo::World fills in from that moment.+ module Fiction+ DOMAIN = 'nordlicht.example'++ PEOPLE = {+ svenja: { first_name: 'Svenja', last_name: 'Brandt' }, # project lead, signed in+ jana: { first_name: 'Jana', last_name: 'Petersen' }, # managing director, account admin+ malte: { first_name: 'Malte', last_name: 'Hansen' }, # development+ ole: { first_name: 'Ole', last_name: 'Jensen' }, # development+ lena: { first_name: 'Lena', last_name: 'Thiel' }, # design+ finn: { first_name: 'Finn', last_name: 'Carstensen' } # support+ }.freeze++ # The owner of the organisation. Everybody else, the signed-in person included,+ # holds the team role: a visitor of the demo is never an account admin.+ OWNER = :jana+ SIGNED_IN = :svenja++ ALL_PROJECTS = %w[chats notes meetings tickets documents time_tracking].flat_map do |area|+ ["read_access_#{area}_all_projects", "write_access_#{area}_all_projects"]+ end.freeze++ # Read and write in every project, the assistant, and names in full. What a small+ # agency gives its whole team.+ TEAM_ROLE = {+ title: { de: 'Team', en: 'Team' },+ description: { de: 'Arbeitet in allen Projekten mit', en: 'Works in every project' },+ permissions: {+ 'projects' => %w[change_project_properties create_new_projects read_access_documentation_all_projects] ++ ALL_PROJECTS,+ 'users' => %w[view_user_full_name view_user_contact_details],+ 'assistant' => %w[use_assistant]+ }+ }.freeze++ # Every member of the team works in every project, as on the project permissions+ # page. The project lead also sees and corrects everybody's hours.+ PROJECT_ACCESS = { tickets_access: :read_write, notes_access: :read_write, documents_access: :read_write,+ chats_access: :read_write, meetings_access: :read_write,+ documentation_access: :read_only, members_access: :read_only }.freeze+ LEAD_TIME_RIGHTS = { can_view_all: true, can_edit_all: true }.freeze++ PROJECTS = {+ deichblick: { de: 'Deichblick Kundenportal', en: 'Deichblick client portal',+ description: { de: 'Objektverwaltung für Deichblick Immobilien.',+ en: 'Property management for Deichblick Immobilien.' } },+ faehrhaus: { de: 'Fährhaus Tourenplanung', en: 'Fährhaus route planning',+ description: { de: 'Tourenplanung für Fährhaus Logistik.',+ en: 'Route planning for Fährhaus Logistik.' } },+ intern: { de: 'Nordlicht intern', en: 'Nordlicht internal',+ description: { de: 'Eigene Website und Abläufe.', en: 'Our own website and processes.' } }+ }.freeze++ # Oldest first: the numbers follow the order of creation.+ TICKETS = [+ { de: 'Anmeldung mit Einmalcode für Mieter', en: 'One-time code sign-in for tenants',+ status: 'resolved', priority: 'high', assignee: :malte },+ { de: 'Mieterportal: Dokumente nach Objekt sortieren', en: 'Tenant portal: sort documents by property',+ status: 'resolved', priority: 'normal', assignee: :ole },+ { de: 'Schadensmeldung mit Fotos', en: 'Damage report with photos',+ status: 'in_progress', priority: 'high', assignee: :malte },+ { de: 'Nebenkostenabrechnung als PDF exportieren', en: 'Export the service charge statement as PDF',+ status: 'in_progress', priority: 'urgent', assignee: :ole },+ { de: 'Entwürfe für die Objektübersicht', en: 'Designs for the property overview',+ status: 'in_progress', priority: 'normal', assignee: :lena },+ { de: 'Login-Fehler bei Umlauten im Passwort', en: 'Login fails with umlauts in the password',+ status: 'new', priority: 'urgent', assignee: :finn },+ { de: 'Hausmeister-Rolle mit Lesezugriff', en: 'Caretaker role with read access',+ status: 'new', priority: 'normal', assignee: :malte },+ { de: 'Erinnerung vor Ablauf der Wartungsverträge', en: 'Reminder before maintenance contracts expire',+ status: 'backlog', priority: 'low', assignee: nil },+ { de: 'Schnittstelle zur Buchhaltung klären', en: 'Clarify the interface to accounting',+ status: 'backlog', priority: 'normal', assignee: :svenja }+ ].freeze++ # Minutes per person and day, on the ticket at that index.+ TIME = [+ { person: :malte, days_ago: 0, minutes: 150, ticket: 2,+ de: 'Upload der Fotos, Vorschau', en: 'Photo upload, preview' },+ { person: :ole, days_ago: 0, minutes: 90, ticket: 3,+ de: 'PDF-Vorlage, Summenzeile', en: 'PDF template, totals row' },+ { person: :lena, days_ago: 1, minutes: 240, ticket: 4,+ de: 'Objektübersicht, zweiter Entwurf', en: 'Property overview, second draft' },+ { person: :malte, days_ago: 1, minutes: 210, ticket: 2,+ de: 'Schadensmeldung: Formular und Prüfung', en: 'Damage report: form and validation' },+ { person: :svenja, days_ago: 1, minutes: 60, ticket: nil,+ de: 'Abstimmung mit Deichblick', en: 'Call with Deichblick' },+ { person: :ole, days_ago: 2, minutes: 180, ticket: 3,+ de: 'Datenabfrage für die Abrechnung', en: 'Query for the statement' },+ { person: :finn, days_ago: 2, minutes: 45, ticket: 5,+ de: 'Fehler nachgestellt', en: 'Reproduced the error' }+ ].freeze++ # The dates a text names, in days from the moment the world is built, and how a+ # date reads inside a sentence.+ DATES = { accepted_on: -8, next_meeting_on: 14 }.freeze+ DATE_FORMAT = { de: '%-d. %B', en: '%-d %B' }.freeze++ NOTES = [+ { de: 'Abnahmeprotokoll Mieterportal', en: 'Acceptance record tenant portal',+ content: {+ de: '<p>Abnahme mit Deichblick Immobilien am %<accepted_on>s, im Büro Kiel.</p>' \+ '<p><strong>Abgenommen</strong></p>' \+ '<ul><li>Anmeldung mit Einmalcode</li><li>Dokumente je Objekt</li>' \+ '<li>Postfach für Mieter</li></ul>' \+ '<p><strong>Offen</strong></p>' \+ '<ul><li>Schadensmeldung mit Fotos, Abnahme nach dem Test mit drei Hausmeistern</li>' \+ '<li>PDF-Export der Nebenkostenabrechnung, Termin Ende des Monats</li></ul>' \+ '<p>Nächster Termin: %<next_meeting_on>s.</p>',+ en: '<p>Acceptance with Deichblick Immobilien on %<accepted_on>s, at the Kiel office.</p>' \+ '<p><strong>Accepted</strong></p>' \+ '<ul><li>Sign-in with a one-time code</li><li>Documents per property</li>' \+ '<li>Inbox for tenants</li></ul>' \+ '<p><strong>Open</strong></p>' \+ '<ul><li>Damage report with photos, accepted after the test with three caretakers</li>' \+ '<li>PDF export of the service charge statement, due at the end of the month</li></ul>' \+ '<p>Next meeting: %<next_meeting_on>s.</p>'+ } },+ { de: 'Wie wir mit Deichblick abrechnen', en: 'How we bill Deichblick',+ content: { de: 'Monatlich nach Aufwand, Stundensatz laut Rahmenvertrag, Rechnung bis zum Dritten.',+ en: 'Monthly by effort, hourly rate per framework agreement, invoice by the third.' } },+ { de: 'Server und Zugänge', en: 'Servers and access',+ content: { de: 'Staging und Produktion bei Deichblick, Zugang über VPN. Ansprechpartner im Kundenportal.',+ en: 'Staging and production at Deichblick, access via VPN. Contacts in the client portal.' } }+ ].freeze++ # Comments on the ticket of the detail motif, oldest first.+ COMMENTS = [+ { person: :svenja, hours_ago: 26,+ de: 'Deichblick braucht die Summen je Objekt und je Mieter, nicht nur je Objekt.',+ en: 'Deichblick needs the totals per property and per tenant, not only per property.' },+ { person: :ole, hours_ago: 2,+ de: 'Summenzeile steht, Mieter-Ebene ist drin. Morgen die Vorlage mit dem Logo von Deichblick.',+ en: 'Totals row is done, tenant level is in. Tomorrow the template with the Deichblick logo.' }+ ].freeze++ # Two meetings. The first comes with its summary, the second without one, so a+ # visitor of the demo can let the assistant write it. Speakers in a transcript+ # carry the display name of a participant; guests have no account.+ MEETINGS = [+ { project: :deichblick, days_ago: 2, minutes: 30,+ title: { de: 'Wochentermin mit Deichblick', en: 'Weekly call with Deichblick' },+ participants: [:svenja, :ole, 'Kerstin Möller'],+ transcript: {+ de: <<~TEXT,+ Svenja Brandt: Kurzer Stand zur Nebenkostenabrechnung. Ole, wie weit bist du?+ Ole Jensen: Der PDF-Export läuft, die Summenzeile steht. Die Summen je Mieter baue ich gerade ein.+ Kerstin Möller: Das ist wichtig für uns. Die Mieter fragen jedes Jahr nach ihrem eigenen Anteil.+ Ole Jensen: Dann kommt pro Mieter eine eigene Seite. Brauchen Sie das Logo von Deichblick oben?+ Kerstin Möller: Ja, bitte. Ich schicke es heute noch als Vektordatei.+ Svenja Brandt: Und die Schadensmeldung?+ Kerstin Möller: Die testen drei Hausmeister ab Montag. Danach können wir sie abnehmen.+ Svenja Brandt: Gut. Dann sehen wir uns zur Abnahme in zwei Wochen.+ TEXT+ en: <<~TEXT+ Svenja Brandt: Quick update on the service charge statement. Ole, how far are you?+ Ole Jensen: The PDF export works and the totals row is done. I am adding the totals per tenant now.+ Kerstin Möller: That matters to us. Tenants ask for their own share every year.+ Ole Jensen: Then each tenant gets a page of their own. Do you need the Deichblick logo at the top?+ Kerstin Möller: Yes, please. I will send it today as a vector file.+ Svenja Brandt: And the damage report?+ Kerstin Möller: Three caretakers test it from Monday. After that we can accept it.+ Svenja Brandt: Good. Then we meet for the acceptance in two weeks.+ TEXT+ },+ summary: {+ de: <<~TEXT,+ **Nebenkostenabrechnung:** PDF-Export und Summenzeile fertig. Jeder Mieter bekommt eine eigene Seite mit seinem Anteil.++ **Schadensmeldung:** Drei Hausmeister testen ab Montag, danach Abnahme.++ **Aufgaben**+ - Kerstin Möller schickt das Logo als Vektordatei.+ - Ole Jensen baut die Seite je Mieter mit Logo.+ - Abnahmetermin in zwei Wochen.+ TEXT+ en: <<~TEXT+ **Service charge statement:** PDF export and totals row are done. Each tenant gets a page of their own with their share.++ **Damage report:** Three caretakers test it from Monday, acceptance afterwards.++ **Action items**+ - Kerstin Möller sends the logo as a vector file.+ - Ole Jensen builds the page per tenant, with the logo.+ - Acceptance meeting in two weeks.+ TEXT+ } },+ { project: :faehrhaus, days_ago: 1, minutes: 45,+ title: { de: 'Kick-off Tourenplanung', en: 'Kick-off route planning' },+ participants: [:jana, :svenja, :malte, 'Tobias Reimers'],+ transcript: {+ de: <<~TEXT,+ Jana Petersen: Willkommen zum Kick-off. Tobias, erzähl kurz, was heute nicht funktioniert.+ Tobias Reimers: Wir planen 14 Fahrer mit einer Tabelle. Jede Änderung am Morgen kostet uns eine Stunde.+ Malte Hansen: Woher kommen die Aufträge? Per Mail, per Telefon, aus einem System?+ Tobias Reimers: Zwei Drittel aus unserem Warenwirtschaftssystem, der Rest per Telefon.+ Malte Hansen: Dann lesen wir die Aufträge aus der Warenwirtschaft und erfassen den Rest von Hand.+ Svenja Brandt: Für den ersten Schritt reicht eine Tagesansicht pro Fahrer, die man umsortieren kann.+ Tobias Reimers: Wichtig ist, dass die Fahrer die Tour auf dem Handy sehen.+ Jana Petersen: Dann nehmen wir das in den ersten Meilenstein. Svenja schickt bis Freitag ein Angebot.+ TEXT+ en: <<~TEXT+ Jana Petersen: Welcome to the kick-off. Tobias, tell us briefly what does not work today.+ Tobias Reimers: We plan 14 drivers in a spreadsheet. Every change in the morning costs us an hour.+ Malte Hansen: Where do the orders come from? Email, phone, another system?+ Tobias Reimers: Two thirds from our inventory system, the rest by phone.+ Malte Hansen: Then we read the orders from the inventory system and enter the rest by hand.+ Svenja Brandt: For the first step a day view per driver that can be reordered is enough.+ Tobias Reimers: What matters is that the drivers see their route on their phone.+ Jana Petersen: Then that goes into the first milestone. Svenja sends a proposal by Friday.+ TEXT+ },+ summary: nil }+ ].freeze++ # The assistant motif: one question, one answer citing a ticket, the hours on it+ # and a note. [1] to [3] are the inline links to the citations, in the order of+ # Lalabase::Demo::World#add_chat. The answer is stored, not generated; it has to+ # be one the product really gives (checked against a real run before a new set+ # of pictures).+ CHAT = {+ question: { de: 'Wie weit ist die Nebenkostenabrechnung für Deichblick?',+ en: 'How far along is the service charge statement for Deichblick?' },+ answer: {+ de: 'Der PDF-Export der Nebenkostenabrechnung ist in Bearbeitung [1]. Ole hat diese Woche ' \+ '4:30 Stunden darauf gebucht, zuletzt heute an der Summenzeile [2]. Laut Abnahmeprotokoll ' \+ 'vom %<accepted_on>s sind Anmeldung, Dokumente und Postfach abgenommen, die Schadensmeldung ist ' \+ 'noch offen [3].',+ en: 'The PDF export of the service charge statement is in progress [1]. Ole has booked ' \+ '4:30 hours on it this week, most recently today on the totals row [2]. According to the ' \+ 'acceptance record of %<accepted_on>s, sign-in, documents and inbox are accepted; the damage ' \+ 'report is still open [3].'+ },+ ticket: 3,+ note: 0,+ model: 'mistral-medium-latest'+ }.freeze++ module_function++ # The sidebar shows the part before the @, so the address carries the full name.+ def email(key)+ person = PEOPLE.fetch(key)+ "#{I18n.transliterate(person[:first_name]).downcase}.#{I18n.transliterate(person[:last_name]).downcase}@#{DOMAIN}"+ end++ def full_name(key) = PEOPLE.fetch(key).values_at(:first_name, :last_name).join(' ')++ # Fills the date placeholders of a text, seen from `now`.+ def dated(text, locale, now)+ dates = DATES.transform_values do |days|+ I18n.l((now + days.days).to_date, format: DATE_FORMAT.fetch(locale), locale: locale)+ end+ format(text, **dates)+ end+ end+ end+enddiff --git a/lib/lalabase/demo/world.rb b/lib/lalabase/demo/world.rbnew file mode 100644index 0000000..a3d20f1--- /dev/null+++ b/lib/lalabase/demo/world.rb@@ -0,0 +1,217 @@+# frozen_string_literal: true++module Lalabase+ module Demo+ # Builds the Nordlicht fiction (Lalabase::Demo::Fiction) in one language, for the+ # product screenshots and for the public demo.+ #+ # Every write goes through the path a real instance uses: the organisation through+ # Actors::CreateOrganisation, tickets, notes, comments, meetings and hours through+ # their actors, projects the way Organisations::ProjectsController creates them.+ # No factories: the demo runs in production, where FactoryBot is not installed,+ # and a factory would show a state no real instance produces. Only the stored+ # assistant answer is written directly, because its actor would ask a model.+ #+ # Entry point: build. The order of writes is explicit: people before projects,+ # projects before tickets, tickets before the hours booked on them.+ #+ # Lalabase::Demo::World.new(locale: :en).build+ #+ # `now` is the moment the world is seen from (frozen for the screenshots, the time+ # of the reset for the demo). `organisation` takes extra attributes for the+ # organisation, such as the AI switches. `embeddings` marks notes, comments and+ # meetings for the assistant's search.+ class World+ ORGANISATION_NAME = 'Nordlicht Software GmbH'++ attr_reader :organisation, :chat, :notes, :meetings++ def initialize(locale:, now: Time.current, organisation: {}, embeddings: false, password: nil)+ @locale = locale.to_sym+ @now = now+ @organisation_attributes = organisation+ @embeddings = embeddings+ @password = password || SecureRandom.base58(24)+ @people = {}+ @projects = {}+ @tickets = []+ end++ def person(key) = @people.fetch(key)+ def project(key) = @projects.fetch(key)+ def ticket(index) = @tickets.fetch(index)+ def signed_in = person(Fiction::SIGNED_IN)++ def build+ # The default smart folders and the role take their names from the locale at+ # creation, as they do for a real person who works in that language.+ I18n.with_locale(@locale) do+ create_organisation+ ActsAsTenant.with_tenant(@organisation) { build_inside }+ end+ self+ end++ private++ def build_inside+ role = add_team_role+ Fiction::PEOPLE.each_key do |key|+ next if key == Fiction::OWNER++ @people[key] = add_user(key)+ @people[key].memberships.create!(organisation: @organisation, role: role, active: true)+ end+ Fiction::PROJECTS.each_key { |key| @projects[key] = add_project(key) }+ add_tickets+ add_time+ add_notes+ add_comments+ add_meetings+ add_chat+ end++ def create_organisation+ owner = add_user(Fiction::OWNER)+ @people[Fiction::OWNER] = owner+ @organisation = Organisation.new(name: ORGANISATION_NAME, subdomain: 'nordlicht', domain: Fiction::DOMAIN,+ **@organisation_attributes)+ succeed!(Actors::CreateOrganisation.call(organisation: @organisation, owner: owner, current_user: owner))+ end++ # Confirmed right away: there is no inbox behind nordlicht.example.+ def add_user(key)+ User.create!(**Fiction::PEOPLE.fetch(key), email: Fiction.email(key),+ password: @password, password_confirmation: @password,+ language_preference: @locale.to_s, terms_accepted_at: @now,+ &:skip_confirmation!)+ end++ def add_team_role+ definition = Fiction::TEAM_ROLE+ role = @organisation.roles.create!(title: definition[:title].fetch(@locale),+ description: definition[:description].fetch(@locale))+ definition[:permissions].each do |category, actions|+ actions.each { |action| role.permissions.create!(category: category, action: action, allowed: true) }+ end+ role+ end++ # Mirrors Organisations::ProjectsController#create with default attributes ticked.+ def add_project(key)+ entry = Fiction::PROJECTS.fetch(key)+ project = @organisation.projects.create!(name: entry.fetch(@locale),+ description: entry[:description].fetch(@locale))+ Projects::DefaultAttributeService.new(project).call+ Projects::DefaultSmartFolderService.new(project).call(signed_in)+ add_members(project)+ project+ end++ # Mirrors Organisations::ProjectPermissionsController#create and its time+ # settings, without the activity entries a person adding a colleague leaves.+ def add_members(project)+ @people.each do |key, user|+ next if key == Fiction::OWNER++ project.project_permissions.create!(user: user, **Fiction::PROJECT_ACCESS)+ user.time_session_permission_for(project)+ .update!(key == Fiction::SIGNED_IN ? Fiction::LEAD_TIME_RIGHTS : {})+ Projects::DefaultSmartFolderService.new(project).create_my_tasks_for(user) unless key == Fiction::SIGNED_IN+ end+ end++ def add_tickets+ Fiction::TICKETS.each do |entry|+ params = { title: entry.fetch(@locale),+ custom_attributes: { 'status' => entry[:status], 'priority' => entry[:priority] } }+ params[:assignee_ids] = [person(entry[:assignee]).id] if entry[:assignee]+ @tickets << succeed!(Actors::SaveTicket.call(project: project(:deichblick), params: params,+ current_user: signed_in))+ end+ # Created over the last weeks, oldest first, so the list does not say "less+ # than a minute ago" nine times.+ @tickets.each_with_index do |ticket, index|+ backdate(ticket, @now - ((@tickets.size - index) * 3).days)+ end+ end++ def add_time+ Fiction::TIME.each do |entry|+ creator = person(entry[:person])+ session = TimeSession.new(organisation: @organisation, project: project(:deichblick),+ ticket: entry[:ticket] && ticket(entry[:ticket]), creator: creator,+ duration: entry[:minutes], occurred_on: @now - entry[:days_ago].days,+ description: entry.fetch(@locale))+ succeed!(Actors::SaveTimeSession.call(time_session: session, attributes: {},+ group_change: { requested: false }, current_user: creator))+ end+ end++ def add_notes+ @notes = Fiction::NOTES.each_with_index.map do |entry, index|+ params = { title: entry.fetch(@locale), content: dated(entry[:content].fetch(@locale)),+ description: nil, create_embeddings: @embeddings }+ note = succeed!(Actors::SaveNote.call(project: project(:deichblick), params: params, current_user: signed_in))+ backdate(note, @now - (index + 1).weeks)+ end+ end++ def add_comments+ target = ticket(Fiction::CHAT[:ticket])+ Fiction::COMMENTS.each do |entry|+ params = { content: entry.fetch(@locale), create_embeddings: @embeddings }+ post = succeed!(Actors::SavePost.call(ticket: target, params: params, current_user: person(entry[:person])))+ backdate(post, @now - entry[:hours_ago].hours)+ end+ end++ def add_meetings+ @meetings = Fiction::MEETINGS.map do |entry|+ params = { title: entry[:title].fetch(@locale), occurred_at: @now - entry[:days_ago].days,+ duration_minutes: entry[:minutes], transcript: entry[:transcript].fetch(@locale),+ generated_summary: entry[:summary]&.fetch(@locale).to_s, create_embeddings: @embeddings,+ participants: entry[:participants].map { |who| participant(who) } }+ succeed!(Actors::SaveMeeting.call(project: project(entry[:project]), params: params, current_user: signed_in))+ end+ end++ # A key is a person of the company, a string a guest without an account.+ def participant(who)+ return { display_name: who, user_id: nil } if who.is_a?(String)++ { display_name: Fiction.full_name(who), user_id: person(who).id }+ end++ # The first post of a chat renders as the question (Chatpost#set_initial_role+ # makes it 'system'). model_used marks the answer as finished; without it the [n]+ # links stay text.+ def add_chat+ spec = Fiction::CHAT+ @chat = Chat.new(organisation: @organisation, user: signed_in)+ @chat.chatposts.build(organisation: @organisation, user: signed_in, content: spec[:question].fetch(@locale))+ @chat.save!+ citations = [Lalabase::Citations.ticket(ticket(spec[:ticket])),+ Lalabase::Citations.time_report(project(:deichblick), {}),+ Lalabase::Citations.note(@notes.fetch(spec[:note]))]+ @chat.chatposts.create!(organisation: @organisation, user: signed_in, role: 'assistant',+ content: dated(spec[:answer].fetch(@locale)), model_used: spec[:model],+ source_citations: citations.map(&:deep_stringify_keys))+ @chat.chatposts.update_all(created_at: @now - 20.minutes)+ end++ def dated(text) = Fiction.dated(text, @locale, @now)++ def backdate(record, at)+ record.update_columns(created_at: at, updated_at: at)+ record+ end++ def succeed!(result)+ raise "Demo world: #{result.errors.to_sentence}" unless result.success?++ result.resource+ end+ end+ end+enddiff --git a/spec/lib/lalabase/demo/world_spec.rb b/spec/lib/lalabase/demo/world_spec.rbnew file mode 100644index 0000000..b9d22dc--- /dev/null+++ b/spec/lib/lalabase/demo/world_spec.rb@@ -0,0 +1,113 @@+# frozen_string_literal: true++require 'rails_helper'++RSpec.describe Lalabase::Demo::World do+ include ActiveSupport::Testing::TimeHelpers++ let(:now) { Time.zone.local(2026, 11, 4, 9, 0) }+ let(:password) { 'demo-password-for-the-spec' }+ let(:fiction) { Lalabase::Demo::Fiction }++ # A seeder writes one record after another through the services a request uses+ # once; the repeated lookups that follow are not a page's N+1.+ def build(**options)+ Prosopite.pause do+ travel_to(now) { described_class.new(locale: :en, now: now, password: password, **options).build }+ end+ end++ describe 'the world it builds' do+ let!(:world) { build }+ let(:organisation) { world.organisation }++ around { |example| ActsAsTenant.without_tenant { example.run } }++ it 'holds the people, projects and records of the fiction' do+ expect(organisation.name).to eq(described_class::ORGANISATION_NAME)+ expect(organisation.users.pluck(:email)).to match_array(fiction::PEOPLE.keys.map { fiction.email(_1) })+ expect(organisation.projects.pluck(:name)).to match_array(fiction::PROJECTS.values.map { _1[:en] })+ expect(world.project(:deichblick).tickets.order(:created_at).pluck(:title)).to eq(fiction::TICKETS.map { _1[:en] })+ expect(TimeSession.where(organisation: organisation).count).to eq(fiction::TIME.size)+ expect(world.notes.map(&:title)).to eq(fiction::NOTES.map { _1[:en] })+ expect(world.ticket(fiction::CHAT[:ticket]).posts.count).to eq(fiction::COMMENTS.size)+ expect(world.chat.chatposts.count).to eq(2)+ end++ # The demo signs a visitor in as this person: every right of the team, none of+ # the account.+ it 'gives the signed-in person the team role, not the account admin role' do+ signed_in = world.signed_in+ expect(signed_in.email).to eq(fiction.email(fiction::SIGNED_IN))+ expect(signed_in.role_in_organisation(organisation)).not_to be_account_admin+ expect(world.person(fiction::OWNER).role_in_organisation(organisation)).to be_account_admin+ expect(signed_in.has_permission_in_organisation?(organisation, 'assistant', 'use_assistant')).to be(true)+ expect(signed_in.can_access_project?(world.project(:faehrhaus), :write, :tickets)).to be(true)+ end++ # The time list is the first thing that went missing without the admin role.+ it 'lets the signed-in person see everybody\'s hours, and the others their own' do+ expect(TimeSessions::ViewingScope.call(user: world.signed_in, project: world.project(:deichblick)).tier)+ .to eq(:all)+ expect(TimeSessions::ViewingScope.call(user: world.person(:ole), project: world.project(:deichblick)).tier)+ .to eq(:own)+ end++ it 'lets every person sign in with the given password, confirmed' do+ organisation.users.each do |user|+ expect(user.valid_password?(password)).to be(true)+ expect(user).to be_confirmed+ end+ end++ it 'adds one meeting with its summary and one waiting for it, with guests among the participants' do+ with_summary, without_summary = world.meetings+ expect(with_summary.generated_summary).to include('Damage report')+ expect(without_summary.generated_summary).to be_blank+ expect(without_summary.summary_source).to be_present+ expect(with_summary.meeting_participants.pluck(:display_name, :user_id))+ .to contain_exactly(['Svenja Brandt', world.person(:svenja).id], ['Ole Jensen', world.person(:ole).id],+ ['Kerstin Möller', nil])+ end++ # A text names its dates from the moment of the build, so a world built today+ # does not speak of an acceptance six months ago.+ it 'fills the dates of its texts from the moment it is built' do+ expect(world.notes.first.content.to_s).to include('Acceptance with Deichblick Immobilien on 27 October')+ expect(world.chat.chatposts.find_by(role: 'assistant').content).to include('acceptance record of 27 October')+ expect(world.notes.first.content.to_s + world.chat.chatposts.map(&:content).join).not_to include('%<')+ end++ it 'dates its records back from the moment it is built' do+ expect(world.ticket(0).created_at).to eq(now - (fiction::TICKETS.size * 3).days)+ expect(TimeSession.where(organisation: organisation).maximum(:occurred_on).to_date).to eq(now.to_date)+ end++ it 'leaves the assistant search off unless asked' do+ expect(world.notes.map(&:create_embeddings)).to all(be(false))+ expect(world.meetings.map(&:create_embeddings)).to all(be(false))+ end+ end++ it 'marks notes, comments and meetings for the search when asked' do+ world = build(embeddings: true)+ ActsAsTenant.without_tenant do+ expect(world.notes.map(&:create_embeddings)).to all(be(true))+ expect(world.meetings.map(&:create_embeddings)).to all(be(true))+ expect(Post.where(organisation: world.organisation).pluck(:create_embeddings)).to all(be(true))+ end+ end++ it 'passes extra attributes to the organisation' do+ world = build(organisation: { assistant_enabled: true, ai_enabled: true })+ expect(world.organisation.reload).to have_attributes(assistant_enabled: true, ai_enabled: true)+ end++ # The demo builds this world in production, where the test group of the bundle is+ # not installed. A tripwire, not a proof: it reads the source.+ it 'uses no factories' do+ code = Rails.root.join('lib/lalabase/demo/world.rb').readlines.grep_v(/\A\s*#/).join+ expect(code).to include('Actors::SaveTicket.call')+ expect(code).not_to match(/FactoryBot|\bcreate\(:|\bbuild\(:/)+ end+enddiff --git a/spec/marketing/nordlicht_fiction.rb b/spec/marketing/nordlicht_fiction.rbdeleted file mode 100644index 16a716d..0000000--- a/spec/marketing/nordlicht_fiction.rb+++ /dev/null@@ -1,151 +0,0 @@-# frozen_string_literal: true--# The company in the product screenshots of the project website: Nordlicht Software GmbH, Kiel, six-# people, two clients. Everything here is invented. Addresses use nordlicht.example-# (RFC 2606, never deliverable), avatars are initials, and no name belongs to a real-# person we know of. Before a new set of pictures goes to the website, every name in-# this file goes through script/leak_guard.-#-# Each text exists in German and English, because the pictures for /en show the-# English interface, and an English interface around German ticket titles would look-# like a product made for Germany only.-#-# Writes go through the paths a real instance uses where those paths decide what the-# page shows (Projects::DefaultAttributeService for status and priority,-# Actors::SaveTicket for the ticket numbers), and through factories everywhere else,-# like the system specs.-module NordlichtFiction- # A Wednesday morning: the week columns of the time list show Monday to today.- NOW = Time.zone.local(2026, 10, 14, 10, 30)-- DOMAIN = 'nordlicht.example'-- PEOPLE = {- svenja: { first_name: 'Svenja', last_name: 'Brandt' }, # project lead, signed in- jana: { first_name: 'Jana', last_name: 'Petersen' }, # managing director- malte: { first_name: 'Malte', last_name: 'Hansen' }, # development- ole: { first_name: 'Ole', last_name: 'Jensen' }, # development- lena: { first_name: 'Lena', last_name: 'Thiel' }, # design- finn: { first_name: 'Finn', last_name: 'Carstensen' } # support- }.freeze-- PROJECTS = {- deichblick: { de: 'Deichblick Kundenportal', en: 'Deichblick client portal',- description: { de: 'Objektverwaltung für Deichblick Immobilien.',- en: 'Property management for Deichblick Immobilien.' } },- faehrhaus: { de: 'Fährhaus Tourenplanung', en: 'Fährhaus route planning',- description: { de: 'Tourenplanung für Fährhaus Logistik.',- en: 'Route planning for Fährhaus Logistik.' } },- intern: { de: 'Nordlicht intern', en: 'Nordlicht internal',- description: { de: 'Eigene Website und Abläufe.', en: 'Our own website and processes.' } }- }.freeze-- # Oldest first: the numbers follow the order of creation.- TICKETS = [- { de: 'Anmeldung mit Einmalcode für Mieter', en: 'One-time code sign-in for tenants',- status: 'resolved', priority: 'high', assignee: :malte },- { de: 'Mieterportal: Dokumente nach Objekt sortieren', en: 'Tenant portal: sort documents by property',- status: 'resolved', priority: 'normal', assignee: :ole },- { de: 'Schadensmeldung mit Fotos', en: 'Damage report with photos',- status: 'in_progress', priority: 'high', assignee: :malte },- { de: 'Nebenkostenabrechnung als PDF exportieren', en: 'Export the service charge statement as PDF',- status: 'in_progress', priority: 'urgent', assignee: :ole },- { de: 'Entwürfe für die Objektübersicht', en: 'Designs for the property overview',- status: 'in_progress', priority: 'normal', assignee: :lena },- { de: 'Login-Fehler bei Umlauten im Passwort', en: 'Login fails with umlauts in the password',- status: 'new', priority: 'urgent', assignee: :finn },- { de: 'Hausmeister-Rolle mit Lesezugriff', en: 'Caretaker role with read access',- status: 'new', priority: 'normal', assignee: :malte },- { de: 'Erinnerung vor Ablauf der Wartungsverträge', en: 'Reminder before maintenance contracts expire',- status: 'backlog', priority: 'low', assignee: nil },- { de: 'Schnittstelle zur Buchhaltung klären', en: 'Clarify the interface to accounting',- status: 'backlog', priority: 'normal', assignee: :svenja }- ].freeze-- # Minutes per person and day, relative to NOW, on the ticket at that index.- TIME = [- { person: :malte, days_ago: 0, minutes: 150, ticket: 2,- de: 'Upload der Fotos, Vorschau', en: 'Photo upload, preview' },- { person: :ole, days_ago: 0, minutes: 90, ticket: 3,- de: 'PDF-Vorlage, Summenzeile', en: 'PDF template, totals row' },- { person: :lena, days_ago: 1, minutes: 240, ticket: 4,- de: 'Objektübersicht, zweiter Entwurf', en: 'Property overview, second draft' },- { person: :malte, days_ago: 1, minutes: 210, ticket: 2,- de: 'Schadensmeldung: Formular und Prüfung', en: 'Damage report: form and validation' },- { person: :svenja, days_ago: 1, minutes: 60, ticket: nil,- de: 'Abstimmung mit Deichblick', en: 'Call with Deichblick' },- { person: :ole, days_ago: 2, minutes: 180, ticket: 3,- de: 'Datenabfrage für die Abrechnung', en: 'Query for the statement' },- { person: :finn, days_ago: 2, minutes: 45, ticket: 5,- de: 'Fehler nachgestellt', en: 'Reproduced the error' }- ].freeze-- NOTES = [- { de: 'Abnahmeprotokoll Mieterportal', en: 'Acceptance record tenant portal',- content: {- de: '<p>Abnahme mit Deichblick Immobilien am 6. Oktober, im Büro Kiel.</p>' \- '<p><strong>Abgenommen</strong></p>' \- '<ul><li>Anmeldung mit Einmalcode</li><li>Dokumente je Objekt</li>' \- '<li>Postfach für Mieter</li></ul>' \- '<p><strong>Offen</strong></p>' \- '<ul><li>Schadensmeldung mit Fotos, Abnahme nach dem Test mit drei Hausmeistern</li>' \- '<li>PDF-Export der Nebenkostenabrechnung, Termin Ende Oktober</li></ul>' \- '<p>Nächster Termin: 28. Oktober.</p>',- en: '<p>Acceptance with Deichblick Immobilien on 6 October, at the Kiel office.</p>' \- '<p><strong>Accepted</strong></p>' \- '<ul><li>Sign-in with a one-time code</li><li>Documents per property</li>' \- '<li>Inbox for tenants</li></ul>' \- '<p><strong>Open</strong></p>' \- '<ul><li>Damage report with photos, accepted after the test with three caretakers</li>' \- '<li>PDF export of the service charge statement, due end of October</li></ul>' \- '<p>Next meeting: 28 October.</p>'- } },- { de: 'Wie wir mit Deichblick abrechnen', en: 'How we bill Deichblick',- content: { de: 'Monatlich nach Aufwand, Stundensatz laut Rahmenvertrag, Rechnung bis zum Dritten.',- en: 'Monthly by effort, hourly rate per framework agreement, invoice by the third.' } },- { de: 'Server und Zugänge', en: 'Servers and access',- content: { de: 'Staging und Produktion bei Deichblick, Zugang über VPN. Ansprechpartner im Kundenportal.',- en: 'Staging and production at Deichblick, access via VPN. Contacts in the client portal.' } }- ].freeze-- # Comments on the ticket of the detail motif, oldest first, hours before NOW.- COMMENTS = [- { person: :svenja, hours_ago: 26,- de: 'Deichblick braucht die Summen je Objekt und je Mieter, nicht nur je Objekt.',- en: 'Deichblick needs the totals per property and per tenant, not only per property.' },- { person: :ole, hours_ago: 2,- de: 'Summenzeile steht, Mieter-Ebene ist drin. Morgen die Vorlage mit dem Logo von Deichblick.',- en: 'Totals row is done, tenant level is in. Tomorrow the template with the Deichblick logo.' }- ].freeze-- # The assistant motif: one question, one answer citing a ticket, the hours on it and- # a note. [1] to [3] are the inline links to the citations, in the order of- # NordlichtWorld#add_chat. The answer is stored, not generated; it has to be one the- # product really gives (checked against a real run before a new set of pictures).- CHAT = {- question: { de: 'Wie weit ist die Nebenkostenabrechnung für Deichblick?',- en: 'How far along is the service charge statement for Deichblick?' },- answer: {- de: 'Der PDF-Export der Nebenkostenabrechnung ist in Bearbeitung [1]. Ole hat diese Woche ' \- '4:30 Stunden darauf gebucht, zuletzt heute an der Summenzeile [2]. Laut Abnahmeprotokoll ' \- 'vom 6. Oktober sind Anmeldung, Dokumente und Postfach abgenommen, die Schadensmeldung ist ' \- 'noch offen [3].',- en: 'The PDF export of the service charge statement is in progress [1]. Ole has booked ' \- '4:30 hours on it this week, most recently today on the totals row [2]. According to the ' \- 'acceptance record of 6 October, sign-in, documents and inbox are accepted; the damage ' \- 'report is still open [3].'- },- ticket: 3,- note: 0- }.freeze-- module_function-- def text(entry, locale) = entry.fetch(locale)-- # The sidebar shows the part before the @, so the address carries the full name.- def email(key)- person = PEOPLE.fetch(key)- "#{I18n.transliterate(person[:first_name]).downcase}.#{I18n.transliterate(person[:last_name]).downcase}@#{DOMAIN}"- end-enddiff --git a/spec/marketing/screenshots_spec.rb b/spec/marketing/screenshots_spec.rbindex 96f24dd..8a4c348 100644--- a/spec/marketing/screenshots_spec.rb+++ b/spec/marketing/screenshots_spec.rb@@ -1,7 +1,6 @@# frozen_string_literal: truerequire 'rails_helper'-require_relative 'nordlicht_fiction'# The product screenshots for the project website.#@@ -9,13 +8,20 @@ require_relative 'nordlicht_fiction'## MARKETING_SCREENSHOTS=1 bundle exec rspec spec/marketing/screenshots_spec.rb#-# It builds the Nordlicht fiction in the test database, freezes the clock and saves+# It builds the Nordlicht fiction (Lalabase::Demo::World, the same world as the+# public demo) in the test database, freezes the clock and saves# one picture per motif and language to tmp/screenshots/marketing/<locale>/. The# website imports them from there; nothing of it is committed here.## It fails loudly when a screen changes shape (a selector it waits for is gone), which# is the point: a stale picture on the website is worse than a red run.module MarketingScreenshots+ # A Wednesday morning: the week columns of the time list show Monday to today.+ NOW = Time.zone.local(2026, 10, 14, 10, 30)+ # The assistant shows without a real model behind it: the answer in the pictures+ # is stored, and a key that is never called only switches the panel on.+ ORGANISATION = { ai_enabled: true, assistant_enabled: true, ai_provider: 'openai',+ ai_access_token: 'sk-fiction-0000000000000000' }.freezeOUTPUT = Rails.root.join('tmp/screenshots/marketing')# Wide enough that the ticket list shows names and dates in full.WIDTH = 1600@@ -50,7 +56,7 @@ RSpec.describe 'Marketing screenshots', :marketing_screenshots, type: :system do# assistant picture stays for every picture after it.page.driver.browser.manage.window.resize_to(MarketingScreenshots::WIDTH, MarketingScreenshots::HEIGHT)Prosopite.pause- travel_to NordlichtFiction::NOW+ travel_to MarketingScreenshots::NOWset_browser_clockend@@ -62,7 +68,7 @@ RSpec.describe 'Marketing screenshots', :marketing_screenshots, type: :system do# every page before any script of the page runs.def set_browser_clockreal_ms = Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond)- offset = (NordlichtFiction::NOW.to_f * 1000).to_i - real_ms+ offset = (MarketingScreenshots::NOW.to_f * 1000).to_i - real_mspage.driver.browser.execute_cdp('Page.addScriptToEvaluateOnNewDocument', source: <<~JS)(() => {const RealDate = Date@@ -127,16 +133,19 @@ RSpec.describe 'Marketing screenshots', :marketing_screenshots, type: :system do%i[de en].each do |locale|context "in #{locale}" do- let(:world) { NordlichtWorld.new(locale).build }+ let(:world) do+ Lalabase::Demo::World.new(locale:, now: MarketingScreenshots::NOW,+ organisation: MarketingScreenshots::ORGANISATION).build+ endbefore doActsAsTenant.current_tenant = world.organisation- sign_in world.person(:svenja)+ sign_in world.signed_inendit 'takes the ticket list' dovisit organisation_project_tickets_path(world.organisation, world.project(:deichblick))- expect(page).to have_text(NordlichtFiction::TICKETS.last.fetch(locale))+ expect(page).to have_text(Lalabase::Demo::Fiction::TICKETS.last.fetch(locale))capture(locale, :tickets)end@@ -145,7 +154,7 @@ RSpec.describe 'Marketing screenshots', :marketing_screenshots, type: :system doit 'takes the time list' dopage.driver.browser.manage.window.resize_to(MarketingScreenshots::TILE_WIDTH, MarketingScreenshots::HEIGHT)visit organisation_time_sessions_path(world.organisation, date_range: 'this_week')- expect(page).to have_text(NordlichtFiction::TICKETS[3].fetch(locale))+ expect(page).to have_text(Lalabase::Demo::Fiction::TICKETS[3].fetch(locale))capture(locale, :time, clip_to: '#timeSessions')end@@ -153,7 +162,9 @@ RSpec.describe 'Marketing screenshots', :marketing_screenshots, type: :system doit 'takes the knowledge list with an open note' dovisit organisation_project_knowledge_index_path(world.organisation, world.project(:deichblick),note_id: world.notes.first.id)- last_line = Nokogiri::HTML.fragment(NordlichtFiction::NOTES.first[:content].fetch(locale)).css('p').last.text+ content = Lalabase::Demo::Fiction::NOTES.first[:content].fetch(locale)+ last_line = Nokogiri::HTML.fragment(Lalabase::Demo::Fiction.dated(content, locale, MarketingScreenshots::NOW))+ .css('p').last.textexpect(page).to have_text(last_line)expect(page).to have_no_css('.layout.hide-content')capture(locale, :knowledge, clip_to: 'main.column.content', until_bottom_of: '#note-header')@@ -161,9 +172,9 @@ RSpec.describe 'Marketing screenshots', :marketing_screenshots, type: :system do# One ticket with its comments and the hours booked on it.it 'takes a ticket with its context' do- ticket = world.ticket(NordlichtFiction::CHAT[:ticket])+ ticket = world.ticket(Lalabase::Demo::Fiction::CHAT[:ticket])visit organisation_project_ticket_path(world.organisation, world.project(:deichblick), ticket)- expect(page).to have_text(NordlichtFiction::COMMENTS.last.fetch(locale))+ expect(page).to have_text(Lalabase::Demo::Fiction::COMMENTS.last.fetch(locale))capture(locale, :ticket)end@@ -183,131 +194,3 @@ RSpec.describe 'Marketing screenshots', :marketing_screenshots, type: :system doendendend--# Builds the fiction for one language. A class rather than let-blocks, so the order of-# writes is explicit: people before projects, projects before tickets, tickets before-# the hours booked on them.-class NordlichtWorld- include FactoryBot::Syntax::Methods-- attr_reader :organisation, :chat, :notes-- def initialize(locale)- @locale = locale- @people = {}- @projects = {}- @tickets = []- end-- def person(key) = @people.fetch(key)- def project(key) = @projects.fetch(key)- def ticket(index) = @tickets.fetch(index)-- def build- @organisation = create(:organisation, name: 'Nordlicht Software GmbH', subdomain: 'nordlicht',- domain: NordlichtFiction::DOMAIN, assistant_enabled: true,- ai_provider: 'openai', ai_access_token: 'sk-fiction-0000000000000000')- # The default smart folders take their names from the locale at creation, as they- # do for a real person who creates a project in that language.- I18n.with_locale(@locale) { build_inside }- self- end-- private-- def build_inside- ActsAsTenant.with_tenant(@organisation) do- role = create(:admin_role, organisation: @organisation)- create(:permission, role: role, category: 'assistant', action: 'use_assistant', allowed: true)- NordlichtFiction::PEOPLE.each { |key, names| @people[key] = add_person(key, names, role) }- NordlichtFiction::PROJECTS.each_key { |key| @projects[key] = add_project(key) }- add_tickets- add_time- add_notes- add_comments- add_chat- end- end-- def add_person(key, names, role)- user = create(:user, **names, email: NordlichtFiction.email(key), language_preference: @locale.to_s)- create(:membership, user: user, organisation: @organisation, role: role, active: true)- user- end-- def add_project(key)- entry = NordlichtFiction::PROJECTS.fetch(key)- project = create(:project, organisation: @organisation, name: entry.fetch(@locale),- description: entry[:description].fetch(@locale), repository: nil)- Projects::DefaultAttributeService.new(project).call- Projects::DefaultSmartFolderService.new(project).call(person(:svenja))- project- end-- def add_tickets- NordlichtFiction::TICKETS.each do |entry|- params = { title: entry.fetch(@locale),- custom_attributes: { 'status' => entry[:status], 'priority' => entry[:priority] } }- params[:assignee_ids] = [person(entry[:assignee]).id] if entry[:assignee]- result = Actors::SaveTicket.call(project: project(:deichblick), params: params, current_user: person(:svenja))- raise "Fiction ticket failed: #{result.errors.to_sentence}" unless result.success?-- @tickets << result.resource- end- # Created over the last weeks, oldest first, so the list does not say "less than a- # minute ago" nine times.- @tickets.each_with_index do |ticket, index|- at = NordlichtFiction::NOW - ((@tickets.size - index) * 3).days- ticket.update_columns(created_at: at, updated_at: at)- end- end-- def add_time- NordlichtFiction::TIME.each do |entry|- create(:time_session, organisation: @organisation, project: project(:deichblick),- ticket: entry[:ticket] && @tickets.fetch(entry[:ticket]),- creator: person(entry[:person]), duration: entry[:minutes],- occurred_on: NordlichtFiction::NOW - entry[:days_ago].days,- description: entry.fetch(@locale))- end- end-- def add_notes- @notes = NordlichtFiction::NOTES.map do |entry|- create(:note, organisation: @organisation, project: project(:deichblick), creator: person(:svenja),- title: entry.fetch(@locale), content: entry[:content].fetch(@locale),- description: nil, create_embeddings: false)- end- @notes.each_with_index do |note, index|- at = NordlichtFiction::NOW - (index + 1).weeks- note.update_columns(created_at: at, updated_at: at)- end- end-- def add_comments- ticket = @tickets.fetch(NordlichtFiction::CHAT[:ticket])- NordlichtFiction::COMMENTS.each do |entry|- post = create(:post, ticket: ticket, organisation: @organisation, user: person(entry[:person]),- content: entry.fetch(@locale), create_embeddings: false)- at = NordlichtFiction::NOW - entry[:hours_ago].hours- post.update_columns(created_at: at, updated_at: at)- end- end-- # The first post of a chat renders as the question (Chatpost#set_initial_role makes it- # 'system'). model_used marks the answer as finished; without it the [n] links stay text.- def add_chat- spec = NordlichtFiction::CHAT- svenja = person(:svenja)- @chat = create(:chat, organisation: @organisation, user: svenja)- @chat.chatposts.first.update!(user: svenja, content: spec[:question].fetch(@locale))- citations = [Lalabase::Citations.ticket(@tickets.fetch(spec[:ticket])),- Lalabase::Citations.time_report(project(:deichblick), {}),- Lalabase::Citations.note(@notes.fetch(spec[:note]))]- create(:chatpost, chat: @chat, organisation: @organisation, user: svenja, role: 'assistant',- content: spec[:answer].fetch(@locale), model_used: 'mistral-medium-latest',- source_citations: citations.map(&:deep_stringify_keys))- # A fixed moment instead of "less than a minute ago", which flips while the run takes.- @chat.chatposts.update_all(created_at: NordlichtFiction::NOW - 20.minutes)- end-end