refactor(xlsform2lstsv): per-call conversion state; synchronous internals - #77
Merged
Merged
Conversation
…nals
XLSFormToTSVConverter kept all per-conversion state on the instance and
reset it with seven clear() calls at the start of convert(). Because
convert() awaited inside every row, two concurrent calls on one instance
corrupted each other. Reproduced: the second call's reset wiped the first
call's choice lists ("list 'colors' has no rows on the choices sheet").
- The collaborators and state now belong to an internal Conversion object
that convert() creates for each call. XLSFormToTSVConverter holds only its
resolved options (resolveConfig), so an instance can be reused, including
concurrently. The collaborators' clear() methods are gone.
- The internals are synchronous: the XPath transpiler gains sync cores
(xpathToLimeSurveySync, convertRelevanceSync, convertConstraintSync). The
public xpathToLimeSurvey/convertRelevance/convertConstraint stay
Promise-returning, and so does convert(), which rejects on error.
Public API unchanged. Every TSV snapshot is identical.
tests/ts/integration/converterConcurrency.test.ts runs four surveys
concurrently on one instance and compares them with separate instances;
it fails on main and passes here.
Closes #62
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #62.
The suspected bug was real. Two concurrent
convert()calls on one instance failed. The second call's reset wiped the first call's choice lists mid-run, and it threwlist 'colors' has no rows on the choices sheet.Change:
Conversionobject thatconvert()creates fresh for each call.XLSFormToTSVConverterkeeps only its resolved options (viaresolveConfig, from refactor: move XLSForm row types out of config/, simplify ConfigManager #64). The seven manualclear()resets and the collaborators'clear()methods are gone.xpathToLimeSurveySync,convertRelevanceSync,convertConstraintSync.TranspilerHelper,GroupEmitter,MatrixHandlerand the conversion no longerawaitanything.xpathToLimeSurvey,convertRelevanceandconvertConstraintstay Promise-returning.convert()still returns a Promise, and rejects on error instead of throwing synchronously.Not done here: turning the collaborators into stateless functions, and removing the callback bags (
matrixHelpers(),answerHelpers()). With per-call objects that's cosmetic; #69 (theInstrumentmodel) is the natural place to rework them.Tests:
tests/ts/integration/converterConcurrency.test.ts: four surveys converted concurrently on one instance, compared with separate instances. It fails onmain, passes here. Also covers instance reuse, and that errors reject rather than throw.npm run validateis clean.🤖 Generated with Claude Code