From 66370babcc04247ddc547ca6c0417f468e83aabf Mon Sep 17 00:00:00 2001 From: Simon Heybrock Date: Mon, 23 Nov 2026 07:46:47 +0000 Subject: [PATCH 1/2] Let a batch that stopped following follow again Intake.follow(label) lets a batch made from a source follow in place of the batch that follows now. It writes "follows": false to that batch, then "follows": true to label; if the second write is refused, the batch before follows again. create shares this code. The rule that a stopped batch cannot follow again had no reason in the batch layer: a batch keeps the keys it has considered, so its next step adds exactly the filled rows it has not considered, also those that another batch took meanwhile. The page offers no action for it, so the page is unchanged; the guide, ADR 0013 and the docstrings say so. Co-Authored-By: Claude Opus 5.5 --- ...013-follow-adds-the-rows-not-considered.md | 21 ++-- packages/essapps/docs/batch.md | 21 ++-- packages/essapps/src/ess/apps/batch/intake.py | 92 +++++++++++++----- .../essapps/src/ess/apps/batch/web/README.md | 2 +- .../essapps/src/ess/apps/batch/web/api.py | 2 +- .../essapps/src/ess/apps/batch/web/page.py | 10 +- packages/essapps/tests/batch/intake_test.py | 96 ++++++++++++++++++- 7 files changed, 193 insertions(+), 51 deletions(-) diff --git a/docs/developer/adr/0013-follow-adds-the-rows-not-considered.md b/docs/developer/adr/0013-follow-adds-the-rows-not-considered.md index abadc934..c9e7e5ae 100644 --- a/docs/developer/adr/0013-follow-adds-the-rows-not-considered.md +++ b/docs/developer/adr/0013-follow-adds-the-rows-not-considered.md @@ -121,7 +121,7 @@ intake.create('loki-iofq', title='Evening', source='sample-runs', follow=True) # the batch 'afternoon' stops following ``` -The earlier batch keeps its rows, also those from 60400 on, until a person removes them. It has considered the keys it has seen, and takes no row that arrives later, since it cannot follow again. +The earlier batch keeps its rows, also those from 60400 on, until a person removes them. It has considered the keys it has seen, and takes no row that arrives later while it does not follow. A batch of only the rows that arrive later takes no row at making. Every row filled then is considered, so no row is reduced again: @@ -130,22 +130,23 @@ intake.create('loki-iofq', title='Night', source='sample-runs', choose=Range(later=True), follow=True) ``` -### A batch follows from the time it is made, until it is stopped +### A batch follows from the time it is made or told to follow, until it is stopped -Follow is chosen when a batch is made. A batch that follows can be stopped. A batch that does not follow cannot be made to follow. +A batch made from a source follows from its making with Follow, or from `intake.follow(label)`. A batch that follows can be stopped. ```python intake.create(..., source='sample-runs', follow=True) # follows; the batch that followed before stops intake.following # its label -intake.stop() # none follows; that batch cannot follow again +intake.stop() # none follows +intake.follow('afternoon') # follows again; the batch that followed before stops ``` - At most one batch follows, as in ADR 0011: `Intake` keeps whether a batch follows in its `source.json`, a restart resumes, and removing that batch ends Follow. Since `considered` is kept, the first step after a restart adds the rows that arrived in between. -- A batch made without a source cannot follow: only `intake.create`, which takes a source, takes `follow=True`. +- A batch made without a source cannot follow: only `intake.create`, which takes a source, takes `follow=True`, and `intake.follow` refuses a batch without one. +- A batch that follows again adds at its next step every row of its source that is filled and not considered: those that arrived while it did not follow, also those that another batch took meanwhile. A row left out when it was made, or removed by a person, stays out, since its key is considered. - A batch that follows has no last row. With one, the rows filled between the last row chosen and the making would be considered and never added, and the rows that arrive later would be. The range that a person picks is a value, `Range(first, last, later)`, which `Intake` reads: `create(follow=True)` with a `Range` that has a `last` is refused there. The page leaves the end of the range open while Follow is ticked, to say so before a person sends the form; the command does not follow. A `choose` that is a function may pick any rows, also with Follow: the rows were chosen in code, and the filled rows that it leaves out are considered, so Follow adds only the rows that arrive later. -- Nothing is kept that says a batch has followed. A batch is stopped when its `source.json` says that it does not follow, and no call writes that it follows again. -- So the next batch is one form, "New batch" with Follow, and a step never takes a row that another batch took since. -- On the page, Follow is a state with one action, "Stop following", not a switch. +- Nothing is kept that says a batch has followed. A batch made without Follow and a batch that was stopped are in the same state, and `intake.follow` writes `"follows": true` to either. +- On the page, the next batch is one form, "New batch" with Follow. Follow is a state with one action, "Stop following", not a switch: the page offers no action to let a batch follow again. ## Example @@ -169,7 +170,7 @@ A batch made from `sample-runs` with the rows from run 60339 on, with Follow. - **Add a row at once and fill its empty cells later.** It needs no memory of what waits. But it fills a cell again that a person emptied, and an empty cell of a parameter that takes `None` is a value (ADR 0012), so "not listed yet" and "none" cannot be told apart. - **A step changes cells that have a value**, as today, so that a transmission run measured again reaches the earlier rows and they are reduced again. It needs to know who wrote each cell, and results change with nobody asking. A person can do it for the rows they choose. - **A scope kept in the header** (ADR 0011): a slice of an index that a source gives each row. With `considered`, the start of the slice is the choice of rows at making, and it has no end: the next batch is made from the source and follows in its place. The index, its type, and the conversion of the ends go. -- **Follow turned on and off for a batch made before**, a switch on its page. A batch that follows again after another batch followed takes every row that arrived since, also the rows that the other batch took, and the next batch is two actions: make it, then turn Follow on. +- **Follow as a switch on the page of each batch**, in place of Follow in "New batch". The next batch would be two actions: make it, then turn Follow on. And a person who turns it on for an earlier batch may not expect that it takes the rows that another batch took since. - **A row is added once it can be reduced**, in place of once the source has filled it. A column that the source does not fill would hold the row back for ever, and a parameter that takes `None` would let a row through before its file is listed. ## Consequences @@ -178,7 +179,7 @@ A batch made from `sample-runs` with the rows from run 60339 on, with Follow. - The rule of a step is "ready and without a record". `RowState.changed_by_hand`, the columns `at` of `Automatic`, and the exception for cells set by hand go. - A row that only waits is not in the table. The page says how many rows wait, and a person can add them. - A transmission run measured again reaches no earlier row, and a correction of a run changes no row that the table has. -- A stop by mistake cannot be undone. A person adds the later rows with "Add rows from the runs", or makes a batch from the source, with Follow, that starts at the first row the stopped batch lacks. +- A stop by mistake is undone in code with `intake.follow(label)`, not on the page. On the page, a person adds the later rows with "Add rows from the runs", or makes a batch from the source, with Follow, that starts at the first row the stopped batch lacks. - A person who wants to try settings on a few rows first makes a batch without Follow, then the batch that follows with "Start with the settings of" the first. The rows tried are reduced again in the second batch. - A batch made with Follow is stepped within seconds: the rows taken at making are reduced with the settings it was made with. - `considered` grows by one key for each row that the source ever gave: some tens of bytes per row. diff --git a/packages/essapps/docs/batch.md b/packages/essapps/docs/batch.md index 0289410f..5fcb0e4d 100644 --- a/packages/essapps/docs/batch.md +++ b/packages/essapps/docs/batch.md @@ -82,7 +82,7 @@ Nothing in the batch layer imports the page or the command. | row source | code of the application that makes rows from the files (a `RowSource`) | | filled, waits | a row of the source is filled once it has a value in each of `RowSource.fills`; until then it waits | | considered | the keys of the source that a batch made from it has taken or left out | -| Follow | a step every few seconds on one batch: add the rows of its source that are filled and not considered, then reduce the rows that are ready and have no result; chosen when the batch is made, until it is stopped | +| Follow | a step every few seconds on one batch: add the rows of its source that are filled and not considered, then reduce the rows that are ready and have no result; from the making of the batch or `intake.follow(label)`, until it is stopped | `manager.create` and `intake.create` return the `Batch`, and `manager.batch(label)` gives it again. Every other method that names a batch takes its label. @@ -138,7 +138,7 @@ Other tables are always named with what they are of: 4. **A step never changes a row that the batch table has.** It adds rows, and reduces rows that have no result. 5. **A batch is shown without its source and without the files.** A file that is not found is a problem of its row. 6. **The rules are in the batch layer.** A refusal is a `ValueError`. The page and the command show it and copy no rule of the batch layer. The page refuses only a request that no call of the batch layer can express, such as Follow without a row source. The batch layer has no lock and no timer. -7. **Follow is chosen when a batch is made.** A batch follows from `intake.create(..., follow=True)` until `intake.stop()`, its removal, or the making of another batch that follows. A batch that does not follow cannot be made to follow. +7. **At most one batch follows.** It starts with `intake.create(..., follow=True)` or `intake.follow(label)`, and ends with `intake.stop()`, the removal of the batch, or another batch that starts to follow. ### What is kept on disk @@ -155,6 +155,7 @@ Other tables are always named with what they are of: A label is a batch if and only if `header.json` exists. `manager.create` writes rows and settings, then the header. `intake.create` then, if the batch follows, writes `"follows": false` to the `source.json` of the batch that followed, then writes the `source.json` of the batch; if the definitions refuse a write, it removes the batch again. +`intake.follow(label)` writes `"follows": false` to the `source.json` of the batch that followed, then `"follows": true` to that of `label`; a process that stops in between leaves no batch that follows. So a batch of `intake.create` is not always made as asked or not at all: a process that stops between the header and the batch's `source.json` leaves a batch made without a source, which neither offers rows nor follows, and no batch that follows. `manager.remove` deletes the header, then every other file of the label, `source.json` too. So whether a batch follows goes with its label: a batch made again with the label does not follow unless made so. @@ -260,11 +261,12 @@ They make it from the source, with the settings of the afternoon, and with Follo evening = intake.create('loki-iofq', title='Evening', source='sample-runs', choose=Range(first='60400'), settings=manager.batch('afternoon').settings, label='evening', - follow=True) # 'afternoon' stops following, and cannot follow again + follow=True) # 'afternoon' stops following ``` No row moves between batches. `afternoon` keeps its rows, also those from 60400 on that it added before, until a person removes them. +`intake.follow('afternoon')` would let it follow again, in place of `evening`: its next step would add every filled row it has not considered, also those that `evening` took. A batch that follows has no last row: the rows filled between a last row and the making would never be added. `intake.create` refuses `follow=True` with a `Range` that has a `last` (see [From a row source](#from-a-row-source)); a function as `choose` may pick any rows, and the filled rows it leaves out are considered. For a batch of only the rows that arrive from now on, `choose` takes none: `choose=Range(later=True)`. @@ -547,8 +549,8 @@ If the process stops while a batch that follows is made, the batch may be there ## Follow -At most one batch follows: the last one made with `follow=True`, until it is stopped. -The life of a batch; a batch made without Follow and a batch that stopped are in the same state: +At most one batch follows: the last one made with `follow=True` or given to `intake.follow(label)`, until it is stopped. +The life of a batch made from a source; a batch made without Follow and a batch that stopped are in the same state: ```mermaid stateDiagram-v2 @@ -556,7 +558,8 @@ stateDiagram-v2 still: does not follow [*] --> still: create(...) [*] --> follows: intake.create(..., follow=True) - follows --> still: stop(), or another batch made with Follow + still --> follows: intake.follow(label) + follows --> still: stop(), or another batch starts to follow still --> removed: remove() follows --> removed: remove() ``` @@ -564,7 +567,8 @@ stateDiagram-v2 ```python intake.create(..., source='sample-runs', follow=True) # follows; the batch that followed stops intake.following # its label, or None -intake.stop() # none follows; the batch that followed cannot follow again +intake.stop() # none follows +intake.follow(label) # this batch follows; the batch that followed stops done = intake.step() # a Step, or None if none follows intake.offered(label) # the rows of the source that the table lacks, with a boolean column `waits` intake.take(label, keys) # put these rows as the source gives them now, then consider them @@ -616,6 +620,7 @@ sequenceDiagram - A row with a result is never reduced by a step, also when it is outdated, failed or cancelled. - A row whose request is refused does not hold back the others; `done.refused` says why, and the next step tries again. - A batch of the manager persists what it submits. +- A batch that follows again adds at its next step every row of its source that is filled and not considered: those that arrived while it did not follow, also those that another batch took meanwhile. A row left out when it was made, or removed by a person, stays out. `intake.follow` refuses a batch made without a source, or whose source is not registered. - `manager.remove(label)` of the batch that follows ends Follow, since `source.json` goes with the label: `intake.following` is then `None`, and `intake.step()` does nothing. A batch made again with the label does not follow unless made so. A source whose row grows, such as the runs of a sample so far, gives the grown list a new key: @@ -728,5 +733,5 @@ Each action of the page is one call of the batch layer: - A correction of a run changes no batch. - No range of runs is kept: "from run 60339 on" is the choice of rows when the batch is made. - No row moves between batches: the next batch is made from the source. -- One batch follows at a time, and a batch that stopped following never follows again. The command does no step. +- One batch follows at a time. The page offers no action to let a stopped batch follow again. The command does no step. - The batch layer has no lock and no timer: whoever serves owns both. diff --git a/packages/essapps/src/ess/apps/batch/intake.py b/packages/essapps/src/ess/apps/batch/intake.py index 59cd234a..976d6f60 100644 --- a/packages/essapps/src/ess/apps/batch/intake.py +++ b/packages/essapps/src/ess/apps/batch/intake.py @@ -18,11 +18,13 @@ made again with the label does not follow unless made so. :meth:`Intake.create` makes the batch with the manager, which writes its settings, rows and header; with ``follow``, it then ends Follow on the batch -that followed; then it writes ``source``. So no two batches follow, also -when a process stops in between. A batch follows from the time it is made, -if made so, until :meth:`Intake.stop` or its removal; nothing turns Follow -on for a batch made before. :meth:`Intake.step` is one step of Follow on the -batch that follows:: +that followed; then it writes ``source``. :meth:`Intake.follow` ends +Follow on the batch that followed, then writes that its batch follows. So no +two batches follow, also when a process stops in between. A batch follows +from the time it is made with ``follow`` or :meth:`Intake.follow` is called, +until :meth:`Intake.stop`, its removal, or another batch that starts to +follow. :meth:`Intake.step` is one step of Follow on the batch that +follows:: made = source_of(label) # source.json done = step(batch(label), sources[made.source], made.considered) # put, reduce @@ -160,14 +162,58 @@ def _write_follows(self, label: str, follows: bool) -> None: def stop(self) -> None: """ - End Follow: no batch follows from then on, and the batch that followed - cannot follow again. Nothing is done if no batch follows. + End Follow: no batch follows from then on, until :meth:`follow` or + :meth:`create` with ``follow``. Nothing is done if no batch follows. """ if (label := self.following) is None: return self._write_follows(label, False) self._set_following(None) + def follow(self, label: str) -> None: + """ + Let the batch of ``label`` follow from then on, in place of the batch + that follows now. Nothing is done if it follows already. + + Its first step adds every row of its source that is filled and that + the batch has not considered, also a row that arrived while it did + not follow and a row that another batch took meanwhile. A row left + out when the batch was made, or removed by a person, is considered + and stays out. + + ``source.json`` of the batch that follows now is written to say that + it follows no more, then that of ``label`` to say that it follows. A + process that stops in between leaves no batch that follows. If the + definitions refuse the second write, the batch that followed is + written to follow again. + + Raises ``KeyError`` if no batch has the label, and ``ValueError`` if + it was not made from a source or its source is not registered. + """ + self._source(self._made(label).source) + if (before := self.following) == label: + return + self._follow_instead(before, lambda: self._write_follows(label, True)) + self._set_following(label) + + def _follow_instead(self, before: str | None, write: Callable[[], None]) -> None: + """ + End Follow on the batch of ``before``, if given, then call ``write``, + which writes the ``source.json`` of the batch that follows in its + place. If the definitions refuse either, ``before`` follows again. + """ + ended = None # the batch whose Follow was ended, to follow again + try: + if before is not None: + self._write_follows(before, False) + ended = before + write() + except NotKept: + if ended is not None: + with suppress(NotKept): # the first error is what to say + self._write_follows(ended, True) + raise + def _source(self, name: str) -> RowSource: """The source registered as ``name``; ``ValueError`` if none is.""" if name not in self.sources: @@ -246,9 +292,9 @@ def create( manager writes the settings, the rows and the header; then, with ``follow``, the ``source.json`` of the batch that followed says that it follows no more; then the ``source.json`` of the batch is written. - If the definitions refuse one of these writes, the batch is removed - again (:meth:`~.manager.BatchManager.remove`), and the batch that - followed is written to follow again, if its Follow was ended. A process + If the definitions refuse one of these writes, the batch that + followed is written to follow again, if its Follow was ended, and the + batch is removed again (:meth:`~.manager.BatchManager.remove`). A process that stops between the header and the batch's ``source.json`` leaves a batch made without a source, which neither offers rows nor follows, and no batch that follows. @@ -270,10 +316,11 @@ def create( follow: Whether the batch follows its source from the time it is made, in place of the batch that followed before. A batch made without - ``follow`` never follows. A :class:`~.source.Range` with a - ``last`` is refused with ``follow``; a function may choose any - rows, and the filled rows that it leaves out are considered, so - Follow adds only the rows that arrive later. + ``follow`` follows only after :meth:`follow`. A + :class:`~.source.Range` with a ``last`` is refused with + ``follow``; a function may choose any rows, and the filled rows + that it leaves out are considered, so Follow adds only the rows + that arrive later. Raises ------ @@ -307,19 +354,16 @@ def create( label=label, ) made = FromSource(source, frozenset(arrived.index), follows=follow) - ended = None # the batch whose Follow was ended, to follow again try: - if follow and before is not None: - self._write_follows(before, False) - ended = before - self.manager.definitions.save(source_key(batch.label), source_data(made)) + self._follow_instead( + before if follow else None, + lambda: self.manager.definitions.save( + source_key(batch.label), source_data(made) + ), + ) except NotKept: - # The first error is what to say. - with suppress(NotKept): + with suppress(NotKept): # the first error is what to say self.manager.remove(batch.label) - if ended is not None: - with suppress(NotKept): - self._write_follows(ended, True) raise if follow: self._set_following(batch.label) diff --git a/packages/essapps/src/ess/apps/batch/web/README.md b/packages/essapps/src/ess/apps/batch/web/README.md index e14e4269..32dc18b3 100644 --- a/packages/essapps/src/ess/apps/batch/web/README.md +++ b/packages/essapps/src/ess/apps/batch/web/README.md @@ -79,7 +79,7 @@ Each state replaces the form, but not while the focused input holds a value type A batch follows from the time it is made, if **Follow** is ticked in **+ New batch** (see [Making a batch](#making-a-batch)), until it is stopped. At most one batch follows: making one with Follow stops the batch that followed before, and the list of batches marks the one that follows. -The page of the batch that follows has **Stop following** next to **List runs again** (`POST api/follow/stop`, `Intake.stop`). It asks once, since the batch cannot follow again; rows that arrive later are then added with **+ Add rows from the runs**, or go to a new batch. +The page of the batch that follows has **Stop following** next to **List runs again** (`POST api/follow/stop`, `Intake.stop`). It asks once, since the page offers no action to let the batch follow again; rows that arrive later are then added with **+ Add rows from the runs**, or go to a new batch. The page of a batch that does not follow has no Follow control. While a batch follows, a timer in the server runs a step every `interval` seconds (5 by default; `Pages(intake, interval=...)`, or `--interval SECONDS`), under the lock of every request, with or without a page open. A step is `Intake.step`: diff --git a/packages/essapps/src/ess/apps/batch/web/api.py b/packages/essapps/src/ess/apps/batch/web/api.py index b31c2936..90227877 100644 --- a/packages/essapps/src/ess/apps/batch/web/api.py +++ b/packages/essapps/src/ess/apps/batch/web/api.py @@ -223,7 +223,7 @@ def cancel(page: PageOfLabel) -> State: @batch.post('/api/follow/stop') def stop_following(page: PageOfLabel) -> State: - """Stop Follow, if this batch follows; it cannot follow again.""" + """Stop Follow, if this batch follows; the page offers no action to undo it.""" return page.stop_following() @batch.post('/api/settings') diff --git a/packages/essapps/src/ess/apps/batch/web/page.py b/packages/essapps/src/ess/apps/batch/web/page.py index 2f3a02d0..dce95651 100644 --- a/packages/essapps/src/ess/apps/batch/web/page.py +++ b/packages/essapps/src/ess/apps/batch/web/page.py @@ -94,9 +94,10 @@ A batch follows from the time it is made, if a person chooses Follow in "New batch" (:meth:`Pages.create <.pages.Pages.create>`). Its page then has -the action "Stop following" (:meth:`Page.stop_following`), after which the -batch never follows again; the page of a batch that does not follow has no -action of Follow. While a batch follows, :meth:`Pages.tick +the action "Stop following" (:meth:`Page.stop_following`); the page offers +no action to let a stopped batch follow again +(:meth:`~ess.apps.batch.Intake.follow`), and the page of a batch that does +not follow has no action of Follow. While a batch follows, :meth:`Pages.tick <.pages.Pages.tick>` steps it every ``interval`` seconds (:meth:`~ess.apps.batch.Intake.step`), which adds the rows of its source that are new and filled, and reduces the rows that @@ -942,7 +943,8 @@ def cancel(self) -> str: def stop_following(self) -> str: """ Let none follow, if this batch follows - (:meth:`~ess.apps.batch.Intake.stop`); it cannot follow again. + (:meth:`~ess.apps.batch.Intake.stop`); the page offers no action to + let it follow again. """ if not self._follows(): return '' # another batch follows, or none diff --git a/packages/essapps/tests/batch/intake_test.py b/packages/essapps/tests/batch/intake_test.py index 753cb9d1..4afbbdc5 100644 --- a/packages/essapps/tests/batch/intake_test.py +++ b/packages/essapps/tests/batch/intake_test.py @@ -235,8 +235,9 @@ def choose(given: pd.DataFrame) -> pd.DataFrame: lambda i: i.source('b'), lambda i: i.offered('b'), lambda i: i.take('b', []), + lambda i: i.follow('b'), ], - ids=['source', 'offered', 'take'], + ids=['source', 'offered', 'take', 'follow'], ) def test_a_label_that_is_no_batch_is_refused( intake: Intake, call: Callable[[Intake], Any] @@ -392,7 +393,7 @@ def test_rows_that_cannot_be_taken_are_refused_and_nothing_changes( pd.testing.assert_frame_equal(made.manager.batch('a').frame(), before) -def test_a_batch_made_without_a_source_offers_and_takes_no_rows( +def test_a_batch_made_without_a_source_offers_and_takes_no_rows_and_cannot_follow( intake: Intake, ) -> None: intake.manager.create('plain', title='A', label='a') @@ -401,6 +402,9 @@ def test_a_batch_made_without_a_source_offers_and_takes_no_rows( intake.offered('a') with pytest.raises(ValueError, match='a was not made from a row source'): intake.take('a', ['1']) + with pytest.raises(ValueError, match='a was not made from a row source'): + intake.follow('a') + assert intake.following is None class _SourceRefused(Refusing): @@ -552,6 +556,91 @@ def test_a_stopped_batch_gets_no_rows_at_a_step( assert intake.offered('a')['waits'].to_dict() == {'2': False} +def test_a_stopped_batch_follows_again_and_its_step_adds_the_rows_filled_since( + intake: Intake, sample: Measure +) -> None: + sample(1, 'water') + sample(2, 'sds') + batch = intake.create( + 'plain', title='A', source='pairs', choose=Range(first='2'), label='a' + ) + intake.stop() + sample(3, 'oil') + + intake.follow('a') + intake.step() + + assert intake.following == 'a' + assert list(batch.frame().index) == ['2', '3'] # 1 was left out at making + + +def test_a_batch_that_follows_again_adds_the_rows_that_another_took_meanwhile( + two: Intake, sample: Measure +) -> None: + sample(1, 'water') + two.follow('b') + two.step() + + two.follow('a') + two.step() + + assert list(two.manager.batch('a').frame().index) == ['1'] + assert list(two.manager.batch('b').frame().index) == ['1'] + + +def test_a_batch_told_to_follow_ends_follow_on_the_one_before_then_writes_its_own( + two: Intake, refusing: Refusing, definitions: FolderDefinitions +) -> None: + two.follow('b') + + assert refusing.saved[-2:] == [source_key('a'), source_key('b')] + assert _follows(definitions) == ['b'] + assert two.following == 'b' + + +def test_a_batch_told_to_follow_follows_after_a_restart( + two: Intake, client: Client, definitions: FolderDefinitions +) -> None: + two.stop() + + two.follow('b') + + assert _again(client, definitions).following == 'b' + + +def test_a_batch_that_follows_already_is_left_as_it_is( + two: Intake, refusing: Refusing +) -> None: + version, saved = two.version, list(refusing.saved) + + two.follow('a') + + assert (two.version, refusing.saved) == (version, saved) + + +def test_a_batch_whose_source_is_not_registered_cannot_follow( + two: Intake, client: Client, definitions: FolderDefinitions +) -> None: + again = Intake(BatchManager(client, definitions=definitions), sources={}) + + with pytest.raises(ValueError, match='the source pairs is not registered'): + again.follow('b') + assert again.following == 'a' + + +def test_a_batch_refused_to_follow_leaves_the_one_before_following( + two: Intake, refusing: Refusing, client: Client, definitions: FolderDefinitions +) -> None: + refusing.part = source_key('b') + + with pytest.raises(NotKept): + two.follow('b') + + assert two.following == 'a' + assert _follows(definitions) == ['a'] + assert _again(client, definitions).following == 'a' + + def test_a_batch_removed_through_the_manager_follows_no_longer( two: Intake, client: Client, definitions: FolderDefinitions ) -> None: @@ -636,8 +725,9 @@ def test_which_batch_follows_stays_if_the_definitions_refuse_a_change( [ lambda i: i.create('plain', title='C', source='pairs', follow=True), lambda i: i.stop(), + lambda i: i.follow('b'), ], - ids=['create', 'stop'], + ids=['create', 'stop', 'follow'], ) def test_the_version_moves_at_each_change_of_which_follows( two: Intake, change: Callable[[Intake], object] From 9a5da328eb5f0321b019b2f27868306a206fb9d9 Mon Sep 17 00:00:00 2001 From: Simon Heybrock Date: Mon, 23 Nov 2026 07:49:15 +0000 Subject: [PATCH 2/2] Page: say that the page cannot make a stopped batch follow again The question before "Stop following" said that the batch cannot follow again. That holds for the page, which has no action for it, and no longer for the batch layer (`Intake.follow`). Co-Authored-By: Claude Fable 5.2 --- packages/essapps/src/ess/apps/batch/web/static/app.js | 4 ++-- packages/essapps/tests/batch/web_browser_test.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/essapps/src/ess/apps/batch/web/static/app.js b/packages/essapps/src/ess/apps/batch/web/static/app.js index 65a13959..77ed6cad 100644 --- a/packages/essapps/src/ess/apps/batch/web/static/app.js +++ b/packages/essapps/src/ess/apps/batch/web/static/app.js @@ -958,9 +958,9 @@ function renderFollow(follow) { rows.empty.textContent = follow.on ? 'No rows yet. Follow adds the rows of the runs that arrive.' : NO_ROWS; } -// Stop Follow, once the person agrees that it cannot be turned on again. +// Stop Follow, once the person agrees: the page has no action to turn it on again. function stopFollowing() { - const question = `Stop following? "${view.state.title}" cannot follow again. Rows that arrive later are added with "Add rows from the runs", or go to a new batch.`; + const question = `Stop following? This page cannot make "${view.state.title}" follow again. Rows that arrive later are added with "Add rows from the runs", or go to a new batch.`; if (confirm(question)) act('follow/stop'); } diff --git a/packages/essapps/tests/batch/web_browser_test.py b/packages/essapps/tests/batch/web_browser_test.py index 174c8960..dd76edf6 100644 --- a/packages/essapps/tests/batch/web_browser_test.py +++ b/packages/essapps/tests/batch/web_browser_test.py @@ -745,7 +745,7 @@ def answer(dialog: Any) -> None: following.wait_for_selector('#stop-follow', state='hidden') assert following.is_hidden('#follow-status') assert intake.following is None - assert 'cannot follow again' in asked[0] + assert 'follow again' in asked[0] assert 'Add rows from the runs' in asked[0]