Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wes-run-outputs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@elixir-cloud/wes": minor
---

Show run outputs with GA4GH IO Schema hints: `ecc-client-ga4gh-wes-run` gains `ioSchema`, `outputOptions`, `outputProvider` and `allowedSchemes`; with a schema, its Outputs tab shows the normalised outputs of a run that has ended through `ecc-client-ga4gh-wes-run-output` (titles, descriptions, viewers, downloads), with warnings for partial and non-conformant outputs and the normaliser's reports; without one, the raw outputs stay. `@elixir-cloud/wes/utils` exports the output normaliser (`normaliseOutputs`, `NormalisationError`, `FINAL_STATES`). `IoSchemaCheck` gains an optional `validateOutputs` (`OutputsValidator`): a validator set with `setIoSchemaValidator()` needs it for the normaliser.
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import React, { useMemo, useState } from 'react';
import { ECCClientGa4ghWesRun } from '@elixir-cloud/wes/react';
import type { RunLog, WesProvider } from '@elixir-cloud/wes/providers';
import PreviewLayout from '@/components/common/PreviewLayout';
import { ioFormExamples } from '@/components/packages/wes/ioFormExamples';
import {
DEMO_RUN,
exampleOutputProvider,
} from '@/components/packages/wes/runOutputExample';

const allowedSchemes = ['drs', 'https', 's3'];

/** The output directory of the demo run, as miniwdl sees it (made up). */
const LOCAL_DIR = '/data/miniwdl-runs/20261113_021212_io_schema_demo/out';

/** Outputs of the demo workflow as miniwdl reports them: local paths. */
const reported: Record<string, string> = {
'io_schema_demo.report': `${LOCAL_DIR}/report/report.html`,
'io_schema_demo.read_counts': `${LOCAL_DIR}/read_counts/read_counts.tsv`,
'io_schema_demo.filtered_bam': `${LOCAL_DIR}/filtered_bam/filtered.bam`,
'io_schema_demo.filtered_bam_index': `${LOCAL_DIR}/filtered_bam_index/filtered.bam.bai`,
};

const runs: Record<string, { label: string; log: RunLog }> = {
complete: {
label: 'Completed run',
log: {
run_id: 'demo-complete',
state: 'COMPLETE',
outputs: reported,
} as unknown as RunLog,
},
failed: {
label: 'Failed run (partial outputs)',
log: {
run_id: 'demo-failed',
state: 'EXECUTOR_ERROR',
outputs: {
'io_schema_demo.report': reported['io_schema_demo.report'],
'io_schema_demo.read_counts': reported['io_schema_demo.read_counts'],
},
} as unknown as RunLog,
},
};

/** A provider that returns one made-up run of the demo workflow. */
class DemoRunProvider implements WesProvider {
private log: RunLog;

constructor(log: RunLog) {
this.log = {
...log,
request: {
workflow_type: 'WDL',
workflow_type_version: '1.1',
workflow_url: 'https://example.org/demo.wdl',
workflow_params: {},
},
run_log: {},
task_logs: [],
} as unknown as RunLog;
}

async getRunLog() {
return this.log;
}

async getServiceInfo(): Promise<never> {
throw new Error('Not available in the demo.');
}

async runWorkflow(): Promise<never> {
throw new Error('Not available in the demo.');
}

async listRuns() {
return { runs: [] };
}

async getRunStatus(): Promise<never> {
throw new Error('Not available in the demo.');
}

async cancelRun(): Promise<never> {
throw new Error('Not available in the demo.');
}
}

