@datagrok/hit-triage 1.10.8 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.grokignore +2 -0
- package/.turbo/turbo-build.log +24 -6
- package/.vscode/settings.json +16 -0
- package/CHANGELOG.md +80 -1
- package/CLAUDE.md +87 -10
- package/README_HD.md +14 -14
- package/README_HT.md +6 -6
- package/README_PH.md +110 -0
- package/bdd/bdd.config.json +3 -0
- package/bdd/bindings/campaign.ts +626 -0
- package/bdd/bindings/hit-design.ts +93 -0
- package/bdd/bindings/landing.ts +839 -0
- package/bdd/bindings/pepti-hit.ts +35 -0
- package/bdd/features/campaign/crumbs.feature +22 -0
- package/bdd/features/campaign/grid.feature +56 -0
- package/bdd/features/campaign/merge.feature +105 -0
- package/bdd/features/campaign/molecule-vid.feature +40 -0
- package/bdd/features/campaign/permissions.feature +46 -0
- package/bdd/features/campaign/progress-tracker.feature +89 -0
- package/bdd/features/campaign/refresh-hint.feature +33 -0
- package/bdd/features/campaign/ribbon.feature +49 -0
- package/bdd/features/campaign/stage-choices.feature +39 -0
- package/bdd/features/campaign/submit.feature +135 -0
- package/bdd/features/campaign/tracker-cards.feature +46 -0
- package/bdd/features/campaign/view-only.feature +37 -0
- package/bdd/features/hit-design/campaign-column-metadata.feature +61 -0
- package/bdd/features/landing/campaign-deep-links.feature +61 -0
- package/bdd/features/landing/hit-design-campaigns-fixes.feature +116 -0
- package/bdd/features/landing/hit-design-campaigns.feature +153 -0
- package/bdd/features/landing/hit-triage-campaigns.feature +99 -0
- package/bdd/features/landing/new-campaign.feature +69 -0
- package/bdd/features/landing/pep-triage-campaigns.feature +41 -0
- package/bdd/features/landing/pepti-hit-landing.feature +132 -0
- package/bdd/features/pepti-hit/helm-edit.feature +47 -0
- package/bdd/features/templates/template-editor.feature +130 -0
- package/bdd/features/templates/template-picker.feature +112 -0
- package/bdd/features/templates/triage-forms.feature +59 -0
- package/bdd/fixtures/bar-chart.layout +1 -0
- package/bdd/fixtures/merge-local.csv +2 -0
- package/bdd/generated/campaign/crumbs.test.ts +33 -0
- package/bdd/generated/campaign/grid.test.ts +79 -0
- package/bdd/generated/campaign/merge.test.ts +134 -0
- package/bdd/generated/campaign/molecule-vid.test.ts +52 -0
- package/bdd/generated/campaign/permissions.test.ts +58 -0
- package/bdd/generated/campaign/progress-tracker.test.ts +129 -0
- package/bdd/generated/campaign/refresh-hint.test.ts +44 -0
- package/bdd/generated/campaign/ribbon.test.ts +65 -0
- package/bdd/generated/campaign/stage-choices.test.ts +55 -0
- package/bdd/generated/campaign/submit.test.ts +167 -0
- package/bdd/generated/campaign/tracker-cards.test.ts +49 -0
- package/bdd/generated/campaign/view-only.test.ts +51 -0
- package/bdd/generated/hit-design/campaign-column-metadata.test.ts +76 -0
- package/bdd/generated/landing/campaign-deep-links.test.ts +68 -0
- package/bdd/generated/landing/hit-design-campaigns-fixes.test.ts +99 -0
- package/bdd/generated/landing/hit-design-campaigns.test.ts +160 -0
- package/bdd/generated/landing/hit-triage-campaigns.test.ts +107 -0
- package/bdd/generated/landing/new-campaign.test.ts +78 -0
- package/bdd/generated/landing/pep-triage-campaigns.test.ts +52 -0
- package/bdd/generated/landing/pepti-hit-landing.test.ts +130 -0
- package/bdd/generated/pepti-hit/helm-edit.test.ts +64 -0
- package/bdd/generated/templates/template-editor.test.ts +137 -0
- package/bdd/generated/templates/template-picker.test.ts +119 -0
- package/bdd/generated/templates/triage-forms.test.ts +68 -0
- package/bdd/package.json +1 -0
- package/bdd/tsconfig.json +13 -0
- package/css/hit-triage.css +27 -23
- package/dist/package-test.js +690 -4
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +318 -73
- package/dist/package.js.map +1 -1
- package/package.json +15 -8
- package/queries/locks.sql +37 -0
- package/src/app/accordeons/layout-input.ts +52 -44
- package/src/app/accordeons/new-campaign-accordeon.ts +91 -54
- package/src/app/accordeons/new-hit-design-campaign-accordeon.ts +3 -67
- package/src/app/accordeons/new-pep-triage-template-accordeon.ts +39 -41
- package/src/app/accordeons/new-template-accordeon.ts +41 -24
- package/src/app/ai/view-functions.ts +22 -19
- package/src/app/base-view.ts +99 -8
- package/src/app/consts.ts +8 -5
- package/src/app/dialogs/functions-dialog.ts +14 -9
- package/src/app/dialogs/merge-table-dialog.ts +181 -325
- package/src/app/hit-app-base.ts +61 -90
- package/src/app/hit-design-app.ts +492 -882
- package/src/app/hit-design-views/info-view.ts +57 -407
- package/src/app/hit-design-views/submit-view.ts +216 -111
- package/src/app/hit-design-views/tiles-view.ts +168 -123
- package/src/app/hit-design-views/utils.css +0 -8
- package/src/app/hit-triage-app.ts +69 -38
- package/src/app/hit-triage-views/info-view.ts +70 -371
- package/src/app/pep-triage-app.ts +2 -2
- package/src/app/pep-triage-views/info-view.ts +42 -83
- package/src/app/pepti-hit-app.ts +32 -183
- package/src/app/pepti-hits-views/info-view.ts +15 -37
- package/src/app/shared/campaign-catalog.ts +408 -0
- package/src/app/shared/campaign-session.ts +557 -0
- package/src/app/shared/compute-editor.ts +274 -0
- package/src/app/shared/hit-home.ts +45 -0
- package/src/app/shared/new-campaign-form.ts +90 -0
- package/src/app/shared/permissions-editor.ts +93 -0
- package/src/app/shared/template-editor.ts +331 -0
- package/src/app/shared/template-picker.ts +154 -0
- package/src/app/types.ts +2 -0
- package/src/app/utils/merge-table.ts +183 -78
- package/src/app/utils.ts +34 -325
- package/src/package-api.ts +29 -8
- package/src/package-test.ts +17 -2
- package/src/package.g.ts +12 -8
- package/src/package.ts +19 -7
- package/src/tests/ai.ts +244 -0
- package/src/tests/campaign-layout.ts +82 -0
- package/src/tests/campaign-session.ts +168 -0
- package/src/tests/campaigns.ts +23 -0
- package/src/tests/catalog.ts +156 -0
- package/src/tests/compat.ts +482 -0
- package/src/tests/compute.ts +165 -0
- package/src/tests/fixtures.ts +359 -0
- package/src/tests/merge.ts +149 -0
- package/src/tests/owners.ts +11 -0
- package/src/tests/save-lock.ts +932 -0
- package/src/tests/storage.ts +106 -0
- package/src/tests/template-editor.ts +538 -0
- package/src/tests/templates.ts +143 -0
- package/src/tests/triage-start.ts +81 -0
- package/src/tests/u2-guards.ts +384 -0
- package/src/tests/vid.ts +77 -0
- package/tsconfig.json +3 -0
- package/src/app/accordeons/new-hit-design-template-accordeon.ts +0 -238
- package/src/app/dialogs/permissions-dialog.ts +0 -66
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
import * as grok from 'datagrok-api/grok';
|
|
3
|
+
import * as DG from 'datagrok-api/dg';
|
|
4
|
+
import {category, expect, test, waitUntil} from '@datagrok-libraries/test/src/test';
|
|
5
|
+
import {calculateColumns} from '../app/utils/calculate-single-cell';
|
|
6
|
+
import {designCampaign, designCsv, expectSame, noComputeTemplate, Sandbox} from './fixtures';
|
|
7
|
+
|
|
8
|
+
const compute = () => document.querySelector<HTMLElement>('[data-u2-name="compute"]');
|
|
9
|
+
|
|
10
|
+
/** A compute function of this test alone, registered in the page as `core:<name>`; [run] gets the table it is handed
|
|
11
|
+
* and adds its column under a free name, as Chem's functions do. The molecules come as the column's name: a function
|
|
12
|
+
* registered in the page does not resolve a column from it. */
|
|
13
|
+
function testFunction(run: (table: DG.DataFrame) => void): string {
|
|
14
|
+
const name = `zzb3Compute${DG.Utils.randomString(8)}`;
|
|
15
|
+
grok.functions.register({signature: `void ${name}(dataframe table, string molecules)`, run});
|
|
16
|
+
return `core:${name}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function designTable(): DG.DataFrame {
|
|
20
|
+
const df = DG.DataFrame.fromCsv(designCsv);
|
|
21
|
+
df.col('Molecule')!.semType = DG.SEMTYPE.MOLECULE;
|
|
22
|
+
return df;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function computeButton(text: string): HTMLButtonElement | undefined {
|
|
26
|
+
return Array.from(compute()?.querySelectorAll<HTMLButtonElement>('button') ?? [])
|
|
27
|
+
.find((b) => b.textContent?.trim() === text);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
category('Campaign view: compute', () => {
|
|
31
|
+
test('Calculate additional properties shows every function\'s settings while a table without a name is open', async () => {
|
|
32
|
+
const sb = await Sandbox.create('compute');
|
|
33
|
+
const nameless = DG.DataFrame.fromColumns([DG.Column.fromStrings('a', ['x'])]);
|
|
34
|
+
try {
|
|
35
|
+
const t = noComputeTemplate('ZZB3 Compute', 'ZZB3');
|
|
36
|
+
await sb.writeTemplate(t);
|
|
37
|
+
await sb.writeCampaign(designCampaign(sb, 'ZZB3-1', t, {version: 1}), designCsv);
|
|
38
|
+
const app = await sb.hitDesign();
|
|
39
|
+
await sb.openDesign(app, 'ZZB3-1');
|
|
40
|
+
grok.shell.addTable(nameless);
|
|
41
|
+
nameless.name = null as unknown as string;
|
|
42
|
+
app.editCompute();
|
|
43
|
+
await waitUntil(() => compute() != null, 'the compute dialog did not open', 10000);
|
|
44
|
+
const rows = Array.from(compute()!.querySelectorAll<HTMLElement>('[role="option"]'));
|
|
45
|
+
expect(rows.length > 1, true, 'the dialog lists functions');
|
|
46
|
+
for (const row of rows)
|
|
47
|
+
row.click();
|
|
48
|
+
expectSame(Array.from(compute()!.querySelectorAll('[role="region"] [data-u2="readonly-field"] .u2-param-source-error'),
|
|
49
|
+
(el) => el.textContent), [], 'the settings that could not be shown');
|
|
50
|
+
computeButton('CANCEL')?.click();
|
|
51
|
+
} finally {
|
|
52
|
+
grok.shell.closeTable(nameless);
|
|
53
|
+
await sb.dispose();
|
|
54
|
+
}
|
|
55
|
+
}, {timeout: 120000});
|
|
56
|
+
|
|
57
|
+
test('a calculation over the table names its columns after the molecule column and saves no hidden column', async () => {
|
|
58
|
+
const sb = await Sandbox.create('compute');
|
|
59
|
+
try {
|
|
60
|
+
const t = noComputeTemplate('ZZB3 Compute', 'ZZB3');
|
|
61
|
+
await sb.writeTemplate(t);
|
|
62
|
+
await sb.writeCampaign(designCampaign(sb, 'ZZB3-1', t, {version: 1}), designCsv);
|
|
63
|
+
const app = await sb.hitDesign();
|
|
64
|
+
await sb.openDesign(app, 'ZZB3-1');
|
|
65
|
+
const df = app.dataFrame!;
|
|
66
|
+
// what Chem keeps once a filter or a search read the molecules
|
|
67
|
+
const cache = df.columns.addNewString('~Molecule.canonicalSmiles');
|
|
68
|
+
cache.init((i) => df.get('Molecule', i));
|
|
69
|
+
cache.semType = DG.SEMTYPE.MOLECULE;
|
|
70
|
+
app.editCompute();
|
|
71
|
+
await waitUntil(() => computeButton('OK')?.disabled === false, 'the compute dialog never let OK go', 30000);
|
|
72
|
+
const box = Array.from(compute()!.querySelectorAll('[role="option"]'))
|
|
73
|
+
.find((r) => r.textContent?.trim() === 'Pharmacophores')?.querySelector<HTMLInputElement>('input[type="checkbox"]');
|
|
74
|
+
expect(box != null, true, 'Chem\'s Pharmacophores is offered');
|
|
75
|
+
box!.click();
|
|
76
|
+
computeButton('OK')!.click();
|
|
77
|
+
await waitUntil(() => app.campaign?.version === 2 && !app.isSaving, 'the calculation was not saved', 60000);
|
|
78
|
+
const calculated = df.columns.names().filter((n) => n.startsWith('Acceptor'));
|
|
79
|
+
expectSame(calculated, ['Acceptor (Molecule)'], 'the calculated column, named after the molecule column');
|
|
80
|
+
expect(app.molColName, 'Molecule', 'the molecule column');
|
|
81
|
+
const saved = await grok.dapi.files.readCsv(sb.savePath('ZZB3-1'));
|
|
82
|
+
expectSame(saved.columns.names().filter((n) => n.includes('~')), [], 'columns of the saved table naming a hidden one');
|
|
83
|
+
const json = await sb.readCampaign('ZZB3-1');
|
|
84
|
+
expectSame([...Object.keys(json.columnSemTypes), ...Object.keys(json.columnTypes), ...Object.keys(json.columnTags)]
|
|
85
|
+
.filter((n) => n.includes('~')), [], 'columns campaign.json names that are hidden ones');
|
|
86
|
+
} finally {
|
|
87
|
+
await sb.dispose();
|
|
88
|
+
}
|
|
89
|
+
}, {timeout: 180000});
|
|
90
|
+
|
|
91
|
+
test('a hidden column in a campaign\'s table is dropped on open and is never its molecule column', async () => {
|
|
92
|
+
const sb = await Sandbox.create('compute');
|
|
93
|
+
try {
|
|
94
|
+
const t = noComputeTemplate('ZZB3 Compute', 'ZZB3');
|
|
95
|
+
await sb.writeTemplate(t);
|
|
96
|
+
await sb.writeCampaign(designCampaign(sb, 'ZZB3-1', t, {version: 1,
|
|
97
|
+
columnSemTypes: {'~Molecule.canonicalSmiles': 'Molecule', 'Molecule': 'Molecule'}}),
|
|
98
|
+
'~Molecule.canonicalSmiles,Molecule,Stage,V-iD,Note\nCCO,CCO,Idea,,first\nc1ccccc1,c1ccccc1,Made,,second\n');
|
|
99
|
+
const app = await sb.hitDesign();
|
|
100
|
+
await sb.openDesign(app, 'ZZB3-1');
|
|
101
|
+
expect(app.molColName, 'Molecule', 'the molecule column');
|
|
102
|
+
expectSame(app.dataFrame!.columns.names(), ['Molecule', 'Stage', 'V-iD', 'Note'], 'the columns the campaign opens with');
|
|
103
|
+
} finally {
|
|
104
|
+
await sb.dispose();
|
|
105
|
+
}
|
|
106
|
+
}, {timeout: 120000});
|
|
107
|
+
|
|
108
|
+
test('a calculation over the table tells its grid and filters that the values changed', async () => {
|
|
109
|
+
const df = designTable();
|
|
110
|
+
const fn = testFunction((table) => table.columns.addNewInt(table.columns.getUnusedName('ZZB3 length'))
|
|
111
|
+
.init((i) => (table.get('Molecule', i) as string).length));
|
|
112
|
+
await calculateColumns({descriptors: [], externals: {[fn]: {}}}, df, 'Molecule');
|
|
113
|
+
expectSame(df.col('ZZB3 length')?.toList(), [3, 8], 'the first calculation');
|
|
114
|
+
df.set('Molecule', 0, 'CCCO');
|
|
115
|
+
let changed = 0;
|
|
116
|
+
const sub = df.onValuesChanged.subscribe(() => changed++);
|
|
117
|
+
try {
|
|
118
|
+
await calculateColumns({descriptors: [], externals: {[fn]: {}}}, df, 'Molecule');
|
|
119
|
+
} finally {
|
|
120
|
+
sub.unsubscribe();
|
|
121
|
+
}
|
|
122
|
+
expectSame(df.col('ZZB3 length')?.toList(), [4, 8], 'the column filled again in place');
|
|
123
|
+
expect(changed > 0, true, 'the table said its values changed');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('the functions read the table\'s other columns, never a hidden one; run again, they fill their own columns', async () => {
|
|
127
|
+
const df = designTable();
|
|
128
|
+
const cache = df.columns.addNewString('~Molecule.canonicalSmiles');
|
|
129
|
+
cache.init((i) => df.get('Molecule', i));
|
|
130
|
+
const seen: string[][] = [];
|
|
131
|
+
const fn = testFunction((table) => {
|
|
132
|
+
seen.push(table.columns.names());
|
|
133
|
+
table.columns.addNewString(table.columns.getUnusedName('Note length')).init((i) => `${table.get('Note', i)}`.length.toString());
|
|
134
|
+
});
|
|
135
|
+
await calculateColumns({descriptors: [], externals: {[fn]: {}}}, df, 'Molecule');
|
|
136
|
+
expectSame(seen[0], ['Molecule', 'Stage', 'V-iD', 'Note'], 'the columns the function is handed');
|
|
137
|
+
expectSame(df.col('Note length')?.toList(), ['5', '6'], 'the column made from the notes');
|
|
138
|
+
df.set('Note', 1, 'the second one');
|
|
139
|
+
await calculateColumns({descriptors: [], externals: {[fn]: {}}}, df, 'Molecule');
|
|
140
|
+
expectSame(df.columns.names(), ['Molecule', 'Stage', 'V-iD', 'Note', '~Molecule.canonicalSmiles', 'Note length'],
|
|
141
|
+
'the columns after the second calculation');
|
|
142
|
+
expectSame(df.col('Note length')?.toList(), ['5', '14'], 'the column filled again from the notes');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('fractions calculated for an integer column fill it where it is, its filter and its viewers kept', async () => {
|
|
146
|
+
const df = designTable();
|
|
147
|
+
df.columns.insert(DG.Column.fromInt32Array('MW', new Int32Array([1, 2])), 1);
|
|
148
|
+
const view = grok.shell.addTableView(df);
|
|
149
|
+
try {
|
|
150
|
+
const plot = view.scatterPlot({x: 'MW', y: 'MW'});
|
|
151
|
+
const filters = view.getFiltersGroup({createDefaultFilters: false});
|
|
152
|
+
filters.updateOrAdd({type: DG.FILTER_TYPE.HISTOGRAM, column: 'MW', min: 1, max: 2});
|
|
153
|
+
await waitUntil(() => filters.getStates('MW', DG.FILTER_TYPE.HISTOGRAM).length === 1, 'the filter on MW was not added', 5000);
|
|
154
|
+
const fn = testFunction((table) => table.columns.addNewFloat(table.columns.getUnusedName('MW')).init((i) => [46.25, 78.5][i]));
|
|
155
|
+
await calculateColumns({descriptors: [], externals: {[fn]: {}}}, df, 'Molecule');
|
|
156
|
+
expectSame(df.col('MW')?.toList(), [46.25, 78.5], 'the calculated values');
|
|
157
|
+
expect(filters.getStates('MW', DG.FILTER_TYPE.HISTOGRAM).length, 1, 'filters on MW');
|
|
158
|
+
expect(plot.props.xColumnName, 'MW', 'the scatter plot\'s x');
|
|
159
|
+
expectSame(df.columns.names(), ['Molecule', 'MW', 'Stage', 'V-iD', 'Note'], 'the columns, in their order');
|
|
160
|
+
} finally {
|
|
161
|
+
view.close();
|
|
162
|
+
grok.shell.closeTable(df);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
});
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
import * as grok from 'datagrok-api/grok';
|
|
3
|
+
import * as DG from 'datagrok-api/dg';
|
|
4
|
+
import {waitUntil} from '@datagrok-libraries/test/src/test';
|
|
5
|
+
import {_package} from '../package';
|
|
6
|
+
import {AppName, HitDesignTemplate, HitTriageTemplate, PepTriageTemplate} from '../app/types';
|
|
7
|
+
import {CampaignJsonName, CampaignTableName, HitDesignMolColName, PeptiHitHelmColName} from '../app/consts';
|
|
8
|
+
import {HitDesignApp} from '../app/hit-design-app';
|
|
9
|
+
import {HitTriageApp} from '../app/hit-triage-app';
|
|
10
|
+
import {PeptiHitApp} from '../app/pepti-hit-app';
|
|
11
|
+
import {PepTriageApp} from '../app/pep-triage-app';
|
|
12
|
+
import {obfuscateSmiles} from '../app/utils/molreg';
|
|
13
|
+
import type {INewCampaignResult} from '../app/accordeons/new-campaign-accordeon';
|
|
14
|
+
import {defaultCampaignStorage, getDefaultCampaignStorageSettings} from '../packageSettingsEditor';
|
|
15
|
+
import * as api from '../package-api';
|
|
16
|
+
|
|
17
|
+
export const allUsers = DG.Group.defaultGroupsIds['All users'];
|
|
18
|
+
export const otherUserId = '00000000-0000-0000-0000-000000000001';
|
|
19
|
+
export const unknownGroupId = '00000000-0000-0000-0000-00000000b3b3';
|
|
20
|
+
|
|
21
|
+
/** JSON with sorted keys, so two objects compare by content. */
|
|
22
|
+
function canon(x: unknown): string {
|
|
23
|
+
const sort = (v: any): any => Array.isArray(v) ? v.map(sort) : v && typeof v === 'object' ?
|
|
24
|
+
Object.fromEntries(Object.keys(v).sort().map((k) => [k, sort(v[k])])) : v;
|
|
25
|
+
return JSON.stringify(sort(x));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function expectSame(actual: unknown, expected: unknown, what: string): void {
|
|
29
|
+
if (canon(actual) !== canon(expected))
|
|
30
|
+
throw new Error(`${what}: expected ${canon(expected)}, got ${canon(actual)}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Ad-hoc SQL on the database the package's own queries use. */
|
|
34
|
+
export async function hitdesignSql(sql: string): Promise<DG.DataFrame> {
|
|
35
|
+
const connection = (DG.Func.find({package: 'HitTriage', name: 'GetLastModified'})[0] as DG.DataQuery).connection;
|
|
36
|
+
return await connection.query('ZZB3 probe', sql).apply();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const sqlText = (s: string) => `'${s.replace(/'/g, '\'\'')}'`;
|
|
40
|
+
|
|
41
|
+
/** Records the calls of a package query made while [body] runs (live, in [calls]), each as its [input]'s length. */
|
|
42
|
+
export async function countQueryCalls<T>(queryName: string, input: string | null,
|
|
43
|
+
body: (calls: number[]) => Promise<T>): Promise<{result: T, calls: number[]}> {
|
|
44
|
+
const calls: number[] = [];
|
|
45
|
+
const sub = grok.functions.onBeforeRunAction.subscribe((fc) => {
|
|
46
|
+
if (fc?.func?.nqName?.toLowerCase() === `hittriage:${queryName.toLowerCase()}`)
|
|
47
|
+
calls.push(input ? ((fc.inputs as {[name: string]: unknown[] | undefined})[input]?.length ?? -1) : 1);
|
|
48
|
+
});
|
|
49
|
+
try {
|
|
50
|
+
return {result: await body(calls), calls};
|
|
51
|
+
} finally {
|
|
52
|
+
sub.unsubscribe();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function noComputeTemplate(name: string, key: string): HitDesignTemplate {
|
|
57
|
+
return {
|
|
58
|
+
name, key,
|
|
59
|
+
campaignFields: [
|
|
60
|
+
{name: 'Chemist', type: 'String', required: true},
|
|
61
|
+
{name: 'Deadline', type: 'Date'},
|
|
62
|
+
{name: 'Target MW', type: 'Number'},
|
|
63
|
+
],
|
|
64
|
+
stages: ['Idea', 'Made', 'Tested'],
|
|
65
|
+
compute: {descriptors: {enabled: false, args: []}, functions: [], scripts: [], queries: []},
|
|
66
|
+
submit: {fName: 'demoFileSubmit', package: 'HitTriage'},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function triageTemplate(name: string, key: string): HitTriageTemplate {
|
|
71
|
+
return {
|
|
72
|
+
name, key,
|
|
73
|
+
campaignFields: [
|
|
74
|
+
{name: 'Chemist', type: 'String', required: true},
|
|
75
|
+
{name: 'Deadline', type: 'Date', required: false},
|
|
76
|
+
{name: 'Scaffold', type: 'Molecule', required: false},
|
|
77
|
+
],
|
|
78
|
+
dataSourceType: 'Query',
|
|
79
|
+
queryFunctionName: 'Demo Molecules variable',
|
|
80
|
+
compute: {descriptors: {enabled: false, args: []}, functions: [], scripts: [], queries: []},
|
|
81
|
+
submit: {fName: 'demoFileSubmit', package: 'HitTriage'},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function pepTriageTemplate(name: string, key: string): PepTriageTemplate {
|
|
86
|
+
return {...triageTemplate(name, key), sequenceColumnName: 'Helm', moleculeColumnName: 'molfile(Helm)',
|
|
87
|
+
queryFunctionName: 'Demo Peptide Sequences'};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A Date campaign field as the new-campaign form writes it. */
|
|
91
|
+
export const formDate = {_value: '2026-03-27T00:00:00.000Z', isUtc: false, date: '2026-03-27T00:00:00.000Z'};
|
|
92
|
+
/** The older shape of the demo campaigns (HTD-1). */
|
|
93
|
+
export const oldDate = {a: 1759953600000, b: false, date: '2025-10-08T20:00:00.000Z'};
|
|
94
|
+
|
|
95
|
+
export const designCsv = 'Molecule,Stage,V-iD,Note\nCCO,Idea,,first\nc1ccccc1,Made,,second\n';
|
|
96
|
+
export const designColumns = {
|
|
97
|
+
columnSemTypes: {'Molecule': 'Molecule', 'Stage': null, 'V-iD': null, 'Note': null},
|
|
98
|
+
columnTypes: {'Molecule': 'string', 'Stage': 'string', 'V-iD': 'string', 'Note': 'string'},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** A Hit Design campaign.json in its full shape, over {@link designCsv}. */
|
|
102
|
+
export function designCampaign(sb: Sandbox, id: string, template: HitDesignTemplate, extra: {[key: string]: unknown} = {}):
|
|
103
|
+
{name: string, [key: string]: any} {
|
|
104
|
+
const user = DG.User.current();
|
|
105
|
+
return {
|
|
106
|
+
name: id, friendlyName: `Friendly ${id}`, templateName: template.name, status: 'In Progress', createDate: '2024/9/4',
|
|
107
|
+
campaignFields: {'Chemist': 'Ann', 'Deadline': formDate, 'Target MW': 350},
|
|
108
|
+
...designColumns, rowCount: 2, filteredRowCount: 2, savePath: sb.savePath(id), version: 3,
|
|
109
|
+
authorUserId: user.id, authorUserFriendlyName: user.friendlyName, lastModifiedUserName: 'Someone Else',
|
|
110
|
+
permissions: {view: [allUsers], edit: [allUsers]}, template, ...extra,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The landing's Start (`startNewCampaign`): a new campaign from [template], saved once. The app's first row comes
|
|
115
|
+
* filled, so no sketcher opens. */
|
|
116
|
+
export async function startDesignCampaign(app: HitDesignApp, template: HitDesignTemplate, fields: {[key: string]: unknown},
|
|
117
|
+
name?: string, first = 'CCO'): Promise<string> {
|
|
118
|
+
const stubbed = app as unknown as {newCampaignFrame: (t: HitDesignTemplate) => DG.DataFrame};
|
|
119
|
+
const frame = stubbed.newCampaignFrame.bind(app);
|
|
120
|
+
stubbed.newCampaignFrame = (t) => {
|
|
121
|
+
const df = frame(t);
|
|
122
|
+
df.col(app instanceof PeptiHitApp ? PeptiHitHelmColName : HitDesignMolColName)!.set(0, first);
|
|
123
|
+
return df;
|
|
124
|
+
};
|
|
125
|
+
try {
|
|
126
|
+
await app.startNewCampaign(template, fields, name);
|
|
127
|
+
} finally {
|
|
128
|
+
delete (stubbed as {newCampaignFrame?: unknown}).newCampaignFrame;
|
|
129
|
+
}
|
|
130
|
+
return app.campaignId!;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Hit Triage's Start (the landing's `startCampaign`): a new campaign from [template] over a one-molecule table read
|
|
134
|
+
* from a file, saved once. */
|
|
135
|
+
export async function startTriageCampaign(app: HitTriageApp, template: HitTriageTemplate, smiles: string,
|
|
136
|
+
name?: string): Promise<string> {
|
|
137
|
+
const start = app.infoView as unknown as {startCampaign: (t: HitTriageTemplate, camp: INewCampaignResult) => Promise<void>};
|
|
138
|
+
// no trailing newline: fromCsv reads one as an empty row
|
|
139
|
+
await start.startCampaign(template, {df: DG.DataFrame.fromCsv(`smiles\n${smiles}`), type: 'File',
|
|
140
|
+
campaignProps: {Chemist: name ?? smiles}, friendlyName: name});
|
|
141
|
+
return app.campaignId!;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Whether a balloon showing [text] is on the page. */
|
|
145
|
+
export function hasBalloon(text: string): boolean {
|
|
146
|
+
return Array.from(document.querySelectorAll('.d4-balloon')).some((b) => b.textContent?.includes(text));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Appends rows given by column name; filled molecules keep the row-added handler from opening the sketcher. */
|
|
150
|
+
export function addRows(df: DG.DataFrame, rows: {[col: string]: unknown}[]): void {
|
|
151
|
+
for (const r of rows)
|
|
152
|
+
df.rows.addNew(df.columns.names().map((n) => r[n] ?? null), true);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let nextIsolatedName: AppName = 'PeptiHit';
|
|
156
|
+
|
|
157
|
+
/** PeptiHit and PepTriage hardcode their app name; the sandbox gives them its own. */
|
|
158
|
+
class IsolatedPeptiHitApp extends PeptiHitApp {
|
|
159
|
+
private isolatedName?: AppName;
|
|
160
|
+
constructor(c: DG.FuncCall, name: AppName) {
|
|
161
|
+
nextIsolatedName = name;
|
|
162
|
+
super(c);
|
|
163
|
+
this.isolatedName = name;
|
|
164
|
+
}
|
|
165
|
+
override get appName(): AppName {return this.isolatedName ?? nextIsolatedName;}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
class IsolatedPepTriageApp extends PepTriageApp {
|
|
169
|
+
private isolatedName?: AppName;
|
|
170
|
+
constructor(c: DG.FuncCall, name: AppName) {
|
|
171
|
+
nextIsolatedName = name;
|
|
172
|
+
super(c);
|
|
173
|
+
this.isolatedName = name;
|
|
174
|
+
}
|
|
175
|
+
override get appName(): AppName {return this.isolatedName ?? nextIsolatedName;}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
type AnyApp = HitDesignApp | HitTriageApp;
|
|
179
|
+
|
|
180
|
+
/** The private parts of the Hit Triage app a test has to reach. */
|
|
181
|
+
export const internals = (app: AnyApp) => app as unknown as {
|
|
182
|
+
_pickView?: DG.TableView, _pickViewPromise?: Promise<void> | null,
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* A throwaway app name. Every path the apps build (`<app>/campaigns`, `<app>/templates`,
|
|
187
|
+
* `System.AppData/HitTriage/<app>/…`) and every hitdesign row (`app_name`) are private to it, so other
|
|
188
|
+
* sessions on the stand never list its campaigns, and the cleanup is one folder and one `app_name`.
|
|
189
|
+
* The few branches on the app name itself (the AI description, `createHitCampaign`'s PeptiHit table) see
|
|
190
|
+
* neither app, so no test goes through them.
|
|
191
|
+
*/
|
|
192
|
+
export class Sandbox {
|
|
193
|
+
readonly appName: AppName;
|
|
194
|
+
private readonly href = window.location.href;
|
|
195
|
+
private readonly showHelp = grok.shell.windows.showHelp;
|
|
196
|
+
private readonly apps: AnyApp[] = [];
|
|
197
|
+
private maxVidId = 0;
|
|
198
|
+
/** Obfuscated canonical SMILES only this test registers: their dictionary rows go too. */
|
|
199
|
+
readonly ownMolecules = new Set<string>();
|
|
200
|
+
|
|
201
|
+
private constructor(tag: string) {
|
|
202
|
+
this.appName = `ZZB3 ${tag} ${DG.Utils.randomString(6)}` as AppName;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
static async create(tag: string): Promise<Sandbox> {
|
|
206
|
+
const folder = await getDefaultCampaignStorageSettings();
|
|
207
|
+
if (folder.replace(/\/$/, '') !== defaultCampaignStorage)
|
|
208
|
+
throw new Error(`new campaigns would go to ${folder}, outside the sandbox: the tests need the default campaign folder`);
|
|
209
|
+
const sb = new Sandbox(tag);
|
|
210
|
+
sb.maxVidId = (await hitdesignSql('SELECT COALESCE(MAX(id), 0) AS id FROM hitdesign.vid_dictionary')).get('id', 0);
|
|
211
|
+
return sb;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
path(id: string, file: string = CampaignJsonName): string {
|
|
215
|
+
return `${this.appName}/campaigns/${id}/${file}`;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** The dot form campaign.json keeps in `savePath`. */
|
|
219
|
+
savePath(id: string, folder = 'campaigns'): string {
|
|
220
|
+
return `System.AppData/HitTriage/${this.appName}/${folder}/${id}/${CampaignTableName}`;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** The colon form Hit Triage keeps in `ingest.query`. */
|
|
224
|
+
ingestPath(id: string): string {
|
|
225
|
+
return `System:AppData/HitTriage/${this.appName}/campaigns/${id}/${CampaignTableName}`;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
ownMolecule(smiles: string): string {
|
|
229
|
+
this.ownMolecules.add(obfuscateSmiles(_package.convertToSmiles(smiles)));
|
|
230
|
+
return smiles;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async writeTemplate(t: {name: string}): Promise<void> {
|
|
234
|
+
await _package.files.writeAsText(`${this.appName}/templates/${t.name}.json`, JSON.stringify(t));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async writeCampaign(campaign: {name: string}, csv: string, tablePath?: string): Promise<void> {
|
|
238
|
+
if (tablePath)
|
|
239
|
+
await grok.dapi.files.writeAsText(tablePath, csv);
|
|
240
|
+
else
|
|
241
|
+
await _package.files.writeAsText(this.path(campaign.name, CampaignTableName), csv);
|
|
242
|
+
await _package.files.writeAsText(this.path(campaign.name), JSON.stringify(campaign));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async readCampaignText(id: string): Promise<string> {
|
|
246
|
+
return await _package.files.readAsText(this.path(id));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
async readCampaign(id: string): Promise<{[key: string]: any}> {
|
|
250
|
+
return JSON.parse(await this.readCampaignText(id));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async lastModified(id: string): Promise<string | null> {
|
|
254
|
+
const df = await api.queries.getLastModified(this.appName, id);
|
|
255
|
+
return df.rowCount ? df.col('updated_at')!.getString(0) : null;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
private call(name: string, params?: {[name: string]: unknown}): DG.FuncCall {
|
|
259
|
+
return DG.Func.find({package: 'HitTriage', name})[0].prepare(params);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** The app as a link opens it when [campaignId] is given: the router passes the link's `campaignId` to its call. */
|
|
263
|
+
async hitDesign(campaignId?: string): Promise<HitDesignApp> {
|
|
264
|
+
return await this.start(new HitDesignApp(this.call('hitDesignApp', {campaignId}), this.appName));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async peptiHit(): Promise<PeptiHitApp> {
|
|
268
|
+
await grok.functions.call('Bio:initBio', {});
|
|
269
|
+
return await this.start(new IsolatedPeptiHitApp(this.call('peptiHitApp'), this.appName));
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async hitTriage(): Promise<HitTriageApp> {
|
|
273
|
+
return await this.start(new HitTriageApp(this.call('hitTriageApp'), this.appName));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
async pepTriage(): Promise<PepTriageApp> {
|
|
277
|
+
await grok.functions.call('Bio:initBio', {});
|
|
278
|
+
return await this.start(new IsolatedPepTriageApp(this.call('pepTriageApp'), this.appName));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
private async start<T extends AnyApp>(app: T): Promise<T> {
|
|
282
|
+
this.apps.push(app);
|
|
283
|
+
grok.shell.addView(app.multiView);
|
|
284
|
+
const root = app.infoView.root;
|
|
285
|
+
// the template picker, or its offer to create the first template
|
|
286
|
+
await waitUntil(() => root.querySelector('[data-u2-name="template-picker"] select, [data-u2-name="template-picker"] ' +
|
|
287
|
+
'[data-u2="empty-state"]') != null && root.querySelector('.d4-update-shadow') == null,
|
|
288
|
+
`the ${this.appName} landing did not finish loading`, 30000);
|
|
289
|
+
return app;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** Opens a Hit Design / PeptiHit campaign the way its link on the landing does. */
|
|
293
|
+
async openDesign(app: HitDesignApp, id: string): Promise<DG.TableView> {
|
|
294
|
+
await app.infoView.setCampaign(id);
|
|
295
|
+
const view = app.designView;
|
|
296
|
+
if (app.campaignId !== id || !view)
|
|
297
|
+
throw new Error(`campaign ${id} did not open`);
|
|
298
|
+
return view;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** Opens a Hit Triage / PepTriage campaign; its pick view finishes setting up on timers. */
|
|
302
|
+
async openTriage(app: HitTriageApp, id: string): Promise<DG.TableView> {
|
|
303
|
+
await app.infoView.setCampaign(id);
|
|
304
|
+
await waitUntil(() => app.campaignId === id && internals(app)._pickViewPromise != null, `campaign ${id} did not open`, 30000);
|
|
305
|
+
await internals(app)._pickViewPromise;
|
|
306
|
+
const preset = app.campaign?.filters;
|
|
307
|
+
await waitUntil(() => app.filterSettings !== preset, `the pick view of ${id} never read its filters`, 10000);
|
|
308
|
+
return internals(app)._pickView!;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
async savesDone(): Promise<void> {
|
|
312
|
+
await waitUntil(() => this.apps.every((a) => !(a instanceof HitDesignApp && a.isSaving)),
|
|
313
|
+
'a campaign save is still running', 60000);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
async dispose(): Promise<void> {
|
|
317
|
+
try {
|
|
318
|
+
for (const d of DG.Dialog.getOpenDialogs())
|
|
319
|
+
d.close();
|
|
320
|
+
await this.savesDone();
|
|
321
|
+
const open = Array.from(grok.shell.views).map((v) => v.dart);
|
|
322
|
+
for (const app of this.apps) {
|
|
323
|
+
for (const v of [app instanceof HitDesignApp ? app.designView : undefined, internals(app)._pickView, app.multiView]) {
|
|
324
|
+
if (v && open.includes(v.dart))
|
|
325
|
+
v.close();
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
// a progress tracker left open saves its moves as its view closes
|
|
329
|
+
await this.savesDone();
|
|
330
|
+
} finally {
|
|
331
|
+
history.replaceState(history.state, '', this.href);
|
|
332
|
+
grok.shell.windows.showHelp = this.showHelp;
|
|
333
|
+
delete (_package.campaignsCache as {[key: string]: unknown})[this.appName];
|
|
334
|
+
await this.removeServerState();
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
private async removeServerState(): Promise<void> {
|
|
339
|
+
if (await _package.files.exists(this.appName))
|
|
340
|
+
await _package.files.delete(this.appName);
|
|
341
|
+
const app = sqlText(this.appName);
|
|
342
|
+
const vids = (await hitdesignSql(`WITH d AS (DELETE FROM hitdesign.campaign_vids WHERE app_name = ${app} RETURNING vid) SELECT DISTINCT vid FROM d`))
|
|
343
|
+
.col('vid')!.toList() as string[];
|
|
344
|
+
if (vids.length) {
|
|
345
|
+
const own = Array.from(this.ownMolecules).map(sqlText).join(',') || 'NULL';
|
|
346
|
+
await hitdesignSql(`WITH d AS (DELETE FROM hitdesign.vid_dictionary v WHERE v.vid IN (${vids.map(sqlText).join(',')}) ` +
|
|
347
|
+
`AND (v.id > ${this.maxVidId} OR v.mh_string IN (${own})) ` +
|
|
348
|
+
'AND NOT EXISTS (SELECT 1 FROM hitdesign.campaign_vids c WHERE c.vid = v.vid) RETURNING 1) SELECT COUNT(*) AS n FROM d');
|
|
349
|
+
}
|
|
350
|
+
await hitdesignSql(`WITH a AS (DELETE FROM hitdesign.update_logs WHERE app_name = ${app} RETURNING 1), ` +
|
|
351
|
+
`b AS (DELETE FROM hitdesign.campaign_locks WHERE app_name = ${app} RETURNING 1) ` +
|
|
352
|
+
'SELECT (SELECT COUNT(*) FROM a) + (SELECT COUNT(*) FROM b) AS n');
|
|
353
|
+
const left = await hitdesignSql(`SELECT (SELECT COUNT(*) FROM hitdesign.update_logs WHERE app_name = ${app}) + ` +
|
|
354
|
+
`(SELECT COUNT(*) FROM hitdesign.campaign_locks WHERE app_name = ${app}) + ` +
|
|
355
|
+
`(SELECT COUNT(*) FROM hitdesign.campaign_vids WHERE app_name = ${app}) AS n`);
|
|
356
|
+
if (await _package.files.exists(this.appName) || left.get('n', 0) > 0)
|
|
357
|
+
throw new Error(`${this.appName}: the cleanup left files or hitdesign rows behind`);
|
|
358
|
+
}
|
|
359
|
+
}
|