mirror of
https://github.com/mudler/LocalAI.git
synced 2026-10-28 09:08:54 -04:00
* feat(addons): generate and load a static carrier key set A split deployment needs the owner and the frontends to share certificates and a signing key that outlive a process. The loopback carrier makes fresh keys at every start, so it cannot serve that. GenerateCarrierKeys writes a CA certificate, an owner leaf and a frontend leaf, and the frontend signing key pair. It drops the CA key, so nobody can issue a third leaf, and it refuses to overwrite any file. LoadCarrierConfig reads only the files of one role and refuses key files that group or other users can access. The owner never forwards, but NewCarrier still requires a signing key, so the owner config gets a throwaway key in memory instead of the frontends' private key. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): add util addons-carrier-keys An operator who runs the add-on owner and its frontends as separate workloads needs a way to make the shared key set. The command wraps GenerateCarrierKeys: --out names the directory and --owner-host, which can repeat, sets the names the owner certificate is valid for. It prints which files belong on the owner and which on the frontends. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): add the owner and frontend roles to local-ai run Every local-ai run process is its own add-on owner, so a distributed deployment cannot scale its frontends: replicas that share a data volume fight over the owner lock. --addons-role selects combined (today's behaviour, the default), owner or frontend. The owner and frontend roles also take --addons-owner-address and --addons-carrier-dir, and the owner takes --addons-owner-listen. They use the fixed carrier identities and the key set from the carrier key directory. The frontend role has no add-on root, so it never creates the add-ons folder. A bad role setup stops startup with a message that names the flag. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): keep the frontend role away from owner state A frontend holds no add-on state, but it still wrote the library sources file of the data path, which is the owner's file. The frontend role now skips the library option and reads only the galleries named by the flags, and logs a warning when it has no account database, because its pins are then kept per frontend. The add-on manager rejects a relative root even for a forwarding frontend, so the frontend config names the absolute path where an owner would keep its state. Nothing creates or opens it, and a spec checks that the data path stays empty. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * test(addons): run the owner and frontends as separate applications The split roles are only useful if an owner and its frontends work as separate processes that share nothing but the carrier keys and the owner address. A spec now builds them as separate Application values with their own data paths and keys from GenerateCarrierKeys. It covers a frontend that lists apps and reads add-on status through the owner, two frontends on one key set, a frontend that starts while the owner is down and answers unavailable, a second owner refused on the same root, and an owner that restarts on the same root and address and still serves the installed add-on to the same frontend. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * docs(addons): describe running the owner as its own workload An operator who runs several frontend replicas had no documented way to stop each one from being its own add-on owner. The add-ons page now has a section for the owner and frontend roles: one owner replica with its own volume and a recreate-style rollout, a stable owner address, key generation and per-role mounts, a Compose example, what a restart and an owner outage look like, the models-path limit, and the frontend limits. The singleton section names the roles and the distributed-state mode, and the distributed mode page links to the new section. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): gate the addons feature in /api/features One function, Application.AddonsFeature, decides whether the add-on side is on. A combined or owner process answers true when add-ons are enabled and the owner manager exists. A frontend answers true when the owner answered the carrier's audience call within 2 s, and keeps that answer for 10 s so /api/features does not dial the owner per request. /api/features reports the result as "addons", and fine_tuning and quantization take the same value, because both are add-ons. The frontend cache is per-instance state. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): answer 503 on every add-on route when add-ons are off With --addons-enabled=false the real add-on, fine-tuning and quantization routes and services are not registered. One catch-all per prefix answers the typed unavailable response of an absent owner, for any path under it, so a client cannot tell which routes exist. The response is the one the gateway already writes (gateway.WriteUnavailable over typedError), not a second format. With add-ons on, the same routes sit behind RequireAddonsFeature, which reads Application.AddonsFeature, so a frontend that cannot reach the owner gives the same answer. The per-user feature middleware still runs after the gate. No endpoint is added, so the swagger, /api/instructions and RouteFeatureRegistry surfaces do not change. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): build no carrier for a frontend with add-ons off addonConfigFor already returned the zero config before it read a role flag when add-ons are disabled. Say so on the way out: when a role, owner address, listen address or carrier directory flag is set, log one info line that the flags are ignored. A frontend with --addons-enabled=false needs no owner address and no key directory, loads no keys and builds no carrier. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(ui): hide add-on entries when the addons feature is off The UI reads features.addons from /api/features. When it is false: the sidebar shows no Add-ons entry and no pinned apps, the 404 page lists no add-on destination, the shell does not call /api/addons/pins or /api/addons/builtin, and /app/addons, /app/addons/*, /app/fine-tune and /app/quantize lead back to /app. The Build hub tabs for add-ons, fine-tuning and quantization were already keyed on features and now follow the gate. An absent key (an older server) counts as on. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * docs(addons): describe the addons feature gate The --addons-enabled row now says the UI hides the add-on entries and every add-on, fine-tuning and quantization route answers 503. A new subsection describes the addons key of /api/features, the 10 s frontend cache as per-instance state, and that a frontend with add-ons off needs no owner address or key directory. The fine-tuning and quantization pages say they are off with --addons-enabled=false. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(addons): give a frontend no add-on state root OwnerConfig.validate required an absolute root for every role, so a frontend named a path under the data directory that nothing was allowed to open. Only the owner has a state root now: validate checks it when the instance is the owner, and the frontend role leaves Root empty. Nothing on a frontend reads or creates it. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(addons): make the carrier signing key optional for the owner NewCarrier required an Ed25519 signing key of every instance, so the owner role loaded a throwaway key in memory that it never used. The owner never signs an outbound request, so it now needs none: NewCarrier accepts an empty key when the instance is the owner and still requires a whole key from a frontend, and a malformed key is refused for both. LoadCarrierConfig no longer generates one. The owner still verifies frontend signatures with frontend-sign.pub. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Keep the owner address out of the add-on identity file The owner address is runtime configuration, so storing it and comparing the whole file made a moved owner refuse its own root. The identity file now holds the owner ID and storage ID only. An older file that still has an address loads, and the address is ignored. A different owner ID or storage ID is still refused. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * docs(addons): state that an existing root loads under the owner role The owner identity no longer stores its address, so a root written by a single node loads under the owner role when the owner and storage identity match. Say so, and keep the caveat about absolute paths in the journal. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(addons): refuse library-source routes on a frontend A frontend must keep no owner state, but the library-source routes, the ApplyLibraries call and the startup official-libraries step still opened and wrote addons/sources.json in its data path. Mark the frontend role in the add-on config, also when add-ons are off. On a frontend, LibrarySources returns the unavailable error, ApplyLibraries does nothing and the startup step skips the store. The six /api/library/sources routes answer 503 with the body that the add-on feature gate writes, and an X-LocalAI-Reason header names the cause. Reads are refused too: the carrier has no verb for them. Owner and combined roles are unchanged. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(addons): put the reason in the unavailable body WriteUnavailable wrote the plain text "addon request failed", and the library-source refusal put its reason in an X-LocalAI-Reason header. Write the LocalAI error envelope instead, with a message, a type and the code "unavailable", and keep the 503 status. The message names the cause: add-ons are off on this instance, the add-on owner is not reachable, or library sources are managed on the owner. Remove the header. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): serve library calls on the add-on owner Add the carrier verbs a frontend needs to work on the library through the owner: library-list, library-add, library-update, library-enable, library-disable, library-remove, library-backend-resolve and library-backend-releases. A call carries the operation in one LibraryCall field of the wire request, so an old owner rejects it as an invalid binding. Every verb but the three reads is a mutation, and the reply is an envelope of data or a typed error, so a frontend gives the status the owner's own routes give. The owner serves them through gateway.LibraryAdmin, implemented in the application on the same LocalAdmin as the owner's HTTP routes. It runs the owner's administrator check before any store call. Add two peer-authenticated reads that take no actor and leave the audience reply unchanged: GET /addons/capabilities (protocol, calls and the owner's OS and architecture) and GET /addons/library/snapshot (the gallery-relevant source list and its version). Split the backend install: Installer.Resolve is the owner's half (resolve, pick the meta backend for the asker's capability, pin by digest) and returns a Plan; the node that installs runs the collision check and the gallery install itself. Move the source administration behind library.Admin and add library.ReconcileInfos for a source list read from the owner. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): forward library routes from a frontend to the owner A frontend refused the library-source routes and did not serve the backend library routes. Forward them instead, and keep the owner the only writer of the sources. The library-source routes work on library.Admin: the local store on a combined or owner process, the carrier on a frontend. The frontend checks the calling account (a legacy API key is refused with 401), and the owner checks the administrator right again before any store call. With add-ons off, a frontend answers these routes with a 503. A frontend asks the owner for its source list every 60 seconds through the peer-authenticated snapshot call and rebuilds its model and backend gallery lists, and the official-libraries switch, only when the version changed. If the owner does not answer, it keeps the last lists and marks them stale. Changing official_libraries on a frontend is refused with 409. The backend library install is split. The owner resolves the entry and pins the image; the frontend runs the gallery install on its own node, with its own size limit and strict mode. A frontend refuses library calls to an owner that does not serve them, or that runs on another OS or architecture. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * docs(addons): document library operations on a frontend Replace the frontend limits that said a frontend refuses the library routes with what happens now: the library sources and the backend library go through the owner, the gallery lists follow the owner every 60 seconds, official_libraries is set on the owner, and the owner and the frontends must run on one OS and architecture. Add specs for the split owner: a frontend lists sources through the owner, a source added on a frontend reaches the owner and then the other frontend after a refresh, a write with the owner down answers 503 with the error envelope, official_libraries answers 409 on a frontend and a change on the owner reaches the frontend's gallery lists, the lists are kept and marked stale while the owner is down, a platform mismatch and a legacy API key are refused, and a frontend installs a backend into its own path from the owner's plan. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): check the shared models path with a probe Exports write into the models path of the owner, and frontends load models from their own path. A wrong mount fails silently: the export succeeds and the model never appears. The owner writes a probe file with a random nonce into its models path at start. A frontend fetches the nonce over the carrier and checks at start, then every 60 seconds, that the same file is visible at the same absolute path. On a mismatch it logs an error, reports model_exports false and blocks its export and import routes. The owner refuses an export or import while its own probe is missing, and keeps running if it cannot write the probe. An unreachable or older owner gives "unknown" and leaves exports on. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * docs(api): describe the library refusal and forwarding The library-source and backend-library routes forward to the add-on owner on a frontend and answer 503 when the owner cannot serve them. Add the 503 to their swagger annotations, regenerate the swagger files, and say in /api/instructions that a frontend forwards these routes. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): let frontends run the backend update check through the owner In named-user mode a frontend has no user to act as, so the background backend update check failed there. Add one read-only system call for the release lookup. The owner accepts it only on the peer-authenticated route from a pinned frontend, only for backend-releases, and without an actor. Calls through /addons/forward cannot carry the mark, and every user-facing call still goes through the administrator check. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(mcp): expose the backend update check as a tool Add list_backend_library_updates, a read-only tool for GET /backends/library/updates. The in-process client reads the library installer, and the HTTP client calls the route. The six library source routes stay out of the catalog: the assistant has no per-call actor and no approval card for library changes. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(api): add export status routes for fine-tuning and quantization The add-on UIs could not know that model exports are blocked until a user hit the refusal of the export route. Add GET /api/fine-tuning/status and GET /api/quantization/status. Each returns {"model_exports": bool}, from the same check that drives the model_exports key of /api/features. The routes sit behind the add-ons gate, so they answer 503 when add-ons are off. They are listed in the swagger spec, the instructions registry, the route-feature registry and the feature docs. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(addons): disable exports when the models probe fails The fine-tuning and quantization pages now read the new status route and turn off the export form, the checkpoint export button and the import button when model_exports is false. A short reason shows next to the control. A failed or slow answer leaves the controls on, as the server does for an unknown check. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
262 lines
14 KiB
JavaScript
262 lines
14 KiB
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { readFileSync, readdirSync } from 'node:fs'
|
|
import { join } from 'node:path'
|
|
import { load, draw, here, hostUi, React, renderToString } from './load.mjs'
|
|
import { createApi } from '../src/api.js'
|
|
import en from '../src/i18n/en.js'
|
|
|
|
const read = (p) => readFileSync(p, 'utf8')
|
|
const src = join(here, '../src')
|
|
const toolsUi = join(here, '../../../internal/tools-ui/src')
|
|
const files = (dir) => readdirSync(dir, { recursive: true }).filter(f => /\.(jsx?|mjs)$/.test(f)).map(f => join(dir, f))
|
|
const ownText = files(src).map(read).join('\n')
|
|
const sharedText = files(toolsUi).map(read).join('\n')
|
|
|
|
const flatten = (obj, prefix = '') => Object.entries(obj).flatMap(([k, v]) =>
|
|
typeof v === 'string' ? [[`${prefix}${k}`, v]] : v && typeof v === 'object' && !Array.isArray(v) ? flatten(v, `${prefix}${k}.`) : [])
|
|
|
|
const job = (extra = {}) => ({ id: 'job-1234567890', model: 'org/base', backend: 'trl', training_type: 'lora', training_method: 'sft', created_at: '2026-10-18T10:00:00Z', ...extra })
|
|
|
|
test('page: the first paint has the core test ids of the form and the job list', async () => {
|
|
const { mod, sdk } = await load()
|
|
const html = draw(await mod.createAddon(sdk), { page: 'jobs', path: '' })
|
|
for (const id of ['fine-tune-page', 'fine-tune-form', 'tool-steps', 'tool-checks', 'ft-bar', 'ft-start', 'ft-recipe', 'ft-jobs', 'ft-more-toggle']) {
|
|
if (id === 'ft-more-toggle') continue // inside the closed disclosure
|
|
assert.match(html, new RegExp(`data-testid="${id}"`), id)
|
|
}
|
|
})
|
|
|
|
test('page: a viewer without fine_tuning gets the off notice, no form and no core call', async () => {
|
|
const { mod, sdk, calls } = await load({ viewer: { isAdmin: () => false, hasFeature: (f) => f !== 'fine_tuning' } })
|
|
const html = draw(await mod.createAddon(sdk), { page: 'jobs', path: '' })
|
|
assert.match(html, /data-testid="tool-off"/)
|
|
assert.match(html, /Your account cannot fine-tune/)
|
|
assert.doesNotMatch(html, /fine-tune-form/)
|
|
assert.deepEqual(calls, [])
|
|
})
|
|
|
|
test('page: the API helper uses the core fine-tuning paths and bodies', async () => {
|
|
const seen = []
|
|
const reply = { ok: true, json: async () => ({}) }
|
|
const ctx = {
|
|
core: { fetch: async (p, i) => { seen.push([p, i]); return reply } },
|
|
json: async (p, i) => { seen.push([p, i]); return {} },
|
|
}
|
|
const api = createApi(ctx)
|
|
await api.fineTune.status()
|
|
await api.fineTune.listBackends()
|
|
await api.fineTune.listJobs()
|
|
await api.fineTune.getJob('a b')
|
|
await api.fineTune.startJob({ model: 'm' })
|
|
await api.fineTune.stopJob('j1', true)
|
|
await api.fineTune.stopJob('j1', false)
|
|
await api.fineTune.deleteJob('j1')
|
|
await api.fineTune.listCheckpoints('j1')
|
|
await api.fineTune.exportModel('j1', { name: 'n' })
|
|
await api.resources.get()
|
|
const paths = seen.map(s => `${s[1]?.method || 'GET'} ${s[0]}`)
|
|
assert.deepEqual(paths, [
|
|
'GET /api/fine-tuning/status', 'GET /api/fine-tuning/backends', 'GET /api/fine-tuning/jobs', 'GET /api/fine-tuning/jobs/a%20b',
|
|
'POST /api/fine-tuning/jobs', 'POST /api/fine-tuning/jobs/j1/stop?save_checkpoint=true',
|
|
'POST /api/fine-tuning/jobs/j1/stop?save_checkpoint=false', 'DELETE /api/fine-tuning/jobs/j1',
|
|
'GET /api/fine-tuning/jobs/j1/checkpoints', 'POST /api/fine-tuning/jobs/j1/export', 'GET /api/resources',
|
|
])
|
|
assert.equal(seen[4][1].body, JSON.stringify({ model: 'm' }))
|
|
assert.equal(seen[4][1].headers['Content-Type'], 'application/json')
|
|
})
|
|
|
|
test('page: the dataset upload is a FormData body with no Content-Type header', async () => {
|
|
const seen = []
|
|
const ctx = { json: async (p, i) => { seen.push([p, i]); return { path: '/x/y.jsonl' } } }
|
|
const out = await createApi(ctx).fineTune.uploadDataset(new Blob(['{}'], { type: 'application/json' }))
|
|
assert.equal(out.path, '/x/y.jsonl')
|
|
const [path, init] = seen[0]
|
|
assert.equal(path, '/api/fine-tuning/datasets')
|
|
assert.equal(init.method, 'POST')
|
|
assert.ok(init.body instanceof FormData)
|
|
assert.equal(init.headers, undefined)
|
|
})
|
|
|
|
test('page: a failed upload or call throws the server message', async () => {
|
|
const { mod, sdk } = await load({ fetch: async () => ({ ok: false, status: 413, json: async () => ({ error: { message: 'too big' } }) }) })
|
|
const { api } = await mod.__partsFor(sdk)
|
|
await assert.rejects(api.fineTune.uploadDataset(new Blob(['x'])), /too big/)
|
|
await assert.rejects(api.fineTune.listJobs(), /too big/)
|
|
})
|
|
|
|
test('page: the progress stream is read through core.fetch with the abort signal', async () => {
|
|
const seen = []
|
|
const ctx = { core: { fetch: async (p, i) => { seen.push([p, i]); return { ok: true } } } }
|
|
const controller = new AbortController()
|
|
await createApi(ctx).fineTune.progress('j 1', controller.signal)
|
|
assert.equal(seen[0][0], '/api/fine-tuning/jobs/j%201/progress')
|
|
assert.equal(seen[0][1].signal, controller.signal)
|
|
})
|
|
|
|
test('page: the download link carries the base path', async () => {
|
|
const { mod, sdk } = await load()
|
|
// The base path is read from the <base href> element, as the host reads it.
|
|
globalThis.document = { querySelector: () => ({ getAttribute: () => 'http://localhost/base/' }) }
|
|
let ExportPanel
|
|
try { ExportPanel = (await mod.__partsFor(sdk)).parts.ExportPanel } finally { delete globalThis.document }
|
|
const html = renderToString(React.createElement(ExportPanel, { job: job({ status: 'completed', export_status: 'completed', export_model_name: 'my-model' }) }))
|
|
assert.match(html, /href="\/base\/api\/fine-tuning\/jobs\/job-1234567890\/download"/)
|
|
assert.match(html, /data-testid="export-next"/)
|
|
assert.match(html, /href="\/base\/app\/chat\/my-model"/)
|
|
})
|
|
|
|
test('progress: a running job whose percent reads 0 shows an unknown progress, not 0%', async () => {
|
|
const { mod, sdk } = await load()
|
|
const { JobView } = (await mod.__partsFor(sdk)).parts
|
|
const html = renderToString(React.createElement(JobView, {
|
|
job: job({ status: 'training' }),
|
|
seed: { latest: { status: 'training', progress_percent: 0, current_step: 0, total_steps: 100 } },
|
|
onStop() {}, onReuse() {}, onResume() {}, onTerminal() {}, exportCheckpoint() {},
|
|
}))
|
|
assert.match(html, /data-testid="job-view"/)
|
|
assert.match(html, /data-indeterminate/)
|
|
assert.doesNotMatch(html, /bt-job__percent">0/)
|
|
assert.match(html, /Progress not reported yet/)
|
|
})
|
|
|
|
test('progress: a running job with a percent shows it', async () => {
|
|
const { mod, sdk } = await load()
|
|
const { JobView } = (await mod.__partsFor(sdk)).parts
|
|
const html = renderToString(React.createElement(JobView, {
|
|
job: job({ status: 'training' }),
|
|
seed: { latest: { status: 'training', progress_percent: 40, current_step: 40, total_steps: 100 } },
|
|
onStop() {}, onReuse() {}, onResume() {}, onTerminal() {}, exportCheckpoint() {},
|
|
}))
|
|
assert.match(html, /bt-job__percent">40<small>/)
|
|
assert.match(html, /aria-valuenow="40"/)
|
|
assert.doesNotMatch(html, /data-indeterminate/)
|
|
assert.match(html, /data-testid="job-stop"/)
|
|
})
|
|
|
|
test('progress: a failed job shows its message and the retry control', async () => {
|
|
const { mod, sdk } = await load()
|
|
const { JobView } = (await mod.__partsFor(sdk)).parts
|
|
const html = renderToString(React.createElement(JobView, {
|
|
job: job({ status: 'failed', message: 'CUDA out of memory' }),
|
|
seed: { latest: null }, onStop() {}, onReuse() {}, onResume() {}, onTerminal() {}, exportCheckpoint() {},
|
|
}))
|
|
assert.match(html, /data-testid="job-failed-message"[^>]*>CUDA out of memory/)
|
|
assert.match(html, /data-testid="job-retry"/)
|
|
assert.match(html, /data-testid="job-try"/)
|
|
})
|
|
|
|
test('export: the export panel and the checkpoint export buttons are for an administrator', async () => {
|
|
const done = job({ status: 'completed' })
|
|
const seed = { checkpoints: [{ path: '/srv/c1', step: 10, loss: 0.5, epoch: 1 }] }
|
|
const admin = await load({ viewer: { isAdmin: () => true, hasFeature: () => true } })
|
|
const a = (await admin.mod.__partsFor(admin.sdk)).parts
|
|
const adminPanel = renderToString(React.createElement(a.ExportPanel, { job: done, seed }))
|
|
assert.match(adminPanel, /id="ft-export-format"/)
|
|
assert.doesNotMatch(adminPanel, /data-testid="export-admin-only"/)
|
|
const adminJob = renderToString(React.createElement(a.JobView, { job: done, seed, onStop() {}, onReuse() {}, onResume() {}, onTerminal() {}, exportCheckpoint() {} }))
|
|
assert.match(adminJob, /data-testid="job-checkpoints"/)
|
|
assert.match(adminJob, /data-icon="save"/)
|
|
|
|
const member = await load({ viewer: { isAdmin: () => false, hasFeature: () => true } })
|
|
const m = (await member.mod.__partsFor(member.sdk)).parts
|
|
const memberPanel = renderToString(React.createElement(m.ExportPanel, { job: done, seed }))
|
|
assert.match(memberPanel, /data-testid="export-admin-only"/)
|
|
assert.match(memberPanel, /Exporting a model is for administrators/)
|
|
assert.doesNotMatch(memberPanel, /ft-export-format/)
|
|
const memberJob = renderToString(React.createElement(m.JobView, { job: done, seed, onStop() {}, onReuse() {}, onResume() {}, onTerminal() {}, exportCheckpoint() {} }))
|
|
assert.match(memberJob, /data-testid="job-checkpoints"/)
|
|
assert.doesNotMatch(memberJob, /data-icon="save"/)
|
|
})
|
|
|
|
test('dialogs: the stop and delete dialogs are host layers with the core test ids', async () => {
|
|
const { mod, sdk } = await load()
|
|
const { StopDialogBody, DeleteDialogBody } = (await mod.__partsFor(sdk)).parts
|
|
const stop = renderToString(React.createElement(StopDialogBody, { onChoose() {}, close() {} }))
|
|
for (const id of ['stop-dialog', 'stop-discard', 'stop-keep']) assert.match(stop, new RegExp(`data-testid="${id}"`), id)
|
|
const del = renderToString(React.createElement(DeleteDialogBody, { onConfirm() {}, close() {} }))
|
|
for (const id of ['delete-dialog', 'delete-confirm']) assert.match(del, new RegExp(`data-testid="${id}"`), id)
|
|
})
|
|
|
|
test('dialogs: choosing in the stop dialog stops with or without a checkpoint and closes the layer', async () => {
|
|
const { mod, sdk } = await load()
|
|
const { StopDialogBody } = (await mod.__partsFor(sdk)).parts
|
|
const out = []
|
|
const tree = StopDialogBody({ onChoose: (keep) => out.push(['choose', keep]), close: () => out.push(['close']) })
|
|
const buttons = []
|
|
const walk = (n) => { if (!n || typeof n !== 'object') return; if (n.props?.['data-testid']?.startsWith('stop-') && n.props.onClick) buttons.push(n); [].concat(n.props?.children || []).forEach(walk) }
|
|
walk(tree)
|
|
buttons.find(b => b.props['data-testid'] === 'stop-keep').props.onClick()
|
|
buttons.find(b => b.props['data-testid'] === 'stop-discard').props.onClick()
|
|
assert.deepEqual(out, [['close'], ['choose', true], ['close'], ['choose', false]])
|
|
})
|
|
|
|
test('chart: the loss chart draws a line from two steps and a waiting note before', async () => {
|
|
const { mod, sdk } = await load()
|
|
const { LossChart } = (await mod.__partsFor(sdk)).parts
|
|
const some = renderToString(React.createElement(LossChart, { events: [{ current_step: 1, loss: 2 }, { current_step: 2, loss: 1.5 }], totalSteps: 10 }))
|
|
assert.match(some, /data-testid="job-chart"/)
|
|
assert.match(some, /<polyline class="bt-chart__line"/)
|
|
const none = renderToString(React.createElement(LossChart, { events: [], totalSteps: 10 }))
|
|
assert.match(none, /The chart draws once the job has reported two steps/)
|
|
})
|
|
|
|
test('plural: the job count picks the singular and the plural key', async () => {
|
|
const { mod, sdk } = await load()
|
|
const { ctx } = await mod.__partsFor(sdk)
|
|
assert.equal(ctx.plural('jobs.count', 1), '1 kept on this server')
|
|
assert.equal(ctx.plural('jobs.count', 3), '3 kept on this server')
|
|
})
|
|
|
|
test('i18n: every literal key the add-on and the shared views read is in en.js', () => {
|
|
const keys = new Set()
|
|
for (const text of [ownText, sharedText]) for (const m of text.matchAll(/\bt\(\s*'([A-Za-z0-9_.]+)'/g)) keys.add(m[1])
|
|
assert.ok(keys.size > 100, `found only ${keys.size} literal keys`)
|
|
const missing = [...keys].filter(k => typeof en[k] !== 'string')
|
|
assert.deepEqual(missing, [])
|
|
})
|
|
|
|
test('i18n: en.js repeats the host strings and adds only the keys the add-on owns', () => {
|
|
const tools = Object.fromEntries(flatten(JSON.parse(read(join(hostUi, 'public/locales/en/tools.json')))))
|
|
const own = []
|
|
for (const [k, v] of Object.entries(en)) {
|
|
if (k in tools) assert.equal(v, tools[k], k)
|
|
else own.push(k)
|
|
}
|
|
assert.deepEqual(own.sort(), ['export.adminOnly.text', 'export.adminOnly.title', 'export.blocked', 'run.unknownPercent'])
|
|
assert.equal(Object.keys(en).some(k => k.startsWith('quantize.')), false)
|
|
})
|
|
|
|
test('style: the stylesheet starts with the shared tools rules unchanged', () => {
|
|
assert.ok(read(join(src, 'style.css')).startsWith(read(join(toolsUi, 'tools.css'))))
|
|
})
|
|
|
|
test('source: no file imports a core UI file or the router', () => {
|
|
for (const f of files(src)) {
|
|
const text = read(f)
|
|
assert.doesNotMatch(text, /from\s+['"][^'"]*core\/http\/react-ui/, f)
|
|
assert.doesNotMatch(text, /from\s+['"](react|react-dom|react-router-dom|react-i18next)['"]/, f)
|
|
assert.doesNotMatch(text, /\bEventSource\b/, f)
|
|
}
|
|
})
|
|
|
|
test('export: the export controls are off with the reason when the models probe fails', async () => {
|
|
const done = job({ status: 'completed' })
|
|
const seed = { checkpoints: [{ path: '/srv/c1', step: 10, loss: 0.5, epoch: 1 }] }
|
|
const { mod, sdk } = await load()
|
|
const { ExportPanel, JobView } = (await mod.__partsFor(sdk)).parts
|
|
const blocked = renderToString(React.createElement(ExportPanel, { job: done, seed, modelExports: false }))
|
|
assert.match(blocked, /data-testid="export-blocked"/)
|
|
assert.match(blocked, new RegExp(en['export.blocked'].slice(0, 30)))
|
|
assert.match(blocked, /<button[^>]*disabled=""[^>]*>[^]*?<\/button>/)
|
|
const open = renderToString(React.createElement(ExportPanel, { job: done, seed }))
|
|
assert.doesNotMatch(open, /data-testid="export-blocked"/)
|
|
const props = { job: done, seed, onStop() {}, onReuse() {}, onResume() {}, onTerminal() {}, exportCheckpoint() {} }
|
|
const off = renderToString(React.createElement(JobView, { ...props, modelExports: false }))
|
|
const on = renderToString(React.createElement(JobView, props))
|
|
const exportBtn = (html) => html.match(/<button[^>]*title="[^"]*"[^>]*><i data-icon="save"/)[0]
|
|
assert.match(exportBtn(off), /disabled=""/)
|
|
assert.match(exportBtn(off), new RegExp(en['export.blocked'].slice(0, 30)))
|
|
assert.doesNotMatch(exportBtn(on), /disabled/)
|
|
})
|