export default function RunSchemaOutputsPreview() {
const [run, setRun] = useState('complete');
const provider = useMemo(() => new DemoRunProvider(runs[run].log), [run]);

return (
<PreviewLayout>
<div className='flex w-full flex-col gap-4'>
<label className='flex items-center gap-2 text-sm'>
Run
<select
className='rounded-md border px-2 py-1'
value={run}
onChange={(e) => setRun(e.target.value)}
>
{Object.entries(runs).map(([key, { label }]) => (
<option key={key} value={key}>
{label}
</option>
))}
</select>
</label>
<ECCClientGa4ghWesRun
key={run}
provider={provider}
runId={runs[run].log.run_id}
ioSchema={ioFormExamples.demo.schema}
outputOptions={{ outputDir: DEMO_RUN, localDir: LOCAL_DIR }}
outputProvider={exampleOutputProvider}
allowedSchemes={allowedSchemes}
/>
</div>
</PreviewLayout>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { withBasePath } from '@/utils/basePath';

export const PROFILE_COMMIT = '2c3dc49ad89f0a556272f160369a2a2d7a21dac3';

const DEMO_RUN =
export const DEMO_RUN =
's3://conquest/v1/workflow-runs/9f1c2e4a-5b6d-4e7f-8a9b-0c1d2e3f4a5b/outputs/files/miniwdl-runs/20261113_021212_io_schema_demo/out';

/** Schemas of the outputs (the `properties` of `outputs`). */
Expand Down
71 changes: 67 additions & 4 deletions apps/documentation/pages/docs/wes/components/run.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Callout, Tabs } from 'nextra/components'
import ComponentName from '@/components/common/ComponentName'
import RunPreview from '@/components/packages/wes/RunPreview'
import RunSchemaOutputsPreview from '@/components/packages/wes/RunSchemaOutputsPreview'

# EccClientGa4ghWesRun Component

Expand Down Expand Up @@ -77,12 +78,74 @@ This example shows the details for a specific workflow run ID.
</Tabs.Tab>
</Tabs>

### Outputs with an IO schema

Without an IO schema, the Outputs tab shows `RunLog.outputs` as the server reports it. With the workflow's [IO schema](../io-schema) (`ioSchema`), it shows the [normalised outputs](../io-schema#run-outputs) of a run that has ended: each output by its title and description, with its viewer hint (a table, an HTML report in a sandboxed frame) and download, as [`ecc-client-ga4gh-wes-run-output`](./run-output) shows it. Only URIs with a scheme from `allowedSchemes` are fetched or offered for download, through `outputProvider`.

- While the run hasn't ended, the tab says that outputs are shown when it has (without the raw outputs).
- Outputs of a run that didn't complete are shown with a warning that they may be incomplete; invalid ones are left out and named.
- Outputs that don't match the schema are kept, with a warning and the errors.
- Outputs that the engine reports but the schema doesn't declare, and listed files that no output found ("Other files"), are shown without a description; outputs that weren't produced are named.
- Outputs that can't be converted (e.g. files that can't be located, or values nested too deeply), globs that match several files, and listed files with unsafe paths are named in notices.
- If the outputs can't be normalised (e.g. an unsupported shape, or a schema that doesn't conform to the profile), the tab says why and shows them as reported.

Where the server keeps the run's files is deployment knowledge: `outputOptions` gives it (`outputDir`, `localDir`, `files`), or a function of the run log that returns it, also as a promise (e.g. to fetch a listing). The outputs are normalised again whenever `ioSchema` or `outputOptions` changes, so pass the same object or function between renders (in React, define it outside the component or memoise it). The normaliser and the output element are loaded when they are first needed.

This preview uses a provider that returns a run of the profile's demo workflow (WDL), as miniwdl reports it (local paths), from a completed or a failed run:

<Tabs items={['Preview', 'React']}>
<Tabs.Tab>
<RunSchemaOutputsPreview />
</Tabs.Tab>

<Tabs.Tab>
```tsx showLineNumbers copy filename="run-outputs.tsx"
import React from 'react';
import { ECCClientGa4ghWesRun } from '@elixir-cloud/wes/react';
import { RestWesProvider } from '@elixir-cloud/wes/providers';
import type { RunLog, WesOutputProvider } from '@elixir-cloud/wes/providers';

// Defined once, so that the outputs aren't normalised on every render
const outputOptions = (runLog: RunLog) => ({
outputDir: `s3://bucket/runs/${runLog.run_id}`,
});

