Skip to content

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.

fix: review round 3 of #121, read each form's proof once and count only the probe's own markers

Guido Boyked5ab2501c4d3
diff --git a/app/services/meetings/transcript_mark.rb b/app/services/meetings/transcript_mark.rb
index 7e6d563..7b082e7 100644
--- a/app/services/meetings/transcript_mark.rb
+++ b/app/services/meetings/transcript_mark.rb
@@ -90,8 +90,27 @@ module Meetings
# The place of a heard form at the mark: the mark's own place for the form
# as marked, else the occurrence of the changed form that overlaps the mark,
- # proved at its place on the page the same way.
+ # proved at its place on the page the same way. Read once per form: the
+ # dialog asks again for "everywhere", and each proof renders the page.
def place_of(heard)
+ @places ||= {}
+ @places[words(heard)] ||= proved_place_of(heard)
+ end
+
+ # Whether "everywhere" may replace the heard form: the form stands at the
+ # mark, and the page shows every stored occurrence of it, each at a place of
+ # its own and in order, with the page otherwise as before.
+ def everywhere?(heard)
+ @everywhere ||= {}
+ key = words(heard)
+ return @everywhere[key] if @everywhere.key?(key)
+
+ @everywhere[key] = place_of(heard).success? && all_shown?(replacement_for(heard))
+ end
+
+ private
+
+ def proved_place_of(heard)
result = resolve
return result unless result.success?
return result if same_form?(heard)
@@ -106,18 +125,6 @@ module Meetings
Result.new(place: place_for(occurrence), error: nil)
end
- # Whether "everywhere" may replace the heard form: the form stands at the
- # mark, and the page shows every stored occurrence of it, each at a place of
- # its own and in order, with the page otherwise as before.
- def everywhere?(heard)
- @everywhere ||= {}
- return @everywhere[heard] if @everywhere.key?(heard)
-
- @everywhere[heard] = place_of(heard).success? && all_shown?(replacement_for(heard))
- end
-
- private
-
def map(start)
shown = TermReplacement.new(text: visible, heard: @mark, skip_frontmatter: false).scan
line_index, column = line_and_column(start)
@@ -157,12 +164,13 @@ module Meetings
# Every occurrence replaced by a marker of its own: the page shows the
# markers once each, in order, and with the stored texts put back it is the
- # page as it was.
+ # page as it was. Text of the transcript that only looks like a marker is
+ # no marker of this probe, and stays as it is (review round 3 of #121).
def all_shown?(replacement)
texts = {}
probe = replacement.replace_each { |occurrence| new_marker.tap { |marker| texts[marker] = replacement.text_at(occurrence) } }
shown = text_of(@render.call(probe.text))
- return false unless shown.scan(MARKER) == texts.keys
+ return false unless shown.scan(MARKER).select { |marker| texts.key?(marker) } == texts.keys
shown.gsub(MARKER) { |marker| texts.fetch(marker, marker) } == visible
end
diff --git a/config/locales/views/meetings.de.yml b/config/locales/views/meetings.de.yml
index 7d0b318..4b0b2df 100644
--- a/config/locales/views/meetings.de.yml
+++ b/config/locales/views/meetings.de.yml
@@ -181,7 +181,7 @@ de:
other: "Kommt %{count}-mal vor, davon %{speaker_count}-mal bei %{speaker}."
not_at_mark: Diese Form steht nicht an der markierten Stelle. Ändere sie oder markiere neu.
ambiguous: Diese Form lässt sich an der markierten Stelle nicht sicher zuordnen. Markiere sie neu oder ändere sie über „Bearbeiten“.
- everywhere_hidden: Überall ersetzen geht hier nicht. Die Form steht auch an Stellen, die die Seite nicht zeigt (etwa in einem Link).
+ everywhere_hidden: Überall ersetzen geht hier nicht. Die Seite zeigt nicht jede Stelle dieser Form so, wie sie gespeichert ist (etwa in einem Link).
heard_blank: Bitte die gehörte Form eingeben.
mark_errors:
not_found: Diese Stelle lässt sich im Transkript nicht finden. Lade die Seite neu und markiere noch einmal.
diff --git a/config/locales/views/meetings.en.yml b/config/locales/views/meetings.en.yml
index 6d4a7a8..9db7b04 100644
--- a/config/locales/views/meetings.en.yml
+++ b/config/locales/views/meetings.en.yml
@@ -180,7 +180,7 @@ en:
other: "Appears %{count} times, %{speaker_count} of them by %{speaker}."
not_at_mark: This form does not stand at the marked place. Change it or mark again.
ambiguous: This form cannot be matched to the marked place for sure. Mark it again or change it through "Edit".
- everywhere_hidden: Replacing everywhere does not work here. The form also stands in places the page does not show (in a link, for example).
+ everywhere_hidden: Replacing everywhere does not work here. The page does not show every place of this form as it is stored (in a link, for example).
heard_blank: Please enter the heard form.
mark_errors:
not_found: This place cannot be found in the transcript. Reload the page and mark again.
diff --git a/spec/requests/organisations/meeting_term_corrections_spec.rb b/spec/requests/organisations/meeting_term_corrections_spec.rb
index 9a5630e..097039e 100644
--- a/spec/requests/organisations/meeting_term_corrections_spec.rb
+++ b/spec/requests/organisations/meeting_term_corrections_spec.rb
@@ -132,6 +132,7 @@ RSpec.describe 'Organisations::MeetingTermCorrections', :ci_guard, type: :reques
expect(dialog).to have_text(I18n.t("#{tc}.count.found_by_speaker", count: 3, speaker_count: 2, speaker: 'Ben Birne'))
expect(dialog).to have_button(I18n.t("#{tc}.everywhere", count: 3))
expect(dialog).to have_button(I18n.t("#{tc}.here"))
+ expect(dialog).to have_no_text(I18n.t("#{tc}.count.everywhere_hidden"))
expect(dialog).to have_css("input[name='digest'][value='#{digest}']", visible: :all)
end
diff --git a/spec/services/meetings/transcript_mark_spec.rb b/spec/services/meetings/transcript_mark_spec.rb
index b437f69..f743a1a 100644
--- a/spec/services/meetings/transcript_mark_spec.rb
+++ b/spec/services/meetings/transcript_mark_spec.rb
@@ -190,6 +190,55 @@ RSpec.describe Meetings::TranscriptMark do
expect(mark.place_of('Lala *beis*').error).to eq(:ambiguous)
end
+ # Review round 3 of #121: a changed form that begins before the mark, at
+ # the first match and at a later one.
+ it 'finds a changed form that begins before the mark' do
+ text = "Anna: Herr Lala Beis sagte etwas.\nBen: Lala Beis nochmal."
+
+ first = mark_object(text, mark: 'Beis', nth: 0)
+ later = mark_object(text, mark: 'Beis', nth: 1)
+
+ expect(first.place_of('Lala Beis').place.to_h).to eq(line_index: 0, char_offset: 11, length: 9)
+ expect(later.place_of('Lala Beis').place.to_h).to eq(line_index: 1, char_offset: 5, length: 9)
+ end
+
+ # Review round 3 of #121: the page shows every marker, in order, and still
+ # is not the page it was: the stored "&" shows as "&", and the
+ # markers in it show as text. Only the comparison with the old page sees it.
+ it 'refuses everywhere where the markers show but the page around them does not stay the same' do
+ text = "Anna: amp ist eine Abkuerzung, R&D auch, und amp nochmal.\n"
+ mark = mark_object(text, mark: 'amp')
+
+ expect(mark.resolve).to be_success
+ expect(mark.everywhere?('amp')).to be(false)
+ end
+
+ # Review round 3 of #121: text that only looks like a marker is not one.
+ it 'allows everywhere beside text that looks like a marker' do
+ text = "Ben: Lalabeis und QabcdefghijklmnopQ.\nAnna: Lalabeis.\n"
+ mark = mark_object(text)
+
+ expect(mark.everywhere?('Lalabeis')).to be(true)
+ end
+
+ # Review round 3 of #121: the count runs at every pause in typing; the
+ # changed form's proof is read once, not again for "everywhere".
+ it 'renders the page at most four times for a changed form and everywhere' do
+ text = "Anna: Lala beis heute.\nBen: Lala ist da.\n"
+ calls = 0
+ counting = lambda do |source|
+ calls += 1
+ render.call(source)
+ end
+ mark = described_class.new(transcript: text, render: counting, participants: participants,
+ **browser_mark(text, 'Lala beis'))
+
+ mark.place_of('Lala')
+ mark.everywhere?('Lala')
+
+ expect(calls).to be <= 4
+ end
+
it 'refuses a changed form that does not stand at the mark' do
text = "Anna: Lala beis heute.\nBen: Konto ok"
mark = mark_object(text, mark: 'Lala beis')
@@ -215,14 +264,16 @@ RSpec.describe Meetings::TranscriptMark do
expect(result.error).to eq(:ambiguous)
end
- # Review round 2 of #121: where the 40 characters around the mark repeat,
- # only the offset tells the places apart.
+ # Review rounds 2 and 3 of #121: where the 40 characters around the mark
+ # repeat, only the offset tells the places apart. The sixth of ten equal
+ # lines has 40 equal characters on either side (the third of six had not).
it 'tells places with the same context apart by the offset alone' do
- text = Array.new(6) { 'Ben: Lalabeis ja' }.join("\n")
-
- result = resolve(text, **browser_mark(text, 'Lalabeis', nth: 2))
+ text = Array.new(10) { 'Ben: Lalabeis ja' }.join("\n")
+ mark = browser_mark(text, 'Lalabeis', nth: 5)
+ same = browser_mark(text, 'Lalabeis', nth: 4)
- expect(result.place.to_h.values_at(:line_index, :char_offset)).to eq([2, 5])
+ expect(mark.values_at(:before, :after)).to eq(same.values_at(:before, :after))
+ expect(resolve(text, **mark).place.to_h.values_at(:line_index, :char_offset)).to eq([5, 5])
end
it 'refuses a mark over a line break and a mark too long for the glossary' do
diff --git a/spec/system/meeting_term_correction_spec.rb b/spec/system/meeting_term_correction_spec.rb
index 9a3d8d7..a3eee71 100644
--- a/spec/system/meeting_term_correction_spec.rb
+++ b/spec/system/meeting_term_correction_spec.rb
@@ -164,18 +164,19 @@ RSpec.describe 'Correcting a term in a meeting', type: :system do
expect(meeting.reload.transcript).to start_with("Anna: Wir testen Lalabase heute.\nBen: Lalabeis kann viel")
end
- # Review round 2 of #121: where the 40 characters around the mark repeat,
- # only the offset the browser counts tells the places apart.
+ # Review rounds 2 and 3 of #121: where the 40 characters around the mark
+ # repeat, only the offset the browser counts tells the places apart. The
+ # sixth of ten equal lines has 40 equal characters on either side.
it 'corrects the marked one of several lines that read the same' do
user = admin(:de)
meeting = meeting_for(user)
- repeated = Array.new(6) { 'Ben: Lalabeis ja' }.join("\n")
+ repeated = Array.new(10) { 'Ben: Lalabeis ja' }.join("\n")
meeting.update!(transcript: repeated)
sign_in user
visit organisation_project_meetings_path(organisation, project, meeting_id: meeting.id)
expect(page).to have_text('Ben: Lalabeis ja')
- mark_in_transcript(meeting, 'Lalabeis', nth: 2)
+ mark_in_transcript(meeting, 'Lalabeis', nth: 5)
find("#meeting-term-correction-trigger-#{meeting.id}").click
within('[role="dialog"]') do
fill_in I18n.t("#{tc}.correct_label", locale: :de), with: 'Lalabase'
@@ -183,9 +184,9 @@ RSpec.describe 'Correcting a term in a meeting', type: :system do
end
expect(page).to have_text(I18n.t("#{tc}.flash.replaced", count: 1, locale: :de))
- expect(meeting.reload.transcript.split("\n")).to eq(
- ['Ben: Lalabeis ja', 'Ben: Lalabeis ja', 'Ben: Lalabase ja', 'Ben: Lalabeis ja', 'Ben: Lalabeis ja', 'Ben: Lalabeis ja']
- )
+ lines = meeting.reload.transcript.split("\n")
+ expect(lines[5]).to eq('Ben: Lalabase ja')
+ expect(lines.count('Ben: Lalabeis ja')).to eq(9)
end
it 'offers no correction in the panel beside a ticket' do