Gobernanza: execution, models (training, run monitor, checks, lineage, bundles, interpretability), EEG studies

Share one execution selection across training and analysis. Use the first
configured scheduler for a remote default and let the API validate typed
addresses. Suspend health polling when the document is hidden. Poll each
run serially, retry status reads on transient errors, and compute ETA from
completed items and elapsed seconds.

Reuse the Conectar Formly types with nullable fields and inlined references.
Omit the optional cohort when its name is blank, and offer the declared
input sets in a datalist with filename validation before upload. Identify
the versions created by a training run from its version log lines, then
check each exact version before promotion. Use native dialogs for checks,
lineage, bulk confirmation and preview. Recheck promotion eligibility before
submitting changes, and list results per version.

Verify bundle hashes using SubtleCrypto before upload. Use blob downloads
for bundles and reports. Read age centiles from the curve endpoint and keep
the count-rate reference line from the report. Join study metrics by code
and regional values by feature, skipping absent ages and values. Use one
Plotly trace per association pair and scale the forest plot height by row
count.

Preflight the TEA pipeline before staging EDFs, then start the pipeline once
for the batch. Refresh studies, their overlays and summary on completed
runs. Page through analyze history to compare its end times against the
latest tea_eeg result. The branch base lacks export/pdf.ts, so the preview
uses the specified TODO and omits the PDF action.

Added Vitest coverage for execution and run polling, ETA and cancellation,
training schema, version actions, bundle digest verification, study overlays
and the association forest. Ruff check, Ruff format --check, Prettier,
strict Angular and TypeScript diagnostics for Gobernanza and git diff --check
passed. npm ci, ng build and vitest run are assigned to the test machines.
This commit is contained in:
2026-11-30 13:53:24 -06:00
parent 5d03f333f7
commit e2d1c9f277
17 changed files with 2202 additions and 265 deletions
+127
View File
@@ -0,0 +1,127 @@
import { Component, inject, input, model, output, signal } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { Api } from '../api/api';
import { exportModels, type ExportModels$Params } from '../api/fn/models/export-models';
import { importModels } from '../api/fn/models/import-models';
import type { Domain } from '../api/models/domain';
import { errorText } from './run-monitor';
export async function verifiedImport<T>(
file: Blob,
expected: string,
upload: (sha256: string) => Promise<T>,
): Promise<T> {
const digest = await crypto.subtle.digest('SHA-256', await file.arrayBuffer());
const sha256 = Array.from(new Uint8Array(digest), (byte) =>
byte.toString(16).padStart(2, '0'),
).join('');
if (expected.trim().toLowerCase() !== sha256) {
throw new Error('El SHA-256 del archivo no coincide con el esperado.');
}
return upload(sha256);
}
export function download(blob: Blob, filename: string): void {
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = filename;
link.click();
setTimeout(() => URL.revokeObjectURL(url), 0);
}
@Component({
selector: 'app-governance-bundles',
imports: [FormsModule, MatButtonModule],
template: `
<section class="card">
<h3>Bundles</h3>
<form (ngSubmit)="export()">
<label
>Versiones
<select name="versions" [(ngModel)]="selection">
<option value="champion">En producción</option>
<option value="latest">Últimas</option>
<option value="all">Todas</option>
</select>
</label>
<button mat-stroked-button type="submit" [disabled]="exporting()">Exportar bundle</button>
</form>
@if (exportedHash()) {
<p>
SHA-256 <code>{{ exportedHash() }}</code>
</p>
}
<form (ngSubmit)="import(file)">
<label>Archivo ZIP <input #file type="file" accept=".zip" required /></label>
<label>SHA-256 esperado <input name="hash" [(ngModel)]="hash" required /></label>
<button mat-stroked-button type="submit" [disabled]="importing() || disabled()">
Importar bundle
</button>
</form>
@if (message()) {
<p role="alert">{{ message() }}</p>
}
</section>
`,
})
export class Bundles {
private readonly api = inject(Api);
readonly domain = input.required<Domain>();
readonly disabled = input(false);
readonly started = output<string>();
protected readonly selection = signal<NonNullable<ExportModels$Params['versions']>>('champion');
protected readonly exportedHash = signal('');
protected readonly hash = signal('');
protected readonly message = signal('');
protected readonly exporting = signal(false);
readonly importing = model(false);
protected async export(): Promise<void> {
this.exporting.set(true);
this.message.set('');
this.exportedHash.set('');
const domain = this.domain();
try {
const response = await this.api.invoke$Response(exportModels, {
domain,
versions: this.selection(),
});
const sha256 = response.headers.get('X-Bundle-Sha256') ?? '';
this.exportedHash.set(sha256);
download(response.body, `${domain}-models-${sha256.slice(0, 12)}.zip`);
} catch (error) {
if (error instanceof Error && 'error' in error && error.error instanceof Blob) {
this.message.set(await error.error.text());
} else {
this.message.set(errorText(error));
}
} finally {
this.exporting.set(false);
}
}
protected async import(input: HTMLInputElement): Promise<void> {
const file = input.files?.[0];
if (!file || this.importing() || this.disabled()) return;
this.importing.set(true);
this.message.set('');
const domain = this.domain();
try {
const { run_id } = await verifiedImport(file, this.hash(), (sha256) =>
this.api.invoke(importModels, {
domain,
sha256,
body: { file: file as unknown as string },
}),
);
input.value = '';
if (domain === this.domain()) this.started.emit(run_id);
} catch (error) {
this.message.set(errorText(error));
} finally {
this.importing.set(false);
}
}
}