export default function RunOutputs({
schema,
outputProvider,
}: {
schema: object;
outputProvider: WesOutputProvider;
}) {
const provider = new RestWesProvider(
'https://wes.example.com/ga4gh/wes/v1'
);

return (
<ECCClientGa4ghWesRun
provider={provider}
runId="placeholder-run-id"
ioSchema={schema}
outputOptions={outputOptions}
outputProvider={outputProvider}
allowedSchemes={['drs', 'https', 's3']}
/>
);
}
```
</Tabs.Tab>
</Tabs>

## Properties

| Property | Type | Default | Description |
|------------|---------------------------|---------|--------------------------------------------------------------------------------|
| `runId` | `string` | `""` | ID of the workflow run to display details for. |
| `provider` | `WesProvider` | `null` | Data provider for fetching run data (see [Providers](/docs/wes/providers)) |
| Property | Type | Default | Description |
|------------------|---------------------------|-------------|--------------------------------------------------------------------------------|
| `runId` | `string` | `""` | ID of the workflow run to display details for. |
| `provider` | `WesProvider` | `null` | Data provider for fetching run data (see [Providers](/docs/wes/providers)) |
| `ioSchema` | `object` | `undefined` | The workflow's IO schema (GA4GH IO Schema Profile 0.3.0); shows the normalised outputs |
| `outputOptions` | `OutputOptions \| (runLog) => OutputOptions \| Promise<OutputOptions>` | `undefined` | Where the run keeps its files: `outputDir` (URI), `localDir` (path as the engine sees it), `files` (a listing) |
| `outputProvider` | `WesOutputProvider` | `undefined` | Fetches output files for viewers and returns download URLs (see [Run Output](./run-output)) |
| `allowedSchemes` | `string[]` | `['drs', 'https']` | URI schemes of outputs that may be fetched or downloaded |

## Events

Expand Down
23 changes: 23 additions & 0 deletions apps/documentation/pages/docs/wes/io-schema.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@ const request = await buildRunRequest(schema, values, {

The translation passes the profile's test vectors (`tests/vectors/wes-params`, `workflow-urls` and `trs-files`). It needs a validator that can check subschemas (`validateAt` of the check result), and refuses schemas that it can't follow: references that don't resolve within the document, references and branches inside embedded `$id` resources, and `$dynamicRef`. GALAXY workflows have no binding in profile 0.3.0.

## Run outputs

`normaliseOutputs()` from `@elixir-cloud/wes/utils` builds the [normalised outputs object](https://ga4gh-io-schema.readthedocs.io/en/latest/specification/outputs/#the-normalised-outputs-object) of a WES run from what the server reports, keyed by the outputs of an IO schema, which [`ecc-client-ga4gh-wes-run`](./components/run#outputs-with-an-io-schema) shows:

```typescript
import { normaliseOutputs } from '@elixir-cloud/wes/utils';

