From b9714a9e799f0bfb887eb62bd54bf3f54d63d7f4 Mon Sep 17 00:00:00 2001 From: Will Mobley Date: Fri, 20 Nov 2026 15:40:10 -0600 Subject: [PATCH 1/7] Replace a piece's contracts in the same transaction as its sync upsert The catalog sync deleted the contracts of every piece first, then upserted the pieces one request at a time. For the ~30 s that took, a flow check found pieces with no inputs or outputs and refused runs with FLOW_WIRE_TARGET, FLOW_WIRE_SOURCE and FLOW_OUTPUT. Each piece's delete and upsert are now one mutation, which Hasura runs as one transaction. --- svo-adapter-service/app/hasura.py | 42 +++++++++++++++++++ svo-adapter-service/app/mint_sync.py | 36 +++++++--------- svo-adapter-service/app/store.py | 7 ++++ .../tests/test_etl_piece_ownership.py | 2 +- .../tests/test_etl_sync_roundtrip.py | 17 ++++---- 5 files changed, 75 insertions(+), 29 deletions(-) diff --git a/svo-adapter-service/app/hasura.py b/svo-adapter-service/app/hasura.py index e6da38c9..943e6e61 100755 --- a/svo-adapter-service/app/hasura.py +++ b/svo-adapter-service/app/hasura.py @@ -320,6 +320,48 @@ async def execute(self, query: str, variables: dict[str, Any] | None = None) -> # The sync re-inserts a spec's contracts on every run (nested insert under an # upserted spec appends), so it clears them first. Edges cascade and are # recomputed after the sync. +# Replace one registry row and its contracts in one request. Hasura runs the root +# fields of a mutation in order inside one transaction, so the row is never seen +# without contracts: a flow checked during a sync no longer finds a piece with no +# inputs or outputs. `$ids` is the row's own id when its contracts are replaced, +# else empty (an `_in` of nothing deletes nothing). +REPLACE_TRANSFORM_SPEC_MUTATION = """ +mutation ReplaceMintSyncSpec($ids: [String!]!, $obj: adapter_transform_spec_insert_input!) { + delete_adapter_transform_contract(where: { transform_spec_id: { _in: $ids } }) { + affected_rows + } + insert_adapter_transform_spec_one( + object: $obj + on_conflict: { + constraint: transform_spec_mint_model_config_id_key + update_columns: [ + name description transform_type method tapis_app_id app_version + stage env_from_args file_inputs mint_synced_at + ] + } + ) { id mint_model_config_id } +} +""" + +REPLACE_ETL_TRANSFORM_SPEC_MUTATION = """ +mutation ReplaceMintETLSpec($ids: [String!]!, $obj: adapter_transform_spec_insert_input!) { + delete_adapter_transform_contract(where: { transform_spec_id: { _in: $ids } }) { + affected_rows + } + insert_adapter_transform_spec_one( + object: $obj + on_conflict: { + constraint: transform_spec_pkey + update_columns: [ + name description transform_type method tapis_app_id app_version + stage parameters_schema_json env_from_args file_inputs mint_synced_at + owner_username visibility mint_etl_process_id + ] + } + ) { id } +} +""" + DELETE_SPEC_CONTRACTS_MUTATION = """ mutation DeleteSpecContracts($ids: [String!]!) { delete_adapter_transform_contract(where: { transform_spec_id: { _in: $ids } }) { diff --git a/svo-adapter-service/app/mint_sync.py b/svo-adapter-service/app/mint_sync.py index 48d30cf3..48c6ecf1 100755 --- a/svo-adapter-service/app/mint_sync.py +++ b/svo-adapter-service/app/mint_sync.py @@ -440,8 +440,7 @@ async def sync_one_etl_process(hasura_client: Any, process: dict[str, Any]) -> d when the process cannot be a registry row. ``hasura_client`` is the adapter's own (admin) client: it writes the adapter schema. An approval already recorded for the piece is kept; it still has to match the piece to count.""" - from .hasura import ( - DELETE_SPEC_CONTRACTS_MUTATION, GET_APPROVAL_SPEC_QUERY, UPSERT_ETL_TRANSFORM_SPEC_MUTATION) + from .hasura import GET_APPROVAL_SPEC_QUERY, REPLACE_ETL_TRANSFORM_SPEC_MUTATION row = etl_process_to_spec_row(process, []) if row is None: @@ -453,11 +452,12 @@ async def sync_one_etl_process(hasura_client: Any, process: dict[str, Any]) -> d if existing and existing.get("mint_etl_process_id") != row["id"]: raise SpecIdCollision(f"a registry spec with id {row['id']} already exists and is not this piece") contracts = row.pop("contracts", None) - await hasura_client.execute(DELETE_SPEC_CONTRACTS_MUTATION, {"ids": [row["id"]]}) row["mint_synced_at"] = "now()" if contracts: row["contracts"] = contracts - await hasura_client.execute(UPSERT_ETL_TRANSFORM_SPEC_MUTATION, {"obj": row}) + # The old contracts go in the same transaction as the upsert (see + # REPLACE_ETL_TRANSFORM_SPEC_MUTATION), so the piece is never seen without them. + await hasura_client.execute(REPLACE_ETL_TRANSFORM_SPEC_MUTATION, {"ids": [row["id"]], "obj": row}) return row @@ -477,12 +477,11 @@ async def sync_mint_to_adapter( 5. Return a SyncResult with counts + warnings """ from .hasura import ( - UPSERT_TRANSFORM_SPEC_MUTATION, - UPSERT_ETL_TRANSFORM_SPEC_MUTATION, + REPLACE_TRANSFORM_SPEC_MUTATION, + REPLACE_ETL_TRANSFORM_SPEC_MUTATION, DELETE_OBSOLETE_MINT_SPECS_MUTATION, DELETE_OBSOLETE_ETL_SPECS_MUTATION, GET_MINT_SPEC_IDS_QUERY, - DELETE_SPEC_CONTRACTS_MUTATION, ) if mint_client is None: @@ -544,27 +543,22 @@ async def sync_mint_to_adapter( } existing_ids = set(spec_id_by_config) - # Replace, don't append: clear the contracts of every spec this sync is - # about to re-insert them for. - replace_ids = sorted({ - str(row["id"]) if "mint_model_config_id" not in row - else str(spec_id_by_config.get(row["mint_model_config_id"]) or "") - for row in rows_to_upsert if row.get("contracts") - } - {""}) - if replace_ids: - await hasura_client.execute(DELETE_SPEC_CONTRACTS_MUTATION, {"ids": replace_ids}) - for row in rows_to_upsert: contracts = row.pop("contracts", None) is_etl = "mint_model_config_id" not in row is_update = row.get("mint_model_config_id") in existing_ids if not is_etl else False - # Upsert on mint_model_config_id: if the row exists, update all fields; - # contracts are deleted and re-inserted via the nested mutation. + # Replace, don't append: a row whose contracts are re-inserted has its old + # ones deleted in the same transaction as the upsert, so no reader ever + # sees the row without contracts. A row synced without contracts keeps + # the ones it has. + spec_id = (str(row["id"]) if is_etl + else str(spec_id_by_config.get(row["mint_model_config_id"]) or "")) + replace_ids = [spec_id] if contracts and spec_id else [] row["mint_synced_at"] = "now()" if contracts: row["contracts"] = contracts - mutation = UPSERT_ETL_TRANSFORM_SPEC_MUTATION if is_etl else UPSERT_TRANSFORM_SPEC_MUTATION - await hasura_client.execute(mutation, {"obj": row}) + mutation = REPLACE_ETL_TRANSFORM_SPEC_MUTATION if is_etl else REPLACE_TRANSFORM_SPEC_MUTATION + await hasura_client.execute(mutation, {"ids": replace_ids, "obj": row}) if is_update: result.updated += 1 else: diff --git a/svo-adapter-service/app/store.py b/svo-adapter-service/app/store.py index 472b35d7..5de955e0 100755 --- a/svo-adapter-service/app/store.py +++ b/svo-adapter-service/app/store.py @@ -437,6 +437,13 @@ def _op_UpsertMintETLSpec(self, v): def _op_DeleteSpecContracts(self, v): return {"delete_adapter_transform_contract": {"affected_rows": 0}} + # The replace mutations: delete the row's contracts, then upsert it, as one. + def _op_ReplaceMintSyncSpec(self, v): + return {**self._op_DeleteSpecContracts(v), **self._op_UpsertMintSyncSpec(v)} + + def _op_ReplaceMintETLSpec(self, v): + return {**self._op_DeleteSpecContracts(v), **self._op_UpsertMintETLSpec(v)} + def _op_GetMintSpecIds(self, v): mint_rows = [ {"mint_model_config_id": r["mint_model_config_id"]} diff --git a/svo-adapter-service/tests/test_etl_piece_ownership.py b/svo-adapter-service/tests/test_etl_piece_ownership.py index 4f400ce8..f56114e7 100644 --- a/svo-adapter-service/tests/test_etl_piece_ownership.py +++ b/svo-adapter-service/tests/test_etl_piece_ownership.py @@ -84,7 +84,7 @@ def test_built_in_process_stays_public_and_ownerless(): def test_sync_upserts_ownership_and_never_writes_approval(): fake = _FakeHasura([_process()]) asyncio.run(sync_mint_to_adapter(fake)) - (upsert,) = fake.variables_of("UpsertMintETLSpec") + (upsert,) = fake.variables_of("ReplaceMintETLSpec") assert upsert["obj"]["owner_username"] == "alice" assert upsert["obj"]["visibility"] == "private" assert "approved_source_sha256" not in upsert["obj"] diff --git a/svo-adapter-service/tests/test_etl_sync_roundtrip.py b/svo-adapter-service/tests/test_etl_sync_roundtrip.py index 5f8180e5..b10bc96b 100644 --- a/svo-adapter-service/tests/test_etl_sync_roundtrip.py +++ b/svo-adapter-service/tests/test_etl_sync_roundtrip.py @@ -16,7 +16,7 @@ ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT)) -from app.hasura import DELETE_SPEC_CONTRACTS_MUTATION # noqa: E402 +from app.hasura import DELETE_SPEC_CONTRACTS_MUTATION, REPLACE_ETL_TRANSFORM_SPEC_MUTATION # noqa: E402 from app.mint_sync import etl_process_to_spec_row, sync_mint_to_adapter # noqa: E402 from app.planner import build_plan_json # noqa: E402 @@ -95,13 +95,16 @@ async def execute(self, query: str, variables: dict | None = None) -> dict: return {"insert_adapter_transform_spec_one": {"id": "x"}} -def test_resync_clears_contracts_before_reinserting(): +def test_resync_replaces_contracts_in_the_same_request_as_the_upsert(): + # One request per piece deletes its contracts and upserts it, which Hasura runs + # as one transaction: a flow checked mid-sync never sees a piece without them. aoi = next(s for s in _hosted_specs() if s.get("id") == "ts-aoi-from-boundary") fake = _FakeHasura([_as_catalog_row(register.to_object(aoi))], existing=[]) asyncio.run(sync_mint_to_adapter(fake, dry_run=False)) - kinds = [q for q, _ in fake.calls] - delete_at = next(i for i, q in enumerate(kinds) if q == DELETE_SPEC_CONTRACTS_MUTATION) - upsert_at = next(i for i, q in enumerate(kinds) if "UpsertMintETLSpec" in q) - assert delete_at < upsert_at - assert fake.calls[delete_at][1] == {"ids": ["ts-aoi-from-boundary"]} + assert not any(q == DELETE_SPEC_CONTRACTS_MUTATION for q, _ in fake.calls) + (query, variables), = [(q, v) for q, v in fake.calls if "ReplaceMintETLSpec" in q] + assert query == REPLACE_ETL_TRANSFORM_SPEC_MUTATION + assert query.index("delete_adapter_transform_contract") < query.index("insert_adapter_transform_spec_one") + assert variables["ids"] == ["ts-aoi-from-boundary"] + assert variables["obj"]["contracts"] From 2faafcd266bfaddaf7cdd6802a9effcd346a307a Mon Sep 17 00:00:00 2001 From: Will Mobley Date: Fri, 20 Nov 2026 15:46:05 -0600 Subject: [PATCH 2/7] Show only the parameters that differ between runs as table columns The Runs step table had one column per adjustable parameter, so flows with many settings produced wide tables with horizontal and vertical scroll bars nested inside the step pane. Parameters that differ between the listed runs keep a column; the rest are summarised once above the table as 'Same for every run'. The table no longer has its own vertical scroll box. --- .../src/pages/modeling/thread/MintRuns.tsx | 124 ++++++++++++++---- .../thread/__tests__/MintRuns.test.tsx | 80 ++++++++++- 2 files changed, 176 insertions(+), 28 deletions(-) diff --git a/ui-react/src/pages/modeling/thread/MintRuns.tsx b/ui-react/src/pages/modeling/thread/MintRuns.tsx index 84993e1d..60090704 100644 --- a/ui-react/src/pages/modeling/thread/MintRuns.tsx +++ b/ui-react/src/pages/modeling/thread/MintRuns.tsx @@ -1049,6 +1049,87 @@ interface MintRunsProps { const PAGE_SIZE = 100; +interface RunParam { + id?: string | null; + name?: string | null; + default?: string | null; +} + +function humanizeName(name?: string | null): string { + return (name ?? '').replace(/[-_]/g, ' '); +} + +/** The value a run shows for a parameter: its binding, else the default. */ +function runParamValue(param: RunParam, execution: Execution): string { + let value = execution.bindings[param.id ?? ''] as unknown; + if (value == null) value = param.default ?? null; + if (typeof value === 'string' && value.startsWith('__region_geojson')) { + return 'Region GeoJSON'; + } + if (value == null || value === '') return '—'; + return String(value); +} + +/** + * Split parameters into those that tell the listed runs apart (they get a + * column) and those every run shares (they are summarised above the table). + */ +function splitRunParams

