From 3133db36afd05754d87f7188a5c2b95cb021b289 Mon Sep 17 00:00:00 2001 From: Tim Haasdyk Date: Thu, 30 Jul 2026 20:43:28 +0200 Subject: [PATCH 1/3] Add chorusmerge merge-handler smoke-test (red until next commit) FwHeadless silently drops FieldWorks edits when a file needs a real 3-way merge: the ChorusMerge process never finds its *-ChorusPlugin.dll handlers (MEF scans the cwd, and hg runs the merge tool from the repo, not /app), so conflicts fall back to whole-file "keep ours". This smoke-test runs the real chorusmerge from a non-/app cwd on a split PartsOfSpeech.list, editing two different possibility items, and asserts both survive. It fails on the current setup by design; the fix follows next. Fixes #2509, part of #2508. Co-Authored-By: Claude Opus 4.8 --- backend/FwHeadless/Dockerfile | 4 + .../chorusmerge-smoke/PartsOfSpeech.base.list | 246 ++++++++++++++++++ backend/FwHeadless/chorusmerge-smoke/run.sh | 34 +++ 3 files changed, 284 insertions(+) create mode 100644 backend/FwHeadless/chorusmerge-smoke/PartsOfSpeech.base.list create mode 100644 backend/FwHeadless/chorusmerge-smoke/run.sh diff --git a/backend/FwHeadless/Dockerfile b/backend/FwHeadless/Dockerfile index 965961f51e..7e92ad4637 100644 --- a/backend/FwHeadless/Dockerfile +++ b/backend/FwHeadless/Dockerfile @@ -43,6 +43,10 @@ RUN test -f FixFwData \ && python3 -c "import zipfile; open('/tmp/smoke.fwdata','wb').write(zipfile.ZipFile('/tmp/test-template-repo.zip').read('kevin-test-01.fwdata'))" \ && ./FixFwData /tmp/smoke.fwdata; ec=$?; rm -f /tmp/test-template-repo.zip /tmp/smoke.fwdata; \ if [ $ec -gt 1 ]; then echo "FixFwData smoke test failed with exit $ec"; exit 1; fi +# Smoke-test: chorusmerge must engage the FieldWorks merge handler, not silently keep one +# whole file (#2508). Runs the real wrapper from a non-/app cwd, exactly as hg does. +COPY FwHeadless/chorusmerge-smoke/ /opt/chorusmerge-smoke/ +RUN chmod +x /opt/chorusmerge-smoke/run.sh && /opt/chorusmerge-smoke/run.sh USER www-data:www-data ENV XDG_DATA_HOME=/var/www/.local/share ENTRYPOINT ["tini", "--"] diff --git a/backend/FwHeadless/chorusmerge-smoke/PartsOfSpeech.base.list b/backend/FwHeadless/chorusmerge-smoke/PartsOfSpeech.base.list new file mode 100644 index 0000000000..fbee34c375 --- /dev/null +++ b/backend/FwHeadless/chorusmerge-smoke/PartsOfSpeech.base.list @@ -0,0 +1,246 @@ + + + + + Pos + + + + + + + + + + + + Parts Of Speech + + + + + adv + + + + Adverb + + + + + + An adverb, narrowly defined, is a part of speech whose members modify verbs for such categories as time, manner, place, or direction. An adverb, broadly defined, is a part of speech whose members modify any constituent class of words other than nouns, such as verbs, adjectives, adverbs, phrases, clauses, or sentences. Under this definition, the possible type of modification depends on the class of the constituent being modified. + + + + + + + Adverb + + + + + + + + n + + + + Noun + + + + + + A noun is a broad classification of parts of speech which include substantives and nominals. + + + + + + + Noun + + + + + + + + pro-form + + + + Pro-form + + + + + + A pro-form is a part of speech whose members usually substitute for other constituents, including phrases, clauses, or sentences, and whose meaning is recoverable from the linguistic or extralinguistic context. + + + + + + + Pro-form + + + + + + pro + + + + Pronoun + + + + + + A pronoun is a pro-form which functions like a noun and substitutes for a noun or noun phrase. + + + + + + + Pronoun + + + + + + + + + + + + v + + + + Verb + + + + + + A verb is a part of speech whose members typically signal events and actions; constitute, singly or in a phrase, a minimal predicate in a clause; govern the number and types of other constituents which may occur in the clause; and, in inflectional languages, may be inflected for tense, aspect, voice, modality, or agreement with other constituents in person, number, or grammatical gender. + + + + + + + Verb + + + + + + + + + + + + + \ No newline at end of file diff --git a/backend/FwHeadless/chorusmerge-smoke/run.sh b/backend/FwHeadless/chorusmerge-smoke/run.sh new file mode 100644 index 0000000000..58e36f96c8 --- /dev/null +++ b/backend/FwHeadless/chorusmerge-smoke/run.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Smoke-test: does chorusmerge actually engage the FieldWorks merge handler, or silently +# fall back to keeping one whole file? See sillsdev/languageforge-lexbox#2508 / #2509. +# +# PartsOfSpeech.base.list is the FLExBridge split (nested) form of a possibility list — what +# hg actually versions and merges. Regenerate from a .fwdata with the FLExBridge split CLI. +# +# The handler is discovered by scanning the *current working directory* for *-ChorusPlugin.dll, +# and hg runs the merge tool with cwd = the repo (not /app). So this MUST run from a non-/app +# cwd to be meaningful — running it from /app would hide the bug and pass falsely. +set -euo pipefail + +APP=${APP:-/app} +SMOKE="$(dirname "$(readlink -f "$0")")" +BASE="$SMOKE/PartsOfSpeech.base.list" +WORK="$(mktemp -d)" +trap 'rm -rf "$WORK"' EXIT + +# Two edits to DIFFERENT possibility items (different guids) => they must auto-merge cleanly. +# A real 3-way merge keeps both; the whole-file "keep ours" fallback drops the theirs edit. +sed 's#>Adverb#>Adverb_OURS#' "$BASE" > "$WORK/ours.list" +sed 's#>Verb#>Verb_THEIRS#' "$BASE" > "$WORK/theirs.list" +cp "$WORK/ours.list" "$WORK/merged.list" # ChorusMerge writes the result back to arg 0 + +cd "$WORK" # a non-/app cwd, exactly as hg runs the merge tool inside the repo +ChorusPathToRepository="$WORK" "$APP/chorusmerge" "$WORK/merged.list" "$BASE" "$WORK/theirs.list" || true + +if grep -q Adverb_OURS "$WORK/merged.list" && grep -q Verb_THEIRS "$WORK/merged.list"; then + echo "chorusmerge smoke OK: FieldWorks 3-way merge engaged; both edits preserved" +else + echo "chorusmerge smoke FAILED: merge dropped a side (FieldWorks handler not engaged)" + echo " Adverb_OURS=$(grep -c Adverb_OURS "$WORK/merged.list" || true) Verb_THEIRS=$(grep -c Verb_THEIRS "$WORK/merged.list" || true)" + exit 1 +fi From 2599fa3922986f92076397c25d24abc4e03a8be1 Mon Sep 17 00:00:00 2001 From: Tim Haasdyk Date: Thu, 30 Jul 2026 20:45:03 +0200 Subject: [PATCH 2/3] Fix chorusmerge FieldWorks handler discovery (cd to app dir) ChorusMerge finds its *-ChorusPlugin.dll handlers with a cwd-relative MEF scan, but hg runs the merge tool from the repo, not /app, so the handlers were never found and merges fell back to whole-file "keep ours". cd into the script dir so they're found; hg passes absolute file paths, so changing cwd is safe. Turns the previous commit's smoke-test green. Fixes #2510. Part of #2508; durable upstream fix tracked in #2511 / sillsdev/chorus#392. Co-Authored-By: Claude Opus 4.8 --- backend/FwHeadless/chorusmerge | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/FwHeadless/chorusmerge b/backend/FwHeadless/chorusmerge index fdf1c1160b..f1010618e5 100755 --- a/backend/FwHeadless/chorusmerge +++ b/backend/FwHeadless/chorusmerge @@ -1,6 +1,10 @@ #!/bin/bash -# cwd while running script is inside hg repo, so ensure we look for ChorusMerge.dll in right place +# cwd while running script is inside the hg repo. ChorusMerge finds its FieldWorks merge +# handlers by scanning the cwd for *-ChorusPlugin.dll (MEF DirectoryCatalog(".")), so cd to +# where they sit next to ChorusMerge.dll, else merges silently fall back to "keep ours". +# hg passes absolute file paths to the merge tool, so changing cwd is safe. SCRIPT_DIR=$(dirname $(readlink -f "$0")) +cd "$SCRIPT_DIR" exec dotnet "${SCRIPT_DIR}/ChorusMerge.dll" "$@" From 5f59196325bd69945d4f79b8398dd955186b3854 Mon Sep 17 00:00:00 2001 From: Tim Haasdyk Date: Thu, 30 Jul 2026 22:08:34 +0200 Subject: [PATCH 3/3] Address Devin review: fail loudly on cd failure; don't ship smoke assets - chorusmerge: exit non-zero if `cd` to the app dir fails, so a merge can't silently fall back to "keep ours" (a failed merge tool makes Chorus roll back and throw instead). - Dockerfile: bind-mount the smoke fixture instead of COPY, so it isn't shipped in the runtime image. - smoke run.sh: capture the merge tool's exit code in the failure diagnostic. Part of #2508. Co-Authored-By: Claude Opus 4.8 --- backend/FwHeadless/Dockerfile | 5 +++-- backend/FwHeadless/chorusmerge | 4 +++- backend/FwHeadless/chorusmerge-smoke/run.sh | 5 +++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/backend/FwHeadless/Dockerfile b/backend/FwHeadless/Dockerfile index 7e92ad4637..e5f0eb552a 100644 --- a/backend/FwHeadless/Dockerfile +++ b/backend/FwHeadless/Dockerfile @@ -45,8 +45,9 @@ RUN test -f FixFwData \ if [ $ec -gt 1 ]; then echo "FixFwData smoke test failed with exit $ec"; exit 1; fi # Smoke-test: chorusmerge must engage the FieldWorks merge handler, not silently keep one # whole file (#2508). Runs the real wrapper from a non-/app cwd, exactly as hg does. -COPY FwHeadless/chorusmerge-smoke/ /opt/chorusmerge-smoke/ -RUN chmod +x /opt/chorusmerge-smoke/run.sh && /opt/chorusmerge-smoke/run.sh +# Bind-mount rather than COPY so the fixture/script don't ship in the runtime image. +RUN --mount=type=bind,source=FwHeadless/chorusmerge-smoke,target=/opt/chorusmerge-smoke \ + bash /opt/chorusmerge-smoke/run.sh USER www-data:www-data ENV XDG_DATA_HOME=/var/www/.local/share ENTRYPOINT ["tini", "--"] diff --git a/backend/FwHeadless/chorusmerge b/backend/FwHeadless/chorusmerge index f1010618e5..62f77d0e8b 100755 --- a/backend/FwHeadless/chorusmerge +++ b/backend/FwHeadless/chorusmerge @@ -5,6 +5,8 @@ # where they sit next to ChorusMerge.dll, else merges silently fall back to "keep ours". # hg passes absolute file paths to the merge tool, so changing cwd is safe. SCRIPT_DIR=$(dirname $(readlink -f "$0")) -cd "$SCRIPT_DIR" +# Fail loudly rather than merge from the wrong cwd: a merge without the handlers silently +# keeps "ours" (the #2508 data loss); a non-zero exit makes Chorus roll back and throw. +cd "$SCRIPT_DIR" || { echo "chorusmerge: cannot cd to $SCRIPT_DIR; refusing to merge without the FieldWorks handlers" >&2; exit 1; } exec dotnet "${SCRIPT_DIR}/ChorusMerge.dll" "$@" diff --git a/backend/FwHeadless/chorusmerge-smoke/run.sh b/backend/FwHeadless/chorusmerge-smoke/run.sh index 58e36f96c8..640c9f8960 100644 --- a/backend/FwHeadless/chorusmerge-smoke/run.sh +++ b/backend/FwHeadless/chorusmerge-smoke/run.sh @@ -23,12 +23,13 @@ sed 's#>Verb#>Verb_THEIRS#' "$BASE" > "$WORK/theirs.list" cp "$WORK/ours.list" "$WORK/merged.list" # ChorusMerge writes the result back to arg 0 cd "$WORK" # a non-/app cwd, exactly as hg runs the merge tool inside the repo -ChorusPathToRepository="$WORK" "$APP/chorusmerge" "$WORK/merged.list" "$BASE" "$WORK/theirs.list" || true +rc=0 +ChorusPathToRepository="$WORK" "$APP/chorusmerge" "$WORK/merged.list" "$BASE" "$WORK/theirs.list" || rc=$? if grep -q Adverb_OURS "$WORK/merged.list" && grep -q Verb_THEIRS "$WORK/merged.list"; then echo "chorusmerge smoke OK: FieldWorks 3-way merge engaged; both edits preserved" else - echo "chorusmerge smoke FAILED: merge dropped a side (FieldWorks handler not engaged)" + echo "chorusmerge smoke FAILED: merge dropped a side (FieldWorks handler not engaged; chorusmerge exit=$rc)" echo " Adverb_OURS=$(grep -c Adverb_OURS "$WORK/merged.list" || true) Verb_THEIRS=$(grep -c Verb_THEIRS "$WORK/merged.list" || true)" exit 1 fi