Fix UI dataset upload field order

This commit is contained in:
Emil
2026-07-23 22:20:18 +03:00
parent e83e0b5e1f
commit 5be87ad762
2 changed files with 31 additions and 1 deletions
@@ -170,6 +170,36 @@ func TestUIRejectsCrossOriginUpload(t *testing.T) {
}
}
func TestUIUploadDatasetCreatesJob(t *testing.T) {
e := newEnv(t, healthy)
var body bytes.Buffer
mw := multipart.NewWriter(&body)
_ = mw.WriteField("workload", "similarity-search")
_ = mw.WriteField("parameters", `{"query_smiles":"CCO","top_k":20,"progress_every":0}`)
_ = mw.WriteField("chunk_rows", "1000")
file, err := mw.CreateFormFile("file", "chembl.tsv")
if err != nil {
t.Fatal(err)
}
_, _ = io.WriteString(file, "chembl_id\tcanonical_smiles\nCHEMBL1\tCCO\n")
if err := mw.Close(); err != nil {
t.Fatal(err)
}
req, _ := http.NewRequestWithContext(context.Background(), "POST", e.ts.URL+"/ui/api/jobs/upload", &body)
req.Header.Set("Content-Type", mw.FormDataContentType())
req.SetBasicAuth("operator", uiToken)
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusCreated {
result, _ := io.ReadAll(resp.Body)
t.Fatalf("UI upload = %d: %s", resp.StatusCode, result)
}
}
func TestUIJobAndArtifactAreScopedToTheirJob(t *testing.T) {
e := newEnv(t, healthy)
code, job := e.do(t, "POST", "/jobs", `{"workload":"w","input_uri":"s3://in","chunks":[{"chunk_index":0,"input_uri":"s3://c","input_sha256":"sha"}]}`)
@@ -1 +1 @@
{{define "new-job.html"}}<!doctype html><html><head><meta charset="utf-8"><title>New SciMesh run</title><style>body{font:16px system-ui;margin:2rem;max-width:760px}label{display:block;margin:.8rem 0}input{width:100%;padding:.45rem}button{padding:.6rem 1rem}#error{color:#a00}</style></head><body><p><a href="/ui">← Dashboard</a></p><h1>New similarity-search pipeline check</h1><p>This creates a diagnostic shard job. Use <code>query_smiles</code>; global multi-shard reduction is not available yet.</p><form id="run"><label>ChEMBL TSV <input type="file" name="file" required accept=".tsv,.txt,text/tab-separated-values"></label><label>Query SMILES <input name="query_smiles" required maxlength="200" value="CCO"></label><label>Top k <input name="top_k" type="number" min="1" max="100000" value="20" required></label><label>Rows per shard <input name="chunk_rows" type="number" min="1" max="100000" value="1000" required></label><button>Upload and create job</button></form><p id="error" role="alert"></p><script>document.querySelector('#run').addEventListener('submit',async e=>{e.preventDefault();const f=new FormData(e.target);const p={query_smiles:f.get('query_smiles'),top_k:Number(f.get('top_k')),progress_every:0};f.set('workload','similarity-search');f.set('parameters',JSON.stringify(p));try{const r=await fetch('/ui/api/jobs/upload',{method:'POST',body:f});const d=await r.json();if(!r.ok)throw Error(d.error||'Upload failed');location.href='/ui/jobs/'+d.job_id}catch(err){document.querySelector('#error').textContent=err.message}})</script></body></html>{{end}}
{{define "new-job.html"}}<!doctype html><html><head><meta charset="utf-8"><title>New SciMesh run</title><style>body{font:16px system-ui;margin:2rem;max-width:760px}label{display:block;margin:.8rem 0}input{width:100%;padding:.45rem}button{padding:.6rem 1rem}#error{color:#a00}</style></head><body><p><a href="/ui">← Dashboard</a></p><h1>New similarity-search pipeline check</h1><p>This creates a diagnostic shard job. Use <code>query_smiles</code>; global multi-shard reduction is not available yet.</p><form id="run"><label>ChEMBL TSV <input type="file" name="file" required accept=".tsv,.txt,text/tab-separated-values"></label><label>Query SMILES <input name="query_smiles" required maxlength="200" value="CCO"></label><label>Top k <input name="top_k" type="number" min="1" max="100000" value="20" required></label><label>Rows per shard <input name="chunk_rows" type="number" min="1" max="100000" value="1000" required></label><button>Upload and create job</button></form><p id="error" role="alert"></p><script>document.querySelector('#run').addEventListener('submit',async e=>{e.preventDefault();const fields=new FormData(e.target),file=fields.get('file'),p={query_smiles:fields.get('query_smiles'),top_k:Number(fields.get('top_k')),progress_every:0},upload=new FormData();upload.append('workload','similarity-search');upload.append('parameters',JSON.stringify(p));upload.append('chunk_rows',fields.get('chunk_rows'));upload.append('file',file,file.name);try{const r=await fetch('/ui/api/jobs/upload',{method:'POST',body:upload});const d=await r.json();if(!r.ok)throw Error(d.error||'Upload failed');location.href='/ui/jobs/'+d.job_id}catch(err){document.querySelector('#error').textContent=err.message}})</script></body></html>{{end}}