dashboardFallbackArgs rewrote args.indexOf('serve'), the first token equal
to 'serve'. For a profile literally named 'serve' that is the --profile
value, so the fallback corrupted the profile and left the real serve
subcommand in place for a runtime that cannot parse it. The remote
ownership verifiers had the same collision: a remote dashboard spawned
under a 'serve' profile carried two 'serve' tokens in its cmdline and was
judged foreign, so stale cleanup refused to reap it.
Both now locate the subcommand positionally, skipping the value consumed
by -m/--profile/-p, and the remote verifiers count only non-value 'serve'
tokens.
97 lines
3.0 KiB
TypeScript
97 lines
3.0 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
|
|
import { test } from 'vitest'
|
|
|
|
import { dashboardFallbackArgs, serveBackendArgs, sourceDeclaresServe } from './backend-command'
|
|
|
|
test('serveBackendArgs pins a profile when provided', () => {
|
|
assert.deepEqual(serveBackendArgs('worker'), ['--profile', 'worker', 'serve', '--host', '127.0.0.1', '--port', '0'])
|
|
})
|
|
|
|
test('dashboardFallbackArgs preserves a --profile flag ahead of serve', () => {
|
|
const serve = ['-m', 'hermes_cli.main', '--profile', 'worker', 'serve', '--host', '127.0.0.1', '--port', '0']
|
|
assert.deepEqual(dashboardFallbackArgs(serve), [
|
|
'-m',
|
|
'hermes_cli.main',
|
|
'--profile',
|
|
'worker',
|
|
'dashboard',
|
|
'--no-open',
|
|
'--host',
|
|
'127.0.0.1',
|
|
'--port',
|
|
'0'
|
|
])
|
|
})
|
|
|
|
test('dashboardFallbackArgs skips a profile named "serve" and rewrites the subcommand', () => {
|
|
// The profile VALUE 'serve' is not the subcommand: rewriting at index 1
|
|
// yields `--profile dashboard --no-open serve`, which still runs `serve`.
|
|
const serve = ['-m', 'hermes_cli.main', '--profile', 'serve', 'serve', '--host', '127.0.0.1', '--port', '0']
|
|
assert.deepEqual(dashboardFallbackArgs(serve), [
|
|
'-m',
|
|
'hermes_cli.main',
|
|
'--profile',
|
|
'serve',
|
|
'dashboard',
|
|
'--no-open',
|
|
'--host',
|
|
'127.0.0.1',
|
|
'--port',
|
|
'0'
|
|
])
|
|
})
|
|
|
|
test('dashboardFallbackArgs skips a -p profile value named "serve"', () => {
|
|
const serve = ['-p', 'serve', 'serve', '--host', '127.0.0.1', '--port', '0']
|
|
assert.deepEqual(dashboardFallbackArgs(serve), [
|
|
'-p',
|
|
'serve',
|
|
'dashboard',
|
|
'--no-open',
|
|
'--host',
|
|
'127.0.0.1',
|
|
'--port',
|
|
'0'
|
|
])
|
|
})
|
|
|
|
test('dashboardFallbackArgs rewrites through a --profile=serve self-contained flag', () => {
|
|
const serve = ['--profile=serve', 'serve', '--host', '127.0.0.1', '--port', '0']
|
|
assert.deepEqual(dashboardFallbackArgs(serve), [
|
|
'--profile=serve',
|
|
'dashboard',
|
|
'--no-open',
|
|
'--host',
|
|
'127.0.0.1',
|
|
'--port',
|
|
'0'
|
|
])
|
|
})
|
|
|
|
test('dashboardFallbackArgs leaves a serve-looking profile value alone when there is no subcommand', () => {
|
|
const args = ['--profile', 'serve']
|
|
assert.deepEqual(dashboardFallbackArgs(args), args)
|
|
})
|
|
|
|
test('dashboardFallbackArgs is a no-op (copy) when there is no serve token', () => {
|
|
const args = ['-m', 'hermes_cli.main', 'dashboard', '--no-open']
|
|
const out = dashboardFallbackArgs(args)
|
|
assert.deepEqual(out, args)
|
|
})
|
|
|
|
test('sourceDeclaresServe detects the serve subparser registration', () => {
|
|
assert.equal(sourceDeclaresServe('subparsers.add_parser("serve", help="...")'), true)
|
|
assert.equal(sourceDeclaresServe("subparsers.add_parser('serve')"), true)
|
|
assert.equal(sourceDeclaresServe('subparsers.add_parser(\n "serve",\n)'), true)
|
|
})
|
|
|
|
test('sourceDeclaresServe does not false-positive on the substring "server"', () => {
|
|
const oldSource = `
|
|
dashboard_parser = subparsers.add_parser("dashboard", help="Start the web UI dashboard")
|
|
from hermes_cli.web_server import start_server # web server
|
|
`
|
|
|
|
assert.equal(sourceDeclaresServe(oldSource), false)
|
|
})
|