Repository navigation
Description
Problem Statement
src/app/store/Run.ts is one 1,699-line class. 43% of it (lines 573–1305 at a146ed1) is the four command builders: the code that turns a run's settings into the argument lists for RAxML, RAxML-NG, ModelTest-NG and ASTRAL. That code is the part of the app most likely to produce a wrong analysis, and it is the least tested: no test fixes a whole command, and the builders can only be exercised by constructing a full Run with its MobX state and bridge listeners. A developer changing one flag has to read the builders inside a class that also owns input files, output naming, run lifecycle and console text.
Solution
Command building leaves the Run class and becomes plain functions in src/app/store/command/, one file per binary. Each command builder takes a narrow typed input listing only what it reads, and Run satisfies that input by passing itself. What remains in Run.ts is state and lifecycle.
Before anything moves, command pins fix the exact argument lists that today's Run produces for every analysis. The move is then proven by those pins not changing. No user-visible behaviour changes: every generated command stays character-for-character identical.
User Stories
- As a developer changing a command-line flag, I want the builder for one binary in its own file, so that I read only the code for that binary.
- As a developer, I want to call a command builder with a plain object, so that I can test a flag without constructing a
Run. - As a developer, I want to run a builder for Windows and for macOS/Linux in the same test file, so that path quoting is checked on both without mocking the host.
- As a developer moving or restructuring builder code, I want a command pin for every analysis in three variants, so that any change to a generated argument fails a test.
- As a reviewer of a move, I want the pins' snapshot files to be absent from the diff, so that I can confirm at a glance that no command changed.
- As a developer working on views or other store tests, I want
run.args,run.commandandrun.settingsFileContentto keep working as they do today, so that nothing outsideRun.tshas to change. - As a user, I want every analysis to run with exactly the arguments it gets today, so that results are unaffected by the refactor.
Implementation Decisions
Seam. Run stays the one page store that views and tests talk to. Its getters args, command and settingsFileContent stay and call into src/app/store/command/. The four builder methods raxmlArgs, raxmlNgArgs, modeltestNgArgs and astralArgs are removed from Run once moved; nothing outside Run.ts calls them.
Files. src/app/store/command/ holds:
astral.ts,modeltestNg.ts,raxmlNg.ts,raxml.ts: one command builder each.index.ts: the dispatch (commandArgs), the command string, the settings-file text, and theCmdArgtype.
Builder input. Each builder declares its own input interface in its own file, listing only the members it reads. The input mirrors the nesting Run already has (for example numThreads: { notAvailable, value } and finalAlignment: { path, partitionFilePath, partition: { isDefault } }); it is not flattened. Three shared pieces cover output (outputDir, outputNameSafe), the partition choice, and the two constraint trees. The dispatch takes the intersection of the four inputs plus usesAstral, usesModeltestNg and usesRaxmlNg. It must be a type intersection, not an interface extending the four: the builders read different parts of tree.
Signatures.
interface Platform { windows: boolean }
astralArgs( run: AstralInput, platform: Platform ): string[][]
modeltestNgArgs( run: ModeltestNgInput, platform: Platform ): CmdArg[][]
raxmlNgArgs( run: RaxmlNgInput, platform: Platform ): CmdArg[][]
raxmlArgs( run: RaxmlInput, platform: Platform ): CmdArg[][]
commandArgs( run: CommandInput, platform: Platform ): CmdArg[][]The platform is a second argument shaped like the one quote takes. Run passes the host's value. No file under command/ reads host.
Command string and settings text. These become two functions that take plain values, not a run: the command string takes the binary name, the argument lists, and whether the binary is ASTRAL; the settings text takes the app version, the analysis title, the binary's name and version, the output folder, and the argument lists.
Verbatim move. Builder bodies move with this. replaced by run. and no other edit. Comments move with the code, including the old Python command notes. Value types are copied as they are today, including numRepetitions.value and numRepetitionsNg.value as number | string and the thread count as a number.
Unchanged. RunOptions.ts, Alignment.ts, FinalAlignment.ts, every view, the renderer bridge payloads, and the two @ts-expect-error lines in start and startAstral. The RAxML-NG ancestral-states builder keeps choosing its partition by "more than one alignment" (Run.ts:792). No new dependency.
Prototype of the input types and signatures, checked by yarn typecheck against the real Run: commandInput.prototype.ts on the throwaway branch 417-what-the-command-builders-take-as-input. Don't merge it.
Testing Decisions
A good test here asserts what leaves the seam: the argument lists a run would send to a binary. It does not assert how a builder is structured inside.
-
Command pins. One table of cases run through Vitest file snapshots (
toMatchSnapshot). Each pin assertsrun.args. Every analysis (8 RAxML, 6 RAxML-NG) is pinned in three variants:- Bare: a binary without the threads flag where one exists, every option off, default partition.
- Full: a threaded binary, a loaded partition file, an outgroup, both constraint trees, branch lengths, SH-like values, a starting tree: whatever that analysis accepts.
- Alternate: a non-default partition with no partition file, and SH-like values without branch lengths.
ModelTest-NG is pinned for nucleotide, protein and another data type. ASTRAL is pinned with and without a loaded tree.
run.commandandrun.settingsFileContentare pinned once per binary. Every pin builds a realRunwith its real option objects, with the seed fixed throughsetRandomSeed, a fixed output folder and a fixed thread count. Prior art:makeRuninsrc/app/store/Run.computeds.test.ts. -
Both platforms. The same table runs a second time with the host set to Windows and Windows-style paths (
C:\out). The store reads the Windows flag once at import, so this is a second test file that sets the host before importing. Prior art:src/app/store/host.test.ts. -
Proof of coverage. Every branch in the four builders is hit by the pins. The implementer checks this once with a one-off coverage run. No coverage dependency and no CI step are added.
-
Frozen snapshots. After the pin ticket, no ticket in this spec changes a snapshot file.
-
Direct builder tests. Each builder file gets one small test that runs it on a plain object for both platforms. The pins remain the thorough check; the table is not repeated against the functions.
-
End-to-end. No ticket runs
test:e2elocally. CI runs it on the pull requests.
These are the repo's first snapshot files.
Out of Scope
- Restructuring the 495-line RAxML
switch(one function per analysis, shared argument prefixes). A follow-up once the pins exist. - The two
@ts-expect-errorlines instartandstartAstral, and where number arguments become strings. - Breaking
Runinto several stores, or changing what views read. - Moving input files, output name and folder, run-event listeners or console text out of
Run.ts. - Splitting
RunOptions.tsorAlignment.ts. - Fixing any bug found on the way, including the ancestral-states partition choice. Each stays in its own ticket.
Further Notes
- Map: Map: split Run.ts #415. Decisions: Which option variants the command pins cover #416 (what the command pins cover), What the command builders take as input #417 (what the command builders take as input), Write the spec for the Run.ts split #418 (slices and acceptance criteria).
- Glossary terms: Command builder, Command pin, Page store.
Run.tslands near 900 lines. That is a consequence, not a goal.
Activity