const result = await normaliseOutputs(schema, runLog, {
outputDir: 's3://bucket/runs/7', // where the server keeps the run's files
localDir: '/data/runs/7/out', // the same directory as the engine sees it
});
// result.conformance: 'conformant' | 'non-conformant' | 'partial'
// result.outputs: { report: 's3://bucket/runs/7/report/report.html', ... }
```

- Outputs are found **by name** (the property name, or `name` of `x-ga4gh-parameter`, qualified with the entry point for WDL), else **by `x-ga4gh-output-glob`** among the files that the server lists: Sapporo's list of files, WESkit's `filesystem`, or `files` of the options. CWL `File` and `Directory` objects give their `location`; paths under `localDir`, and relative paths, become URIs under `outputDir` (each segment percent-encoded); other paths are reported as `unconverted`.
- Listed entries are checked before globs are matched: absolute paths, `.`, `..` and empty segments, backslashes, control characters, a colon in the first segment, URIs outside `outputDir`, with a query or fragment, or with an encoded `/` are skipped and reported (`skippedFiles`, without user information, query and fragment, which may carry credentials). WESkit's presigned URLs (`S3`) are dropped.
- The object is validated against `outputs` for a run that completed (`non-conformant` outputs are kept as they are, with `errors`); for a run that ended otherwise, output by output, and invalid outputs are left out (`removed`). File references must be absolute URIs with one of their `schemes`.
- Outputs that the schema doesn't declare (`undeclared`), files that no output found (`unmatchedFiles`) and globs of one file with several matches (`ambiguous`) are reported, never dropped silently.
- A run that hasn't ended, a run log of an unsupported shape and inconsistent options raise a `NormalisationError` (with `schemaErrors` for a schema that doesn't conform to the profile).

The normaliser never fetches anything, and it doesn't check output URIs against the deployment's allow-list: [`ecc-client-ga4gh-wes-run-output`](./components/run-output) does that before it shows or fetches a file. It passes the profile's test vectors (`tests/vectors/wes-outputs`) and needs a validator that validates outputs (`validateOutputs` of the check result). Unlike the reference implementation, it checks the `schemes` of file references only in the shapes that values are converted by (files, lists, records, files keyed by name, a single branch besides `null`, `allOf`), not inside other unions. It doesn't follow references into embedded `$id` resources (the value is then kept as reported, for validation to report), and refuses values nested more than 64 levels deep (`unconverted`).

## Descriptions

Titles, descriptions and `enum` values of IO schemas are always shown as text, never as markup.
Expand Down
58 changes: 56 additions & 2 deletions packages/ecc-client-ga4gh-wes/scripts/sync-io-schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
* - `src/io-schema/profile.ts`: the meta-schema and its vocabularies, with
* the commit and the version of the profile;
* - `src/io-schema/tests/fixtures/*.ts`: the conformance suite, the test
* vectors (file reference values, engine bindings, workflow URLs and TRS
* files) and the example schemas, for the tests and the demos.
* vectors (file reference values, engine bindings, workflow URLs, TRS
* files and outputs of runs) and the example schemas, for the tests and
* the demos.
*
* Usage, from the package directory:
*
Expand Down Expand Up @@ -173,6 +174,59 @@ export const WES_PARAMS_CASES: WesParamsCase[] = ${json(
`
);

/**
* The cases of `tests/vectors/<kind>/<case>/`, each with its JSON files by
* name (without `.json`), sorted by name.
*/
const flatCaseDirectories = (kind) =>
readdirSync(path.join(checkout, "tests", "vectors", kind), {
withFileTypes: true,
})
.filter((entry) => entry.isDirectory())
.map((entry) => entry.name)
.sort()
.map((name) => {
const files = {};
const at = ["tests", "vectors", kind, name];
for (const file of readdirSync(path.join(checkout, ...at))
.filter((entry) => entry.endsWith(".json"))
.sort()) {
files[file.replace(/\.json$/, "")] = readJson(...at, file);
}
return { name, ...files };
});

write(
"src/io-schema/tests/fixtures/wes-outputs.ts",
`${header(
"Test vectors of the output normaliser (`tests/vectors/wes-outputs/`)."
)}
export interface WesOutputsCase {
name: string;
schema: Record<string, unknown>;
run_log: Record<string, unknown>;
options?: { outputDir?: string; localDir?: string; files?: unknown[] };
/** The expected result, or else \`error\` */
expected?: {
description: string;
conformance: string;
outputs: Record<string, unknown>;
removed?: string[];
ambiguous?: Record<string, string[]>;
unconverted?: string[];
undeclared?: string[];
unmatchedFiles?: string[];
skippedFiles?: unknown[];
};
error?: Record<string, unknown>;
}

export const WES_OUTPUTS_CASES: WesOutputsCase[] = ${json(
flatCaseDirectories("wes-outputs")
)};
`
);

write(
"src/io-schema/tests/fixtures/trs.ts",
`${header(
Expand Down
Loading