( + params: P[], + executions: Execution[], +): { varying: P[]; common: Array<{ param: P; value: string }> } { + const varying: P[] = []; + const common: Array<{ param: P; value: string }> = []; + for (const param of params) { + const values = new Set(executions.map((e) => runParamValue(param, e))); + if (values.size > 1) { + varying.push(param); + } else { + const value = executions[0] ? runParamValue(param, executions[0]) : '—'; + if (value !== '—') common.push({ param, value }); + } + } + return { varying, common }; +} + +const SAME_FOR_EVERY_RUN_LIMIT = 6; + +function SameForEveryRun({ + items, + testId, +}: { + items: Array<{ param: RunParam; value: string }>; + testId: string; +}) { + const [showAll, setShowAll] = useState(false); + if (items.length === 0) return null; + const truncated = items.length > SAME_FOR_EVERY_RUN_LIMIT && !showAll; + const shown = truncated ? items.slice(0, SAME_FOR_EVERY_RUN_LIMIT) : items; + return ( +

+ Same for every run:{' '} + {shown.map(({ param, value }, i) => ( + + {i > 0 && ' · '} + {humanizeName(param.name)} {value} + + ))} + {items.length > SAME_FOR_EVERY_RUN_LIMIT && ( + <> + {' '} + + + )} +

+ ); +} + export function MintRuns({ threadId, threadData, @@ -1351,7 +1432,11 @@ export function MintRuns({ // ── adjustable inputs / params for column headers ───────────── const adjustableInputs = model.input_files.filter((f) => !f.value); - const adjustableParams = userParameters(model).filter((p) => !p.value); + const settableParams = userParameters(model).filter((p) => !p.value); + const { varying: adjustableParams, common: sameParams } = splitRunParams( + settableParams, + grouped.executions, + ); return (
  • @@ -1568,8 +1653,10 @@ export function MintRuns({ - {/* Runs table */} -
    + {/* Runs table: paged, so it grows with the step pane instead of + adding a scroll box of its own. */} + +
    {grouped.loading ? (
    @@ -1579,7 +1666,7 @@ export function MintRuns({ className="w-full border-collapse text-xs" data-testid={`runs-table-${mid}`} > - + Run @@ -1617,7 +1704,7 @@ export function MintRuns({ ))} {adjustableParams.map((p) => ( - {(p.name ?? '').replace(/[-_]/g, ' ')} + {humanizeName(p.name)} ))} @@ -1643,10 +1730,6 @@ export function MintRuns({ ) : ( grouped.executions.map((execution: Execution) => { - const paramDefaults: Record = {}; - userParameters(model).forEach( - (p) => (paramDefaults[p.id ?? ''] = p.default ?? null), - ); return ( @@ -1713,24 +1796,11 @@ export function MintRuns({ ); })} - {adjustableParams.map((param) => { - let pval = execution.bindings[param.id ?? ''] as - | string - | null - | undefined; - if (pval == null) pval = paramDefaults[param.id ?? '']; - if ( - typeof pval === 'string' && - pval.startsWith('__region_geojson') - ) { - pval = 'Region GeoJSON'; - } - return ( - - {pval ?? '—'} - - ); - })} + {adjustableParams.map((param) => ( + + {runParamValue(param, execution)} + + ))} ); }) diff --git a/ui-react/src/pages/modeling/thread/__tests__/MintRuns.test.tsx b/ui-react/src/pages/modeling/thread/__tests__/MintRuns.test.tsx index 73bf3ccc..af3984d0 100644 --- a/ui-react/src/pages/modeling/thread/__tests__/MintRuns.test.tsx +++ b/ui-react/src/pages/modeling/thread/__tests__/MintRuns.test.tsx @@ -2,7 +2,7 @@ * Tests for MintRuns — execution lifecycle step. */ import { afterEach, beforeEach, describe, expect, it, vi, type Mock } from 'vitest'; -import { screen, fireEvent, waitFor } from '@testing-library/react'; +import { screen, fireEvent, waitFor, within } from '@testing-library/react'; import { renderWithProviders } from '@/test/utils/render'; import { storeTokens } from '@/lib/auth/token-store'; import { MintRuns } from '../MintRuns'; @@ -943,3 +943,81 @@ describe('MintRuns archived files', () => { ); }); }); + +// A flow can expose a dozen settings; only the ones that tell runs apart earn +// a column, the rest are summarised once above the table. +describe('MintRuns runs table columns', () => { + const model = { + ...mockModel, + input_parameters: [ + { id: 'p-depth', name: 'flood_depth', type: 'float', default: '10' }, + { id: 'p-mode', name: 'match_mode', type: 'string', default: 'longest_match' }, + { id: 'p-max', name: 'max_files', type: 'int', default: '200' }, + ], + }; + const thread: ThreadExecutionData = { + ...mockThreadDataSubmitted, + models: { 'model-1': model }, + model_ensembles: { + 'model-1': { + id: 'ens-1', + bindings: { 'p-depth': ['15', '25'], 'p-mode': ['longest_match'], 'p-max': ['200'] }, + }, + }, + }; + const run = (id: string, bindings: Record) => ({ + id, + modelid: 'model-1', + status: 'SUCCESS', + run_progress: 1, + bindings, + results: {}, + }); + + function renderRuns(runs: ReturnType[]) { + return renderWithProviders( + , + ); + } + + it('shows no parameter columns for one run and lists every value as shared', () => { + renderRuns([run('exec-1', { 'p-depth': '15' })]); + const table = screen.getByTestId('runs-table-model-1'); + expect(within(table).queryByText('Parameters')).not.toBeInTheDocument(); + expect(within(table).queryByText('flood depth')).not.toBeInTheDocument(); + const line = screen.getByTestId('same-for-every-run-model-1'); + expect(line).toHaveTextContent('Same for every run:'); + expect(line).toHaveTextContent('flood depth 15'); + expect(line).toHaveTextContent('match mode longest_match'); + expect(line).toHaveTextContent('max files 200'); + }); + + it('gives only the parameter that differs a column', () => { + renderRuns([run('exec-1', { 'p-depth': '15' }), run('exec-2', { 'p-depth': '25' })]); + const table = screen.getByTestId('runs-table-model-1'); + expect(within(table).getByText('flood depth')).toBeInTheDocument(); + expect(within(table).queryByText('match mode')).not.toBeInTheDocument(); + expect(within(table).queryByText('max files')).not.toBeInTheDocument(); + expect(within(table).getByText('15')).toBeInTheDocument(); + expect(within(table).getByText('25')).toBeInTheDocument(); + const line = screen.getByTestId('same-for-every-run-model-1'); + expect(line).toHaveTextContent('match mode longest_match'); + expect(line).not.toHaveTextContent('flood depth'); + }); + + it('does not wrap the table in a vertically scrolling box', () => { + renderRuns([run('exec-1', {}), run('exec-2', {})]); + const wrapper = screen.getByTestId('runs-table-model-1').parentElement; + expect(wrapper?.className).not.toContain('max-h-96'); + expect(wrapper?.className).not.toMatch(/\boverflow-(auto|y-)/); + }); +}); From 5e474fb608b5fb23152e6cdc5d6186cd8ffdb286 Mon Sep 17 00:00:00 2001 From: Will Mobley Date: Fri, 20 Nov 2026 15:52:03 -0600 Subject: [PATCH 3/7] Credentials: show a typed value on request and save values trimmed A pasted key with a space at either end reached the model server as a key that does not start with sk-, and was refused with a 401 though it looked right. The Saved credentials form now has a show/hide button for each typed value and warns when a value starts or ends with a space or a quote mark. The adapter stores every field with spaces at either end removed, and the form trims too. Stored values are still never read back. --- svo-adapter-service/app/secrets.py | 17 +++++-- .../tests/test_secrets_store.py | 10 +++- ui-react/src/lib/user-secrets.ts | 18 ++++++- .../src/pages/account/CredentialsPage.tsx | 50 +++++++++++++++---- .../__tests__/CredentialsPage.test.tsx | 30 +++++++++++ 5 files changed, 110 insertions(+), 15 deletions(-) diff --git a/svo-adapter-service/app/secrets.py b/svo-adapter-service/app/secrets.py index b40be962..7e9b54d6 100644 --- a/svo-adapter-service/app/secrets.py +++ b/svo-adapter-service/app/secrets.py @@ -110,23 +110,32 @@ def validate_name(name: str) -> str: def validate_fields(fields: dict[str, str]) -> dict[str, str]: - """Field names ``[a-z0-9_]{1,32}``, at most 16, 4 KiB total, no NUL/newline.""" + """Field names ``[a-z0-9_]{1,32}``, at most 16, 4 KiB total, no NUL/newline. + + Returns the fields with spaces at either end of each value removed: they are + never part of a key or an address, and sent along they make a server reject a + key that looks right (a pasted " sk-..."). Store what this returns.""" if not isinstance(fields, dict) or not fields: raise SecretValidationError("fields must be a non-empty object") if len(fields) > MAX_FIELDS: raise SecretValidationError(f"at most {MAX_FIELDS} fields are allowed") total = 0 + cleaned: dict[str, str] = {} for key, value in fields.items(): if not isinstance(key, str) or not FIELD_RE.match(key): raise SecretValidationError("field names must match [a-z0-9_]{1,32}") - if not isinstance(value, str) or not value: + if not isinstance(value, str): raise SecretValidationError(f"field {key!r} must be a non-empty string") if "\x00" in value or "\n" in value or "\r" in value: raise SecretValidationError(f"field {key!r} must not contain NUL or newlines") + value = value.strip() + if not value: + raise SecretValidationError(f"field {key!r} must be a non-empty string") + cleaned[key] = value total += len(key.encode()) + len(value.encode()) if total > MAX_TOTAL_BYTES: raise SecretValidationError(f"fields exceed {MAX_TOTAL_BYTES} bytes in total") - return fields + return cleaned # -------------------------------------------------------------------------- @@ -215,7 +224,7 @@ async def find(self, scope: str, owner: str, name: str, configuration_id: str) - async def put(self, *, scope, owner, name, configuration_id, pinned_app_id, pinned_app_version, fields, actor) -> dict[str, Any]: validate_name(name) - validate_fields(fields) + fields = validate_fields(fields) existing = await self.find(scope, owner, name, configuration_id) now = datetime.now(tz=timezone.utc).isoformat() row = { diff --git a/svo-adapter-service/tests/test_secrets_store.py b/svo-adapter-service/tests/test_secrets_store.py index 29618ef8..9ae698be 100644 --- a/svo-adapter-service/tests/test_secrets_store.py +++ b/svo-adapter-service/tests/test_secrets_store.py @@ -124,13 +124,21 @@ def test_bad_secret_names_are_rejected(name): @pytest.mark.parametrize("fields", [ - {}, {"Bad": "x"}, {"a" * 33: "x"}, {"a": ""}, {"a": "x\ny"}, {"a": "x\x00y"}, + {}, {"Bad": "x"}, {"a" * 33: "x"}, {"a": ""}, {"a": " "}, {"a": "x\ny"}, {"a": "x\x00y"}, {f"f{i}": "v" for i in range(17)}, {"a": "x" * 4097}]) def test_bad_field_sets_are_rejected(fields): with pytest.raises(secrets_store.SecretValidationError): secrets_store.validate_fields(fields) +def test_values_are_stored_without_spaces_at_either_end(): + # A pasted " sk-abc " reaches the model server as the key it is, not with the spaces. + assert secrets_store.validate_fields({"api_key": " sk-abc\t", "url": "https://x "}) == { + "api_key": "sk-abc", "url": "https://x"} + # Spaces inside a value are kept. + assert secrets_store.validate_fields({"note": " a b "}) == {"note": "a b"} + + def test_rotation_reencrypts_under_the_new_key_and_the_old_key_can_go(monkeypatch): old = Fernet.generate_key().decode() new = Fernet.generate_key().decode() diff --git a/ui-react/src/lib/user-secrets.ts b/ui-react/src/lib/user-secrets.ts index 56326d99..1d69b545 100644 --- a/ui-react/src/lib/user-secrets.ts +++ b/ui-react/src/lib/user-secrets.ts @@ -107,6 +107,22 @@ export async function deleteUserSecret(name: string): Promise { } /** The first rule a credential breaks, as a sentence, or null when it is fine. */ +/** + * What may be wrong with a typed value, shown under its box, or null. Spaces at + * either end are removed when the value is saved; quote marks are kept (a value + * may hold them), but usually come from copying a key out of a config file. + */ +export function credentialValueWarning(value: string): string | null { + if (value === '') return null; + if (value !== value.trim()) { + return 'This value starts or ends with a space. Spaces at either end are removed when it is saved.'; + } + if (/^["'`]|["'`]$/.test(value)) { + return 'This value starts or ends with a quote mark. Remove it unless the quote is part of the value.'; + } + return null; +} + export function validateUserSecret( name: string, fields: Array<{ name: string; value: string }>, @@ -123,7 +139,7 @@ export function validateUserSecret( } if (seen.has(f.name)) return 'Each field name can be used only once.'; seen.add(f.name); - if (f.value === '') return `Enter a value for "${f.name}".`; + if (f.value.trim() === '') return `Enter a value for "${f.name}".`; } const bytes = fields.reduce( (n, f) => diff --git a/ui-react/src/pages/account/CredentialsPage.tsx b/ui-react/src/pages/account/CredentialsPage.tsx index e1fcaea4..cf08bfd2 100644 --- a/ui-react/src/pages/account/CredentialsPage.tsx +++ b/ui-react/src/pages/account/CredentialsPage.tsx @@ -3,8 +3,11 @@ * * A value is typed into a password field, sent once and never shown again, so * replacing a credential means entering every field again. Values live only in - * this form's state and are dropped as soon as the save succeeds. + * this form's state and are dropped as soon as the save succeeds. "Show" reveals + * only what is typed in the form, so the person can check it before saving; a + * stored value is never read back. */ +import { Eye, EyeOff } from 'lucide-react'; import { useCallback, useEffect, useState } from 'react'; import { ConfirmDialog } from '@/components/common/ConfirmDialog'; @@ -12,6 +15,7 @@ import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { + credentialValueWarning, deleteUserSecret, listUserSecrets, MODEL_SERVER_PRESET, @@ -53,6 +57,8 @@ export function CredentialsPage() { const [notice, setNotice] = useState(null); const [saving, setSaving] = useState(false); const [toDelete, setToDelete] = useState(null); + // Which typed values are shown in clear, by field key. Reset with the form. + const [shown, setShown] = useState>({}); const reload = useCallback(async () => { try { @@ -69,6 +75,7 @@ export function CredentialsPage() { const open = (next: FormState) => { setForm(next); + setShown({}); setFormError(null); setNotice(null); }; @@ -85,6 +92,7 @@ export function CredentialsPage() { const close = () => { setForm(null); + setShown({}); setFormError(null); }; @@ -104,11 +112,14 @@ export function CredentialsPage() { setFormError(null); try { const fields: Record = {}; - for (const f of form.fields) fields[f.name] = f.value; + // Spaces at either end are never part of a key or an address; sent, they make + // a server reject a key that looks right. + for (const f of form.fields) fields[f.name] = f.value.trim(); await saveUserSecret(form.name, fields); const verb = form.mode === 'replace' ? 'replaced' : 'saved'; // Drop every typed value from state before anything else happens. setForm(null); + setShown({}); setNotice(`Credential "${form.name}" ${verb}.`); await reload(); } catch (error) { @@ -237,13 +248,34 @@ export function CredentialsPage() {
    - patchField(f.key, { value: e.target.value })} - /> +
    + patchField(f.key, { value: e.target.value })} + /> + +
    + {credentialValueWarning(f.value) && ( +

    + {credentialValueWarning(f.value)} +

    + )}
    {form.mode === 'add' && form.fields.length > 1 && ( + )} + {problem} +
    + ); +} diff --git a/ui-react/src/components/modeling/runs/SameForEveryRun.tsx b/ui-react/src/components/modeling/runs/SameForEveryRun.tsx new file mode 100644 index 00000000..3fac4d28 --- /dev/null +++ b/ui-react/src/components/modeling/runs/SameForEveryRun.tsx @@ -0,0 +1,42 @@ +import { useState } from 'react'; + +import { humanizeName, type RunParam } from '@/lib/modeling/run-settings'; + +const SAME_FOR_EVERY_RUN_LIMIT = 6; + +/** The settings every listed run shares, summarised once above a table. */ +export function SameForEveryRun({ + items, + testId, +}: { + items: Array<{ param: RunParam; value: string }>; + testId: string; +}) { + const [showAll, setShowAll] = useState(false); + if (items.length === 0) return null; + const truncated = items.length > SAME_FOR_EVERY_RUN_LIMIT && !showAll; + const shown = truncated ? items.slice(0, SAME_FOR_EVERY_RUN_LIMIT) : items; + return ( +

    + Same for every run:{' '} + {shown.map(({ param, value }, i) => ( + + {i > 0 && ' · '} + {humanizeName(param.name)} {value} + + ))} + {items.length > SAME_FOR_EVERY_RUN_LIMIT && ( + <> + {' '} + + + )} +

    + ); +} diff --git a/ui-react/src/components/modeling/runs/SettingsUsed.tsx b/ui-react/src/components/modeling/runs/SettingsUsed.tsx new file mode 100644 index 00000000..b8ac3e6c --- /dev/null +++ b/ui-react/src/components/modeling/runs/SettingsUsed.tsx @@ -0,0 +1,44 @@ +import type { Execution } from '@/graphql/generated/execution'; +import { settingsUsed, type RunParam } from '@/lib/modeling/run-settings'; + +/** + * What one run was given: its settings, those changed from their default first. + * Collapsed, so a run that used only defaults does not take up the page. + */ +export function SettingsUsed({ + params, + execution, + testId, + summary = 'Settings used', +}: { + params: RunParam[]; + execution: Execution | undefined; + testId: string; + summary?: string; +}) { + const settings = execution ? settingsUsed(params, execution) : []; + if (settings.length === 0) return null; + const changed = settings.filter((s) => s.changed).length; + return ( +
    + + {summary} + + ({settings.length} + {changed > 0 ? `, ${changed} changed from default` : ''}) + + +
    + {settings.map((setting) => ( +
    +
    + {setting.label} + {setting.changed && changed} +
    +
    {setting.value}
    +
    + ))} +
    +
    + ); +} diff --git a/ui-react/src/lib/__tests__/result-preview.test.ts b/ui-react/src/lib/__tests__/result-preview.test.ts new file mode 100644 index 00000000..d54e1273 --- /dev/null +++ b/ui-react/src/lib/__tests__/result-preview.test.ts @@ -0,0 +1,54 @@ +import { describe, expect, it } from 'vitest'; + +import { parseCsvRows, prettyJson, previewKind, readBlobText } from '../result-preview'; + +describe('previewKind', () => { + it('reads the kind from the file name', () => { + expect(previewKind('report.md')).toBe('markdown'); + expect(previewKind('REPORT.MARKDOWN')).toBe('markdown'); + expect(previewKind('table.csv')).toBe('csv'); + expect(previewKind('lexicon.json')).toBe('json'); + expect(previewKind('map.tif')).toBeNull(); + expect(previewKind('noextension')).toBeNull(); + }); +}); + +describe('parseCsvRows', () => { + it('reads quoted fields, doubled quotes and a newline inside quotes', () => { + const rows = parseCsvRows('a,b\n"x, y","say ""hi"""\n"two\nlines",z\n'); + expect(rows).toEqual([ + ['a', 'b'], + ['x, y', 'say "hi"'], + ['two\nlines', 'z'], + ]); + }); + + it('stops after the row limit and handles CRLF and a missing final newline', () => { + const text = Array.from({ length: 30 }, (_, i) => `r${i},v${i}`).join('\r\n'); + const rows = parseCsvRows(text, 10); + expect(rows).toHaveLength(10); + expect(rows[9]).toEqual(['r9', 'v9']); + expect(parseCsvRows('a,b\n1,2')).toEqual([ + ['a', 'b'], + ['1', '2'], + ]); + }); +}); + +describe('prettyJson', () => { + it('indents valid JSON and leaves cut-off JSON as it was', () => { + expect(prettyJson('{"a":1}')).toBe('{\n "a": 1\n}'); + expect(prettyJson('{"a":')).toBe('{"a":'); + }); +}); + +describe('readBlobText', () => { + it('reads a small blob whole', async () => { + expect(await readBlobText(new Blob(['hello']))).toEqual({ text: 'hello', truncated: false }); + }); + + it('reads only the first bytes of a large blob and says so', async () => { + const read = await readBlobText(new Blob(['abcdefghij']), 4); + expect(read).toEqual({ text: 'abcd', truncated: true }); + }); +}); diff --git a/ui-react/src/lib/__tests__/run-settings.test.ts b/ui-react/src/lib/__tests__/run-settings.test.ts new file mode 100644 index 00000000..45947974 --- /dev/null +++ b/ui-react/src/lib/__tests__/run-settings.test.ts @@ -0,0 +1,49 @@ +import { describe, expect, it } from 'vitest'; + +import type { Execution } from '@/graphql/generated/execution'; +import { runDuration, settingsUsed, splitRunParams } from '../modeling/run-settings'; + +const run = (bindings: Record): Execution => ({ + id: 'e', + modelid: 'm', + status: 'SUCCESS', + bindings, + results: {}, +}); + +const params = [ + { id: 'p1', name: 'flood_depth', default: '10' }, + { id: 'p2', name: 'match_mode', default: 'longest' }, + { id: 'p3', name: 'unset_thing', default: null }, +]; + +describe('settingsUsed', () => { + it('lists changed settings first, leaves out those with no value', () => { + const used = settingsUsed(params, run({ p2: 'shortest' })); + expect(used.map((s) => [s.label, s.value, s.changed])).toEqual([ + ['match mode', 'shortest', true], + ['flood depth', '10', false], + ]); + }); + + it('does not call a binding that equals the default changed', () => { + expect(settingsUsed(params, run({ p1: '10' }))[0]?.changed).toBe(false); + }); +}); + +describe('splitRunParams', () => { + it('gives a column to what differs and summarises the rest', () => { + const { varying, common } = splitRunParams(params, [run({ p1: '1' }), run({ p1: '2' })]); + expect(varying.map((p) => p.id)).toEqual(['p1']); + expect(common.map((c) => c.param.id)).toEqual(['p2']); + }); +}); + +describe('runDuration', () => { + it('words a duration, and is null while unfinished', () => { + expect(runDuration('2026-01-01T00:00:00Z', '2026-01-01T00:00:42Z')).toBe('42 s'); + expect(runDuration('2026-01-01T00:00:00Z', '2026-01-01T00:03:10Z')).toBe('3 min'); + expect(runDuration('2026-01-01T00:00:00Z', '2026-01-01T02:05:00Z')).toBe('2 h 05 min'); + expect(runDuration('2026-01-01T00:00:00Z', null)).toBeNull(); + }); +}); diff --git a/ui-react/src/lib/modeling/run-settings.ts b/ui-react/src/lib/modeling/run-settings.ts new file mode 100644 index 00000000..2eaed5c4 --- /dev/null +++ b/ui-react/src/lib/modeling/run-settings.ts @@ -0,0 +1,89 @@ +/** + * What a run was given: the parameter values it used, and how runs of one model + * compare. Pure functions shared by the Runs and Results steps. + */ +import type { Execution } from '@/graphql/generated/execution'; + +/** The longest a model job may run unless the person chose another time. */ +export const DEFAULT_MAX_MINUTES = 60; + +export interface RunParam { + id?: string | null; + name?: string | null; + default?: string | null; +} + +export function humanizeName(name?: string | null): string { + return (name ?? '').replace(/[-_]/g, ' '); +} + +/** The value a run shows for a parameter: its binding, else the default. */ +export function runParamValue(param: RunParam, execution: Execution): string { + let value = execution.bindings[param.id ?? ''] as unknown; + if (value == null) value = param.default ?? null; + if (typeof value === 'string' && value.startsWith('__region_geojson')) { + return 'Region GeoJSON'; + } + if (value == null || value === '') return '—'; + return String(value); +} + +/** + * Split parameters into those that tell the listed runs apart (they get a + * column) and those every run shares (they are summarised above the table). + */ +export function splitRunParams

    ( + params: P[], + executions: Execution[], +): { varying: P[]; common: Array<{ param: P; value: string }> } { + const varying: P[] = []; + const common: Array<{ param: P; value: string }> = []; + for (const param of params) { + const values = new Set(executions.map((e) => runParamValue(param, e))); + if (values.size > 1) { + varying.push(param); + } else { + const value = executions[0] ? runParamValue(param, executions[0]) : '—'; + if (value !== '—') common.push({ param, value }); + } + } + return { varying, common }; +} + +export interface UsedSetting { + id: string; + label: string; + value: string; + /** The run used a value other than the parameter's default. */ + changed: boolean; +} + +/** + * The settings one run used, those changed from their default first. A setting + * with no value (no binding, no default) is left out. + */ +export function settingsUsed(params: RunParam[], execution: Execution): UsedSetting[] { + const used = params.flatMap((param, index) => { + const value = runParamValue(param, execution); + if (value === '—') return []; + const bound = execution.bindings[param.id ?? ''] as unknown; + const changed = bound != null && bound !== '' && String(bound) !== String(param.default ?? ''); + return [{ id: param.id ?? String(index), label: humanizeName(param.name), value, changed }]; + }); + return [...used.filter((s) => s.changed), ...used.filter((s) => !s.changed)]; +} + +/** How long a run took, or null while it is unfinished or its times are unknown. */ +export function runDuration( + start: string | null | undefined, + end: string | null | undefined, +): string | null { + if (!start || !end) return null; + const ms = Date.parse(end) - Date.parse(start); + if (!Number.isFinite(ms) || ms < 0) return null; + const seconds = Math.round(ms / 1000); + if (seconds < 60) return `${seconds} s`; + const minutes = Math.floor(seconds / 60); + if (minutes < 60) return `${minutes} min`; + return `${Math.floor(minutes / 60)} h ${String(minutes % 60).padStart(2, '0')} min`; +} diff --git a/ui-react/src/lib/result-preview.ts b/ui-react/src/lib/result-preview.ts new file mode 100644 index 00000000..b813ad6d --- /dev/null +++ b/ui-react/src/lib/result-preview.ts @@ -0,0 +1,86 @@ +/** + * Helpers for the inline preview of a result file: what kind of text it is, a + * capped read of its content, and small parsers. Pure, apart from the blob read. + */ + +/** The most a preview reads of one file. */ +export const PREVIEW_MAX_BYTES = 200 * 1024; +/** How many CSV rows a preview shows, header included. */ +export const PREVIEW_CSV_ROWS = 10; + +export type PreviewKind = 'markdown' | 'csv' | 'json'; + +/** What a file can be previewed as, from its name; null when it cannot. */ +export function previewKind(name: string): PreviewKind | null { + const extension = /\.([a-z0-9]+)(?:[?#].*)?$/i.exec(name)?.[1]?.toLowerCase(); + if (extension === 'md' || extension === 'markdown') return 'markdown'; + if (extension === 'csv') return 'csv'; + if (extension === 'json') return 'json'; + return null; +} + +/** The first `maxBytes` of a blob as text, and whether the rest was left out. */ +export async function readBlobText( + blob: Blob, + maxBytes = PREVIEW_MAX_BYTES, +): Promise<{ text: string; truncated: boolean }> { + const part = blob.size > maxBytes ? blob.slice(0, maxBytes) : blob; + const text = + typeof part.text === 'function' + ? await part.text() + : await new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onload = () => resolve(String(reader.result ?? '')); + reader.onerror = () => reject(reader.error); + reader.readAsText(part); + }); + return { text, truncated: blob.size > maxBytes }; +} + +/** The first `maxRows` rows of CSV text, with quoted fields and doubled quotes read. */ +export function parseCsvRows(text: string, maxRows = PREVIEW_CSV_ROWS): string[][] { + const rows: string[][] = []; + let row: string[] = []; + let field = ''; + let quoted = false; + const endRow = () => { + row.push(field); + field = ''; + if (row.some((cell) => cell !== '')) rows.push(row); + row = []; + }; + for (let i = 0; i < text.length && rows.length < maxRows; i += 1) { + const char = text[i]; + if (quoted) { + if (char === '"' && text[i + 1] === '"') { + field += '"'; + i += 1; + } else if (char === '"') { + quoted = false; + } else { + field += char; + } + } else if (char === '"') { + quoted = true; + } else if (char === ',') { + row.push(field); + field = ''; + } else if (char === '\n' || char === '\r') { + if (char === '\r' && text[i + 1] === '\n') i += 1; + endRow(); + } else { + field += char; + } + } + if (rows.length < maxRows && (field !== '' || row.length > 0)) endRow(); + return rows.slice(0, maxRows); +} + +/** JSON text indented, or the text as it was when it does not parse (a cut-off file). */ +export function prettyJson(text: string): string { + try { + return JSON.stringify(JSON.parse(text), null, 2); + } catch { + return text; + } +} diff --git a/ui-react/src/pages/modeling/MintThread.tsx b/ui-react/src/pages/modeling/MintThread.tsx index c36aa669..e8dddabe 100644 --- a/ui-react/src/pages/modeling/MintThread.tsx +++ b/ui-react/src/pages/modeling/MintThread.tsx @@ -81,6 +81,7 @@ import { MintParameters } from './thread/MintParameters'; import type { PublishRequest } from '@/lib/publish-outputs'; import type { SpatialSelection } from './thread/SpatialScopeMap'; import { MintRuns } from './thread/MintRuns'; +import { DEFAULT_MAX_MINUTES } from '@/lib/modeling/run-settings'; import { MintResults } from './thread/MintResults'; import { WizardRail, type ThreadStepNav } from './thread/wizard/WizardRail'; import { deriveStepStates } from './thread/wizard/deriveStepStates'; @@ -1299,6 +1300,10 @@ export function MintThread({ onFetchRuns={handleFetchRuns} onPublishResults={handlePublishResults} onPromoteOutputs={() => setCurrentSection('runs')} + onOpenRuns={() => setCurrentSection('runs')} + onRestartRuns={ + perm.write ? (modelId) => handleSubmitRuns(modelId, DEFAULT_MAX_MINUTES) : undefined + } /> ); case 'summary': diff --git a/ui-react/src/pages/modeling/thread/FlowRunPanel.tsx b/ui-react/src/pages/modeling/thread/FlowRunPanel.tsx index fc371755..0aa56411 100644 --- a/ui-react/src/pages/modeling/thread/FlowRunPanel.tsx +++ b/ui-react/src/pages/modeling/thread/FlowRunPanel.tsx @@ -4,10 +4,12 @@ * A flow runs as a graph of steps, not as one model job, so the model-shaped * "prepare inputs / run model / hand off" rows do not describe it. This panel * draws the run's own `workflow_stages`: one node per step, joined by - * `depends_on`, with a plain list of the same steps underneath. + * `depends_on`, once. A run stopped for an edit puts its controls first; a run + * that failed says why and offers Restart; step task ids sit under a collapsed + * "Technical details". */ import { RefreshCw } from 'lucide-react'; -import { useState } from 'react'; +import { useState, type ReactNode } from 'react'; import { WorkflowCanvas, @@ -15,8 +17,10 @@ import { type WorkflowCanvasPosition, } from '@/components/modeling/WorkflowCanvas'; import { FLOW_LAYOUT_OPTIONS, flowCanvasHeight, layoutFlowGraph } from '@/lib/flow-graph-layout'; -import { EnsembleManagerError, type UnifiedRunSnapshot } from '@/lib/ensemble-manager'; -import { flowErrorMessage, stepErrorText } from '@/lib/flow-errors'; +import { RunFailureNotice } from '@/components/modeling/runs/RunFailureNotice'; +import type { UnifiedRunSnapshot } from '@/lib/ensemble-manager'; +import { stepErrorText } from '@/lib/flow-errors'; +import { normalizeRunStatus } from '@/lib/modeling/run-status'; import { EditedInputNote } from './EditedInputNote'; import { PausedFlowStep, type PausedEdit } from './PausedFlowStep'; @@ -43,15 +47,6 @@ const STEP_NODE_CLASS: Record = { skipped: 'border-gray-200 bg-gray-50 text-gray-500', }; -const STEP_PILL_CLASS: Record = { - waiting: 'bg-gray-100 text-gray-700', - running: 'bg-blue-100 text-blue-800', - completed: 'bg-green-100 text-green-800', - failed: 'bg-red-100 text-red-800', - cancelled: 'bg-red-100 text-red-800', - skipped: 'bg-gray-100 text-gray-500', -}; - const TERMINAL_RUN_STATUSES = ['completed', 'failed', 'cancelled']; /** A step's state from the word the Ensemble Manager reports for it. */ @@ -118,34 +113,6 @@ function FlowStepNode({ node }: { node: FlowGraphNode }) { ); } -/** The run-level refusal text for a failed flow, once. */ -function RunFailure({ run }: { run: UnifiedRunSnapshot }) { - if (!run.failure_code && !run.error_message) return null; - const known = run.failure_code - ? flowErrorMessage(new EnsembleManagerError(0, run.error_message ?? '', run.failure_code)) - : null; - return ( -

    - {known ? ( - <> -
    {known.title}
    - {known.lines.map((line, index) => ( -
    {line}
    - ))} - - ) : ( - <> - {run.failure_code &&
    Failure: {run.failure_code}
    } - {run.error_message &&
    {run.error_message}
    } - - )} -
    - ); -} - export interface FlowRunPanelProps { run: UnifiedRunSnapshot; onRefresh?: () => Promise; @@ -158,6 +125,11 @@ export interface FlowRunPanelProps { username?: string; /** Sends the user's edited file on and continues the run. */ onResume?: (edit: PausedEdit) => Promise; + /** Sends the flow again after it failed or was cancelled. */ + onRestart?: () => void; + restarting?: boolean; + /** Why the last send was refused, shown beside Restart. */ + restartProblem?: ReactNode; } export function FlowRunPanel({ @@ -170,6 +142,9 @@ export function FlowRunPanel({ ensembleManagerApi = '', username = '', onResume, + onRestart, + restarting = false, + restartProblem, }: FlowRunPanelProps) { const [confirmingCancel, setConfirmingCancel] = useState(false); const stages: FlowStage[] = run.workflow_stages?.length @@ -188,24 +163,51 @@ export function FlowRunPanel({ const tapisWorkflow = run.tapis_workflow; const active = !TERMINAL_RUN_STATUSES.includes(String(run.status ?? '')); const canvasHeight = flowCanvasHeight(graph.positions); + const outcome = normalizeRunStatus(run.status); + const ended = outcome === 'failed' || outcome === 'cancelled'; + const stepErrors = stages.flatMap((stage) => + stage.error_message ? [`${flowStepLabel(stage)}: ${stepErrorText(stage.error_message)}`] : [], + ); + const tasks = stages.filter((stage) => stage.provider_ids?.task_id); return ( -
    +
    + {run.status === 'awaiting_edit' && run.pause && ( + stage.stage_id === `step-${run.pause?.paused_after_step}`)?.name + } + /> + )} + {run.replacement && } + + {(ended || run.failure_code || run.error_message || onRestart) && ( + + )} +
    - Flow steps + Steps {onRefresh && ( )}
    @@ -220,48 +222,6 @@ export function FlowRunPanel({ testId="flow-graph-canvas" /> - {run.status === 'awaiting_edit' && run.pause && ( - stage.stage_id === `step-${run.pause?.paused_after_step}`)?.name - } - /> - )} - {run.replacement && } - -
      - {stages.map((stage) => { - const state = flowStepState(stage.status); - const taskId = stage.provider_ids?.task_id; - return ( -
    1. -
      - {flowStepLabel(stage)} - - {STEP_LABEL[state]} - -
      - {stage.error_message && ( -

      {stepErrorText(stage.error_message)}

      - )} - {taskId && ( -

      - Task {taskId} -

      - )} -
    2. - ); - })} -
    - {active && onCancel && (
    {confirmingCancel ? ( @@ -305,10 +265,8 @@ export function FlowRunPanel({
    )} - - -
    - Technical identifiers +
    + Technical details
    Tapis workflow run ID: {tapisWorkflow?.run_id ?? 'not submitted yet'} @@ -323,6 +281,15 @@ export function FlowRunPanel({ Execution ID: {run.run_id}
    )} + {tasks.length > 0 && ( +
      + {tasks.map((stage) => ( +
    • + {flowStepLabel(stage)}: task {stage.provider_ids?.task_id} +
    • + ))} +
    + )}
    @@ -331,9 +298,6 @@ export function FlowRunPanel({ Showing the last saved workflow state. Refresh failed: {refreshError}
    )} -

    - Application logs and files remain available from the run records below. -

    ); } diff --git a/ui-react/src/pages/modeling/thread/MintResults.tsx b/ui-react/src/pages/modeling/thread/MintResults.tsx index 4f20e63c..64805e0e 100644 --- a/ui-react/src/pages/modeling/thread/MintResults.tsx +++ b/ui-react/src/pages/modeling/thread/MintResults.tsx @@ -7,7 +7,7 @@ * * Legacy: ui/src/screens/modeling/thread/mint-results.ts */ -import { userParameters } from '@/lib/secret-parameters'; +import { secretErrorMessage, userParameters } from '@/lib/secret-parameters'; import { Download, RefreshCw } from 'lucide-react'; import { useCallback, useEffect, useState } from 'react'; @@ -18,9 +18,21 @@ import { ModelOutputFile, ThreadExecutionData, } from '@/graphql/generated/execution'; +import { CollapsibleCard } from '@/components/common/CollapsibleCard'; import { RunAnswerCard } from '@/components/modeling/runs/RunAnswerCard'; +import { RunFailureNotice } from '@/components/modeling/runs/RunFailureNotice'; +import { SameForEveryRun } from '@/components/modeling/runs/SameForEveryRun'; +import { SettingsUsed } from '@/components/modeling/runs/SettingsUsed'; +import { flowErrorMessage } from '@/lib/flow-errors'; +import { + aggregateRunStatus, + displayStatusLabel, + statusPillClasses, +} from '@/lib/modeling/run-status'; +import { humanizeName, runParamValue, splitRunParams } from '@/lib/modeling/run-settings'; import { EditedInputNote } from './EditedInputNote'; import { ExecutionFilesDialog } from './ExecutionFilesDialog'; +import { OutputBlock } from './OutputBlock'; import { TapisResult } from './TapisResult'; import { EnsembleManagerError, @@ -135,6 +147,10 @@ interface MintResultsProps { * model configuration declares no output. */ onPromoteOutputs?: () => void; + /** Take the user to the Runs step: where a paused run is edited and a failed one restarted. */ + onOpenRuns?: () => void; + /** Send a model's runs again after they failed. Rejects with the Ensemble Manager's refusal. */ + onRestartRuns?: (modelId: string) => Promise; } // ─── Component ──────────────────────────────────────────────────────────────── @@ -152,6 +168,8 @@ export function MintResults({ onIngestResults, onPublishResults, onPromoteOutputs, + onOpenRuns, + onRestartRuns, unifiedRuns, }: MintResultsProps) { const modelIds = Object.keys(threadData.execution_summary ?? {}); @@ -169,6 +187,10 @@ export function MintResults({ const [filesFor, setFilesFor] = useState<{ executionId: string; modelId: string } | null>(null); const [pages, setPages] = useState>({}); const [showAllOutputs, setShowAllOutputs] = useState(true); + // A card the user closed (or opened) keeps that choice; the rest start open. + const [cardOpen, setCardOpen] = useState>({}); + const [restarting, setRestarting] = useState>({}); + const [restartError, setRestartError] = useState>({}); const [publishWaiting, setPublishWaiting] = useState>({}); const [publishError, setPublishError] = useState>({}); // The server's own error code, kept beside the message. NO_OUTPUTS_DECLARED @@ -228,6 +250,30 @@ export function MintResults({ [onPublishResults, onFetchRuns, pages], ); + const handleRestart = useCallback( + async (mid: string) => { + if (!onRestartRuns) return; + setRestarting((r) => ({ ...r, [mid]: true })); + setRestartError((e) => ({ ...e, [mid]: '' })); + try { + await onRestartRuns(mid); + // The new run is followed in the Runs step. + onOpenRuns?.(); + } catch (err) { + const refusal = flowErrorMessage(err); + setRestartError((e) => ({ + ...e, + [mid]: refusal + ? [refusal.title, ...refusal.lines].join(' ') + : (secretErrorMessage(err) ?? (err instanceof Error ? err.message : String(err))), + })); + } finally { + setRestarting((r) => ({ ...r, [mid]: false })); + } + }, + [onRestartRuns, onOpenRuns], + ); + // ─ CSV download ───────────────────────────────────────────────────────── function handleDownloadCsv( groupedExecutions: Record, @@ -286,12 +332,7 @@ export function MintResults({ return (
    -

    - This step is for browsing the results of the models that you ran earlier. -

    -

    Results

    - -
      +
        {modelIds.map((mid) => { const summary = threadData.execution_summary[mid]!; const model = threadData.models[mid]; @@ -301,15 +342,16 @@ export function MintResults({ const currentPage = pages[mid] ?? 1; const totalPages = Math.ceil((summary.total_runs || 1) / PAGE_SIZE); - const finishedRuns = (summary.successful_runs ?? 0) + (summary.failed_runs ?? 0); + const successfulRuns = summary.successful_runs ?? 0; + const failedRuns = summary.failed_runs ?? 0; + const submittedRuns = summary.submitted_runs ?? 0; + const finishedRuns = successfulRuns + failedRuns; const submitted = summary.submitted_for_execution || summary.submission_time; const finished = finishedRuns >= summary.total_runs && summary.total_runs > 0; - const runningRuns = (summary.submitted_runs ?? 0) - finishedRuns; - const pendingRuns = summary.total_runs - (summary.submitted_runs ?? 0); - const publishedAll = (summary.published_runs ?? 0) >= (summary.successful_runs ?? 0); const submittedPublishing = !!summary.submitted_for_publishing; const submittedIngestion = !!summary.submitted_for_ingestion; const finishedIngestion = (summary.ingested_runs ?? 0) >= summary.total_runs; + const run = unifiedRuns?.[mid]; if (!submitted) { return ( @@ -322,15 +364,23 @@ export function MintResults({ ); } + const status = aggregateRunStatus({ + totalRuns: summary.total_runs, + submittedRuns, + successfulRuns, + failedRuns, + fallbackStatus: run?.status ?? grouped.executions[0]?.status?.toLowerCase(), + }); + const isSingleRun = summary.total_runs <= 1; + const open = cardOpen[mid] ?? true; + // Determine which outputs to show const allOutputs = model.output_files; - let shownOutputs = allOutputs; - if (!showAllOutputs) { - shownOutputs = allOutputs.filter((o) => - matchVariables(threadData.response_variables, o.variables), - ); - } - const hasExtraOutputs = shownOutputs.length < allOutputs.length; + const matching = allOutputs.filter((o) => + matchVariables(threadData.response_variables, o.variables), + ); + const shownOutputs = showAllOutputs ? allOutputs : matching; + const hasExtraOutputs = matching.length > 0 && matching.length < allOutputs.length; // Filter executions with results const executionsWithResults = grouped.executions.filter( @@ -342,70 +392,94 @@ export function MintResults({ }); const adjustableInputs = model.input_files.filter((f) => !f.value); - const adjustableParams = userParameters(model).filter((p) => !p.value); + const settableParams = userParameters(model).filter((p) => !p.value); + const { varying: varyingParams, common: sameParams } = splitRunParams( + settableParams, + executionsWithResults, + ); + const resultExecution = executionsWithResults[0]; - return ( -
      • -
        {model.name}
        -
        - - {unifiedRuns?.[mid]?.replacement && ( - - )} - {submitted && ( - <> -

        - Below are results of all successfully completed model executions. -

        -

        - {summary.total_runs} runs required. {!finished ? 'So far, ' : ''} - {summary.submitted_runs} submitted, {summary.successful_runs} succeeded,{' '} - 0 ? 'text-red-600' : ''}> - {summary.failed_runs} failed - - . {runningRuns > 0 && `${runningRuns} running`} - {runningRuns > 0 && pendingRuns > 0 && ', '} - {pendingRuns > 0 && `${pendingRuns} waiting`} -

        - - )} + const refresh = + finished && onPublishResults + ? () => void handlePublish(mid) + : () => onFetchRuns(mid, currentPage, PAGE_SIZE); - {/* Action buttons */} -
        - {finished && ( + return ( +
      • + setCardOpen((current) => ({ ...current, [mid]: next }))} + title={model.name} + summary={ + + {displayStatusLabel(status)} + + } + > +
        + + {!isSingleRun && !grouped.loading && Object.keys(groupedByKey).length > 0 && ( + )} + {!isSingleRun && hasExtraOutputs && ( + )} {submittedPublishing && !finished && ( -

        + Publishing… {summary.published_runs ?? 0}/{summary.total_runs} runs. -

        + )} {ingestionApiAvailable && finished && !submittedIngestion && canWrite && ( )} {submittedIngestion && !finishedIngestion && ( -

        + Saving… fetched {summary.fetched_run_outputs ?? 0}/{summary.total_runs}, ingested {summary.ingested_runs ?? 0}/{summary.total_runs}. -

        + )}
        @@ -443,236 +517,167 @@ export function MintResults({ ) )} - {/* Pagination + controls */} -
        - {!grouped.loading && ( - <> - - - Page {currentPage} of {totalPages} - - - - )} - - {(hasExtraOutputs || showAllOutputs) && !grouped.loading && ( - - )} - -
        - {!grouped.loading && Object.keys(groupedByKey).length > 0 && ( + {/* A run that has not finished says where it is, and what to do. */} + {status === 'paused' && ( +
        + Waiting for your edit + {onOpenRuns && ( )} -
        -
        + )} + {(status === 'running' || status === 'completing' || status === 'waiting') && ( +

        + + {status === 'waiting' ? 'Waiting to start' : 'Running'} + {!isSingleRun && ` — ${finishedRuns} of ${summary.total_runs} finished`} +

        + )} + {(status === 'failed' || status === 'cancelled') && ( + 0 + ? [`${failedRuns} of ${summary.total_runs} runs failed.`] + : [] + } + onRestart={onRestartRuns ? () => void handleRestart(mid) : undefined} + restarting={restarting[mid]} + problem={ + restartError[mid] ? ( +

        + {restartError[mid]} +

        + ) : undefined + } + testId={`result-failure-${mid}`} + /> + )} - {/* Results table */} -
        - {grouped.loading ? ( -
        - -
        - ) : ( - - - - {shownOutputs.length > 0 && ( - - )} + + {run?.replacement && } + + {isSingleRun ? ( + <> + {resultExecution ? ( +
          + {shownOutputs.map((out) => { + const result = resultExecution.results[out.id]; + if (!result) return null; + const url = getResultUrl( + result, + resultExecution.execution_engine, + mintConfig, + ); + return ( + + setFilesFor({ executionId, modelId: mid }) + } + /> + ); + })} +
        + ) : grouped.loading ? ( +
        + +
        + ) : ( + status === 'completed' && ( +

        + No results yet. Use Refresh to fetch them. +

        + ) + )} + {resultExecution && ( +
        + + How this was made + +
        {adjustableInputs.length > 0 && ( -
        +
        + {adjustableInputs.map((inp) => ( +
        +
        {humanizeName(inp.name)}
        +
        + +
        +
        + ))} +
        )} - {adjustableParams.length > 0 && ( - - )} - - - {shownOutputs.map((o) => ( - - ))} - {adjustableInputs.map((f) => ( - - ))} - {adjustableParams.map((p) => ( - - ))} - - - - {Object.keys(groupedByKey).length === 0 ? ( - - - - ) : ( - Object.values(groupedByKey).map((execution) => { - const paramDefaults: Record = {}; - userParameters(model).forEach( - (p) => (paramDefaults[p.id ?? ''] = p.default ?? null), - ); - return ( - - {shownOutputs.map((out) => { - const result = execution.results[out.id]; - if (!result) - return ( - - ); - const url = getResultUrl( - result, - execution.execution_engine, - mintConfig, - ); - const fname = getResultName(result); - return ( - - ); - })} - {adjustableInputs.map((inp) => { - return ( - - ); - })} - {adjustableParams.map((param) => { - let pval = execution.bindings[param.id ?? ''] as - | string - | null - | undefined; - if (!pval) pval = paramDefaults[param.id ?? '']; - if ( - typeof pval === 'string' && - pval.startsWith('__region_geojson') - ) { - pval = 'Region GeoJSON'; - } - return ( - - ); - })} - - ); - }) - )} - -
        - Outputs - - Inputs - - Parameters -
        - {(o.name ?? '').replace(/[-_]/g, ' ')} - - {(f.name ?? '').replace(/[-_]/g, ' ')} - - {(p.name ?? '').replace(/[-_]/g, ' ')} -
        - — No results available — -
        - — - - {!url ? ( - {fname || 'No file'} - ) : resultScheme(url) === 'tapis' ? ( - - setFilesFor({ executionId, modelId: mid }) - } - /> - ) : resultScheme(url) === 'web' ? ( - - {fname} - - ) : ( - {fname} - )} - - - - {pval ?? '—'} -
        - )} -
        -
        + +
    + + )} + + ) : ( +
    + {totalPages > 1 && !grouped.loading && ( +
    + + + Page {currentPage} of {totalPages} + + +
    + )} + + setFilesFor({ executionId, modelId: mid })} + /> +
    + )} +
  • ); })} @@ -706,3 +711,143 @@ export function MintResults({ ); } + +/** The runs of a model that ran more than once, one row each: its outputs, then what differs. */ +function ResultsTable({ + modelId, + loading, + outputs, + inputs, + params, + executions, + mintConfig, + ensembleManagerApi, + onOpenFolder, +}: { + modelId: string; + loading: boolean; + outputs: ModelOutputFile[]; + inputs: Array<{ id: string; name?: string | null }>; + params: Array<{ id?: string | null; name?: string | null; default?: string | null }>; + executions: Execution[]; + mintConfig: MintResultsProps['mintConfig']; + ensembleManagerApi: string; + onOpenFolder: (executionId: string) => void; +}) { + return ( +
    + {loading ? ( +
    + +
    + ) : ( + + + + {outputs.length > 0 && ( + + )} + {inputs.length > 0 && ( + + )} + {params.length > 0 && ( + + )} + + + {outputs.map((o) => ( + + ))} + {inputs.map((f) => ( + + ))} + {params.map((p) => ( + + ))} + + + + {executions.length === 0 ? ( + + + + ) : ( + executions.map((execution) => ( + + {outputs.map((out) => { + const result = execution.results[out.id]; + if (!result) + return ( + + ); + const url = getResultUrl(result, execution.execution_engine, mintConfig); + const fname = getResultName(result); + return ( + + ); + })} + {inputs.map((inp) => ( + + ))} + {params.map((param) => ( + + ))} + + )) + )} + +
    + Outputs + + Inputs + + Parameters +
    + {humanizeName(o.name)} + + {humanizeName(f.name)} + + {humanizeName(p.name)} +
    + — No results available — +
    + — + + {!url ? ( + {fname || 'No file'} + ) : resultScheme(url) === 'tapis' ? ( + + ) : resultScheme(url) === 'web' ? ( + + {fname} + + ) : ( + {fname} + )} + + + + {runParamValue(param, execution)} +
    + )} +
    + ); +} diff --git a/ui-react/src/pages/modeling/thread/MintRuns.tsx b/ui-react/src/pages/modeling/thread/MintRuns.tsx index 60090704..70c365b1 100644 --- a/ui-react/src/pages/modeling/thread/MintRuns.tsx +++ b/ui-react/src/pages/modeling/thread/MintRuns.tsx @@ -7,8 +7,8 @@ * * Legacy: ui/src/screens/modeling/thread/mint-runs.ts */ -import { ExternalLink, FolderOpen, RefreshCw, X } from 'lucide-react'; -import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; +import { ExternalLink, FolderOpen, RefreshCw, RotateCcw, X } from 'lucide-react'; +import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'; import { Link } from 'react-router-dom'; import { @@ -23,10 +23,12 @@ import { type WorkflowCanvasEdge, type WorkflowCanvasPosition, } from '@/components/modeling/WorkflowCanvas'; -import { RunConfigurationSummary } from '@/components/modeling/runs/RunConfigurationSummary'; +import { CollapsibleCard } from '@/components/common/CollapsibleCard'; import { RunAnswerCard } from '@/components/modeling/runs/RunAnswerCard'; +import { RunFailureNotice } from '@/components/modeling/runs/RunFailureNotice'; import { RunStageTimeline } from '@/components/modeling/runs/RunStageTimeline'; -import { RunStatusSummary } from '@/components/modeling/runs/RunStatusSummary'; +import { SameForEveryRun } from '@/components/modeling/runs/SameForEveryRun'; +import { SettingsUsed } from '@/components/modeling/runs/SettingsUsed'; import { fetchExecutionLog, fetchPlanPublishers, @@ -35,7 +37,22 @@ import { type UnifiedRunSnapshot, } from '@/lib/ensemble-manager'; import { adapterParametersComplete, type ThreadAdapterPlan } from '@/lib/adapter-execution'; -import { aggregateRunStatus, stageStatusFromLegacyState } from '@/lib/modeling/run-status'; +import { + aggregateRunStatus, + displayStatusLabel, + formatDateValue, + normalizeRunStatus, + stageStatusFromLegacyState, + statusPillClasses, + type RunDisplayStatus, +} from '@/lib/modeling/run-status'; +import { + DEFAULT_MAX_MINUTES, + humanizeName, + runDuration, + runParamValue, + splitRunParams, +} from '@/lib/modeling/run-settings'; import { flowErrorMessage, type FlowErrorMessage } from '@/lib/flow-errors'; import { inputResourceCount } from '@/lib/thread-execution'; import { secretErrorMessage, userParameters } from '@/lib/secret-parameters'; @@ -663,6 +680,11 @@ interface UnifiedExecutionPanelProps { refreshError?: string; onCancel?: () => Promise; cancelling?: boolean; + /** Sends the model again after it failed or was cancelled. */ + onRestart?: () => void; + restarting?: boolean; + /** Why the last send was refused, shown beside Restart. */ + restartProblem?: ReactNode; } /** @@ -705,6 +727,9 @@ function UnifiedExecutionPanel({ refreshError, onCancel, cancelling = false, + onRestart, + restarting = false, + restartProblem, }: UnifiedExecutionPanelProps) { const adapterRuns = run.adapter_runs ?? []; const health = runHealth(run); @@ -988,20 +1013,20 @@ function UnifiedExecutionPanel({ - {(run.failure_code || run.error_message) && ( -
    - {run.failure_code &&
    Failure: {run.failure_code}
    } - {run.error_message &&
    {run.error_message}
    } -
    + {(run.failure_code || run.error_message || onRestart) && ( + )} {refreshError && (
    Showing the last saved workflow state. Refresh failed: {refreshError}
    )} -

    - Application logs and files remain available from the run records below. -

    ); } @@ -1049,83 +1074,258 @@ interface MintRunsProps { const PAGE_SIZE = 100; -interface RunParam { - id?: string | null; - name?: string | null; - default?: string | null; -} +// ─── Run card pieces ────────────────────────────────────────────────────────── -function humanizeName(name?: string | null): string { - return (name ?? '').replace(/[-_]/g, ' '); +/** A model's card opens by itself when it needs attention, or when it is the only one. */ +function defaultCardOpen(status: RunDisplayStatus | null, modelCount: number): boolean { + return modelCount === 1 || status !== 'completed'; } -/** The value a run shows for a parameter: its binding, else the default. */ -function runParamValue(param: RunParam, execution: Execution): string { - let value = execution.bindings[param.id ?? ''] as unknown; - if (value == null) value = param.default ?? null; - if (typeof value === 'string' && value.startsWith('__region_geojson')) { - return 'Region GeoJSON'; - } - if (value == null || value === '') return '—'; - return String(value); +/** Why the last send of a model was refused. */ +function SubmitProblems({ + modelId, + refusal, + error, + onOpenFlowRun, +}: { + modelId: string; + refusal?: FlowErrorMessage; + error?: string; + onOpenFlowRun?: (modelId: string, runId: string) => Promise; +}) { + if (!refusal && !error) return null; + return ( + <> + {refusal && ( +
    +

    {refusal.title}

    +
      + {refusal.lines.map((line, index) => ( +
    • {line}
    • + ))} +
    + {refusal.runId && onOpenFlowRun && ( + + )} +
    + )} + {error &&

    {error}

    } + + ); } -/** - * Split parameters into those that tell the listed runs apart (they get a - * column) and those every run shares (they are summarised above the table). - */ -function splitRunParams

    ( - params: P[], - executions: Execution[], -): { varying: P[]; common: Array<{ param: P; value: string }> } { - const varying: P[] = []; - const common: Array<{ param: P; value: string }> = []; - for (const param of params) { - const values = new Set(executions.map((e) => runParamValue(param, e))); - if (values.size > 1) { - varying.push(param); - } else { - const value = executions[0] ? runParamValue(param, executions[0]) : '—'; - if (value !== '—') common.push({ param, value }); - } - } - return { varying, common }; +/** The runs of a model that ran more than once: one row each, with a Restart on a failed row. */ +function RunsTable({ + modelId, + isFlow, + loading, + executions, + inputs, + params, + onViewLog, + onViewFiles, + onRestart, + restarting, +}: { + modelId: string; + isFlow: boolean; + loading: boolean; + executions: Execution[]; + inputs: Array<{ id: string; name?: string | null }>; + params: Array<{ id?: string | null; name?: string | null; default?: string | null }>; + onViewLog: (executionId: string) => void; + onViewFiles: (executionId: string) => void; + /** Present only when the model has ended and the viewer may run it. */ + onRestart?: () => void; + restarting?: boolean; +}) { + const showRestart = Boolean(onRestart) && executions.some((e) => e.status === 'FAILURE'); + const fixedColumns = 5 + (showRestart ? 1 : 0); + return ( +

    + {loading ? ( +
    + +
    + ) : ( + + + + + {inputs.length > 0 && ( + + )} + {params.length > 0 && ( + + )} + + + + + + + + {showRestart && + ))} + {params.map((p) => ( + + ))} + + + + {executions.length === 0 ? ( + + + + ) : ( + executions.map((execution) => ( + + + + + + + {showRestart && ( + + )} + {inputs.length + params.length === 0 && ( + + )} + {inputs.map((input) => { + const res = execution.bindings[input.id] as { + name?: string; + url?: string; + location?: string; + } | null; + const url = res ? getResourceUrl(res) : ''; + return ( + + ); + })} + {params.map((param) => ( + + ))} + + )) + )} + +
    + Run + + Inputs + + Parameters +
    StatusStartEndLogFiles} + {inputs.length + params.length === 0 && } + {inputs.map((f) => ( + + {humanizeName(f.name)} + + {humanizeName(p.name)} +
    + {isFlow ? ( + + No run records yet. Use Reload once the run has started. + + ) : ( +
    + + Loading run records… +
    + )} +
    + + + {toDateTimeString(execution.start_time)} + + {toDateTimeString(execution.end_time)} + + + + + + {execution.status === 'FAILURE' && ( + + )} + No inputs or parameters + {res && url ? ( + + {res.name ?? url} + + ) : ( + '—' + )} + + {runParamValue(param, execution)} +
    + )} +
    + ); } -const SAME_FOR_EVERY_RUN_LIMIT = 6; - -function SameForEveryRun({ - items, +/** One line of counters for a model that ran more than once. */ +function RunCounters({ testId, + total, + successful, + failed, + running, + pending, }: { - items: Array<{ param: RunParam; value: string }>; testId: string; + total: number; + successful: number; + failed: number; + running: number; + pending: number; }) { - const [showAll, setShowAll] = useState(false); - if (items.length === 0) return null; - const truncated = items.length > SAME_FOR_EVERY_RUN_LIMIT && !showAll; - const shown = truncated ? items.slice(0, SAME_FOR_EVERY_RUN_LIMIT) : items; return ( -

    - Same for every run:{' '} - {shown.map(({ param, value }, i) => ( - - {i > 0 && ' · '} - {humanizeName(param.name)} {value} - - ))} - {items.length > SAME_FOR_EVERY_RUN_LIMIT && ( - <> - {' '} - - - )} +

    + + {successful} of {total} completed + + {failed > 0 && · {failed} failed} + {running > 0 && · {running} running} + {pending > 0 && · {pending} waiting}

    ); } @@ -1190,6 +1390,9 @@ export function MintRuns({ const [publishSelections, setPublishSelections] = useState< Record >({}); + // A card the user opened or closed keeps that choice; until then it follows + // its model's state (see `defaultCardOpen`). + const [cardOpen, setCardOpen] = useState>({}); const [logDialogOpen, setLogDialogOpen] = useState(false); const [logContent, setLogContent] = useState(null); const logAbortRef = useRef(null); @@ -1250,7 +1453,7 @@ export function MintRuns({ const handleSubmit = useCallback( async (mid: string) => { - const minutes = Number(maxMinutes[mid] ?? '60'); + const minutes = Number(maxMinutes[mid] ?? String(DEFAULT_MAX_MINUTES)); if (!Number.isInteger(minutes) || minutes < 1) { setRuntimeErrors((errors) => ({ ...errors, @@ -1363,9 +1566,8 @@ export function MintRuns({ )} -

    Runs

    -
      +
        {modelIds.map((mid) => { const summary = threadData.execution_summary[mid]!; const model = threadData.models[mid]; @@ -1401,24 +1603,32 @@ export function MintRuns({ fallbackStatus: workflowRun?.status, }); const isFlowRun = Boolean(model.isFlow) || workflowRun?.adapter_stage === 'flow'; + const isSingleRun = summary.total_runs <= 1; + const ended = displayStatus === 'failed' || displayStatus === 'cancelled'; const nextAction = displayStatus === 'failed' - ? 'Review the failed run and its diagnostics before trying again.' - : displayStatus === 'completed' - ? isFlowRun - ? 'The flow run is complete. Continue to review its results.' - : 'The model run is complete. Continue to review or publish its results.' - : displayStatus === 'paused' - ? 'The flow is paused for your edit. Download the file below, change it, upload your copy and resume.' - : displayStatus === 'completing' - ? isFlowRun - ? 'The flow finished and its outputs are being prepared.' - : 'The model finished and its output is being prepared for the next stage.' - : displayStatus === 'running' + ? canSubmitRuns + ? 'The run failed. Read the reason below, then restart it.' + : 'The run failed. Read the reason below and open its log.' + : displayStatus === 'cancelled' + ? canSubmitRuns + ? 'The run was cancelled. Restart it to run it again.' + : 'The run was cancelled.' + : displayStatus === 'completed' + ? isFlowRun + ? 'The flow run is complete. Continue to review its results.' + : 'The model run is complete. Continue to review or publish its results.' + : displayStatus === 'paused' + ? 'The flow is paused for your edit. Download the file, change it, upload your copy and resume.' + : displayStatus === 'completing' ? isFlowRun - ? 'The flow is running. Results will appear when it completes.' - : 'The model is running. Results will appear when it completes.' - : 'The run is waiting to start.'; + ? 'The flow finished and its outputs are being prepared.' + : 'The model finished and its output is being prepared for the next stage.' + : displayStatus === 'running' + ? isFlowRun + ? 'The flow is running. Results will appear when it completes.' + : 'The model is running. Results will appear when it completes.' + : 'The run is waiting to start.'; // ── count inputs × params for display ────────────────────────── const nParameters = userParameters(model) @@ -1438,379 +1648,323 @@ export function MintRuns({ grouped.executions, ); + // ── the card's header ───────────────────────────────────────── + const startedAt = + latestExecution?.start_time ?? (typeof submitted === 'string' ? submitted : undefined); + const finishedAt = grouped.executions + .map((execution) => execution.end_time) + .filter((time): time is string => Boolean(time)) + .sort() + .at(-1); + const took = + displayStatus === 'completed' || ended ? runDuration(startedAt, finishedAt) : null; + const headerStatus: RunDisplayStatus | null = submitted ? displayStatus : null; + const open = cardOpen[mid] ?? defaultCardOpen(headerStatus, modelIds.length); + + // ── Restart: send this model again, only after it ended ─────── + const restart = + canSubmitRuns && submitted && ended ? () => void handleSubmit(mid) : undefined; + const problems = ( + + ); + const refreshRun = + onRefreshWorkflow && + (Boolean(unifiedRuns?.[mid]) || workflowRun?.run_id?.startsWith('ue_')) + ? async () => { + await onRefreshWorkflow(mid); + onFetchRuns(mid, currentPage, PAGE_SIZE); + } + : undefined; + const cancelRun = + onCancelWorkflow && workflowRun?.run_id?.startsWith('ue_') + ? () => onCancelWorkflow(mid) + : undefined; + // A model run many times with no run of its own record is just its table. + const showPanel = + Boolean(workflowRun) && + (isSingleRun || + isFlowRun || + Boolean(unifiedRuns?.[mid]) || + Boolean(workflowRun?.run_id?.startsWith('ue_'))); + return (
      • - {summary.total_runs > 0 && submitted && ( - - } - /> - )} - - {!summary.total_runs ? ( -
        - 🚨 No runs configured. Please go back to the Data and Parameters steps. -
        - ) : !submitted ? ( -
        -
        {model.name ?? mid}
        -

        - The parameter settings require {summary.total_runs} runs ({nInputs} input - resources × {nParameters} parameters).{' '} - {model.output_files.length * summary.total_runs} output files will be generated. -

        - {!paramsDone ? ( -

        - {adapterPlanError - ? 'SVO adapter plan discovery failed; return to Parameters and retry.' - : adapterPlansLoading - ? 'Waiting for SVO adapter plan discovery to finish.' - : 'Complete the required model and SVO adapter parameters before sending runs.'} + setCardOpen((current) => ({ ...current, [mid]: next }))} + title={model.name ?? mid} + summary={ + <> + {headerStatus ? ( + + {displayStatusLabel(headerStatus)} + + ) : ( + summary.total_runs > 0 && ( + + Not sent yet + + ) + )} + {took ? ( + took {took} + ) : startedAt && submitted ? ( + Started {formatDateValue(startedAt)} + ) : null} + + } + > + {!summary.total_runs ? ( +

        + 🚨 No runs configured. Please go back to the Data and Parameters steps. +
        + ) : !submitted ? ( +
        +

        + The parameter settings require {summary.total_runs} runs ({nInputs} input + resources × {nParameters} parameters).{' '} + {model.output_files.length * summary.total_runs} output files will be + generated.

        - ) : canExecute && canWrite ? ( -
        -
        + {!paramsDone ? ( +

        + {adapterPlanError + ? 'SVO adapter plan discovery failed; return to Parameters and retry.' + : adapterPlansLoading + ? 'Waiting for SVO adapter plan discovery to finish.' + : 'Complete the required model and SVO adapter parameters before sending runs.'} +

        + ) : canExecute && canWrite ? ( +
        +
        + {!model.isFlow && ( + + )} + +
        {!model.isFlow && ( - + + setPublishSelections((current) => ({ ...current, [mid]: selection })) + } + /> )} - + {problems}
        - {!model.isFlow && ( - - setPublishSelections((current) => ({ ...current, [mid]: selection })) - } + ) : ( +

        + You don't have permission to send runs on this sub-task. +

        + )} +
        + ) : ( + <> +

        {nextAction}

        + + {!isSingleRun && ( + + )} + + {showPanel && workflowRun && isFlowRun ? ( + onResumeWorkflow(mid, edit) + : undefined + } + onRestart={restart} + restarting={waiting[mid]} + restartProblem={problems} + /> + ) : showPanel && workflowRun ? ( + + ) : ended ? ( + + ) : null} + + {isSingleRun ? ( +
        + {latestExecution ? ( +
        + + +
        + ) : grouped.loading ? ( + + + Loading run records… + + ) : ( + + No run records yet. Refresh once the run has started. + + )} + - )} - {flowRefusals[mid] && ( -
        -

        {flowRefusals[mid].title}

        -
          - {flowRefusals[mid].lines.map((line, index) => ( -
        • {line}
        • - ))} -
        - {flowRefusals[mid].runId && - (onOpenFlowRun ? ( +
        + ) : ( +
        + {/* Reload, and a pager only when there is more than one page. */} +
        + {totalPages > 1 && ( + <> + + + Page {currentPage} of {totalPages} + - ) : null)} + + )} +
        - )} - {runtimeErrors[mid] && ( -

        {runtimeErrors[mid]}

        - )} -
        - ) : ( -

        - You don't have permission to send runs on this sub-task. -

        - )} -
        - ) : ( -
        - {workflowRun && isFlowRun ? ( - onRefreshWorkflow(mid) - : undefined - } - refreshing={workflowRefreshing?.[mid]} - refreshError={workflowRefreshErrors?.[mid]} - onCancel={ - onCancelWorkflow && workflowRun.run_id?.startsWith('ue_') - ? () => onCancelWorkflow(mid) - : undefined - } - cancelling={workflowCancelling?.[mid]} - ensembleManagerApi={ensembleManagerApi} - username={currentUsername} - onResume={ - onResumeWorkflow && workflowRun.run_id?.startsWith('ue_') - ? (edit) => onResumeWorkflow(mid, edit) - : undefined - } - /> - ) : workflowRun ? ( - onRefreshWorkflow(mid) - : undefined - } - refreshing={workflowRefreshing?.[mid]} - refreshError={workflowRefreshErrors?.[mid]} - onCancel={ - onCancelWorkflow && workflowRun.run_id?.startsWith('ue_') - ? () => onCancelWorkflow(mid) - : undefined - } - cancelling={workflowCancelling?.[mid]} - /> - ) : null} - - {/* Pagination + Reload bar */} -
        - - - Page {currentPage} of {totalPages} - - -
        - -
        -
        - {/* Runs table: paged, so it grows with the step pane instead of - adding a scroll box of its own. */} - -
        - {grouped.loading ? ( -
        - + {/* Runs table: paged, so it grows with the step pane instead of + adding a scroll box of its own. */} + + void handleViewLog(id)} + onViewFiles={(id) => setFilesFor({ executionId: id, modelId: mid })} + onRestart={restart} + restarting={waiting[mid]} + />
        - ) : ( - - - - - {adjustableInputs.length > 0 && ( - - )} - {adjustableParams.length > 0 && ( - - )} - - - - - - - - {adjustableInputs.length + adjustableParams.length === 0 && ( - - ))} - {adjustableParams.map((p) => ( - - ))} - - - - {grouped.executions.length === 0 ? ( - - - - ) : ( - grouped.executions.map((execution: Execution) => { - return ( - - - - - - - {adjustableInputs.length + adjustableParams.length === 0 && ( - - )} - {adjustableInputs.map((input) => { - const res = execution.bindings[input.id ?? ''] as { - name?: string; - url?: string; - location?: string; - } | null; - const url = res ? getResourceUrl(res) : ''; - return ( - - ); - })} - {adjustableParams.map((param) => ( - - ))} - - ); - }) - )} - -
        - Run - - Inputs - - Parameters -
        StatusStartEndLogFiles - )} - {adjustableInputs.map((f) => ( - - {(f.name ?? '').replace(/[-_]/g, ' ')} - - {humanizeName(p.name)} -
        - {model.isFlow ? ( - - No run records yet. Use Reload once the run has started. - - ) : ( -
        - - Loading run records… -
        - )} -
        - - - {toDateTimeString(execution.start_time)} - - {toDateTimeString(execution.end_time)} - - - - - - No inputs or parameters - - {res && url ? ( - - {res.name ?? url} - - ) : ( - '—' - )} - - {runParamValue(param, execution)} -
        )} -
        -
        - )} + + )} +
      • ); })} diff --git a/ui-react/src/pages/modeling/thread/OutputBlock.tsx b/ui-react/src/pages/modeling/thread/OutputBlock.tsx new file mode 100644 index 00000000..06f73d6b --- /dev/null +++ b/ui-react/src/pages/modeling/thread/OutputBlock.tsx @@ -0,0 +1,156 @@ +/** + * OutputBlock — one declared output of a run: its label, type, Download, Copy + * location, and a preview that opens in place. + */ +import { ChevronRight, Copy, Download, FolderOpen } from 'lucide-react'; +import { useState } from 'react'; + +import { previewKind } from '@/lib/result-preview'; +import { FileDownloadButton } from './FileDownloadButton'; +import { ResultPreview } from './ResultPreview'; +import { useTapisResultKind } from './useTapisResultKind'; + +export interface OutputBlockProps { + ensembleManagerApi: string; + executionId: string; + /** What the output is called, as the model declares it. */ + label: string; + /** The declared format, when the model says one. */ + format?: string | null; + /** The file's name. */ + name: string; + /** Where it is: `tapis://`, a web address, or something that is only text. */ + url: string; + scheme: 'tapis' | 'web' | 'text'; + /** Open the run's folder: the answer for a result that is a folder. */ + onOpenFolder: (executionId: string) => void; +} + +function typeLabel(format: string | null | undefined, name: string): string { + if (format) return format; + return /\.([a-z0-9]+)$/i.exec(name)?.[1]?.toUpperCase() ?? ''; +} + +export function OutputBlock({ + ensembleManagerApi, + executionId, + label, + format, + name, + url, + scheme, + onOpenFolder, +}: OutputBlockProps) { + // Asked of Tapis only for a tapis:// location; the others never use it. + const tapisKind = useTapisResultKind(ensembleManagerApi, executionId, url, scheme === 'tapis'); + const kind = previewKind(name); + const previewable = + Boolean(kind) && (scheme === 'web' || (scheme === 'tapis' && tapisKind === 'file')); + const [open, setOpen] = useState(null); + // A report is what the run was for, so it opens by itself; the rest wait to be asked for. + const expanded = open ?? kind === 'markdown'; + + const download = + scheme === 'tapis' && tapisKind === 'file' ? ( + + ) : scheme === 'web' ? ( + + + Download + + ) : null; + + return ( +
      • +
        + {label} + {typeLabel(format, name) && ( + + {typeLabel(format, name)} + + )} + {name} + + {download} + {scheme === 'tapis' && tapisKind === 'folder' && ( + + )} + {scheme === 'tapis' && tapisKind === 'unknown' && ( + … + )} + {scheme === 'tapis' && tapisKind === 'error' && ( + + (location not readable) + + )} + {url && ( + + )} + +
        + {previewable && kind && ( +
        + + {expanded && ( +
        + +
        + )} +
        + )} +
      • + ); +} diff --git a/ui-react/src/pages/modeling/thread/ResultPreview.tsx b/ui-react/src/pages/modeling/thread/ResultPreview.tsx new file mode 100644 index 00000000..5eda8ab8 --- /dev/null +++ b/ui-react/src/pages/modeling/thread/ResultPreview.tsx @@ -0,0 +1,148 @@ +/** + * ResultPreview — the start of one result file, shown inline. + * + * Read only when the block is open (it mounts then): a Markdown report rendered, + * the first rows of a CSV as a small table, JSON indented. A Tapis file is read + * through the same Ensemble Manager route, with the same token, as its Download + * button; a web address is fetched as the link would be. At most the first + * 200 KB is read. If the file cannot be read, the preview says so quietly and + * offers the Download instead. + */ +import { useEffect, useState, type ReactNode } from 'react'; + +import { MarkdownLite } from '@/components/common/MarkdownLite'; +import { downloadExecutionFile, parseTapisUri } from '@/lib/ensemble-manager'; +import { + PREVIEW_CSV_ROWS, + PREVIEW_MAX_BYTES, + parseCsvRows, + prettyJson, + readBlobText, + type PreviewKind, +} from '@/lib/result-preview'; + +type State = + | { status: 'loading' } + | { status: 'error' } + | { status: 'ready'; text: string; truncated: boolean }; + +export interface ResultPreviewProps { + kind: PreviewKind; + ensembleManagerApi: string; + executionId: string; + /** A `tapis://` location, or a web address. */ + url: string; + /** The Download control, repeated beside the fallback message. */ + download?: ReactNode; +} + +async function readResult( + props: Pick, + signal: AbortSignal, +): Promise { + const location = parseTapisUri(props.url); + if (location) { + return ( + await downloadExecutionFile(props.ensembleManagerApi, props.executionId, location, signal) + ).blob; + } + const response = await fetch(props.url, { signal }); + if (!response.ok) throw new Error(`HTTP ${response.status}`); + return response.blob(); +} + +export function ResultPreview({ + kind, + ensembleManagerApi, + executionId, + url, + download, +}: ResultPreviewProps) { + const [state, setState] = useState({ status: 'loading' }); + + useEffect(() => { + const controller = new AbortController(); + setState({ status: 'loading' }); + readResult({ ensembleManagerApi, executionId, url }, controller.signal) + .then((blob) => readBlobText(blob, PREVIEW_MAX_BYTES)) + .then((read) => !controller.signal.aborted && setState({ status: 'ready', ...read })) + .catch(() => !controller.signal.aborted && setState({ status: 'error' })); + return () => controller.abort(); + }, [ensembleManagerApi, executionId, url]); + + if (state.status === 'loading') { + return ( +
        + + Loading preview… +
        + ); + } + if (state.status === 'error') { + return ( +

        + Preview unavailable — {download ?? 'use Download'} +

        + ); + } + + let body: ReactNode; + if (kind === 'markdown') { + body = ; + } else if (kind === 'csv') { + const [head, ...rows] = parseCsvRows(state.text, PREVIEW_CSV_ROWS); + body = head ? ( +
        + + + + {head.map((cell, n) => ( + + ))} + + + + {rows.map((row, r) => ( + + {row.map((cell, n) => ( + + ))} + + ))} + +
        + {cell} +
        + {cell} +
        +
        + ) : ( +

        The file is empty.

        + ); + } else { + body = ( +
        +        {prettyJson(state.text)}
        +      
        + ); + } + + return ( +
        + {body} + {(state.truncated || kind === 'csv') && ( +

        + {kind === 'csv' ? `First ${PREVIEW_CSV_ROWS - 1} rows. ` : ''} + {state.truncated ? 'Only the start of the file is shown. ' : ''} + Download for the whole file. +

        + )} +
        + ); +} diff --git a/ui-react/src/pages/modeling/thread/TapisResult.tsx b/ui-react/src/pages/modeling/thread/TapisResult.tsx index e47b7329..13163ba9 100644 --- a/ui-react/src/pages/modeling/thread/TapisResult.tsx +++ b/ui-react/src/pages/modeling/thread/TapisResult.tsx @@ -7,25 +7,9 @@ * download through the Ensemble Manager, a folder opens the files dialog. */ import { Copy, FolderOpen } from 'lucide-react'; -import { useEffect, useState } from 'react'; -import { fetchExecutionListing, type ExecutionResultLocation } from '@/lib/ensemble-manager'; import { FileDownloadButton } from './FileDownloadButton'; - -// Cells of one run ask for the same listing; share the request while it is in flight. -const inFlight = new Map>(); - -function loadResultKinds(api: string, executionId: string): Promise { - const key = `${api}|${executionId}`; - let pending = inFlight.get(key); - if (!pending) { - pending = fetchExecutionListing(api, executionId) - .then((listing) => listing.results) - .finally(() => inFlight.delete(key)); - inFlight.set(key, pending); - } - return pending; -} +import { useTapisResultKind } from './useTapisResultKind'; export interface TapisResultProps { ensembleManagerApi: string; @@ -42,22 +26,7 @@ export function TapisResult({ url, onOpenFolder, }: TapisResultProps) { - const [kind, setKind] = useState<'file' | 'folder' | 'unknown' | 'error'>('unknown'); - - useEffect(() => { - let cancelled = false; - setKind('unknown'); - loadResultKinds(ensembleManagerApi, executionId) - .then((results) => { - if (cancelled) return; - const match = results.find((result) => result.url === url); - setKind(match ? match.kind : 'error'); - }) - .catch(() => !cancelled && setKind('error')); - return () => { - cancelled = true; - }; - }, [ensembleManagerApi, executionId, url]); + const kind = useTapisResultKind(ensembleManagerApi, executionId, url); return ( diff --git a/ui-react/src/pages/modeling/thread/__tests__/FlowRunPanel.test.tsx b/ui-react/src/pages/modeling/thread/__tests__/FlowRunPanel.test.tsx index de73c91c..b4618148 100644 --- a/ui-react/src/pages/modeling/thread/__tests__/FlowRunPanel.test.tsx +++ b/ui-react/src/pages/modeling/thread/__tests__/FlowRunPanel.test.tsx @@ -2,7 +2,7 @@ * Tests for FlowRunPanel and the flow graph it draws from `workflow_stages`. */ import { describe, expect, it, vi } from 'vitest'; -import { fireEvent, render, screen } from '@testing-library/react'; +import { fireEvent, render, screen, within } from '@testing-library/react'; import type { UnifiedRunSnapshot } from '@/lib/ensemble-manager'; import { FlowRunPanel, flowStageGraph, flowStepState } from '../FlowRunPanel'; @@ -96,14 +96,13 @@ describe('gather stages', () => { }), ...gather.slice(1), ]; - render(); - expect(screen.getByTestId('flow-step-step-gather-1')).toHaveTextContent( + render(); + expect(screen.getByTestId('flow-node-step-gather-1')).toHaveTextContent( 'Gather Elevation files', ); - expect(screen.getByTestId('flow-step-step-gather-1')).toHaveTextContent( - 'file 3 on data.example.org', - ); - expect(screen.getByTestId('flow-step-step-1')).toBeInTheDocument(); + expect(screen.getByTestId('run-step-errors')).toHaveTextContent('Gather Elevation files: '); + expect(screen.getByTestId('run-step-errors')).toHaveTextContent('file 3 on data.example.org'); + expect(screen.getByTestId('flow-node-step-1')).toBeInTheDocument(); }); }); @@ -118,15 +117,18 @@ describe('flowStepState', () => { }); describe('FlowRunPanel', () => { - it('lists every step by name with its status', () => { + it('shows every step once, by name with its status', () => { render(); - const list = screen.getByTestId('flow-step-list'); - expect(list.children).toHaveLength(4); - expect(screen.getByTestId('flow-step-step-1')).toHaveTextContent('Sensemaking: ingest corpus'); - expect(screen.getByTestId('flow-step-step-1')).toHaveTextContent('Completed'); - expect(screen.getByTestId('flow-step-step-2')).toHaveTextContent('Running'); - expect(screen.getByTestId('flow-step-step-3')).toHaveTextContent('Waiting'); + expect(screen.getByTestId('flow-node-step-1')).toHaveTextContent('Sensemaking: ingest corpus'); + expect(screen.getByTestId('flow-node-step-1')).toHaveTextContent('Completed'); + expect(screen.getByTestId('flow-node-step-2')).toHaveTextContent('Running'); + expect(screen.getByTestId('flow-node-step-3')).toHaveTextContent('Waiting'); expect(screen.getByTestId('flow-node-step-4')).toBeInTheDocument(); + // No second, visible list of the same steps: the only list is the task ids + // inside the collapsed Technical details. + expect(screen.getByTestId('flow-technical-details')).toContainElement( + screen.getByTestId('flow-step-list'), + ); expect(screen.queryByText(/run model/i)).not.toBeInTheDocument(); expect(screen.queryByText(/pass inputs to model/i)).not.toBeInTheDocument(); }); @@ -148,7 +150,6 @@ describe('FlowRunPanel', () => { ['step-2', 'Completed'], ['step-3', 'Running'], ] as const) { - expect(screen.getByTestId(`flow-step-${id}`)).toHaveTextContent(word); expect(screen.getByTestId(`flow-node-${id}`)).toHaveTextContent(word); } }); @@ -170,8 +171,7 @@ describe('FlowRunPanel', () => { })} />, ); - expect(screen.getAllByText('Starting the flow').length).toBeGreaterThan(0); - expect(screen.getByTestId('flow-step-list').children).toHaveLength(1); + expect(screen.getAllByText('Starting the flow')).toHaveLength(1); }); it('shows a failed step with its error message', () => { @@ -186,8 +186,8 @@ describe('FlowRunPanel', () => { })} />, ); - expect(screen.getByTestId('flow-step-step-2')).toHaveTextContent('Failed'); - expect(screen.getByTestId('flow-step-step-2')).toHaveTextContent('out of memory'); + expect(screen.getByTestId('flow-node-step-2')).toHaveTextContent('Failed'); + expect(screen.getByTestId('run-step-errors')).toHaveTextContent('Embed: out of memory'); }); it('shows a readable run-level message once', () => { @@ -214,13 +214,47 @@ describe('FlowRunPanel', () => { expect(screen.getByText('boom')).toBeInTheDocument(); }); - it('keeps the Tapis ids under Technical identifiers and each step task id', () => { + it('keeps the Tapis ids and each step task id under a collapsed Technical details', () => { render(); - expect(screen.getByText('wr-1')).toBeInTheDocument(); - expect(screen.getByText('wf-1')).toBeInTheDocument(); + const details = screen.getByTestId('flow-technical-details') as HTMLDetailsElement; + expect(details.open).toBe(false); + expect(within(details).getByText('wr-1')).toBeInTheDocument(); + expect(within(details).getByText('wf-1')).toBeInTheDocument(); expect(screen.getByTestId('flow-step-step-2')).toHaveTextContent('task-step-2'); }); + it('offers Restart on a failed run, disables it while sending, and not on a running one', () => { + const onRestart = vi.fn(); + const failed = flowRun({ status: 'failed', failure_code: 'FLOW_FAILED', error_message: 'x' }); + const { rerender } = render(); + fireEvent.click(screen.getByRole('button', { name: 'Restart' })); + expect(onRestart).toHaveBeenCalledTimes(1); + + rerender(); + expect(screen.getByRole('button', { name: /restarting/i })).toBeDisabled(); + + rerender(); + expect(screen.queryByRole('button', { name: /restart/i })).not.toBeInTheDocument(); + }); + + it('puts the edit controls first for a paused run, before the step diagram', () => { + const paused = flowRun({ + status: 'awaiting_edit', + started_by: 'alice', + model_child_id: 'exec-1', + pause: { + output_key: '1:1', + file: 'draft.json', + file_location: 'tapis://ls6/scratch/alice/draft.json', + paused_after_step: 1, + paused_at: null, + }, + }); + render(); + const panel = screen.getByTestId('flow-run-panel'); + expect(panel.firstElementChild).toBe(screen.getByTestId('flow-paused')); + }); + it('offers cancel while the run is active and not after it ends', () => { const onCancel = vi.fn().mockResolvedValue(undefined); const { rerender } = render(); diff --git a/ui-react/src/pages/modeling/thread/__tests__/MintResults.test.tsx b/ui-react/src/pages/modeling/thread/__tests__/MintResults.test.tsx index ee594d1b..38fd9295 100644 --- a/ui-react/src/pages/modeling/thread/__tests__/MintResults.test.tsx +++ b/ui-react/src/pages/modeling/thread/__tests__/MintResults.test.tsx @@ -111,7 +111,8 @@ describe('MintResults', () => { onFetchRuns={vi.fn()} />, ); - expect(screen.getByText(/Results/)).toBeInTheDocument(); + expect(screen.getByTestId('mint-results')).toBeInTheDocument(); + expect(screen.getByText('HydroModel')).toBeInTheDocument(); }); it('renders the model name', () => { @@ -228,7 +229,7 @@ describe('MintResults', () => { expect(onContinue).toHaveBeenCalledOnce(); }); - it('shows fetch results button when runs are finished', () => { + it('shows the Refresh button when runs are finished', () => { const threadDataFinished: ThreadExecutionData = { ...mockThreadDataSubmitted, execution_summary: { @@ -253,7 +254,7 @@ describe('MintResults', () => { onPublishResults={vi.fn()} />, ); - expect(screen.getByTestId('fetch-results-model-1')).toBeInTheDocument(); + expect(screen.getByTestId('refresh-results-model-1')).toBeInTheDocument(); }); // ── #110: the button used to make no request, and a failure said nothing ── @@ -289,11 +290,11 @@ describe('MintResults', () => { ); } - it('calls onPublishResults when Fetch results is clicked', async () => { + it('calls onPublishResults when Refresh is clicked', async () => { const onPublishResults = vi.fn().mockResolvedValue(undefined); renderFinished(onPublishResults); - fireEvent.click(screen.getByTestId('fetch-results-model-1')); + fireEvent.click(screen.getByTestId('refresh-results-model-1')); await waitFor(() => expect(onPublishResults).toHaveBeenCalledWith('model-1')); }); @@ -308,7 +309,7 @@ describe('MintResults', () => { // The mount effect loads page 1 once; the publish must load it again. await waitFor(() => expect(onFetchRuns).toHaveBeenCalledTimes(1)); - fireEvent.click(screen.getByTestId('fetch-results-model-1')); + fireEvent.click(screen.getByTestId('refresh-results-model-1')); await waitFor(() => expect(onFetchRuns).toHaveBeenCalledTimes(2)); expect(onFetchRuns).toHaveBeenLastCalledWith('model-1', 1, expect.any(Number)); @@ -320,7 +321,7 @@ describe('MintResults', () => { await waitFor(() => expect(onFetchRuns).toHaveBeenCalledTimes(1)); - fireEvent.click(screen.getByTestId('fetch-results-model-1')); + fireEvent.click(screen.getByTestId('refresh-results-model-1')); expect(await screen.findByTestId('publish-error-model-1')).toBeInTheDocument(); expect(onFetchRuns).toHaveBeenCalledTimes(1); @@ -334,7 +335,7 @@ describe('MintResults', () => { ); renderFinished(onPublishResults); - fireEvent.click(screen.getByTestId('fetch-results-model-1')); + fireEvent.click(screen.getByTestId('refresh-results-model-1')); expect(await screen.findByTestId('publish-error-model-1')).toHaveTextContent( 'No executions found to publish', @@ -367,7 +368,7 @@ describe('MintResults', () => { />, ); - fireEvent.click(screen.getByTestId('fetch-results-model-1')); + fireEvent.click(screen.getByTestId('refresh-results-model-1')); expect(await screen.findByTestId('publish-error-model-1')).toHaveTextContent( /declares no output/i, @@ -383,7 +384,7 @@ describe('MintResults', () => { .mockRejectedValue(new EnsembleManagerError(403, 'Ensemble manager returned 403: nope')), ); - fireEvent.click(screen.getByTestId('fetch-results-model-1')); + fireEvent.click(screen.getByTestId('refresh-results-model-1')); expect(await screen.findByTestId('publish-error-model-1')).toHaveTextContent( 'Ensemble manager returned 403: nope', diff --git a/ui-react/src/pages/modeling/thread/__tests__/MintResultsCards.test.tsx b/ui-react/src/pages/modeling/thread/__tests__/MintResultsCards.test.tsx new file mode 100644 index 00000000..f38a5749 --- /dev/null +++ b/ui-react/src/pages/modeling/thread/__tests__/MintResultsCards.test.tsx @@ -0,0 +1,332 @@ +/** + * The Results step's cards: one collapsible card per model, each output as its + * own block with an inline preview, and a plain account of a run that has not + * finished. + */ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { fireEvent, screen, waitFor, within } from '@testing-library/react'; + +import { renderWithProviders } from '@/test/utils/render'; +import { setMintConfig } from '@/test/utils/mint-config'; +import { MintResults } from '../MintResults'; +import type { + Execution, + ExecutionSummary, + ModelExecutionsMap, + ThreadExecutionData, +} from '@/graphql/generated/execution'; +import { EnsembleManagerError, type UnifiedRunSnapshot } from '@/lib/ensemble-manager'; + +// ─── Fixtures ──────────────────────────────────────────────────────────────── + +const REPORT = 'tapis://cloud.data/home/u/out/report.md'; +const TABLE = 'tapis://cloud.data/home/u/out/scores.csv'; +const LEXICON = 'tapis://cloud.data/home/u/out/lexicon.json'; + +const model = { + id: 'm1', + name: 'Sensemaking', + input_parameters: [ + { id: 'p-depth', name: 'flood_depth', type: 'float', default: '10' }, + { id: 'p-mode', name: 'match_mode', type: 'string', default: 'longest' }, + ], + input_files: [{ id: 'in-1', name: 'Documents' }], + output_files: [ + { id: 'o-report', name: 'report', format: 'Markdown' }, + { id: 'o-table', name: 'scores' }, + { id: 'o-lexicon', name: 'lexicon' }, + ], +}; + +function thread(over: Partial = {}): ThreadExecutionData { + return { + id: 'thread-1', + models: { m1: model } as never, + model_ensembles: { + m1: { id: 'ens-1', bindings: { 'p-depth': ['10'], 'p-mode': ['longest'] } }, + }, + execution_summary: { + m1: { + total_runs: 1, + submitted_runs: 1, + successful_runs: 1, + failed_runs: 0, + submitted_for_execution: true, + submission_time: '2024-01-01T00:00:00Z', + ...over, + }, + }, + data: {}, + }; +} + +const run = (id: string, over: Partial = {}): Execution => ({ + id, + modelid: 'm1', + status: 'SUCCESS', + bindings: { 'in-1': { id: 'r1', name: 'a.txt', url: 'https://x/a.txt' }, 'p-mode': 'shortest' }, + results: { + 'o-report': { id: 'o-report', name: 'report.md', url: REPORT }, + 'o-table': { id: 'o-table', name: 'scores.csv', url: TABLE }, + 'o-lexicon': { id: 'o-lexicon', name: 'lexicon.json', url: LEXICON }, + }, + ...over, +}); + +const oneRun: ModelExecutionsMap = { m1: { loading: false, executions: [run('exec-1')] } }; + +const listing = { + ok: true, + status: 200, + json: () => + Promise.resolve({ + files: [], + results: [REPORT, TABLE, LEXICON].map((url) => ({ name: 'x', url, kind: 'file' })), + }), +}; + +const content = (text: string) => ({ + ok: true, + status: 200, + headers: new Headers(), + blob: () => Promise.resolve(new Blob([text])), +}); + +const csv = ['id,score', ...Array.from({ length: 14 }, (_, i) => `row${i + 1},${i}`)].join('\n'); + +function renderResults(props: Partial> = {}) { + return renderWithProviders( + , + ); +} + +let fetchMock: ReturnType; +const contentCalls = () => + fetchMock.mock.calls.filter(([url]) => String(url).includes('/files/content')); + +beforeEach(() => { + setMintConfig({ ENSEMBLE_MANAGER_API: 'http://ensemble' }); + fetchMock = vi.fn(async (url: string) => { + const u = String(url); + if (!u.includes('/files/content')) return listing; + if (u.includes('report.md')) return content('# Findings\n\nThe **corpus** has two themes.\n'); + if (u.includes('scores.csv')) return content(csv); + return content('{"a":{"b":1}}'); + }); + vi.stubGlobal('fetch', fetchMock); +}); +afterEach(() => vi.unstubAllGlobals()); + +// ─── Output blocks and previews ────────────────────────────────────────────── + +describe('a single run with results', () => { + it('shows each output as its own block with label, type, Download and Copy location', async () => { + renderResults(); + const blocks = await screen.findAllByTestId('output-block'); + expect(blocks).toHaveLength(3); + const report = blocks[0]!; + expect(report).toHaveTextContent('report'); + expect(report).toHaveTextContent('Markdown'); + expect(await within(report).findByTestId('download-file')).toBeInTheDocument(); + expect(within(report).getByTestId('copy-location')).toBeInTheDocument(); + expect(blocks[1]).toHaveTextContent('CSV'); + // One table-free block per output, not one column each. + expect(screen.queryByTestId('results-table-m1')).not.toBeInTheDocument(); + }); + + it('renders the Markdown report inline once it is open', async () => { + renderResults(); + expect(await screen.findByRole('heading', { name: 'Findings' })).toBeInTheDocument(); + expect(screen.getByText('corpus').tagName).toBe('STRONG'); + const call = contentCalls()[0]!; + expect(String(call[0])).toContain('path=home%2Fu%2Fout%2Freport.md'); + }); + + it('reads a file only when its block is open, and shows CSV as a small table', async () => { + renderResults(); + await screen.findByRole('heading', { name: 'Findings' }); + // The CSV and JSON blocks are closed: nothing of theirs was fetched yet. + expect(contentCalls().filter(([u]) => String(u).includes('scores.csv'))).toHaveLength(0); + expect(contentCalls().filter(([u]) => String(u).includes('lexicon.json'))).toHaveLength(0); + + const toggles = screen.getAllByTestId('preview-toggle'); + expect(toggles[1]).toHaveAttribute('aria-expanded', 'false'); + fireEvent.click(toggles[1]!); + const table = await screen.findByTestId('preview-csv'); + // Header plus the first rows only, not all fifteen lines. + expect(within(table).getAllByRole('row').length).toBeLessThanOrEqual(10); + expect(within(table).getByText('row1')).toBeInTheDocument(); + expect(within(table).queryByText('row14')).not.toBeInTheDocument(); + expect(toggles[1]).toHaveAttribute('aria-expanded', 'true'); + }); + + it('pretty-prints JSON when it is opened', async () => { + renderResults(); + await screen.findByRole('heading', { name: 'Findings' }); + fireEvent.click(screen.getAllByTestId('preview-toggle')[2]!); + expect(await screen.findByTestId('preview-json')).toHaveTextContent('"b": 1'); + }); + + it('closes a preview again', async () => { + renderResults(); + await screen.findByRole('heading', { name: 'Findings' }); + fireEvent.click(screen.getAllByTestId('preview-toggle')[0]!); + expect(screen.queryByRole('heading', { name: 'Findings' })).not.toBeInTheDocument(); + }); + + it('says the preview is unavailable, with a Download, when the file cannot be read', async () => { + fetchMock.mockImplementation(async (url: string) => + String(url).includes('/files/content') + ? { ok: false, status: 500, json: () => Promise.resolve({ message: 'nope' }) } + : listing, + ); + renderResults(); + const fallback = await screen.findByTestId('preview-unavailable'); + expect(fallback).toHaveTextContent('Preview unavailable'); + expect(within(fallback).getByRole('button', { name: /download/i })).toBeInTheDocument(); + expect(screen.queryByRole('alert')).not.toBeInTheDocument(); + }); + + it('keeps how it was made collapsed, with the inputs and the settings', async () => { + renderResults(); + await screen.findAllByTestId('output-block'); + const how = screen.getByTestId('how-made-m1') as HTMLDetailsElement; + expect(how.open).toBe(false); + expect(within(how).getByRole('link', { name: 'a.txt' })).toBeInTheDocument(); + expect(within(how).getByTestId('results-settings-m1')).toHaveTextContent('match mode'); + }); + + it('has no boilerplate sentences and one refresh control', async () => { + renderResults(); + await screen.findAllByTestId('output-block'); + expect(screen.queryByText(/below are results/i)).not.toBeInTheDocument(); + expect(screen.queryByText(/runs required/i)).not.toBeInTheDocument(); + expect(screen.queryByText(/fetch results/i)).not.toBeInTheDocument(); + expect(screen.queryByRole('button', { name: /reload/i })).not.toBeInTheDocument(); + expect(screen.getAllByRole('button', { name: /refresh/i })).toHaveLength(1); + }); +}); + +// ─── Card ──────────────────────────────────────────────────────────────────── + +describe('the model card', () => { + it('shows the status in the header and collapses on a click', async () => { + renderResults(); + const head = screen.getByRole('button', { name: /sensemaking/i }); + expect(head).toHaveTextContent('Completed'); + expect(head).toHaveAttribute('aria-expanded', 'true'); + await screen.findAllByTestId('output-block'); + fireEvent.click(head); + expect(head).toHaveAttribute('aria-expanded', 'false'); + expect(screen.queryByTestId('output-block')).not.toBeInTheDocument(); + }); +}); + +// ─── Not finished ──────────────────────────────────────────────────────────── + +describe('a run that has not finished', () => { + const unfinished = { + loading: false, + executions: [run('exec-1', { status: 'RUNNING', results: {} })], + }; + + it('says a paused run waits for the user, with a way to the Runs step', () => { + const onOpenRuns = vi.fn(); + renderResults({ + threadData: thread({ successful_runs: 0 }), + executions: { m1: unfinished }, + unifiedRuns: { m1: { run_id: 'ue_1', status: 'awaiting_edit' } }, + onOpenRuns, + }); + expect(screen.getByTestId('result-paused-m1')).toHaveTextContent('Waiting for your edit'); + expect(screen.queryByText(/no results available/i)).not.toBeInTheDocument(); + expect(screen.queryByText(/1 running/i)).not.toBeInTheDocument(); + fireEvent.click(screen.getByTestId('open-runs-m1')); + expect(onOpenRuns).toHaveBeenCalled(); + }); + + it('says Running for a run in progress', () => { + renderResults({ threadData: thread({ successful_runs: 0 }), executions: { m1: unfinished } }); + expect(screen.getByTestId('result-running-m1')).toHaveTextContent('Running'); + expect(screen.queryByTestId('output-block')).not.toBeInTheDocument(); + }); + + const failedThread = thread({ successful_runs: 0, failed_runs: 1 }); + const failedRun: UnifiedRunSnapshot = { + run_id: 'ue_1', + status: 'failed', + failure_code: 'MODEL_FAILED', + error_message: 'job exited with code 2', + }; + + it('gives a failed run its reason and a Restart that sends it and opens the Runs step', async () => { + const onRestartRuns = vi.fn().mockResolvedValue(undefined); + const onOpenRuns = vi.fn(); + renderResults({ + threadData: failedThread, + executions: { m1: unfinished }, + unifiedRuns: { m1: failedRun }, + onRestartRuns, + onOpenRuns, + }); + expect(screen.getByText('job exited with code 2')).toBeInTheDocument(); + fireEvent.click(screen.getByRole('button', { name: 'Restart' })); + await waitFor(() => expect(onRestartRuns).toHaveBeenCalledWith('m1')); + await waitFor(() => expect(onOpenRuns).toHaveBeenCalled()); + }); + + it('disables Restart while it sends and shows a refusal', async () => { + let fail: (error: Error) => void = () => undefined; + const onRestartRuns = vi.fn( + () => + new Promise((_, reject) => { + fail = reject; + }), + ); + renderResults({ + threadData: failedThread, + executions: { m1: unfinished }, + unifiedRuns: { m1: failedRun }, + onRestartRuns, + }); + fireEvent.click(screen.getByRole('button', { name: 'Restart' })); + expect(await screen.findByRole('button', { name: /restarting/i })).toBeDisabled(); + fail(new EnsembleManagerError(500, 'refused')); + expect(await screen.findByTestId('restart-error-m1')).toHaveTextContent('refused'); + expect(screen.getByRole('button', { name: 'Restart' })).toBeEnabled(); + }); +}); + +// ─── Several runs ──────────────────────────────────────────────────────────── + +describe('several runs of one model', () => { + it('keeps one results table, trimmed to the settings that differ', () => { + const sweep = thread({ total_runs: 2, submitted_runs: 2, successful_runs: 2 }); + renderResults({ + threadData: sweep, + executions: { + m1: { + loading: false, + executions: [ + run('exec-1', { bindings: { 'p-depth': '1', 'p-mode': 'x' } }), + run('exec-2', { bindings: { 'p-depth': '2', 'p-mode': 'x' } }), + ], + }, + }, + }); + const table = screen.getByTestId('results-table-m1'); + expect(within(table).getByText('flood depth')).toBeInTheDocument(); + expect(within(table).queryByText('match mode')).not.toBeInTheDocument(); + expect(screen.getByTestId('results-same-m1')).toHaveTextContent('match mode x'); + expect(screen.queryByTestId('output-block')).not.toBeInTheDocument(); + expect(screen.queryByText(/Page \d+ of/)).not.toBeInTheDocument(); + }); +}); diff --git a/ui-react/src/pages/modeling/thread/__tests__/MintRuns.test.tsx b/ui-react/src/pages/modeling/thread/__tests__/MintRuns.test.tsx index af3984d0..ff6fedd3 100644 --- a/ui-react/src/pages/modeling/thread/__tests__/MintRuns.test.tsx +++ b/ui-react/src/pages/modeling/thread/__tests__/MintRuns.test.tsx @@ -856,7 +856,7 @@ describe('MintRuns log fetch authentication', () => { onSubmitRuns={vi.fn()} />, ); - fireEvent.click(screen.getByRole('button', { name: /view log/i })); + fireEvent.click(screen.getByRole('button', { name: /^log$/i })); } function fetchInit(): RequestInit { diff --git a/ui-react/src/pages/modeling/thread/__tests__/MintRunsCards.test.tsx b/ui-react/src/pages/modeling/thread/__tests__/MintRunsCards.test.tsx new file mode 100644 index 00000000..01dbcdc1 --- /dev/null +++ b/ui-react/src/pages/modeling/thread/__tests__/MintRunsCards.test.tsx @@ -0,0 +1,498 @@ +/** + * The Runs step's cards: one collapsible card per model, steps shown once, a + * single run without the ensemble furniture, and Restart for a run that failed. + */ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { fireEvent, screen, waitFor, within } from '@testing-library/react'; + +import { renderWithProviders } from '@/test/utils/render'; +import { MintRuns } from '../MintRuns'; +import type { + Execution, + ExecutionSummary, + ModelExecutionsMap, + ThreadExecutionData, +} from '@/graphql/generated/execution'; +import { EnsembleManagerError, type UnifiedRunSnapshot } from '@/lib/ensemble-manager'; + +// ─── Fixtures ──────────────────────────────────────────────────────────────── + +const params = [ + { id: 'p-depth', name: 'flood_depth', type: 'float', default: '10' }, + { id: 'p-mode', name: 'match_mode', type: 'string', default: 'longest' }, +]; + +function model(id: string, extra: Record = {}) { + return { + id, + name: `Model ${id}`, + input_parameters: params, + input_files: [], + output_files: [{ id: `${id}-out`, name: 'report' }], + ...extra, + }; +} + +function summary(over: Partial = {}): ExecutionSummary { + return { + total_runs: 1, + submitted_runs: 1, + successful_runs: 1, + failed_runs: 0, + submitted_for_execution: true, + submission_time: '2024-01-01T00:00:00Z', + ...over, + }; +} + +function thread( + models: Array<{ + id: string; + model?: Record; + summary?: Partial; + }>, +): ThreadExecutionData { + return { + id: 'thread-1', + models: Object.fromEntries(models.map((m) => [m.id, model(m.id, m.model)])) as never, + model_ensembles: Object.fromEntries( + models.map((m) => [ + m.id, + { id: `ens-${m.id}`, bindings: { 'p-depth': ['10'], 'p-mode': ['longest'] } }, + ]), + ), + execution_summary: Object.fromEntries(models.map((m) => [m.id, summary(m.summary)])), + data: {}, + }; +} + +const execution = (id: string, modelId: string, over: Partial = {}): Execution => ({ + id, + modelid: modelId, + status: 'SUCCESS', + run_progress: 1, + start_time: '2024-01-01T00:00:00Z', + end_time: '2024-01-01T00:04:00Z', + bindings: {}, + results: {}, + ...over, +}); + +const stages = [ + { + stage_id: 'step-1', + type: 'flow_step', + name: 'Ingest corpus', + depends_on: [], + status: 'completed', + provider: 'tapis-workflows', + provider_ids: { task_id: 'step-1-etl_process' }, + }, + { + stage_id: 'step-2', + type: 'flow_step', + name: 'Embed', + depends_on: ['step-1'], + status: 'running', + provider: 'tapis-workflows', + provider_ids: { task_id: 'step-2-etl_process' }, + }, +]; + +const flowRun = (over: Partial = {}): UnifiedRunSnapshot => ({ + run_id: 'ue_flow-1', + status: 'adapter_running', + adapter_stage: 'flow', + execution_mode: 'workflow_pipeline', + tapis_workflow: { + provider: 'tapis-workflows', + workflow_id: 'wf-1', + run_id: 'wr-1', + stage_count: 2, + }, + workflow_stages: stages, + ...over, +}); + +function renderRuns(props: Partial> = {}) { + return renderWithProviders( + , + ); +} + +const header = (name: RegExp | string) => screen.getByRole('button', { name }); + +beforeEach(() => { + vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ ok: true, json: () => Promise.resolve({}) })); +}); +afterEach(() => vi.unstubAllGlobals()); + +// ─── A single run ──────────────────────────────────────────────────────────── + +describe('a single run', () => { + const flowThread = thread([ + { + id: 'flow-1', + model: { isFlow: true, input_parameters: [] }, + summary: { successful_runs: 0 }, + }, + ]); + const flowExecutions: ModelExecutionsMap = { + 'flow-1': { + loading: false, + executions: [execution('exec-1', 'flow-1', { status: 'RUNNING' })], + }, + }; + + it('has no counters, run configuration box, pager or run table, and has Log and Files', () => { + renderRuns({ + threadData: flowThread, + executions: flowExecutions, + unifiedRuns: { 'flow-1': flowRun() }, + }); + expect(screen.queryByTestId('run-counters-flow-1')).not.toBeInTheDocument(); + expect(screen.queryByText(/run configuration/i)).not.toBeInTheDocument(); + expect(screen.queryByText(/Page \d+ of/)).not.toBeInTheDocument(); + expect(screen.queryByRole('button', { name: 'Back' })).not.toBeInTheDocument(); + expect(screen.queryByTestId('runs-table-flow-1')).not.toBeInTheDocument(); + expect(screen.queryByText(/technical identifiers/i)).not.toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Log' })).toBeInTheDocument(); + expect(screen.getByTestId('view-files-exec-1')).toBeInTheDocument(); + }); + + it('shows each step once and keeps task ids under a collapsed Technical details', () => { + renderRuns({ + threadData: flowThread, + executions: flowExecutions, + unifiedRuns: { 'flow-1': flowRun() }, + }); + expect(screen.getAllByTestId(/^flow-node-/)).toHaveLength(2); + const details = screen.getByTestId('flow-technical-details') as HTMLDetailsElement; + expect(details.open).toBe(false); + expect(within(details).getByText('step-2-etl_process')).toBeInTheDocument(); + expect(screen.queryByText(/^Task step-2/)).not.toBeInTheDocument(); + }); + + it('puts the log and files buttons on the card and opens the log', async () => { + (globalThis.fetch as ReturnType).mockResolvedValue({ + ok: true, + text: () => Promise.resolve('log line'), + }); + renderRuns({ + threadData: flowThread, + executions: flowExecutions, + unifiedRuns: { 'flow-1': flowRun() }, + }); + fireEvent.click(screen.getByRole('button', { name: 'Log' })); + expect(await screen.findByRole('dialog', { name: 'Run log' })).toBeInTheDocument(); + await waitFor(() => expect(screen.getByText('log line')).toBeInTheDocument()); + }); + + it('lists the settings used collapsed, those changed from default first', () => { + renderRuns({ + threadData: thread([{ id: 'm1' }]), + executions: { + m1: { + loading: false, + executions: [execution('exec-1', 'm1', { bindings: { 'p-mode': 'shortest' } })], + }, + }, + }); + const used = screen.getByTestId('settings-used-m1') as HTMLDetailsElement; + expect(used.open).toBe(false); + expect(used).toHaveTextContent('1 changed from default'); + const terms = within(used) + .getAllByRole('term') + .map((t) => t.textContent); + expect(terms[0]).toContain('match mode'); + expect(terms[1]).toContain('flood depth'); + }); +}); + +// ─── Several runs ──────────────────────────────────────────────────────────── + +describe('several runs of one model', () => { + const sweep = thread([ + { + id: 'm1', + summary: { total_runs: 3, submitted_runs: 3, successful_runs: 2, failed_runs: 0 }, + }, + ]); + const rows = (...statuses: string[]): ModelExecutionsMap => ({ + m1: { + loading: false, + executions: statuses.map((status, i) => + execution(`exec-${i + 1}`, 'm1', { status, bindings: { 'p-depth': String(i) } }), + ), + }, + }); + + it('shows compact counters and the table, and no pager for one page', () => { + renderRuns({ threadData: sweep, executions: rows('SUCCESS', 'SUCCESS', 'RUNNING') }); + expect(screen.getByTestId('run-counters-m1')).toHaveTextContent('2 of 3 completed'); + expect(screen.getByTestId('run-counters-m1')).toHaveTextContent('1 running'); + expect(screen.getByTestId('runs-table-m1')).toBeInTheDocument(); + expect(screen.queryByText(/Page \d+ of/)).not.toBeInTheDocument(); + expect(screen.queryByTestId('single-run-m1')).not.toBeInTheDocument(); + expect(screen.queryByText(/run configuration/i)).not.toBeInTheDocument(); + // The table still trims: only what differs between runs is a column. + const table = screen.getByTestId('runs-table-m1'); + expect(within(table).getByText('flood depth')).toBeInTheDocument(); + expect(within(table).queryByText('match mode')).not.toBeInTheDocument(); + expect(screen.getByTestId('same-for-every-run-m1')).toHaveTextContent('match mode longest'); + }); + + it('shows a pager only when there is more than one page', () => { + renderRuns({ + threadData: thread([ + { id: 'm1', summary: { total_runs: 250, submitted_runs: 250, successful_runs: 0 } }, + ]), + executions: rows('RUNNING', 'RUNNING'), + }); + expect(screen.getByText('Page 1 of 3')).toBeInTheDocument(); + }); +}); + +// ─── Cards: collapse, defaults ─────────────────────────────────────────────── + +describe('collapsible model cards', () => { + const several = thread([ + { id: 'done', summary: { successful_runs: 1 } }, + { id: 'busy', summary: { successful_runs: 0 } }, + { id: 'broke', summary: { successful_runs: 0, failed_runs: 1 } }, + ]); + const execs: ModelExecutionsMap = { + done: { loading: false, executions: [execution('e-done', 'done')] }, + busy: { loading: false, executions: [execution('e-busy', 'busy', { status: 'RUNNING' })] }, + broke: { loading: false, executions: [execution('e-broke', 'broke', { status: 'FAILURE' })] }, + }; + + it('opens the ones that need attention and closes a completed one when there are several', () => { + renderRuns({ threadData: several, executions: execs }); + expect(header(/Model done/)).toHaveAttribute('aria-expanded', 'false'); + expect(header(/Model busy/)).toHaveAttribute('aria-expanded', 'true'); + expect(header(/Model broke/)).toHaveAttribute('aria-expanded', 'true'); + expect(screen.queryByTestId('view-files-e-done')).not.toBeInTheDocument(); + expect(screen.getByTestId('view-files-e-busy')).toBeInTheDocument(); + }); + + it('opens a completed model when it is the only one', () => { + renderRuns({ + threadData: thread([{ id: 'done', summary: { successful_runs: 1 } }]), + executions: { done: execs.done! }, + }); + expect(header(/Model done/)).toHaveAttribute('aria-expanded', 'true'); + }); + + it('toggles on a click, hides the content, and remembers the choice', () => { + const view = renderRuns({ threadData: several, executions: execs }); + fireEvent.click(header(/Model done/)); + expect(header(/Model done/)).toHaveAttribute('aria-expanded', 'true'); + expect(screen.getByTestId('view-files-e-done')).toBeInTheDocument(); + + fireEvent.click(header(/Model busy/)); + expect(header(/Model busy/)).toHaveAttribute('aria-expanded', 'false'); + expect(screen.queryByTestId('view-files-e-busy')).not.toBeInTheDocument(); + + // A re-render with the same data keeps what the user chose. + view.rerender( + , + ); + expect(header(/Model done/)).toHaveAttribute('aria-expanded', 'true'); + expect(header(/Model busy/)).toHaveAttribute('aria-expanded', 'false'); + }); + + it('shows the status and the time it took in the header', () => { + renderRuns({ threadData: several, executions: execs }); + expect(header(/Model done/)).toHaveTextContent('Completed'); + expect(header(/Model done/)).toHaveTextContent('took 4 min'); + expect(header(/Model busy/)).toHaveTextContent('Running'); + expect(header(/Model busy/)).toHaveTextContent('Started'); + }); +}); + +// ─── Paused ────────────────────────────────────────────────────────────────── + +describe('a run paused for an edit', () => { + it('shows the edit controls directly under the sentence, before the steps', () => { + const paused = flowRun({ + status: 'awaiting_edit', + started_by: 'alice', + model_child_id: 'exec-1', + pause: { + output_key: '1:1', + file: 'lexicon.json', + file_location: 'tapis://ls6/scratch/alice/lexicon.json', + paused_after_step: 1, + paused_at: null, + }, + }); + renderRuns({ + threadData: thread([ + { id: 'flow-1', model: { isFlow: true }, summary: { successful_runs: 0 } }, + ]), + executions: { + 'flow-1': { + loading: false, + executions: [execution('exec-1', 'flow-1', { status: 'RUNNING' })], + }, + }, + unifiedRuns: { 'flow-1': paused }, + currentUsername: 'alice', + onResumeWorkflow: vi.fn(), + }); + const panel = screen.getByTestId('flow-run-panel'); + expect(panel.firstElementChild).toBe(screen.getByTestId('flow-paused')); + expect(screen.getByRole('button', { name: 'Upload the edited file' })).toBeInTheDocument(); + expect(screen.getByTestId('resume-flow')).toBeInTheDocument(); + expect(header(/Model flow-1/)).toHaveAttribute('aria-expanded', 'true'); + }); +}); + +// ─── Restart ───────────────────────────────────────────────────────────────── + +describe('restarting a failed run', () => { + const failedThread = thread([ + { id: 'm1', summary: { successful_runs: 0, failed_runs: 1 } }, + { id: 'm2', summary: { successful_runs: 1 } }, + ]); + const failedRows: ModelExecutionsMap = { + m1: { loading: false, executions: [execution('exec-1', 'm1', { status: 'FAILURE' })] }, + m2: { loading: false, executions: [execution('exec-2', 'm2')] }, + }; + const failure = (over: Partial = {}): UnifiedRunSnapshot => ({ + run_id: 'ue_m1', + status: 'failed', + execution_mode: 'workflow_pipeline', + failure_code: 'MODEL_FAILED', + error_message: 'job exited with code 2', + ...over, + }); + + it('shows the reason and a Restart button on the failed model only', () => { + renderRuns({ + threadData: failedThread, + executions: failedRows, + unifiedRuns: { m1: failure() }, + }); + expect(screen.getByText('Failure: MODEL_FAILED')).toBeInTheDocument(); + expect(screen.getByText('job exited with code 2')).toBeInTheDocument(); + expect(screen.getAllByRole('button', { name: 'Restart' })).toHaveLength(1); + }); + + it('sends that model again, and only that model', async () => { + const onSubmitRuns = vi.fn().mockResolvedValue(undefined); + renderRuns({ + threadData: failedThread, + executions: failedRows, + unifiedRuns: { m1: failure() }, + onSubmitRuns, + }); + fireEvent.click(screen.getByRole('button', { name: 'Restart' })); + await waitFor(() => expect(onSubmitRuns).toHaveBeenCalledTimes(1)); + expect(onSubmitRuns).toHaveBeenCalledWith('m1', 60); + }); + + it('disables Restart while the send is in flight, so it cannot start twice', async () => { + let finish: () => void = () => undefined; + const onSubmitRuns = vi.fn( + () => + new Promise((resolve) => { + finish = resolve; + }), + ); + renderRuns({ + threadData: failedThread, + executions: failedRows, + unifiedRuns: { m1: failure() }, + onSubmitRuns, + }); + fireEvent.click(screen.getByRole('button', { name: 'Restart' })); + const pending = await screen.findByRole('button', { name: /restarting/i }); + expect(pending).toBeDisabled(); + fireEvent.click(pending); + expect(onSubmitRuns).toHaveBeenCalledTimes(1); + finish(); + await waitFor(() => expect(screen.getByRole('button', { name: 'Restart' })).toBeEnabled()); + }); + + it('shows why a restart was refused', async () => { + renderRuns({ + threadData: failedThread, + executions: failedRows, + unifiedRuns: { m1: failure() }, + onSubmitRuns: vi.fn().mockRejectedValue(new EnsembleManagerError(500, 'boom')), + }); + fireEvent.click(screen.getByRole('button', { name: 'Restart' })); + expect(await screen.findByText('boom')).toBeInTheDocument(); + }); + + it('restarts a failed flow too, and not while it is running or without permission', () => { + const flowThread = thread([ + { id: 'flow-1', model: { isFlow: true }, summary: { successful_runs: 0, failed_runs: 1 } }, + ]); + const flowFailed = flowRun({ status: 'failed', failure_code: 'FLOW_FAILED' }); + const view = renderRuns({ threadData: flowThread, unifiedRuns: { 'flow-1': flowFailed } }); + expect(screen.getByRole('button', { name: 'Restart' })).toBeInTheDocument(); + view.unmount(); + + renderRuns({ threadData: flowThread, unifiedRuns: { 'flow-1': flowFailed }, canWrite: false }); + expect(screen.queryByRole('button', { name: 'Restart' })).not.toBeInTheDocument(); + }); + + it('offers no Restart on a run that is still running', () => { + renderRuns({ + threadData: thread([{ id: 'm1', summary: { successful_runs: 0 } }]), + executions: { + m1: { loading: false, executions: [execution('exec-1', 'm1', { status: 'RUNNING' })] }, + }, + }); + expect(screen.queryByRole('button', { name: /restart/i })).not.toBeInTheDocument(); + }); + + it('offers Restart on each failed row of an ensemble, all calling the same send', async () => { + const onSubmitRuns = vi.fn().mockResolvedValue(undefined); + renderRuns({ + threadData: thread([ + { + id: 'm1', + summary: { total_runs: 3, submitted_runs: 3, successful_runs: 1, failed_runs: 2 }, + }, + ]), + executions: { + m1: { + loading: false, + executions: [ + execution('exec-1', 'm1', { status: 'FAILURE', bindings: { 'p-depth': '1' } }), + execution('exec-2', 'm1', { status: 'SUCCESS', bindings: { 'p-depth': '2' } }), + execution('exec-3', 'm1', { status: 'FAILURE', bindings: { 'p-depth': '3' } }), + ], + }, + }, + onSubmitRuns, + }); + expect(screen.getByTestId('restart-run-exec-1')).toBeInTheDocument(); + expect(screen.queryByTestId('restart-run-exec-2')).not.toBeInTheDocument(); + fireEvent.click(screen.getByTestId('restart-run-exec-3')); + await waitFor(() => expect(onSubmitRuns).toHaveBeenCalledWith('m1', 60)); + }); +}); diff --git a/ui-react/src/pages/modeling/thread/__tests__/MintRunsFlow.test.tsx b/ui-react/src/pages/modeling/thread/__tests__/MintRunsFlow.test.tsx index 2c37ccb3..f2e87426 100644 --- a/ui-react/src/pages/modeling/thread/__tests__/MintRunsFlow.test.tsx +++ b/ui-react/src/pages/modeling/thread/__tests__/MintRunsFlow.test.tsx @@ -103,8 +103,8 @@ describe('MintRuns for a flow', () => { renderRuns(); expect(screen.getByTestId('flow-run-panel')).toBeInTheDocument(); expect(screen.queryByTestId('unified-execution-panel')).not.toBeInTheDocument(); - expect(screen.getByTestId('flow-step-step-1')).toHaveTextContent('Ingest corpus'); - expect(screen.getByTestId('flow-step-step-2')).toHaveTextContent('Running'); + expect(screen.getByTestId('flow-node-step-1')).toHaveTextContent('Ingest corpus'); + expect(screen.getByTestId('flow-node-step-2')).toHaveTextContent('Running'); expect(screen.queryByText(/run model/i)).not.toBeInTheDocument(); expect(screen.queryByText(/pass inputs to model/i)).not.toBeInTheDocument(); expect(screen.queryByText(/the model is running/i)).not.toBeInTheDocument(); @@ -201,7 +201,7 @@ describe('MintRuns for a flow', () => { expect(screen.getByText('Waiting for your edit')).toBeInTheDocument(); expect( screen.getByText( - 'The flow is paused for your edit. Download the file below, change it, upload your copy and resume.', + 'The flow is paused for your edit. Download the file, change it, upload your copy and resume.', ), ).toBeInTheDocument(); expect(screen.queryByText(/the flow is running/i)).not.toBeInTheDocument(); diff --git a/ui-react/src/pages/modeling/thread/__tests__/MintThread.test.tsx b/ui-react/src/pages/modeling/thread/__tests__/MintThread.test.tsx index 23e812f5..1dc8c918 100644 --- a/ui-react/src/pages/modeling/thread/__tests__/MintThread.test.tsx +++ b/ui-react/src/pages/modeling/thread/__tests__/MintThread.test.tsx @@ -194,7 +194,7 @@ const executionMock = { /** * The same thread once its runs have finished, which is the only state that - * renders the Results step's Fetch results button. + * renders the Results step's Refresh button. */ const executionFinishedMock = { request: { query: GetThreadExecutionDocument, variables: { id: 'test-thread-id' } }, @@ -396,7 +396,7 @@ describe('MintThread', () => { }); }); - it('wires Fetch results to the ensemble manager', async () => { + it('wires Refresh to the ensemble manager', async () => { // The regression this guards: MintThread rendered MintResults without // onPublishResults, and MintResults returns on its first line when that // prop is absent — so the button made no request at all (#110). Asserting @@ -412,7 +412,7 @@ describe('MintThread', () => { await waitFor(() => expect(resultsStep).not.toBeDisabled(), { timeout: 3000 }); resultsStep.click(); - const button = await screen.findByTestId('fetch-results-cfgA'); + const button = await screen.findByTestId('refresh-results-cfgA'); button.click(); await waitFor(() => diff --git a/ui-react/src/pages/modeling/thread/__tests__/PausedFlowStep.test.tsx b/ui-react/src/pages/modeling/thread/__tests__/PausedFlowStep.test.tsx index ca20a54a..4a70536d 100644 --- a/ui-react/src/pages/modeling/thread/__tests__/PausedFlowStep.test.tsx +++ b/ui-react/src/pages/modeling/thread/__tests__/PausedFlowStep.test.tsx @@ -254,7 +254,7 @@ describe('FlowRunPanel for a paused run', () => { />, ); expect(screen.getByTestId('flow-paused')).toHaveTextContent('Paused after “Draft the lexicon”'); - expect(screen.getByTestId('flow-step-step-2')).toHaveTextContent('Waiting'); + expect(screen.getByTestId('flow-node-step-2')).toHaveTextContent('Waiting'); await user.click(screen.getByTestId('cancel-workflow')); expect(screen.getByText(/It stops here and cannot be continued/)).toBeInTheDocument(); await user.click(screen.getByTestId('confirm-cancel-workflow')); diff --git a/ui-react/src/pages/modeling/thread/useTapisResultKind.ts b/ui-react/src/pages/modeling/thread/useTapisResultKind.ts new file mode 100644 index 00000000..fc046431 --- /dev/null +++ b/ui-react/src/pages/modeling/thread/useTapisResultKind.ts @@ -0,0 +1,54 @@ +/** + * useTapisResultKind — whether Tapis says a result location is a file or a folder. + * + * The Ensemble Manager lists a run with each result marked by Tapis; the name of + * the location is never used to guess. + */ +import { useEffect, useState } from 'react'; + +import { fetchExecutionListing, type ExecutionResultLocation } from '@/lib/ensemble-manager'; + +// Cells of one run ask for the same listing; share the request while it is in flight. +const inFlight = new Map>(); + +function loadResultKinds(api: string, executionId: string): Promise { + const key = `${api}|${executionId}`; + let pending = inFlight.get(key); + if (!pending) { + pending = fetchExecutionListing(api, executionId) + .then((listing) => listing.results) + .finally(() => inFlight.delete(key)); + inFlight.set(key, pending); + } + return pending; +} + +export type TapisResultKind = 'file' | 'folder' | 'unknown' | 'error'; + +/** Whether Tapis says a result location is a file or a folder (the name is never used to guess). */ +export function useTapisResultKind( + ensembleManagerApi: string, + executionId: string, + url: string, + enabled = true, +): TapisResultKind { + const [kind, setKind] = useState('unknown'); + + useEffect(() => { + if (!enabled) return; + let cancelled = false; + setKind('unknown'); + loadResultKinds(ensembleManagerApi, executionId) + .then((results) => { + if (cancelled) return; + const match = results.find((result) => result.url === url); + setKind(match ? match.kind : 'error'); + }) + .catch(() => !cancelled && setKind('error')); + return () => { + cancelled = true; + }; + }, [ensembleManagerApi, executionId, url, enabled]); + + return kind; +} diff --git a/ui-react/tailwind.config.ts b/ui-react/tailwind.config.ts index 0139c9e3..e88c8423 100644 --- a/ui-react/tailwind.config.ts +++ b/ui-react/tailwind.config.ts @@ -55,10 +55,20 @@ const config: Config = { from: { height: 'var(--radix-accordion-content-height)' }, to: { height: '0' }, }, + 'card-down': { + from: { height: '0', opacity: '0' }, + to: { height: 'var(--radix-accordion-content-height)', opacity: '1' }, + }, + 'card-up': { + from: { height: 'var(--radix-accordion-content-height)', opacity: '1' }, + to: { height: '0', opacity: '0' }, + }, }, animation: { 'accordion-down': 'accordion-down 0.2s ease-out', 'accordion-up': 'accordion-up 0.2s ease-out', + 'card-down': 'card-down 0.2s ease-out', + 'card-up': 'card-up 0.2s ease-out', }, borderRadius: { lg: 'var(--radius)', From 9ab02635e703cf62351cfea8a442a6c335e45afa Mon Sep 17 00:00:00 2001 From: Will Mobley Date: Fri, 20 Nov 2026 16:28:22 -0600 Subject: [PATCH 6/7] Give every adapter-backed plan its own plan id, with a test per plan kind A plan id is the encoded plan, and submitting an id that already has a record returns that record. Pre-model steps, post-model plans and flow plans now all carry a nonce, so planning again after a failed run is a new run even if the adapter returns the same plan id, while submitting one plan twice still returns one run. Tests plan, fail, re-plan and submit for each kind (pre-model, post- model, flow, plain job) with an adapter that repeats its ids, and check the plan id size limit with the nonce. --- .../services/unifiedExecutionRestart.test.ts | 332 ++++++++++++++++++ .../services/unifiedExecutionService.ts | 19 +- 2 files changed, 345 insertions(+), 6 deletions(-) create mode 100644 mint-ensemble-manager/src/api/api-v1/services/unifiedExecutionRestart.test.ts diff --git a/mint-ensemble-manager/src/api/api-v1/services/unifiedExecutionRestart.test.ts b/mint-ensemble-manager/src/api/api-v1/services/unifiedExecutionRestart.test.ts new file mode 100644 index 00000000..5b095774 --- /dev/null +++ b/mint-ensemble-manager/src/api/api-v1/services/unifiedExecutionRestart.test.ts @@ -0,0 +1,332 @@ +/** + * Running a model again after a failed run: for each kind of plan, planning + * again after the failed run gives a new plan id and so a new run record, while + * submitting one plan twice still returns its one run. The adapter is made to + * answer with the same ids every time, so a new run never depends on it varying. + */ +import { createUnifiedExecutionService, ParentRunResponse } from "./unifiedExecutionService"; +import { + UnifiedExecutionRecord, + UnifiedExecutionStep, + UnifiedExecutionStore +} from "./unifiedExecutionStore"; +import { FlowThreadContext } from "./flowExecution"; + +jest.mock("@/classes/graphql/graphql_functions_v2", () => ({ + getThread: jest.fn().mockResolvedValue({ id: "thread-1" }) +})); + +jest.mock("@/classes/mint/mint-functions", () => ({ + getConfiguration: jest.fn().mockReturnValue({ + execution_engine: "tapis", + svo_adapter_api: "http://adapter.local", + unified_plan_secret: "test-secret" + }) +})); + +const AUTH = "Bearer user-token"; +type LegacyServices = Parameters[0]; +const asParent = (response: unknown) => response as ParentRunResponse; + +describe("running a model again after a failed run", () => { + const legacy = { + local: { submitExecution: jest.fn() }, + wings: { submitExecution: jest.fn() }, + tapis: { + submitExecution: jest.fn(), + buildCompositeWorkflowModelTask: jest.fn(), + compositeModelContext: jest.fn(), + getExecution: jest.fn(), + getJobStatus: jest.fn(), + updateCompositeWorkflowExecution: jest.fn() + } + }; + const flows = { + flowContext: jest.fn(), + startFlowExecution: jest.fn(), + recordFlowEdit: jest.fn(), + finishFlowExecution: jest.fn() + }; + let records: Map; + let fetchMock: jest.Mock; + let planCalls: number; + + function store(): UnifiedExecutionStore { + const steps = new Map(); + return { + async getByPlanId(planId) { + return [...records.values()].find((r) => r.plan_id === planId) || null; + }, + async getById(id) { + return records.get(id) || null; + }, + async listByThread(threadId, modelId) { + return [...records.values()].filter( + (r) => r.thread_id === threadId && r.model_id === modelId + ); + }, + async listSteps(executionId) { + return [...steps.values()].filter((s) => s.execution_id === executionId); + }, + async upsertStep(input) { + const step = { id: `step-${input.step_key}`, ...input } as UnifiedExecutionStep; + steps.set(step.step_key, step); + return step; + }, + async insert(input) { + const record = { + id: `parent-${records.size + 1}`, + ...input + } as UnifiedExecutionRecord; + records.set(record.id, record); + return record; + }, + async update(id, set) { + const record = records.get(id); + if (!record) return null; + Object.assign(record, set); + return record; + }, + async compareAndSet(id, _expected, set) { + const record = records.get(id); + if (!record) return null; + Object.assign(record, set); + return record; + } + } as UnifiedExecutionStore; + } + + const submitsToAdapter = () => + fetchMock.mock.calls.filter(([url]) => String(url).endsWith("/workflows/submit")).length; + + /** Fail the run that exists, as a finished run that did not succeed. */ + function failAll() { + for (const record of records.values()) { + Object.assign(record, { + status: "failed", + failure_code: "MODEL_FAILED", + error_message: "job failed" + }); + } + } + + beforeEach(() => { + jest.clearAllMocks(); + records = new Map(); + planCalls = 0; + fetchMock = jest.fn(async (url: string, init?: { method?: string }) => { + const path = String(url).replace("http://adapter.local", ""); + const ok = (body: unknown) => ({ ok: true, status: 200, json: async () => body }); + if (path.startsWith("/workflows/submit")) { + return ok({ + run_id: "adapter-run-1", + status: "running", + tapis_workflow_id: "wf-1", + tapis_run_id: "tr-1" + }); + } + if (path.startsWith("/plans/flow")) { + planCalls += 1; + // The same adapter plan id every time: it never varies. + return ok({ + plan_id: "adapter-plan-1", + plan_json: { steps: [{ step: 1, name: "ingest", depends_on: [] }] } + }); + } + if (path.startsWith("/plans")) { + // A POST plans; a GET of /plans/ reads the stored one. + if (init?.method === "POST") planCalls += 1; + return ok({ + status: "deferred", + plan_id: "deferred-plan-1", + plan_hash: "same-hash", + plan_json: { parameters: [] } + }); + } + if (path.startsWith("/data-objects")) return ok({ id: "do-1" }); + throw new Error(`unexpected adapter call ${path}`); + }); + global.fetch = fetchMock as unknown as typeof fetch; + legacy.tapis.compositeModelContext.mockResolvedValue({ + configuration_id: "model-1", + region: null, + has_bound_inputs: false, + filled_app_inputs: [], + outputs: [], + unmatched_optional_inputs: [] + }); + legacy.tapis.buildCompositeWorkflowModelTask.mockResolvedValue({ + execution_id: "model-child-1", + output_uri: "tapis://ls6/out/ue_parent-1/model/cbb", + output_name: "cbb", + output_format: "cbc", + job_definition: { name: "job", appId: "modflow6", appVersion: "0.0.1" } + }); + legacy.tapis.submitExecution.mockResolvedValue({ submittedExecutions: ["exec-1"] }); + flows.startFlowExecution.mockResolvedValue("exec-1"); + flows.finishFlowExecution.mockResolvedValue(undefined); + }); + + const service = (withFlows = false) => + createUnifiedExecutionService(legacy as unknown as LegacyServices, { + store: store(), + ...(withFlows ? { flows } : {}) + }); + + const BASE = { + executor: "ensemble_manager", + thread_id: "thread-1", + model_id: "model-1", + execution_engine: "tapis" + }; + + describe("pre-model adapter steps", () => { + const request = { + ...BASE, + adapter_steps: [ + { + adapter_plan_id: "adapter-plan-1", + model_io_id: "input-1", + source_resource_id: "source-1" + } + ] + }; + + it("gives a failed run and a re-plan a new record, and one plan twice one record", async () => { + const svc = service(); + const first = (await svc.createPlan(request)) as { plan_id: string }; + const run1 = asParent(await svc.submit({ plan_id: first.plan_id }, AUTH)); + failAll(); + + // The same plan again: still the failed record, nothing sent. + const sent = submitsToAdapter(); + expect(asParent(await svc.submit({ plan_id: first.plan_id }, AUTH)).run_id).toBe( + run1.run_id + ); + expect(submitsToAdapter()).toBe(sent); + + const second = (await svc.createPlan(request)) as { plan_id: string }; + expect(second.plan_id).not.toBe(first.plan_id); + const run2 = asParent(await svc.submit({ plan_id: second.plan_id }, AUTH)); + expect(run2.run_id).not.toBe(run1.run_id); + expect(records.size).toBe(2); + expect(submitsToAdapter()).toBe(sent + 1); + expect(asParent(await svc.submit({ plan_id: second.plan_id }, AUTH)).run_id).toBe( + run2.run_id + ); + expect(records.size).toBe(2); + }); + }); + + describe("post-model adapter", () => { + const request = { + ...BASE, + post_model_adapter: { + model_io_id: "cbc-output", + model_output_key: "cbb", + source_contract: { standard_variable_uri: "mint:cbc", format: "cbc" }, + target_contract: { standard_variable_uri: "mint:springflow" } + } + }; + const submitBody = (planId: string) => ({ + plan_id: planId, + adapter_parameter_values: { "deferred-plan-1": {} } + }); + + it("gives a failed run and a re-plan a new record even when the adapter repeats its plan id", async () => { + const svc = service(); + const first = (await svc.createPlan(request)) as { plan_id: string }; + const run1 = asParent(await svc.submit(submitBody(first.plan_id), AUTH)); + failAll(); + + const second = (await svc.createPlan(request)) as { plan_id: string }; + expect(planCalls).toBe(2); + expect(second.plan_id).not.toBe(first.plan_id); + const run2 = asParent(await svc.submit(submitBody(second.plan_id), AUTH)); + expect(run2.run_id).not.toBe(run1.run_id); + expect(records.size).toBe(2); + + const again = asParent(await svc.submit(submitBody(second.plan_id), AUTH)); + expect(again.run_id).toBe(run2.run_id); + expect(records.size).toBe(2); + }); + }); + + describe("flow", () => { + const context: FlowThreadContext = { + is_flow: true, + caller: "alice", + thread_bindings: {}, + inputs: [], + parameters: [], + outputs: [{ model_io_id: "out-1", name: "report" }], + dates: {} + } as unknown as FlowThreadContext; + const request = { ...BASE, model_id: "cfg-flow" }; + + beforeEach(() => flows.flowContext.mockResolvedValue(context)); + + it("gives a failed run and a re-plan a new record even when the adapter repeats its plan id", async () => { + const svc = service(true); + const first = (await svc.createPlan(request, AUTH)) as { plan_id: string }; + const run1 = asParent(await svc.submit({ plan_id: first.plan_id }, AUTH)); + failAll(); + + const second = (await svc.createPlan(request, AUTH)) as { plan_id: string }; + expect(planCalls).toBe(2); + expect(second.plan_id).not.toBe(first.plan_id); + const run2 = asParent(await svc.submit({ plan_id: second.plan_id }, AUTH)); + expect(run2.run_id).not.toBe(run1.run_id); + expect(records.size).toBe(2); + expect(flows.startFlowExecution).toHaveBeenCalledTimes(2); + + expect(asParent(await svc.submit({ plan_id: second.plan_id }, AUTH)).run_id).toBe( + run2.run_id + ); + expect(records.size).toBe(2); + expect(flows.startFlowExecution).toHaveBeenCalledTimes(2); + }); + + it("still refuses a second run while one is open", async () => { + const svc = service(true); + const first = (await svc.createPlan(request, AUTH)) as { plan_id: string }; + await svc.submit({ plan_id: first.plan_id }, AUTH); + const second = (await svc.createPlan(request, AUTH)) as { plan_id: string }; + await expect(svc.submit({ plan_id: second.plan_id }, AUTH)).rejects.toMatchObject({ + code: "FLOW_ALREADY_RUNNING" + }); + }); + }); + + describe("plain model job", () => { + it("keeps no run record, so every submit sends the job again", async () => { + const svc = service(); + const first = (await svc.createPlan(BASE)) as { plan_id: string }; + await svc.submit({ plan_id: first.plan_id }, AUTH); + const second = (await svc.createPlan(BASE)) as { plan_id: string }; + await svc.submit({ plan_id: second.plan_id }, AUTH); + expect(legacy.tapis.submitExecution).toHaveBeenCalledTimes(2); + expect(records.size).toBe(0); + }); + }); + + describe("plan id size", () => { + it("still fits with the nonce for a long pre-model plan, and fails with a clear error past the limit", async () => { + const svc = service(); + const long = (n: number) => ({ + ...BASE, + model_id: "m".repeat(120), + adapter_steps: Array.from({ length: n }, (_, i) => ({ + adapter_plan_id: `a${i}`.padEnd(36, "a"), + model_io_id: "i".repeat(36), + source_resource_id: "s".repeat(36) + })) + }); + const ok = (await svc.createPlan(long(4))) as { plan_id: string }; + expect(ok.plan_id.length).toBeLessThanOrEqual(2400); + await expect(svc.createPlan(long(40))).rejects.toMatchObject({ + code: "PLAN_TOO_LARGE" + }); + }); + }); +}); diff --git a/mint-ensemble-manager/src/api/api-v1/services/unifiedExecutionService.ts b/mint-ensemble-manager/src/api/api-v1/services/unifiedExecutionService.ts index 540ab480..96258bd9 100644 --- a/mint-ensemble-manager/src/api/api-v1/services/unifiedExecutionService.ts +++ b/mint-ensemble-manager/src/api/api-v1/services/unifiedExecutionService.ts @@ -91,10 +91,12 @@ interface LegacyPlan { model_id: string; execution_engine: string; adapter_steps?: AdapterStep[]; - // Makes each planning of a pre-model adapter run its own plan. The steps name - // saved adapter plans, so without it a plan for the same thread and model is - // always the same plan id, and submitting it again returns the earlier run - // (which cannot be started again) instead of starting a new one. + // Makes each planning its own plan. A plan id is the encoded plan, and a + // submit of a plan id that already has a record returns that record. Pre-model + // steps name saved adapter plans, so their plan id would never change; a flow's + // or post-model plan id changes only if the adapter happens to mint a new plan + // each time. The nonce makes a re-plan after a failure a new run whatever the + // adapter does, while submitting one plan twice still returns one run. nonce?: string; post_model_adapter?: PostModelAdapter; // Input ETL is planned by the bridge (POST /plans/model-inputs). The plan @@ -466,6 +468,10 @@ function isRunOwnerMismatch(error: unknown): boolean { ); } +function planNonce(): string { + return crypto.randomBytes(6).toString("hex"); +} + function planHash(plan: LegacyPlan): string { return crypto.createHash("sha256").update(JSON.stringify(plan)).digest("hex"); } @@ -2285,7 +2291,8 @@ export function createUnifiedExecutionService( thread_id: body.thread_id, model_id: body.model_id, execution_engine: "tapis", - flow: plannedFlow.flow + flow: plannedFlow.flow, + nonce: planNonce() }; return { executor, @@ -2538,8 +2545,8 @@ export function createUnifiedExecutionService( source_resource_id: step.source_resource_id }; }); - if (plan.adapter_steps.length) plan.nonce = crypto.randomBytes(6).toString("hex"); } + if (plan.post_model_adapter || plan.adapter_steps?.length) plan.nonce = planNonce(); return { executor, version: 1, From af333f80e4d064a0d84842dba7730eba2cd486d2 Mon Sep 17 00:00:00 2001 From: Will Mobley Date: Fri, 20 Nov 2026 16:28:22 -0600 Subject: [PATCH 7/7] Make Restart safe and the result previews bounded Restart: one control shared by the Runs and Results steps. It carries the earlier run's maximum time and queue (or shows the default to change), pre- selects the catalogs the earlier plan published to, is offered only once every run of the model is over, asks to confirm for a model run several times (restart all N runs, successes included), and is disabled while a send of that model is in flight in either step. The per-row button is gone. Previews: only Tapis files are previewed, never a web address. The body is read as a stream and cancelled at 200 KB; a Markdown report opens by itself only when the listing says it is under 100 KB. Markdown input is bounded (line length, line count, bounded patterns) with a notice, links show their host, CSV rows and cells are capped, JSON is indented only below a size and depth limit, and a cut off JSON or CSV is described as cut off. --- ui-react/docs/docs/facilitator/results.md | 14 +- ui-react/docs/docs/facilitator/run-a-flow.md | 15 +- .../src/components/common/MarkdownLite.tsx | 60 ++++- .../common/__tests__/CollapsibleCard.test.tsx | 22 ++ .../common/__tests__/MarkdownLite.test.tsx | 48 ++++ .../modeling/runs/RunFailureNotice.tsx | 29 +-- .../lib/__tests__/ensemble-manager.test.ts | 77 ++++++ .../src/lib/__tests__/publish-outputs.test.ts | 46 ++++ .../src/lib/__tests__/result-preview.test.ts | 95 +++++-- ui-react/src/lib/ensemble-manager.ts | 80 +++++- ui-react/src/lib/publish-outputs.ts | 60 +++++ ui-react/src/lib/result-preview.ts | 119 ++++++--- ui-react/src/pages/modeling/MintThread.tsx | 32 ++- .../pages/modeling/thread/FlowRunPanel.tsx | 17 +- .../src/pages/modeling/thread/MintResults.tsx | 71 +++--- .../src/pages/modeling/thread/MintRuns.tsx | 146 ++++++----- .../src/pages/modeling/thread/OutputBlock.tsx | 21 +- .../src/pages/modeling/thread/RestartRun.tsx | 235 ++++++++++++++++++ .../pages/modeling/thread/ResultPreview.tsx | 64 ++--- .../thread/__tests__/FlowRunPanel.test.tsx | 14 +- .../__tests__/MintResultsCards.test.tsx | 179 ++++++++++++- .../thread/__tests__/MintRunsCards.test.tsx | 148 +++++++++-- .../modeling/thread/useTapisResultKind.ts | 64 +++-- 23 files changed, 1329 insertions(+), 327 deletions(-) create mode 100644 ui-react/src/lib/__tests__/publish-outputs.test.ts create mode 100644 ui-react/src/pages/modeling/thread/RestartRun.tsx diff --git a/ui-react/docs/docs/facilitator/results.md b/ui-react/docs/docs/facilitator/results.md index 15e24a6b..ae10aab8 100644 --- a/ui-react/docs/docs/facilitator/results.md +++ b/ui-react/docs/docs/facilitator/results.md @@ -10,13 +10,15 @@ A run that finishes is not the same as an answer you can rely on, so review the ## Preview a result -Under an output, **Preview** shows the start of the file in place: +Under an output that DYNAMO stored in Tapis, **Preview** shows the start of the file in place: -- **A Markdown report** (`.md`) is shown formatted, and is open when the card opens. -- **A CSV file** shows its header and first rows as a small table. -- **A JSON file** is shown indented. +- **A Markdown report** (`.md`) is shown formatted. A link in it shows the address it goes to beside its words. +- **A CSV file** shows its header and first rows as a small table. Very wide rows and very long cells are shortened. +- **A JSON file** is shown indented. A file that is cut off, very large or deeply nested is shown as it is, with a note saying why. -CSV and JSON previews are closed until you open them, and a file is read only when its preview is open. At most the first 200 KB is read; where that cuts the file short, the preview says so. If the file cannot be read, the preview says *Preview unavailable* and offers **Download**. Other kinds of file have **Download** only. +A preview is closed until you open it, except that a Markdown report opens by itself when the file list says it is under 100 KB. A file is read only when its preview is open, and only its first 200 KB is read; where that cuts the file short, the preview says so. If the file cannot be read, the preview says *Preview unavailable* and offers **Download**. Other kinds of file have **Download** only. + +An output that is a web address is not read or previewed by DYNAMO, so that opening a result never sends your browser to another site. It has **Download**, which opens the address, and **Copy location**. ## A run that has not finished @@ -24,7 +26,7 @@ The card says where the run is instead of showing results: - **Waiting for your edit.** The flow is paused. Select **Go to Runs to edit and resume**. - **Running.** The results will appear when it finishes. Use **Refresh** to check. -- **Failed.** The card shows the reason and a **Restart** button, the same one as in the Runs step. After you restart, DYNAMO opens the Runs step so you can follow the new run. +- **Failed.** The card shows the reason and the same **Restart** control as in the Runs step, with the same run time and publishing choices, and the same confirmation for a model run several times. After you restart, DYNAMO opens the Runs step so you can follow the new run. ## A model run many times diff --git a/ui-react/docs/docs/facilitator/run-a-flow.md b/ui-react/docs/docs/facilitator/run-a-flow.md index 9dc79e66..6f097c06 100644 --- a/ui-react/docs/docs/facilitator/run-a-flow.md +++ b/ui-react/docs/docs/facilitator/run-a-flow.md @@ -91,13 +91,14 @@ When a run finishes, the card says *The flow run is complete. Continue to review ### When a run fails -A failed run shows a red box with the reason: the failure message, and a line for each step that failed. It also shows a **Restart** button. **Restart** sends the same model again with the same data and settings, and only that model, as a new run. - -- The button is disabled while the new run is being sent, so it is never started twice. -- It is shown only once the run has ended (failed or cancelled), and only to someone who can send runs on the thread. A run that is still going has **Cancel run** instead. -- If the run cannot be sent, the reason is shown under the button. For example, a flow that is already running in the thread is refused with *This flow is already running*. -- A run is sent with the default maximum run time of 60 minutes for a model; a flow has no maximum. -- In a table of runs, each failed row has a **Restart** button. It sends the model's runs again, not only that row: DYNAMO starts a model's runs together. +A failed run shows a red box with the reason: the failure message, and a line for each step that failed. Below it is a **Restart** button. **Restart** sends the same model again with the same data and settings, and only that model, as a new run. + +- **Only when every run is over.** If a model ran several times and one run failed while others are still going, the card says so and offers no Restart until the others have finished. +- **What is carried over.** For a model, the box shows **Maximum run time (minutes)**: the earlier run's time when it was kept, otherwise the default of 60, which you can change. If the earlier run published its outputs to a catalog, **Publish outputs** is already ticked with the same catalogs; check its settings before you restart. A flow has no maximum time and does not publish this way. +- **Several runs.** The button then reads **Restart all N runs**. It asks you to confirm, and says that runs which succeeded are sent again too: DYNAMO starts a model's runs together, so a single run cannot be restarted alone. +- **Never twice.** The button is disabled while the new run is being sent, in the Runs step and in the Results step alike. +- **Who.** Only someone who can send runs on the thread sees it. A run that is still going has **Cancel run** instead. +- **If it is refused**, the reason is shown under the button. For example, a flow already running in the thread is refused with *This flow is already running*. ## When a flow pauses for your edit diff --git a/ui-react/src/components/common/MarkdownLite.tsx b/ui-react/src/components/common/MarkdownLite.tsx index dd692902..21b8bb9a 100644 --- a/ui-react/src/components/common/MarkdownLite.tsx +++ b/ui-react/src/components/common/MarkdownLite.tsx @@ -8,9 +8,26 @@ import { Fragment, type ReactNode } from 'react'; * implementation: anything it does not know shows as plain text. */ -const INLINE = /(`[^`]+`)|(\*\*[^*]+\*\*)|(\*[^*\s][^*]*\*)|(\[[^\]]+\]\([^)\s]+\))/g; +// Every quantifier is bounded, and no line longer than MAX_LINE reaches a pattern, +// so no input can make a pattern take more than a few million steps. +const INLINE = + /(`[^`]{1,500}`)|(\*\*[^*]{1,500}\*\*)|(\*[^*\s][^*]{0,500}\*)|(\[[^\]]{1,200}\]\([^)\s]{1,2000}\))/g; +/** The longest line, and the most lines, that are read; the rest is left out with a notice. */ +export const MARKDOWN_MAX_LINE = 2000; +export const MARKDOWN_MAX_LINES = 3000; + +function hostOf(href: string): string | null { + try { + return new URL(href).hostname || null; + } catch { + return null; + } +} function inline(text: string, keyBase: string): ReactNode[] { + if (text.length > MARKDOWN_MAX_LINE) { + return [...inline(text.slice(0, MARKDOWN_MAX_LINE), keyBase), text.slice(MARKDOWN_MAX_LINE)]; + } const out: ReactNode[] = []; let last = 0; let index = 0; @@ -33,17 +50,23 @@ function inline(text: string, keyBase: string): ReactNode[] { const link = /^\[([^\]]+)\]\(([^)\s]+)\)$/.exec(token); const label = link?.[1] ?? token; const href = link?.[2] ?? ''; + const host = /^https?:\/\//i.test(href) ? hostOf(href) : null; out.push( - /^https?:\/\//i.test(href) ? ( - - {label} - + host ? ( + + + {label} + + {/* Where the link goes, so its words cannot hide it. */} + {label.replace(/\/$/, '') !== href.replace(/\/$/, '') && ( + ({host}) + )} + ) : ( label ), @@ -81,7 +104,14 @@ const HEADING_CLASS = [ ]; export function MarkdownLite({ source, testId }: { source: string; testId?: string }) { - const lines = source.replace(/\r\n?/g, '\n').split('\n'); + let cutLine = false; + const allLines = source.replace(/\r\n?/g, '\n').split('\n'); + const cut = allLines.length > MARKDOWN_MAX_LINES; + const lines = allLines.slice(0, MARKDOWN_MAX_LINES).map((line) => { + if (line.length <= MARKDOWN_MAX_LINE) return line; + cutLine = true; + return line.slice(0, MARKDOWN_MAX_LINE); + }); const blocks: ReactNode[] = []; let i = 0; const startsBlock = (line: string) => @@ -216,6 +246,12 @@ export function MarkdownLite({ source, testId }: { source: string; testId?: stri return (
        {blocks} + {(cut || cutLine) && ( +

        + Part of this report is not shown (very long lines or too many lines). Download for the + whole file. +

        + )}
        ); } diff --git a/ui-react/src/components/common/__tests__/CollapsibleCard.test.tsx b/ui-react/src/components/common/__tests__/CollapsibleCard.test.tsx index 63fdf16e..341b7a70 100644 --- a/ui-react/src/components/common/__tests__/CollapsibleCard.test.tsx +++ b/ui-react/src/components/common/__tests__/CollapsibleCard.test.tsx @@ -1,5 +1,6 @@ import { describe, expect, it } from 'vitest'; import { fireEvent, render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import { useState } from 'react'; import { CollapsibleCard } from '../CollapsibleCard'; @@ -52,4 +53,25 @@ describe('CollapsibleCard', () => { const body = screen.getByText('card body').closest('[data-state]'); expect(body?.className).toContain('motion-reduce:animate-none'); }); + + it('is a real button the keyboard reaches, and Enter and Space toggle it', async () => { + const user = userEvent.setup(); + render(); + const header = screen.getByRole('button', { name: /flood model/i }); + expect(header.tagName).toBe('BUTTON'); + await user.tab(); + expect(header).toHaveFocus(); + await user.keyboard('{Enter}'); + expect(header).toHaveAttribute('aria-expanded', 'false'); + expect(screen.queryByText('card body')).not.toBeInTheDocument(); + await user.keyboard(' '); + expect(header).toHaveAttribute('aria-expanded', 'true'); + expect(screen.getByText('card body')).toBeInTheDocument(); + }); + + it('names the region its button controls', () => { + render(); + const header = screen.getByRole('button', { name: /flood model/i }); + expect(header).toHaveAttribute('aria-controls'); + }); }); diff --git a/ui-react/src/components/common/__tests__/MarkdownLite.test.tsx b/ui-react/src/components/common/__tests__/MarkdownLite.test.tsx index 7199e283..010c6508 100644 --- a/ui-react/src/components/common/__tests__/MarkdownLite.test.tsx +++ b/ui-react/src/components/common/__tests__/MarkdownLite.test.tsx @@ -45,4 +45,52 @@ describe('MarkdownLite', () => { const { container } = render(); expect(container.querySelector('pre')).toHaveTextContent('# not a heading'); }); + + describe('hostile input', () => { + it('renders a 200 KB line of "[" quickly, and says part was left out', () => { + const started = Date.now(); + render(); + expect(Date.now() - started).toBeLessThan(2000); + expect(screen.getByTestId('markdown-truncated')).toBeInTheDocument(); + }); + + it('renders 200 KB of "[a](" quickly', () => { + const started = Date.now(); + render(); + expect(Date.now() - started).toBeLessThan(2000); + }); + + it('renders a long line of "**a" and of "*" quickly', () => { + const started = Date.now(); + render(); + expect(Date.now() - started).toBeLessThan(3000); + }); + + it('stops after the line limit and says so', () => { + const source = Array.from({ length: 6000 }, (_, i) => `- item ${i}`).join('\n'); + render(); + expect(screen.getAllByRole('listitem').length).toBeLessThanOrEqual(3000); + expect(screen.getByTestId('markdown-truncated')).toBeInTheDocument(); + }); + + it('does not say anything was left out for an ordinary report', () => { + render(); + expect(screen.queryByTestId('markdown-truncated')).not.toBeInTheDocument(); + }); + }); + + describe('links', () => { + it('shows the host beside a link whose words differ from its address', () => { + render(); + const link = screen.getByRole('link', { name: 'your bank' }); + expect(link.parentElement).toHaveTextContent('your bank (evil.example)'); + }); + + it('adds no host for a link whose words are its address', () => { + const { container } = render( + , + ); + expect(container).not.toHaveTextContent('(example.com)'); + }); + }); }); diff --git a/ui-react/src/components/modeling/runs/RunFailureNotice.tsx b/ui-react/src/components/modeling/runs/RunFailureNotice.tsx index 06725c0e..fec342c6 100644 --- a/ui-react/src/components/modeling/runs/RunFailureNotice.tsx +++ b/ui-react/src/components/modeling/runs/RunFailureNotice.tsx @@ -1,4 +1,3 @@ -import { RotateCcw } from 'lucide-react'; import type { ReactNode } from 'react'; import { EnsembleManagerError, type UnifiedRunSnapshot } from '@/lib/ensemble-manager'; @@ -10,27 +9,21 @@ export interface RunFailureNoticeProps { /** What failed inside the run, one line per step, shown under the reason. */ stepErrors?: string[]; cancelled?: boolean; - /** Sends the model again. Absent means the viewer cannot run it. */ - onRestart?: () => void; - /** A send is in flight: Restart is disabled so nothing is started twice. */ - restarting?: boolean; - /** Why the send was refused, shown under the button. */ - problem?: ReactNode; + /** What the viewer can do about it: the restart control, when they may run the model. */ + actions?: ReactNode; testId?: string; } /** * Why a run did not finish, and the way to run it again. The reason is the * Ensemble Manager's own failure code and message, in words when the code is a - * known flow refusal. + * known flow refusal. The way to run it again is passed in as `actions`. */ export function RunFailureNotice({ run, stepErrors = [], cancelled = false, - onRestart, - restarting = false, - problem, + actions, testId = 'run-failure', }: RunFailureNoticeProps) { const known = run?.failure_code @@ -67,19 +60,7 @@ export function RunFailureNotice({ ))}
      )} - {onRestart && ( - - )} - {problem} + {actions} ); } diff --git a/ui-react/src/lib/__tests__/ensemble-manager.test.ts b/ui-react/src/lib/__tests__/ensemble-manager.test.ts index 3942f010..a6bee8c6 100644 --- a/ui-react/src/lib/__tests__/ensemble-manager.test.ts +++ b/ui-react/src/lib/__tests__/ensemble-manager.test.ts @@ -25,6 +25,7 @@ import { submitRuns, submitExecutionPlan, isResultDownload, + readExecutionFilePrefix, } from '@/lib/ensemble-manager'; function lastRequest(): [string, RequestInit] { @@ -460,3 +461,79 @@ describe('isResultDownload', () => { expect(isResultDownload('https://example.org/a.csv', [folder])).toBe(false); }); }); + +describe('readExecutionFilePrefix', () => { + const file = { systemId: 'cloud.data', path: 'home/u/out/report.md' }; + + function streamed(chunks: Uint8Array[]) { + let at = 0; + const cancel = vi.fn().mockResolvedValue(undefined); + const read = vi.fn(async () => + at < chunks.length ? { done: false, value: chunks[at++] } : { done: true, value: undefined }, + ); + return { + cancel, + read, + response: { ok: true, status: 200, body: { getReader: () => ({ read, cancel }) } }, + }; + } + + beforeEach(() => { + localStorage.clear(); + storeTokens({ accessToken: 'tok' }); + }); + afterEach(() => { + vi.unstubAllGlobals(); + localStorage.clear(); + }); + + it('asks the download route with the same token, and stops reading at the cap', async () => { + const chunks = [new Uint8Array(60), new Uint8Array(60), new Uint8Array(60)]; + const s = streamed(chunks); + const fetchMock = vi.fn().mockResolvedValue(s.response); + vi.stubGlobal('fetch', fetchMock); + + const out = await readExecutionFilePrefix('http://em', 'exec-1', file, 100); + + expect(String(fetchMock.mock.calls[0]?.[0])).toBe( + 'http://em/executions/exec-1/files/content?path=home%2Fu%2Fout%2Freport.md&systemId=cloud.data', + ); + expect(fetchMock.mock.calls[0]?.[1].headers).toMatchObject({ Authorization: 'Bearer tok' }); + expect(out.bytes).toHaveLength(100); + expect(out.truncated).toBe(true); + // The third chunk was never pulled, and the body was cancelled. + expect(s.read).toHaveBeenCalledTimes(2); + expect(s.cancel).toHaveBeenCalled(); + }); + + it('returns a small file whole and untruncated', async () => { + const s = streamed([new TextEncoder().encode('hello')]); + vi.stubGlobal('fetch', vi.fn().mockResolvedValue(s.response)); + const out = await readExecutionFilePrefix('http://em', 'exec-1', file, 100); + expect(new TextDecoder().decode(out.bytes)).toBe('hello'); + expect(out.truncated).toBe(false); + expect(s.cancel).not.toHaveBeenCalled(); + }); + + it('falls back to a whole read, keeping the start, when the body is not a stream', async () => { + vi.stubGlobal( + 'fetch', + vi + .fn() + .mockResolvedValue({ ok: true, status: 200, blob: async () => new Blob(['abcdefghij']) }), + ); + const out = await readExecutionFilePrefix('http://em', 'exec-1', file, 4); + expect(new TextDecoder().decode(out.bytes)).toBe('abcd'); + expect(out.truncated).toBe(true); + }); + + it('rejects like a download does when the route refuses', async () => { + vi.stubGlobal( + 'fetch', + vi.fn().mockResolvedValue({ ok: false, status: 403, json: async () => ({ message: 'raw' }) }), + ); + await expect(readExecutionFilePrefix('http://em', 'exec-1', file, 100)).rejects.toThrow( + 'Your account cannot read this file in Tapis storage.', + ); + }); +}); diff --git a/ui-react/src/lib/__tests__/publish-outputs.test.ts b/ui-react/src/lib/__tests__/publish-outputs.test.ts new file mode 100644 index 00000000..50aab083 --- /dev/null +++ b/ui-react/src/lib/__tests__/publish-outputs.test.ts @@ -0,0 +1,46 @@ +import { describe, expect, it } from 'vitest'; + +import type { PlanPublisher } from '@/lib/ensemble-manager'; +import { priorPublish, selectionFromPrior } from '../publish-outputs'; + +const encode = (plan: unknown) => + `em_${btoa(JSON.stringify(plan)).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')}.sig`; + +const publisher: PlanPublisher = { + transform_spec_id: 'spec-1', + name: 'Publish', + catalog_tokens: ['ckan', 'stac'], + catalog_options: [['ckan', 'stac'], ['ckan']], + parameters: [{ name: 'title', default: 'My run' }], + can_publish: { ok: true, reason: null }, +}; + +describe('priorPublish', () => { + it('reads the catalogs and output the earlier plan asked to publish', () => { + expect( + priorPublish(encode({ publish: ['ckan'], post_model_adapter: { model_output_key: 'cbb' } })), + ).toEqual({ tokens: ['ckan'], outputKey: 'cbb' }); + }); + + it('is null for a plan that published nothing, or an id it cannot read', () => { + expect(priorPublish(encode({ thread_id: 't' }))).toBeNull(); + expect(priorPublish('em_!!!.sig')).toBeNull(); + expect(priorPublish('svo_abc')).toBeNull(); + expect(priorPublish(undefined)).toBeNull(); + }); +}); + +describe('selectionFromPrior', () => { + it('picks the publisher offering exactly those catalogs, with its parameter defaults', () => { + expect(selectionFromPrior([publisher], { tokens: ['ckan'] })).toEqual({ + transformSpecId: 'spec-1', + values: { title: 'My run' }, + tokens: ['ckan'], + }); + }); + + it('is null when no publisher offers them any more', () => { + expect(selectionFromPrior([publisher], { tokens: ['zenodo'] })).toBeNull(); + expect(selectionFromPrior([publisher], null)).toBeNull(); + }); +}); diff --git a/ui-react/src/lib/__tests__/result-preview.test.ts b/ui-react/src/lib/__tests__/result-preview.test.ts index d54e1273..d6ca9565 100644 --- a/ui-react/src/lib/__tests__/result-preview.test.ts +++ b/ui-react/src/lib/__tests__/result-preview.test.ts @@ -1,6 +1,13 @@ import { describe, expect, it } from 'vitest'; -import { parseCsvRows, prettyJson, previewKind, readBlobText } from '../result-preview'; +import { + PREVIEW_CSV_CELL_CHARS, + PREVIEW_CSV_COLUMNS, + decodePreviewText, + parseCsvRows, + prettyJson, + previewKind, +} from '../result-preview'; describe('previewKind', () => { it('reads the kind from the file name', () => { @@ -13,42 +20,94 @@ describe('previewKind', () => { }); }); +describe('decodePreviewText', () => { + it('decodes UTF-8 and survives a cut multi-byte character', () => { + expect(decodePreviewText(new TextEncoder().encode('héllo'))).toBe('héllo'); + const cut = new TextEncoder().encode('é').slice(0, 1); + expect(() => decodePreviewText(cut)).not.toThrow(); + }); +}); + describe('parseCsvRows', () => { it('reads quoted fields, doubled quotes and a newline inside quotes', () => { - const rows = parseCsvRows('a,b\n"x, y","say ""hi"""\n"two\nlines",z\n'); + const { rows, truncated } = parseCsvRows('a,b\n"x, y","say ""hi"""\n"two\nlines",z\n'); expect(rows).toEqual([ ['a', 'b'], ['x, y', 'say "hi"'], ['two\nlines', 'z'], ]); + expect(truncated).toBe(false); }); - it('stops after the row limit and handles CRLF and a missing final newline', () => { + it('stops after the row limit, says more followed, and handles CRLF', () => { const text = Array.from({ length: 30 }, (_, i) => `r${i},v${i}`).join('\r\n'); - const rows = parseCsvRows(text, 10); + const { rows, truncated } = parseCsvRows(text, 10); expect(rows).toHaveLength(10); expect(rows[9]).toEqual(['r9', 'v9']); - expect(parseCsvRows('a,b\n1,2')).toEqual([ - ['a', 'b'], - ['1', '2'], - ]); + expect(truncated).toBe(true); + }); + + it('is not truncated when it ends exactly at the limit, or has no final newline', () => { + expect(parseCsvRows('a,b\n1,2', 10)).toEqual({ + rows: [ + ['a', 'b'], + ['1', '2'], + ], + truncated: false, + }); + expect(parseCsvRows('a\n1\n', 2).truncated).toBe(false); + }); + + it('caps the columns of a row and the characters of a cell, and says so', () => { + const wide = Array.from({ length: PREVIEW_CSV_COLUMNS + 30 }, (_, i) => `c${i}`).join(','); + const parsed = parseCsvRows(wide); + expect(parsed.rows[0]).toHaveLength(PREVIEW_CSV_COLUMNS); + expect(parsed.truncated).toBe(true); + + const long = parseCsvRows(`${'x'.repeat(100_000)},b`); + expect(long.rows[0]?.[0]).toHaveLength(PREVIEW_CSV_CELL_CHARS); + expect(long.rows[0]?.[1]).toBe('b'); + expect(long.truncated).toBe(true); + }); + + it('is fast on a very large single-line file', () => { + const started = Date.now(); + parseCsvRows(','.repeat(200_000)); + expect(Date.now() - started).toBeLessThan(1000); }); }); describe('prettyJson', () => { - it('indents valid JSON and leaves cut-off JSON as it was', () => { - expect(prettyJson('{"a":1}')).toBe('{\n "a": 1\n}'); - expect(prettyJson('{"a":')).toBe('{"a":'); + it('indents valid JSON', () => { + expect(prettyJson('{"a":1}')).toEqual({ text: '{\n "a": 1\n}' }); + }); + + it('shows cut-off JSON as it is and says it was cut off, not that it is malformed', () => { + const cut = prettyJson('{"a":', { truncated: true }); + expect(cut.text).toBe('{"a":'); + expect(cut.note).toMatch(/only the start/i); + expect(cut.note).not.toMatch(/not valid/i); + }); + + it('says so for JSON that does not parse', () => { + expect(prettyJson('{"a":').note).toMatch(/not valid JSON/); }); -}); -describe('readBlobText', () => { - it('reads a small blob whole', async () => { - expect(await readBlobText(new Blob(['hello']))).toEqual({ text: 'hello', truncated: false }); + it('does not indent a file that is too large', () => { + const big = JSON.stringify({ a: 'x'.repeat(200_000) }); + const out = prettyJson(big); + expect(out.text).toBe(big); + expect(out.note).toMatch(/too large/); }); - it('reads only the first bytes of a large blob and says so', async () => { - const read = await readBlobText(new Blob(['abcdefghij']), 4); - expect(read).toEqual({ text: 'abcd', truncated: true }); + it('does not indent, and does not blow the stack on, deeply nested JSON', () => { + const deep = '['.repeat(50_000) + ']'.repeat(50_000); + const started = Date.now(); + const out = prettyJson(deep); + expect(out.text).toBe(deep); + expect(out.note).toMatch(/nested too deeply/); + expect(Date.now() - started).toBeLessThan(1000); + const ok = '['.repeat(10) + ']'.repeat(10); + expect(prettyJson(ok).note).toBeUndefined(); }); }); diff --git a/ui-react/src/lib/ensemble-manager.ts b/ui-react/src/lib/ensemble-manager.ts index 0ee71cfe..2bc9eba5 100644 --- a/ui-react/src/lib/ensemble-manager.ts +++ b/ui-react/src/lib/ensemble-manager.ts @@ -497,6 +497,7 @@ export function submitExecutionPlan( plan_id: string; parameter_values?: Record; max_minutes?: number; + queue?: string; run_name?: string; recreate?: boolean; dry_run?: boolean; @@ -810,16 +811,12 @@ function filenameFromDisposition(header: string | null, fallbackPath: string): s return plain ?? fallbackPath.split('/').pop() ?? 'download'; } -/** - * Fetch one result file through the Ensemble Manager, with the user's token. - * The server streams it from Tapis; the browser cannot open a `tapis://` URI. - */ -export async function downloadExecutionFile( +async function requestExecutionFile( ensembleManagerApi: string, executionId: string, file: { systemId: string; path: string }, signal?: AbortSignal, -): Promise<{ blob: Blob; filename: string }> { +): Promise { const query = new URLSearchParams({ path: file.path, systemId: file.systemId }); const url = `${ensembleManagerApi}/executions/${encodeURIComponent(executionId)}/files/content?${query}`; const resp = await fetch(url, { signal, headers: ensembleManagerHeaders() }); @@ -830,12 +827,83 @@ export async function downloadExecutionFile( } throw error; } + return resp; +} + +/** + * Fetch one result file through the Ensemble Manager, with the user's token. + * The server streams it from Tapis; the browser cannot open a `tapis://` URI. + */ +export async function downloadExecutionFile( + ensembleManagerApi: string, + executionId: string, + file: { systemId: string; path: string }, + signal?: AbortSignal, +): Promise<{ blob: Blob; filename: string }> { + const resp = await requestExecutionFile(ensembleManagerApi, executionId, file, signal); return { blob: await resp.blob(), filename: filenameFromDisposition(resp.headers?.get('Content-Disposition') ?? null, file.path), }; } +/** + * Read only the start of a result file, for a preview. The route is the same as + * the download's and it does not answer a `Range` request, so the body is read + * as a stream and cancelled once `maxBytes` have arrived: the rest of a large + * file is never pulled into the browser. + */ +export async function readExecutionFilePrefix( + ensembleManagerApi: string, + executionId: string, + file: { systemId: string; path: string }, + maxBytes: number, + signal?: AbortSignal, +): Promise<{ bytes: Uint8Array; truncated: boolean }> { + const resp = await requestExecutionFile(ensembleManagerApi, executionId, file, signal); + const reader = resp.body?.getReader?.(); + if (!reader) { + // No streaming body (an old browser): read it, then keep the start. + const blob = await resp.blob(); + const start = blob.slice(0, maxBytes); + const buffer = + typeof start.arrayBuffer === 'function' + ? await start.arrayBuffer() + : await new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onload = () => resolve(reader.result as ArrayBuffer); + reader.onerror = () => reject(reader.error); + reader.readAsArrayBuffer(start); + }); + return { bytes: new Uint8Array(buffer), truncated: blob.size > maxBytes }; + } + const chunks: Uint8Array[] = []; + let received = 0; + let truncated = false; + for (;;) { + const { done, value } = await reader.read(); + if (done) break; + if (value) { + chunks.push(value); + received += value.length; + } + if (received > maxBytes) { + truncated = true; + await reader.cancel().catch(() => undefined); + break; + } + } + const bytes = new Uint8Array(Math.min(received, maxBytes)); + let offset = 0; + for (const chunk of chunks) { + const room = bytes.length - offset; + if (room <= 0) break; + bytes.set(chunk.length > room ? chunk.subarray(0, room) : chunk, offset); + offset += Math.min(chunk.length, room); + } + return { bytes, truncated }; +} + /** Save a blob as a file through a temporary object URL. */ export function saveBlob(blob: Blob, filename: string): void { const objectUrl = URL.createObjectURL(blob); diff --git a/ui-react/src/lib/publish-outputs.ts b/ui-react/src/lib/publish-outputs.ts index cc30d99f..1913f5d4 100644 --- a/ui-react/src/lib/publish-outputs.ts +++ b/ui-react/src/lib/publish-outputs.ts @@ -103,3 +103,63 @@ export function publisherDefaults(publisher: PlanPublisher): Record char.charCodeAt(0)); + const plan = JSON.parse(new TextDecoder().decode(bytes)) as { + publish?: unknown; + post_model_adapter?: { model_output_key?: unknown }; + }; + const tokens = Array.isArray(plan.publish) + ? plan.publish.filter((token): token is string => typeof token === 'string') + : []; + if (tokens.length === 0) return null; + const outputKey = plan.post_model_adapter?.model_output_key; + return { tokens, ...(typeof outputKey === 'string' ? { outputKey } : {}) }; + } catch { + return null; + } +} + +/** + * The selection that repeats an earlier publish: the publisher offering exactly + * those catalogs, with its parameters at their defaults (the values the earlier + * run used are not kept, so the person checks them before restarting). + */ +export function selectionFromPrior( + publishers: PlanPublisher[], + prior: PriorPublish | null, +): PublishSelection | null { + if (!prior) return null; + const wanted = [...prior.tokens].sort().join('+'); + for (const publisher of publishers) { + const option = publisherCatalogOptions(publisher).find( + (tokens) => [...tokens].sort().join('+') === wanted, + ); + if (option) { + return { + transformSpecId: publisher.transform_spec_id, + values: publisherDefaults(publisher), + tokens: option, + ...(prior.outputKey ? { outputId: prior.outputKey } : {}), + }; + } + } + return null; +} diff --git a/ui-react/src/lib/result-preview.ts b/ui-react/src/lib/result-preview.ts index b813ad6d..73c4e33c 100644 --- a/ui-react/src/lib/result-preview.ts +++ b/ui-react/src/lib/result-preview.ts @@ -1,12 +1,20 @@ /** * Helpers for the inline preview of a result file: what kind of text it is, a - * capped read of its content, and small parsers. Pure, apart from the blob read. + * capped decode of its start, and small bounded parsers. Pure. */ /** The most a preview reads of one file. */ export const PREVIEW_MAX_BYTES = 200 * 1024; +/** A preview opens by itself only for a file known to be this small or smaller. */ +export const PREVIEW_AUTO_OPEN_MAX_BYTES = 100 * 1024; /** How many CSV rows a preview shows, header included. */ export const PREVIEW_CSV_ROWS = 10; +/** The widest CSV row, and the longest cell, a preview shows. */ +export const PREVIEW_CSV_COLUMNS = 50; +export const PREVIEW_CSV_CELL_CHARS = 500; +/** JSON is indented only up to this size and nesting depth. */ +export const PREVIEW_JSON_MAX_CHARS = 150_000; +export const PREVIEW_JSON_MAX_DEPTH = 64; export type PreviewKind = 'markdown' | 'csv' | 'json'; @@ -19,68 +27,113 @@ export function previewKind(name: string): PreviewKind | null { return null; } -/** The first `maxBytes` of a blob as text, and whether the rest was left out. */ -export async function readBlobText( - blob: Blob, - maxBytes = PREVIEW_MAX_BYTES, -): Promise<{ text: string; truncated: boolean }> { - const part = blob.size > maxBytes ? blob.slice(0, maxBytes) : blob; - const text = - typeof part.text === 'function' - ? await part.text() - : await new Promise((resolve, reject) => { - const reader = new FileReader(); - reader.onload = () => resolve(String(reader.result ?? '')); - reader.onerror = () => reject(reader.error); - reader.readAsText(part); - }); - return { text, truncated: blob.size > maxBytes }; +/** Decode the bytes of a file's start as text (a cut multi-byte character becomes a replacement mark). */ +export function decodePreviewText(bytes: Uint8Array): string { + return new TextDecoder('utf-8').decode(bytes); } -/** The first `maxRows` rows of CSV text, with quoted fields and doubled quotes read. */ -export function parseCsvRows(text: string, maxRows = PREVIEW_CSV_ROWS): string[][] { +/** + * The first `maxRows` rows of CSV text, with quoted fields and doubled quotes + * read. `truncated` is true when more rows followed, a row was wider than + * `PREVIEW_CSV_COLUMNS`, or a cell was longer than `PREVIEW_CSV_CELL_CHARS`. + */ +export function parseCsvRows( + text: string, + maxRows = PREVIEW_CSV_ROWS, +): { rows: string[][]; truncated: boolean } { const rows: string[][] = []; let row: string[] = []; let field = ''; let quoted = false; - const endRow = () => { - row.push(field); + let truncated = false; + let more = false; + const addField = () => { + if (row.length < PREVIEW_CSV_COLUMNS) row.push(field); + else truncated = true; field = ''; + }; + const addChar = (char: string) => { + if (field.length < PREVIEW_CSV_CELL_CHARS) field += char; + else truncated = true; + }; + const endRow = () => { + addField(); if (row.some((cell) => cell !== '')) rows.push(row); row = []; }; - for (let i = 0; i < text.length && rows.length < maxRows; i += 1) { - const char = text[i]; + for (let i = 0; i < text.length; i += 1) { + if (rows.length >= maxRows) { + more = text.slice(i).trim() !== ''; + break; + } + const char = text[i] as string; if (quoted) { if (char === '"' && text[i + 1] === '"') { - field += '"'; + addChar('"'); i += 1; } else if (char === '"') { quoted = false; } else { - field += char; + addChar(char); } } else if (char === '"') { quoted = true; } else if (char === ',') { - row.push(field); - field = ''; + addField(); } else if (char === '\n' || char === '\r') { if (char === '\r' && text[i + 1] === '\n') i += 1; endRow(); } else { - field += char; + addChar(char); } } if (rows.length < maxRows && (field !== '' || row.length > 0)) endRow(); - return rows.slice(0, maxRows); + return { rows, truncated: truncated || more }; } -/** JSON text indented, or the text as it was when it does not parse (a cut-off file). */ -export function prettyJson(text: string): string { +/** The deepest nesting of `{` and `[` outside strings, stopping early once past `limit`. */ +function jsonDepth(text: string, limit: number): number { + let depth = 0; + let deepest = 0; + let inString = false; + for (let i = 0; i < text.length; i += 1) { + const char = text[i]; + if (inString) { + if (char === '\\') i += 1; + else if (char === '"') inString = false; + } else if (char === '"') { + inString = true; + } else if (char === '{' || char === '[') { + depth += 1; + if (depth > deepest) deepest = depth; + if (deepest > limit) return deepest; + } else if (char === '}' || char === ']') { + depth -= 1; + } + } + return deepest; +} + +/** + * JSON text indented. It is shown as it was, with a note saying why, when it is + * cut off (only its start was read), too large, too deeply nested, or does not parse. + */ +export function prettyJson( + text: string, + options: { truncated?: boolean } = {}, +): { text: string; note?: string } { + if (options.truncated) { + return { text, note: 'Only the start of this file was read, so it is shown as it is.' }; + } + if (text.length > PREVIEW_JSON_MAX_CHARS) { + return { text, note: 'This file is too large to indent, so it is shown as it is.' }; + } + if (jsonDepth(text, PREVIEW_JSON_MAX_DEPTH) > PREVIEW_JSON_MAX_DEPTH) { + return { text, note: 'This file is nested too deeply to indent, so it is shown as it is.' }; + } try { - return JSON.stringify(JSON.parse(text), null, 2); + return { text: JSON.stringify(JSON.parse(text), null, 2) }; } catch { - return text; + return { text, note: 'This file is not valid JSON, so it is shown as it is.' }; } } diff --git a/ui-react/src/pages/modeling/MintThread.tsx b/ui-react/src/pages/modeling/MintThread.tsx index e8dddabe..1c9304e8 100644 --- a/ui-react/src/pages/modeling/MintThread.tsx +++ b/ui-react/src/pages/modeling/MintThread.tsx @@ -81,7 +81,7 @@ import { MintParameters } from './thread/MintParameters'; import type { PublishRequest } from '@/lib/publish-outputs'; import type { SpatialSelection } from './thread/SpatialScopeMap'; import { MintRuns } from './thread/MintRuns'; -import { DEFAULT_MAX_MINUTES } from '@/lib/modeling/run-settings'; +import type { RestartOptions } from './thread/RestartRun'; import { MintResults } from './thread/MintResults'; import { WizardRail, type ThreadStepNav } from './thread/wizard/WizardRail'; import { deriveStepStates } from './thread/wizard/deriveStepStates'; @@ -831,7 +831,7 @@ export function MintThread({ ); const handleSubmitRuns = useCallback( - async (modelId: string, maxMinutes: number, publish?: PublishRequest) => { + async (modelId: string, maxMinutes: number, publish?: PublishRequest, queue?: string) => { const isFlow = Boolean(threadExecutionData?.models[modelId]?.isFlow); if (!isFlow && (adapterPlansLoading || adapterPlanError)) { throw new Error('SVO adapter plan discovery must complete before workflow submission.'); @@ -972,6 +972,7 @@ export function MintThread({ const submitted = await submitExecutionPlan(ensembleManagerApi, { plan_id: plan.plan_id, max_minutes: maxMinutes, + ...(queue ? { queue } : {}), adapter_parameter_values: adapterParameterValues, ...(publish && Object.keys(publish.values).length > 0 ? { parameter_values: publish.values } @@ -1027,6 +1028,26 @@ export function MintThread({ ], ); + // A restart of a model, from the Runs or the Results step. Kept here so that a + // send started in one step shows as in flight in the other, and a second one + // for the same model is ignored until the first is done. + const [restartingModels, setRestartingModels] = useState>({}); + const restartingNow = useRef>({}); + const handleRestartRuns = useCallback( + async (modelId: string, options: RestartOptions) => { + if (restartingNow.current[modelId]) return; + restartingNow.current[modelId] = true; + setRestartingModels((current) => ({ ...current, [modelId]: true })); + try { + await handleSubmitRuns(modelId, options.maxMinutes, options.publish, options.queue); + } finally { + restartingNow.current[modelId] = false; + setRestartingModels((current) => ({ ...current, [modelId]: false })); + } + }, + [handleSubmitRuns], + ); + // Show the run a flow refused to duplicate, so the user can follow it. const handleOpenFlowRun = useCallback( async (modelId: string, runId: string) => { @@ -1274,6 +1295,8 @@ export function MintThread({ onContinue={goNext} onFetchRuns={handleFetchRuns} onSubmitRuns={handleSubmitRuns} + onRestartRuns={perm.write ? handleRestartRuns : undefined} + restartingModels={restartingModels} onOpenFlowRun={handleOpenFlowRun} onRefreshWorkflow={handleRefreshWorkflow} workflowRefreshErrors={unifiedRunErrors} @@ -1301,9 +1324,8 @@ export function MintThread({ onPublishResults={handlePublishResults} onPromoteOutputs={() => setCurrentSection('runs')} onOpenRuns={() => setCurrentSection('runs')} - onRestartRuns={ - perm.write ? (modelId) => handleSubmitRuns(modelId, DEFAULT_MAX_MINUTES) : undefined - } + onRestartRuns={perm.write ? handleRestartRuns : undefined} + restartingModels={restartingModels} /> ); case 'summary': diff --git a/ui-react/src/pages/modeling/thread/FlowRunPanel.tsx b/ui-react/src/pages/modeling/thread/FlowRunPanel.tsx index 0aa56411..81da7c2a 100644 --- a/ui-react/src/pages/modeling/thread/FlowRunPanel.tsx +++ b/ui-react/src/pages/modeling/thread/FlowRunPanel.tsx @@ -125,11 +125,8 @@ export interface FlowRunPanelProps { username?: string; /** Sends the user's edited file on and continues the run. */ onResume?: (edit: PausedEdit) => Promise; - /** Sends the flow again after it failed or was cancelled. */ - onRestart?: () => void; - restarting?: boolean; - /** Why the last send was refused, shown beside Restart. */ - restartProblem?: ReactNode; + /** The control that sends the flow again, once it failed or was cancelled. */ + restartControl?: ReactNode; } export function FlowRunPanel({ @@ -142,9 +139,7 @@ export function FlowRunPanel({ ensembleManagerApi = '', username = '', onResume, - onRestart, - restarting = false, - restartProblem, + restartControl, }: FlowRunPanelProps) { const [confirmingCancel, setConfirmingCancel] = useState(false); const stages: FlowStage[] = run.workflow_stages?.length @@ -185,14 +180,12 @@ export function FlowRunPanel({ )} {run.replacement && } - {(ended || run.failure_code || run.error_message || onRestart) && ( + {(ended || run.failure_code || run.error_message || restartControl) && ( )} diff --git a/ui-react/src/pages/modeling/thread/MintResults.tsx b/ui-react/src/pages/modeling/thread/MintResults.tsx index 64805e0e..38174b06 100644 --- a/ui-react/src/pages/modeling/thread/MintResults.tsx +++ b/ui-react/src/pages/modeling/thread/MintResults.tsx @@ -7,7 +7,7 @@ * * Legacy: ui/src/screens/modeling/thread/mint-results.ts */ -import { secretErrorMessage, userParameters } from '@/lib/secret-parameters'; +import { userParameters } from '@/lib/secret-parameters'; import { Download, RefreshCw } from 'lucide-react'; import { useCallback, useEffect, useState } from 'react'; @@ -23,7 +23,6 @@ import { RunAnswerCard } from '@/components/modeling/runs/RunAnswerCard'; import { RunFailureNotice } from '@/components/modeling/runs/RunFailureNotice'; import { SameForEveryRun } from '@/components/modeling/runs/SameForEveryRun'; import { SettingsUsed } from '@/components/modeling/runs/SettingsUsed'; -import { flowErrorMessage } from '@/lib/flow-errors'; import { aggregateRunStatus, displayStatusLabel, @@ -33,6 +32,7 @@ import { humanizeName, runParamValue, splitRunParams } from '@/lib/modeling/run- import { EditedInputNote } from './EditedInputNote'; import { ExecutionFilesDialog } from './ExecutionFilesDialog'; import { OutputBlock } from './OutputBlock'; +import { RestartRun, type RestartOptions } from './RestartRun'; import { TapisResult } from './TapisResult'; import { EnsembleManagerError, @@ -149,8 +149,13 @@ interface MintResultsProps { onPromoteOutputs?: () => void; /** Take the user to the Runs step: where a paused run is edited and a failed one restarted. */ onOpenRuns?: () => void; - /** Send a model's runs again after they failed. Rejects with the Ensemble Manager's refusal. */ - onRestartRuns?: (modelId: string) => Promise; + /** + * Send a model again after it failed. Rejects with the Ensemble Manager's + * refusal. Absent means the viewer cannot run the model. + */ + onRestartRuns?: (modelId: string, options: RestartOptions) => Promise; + /** Models whose restart is in flight, in either step. */ + restartingModels?: Record; } // ─── Component ──────────────────────────────────────────────────────────────── @@ -170,6 +175,7 @@ export function MintResults({ onPromoteOutputs, onOpenRuns, onRestartRuns, + restartingModels, unifiedRuns, }: MintResultsProps) { const modelIds = Object.keys(threadData.execution_summary ?? {}); @@ -189,8 +195,6 @@ export function MintResults({ const [showAllOutputs, setShowAllOutputs] = useState(true); // A card the user closed (or opened) keeps that choice; the rest start open. const [cardOpen, setCardOpen] = useState>({}); - const [restarting, setRestarting] = useState>({}); - const [restartError, setRestartError] = useState>({}); const [publishWaiting, setPublishWaiting] = useState>({}); const [publishError, setPublishError] = useState>({}); // The server's own error code, kept beside the message. NO_OUTPUTS_DECLARED @@ -250,30 +254,6 @@ export function MintResults({ [onPublishResults, onFetchRuns, pages], ); - const handleRestart = useCallback( - async (mid: string) => { - if (!onRestartRuns) return; - setRestarting((r) => ({ ...r, [mid]: true })); - setRestartError((e) => ({ ...e, [mid]: '' })); - try { - await onRestartRuns(mid); - // The new run is followed in the Runs step. - onOpenRuns?.(); - } catch (err) { - const refusal = flowErrorMessage(err); - setRestartError((e) => ({ - ...e, - [mid]: refusal - ? [refusal.title, ...refusal.lines].join(' ') - : (secretErrorMessage(err) ?? (err instanceof Error ? err.message : String(err))), - })); - } finally { - setRestarting((r) => ({ ...r, [mid]: false })); - } - }, - [onRestartRuns, onOpenRuns], - ); - // ─ CSV download ───────────────────────────────────────────────────────── function handleDownloadCsv( groupedExecutions: Record, @@ -372,6 +352,11 @@ export function MintResults({ fallbackStatus: run?.status ?? grouped.executions[0]?.status?.toLowerCase(), }); const isSingleRun = summary.total_runs <= 1; + const allOver = + !grouped.executions.some((e) => + ['RUNNING', 'WAITING'].includes(e.status.toUpperCase()), + ) && + (isSingleRun || finishedRuns >= summary.total_runs); const open = cardOpen[mid] ?? true; // Determine which outputs to show @@ -555,16 +540,24 @@ export function MintResults({ ? [`${failedRuns} of ${summary.total_runs} runs failed.`] : [] } - onRestart={onRestartRuns ? () => void handleRestart(mid) : undefined} - restarting={restarting[mid]} - problem={ - restartError[mid] ? ( -

      - {restartError[mid]} -

      - ) : undefined - } testId={`result-failure-${mid}`} + actions={ + !onRestartRuns ? undefined : allOver ? ( + + ) : ( +

      Restart is offered when every run has finished.

      + ) + } /> )} diff --git a/ui-react/src/pages/modeling/thread/MintRuns.tsx b/ui-react/src/pages/modeling/thread/MintRuns.tsx index 70c365b1..74d0f807 100644 --- a/ui-react/src/pages/modeling/thread/MintRuns.tsx +++ b/ui-react/src/pages/modeling/thread/MintRuns.tsx @@ -7,7 +7,7 @@ * * Legacy: ui/src/screens/modeling/thread/mint-runs.ts */ -import { ExternalLink, FolderOpen, RefreshCw, RotateCcw, X } from 'lucide-react'; +import { ExternalLink, FolderOpen, RefreshCw, X } from 'lucide-react'; import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'; import { Link } from 'react-router-dom'; @@ -59,6 +59,7 @@ import { secretErrorMessage, userParameters } from '@/lib/secret-parameters'; import { ExecutionFilesDialog } from './ExecutionFilesDialog'; import { FlowRunPanel } from './FlowRunPanel'; import { PublishOutputsControl } from './PublishOutputsControl'; +import { RestartRun, type RestartOptions } from './RestartRun'; import { publishRequestFor, type PublishRequest, @@ -680,11 +681,8 @@ interface UnifiedExecutionPanelProps { refreshError?: string; onCancel?: () => Promise; cancelling?: boolean; - /** Sends the model again after it failed or was cancelled. */ - onRestart?: () => void; - restarting?: boolean; - /** Why the last send was refused, shown beside Restart. */ - restartProblem?: ReactNode; + /** The control that sends the model again, once it failed or was cancelled. */ + restartControl?: ReactNode; } /** @@ -727,9 +725,7 @@ function UnifiedExecutionPanel({ refreshError, onCancel, cancelling = false, - onRestart, - restarting = false, - restartProblem, + restartControl, }: UnifiedExecutionPanelProps) { const adapterRuns = run.adapter_runs ?? []; const health = runHealth(run); @@ -1013,13 +1009,11 @@ function UnifiedExecutionPanel({ - {(run.failure_code || run.error_message || onRestart) && ( + {(run.failure_code || run.error_message || restartControl) && ( )} {refreshError && ( @@ -1055,6 +1049,14 @@ interface MintRunsProps { onContinue: () => void; onFetchRuns: (modelId: string, page: number, pageSize: number) => void; onSubmitRuns: (modelId: string, maxMinutes: number, publish?: PublishRequest) => Promise; + /** + * Send a model again after it failed. MintThread owns it so a send started + * from either step shows as in flight in both. Without it, Restart sends + * through `onSubmitRuns`. + */ + onRestartRuns?: (modelId: string, options: RestartOptions) => Promise; + /** Models whose restart is in flight, in either step. */ + restartingModels?: Record; /** Follow a flow run that is already in progress (`FLOW_ALREADY_RUNNING`). */ onOpenFlowRun?: (modelId: string, runId: string) => Promise; onExecutionSummaryChanged?: (summary: ExecutionSummaryMap) => void; @@ -1120,7 +1122,7 @@ function SubmitProblems({ ); } -/** The runs of a model that ran more than once: one row each, with a Restart on a failed row. */ +/** The runs of a model that ran more than once: one row each. */ function RunsTable({ modelId, isFlow, @@ -1130,8 +1132,6 @@ function RunsTable({ params, onViewLog, onViewFiles, - onRestart, - restarting, }: { modelId: string; isFlow: boolean; @@ -1141,12 +1141,8 @@ function RunsTable({ params: Array<{ id?: string | null; name?: string | null; default?: string | null }>; onViewLog: (executionId: string) => void; onViewFiles: (executionId: string) => void; - /** Present only when the model has ended and the viewer may run it. */ - onRestart?: () => void; - restarting?: boolean; }) { - const showRestart = Boolean(onRestart) && executions.some((e) => e.status === 'FAILURE'); - const fixedColumns = 5 + (showRestart ? 1 : 0); + const fixedColumns = 5; return (
      {loading ? ( @@ -1177,7 +1173,6 @@ function RunsTable({ End Log Files - {showRestart && } {inputs.length + params.length === 0 && } {inputs.map((f) => ( @@ -1243,23 +1238,6 @@ function RunsTable({ Files - {showRestart && ( - - {execution.status === 'FAILURE' && ( - - )} - - )} {inputs.length + params.length === 0 && ( No inputs or parameters )} @@ -1348,6 +1326,8 @@ export function MintRuns({ onContinue, onFetchRuns, onSubmitRuns, + onRestartRuns, + restartingModels, onOpenFlowRun, onPublishExecution, onOutputsChanged, @@ -1605,30 +1585,38 @@ export function MintRuns({ const isFlowRun = Boolean(model.isFlow) || workflowRun?.adapter_stage === 'flow'; const isSingleRun = summary.total_runs <= 1; const ended = displayStatus === 'failed' || displayStatus === 'cancelled'; + // Restart only once every run of the model is over: a failed run next to + // runs still going would be sent again on top of them. + const anyActive = grouped.executions.some((e) => + ['RUNNING', 'WAITING'].includes(e.status.toUpperCase()), + ); + const allOver = !anyActive && (isSingleRun || finishedRuns >= summary.total_runs); const nextAction = - displayStatus === 'failed' - ? canSubmitRuns - ? 'The run failed. Read the reason below, then restart it.' - : 'The run failed. Read the reason below and open its log.' - : displayStatus === 'cancelled' + ended && !allOver + ? 'Some runs have failed. Restart is offered when the others have finished.' + : displayStatus === 'failed' ? canSubmitRuns - ? 'The run was cancelled. Restart it to run it again.' - : 'The run was cancelled.' - : displayStatus === 'completed' - ? isFlowRun - ? 'The flow run is complete. Continue to review its results.' - : 'The model run is complete. Continue to review or publish its results.' - : displayStatus === 'paused' - ? 'The flow is paused for your edit. Download the file, change it, upload your copy and resume.' - : displayStatus === 'completing' - ? isFlowRun - ? 'The flow finished and its outputs are being prepared.' - : 'The model finished and its output is being prepared for the next stage.' - : displayStatus === 'running' + ? 'The run failed. Read the reason below, then restart it.' + : 'The run failed. Read the reason below and open its log.' + : displayStatus === 'cancelled' + ? canSubmitRuns + ? 'The run was cancelled. Restart it to run it again.' + : 'The run was cancelled.' + : displayStatus === 'completed' + ? isFlowRun + ? 'The flow run is complete. Continue to review its results.' + : 'The model run is complete. Continue to review or publish its results.' + : displayStatus === 'paused' + ? 'The flow is paused for your edit. Download the file, change it, upload your copy and resume.' + : displayStatus === 'completing' ? isFlowRun - ? 'The flow is running. Results will appear when it completes.' - : 'The model is running. Results will appear when it completes.' - : 'The run is waiting to start.'; + ? 'The flow finished and its outputs are being prepared.' + : 'The model finished and its output is being prepared for the next stage.' + : displayStatus === 'running' + ? isFlowRun + ? 'The flow is running. Results will appear when it completes.' + : 'The model is running. Results will appear when it completes.' + : 'The run is waiting to start.'; // ── count inputs × params for display ────────────────────────── const nParameters = userParameters(model) @@ -1661,9 +1649,27 @@ export function MintRuns({ const headerStatus: RunDisplayStatus | null = submitted ? displayStatus : null; const open = cardOpen[mid] ?? defaultCardOpen(headerStatus, modelIds.length); - // ── Restart: send this model again, only after it ended ─────── - const restart = - canSubmitRuns && submitted && ended ? () => void handleSubmit(mid) : undefined; + // ── Restart: send this model again, only once every run is over ── + const restartControl = + canSubmitRuns && submitted && ended && allOver ? ( + + options.publish + ? onSubmitRuns(modelId, options.maxMinutes, options.publish) + : onSubmitRuns(modelId, options.maxMinutes)) + } + onOpenFlowRun={onOpenFlowRun} + /> + ) : undefined; const problems = ( onResumeWorkflow(mid, edit) : undefined } - onRestart={restart} - restarting={waiting[mid]} - restartProblem={problems} + restartControl={restartControl} /> ) : showPanel && workflowRun ? ( ) : ended ? ( ) : null} @@ -1957,8 +1957,6 @@ export function MintRuns({ params={adjustableParams} onViewLog={(id) => void handleViewLog(id)} onViewFiles={(id) => setFilesFor({ executionId: id, modelId: mid })} - onRestart={restart} - restarting={waiting[mid]} />
      )} diff --git a/ui-react/src/pages/modeling/thread/OutputBlock.tsx b/ui-react/src/pages/modeling/thread/OutputBlock.tsx index 06f73d6b..bd401251 100644 --- a/ui-react/src/pages/modeling/thread/OutputBlock.tsx +++ b/ui-react/src/pages/modeling/thread/OutputBlock.tsx @@ -5,10 +5,10 @@ import { ChevronRight, Copy, Download, FolderOpen } from 'lucide-react'; import { useState } from 'react'; -import { previewKind } from '@/lib/result-preview'; +import { PREVIEW_AUTO_OPEN_MAX_BYTES, previewKind } from '@/lib/result-preview'; import { FileDownloadButton } from './FileDownloadButton'; import { ResultPreview } from './ResultPreview'; -import { useTapisResultKind } from './useTapisResultKind'; +import { useTapisResultInfo } from './useTapisResultKind'; export interface OutputBlockProps { ensembleManagerApi: string; @@ -42,13 +42,20 @@ export function OutputBlock({ onOpenFolder, }: OutputBlockProps) { // Asked of Tapis only for a tapis:// location; the others never use it. - const tapisKind = useTapisResultKind(ensembleManagerApi, executionId, url, scheme === 'tapis'); + const { kind: tapisKind, size } = useTapisResultInfo( + ensembleManagerApi, + executionId, + url, + scheme === 'tapis', + ); const kind = previewKind(name); - const previewable = - Boolean(kind) && (scheme === 'web' || (scheme === 'tapis' && tapisKind === 'file')); + const previewable = Boolean(kind) && scheme === 'tapis' && tapisKind === 'file'; const [open, setOpen] = useState(null); - // A report is what the run was for, so it opens by itself; the rest wait to be asked for. - const expanded = open ?? kind === 'markdown'; + // A report is what the run was for, so it opens by itself, but only when the + // listing says it is small; every other preview waits to be asked for. A web + // address is never read from here: it only has Download. + const expanded = + open ?? (kind === 'markdown' && size !== null && size <= PREVIEW_AUTO_OPEN_MAX_BYTES); const download = scheme === 'tapis' && tapisKind === 'file' ? ( diff --git a/ui-react/src/pages/modeling/thread/RestartRun.tsx b/ui-react/src/pages/modeling/thread/RestartRun.tsx new file mode 100644 index 00000000..3ec8b851 --- /dev/null +++ b/ui-react/src/pages/modeling/thread/RestartRun.tsx @@ -0,0 +1,235 @@ +/** + * RestartRun — send a model again after its runs ended without success. + * + * What the earlier run used is carried over, never dropped silently: the + * maximum run time and queue come from its record when it kept them (else the + * default is shown, and can be changed), and the catalogs it published to are + * read from its plan and pre-selected, with the publisher's parameters shown to + * check. A model that ran several times is sent again as a whole, so the button + * says how many runs, asks to confirm, and says that runs which succeeded are + * sent again too. + */ +import { RotateCcw } from 'lucide-react'; +import { useEffect, useState } from 'react'; + +import type { ThreadModel } from '@/graphql/generated/execution'; +import { + fetchPlanPublishers, + type PlanPublisher, + type UnifiedRunSnapshot, +} from '@/lib/ensemble-manager'; +import { flowErrorMessage } from '@/lib/flow-errors'; +import { DEFAULT_MAX_MINUTES } from '@/lib/modeling/run-settings'; +import { + priorPublish, + publishRequestFor, + selectionFromPrior, + type PublishRequest, + type PublishSelection, +} from '@/lib/publish-outputs'; +import { secretErrorMessage } from '@/lib/secret-parameters'; +import { PublishOutputsControl } from './PublishOutputsControl'; + +/** What a restart sends; the same as the first send, plus the queue the first run used. */ +export interface RestartOptions { + maxMinutes: number; + queue?: string; + publish?: PublishRequest; +} + +export interface RestartRunProps { + modelId: string; + model: ThreadModel; + /** The earlier run's record: where its maximum time, queue and plan are read from. */ + run?: UnifiedRunSnapshot; + /** How many runs the model has; more than one means the whole set is sent again. */ + totalRuns: number; + successfulRuns: number; + ensembleManagerApi: string; + /** A send of this model is in flight (from either step): the button is disabled. */ + inFlight: boolean; + onRestart: (modelId: string, options: RestartOptions) => Promise; + /** Follow the run already in progress, when a flow refuses because one is. */ + onOpenFlowRun?: (modelId: string, runId: string) => Promise; + /** Called once the new run is sent, e.g. to open the Runs step. */ + onRestarted?: () => void; +} + +function storedJobOptions(run?: UnifiedRunSnapshot): { maxMinutes?: number; queue?: string } { + const result = run?.model_result as + | { __max_minutes?: unknown; __queue?: unknown } + | null + | undefined; + const minutes = Number(result?.__max_minutes); + return { + ...(Number.isInteger(minutes) && minutes >= 1 ? { maxMinutes: minutes } : {}), + ...(typeof result?.__queue === 'string' && result.__queue ? { queue: result.__queue } : {}), + }; +} + +export function RestartRun({ + modelId, + model, + run, + totalRuns, + successfulRuns, + ensembleManagerApi, + inFlight, + onRestart, + onOpenFlowRun, + onRestarted, +}: RestartRunProps) { + const stored = storedJobOptions(run); + const isFlow = Boolean(model.isFlow); + const [minutes, setMinutes] = useState(String(stored.maxMinutes ?? DEFAULT_MAX_MINUTES)); + const [publishers, setPublishers] = useState([]); + // undefined: the person has not chosen, so the earlier run's choice stands. + const [chosen, setChosen] = useState(undefined); + const [confirming, setConfirming] = useState(false); + const [sending, setSending] = useState(false); + const [problem, setProblem] = useState<{ lines: string[]; runId?: string } | null>(null); + + useEffect(() => { + if (isFlow || !ensembleManagerApi) return; + const controller = new AbortController(); + fetchPlanPublishers(ensembleManagerApi, modelId, controller.signal) + .then((response) => setPublishers(response.publishers ?? [])) + .catch(() => undefined); + return () => controller.abort(); + }, [ensembleManagerApi, modelId, isFlow]); + + const selection = + chosen !== undefined ? chosen : selectionFromPrior(publishers, priorPublish(run?.plan_id)); + const many = totalRuns > 1; + const busy = inFlight || sending; + const minutesValue = Number(minutes); + const minutesValid = Number.isInteger(minutesValue) && minutesValue >= 1; + + async function send() { + setConfirming(false); + if (!isFlow && !minutesValid) { + setProblem({ lines: ['Enter a positive whole number of minutes.'] }); + return; + } + setProblem(null); + setSending(true); + try { + const publish = isFlow ? undefined : publishRequestFor(publishers, selection); + await onRestart(modelId, { + maxMinutes: isFlow ? DEFAULT_MAX_MINUTES : minutesValue, + ...(stored.queue ? { queue: stored.queue } : {}), + ...(publish ? { publish } : {}), + }); + onRestarted?.(); + } catch (error) { + const refusal = isFlow ? flowErrorMessage(error) : null; + setProblem( + refusal + ? { lines: [refusal.title, ...refusal.lines], runId: refusal.runId } + : { + lines: [ + secretErrorMessage(error) ?? + (error instanceof Error ? error.message : String(error)), + ], + }, + ); + } finally { + setSending(false); + } + } + + return ( +
      + {!isFlow && ( + + )} + {!isFlow && publishers.length > 0 && ( + + )} + {confirming ? ( +
      +

      + This sends all {totalRuns} runs again + {successfulRuns > 0 ? `, including the ${successfulRuns} that succeeded` : ''}. +

      +
      + + +
      +
      + ) : ( + + )} + {problem && ( +
      + {problem.lines.map((line, index) => ( +

      1 ? 'font-medium' : ''}> + {line} +

      + ))} + {problem.runId && onOpenFlowRun && ( + + )} +
      + )} +
      + ); +} diff --git a/ui-react/src/pages/modeling/thread/ResultPreview.tsx b/ui-react/src/pages/modeling/thread/ResultPreview.tsx index 5eda8ab8..2ef52571 100644 --- a/ui-react/src/pages/modeling/thread/ResultPreview.tsx +++ b/ui-react/src/pages/modeling/thread/ResultPreview.tsx @@ -4,20 +4,20 @@ * Read only when the block is open (it mounts then): a Markdown report rendered, * the first rows of a CSV as a small table, JSON indented. A Tapis file is read * through the same Ensemble Manager route, with the same token, as its Download - * button; a web address is fetched as the link would be. At most the first - * 200 KB is read. If the file cannot be read, the preview says so quietly and + * button, and only its first 200 KB is pulled (the body is cancelled at the cap). + * A web address is never read from here. If the file cannot be read, the preview says so quietly and * offers the Download instead. */ import { useEffect, useState, type ReactNode } from 'react'; import { MarkdownLite } from '@/components/common/MarkdownLite'; -import { downloadExecutionFile, parseTapisUri } from '@/lib/ensemble-manager'; +import { parseTapisUri, readExecutionFilePrefix } from '@/lib/ensemble-manager'; import { PREVIEW_CSV_ROWS, PREVIEW_MAX_BYTES, + decodePreviewText, parseCsvRows, prettyJson, - readBlobText, type PreviewKind, } from '@/lib/result-preview'; @@ -30,27 +30,12 @@ export interface ResultPreviewProps { kind: PreviewKind; ensembleManagerApi: string; executionId: string; - /** A `tapis://` location, or a web address. */ + /** The `tapis://` location of the file. Only Tapis files are previewed. */ url: string; /** The Download control, repeated beside the fallback message. */ download?: ReactNode; } -async function readResult( - props: Pick, - signal: AbortSignal, -): Promise { - const location = parseTapisUri(props.url); - if (location) { - return ( - await downloadExecutionFile(props.ensembleManagerApi, props.executionId, location, signal) - ).blob; - } - const response = await fetch(props.url, { signal }); - if (!response.ok) throw new Error(`HTTP ${response.status}`); - return response.blob(); -} - export function ResultPreview({ kind, ensembleManagerApi, @@ -63,9 +48,23 @@ export function ResultPreview({ useEffect(() => { const controller = new AbortController(); setState({ status: 'loading' }); - readResult({ ensembleManagerApi, executionId, url }, controller.signal) - .then((blob) => readBlobText(blob, PREVIEW_MAX_BYTES)) - .then((read) => !controller.signal.aborted && setState({ status: 'ready', ...read })) + const location = parseTapisUri(url); + if (!location) { + setState({ status: 'error' }); + return; + } + readExecutionFilePrefix( + ensembleManagerApi, + executionId, + location, + PREVIEW_MAX_BYTES, + controller.signal, + ) + .then( + ({ bytes, truncated }) => + !controller.signal.aborted && + setState({ status: 'ready', text: decodePreviewText(bytes), truncated }), + ) .catch(() => !controller.signal.aborted && setState({ status: 'error' })); return () => controller.abort(); }, [ensembleManagerApi, executionId, url]); @@ -90,10 +89,14 @@ export function ResultPreview({ } let body: ReactNode; + let truncatedRows = false; + let jsonNote: string | undefined; if (kind === 'markdown') { body = ; } else if (kind === 'csv') { - const [head, ...rows] = parseCsvRows(state.text, PREVIEW_CSV_ROWS); + const parsed = parseCsvRows(state.text, PREVIEW_CSV_ROWS); + truncatedRows = parsed.truncated; + const [head, ...rows] = parsed.rows; body = head ? (
      @@ -123,12 +126,14 @@ export function ResultPreview({

      The file is empty.

      ); } else { + const json = prettyJson(state.text, { truncated: state.truncated }); + jsonNote = json.note; body = (
      -        {prettyJson(state.text)}
      +        {json.text}
             
      ); } @@ -136,10 +141,11 @@ export function ResultPreview({ return (
      {body} - {(state.truncated || kind === 'csv') && ( -

      - {kind === 'csv' ? `First ${PREVIEW_CSV_ROWS - 1} rows. ` : ''} - {state.truncated ? 'Only the start of the file is shown. ' : ''} + {(state.truncated || truncatedRows || jsonNote) && ( +

      + {jsonNote ? `${jsonNote} ` : ''} + {truncatedRows ? `Only the first ${PREVIEW_CSV_ROWS - 1} rows are shown. ` : ''} + {state.truncated && kind !== 'json' ? 'Only the start of the file is shown. ' : ''} Download for the whole file.

      )} diff --git a/ui-react/src/pages/modeling/thread/__tests__/FlowRunPanel.test.tsx b/ui-react/src/pages/modeling/thread/__tests__/FlowRunPanel.test.tsx index b4618148..4d42bc66 100644 --- a/ui-react/src/pages/modeling/thread/__tests__/FlowRunPanel.test.tsx +++ b/ui-react/src/pages/modeling/thread/__tests__/FlowRunPanel.test.tsx @@ -223,15 +223,13 @@ describe('FlowRunPanel', () => { expect(screen.getByTestId('flow-step-step-2')).toHaveTextContent('task-step-2'); }); - it('offers Restart on a failed run, disables it while sending, and not on a running one', () => { - const onRestart = vi.fn(); + it('shows the restart control in the failure box of a failed run, and not for a running one', () => { const failed = flowRun({ status: 'failed', failure_code: 'FLOW_FAILED', error_message: 'x' }); - const { rerender } = render(); - fireEvent.click(screen.getByRole('button', { name: 'Restart' })); - expect(onRestart).toHaveBeenCalledTimes(1); - - rerender(); - expect(screen.getByRole('button', { name: /restarting/i })).toBeDisabled(); + const { rerender } = render( + Restart} />, + ); + const box = screen.getByTestId('run-failure'); + expect(within(box).getByRole('button', { name: 'Restart' })).toBeInTheDocument(); rerender(); expect(screen.queryByRole('button', { name: /restart/i })).not.toBeInTheDocument(); diff --git a/ui-react/src/pages/modeling/thread/__tests__/MintResultsCards.test.tsx b/ui-react/src/pages/modeling/thread/__tests__/MintResultsCards.test.tsx index f38a5749..6cf4bf91 100644 --- a/ui-react/src/pages/modeling/thread/__tests__/MintResultsCards.test.tsx +++ b/ui-react/src/pages/modeling/thread/__tests__/MintResultsCards.test.tsx @@ -75,22 +75,42 @@ const run = (id: string, over: Partial = {}): Execution => ({ const oneRun: ModelExecutionsMap = { m1: { loading: false, executions: [run('exec-1')] } }; -const listing = { +/** A listing of the run's files; the size of each is what a preview reads to decide to open. */ +const listingOf = (sizes: Record) => ({ ok: true, status: 200, json: () => Promise.resolve({ - files: [], + files: Object.entries(sizes).map(([url, size]) => ({ name: 'x', path: 'p', url, size })), results: [REPORT, TABLE, LEXICON].map((url) => ({ name: 'x', url, kind: 'file' })), }), -}; - -const content = (text: string) => ({ - ok: true, - status: 200, - headers: new Headers(), - blob: () => Promise.resolve(new Blob([text])), }); +const listing = listingOf({ [REPORT]: 500, [TABLE]: 2000, [LEXICON]: 100 }); + +/** A response whose body is read as a stream, `chunk` bytes at a time, as the route sends it. */ +let lastCancel: ReturnType; +const content = (text: string, chunk = 64 * 1024) => { + const bytes = new TextEncoder().encode(text); + let at = 0; + lastCancel = vi.fn().mockResolvedValue(undefined); + return { + ok: true, + status: 200, + headers: new Headers(), + body: { + getReader: () => ({ + read: async () => { + if (at >= bytes.length) return { done: true, value: undefined }; + const value = bytes.slice(at, at + chunk); + at += chunk; + return { done: false, value }; + }, + cancel: lastCancel, + }), + }, + blob: () => Promise.resolve(new Blob([bytes])), + }; +}; const csv = ['id,score', ...Array.from({ length: 14 }, (_, i) => `row${i + 1},${i}`)].join('\n'); @@ -195,6 +215,87 @@ describe('a single run with results', () => { expect(screen.queryByRole('alert')).not.toBeInTheDocument(); }); + it('does not open the report by itself when its size is not known or is large', async () => { + fetchMock.mockImplementation(async (url: string) => + String(url).includes('/files/content') + ? content('# Findings\n') + : listingOf({ [REPORT]: 5 * 1024 * 1024 }), + ); + renderResults(); + const toggles = await screen.findAllByTestId('preview-toggle'); + expect(toggles[0]).toHaveAttribute('aria-expanded', 'false'); + expect(contentCalls()).toHaveLength(0); + // Asking for it opens it. + fireEvent.click(toggles[0]!); + expect(await screen.findByRole('heading', { name: 'Findings' })).toBeInTheDocument(); + }); + + it('reads as a stream and cancels at the 200 KB cap, saying only the start is shown', async () => { + const big = '# Big\n\n' + 'word '.repeat(150_000); + fetchMock.mockImplementation(async (url: string) => + String(url).includes('/files/content') + ? content(big, 64 * 1024) + : listingOf({ [REPORT]: 90_000, [TABLE]: 2000, [LEXICON]: 100 }), + ); + renderResults(); + await screen.findByRole('heading', { name: 'Big' }); + expect(lastCancel).toHaveBeenCalled(); + expect(screen.getByTestId('preview-note')).toHaveTextContent('Only the start of the file'); + }); + + it('never previews or fetches a web address, and still offers its Download link', async () => { + renderResults({ + executions: { + m1: { + loading: false, + executions: [ + run('exec-1', { + results: { + 'o-report': { id: 'o-report', name: 'report.md', url: 'https://evil.example/r.md' }, + }, + }), + ], + }, + }, + }); + const link = await screen.findByTestId('download-link'); + expect(link).toHaveAttribute('href', 'https://evil.example/r.md'); + expect(screen.queryByTestId('preview-toggle')).not.toBeInTheDocument(); + expect( + fetchMock.mock.calls.map(([u]) => String(u)).some((u) => u.includes('evil.example')), + ).toBe(false); + }); + + it('says a CSV was cut short only when it was', async () => { + renderResults(); + await screen.findByRole('heading', { name: 'Findings' }); + fireEvent.click(screen.getAllByTestId('preview-toggle')[1]!); + await screen.findByTestId('preview-csv'); + expect(screen.getByTestId('preview-note')).toHaveTextContent('Only the first 9 rows'); + }); + + it('shows a short CSV with no caption', async () => { + fetchMock.mockImplementation(async (url: string) => + String(url).includes('/files/content') ? content('id,score\nr1,1\nr2,2\n') : listing, + ); + renderResults(); + await screen.findAllByTestId('output-block'); + fireEvent.click(screen.getAllByTestId('preview-toggle')[1]!); + await screen.findByTestId('preview-csv'); + expect(screen.queryByTestId('preview-note')).not.toBeInTheDocument(); + }); + + it('falls back quietly when Tapis refuses the file (403) too', async () => { + fetchMock.mockImplementation(async (url: string) => + String(url).includes('/files/content') + ? { ok: false, status: 403, json: () => Promise.resolve({ message: 'raw' }) } + : listing, + ); + renderResults(); + expect(await screen.findByTestId('preview-unavailable')).toBeInTheDocument(); + expect(screen.queryByRole('alert')).not.toBeInTheDocument(); + }); + it('keeps how it was made collapsed, with the inputs and the settings', async () => { renderResults(); await screen.findAllByTestId('output-block'); @@ -237,6 +338,10 @@ describe('a run that has not finished', () => { loading: false, executions: [run('exec-1', { status: 'RUNNING', results: {} })], }; + const failedExecutions = { + loading: false, + executions: [run('exec-1', { status: 'FAILURE', results: {} })], + }; it('says a paused run waits for the user, with a way to the Runs step', () => { const onOpenRuns = vi.fn(); @@ -272,17 +377,31 @@ describe('a run that has not finished', () => { const onOpenRuns = vi.fn(); renderResults({ threadData: failedThread, - executions: { m1: unfinished }, + executions: { m1: failedExecutions }, unifiedRuns: { m1: failedRun }, onRestartRuns, onOpenRuns, }); expect(screen.getByText('job exited with code 2')).toBeInTheDocument(); fireEvent.click(screen.getByRole('button', { name: 'Restart' })); - await waitFor(() => expect(onRestartRuns).toHaveBeenCalledWith('m1')); + await waitFor(() => expect(onRestartRuns).toHaveBeenCalledWith('m1', { maxMinutes: 60 })); await waitFor(() => expect(onOpenRuns).toHaveBeenCalled()); }); + it('carries the earlier run time into the restart', async () => { + const onRestartRuns = vi.fn().mockResolvedValue(undefined); + renderResults({ + threadData: failedThread, + executions: { m1: failedExecutions }, + unifiedRuns: { m1: { ...failedRun, model_result: { __max_minutes: 180, __queue: 'q' } } }, + onRestartRuns, + }); + fireEvent.click(screen.getByRole('button', { name: 'Restart' })); + await waitFor(() => + expect(onRestartRuns).toHaveBeenCalledWith('m1', { maxMinutes: 180, queue: 'q' }), + ); + }); + it('disables Restart while it sends and shows a refusal', async () => { let fail: (error: Error) => void = () => undefined; const onRestartRuns = vi.fn( @@ -293,7 +412,7 @@ describe('a run that has not finished', () => { ); renderResults({ threadData: failedThread, - executions: { m1: unfinished }, + executions: { m1: failedExecutions }, unifiedRuns: { m1: failedRun }, onRestartRuns, }); @@ -303,6 +422,42 @@ describe('a run that has not finished', () => { expect(await screen.findByTestId('restart-error-m1')).toHaveTextContent('refused'); expect(screen.getByRole('button', { name: 'Restart' })).toBeEnabled(); }); + + it('shows Restart as in flight when the Runs step started it', () => { + renderResults({ + threadData: failedThread, + executions: { m1: failedExecutions }, + unifiedRuns: { m1: failedRun }, + onRestartRuns: vi.fn(), + restartingModels: { m1: true }, + }); + expect(screen.getByRole('button', { name: /restarting/i })).toBeDisabled(); + }); + + it('offers no Restart without permission, or while other runs are still going', () => { + const view = renderResults({ + threadData: failedThread, + executions: { m1: failedExecutions }, + unifiedRuns: { m1: failedRun }, + }); + expect(screen.queryByRole('button', { name: /restart/i })).not.toBeInTheDocument(); + view.unmount(); + renderResults({ + threadData: thread({ total_runs: 2, submitted_runs: 2, successful_runs: 0, failed_runs: 1 }), + executions: { + m1: { + loading: false, + executions: [ + run('exec-1', { status: 'FAILURE', results: {} }), + run('exec-2', { status: 'RUNNING', results: {} }), + ], + }, + }, + unifiedRuns: { m1: failedRun }, + onRestartRuns: vi.fn(), + }); + expect(screen.queryByRole('button', { name: /restart/i })).not.toBeInTheDocument(); + }); }); // ─── Several runs ──────────────────────────────────────────────────────────── diff --git a/ui-react/src/pages/modeling/thread/__tests__/MintRunsCards.test.tsx b/ui-react/src/pages/modeling/thread/__tests__/MintRunsCards.test.tsx index 01dbcdc1..5e6b42ae 100644 --- a/ui-react/src/pages/modeling/thread/__tests__/MintRunsCards.test.tsx +++ b/ui-react/src/pages/modeling/thread/__tests__/MintRunsCards.test.tsx @@ -469,30 +469,144 @@ describe('restarting a failed run', () => { expect(screen.queryByRole('button', { name: /restart/i })).not.toBeInTheDocument(); }); - it('offers Restart on each failed row of an ensemble, all calling the same send', async () => { + const sweepThread = thread([ + { id: 'm1', summary: { total_runs: 3, submitted_runs: 3, successful_runs: 1, failed_runs: 2 } }, + ]); + const sweepRows = (...statuses: string[]): ModelExecutionsMap => ({ + m1: { + loading: false, + executions: statuses.map((status, i) => + execution(`exec-${i + 1}`, 'm1', { status, bindings: { 'p-depth': String(i + 1) } }), + ), + }, + }); + + it('has no per-row Restart in a table of runs; one model-level button asks to confirm first', async () => { const onSubmitRuns = vi.fn().mockResolvedValue(undefined); + renderRuns({ + threadData: sweepThread, + executions: sweepRows('FAILURE', 'SUCCESS', 'FAILURE'), + onSubmitRuns, + }); + expect(screen.queryByTestId(/^restart-run-exec-/)).not.toBeInTheDocument(); + fireEvent.click(screen.getByRole('button', { name: 'Restart all 3 runs' })); + // Nothing is sent until the person confirms, and the card says what is sent. + expect(onSubmitRuns).not.toHaveBeenCalled(); + expect(screen.getByTestId('restart-confirm-m1')).toHaveTextContent( + 'sends all 3 runs again, including the 1 that succeeded', + ); + fireEvent.click(screen.getByRole('button', { name: 'Cancel' })); + expect(onSubmitRuns).not.toHaveBeenCalled(); + + fireEvent.click(screen.getByRole('button', { name: 'Restart all 3 runs' })); + fireEvent.click(screen.getByTestId('restart-confirm-yes-m1')); + await waitFor(() => expect(onSubmitRuns).toHaveBeenCalledWith('m1', 60)); + }); + + it('offers no Restart while a sibling run is still running, even though one failed', () => { renderRuns({ threadData: thread([ { id: 'm1', - summary: { total_runs: 3, submitted_runs: 3, successful_runs: 1, failed_runs: 2 }, + summary: { total_runs: 3, submitted_runs: 3, successful_runs: 0, failed_runs: 1 }, }, ]), - executions: { - m1: { - loading: false, - executions: [ - execution('exec-1', 'm1', { status: 'FAILURE', bindings: { 'p-depth': '1' } }), - execution('exec-2', 'm1', { status: 'SUCCESS', bindings: { 'p-depth': '2' } }), - execution('exec-3', 'm1', { status: 'FAILURE', bindings: { 'p-depth': '3' } }), - ], - }, - }, - onSubmitRuns, + executions: sweepRows('FAILURE', 'RUNNING', 'SUCCESS'), + unifiedRuns: { m1: failure() }, }); - expect(screen.getByTestId('restart-run-exec-1')).toBeInTheDocument(); - expect(screen.queryByTestId('restart-run-exec-2')).not.toBeInTheDocument(); - fireEvent.click(screen.getByTestId('restart-run-exec-3')); - await waitFor(() => expect(onSubmitRuns).toHaveBeenCalledWith('m1', 60)); + expect(screen.queryByRole('button', { name: /restart/i })).not.toBeInTheDocument(); + expect( + screen.getByText(/restart is offered when the others have finished/i), + ).toBeInTheDocument(); + }); + + it('carries the earlier run time and queue, and lets the time be changed', async () => { + const onRestartRuns = vi.fn().mockResolvedValue(undefined); + renderRuns({ + threadData: failedThread, + executions: failedRows, + unifiedRuns: { m1: failure({ model_result: { __max_minutes: 240, __queue: 'skx-dev' } }) }, + onRestartRuns, + }); + const minutes = screen.getByTestId('restart-minutes-m1'); + expect(minutes).toHaveValue(240); + fireEvent.change(minutes, { target: { value: '300' } }); + fireEvent.click(screen.getByRole('button', { name: 'Restart' })); + await waitFor(() => + expect(onRestartRuns).toHaveBeenCalledWith('m1', { maxMinutes: 300, queue: 'skx-dev' }), + ); + }); + + it('shows the default time that will be used when the earlier one was not kept', () => { + renderRuns({ + threadData: failedThread, + executions: failedRows, + unifiedRuns: { m1: failure() }, + }); + expect(screen.getByTestId('restart-minutes-m1')).toHaveValue(60); + expect(screen.getByText(/earlier run's time was not kept/i)).toBeInTheDocument(); + }); + + describe('publishing', () => { + const publisher = { + transform_spec_id: 'spec-1', + name: 'Publish', + catalog_tokens: ['ckan', 'stac'], + parameters: [], + can_publish: { ok: true, reason: null }, + }; + const planWithPublish = `em_${btoa(JSON.stringify({ publish: ['ckan', 'stac'] })) + .replace(/\+/g, '-') + .replace(/\//g, '_') + .replace(/=+$/, '')}.sig`; + + beforeEach(() => { + (globalThis.fetch as ReturnType).mockImplementation(async (url: string) => ({ + ok: true, + json: async () => + String(url).includes('/plans/publishers') ? { publishers: [publisher] } : {}, + })); + }); + + it('pre-selects what the earlier run published and sends it again', async () => { + const onRestartRuns = vi.fn().mockResolvedValue(undefined); + renderRuns({ + threadData: failedThread, + executions: failedRows, + unifiedRuns: { m1: failure({ plan_id: planWithPublish }) }, + onRestartRuns, + }); + expect(await screen.findByTestId('publish-catalog-m1')).toBeInTheDocument(); + expect(screen.getByTestId('publish-toggle-m1')).toBeChecked(); + fireEvent.click(screen.getByRole('button', { name: 'Restart' })); + await waitFor(() => expect(onRestartRuns).toHaveBeenCalled()); + expect(onRestartRuns.mock.calls[0]?.[1]).toMatchObject({ + publish: { tokens: ['ckan', 'stac'] }, + }); + }); + + it('sends no publish when the earlier run published nothing and none is chosen', async () => { + const onRestartRuns = vi.fn().mockResolvedValue(undefined); + renderRuns({ + threadData: failedThread, + executions: failedRows, + unifiedRuns: { m1: failure() }, + onRestartRuns, + }); + expect(await screen.findByTestId('publish-toggle-m1')).not.toBeChecked(); + fireEvent.click(screen.getByRole('button', { name: 'Restart' })); + await waitFor(() => expect(onRestartRuns).toHaveBeenCalled()); + expect(onRestartRuns.mock.calls[0]?.[1]).not.toHaveProperty('publish'); + }); + }); + + it('shows Restart as in flight when a send from the other step is running', () => { + renderRuns({ + threadData: failedThread, + executions: failedRows, + unifiedRuns: { m1: failure() }, + restartingModels: { m1: true }, + }); + expect(screen.getByRole('button', { name: /restarting/i })).toBeDisabled(); }); }); diff --git a/ui-react/src/pages/modeling/thread/useTapisResultKind.ts b/ui-react/src/pages/modeling/thread/useTapisResultKind.ts index fc046431..1a274c6b 100644 --- a/ui-react/src/pages/modeling/thread/useTapisResultKind.ts +++ b/ui-react/src/pages/modeling/thread/useTapisResultKind.ts @@ -1,23 +1,31 @@ /** - * useTapisResultKind — whether Tapis says a result location is a file or a folder. + * useTapisResultKind — whether Tapis says a result location is a file or a + * folder, and how big the file is. * * The Ensemble Manager lists a run with each result marked by Tapis; the name of - * the location is never used to guess. + * the location is never used to guess. The size comes from the same listing. */ import { useEffect, useState } from 'react'; -import { fetchExecutionListing, type ExecutionResultLocation } from '@/lib/ensemble-manager'; +import { + fetchExecutionListing, + type ExecutionFile, + type ExecutionResultLocation, +} from '@/lib/ensemble-manager'; + +interface Listing { + files: ExecutionFile[]; + results: ExecutionResultLocation[]; +} // Cells of one run ask for the same listing; share the request while it is in flight. -const inFlight = new Map>(); +const inFlight = new Map>(); -function loadResultKinds(api: string, executionId: string): Promise { +function loadListing(api: string, executionId: string): Promise { const key = `${api}|${executionId}`; let pending = inFlight.get(key); if (!pending) { - pending = fetchExecutionListing(api, executionId) - .then((listing) => listing.results) - .finally(() => inFlight.delete(key)); + pending = fetchExecutionListing(api, executionId).finally(() => inFlight.delete(key)); inFlight.set(key, pending); } return pending; @@ -25,30 +33,50 @@ function loadResultKinds(api: string, executionId: string): Promise('unknown'); +): TapisResultInfo { + const [info, setInfo] = useState({ kind: 'unknown', size: null }); useEffect(() => { if (!enabled) return; let cancelled = false; - setKind('unknown'); - loadResultKinds(ensembleManagerApi, executionId) - .then((results) => { + setInfo({ kind: 'unknown', size: null }); + loadListing(ensembleManagerApi, executionId) + .then(({ files, results }) => { if (cancelled) return; const match = results.find((result) => result.url === url); - setKind(match ? match.kind : 'error'); + const size = files.find((file) => file.url === url)?.size; + setInfo( + match + ? { kind: match.kind, size: typeof size === 'number' && size > 0 ? size : null } + : { kind: 'error', size: null }, + ); }) - .catch(() => !cancelled && setKind('error')); + .catch(() => !cancelled && setInfo({ kind: 'error', size: null })); return () => { cancelled = true; }; }, [ensembleManagerApi, executionId, url, enabled]); - return kind; + return info; +} + +/** Just the kind, for a result that needs no size. */ +export function useTapisResultKind( + ensembleManagerApi: string, + executionId: string, + url: string, + enabled = true, +): TapisResultKind { + return useTapisResultInfo(ensembleManagerApi, executionId, url, enabled).kind; }